From a465569b227f03b04867620ffd2097beaefb4199 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Sat, 19 Apr 2008 03:40:30 +0000 Subject: [PATCH] Fixed amb1607 - TF2 extension critical hit crashes. --HG-- branch : sourcemod-1.0.x extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/branches/sourcemod-1.0.x%402082 --- extensions/tf2/criticals.cpp | 36 ++++- extensions/tf2/msvc9/tf2.sln | 20 +++ extensions/tf2/msvc9/tf2.vcproj | 264 ++++++++++++++++++++++++++++++++ gamedata/sm-tf2.games.txt | 6 + 4 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 extensions/tf2/msvc9/tf2.sln create mode 100644 extensions/tf2/msvc9/tf2.vcproj diff --git a/extensions/tf2/criticals.cpp b/extensions/tf2/criticals.cpp index e8086168..addad9ec 100644 --- a/extensions/tf2/criticals.cpp +++ b/extensions/tf2/criticals.cpp @@ -177,12 +177,46 @@ bool CriticalHitManager::CreateCriticalMeleeDetour() jit->write_ubyte(0x75); jit->write_ubyte(50-((jit->outptr+1)-jit->outbase)); + int callbyte = -1; + /* The callbyte should return the nth byte (starting from 1) in the backup bytes - Should be an 0xE8 (call) */ + g_pGameConf->GetOffset("CalcCriticalMeleeCallByte", &callbyte); + + callbyte--; + void *function = NULL; + + if (callbyte > -1) + { + /* Check if the 'callbyte' is actually a call */ + if (melee_restore.patch[callbyte] != 0xE8) + { + g_pSM->LogError(myself, "Invalid callbyte - Melee detour may work incorrectly"); + } + else + { + /* Find the absolute address of the function it calls */ + void *offsetaddr = (void *)((unsigned char *)melee_address + callbyte + 1); + int offset = (int)*(unsigned char *)offsetaddr; + function = (unsigned char *)offsetaddr + offset + 4; + } + } + /* Patch old bytes in */ for (size_t i=0; iwrite_ubyte(melee_restore.patch[i]); + if (i != callbyte) + { + jit->write_ubyte(melee_restore.patch[i]); + continue; + } + + /* Write in the adjusted call instead */ + jitoffs_t call = IA32_Call_Imm32(jit, 0); + IA32_Write_Jump32_Abs(jit, call, function); + + i += 4; } + /* Return to the original function */ call = IA32_Jump_Imm32(jit, 0); IA32_Write_Jump32_Abs(jit, call, (unsigned char *)melee_address + melee_restore.bytes); diff --git a/extensions/tf2/msvc9/tf2.sln b/extensions/tf2/msvc9/tf2.sln new file mode 100644 index 00000000..e49c809d --- /dev/null +++ b/extensions/tf2/msvc9/tf2.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tf2", "tf2.vcproj", "{B3E797CF-4E77-4C9D-B8A8-7589B6902206}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug - Orange Box|Win32 = Debug - Orange Box|Win32 + Release - Orange Box|Win32 = Release - Orange Box|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Debug - Orange Box|Win32.ActiveCfg = Debug - Orange Box|Win32 + {B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Debug - Orange Box|Win32.Build.0 = Debug - Orange Box|Win32 + {B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Release - Orange Box|Win32.ActiveCfg = Release - Orange Box|Win32 + {B3E797CF-4E77-4C9D-B8A8-7589B6902206}.Release - Orange Box|Win32.Build.0 = Release - Orange Box|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/extensions/tf2/msvc9/tf2.vcproj b/extensions/tf2/msvc9/tf2.vcproj new file mode 100644 index 00000000..96ba1de9 --- /dev/null +++ b/extensions/tf2/msvc9/tf2.vcproj @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gamedata/sm-tf2.games.txt b/gamedata/sm-tf2.games.txt index c78f2644..7d5833cb 100644 --- a/gamedata/sm-tf2.games.txt +++ b/gamedata/sm-tf2.games.txt @@ -65,6 +65,12 @@ "linux" "7" "windows" "9" } + /* The byte number (starting from 1) of the call (0xE8) byte or -1 if none */ + "CalcCriticalMeleeCallByte" + { + "linux" "-1" + "windows" "5" + } "CalcCriticalKnifeBackup" { "linux" "11"