From e83239e05308b5aa6c5c052b271ac94336b1dac9 Mon Sep 17 00:00:00 2001 From: zaCade Date: Fri, 27 Sep 2019 17:23:39 +0200 Subject: [PATCH] Read offset from gamedata instead of hardcoded. --- .../addons/sourcemod/gamedata/zombiereloaded.txt | 14 ++++++++++++++ src/zr/tools.inc | 16 ++++++++-------- src/zr/tools_functions.inc | 8 -------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/cstrike/addons/sourcemod/gamedata/zombiereloaded.txt b/cstrike/addons/sourcemod/gamedata/zombiereloaded.txt index f52a68b..5a5f6c8 100644 --- a/cstrike/addons/sourcemod/gamedata/zombiereloaded.txt +++ b/cstrike/addons/sourcemod/gamedata/zombiereloaded.txt @@ -1,3 +1,17 @@ "Games" { + "cstrike" + { + "Offsets" + { + // CCSPlayer::m_LastHitGroup + // CCSPlayer::OnTakeDamage_Alive(CTakeDamageInfo const&)+122 mov ecx, [ebp+this] + // CCSPlayer::OnTakeDamage_Alive(CTakeDamageInfo const&)+125 mov edx, [ecx+4444] + // CCSPlayer::OnTakeDamage_Alive(CTakeDamageInfo const&)+12B mov dword ptr [esp+4], offset aHitgroup ; "hitgroup" + "m_LastHitGroup" + { + "linux" "4444" + } + } + } } diff --git a/src/zr/tools.inc b/src/zr/tools.inc index 5a1c025..a5ff38f 100644 --- a/src/zr/tools.inc +++ b/src/zr/tools.inc @@ -92,27 +92,27 @@ ToolsFindOffsets() LogEvent(false, LogType_Fatal, LOG_CORE_EVENTS, LogModule_Tools, "Offsets", "Offset \"CBasePlayer::m_iFOV\" was not found."); } + // If offset "m_hActiveWeapon" can't be found, then stop the plugin. g_iActiveWeapon = FindSendPropInfo("CBaseCombatCharacter", "m_hActiveWeapon"); if (g_iActiveWeapon == -1) { LogEvent(false, LogType_Fatal, LOG_CORE_EVENTS, LogModule_Tools, "Offsets", "Offset \"CBaseCombatCharacter::m_hActiveWeapon\" was not found."); } - // CCSPlayer::m_LastHitGroup - // CCSPlayer::OnTakeDamage_Alive(CTakeDamageInfo const&)+122 mov ecx, [ebp+this] - // CCSPlayer::OnTakeDamage_Alive(CTakeDamageInfo const&)+125 mov edx, [ecx+4444] - // CCSPlayer::OnTakeDamage_Alive(CTakeDamageInfo const&)+12B mov dword ptr [esp+4], offset aHitgroup ; "hitgroup" - g_iToolsLastHitGroup = 4444; - Handle hGameConf = LoadGameConfigFile("zombiereloaded"); if (hGameConf != INVALID_HANDLE) { - // Reserved + // If offset "m_LastHitGroup" can't be found, then stop the plugin. + g_iToolsLastHitGroup = GameConfGetOffset(hGameConf, "m_LastHitGroup"); + if (g_iToolsLastHitGroup == -1) + { + LogEvent(false, LogType_Fatal, LOG_CORE_EVENTS, LogModule_Tools, "Offsets", "Gamedata Offset \"CCSPlayer::m_LastHitGroup\" was not found."); + } CloseHandle(hGameConf); } else - LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Tools, "Offsets", "Couldn't load zombiereloaded game config!"); + LogEvent(false, LogType_Fatal, LOG_CORE_EVENTS, LogModule_Tools, "Offsets", "Couldn't load zombiereloaded game config!"); // Forward event to modules. WeaponsOnOffsetsFound(); diff --git a/src/zr/tools_functions.inc b/src/zr/tools_functions.inc index 73cfae2..634f178 100644 --- a/src/zr/tools_functions.inc +++ b/src/zr/tools_functions.inc @@ -268,10 +268,6 @@ stock int ToolsGetClientActiveWeapon(int client) */ stock int ToolsGetClientLastHitGroup(int client) { -/* WRONG OFFSET - if (g_iToolsLastHitGroup == -1) - g_iToolsLastHitGroup = FindDataMapInfo(client, "m_LastHitGroup"); -*/ return GetEntData(client, g_iToolsLastHitGroup, 4); } @@ -283,9 +279,5 @@ stock int ToolsGetClientLastHitGroup(int client) */ stock void ToolsSetClientLastHitGroup(int client, int hitgroup) { -/* WRONG OFFSET - if (g_iToolsLastHitGroup == -1) - g_iToolsLastHitGroup = FindDataMapInfo(client, "m_LastHitGroup"); -*/ SetEntData(client, g_iToolsLastHitGroup, hitgroup, 4); }