Advertisement
Guest User

Deobfuscated GTA V UFO Script

a guest
Apr 30th, 2015
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. /************************************
  2. Deobfuscation of GTAV UFO script
  3. Created by Reddit User /u/KuztomX
  4. Original found at http://pastebin.com/wrecyG44
  5. ************************************/  
  6.  
  7. void main()
  8.  
  9. {
  10.  
  11. // Initialize some variables
  12.  
  13. l_2 = 1;
  14.  
  15. l_3 = 134;
  16.  
  17. l_4 = 134;
  18.  
  19. l_5 = 1;
  20.  
  21. l_6 = 1;
  22.  
  23. l_7 = 1;
  24.  
  25. l_8 = 134;
  26.  
  27. l_9 = 1;
  28.  
  29. l_10 = 12;
  30.  
  31. l_11 = 12;
  32.  
  33.  
  34. // If some value in memory (RAM) is equal to ZERO
  35. // Then disable the UFO
  36.  
  37. if (rPtr(((&g_86931) + 7795) + 3818) == 0)
  38.  
  39. {
  40.  
  41. DisableUFO(); // formerly called sub_4256()
  42.  
  43. }
  44.  
  45.  
  46. // If some property of the player is not equal to ZERO,
  47. // Then disable the UFO
  48.  
  49. if (PLAYER::0x4B37333C(18) != 0)
  50.  
  51. {
  52.  
  53. DisableUFO(); // formerly called sub_4256()
  54.  
  55. }
  56.  
  57.  
  58. // Main logic which will continually loop
  59.  
  60. while (true)
  61.  
  62. {
  63.  
  64. // This is meaningless as 1 does not equal to zero
  65.  
  66. if (1 == 0)
  67.  
  68. {
  69.  
  70. return;
  71.  
  72. }
  73.  
  74.  
  75. // A wait call of 0 msecs, probably to let other threads interrupt if needed (so as not to COMPLETELY hog all CPU resources)
  76.  
  77. SYSTEM::WAIT(0);
  78.  
  79.  
  80.  
  81. // If player isn't even in range of UFO
  82. // Then disable the UFO
  83.  
  84. if (BRAIN::IS_WORLD_POINT_WITHIN_BRAIN_ACTIVATION_RANGE() == 0)
  85.  
  86. {
  87.  
  88. DisableUFO(); // formerly called sub_4256()
  89.  
  90. }
  91.  
  92.  
  93.  
  94. // The loop has three different states:
  95. // - "Check for UFO conditions" State
  96. // - "Turn on UFO" State
  97. // - "Disable UFO when conditions go away" State
  98. // This switch statement executes code based on the current state
  99. // As one state completes, the script moves incrementally to the next state
  100.  
  101. switch (current_state)
  102.  
  103. {
  104.  
  105. case 0: // Check for UFO conditions State
  106.  
  107. {
  108.  
  109. // If it is 3 Oclock AND the weather conditions are right (raining / thundering)
  110. // Then move to next state (Turn on UFO Step)
  111.  
  112. bool Is_It_3_OCLOCK = TIME::GET_CLOCK_HOURS() == 3;
  113.  
  114. if (Is_It_3_OCLOCK & AreWeatherConditionsRightForUFO()) // formerly called sub_4214
  115.  
  116. {
  117.  
  118. current_state = 1;
  119.  
  120. }
  121.  
  122. break;
  123.  
  124. }
  125.  
  126. case 1: // "Turn on UFO" State
  127.  
  128.  
  129. // This method will do nothing because it checks if the first variable (149) matches 192 before it does anything
  130. // Otherwise, it does nothing. In this case, sending 149 will do nothing so this call doesn't matter
  131.  
  132. sub_CF(149, 1, 0, 1);
  133.  
  134.  
  135. // Move to the next state, which is "Disable UFO when conditions go away Step"
  136.        
  137. current_state = 2;
  138.  
  139.  
  140. // If the ambient zone is not UFO, then turn it on
  141.  
  142. if (AUDIO::IS_AMBIENT_ZONE_ENABLED("AZ_SPECIAL_UFO_03") == 0)
  143.  
  144.                 {
  145.  
  146.                     AUDIO::SET_AMBIENT_ZONE_STATE("AZ_SPECIAL_UFO_03", 1, 1);
  147.  
  148.                 }
  149.  
  150.                 break;
  151.  
  152.  
  153. case 2: // "Disable UFO when conditions go away" State
  154.  
  155.       {
  156.  
  157. // If it is no longer 3 Oclock OR the weather conditions stopped raining / thundering
  158. // Then disable the UFO
  159.  
  160.             bool Is_It_NOT_3_OCLOCK = TIME::GET_CLOCK_HOURS() != 3;
  161.  
  162.  
  163.  
  164.             if (Is_It_NOT_3_OCLOCK | (AreWeatherConditionsRightForUFO() == 0)) // formerly called sub_4214
  165.  
  166.             {
  167.  
  168.             DisableUFO(); // formerly called sub_4256()
  169.  
  170.             }
  171.  
  172.             break;
  173.  
  174. }
  175.  
  176. }
  177.  
  178. }
  179.  
  180. }
  181.  
  182.  
  183.  
  184. void sub_CF(var A_0, var A_1, var A_2, var A_3)
  185.  
  186. {
  187.  
  188. // The only value passed into variable A_0 from the Main Loop is 149
  189. // So at this point, this conditional check will fail and the method will do nothing
  190. // So all the other logic in this is meaningless for this context
  191.  
  192. if (A_0 != 192)
  193.  
  194. {
  195.  
  196.  
  197. // All this logic in here WILL ONLY be called if something OTHER than 149 is passed into variable A_0
  198. // Because 149 is hard-coded, the only way this will happen is if someone manipulates the value with a Game-Genie-like tool
  199. // OR if Rockstar publishes an update that changes that code to pass in 192 instead of 149
  200. // OR if the hardcoded values in the script can be changed during runtime by the engine (which means we need to look elsewhere in code)
  201.  
  202.     if (g_59935 != 0)
  203.  
  204.   {
  205.  
  206.     setElem(A_1, A_0, ((&g_1338499) + 61) + 226, 4);
  207.  
  208.     }
  209.  
  210.       else
  211.  
  212.       {
  213.  
  214.       setElem(A_1, A_0, ((&g_86931) + 4964) + 226, 4);
  215.  
  216.   }
  217.  
  218.       setElem(A_2, A_0, &g_26924, 4);
  219.  
  220.       setElem(1, A_0, &g_27117, 4);
  221.  
  222.       sub_22F(A_0, A_3, 0);
  223.  
  224.       sub_127(A_0, A_1);
  225.  
  226. }
  227.  
  228. }
  229.  
  230.  
  231. // The rest of the code is meaningless until the value 192 is passed into variable A_0 of method Sub_CF
  232.  
  233. ...
  234.  
  235.  
  236. // Method: AreWeatherConditionsRightForUFO
  237. // Original Call: sub_4214
  238. // Checks to see that the next or previous weather is either rain or thunder
  239.  
  240. var AreWeatherConditionsRightForUFO()
  241.  
  242. {
  243.  
  244.  
  245. // Check a bunch of conditions, and if one matches, return true
  246. // Conditions checked
  247. // Next weather is rain
  248. // Next weather is thunder
  249. // Previous weather is rain
  250. // Previous weather is thunder
  251.  
  252. var num1 = GAMEPLAY::IS_NEXT_WEATHER_TYPE("RAIN");
  253.  
  254. var num6 = num1 | GAMEPLAY::IS_NEXT_WEATHER_TYPE("THUNDER");
  255.  
  256. var num7 = num6 | GAMEPLAY::IS_PREV_WEATHER_TYPE("RAIN");
  257.  
  258. if ((num7 | GAMEPLAY::IS_PREV_WEATHER_TYPE("THUNDER")) != 0)
  259.  
  260. {
  261.  
  262. return 1;
  263.  
  264. }
  265.  
  266. return 0;
  267.  
  268. }
  269.  
  270.  
  271.  
  272.  
  273. // Method: DisableUFO
  274. // Original Call: sub_4256()
  275. // Disables the ambient setting for the UFO and terminates the thread (exiting UFO logic)
  276.  
  277. void DisableUFO()
  278.  
  279. {
  280.  
  281. // Call sub_CF with hardcoded value 149 for parameter A_0, which means this will do nothing
  282.  
  283.     sub_CF(149, 0, 1, 1);
  284.  
  285.  
  286. // If the ambient zone for UFO is enabled
  287. // Then disable it
  288.  
  289. if (AUDIO::IS_AMBIENT_ZONE_ENABLED("AZ_SPECIAL_UFO_03") != 0)
  290.  
  291. {
  292.  
  293. AUDIO::SET_AMBIENT_ZONE_STATE("AZ_SPECIAL_UFO_03", 0, 1);
  294.  
  295. }
  296.  
  297.  
  298. // Terminate the thread, which breaks us from the UFO main loop
  299.  
  300. SCRIPT::TERMINATE_THIS_THREAD();
  301.  
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement