Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************
- Deobfuscation of GTAV UFO script
- Created by Reddit User /u/KuztomX
- Original found at http://pastebin.com/wrecyG44
- ************************************/
- void main()
- {
- // Initialize some variables
- l_2 = 1;
- l_3 = 134;
- l_4 = 134;
- l_5 = 1;
- l_6 = 1;
- l_7 = 1;
- l_8 = 134;
- l_9 = 1;
- l_10 = 12;
- l_11 = 12;
- // If some value in memory (RAM) is equal to ZERO
- // Then disable the UFO
- if (rPtr(((&g_86931) + 7795) + 3818) == 0)
- {
- DisableUFO(); // formerly called sub_4256()
- }
- // If some property of the player is not equal to ZERO,
- // Then disable the UFO
- if (PLAYER::0x4B37333C(18) != 0)
- {
- DisableUFO(); // formerly called sub_4256()
- }
- // Main logic which will continually loop
- while (true)
- {
- // This is meaningless as 1 does not equal to zero
- if (1 == 0)
- {
- return;
- }
- // A wait call of 0 msecs, probably to let other threads interrupt if needed (so as not to COMPLETELY hog all CPU resources)
- SYSTEM::WAIT(0);
- // If player isn't even in range of UFO
- // Then disable the UFO
- if (BRAIN::IS_WORLD_POINT_WITHIN_BRAIN_ACTIVATION_RANGE() == 0)
- {
- DisableUFO(); // formerly called sub_4256()
- }
- // The loop has three different states:
- // - "Check for UFO conditions" State
- // - "Turn on UFO" State
- // - "Disable UFO when conditions go away" State
- // This switch statement executes code based on the current state
- // As one state completes, the script moves incrementally to the next state
- switch (current_state)
- {
- case 0: // Check for UFO conditions State
- {
- // If it is 3 Oclock AND the weather conditions are right (raining / thundering)
- // Then move to next state (Turn on UFO Step)
- bool Is_It_3_OCLOCK = TIME::GET_CLOCK_HOURS() == 3;
- if (Is_It_3_OCLOCK & AreWeatherConditionsRightForUFO()) // formerly called sub_4214
- {
- current_state = 1;
- }
- break;
- }
- case 1: // "Turn on UFO" State
- // This method will do nothing because it checks if the first variable (149) matches 192 before it does anything
- // Otherwise, it does nothing. In this case, sending 149 will do nothing so this call doesn't matter
- sub_CF(149, 1, 0, 1);
- // Move to the next state, which is "Disable UFO when conditions go away Step"
- current_state = 2;
- // If the ambient zone is not UFO, then turn it on
- if (AUDIO::IS_AMBIENT_ZONE_ENABLED("AZ_SPECIAL_UFO_03") == 0)
- {
- AUDIO::SET_AMBIENT_ZONE_STATE("AZ_SPECIAL_UFO_03", 1, 1);
- }
- break;
- case 2: // "Disable UFO when conditions go away" State
- {
- // If it is no longer 3 Oclock OR the weather conditions stopped raining / thundering
- // Then disable the UFO
- bool Is_It_NOT_3_OCLOCK = TIME::GET_CLOCK_HOURS() != 3;
- if (Is_It_NOT_3_OCLOCK | (AreWeatherConditionsRightForUFO() == 0)) // formerly called sub_4214
- {
- DisableUFO(); // formerly called sub_4256()
- }
- break;
- }
- }
- }
- }
- void sub_CF(var A_0, var A_1, var A_2, var A_3)
- {
- // The only value passed into variable A_0 from the Main Loop is 149
- // So at this point, this conditional check will fail and the method will do nothing
- // So all the other logic in this is meaningless for this context
- if (A_0 != 192)
- {
- // All this logic in here WILL ONLY be called if something OTHER than 149 is passed into variable A_0
- // Because 149 is hard-coded, the only way this will happen is if someone manipulates the value with a Game-Genie-like tool
- // OR if Rockstar publishes an update that changes that code to pass in 192 instead of 149
- // 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)
- if (g_59935 != 0)
- {
- setElem(A_1, A_0, ((&g_1338499) + 61) + 226, 4);
- }
- else
- {
- setElem(A_1, A_0, ((&g_86931) + 4964) + 226, 4);
- }
- setElem(A_2, A_0, &g_26924, 4);
- setElem(1, A_0, &g_27117, 4);
- sub_22F(A_0, A_3, 0);
- sub_127(A_0, A_1);
- }
- }
- // The rest of the code is meaningless until the value 192 is passed into variable A_0 of method Sub_CF
- ...
- // Method: AreWeatherConditionsRightForUFO
- // Original Call: sub_4214
- // Checks to see that the next or previous weather is either rain or thunder
- var AreWeatherConditionsRightForUFO()
- {
- // Check a bunch of conditions, and if one matches, return true
- // Conditions checked
- // Next weather is rain
- // Next weather is thunder
- // Previous weather is rain
- // Previous weather is thunder
- var num1 = GAMEPLAY::IS_NEXT_WEATHER_TYPE("RAIN");
- var num6 = num1 | GAMEPLAY::IS_NEXT_WEATHER_TYPE("THUNDER");
- var num7 = num6 | GAMEPLAY::IS_PREV_WEATHER_TYPE("RAIN");
- if ((num7 | GAMEPLAY::IS_PREV_WEATHER_TYPE("THUNDER")) != 0)
- {
- return 1;
- }
- return 0;
- }
- // Method: DisableUFO
- // Original Call: sub_4256()
- // Disables the ambient setting for the UFO and terminates the thread (exiting UFO logic)
- void DisableUFO()
- {
- // Call sub_CF with hardcoded value 149 for parameter A_0, which means this will do nothing
- sub_CF(149, 0, 1, 1);
- // If the ambient zone for UFO is enabled
- // Then disable it
- if (AUDIO::IS_AMBIENT_ZONE_ENABLED("AZ_SPECIAL_UFO_03") != 0)
- {
- AUDIO::SET_AMBIENT_ZONE_STATE("AZ_SPECIAL_UFO_03", 0, 1);
- }
- // Terminate the thread, which breaks us from the UFO main loop
- SCRIPT::TERMINATE_THIS_THREAD();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement