Found PED (dummies) walking code in exe

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
Post Reply
User avatar
B-$hep
Immortal
Posts: 565
Joined: 24 Apr 2009, 21:43
GH nick: B-Shep
Location: Finland

Found PED (dummies) walking code in exe

Post by B-$hep »

I decided to make new thread, maybe there is such thread already, then sorry.
You can copy/paste there and delete this.


My primary goal for 2 days (weekend) was to find out where is the code in exe that makes peds move.
I wanted to find this thing for a long time.
And after lots of work and jumping around here and there and finally finding a way to make it faster I found the place where ped walking is controlled.
Hard work paid off finally. At least I can say, I didnt waste 2 days just for nothing.

Of course it's not everything. I found one function thanks to Ghidra + CE + Visual C++.
Immediately saw some interesting patterns in code and decided to change some values.
And yes, it worked. Its the walking code.

My goal is to RE this ped walking logic and recreate it in C++.
Just simple 2D gfx app in 2D mode using some sprites or just circles with arrows (as heads).


I will keep working.
Always wear safety glasses while programming.
User avatar
Pizzadox
Car Jacker
Car Jacker
Posts: 42
Joined: 08 Jul 2015, 17:52
GH nick: Pizzadox
Contact:

Re: Found PED (dummies) walking code in exe

Post by Pizzadox »

yes but it might be a problem because i think its much more complex than that because peds in game have some kinda navmeshes to tell them where they should/shouldnt walk or even drive, i believe it might be a problem to recreate or mimic it because map editor doesnt offer you such options

btw i dont remember how peds/vehicles move or how they find their way around custom maps (maybe its material based?)
i bang hoes
User avatar
B-$hep
Immortal
Posts: 565
Joined: 24 Apr 2009, 21:43
GH nick: B-Shep
Location: Finland

Re: Found PED (dummies) walking code in exe

Post by B-$hep »

I dont think its complicated.
Just move peds forward, check 1 block in advance, what it has. Is it wall, water, or road.
If peds are running scared then they mostly do it randomly etc.
In corners check what directions have pavements and if there are more than one choise, then choose random direction and continue walking..

The logic behind this is not hard.
But there are few good/funny things that im interested in.

Its possible that most of the ped walking is done just in collision code which i have found also.
Whenever they see obstacle 1 block in advance of them or collision sphere radius, then they slowly turn away before reaching them.

Its not hard to code this from scratch but its hard to replicate it 100% to match GTA2 without figuring out GTA2 logic/code.

EDIT:
I think and it seems that GTA2 uses state machine. They use lots of struct fields to change state of peds and game. They are controlled every frame or by some specific time.
If some struct field (state) changes (for example: from PED_WALK to PED_SCARED) then game commands the ped to run away, changes animations, chooses random direction etc..

After some time it returns to normal if he survives and is not chased by main player or something. Each ped has action timer and 3 states or something, cant remember atm.

Kinda neat way the things are organized in GTA2.
In GTA2 demo there is even more stuff left behind. More text and code stuff.
In released game some things changed and stuff got cleaned up a bit.

Noobish way is to use "hundreds" of booleans, ie: if(ped_scared==true) then .. "other BS.
But GTA2 doesnt do that. Just huge structs with all kinds of fields that are changed as needed.
Always wear safety glasses while programming.
User avatar
Pizzadox
Car Jacker
Car Jacker
Posts: 42
Joined: 08 Jul 2015, 17:52
GH nick: Pizzadox
Contact:

Re: Found PED (dummies) walking code in exe

Post by Pizzadox »

B-$hep wrote: 09 May 2022, 15:15 I dont think its complicated.
Just move peds forward, check 1 block in advance, what it has. Is it wall, water, or road.
If peds are running scared then they mostly do it randomly etc.
In corners check what directions have pavements and if there are more than one choise, then choose random direction and continue walking..

The logic behind this is not hard.
But there are few good/funny things that im interested in.

Its possible that most of the ped walking is done just in collision code which i have found also.
Whenever they see obstacle 1 block in advance of them or collision sphere radius, then they slowly turn away before reaching them.

Its not hard to code this from scratch but its hard to replicate it 100% to match GTA2 without figuring out GTA2 logic/code.

EDIT:
I think and it seems that GTA2 uses state machine. They use lots of struct fields to change state of peds and game. They are controlled every frame or by some specific time.
If some struct field (state) changes (for example: from PED_WALK to PED_SCARED) then game commands the ped to run away, changes animations, chooses random direction etc..

After some time it returns to normal if he survives and is not chased by main player or something. Each ped has action timer and 3 states or something, cant remember atm.

Kinda neat way the things are organized in GTA2.
In GTA2 demo there is even more stuff left behind. More text and code stuff.
In released game some things changed and stuff got cleaned up a bit.

Noobish way is to use "hundreds" of booleans, ie: if(ped_scared==true) then .. "other BS.
But GTA2 doesnt do that. Just huge structs with all kinds of fields that are changed as needed.
yes it makes more sense that peds trace one block in advance, i mean in 1999 game development was pretty str8 forward
i think using if(ped_scared) would work very well, in fact they might coded it this way because theres no need for hundreds different checks like that or to overcomplicate stuff, it could be done with less than 10 if()'s/switches, the peds are pretty simple ingame, they didnt over complicated them at all
all what peds do in game is they walk around by checking for obstacles in their way, run away from gunshots or close vehicles, say random silly stuff when you stand close to them, shoot you if they hate you or help you if they love you and infact theres 3 special peds which theyre the most "complicated", one of them steals random vehicles, another one likes to steal money only from you and elvis of course which they trace each other to talk in a single line which breaks if you scare them
seems like theres alot of distance and condition(state) checks ingame which makes most of the stuff work

may i ask you what is the point of reversing the game so hard? haha
i know you cant do such things just for fun, there must be a reason you trying to do whatever you do, you trying to make a clone game?(which is completely cool)
i bang hoes
User avatar
B-$hep
Immortal
Posts: 565
Joined: 24 Apr 2009, 21:43
GH nick: B-Shep
Location: Finland

Re: Found PED (dummies) walking code in exe

Post by B-$hep »

I answer for second part at the moment because I'm busy at work.

Why I reverse, because I love this game.
We played GTA1 in computer class in early 2000. Because our teacher was nice guy and let us play games sometimes too. For me this was new world.
It was very very interesting game. I didn't care about its poor gfx.
Later GTA2 was discovered by me. It was love from first sight.
It was also year 2000 but a bit later.
Got my first PC in 2001 or so at home and saw a GTA2 original CD in computer store.
Bought it immediately without any hesitation.

So I have played GTA2 since then.
GTA1 not so much but it's installed.

I even have my own script compiler and map editor made.
Still developing them
Always wear safety glasses while programming.
User avatar
Pizzadox
Car Jacker
Car Jacker
Posts: 42
Joined: 08 Jul 2015, 17:52
GH nick: Pizzadox
Contact:

Re: Found PED (dummies) walking code in exe

Post by Pizzadox »

B-$hep wrote: 10 May 2022, 04:02 I answer for second part at the moment because I'm busy at work.

Why I reverse, because I love this game.
We played GTA1 in computer class in early 2000. Because our teacher was nice guy and let us play games sometimes too. For me this was new world.
It was very very interesting game. I didn't care about its poor gfx.
Later GTA2 was discovered by me. It was love from first sight.
It was also year 2000 but a bit later.
Got my first PC in 2001 or so at home and saw a GTA2 original CD in computer store.
Bought it immediately without any hesitation.

So I have played GTA2 since then.
GTA1 not so much but it's installed.

I even have my own script compiler and map editor made.
Still developing them
i have noting to say but
respect
i bang hoes
Post Reply