void getSamp () { if ( set.basic_mode ) return; uint32_t samp_dll = getSampAddress(); if ( samp_dll != NULL ) { g_dwSAMP_Addr = ( uint32_t ) samp_dll; if ( g_dwSAMP_Addr != NULL ) { if ( memcmp_safe((uint8_t *)g_dwSAMP_Addr + 0xBABE, hex_to_bin(SAMP_CMP_03DR1), 10) ) { strcpy(g_szSAMPVer, "SA:MP 0.3d"); Log( "%s was detected. g_dwSAMP_Addr: 0x%p", g_szSAMPVer, g_dwSAMP_Addr ); iIsSAMPSupported = 1; } else if ( memcmp_safe((uint8_t *)g_dwSAMP_Addr + 0xBABE, hex_to_bin(SAMP_CMP_03DR2), 10) ) { strcpy(g_szSAMPVer, "SA:MP 0.3d-R2"); Log( "%s was detected. g_dwSAMP_Addr: 0x%p", g_szSAMPVer, g_dwSAMP_Addr ); // (0.3d-R2 temp) disable AC if(memcmp_safe((uint32_t *)(g_dwSAMP_Addr + 0x8F210), "\xE9\x34\x91\x24\x00", 5)) memset_safe((uint32_t *)(g_dwSAMP_Addr + 0x8F210), 0xC3, 1); iIsSAMPSupported = 0; set.basic_mode = true; g_dwSAMP_Addr = NULL; } else { Log( "Unknown SA:MP version. Running in basic mode." ); iIsSAMPSupported = 0; set.basic_mode = true; g_dwSAMP_Addr = NULL; } } } else { iIsSAMPSupported = 0; set.basic_mode = true; Log( "samp.dll not found. Running in basic mode." ); } return; }
int patcher_install ( struct patch_set *patch ) { int i; /* previous initialization failed; always return error. */ if ( !patch->initialized && patch->failed ) return 0; if ( !patch->initialized ) { patch->failed = 1; for ( i = 0; i < PATCHER_CHUNKS_MAX; i++ ) { if ( patch->chunk[i].ptr == NULL ) break; if ( patch->chunk[i].data_cmp != NULL && !memcmp_safe((uint8_t *)patch->chunk[i].ptr, patch->chunk[i].data_cmp, patch->chunk[i].len) ) { void *mem = malloc( patch->chunk[i].len ); if ( mem != NULL ) { if ( memcpy_safe(mem, patch->chunk[i].ptr, patch->chunk[i].len) ) { } free( mem ); } return 0; } if ( patch->chunk[i].data_orig == NULL ) patch->chunk[i].data_orig = (uint8_t *)malloc( patch->chunk[i].len ); if ( patch->chunk[i].data_orig == NULL ) continue; if ( !memcpy_safe(patch->chunk[i].data_orig, patch->chunk[i].ptr, patch->chunk[i].len) ) { //Log( "Failed to copy original data for patch '%s' chunk %d @ 0x%p", patch->name, i, patch->chunk[i].ptr ); } } patch->initialized = 1; patch->failed = 0; //Log("Initialized patch '%s'.", patch->name); } if ( !patch->installed || patch->has_volatile ) { for ( i = 0; i < PATCHER_CHUNKS_MAX; i++ ) { if ( patch->chunk[i].ptr == NULL ) break; if ( patch->installed && !patch->chunk[i].is_volatile ) break; if ( patch->chunk[i].data_rep == NULL ) { if ( !memset_safe((uint8_t *)patch->chunk[i].ptr, 0x90, patch->chunk[i].len) ) {} //Log( "Failed to install patch '%s' chunk %d", patch->name, i ); } else { if ( !memcpy_safe((uint8_t *)patch->chunk[i].ptr, patch->chunk[i].data_rep, patch->chunk[i].len) ) {} //Log( "Failed to install patch '%s' chunk %d", patch->name, i ); } } if ( !patch->installed ) { patch->installed = 1; //Log("Installed patch '%s'.", patch->name); } } return 1; }