Epic GTA2 Script Decompiler (AKA SCR Decompiler)

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
User avatar
Sektor
Boss
Boss
Posts: 1423
Joined: 04 Mar 2008, 06:51
GH nick: Sektor
Location: GTAMP.com
Contact:

Re: SCR decompiler

Post by Sektor »

I split this topic from the original. It would be better if TM attaches files to the first post since they can get lost on the other pages.
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

Pyro wrote:While it correctly shows the door placement, all the checks it needs on how to open the door were all set to 0.0. Fortunately I knew how to correct it and now all the doors in ste are working correctly. Just for reference, here's my code with the updated info of what it should have looked like:
NOOOooooo.... :D you did it wrong... if you set the target width/height to zero it means the trigger will be autogenerated on front of the door! my editor shows it correctly. god damn use it! :D (docs say ALL must be, but ive tested and only w/h must be set to zero!).
Pyro wrote:As you can see, I re-named the doors more appropriately ...
That gives me an idea... maybe the variable names should be padded with zeroes? then its much easier to replace their names since if you try to replace "obj1" it will also replace "obj11" etc. on the other hand, it makes it really fugly: "obj001", well, maybe i could add an option.
Pyro wrote:Also, I noticed a lot of floating points have two decimal places after them (like 127.50). While the game doesn't have a problem with this, but wondering if this is done from the decompiler or the actual person who coded it all those years ago? Just trivial really but I've always used one decimal place myself.
floats arent stored with dots and numbers in any binary files, not even in SCR ;D so instead, its calculated which allows you to have at least 6 decimal precision rougly said (in SCR floats its calculated with: x/16384). I am displaying floats with 2 decimal precision because that is the highest you can use (more precise than that are impractical for anything). and i have really no way of knowing the original precision, unlike from .mis files. sure i could strip off the zeroes from end of the float values, but then it might look dumb if you actually use 2 decimal precision (like the golden-lap map does for the wall objects); some values would be 2 decimals and some 1, in same line of code! then it would look all crazy and unclean :(
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

Sektor, thanks, i still think there should be one thread though, but its hard to have such since only one person can edit the first post. But i guess B-$hep wants to do it alone then... Im just a bit confused of his raging here about stealing his project when he himself said "It's very boring work" -- i did him a favor by doing all that dirty boring work for him... So whats the problem, B-$hep?

I still havent figured out the IF/WHILE things... its still open for anyone to join here, even for you B-$hep! Figure out how to build up the original IF structure, or something that will work equally well with same size of script (if nothing else is possible), and you will get FAME AND RESPECT [respect] 8-)
User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: SCR decompiler

Post by Pyro »

T.M. wrote:NOOOooooo.... :D you did it wrong... if you set the target width/height to zero it means the trigger will be autogenerated on front of the door! my editor shows it correctly. god damn use it! :D (docs say ALL must be, but ive tested and only w/h must be set to zero!).
Ha, you were right - it does indeed work with second set being all 0.0 :shock: I've been so used to putting manual coordinates in for doors (and even bil.mis has coordinates!) since forever. Only noticed in the documentation right now it does say you can put 0.0 for the trigger to do it automatically :oops: Oh well, live and learn, eh? So I wasn't wrong, both are correct ways of doing it :P
T.M. wrote:That gives me an idea... maybe the variable names should be padded with zeroes? then its much easier to replace their names since if you try to replace "obj1" it will also replace "obj11" etc. on the other hand, it makes it really fugly: "obj001", well, maybe i could add an option.
Do you mean change variables like "auto1, auto2... auto9, auto10" into "auto01, auto02... auto09, auto10" (extra 0 before the number if less than 10)? If so, I do it this way myself so I have plenty of choice from 00 all the way to 99 and never needed anything past 100 yet. I think adding two 0's (e.g. auto001) might be a bit overkill, but that's my opinion only.
T.M. wrote:...stuff about floating points with decimal places...
Alrighty, its no problem really. I just personally like having it as one decimal place in floats and it's easy/quick enough to change anyway. 8-)

PS - it seems the ste.scr I have currently doesn't have the Redneck crane fix in it (using Vikes newest/latest gta2.exe - thought it was supposed to come with the fix?). Still, since I'm making a "ste-new.mis" I fixed it in this one. Just a 'simple' case of moving the crane powerup generator up one block (from 4.5,83.5,3.0 to 4.5,82.5,3.0).
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

Pyro wrote:Do you mean change variables like "auto1, auto2... auto9, auto10" into "auto01, auto02... auto09, auto10" (extra 0 before the number if less than 10)? If so, I do it this way myself so I have plenty of choice from 00 all the way to 99 and never needed anything past 100 yet. I think adding two 0's (e.g. auto001) might be a bit overkill, but that's my opinion only.
Yes, actually i thought of calculating the maximum amount of the objects (or other types of stuff) and thus getting how many preceding zeroes there should be. Since i already read the SCR file TWICE because of how functions are saved, this shouldnt add much more complexity into it.
Pyro wrote:PS - it seems the ste.scr I have currently doesn't have the Redneck crane fix in it (using Vikes newest/latest gta2.exe - thought it was supposed to come with the fix?). Still, since I'm making a "ste-new.mis" I fixed it in this one. Just a 'simple' case of moving the crane powerup generator up one block (from 4.5,83.5,3.0 to 4.5,82.5,3.0).
As i said before, im not entirely sure which file this crane fix should be in, this .mis file i generated is from the single player missions (as far as i understand). maybe the fix is in the multiplayer version? multiplayer map showed them fine i think.
User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: SCR decompiler

Post by Pyro »

The crane fix should be in the main "ste.scr" file itself. Not sure what part was fixed, but my method in my mis file is to move the powerup generator by 1 block. Hope this helps.
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

Crap... i dont think i can make the padded variable names, i would have to decompile it twice... while atm i dont really do it twice, i just read subroutine declarations twice. and it gets tricky when i have "shop1" etc for objects as well... i could do this though, but then there would be the same logic twice in different parts of code, and if i change the reader functions a little, i would have to update the other piece of code as well.. and eh.. i dont think its that important anyways, since i think its easiest to replace those variables when you just choose "whole word only" option :D
User avatar
Cuban-Pete
Immortal
Posts: 909
Joined: 29 Jan 2010, 15:03
GH nick: Cuban-Pete

Re: SCR decompiler

Post by Cuban-Pete »

All this talk about compiling, decompiling and hacking makes me wanna start programming again, txt2gta2 still needs some updating, but it's so long ago I worked on it. :-)

Anyway, continue decompiling!
"Mmmm, your eyes are so beautiful."
User avatar
B-$hep
Immortal
Posts: 568
Joined: 24 Apr 2009, 21:43
GH nick: B-Shep
Location: EU

Re: SCR decompiler

Post by B-$hep »

T.M. wrote:Figure out how to build up the original IF structure, or something that will work equally well with same size of script
What do you mean by that?

"with same size of script"?

I probably missed some posts (this topic is getting big).
Always wear safety glasses while programming.
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

Yeah, same size of script, so its still possible to decompile and compile any script without increasing its script size. for example you could use GOSUB command with simple IF commands, i think. but thats rather crappy way of doing it...
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

Damn, i really want to make my own compiler now: the current compiler is REALLY slow! i made the simplest and longest possible script, but its still compiling it as slow as the biggest known map script i have. I just added 5690 DO_NOWT commands + LEVELSTART/LEVELEND (maximum size of script), and you know how long it took? 5 seconds! crazy! what is it doing all that time? i have no idea... it shouldnt take that long.

While i was figuring out the missions, i noticed the mission scripts have 8 byte header:

Code: Select all

3C16 3C16 0030 0000
- the first 2 values is the amount of pointers the base script has (including the useless first zero pointer). both have same value for some weird reason.
- after that comes the size of the mission script commands data.
- then there is just null value which i dont completely understand whats its purpose, i assume its just padding.
- then starts the mission script pointers (max 1536).

conclusions after testing a while:
- maximum base script size = 45544 bytes
- maximum mission script size = 65536-base_script_size, EXCEPT: there is max 1536 pointers! i tried to add max+1 pointers and the last pointer simply didnt appear in the file at all, but the script did get larger! so its possible to make too large mission script and not get notified by compiler that its not going to work in gta2. i also noticed it seems the actual maximum for mission script commands data size = 56260, compiler refused to compile after that size reached. what is weird is mission scripts allow more script data than base scripts! but since they cant have enough pointers that size can never be reached though.

gotta do some more testing:
- checking if all my mission files i have has the same logic in the .scr file first 8 bytes.
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

I noticed that you cant declare trains, gangs, zones or use .mis script names inside the mission scripts .mis code. Reason: .scr files usually store those strings in the end of file, but for missions those arent stored, not even in the base script file, but whats weird that the compiler doesnt say anything is wrong, and it even writes the SCR code for those commands! it even includes a pointer for the strings, which point to nowhere! so this might be a reason why some of your mission scripts havent been working sometimes.

I also noticed the second variable in the 8 byte header in mission scripts is just garbage! it is totally random in every mission file, i happened to be lucky (as usually) and i had the same value there as the first variable had.

I've been working on decompiling the missions now. I decided to make the decompiler as a DLL file: easier to update and work on it from any program. the DLL has one function which takes parameters: base_script, base_script_output, array of mission_scripts, array of mission_scripts_output. You can also edit the prefixes for variable names with global strings like "VARNAME_PLAYER", just change it and the PLAYER_PED variables will have different prefix the next time you call decompile_scr() function. although, i think i shouldnt use globals like that... maybe a function is better for changing those values, or not. i would need two parameters: type and the string to change to... uh. i think variables are just fine! oh and it will also return integer value of error code, zero = success.

I made my editor use that DLL now, and when you load a map without a .mis file, it will automatically decompile the SCR and put it into "data/decompiled/" folder. its pretty nice to be able to see inside any map script! now if i just could decompile the if-structures :roll:
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: SCR decompiler

Post by elypter »

wow, again very nice progress
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. »

Oh yeah, just finished it, works perfectly! Im gladly surprised it worked at the first compile (was coding for long time without the ability to test it, and made tons of changes in the code!). It even allows you to refer in the base script subroutines or variables (which should be possible in gta2 missions too, at least the compiler writes references to those).

Here is some missions decompiled:
http://pastebin.com/ZNypyagZ
http://pastebin.com/S75KkTgc
http://pastebin.com/7JkUAJ6f

Edit: added to pastebin and changed script and added "debug info", using decimal values instead of hex now! and it displays the data for all boolean commands, so you can figure those if-jumps/else's etc they have stored data in there, note: the data part doesnt have the 3 variable header, cmd.this and cmd.next is inside the braces: (this -> next)
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

I tried to increase the maximum script size manually: i wrote few more commands in the file with hex editor. What happened? IT WORKED!

So, the compiler is limiting the max script size on its own! GTA2 still can read scripts with size 65k, we just need to find out how to remove this limitation from the compiler! The compiler starts crying after your script exceeds 45544 bytes (havent been able to test it with byte precision since i have no way of adding only 1 more byte in the script, all commands size in SCR file is 4 bytes blocks, so this number is in 4 bytes precision then!).
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

I was playing around and made this:
Image

Code: Select all

auto1 = CREATE_CAR (100.5, 215.5, 255.0) 1 0 COPCAR TRAIN END
the train will appear after you go inside the copcar. too bad it will crash if:
- it hits some car, it will blow up any car it hits, and blowing up for some reason crashes.
- you or any ped tries to get inside the train.
- you shoot it with flamer or etc, or you blow it up, or shoot it enough to make smoke.
- you press CTRL to release the trailer.

I also found out that MINI_CAR cant be created with CAR_DATA declarations, because the compiler is buggy! i edited the .scr file with hex editor again and set the MINI_CAR value there, and it worked! damn crappy compiler, makes me want to do it myself already!

also fixed some bugs in the decompiler, for example the mini_car, i had ignored it for some reason.
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: SCR decompiler

Post by elypter »

awesome
yur sa'nok ngeyä
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 »

T.M. wrote:I tried to increase the maximum script size manually: i wrote few more commands in the file with hex editor. What happened? IT WORKED!

So, the compiler is limiting the max script size on its own! GTA2 still can read scripts with size 65k, we just need to find out how to remove this limitation from the compiler! The compiler starts crying after your script exceeds 45544 bytes (havent been able to test it with byte precision since i have no way of adding only 1 more byte in the script, all commands size in SCR file is 4 bytes blocks, so this number is in 4 bytes precision then!).
So, it should be limited to 65k because of the two byte pointers; but it's limited to ~45544 bytes by the compiler? And you want me to... coax it into not doing that? ;)
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

Vike the Hube wrote:So, it should be limited to 65k because of the two byte pointers; but it's limited to ~45544 bytes by the compiler? And you want me to... coax it into not doing that? ;)
Yes, but you dont have to if you dont want, just thought it would be interesting to you... i tried to look a little bit in the compiler binary files but i couldnt even find those error message strings! damn i suck at hacking. :oops:
User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: SCR decompiler

Post by Pyro »

Cool stuff.

Did you modify the SCR by hex in any way to make the trailer (well, train in your case) attach to car? Always thought adding trailers to cars normally (via MIS) was bugged and didn't work even using proper cars like a Truck Cab (both versions) and any trailer.

Also noticed that the code for TRAIN actually gives the passenger carriage rather than the powered train itself :P
Post Reply