Quantcast

Jump to content

» «
Photo

Access Game's variables?

9 replies to this topic
123iamking
  • 123iamking

    Who am I?

  • Members
  • Joined: 21 Jan 2011

#1

Posted 02 August 2014 - 05:36 AM

ScriptHook give us a way to access Game's void through GTA Native function, but I wonder is there a way to access Game variables?

for example in the startup script, there are some variables that the Mission's script can access (from GTA 4)

void main()
{
    unknown uVar2;
    string sVar3;

    l_U4 = 0;
    l_U5 = 1;
    l_U6 = 3;
    l_U8 = 0;
    l_U25 = -1;
    l_U29 = 0;
    l_U30 = 1;
    l_U31 = 1;
    l_U32 = -1;
    l_U33 = 1;
    l_U34 = 0;
    g_U0 = 0;
    g_U1 = 0;
    g_U2 = 0;
   ...
    g_U9938 = 1;
    ProtectedSet(g_U9939, 6);
    g_U9940 = 0;
    g_U9941 = 0;
    g_U9942 = 1;
   ...
}

Because the mission scripts can access, I think those variables are public type. So I think there should be a way to access and change those variables
.For example, the script derrick3 can access those variable which's in the startup script:

        g_U9942 = 0;
        SET_MAX_WANTED_LEVEL( 0 );
        CLEAR_WANTED_LEVEL( l_U838 );
        SET_WANTED_MULTIPLIER( 0.00000000 );

Thanks for reading!


NTAuthority
  • NTAuthority

    hell, no, tunnel, no

  • Feroci
  • Joined: 09 Sep 2008
  • European-Union
  • Most Knowledgeable [Technology] 2013
    Best Map 2013 "ViceCityStories PC Edition"
    Contribution Award [Modding]

#2

Posted 02 August 2014 - 10:26 PM

Global script variables should be easy to access using a version-specific memory address offset. I just don't have it at hand, so I'm not posting it right now.
  • 123iamking likes this

123iamking
  • 123iamking

    Who am I?

  • Members
  • Joined: 21 Jan 2011

#3

Posted 06 August 2014 - 01:59 AM

@NTAuthority: awesome! I hope it can be done in scripthookdotnet for C# code. but if it coud only be done in ScriptHook (C++) should be ok too. I'm looking forward for your reply :)

jenksta
  • jenksta

    Player Hater

  • Members
  • Joined: 22 Dec 2008
  • United-Kingdom

#4

Posted 06 August 2014 - 12:51 PM

void* g_pScriptGlobals
EFLC 1.1.2.0: 0x16EAD5C
IV 1.0.7.0: 0x1849AEC
IV 1.0.4.0: 0x16257A8

NTAuthority
  • NTAuthority

    hell, no, tunnel, no

  • Feroci
  • Joined: 09 Sep 2008
  • European-Union
  • Most Knowledgeable [Technology] 2013
    Best Map 2013 "ViceCityStories PC Edition"
    Contribution Award [Modding]

#5

Posted 06 August 2014 - 01:19 PM Edited by NTAuthority, 06 August 2014 - 01:20 PM.

Relevant C++ code:
 
static int*& g_scriptGlobals = *(int**)0x1849AEC;

int GetScriptGlobal(int index)
{
	return g_scriptGlobals[index];
}
  • 123iamking likes this

123iamking
  • 123iamking

    Who am I?

  • Members
  • Joined: 21 Jan 2011

#6

Posted 07 August 2014 - 04:27 AM

Relevant C++ code:
 

static int*& g_scriptGlobals = *(int**)0x1849AEC;

int GetScriptGlobal(int index)
{
	return g_scriptGlobals[index];
}

Thank NTAuthority, I have checked this http://www.gtamoddin...x.php?title=SCO and this http://www.gtamoddin...ddresses_(GTA4)

but I still don't know what index I should put.

Can you give me an example, like I want to get this g_U9938 bool value and change it to False?

Thank in advance :)


NTAuthority
  • NTAuthority

    hell, no, tunnel, no

  • Feroci
  • Joined: 09 Sep 2008
  • European-Union
  • Most Knowledgeable [Technology] 2013
    Best Map 2013 "ViceCityStories PC Edition"
    Contribution Award [Modding]

#7

Posted 07 August 2014 - 01:28 PM

I'm assuming the index is 9938, just for an obvious guess. :p


123iamking
  • 123iamking

    Who am I?

  • Members
  • Joined: 21 Jan 2011

#8

Posted 08 August 2014 - 01:03 AM

Thank :) but Can you give me the link where you get the information about "static int*& g_scriptGlobals = *(int**)0x1849AEC;"; I wanna research more about this :karmaeater:


NTAuthority
  • NTAuthority

    hell, no, tunnel, no

  • Feroci
  • Joined: 09 Sep 2008
  • European-Union
  • Most Knowledgeable [Technology] 2013
    Best Map 2013 "ViceCityStories PC Edition"
    Contribution Award [Modding]

#9

Posted 08 August 2014 - 01:29 AM

Thank :) but Can you give me the link where you get the information about "static int*& g_scriptGlobals = *(int**)0x1849AEC;"; I wanna research more about this :karmaeater:

The address is the same as the 1.0.7.0 jenksta posted; I personally obtained it from checking the script runtime function in the game and checking the 'global' opcode as documented on GTAModding's SCO page in IDA, but reverse engineering tends to be a fairly complicated subject, although it is rewarding even as an addition to the native game script functionality... it's a bit hard to get into, however, and even harder to explain.

Outside of the address, the turning it into a C++ reference is in order to access it without manually dereferencing this part (C++ references are simply a regular pointer internally -- on common architectures -- except 'automatically' assigned), outside of that it directs to a standard 'array' (as you're using [] dereference syntax, one can fairly call it an array) of integer (and actually floating-point too, but as the variable you need is an integer) values.

byteMe420
  • byteMe420

    Fvck Everything

  • Members
  • Joined: 02 Jul 2014
  • United-States

#10

Posted 08 August 2014 - 06:53 AM

google lena's reversing tutorials if you want to introduce yourself to learning how to find all this stuff

  • lpgunit likes this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users