Skip to content

Commit

Permalink
Add GarbageCollectorForcer ASI. Make AceSlammer buildable (disable ra…
Browse files Browse the repository at this point in the history
…gdoll features)
  • Loading branch information
Mgamerz committed Nov 22, 2020
1 parent 4e0b4e3 commit 183a59d
Show file tree
Hide file tree
Showing 13 changed files with 341 additions and 53 deletions.
54 changes: 43 additions & 11 deletions AceSlammer/AceSlammer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,36 @@
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "detours.lib") //Library needed for Hooking part.

ME3TweaksASILogger logger("Ace Slammer v1", "AceSlammer.txt");
//ME3TweaksASILogger logger("Ace Slammer v1", "AceSlammer.txt");

bool fetchNextItem = false;
bool changeGravity = false;

const int NEXTSTATE_SLAMMING = 1;
const int NEXTSTATE_ZEROG = 2;
const int NEXTSTATE_UPGRAV = 3;
const int NEXTSTATE_NORMAL = 4;
int nextState = NEXTSTATE_UPGRAV;
int numTicksBetweenRagdoll = 12;
int currentRagdollTick = 0;


void __fastcall HookedPE(UObject* pObject, void* edx, UFunction* pFunction, void* pParms, void* pResult)
{
if (fetchNextItem) {
if (changeGravity) {
char* szName = pFunction->GetFullName();
if (strcmp(szName, "Function SFXGame.BioPlayerController.PlayerTick") == 0)
{
bool nextStateSet = false;
ABioPlayerController* bpc = reinterpret_cast<ABioPlayerController*>(pObject);
if (!nextStateSet && nextState == NEXTSTATE_SLAMMING)
{
bpc->WorldInfo->WorldGravityZ = -3100;
bpc->WorldInfo->WorldGravityZ = -6000; //Slam it like Shaq
nextState = NEXTSTATE_NORMAL;
nextStateSet = true;
}
if (!nextStateSet && nextState == NEXTSTATE_NORMAL)
{
bpc ->WorldInfo->WorldGravityZ = -981;
bpc->WorldInfo->WorldGravityZ = -981; //Normal
nextState = NEXTSTATE_UPGRAV;
nextStateSet = true;
}
Expand All @@ -48,15 +51,43 @@ void __fastcall HookedPE(UObject* pObject, void* edx, UFunction* pFunction, void
}
if (!nextStateSet && nextState == NEXTSTATE_UPGRAV)
{
bpc->WorldInfo->WorldGravityZ = 500;
bpc->WorldInfo->WorldGravityZ = 700; //Going up
nextState = NEXTSTATE_ZEROG;
nextStateSet = true;
}

logger.writeToLog(string_format("GRAVITY: %f\n", bpc->WorldInfo->WorldGravityZ), true);
//logger.writeToLog(string_format("GRAVITY: %f\n", bpc->WorldInfo->WorldGravityZ), true);
//logger.writeToConsoleOnly(string_format("Default gravity: %f", wi->DefaultGravityZ), true);
//logger.writeToLog(string_format("%s", szName), true);
fetchNextItem = false;
changeGravity = false;
//logger.writeToLog(string_format("Ragdoll tick %d/%d\n", currentRagdollTick, numTicksBetweenRagdoll), true);
//if (currentRagdollTick >= numTicksBetweenRagdoll)
//{
// auto playerObj = FindObjectOfType(ASFXPawn_Player::StaticClass());
// if (playerObj != NULL) {
// auto player = static_cast<ASFXPawn_Player*>(playerObj);
// auto pawns = FindObjectsOfType(ABioPawn::StaticClass());
// for (int i = 0; i < pawns.Count; i++) {
// auto pawn = static_cast<ABioPawn*>(pawns.Data[i]);
// if (pawn != NULL && pawn->CanRagdoll() && pawn->bCanRagdoll) {
// auto pname = pawn->Name.GetName();
// auto pid = pawn->Name.GetIndex();
// if (pid > 0) {
// // I have no idea what i'm doing
// // But I hate C/C++ strings
// /*auto commandS = string_format("testragdoll %s_%d", pname, pid - 1);
// auto commandWS = s2ws(commandS);
// wchar_t* t = (wchar_t*)commandWS.c_str();
// logger.writeToLog(t, true, true);
// pawn->Controller->ConsoleCommand(t, false);*/
// //pawn->InitRagdoll();
// //pawn->rag
// }
// }
// }
// }
// currentRagdollTick = 0;
//}
}
}
ProcessEvent(pObject, pFunction, pParms, pResult);
Expand All @@ -73,7 +104,7 @@ void timer_start(function<unsigned(void)> func, unsigned int interval)
}


unsigned test()
unsigned timerTick()
{
unsigned nextInterval = 100; //default 100ms
if (nextState == NEXTSTATE_SLAMMING)
Expand All @@ -92,7 +123,8 @@ unsigned test()
{
nextInterval = 250;
}
fetchNextItem = true;
changeGravity = true;
currentRagdollTick++;
return nextInterval;
}

Expand All @@ -104,7 +136,7 @@ void onAttach()
DetourAttach(&(PVOID&)ProcessEvent, HookedPE); //This command will start your Hook.
DetourTransactionCommit();
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
timer_start(test, 1000);
timer_start(timerTick, 1000);
}

BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
Expand Down
2 changes: 1 addition & 1 deletion AceSlammer/AceSlammer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;KismetLogger_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;KismetLogger_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
Expand Down
8 changes: 5 additions & 3 deletions ConsoleExtension/ConsoleExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#pragma comment(lib, "detours.lib") //Library needed for Hooking part.


#define LOGGING 0
#define LOGGING 1

#if LOGGING
ME3TweaksASILogger logger("ConsoleExtension v1", "ConsoleExtension.txt", false);
Expand All @@ -45,6 +45,8 @@ bool shouldSetCamPOV;

FTPOV savedPOVs[10];

wchar_t presencetext[256];
wchar_t currentpresencetext[256];
void HandleConsoleCommand(USFXConsole* console, const wstring& cmd)
{
if (cmd.rfind(L"savecam ") == 0 && cmd.length() == 9)
Expand Down Expand Up @@ -82,7 +84,7 @@ void HandleConsoleCommand(USFXConsole* console, const wstring& cmd)
auto playerpawn = (ASFXPawn_Player*)playerpawns.Data[i];
playerpawn->GroundSpeed = 400.0;
playerpawn->CombatGroundSpeed = 350.0;
playerpawn->StormSpeed = 700.0;
playerpawn->StormSpeed = 700.0;
playerpawn->AccelRate = 1500.0;
}
}
Expand All @@ -107,7 +109,7 @@ void __fastcall HookedPE(UObject* pObject, void* edx, UFunction* pFunction, void
screenLogger.LogMessage(msg);
#endif

}
}
}
#if LOGGING
else if (!strcmp(funcName, "Function SFXGame.BioHUD.PostRender"))
Expand Down
78 changes: 47 additions & 31 deletions Experiments/Experiments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
#pragma comment(lib, "detours.lib") //Library needed for Hooking part.

//ME3TweaksASILogger logger("Match Stats Collector", "MatchStats.txt");
ME3TweaksASILogger logger("MP Controller Client Fix", "WorldInfo.txt");
//ME3TweaksASILogger logger("MP Controller Client Fix", "WorldInfo.txt");
ME3TweaksASILogger logger("Experiments", "Experiments.txt");
bool logNextTick = false;
int interval = 60 * 10; //7 seconds (or 60fps ticks)
int currentTick = 0;

FVector inline RotationToVector(FRotator Rotation) {
FVector Vector;
Expand All @@ -35,7 +38,19 @@ FVector inline RotationToVector(FRotator Rotation) {
void __fastcall HookedPE(UObject* pObject, void* edx, UFunction* pFunction, void* pParms, void* pResult)
{
char* szName = pFunction->GetFullName();
//if (isPartOf(szName, "Function Engine.DebugCameraHUD.PostRender"))
if (strcmp(szName, "Function SFXGame.SFXSFHandler_PCPersonalization.Update") == 0)
{
if (currentTick >= interval)
{
currentTick -= interval;
logger.writeToConsoleOnly(L"Garbage collecting.\n", true);
auto sfxHandler = static_cast<USFXSFHandler_PCPersonalization*>(pObject);
sfxHandler->oWorldInfo->ForceGarbageCollection(false);
} else
{
currentTick++;
}
}
//{
// ProcessEvent(pObject, pFunction, pParms, pResult);
// ADebugCameraHUD* debugCameraHud = (ADebugCameraHUD*)pObject;
Expand Down Expand Up @@ -114,24 +129,24 @@ void __fastcall HookedPE(UObject* pObject, void* edx, UFunction* pFunction, void
// }*/
//}
//else
if (isPartOf(szName, "Function SFXGame.SFXConsole.InputKey")) {
USFXConsole_execInputKey_Parms* params = (USFXConsole_execInputKey_Parms*)pParms;
//Event: 0 - > Down
//Event: 1 - > Up
//Event: 2 - > Holding
//logger.writeToConsoleOnly(string_format("Key pressed: %u %s\n", params->Event, params->Key.GetName()), true);
if (isPartOf(params->Key.GetName(), "Xbox")) {
if (params->Event == 0) {
logger.writeToConsoleOnly(string_format("%s DOWN\n", params->Key.GetName()), true);
}
else if (params->Event == 1) {
logger.writeToConsoleOnly(string_format("%s UP\n", params->Key.GetName()), true);
}
else if (params->Event == 2) {
logger.writeToConsoleOnly(string_format("%s HOLD\n", params->Key.GetName()), true);
}
}
}
//if (isPartOf(szName, "Function SFXGame.SFXConsole.InputKey")) {
// USFXConsole_execInputKey_Parms* params = (USFXConsole_execInputKey_Parms*)pParms;
// //Event: 0 - > Down
// //Event: 1 - > Up
// //Event: 2 - > Holding
// //logger.writeToConsoleOnly(string_format("Key pressed: %u %s\n", params->Event, params->Key.GetName()), true);
// if (isPartOf(params->Key.GetName(), "Xbox")) {
// if (params->Event == 0) {
// logger.writeToConsoleOnly(string_format("%s DOWN\n", params->Key.GetName()), true);
// }
// else if (params->Event == 1) {
// logger.writeToConsoleOnly(string_format("%s UP\n", params->Key.GetName()), true);
// }
// else if (params->Event == 2) {
// logger.writeToConsoleOnly(string_format("%s HOLD\n", params->Key.GetName()), true);
// }
// }
//}
ProcessEvent(pObject, pFunction, pParms, pResult);
}

Expand Down Expand Up @@ -172,17 +187,18 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
case DLL_PROCESS_ATTACH:
// Check if DLC_MOD_ControllerSupport exists at ..\..\BioGame\DLC
if (dirExists("..\\..\\BIOGame\\DLC\\DLC_MOD_ControllerSupport") != 0)
{
DisableThreadLibraryCalls(hModule);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)onAttach, NULL, 0, NULL);
}
/*else
{
MessageBoxW(NULL, L"Controller mod not installed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
}*/
//doesn't exist otherwise
return true;
//MessageBox(NULL, L"Take snapshot now.", L"Stall ASI", MB_ICONINFORMATION);
//if (dirExists("..\\..\\BIOGame\\DLC\\DLC_MOD_ControllerSupport") != 0)
//{
DisableThreadLibraryCalls(hModule);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)onAttach, NULL, 0, NULL);
//}
///*else
//{
// MessageBoxW(NULL, L"Controller mod not installed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
//}*/
////doesn't exist otherwise
//return true;
break;

case DLL_PROCESS_DETACH:
Expand Down
8 changes: 8 additions & 0 deletions FemShep-ME3-ASI-Plugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SplashEnabler", "SplashEnab
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SplashEnablerHost", "SplashEnablerHost\SplashEnablerHost.vcxproj", "{5C263389-C3FD-4A20-91CB-DE4AC00FBF57}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GarbageCollectionForcer", "GarbageCollectorForcer\GarbageCollectionForcer.vcxproj", "{5B71CD3D-EC3C-46BD-8993-9D25105D1D6F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -118,6 +120,12 @@ Global
{5C263389-C3FD-4A20-91CB-DE4AC00FBF57}.Release|x64.Build.0 = Release|x64
{5C263389-C3FD-4A20-91CB-DE4AC00FBF57}.Release|x86.ActiveCfg = Release|Win32
{5C263389-C3FD-4A20-91CB-DE4AC00FBF57}.Release|x86.Build.0 = Release|Win32
{5B71CD3D-EC3C-46BD-8993-9D25105D1D6F}.Debug|x64.ActiveCfg = Debug|Win32
{5B71CD3D-EC3C-46BD-8993-9D25105D1D6F}.Debug|x86.ActiveCfg = Debug|Win32
{5B71CD3D-EC3C-46BD-8993-9D25105D1D6F}.Debug|x86.Build.0 = Debug|Win32
{5B71CD3D-EC3C-46BD-8993-9D25105D1D6F}.Release|x64.ActiveCfg = Release|Win32
{5B71CD3D-EC3C-46BD-8993-9D25105D1D6F}.Release|x86.ActiveCfg = Release|Win32
{5B71CD3D-EC3C-46BD-8993-9D25105D1D6F}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
58 changes: 58 additions & 0 deletions GarbageCollectorForcer/GarbageCollectionForcer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <chrono>
#include <string>
#include "../ME3SDK/SdkHeaders.h"
#include "../detours/detours.h"

#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "detours.lib") //Library needed for Hooking part.

typedef void(__thiscall* tProcessEvent)(class UObject*, class UFunction*, void*, void*);
tProcessEvent ProcessEvent = (tProcessEvent)0x00453120;

auto _personalization_lastForcedGC = std::chrono::steady_clock::now(); // Init at app boot
auto _personalizationGCInterval = 8;

void __fastcall HookedPE(UObject *pObject, void *edx, UFunction *pFunction, void *pParms, void *pResult)
{
char* szName = pFunction->GetFullName();

// Force Garbage Collection when the personalization UI is open (armor locker) every 8 seconds.
if (strcmp(szName, "Function SFXGame.SFXSFHandler_PCPersonalization.Update") == 0)
{
auto now = std::chrono::steady_clock::now();
auto time_elapsed = std::chrono::duration_cast<std::chrono::seconds>(now - _personalization_lastForcedGC).count();
if (time_elapsed > _personalizationGCInterval)
{
USFXSFHandler_PCPersonalization* sfxHandler = static_cast<USFXSFHandler_PCPersonalization*>(pObject);
sfxHandler->oWorldInfo->ForceGarbageCollection(false);
_personalization_lastForcedGC = now;
}
}
ProcessEvent(pObject, pFunction, pParms, pResult);
}

void onAttach()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread()); //This command set the current working thread to the game current thread.
DetourAttach(&(PVOID&)ProcessEvent, HookedPE); //This command will start your Hook.
DetourTransactionCommit();
}

BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)onAttach, NULL, 0, NULL);
return true;
break;

case DLL_PROCESS_DETACH:
return true;
break;
}
return true;
};

22 changes: 22 additions & 0 deletions GarbageCollectorForcer/GarbageCollectionForcer.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="KismetLogger.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Binary file added GarbageCollectorForcer/GarbageCollectionForcer.rc
Binary file not shown.
Loading

0 comments on commit 183a59d

Please sign in to comment.