Advertisement
HolywoodJack

HungUpThePhone.cpp

Apr 20th, 2022
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. #include "plugin.h"
  2. #include "CHud.h"
  3. #include "GameVersion.h"
  4. #include "CPad.h"
  5. #include "CRunningScript.h"
  6. #include "CTimer.h"
  7. #include "extensions\ScriptCommands.h"
  8.  
  9. bool messageActive = false;
  10.  
  11. char* messageText = new char[255];
  12.  
  13. int playMessageOneTime = 0;
  14. int hungUpNow = 0;
  15. int playaAction = 0;
  16. int _ZN6CWorld7PlayersE_11 = 0;
  17. int commandHasMissionAudioFinished = 0x45ABEB;
  18.  
  19. static int CRunningScriptCollectParameters = 0x451010;
  20. static int CAudioAudioScriptObjEnded = 0x5F9790;
  21. static int CRunningScriptUpdateCompareFlag = 0x463F00;
  22. static int CAudioAudioScriptObjEnded_1 = 0x5F97B0;
  23.  
  24. // if (plugin::patch::GetUShort(commandHasMissionAudioFinished + 0x20) != 0x474) {
  25. // plugin::patch::SetUShort(commandHasMissionAudioFinished + 0x20, 0x474);
  26. // }
  27.  
  28. __declspec(naked) void command_03D2() {
  29. _asm {
  30. lea eax,[ebp+0x10]
  31. mov ecx,ebp
  32. push 1
  33. push eax
  34. call CRunningScriptCollectParameters
  35. mov eax,ds:[0x7D7438]
  36. mov ecx,0xA10B8A
  37. dec eax
  38. cmp hungUpNow, 1
  39. je hungUp
  40. push eax
  41. call CAudioAudioScriptObjEnded
  42. test al,al
  43. je loc_45AC11
  44. hungUp:
  45. mov al,1
  46. jmp loc_45AC13
  47. loc_45AC11:
  48. xor al,al
  49. loc_45AC13:
  50. mov ecx,ebp
  51. push eax
  52. call CRunningScriptUpdateCompareFlag
  53. xor al,al
  54. add esp,0x208
  55. pop ebp
  56. pop edi
  57. pop esi
  58. pop ebx
  59. ret 4
  60. }
  61. }
  62.  
  63. __declspec(naked) void command_03D2_11() {
  64. _asm {
  65. lea eax,[ebp+0x10]
  66. mov ecx,ebp
  67. push 1
  68. push eax
  69. call CRunningScriptCollectParameters
  70. mov eax,ds:[0x7D7440]
  71. mov ecx,0xA10B93
  72. dec eax
  73. cmp hungUpNow, 1
  74. je hungUp_1
  75. push eax
  76. call CAudioAudioScriptObjEnded_1
  77. test al,al
  78. je lab_45AC11
  79. hungUp_1:
  80. mov al,1
  81. jmp lab_45AC13
  82. lab_45AC11:
  83. xor al,al
  84. lab_45AC13:
  85. mov ecx,ebp
  86. push eax
  87. call CRunningScriptUpdateCompareFlag
  88. xor al,al
  89. add esp,0x208
  90. pop ebp
  91. pop edi
  92. pop esi
  93. pop ebx
  94. ret 4
  95. }
  96. }
  97.  
  98. using namespace plugin;
  99.  
  100. class HungUpThePhone {
  101. public:
  102. HungUpThePhone() {
  103.  
  104. if (plugin::IsGameVersion10en()) {
  105. injector::MakeJMP(commandHasMissionAudioFinished, command_03D2);
  106. } else {
  107. if (plugin::IsGameVersion11en()) {
  108. injector::MakeJMP(commandHasMissionAudioFinished, command_03D2_11);
  109. } else {
  110. CHud::SetHelpMessage("Unsupported game version!", false, false);
  111. }
  112. }
  113.  
  114. Events::initGameEvent += [] {
  115. playMessageOneTime = GetPrivateProfileInt("HungUpThePhone", "PlayMessageOnce", 0, PLUGIN_PATH("HungUpThePhone.ini"));
  116. };
  117.  
  118. Events::gameProcessEvent += [] {
  119.  
  120. // 0x94AD30 // 1.1
  121.  
  122. if (plugin::IsGameVersion10en()) {
  123. CPlayerPed *playa = FindPlayerPed();
  124. if (playa) {
  125.  
  126. // Command<0x0ADF>("ABCD", "_____"); // ADD_TEXT_LABEL
  127. // Command<0x0AE0>("ABCD"); // REMOVE_TEXT_LABEL
  128. // Command<Commands::PRINT_HELP>('ABCD'); // opcode_03E5
  129. // DWORD TheText = 0x94B220;
  130. // wchar_t *v27 = plugin::CallMethod<0x584F30>(TheText, "ABCD"); // CText::Get(&TheText, "ABCD");
  131.  
  132. if (playa->m_dwAction == 36) { // 36 - uses cellphone
  133. if (CTimer::m_snTimeInMilliseconds - Pads->LastTimeTouched) {
  134. if (!messageActive) {
  135. GetPrivateProfileString("HungUpThePhone", "PhoneMessage", "", messageText, 255, PLUGIN_PATH("HungUpThePhone.ini"));
  136. CHud::SetHelpMessage(messageText, false, false); messageActive = true;
  137. }
  138. }
  139. if (Pads->ExitVehicleJustDown()) { // 70 - F key
  140. hungUpNow = 1;
  141. }
  142. } else {
  143. hungUpNow = 0; messageActive = false;
  144. }
  145. }
  146. } else {
  147. if (plugin::IsGameVersion11en()) {
  148. _ZN6CWorld7PlayersE_11 = plugin::patch::GetUInt(0x94AD30);
  149. playaAction = plugin::patch::GetUInt(_ZN6CWorld7PlayersE_11 + 0x244);
  150. if (playaAction == 36) { // 36 - uses cellphone
  151. if (CTimer::m_snTimeInMilliseconds - Pads->LastTimeTouched) {
  152. if (!messageActive) {
  153. GetPrivateProfileString("HungUpThePhone", "PhoneMessage", "", messageText, 255, PLUGIN_PATH("HungUpThePhone.ini"));
  154. CHud::SetHelpMessage(messageText, false, false); messageActive = true;
  155. }
  156. }
  157. if (Pads->ExitVehicleJustDown()) { // 70 - F key
  158. hungUpNow = 1;
  159. }
  160. } else {
  161. hungUpNow = 0; messageActive = false;
  162. }
  163. } else {
  164. if (!messageActive) {
  165. CHud::SetHelpMessage("Unsupported game version!", false, false); messageActive = true;
  166. }
  167. }
  168. }
  169. };
  170. }
  171. } hungUpThePhone;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement