Valps Posted November 7 Share Posted November 7 For a long time TradeMark (T.M.) decompiler was left unfinished, since only the logical structure of scripts were missing, i.e. IF/ELSE/WHILE structures. T.M. has released the source code of his incomplete decompiler at October 2012, twelve years ago and until 2024 no one has solved it. In the recent weeks I was studying these structures by compiling simple scripts, looking at the compiled files using an hex editor, then modifying a little the same script, compiling it again, comparing both scripts to know what have changed in hex data, and repeating all this process many many times till I've found the pattern of these structures. The result of that analysis can be seen here: https://gtamp.com/forum/viewtopic.php?t=1393 I took the source code of T.M. decompiler and I began doing the most easier task to the most difficult one; in this order: 1 - Restore ENDIFs and ENDWHILEs 2 - Distinguish a IF from a WHILE 3 - Restore simple IFs (without ELSEs and without AND/OR/NOT operators) and WHILEs 4 - Restore ELSEs from IFs if they have them 5 - Restore the NOT operator 6 - Restore the AND/OR operators It was decompiling almost everything but crashing on WHILE_EXECs. After analyzing a little more, I've had to significantly change the code since some of my initial assumptions were a little wrong. Then I have finished the next task: 7 - Distinguish a WHILE from WHILE_EXEC After finishing IF/WHILEs I did a lot of tests decompiling other scripts but I found an error in my decompiler when trying to decompile Capital City. In one of its missions the script has what my decompiler has interpreted it as a WHILE without any commands, like WHILE ( count < 3 ) ENDWHILE After thinking for some time, I recognized it as a DO...WHILE_TRUE structure, but this type of structure is very rarely used in GTA2 script (not even one of the official levels use it). However, in order to complete the decompiler, I have studied and understood this structure, which wasn't too hard. Then I have finished the last task of the logical structures: 8 - Restore DO...WHILE_TRUE structures Before moving on, I have tested the recompiled scripts of the official districts, but it not took too long until I realised that original issues of T.M. decompiler with I was already aware of: 1°: it doesn't differentiate the char objective ENTER_CAR_AS_PASSENGER from ENTER_CAR_AS_DRIVER, always misreplacing the former with the last one; 2°: GTA2 don't recognize scripted lights that have radius 8.00 (that lights are allowed in map editor though), so the game just ignore them, causing issues on some missions like "Penal Ties" and "Water Carry On" which uses lights with maximum radius 8.00. I didn't take too long to fix both issues, so the decompiler now: 9 - Distinguish ENTER_CAR_AS_PASSENGER from ENTER_CAR_AS_DRIVER 10 - Decompile lights with radius 8.00 to 7.99 The final test was to decompile all official levels of the game (Downtown, Residential and Industrial districts, besides the bonus levels A,B,...,H,I), recompile them again and play them in order to know if all features were working and the behaviour is the same of the original ones. The decompiler has successfully created compilable versions of all levels which very accurately recreate all of them. The TradeMark decompiler is finally complete and functional. This means that now you can decompile whichever script you want, from simple multiplayer scripts to even an entire district from singleplayer. Now you can edit whatever you want (parked cars, tokens, kill frenzies, gangs, maximum wanted level, zones, missions, the clothes of claude speed etc.), recompile and play it. The script of Capital City, for example, now can be viewed and modded by everyone. The only thing the decompiler doesn't restore is the original labels of variables, with in this case is impossible. The reason is pretty much the same of some reverse engineering cases: the compiled files don't keep these labels, only their abstract index. However I'm doing this manually to the main districts (Downtown and Residential) giving names which are intelligible. It helps modifying missions, which is the case of Toughened Downtown by WorldofWind (W.I.P. at this moment) and perhaps in the future Toughened Residential. Downtown is already finished: https://gtamp.com/forum/viewtopic.php?t=1389 Residential is going to be finished yet, but I will release it here: https://gtamp.com/forum/viewtopic.php?t=1392 Download of the complete decompiler (or view its source code): https://github.com/Valps/gta2-tm-scr-decompiler/releases Sektor, BBBean, rhospeed and 3 others 5 1 Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/ Share on other sites More sharing options...
cant remember Posted November 7 Share Posted November 7 Wow! That's amazing, nice work! Didn't DMA design release the source script for one of the levels? I don't remember which but that would also be a good test case if the decompiled script looks like the one they released, and would be at least one that we have the variable names for. Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072455585 Share on other sites More sharing options...
Valps Posted November 7 Author Share Posted November 7 6 hours ago, cant remember said: Wow! That's amazing, nice work! Didn't DMA design release the source script for one of the levels? I don't remember which but that would also be a good test case if the decompiled script looks like the one they released, and would be at least one that we have the variable names for. They have released the source script of Industrial District. I've tested the decompiler on it and a lot of fanmade singleplayer maps such as Zombie Survival which uses a lot of nested IF/WHILEs, ELSEs, ANDs and ORs. I didn't compared all lines (Zombie Survival has more than 2500 lines) but for any piece of code I have looked at, the comparison was 1:1 Another way of testing the decompiler is recompiling the script and playing it, which I've done with all official levels. Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072455743 Share on other sites More sharing options...
cant remember Posted November 8 Share Posted November 8 Man if I had this back in the day, I always wished I could crank up the amount of parked cars, I still wonder what the limit is. I always used to place plenty of parked cars in my maps and never had any ill effect. Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072455896 Share on other sites More sharing options...
Jeansowaty Posted November 10 Share Posted November 10 My dearest congratulations! I always dreamed of being able to play around with the sauce code and maybe try to fix some of those abysmal Residential (and maybe some Industrial) rampages. Now it's totally possible, ain't it? And gosh imagine if someone made an extended cue at 2 and added more missions. That would be so epic. Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072456879 Share on other sites More sharing options...
cant remember Posted November 11 Share Posted November 11 19 hours ago, Jeansowaty said: sauce code From now on that is how I will say it. Jeansowaty 1 Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072457133 Share on other sites More sharing options...
Yutes of Cards Posted November 12 Share Posted November 12 I wonder if would make the downtown district more better (like making it actually like the rest of the game having the gangs with actual weapons with lower respect besides pistols) Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072457428 Share on other sites More sharing options...
Valps Posted November 12 Author Share Posted November 12 On 11/10/2024 at 4:27 PM, Jeansowaty said: My dearest congratulations! I always dreamed of being able to play around with the sauce code and maybe try to fix some of those abysmal Residential (and maybe some Industrial) rampages. Now it's totally possible, ain't it? And gosh imagine if someone made an extended cue at 2 and added more missions. That would be so epic. Yes, it's totally possible. All kill frenzies settings are on the very end of ste.mis. You just need to change their respective commands: START_BASIC_KF_TEMPLATE START_BONUS_CHECK DO_BASIC_KF_TEMPLATE All of them are documented at https://projectcerbera.com/gta/2/tutorials/frenzies Also, the number of missions a map can have is totally flexible (it's not hardcoded). So we can add more missions if we want (without needing to replace the original ones). We can create new phones for them or add them to the existing ones. 6 hours ago, Yutes of Cards said: I wonder if would make the downtown district more better (like making it actually like the rest of the game having the gangs with actual weapons with lower respect besides pistols) In the future I will make "Enhanced Downtown", which will have missions a little more difficult (along the lines of Residential or Industrial), better weapons for gangs (instead of just pistol), respawning kill frenzies on fail, three new "ultimate" gang missions and some neutral missions (along the lines of Vice City's pay phones). Jeansowaty and undergroundvicious 1 1 Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072457591 Share on other sites More sharing options...
Jeansowaty Posted November 12 Share Posted November 12 I'm absolutely mesmerized dude! Jeez this takes me back to what I was doing 10 years ago, so awesome. I think the Zaibatsu and Yakuza should have a Machine Gun as their main 3rd gun and the Loonies the Flamethrower seeing as (except Red Valdez) all the gang bosses follow this pattern. Giving GTA2 justice and fixing all the rushed stuff the game had is so nice to imagine. Did you know the game originally also had one or two more green phone missions for each gang btw? Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072457631 Share on other sites More sharing options...
Valps Posted November 12 Author Share Posted November 12 18 minutes ago, Jeansowaty said: I'm absolutely mesmerized dude! Jeez this takes me back to what I was doing 10 years ago, so awesome. I think the Zaibatsu and Yakuza should have a Machine Gun as their main 3rd gun and the Loonies the Flamethrower seeing as (except Red Valdez) all the gang bosses follow this pattern. Giving GTA2 justice and fixing all the rushed stuff the game had is so nice to imagine. Did you know the game originally also had one or two more green phone missions for each gang btw? I will consider it in my enhanced downtown. But for now changing three lines in wil.mis you will get what you want: SET_GANG_INFO (yakuzagang, 13, PISTOL, PISTOL, MACHINE_GUN, 2, 31.00, 157.00, 2.00, 1, MIURA, 15) SET_GANG_INFO (zaibatsugang, 8, PISTOL, PISTOL, MACHINE_GUN, 3, 188.50, 37.50, 2.00, 1, VTYPE, 2) SET_GANG_INFO (looniegang, 11, PISTOL, PISTOL, FLAME_THROWER, 1, 38.50, 38.50, 2.00, 1, ISETTA, 16) The first weapon is their default weapon (from little negative respect up to max positive respect), the second weapon is their weapon they use when they hate you (respect considerably negative) and the third is when you have max negative respect. I didn't know that devs once wanted to give more easy missions. I know that they have created a command solely to set green phones, because the default command to launch gang missions require 2 missions, but green phones have 1 mission. Jeansowaty 1 Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072457655 Share on other sites More sharing options...
Jeansowaty Posted November 12 Share Posted November 12 3 hours ago, Valps said: I will consider it in my enhanced downtown. But for now changing three lines in wil.mis you will get what you want: SET_GANG_INFO (yakuzagang, 13, PISTOL, PISTOL, MACHINE_GUN, 2, 31.00, 157.00, 2.00, 1, MIURA, 15) SET_GANG_INFO (zaibatsugang, 8, PISTOL, PISTOL, MACHINE_GUN, 3, 188.50, 37.50, 2.00, 1, VTYPE, 2) SET_GANG_INFO (looniegang, 11, PISTOL, PISTOL, FLAME_THROWER, 1, 38.50, 38.50, 2.00, 1, ISETTA, 16) The first weapon is their default weapon (from little negative respect up to max positive respect), the second weapon is their weapon they use when they hate you (respect considerably negative) and the third is when you have max negative respect. I didn't know that devs once wanted to give more easy missions. I know that they have created a command solely to set green phones, because the default command to launch gang missions require 2 missions, but green phones have 1 mission. I'm aware of that my friend, I've been also tinkering around with custom map scripts these 10 or so years ago but yeah consider it as a suggestion of sorts. Second gun can be grenades or dual pistols or something. Nonetheless the design doc explicitly mentioned that each gang would have more missions than what we got in final, and apparently the final total would've been 75 or so. Quite interesting if you ask me. Valps 1 Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072457777 Share on other sites More sharing options...
Yutes of Cards Posted November 12 Share Posted November 12 9 hours ago, Valps said: In the future I will make "Enhanced Downtown", which will have missions a little more difficult (along the lines of Residential or Industrial), better weapons for gangs (instead of just pistol), respawning kill frenzies on fail, three new "ultimate" gang missions and some neutral missions (along the lines of Vice City's pay phones). I played that, since it be a fresher way and maybe it make things intresting Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072457902 Share on other sites More sharing options...
BBBean Posted November 18 Share Posted November 18 Nice work! Hehe, I made some simple mods with hex editor once and also tried to make the Mad island gangsters drive their gang car but didn't manage to get it to work. I guess it might be easier with scripts. Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072460743 Share on other sites More sharing options...
Valps Posted November 18 Author Share Posted November 18 6 hours ago, BBBean said: Nice work! Hehe, I made some simple mods with hex editor once and also tried to make the Mad island gangsters drive their gang car but didn't manage to get it to work. I guess it might be easier with scripts. Mad Island from Industrial? The source code of this district is already public, and it's the original version the devs have used to make the level. You can get it by downloading the official compiler miss2.exe ( https://gtamp.com/GTA2/gta2script.7z ), since Industrial script is included together as an example. Link to comment https://gtaforums.com/topic/999466-scr-decompiler-finally-100-functional/#findComment-1072460969 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now