[Hooking] Optimizie inline-asm hooks

This commit is contained in:
momo5502 2017-02-01 13:44:25 +01:00
parent 7954330418
commit 29acb108be
15 changed files with 196 additions and 94 deletions

View File

@ -84,15 +84,28 @@ namespace Components
push esi
push edi
push eax
pushad
// Check if custom handler should be bypassed
call AssetHandler::HasThreadBypass
mov [esp + 20h], eax
popad
pop eax
test al, al
jnz finishOriginal
mov ecx, [esp + 18h] // Asset type
mov ebx, [esp + 1Ch] // Filename
push eax
pushad
push ebx
push ecx
@ -100,6 +113,11 @@ namespace Components
add esp, 8h
mov[esp + 20h], eax
popad
pop eax
test eax, eax
jnz finishFound
@ -196,11 +214,18 @@ namespace Components
{
__asm
{
push [esp + 8]
push [esp + 8]
push eax
pushad
push [esp + 2Ch]
push [esp + 2Ch]
call AssetHandler::IsAssetEligible
add esp, 08h
mov [esp + 20h], eax
popad
pop eax
test al, al
jz doNotLoad

View File

@ -97,7 +97,7 @@ namespace Components
Network::SendCommand(sock, adr, "connect", connectData.SerializeAsString());
}
void Auth::ParseConnectData(Game::msg_t* msg, Game::netadr_t addr)
void Auth::ParseConnectData(Game::msg_t* msg, Game::netadr_t* addr)
{
Network::Address address(addr);
@ -210,12 +210,17 @@ namespace Components
{
__asm
{
pushad
lea eax, [esp + 20h]
push eax
push esi
call Auth::ParseConnectData
pop esi
pop eax
popad
mov edi, 6265FEh
jmp edi
push 6265FEh
retn
}
}

View File

@ -47,7 +47,7 @@ namespace Components
static Utils::Cryptography::ECC::Key GuidKey;
static void SendConnectDataStub(Game::netsrc_t sock, Game::netadr_t adr, const char *format, int len);
static void ParseConnectData(Game::msg_t* msg, Game::netadr_t addr);
static void ParseConnectData(Game::msg_t* msg, Game::netadr_t* addr);
static void DirectConnectStub();
static void Frame();

View File

@ -452,7 +452,9 @@ namespace Components
// We need esi preserved here, so we have to backup 'all' registers when storing the safearea
call Game::Con_DrawSolidConsole
pushad
call Console::RestoreSafeArea
popad
retn
}
}

View File

@ -67,7 +67,9 @@ namespace Components
{
__asm
{
pushad
call Dedicated::PostInitialization
popad
// Start Com_EvenLoop
mov eax, 43D140h

View File

@ -49,9 +49,11 @@ namespace Components
mov ecx, 5A6510h
call ecx
pushad
push esi
call Lean::SetLeanFlags
pop esi
popad
retn
}
}

View File

@ -143,13 +143,17 @@ namespace Components
{
__asm
{
pushad
push 1
push [esp + 8h]
push [esp + 28h]
call Logger::NetworkLog
add esp, 8h
mov eax, 4576C0h
jmp eax
popad
push 4576C0h
retn
}
}
@ -161,22 +165,26 @@ namespace Components
test eax, eax
jz returnPrint
push [esp + 8h]
pushad
push [esp + 28h]
call Logger::PrintMessagePipe
add esp, 4h
popad
retn
returnPrint:
pushad
push 0
push [esp + 0Ch]
push [esp + 2Ch]
call Logger::NetworkLog
add esp, 8h
popad
push esi
mov esi, [esp + 0Ch]
mov eax, 4AA835h
jmp eax
push 4AA835h
retn
}
}

View File

@ -54,12 +54,19 @@ namespace Components
{
__asm
{
push eax
pushad
push ecx
call Materials::ResolveMaterial
add esp, 4h
mov edx, 5310F0h
jmp edx
mov[esp + 20h], eax
popad
pop eax
push 5310F0h
retn
}
}
@ -82,13 +89,21 @@ namespace Components
{
__asm
{
push eax
pushad
push edx // Material
push eax // offset
push ecx // String
call Materials::WriteDeathMessageIcon
add esp, 0Ch
add esp, 14h
mov[esp + 20h], eax
popad
pop eax
add esp, 8h
retn
}
}

View File

@ -302,10 +302,16 @@ namespace Components
__asm
{
lea eax, [esp + 0C54h]
pushad
push ebp // Command
push eax // Address pointer
call Network::DeployPacket
add esp, 8h
popad
mov al, 1
pop edi
pop esi

View File

@ -52,16 +52,21 @@ namespace Components
{
__asm
{
lea ecx, [esp + 10h]
pushad
lea ecx, [esp + 30h]
push ecx
call Script::StoreScriptName
add esp, 4h
popad
push ebp
mov ebp, ds:1CDEAA8h
mov ecx, 427DC3h
jmp ecx
push 427DC3h
retn
}
}
@ -75,12 +80,14 @@ namespace Components
{
__asm
{
pushad
call Script::RestoreScriptName
popad
mov ds:1CDEAA8h, ebp
mov eax, 427E77h
jmp eax
push 427E77h
retn
}
}

View File

@ -99,11 +99,14 @@ namespace Components
{
__asm
{
pushad
push eax
call ServerInfo::DrawScoreboardInfo
pop eax
mov ecx, 591B70h
jmp ecx
popad
push 591B70h
retn
}
}

View File

@ -85,15 +85,17 @@ namespace Components
{
__asm
{
pushad
call Theatre::WriteBaseline
popad
// Restore overwritten operation
mov ecx, 0A5E9C4h
mov [ecx], 0
// Return to original code
mov ecx, 5A863Ah
jmp ecx
push 5A863Ah
retn
}
}
@ -110,8 +112,8 @@ namespace Components
retn
continue:
mov eax, 5A1AD0h
jmp eax
push 5A1AD0h
retn
}
}
@ -129,8 +131,8 @@ namespace Components
continue:
mov eax, 0B2BB90h
mov esi, 5A8E08h
jmp esi
push 5A8E08h
retn
}
}
@ -150,8 +152,8 @@ namespace Components
mov ecx, [esp + 10h]
push 10h
push ecx
mov eax, 4CB3F6h
jmp eax
push 4CB3F6h
retn
}
}

View File

@ -126,9 +126,11 @@ namespace Components
{
__asm
{
pushad
push edi
call Zones::LoadXModelLodInfo
add esp, 4h
popad
mov eax, [esp + 8h]
push eax

View File

@ -345,13 +345,16 @@ namespace Game
return poolEntry;
}
void Menu_FreeItemMemory(Game::itemDef_t* item)
__declspec(naked) void Menu_FreeItemMemory(Game::itemDef_t* /*item*/)
{
__asm
{
mov edi, item
pushad
mov edi, [esp + 24h]
mov eax, 63D880h
call eax
popad
retn
}
}
@ -402,20 +405,22 @@ namespace Game
return gameType;
}
float UI_GetScoreboardLeft(void* a1)
__declspec(naked) float UI_GetScoreboardLeft(void* /*a1*/)
{
// ReSharper disable once CppEntityNeverUsed
static int func = 0x590390;
float result = 0;
__asm
{
mov eax, a1
call func
mov result, eax
}
push eax
pushad
return result;
mov ecx, 590390h
mov eax, [esp + 28h]
call ecx
mov[esp + 20h], eax
popad
pop eax
retn
}
}
const char *DB_GetXAssetName(XAsset *asset)
@ -463,32 +468,39 @@ namespace Game
return false;
}
XAssetHeader DB_FindXAssetDefaultHeaderInternal(XAssetType _type)
__declspec(naked) XAssetHeader DB_FindXAssetDefaultHeaderInternal(XAssetType /*type*/)
{
// ReSharper disable once CppEntityNeverUsed
static int func = 0x5BB210;
XAssetHeader result;
__asm
{
push edi
mov edi, _type
call func
pop edi
mov result, eax
}
push eax
pushad
return result;
mov eax, 5BB210h
mov edi, [esp + 28h]
call eax
mov [esp + 20h], eax
popad
pop eax
retn
}
}
void FS_AddLocalizedGameDirectory(const char *path, const char *dir)
__declspec(naked) void FS_AddLocalizedGameDirectory(const char* /*path*/, const char* /*dir*/)
{
__asm
{
mov ebx, path
mov eax, dir
pushad
mov ebx, [esp + 24h]
mov eax, [esp + 28h]
mov ecx, 642EF0h
call ecx
popad
retn
}
}
@ -515,52 +527,57 @@ namespace Game
return hash;
}
void R_LoadSunThroughDvars(const char* mapname, sunflare_t* sun)
__declspec(naked) void R_LoadSunThroughDvars(const char* /*mapname*/, sunflare_t* /*sun*/)
{
__asm
{
push ecx
push sun
mov eax, mapname
pushad
push [esp + 28h]
mov eax, [esp + 28h]
mov ecx, 53F990h
call ecx
add esp, 4h
pop ecx
popad
retn
}
}
void R_SetSunFromDvars(sunflare_t* sun)
__declspec(naked) void R_SetSunFromDvars(sunflare_t* /*sun*/)
{
__asm
{
push esi
mov esi, sun
pushad
mov esi, [esp + 24h]
mov eax, 53F6D0h
call ecx
call eax
pop esi
popad
retn
}
}
void SV_KickClient(client_t* client, const char* reason)
__declspec(naked) void SV_KickClient(client_t* /*client*/, const char* /*reason*/)
{
__asm
{
push edi
push esi
pushad
mov edi, 0
mov esi, client
push reason
mov esi, [esp + 24h]
push[esp + 28h]
push 0
push 0
mov eax, 6249A0h
call eax
add esp, 0Ch
pop esi
pop edi
popad
retn
}
}
@ -568,7 +585,7 @@ namespace Game
{
if (client->state < 5)
{
Components::Network::Send(client->addr, Utils::String::VA("error\n%s", reason.data()));
Components::Network::SendCommand(client->addr, "error", reason);
}
SV_KickClient(client, reason.data());
@ -584,27 +601,29 @@ namespace Game
Game::SV_GameSendServerCommand(clientNum, 0, Utils::String::VA("%c \"%s\"", 0x67, message.data()));
}
void IN_KeyUp(kbutton_t* button)
__declspec(naked) void IN_KeyUp(kbutton_t* /*button*/)
{
__asm
{
push esi
mov esi, button
pushad
mov esi, [esp + 24h]
mov eax, 5A5580h
call eax
pop esi
popad
retn
}
}
void IN_KeyDown(kbutton_t* button)
__declspec(naked) void IN_KeyDown(kbutton_t* /*button*/)
{
__asm
{
push esi
mov esi, button
pushad
mov esi, [esp + 24h]
mov eax, 5A54E0h
call eax
pop esi
popad
retn
}
}
@ -639,23 +658,23 @@ namespace Game
}
}
void Load_VertexBuffer(void* data, IDirect3DVertexBuffer9** where, int len)
__declspec(naked) void Load_VertexBuffer(void* /*data*/, IDirect3DVertexBuffer9** /*where*/, int /*len*/)
{
__asm
{
push edi
push ebx
pushad
mov eax, len
mov edi, where
push data
mov eax, [esp + 2Ch]
mov edi, [esp + 28h]
push[esp + 24h]
mov ebx, 5112C0h
call ebx
add esp, 4
pop ebx
pop edi
popad
retn
}
}

View File

@ -65,11 +65,15 @@ BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*l
{
__asm
{
pushad
// This has to be called, otherwise the hook is not uninstalled and we're looping into infinity
call Main::Initialize
mov eax, 6BAC0Fh
jmp eax
popad
push 6BAC0Fh
retn
}
})->install();
}