3434#include " asm/asm.h"
3535#include " CDetour/detourhelpers.h"
3636
37- // TODO: Replace sig search to offsets, copy original by copy_bytes and restore when unpatch.
37+ #define OP_CALL 0xE8
38+ #define OP_CALL_SIZE 5
3839
39- unsigned char UpdateMarkersReached_orig[] = { 0xE8 , 0x35 , 0x69 , 0xBA , 0xFF , 0xC1 , 0xF8 , 0x02 };
40- unsigned char UpdateMarkersReached_patch[] = { 0x8B , 0x80 , 0x90 , 0x04 , 0x00 , 0x00 , 0x31 , 0xD2 , 0xB9 , TEAM_SIZE, 0x00 , 0x00 , 0x00 , 0xF7 , 0xF1 };
40+ # define OP_MOV 0xA1
41+ # define OP_MOV_SIZE 5
4142
42- unsigned char AddSurvivorStats_orig[] = { 0xE8 , 0xF1 , 0x9C , 0xB7 , 0xFF , 0xC1 , 0xF8 , 0x02 };
43- unsigned char AddSurvivorStats_patch[] = { 0x8B , 0x80 , 0x90 , 0x04 , 0x00 , 0x00 , 0x31 , 0xD2 , 0xB9 , TEAM_SIZE, 0x00 , 0x00 , 0x00 , 0xF7 , 0xF1 };
43+ // TODO: Create CUT/PASTE masks functions for wrap instructions inside my patch
4444
45- unsigned char GetVersusCompletion_orig [] = { 0x8B , 0xB8 , 0x90 , 0x04 , 0x00 , 0x00 , 0xC1 , 0xFF , 0x02 };
46- unsigned char GetVersusCompletion_patch [] = { 0x8B , 0x80 , 0x90 , 0x04 , 0x00 , 0x00 , 0x31 , 0xD2 , 0xBF , TEAM_SIZE, 0x00 , 0x00 , 0x00 , 0xF7 , 0xF7 , 0x89 , 0xC7 };
45+ unsigned char UpdateMarkersReached_orig [] = { 0xE8 , 0x2A , 0x2A , 0x2A , 0x2A , 0xF3 , 0x0F , 0x2A , 0x2A , 0x2A , 0xC1 , 0xF8 , 0x02 };
46+ unsigned char UpdateMarkersReached_patch [] = { 0x8B , 0x80 , 0xE8 , 0x0D , 0x00 , 0x00 , 0x31 , 0xD2 , 0xBB , TEAM_SIZE, 0x00 , 0x00 , 0x00 , 0xF7 , 0xF3 };
4747
48- #ifdef _DEBUG
48+ unsigned char AddSurvivorStats_orig[] = { 0xE8 , 0x2A , 0x2A , 0x2A , 0x2A , 0xC1 , 0xF8 , 0x02 };
49+ unsigned char AddSurvivorStats_patch[] = { 0x8B , 0x80 , 0xE8 , 0x0D , 0x00 , 0x00 , 0x31 , 0xD2 , 0xB9 , TEAM_SIZE, 0x00 , 0x00 , 0x00 , 0xF7 , 0xF1 };
50+
51+ unsigned char GetVersusCompletion_orig[] = { 0x8B , 0x55 , 0x2A , 0xA1 , 0x2A , 0x2A , 0x2A , 0x2A , 0x8B , 0xBA , 0xE8 , 0x0D , 0x00 , 0x00 , 0x89 , 0x2A , 0x2A , 0xC1 , 0xFF , 0x02 };
52+ unsigned char GetVersusCompletion_patch[] = { 0x8B , 0x45 , 0x08 , 0x8B , 0x80 , 0xE8 , 0x0D , 0x00 , 0x00 , 0x31 , 0xD2 , 0xBF , TEAM_SIZE, 0x00 , 0x00 , 0x00 , 0xF7 , 0xF7 , 0x89 , 0xC7 };
53+
54+ #ifdef DEBUG
4955void memDump (unsigned char *pAddr, size_t len) {
5056 g_pSmmAPI->ConPrintf (" Start dump at: %p\n " , pAddr);
5157 size_t llen = len;
@@ -69,24 +75,39 @@ void ScoreCode::Patch() {
6975
7076 ISourcePawnEngine *sengine = g_pSM->GetScriptingEngine ();
7177
78+ // prepare the trampoline
7279 m_injectMarker = (unsigned char *)sengine->AllocatePageMemory (sizeof (UpdateMarkersReached_patch) + OP_JMP_SIZE);
7380 copy_bytes (UpdateMarkersReached_patch, m_injectMarker, sizeof (UpdateMarkersReached_patch));
74- inject_jmp (m_injectMarker + sizeof (UpdateMarkersReached_patch), m_pMarkers + sizeof (UpdateMarkersReached_orig));
81+ inject_jmp (m_injectMarker + sizeof (UpdateMarkersReached_patch), m_pMarkers + OP_CALL_SIZE);
82+ // copy original code to our buffer
7583 SetMemPatchable (m_pMarkers, sizeof (UpdateMarkersReached_orig));
84+ copy_bytes (m_pMarkers, UpdateMarkersReached_orig, sizeof (UpdateMarkersReached_orig));
85+ // inject jmp to trampoline and nop some bytes after target instruction
7686 inject_jmp (m_pMarkers, m_injectMarker);
77- fill_nop (m_pMarkers + OP_JMP_SIZE, sizeof (UpdateMarkersReached_orig) - OP_JMP_SIZE );
87+ fill_nop (m_pMarkers + sizeof (UpdateMarkersReached_orig) - 3 , 3 );
7888
89+ // prepare the trampoline
7990 m_injectStats = (unsigned char *)sengine->AllocatePageMemory (sizeof (AddSurvivorStats_patch) + OP_JMP_SIZE);
8091 copy_bytes (AddSurvivorStats_patch, m_injectStats, sizeof (AddSurvivorStats_patch));
8192 inject_jmp (m_injectStats + sizeof (AddSurvivorStats_patch), m_pL4DStats + sizeof (AddSurvivorStats_orig));
93+ // copy original code to our buffer
8294 SetMemPatchable (m_pL4DStats, sizeof (AddSurvivorStats_orig));
95+ copy_bytes (m_pL4DStats, AddSurvivorStats_orig, sizeof (AddSurvivorStats_orig));
96+ // inject jmp to trampoline
8397 inject_jmp (m_pL4DStats, m_injectStats);
8498 fill_nop (m_pL4DStats + OP_JMP_SIZE, sizeof (AddSurvivorStats_orig) - OP_JMP_SIZE);
8599
100+ // prepare the trampoline
86101 m_injectCompl = (unsigned char *)sengine->AllocatePageMemory (sizeof (GetVersusCompletion_patch) + OP_JMP_SIZE);
87- copy_bytes (GetVersusCompletion_patch, m_injectCompl, sizeof (GetVersusCompletion_patch));
88- inject_jmp (m_injectCompl + sizeof (GetVersusCompletion_patch), m_pCompletion + sizeof (GetVersusCompletion_orig));
102+ unsigned char *pInjectEnd = m_injectCompl;
103+ copy_bytes (GetVersusCompletion_patch, m_injectCompl, sizeof (GetVersusCompletion_patch)); pInjectEnd += sizeof (GetVersusCompletion_patch);
104+ copy_bytes (m_pCompletion + 3 , pInjectEnd, OP_MOV_SIZE); pInjectEnd += OP_MOV_SIZE;
105+ copy_bytes (m_pCompletion + sizeof (GetVersusCompletion_orig) - 6 , pInjectEnd, 3 ); pInjectEnd += 3 ;
106+ inject_jmp (pInjectEnd, m_pCompletion + sizeof (GetVersusCompletion_orig));
107+ // copy original code to our buffer
89108 SetMemPatchable (m_pCompletion, sizeof (GetVersusCompletion_orig));
109+ copy_bytes (m_pCompletion, GetVersusCompletion_orig, sizeof (GetVersusCompletion_orig));
110+ // inject jmp to trampoline
90111 inject_jmp (m_pCompletion, m_injectCompl);
91112 fill_nop (m_pCompletion + OP_JMP_SIZE, sizeof (GetVersusCompletion_orig) - OP_JMP_SIZE);
92113
0 commit comments