Epic GTA2 Script Decompiler (AKA SCR Decompiler)

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

B-$hep wrote:You asked what i have figured out. basically the stuff you posted.
yes, post them here.
B-$hep wrote:For parameters, i just skipped zero bytes and most of the time i assumed that each parameter is in same order. And most of the stuff is saved in same format.
I changed stuff in scr and looked at the same place again, if something changed there, i wrote it down, that way i figured out the location of current modified parameter in scr
zero bytes arent necessarily useless, some strings are compiled into zero for example. and i noticed in DOOR_DATA the parameters werent in the same order as usually: block coords came first, etc. you can see in my code. i dont think you can figure it out that easily if you just change the parameter, some parameters may take 2 bytes, some may take 1 byte, you have to figure that out too. for example the last param in DOOR_DATA seemed like it was going to be 1byte like the previous, but nah: it takes variable names so it must be 2 bytes, even if i never see it using the other byte, i can guess its 2 bytes.
B-$hep wrote: For ex:
Your last piece of dump:

Code: Select all

CHANGE_BLOCK LID (32, 232, 255) NOT_FLAT NOT_FLIP 0 1 255


BA00 7B00 0000 20E8 FF05 FF00 0000 7B00
BA00 is 186 in decimal, so: GOTO line 186 in list and voila.
i dont understand why you need to go to any line in any file, you see it is CHANGE_BLOCK (lid) already, the BA00 only tells you which command to link with that function (in my c++ code) so i just use my "scr_commands.h" list and search for "BA00" in hex and get the enum for it i created. (i updated the list to have hex value next to it in comments so i can easily get the command enum). theres no point checking if the command is "correct" - of course its correct! you only have to figure out the logic why is it that command. for example in DOOR_DATA it was hard because if you added extra parameter and depending on open_type it changed the command value. theres 6 different commands for DOOR_DATA. you can see the complexity in my code.

how i did it: i opened HxD (nice hex editor) compiled a script, copied the data that was added (i know where the script ends so its easy), then i add more script commands and compile, then i just open HxD again it will automatically refresh the file and remain my selection cursor so i know exactly which place the new data starts now, so i copy that data again and so on. its really easy, no need to lookup any tables or etc.

B-$hep wrote:I worked a damn one year on that crap, and you assume i don't know nothing about it?
where did i say you know nothing about it? i worked for 2 days on this thing and learnt everything you did in 1 year... and im not even a "hacker" as you call yourself.
B-$hep wrote:Why i started working on my compiler then, if i wouldn't know anything about it?
WHAT? thats like saying why learn something if you dont know how to do it already.
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

Holy shit. SET_STATION_INFO is tricky. it seems to store the track names in the "random" byte stream (5120 bytes at end of file). i will add the random stream reading to my code now, since it seems to be in use some way.

Edit: i had something wrong, i was splitting the string arrays from wrong offset, then i found out that there is 2 byte header which tells the array data length in bytes, and more stuff explained:

Code: Select all

AC00 // array data length (172):
trak   ?  type   ?  len:   char array + nullchar (array with lenght-byte length must be divisible by 2 bytes!)
0C00 0000 0A00 0000  07:74 7261 6B32 3200 
0B00 0000 0A00 0000  05:74 7261 6B00 
0A00 0000 0A00 0000  0D:74 7261 6B32 3066 6464 7367 0000 
0900 0000 0A00 0000  07:74 7261 6B31 3300 
0800 0000 0A00 0000  03:74 7200 
0700 0000 0A00 0000  0F:74 7261 6B31 3168 6877 6877 6877 0000 
0600 0000 0A00 0000  07:74 7261 6B31 3000 
0500 0000 0A00 0000  07:74 7261 6B30 3300 
0400 0000 0A00 0000  0B:74 7261 6B30 3268 6168 6100 
0300 0000 0A00 0000  07:74 7261 6B30 3100
.mis script used:

Code: Select all

SET_STATION_INFO (trak01, 1, 2, 255)
SET_STATION_INFO (trak02haha, 4, 5, 258)
SET_STATION_INFO (trak03, 7, 8, 1337)
SET_STATION_INFO (trak10, 10, 11, 12)
SET_STATION_INFO (trak11hhwhwhw, 13, 14, 15)
SET_STATION_INFO (tr, 16, 17, 18)
SET_STATION_INFO (trak13, 19, 20, 21)
SET_STATION_INFO (trak20fddsg, 22, 23, 24)
SET_STATION_INFO (trak, 25, 26, 27)
SET_STATION_INFO (trak22, 28, 29, 30)
EDIT: figured out the first 2 bytes and the "0A00" after it: 0A00 means the datatype or something, 0A00 appears only for SET_STATION_INFO and 1100 appears for only SET_GANG_INFO. so both of these commands puts their strings into same array! and this array is filled in reverse order.

elypter: nope, it doesnt write only at the end of file.
Last edited by T.M. on 20 Oct 2011, 15:38, edited 8 times in total.
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: SCR decompiler

Post by elypter »

if you post the mis we could try to figure out what this is for.
btw, does the command only write at the end of the file or also like a regular command?

if it had something to do with train controlling this information could possibly also help to eliminate gta2 crashes that have to do with trains.
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. »

Figured out the trains now. was lots of work, not as much as DOOR_DATA though.

Code: Select all

struct SCR_STRING_HEADER {
	Uint16 str_id; // strings are converted into integers, this is reference point to translate integer -> string.
	Uint16 unknown1;
	Uint16 datatype; // different commands have different value for this, its not same as the header.type value.
	Uint16 unknown2; // looks like 32bit vars both of these. but its impossible to have over 65k strings so lets assume they are not 32bit.
	Uint8 len; // following string length: (read separately, in 2 bytes blocks).
};

struct StringMapStruct {
	Uint16 datatype;
	string str;
	StringMapStruct(){}
	StringMapStruct(Uint16 datatype, string str) : datatype(datatype), str(str) {}
};

typedef map<Uint16, StringMapStruct, greater<Uint16> > StringMapStructMap;
StringMapStructMap StringMap;


// reads the array in the 5120 bytes block,
// note: the items in this array are saved in reverse order (for some unknown reason),
// newest item is always at the beginning of the array.
void read_scr_strings_array(Uint8 *strings){
	int data_len = (int)read_scr_type(Uint16, strings, 0);
	int curpos = sizeof(Uint16); // set reading pos after header.
	while(curpos < data_len){
		SCR_STRING_HEADER &data = read_scr_type(SCR_STRING_HEADER, strings, curpos);
		curpos += sizeof(SCR_STRING_HEADER);
		string str;
		for(int u = 0; u < data.len; u++){
			char &chr = read_scr_type(char, strings, curpos+u);
			if(chr == NULL) break;
			str += chr;
		}
		StringMap[data.str_id] = StringMapStruct(data.datatype, str);
		curpos += data.len;
	}
}

// used to return SET_STATION_INFO etc platform names.
// or any command strings (except variablenames, they arent stored at all).
string get_scr_string(const Uint16 &str_id){
	if(array_key_exists(str_id, StringMap)){
		return StringMap[str_id].str;
	}else{
		return "<STRNOTFOUND>"; // in case of error (shouldnt be possible)
	}
}


struct for SET_STATION_INFO:

Code: Select all

struct SCR_SET_STATION {
	SCR_CMD_SHORT_FORMAT(
		Uint16 unknown;
		Uint16 platform;
		Uint8 num_passenger;
		Uint8 num_freight;
		Uint8 num_boxcar;
		Uint8 padding1;
		Uint16 padding2;
	);
};
string read_SET_STATION(FPStruct &params){
	get_data(SCR_SET_STATION, data);
	return sprintf_str("SET_STATION_INFO (%s, %d, %d, %d)", get_scr_string(data.platform).c_str(), data.num_passenger, data.num_freight, data.num_boxcar);
}
LinkToFunc(SCRCMD_SET_STATION, read_SET_STATION);
SCR_CMD_SHORT_FORMAT has: {type, cmd} (4 bytes total)

here is what it does:

Code: Select all

SET_STATION_INFO (trak01, 1, 2, 25)
SET_STATION_INFO (trakhihi, 4, 5, 25)
SET_STATION_INFO (tra, 7, 8, 13)
SET_STATION_INFO (traklongname, 10, 11, 12)
pointless to compare to original .mis since they are equal.

edit: i got interesting idea: we could store the variable names in this same array, but im not sure if 5120 bytes is enough in large scripts... but it should be possible. of course it would only be useful if we made our own compiler.
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

I parsed the ste.scr: around ~300 commands:

Code: Select all

PLAYER_PED p1 = (113.50, 124.70, 255.00) 25 1
PARKED_CAR_DATA auto1 = (38.50, 26.50, 255.00) 2 170 TRUKCAB1
PARKED_CAR_DATA auto2 = (46.50, 27.50, 255.00) 3 15 PICKUP
PARKED_CAR_DATA auto3 = (33.50, 42.50, 255.00) 4 15 PICKUP
PARKED_CAR_DATA auto4 = (33.50, 34.50, 255.00) 5 170 PICKUP
PARKED_CAR_DATA auto5 = (36.50, 48.50, 255.00) 7 82 VESPA
PARKED_CAR_DATA auto6 = (9.50, 44.50, 255.00) 8 265 PICKUP
PARKED_CAR_DATA auto7 = (9.50, 46.50, 255.00) 9 82 TRUKCAB1
PARKED_CAR_DATA auto8 = (9.50, 47.50, 255.00) 10 265 PICKUP
PARKED_CAR_DATA auto9 = (11.50, 47.50, 255.00) 12 82 PICKUP
PARKED_CAR_DATA auto10 = (9.50, 51.50, 255.00) 11 265 PICKUP
PARKED_CAR_DATA auto11 = (14.50, 61.50, 255.00) 13 15 VESPA
PARKED_CAR_DATA auto12 = (30.50, 81.50, 255.00) 15 170 PICKUP
PARKED_CAR_DATA auto13 = (41.50, 71.50, 255.00) 16 170 PICKUP
PARKED_CAR_DATA auto14 = (69.50, 74.50, 255.00) 18 15 PICKUP
PARKED_CAR_DATA auto15 = (53.50, 54.50, 255.00) 19 170 PICKUP
PARKED_CAR_DATA auto16 = (68.50, 53.50, 255.00) 20 265 VESPA
PARKED_CAR_DATA auto17 = (50.50, 40.50, 255.00) 21 82 PICKUP
PARKED_CAR_DATA auto18 = (53.50, 35.50, 255.00) 22 15 PICKUP
PARKED_CAR_DATA auto19 = (45.50, 19.50, 255.00) 23 15 PICKUP
PARKED_CAR_DATA auto20 = (22.50, 79.50, 255.00) 2 82 TRUKTRNS
PARKED_CAR_DATA auto21 = (212.50, 71.50, 255.00) 2 265 TRUKTRNS
PARKED_CAR_DATA auto22 = (178.50, 222.50, 255.00) 2 82 TRUKTRNS
PARKED_CAR_DATA auto23 = (9.50, 187.50, 255.00) 2 82 TRUKTRNS
PARKED_CAR_DATA auto24 = (94.50, 33.50, 255.00) 2 82 TRUKTRNS
PARKED_CAR_DATA auto25 = (229.50, 74.50, 255.00) 2 265 TRUKTRNS
PARKED_CAR_DATA auto26 = (94.50, 76.50, 255.00) 0 98 FIAT
PARKED_CAR_DATA auto27 = (94.50, 77.50, 255.00) 1 271 MERC
PARKED_CAR_DATA auto28 = (96.50, 78.50, 255.00) 2 91 MORRIS
PARKED_CAR_DATA auto29 = (94.50, 80.50, 255.00) 3 89 ZCX5
PARKED_CAR_DATA auto30 = (96.50, 83.50, 255.00) 4 272 MORGAN
PARKED_CAR_DATA auto31 = (96.50, 86.50, 255.00) 5 268 SPRITE
PARKED_CAR_DATA auto32 = (96.50, 88.50, 255.00) 6 87 TRANCEAM
PARKED_CAR_DATA auto33 = (96.50, 89.50, 255.00) 7 271 MESSER
PARKED_CAR_DATA auto34 = (145.50, 70.50, 255.00) 8 183 FIAT
PARKED_CAR_DATA auto35 = (148.50, 70.50, 255.00) 9 1 ZCX5
PARKED_CAR_DATA auto36 = (150.50, 70.50, 255.00) 10 359 MORRIS
PARKED_CAR_DATA auto37 = (175.50, 170.50, 255.00) 11 94 SPIDER
PARKED_CAR_DATA auto38 = (213.50, 94.50, 255.00) 12 273 MORGAN
PARKED_CAR_DATA auto39 = (128.50, 129.50, 255.00) 13 91 SPRITE
PARKED_CAR_DATA auto40 = (128.50, 130.50, 255.00) 14 89 TRANCEAM
PARKED_CAR_DATA auto41 = (130.50, 131.50, 255.00) 15 272 ZCX5
PARKED_CAR_DATA auto42 = (130.50, 133.50, 255.00) 16 91 FIAT
PARKED_CAR_DATA auto43 = (177.50, 165.50, 255.00) 10 89 MERC
PARKED_CAR_DATA auto44 = (177.50, 166.50, 255.00) 11 92 MORRIS
PARKED_CAR_DATA auto45 = (175.50, 168.50, 255.00) 12 271 SPIDER
PARKED_CAR_DATA auto46 = (177.50, 171.50, 3.00) 2 269 ZCX5
PARKED_CAR_DATA auto47 = (175.50, 173.50, 255.00) 3 89 SPRITE
PARKED_CAR_DATA auto48 = (175.50, 174.50, 255.00) 4 271 TRANCEAM
PARKED_CAR_DATA auto49 = (137.50, 200.50, 255.00) 5 181 MESSER
PARKED_CAR_DATA auto50 = (139.50, 200.50, 255.00) 14 179 FIAT
PARKED_CAR_DATA auto51 = (140.50, 200.50, 255.00) 15 1 MERC
PARKED_CAR_DATA auto52 = (139.50, 202.50, 255.00) 16 2 ZCX5
PARKED_CAR_DATA auto53 = (142.50, 202.50, 255.00) 10 179 SPIDER
PARKED_CAR_DATA auto54 = (143.50, 202.50, 255.00) 11 1 MORGAN
PARKED_CAR_DATA auto55 = (146.50, 202.50, 255.00) 12 181 SPRITE
PARKED_CAR_DATA auto56 = (148.50, 200.50, 255.00) 2 2 TRANCEAM
PARKED_CAR_DATA auto57 = (152.50, 200.50, 255.00) 3 179 MESSER
PARKED_CAR_DATA auto58 = (153.50, 200.50, 255.00) 4 178 FIAT
PARKED_CAR_DATA auto59 = (155.50, 202.50, 255.00) 5 2 MERC
PARKED_CAR_DATA auto60 = (156.50, 223.50, 255.00) 10 91 MORRIS
PARKED_CAR_DATA auto61 = (156.50, 224.50, 255.00) 11 271 SPIDER
PARKED_CAR_DATA auto62 = (157.50, 225.50, 255.00) 12 91 MORGAN
PARKED_CAR_DATA auto63 = (74.50, 249.50, 255.00) 13 179 SPRITE
PARKED_CAR_DATA auto64 = (75.50, 249.50, 255.00) 14 1 TRANCEAM
PARKED_CAR_DATA auto65 = (77.50, 250.50, 255.00) 2 179 ZCX5
PARKED_CAR_DATA auto66 = (79.50, 250.50, 255.00) 1 181 FIAT
PARKED_CAR_DATA auto67 = (81.50, 249.50, 255.00) 2 2 MERC
PARKED_CAR_DATA auto68 = (82.50, 249.50, 255.00) 3 182 MORRIS
PARKED_CAR_DATA auto69 = (102.50, 137.50, 255.00) 4 89 SPIDER
PARKED_CAR_DATA auto70 = (102.50, 139.50, 255.00) 5 269 ZCX5
PARKED_CAR_DATA auto71 = (100.50, 140.50, 255.00) 3 91 SPRITE
PARKED_CAR_DATA auto72 = (100.50, 141.50, 255.00) 4 272 TRANCEAM
PARKED_CAR_DATA auto73 = (49.50, 114.50, 255.00) 5 1 MESSER
PARKED_CAR_DATA auto74 = (42.50, 196.50, 255.00) 14 181 ZCX5
PARKED_CAR_DATA auto75 = (45.50, 196.50, 255.00) 15 178 TRANCEAM
PARKED_CAR_DATA auto76 = (84.50, 224.50, 255.00) 0 89 COPCAR
PARKED_CAR_DATA auto77 = (84.50, 226.50, 255.00) 0 87 COPCAR
PARKED_CAR_DATA auto78 = (235.50, 147.50, 255.00) 0 3 COPCAR
PARKED_CAR_DATA auto79 = (236.50, 147.50, 255.00) 0 177 COPCAR
PARKED_CAR_DATA auto80 = (233.50, 148.50, 255.00) 0 93 COPCAR
PARKED_CAR_DATA auto81 = (233.50, 150.50, 255.00) 0 89 COPCAR
PARKED_CAR_DATA auto82 = (97.00, 139.50, 255.00) 0 92 MEDICAR
PARKED_CAR_DATA auto83 = (97.00, 141.50, 255.00) 0 273 MEDICAR
PARKED_CAR_DATA auto84 = (49.00, 214.50, 255.00) 0 89 MEDICAR
PARKED_CAR_DATA auto85 = (206.00, 148.50, 255.00) 0 92 MEDICAR
PARKED_CAR_DATA auto86 = (138.00, 96.50, 255.00) 0 88 MEDICAR
PARKED_CAR_DATA auto87 = (5.00, 122.50, 255.00) 0 92 MEDICAR
PARKED_CAR_DATA auto88 = (5.00, 123.50, 255.00) 0 272 MEDICAR
PARKED_CAR_DATA auto89 = (229.00, 123.00, 255.00) 0 181 FIRETRUK
PARKED_CAR_DATA auto90 = (31.00, 144.00, 2.00) 0 178 FIRETRUK
PARKED_CAR_DATA auto91 = (111.50, 126.50, 255.00) 1 121 SPIDER
CAR_DATA auto92 = (229.50, 178.00, 255.00) 1 270 GT24640
CAR_DATA auto93 = (58.50, 3.50, 255.00) 1 90 GT24640
CAR_DATA auto94 = (3.00, 207.00, 255.00) 1 180 GT24640
CAR_DATA auto95 = (139.00, 254.00, 255.00) 1 180 GT24640
CAR_DATA auto96 = (184.50, 202.50, 255.00) 1 270 GT24640
CAR_DATA auto97 = (93.50, 53.50, 255.00) 1 180 GT24640
CAR_DATA auto98 = (127.00, 47.00, 255.00) 1 90 GT24640
CAR_DATA auto99 = (216.00, 117.00, 255.00) 1 180 GT24640
SET_STATION_INFO (trak00, 3, 0, 1)
SET_STATION_INFO (trak01, 3, 0, 1)
SET_STATION_INFO (trak10, 3, 0, 1)
SET_STATION_INFO (trak11, 3, 0, 1)
SET_STATION_INFO (trak20, 3, 0, 1)
SET_STATION_INFO (trak21, 3, 0, 1)
OBJ_DATA obj1 = (234.50, 202.50, 2.00) 90 GREEN_PHONE
OBJ_DATA obj2 = (235.50, 202.50, 2.00) 90 GREEN_PHONE
OBJ_DATA obj3 = (206.50, 227.50, 2.00) 0 YELLOW_PHONE
OBJ_DATA obj4 = (206.50, 228.50, 2.00) 0 YELLOW_PHONE
OBJ_DATA obj5 = (222.50, 221.50, 2.00) 90 RED_PHONE
OBJ_DATA obj6 = (18.50, 68.50, 2.00) 180 GREEN_PHONE
OBJ_DATA obj7 = (18.50, 67.50, 2.00) 180 GREEN_PHONE
OBJ_DATA obj8 = (84.50, 30.50, 4.00) 180 YELLOW_PHONE
OBJ_DATA obj9 = (84.50, 29.50, 4.00) 180 YELLOW_PHONE
OBJ_DATA obj10 = (4.50, 5.50, 2.00) 90 RED_PHONE
OBJ_DATA obj11 = (166.50, 19.50, 3.00) 180 GREEN_PHONE
OBJ_DATA obj12 = (166.50, 16.50, 3.00) 180 GREEN_PHONE
OBJ_DATA obj13 = (224.50, 34.50, 3.00) 90 YELLOW_PHONE
OBJ_DATA obj14 = (225.50, 34.50, 3.00) 90 YELLOW_PHONE
OBJ_DATA obj15 = (208.50, 25.50, 4.00) 0 RED_PHONE
OBJ_DATA obj16 = (199.00, 25.50, 3.00) 0 PHONE
OBJ_DATA obj17 = (47.50, 49.50, 2.00) 90 PHONE
OBJ_DATA obj18 = (211.50, 219.50, 2.00) 270 PHONE
CAR_DATA autodec1
CAR_DATA autodec2
CAR_DATA autodec3
CHAR_DATA chrdec1
CHAR_DATA chrdec2
CHAR_DATA chrdec3
CHAR_DATA chrdec4
CHAR_DATA chrdec5
DOOR_DATA door1 = DOUBLE (211, 31, 3) (0.00, 0.00, 0.00,  0.00, 0.00) BOTTOM 0 ONE_CAR CLOSE_NEVER 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA door2 = DOUBLE (53, 66, 2) (0.00, 0.00, 0.00,  0.00, 0.00) LEFT 0 ONE_CAR CLOSE_NEVER 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA door3 = DOUBLE (235, 192, 2) (0.00, 0.00, 0.00,  0.00, 0.00) TOP 1 ONE_CAR CLOSE_NEVER 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA door4 = DOUBLE (101, 124, 2) (0.00, 0.00, 0.00,  0.00, 0.00) BOTTOM 0 ONE_CAR CLOSE_NEVER 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA door5 = DOUBLE (35, 224, 2) (0.00, 0.00, 0.00,  0.00, 0.00) TOP 0 ONE_CAR CLOSE_NEVER 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA door6 = DOUBLE (36, 229, 2) (0.00, 0.00, 0.00,  0.00, 0.00) BOTTOM 0 ONE_CAR CLOSE_NEVER 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA door7 = DOUBLE (175, 229, 2) (0.00, 0.00, 0.00,  0.00, 0.00) LEFT 1 ONE_CAR CLOSE_NEVER 0 NOT_FLIPPED NOT_REVERSED
DOOR_DATA door8 = DOUBLE (236, 116, 2) (0.00, 0.00, 0.00,  0.00, 0.00) BOTTOM 0 ONE_CAR CLOSE_NEVER 0 NOT_FLIPPED NOT_REVERSED
OBJ_DATA obj19 = (120.50, 120.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj20 = (121.50, 120.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj21 = (242.50, 123.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj22 = (243.50, 123.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj23 = (243.50, 135.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj24 = (242.50, 135.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj25 = (242.50, 209.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj26 = (243.50, 209.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj27 = (243.50, 233.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj28 = (242.50, 233.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj29 = (120.50, 137.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj30 = (121.50, 137.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj31 = (63.50, 212.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj32 = (64.50, 212.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj33 = (64.50, 229.50, 3.00) 0 TUNNEL_BLOCKER
OBJ_DATA obj34 = (63.50, 229.50, 3.00) 0 TUNNEL_BLOCKER
PARKED_CAR_DATA auto100 = (13.00, 83.00, 2.00) 0 91 TANK
PARKED_CAR_DATA auto101 = (29.00, 178.00, 3.00) 0 180 TANK
PARKED_CAR_DATA auto102 = (67.50, 17.50, 2.00) -1 90 ZCX5
PARKED_CAR_DATA auto103 = (6.50, 173.50, 2.00) 2 0 ZCX5
PARKED_CAR_DATA auto104 = (242.50, 185.50, 2.00) 9 0 ZCX5
PARKED_CAR_DATA auto105 = (65.50, 17.50, 2.00) 2 92 TRUKTRNS
PARKED_CAR_DATA auto106 = (6.50, 174.50, 2.00) 2 92 TRUKTRNS
PARKED_CAR_DATA auto107 = (243.50, 185.50, 2.00) 2 182 TRUKTRNS
OBJ_DATA obj35 = (132.50, 171.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj36 = (253.50, 86.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj37 = (113.50, 144.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj38 = (161.50, 78.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj39 = (176.50, 143.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj40 = (84.50, 57.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj41 = (112.50, 164.50, 2.00) 0 KILL_FRENZY
OBJ_DATA obj42 = (9.50, 27.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj43 = (43.50, 146.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj44 = (147.50, 43.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj45 = (151.50, 122.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj46 = (212.50, 201.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj47 = (146.50, 211.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj48 = (172.50, 192.50, 255.00) 0 KILL_FRENZY
OBJ_DATA obj49 = (208.50, 93.50, 255.00) 0 KILL_FRENZY
CAR_DATA autodec4
CAR_DATA autodec5
CAR_DATA autodec6
CAR_DATA autodec7
CAR_DATA autodec8
CAR_DATA autodec9
CAR_DATA autodec10
CAR_DATA autodec11
CAR_DATA autodec12
CHAR_DATA chrdec6
LEVELSTART
OBJ_DATA obj50 = (195.50, 4.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj51 = (246.50, 2.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj52 = (220.50, 29.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj53 = (253.50, 49.50, 4.00) 0 BONUS_TOKEN
OBJ_DATA obj54 = (78.50, 1.50, 6.00) 0 BONUS_TOKEN
OBJ_DATA obj55 = (32.50, 6.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj56 = (40.50, 4.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj57 = (82.50, 18.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj58 = (65.50, 79.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj59 = (14.50, 76.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj60 = (81.50, 55.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj61 = (101.50, 51.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj62 = (138.50, 54.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj63 = (215.50, 78.50, 4.00) 0 BONUS_TOKEN
OBJ_DATA obj64 = (141.50, 81.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj65 = (154.50, 82.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj66 = (245.50, 122.50, 3.00) 0 BONUS_TOKEN
OBJ_DATA obj67 = (68.50, 204.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj68 = (52.50, 202.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj69 = (47.50, 205.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj70 = (73.50, 221.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj71 = (105.50, 202.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj72 = (75.50, 163.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj73 = (65.50, 124.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj74 = (147.50, 178.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj75 = (176.50, 183.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj76 = (199.50, 173.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj77 = (117.50, 120.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj78 = (127.50, 92.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj79 = (102.50, 68.50, 1.00) 0 BONUS_TOKEN
OBJ_DATA obj80 = (62.50, 100.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj81 = (162.50, 136.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj82 = (208.50, 106.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj83 = (127.50, 211.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj84 = (148.50, 224.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj85 = (190.50, 251.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj86 = (236.50, 195.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj87 = (241.50, 235.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj88 = (136.50, 147.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj89 = (36.50, 97.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj90 = (39.50, 111.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj91 = (32.50, 106.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj92 = (196.50, 234.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj93 = (95.50, 145.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj94 = (168.50, 54.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj95 = (2.50, 190.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj96 = (159.50, 4.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj97 = (11.50, 32.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj98 = (116.50, 237.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj99 = (241.50, 108.50, 255.00) 0 BONUS_TOKEN
OBJ_DATA obj100 = (180.50, 226.50, 4.00) 0 COLLECT_03
OBJ_DATA obj101 = (96.50, 163.50, 6.00) 0 COLLECT_28
OBJ_DATA obj102 = (96.50, 164.50, 6.00) 0 COLLECT_29
OBJ_DATA obj103 = (243.50, 237.50, 5.00) 0 COLLECT_03
OBJ_DATA obj104 = (162.00, 38.00, 4.00) 0 COLLECT_16
OBJ_DATA obj105 = (17.00, 149.00, 3.00) 0 COLLECT_17
OBJ_DATA obj106 = (76.00, 205.00, 3.00) 0 COLLECT_18
OBJ_DATA obj107 = (173.00, 123.00, 6.00) 0 COLLECT_34
OBJ_DATA obj108 = (166.50, 124.50, 3.00) 0 COLLECT_28
OBJ_DATA obj109 = (54.50, 66.00, 5.00) 0 COLLECT_28
OBJ_DATA obj110 = (32.50, 69.50, 2.00) 0 COLLECT_35
OBJ_DATA obj111 = (63.00, 82.50, 3.00) 0 COLLECT_36
OBJ_DATA obj112 = (69.80, 37.50, 4.00) 0 COLLECT_18
OBJ_DATA obj113 = (241.50, 236.50, 5.00) 0 COLLECT_35
OBJ_DATA obj114 = (242.50, 236.50, 5.00) 0 COLLECT_36
OBJ_DATA obj115 = (243.50, 236.50, 5.00) 0 COLLECT_34
OBJ_DATA obj116 = (241.50, 237.50, 5.00) 0 COLLECT_29
OBJ_DATA obj117 = (242.50, 237.50, 5.00) 0 COLLECT_03
OBJ_DATA obj118 = (243.50, 237.50, 5.00) 0 COLLECT_03
OBJ_DATA obj119 = (215.50, 121.50, 2.00) 0 COLLECT_36
OBJ_DATA obj120 = (158.50, 186.50, 6.00) 0 COLLECT_28
OBJ_DATA obj121 = (147.50, 130.50, 6.00) 0 COLLECT_29
OBJ_DATA obj122 = (147.50, 132.50, 6.00) 0 COLLECT_03
OBJ_DATA obj123 = (147.50, 134.50, 6.00) 0 COLLECT_32
OBJ_DATA obj124 = (119.50, 150.50, 4.00) 0 COLLECT_16
OBJ_DATA obj125 = (110.50, 123.50, 255.00) 0 COLLECT_29
OBJ_DATA obj126 = (131.50, 62.50, 4.00) 0 COLLECT_03
OBJ_DATA obj127 = (55.50, 174.50, 2.00) 0 COLLECT_04
OBJ_DATA obj128 = (112.50, 236.50, 6.00) 0 COLLECT_04
OBJ_DATA obj129 = (112.50, 237.50, 6.00) 0 COLLECT_02
OBJ_DATA obj130 = (127.50, 216.50, 2.00) 0 COLLECT_05
OBJ_DATA obj131 = (166.50, 219.50, 2.00) 0 COLLECT_31
OBJ_DATA obj132 = (178.50, 209.50, 4.00) 0 COLLECT_34
OBJ_DATA obj133 = (178.50, 220.50, 4.00) 0 COLLECT_36
OBJ_DATA obj134 = (189.50, 183.50, 5.00) 0 COLLECT_35
OBJ_DATA obj135 = (131.50, 83.50, 3.00) 0 COLLECT_39
OBJ_DATA obj136 = (179.50, 37.50, 3.00) 0 COLLECT_39
OBJ_DATA obj137 = (149.50, 59.50, 4.00) 0 COLLECT_29
OBJ_DATA obj138 = (43.50, 120.50, 5.00) 0 COLLECT_02
OBJ_DATA obj139 = (50.50, 119.50, 5.00) 0 COLLECT_04
OBJ_DATA obj140 = (36.50, 171.50, 2.00) 0 COLLECT_08
OBJ_DATA obj141 = (87.50, 208.50, 2.00) 0 COLLECT_09
OBJ_DATA obj142 = (75.50, 224.50, 2.00) 0 COLLECT_31
OBJ_DATA obj143 = (28.50, 197.50, 2.00) 0 COLLECT_05
OBJ_DATA obj144 = (77.50, 146.50, 2.00) 0 COLLECT_02
OBJ_DATA obj145 = (90.50, 136.50, 2.00) 0 COLLECT_33
OBJ_DATA obj146 = (90.50, 143.50, 2.00) 0 COLLECT_31
OBJ_DATA obj147 = (123.50, 143.50, 2.00) 0 COLLECT_09
OBJ_DATA obj148 = (118.50, 143.50, 2.00) 0 COLLECT_05
OBJ_DATA obj149 = (128.50, 161.50, 2.00) 0 COLLECT_30
OBJ_DATA obj150 = (131.50, 160.50, 2.00) 0 COLLECT_31
OBJ_DATA obj151 = (136.50, 189.50, 2.00) 0 COLLECT_09
OBJ_DATA obj152 = (193.50, 176.50, 2.00) 0 COLLECT_06
OBJ_DATA obj153 = (192.50, 145.50, 2.00) 0 COLLECT_35
OBJ_DATA obj154 = (80.50, 122.50, 2.00) 0 COLLECT_34
OBJ_DATA obj155 = (172.50, 119.50, 2.00) 0 COLLECT_32
OBJ_DATA obj156 = (122.50, 73.50, 2.00) 0 COLLECT_02
OBJ_DATA obj157 = (98.50, 55.50, 2.00) 0 COLLECT_18
OBJ_DATA obj158 = (44.50, 46.50, 2.00) 0 COLLECT_39
OBJ_DATA obj159 = (46.50, 40.50, 2.00) 0 COLLECT_06
OBJ_DATA obj160 = (8.50, 36.50, 3.00) 0 COLLECT_06
OBJ_DATA obj161 = (79.50, 28.50, 255.00) 0 COLLECT_32
OBJ_DATA obj162 = (79.50, 29.50, 255.00) 0 COLLECT_39
OBJ_DATA obj163 = (18.50, 11.50, 5.00) 0 COLLECT_16
OBJ_DATA obj164 = (210.50, 230.50, 2.00) 0 COLLECT_39
OBJ_DATA obj165 = (171.50, 252.50, 2.00) 0 COLLECT_08
OBJ_DATA obj166 = (74.50, 235.50, 2.00) 0 COLLECT_34
OBJ_DATA obj167 = (114.50, 57.50, 2.00) 0 COLLECT_04
OBJ_DATA obj168 = (25.50, 101.50, 2.00) 0 COLLECT_34
LEVELEND
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 functions can be figured out, gladly.

here is how the command stream looks like:

Code: Select all

FUNCTION
	PHONE_TEMPLATE
	DISPLAY_TIMER
	DISPLAY_TIMER
	WORD_EQUAL_INT
	WORD_EQUAL_INT
	IF_JUMP
		SET_COUNTER_INT
		LAUNCH_MISSION
		DISPLAY_TIMER
	IF_JUMP
RETURN
here is a bit longer one from same file (ste.scr):

Code: Select all


FUNCTION
	CREATE_SOUND
	DISABLE_THREAD
	WORD_LESS_INT
	WORD_EQUAL_INT
	IF_JUMP
		WARP_CHAR
		INCREMENT
		ADD_NEW_BLOCK
		CHANGE_BLOCK_SIDE
		CHANGE_BLOCK_SIDE
		LIGHT_DECSET2
		SET_COUNTER_INT
		DELETE_ITEM
		ADD_SCORE1
		START_EXEC
			CREATE_CAR_3D
			CREATE_CAR_3D
			CREATE_CAR_3D
			CREATE_CAR_3D
			CREATE_CAR_3D
			CREATE_CAR_3D
			CREATE_CAR_3D
			CREATE_CAR_3D
			GIVE_WEAPON1
			GIVE_WEAPON1
			GIVE_WEAPON1
			GIVE_WEAPON1
			GIVE_WEAPON1
			GIVE_WEAPON1
			DISPLAY_MESSAGE
		STOP_EXEC
		CREATE_SOUND
		WARP_CHAR
		INCREMENT
		ADD_NEW_BLOCK
		CHANGE_BLOCK_SIDE
		CHANGE_BLOCK_SIDE
		LIGHT_DECSET2
		SET_COUNTER_INT
		DELETE_ITEM
		ADD_SCORE1
		DISPLAY_TIMER
	IF_JUMP
RETURN
edit: added tabs :D
T.B.
Jaywalker
Jaywalker
Posts: 7
Joined: 20 Oct 2011, 18:12
GH nick: tnick

Re: SCR decompiler

Post by T.B. »

T.M. wrote: MAP_ZONE gng1map = ( 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 )
MAP_ZONE gng2map = ( 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 )
6600 2900 0000 0A00 0B00 0C00 0D00 0E00 0F00 1000 1100 1200 1300 1400 0000 2900
6600 2A00 0000 0B00 0C00 0D00 0E00 0F00 1000 1100 1200 1300 1400 1500 0000 2A00
[/code]
I think you are off by two bytes. The two last bytes above (2900) should be the first bytes of the next line, like this:
(I added 2800 as the line number for the first line)
2800 6600 2900 0000 0A00 0B00 0C00 0D00 0E00 0F00 1000 1100 1200 1300 1400 0000
2900 6600 2A00 0000 0B00 0C00 0D00 0E00 0F00 1000 1100 1200 1300 1400 1500 0000
2A00 .....

The first word is the CommandLine#
The second is the CommandId
The third is next CommandLine# to execute
Haven't checked but I suspect the line#s are used in loops and if..else...
Possibly they are also used as references in the data section at the end of the file.

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

Re: SCR decompiler

Post by T.M. »

No, they are fine. 6600 = MAP_ZONE_SET, why would it change the next line anyways.

The first two variables seem to be always the same: first is 16bit function command ID, second 16bit is the line number (which is useless btw, only useful to see where the command will end (its also added in the end of each command).
T.B.
Jaywalker
Jaywalker
Posts: 7
Joined: 20 Oct 2011, 18:12
GH nick: tnick

Re: SCR decompiler

Post by T.B. »

I see I wasn't clear in my message. I did not mean only the MAP_ZONE_SET command, I meant all the way from file offset 2EE0 onwards.
T.M. wrote:No, they are fine. 6600 = MAP_ZONE_SET, why would it change the next line anyways.

The first two variables seem to be always the same: first is 16bit function command ID, second 16bit is the line number (which is useless btw, only useful to see where the command will end (its also added in the end of each command).
So, please explain how you came to your conclusion with this simple example:
PLAYER_PED player = (44.5, 134.0, 2.0) 33 0
LEVELSTART
LEVELEND

at offset 0000 in file:
00 00 08 00 24 00 2C 00 00 00 00 00 00 00 00 00

at offset 2EE0:
00 00 00 00 E8 FD 13 00 01 00 05 00 02 00 01 00
00 00 00 00 00 20 0B 00 00 80 21 00 00 80 00 00
00 00 21 00 02 00 3B 00 03 00 00 00 03 00 3C 00
FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00


my interpretation is:
00 00 00 00 E8 FD 13 00 (sofar unknown)
01 00 05 00 02 00 01 00 00 00 00 00 00 20 0B 00 00 80 21 00 00 80 00 00 00 00 21 00
02 00 3B 00 03 00 00 00
03 00 3C 00 FF FF 00 00

Also cf. the txt file output of the compiler:
1 PLAYER_PED EXEC 2 (2916352,8781824,131072) 0 33
2 LEVEL_START 3
3 LEVEL_END -1

Have you tried any loops or if...then... yet?
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

Please see my code few pages before. It shows that there is 2 bytes of (unknown) header in the script data, maybe thats why you thought the offsets wrong.

UPDATE: i made a function to output any SCR file all commands, it also outputs the commands i already support, using proper .mis formatting. the unsupported commands have the hex dump next to it if you want to figure those out. (0) means nullpointer, the first command possible.

Here is Dafes death valley map decompiled .scr:
dafemaptest_decompiled.mis
.scr decompiled with hex dump and command names for commands that arent supported yet
(168.82 KiB) Downloaded 803 times
And here is the original which lines have been nicely formatted to match the decompiled version better:
dafemaptest.mis
original dafes map without empty code lines
(134.09 KiB) Downloaded 801 times
Example code from the decompiled file:

Code: Select all

// (0)
// IF_JUMP = [6200 F905 0100 0000 2C06 2C06]
// CHECK_CAR_DRIVER = [8200 2D06 0100 CC00 0000 2D06]
// NOT = [4700 3006 0100 2E06]
// WORD_EQUAL_INT = [5E00 2F06 0100 CD01 0000 2F06]
// NOT = [4700 4006 0100 3006]
// IF_JUMP = [6200 2E06 0100 0000 4006 3106]
// S_IS_S_DIV_I = [4E01 3206 0100 3C04 3B04 2D00 0000 3206]
// WORD_EQUAL_INT = [5E00 3606 0100 3D04 0000 3306]
// ADD_ONSCREEN_COUNTER = [9E01 3406 0100 3A04 3C04 3406]
// SET_COUNTER_INT = [5401 3706 0100 3D04 0100 3606]
// (0)
// IF_JUMP = [6200 3306 0100 0000 3706 3706]
// DECREMENT = [6100 3806 0100 3B04 7801 3806]
// WORD_LESS_INT = [5600 3E06 0100 3B04 0100 3906]
// EXPLODE_ITEM = [9000 3A06 0100 CC00 0000 3A06]
// CLEAR_COUNTER = [9F01 3B06 0100 3A04 0000 3B06]
// SET_COUNTER_INT = [5401 3C06 0100 3D04 0000 3C06]
// SET_COUNTER_INT = [5401 4106 0100 3B04 1815 3E06]
// (0)
T.B. wrote:So, please explain how you came to your conclusion with this simple example:
i didnt, i used more than 1 player for that reason so i can see the repetition! thats how i also figured out theres 2 byte header somewhere messing up the offsets.
Last edited by T.M. on 20 Oct 2011, 21:11, edited 1 time in total.
User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: SCR decompiler

Post by Pyro »

Again, amazing progress on this, and simply amazed at the partial ste.scr! I know the commands are similar to bil.mis but actually seeing the true contents of ste.scr is fantastic. I really hope you guys can pull this off, you're making excellent progress and every day now I look at this and see it progressing in leaps and bounds. I'll be sure to buy both of you a drink in some form or another :P

PS - for a moment I thought T.M. and T.B. were the same person/replaced name but quite funny to see. Maybe they are, maybe they're not :P
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

Thanks!

LoL, im not talking to myself here :-) , i also wonder who is he :roll:

UPDATES: made the coordinates recognize if its 2d or 3d, so the output doesnt have 255.0 anymore 8-) just like in my editor.
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

I noticed weird things: the first command (first pointer) is always something totally random. i noticed this when i added more support for OBJ_DATA, when i outputted the decompiled script, the first line was OBJ_DATA (with invalid parameter values) even when i didnt have any objects. so i looked whats going on at the first pointer: The bytes (8) associated with that pointer are just crazy. i went through all my SCR files and collected the unique streams of bytes, here results:

Code: Select all

7700 97BD 4000 0100 = wil.SCR
1200 E8F4 1200 0100 = naglez_map6p.SCR
1200 D4F4 1200 0100 = scrtest1 – Kopio.SCR
1200 78F4 1200 0100 = zooka_arena5-6.SCR
1200 60F4 1200 0100 = wsrace.scr
0000 F8FD 1200 0100 = rob-3p.scr
0000 E8FD 2200 0100 = naglez_map2p.SCR
0000 E8FD 1300 0100 = VenericIsle.SCR
0000 E8FD 1200 0100 = zombie.SCR
0000 D4F4 1800 0100 = tytyty.SCR
0000 C8FB 7C00 0100 = super2.SCR
0000 C4FB 7C00 0100 = trains.SCR
0000 90FD 1200 0100 = uk_Intro London NEW_1.SCR
0000 84FD 1300 0100 = ptb.SCR
0000 84FD 1200 0100 = ztest.SCR
0000 60FD 1200 0100 = jailbreak.scr
0000 48F4 1700 0100 = 57thDV.SCR
0000 10FB 7E00 0100 = zaibatsu_city.SCR
i have no idea whats the logic there. ideas welcome. only 0100 is same with all scripts, it seems. perhaps a version number? :p

i also noticed that i had some .scr files which were not 82656 bytes in size, but 6kb or etc. is that even possible? and how?

atm im just ignoring the first pointer.
T.B.
Jaywalker
Jaywalker
Posts: 7
Joined: 20 Oct 2011, 18:12
GH nick: tnick

Re: SCR decompiler

Post by T.B. »

T.M. wrote:Please see my code few pages before. It shows that there is 2 bytes of (unknown) header in the script data, maybe thats why you thought the offsets wrong.
No, I think you are reading/interpreting the commandlines with an offset error of two bytes because you showed data starting with the command id and with next lines line number at the end.
UPDATE: i made a function to output any SCR file all commands, it also outputs the commands i already support, using proper .mis formatting. the unsupported commands have the hex dump next to it if you want to figure those out. (0) means nullpointer, the first command possible.
It's impressive what you have achieved already.

But the pointers in the pointer table at the beginning of the file points to structures of type

Code: Select all

struct SCR_BLOCK_HEADER {
   Uint16 cmd;      // current line number
   Uint16 type;     // command id
   Uint16 execcmd;  // next executable line number
...
and no SCR_BLOCK_FOOTER at all.
The current line number and the next executable line become crucial when you try to decompile the complex if..then..else.. and while... and othe loop constructs.

Here's the last lines from dafemaptest as a hex dump from the compiled script, arranged according corrected scr_block_header and with interpretations as well as the last lines from the .txt file produced by the compiler. I added the decimal values for your convenience when comparing with the .txt file lines.

Code: Select all

line   line  type  exec  bool
3517   BD 0D 62 00 B2 0D 01 00 00 00 C0 0D // IF JUMP  0x0DB2 (3506)  0x0DC0 (3520)
3519   BF 0D 62 00 B0 0D 01 00 00 00 C0 0D // IF JUMP  0x0DB0 (3504)  0x0DC0 (3520)
3520   C0 0D 01 01 C4 0D 01 00             // DO NOWT  0x0DC4 (3524)
3521   C1 0D 62 00 40 04 00 00 00 00 C5 0D // IF JUMP  0x0440 (1088)  0x0DC5 (3525)
3524   C4 0D 4D 00 3F 04 01 00 C1 0D 00 00 // GOTO     0x043F (1087)  0x0DC1 (3521)
3525   C5 0D 3C 00 FF FF 00 00             // LEVELEND


3517 	IF_JUMP			EXEC 3506	3520	FALSE 
3519 	IF_JUMP			EXEC 3504	3520	FALSE 
3520 	DO NOWT			EXEC 3524	
3521 	IF_JUMP				 1088	3525	FALSE 
3524 	GOTO			EXEC 1087	
3525 	LEVEL_END			 -1	
T.B.
Jaywalker
Jaywalker
Posts: 7
Joined: 20 Oct 2011, 18:12
GH nick: tnick

Re: SCR decompiler

Post by T.B. »

T.M. wrote:I noticed weird things: the first command (first pointer) is always something totally random. i noticed this when i added more support for OBJ_DATA, when i outputted the decompiled script, the first line was OBJ_DATA (with invalid parameter values) even when i didnt have any objects. so i looked whats going on at the first pointer: The bytes (8) associated with that pointer are just crazy.
I don't know the meaning of the 8 first bytes, but crazy...? Can we comment on the intelligence they represent just becuse we haven't figured out yet what they are?
i went through all my SCR files and collected the unique streams of bytes, here results:

Code: Select all

7700 97BD 4000 0100 = wil.SCR
1200 E8F4 1200 0100 = naglez_map6p.SCR
1200 D4F4 1200 0100 = scrtest1 – Kopio.SCR
1200 78F4 1200 0100 = zooka_arena5-6.SCR
1200 60F4 1200 0100 = wsrace.scr
0000 F8FD 1200 0100 = rob-3p.scr
0000 E8FD 2200 0100 = naglez_map2p.SCR
0000 E8FD 1300 0100 = VenericIsle.SCR
0000 E8FD 1200 0100 = zombie.SCR
0000 D4F4 1800 0100 = tytyty.SCR
0000 C8FB 7C00 0100 = super2.SCR
0000 C4FB 7C00 0100 = trains.SCR
0000 90FD 1200 0100 = uk_Intro London NEW_1.SCR
0000 84FD 1300 0100 = ptb.SCR
0000 84FD 1200 0100 = ztest.SCR
0000 60FD 1200 0100 = jailbreak.scr
0000 48F4 1700 0100 = 57thDV.SCR
0000 10FB 7E00 0100 = zaibatsu_city.SCR
i have no idea whats the logic there. ideas welcome. only 0100 is same with all scripts, it seems. perhaps a version number? :p
Me neither. But I do know that the 0100 belongs to the next command, and is its line number. You should not omit the two bytes you call a script_header. It offsets all your interpretation from here after. As I have tried to explain to you ;-)
i also noticed that i had some .scr files which were not 82656 bytes in size, but 6kb or etc. is that even possible? and how?
Maybe they are screen saver files?
atm im just ignoring the first pointer.
I think that is a sensible thing to do, until the purpose is revealed.
User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: SCR decompiler

Post by Pyro »

Since I don't know anything about 99% of the stuff here, I could throw some ideas for what those pointers might be for (probably all wrong):

- Characters in SCR file name?
- Date stamp?
- Number of lines of code in SCR?
- File size?

Again, these are just total guesses, but I noticed on wil.scr the first 3 pointers (7700 97BD 4000) is much higher than other scripts you list there for example, maybe compare this (wil.scr) to the other official levels (STE and BIL) and see what happens? Are they similar? Completely different?

Maybe try seeing the difference between a large SCR (bil.sty), a medium size SCR (bootcamp.scr or jailbreak.scr) and small-ish ones (maybe compile the very basic script for testing/tutorials or any other SCR which you know has very few lines of code in MIS).

Also had a look to see if they (the hex) makes any words, but comes up with gibberish other than "w??{?@?" (or slight variations of) for the wil.scr value of "7700 97BD 4000".

Hope this might help you or at least give some ideas on what they could be for. Good luck anyway :)
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: SCR decompiler

Post by elypter »

another guess: maybe it has something to do with PSX/PC IFDEF Blocks.
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. »

@T.B.: WOW! i think you are right! the funny thing is: it works either way so far :D I'll add you into the credits ^^ Thanks!

I removed the 2 byte header crap and everything seems alright. but i still need to ignore the first command... since it STILL doesnt make sense.

I converted my code to use the format:

Code: Select all

struct SCR_BLOCK_HEADER {
	Uint16 cmd_this;
	Uint16 type;
	Uint16 cmd_next;
	Uint16 unknown;
	Uint32 padding;
};
i added those 2 last variables since they are the same in all commands so far (simplifies structs),

but some commands like LEVELSTART doesnt have them, so i use this for those:

Code: Select all

struct SCR_SHORT_HEADER {
	Uint16 cmd_this;
	Uint16 type;
	Uint16 cmd_next;
};
although, i never read the data from those commands. except for each pointer i used this struct already (with only type/cmd). so i didnt need to do much changes to fix my code!


I tested your theory, and it seems to make more sense now:

.mis:

Code: Select all

COUNTER count = 0
LEVELSTART

IF (count = 350)
   auto = CREATE_CAR (1.1,2.2,3.3) 1 2 SPRITE END
ENDIF

LEVELEND

.scr:

Code: Select all

0800 1500 0900 0100 0000 0000 // COUNTER
0900 3B00 0A00 0000 // LEVELSTART

0A00 5E00 0D00 0000 0800 5E01 // WORD_EQUAL_INT
0B00 2C00 0E00 0000 0700 0000 6646 0000 CC8C 0000 33D3 0000 0200 0100 2D00 FFFF // CREATE_CAR_3D
0D00 6200 0B00 0000 0000 0E00 // IF_JUMP

0E00 3C00 FFFF // LEVELEND
But weird thing is: why does it skip 0C00 ? it goes straight to 0D00. weird. edit: maybe its a bug? maybe if we fix it then we can allow more commands for maps. ive noticed the maps that run out of commands doesnt even use them all, so maybe this is why.
Last edited by T.M. on 21 Oct 2011, 12:16, edited 1 time in total.
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: SCR decompiler

Post by T.M. »

T.B. wrote:Maybe they are screen saver files?
lol nope, they have exactly same format as any gta2 .scr file,but they seem to be almost like cut off.
elypter wrote:another guess: maybe it has something to do with PSX/PC IFDEF Blocks.
i doubt, theres only few maps with those blocks, but any other map without them also has random crap there.
Pyro wrote:- Characters in SCR file name?
- Date stamp?
- Number of lines of code in SCR?
- File size?
- i think i saw it changing even on same files, so no. even if it was, the values should be smaller and more diverse.
- perhaps, but then there would be more unique values!
- number of lines are static, so no.
- file size is also static.

ive tried to look at any differences but really i cant figure it out :cry:

thanks for help anyways, but you could also compare those files yourself if you wanna help more :D

edit: here is the new correctly decompiled file from dafes map:
dafemaptest_decompiled.mis
decompiled correctly
(163.72 KiB) Downloaded 798 times
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: SCR decompiler

Post by elypter »

- i think i saw it changing even on same files, so no. even if it was, the values should be smaller and more diverse.
- perhaps, but then there would be more unique values!
- number of lines are static, so no.
- file size is also static.
maybe its a checksum
yur sa'nok ngeyä
Post Reply