Page 3 of 3
Re: SCR decompiler
Posted: 09 Aug 2011, 20:34
by B-$hep
Im not sure, because i remember that i upgraded to Delphi 4 or 5 because of some features.
But this one is done in Borland Delphi 3.0.
It even could be wrong because maybe i upgraded from Delphi 2 to Delphi 3.
Dunno... I just don't remember. Almost 3 years ago. Amazing how time flies.
Maybe i upgraded but never actually released that.
Do you want something new? Or bugfix?
I will find the sourcecode and could recompile it and maybe do something with it if you want.
Just tell me.
I actually worked on scr decompiler "behind the scenes" but there is still nothing to show atm.
I understand alot more than previously about SCR file content and the "header" but still it requires a bit more dedication and time. To actually release some better tool.
It's slowly progressing.
Re: SCR decompiler
Posted: 09 Aug 2011, 21:38
by Sektor
I just asked because someone wanted a way to change
GTA2 skins.
Re: SCR decompiler
Posted: 05 Oct 2011, 10:08
by B-$hep
Im working on this project again and i wanted you to show some slow progress on it.
It's very small thing but still, im in the right path.
I understand the SCR header and what it stores but i have to make some good data types to organize the stuff i dig out from SCR to parse and do all the MATH more easily.
Here is just one very small example of some "bits" from simple SCR:
The 3,4,5, etc mean the "VARIABLE indexes" but 600, 100, 1212 are the delay values for DELAY_HERE as you can see.
The parser is not very much hard coded for specific SCR any more because i pretty much figured out the calculation for finding right values and stuff.
But as i said, i need to make some good structs and organize it better.
It's very very alpha atm.
But it is interesting challenge and im working on it.
Re: SCR decompiler
Posted: 05 Oct 2011, 12:43
by elypter
wow, it looks awesome already!
Re: SCR decompiler
Posted: 05 Oct 2011, 20:16
by B-$hep
Well thanks. But as i said, it's very basic atm.
If i figure out the data structs to handle the parsed and calculated data with much better and easier way then i can basically decompile simple small scripts without problem.
I start with small first.
What i mean with data structs is that, i must find a good way to store the GTA2 script commands in decompiler (should i use arrays, C++ std::map's or std::vector's) or anything else, how to store the data read from .scr to make calculating and parsing data and commands more flexible. Etc...
But im such guy who first hacks something working together quickly to see some results (which gives alot of motivation) and then makes it better.
Maybe it's because i was cr@cker.
Re: SCR decompiler
Posted: 05 Oct 2011, 22:04
by elypter
i wonder how gta2 does it. most commands have relatively few arguments but there is one crane powerup command that has ~15. if gta2 uses static structs it would waste quite a lot of ram?
Re: SCR decompiler
Posted: 06 Oct 2011, 14:05
by T.M.
I think its nearly impossible to decompile... although you can always try. I just see it as hard as decompiling exe into C++ again. The SCR bytecode probably works same way: "IF" and "ENDIF" are just goto commands, and its quite hard to figure out which are function calls and which are just if commands and etc...
What im interested is to read the player positions from the SCR code, i dont think more can be read, except maybe the declarations of cars. All in all, it will be harder job than my editor which parses the mis file and lets to edit the objects there.
Have you noticed the compiler generates a .txt file by the way? it seems to be uncompressed version of the SCR:
Code: Select all
20 CHAR_DEC EXEC 21 p5_punched
21 PLAYER_PED EXEC 22 (3670016,3538944,458752) 315 15
22 COUNTER EXEC 23 1 p6_expunch
23 COUNTER EXEC 24 0 p6_trg_punched
24 CHAR_DEC EXEC 25 p6_punched
25 GENERATOR DECSET 26 elec_1 (3735552,3735552,458752) 0 203 400 400
26 GENERATOR DECSET 27 fingers_1 (3735552,3473408,458752) 0 236 400 400
27 GENERATOR DECSET 28 elec_2 (3473408,3473408,458752) 0 203 400 400
28 GENERATOR DECSET 29 fingers_2 (3473408,3735552,458752) 0 236 400 400
29 SET GANG INFO 30 high 7241728 7176192 131072
30 MAP_ZONE_SET 31 info_l 500 100 100 100 600 50 50 50 800 50
31 COUNTER EXEC 32 1 control
32 COUNTER EXEC 33 0 psum
33 COUNTER EXEC 34 0 dsum
34 COUNTER EXEC 35 0 osum
35 COUNTER EXEC 36 0 tsum
36 DEC ONSCREEN CNT 37
37 COUNTER EXEC 38 1 loop
38 LEVEL_START 39
39 SWITCH GEN ONOFF 40 elec_1 -1
40 SWITCH GEN ONOFF 41 fingers_1 -1
41 SWITCH GEN ONOFF 42 elec_2 -1
42 SWITCH GEN ONOFF 43 fingers_2 -1
43 WORD ==INT EXEC 347 loop 1
44 SET COUNTER INT EXEC 45 psum 0
45 SET COUNTER INT EXEC 46 dsum 0
46 SET COUNTER INT EXEC 47 tsum 0
47 CHECK HEALTH EXEC 97 p1 0
48 CHAR INVINCIBLE EXEC 49 p1 1
49 GIVE WEAPON EXEC 50 p1 2 99
50 GIVE WEAPON EXEC 51 p1 4 99
51 PUNCHED SOMEONE?EXEC 53 p1
52 WORD ==INT EXEC 55 p1_trg_punched 0
53 IF_JUMP EXEC 52 59 FALSE
54 WORD ==INT EXEC 59 p1_expunch 1
55 IF_JUMP EXEC 54 59 FALSE
I checked and the integer values (after decoded) match 99.99% to the MIS script coordinate float values, and those integers are stored as-is in the SCR file in binary format.
Re: SCR decompiler
Posted: 06 Oct 2011, 18:01
by elypter
loops are difficult but i think they are possible. the result won't be exactly like the original but that's not a problem.
And even if loops are not decompileable you can still make a "//jump to line 45" out of it which would yet help a lot.
Re: SCR decompiler
Posted: 06 Oct 2011, 20:09
by B-$hep
Nothing is impossible. Just takes a time and a dedication.
Re: SCR decompiler
Posted: 09 Oct 2011, 20:31
by B-$hep
I worked whole day on this thing and this is what i got.
This is the SNEAK.MIS script from "PyroGTA2Collection_sorted"
Code: Select all
// GTA2 SNEAKING MISSION //
// this is just a test to see how well a 'Metal Gear Solid' sneaking mission could work out.
// player
PLAYER_PED p1 = ( 132.5 , 127.5 , 2.0 ) 25 0
// characters
// tank destroyers
CHAR_DATA rpg01
CHAR_DATA rpg02
CHAR_DATA rpg03
CHAR_DATA rpg04
// vehicles (pointless in this mission as you get caught!)
PARKED_CAR_DATA tank01 = ( 163.5 , 128.5 , 2.0 ) -1 0 TANK
PARKED_CAR_DATA jeep01 = ( 159.5 , 128.5 , 2.0 ) -1 20 GUNJEEP
PARKED_CAR_DATA jeep02 = ( 166.5 , 129.5 , 2.0 ) -1 250 GUNJEEP
PARKED_CAR_DATA jeep03 = ( 175.3 , 116.5 , 2.0 ) -1 180 GUNJEEP
// sounds
// lights
// weapons (one-off)
OBJ_DATA armour01 = ( 132.5 , 127.5 , 2.0 ) 0 COLLECT_31
OBJ_DATA armour02 = ( 187.5 , 118.5 , 2.0 ) 0 COLLECT_31
OBJ_DATA silencedmg01 = ( 132.5 , 125.5 , 2.0 ) 0 COLLECT_09
OBJ_DATA silencedmg02 = ( 153.5 , 124.5 , 2.0 ) 0 COLLECT_09
OBJ_DATA silencedmg03 = ( 181.5 , 122.5 , 2.0 ) 0 COLLECT_09
// counters
COUNTER neverends = 1
COUNTER intank = 0
LEVELSTART
WHILE_EXEC ( neverends = 1 )
/*IF ( ( IS_CHARACTER_IN_CAR ( p1 , tank01 ) )
AND ( intank = 0 ) )
rpg01 = CREATE_CHAR ( 158.5 , 122.5 , 2.0 ) 4 0 ARMY END
rpg02 = CREATE_CHAR ( 159.5 , 122.5 , 2.0 ) 4 0 ARMY END
rpg03 = CREATE_CHAR ( 170.5 , 122.5 , 2.0 ) 4 0 ARMY END
rpg04 = CREATE_CHAR ( 171.5 , 122.5 , 2.0 ) 4 0 ARMY END
SET intank = 1
ENDIF */
DO_NOWT
ENDWHILE
LEVELEND
This is the decompiled script. Currently just commands, no values.
Just to show where i am atm.
Yes, level_end is missing. I have some weird kind of loop bug in my code.
The loop hangs for some reason and it stops decompiling.
But the result for one day of work is pretty awesome for me. Im very happy.
I have the command values also, but i didn't bother to parse and display it.
Also i have looked how SCR stores WHILE_EXEC etc loops but first i must fix the bug with loop.
So currently
everything is calculated, nothing is hardcoded anymore.
Basically i can supply him any .scr and it will take it apart.
Forget the Lines in mainscript. The calculation is messed up atm.
See ya soon.
Im gonna work on that bug now.
Re: SCR decompiler
Posted: 09 Oct 2011, 21:53
by Sektor
Nice.
Re: SCR decompiler
Posted: 09 Oct 2011, 22:13
by elypter
yeah, great process.
Re: SCR decompiler
Posted: 10 Oct 2011, 01:04
by Pyro
Very nice stuff!
Re: SCR decompiler
Posted: 15 Oct 2011, 14:21
by B-$hep
Thank you guys.
Decompiler is rewritten now from scratch. This fixed alot of problems and code "uglyness".
Some problems still present, but it's just a matter of time.
More nice stuff:
GTA2\data\
Industrial-6P.scr
Code: Select all
PLAYER_PED player1 = ( 129.5, 121.0, 2.0 ) 0 90
PLAYER_PED player2 = ( 41.5, 192.0, 2.0 ) 8 0
PLAYER_PED player3 = ( 166.0, 220.5, 2.0 ) 9 270
PLAYER_PED player4 = ( 199.0, 45.5, 2.0 ) 10 180
PLAYER_PED player5 = ( 44.5, 102.0, 2.0 ) 7 0
PLAYER_PED player6 = ( 242.5, 168.0, 2.0 ) 5 180
ARROW_DATA
ARROW_DATA
ARROW_DATA
ARROW_DATA
ARROW_DATA
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
GENERATOR
CRANE_DATA
CAR_DATA
CAR_DATA
CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
CAR_DATA
CAR_DATA
CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
PARKED_CAR_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
OBJ_DATA
LEVEL_START
SET_AMBIENT_LEVEL
SET_SHADING_LEVEL
PUT_CAR_ON_TRAILER
PUT_CAR_ON_TRAILER
PUT_CAR_ON_TRAILER
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
GIVE_WEAPON
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
SWITCH_GENERATOR
LEVEL_END
Player_ped's with coordinates. Number of players in SCR is not "guessed" anymore, by filename or anything such. But just correctly calculated from .scr info.
There are still some slight problems with bigger scripts, like bil.scr but it's probably a bug in calculation / reading of different stuff.
And not all commands are included, it's very boring work to do continuously.
I just add them once by one, in different times, until all are there.
PLAYER_PED player# is also calculated and variable name is automatically created.
Same will be done for other commands.
Re: SCR decompiler
Posted: 15 Oct 2011, 15:23
by elypter
it looks really good!
if you need some scripts to test specific criteria, you can ask me. i know most maps and which are doing something special in their scripts. you can also browse for scripts on your own if you need something quickly:
http://gta2dare.omnitude.net/maplist/li ... mode=exist just search for .mis
Re: SCR decompiler
Posted: 15 Oct 2011, 16:27
by T.M.
B-$hep, check my PM.
Re: SCR decompiler
Posted: 15 Oct 2011, 17:58
by B-$hep
@T.M done.
If somebody has time and wants to be included in aboutbox, then please clean up this mess:
And make a list of only OBJECTS in "".
Get rid of everything, except dd # and strings in " ".
For ex:
BOXES
4
I need it to be in same order. Nr's are also important, there are some numbers skipped, i dunno, if there are missing objects in GTA2.
I got this list from miss2 and if it's not gonna be in same order then probably decompiler will show wrong object types.
So:
.data:004D5958 off_4D5958 dd offset aBin_lid ; "BIN_LID"
.data:004D595C dd 1
.data:004D5960 dd offset aBollard ; "BOLLARD"
.data:004D5964 dd 2
1
BIN_LID
2
BOLLARD
etc. Skipped numbers should be marked or just left out. Then i will run through list and if there is a skipped number then i will just ignore the object in decompiler.
I could code a little tool with regex to extract the data, but i think im too lazy for that.
Thanks, even if nobody will do that.
EDIT
Did it by myself anyway. Hacked simple parser together quickly.
Im currently just trying to complete the GENERATOR command, only objects are left.
So i can display them as: COLLECT_00 etc in decompiled script.
But this list will be used by other commands also i believe.
edit: Topic split
http://gtamp.com/forum/viewtopic.php?f=4&t=447