Page 1 of 1

[How To] Rewrite a script in compiled lvl file

Posted: Mon Dec 14, 2015 3:17 am
by AnthonyBF2
In my project to revive the PSP version of swbf2 I have several goals, one of the hardest ones (now solved!) was updating the map selection list while maintaining the rest of the original shell assets, as a newly munged shell.lvl screws up a whole bunch of things on the PS2/PSP platform. I did this by putting a new missionlist.lua inside of shell.lvl over the old one. This allows me to keep all the psp data running and have a new updated map list. I would like to share the process I did to make this possible, so it may help other modders.

This tutorial will mock my exact method of updating the missionlist.lua inside of shell.lvl but you may apply to this your own files/scripts.
First make sure you have 2 or 3 copies of your current file available you will be editing, for me; an original shell.lvl from the PSP version.

We begin by using mod tools and setup a new shell and munge it. Copy Shell folder from assets to data_PSP. Inside data_PSP\Shell\Scripts I make my desired edits, save changes to the missionlist.lua and close it. I go to _build folder, edit munge.bat and change munge_platform from pc to ps2 (You don't need to do this part unless you're modding a console version of swbf2)
For PC modders just run regular visualmunge and make sure you check "Shell" and click munge.

When the munge completes, take your new shell.lvl and open it inside of a hex editor, and open the original shell.lvl in hex editor too. Too avoid any possible confusion, rename the newly munged shell.lvl something else, we aren't going to be using this file anyway.
So now in hex editor, I have open old shell.lvl and new shell.lvl.

In the old shell.lvl, I will find the location where missionlist.lua begins. It looks like this:
Hidden/Spoiler:
Image
Now, copy the data beginning from scr_ to luap
Like so:
Hidden/Spoiler:
Image
(Copy the BYTES and not the ASCII) (The bytes is the left side of hex editor)
Open up notepad, and paste and temporarily save that bit of data. We'll be using it again.

Next put your cursor just behind scr_ and click and drag downward slowly until your cursor reaches the next occurrence of scr_
What we're doing here is highlighting the entire data that runs missionlist.lua. The next script in the file is ifs_sp.lua, so stop copying right before the next scr_ like so:
Hidden/Spoiler:
Image
Now, right-click the BYTES section and fill the data with all 00. Two next screenshots show the top and the bottom of the missionlist.lua script that has been converted to 00.
Top:
Hidden/Spoiler:
Image
Bottom:
Hidden/Spoiler:
Image
Now, in hex editor, open the newly munged shell.lvl created by modtools. (Keep the current "old" file open too)
In the new file, go to where missionlist.lua begins, my new one looks like this:
Hidden/Spoiler:
Image
Now, again, on this new file, put your cursor just behind scr_ and copy all of the data until you find the next scr_
Like so:
Hidden/Spoiler:
Image
Always copy the bytes, and NOT the ASCII.

Now, switch back over to the old file and paste that data, it should look like this:
Hidden/Spoiler:
Image
Next, we return to the notepad document we made with the small header data bytes. Copy that data again, and apply it over the freshly pasted script code, like so:
Hidden/Spoiler:
Image
Now you may save changes to your currently used file and discard the file made by modtools. That new shell.lvl is now ready to be used and give me my updated map list selection!

But WAIT! There is a huge thing I must alert you about before anyone may use this. I didn't exactly know where to add this in the tutorial.
The new script you're making must be smaller than the script you're replacing.
WHY: If your new script is too big, it will replace parts of the next script in the lvl file and corrupt the file, and probably crash your game.

In my specific work, I removed all of the "attract mode maps" gibberish from missionlist.lua. This code seems to serve no purpose and cleared a a good amount of space allowing the new script to become smaller.. So, here is another snapshot of what my ending, new file looks like:
Hidden/Spoiler:
Image
If you have a bunch of 00 spaces before the next script begins, then you are safe.

I hope this can help some body some where in the future. This helped me tons in my quest. :yes:

Re: [How To] Rewrite a script in compiled lvl file

Posted: Mon Dec 14, 2015 3:28 am
by Sketchup
Nice guide
Hidden/Spoiler:
Image

Re: [How To] Rewrite a script in compiled lvl file

Posted: Mon Dec 14, 2015 4:58 am
by Anakin
Modders shouldn't use this too often, because the mods wouldn't be compatible. But very interesting nonetheless.
@Sketchup: please remove your image or use hide tags. It makes me crazy.