Page 4 of 8

Re: SCR decompiler

Posted: 23 Oct 2011, 08:33
by Sektor
I'll use this to make a version of ManDang's Water Town with more tanks, better arrow colours and 6 player support. Rocket Wars 4 Ever needs starting positions changed so it doesn't crash with more than 2 players. Rocket Wars/Rocket Wars Forever need support for more than 4 players.

Months ago, I tried to contact the authors to get the mis files or get them to fix the maps themselves but no reply.

Re: SCR decompiler

Posted: 23 Oct 2011, 12:09
by T.M.
nice.

i was thinking to make a function in my editor which will go through all the maps that doesnt have .mis file, and then decompile the .scr for those maps. but only after i have finished all the functions (if/else etc. can wait)

Re: SCR decompiler

Posted: 23 Oct 2011, 18:41
by T.M.
Finished the rest of the functions; total 250 functions supported now! CRAZY. and 2500 lines of code in the scr_functions.h lol.

Here is ste.scr decompiled again:
http://pastebin.com/Sn8HFiWi

Theres not much more to do than the if/else/functions etc. for the decompiler!

Later, I will do all of the boolean functions that returns a value inside IF's. (although, when i print them, i think they will make compiler error because they should be inside IF's, not sure though).

Re: SCR decompiler

Posted: 24 Oct 2011, 22:10
by T.M.
WOW, just finished START_BONUS_CHECK, this was the most bitchiest function ever!

Code: Select all

struct SCR_START_BONUS {
	SCR_CMD_SHORT_FORMAT(
		Uint16 unk1;
		Uint16 zonename;
		struct {
			Uint8 is_chartype:1;
			Uint8 is_gangtype:1;
			Uint8 unk2:6;
		};
		Sint8 remap;
		Uint8 count;
		Uint8 exclusive;
		union {
			Uint16 gangname;
			Uint16 occupation;
			Uint16 target_model;
		};
		Uint16 time;
		Uint16 car_model;
		Uint32 score;
		Uint16 varname;
		Uint16 by_weapon;
	);
};
string read_START_BONUS(FPStruct &params){
	get_data(SCR_START_BONUS, data);
	string zonename = (data.zonename == 0xFFFF) ? "NO_ZONE" : get_scr_string(data.zonename);
	string extra1;
	string type = data.is_chartype ? "CHAR" : "CAR";
	if(data.is_gangtype){
		extra1 = (data.gangname == 0xFFFF) ? "NONE" : get_scr_string(data.gangname);
	}else{
		if(data.is_chartype){
			extra1 = (data.occupation == 0xFFFF) ? "NONE" : SCR_OCCUPATIONS[data.occupation];
		}else{
			extra1 = (data.target_model == 0xFFFF) ? "NONE" : SCR_CARS[data.target_model];
		}
	}
	string lastparams;
	if(params.type == SCRCMD_START_BONUS1){
		lastparams = extra1;
	}else if(params.type == SCRCMD_START_BONUS2){
		lastparams = extra1 + ", NONE";
	}else if(params.type == SCRCMD_START_BONUS3){
		string remap = (data.remap == 0xFE) ? "NONE" : sprintf_str("%d", data.remap);
		lastparams = extra1 + ", " + remap;
	}
	string car_model = (data.car_model == 0xFFFF) ? "NONE" : SCR_CARS[data.car_model];
	return sprintf_str("%s = START_BONUS_CHECK (%s, %d, %d, %u, %s, %s, %s, %s, %s)", 
		getname(data.varname).c_str(), zonename.c_str(), data.time, data.count, data.score, type.c_str(), 
		SCR_EXCLUSIVE[data.exclusive].c_str(), SCR_KILLED_BY[data.by_weapon].c_str(), car_model.c_str(), lastparams.c_str()
	);
}
LinkToFunc(SCRCMD_START_BONUS1, read_START_BONUS);
LinkToFunc(SCRCMD_START_BONUS2, read_START_BONUS);
LinkToFunc(SCRCMD_START_BONUS3, read_START_BONUS);
As you see, lots of if's and stuff, bitpacked crap etc. was very hard to put it together.

--

I also finished all the boolean functions, and all comparision functions like "counter1 = (counter2 * 5)", and custom functions; which was a bitch to do as well, i have to parse the file TWICE now, since the FORWARD commands are not stored in the SCR at all!! so now i scan all custom functions, make list of them and stick them at beginning of .mis file. I also noticed the MAP_ZONE is bugged atm, it should take the zone names from the strings array in end of SCR file, i'll fix it later.

Currently total 369 commands done! This means theres only 77 more commands to add to finish the compiler! Except i think theres a lot of unused commands too, and those which are left are just if/else/while etc structures, i think.

Here is once again the ste.scr decompiled a bit more:
http://pastebin.com/hLTnit53
You can see theres not much more to decompile than those IF_JUMP's :D

I added "// cmd: " in end of each known line (unknown lines have the value in the hex data (third value from left)) so its easier to figure out the IF's etc.

Re: SCR decompiler

Posted: 25 Oct 2011, 02:34
by Pyro
Wow, very nice indeed! Very awesome seeing a decompiled ste.scr coming along! :shock:

Just a few questions though on the ste.scr (nothing bad I promise! :P ):
  • I'm guessing the FORWARD names are not actually 'function1:', 'function2:' etc but I could be wrong. Only reason why I think this is because of the bil.mis we have with the compiler, but perhaps bil.mis was re-done to look like it is now by the programmer? Finally, since there were different people coding each city/level they might have their own way of doing things? But then looking at the rest of the decompiled script I wonder if it really is called 'function1:' etc!
  • The map zones in script are all called 'zone1', 'zone2' but in the actual ste.gmp (map) they are labelled 's01', 's02' and so on, and these are linked to the GXT file so they show the proper zone names and are also linked to audio/police radio (so when you stand in Zaibatsu Village, the zone name appears as 'Zaibatsu Village' and if you have a wanted level it'll say you are in 'North Zaibatsu Village' for example. In the script calling them zone1 would not link it to the actual zone name in the map itself. Take a look at bil.mis to see what I mean with zone names vs the names inside the map.
  • Lines 420 to 466 are all blank, I'm guessing these are some of the 77 commands that haven't been added yet?
  • The 'DO_EASY_PHONE' should be 'DO_EASY_PHONE_TEMPLATE' and 'PHONE_TEMPLATE' should be 'DO_PHONE_TEMPLATE', but guessing this is also on your list of commands to do (judging by random numbers etc in the function)?
  • There is no command called 'IF_JUMP', but I'm wondering if these are the actual IF/ELSE/WHILE stuff instead? Assuming so judging by the commands that go before them.
  • Seems that whoever wrote the initial ste.scr has stuff all over the place! :shock: Not as tidy as bil.mis anyway :P Again, either different ways of writing code between people or bil.mis was made nicer looking afterwards to be attached with script compiler.
Other than that, excellent stuff! 8-)

Re: SCR decompiler

Posted: 25 Oct 2011, 12:33
by T.M.
Thanks! im as excited as you are :shock: it seems this can be decompiled pretty easy after all.
Pyro wrote:I'm guessing the FORWARD names are not actually 'function1:', 'function2:' etc but I could be wrong. Only reason why I think this is because of the bil.mis we have with the compiler, but perhaps bil.mis was re-done to look like it is now by the programmer? Finally, since there were different people coding each city/level they might have their own way of doing things? But then looking at the rest of the decompiled script I wonder if it really is called 'function1:' etc!
As the variables, neither functions names can be known, so i have to generate my own names, i just happen to chose "function" prefix:

Code: Select all

string read_FUNCTION(FPStruct &params){
	return sprintf_str("%s:", setgetfuncname("function").c_str());
}
Will generate "function5:" etc.
Pyro wrote:The map zones in script are all called 'zone1', 'zone2' but in the actual ste.gmp (map) they are labelled 's01', 's02' and so on
I explained this earlier actually: there was a bug, and im generating my own names istead of taking them from strings array at end of file (where they store the real zone names). I will fix this later!
Pyro wrote:Lines 420 to 466 are all blank, I'm guessing these are some of the 77 commands that haven't been added yet?
All "(0)" commands means nullpointer: it has multiple purposes, and i noticed that also the FORWARD commands generates nullpointers. nullpointers have no data, it is the first pointer in the script and it points into garbage data of 8 bytes which doesnt make any sense so far, and we think its actually just garbage. Why it is "0" reason here:

Code: Select all

#define SCRCMD_0 0 // 0000
#define SCRCMD_1 1 // 0100
#define SCRCMD_2 2 // 0200
#define SCRCMD_3 3 // 0300
#define SCRCMD_4 4 // 0400
#define SCRCMD_PLAYER_PED 5 // 0500
#define SCRCMD_CHAR_DEC 6 // 0600
#define SCRCMD_CHAR_DECSET_2D 7 // 0700
...
Which i also compile into a strings array separately and slightly differently for first 5 items:

Code: Select all

string SCR_COMMANDS[] = {
	"(0)", "(1)", "(2)", "(3)", "(4)", "PLAYER_PED", "CHAR_DEC", "CHAR_DECSET_2D", 
	...
};
So command 0 will return "(0)" as its the zero'th index. This array could be ANYTHING, but Vike managed to get this array from the compiler, and they match quite closely to the function names, its only as a reference to understand what kind of command there is. And the most important part is: when i add support for that yet unknown command, i will just copypaste the (wacky) name into:

Code: Select all

LinkToFunc(SCRCMD_*here*, read_*and sometimes here*);
With these predefined constants it makes it much clearer later when i do IF's such as:

Code: Select all

string read_SAVED_COUNTER(FPStruct &params){
	get_data(SCR_SAVED_COUNTER, data);
	if(params.type == SCRCMD_COUNTER_SAVE){
...
So, i dont have to lookup for any numbers in any arrays to get an idea what that IF is actually doing, and also its less error prone since i cant write those predefined constants wrong or i get compiler error, whereas you could make error and type if(s == 551) when you meant if(s == 51) etc. (command 551 doesnt exist!). And its much harder to type wrong string since all the strings are so different, which makes you spot the error much faster if you happen to type (or copypaste) it wrong.
Pyro wrote:The 'DO_EASY_PHONE' should be 'DO_EASY_PHONE_TEMPLATE' and 'PHONE_TEMPLATE' should be 'DO_PHONE_TEMPLATE', but guessing this is also on your list of commands to do (judging by random numbers etc in the function)?
The unknown command names arent the same as the function names in .mis scripts! For example command for "SET c1 = (c2 + 10)" equals to "S_IS_S_PLUS_I" because #define's can have only "a-z_" chars. But ive done that command already so it doesnt appear in the decompiled script anymore. And yes, those phone templates arent done yet, i will do them later among other commands!
Pyro wrote:Seems that whoever wrote the initial ste.scr has stuff all over the place! :shock: Not as tidy as bil.mis anyway :P Again, either different ways of writing code between people or bil.mis was made nicer looking afterwards to be attached with script compiler.
Im not sure what you mean, but its only matter of code formatting, and there is no way of knowing the empty space and comments from SCR files so it must be all done line after line. Just remember: every variable name WILL be generated by my decompiler, except: zonenames, trainplatformnames(arent these zonesnames?), gangnames and missionfilenames.
Pyro wrote:Other than that, excellent stuff! 8-)
Thanks 8-)

Re: SCR decompiler

Posted: 25 Oct 2011, 12:47
by T.M.
While i was working on this i found some commands that werent in the documents at all:

Code: Select all

EXPLODE_SMALL (auto3)
EXPLODE_NO_RING (auto3)
EXPLODE_LARGE (auto3)
SET_GANGCAR_RATIO(zone3, 12)
SWITCH_GENERATOR(gen1,12) // notice integer value!
but they compile different code in SCR, so there could be some function for those. i didnt test running them in gta2 though.

I also found something weird, probably some ancient remnants of earlier versions of the compiler:

Code: Select all

countername1+10
10+countername2
countername1+countername2
// countername1-10 didnt work! lol!
10-countername2
countername1-countername2
OR are they? can you do like if(countername+10 > 5) ? maybe they are for those... but fucked up is that you cant do if(countername-10 > 5) lol.

Re: SCR decompiler

Posted: 25 Oct 2011, 13:20
by Pyro
Thanks for the replies :-)

To answer one of your questions, train platform names in the script (like 'trak00' in bil.mis) refer to the actual train station platform zone type in the map itself, much like my earlier comment about map zone names in script being linked to zone names in map. So yes, both the script name and map zone name need to be identical for them to work properly (it'll probably crash if you try doing a MAP_ZONE declare with a zone name that doesn't exist in the map itself).

Some of those bits of code you listed in your latest post are actual commands listed in documentation, namely EXPLODE_SMALL, EXPLODE_NO_RING and EXPLODE_LARGE. You are correct though about the SET_GANGCAR_RATIO not being listed in the official documentation (though I have a list of every command the old compiler can recognise, even unlisted ones from documentation). As for the generator, I've always known the SWITCH_GENERATOR command to list the generator name and either ON or OFF, never seen one with an integer value with it. Strange!

According to documentation, you should be able to do different logic on certain counters but I've never really needed to use them for more 'complex' calculations. As for your example, it should be something like IF(countername>=5) countername+10 ENDIF or the likes. As you know, you can throw in NOT's, ELSE, AND, OR and so on. I do know it's rather picky in what order you do things in though :P

Re: SCR decompiler

Posted: 25 Oct 2011, 16:31
by T.M.
Here is the list of commands i havent finished yet.
Only the first list is probably those commands that are still possible to decompile/compile:

// commands that are known in some degree but not implemented yet:

Code: Select all

START_EXEC // not sure what these are.
STOP_EXEC
FOR_LOOP // AFAIK this cannot be compiled.
DO_WHILE // probably same as above, never seen do-while loops.
WHILE
WHILE_EXEC
AND
OR
IF // have no idea what this is, only IF_JUMP seen in output so far.
THEN // for one-liner IF commands
ELSE
GOTO // something to do with loops.
IF_JUMP // seems to be for IF() commands somehow.

// commands not found:

Code: Select all

SEND_CAR_TO_BLOCK
LAST_WEAPON_HIT
SET_CHAR_RESPECT
SAVE_RESPECT
RESTORE_RESPECT
IS_ALARM_RINGING
ROAD_ON_OFF // real name: SWITCH_ROAD, but compiler doesnt recognize it.
S_MINUS_I // "countername-10", but compiler doesnt recognize it.

// commands not found, but are similar to already found ones:

Code: Select all

COUNTER_SET // is not "SET counter1 = 1" etc, already has a command name.
SET // --||--
START_BONUS4 // some combination of START_BONUS_CHECK params, i tried to find it but couldnt!
SET_STATION_4 // possibly remnants of SET_STATION_INFO different parameter options, couldnt find these.
SET_STATION_3 // --||--
SET_STATION_2 // --||--
SET_STATION_1 // --||--
SET_GANG_INFO2 // possibly remnants of SET_GANG_INFO different parameter options, couldnt find these.
MAP_ZONE2 // unknown, MAP_ZONE1 was just MAP_ZONE declaration though. probably remnants again.
SWITCH_GENERATOR3 // remnants again probably, couldnt find.
SWITCH_GENERATOR4 // --||--

// commands unable to compile:

Code: Select all

CREATE_CONVEYOR_2D // conv1 = CREATE_CONVEYOR (...)
CREATE_CONVEYOR_3D // --||--
CREATE_GENERATOR_2D // gen1 = CREATE_GENERATOR (...)
CREATE_GENERATOR_3D // --||--
CREATE_DESTRUCTOR_2D // dest1 = CREATE_DESTRUCTOR (...)
CREATE_DESTRUCTOR_3D // --||--
CHECK_MULT // crashes on compile! real name: CHECK_MULTIPLIER_GREATER

// commands that doesnt compile any valid SCR output:

Code: Select all

FORWARD_DECLARE // real name: "FORWARD funcname:", compiles into nullpointer (it has many meanings, useless).
PLAY_SOUND // real name: PLAY_SOUND(soundname, X.x, Y.y, Z.z) (undocumented!) doesnt produce any SCR output!

--

NEW COMMANDS!!
While going through these unfinished commands, i found out few functions that werent documented at all!

Code: Select all

SEND_CHAR_FOOT   // real name: SEND_CHAR_ON_FOOT(charname, X.x, Y.y, Z.z) 
SEND_CHAR_CAR    // real name: SEND_CHAR_BY_CAR(charname, X.x, Y.y, Z.z) 
ADDSCORE_NO_MULT // real name: ADD_SCORE_NO_MULT(playername, value) 
GROUP_IN_AREA    // real name: IS_GROUP_IN_AREA(charname, X.x, Y.y, Z.z, W.w, H.h)
There were few other commands that werent documented, i think, but i forgot which. And also i found some other commands that didnt produce any compiler output, forgot those too.


I also found out that:

Lights seem to have 3 optional params at end of it: (not documented)

Code: Select all

LIGHT light2 = (200.50, 125.50, 2.00) 2.00 255 (255, 255, 255)
Gangcar ratio seems to be optional parameter: (not documented)

Code: Select all

MAP_ZONE zone1 = (600, 300, 200, 100, 200, 100, 100, 50, 200, 300)
Those both had own SCR command.

--

Has anyone got working "CHECK_MULTIPLIER_GREATER (playername, 0)" command? to me it makes compiler crash! or is there different name for that function?

SWITCH_ROAD isnt recognized by compiler at all, or is the alternative name for this? couldnt find myself.

Re: SCR decompiler

Posted: 25 Oct 2011, 17:35
by Sektor
ADD_SCORE_NO_MULT is in the docs as:

* ADD SCORE NO MULT
This is a variation of the standard 'add score' command, except it ignores the multiplier.

SWITCH_ROAD doesn't work. I don't think there is any other name for it.
CHECK_MULTIPLIER_GREATER crashes the compiler.

SEND_CHAR_ON_FOOT/SEND_CHAR_BY_CAR compile but they don't appear to do anything. They must just be leftovers before they were replaced with SET_CHAR_OBJECTIVE (GOTO_AREA_ON_FOOT/GOTO_AREA_BY_CAR).

Re: SCR decompiler

Posted: 26 Oct 2011, 10:08
by T.B.
@T.M.
// commands that are known in some degree but not implemented yet:

START_EXEC // not sure what these are.
STOP_EXEC
FOR_LOOP // AFAIK this cannot be compiled.
DO_WHILE // probably same as above, never seen do-while loops.
WHILE
WHILE_EXEC
AND
OR
IF // have no idea what this is, only IF_JUMP seen in output so far.
THEN // for one-liner IF commands
ELSE
GOTO // something to do with loops.
IF_JUMP // seems to be for IF() commands somehow.

Have been a little busy lately but yesterday I took a look at the IF..ELSE..ENDIF and I hope the following helps you.
But please note, I checked only with simple (no NOT, AND, OR) IF expressions (variable compared with value), the first being a one level IF statement and the second a two level nested IF statement.

Code: Select all

.mis
COUNTER count = 0
LEVELSTART
IF (count < 100)
  SET_AMBIENT_LEVEL ( 0.5, 10 )
ELSE
  SET_AMBIENT_LEVEL ( 0.9, 10 )
ENDIF

IF (count < 90)
  IF (count < 50)
    SET_AMBIENT_LEVEL ( 0.5, 10 )
  ELSE
    SET_AMBIENT_LEVEL ( 0.9, 10 )
  ENDIF    
ELSE
  IF (count = 100)
    SET_AMBIENT_LEVEL ( 1.0, 10 )
  ELSE
    SET_AMBIENT_LEVEL ( 0.95, 10 )
  ENDIF
ENDIF

LEVELEND
.txt output by compiler

Code: Select all

1 	COUNTER			EXEC 2	0	count 
2 	LEVEL_START			 3	
3 	WORD < INT			 7	count	100	
4 	SET AMBIENT			 8	32768 10 
5 	SET AMBIENT			 8	58980 10 
7 	IF_JUMP				 4	5	FALSE 
8 	WORD < INT			 20	count	90	
9 	WORD < INT			 13	count	50	
10 	SET AMBIENT			 14	32768 10 
11 	SET AMBIENT			 21	58980 10 
13 	IF_JUMP				 10	11	FALSE 
14 	WORD ==INT			 18	count	100	
15 	SET AMBIENT			 21	65536 10 
16 	SET AMBIENT			 21	62256 10 
18 	IF_JUMP				 15	16	FALSE 
20 	IF_JUMP				 9	14	FALSE 
21 	LEVEL_END			 -1	
And some thoughts:

Code: Select all

0000 0000 E8FD 1300

COUNTER (count = 0) 
0100 1500 0200 0100 0000 0000 
               ----      reference to variable 'count'
LEVELSTART
0200 3B00 0300 0000 

IF (count < 100)
0300 5600 0700 0000 0100 6400 word_less_int
this type next       var  val
      
0400 E200 0800 0000 0020 0000 0A00 0000 set_ambient_level
ELSE (no corresponding compiled command)
0500 E200 0800 0000 9939 0000 0A00 0000 set_ambient_level
ENDIF
0700 6200 0400 0000 0000 0500 if_jump
this type next           next
          if true        if false


IF (count < 90)
0800 5600 1400 0000 0100 5A00 word_less_int
IF (count < 50)
0900 5600 0D00 0000 0100 3200 word_less_int
0A00 E200 0E00 0000 0020 0000 0A00 0000 set_ambient_level
ELSE
0B00 E200 1500 0000 9939 0000 0A00 0000 set_ambient_level
ENDIF
0D00 6200 0A00 0000 0000 0B00 if_jump
IF (count = 100)
0E00 5E00 1200 0000 0100 6400 word_equal_int
0F00 E200 1500 0000 0040 0000 0A00 0000 set_ambient_level
ELSE
1000 E200 1500 0000 CC3C 0000 0A00 0000 set_ambient_level
ENDIF
1200 6200 0F00 0000 0000 1000 if_jump
ENDIF
1400 6200 0900 0000 0000 0E00 if_jump

LEVELEND
1500 3C00 FFFF 0000 
So, when compiled
the .mis IF line becomes a comparison command
the .mis ELSE has no corresponding compiled command
the .mis ENDIF becomes IF_JUMP
the .scr comparison commands 'next' points to the IF_JUMP
the .scr IF_JUMP points to the execute_if_true in the 'next' field and to the execute_if_false in the last field
the .scr IF_JUMP execute_if_false points to the line following IF_JUMP if there was no ELSE line in the .mis (this is not seen in the example)

Thus to determine if the IF statement has an ELSE line:
if execute_if_false < this then insert an ELSE before the line indicated by execute_if_false

To deal with nested IF statements I made the decompiling function recursively callable, calling itself after decompiling the IF line and exiting when decompiling the ENDIF line.

Re: SCR decompiler

Posted: 26 Oct 2011, 18:28
by T.M.
I took some time on these IF structures and noticed some things:

It's the other way around: comparison commands becomes IF commands, (i noticed this earlier when i added support for comparison commands).

ENDIF doesnt become IF_JUMP: its actually the comparison command that generates IF_JUMP commands, each comparison command generates their own IF_JUMP, for example if you have "if((var1 = 1) OR (var2 = 2))" it will generate two IF_JUMP commands according to the logic depending if its "OR" or "AND" command between them.

I dont think you can simply just build up a recursive function and be done with this. i might be wrong though (please prove me wrong! :D ), but it seems a bit more trickier than that.

WHILE_EXEC will generate special GOTO command for some weird reason. maybe it will tell GTA2 to go to next frame or something... hard to say. didnt test WHILE loop yet.

I'll take a look at this later, since its the only thing to do anymore: i've finished all commands except these! plus:

I also fixed the MAP_ZONE name bug etc. some fixes with script command parameter strings decompiling incorrect or empty string etc. all fixed now: i ran through all my .SCR files in GTA2 folder, decompiled them and checked if any errors appeared (i added error checking code too). and gladly no errors recorded during decompiling! so it should be all perfect now... SHOULD! you never know, hehe. i also noticed that the trailers actually work even if they were declarations or not: only the 2d version is bugged lol!

Im thinking to write my own compiler soon when this is done, fixing all the stupid bugs etc. possibly make my own syntax too since i hate to write if's like "if((var1 = 5) and (var2 = 6))" instead of: "if(var1 == 5 && var2 == 6)" !! it will be even harder job though: ive never done anything like this before, and tbh i just now start to have a feeling how the binary code in programs is actually executed. ive learnt much from this, im very happy to do this, its interesting at best.

Edit: actually its not just comparison commands that generate IF_JUMP commands: also any function that returns a value (which can be boolean values only, i think) will generate IF_JUMP.

Im still confused about the empty commands there, i think those are just remains from the compiler: maybe there was a command temporarily and it was removed after compiling was finished? i think i could allow larger scripts if i removed all those empty commands between IF_JUMP's and other commands, since the maximum script size is still 65k, if you run out of pointers (max 6k) you can use missions to have more pointers, but they only add up to the base-script, so theres max 65k pointers even if you made million sub-missions there.

Re: SCR decompiler

Posted: 27 Oct 2011, 16:06
by T.M.
While i was trying to figure out these crazy IF structures in dafes map, i started to dream about better format...

Old code: (eww! *creeps*)

Code: Select all

IF ( ( ( ( ( NOT ( CHECK_CHARACTER_HEALTH ( player2 , 0 ) ) ) AND ( NOT ( CHECK_CHARACTER_HEALTH ( player3 , 0 ) ) ) ) AND ( NOT ( CHECK_CHARACTER_HEALTH ( player4 , 0 ) ) ) ) AND ( NOT ( CHECK_CHARACTER_HEALTH ( player5 , 0 ) ) ) ) AND ( NOT ( CHECK_CHARACTER_HEALTH ( player6 , 0 ) ) ) )
	SET_CHAR_OBJECTIVE ( nudebomber1 , KILL_CHAR_ANY_MEANS , player1 )
	SET_CHAR_OBJECTIVE ( nudebomber2 , KILL_CHAR_ANY_MEANS , player1 )
	SET_CHAR_OBJECTIVE ( nudebomber3 , KILL_CHAR_ANY_MEANS , player1 )
ENDIF
New code:

Code: Select all

if(player2.health != 0 && player3.health != 0 && player4.health != 0 && player5.health != 0 && player6.health != 0){
	SET_CHAR_OBJECTIVE(nudebomber1, KILL_CHAR_ANY_MEANS, player1)
	SET_CHAR_OBJECTIVE(nudebomber2, KILL_CHAR_ANY_MEANS, player1)
	SET_CHAR_OBJECTIVE(nudebomber3, KILL_CHAR_ANY_MEANS, player1)
}
Now isnt that nice? 8-)

Re: SCR decompiler

Posted: 27 Oct 2011, 16:45
by Pyro
I don't mind the current way, it's a bit fiddly for the larger IF stuff but easy enough once you know how to do it. Colour coded tags would be nice like in B-$heps editor and makes this easier anyway. Anyone doing GTA2 scripting would use the current coding methods anyway unless you fancy writing an entire new documentation of every command to follow your new syntax :P

I honestly don't think it's needed for a new way of doing it seeing how old this is and how limiting it can be with commands, and as you've noticed too commands that don't work. Probably too much work to build a new compiler that will convert your idea/style into old style that's accepted by scr files for GTA2 to run.

Re: SCR decompiler

Posted: 27 Oct 2011, 16:59
by T.M.
Well, if i manage to make my own compiler, it means i wouldnt be limited only to one type of syntax, and once i have made the compiler i certainly dont want to use that shitty syntax for it :D i could even support two syntaxes, it could be achieved by #version directive at the first line of script; old compiler refuses to compile if # mark is found (if its not #ifdef etc). so it should be safe. And once i can support two formats i would eventually start making it more elegant, so it would end up doing: "if(player1.health != 0)" etc. and you could even choose to convert the new script into old format or other way around :-) and also from SCR -> MIS ;-)

The changes in the format wouldnt be that huge, it should be quite obvious how it works without looking at any special documents (not that i wouldnt make those, not a big job since the format wont change much, it would just become more obvious format and reduce the use of braces everywhere etc), and not all functions would be converted into "player.health" style since calling a function is much tighter in some cases. probably only 1 and 2 parameter functions should be done like that.

edit: The process for compiling a command back to SCR bytecode is super easy now: i already know all the datatypes, and the format of the commands: all i need to do is to reverse the process, and that shouldnt be a problem at all. I can already modify scripts directly from SCR data by just typing "data.remap = 5;" etc. and then i just save the whole script data into the SCR file it came from. The biggest problem with writing the compiler is the (flexible) syntax parser (with limits to the mis scripting). i have no idea how to do it yet. But once i have finished the decompiler completely, then it should be much clearer to me.

Re: SCR decompiler

Posted: 27 Oct 2011, 20:13
by B-$hep
So you're gonna create new MisPad (ScriptPad) also?
Fuck it. Im gonna stop all of my projects for GTA2 community.


It's pointless to do anything, if one guy just takes over the whole world.
You said to me that your not gonna create full scr decompiler. You still did it (doing).
First map editor, then scr decompiler, now MisPad (ScriptPad).

Good luck to you all guys.

Sektor go and delete my fucking ScriptPad topic.
If anyone wants to contact me, you know where to find me.

Re: SCR decompiler

Posted: 27 Oct 2011, 21:13
by Pyro
I really hope that is overreacting. As I said in last post, a new syntax is not needed for this ancient game and people will see the scripting document with the current code in it and stick to it. You'd only need to do a new syntax if you were to re-build the entire game really to fix the current problems/limitations.

I don't know if you and TM have sent PM's to each other about these things but I thought you guys, especially recently, were doing a combined/joint effort on this script decompiler? Like most things, two head are better than one. Since I don't know much about programming I can only give feedback/suggestions on these things as well as explaining some of the script code or mapping stuff GTA2 uses, hence I really appreciate what you guys are doing.

Apart from the slight hiccup with that minor Delphi compile virus attached to your Script Pad recently, I did try out earlier ones and I absolutely love the colour-coded syntax highlighting and bracket colour coding too and I've always wanted something like that all those years ago. So yeah, I hope you don't actually throw all this in the bin as you guys (yourself, TM, Vike and others) have made great contributions/finds on the technical side to this relic of a game that keeps things fresh and alive for mappers/scripters like myself to keep coming back to this.

Re: SCR decompiler

Posted: 27 Oct 2011, 23:59
by elypter
i guess i saw this coming...

i mean unlike in other overcrowded gaming communities here it should be possible to manage to come to an agreement.
It might seem inconvenient to discuss something that you already existing in your mind and to wait for others. I also was rushing some projects in the past but always watched out not to overlook someone.
It's desirable to work on something if you have good ideas and it's going well but this can also have side effects.

Given you have different philosophies of developing you both can yet cooperate better than this.

Re: SCR decompiler

Posted: 28 Oct 2011, 00:30
by T.M.
B-$hep wrote:So you're gonna create new MisPad (ScriptPad) also?
No im not. compiler != scriptpad, yes it uses compiler, you can replace that (ancient) compiler with mine in the future if you want. nothing is preventing you from continuing on scriptpad.. i have no interests on making such editor.
B-$hep wrote:You said to me that your not gonna create full scr decompiler. You still did it (doing).
It was only your fault, it took forever to respond to my PM's, and as i am very curious person, i couldnt just sit on my ass and do nothing. i figured out it pretty quickly and i just wanted to know what you already knew to speed up the process, and to avoid possible errors i had not thought before but which you probably had since you had been working on this for over a year. I repeat: i only asked your help because i thought you actually knew more about it than me, but you didnt. When i got the player positions done, i thought: why not show objects too? after that i couldnt just stop there you know. And while i was progressing, you didnt respond to my requests to work together, you just told you did this and that and never showed any code or attempt for co-operation. So i just continued and thought of doing some progress instead of letting people wait another year until you get anything even barely finished.
B-$hep wrote:First map editor, then scr decompiler, now MisPad (ScriptPad).
I never "took your map editor", that was a project i started long ago without even knowing the existance of your project.

Did you really expect that you can work on some project for over a year and prevent anyone from contributing, just because you started it?

If youre gonna quit everything just because someone else is better, faster or smarter than you at it, then youre never going to get anything done: theres always someone better than you. You seem to think yourself as some kind of epic hacker, but every now and then the reality kicks you in the balls and then this happens.

Re: SCR decompiler

Posted: 29 Oct 2011, 17:07
by Pyro
I just remembered about the project I was doing at making a new ste.mis (for new missions etc - actually called 'ste-new.mis') a while back and just looked at the one you have posted and I'm quite surprised how accurate I got some things by doing it the hard way (like physically going to car parks and noting down the car location, type, colour etc) and others I got completely wrong :P It sure is a handy reference to have!

Did notice the decompiler didn't pick up the garage door coordinates properly. 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:

Code: Select all

DOOR_DATA zaib_door1 = DOUBLE (211,031,3) (211.0,032.0,3.0,2.0,2.0) BOTTOM 0 ANY_PLAYER_ONE_CAR CLOSE_WHEN_OPEN_RULE_FAILS 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA redn_door1 = DOUBLE (053,066,2) (053.0,066.0,2.0,2.0,2.0) LEFT 0 ANY_PLAYER_ONE_CAR CLOSE_WHEN_OPEN_RULE_FAILS 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA scie_door1 = DOUBLE (235,192,2) (236.0,192.0,2.0,2.0,2.0) TOP 1 ANY_PLAYER_ONE_CAR CLOSE_WHEN_OPEN_RULE_FAILS 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA cophq_door = DOUBLE (101,124,2) (101.0,125.0,2.0,2.0,2.0) BOTTOM 0 ANY_PLAYER_ONE_CAR CLOSE_WHEN_OPEN_RULE_FAILS 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA pris_door1 = DOUBLE (035,224,2) (036.0,224.0,2.0,2.0,2.0) TOP 0 ANY_PLAYER_ONE_CAR CLOSE_WHEN_OPEN_RULE_FAILS 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA pris_door2 = DOUBLE (036,229,2) (036.0,230.0,2.0,2.0,2.0) BOTTOM 0 ANY_PLAYER_ONE_CAR CLOSE_WHEN_OPEN_RULE_FAILS 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA scie_door2 = DOUBLE (175,229,2) (175.0,229.0,2.0,2.0,2.0) LEFT 1 ANY_PLAYER_ONE_CAR CLOSE_WHEN_OPEN_RULE_FAILS 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA army_door1 = DOUBLE (236,116,2) (236.0,117.0,2.0,2.0,2.0) BOTTOM 0 ANY_PLAYER_ONE_CAR CLOSE_WHEN_OPEN_RULE_FAILS 0 NOT_FLIPPED NOT_REVERSED
As you can see, I re-named the doors more appropriately and then fixed the door target coordinates (second set of numbers in brackets) as well as change it from ONE_CAR to ANY_PLAYER_ONE_CAR.

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.

Still, nice to see the original ste.mis as a reference, good work as always 8-)