Jo-Milk

Bo1 Explosive Bullets By Jo-Milk

Oct 10th, 2017
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.50 KB | None | 0 0
  1. /*Bo1 Explosive Bullets By Jo-Milk
  2. This will be updated as it's Fugly
  3. 01cedricv2 said he would try to fix it for y'all
  4. Enjoy Port this shit guys works all cods*/
  5. bool ExplosiveBullet[18];
  6.  
  7. /*struct weaponParms  //size 0x44
  8. {
  9.     float forward[3];
  10.     float right[3];
  11.     float up[3];
  12.     float muzzleTrace[3];
  13.     float gunForward[3];
  14.     WeaponVariantDef* weapVarD;//offset To weapVariantDef
  15.     WeaponDef* weapD;//offset To weapDef
  16. };*/
  17.  
  18. struct weaponParms
  19. {
  20.     char unk[0x3C];//Location mainly
  21.     int weapVariantDef;//offset To weapVariantDef
  22.     int weapDef;//offset To weapDef
  23. };
  24. char TESTWPJM[] = { 0x3F, 0x59, 0x20, 0x22, 0xBF, 0x07, 0x9E, 0x73, 0x39, 0xD9, 0x68, 0x88, 0xBF, 0x07, 0x9E, 0x74, 0xBF, 0x59, 0x20, 0x23, 0x80, 0x00, 0x00, 0x00, 0xB9, 0xB8, 0x64, 0xE6, 0x39, 0x66, 0x59, 0x61, 0x3F, 0x7F, 0xFF, 0xFF, 0xC4, 0xC9, 0xA4, 0xA3, 0x44, 0xF4, 0x01, 0x89, 0x44, 0x15, 0x7E, 0xB9, 0x01, 0x2A, 0xB2, 0x90, 0x00, 0x00, 0x00, 0x00, 0xD0, 0x0F, 0x4F, 0xB0, 0x01, 0x17, 0x3D, 0x4C, 0x32, 0xAC, 0x2F, 0xE4};
  25. /*|TESTWPJM|This is a struct weaponParms that I dumped of a rocket the first 0x3C bytes are for where the bullet is going the last two are the weapVariantDef and weapDef used to copy the bullet type*/
  26.  
  27. //it would be cool to make our own weapDef and weapVariantDef since they are mapped in the pdb but I don't have time
  28.  
  29.  
  30. void SetMemory(int Address,char* bytes,int length) //writes over structures and variables
  31. {
  32.         for (int i = 0; i < length; i++)
  33.         {
  34.             *(char*)(Address + (i)) = bytes[i];
  35.         }
  36. }
  37.  
  38.  
  39. void Bullet_Fire_Stub(int attacker, float spread, weaponParms *wp, int weaponEnt, int gameTime)//look hookstart
  40. {
  41.     __nop();
  42.     __nop();
  43.     __nop();
  44.     __nop();
  45.     __nop();
  46.     __nop();
  47.     __nop();
  48. }
  49.  
  50.  
  51. /*This hook is very restricted: meaning it will freeze if you add fancy shit*/
  52. void Bullet_Fire_Hook(int attacker, float spread, weaponParms *wp, int weaponEnt, int gameTime)
  53. {
  54.     int client = (attacker-0x12AB290)/0x2F8;//this was the only way to not freeze I'm open for ideas
  55.     if(client < 18)//if a entity bigger then 17 enters the bool array it will freeze
  56.     {
  57.     if(ExplosiveBullet[client] == true)//if explosive bullet true
  58.     {
  59.     SetMemory((int)&TESTWPJM,(char*)wp,0x3C);/*We take the Location from the regular bullet and give it to the rocket the two last integers are the bullet type using weapondef feel free to change those to your likings to have hind rockets or whatever*/
  60.     ((void(*)(int, unsigned int, float,weaponParms *,const float *,int, const float *,int,int))&ParseAddr(0x378518))(0x12AB290 + (client * 0x2F8),0x0665,2,(weaponParms *)TESTWPJM,(float*)0x924700,0,0,0x13950C8+(client * 0x2A38),0x13950C8+(client * 0x2A38));
  61. /*0x378518 Weapon_RocketLauncher_Fire(gentity_s *ent, unsigned int weaponIndex, float spread, weaponParms *wp, const float *gunVel, gentity_s *target, const float *targetOffset) Note:I added more arguments then needed I didn't test without the playerstate_s but when I debugged I saw r10 and r11 equal to playerstate_s*/
  62.     }
  63.     }
  64. Bullet_Fire_Stub(attacker, spread, wp, weaponEnt, gameTime);
  65. }
  66. /*BTW: this code uses (WeaponVariantDef*)0x01173D4C and (WeaponDef*)0x32AC2FE4 is you change it you can have other types of rockets feel free to share you're findings at-> http://www.nextgenupdate.com/forums/showthread.php?t=958430&p=7251379#post7251379*/
  67. /*--------------------------------------------------Extra----------------------------------------------------------------------*/
  68. //read write syscalls
  69.  int32_t sys_dbg_read_process_memory(uint64_t address, void *data, size_t size)
  70. {
  71.     system_call_4(904, (uint64_t)sys_process_getpid(), address, size, (uint64_t)data);
  72.     return_to_user_prog(int32_t);
  73. }
  74.  
  75. template<typename T>
  76. int32_t ReadProcessMemory(uint32_t address, T data, size_t size)
  77. {
  78.     return sys_dbg_read_process_memory(address, &data, size);
  79. }
  80.  
  81. int32_t sys_dbg_write_process_memory(uint64_t address, const void *data, size_t size)
  82. {
  83.     system_call_4(905, (uint64_t)sys_process_getpid(), address, size, (uint64_t)data);
  84.     return_to_user_prog(int32_t);
  85. }
  86.  
  87. template<typename T>
  88. int32_t WriteProcessMemory(uint32_t address, const T value, size_t size)
  89. {
  90.     return sys_dbg_write_process_memory(address, &value, size);
  91. }
  92.  
  93. void HookFunctionStart(uint32_t functionStartAddress, uint32_t newFunction, uint32_t functionStub)//SC58 showed me this hooking methode
  94. {
  95.     uint32_t normalFunctionStub[8], hookFunctionStub[4];
  96.     sys_dbg_read_process_memory(functionStartAddress, normalFunctionStub, 0x10);//read(saves) first 4 ppc instructions from the function we are hooking
  97.     normalFunctionStub[4] = 0x3D600000 + ((functionStartAddress + 0x10 >> 16) & 0xFFFF);// ppc
  98.     normalFunctionStub[5] = 0x616B0000 + (functionStartAddress + 0x10 & 0xFFFF);// ppc
  99.     normalFunctionStub[6] = 0x7D6903A6;// ppc
  100.     normalFunctionStub[7] = 0x4E800420;// ppc
  101.     sys_dbg_write_process_memory(functionStub, normalFunctionStub, 0x20);//writes the 4 ppc instruction we saved to the stub where we put (nop)s
  102.     hookFunctionStub[0] = 0x3D600000 + ((newFunction >> 16) & 0xFFFF);// ppc
  103.     hookFunctionStub[1] = 0x616B0000 + (newFunction & 0xFFFF);// ppc
  104.     hookFunctionStub[2] = 0x7D6903A6;// ppc
  105.     hookFunctionStub[3] = 0x4E800420;// ppc
  106.     sys_dbg_write_process_memory(functionStartAddress, hookFunctionStub, 0x10);//writes to the function we are hooking 4 ppc instructions to allow to jump to our hook
  107. }
  108.  
  109. HookFunctionStart(0x2B8400, *(uint32_t*)Bullet_Fire_Hook, *(uint32_t*)Bullet_Fire_Stub);
  110. /* 0x2B83F8 Bullet_Fire we could optimize the hook *just guessing* if r8 = 0x3D0 mfcr r12 or just optimize the code to use it in VM_Notify
  111. I don't have time right now....*/
Add Comment
Please, Sign In to add comment