Advertisement
Guest User

Untitled

a guest
Nov 17th, 2014
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.83 KB | None | 0 0
  1. /*
  2.  
  3. PROJECT: mod_sa
  4. LICENSE: See LICENSE in the top level directory
  5. COPYRIGHT: Copyright we_sux, FYP
  6.  
  7. mod_sa is available from http://code.google.com/p/m0d-s0beit-sa/
  8.  
  9. mod_sa is free software: you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation, either version 3 of the License, or
  12. (at your option) any later version.
  13.  
  14. mod_sa is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with mod_sa. If not, see <http://www.gnu.org/licenses/>.
  21.  
  22. */
  23. #include "main.h"
  24.  
  25. #define SAMP_DLL "samp.dll"
  26. #define SAMP_CMP "00E8000085D27408508B"
  27.  
  28. //randomStuff
  29. extern int iViewingInfoPlayer;
  30. int g_iSpectateEnabled = 0, g_iSpectateLock = 0, g_iSpectatePlayerID = -1;
  31. int g_iCursorEnabled = 0;
  32.  
  33. // global samp pointers
  34. int iIsSAMPSupported = 0;
  35. int g_renderSAMP_initSAMPstructs;
  36. stSAMP *g_SAMP = NULL;
  37. stPlayerPool *g_Players = NULL;
  38. stVehiclePool *g_Vehicles = NULL;
  39. stChatInfo *g_Chat = NULL;
  40. stInputInfo *g_Input = NULL;
  41. stKillInfo *g_DeathList = NULL;
  42.  
  43. // global managed support variables
  44. stTranslateGTASAMP_vehiclePool translateGTASAMP_vehiclePool;
  45. stTranslateGTASAMP_pedPool translateGTASAMP_pedPool;
  46.  
  47. stStreamedOutPlayerInfo g_stStreamedOutInfo;
  48.  
  49.  
  50.  
  51. //////////////////////////////////////////////////////////////////////////////////////
  52. ///////////////////////////////////// FUNCTIONS //////////////////////////////////////
  53. //////////////////////////////////////////////////////////////////////////////////////
  54.  
  55. // update SAMPGTA vehicle translation structure
  56. void update_translateGTASAMP_vehiclePool ( void )
  57. {
  58. traceLastFunc( "update_translateGTASAMP_vehiclePool()" );
  59. if ( !g_Vehicles )
  60. return;
  61.  
  62. int iGTAID;
  63. for ( int i = 0; i <= SAMP_VEHICLE_MAX; i++ )
  64. {
  65. if ( g_Vehicles->iIsListed[i] != 1 )
  66. continue;
  67. if ( isBadPtr_writeAny(g_Vehicles->pSAMP_Vehicle[i], sizeof(stSAMPVehicle)) )
  68. continue;
  69. iGTAID = getVehicleGTAIDFromInterface( (DWORD *)g_Vehicles->pSAMP_Vehicle[i]->pGTA_Vehicle );
  70. if ( iGTAID <= SAMP_VEHICLE_MAX && iGTAID >= 0 )
  71. {
  72. translateGTASAMP_vehiclePool.iSAMPID[iGTAID] = i;
  73. }
  74. }
  75. }
  76.  
  77. // update SAMPGTA ped translation structure
  78. void update_translateGTASAMP_pedPool ( void )
  79. {
  80. traceLastFunc( "update_translateGTASAMP_pedPool()" );
  81. if ( !g_Players )
  82. return;
  83.  
  84. int iGTAID, i;
  85. for ( i = 0; i < SAMP_PLAYER_MAX; i++ )
  86. {
  87. if ( i == g_Players->sLocalPlayerID )
  88. {
  89. translateGTASAMP_pedPool.iSAMPID[0] = i;
  90. continue;
  91. }
  92.  
  93. if ( isBadPtr_writeAny(g_Players->pRemotePlayer[i], sizeof(stRemotePlayer)) )
  94. continue;
  95. if ( isBadPtr_writeAny(g_Players->pRemotePlayer[i]->pPlayerData, sizeof(stRemotePlayerData)) )
  96. continue;
  97. if ( isBadPtr_writeAny(g_Players->pRemotePlayer[i]->pPlayerData->pSAMP_Actor, sizeof(stSAMPPed)) )
  98. continue;
  99.  
  100. iGTAID = getPedGTAIDFromInterface( (DWORD *)g_Players->pRemotePlayer[i]->pPlayerData->pSAMP_Actor->pGTA_Ped );
  101. if ( iGTAID <= SAMP_PLAYER_MAX && iGTAID >= 0 )
  102. {
  103. translateGTASAMP_pedPool.iSAMPID[iGTAID] = i;
  104. }
  105. }
  106. }
  107.  
  108. //ClientCommands
  109.  
  110. extern int joining_server;
  111. void cmd_change_server ( char *param ) //127.0.0.1 7777 Username Password
  112. {
  113. traceLastFunc( "cmd_change_server()" );
  114.  
  115. bool success = false;
  116.  
  117. char IP[128], Nick[MAX_PLAYER_NAME], Password[128] = "", Port[128];
  118. int iPort;
  119.  
  120. int ipc = sscanf( param, "%s%s%s%s", IP, Port, Nick, Password );
  121. if ( ipc < 2 )
  122. {
  123. addMessageToChatWindow( "USAGE: /m0d_change_server <ip> <port> <Username> <Server Password>" );
  124. addMessageToChatWindow( "Variables that are set to \"NULL\" (capitalized) will be ignored." );
  125. addMessageToChatWindow( "If you set the Password to \"NULL\" it is set to <no server password>." );
  126. addMessageToChatWindow( "Username and password can also be left out completely." );
  127. return;
  128. }
  129. if ( stricmp( IP, "NULL" ) == NULL )
  130. strcpy( IP, g_SAMP->szIP );
  131.  
  132. if ( stricmp( Port, "NULL" ) == NULL )
  133. iPort = g_SAMP->ulPort;
  134. else
  135. iPort = atoi( Port );
  136.  
  137. if ( ipc > 2 )
  138. {
  139. if ( stricmp( Nick, "NULL" ) != NULL )
  140. {
  141. if ( strlen( Nick ) > ALLOWED_PLAYER_NAME_LENGTH )
  142. Nick[ALLOWED_PLAYER_NAME_LENGTH] = '\0';
  143. setLocalPlayerName( Nick );
  144. }
  145. }
  146. if ( ipc > 3 )
  147. {
  148. if ( stricmp( Password, "NULL" ) == NULL )
  149. strcpy( Password, "" );
  150. }
  151.  
  152. changeServer( IP, iPort, Password );
  153. }
  154.  
  155. void cmd_change_server_fav ( char *param )
  156. {
  157. traceLastFunc( "cmd_change_server_fav()" );
  158.  
  159. if ( strlen(param) == 0 )
  160. {
  161. addMessageToChatWindow( "/m0d_fav_server <server name/part of server name>" );
  162. addMessageToChatWindow( "In order to see the favorite server list type: /m0d_fav_server list" );
  163. return;
  164. }
  165.  
  166. if ( strncmp(param, "list", 4) == 0 )
  167. {
  168. int count = 0;
  169. for ( int i = 0; i < INI_SERVERS_MAX; i++ )
  170. {
  171. if ( set.server[i].server_name == NULL )
  172. continue;
  173.  
  174. count++;
  175. addMessageToChatWindow( "%s", set.server[i].server_name );
  176. }
  177. if ( count == 0 )
  178. addMessageToChatWindow( "No servers in favorite server list. Edit the ini file to add some." );
  179. return;
  180. }
  181.  
  182. for ( int i = 0; i < INI_SERVERS_MAX; i++ )
  183. {
  184. if ( set.server[i].server_name == NULL || set.server[i].ip == NULL
  185. || strlen(set.server[i].ip) < 7 || set.server[i].port == 0 )
  186. continue;
  187.  
  188. if ( !findstrinstr((char *)set.server[i].server_name, param) )
  189. continue;
  190.  
  191. if ( !set.use_current_name )
  192. setLocalPlayerName( set.server[i].nickname );
  193.  
  194. changeServer( set.server[i].ip, set.server[i].port, set.server[i].password );
  195.  
  196. return;
  197. }
  198.  
  199. addMessageToChatWindow( "/m0d_fav_server <server name/part of server name>" );
  200. return;
  201. }
  202.  
  203. void cmd_current_server ( char *param )
  204. {
  205. addMessageToChatWindow( "Server Name: %s", g_SAMP->szHostname );
  206. addMessageToChatWindow( "Server Address: %s:%i", g_SAMP->szIP, g_SAMP->ulPort );
  207. addMessageToChatWindow( "Username: %s", getPlayerName(g_Players->sLocalPlayerID) );
  208. }
  209.  
  210. // strtokstristr?
  211. bool findstrinstr ( char *text, char *find )
  212. {
  213. char realtext[256];
  214. char subtext[256];
  215. char *result;
  216. char *next;
  217. char temp;
  218. int i = 0;
  219.  
  220. traceLastFunc( "findstrinstr()" );
  221.  
  222. // can't find stuff that isn't there unless you are high
  223. if ( text == NULL || find == NULL )
  224. return false;
  225.  
  226. // lower case text ( sizeof()-2 = 1 for array + 1 for termination after while() )
  227. while ( text[i] != NULL && i < (sizeof(realtext)-2) )
  228. {
  229. temp = text[i];
  230. if ( isupper(temp) )
  231. temp = tolower( temp );
  232. realtext[i] = temp;
  233. i++;
  234. }
  235. realtext[i] = 0;
  236.  
  237. // replace unwanted characters/spaces with dots
  238. i = 0;
  239. while ( find[i] != NULL && i < (sizeof(subtext)-2) )
  240. {
  241. temp = find[i];
  242. if ( isupper(temp) )
  243. temp = tolower( temp );
  244. if ( !isalpha(temp) )
  245. temp = '.';
  246. subtext[i] = temp;
  247. i++;
  248. }
  249. subtext[i] = 0;
  250.  
  251. // use i to count the successfully found text parts
  252. i = 0;
  253.  
  254. // split and find every part of subtext/find in text
  255. result = &subtext[0];
  256. while ( *result != NULL )
  257. {
  258. next = strstr( result, "." );
  259. if ( next != NULL )
  260. {
  261. // more than one non-alphabetic character
  262. if ( next == result )
  263. {
  264. do
  265. next++;
  266. while ( *next == '.' );
  267.  
  268. if ( *next == NULL )
  269. return (i != 0);
  270. result = next;
  271. next = strstr( result, "." );
  272. if ( next != NULL )
  273. *next = NULL;
  274. }
  275. else
  276. *next = NULL;
  277. }
  278.  
  279. if ( strstr(realtext, result) == NULL )
  280. return false;
  281.  
  282. if ( next == NULL )
  283. return true;
  284.  
  285. i++;
  286. result = next + 1;
  287. }
  288.  
  289. return false;
  290. }
  291.  
  292. void cmd_tele_loc ( char *param )
  293. {
  294. if ( strlen(param) == 0 )
  295. {
  296. addMessageToChatWindow( "USAGE: /m0d_tele_loc <location name>" );
  297. addMessageToChatWindow( "Use /m0d_tele_locations to show the location names." );
  298. addMessageToChatWindow( "The more specific you are on location name the better the result." );
  299. return;
  300. }
  301.  
  302. for ( int i = 0; i < STATIC_TELEPORT_MAX; i++ )
  303. {
  304. if ( strlen(set.static_teleport_name[i]) == 0 || vect3_near_zero(set.static_teleport[i].pos) )
  305. continue;
  306.  
  307. if ( !findstrinstr(set.static_teleport_name[i], param) )
  308. continue;
  309.  
  310. cheat_state_text( "Teleported to: %s.", set.static_teleport_name[i] );
  311. cheat_teleport( set.static_teleport[i].pos, set.static_teleport[i].interior_id );
  312. return;
  313. }
  314.  
  315. addMessageToChatWindow( "USAGE: /m0d_tele_loc <location name>" );
  316. addMessageToChatWindow( "Use /m0d_tele_locations to show the location names." );
  317. addMessageToChatWindow( "The more specific you are on location name the better the result." );
  318. }
  319.  
  320. void cmd_tele_locations ()
  321. {
  322. for ( int i = 0; i < STATIC_TELEPORT_MAX; i++ )
  323. {
  324. if ( strlen(set.static_teleport_name[i]) == 0 || vect3_near_zero(set.static_teleport[i].pos) )
  325. continue;
  326. addMessageToChatWindow( "%s", set.static_teleport_name[i] );
  327. }
  328.  
  329. addMessageToChatWindow( "To teleport use the menu or: /m0d_tele_loc <location name>" );
  330. }
  331.  
  332. void cmd_pickup ( char *params )
  333. {
  334. if ( !strlen( params ) )
  335. {
  336. addMessageToChatWindow( "USAGE: /m0d_pickup <pickup id>" );
  337. return;
  338. }
  339.  
  340. g_RakClient->SendPickUp( atoi( params ) );
  341. }
  342.  
  343. void cmd_setclass ( char *params )
  344. {
  345. if ( !strlen( params ) )
  346. {
  347. addMessageToChatWindow( "USAGE: /m0d_setclass <class id>" );
  348. return;
  349. }
  350.  
  351. g_RakClient->RequestClass( atoi( params ) );
  352. g_RakClient->SendSpawn();
  353. }
  354.  
  355. void cmd_fakekill ( char *params )
  356. {
  357. int killer, reason, amount;
  358. if ( !strlen( params ) || sscanf( params, "%d%d%d", &killer, &reason, &amount ) < 3 )
  359. {
  360. addMessageToChatWindow( "USAGE: /m0d_fakekill <killer id> <reason> <amount>" );
  361. return;
  362. }
  363. if ( amount < 1 || killer < 0 || killer > SAMP_PLAYER_MAX )
  364. return;
  365.  
  366. for ( int i = 0; i < amount; i++ )
  367. g_RakClient->SendDeath( killer, reason );
  368. }
  369.  
  370. // new functions to check for bad pointers
  371. int isBadPtr_SAMP_iVehicleID ( int iVehicleID )
  372. {
  373. if ( g_Vehicles == NULL || iVehicleID == (uint16_t)-1)
  374. return 1;
  375. return !g_Vehicles->iIsListed[iVehicleID];
  376.  
  377. // this hasn't been required yet
  378. //if (g_Vehicles->pSAMP_Vehicle[iVehicleID] == NULL) continue;
  379. }
  380.  
  381. int isBadPtr_SAMP_iPlayerID ( int iPlayerID )
  382. {
  383. if ( g_Players == NULL || iPlayerID < 0 || iPlayerID > SAMP_PLAYER_MAX)
  384. return 1;
  385. return !g_Players->iIsListed[iPlayerID];
  386. }
  387.  
  388. void getSamp ()
  389. {
  390. if ( set.basic_mode )
  391. return;
  392.  
  393. uint32_t samp_dll = getSampAddress();
  394.  
  395. if ( samp_dll != NULL )
  396. {
  397. g_dwSAMP_Addr = ( uint32_t ) samp_dll;
  398.  
  399. if ( g_dwSAMP_Addr != NULL )
  400. {
  401. if ( memcmp_safe((uint8_t *)g_dwSAMP_Addr + 0xBABE, hex_to_bin(SAMP_CMP), 10) )
  402. {
  403. strcpy(g_szSAMPVer, "SA:MP 0.3z");
  404. Log( "%s was detected. g_dwSAMP_Addr: 0x%p", g_szSAMPVer, g_dwSAMP_Addr );
  405.  
  406. // anticheat patch
  407. struct patch_set fuckAC =
  408. {
  409. "Anticheat patch", 0, 0,
  410. {
  411. { 1, (void *)( g_dwSAMP_Addr + 0x61430 ), NULL, (uint8_t *)"\xC3", 0 },
  412. { 1, (void *)( g_dwSAMP_Addr + 0x5B68B ), NULL, (uint8_t *)"\xEB", 0 },
  413. { 1, (void *)( g_dwSAMP_Addr + 0x71410 ), NULL, (uint8_t *)"\xEB", 0 }
  414. }
  415. };
  416. patcher_install( &fuckAC );
  417.  
  418. DWORD ACPatchOffsets[] =
  419. {
  420. 0x5B681, 0x219F66
  421. };
  422. DWORD ACPatchOffsets2[] =
  423. {
  424. 0x225798
  425. };
  426. static DWORD ACC[2] = { 0, 0 };
  427. DWORD *pACC[] = { &ACC[0], &ACC[2] };
  428. for ( int i = 0; i < _countof( ACPatchOffsets ); i++ )
  429. memcpy_safe( ( void * )( g_dwSAMP_Addr + ACPatchOffsets[i] ), &pACC[0], 4 );
  430. for ( int i = 0; i < _countof( ACPatchOffsets2 ); i++ )
  431. memcpy_safe( (void *)( g_dwSAMP_Addr + ACPatchOffsets2[i] ), &pACC[1], 4 );
  432.  
  433. iIsSAMPSupported = 1;
  434. }
  435. else
  436. {
  437. Log( "Unknown SA:MP version. Running in basic mode." );
  438. iIsSAMPSupported = 0;
  439. set.basic_mode = true;
  440.  
  441. g_dwSAMP_Addr = NULL;
  442. }
  443. }
  444. }
  445. else
  446. {
  447. iIsSAMPSupported = 0;
  448. set.basic_mode = true;
  449. Log( "samp.dll not found. Running in basic mode." );
  450. }
  451.  
  452. return;
  453. }
  454.  
  455. uint32_t getSampAddress ()
  456. {
  457. if ( set.run_mode == RUNMODE_SINGLEPLAYER )
  458. return 0x0;
  459.  
  460. uint32_t samp_dll;
  461.  
  462. if ( set.run_mode == RUNMODE_SAMP )
  463. {
  464. if ( set.wine_compatibility )
  465. {
  466. HMODULE temp = LoadLibrary( SAMP_DLL );
  467. __asm mov samp_dll, eax
  468. }
  469. else
  470. {
  471. void *temp = dll_baseptr_get( SAMP_DLL );
  472. __asm mov samp_dll, eax
  473. }
  474. }
  475.  
  476. if ( samp_dll == NULL )
  477. return 0x0;
  478.  
  479. return samp_dll;
  480. }
  481.  
  482. struct stSAMP *stGetSampInfo ( void )
  483. {
  484. if ( g_dwSAMP_Addr == NULL )
  485. return NULL;
  486.  
  487. uint32_t info_ptr;
  488. info_ptr = ( UINT_PTR ) * ( uint32_t * ) ( (uint8_t *) (void *)((uint8_t *)g_dwSAMP_Addr + SAMP_INFO_OFFSET) );
  489. if ( info_ptr == NULL )
  490. return NULL;
  491.  
  492. return (struct stSAMP *)info_ptr;
  493. }
  494.  
  495. struct stChatInfo *stGetSampChatInfo ( void )
  496. {
  497. if ( g_dwSAMP_Addr == NULL )
  498. return NULL;
  499.  
  500. uint32_t chat_ptr;
  501. chat_ptr = ( UINT_PTR ) * ( uint32_t * ) ( (uint8_t *) (void *)((uint8_t *)g_dwSAMP_Addr + SAMP_CHAT_INFO_OFFSET) );
  502. if ( chat_ptr == NULL )
  503. return NULL;
  504.  
  505. return (struct stChatInfo *)chat_ptr;
  506. }
  507.  
  508. struct stInputInfo *stGetInputInfo ( void )
  509. {
  510. if ( g_dwSAMP_Addr == NULL )
  511. return NULL;
  512.  
  513. uint32_t input_ptr;
  514. input_ptr = ( UINT_PTR ) * ( uint32_t * ) ( (uint8_t *) (void *)((uint8_t *)g_dwSAMP_Addr + SAMP_CHAT_INPUT_INFO_OFFSET) );
  515. if ( input_ptr == NULL )
  516. return NULL;
  517.  
  518. return (struct stInputInfo *)input_ptr;
  519. }
  520.  
  521. struct stKillInfo *stGetKillInfo ( void )
  522. {
  523. if ( g_dwSAMP_Addr == NULL )
  524. return NULL;
  525.  
  526. uint32_t kill_ptr;
  527. kill_ptr = ( UINT_PTR ) * ( uint32_t * ) ( (uint8_t *) (void *)((uint8_t *)g_dwSAMP_Addr + SAMP_KILL_INFO_OFFSET) );
  528. if ( kill_ptr == NULL )
  529. return NULL;
  530.  
  531. return (struct stKillInfo *)kill_ptr;
  532. }
  533.  
  534. D3DCOLOR samp_color_get ( int id, DWORD trans )
  535. {
  536. if ( g_dwSAMP_Addr == NULL )
  537. return NULL;
  538.  
  539. D3DCOLOR *color_table;
  540. if ( id < 0 || id >= (SAMP_PLAYER_MAX + 3) )
  541. return D3DCOLOR_ARGB( 0xFF, 0x99, 0x99, 0x99 );
  542.  
  543. switch ( id )
  544. {
  545. case ( SAMP_PLAYER_MAX ):
  546. return 0xFF888888;
  547.  
  548. case ( SAMP_PLAYER_MAX + 1 ):
  549. return 0xFF0000AA;
  550.  
  551. case ( SAMP_PLAYER_MAX + 2 ):
  552. return 0xFF63C0E2;
  553. }
  554.  
  555. color_table = ( D3DCOLOR * ) ( (uint8_t *)g_dwSAMP_Addr + SAMP_COLOR_OFFSET );
  556. return ( color_table[id] >> 8 ) | trans;
  557. }
  558.  
  559. void spectatePlayer(int iPlayerID)
  560. {
  561. if ( iPlayerID == -1 )
  562. {
  563. GTAfunc_TogglePlayerControllable(0);
  564. GTAfunc_LockActor(0);
  565. pGameInterface->GetCamera()->RestoreWithJumpCut();
  566.  
  567. g_iSpectateEnabled = 0;
  568. g_iSpectateLock = 0;
  569. g_iSpectatePlayerID = -1;
  570. return;
  571. }
  572.  
  573. g_iSpectatePlayerID = iPlayerID;
  574. g_iSpectateLock = 0;
  575. g_iSpectateEnabled = 1;
  576. }
  577.  
  578. void spectateHandle()
  579. {
  580. if(g_iSpectateEnabled)
  581. {
  582. if(g_iSpectateLock) return;
  583.  
  584. if(g_iSpectatePlayerID != -1)
  585. {
  586. if(g_Players->iIsListed[g_iSpectatePlayerID] != 0)
  587. {
  588. if(g_Players->pRemotePlayer[g_iSpectatePlayerID] != NULL)
  589. {
  590. int iState = getPlayerState(g_iSpectatePlayerID);
  591.  
  592. if(iState == PLAYER_STATE_ONFOOT)
  593. {
  594. struct actor_info *pPlayer = getGTAPedFromSAMPPlayerID(g_iSpectatePlayerID);
  595. if(pPlayer == NULL) return;
  596. GTAfunc_CameraOnActor(pPlayer);
  597. g_iSpectateLock = 1;
  598. }
  599. else if(iState == PLAYER_STATE_DRIVER)
  600. {
  601. struct vehicle_info *pPlayerVehicleID = g_Players->pRemotePlayer[g_iSpectatePlayerID]->pPlayerData->pSAMP_Vehicle->pGTA_Vehicle;
  602. if(pPlayerVehicleID == NULL) return;
  603. GTAfunc_CameraOnVehicle(pPlayerVehicleID);
  604. g_iSpectateLock = 1;
  605. }
  606. else if(iState == PLAYER_STATE_PASSENGER)
  607. {
  608. struct vehicle_info *pPlayerVehicleID = g_Players->pRemotePlayer[g_iSpectatePlayerID]->pPlayerData->pSAMP_Vehicle->pGTA_Vehicle;
  609. if(pPlayerVehicleID == NULL) return;
  610. GTAfunc_CameraOnVehicle(pPlayerVehicleID);
  611. g_iSpectateLock = 1;
  612. }
  613. }
  614. else
  615. {
  616. cheat_state_text("Player is not streamed in");
  617. g_iSpectateEnabled = 0;
  618. }
  619. }
  620. }
  621. }
  622. }
  623.  
  624. void sampMainCheat ()
  625. {
  626. traceLastFunc( "sampMainCheat()" );
  627. const int i = sizeof( stRemotePlayerData );
  628. // g_Vehicles & g_Players pointers need to be refreshed or nulled
  629. if ( isBadPtr_writeAny(g_SAMP->pPools, sizeof(stSAMPPools)) )
  630. {
  631. g_Vehicles = NULL;
  632. g_Players = NULL;
  633. }
  634. else if ( g_Vehicles != g_SAMP->pPools->pPool_Vehicle || g_Players != g_SAMP->pPools->pPool_Player )
  635. {
  636. if ( isBadPtr_writeAny(g_SAMP->pPools->pPool_Vehicle, sizeof(stVehiclePool)) )
  637. g_Vehicles = NULL;
  638. else
  639. g_Vehicles = g_SAMP->pPools->pPool_Vehicle;
  640. if ( isBadPtr_writeAny(g_SAMP->pPools->pPool_Player, sizeof(stPlayerPool)) )
  641. g_Players = NULL;
  642. else
  643. g_Players = g_SAMP->pPools->pPool_Player;
  644. }
  645.  
  646. // update GTA to SAMP translation structures
  647. update_translateGTASAMP_vehiclePool();
  648. update_translateGTASAMP_pedPool();
  649.  
  650. spectateHandle();
  651.  
  652. // start chatbox logging
  653. if ( set.chatbox_logging )
  654. {
  655. static int chatbox_init;
  656. if ( !chatbox_init )
  657. {
  658. SYSTEMTIME time;
  659. GetLocalTime( &time );
  660. LogChatbox( false, "Session started at %02d/%02d/%02d", time.wDay, time.wMonth, time.wYear );
  661. chatbox_init = 1;
  662. }
  663. }
  664.  
  665. if ( KEY_DOWN(set.secondary_key) )
  666. {
  667. if ( KEY_PRESSED(set.key_player_info_list) )
  668. cheat_state->player_info_list ^= 1;
  669.  
  670. if ( KEY_PRESSED(set.key_rejoin) )
  671. {
  672. restartGame();
  673. disconnect( 500 );
  674. cheat_state_text( "Rejoining in %d seconds...", set.rejoin_delay / 1000 );
  675. cheat_state->_generic.rejoinTick = GetTickCount();
  676. }
  677.  
  678. if ( KEY_PRESSED(set.key_respawn) )
  679. playerSpawn();
  680. }
  681.  
  682. if ( KEY_DOWN(set.chat_secondary_key) )
  683. {
  684. int i, key, spam;
  685. const char *msg;
  686. for ( i = 0; i < INI_CHATMSGS_MAX; i++ )
  687. {
  688. struct chat_msg *msg_item = &set.chat[i];
  689. if ( msg_item->key == NULL )
  690. continue;
  691. if ( msg_item->msg == NULL )
  692. continue;
  693. if ( msg_item->key != key_being_pressed )
  694. continue;
  695. key = msg_item->key;
  696. msg = msg_item->msg;
  697. spam = msg_item->spam;
  698. if ( spam )
  699. {
  700. if ( msg )
  701. if ( KEY_DOWN(key) )
  702. say( "%s", msg );
  703. }
  704. else
  705. {
  706. if ( msg )
  707. if ( KEY_PRESSED(key) )
  708. say( "%s", msg );
  709. }
  710. }
  711. }
  712.  
  713. static int iSAMPHooksInstalled;
  714. if ( !iSAMPHooksInstalled )
  715. {
  716. installSAMPHooks();
  717. iSAMPHooksInstalled = 1;
  718. }
  719.  
  720. if ( cheat_state->_generic.rejoinTick && cheat_state->_generic.rejoinTick < (GetTickCount() - set.rejoin_delay) )
  721. {
  722. g_SAMP->iGameState = GAMESTATE_WAIT_CONNECT;
  723. cheat_state->_generic.rejoinTick = 0;
  724. }
  725.  
  726. if ( joining_server == 1 )
  727. {
  728. restartGame();
  729. disconnect( 500 );
  730. cheat_state_text( "Joining server in %d seconds...", set.rejoin_delay / 1000 );
  731. cheat_state->_generic.join_serverTick = GetTickCount();
  732. joining_server = 2;
  733. }
  734.  
  735. if ( joining_server == 2
  736. && cheat_state->_generic.join_serverTick
  737. && cheat_state->_generic.join_serverTick < (GetTickCount() - set.rejoin_delay) )
  738. {
  739. g_SAMP->iGameState = GAMESTATE_WAIT_CONNECT;
  740. joining_server = 0;
  741. cheat_state->_generic.join_serverTick = 0;
  742. }
  743. }
  744.  
  745. int getNthPlayerID ( int n )
  746. {
  747. if ( g_Players == NULL )
  748. return -1;
  749.  
  750. int thisplayer = 0;
  751. for ( int i = 0; i < SAMP_PLAYER_MAX; i++ )
  752. {
  753. if ( g_Players->iIsListed[i] != 1 )
  754. continue;
  755. if ( g_Players->sLocalPlayerID == i )
  756. continue;
  757. if ( thisplayer < n )
  758. {
  759. thisplayer++;
  760. continue;
  761. }
  762.  
  763. return i;
  764. }
  765.  
  766. //shouldnt happen
  767. return -1;
  768. }
  769.  
  770. int getPlayerCount ( void )
  771. {
  772. if ( g_Players == NULL )
  773. return NULL;
  774.  
  775. int iCount = 0;
  776. int i;
  777.  
  778. for ( i = 0; i < SAMP_PLAYER_MAX; i++ )
  779. {
  780. if ( g_Players->iIsListed[i] != 1 )
  781. continue;
  782. iCount++;
  783. }
  784.  
  785. return iCount + 1;
  786. }
  787.  
  788. #define SAMP_FUNC_NAMECHANGE 0xA500
  789. int setLocalPlayerName ( const char *name )
  790. {
  791. if ( g_Players == NULL || g_Players->pLocalPlayer == NULL )
  792. return 0;
  793.  
  794. int strlen_name = strlen( name );
  795. if ( strlen_name == 0 || strlen_name > ALLOWED_PLAYER_NAME_LENGTH )
  796. return 0;
  797.  
  798. traceLastFunc( "setLocalPlayerName()" );
  799.  
  800. //strcpy(g_Players->szLocalPlayerName, name);
  801. //g_Players->iStrlen_LocalPlayerName = strlen_name;
  802.  
  803. DWORD vtbl_nameHandler = ((DWORD)&g_Players->pVTBL_txtHandler);
  804. DWORD func = g_dwSAMP_Addr + SAMP_FUNC_NAMECHANGE;
  805. __asm push strlen_name
  806. __asm push name
  807. __asm mov ecx, vtbl_nameHandler
  808. __asm call func
  809. return 1;
  810. }
  811.  
  812. int getVehicleCount ( void )
  813. {
  814. if ( g_Vehicles == NULL )
  815. return NULL;
  816.  
  817. int iCount = 0;
  818. int i;
  819.  
  820. for ( i = 0; i < SAMP_VEHICLE_MAX; i++ )
  821. {
  822. if ( g_Vehicles->iIsListed[i] != 1 )
  823. continue;
  824. iCount++;
  825. }
  826.  
  827. return iCount;
  828. }
  829.  
  830. int getPlayerPos ( int iPlayerID, float fPos[3] )
  831. {
  832. traceLastFunc( "getPlayerPos()" );
  833.  
  834. struct actor_info *pActor = NULL;
  835. struct vehicle_info *pVehicle = NULL;
  836.  
  837. struct actor_info *pSelfActor = actor_info_get( ACTOR_SELF, 0 );
  838.  
  839. if ( g_Players == NULL )
  840. return 0;
  841. if ( g_Players->iIsListed[iPlayerID] != 1 )
  842. return 0;
  843. if ( g_Players->pRemotePlayer[iPlayerID] == NULL )
  844. return 0;
  845. if ( g_Players->pRemotePlayer[iPlayerID]->pPlayerData == NULL )
  846. return 0;
  847.  
  848. if ( g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Actor == NULL )
  849. return 0; // not streamed
  850. else
  851. {
  852. pActor = g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Actor->pGTA_Ped;
  853.  
  854. if ( g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Vehicle != NULL )
  855. pVehicle = g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Vehicle->pGTA_Vehicle;
  856.  
  857. if ( pVehicle != NULL && pActor->vehicle == pVehicle && pVehicle->passengers[0] == pActor )
  858. {
  859. // driver of a vehicle
  860. vect3_copy( &pActor->vehicle->base.matrix[4 * 3], fPos );
  861.  
  862. //vect3_copy(g_Players->pRemotePlayer[iPlayerID]->fVehiclePosition, fPos);
  863. }
  864. else if ( pVehicle != NULL )
  865. {
  866. // passenger of a vehicle
  867. vect3_copy( &pActor->base.matrix[4 * 3], fPos );
  868.  
  869. //vect3_copy(g_Players->pRemotePlayer[iPlayerID]->fActorPosition, fPos);
  870. }
  871. else
  872. {
  873. // on foot
  874. vect3_copy( &pActor->base.matrix[4 * 3], fPos );
  875.  
  876. //vect3_copy(g_Players->pRemotePlayer[iPlayerID]->fActorPosition, fPos);
  877. }
  878. }
  879.  
  880. if ( pSelfActor != NULL )
  881. {
  882. if ( vect3_dist(&pSelfActor->base.matrix[4 * 3], fPos) < 100.0f )
  883. vect3_copy( &pActor->base.matrix[4 * 3], fPos );
  884. }
  885.  
  886. // detect zombies
  887. if ( vect3_near_zero(fPos) )
  888. vect3_copy( &pActor->base.matrix[4 * 3], fPos );
  889.  
  890. return !vect3_near_zero( fPos );
  891. }
  892.  
  893. const char *getPlayerName ( int iPlayerID )
  894. {
  895. if ( g_Players == NULL || iPlayerID < 0 || iPlayerID > SAMP_PLAYER_MAX )
  896. return NULL;
  897.  
  898. if ( iPlayerID == g_Players->sLocalPlayerID )
  899. {
  900. if ( g_Players->iStrlen_LocalPlayerName <= 0xF )
  901. return g_Players->szLocalPlayerName;
  902. return g_Players->pszLocalPlayerName;
  903. }
  904.  
  905. if ( g_Players->pRemotePlayer[iPlayerID] == NULL )
  906. return NULL;
  907.  
  908. if ( g_Players->pRemotePlayer[iPlayerID]->iStrlenName <= 0xF )
  909. return g_Players->pRemotePlayer[iPlayerID]->szPlayerName;
  910.  
  911. return g_Players->pRemotePlayer[iPlayerID]->pszPlayerName;
  912. }
  913.  
  914. int getPlayerState ( int iPlayerID )
  915. {
  916. if ( g_Players == NULL || iPlayerID < 0 || iPlayerID > SAMP_PLAYER_MAX )
  917. return NULL;
  918. if ( iPlayerID == g_Players->sLocalPlayerID )
  919. return NULL;
  920. if ( g_Players->iIsListed[iPlayerID] != 1 )
  921. return NULL;
  922. if ( g_Players->pRemotePlayer[iPlayerID]->pPlayerData == NULL )
  923. return NULL;
  924.  
  925. return g_Players->pRemotePlayer[iPlayerID]->pPlayerData->bytePlayerState;
  926. }
  927.  
  928. int getPlayerVehicleGTAScriptingID ( int iPlayerID )
  929. {
  930. if ( g_Players == NULL )
  931. return 0;
  932.  
  933. // fix to always return our own vehicle always if that's what's being asked for
  934. if ( iPlayerID == ACTOR_SELF )
  935. {
  936. if(g_Players->pLocalPlayer->sCurrentVehicleID == (uint16_t)-1) return 0;
  937.  
  938. stSAMPVehicle *sampveh = g_Vehicles->pSAMP_Vehicle[g_Players->pLocalPlayer->sCurrentVehicleID];
  939. if ( sampveh )
  940. {
  941. return ScriptCarId( sampveh->pGTA_Vehicle );
  942. //return (int)( ((DWORD) sampveh->pGTA_Vehicle) - (DWORD) pool_vehicle->start ) / 2584;
  943. }
  944. else
  945. return 0;
  946. }
  947.  
  948. // make sure remote player is legit
  949. if ( g_Players->pRemotePlayer[iPlayerID] == NULL || g_Players->pRemotePlayer[iPlayerID]->pPlayerData == NULL ||
  950. g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Vehicle == NULL ||
  951. g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Vehicle->pGTA_Vehicle == NULL)
  952. return 0;
  953.  
  954. // make sure samp knows the vehicle exists
  955. if ( g_Vehicles->pSAMP_Vehicle[g_Players->pRemotePlayer[iPlayerID]->pPlayerData->sVehicleID] == NULL )
  956. return 0;
  957.  
  958. // return the remote player's vehicle
  959. return ScriptCarId( g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Vehicle->pGTA_Vehicle );
  960. }
  961.  
  962. int getPlayerSAMPVehicleID(int iPlayerID)
  963. {
  964. if(g_Players == NULL && g_Vehicles == NULL) return 0;
  965. if(g_Players->pRemotePlayer[iPlayerID] == NULL) return 0;
  966. if(g_Vehicles->pSAMP_Vehicle[g_Players->pRemotePlayer[iPlayerID]->pPlayerData->sVehicleID] == NULL) return 0;
  967. return g_Players->pRemotePlayer[iPlayerID]->pPlayerData->sVehicleID;
  968. }
  969.  
  970. struct actor_info *getGTAPedFromSAMPPlayerID ( int iPlayerID )
  971. {
  972. if ( g_Players == NULL || iPlayerID < 0 || iPlayerID > SAMP_PLAYER_MAX )
  973. return NULL;
  974. if ( iPlayerID == g_Players->sLocalPlayerID )
  975. return actor_info_get( ACTOR_SELF, 0 );
  976. if ( g_Players->iIsListed[iPlayerID] != 1 )
  977. return NULL;
  978. if ( g_Players->pRemotePlayer[iPlayerID] == NULL )
  979. return NULL;
  980. if ( g_Players->pRemotePlayer[iPlayerID]->pPlayerData == NULL )
  981. return NULL;
  982. if ( g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Actor == NULL )
  983. return NULL;
  984. if ( g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Actor->pGTA_Ped == NULL )
  985. return NULL;
  986.  
  987. // return actor_info, null or otherwise
  988. return g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Actor->pGTA_Ped;
  989. }
  990.  
  991. struct vehicle_info *getGTAVehicleFromSAMPVehicleID ( int iVehicleID )
  992. {
  993. if ( g_Vehicles == NULL || iVehicleID < 0 || iVehicleID >= SAMP_VEHICLE_MAX )
  994. return NULL;
  995. if ( iVehicleID == g_Players->pLocalPlayer->sCurrentVehicleID )
  996. return vehicle_info_get( VEHICLE_SELF, 0 );
  997. if ( g_Vehicles->iIsListed[iVehicleID] != 1 )
  998. return NULL;
  999.  
  1000. // return vehicle_info, null or otherwise
  1001. return g_Vehicles->pGTA_Vehicle[iVehicleID];
  1002. }
  1003.  
  1004. int getSAMPPlayerIDFromGTAPed ( struct actor_info *pGTAPed )
  1005. {
  1006. if ( g_Players == NULL )
  1007. return 0;
  1008. if ( actor_info_get(ACTOR_SELF, 0) == pGTAPed )
  1009. return g_Players->sLocalPlayerID;
  1010.  
  1011. int i;
  1012. for ( i = 0; i < SAMP_PLAYER_MAX; i++ )
  1013. {
  1014. if ( g_Players->iIsListed[i] != 1 )
  1015. continue;
  1016. if ( g_Players->pRemotePlayer[i] == NULL )
  1017. continue;
  1018. if ( g_Players->pRemotePlayer[i]->pPlayerData == NULL )
  1019. continue;
  1020. if ( g_Players->pRemotePlayer[i]->pPlayerData->pSAMP_Actor == NULL )
  1021. continue;
  1022. if ( g_Players->pRemotePlayer[i]->pPlayerData->pSAMP_Actor->pGTA_Ped == NULL )
  1023. continue;
  1024. if ( g_Players->pRemotePlayer[i]->pPlayerData->pSAMP_Actor->pGTA_Ped == pGTAPed )
  1025. return i;
  1026. }
  1027.  
  1028. return ACTOR_SELF;
  1029. }
  1030.  
  1031. int getSAMPVehicleIDFromGTAVehicle ( struct vehicle_info *pVehicle )
  1032. {
  1033. if ( g_Vehicles == NULL )
  1034. return NULL;
  1035. if ( vehicle_info_get(VEHICLE_SELF, 0) == pVehicle && g_Players != NULL )
  1036. return g_Players->pLocalPlayer->sCurrentVehicleID;
  1037.  
  1038. int i, iReturn = 0;
  1039. for ( i = 0; i < SAMP_VEHICLE_MAX; i++ )
  1040. {
  1041. if ( g_Vehicles->iIsListed[i] != 1 )
  1042. continue;
  1043. if ( g_Vehicles->pGTA_Vehicle[i] == pVehicle )
  1044. return i;
  1045. }
  1046.  
  1047. return VEHICLE_SELF;
  1048. }
  1049.  
  1050. uint32_t getPedGTAScriptingIDFromPlayerID ( int iPlayerID )
  1051. {
  1052. if ( g_Players == NULL )
  1053. return NULL;
  1054.  
  1055. if ( g_Players->iIsListed[iPlayerID] != 1 )
  1056. return NULL;
  1057. if ( g_Players->pRemotePlayer[iPlayerID] == NULL )
  1058. return NULL;
  1059. if ( g_Players->pRemotePlayer[iPlayerID]->pPlayerData == NULL )
  1060. return NULL;
  1061. if ( g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Actor == NULL )
  1062. return NULL;
  1063.  
  1064. return g_Players->pRemotePlayer[iPlayerID]->pPlayerData->pSAMP_Actor->ulGTA_Ped_ID;
  1065. }
  1066.  
  1067. uint32_t getVehicleGTAScriptingIDFromVehicleID ( int iVehicleID )
  1068. {
  1069. if ( g_Vehicles == NULL )
  1070. return NULL;
  1071.  
  1072. if ( g_Vehicles->iIsListed[iVehicleID] != 1 )
  1073. return NULL;
  1074. if ( g_Vehicles->pSAMP_Vehicle[iVehicleID] == NULL )
  1075. return NULL;
  1076.  
  1077. return g_Vehicles->pSAMP_Vehicle[iVehicleID]->ulGTA_Vehicle_ID;
  1078. }
  1079.  
  1080. struct m0dClientCMD
  1081. {
  1082. #pragma pack( 1 )
  1083. char cmd_name[30];
  1084.  
  1085. //char cmd_description[128];
  1086. } m0d_cmd_list[( MAX_CLIENTCMDS - 22 )];
  1087. int m0d_cmd_num = 0;
  1088.  
  1089. void cmd_showCMDS ()
  1090. {
  1091. int i = 0;
  1092. for ( ; i < m0d_cmd_num; i++ )
  1093. {
  1094. addMessageToChatWindow( "%s", m0d_cmd_list[i].cmd_name );
  1095. }
  1096. }
  1097.  
  1098. #define FUNC_ADDCLIENTCMD 0x7BC40
  1099. void addClientCommand ( char *name, int function )
  1100. {
  1101. if ( name == NULL || function == NULL || g_Input == NULL )
  1102. return;
  1103.  
  1104. if ( g_Input->iCMDCount == (MAX_CLIENTCMDS-1) )
  1105. {
  1106. Log( "Error: couldn't initialize '%s'. Maximum command amount reached.", name );
  1107. return;
  1108. }
  1109.  
  1110. if ( strlen(name) > 30 )
  1111. {
  1112. Log( "Error: command name '%s' was too long.", name );
  1113. return;
  1114. }
  1115.  
  1116. if ( m0d_cmd_num < (MAX_CLIENTCMDS - 22) )
  1117. {
  1118. strncpy_s( m0d_cmd_list[m0d_cmd_num].cmd_name, name, sizeof(m0d_cmd_list[m0d_cmd_num].cmd_name)-1 );
  1119. m0d_cmd_num++;
  1120. }
  1121. else
  1122. Log( "m0d_cmd_list[] too short." );
  1123.  
  1124. uint32_t data = g_dwSAMP_Addr + SAMP_CHAT_INPUT_INFO_OFFSET;
  1125. uint32_t func = g_dwSAMP_Addr + FUNC_ADDCLIENTCMD;
  1126. __asm mov eax, data
  1127. __asm mov ecx, [eax]
  1128. __asm push function
  1129. __asm push name
  1130. __asm call func
  1131. }
  1132.  
  1133. bool modcommands = false;
  1134. bool get_isModCommandsActive ()
  1135. {
  1136. return modcommands;
  1137. }
  1138.  
  1139. void init_samp_chat_cmds ()
  1140. {
  1141. if ( modcommands == true )
  1142. {
  1143. return;
  1144. }
  1145. else
  1146. {
  1147. cheat_state_text( "initiated modcommands" );
  1148. modcommands = true;
  1149. }
  1150.  
  1151. addClientCommand( "m0d_show_cmds", (int)cmd_showCMDS );
  1152. addClientCommand( "m0d_change_server", (int)cmd_change_server );
  1153. addClientCommand( "m0d_fav_server", (int)cmd_change_server_fav );
  1154. addClientCommand( "m0d_current_server", (int)cmd_current_server );
  1155. addClientCommand( "m0d_tele_loc", (int)cmd_tele_loc );
  1156. addClientCommand( "m0d_teleport_location", (int)cmd_tele_loc );
  1157. addClientCommand( "m0d_tele_locations", (int)cmd_tele_locations );
  1158. addClientCommand( "m0d_teleport_locations", (int)cmd_tele_locations );
  1159. addClientCommand( "m0d_pickup", (int)cmd_pickup );
  1160. addClientCommand( "m0d_setclass", (int)cmd_setclass );
  1161. addClientCommand( "m0d_fakekill", (int)cmd_fakekill );
  1162. }
  1163.  
  1164. struct gui *gui_samp_cheat_state_text = &set.guiset[1];
  1165. void addMessageToChatWindow ( const char *text, ... )
  1166. {
  1167. if ( g_SAMP != NULL )
  1168. {
  1169. va_list ap;
  1170. if ( text == NULL )
  1171. return;
  1172.  
  1173. char tmp[512];
  1174. memset( tmp, 0, 512 );
  1175.  
  1176. va_start( ap, text );
  1177. vsnprintf( tmp, sizeof(tmp)-1, text, ap );
  1178. va_end( ap );
  1179.  
  1180. addToChatWindow( tmp, D3DCOLOR_XRGB(gui_samp_cheat_state_text->red, gui_samp_cheat_state_text->green,
  1181. gui_samp_cheat_state_text->blue) );
  1182. }
  1183. else
  1184. {
  1185. va_list ap;
  1186. if ( text == NULL )
  1187. return;
  1188.  
  1189. char tmp[512];
  1190. memset( tmp, 0, 512 );
  1191.  
  1192. va_start( ap, text );
  1193. vsnprintf( tmp, sizeof(tmp)-1, text, ap );
  1194. va_end( ap );
  1195.  
  1196. cheat_state_text( tmp, D3DCOLOR_ARGB(255, 0, 200, 200) );
  1197. }
  1198. }
  1199.  
  1200. void addMessageToChatWindowSS ( const char *text, ... )
  1201. {
  1202. if ( g_SAMP != NULL )
  1203. {
  1204. va_list ap;
  1205. if ( text == NULL )
  1206. return;
  1207.  
  1208. char tmp[512];
  1209. memset( tmp, 0, 512 );
  1210.  
  1211. va_start( ap, text );
  1212. vsprintf( tmp, text, ap );
  1213. va_end( ap );
  1214.  
  1215. addMessageToChatWindow( tmp, D3DCOLOR_ARGB(255, 0, 200, 200) );
  1216. }
  1217. else
  1218. {
  1219. va_list ap;
  1220. if ( text == NULL )
  1221. return;
  1222.  
  1223. char tmp[512];
  1224. memset( tmp, 0, 512 );
  1225.  
  1226. va_start( ap, text );
  1227. vsprintf( tmp, text, ap );
  1228. va_end( ap );
  1229.  
  1230. cheat_state_text( tmp, D3DCOLOR_ARGB(255, 0, 200, 200) );
  1231. }
  1232. }
  1233.  
  1234. #define FUNC_ADDTOCHATWND 0x7A4F0
  1235. void addToChatWindow ( char *text, D3DCOLOR textColor, int playerID )
  1236. {
  1237. if ( g_SAMP == NULL || g_Chat == NULL )
  1238. return;
  1239.  
  1240. if ( text == NULL )
  1241. return;
  1242.  
  1243. if ( playerID < -1 )
  1244. playerID = -1;
  1245.  
  1246. uint32_t chatinfo = g_dwSAMP_Addr + SAMP_CHAT_INFO_OFFSET;
  1247. uint32_t func = g_dwSAMP_Addr + FUNC_ADDTOCHATWND;
  1248.  
  1249. if ( playerID != -1 )
  1250. {
  1251. // getPlayerName does the needed validity checks, no need for doubles
  1252. char *playerName = (char*)getPlayerName(playerID);
  1253. if ( playerName == NULL )
  1254. return;
  1255.  
  1256. D3DCOLOR playerColor = samp_color_get(playerID);
  1257.  
  1258. __asm mov eax, dword ptr[chatinfo]
  1259. __asm mov ecx, dword ptr[eax]
  1260. __asm push playerColor
  1261. __asm push textColor
  1262. __asm push playerName
  1263. __asm push text
  1264. __asm push 2
  1265. __asm call func
  1266. return;
  1267. }
  1268.  
  1269. __asm mov eax, dword ptr[chatinfo]
  1270. __asm mov ecx, dword ptr[eax]
  1271. __asm push 0
  1272. __asm push textColor
  1273. __asm push 0
  1274. __asm push text
  1275. __asm push 8
  1276. __asm call func
  1277. return;
  1278. }
  1279.  
  1280. #define FUNC_RESTARTGAME 0x9280
  1281. void restartGame ()
  1282. {
  1283. if ( g_SAMP == NULL )
  1284. return;
  1285.  
  1286. uint32_t samp_info = g_dwSAMP_Addr + SAMP_INFO_OFFSET;
  1287. uint32_t func = g_dwSAMP_Addr + FUNC_RESTARTGAME;
  1288. __asm mov eax, dword ptr[samp_info]
  1289. __asm mov ecx, dword ptr[eax]
  1290. __asm call func
  1291. __asm pop eax
  1292. __asm pop ecx
  1293. }
  1294.  
  1295. void say ( char *text, ... )
  1296. {
  1297. if ( g_SAMP == NULL )
  1298. return;
  1299.  
  1300. if ( text == NULL )
  1301. return;
  1302. if ( isBadPtr_readAny(text, 128) )
  1303. return;
  1304. traceLastFunc( "say()" );
  1305.  
  1306. va_list ap;
  1307. char tmp[128];
  1308. memset( tmp, 0, 128 );
  1309.  
  1310. va_start( ap, text );
  1311. vsprintf( tmp, text, ap );
  1312. va_end( ap );
  1313.  
  1314. addSayToChatWindow( tmp );
  1315. }
  1316.  
  1317. #define FUNC_SAY 0x4CA0
  1318. #define FUNC_SENDCMD 0x7BDD0
  1319. void addSayToChatWindow ( char *msg )
  1320. {
  1321. if ( g_SAMP == NULL )
  1322. return;
  1323.  
  1324. if ( msg == NULL )
  1325. return;
  1326. if ( isBadPtr_readAny(msg, 128) )
  1327. return;
  1328. traceLastFunc( "addSayToChatWindow()" );
  1329.  
  1330. if ( msg[0] == '/' )
  1331. {
  1332. uint32_t func = g_dwSAMP_Addr + FUNC_SENDCMD;
  1333. __asm push msg
  1334. __asm call func
  1335. }
  1336. else
  1337. {
  1338. uint32_t func = g_dwSAMP_Addr + FUNC_SAY;
  1339. void *lpPtr = g_Players->pLocalPlayer;
  1340. __asm mov ebx, dword ptr[lpPtr]
  1341. __asm push msg
  1342. __asm call func
  1343. __asm pop ebx
  1344. }
  1345. }
  1346.  
  1347. #define FUNC_GAMETEXT 0x643B0
  1348. void showGameText ( char *text, int time, int textsize )
  1349. {
  1350. if ( g_SAMP == NULL )
  1351. return;
  1352.  
  1353. uint32_t func = g_dwSAMP_Addr + FUNC_GAMETEXT;
  1354. __asm push textsize
  1355. __asm push time
  1356. __asm push text
  1357. __asm call func
  1358. }
  1359.  
  1360. #define FUNC_SPAWN 0x36D0
  1361. #define FUNC_REQUEST_SPAWN 0x3620
  1362. void playerSpawn ( void )
  1363. {
  1364. if ( g_SAMP == NULL )
  1365. return;
  1366.  
  1367. uint32_t func_request = g_dwSAMP_Addr + FUNC_REQUEST_SPAWN;
  1368. uint32_t func_spawn = g_dwSAMP_Addr + FUNC_SPAWN;
  1369. void *lpPtr = g_Players->pLocalPlayer;
  1370.  
  1371. __asm mov ecx, dword ptr[lpPtr]
  1372. __asm push ecx
  1373. __asm call func_request
  1374. __asm pop ecx
  1375.  
  1376. __asm mov ecx, dword ptr[lpPtr]
  1377. __asm push ecx
  1378. __asm call func_spawn
  1379. __asm pop ecx
  1380. }
  1381.  
  1382. void disconnect ( int reason /*0=timeout, 500=quit*/ )
  1383. {
  1384. if ( g_SAMP == NULL )
  1385. return;
  1386.  
  1387. g_RakClient->GetRakClientInterface()->Disconnect( reason );
  1388. }
  1389.  
  1390. void setPassword ( char *password )
  1391. {
  1392. if ( g_SAMP == NULL )
  1393. return;
  1394.  
  1395. g_RakClient->GetRakClientInterface()->SetPassword( password );
  1396. }
  1397.  
  1398. #define FUNC_SENDINTERIOR 0x4BF0
  1399. void sendSetInterior ( uint8_t interiorID )
  1400. {
  1401. if ( g_SAMP == NULL )
  1402. return;
  1403.  
  1404. uint32_t func = g_dwSAMP_Addr + FUNC_SENDINTERIOR;
  1405. void *lpPtr = g_Players->pLocalPlayer;
  1406. __asm mov ecx, dword ptr[interiorID]
  1407. __asm push ecx
  1408. __asm mov ecx, dword ptr[lpPtr]
  1409. __asm call func
  1410. __asm pop ecx
  1411. }
  1412.  
  1413. #define FUNC_SETSPECIALACTION 0x2C70
  1414. void setSpecialAction ( uint8_t byteSpecialAction )
  1415. {
  1416. if ( g_SAMP == NULL )
  1417. return;
  1418.  
  1419. if ( g_Players->pLocalPlayer == NULL )
  1420. return;
  1421.  
  1422. g_Players->pLocalPlayer->onFootData.byteSpecialAction = byteSpecialAction;
  1423.  
  1424. uint32_t func = g_dwSAMP_Addr + FUNC_SETSPECIALACTION;
  1425. void *lpPtr = g_Players->pLocalPlayer;
  1426. __asm mov ecx, dword ptr[byteSpecialAction]
  1427. __asm push ecx
  1428. __asm mov ecx, dword ptr[lpPtr]
  1429. __asm call func
  1430. __asm pop ecx
  1431. }
  1432.  
  1433. void sendSCMEvent ( int iEvent, int iVehicleID, int iParam1, int iParam2 )
  1434. {
  1435. g_RakClient->SendSCMEvent( iVehicleID, iEvent, iParam1, iParam2 );
  1436. }
  1437.  
  1438. /*
  1439. // this doesn't work when wrapped around the toggle below, samp sux
  1440. CMatrix toggleSAMPCursor_Camera = CMatrix();
  1441. void _cdecl toggleSAMPCursor_SaveCamera ( void )
  1442. {
  1443. pGame->GetCamera()->GetMatrix(&toggleSAMPCursor_Camera);
  1444. }
  1445.  
  1446. void _cdecl toggleSAMPCursor_RestoreCamera ( void )
  1447. {
  1448. pGame->GetCamera()->SetMatrix(&toggleSAMPCursor_Camera);
  1449. }
  1450. */
  1451.  
  1452. #define FUNC_TOGGLECURSOR 0x63E20
  1453. #define FUNC_CURSORUNLOCKACTORCAM 0x63D00
  1454. void toggleSAMPCursor(int iToggle)
  1455. {
  1456. if(g_Input->iInputEnabled) return;
  1457.  
  1458. uint32_t func = g_dwSAMP_Addr + FUNC_TOGGLECURSOR;
  1459. uint32_t obj = * ( DWORD * ) ( g_dwSAMP_Addr + SAMP_MISC_INFO );
  1460.  
  1461. if(iToggle)
  1462. {
  1463. _asm
  1464. {
  1465. //call toggleSAMPCursor_SaveCamera;
  1466. mov ecx, obj;
  1467. push 0;
  1468. push 3;
  1469. call func;
  1470. //call toggleSAMPCursor_RestoreCamera;
  1471. }
  1472. g_iCursorEnabled = 1;
  1473. }
  1474. else
  1475. {
  1476. _asm
  1477. {
  1478. mov ecx, obj;
  1479. push 1;
  1480. push 0;
  1481. call func;
  1482. }
  1483. uint32_t funcunlock = g_dwSAMP_Addr + FUNC_CURSORUNLOCKACTORCAM;
  1484. _asm
  1485. {
  1486. mov ecx, obj;
  1487. call funcunlock;
  1488. }
  1489. g_iCursorEnabled = 0;
  1490. }
  1491. }
  1492.  
  1493. #define HOOK_EXIT_ANTICARJACKED_HOOK 0x1131C
  1494. uint16_t anticarjacked_vehid;
  1495. DWORD anticarjacked_ebx_backup;
  1496. DWORD anticarjacked_jmp;
  1497. uint8_t _declspec ( naked ) carjacked_hook ( void )
  1498. {
  1499. __asm mov anticarjacked_ebx_backup, ebx
  1500. __asm mov ebx, [ebx + 7]
  1501. __asm mov anticarjacked_vehid, bx
  1502. __asm pushad
  1503. cheat_state->_generic.anti_carjackTick = GetTickCount();
  1504. cheat_state->_generic.car_jacked = true;
  1505.  
  1506. if ( g_Vehicles != NULL && g_Vehicles->pGTA_Vehicle[anticarjacked_vehid] != NULL )
  1507. vect3_copy( &g_Vehicles->pGTA_Vehicle[anticarjacked_vehid]->base.matrix[4 * 3],
  1508. cheat_state->_generic.car_jacked_lastPos );
  1509.  
  1510. __asm popad
  1511. __asm mov ebx, g_dwSAMP_Addr
  1512. __asm add ebx, HOOK_EXIT_ANTICARJACKED_HOOK
  1513. __asm mov anticarjacked_jmp, ebx
  1514. __asm xor ebx, ebx
  1515. __asm mov ebx, anticarjacked_ebx_backup
  1516. __asm jmp anticarjacked_jmp
  1517. }
  1518.  
  1519. #define HOOK_EXIT_SERVERMESSAGE_HOOK 0x7AAD1
  1520. int g_iNumPlayersMuted = 0;
  1521. bool g_bPlayerMuted[SAMP_PLAYER_MAX];
  1522. uint8_t _declspec ( naked ) server_message_hook ( void )
  1523. {
  1524. int thismsg;
  1525. DWORD thiscolor;
  1526.  
  1527. __asm mov thismsg, esi
  1528. __asm mov thiscolor, eax
  1529. thiscolor = ( thiscolor >> 8 ) | 0xFF000000;
  1530.  
  1531. static char last_servermsg[256];
  1532. static DWORD allow_show_again;
  1533. if ( !set.anti_spam || cheat_state->_generic.cheat_panic_enabled
  1534. || (strcmp(last_servermsg, (char *)thismsg) != NULL || GetTickCount() > allow_show_again) )
  1535. {
  1536. // might be a personal message by muted player - look for name in server message
  1537. // ignore message, if name was found
  1538. if ( set.anti_spam && g_iNumPlayersMuted > 0 )
  1539. {
  1540. int i, j;
  1541. char *playerName = NULL;
  1542. for ( i = 0, j = 0; i < SAMP_PLAYER_MAX && j < g_iNumPlayersMuted; i++ )
  1543. {
  1544. if ( g_bPlayerMuted[i] )
  1545. {
  1546. playerName = (char*)getPlayerName(i);
  1547.  
  1548. if ( playerName == NULL )
  1549. {
  1550. // Player not connected anymore - remove player from muted list
  1551. g_bPlayerMuted[i] = false;
  1552. g_iNumPlayersMuted--;
  1553. continue;
  1554. }
  1555. else if ( strstr((char*)thismsg, playerName) != NULL )
  1556. goto ignoreThisServChatMsg;
  1557. j++;
  1558. }
  1559. }
  1560. }
  1561. strncpy_s( last_servermsg, (char *)thismsg, sizeof(last_servermsg)-1 );
  1562. addToChatWindow( (char *)thismsg, thiscolor );
  1563. allow_show_again = GetTickCount() + 5000;
  1564.  
  1565. if( set.chatbox_logging )
  1566. LogChatbox( false, "%s", thismsg );
  1567. }
  1568.  
  1569. ignoreThisServChatMsg:
  1570. __asm mov ebx, g_dwSAMP_Addr
  1571. __asm add ebx, HOOK_EXIT_SERVERMESSAGE_HOOK
  1572. __asm jmp ebx
  1573. }
  1574.  
  1575. #define HOOK_EXIT_CLIENTMESSAGE_HOOK 0xDEC8
  1576. uint8_t _declspec ( naked ) client_message_hook ( void )
  1577. {
  1578. static char last_clientmsg[SAMP_PLAYER_MAX][256];
  1579. int thismsg;
  1580. uint16_t id;
  1581.  
  1582. __asm mov id, dx
  1583. __asm lea edx, [esp+0x128]
  1584. __asm mov thismsg, edx
  1585.  
  1586. if ( id >= 0 && id <= SAMP_PLAYER_MAX )
  1587. {
  1588. if( id == g_Players->sLocalPlayerID )
  1589. {
  1590. addToChatWindow( (char*)thismsg, g_Chat->clTextColor, id );
  1591.  
  1592. if( set.chatbox_logging )
  1593. LogChatbox( false, "%s: %s", getPlayerName(id), thismsg );
  1594. goto client_message_hook_jump_out;
  1595. }
  1596.  
  1597. static DWORD allow_show_again = GetTickCount();
  1598. if ( !set.anti_spam
  1599. || (strcmp(last_clientmsg[id], (char *)thismsg) != NULL || GetTickCount() > allow_show_again)
  1600. || cheat_state->_generic.cheat_panic_enabled )
  1601. {
  1602. // ignore chat from muted players
  1603. if ( set.anti_spam && g_iNumPlayersMuted > 0 && g_bPlayerMuted[id] )
  1604. goto client_message_hook_jump_out;
  1605.  
  1606. // nothing to copy anymore, after chatbox_logging, so copy this before
  1607. strncpy_s( last_clientmsg[id], (char *)thismsg, sizeof(last_clientmsg[id])-1 );
  1608.  
  1609. if( set.chatbox_logging )
  1610. LogChatbox( false, "%s: %s", getPlayerName(id), thismsg );
  1611.  
  1612. addToChatWindow( (char*)thismsg, g_Chat->clTextColor, id );
  1613. allow_show_again = GetTickCount() + 5000;
  1614. }
  1615. }
  1616.  
  1617. client_message_hook_jump_out:;
  1618. __asm mov ebx, g_dwSAMP_Addr
  1619. __asm add ebx, HOOK_EXIT_CLIENTMESSAGE_HOOK
  1620. __asm jmp ebx
  1621. }
  1622.  
  1623. #define HOOK_CALL_STREAMEDOUTINFO 0x64430
  1624. DWORD dwStreamedOutInfoOrigFunc;
  1625. float fStreamedOutInfoPosX, fStreamedOutInfoPosY, fStreamedOutInfoPosZ;
  1626. uint16_t wStreamedOutInfoPlayerID;
  1627. uint8_t _declspec ( naked ) StreamedOutInfo ( void )
  1628. {
  1629. _asm
  1630. {
  1631. push eax
  1632. mov eax, dword ptr [esp+12]
  1633. mov fStreamedOutInfoPosX, eax
  1634. mov eax, dword ptr [esp+16]
  1635. mov fStreamedOutInfoPosY, eax
  1636. mov eax, dword ptr [esp+20]
  1637. mov fStreamedOutInfoPosZ, eax
  1638. mov ax, word ptr [esp+24]
  1639. mov wStreamedOutInfoPlayerID, ax
  1640. pop eax
  1641. }
  1642.  
  1643. _asm pushad
  1644. g_stStreamedOutInfo.iPlayerID[wStreamedOutInfoPlayerID] = (int)wStreamedOutInfoPlayerID;
  1645. g_stStreamedOutInfo.fPlayerPos[wStreamedOutInfoPlayerID][0] = fStreamedOutInfoPosX;
  1646. g_stStreamedOutInfo.fPlayerPos[wStreamedOutInfoPlayerID][1] = fStreamedOutInfoPosY;
  1647. g_stStreamedOutInfo.fPlayerPos[wStreamedOutInfoPlayerID][2] = fStreamedOutInfoPosZ;
  1648. _asm popad
  1649.  
  1650. _asm
  1651. {
  1652. push eax
  1653. mov eax, g_dwSAMP_Addr
  1654. add eax, HOOK_CALL_STREAMEDOUTINFO
  1655. mov dwStreamedOutInfoOrigFunc, eax
  1656. pop eax
  1657.  
  1658. jmp dwStreamedOutInfoOrigFunc
  1659. }
  1660. }
  1661.  
  1662. void HandleRPCPacketFunc( unsigned char byteRPCID, RPCParameters *rpcParams, void ( *functionPointer ) ( RPCParameters * ) )
  1663. {
  1664. // use this if you wanna log received RPCs (can help you with finding samp RPC-patches)
  1665. /*if ( byteRPCId != RPC_UpdateScoresPingsIPs )
  1666. {
  1667. int len = rpcParams ? rpcParams->numberOfBitsOfData / 8 : 0;
  1668. Log( "> [RPC Recv] id: %d, func offset: %p, len: %d", byteRPCId, (DWORD)functionPointer - g_dwSAMP_Addr, len );
  1669. }*/
  1670.  
  1671. if ( set.enable_extra_godmode && cheat_state->_generic.hp_cheat && rpcParams )
  1672. {
  1673. if ( byteRPCID == RPC_ScrSetPlayerHealth )
  1674. {
  1675. actor_info *self = actor_info_get( ACTOR_SELF, NULL );
  1676. if ( self )
  1677. {
  1678. BitStream bsData( rpcParams->input, rpcParams->numberOfBitsOfData / 8, false );
  1679. float fHealth;
  1680. bsData.Read( fHealth );
  1681. if ( fHealth < self->hitpoints )
  1682. {
  1683. cheat_state_text( "Warning: Server tried change your health to %0.1f", fHealth );
  1684. return; // exit from the function without processing RPC
  1685. }
  1686. }
  1687. }
  1688. else if ( byteRPCID == RPC_ScrSetVehicleHealth )
  1689. {
  1690. vehicle_info *vself = vehicle_info_get( VEHICLE_SELF, NULL );
  1691. if ( vself )
  1692. {
  1693. BitStream bsData( rpcParams->input, rpcParams->numberOfBitsOfData / 8, false );
  1694. short sId;
  1695. float fHealth;
  1696. bsData.Read( sId );
  1697. bsData.Read( fHealth );
  1698. if ( sId == g_Players->pLocalPlayer->sCurrentVehicleID && fHealth < vself->hitpoints )
  1699. {
  1700. cheat_state_text( "Warning: Server tried change your vehicle health to %0.1f", fHealth );
  1701. return; // exit from the function without processing RPC
  1702. }
  1703. }
  1704. }
  1705. }
  1706.  
  1707. functionPointer( rpcParams );
  1708. }
  1709.  
  1710. #define SAMP_HOOKEXIT_HANDLE_RPC 0x35013
  1711. uint8_t _declspec ( naked ) hook_handle_rpc_packet ( void )
  1712. {
  1713. static DWORD dwTemp1, dwTemp2;
  1714. __asm pushad;
  1715. __asm mov dwTemp1, eax; // RPCParameters rpcParms
  1716. __asm mov dwTemp2, edi; // RPCNode *node
  1717.  
  1718. HandleRPCPacketFunc( *( unsigned char *)dwTemp2, (RPCParameters *)dwTemp1, *( void ( ** ) ( RPCParameters *rpcParams ) )( dwTemp2 + 1 ) );
  1719. dwTemp1 = g_dwSAMP_Addr + SAMP_HOOKEXIT_HANDLE_RPC;
  1720.  
  1721. __asm popad;
  1722. // execute overwritten code
  1723. __asm add esp, 4
  1724. // exit from the custom code
  1725. __asm jmp dwTemp1;
  1726. }
  1727.  
  1728. #define SAMP_HOOKEXIT_HANDLE_RPC2 0x35021
  1729. uint8_t _declspec ( naked ) hook_handle_rpc_packet2 ( void )
  1730. {
  1731. static DWORD dwTemp1, dwTemp2;
  1732. __asm pushad;
  1733. __asm mov dwTemp1, ecx; // RPCParameters rpcParms
  1734. __asm mov dwTemp2, edi; // RPCNode *node
  1735.  
  1736. HandleRPCPacketFunc( *( unsigned char *)dwTemp2, (RPCParameters *)dwTemp1, *( void ( ** ) ( RPCParameters *rpcParams ) )( dwTemp2 + 1 ) );
  1737. dwTemp1 = g_dwSAMP_Addr + SAMP_HOOKEXIT_HANDLE_RPC2;
  1738.  
  1739. __asm popad;
  1740. // exit from the custom code
  1741. __asm jmp dwTemp1;
  1742. }
  1743.  
  1744. #define FUNC_CNETGAMEDESTRUCTOR 0x85E0
  1745. void __stdcall CNetGame__destructor( void )
  1746. {
  1747. // release hooked rakclientinterface, restore original rakclientinterface address and call CNetGame destructor
  1748. if ( g_SAMP->pRakClientInterface != NULL )
  1749. delete g_SAMP->pRakClientInterface;
  1750. g_SAMP->pRakClientInterface = g_RakClient->GetRakClientInterface();
  1751. return ( ( void ( __thiscall * ) ( void * ) ) ( g_dwSAMP_Addr + FUNC_CNETGAMEDESTRUCTOR ) )( g_SAMP );
  1752. }
  1753.  
  1754. void SetupSAMPHook( char *szName, DWORD dwFuncOffset, void *Func, int iType, int iSize, char *szCompareBytes )
  1755. {
  1756. CDetour api;
  1757. int strl = strlen( szCompareBytes );
  1758. uint8_t *bytes = hex_to_bin( szCompareBytes );
  1759.  
  1760. if ( !strl || !bytes || memcmp_safe( (uint8_t *)g_dwSAMP_Addr + dwFuncOffset, bytes, strl / 2 ) )
  1761. {
  1762. if ( api.Create( (uint8_t *)( (uint32_t)g_dwSAMP_Addr ) + dwFuncOffset, (uint8_t *)Func, iType, iSize ) == 0 )
  1763. Log( "Failed to hook %s.", szName );
  1764. }
  1765. else
  1766. {
  1767. Log( "Failed to hook %s (memcmp)", szName );
  1768. }
  1769.  
  1770. if ( bytes )
  1771. free( bytes );
  1772. }
  1773.  
  1774. #define SAMP_HOOKPOS_ServerMessage 0x7AABA
  1775. #define SAMP_HOOKPOS_ClientMessage 0xDE6E
  1776. #define SAMP_HOOK_STATECHANGE 0x1130B
  1777. #define SAMP_HOOK_StreamedOutInfo 0xF82A
  1778. #define SAMP_HOOKENTER_HANDLE_RPC 0x3500D
  1779. #define SAMP_HOOKENTER_HANDLE_RPC2 0x34F99
  1780. #define SAMP_HOOKENTER_CNETGAME_DESTR 0xAD753
  1781. #define SAMP_HOOKENTER_CNETGAME_DESTR2 0xAE8E2
  1782. void installSAMPHooks ()
  1783. {
  1784. if( g_SAMP == NULL )
  1785. return;
  1786.  
  1787. if ( set.anti_spam || set.chatbox_logging )
  1788. {
  1789. SetupSAMPHook( "ServerMessage", SAMP_HOOKPOS_ServerMessage, server_message_hook, DETOUR_TYPE_JMP, 5, "6A00C1E808" );
  1790. SetupSAMPHook( "ClientMessage", SAMP_HOOKPOS_ClientMessage, client_message_hook, DETOUR_TYPE_JMP, 5, "663BD1752D" );
  1791. }
  1792.  
  1793. if ( set.anti_carjacking )
  1794. {
  1795. SetupSAMPHook( "AntiCarJack", SAMP_HOOK_STATECHANGE, carjacked_hook, DETOUR_TYPE_JMP, 5, "6A0568E8" );
  1796. }
  1797.  
  1798. SetupSAMPHook( "StreamedOutInfo", SAMP_HOOK_StreamedOutInfo, StreamedOutInfo, DETOUR_TYPE_CALL_FUNC, 5, "E8" );
  1799. SetupSAMPHook( "HandleRPCPacket", SAMP_HOOKENTER_HANDLE_RPC, hook_handle_rpc_packet, DETOUR_TYPE_JMP, 6, "FF5701" );
  1800. SetupSAMPHook( "HandleRPCPacket2", SAMP_HOOKENTER_HANDLE_RPC2, hook_handle_rpc_packet2, DETOUR_TYPE_JMP, 8, "FF5701" );
  1801. SetupSAMPHook( "CNETGAMEDESTR1", SAMP_HOOKENTER_CNETGAME_DESTR, CNetGame__destructor, DETOUR_TYPE_CALL_FUNC, 5, "E8" );
  1802. SetupSAMPHook( "CNETGAMEDESTR2", SAMP_HOOKENTER_CNETGAME_DESTR2, CNetGame__destructor, DETOUR_TYPE_CALL_FUNC, 5, "E8" );
  1803. }
  1804.  
  1805. #define SAMP_ONFOOTSENDRATE 0xE6098 // at 100035D7 MOV ECX,DWORD PTR DS:[100E6098]
  1806. #define SAMP_INCARSENDRATE 0xE609C
  1807. #define SAMP_AIMSENDRATE 0xE60A0
  1808. void setSAMPCustomSendRates ( int iOnFoot, int iInCar, int iAim, int iHeadSync )
  1809. {
  1810. if ( !set.samp_custom_sendrates_enable )
  1811. return;
  1812. if ( g_dwSAMP_Addr == NULL )
  1813. return;
  1814. if ( g_SAMP == NULL )
  1815. return;
  1816.  
  1817. memcpy_safe( (void *)(g_dwSAMP_Addr + SAMP_ONFOOTSENDRATE), &iOnFoot, sizeof(int) );
  1818. memcpy_safe( (void *)(g_dwSAMP_Addr + SAMP_INCARSENDRATE), &iInCar, sizeof(int) );
  1819. memcpy_safe( (void *)(g_dwSAMP_Addr + SAMP_AIMSENDRATE), &iAim, sizeof(int) );
  1820. }
  1821.  
  1822. #define SAMP_DISABLE_NAMETAGS 0x86770
  1823. #define SAMP_DISABLE_NAMETAGS_HP 0x85670
  1824. int sampPatchDisableNameTags ( int iEnabled )
  1825. {
  1826. static struct patch_set sampPatchEnableNameTags_patch =
  1827. {
  1828. "Remove player status",
  1829. 0,
  1830. 0,
  1831. {
  1832. { 1, (void *)( (uint8_t *)g_dwSAMP_Addr + SAMP_DISABLE_NAMETAGS ), NULL, (uint8_t *)"\xC3", NULL },
  1833. { 1, (void *)( (uint8_t *)g_dwSAMP_Addr + SAMP_DISABLE_NAMETAGS_HP ), NULL, (uint8_t *)"\xC3", NULL }
  1834. }
  1835. };
  1836. if ( iEnabled && !sampPatchEnableNameTags_patch.installed )
  1837. return patcher_install( &sampPatchEnableNameTags_patch );
  1838. else if ( !iEnabled && sampPatchEnableNameTags_patch.installed )
  1839. return patcher_remove( &sampPatchEnableNameTags_patch );
  1840. return NULL;
  1841. }
  1842.  
  1843. #define SAMP_SKIPSENDINTERIOR 0x6985
  1844. int sampPatchDisableInteriorUpdate ( int iEnabled )
  1845. {
  1846. static struct patch_set sampPatchDisableInteriorUpdate_patch =
  1847. {
  1848. "NOP sendinterior",
  1849. 0,
  1850. 0,
  1851. {
  1852. { 1, (void *)( (uint8_t *)g_dwSAMP_Addr + SAMP_SKIPSENDINTERIOR ), NULL, (uint8_t *)"\xEB", NULL }
  1853. }
  1854. };
  1855.  
  1856. if ( iEnabled && !sampPatchDisableInteriorUpdate_patch.installed )
  1857. return patcher_install( &sampPatchDisableInteriorUpdate_patch );
  1858. else if ( !iEnabled && sampPatchDisableInteriorUpdate_patch.installed )
  1859. return patcher_remove( &sampPatchDisableInteriorUpdate_patch );
  1860. return NULL;
  1861. }
  1862.  
  1863. #define SAMP_NOPSCOREBOARDTOGGLEON 0x80D80
  1864. #define SAMP_NOPSCOREBOARDTOGGLEONKEYLOCK 0x81040
  1865. int sampPatchDisableScoreboardToggleOn ( int iEnabled )
  1866. {
  1867. static struct patch_set sampPatchDisableScoreboard_patch =
  1868. {
  1869. "NOP Scoreboard Functions",
  1870. 0,
  1871. 0,
  1872. {
  1873. { 1, (void *)( (uint8_t *)g_dwSAMP_Addr + SAMP_NOPSCOREBOARDTOGGLEON ), NULL, (uint8_t *)"\xC3", NULL },
  1874. { 1, (void *)( (uint8_t *)g_dwSAMP_Addr + SAMP_NOPSCOREBOARDTOGGLEONKEYLOCK ), NULL, (uint8_t *)"\xC3", NULL }
  1875. }
  1876. };
  1877. if ( iEnabled && !sampPatchDisableScoreboard_patch.installed )
  1878. return patcher_install( &sampPatchDisableScoreboard_patch );
  1879. else if ( !iEnabled && sampPatchDisableScoreboard_patch.installed )
  1880. return patcher_remove( &sampPatchDisableScoreboard_patch );
  1881. return NULL;
  1882. }
  1883.  
  1884. #define SAMP_CHATINPUTADJUST_Y 0x7A4C6
  1885. #define SAMP_CHATINPUTADJUST_X 0x7B9E5
  1886. int sampPatchDisableChatInputAdjust ( int iEnabled )
  1887. {
  1888. static struct patch_set sampPatchDisableChatInputAdj_patch =
  1889. {
  1890. "NOP Adjust Chat input box",
  1891. 0,
  1892. 0,
  1893. {
  1894. { 6, (void *)( (uint8_t *)g_dwSAMP_Addr + SAMP_CHATINPUTADJUST_Y ), NULL, (uint8_t *)"\x90\x90\x90\x90\x90\x90", NULL },
  1895. { 7, (void *)( (uint8_t *)g_dwSAMP_Addr + SAMP_CHATINPUTADJUST_X ), NULL, (uint8_t *)"\x90\x90\x90\x90\x90\x90\x90", NULL }
  1896. }
  1897. };
  1898. if ( iEnabled && !sampPatchDisableChatInputAdj_patch.installed )
  1899. return patcher_install( &sampPatchDisableChatInputAdj_patch );
  1900. else if ( !iEnabled && sampPatchDisableChatInputAdj_patch.installed )
  1901. return patcher_remove( &sampPatchDisableChatInputAdj_patch );
  1902. return NULL;
  1903. }
  1904.  
  1905. #define FUNC_DEATH 0x4A90
  1906. void sendDeath ( void )
  1907. {
  1908. if ( g_SAMP == NULL )
  1909. return;
  1910.  
  1911. uint32_t func = g_dwSAMP_Addr + FUNC_DEATH;
  1912. void *lpPtr = g_Players->pLocalPlayer;
  1913. __asm mov ecx, dword ptr[lpPtr]
  1914. __asm push ecx
  1915. __asm call func
  1916. __asm pop ecx
  1917. }
  1918.  
  1919. #define FUNC_ENCRYPT_PORT 0x19870
  1920. void changeServer( const char *pszIp, unsigned ulPort, const char *pszPassword )
  1921. {
  1922. if ( !g_SAMP )
  1923. return;
  1924.  
  1925. ( ( void ( __cdecl * )( unsigned ) )( g_dwSAMP_Addr + FUNC_ENCRYPT_PORT ) )( ulPort );
  1926.  
  1927. disconnect( 500 );
  1928. strcpy( g_SAMP->szIP, pszIp );
  1929. g_SAMP->ulPort = ulPort;
  1930. setPassword( (char *)pszPassword );
  1931. joining_server = 1;
  1932. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement