Advertisement
BaSs_HaXoR

[MW2] How to call raw GSC Functions in an .sprx

Mar 9th, 2015
1,738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.41 KB | None | 0 0
  1. // ############################################################################################### //
  2. /*         How to call raw GSC Functions in an .sprx. Also, how to do waitill xD [RELEASE]         */
  3. // ############################################################################################### //
  4. /*                                        Credits: Ethernet                                        */
  5. // ############################################################################################### //
  6. /*
  7. How to call raw GSC Functions in an .sprx. Also, how to do waitill xD [RELEASE]
  8. Sup guys, if you don't know me, good. I'm from xbox xD. My alias is Maybe Ethernet. I'll be showing you how to call raw gsc functions in your dll/sprx.
  9. */
  10. // Ok so first we want to get our basic functions
  11.  
  12. int Scr_SetParameters(unsigned int Num){
  13.      return *(int*)(0x13C3140 + 0x2038) = Num;
  14. }
  15. //This will set the parameter number
  16.  
  17. struct opd_s{
  18.     uint Sub;
  19.     uint Toc;
  20. };
  21.  
  22. opd_s ParseAddr(int Address){
  23.     opd_s GLS = { Address, 0x724C38 };
  24.     return GLS;
  25. }
  26. //TOC
  27.  
  28. // Next we want to get all the Scr_Add functions together
  29.  
  30. #define Scr_AddInt(Value) ((void(*)(int))&ParseAddr(0x20C608))(Value)
  31. #define Scr_AddFloat(Value) ((void(*)(float))&ParseAddr(0x20C5C0))(Value)
  32. #define Scr_AddString(String) ((void(*)(const char*))&ParseAddr(0x20C428))(String)
  33. #define Scr_AddEntity(Entity) ((void(*)(int))&ParseAddr(0x1B7700))(Entity)
  34. #define Scr_AddVector(Vec) ((void(*)(const float*))&ParseAddr(0x20C330))(Vec)
  35. Now to explain how to actually use these, we're going to use GScr_Earthquake as an example which is located at 0x268B60.
  36.  
  37. // Here's how we do this.
  38.  
  39. // First:
  40. #define Scr_ClearOutParams() ((void(*)(void))&ParseAddr(0x20C19)()
  41.  
  42. void GScr_Earthquake(float scale, float duration, float* source, float radius){
  43.      Scr_AddFloat(radius);
  44.      Scr_AddVector(source);
  45.      Scr_AddFloat(duration);
  46.      Scr_AddFloat(scale);
  47.      Scr_SetParameters(4); //See how I set the parameter number after I finish calling the Scr_Adds?
  48.      ((void(*)())&ParseAddr(0x1A80E8))(); //Call the actual function
  49.      //((void(*)(int))&ParseAddr(0x1A80E8))(ClientID << 16); //Only call this one if the one above doesn't work.
  50.      Scr_ClearOutParams();
  51. }
  52. // See how I called the Scr_Adds from the last parameter to the 1st one? Well you have to do that, idk why really.
  53.  
  54. // Now on to the hook. You need somewhere to call these right? Well your answer is: VM_Resume - 0x2E69C4.
  55.  
  56. // Method to hook: hookFunctionStart - Credit to Xx jAmes t xX for porting this
  57.  
  58. void PatchInJump(int Address, int Destination){
  59.     int FuncBytes[4];
  60.     Destination = *(int*)Destination;
  61.     FuncBytes[0] = 0x3D600000 + ((Destination >> 16) & 0xFFFF);
  62.     if(Destination & 0x8000) FuncBytes[0] += 1;
  63.     FuncBytes[1] = 0x396B0000 + (Destination & 0xFFFF);
  64.     FuncBytes[2] = 0x7D6903A6;
  65.     FuncBytes[3] = 0x4E800420;
  66.     Memcpy((void*)Address, FuncBytes, 4*4);
  67. }
  68.  
  69. void hookFunctionStart(int Address, int saveStub, int Destination){ //Works on every game
  70.     saveStub = *(int*)saveStub;
  71.     int BranchtoAddress = Address + (4*4);
  72.     int StubData[8];
  73.     StubData[0] = 0x3D600000 + ((BranchtoAddress >> 16) & 0xFFFF);
  74.     if(BranchtoAddress & 0x8000) StubData[0] += 1;
  75.     StubData[1] = 0x396B0000 + (BranchtoAddress & 0xFFFF);
  76.     StubData[2] = 0x7D6903A6;
  77.     Memcpy(&StubData[3], (void*)Address, 4*4);
  78.     StubData[7] = 0x4E800420;
  79.     Memcpy((void*)saveStub, StubData, 8*4);
  80.     PatchInJump(Address, Destination);
  81. }
  82. // Now our function hook
  83.  
  84. void VM_ResumeStub(int TimeId){
  85.      __asm("li %r3, 0x3");
  86. }
  87.  
  88. void VM_ResumeHook(int TimeId){ // If this doesn't work, hook int VM_Execute() - 0x20CC08 with hookFunctionStart
  89.      //You would call GScr_Earthquake here. Obv not in the loop. Make sure you implement a check in here to make it //   get called once
  90.      VM_ResumeStub(TimeId);
  91. }
  92. // To call our hook we do
  93.  
  94. hookFunctionStart(0x2E69C4, (int)VM_ResumeStub, (int)VM_ResumeHook);
  95. // Make sure you call that about 2 seconds after your thread is executed.
  96.  
  97. // ############################################################################################### //
  98.  
  99. // Now that's it.  Also, you can call other things like:
  100.  
  101. /*
  102. PlayerCmd_ClonePlayer
  103. PlayerCmd_Suicide
  104. Player_Die
  105. G_RadiusDamage
  106. GScr_NotifyOnPlayerCommand //Someone find this for me on ghosts pls ;-;
  107. G_Damage
  108. and many more!
  109.  
  110. Now on to waitill. Pretty easy tbh.
  111. */
  112. // First
  113.  
  114. #define SL_ConvertToString(StringValue) ((const char*(*)(unsigned short))ParseAddr(0x200280))(StringValue)
  115. Code:
  116. hookFunctionStart(0x20B7C8, (int)VM_NotifyStub, (int)VM_NotifyHook);
  117. Code:
  118. void VM_NotifyStub(unsigned int self, short Stringvalue, unsigned int Paramcount){
  119.      __asm("li %r3, 0x4");
  120. }
  121.  
  122. void VM_NotifyHook(unsigned int self, short Stringvalue, unsigned int Paramcount){
  123.      //Now if we wanted to monitor onPlayerSpawned we do
  124.      int ClientID = ((int(*)(int))&ParseAddr(0x201F90))(self); //Scr_GetSelf
  125.      const char* Notify = SL_ConvertToString(Stringvalue);
  126.      if(!strcmp(Notify, "spawned_player")){
  127.           //Executed on spawn. This monitors for ANY CLIENT THAT SPAWNS!
  128.           GScr_Earthquake(0.6f, 2, (float*)(Playerstate() + 0x1C), 800); //Yes you can call this in V
  129.      }
  130.      VM_NotifyStub(self, Stringvalue, Paramcount);
  131. }
  132. // That's pretty much it :P This works for all cods the same way as it works for this. Just update the offsets.
  133. /* ############################################################################################### */
  134. //BaSs_HaXoR
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement