Epic GTA2 Script Decompiler (AKA SCR Decompiler)

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: SCR decompiler

Post by Pyro »

I know it's a bit lengthy to do a gang car but it isn't that bad all in all. Two (three if you include the gang info which you need anyway) lines is all that's needed so not really fussed over changing it.

[syntax=mis]CAR_DATA zaib_car
...
SET_GANG_INFO (zaibgang,8,PISTOL,SILENCED_MACHINE_GUN,ROCKET_LAUNCHER,3, 68.3,27.5, 2.0,1,VTYPE,2)
...
LEVELSTART
...
zaib_car = CREATE_GANG_CAR (96.5,40.5,2.0) 2 315 VTYPE END[/syntax]

Simples ;-)

PS - TM, any luck with getting true variable names decompiled from, say, map zones correctly? One would guess they were in order in the script anyway (like m01, m02, ,m03... m27 in order) so not too much of a worry overall.
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: SCR decompiler

Post by elypter »

i know it's possible to create them on runtime but if you have too many of them gta2 acts weirdly and randomly deletes cars, even if the player is inside it sometimes and thus causing a crash.

too bad, but if it are only 2 separate single commands there is nothing you can do.
yur sa'nok ngeyä
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

@Pyro, Map zones are already fixed in the decompiler i released with my map editor. It was never about getting "true variable names", that is still impossible, but SCR does store the zone names separately in the file, which i do read now, correctly.
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

User avatar
Vike the Hube
Hitman
Hitman
Posts: 145
Joined: 28 Feb 2010, 22:34
GH nick: vike

Re: SCR decompiler

Post by Vike the Hube »

Thanks TM!
jotab
Mugger
Mugger
Posts: 11
Joined: 23 Jan 2012, 23:08

Re: SCR decompiler

Post by jotab »

T.M. wrote:
Pyro wrote:Just messed about with trailers on cars, and your right about it only working with CAR_DATA (was using PARKED_CAR_DATA previously which doesn't work). Maybe another one to add to list of weirdness. ;-)
Nice, didnt know that! Guess what? I hacked the SCR file again... AND IT WORKS :D LOL so i can make the trailer for those! gta2 supports it but compiler doesnt! damn... who wants me to make the compiler already..? :lol: i do! i start to understand why you guys always use 3d coords btw: because compiler is buggy, some commands works only for cars that have 3d coords etc. :shock: i think i need to find out which commands do that and work around it in my decompiler: atm i just convert 3d to 2d whenever possible, but that might break the scripts after recompile with the bugged compiler. edit: i changed my decompiler to always output 3d coords! too much trouble with all the checks to avoid compiler crashes!
Do create the custom compiler, another step away from half-assed tools from DMA is all good! And write it in a style that you can be confident in releasing, if done it would be a step further into creating a GTA2 clone even if you personally loose interest.

Best regards!
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

I found out that some official maps use EXEC and ENDEXEC script commands! i wonder what they do, but i think i have an idea: maybe they makes all commands between those 2 commands to execute in one frame, like the WHILE_EXEC loop does? so it could ensure that generators all switch on at the same time. or cars would spawn at same time etc. havent tested yet.

This is from downtown SCR decompiled:
[mis]
DECLARE_CRANE_POWERUP (crane2, gen2, 181, 12, 3)
DECLARE_CRANE_POWERUP (crane4, gen1, 239, 249, 3)
LEVELSTART
EXEC
SET_AMBIENT_LEVEL (0.40, 0)
SWITCH_GENERATOR (gen3, ON)
SWITCH_GENERATOR (gen4, ON)
SWITCH_GENERATOR (gen5, ON)
SWITCH_GENERATOR (gen6, ON)
SWITCH_GENERATOR (gen7, ON)
SWITCH_GENERATOR (gen8, ON)
SWITCH_GENERATOR (gen9, ON)
SWITCH_GENERATOR (gen10, ON)
SWITCH_GENERATOR (gen11, ON)
SWITCH_GENERATOR (gen12, ON)
SWITCH_GENERATOR (gen13, ON)
SWITCH_GENERATOR (gen14, ON)
SWITCH_GENERATOR (gen15, ON)
SWITCH_GENERATOR (gen16, ON)
SWITCH_GENERATOR (gen17, ON)
SWITCH_GENERATOR (gen18, ON)
SWITCH_GENERATOR (gen19, ON)
SWITCH_GENERATOR (gen20, ON)
SWITCH_GENERATOR (gen21, ON)
SWITCH_GENERATOR (gen23, ON)
SWITCH_GENERATOR (gen25, ON)
SWITCH_GENERATOR (gen27, ON)
SWITCH_GENERATOR (gen29, ON)
SWITCH_GENERATOR (gen22, ON)
SWITCH_GENERATOR (gen24, ON)
SWITCH_GENERATOR (gen26, ON)
SWITCH_GENERATOR (gen28, ON)
SWITCH_GENERATOR (gen30, ON)
SWITCH_GENERATOR (gen31, ON)
SWITCH_GENERATOR (gen32, ON)
SWITCH_GENERATOR (gen36, ON)
SWITCH_GENERATOR (gen37, ON)
SWITCH_GENERATOR (gen38, ON)
SWITCH_GENERATOR (gen39, ON)
SWITCH_GENERATOR (gen40, ON)
SWITCH_GENERATOR (gen41, ON)
SWITCH_GENERATOR (gen33, ON)
SWITCH_GENERATOR (gen34, ON)
SWITCH_GENERATOR (gen35, ON)
SWITCH_GENERATOR (gen42, ON)
SWITCH_GENERATOR (gen43, ON)
SWITCH_GENERATOR (gen44, ON)
SWITCH_GENERATOR (gen45, ON)
SWITCH_GENERATOR (gen46, ON)
SWITCH_GENERATOR (gen47, ON)
SWITCH_GENERATOR (gen48, ON)
SWITCH_GENERATOR (gen49, ON)
SWITCH_GENERATOR (gen50, ON)
SWITCH_GENERATOR (gen51, ON)
SWITCH_GENERATOR (gen52, ON)
SWITCH_GENERATOR (gen53, ON)
SWITCH_GENERATOR (gen54, ON)
SWITCH_GENERATOR (gen55, ON)
SWITCH_GENERATOR (gen56, ON)
SWITCH_GENERATOR (gen57, ON)
SWITCH_GENERATOR (gen58, ON)
SWITCH_GENERATOR (gen59, ON)
SWITCH_GENERATOR (gen60, ON)
SWITCH_GENERATOR (gen61, ON)
SWITCH_GENERATOR (gen62, ON)
SWITCH_GENERATOR (gen63, ON)
SWITCH_GENERATOR (gen64, ON)
SWITCH_GENERATOR (gen65, ON)
SWITCH_GENERATOR (gen66, ON)
SWITCH_GENERATOR (gen67, ON)
SWITCH_GENERATOR (gen68, ON)
SWITCH_GENERATOR (gen69, ON)
SWITCH_GENERATOR (gen70, ON)
SWITCH_GENERATOR (gen71, ON)
SWITCH_GENERATOR (gen72, ON)
SWITCH_GENERATOR (gen73, ON)
SWITCH_GENERATOR (gen74, ON)
SWITCH_GENERATOR (gen75, ON)
SWITCH_GENERATOR (gen76, ON)
SWITCH_GENERATOR (gen77, ON)
SWITCH_GENERATOR (gen78, ON)
SWITCH_GENERATOR (gen79, ON)
SWITCH_GENERATOR (gen80, ON)
SWITCH_GENERATOR (gen81, ON)
SWITCH_GENERATOR (gen82, ON)
SWITCH_GENERATOR (gen83, ON)
SWITCH_GENERATOR (gen84, ON)
SWITCH_GENERATOR (gen85, ON)
SWITCH_GENERATOR (gen86, ON)
SWITCH_GENERATOR (gen87, ON)
SWITCH_GENERATOR (gen88, ON)
SWITCH_GENERATOR (gen89, ON)
SWITCH_GENERATOR (gen90, ON)
SWITCH_GENERATOR (gen91, ON)
SWITCH_GENERATOR (gen92, ON)
SWITCH_GENERATOR (gen93, ON)
SWITCH_GENERATOR (gen94, ON)
SWITCH_GENERATOR (gen95, ON)
SWITCH_GENERATOR (gen96, ON)
SWITCH_GENERATOR (gen97, ON)
SWITCH_GENERATOR (gen98, ON)
SWITCH_GENERATOR (gen99, ON)
SWITCH_GENERATOR (gen100, ON)
SWITCH_GENERATOR (gen101, ON)
SWITCH_GENERATOR (gen102, ON)
SWITCH_GENERATOR (gen103, ON)
SWITCH_GENERATOR (gen104, ON)
SWITCH_GENERATOR (gen105, ON)
SWITCH_GENERATOR (gen106, ON)
SWITCH_GENERATOR (gen107, ON)
SWITCH_GENERATOR (gen108, ON)
SWITCH_GENERATOR (gen109, ON)
SWITCH_GENERATOR (gen110, ON)
SWITCH_GENERATOR (gen111, ON)
SWITCH_GENERATOR (gen112, ON)
SET_DIR_OF_TV_VANS (159.00, 137.00)
GIVE_CAR_ALARM (auto1)
GIVE_CAR_ALARM (auto2)
GIVE_CAR_ALARM (auto3)
GIVE_CAR_ALARM (auto4)
GIVE_CAR_ALARM (auto5)
GIVE_CAR_ALARM (auto6)
GIVE_CAR_ALARM (auto7)
GIVE_CAR_ALARM (auto8)
GIVE_CAR_ALARM (auto9)
GIVE_CAR_ALARM (auto10)
GIVE_CAR_ALARM (auto11)
GIVE_CAR_ALARM (auto12)
GIVE_CAR_ALARM (auto15)
GIVE_CAR_ALARM (auto20)
GIVE_CAR_ALARM (auto24)
GIVE_CAR_ALARM (auto30)
GIVE_CAR_ALARM (auto29)
GIVE_CAR_ALARM (auto34)
GIVE_CAR_ALARM (auto40)
GIVE_CAR_ALARM (auto17)
GIVE_CAR_ALARM (auto19)
GIVE_CAR_ALARM (auto21)
GIVE_CAR_ALARM (auto41)
GIVE_CAR_ALARM (auto42)
GIVE_CAR_ALARM (auto22)
GIVE_CAR_ALARM (auto25)
GIVE_CAR_ALARM (auto38)
GIVE_CAR_ALARM (auto28)
ENDEXEC
LEVELEND
[/mis]
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: SCR decompiler

Post by elypter »

thats what i thought in the beginning already but i didnt test anythign yet
yur sa'nok ngeyä
User avatar
Lantyz
Psycho
Psycho
Posts: 71
Joined: 14 Apr 2009, 08:20
GH nick: Lantyz
Location: The Netherlands
Contact:

Re: SCR decompiler

Post by Lantyz »

EXEC lets GENERATORs create a weapon in singleplayer right after the game starts, in stead of after the minimum delay. In multiplayer, GENERATORs do this by default. I always wondered why weapon respawns behave differently in single- and multiplayer, and whether there would be a clean workaround. Turns out there is, thanks for finding!
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

Has anyone tried to make the if/while structures yet, now when i gave all the code? Where is that T.B. guy anyways? He seemed to be interested in this.

I was thinking this decompiling for if/while structures again, and i got creeps from thinking that it might be impossible, because if the compiler is bugged (which it is), it would produce code that doesnt have any meaningful structure, for example a code such as:
[mis]
if(lol = 5)
if(wtf = 6)
do_nowt
endif
else
do_nowt
do_nowt
endif
[/mis]
Might be compiled & decompiled back to:
[mis]
if(lol = 5)
do_nowt
if(wtf = 6)
do_nowt
do_nowt
endif
[/mis]
Which then again is not valid mis code. At least this is the impression i got last time when i looked at the compiled scripts bytecode, there seemed to be some illogicalities with the structures such as that, some else's were missing completely or endif's, or something like that.

I dont have time for this myself, maybe some of you have? I have some thoughts/finds about this decompiling in the last lines of scr_functions.h file if someone wants to take a look.
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: SCR decompiler

Post by elypter »

i dont think it is a problem if code that doesnt work as scr because the compiler is bugged cannot be decompiled correctly
yur sa'nok ngeyä
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

elypter wrote:i dont think it is a problem if code that doesnt work as scr because the compiler is bugged cannot be decompiled correctly
God knows how many scripts there are which works, correctly, but when decompiled, doesnt. Because GTA2 allows these bugs to be there, they might not be found yet, until decompiling. So im not sure how useful the decompiler will be, if there is a lot of scripts like that, if not all :lol:
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: SCR decompiler

Post by elypter »

that bugged else structure doesnt work in game. i avoid "else" most of the time because of that. there is no working map that uses this structure. so at least you dont have to worry about this one
yur sa'nok ngeyä
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

elypter wrote:that bugged else structure doesnt work in game. i avoid "else" most of the time because of that. there is no working map that uses this structure. so at least you dont have to worry about this one
What i meant was that GTA2 doesnt whine about it, it lets it "work", but the way it works is something different than the code says, for example you might code something and test the map and notice it works just fine, because you actually made mistake in the code, and the result was what you were looking for, by just your luckyness.

For example the else bug, i dont think i noticed it immediately, but after deep testing, i saw there wasnt all right. Sometimes you might code something so complex that it requires a lot of testing to actually notice such a bug.
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: SCR decompiler

Post by elypter »

oh, ok, these cases cannot be handled correctly then. but fortunately those are very very rare. i cant think of any existing map.
yur sa'nok ngeyä
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

I will be doing a full documenation on the SCR file format in here:
http://gtamp.com/forum/viewtopic.php?f=4&t=560&p=6750
Jones
Psycho
Psycho
Posts: 51
Joined: 08 Aug 2012, 21:25

Re: SCR decompiler

Post by Jones »

I think there is an error in src_commands.h:

Code: Select all

#define SCRCMD_SET_GANG_INFO1 223 // DF00
#define SCRCMD_SET_CHAR_MOM_FAT 448 // DF00
...
#define SCRCMD_MAX_COMMANDS 447 // in case needed.
Forgotten test code or easter egg? :lol:
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

:mrgreen: shh.

How did you find it? Anyways, you won the free invisible teddy bear. Congratulations!

To be honest, I didnt expect anyone to find it ever. ;-)
Jones
Psycho
Psycho
Posts: 51
Joined: 08 Aug 2012, 21:25

Re: SCR decompiler

Post by Jones »

I was curious how the gang (zone) variables got compiled, because the value of the gang name/reference itself (first parameter of SET_GANG_INFO) is without meaning. First I looked into hex dumps of the src and used your command list, but afterwards I found your documentation about strings more helpful. So I searched for the hex value of SET_GANG_INFO in your list and found your joke in doing so. Though needed some time to grasp my finding :D
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: Epic GTA2 Script Decompiler (AKA SCR Decompiler)

Post by T.M. »

Hmm... Its been a whole year from last post? WTF. Time is a bastard. Also, seems like the title has changed magically.

Nobody still got into the if/while things?

I have been doing some silent changes meanwhile, basically thinking how the structures should be represented; one struct per command, or shared structs? I have opened some of the union's into separate structs to make it easier to interpret the structs via another program, which i was also making few months ago, but stopped its development currently; it was supposed to ease up the analyzing and editing of SCR files in binary format.

I dont think i will release my current sources since the changes are minor. I have also renamed some of the "SCRCMD_" enums, and i probably will rename them better in the future (a lot of confusion in the names, 2d name used for 3d commands etc weirdness! (not my fault, lol)).

Oh, and i found "goto" command and its structure was missing from the sources. although, it should not be printed since it is internal command for the loops. Anyways, best to put everything in the sources (at least commented out) if there is some information we have about the SCR format.

[mis]//TWO_PARAMS_LAYOUT(GOTO, sprintf_str("GOTO"); // correct struct, but format not figured out yet;[/mis]

BTW, what the hell were the code tags for C++ ?
Post Reply