GTAMP.com

Grand Theft Auto Multiplayer
It is currently Sat Oct 20, 2018 2:48 am

All times are UTC




Post new topic Reply to topic  [ 148 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8  Next
Author Message
 Post subject: Re: SCR decompiler
PostPosted: Wed Nov 09, 2011 12:08 pm 
Offline
Boss
User avatar

Joined: Tue Mar 04, 2008 6:51 am
Posts: 1342
Location: GTAMP.com
T.M. wrote:
The compiler starts crying after your script exceeds 45544 bytes

Vike discovered it was 45536 bytes and that is B1E0 in miss2.exe. Change B1E0 to F0FF to increase limit to 61695 bytes. On my test script, the compiler gives an assertion error at more than 56332 bytes but that's still better than 45536.

Official compiler with those bytes changed: http://gtamp.com/GTA2/gta2script.7z

Scriptpad compatible version here.


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Wed Nov 09, 2011 12:27 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 953
Location: F21B3EED
Sektor wrote:
Vike discovered it was 45536 bytes and that is B1E0 in miss2.exe. Change B1E0 to F0FF to increase limit to 61695 bytes.
Interesting! 45544-45536 = 8 bytes! and guess what? the first pointer takes 8 bytes of script data! mystery solved: that 8 bytes doesnt belong into script at all, its some sort of header they never get to use.

Sektor wrote:
On my test script, the compiler gives an assertion error at more than 56332 bytes but that's still better than 45536.
Even MORE interesting!: i had found out earlier that maximum mission script size = 56260, but its tricky to test because i had to use minimal base-script, and the base script size affects on how big mission script you can make, so i think the limit you found is the real limit and that could also be extended!! :mrgreen:

Pyro wrote:
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.
I didnt, only if you make it as a CAR_DATA declaration with 2D coordinates (compiler is buggy and will make trailer with same value as the car model). there are many maps with cars with trailers, nothing bugged in it! unless you place them wrong, probably thats why you havent been able to make them since you have no clue how it looks in game while you write the coords by hands ;)

_________________
My GTA2 related projects:


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Wed Nov 09, 2011 1:41 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 953
Location: F21B3EED
Now i understand why i couldnt find any strings in the exes: JernejL had packed the exes with upx! edit: compiler still slow even after unpacking.

Edit: i noticed the new compiler makes weird error messages: "List index out of bounds (-1)" which appears randomly once i make enough big script, and i have never seen it before! did we break the compiler now? maybe theres some other things to change in the exe?

Attachment:
weirderror.png
weirderror.png [ 6.97 KiB | Viewed 22645 times ]


Edit2: no, that cant be compiler.exe error, its something to do with mispad.exe... maximum lines limited to 2000? :D edit3: nah, tested with more than 2000 lines, something to do with the script size, not lines...

_________________
My GTA2 related projects:


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Wed Nov 09, 2011 9:49 pm 
Offline
User avatar

Joined: Fri Apr 24, 2009 9:43 pm
Posts: 515
Location: Estonia
List index out of bounds is very common error within Delphi apps.
If you use TList's, ListBoxes, Memos and such.

Very easy to "get out of bounds" without enough error checking.

_________________
Always wear safety glasses while programming.


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Thu Nov 10, 2011 4:30 am 
Offline
User avatar

Joined: Wed Mar 17, 2010 4:07 am
Posts: 414
Location: Wales, UK
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. ;-)

_________________


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Thu Nov 10, 2011 12:12 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 953
Location: F21B3EED
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!

_________________
My GTA2 related projects:


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Thu Nov 10, 2011 7:30 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 953
Location: F21B3EED
How should the output IF-structures format be? I looked at the official mission scripts for bil.scr (those that came with compiler) and noticed they used a format similar to:
Code:
IF ((((counter1 = 1)
AND (counter2 = 1) )
AND ((counter3 = 1) OR (counter5 = 1)) )
AND (counter4 = 1) )
   // code here.
ENDIF
When i took some time to think about it, i thought it makes sense: the braces after IF command tells how many checks total that one IF structure has! brilliant! and after the IF command the AND/OR commands will tell how many sub-commands does it have at that line! i added space before the last brace for each line except the first IF because then i can debug and check that the first braces count after AND/OR is same as the braces count at end of that line.

What do you think?

--

Other news: i made indentations (and extra lines padding) for the subroutines, at same time i found out that you can use RETURN command inside WHILE_EXEC loop (and probably for WHILE loop as well), it seems to terminate the loop.
Here is how the indentations look like from decompiled script:
Syntax: [ Download ] [ Hide ]
Using GTA2 Script Syntax Highlighting
THREAD_TRIGGER trigger18 = THREAD_WAIT_FOR_CHAR_IN_CAR (p1, auto60, function18:)
function18:
    START_BASIC_KF_TEMPLATE (trigger18, 4311, auto60, p1, TANK_GUN)
    bonus2 = START_BONUS_CHECK (NO_ZONE, 3600, 30, 0, CAR, NOT_EXCLUSIVE, BY_ROCKET_LAUNCHER, TANK, NONE)
    DO_BASIC_KF_TEMPLATE (bonus2, timer1, 120, onscreen1, savecount107, 30, 4311, p1, LIVES, 1)
RETURN

THREAD_TRIGGER trigger19 = THREAD_WAIT_FOR_CHAR_IN_CAR (p1, auto61, function19:)

function19:
    START_BASIC_KF_TEMPLATE (trigger19, 4312, auto61, p1, CAR_MACHINE_GUN)
    bonus3 = START_BONUS_CHECK (NO_ZONE, 3600, 60, 0, CHAR, NOT_EXCLUSIVE, BY_GUN, JEEP, NO_OCCUPATION)
    DO_BASIC_KF_TEMPLATE (bonus3, timer1, 120, onscreen1, savecount107, 60, 4312, p1, LIVES, 1)
RETURN
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.10

edit: tested mis highlighter.

_________________
My GTA2 related projects:


Last edited by T.M. on Tue Nov 22, 2011 3:32 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Thu Nov 10, 2011 11:16 pm 
Offline
User avatar

Joined: Sat Dec 26, 2009 11:53 pm
Posts: 1099
looks like a good way of displaying statements for me

_________________
yur sa'nok ngeyä


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Fri Nov 11, 2011 8:48 pm 
Offline

Joined: Sat May 16, 2009 6:14 am
Posts: 889
Location: London, UK
Amazing progress; this remains a great community. There's always something new to discover in GTA2!

_________________
GTA5 Race, DM & Capture | GTA2 Levels & Coding | GTA2 YouTube Videos
Gran Turismo 6 custom track club(Sign in with PSN details, then follow link again.)


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Sat Nov 12, 2011 12:32 pm 
Offline
User avatar

Joined: Fri Apr 24, 2009 9:43 pm
Posts: 515
Location: Estonia
T.M i have messed with compiler construction tools in few months ago. I wanted to make my own simple language toy compiler, but pretty much lost my interest.

You could use few tools to make the task easier. Many of them will generate wrapper fro different languages, including C / C++.

Pretty popular is Gold Parser Builder:
http://goldparser.org/

It's free and i recommend you to use latest version 5.x not the 4.x
It makes writing compiler alot easier. It does alot of work for you, which would be pretty difficult and boring to make by yourself.

Anyway, spend some time on the webpage, read the faq and stuff.
If you have some questions not answered in webpage, you could ask me also.
I will try to help you. I have messed with GPB pretty alot.

Another is ANTLR.
http://www.antlr.org/

Don't know much about it, but it seems more complicated. Im not sure.
I didn't like it.

_________________
Always wear safety glasses while programming.


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Sun Nov 13, 2011 1:47 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 953
Location: F21B3EED
I managed to make CHECK_MULTIPLIER_GREATER work by hacking the SCR file!

At least i think so, here is the script i used:
Code:
PLAYER_PED p1 = (102.0, 218.5, 255.0) 12 90
CHAR_DATA chr1 // if referred at, the value is 2 in SCR.
counter done = 0

LEVELSTART

while_exec(done = 0)
    if(CHECK_HEADS_GREATER(p1, 1))
        ADD_MULTIPLIER (p1, 1)
    endif
    if(CHECK_CHAR_BEEN_PUNCHED_BY(p1, chr1)) // CHECK_MULTIPLIER_GREATER (p1, 2)
        kill_char(p1)
    endif
endwhile

LEVELEND

then i searched for the SCR code of CHECK_CHAR_BEEN_PUNCHED_BY and replaced with CHECK_MULTIPLIER_GREATER code which is "C400" in hex. and when i got my heads greater than 1, i started to die! so i guess it worked.

Its almost like they first made support for all the commands in GTA2 and then wrote the compiler to generate those codes, and then they ran out of time or just didnt add support for some commands because they never used them?

_________________
My GTA2 related projects:


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Sun Nov 13, 2011 2:17 pm 
Offline
Boss
User avatar

Joined: Tue Mar 04, 2008 6:51 am
Posts: 1342
Location: GTAMP.com
Not sure if I will ever use CHECK_MULTIPLIER_GREATER but its cool to have more power. I hope you can find some other commands.

gta2.exe was made before miss2.exe and I think they copied a lot of GTA1 code.


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Wed Nov 16, 2011 2:40 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 953
Location: F21B3EED
I noticed (again) that all angles must be in range 0-359 for the compiler (it doesnt even make proper warning for that, just absurd error), but i can hack SCR and put any value i want and GTA2 will use it as expected: result = angle % 360, wonder why they made it so hard lol, there are other values that should be limited to some ranges but those werent limited like the angles were, i guess they got tired of checking them after that :D

I've been fixing the decompiler a bit recently: changed some integer values to be signed instead of unsigned. and some other fixes i forgot... oh and i optimized it slightly too, im not using string arrays anymore since i noticed they added a lot pointless overhead, so im using char arrays instead, this way i got like 80k smaller exe or something like that :S I also optimized the reader a bit: i wont copy the header from each command anymore, instead i take the pointer to it, therefore i also removed the header from each of the structs definitions (gladly i used a macro before so it was really easy to remove). i also extended the header size to 8 bytes from 6 bytes, since now when i know all the commands i am sure it is 8 bytes now, this gave some extra work too: i converted all structs to use same macro, hopefully i didnt create any bugs while doing so.

_________________
My GTA2 related projects:


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Wed Nov 16, 2011 4:55 pm 
Offline
User avatar

Joined: Wed Mar 17, 2010 4:07 am
Posts: 414
Location: Wales, UK
Agree with Sektor - never used the CHECK_MULTIPLIER_GREATER myself but handy to have in some form or another.

With the angles, I've always been surprised that angle 0° for things is actually south rather than north (in GTA2 script, north is 180°) and it's even weirder for phones as they use their own unique angle system, where north for phones is 270°. Not sure why they did that, could be to do with the way the phone sprite in STY is shown. Anyway, I've always used a range between 0°-359°, not sure why anyone would want to enter 360° when it's the same as 0°.

Still, a lot of oddities with some code with things like coordinate types (integer or floating point) and ranges between values. As Sektor said, a lot of code was probably used from GTA1.

_________________


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Thu Nov 17, 2011 12:16 pm 
Offline
Boss
User avatar

Joined: Tue Mar 04, 2008 6:51 am
Posts: 1342
Location: GTAMP.com
T.M, can you please attach the latest decompiler code to the first post? Thanks.


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Thu Nov 17, 2011 3:28 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 953
Location: F21B3EED
What are you going to do with it? If the DLL isnt working: you need to compile both projects with "Multi-threaded DLL (/MD)" setting. Oh and you probably want the function definition too:
Syntax: [ Download ] [ Hide ]
Using C++ Syntax Highlighting
__declspec(dllimport) int decompile_scr(const string &base_script, string &base_script_output, const vector<string> &mission_scripts, vector<string> &mission_scripts_output);
Parsed in 0.005 seconds, using GeSHi 1.0.8.10


I'll add the full source code soon, need to make some final changes...

_________________
My GTA2 related projects:


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Thu Nov 17, 2011 3:41 pm 
Offline
Boss
User avatar

Joined: Tue Mar 04, 2008 6:51 am
Posts: 1342
Location: GTAMP.com
I wasn't going to do anything but I noticed the attached code has no mini_car and Vike wanted mini_car SCR code, to help him find mini_car in the gta2.exe.


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Thu Nov 17, 2011 4:10 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 953
Location: F21B3EED
Oh, here is the struct and comments explain the MINI_CAR:
Syntax: [ Download ] [ Hide ]
Using C++ Syntax Highlighting
struct SCR_CAR_DATA_DEC {
    SCR_CMD_FORMAT(
        Uint16 varname;
        Uint16 unk3;
        SCR_XYZ_f pos;
        Uint16 rot;
        Sint16 remap;
        Uint16 car_id;
        Uint16 trailer_id; // 0xFFFF if no trailer, 0xFFFE if MINI_CAR.
    );
};
Parsed in 0.006 seconds, using GeSHi 1.0.8.10

_________________
My GTA2 related projects:


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Mon Dec 19, 2011 9:31 pm 
Offline
User avatar

Joined: Sat Dec 26, 2009 11:53 pm
Posts: 1099
is there theoretically a way to make a command that allows to declare parked gang cars?

_________________
yur sa'nok ngeyä


Top
 Profile  
 
 Post subject: Re: SCR decompiler
PostPosted: Tue Dec 20, 2011 12:24 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 3:00 pm
Posts: 953
Location: F21B3EED
in theory everything is possible if you have enough time ;)

but in reality: no, vike isnt going to do that, its absurdly complex.

there is no identifier in the SCR code that declares something as gang car and something as parked car, those both are just separate commands:
CREATE_GANG_CAR1
CREATE_GANG_CAR2
CREATE_GANG_CAR3
CREATE_GANG_CAR4
PARKED_CAR_DECSET_2D_STR
PARKED_CAR_DECSET_3D_STR
PARKED_CAR_DECSET_2D
PARKED_CAR_DECSET_3D

anyways, why would you need that ?

_________________
My GTA2 related projects:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 148 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group