diff --git a/extensions/tf2/criticals.cpp b/extensions/tf2/criticals.cpp index 3e94ba8c..c6ce26f8 100644 --- a/extensions/tf2/criticals.cpp +++ b/extensions/tf2/criticals.cpp @@ -165,13 +165,11 @@ bool CriticalHitManager::CreateCriticalMeleeDetour() //If TempDetour returns non-zero we want to load something into eax and return this value - //IA32_Test_Rm_Reg(jit, eax, eax, something); - jit->write_ubyte(0x85); - jit->write_ubyte(0xC0); + //test eax, eax + IA32_Test_Rm_Reg(jit, REG_EAX, REG_EAX, MOD_REG); - //JNZ critical_callback+50 - jit->write_ubyte(0x75); - jit->write_ubyte(50-((jit->outptr+1)-jit->outbase)); + //jnz _skip + jitoffs_t jmp = IA32_Jump_Cond_Imm8(jit, CC_NZ, 0); int callbyte = -1; /* The callbyte should return the nth byte (starting from 1) in the backup bytes - Should be an 0xE8 (call) */ @@ -212,18 +210,15 @@ bool CriticalHitManager::CreateCriticalMeleeDetour() 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); - wr.outbase = (jitcode_t)melee_callback+50; - wr.outptr = wr.outbase; - - //copy g_returnvalue into eax - jit->write_ubyte(0xA1); - jit->write_uint32((jit_uint32_t)&g_returnvalue); - + //_skip: + //mov eax, [g_returnvalue] + //ret + IA32_Send_Jump8_Here(jit, jmp); + IA32_Mov_Eax_Mem(jit, (jit_int32_t)&g_returnvalue); IA32_Return(jit); return true; @@ -280,13 +275,11 @@ bool CriticalHitManager::CreateCriticalKnifeDetour() //If TempDetour returns non-zero we want to load something into eax and return this value - //IA32_Test_Rm_Reg(jit, eax, eax, something); - jit->write_ubyte(0x85); - jit->write_ubyte(0xC0); + //test eax, eax + IA32_Test_Rm_Reg(jit, REG_EAX, REG_EAX, MOD_REG); - //JNZ critical_callback+50 - jit->write_ubyte(0x75); - jit->write_ubyte(50-((jit->outptr+1)-jit->outbase)); + //jnz _skip + jitoffs_t jmp = IA32_Jump_Cond_Imm8(jit, CC_NZ, 0); /* Patch old bytes in */ for (size_t i=0; iwrite_ubyte(0xA1); - jit->write_uint32((jit_uint32_t)&g_returnvalue); - + //_skip: + //mov eax, [g_returnvalue] + //ret + IA32_Send_Jump8_Here(jit, jmp); + IA32_Mov_Eax_Mem(jit, (jit_int32_t)&g_returnvalue); IA32_Return(jit); return true; diff --git a/gamedata/sm-tf2.games.txt b/gamedata/sm-tf2.games.txt index 42fd4a62..e690e164 100644 --- a/gamedata/sm-tf2.games.txt +++ b/gamedata/sm-tf2.games.txt @@ -32,13 +32,13 @@ { "library" "server" "linux" "@_ZN18CTFWeaponBaseMelee26CalcIsAttackCriticalHelperEv" - "windows" "\x83\xEC\x08\x56\xE8\x2A\x2A\x2A\x2A\x8B\xF0\x85\xF6" + "windows" "\x83\xEC\x08\x56\x57\x8B\xF1\xE8\x2A\x2A\x2A\x2A\x8B\xF8" } "CalcCriticalKnife" { "library" "server" "linux" "@_ZN8CTFKnife26CalcIsAttackCriticalHelperEv" - "windows" "\x33\xC0\x83\xB9\x74\x12\x00\x00\x01\x0F\x94\xC0\xC3" + "windows" "\x33\xC0\x83\xB9\xF4\x12\x00\x00\x01\x0F\x94\xC0\xC3" } } @@ -57,13 +57,13 @@ "CalcCriticalMeleeBackup" { "linux" "7" - "windows" "9" + "windows" "7" } /* The byte number (starting from 1) of the call (0xE8) byte or -1 if none */ "CalcCriticalMeleeCallByte" { "linux" "-1" - "windows" "5" + "windows" "-1" } "CalcCriticalKnifeBackup" {