• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Forum moderator applications are now open! Click here for details.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

how to recover wasted space in a ROM(and how to remove a batched script)

jakerman999

looking for spriters
52
Posts
16
Years
one of the less severe, but certainly more annoying problems in ROM hacking, is wasting space. this problem can be solved in several ways, such as expanding the ROM, but that could cause errors in some programs. a better solution, albeit one that takes more time, is to trim excess material out of the ROM and rewrite it with empty space.

this tutorial will cover:
fixing an incomplete/wrong script without wasting space (newb friendly and technical)
deleting a script that you don't want
recovering space after multiple compiles
using four Preprocessing Directives in XSE(#clean, #erase, #eraserange and #remove)


in this tutorial, I am using:
1 leaf green ROM
XSE
hex workshop
advance map

an explanation of the preprocessing directives(from the XSE guide)
Spoiler:





before I begin the main section of this tutorial, I'd like to explain how I discovered this method, but its not really important so I'll put it in spoiler for all those interested.
Spoiler:




now dynamic scripts are great, but if they cause problems like this, heres how to fix it.

open the ROM in advance map, then use the "open script" button for where the script is compiled. click in XSE then go back to advance map and open the script again. this should open a second tab with the same script in it.

open the hex viewer from the tools menu and enter the offset where the script is written to. if you've been following good scripting format, there should be a couple blocks of space before where the script starts.if not, look for the first recognizable byte of the script. I'll give you an example script.


Code:
#dynamic 0x000001

'---------------
#org @start
checkflag 0x200
if 0x1 goto @snippet1
lock
msgbox @string1 MSG_NORMAL '"I've got something else t..."
applymovement MOVE_PLAYER @move1
release
end

'---------------
#org @snippet1
end


'---------
' Strings
'---------
#org @string1
= I've got something else to do


'-----------
' Movements
'-----------
#org @move1
#raw 0x10 'Step Down (Normal)
#raw 0xFE 'End of Movements
here the first byte I can see is the checkflag command. placing the cursor on the command and pressing F1 will bring up the command menu, which says that the hex value is 0x2B.

find the first instance of 2B in the hex viewer after the offset, and make sure it is followed by the flag number(remember that hex data is reversed) and it should something like {2B 0020} or {2B00 20} depending on where the script started.

close advance map and fire up hex workshop. scroll down to the rough area where the script should be(I haven't figured how to use the find function) and look for the same lines from the hexviewer. write this offset down, or store it in the notepad section of XSE(a very handy feature)


in XSE, flip to the other tab with the same script and edit it(be it fixing or destroying) and scroll the hexviewer down to the end of the free data. hit compile and watch where the script now ends. clicking on this block will display a number in the userbar(bar at the bottom of the window) that is the address(offset) of the last byte.

if you're going to take the easy route(you save time and lose experience) you can use the directives which I explained earlier.

you could calculate the number of bytes between the start offset and end offset to use the #erase function, or(because you already have the offsets handy), use #eraserange function instead

Code:
 #eraserange 0xstartoffset 0xendoffset
which will reenter FF or 00 bytes depending on your ROM.

for a more technical solution(or just to see what goes on behind the scenes in the erase function) I have provided this spoiler
Spoiler:


you have now removed all of the data from the obsolete script.

if you want to replace the script, either write a new script or edit the decompiled(or leave it as it is if you are performing a recovery) one and recompile to the location you just freed. by doing this, you can recover space from multiple compiles and edit a script without wasting space, making a smaller patch file.


long live free space.
 
Last edited by a moderator:

Full Metal

C(++) Developer.
810
Posts
16
Years
i know i'm not a mod but seriously though.
@gabe
Spoiler:

anyways.
I thought it taught some good habits either way.
 
Last edited:

HackMew

Mewtwo Strikes Back
1,314
Posts
17
Years
  • Seen Oct 26, 2011
Oh, my.... why do people like to NOT read the guide that comes with XSE? The newest version introduced many cleaning directives such as:

  • #erase
  • #eraserange
  • #clean
  • #remove
and more. The guide explains all of them.
 

0m3GA ARS3NAL

Im comin' home...
1,816
Posts
16
Years
Yeah, the #erase directive is all you really ever need.

#erase 0x800000 0x64
That directive would erase 100 bytes from the offset 0x800000.

But like HackMew said...
# #eraserange 0x800000 0x800100
That would remove all bytes from 0x800100

#clean
Removes the last compiled script from the ROM, so long as it was a Dynamic Script. (Having the #dynamic directive at the header.)

#remove 0x800000
This directive would remove the main section of a script located at 0x800000 (Like how scripts have sections, this would delete the only one this points to...)

Please read the guide that comes with XSE, by loading XSE and pressing F2, OR, by navigating to your XSE folder, and double clicking 'Guide.chm'. If you are not able to see file extensions, (Like .chm, or .exe, or .txt, then just click the icon named 'Guide'.)
(LOL, not trying to stand you up HackMew, but I like giving gratuitous amounts of detail as often as possible...)
 

jakerman999

looking for spriters
52
Posts
16
Years
thiscovers a bit more than those functions. it includes instructions on how to remove scripts if they've been compiled multiple times, etc.

and while those functions serve they're purpose, this guide explains how to find what needs to be cleaned, then clean it. those four commands only clean.
 

HackMew

Mewtwo Strikes Back
1,314
Posts
17
Years
  • Seen Oct 26, 2011
thiscovers a bit more than those functions. it includes instructions on how to remove scripts if they've been compiled multiple times, etc.

and while those functions serve they're purpose, this guide explains how to find what needs to be cleaned, then clean it. those four commands only clean.

Yet, those "four commands" aren't written anywhere, are they? Since you explain how to regain wasted free space, there's no reason not to include all the cleaning directives.
 

jakerman999

looking for spriters
52
Posts
16
Years
Yet, those "four commands" aren't written anywhere, are they? Since you explain how to regain wasted free space, there's no reason not to include all the cleaning directives.

alright, I updated the guide. have i appeased your sense of accomplishment yet or do have something else you wish for me to add?
 

ME0W

Still busy working on my hack.
22
Posts
14
Years
  • Age 28
  • Seen Oct 16, 2009
I have a question,
when I used the #eraserange command
on a script, like the one where you battle MAY
on ROUTE 103, the other scripts of some people went blank.
I mean, they have an offset but there are no commands
or anything.

So, when I talk to them in the game, they only show a blank
text box.

Like this:
EXAMPLE:
#eraserange 0x14EB92 0x14ED6B [MAY's SCRIPT]
Then I compiled it.
Then the one I mentioned above happened.
EXAMPLE:
Professor Birch's script
#org 0x800000 [I don't know the offset :)]








BLANK^
Did I do something wrong?
Or should have I used the #erase command instead?

Please help!
It seems that using this command affects other scripts too...
 
Last edited:

HackMew

Mewtwo Strikes Back
1,314
Posts
17
Years
  • Seen Oct 26, 2011
I have a question,
when I used the #eraserange command
on a script, like the one where you battle MAY
on ROUTE 103, the other scripts of some people went blank.
I mean, they have an offset but there are no commands
or anything.

Did I do something wrong?
Or should have I used the #erase command instead?

Please help!
It seems that using this command affects other scripts too...


You better use #removeall instead of #eraserange if you don't know where the script starts and ends, exactly. Check the XSE guide.
 

ME0W

Still busy working on my hack.
22
Posts
14
Years
  • Age 28
  • Seen Oct 16, 2009
Originally posted by HackMew
You better use #removeall instead of #eraserange if you don't know where the script starts and ends, exactly. Check the XSE guide.

Thanks! It helped a lot! Now I feel a lot better...
 
Back
Top