Skip to content

Commit

Permalink
Patch out g_ExpresserRRScriptBridge instead
Browse files Browse the repository at this point in the history
  • Loading branch information
FortyTwoFortyTwo committed Jun 30, 2023
1 parent 7da2b5b commit 3183577
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
28 changes: 19 additions & 9 deletions gamedata/vscript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -331,18 +331,28 @@

// L4D2 have a global pointer that we don't want to modify it on plugin load

"Signatures"
"Addresses"
{
"CSpeechScriptBridge::Init"
{
"linux" "@_ZN19CSpeechScriptBridge4InitEv"
"windows" "\x57\x8B\xF9\x80\x3F\x00\x74\x2A\x68\x2A\x2A\x2A\x2A"
"g_ExpresserRRScriptBridge"
{
"signature" "VScriptServerTerm"
"linux"
{
"offset" "31"
}
"windows"
{
"offset" "42"
}
}

"CSpeechScriptBridge::Term"
}

"Signatures"
{
"VScriptServerTerm"
{
"linux" "@_ZN19CSpeechScriptBridge4TermEv_part_78"
"windows" "\x56\x8B\xF1\x83\x3E\xFF\x74\x2A"
"linux" "@_Z17VScriptServerTermv"
"windows" "\x80\x3D\x2A\x2A\x2A\x2A\x00\x74\x2A\xE8\x2A\x2A\x2A\x2A\xC6\x05\x2A\x2A\x2A\x2A\x01"
}
}
}
Expand Down
45 changes: 20 additions & 25 deletions scripting/vscript/list.sp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
static ArrayList g_aGlobalFunctions;
static ArrayList g_aClasses;

static DynamicDetour g_hSpeechScriptBridgeInit;
static DynamicDetour g_hSpeechScriptBridgeTerm;
static Address g_ExpresserRRScriptBridge;

void List_LoadGamedata(GameData hGameData)
{
Expand All @@ -17,41 +16,42 @@ void List_LoadGamedata(GameData hGameData)
hDetour = VTable_CreateDetour(hGameData, "IScriptVM", "RegisterClass", ReturnType_Bool, HookParamType_Int);
hDetour.Enable(Hook_Post, List_RegisterClass);

Address pAddress;

pAddress = hGameData.GetMemSig("CSpeechScriptBridge::Init");
if (pAddress)
g_hSpeechScriptBridgeInit = new DynamicDetour(pAddress, CallConv_THISCALL, ReturnType_Void, ThisPointer_Address);

pAddress = hGameData.GetMemSig("CSpeechScriptBridge::Term");
Address pAddress = hGameData.GetAddress("g_ExpresserRRScriptBridge");
if (pAddress)
g_hSpeechScriptBridgeTerm = new DynamicDetour(pAddress, CallConv_THISCALL, ReturnType_Void, ThisPointer_Address);
g_ExpresserRRScriptBridge = LoadFromAddress(pAddress, NumberType_Int32);
}

void List_LoadDefaults()
{
g_aGlobalFunctions = new ArrayList();
g_aClasses = new ArrayList();

if (g_hSpeechScriptBridgeInit)
g_hSpeechScriptBridgeInit.Enable(Hook_Pre, List_BlockDetour);
HSCRIPT pScriptVM = GetScriptVM();

if (g_hSpeechScriptBridgeTerm)
g_hSpeechScriptBridgeTerm.Enable(Hook_Pre, List_BlockDetour);
// In L4D2, there are some global variables that we don't want to modify it.
int iMemory[5];
if (g_ExpresserRRScriptBridge)
{
for (int i = 0; i < sizeof(iMemory); i++)
iMemory[i] = LoadFromAddress(g_ExpresserRRScriptBridge + view_as<Address>(i * 4), NumberType_Int32);

HSCRIPT pScriptVM = GetScriptVM();
StoreToAddress(g_ExpresserRRScriptBridge + view_as<Address>(0), 0, NumberType_Int32);
StoreToAddress(g_ExpresserRRScriptBridge + view_as<Address>(4), -1, NumberType_Int32);
StoreToAddress(g_ExpresserRRScriptBridge + view_as<Address>(16), 0, NumberType_Int32);
}

// Create new vscriptvm and set back, so we can collect all of the default stuffs
SetScriptVM(view_as<HSCRIPT>(Address_Null));
GameSystem_ServerInit();
GameSystem_ServerTerm();
SetScriptVM(pScriptVM);

if (g_hSpeechScriptBridgeInit)
g_hSpeechScriptBridgeInit.Disable(Hook_Pre, List_BlockDetour);

if (g_hSpeechScriptBridgeTerm)
g_hSpeechScriptBridgeTerm.Disable(Hook_Pre, List_BlockDetour);
if (g_ExpresserRRScriptBridge)
{
StoreToAddress(g_ExpresserRRScriptBridge + view_as<Address>(0), iMemory[0], NumberType_Int32);
StoreToAddress(g_ExpresserRRScriptBridge + view_as<Address>(4), iMemory[1], NumberType_Int32);
StoreToAddress(g_ExpresserRRScriptBridge + view_as<Address>(16), iMemory[4], NumberType_Int32);
}
}

MRESReturn List_Init(Address pScriptVM, DHookReturn hReturn)
Expand Down Expand Up @@ -82,11 +82,6 @@ MRESReturn List_RegisterClass(Address pScriptVM, DHookReturn hReturn, DHookParam
return MRES_Ignored;
}

MRESReturn List_BlockDetour(Address pThis)
{
return MRES_Supercede;
}

ArrayList List_GetAllGlobalFunctions()
{
return g_aGlobalFunctions;
Expand Down

0 comments on commit 3183577

Please sign in to comment.