The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > ROM Hacking > Tools, Tutorials & Resources
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

Tools, Tutorials & Resources Various tools to help you develop your hacks can be found here.
New threads in this forum are to be approved by a moderator before they are displayed.


Advertise here

Reply
 
Thread Tools
  #1    
Old July 2nd, 2009, 02:44 PM
jakerman999's Avatar
jakerman999
looking for spriters
 
Join Date: Oct 2007
Location: Ingersoll
Age: 21
Gender: Male
Nature: Adamant
Send a message via Windows Live Messenger to jakerman999

Advertise here
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:


Quote:
Originally Posted by #clean
Clean the ROM from the last compiled script, as long as it was a dynamic one.

Usage:
#clean

Example:
#clean
which means, it takes the last script that was compiled to the ROM in question and undoes the change(useful when you notice an error just after you hit the compile button).

Quote:
Originally Posted by #erase
Overwrites a certain amount of bytes with the free space-byte value set, starting from the specified offset.

Usage:
#erase lOffset aValue

Example:
#erase 0x720000 0x64
0x64 (100) bytes from offset 0x720000 got overwritten with free space.
will erase a certain number of bytes after an offset and replace them with free space.

Quote:
Originally Posted by #eraserange
Overwrites a specified range of bytes with the free space-byte value set, starting from the first specified offset and ending at the second specified offset.

Usage:
#eraserange lOffset lOffset

Example:
#eraserange 0x720000 0x720500
0x1F4 (500) bytes from offset 0x7200000 to offset 0x720500 got overwritten with free space.
will replace all bytes between the two offsets with free space.

Quote:
Originally Posted by #remove
Removes the main part of a compiled script, if it's a valid one. Useful to gain free space and removing a spoilt script. By removing it means it's filled with the free space byte, either 0xFF/0x00.

Usage:
#remove lScriptOffset

Example:
#remove 0x16582F
The main part of the script at 0x16582F would be removed.
their are several variations on the #remove command(such as #removeall) but I will not discuss that here until some unforeseen reason presents itself. it can be used similar to the erase command but it is slightly harder use correctly.





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:

what lead me on to this was making a script and compiling it, then realizing i had missed a section. after fixing the script, compiling it again, and decompiling it, I was given the incomplete script again. after repeating the process several times I started to wonder what was stopping the script from being inserted. I opened up the hex viewer in XSE(found in the tools menu) and scrolled down to the space where the data was being written. when i compiled it again(with the viewer still open) it updated the free space, but not where I was writing to. this i quickly realized was because i was using dynamic scripts.





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:

in hex workshop again, highlight from the first offset that we found(the beginning of the script) to the second offset that we found(where we edited the script). right click and press fill. it will bring up a dialog box. type in FF (or 00 depending on ROM) and press enter. when it asks you if you want to back up your ROM, hit yes.


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.
__________________
you must build -inal pylons.

jakerman999's PokePet

sharpshell the level 45 Kabutops!


I have a life, I bought it on e-bay.

support shiny gold!

Last edited by hashtag; April 15th, 2010 at 08:15 AM.
Reply With Quote
  #2    
Old July 5th, 2009, 07:51 AM
Full Metal's Avatar
Full Metal
C(++) Developer.
Community Supporter
 
Join Date: Jan 2008
Location: In my mind.
Age: 19
Gender: Male
Nature: Timid
Send a message via Windows Live Messenger to Full Metal
i know i'm not a mod but seriously though.
@gabe
Spoiler:
why can't it be serious? either way, that wasn't nescesary

anyways.
I thought it taught some good habits either way.
__________________

★ full metal.

I like to push it,
and push it,
until my luck is over.

Last edited by Full Metal; July 5th, 2009 at 08:03 AM.
Reply With Quote
  #3    
Old July 5th, 2009, 07:58 AM
HackMew's Avatar
HackMew
Mewtwo Strikes Back
 
Join Date: Jun 2006
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.
__________________
Reply With Quote
  #4    
Old July 6th, 2009, 03:37 AM
0m3GA ARS3NAL's Avatar
0m3GA ARS3NAL
Im comin' home...
Community Supporter Tier 1
 
Join Date: Jan 2008
Location: Superjail Penitentiary
Age: 21
Gender: Male
Nature: Gentle
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...)
__________________
>Boot Jailbot
>Pass *****
.
.
Jailbot OS Ver 1.1.2
Greetings Warden
of Superjail Penitentiary
Awaiting user input...

>Display User_Info
╠══User Info══╣
Username:
0m3GA ARS3NAL
Age: 18
Sex: Male ♂
Race: Caucasian
Quote:
"What is this
I don't even..."

M/O: Often acts out to get attention, but recently has changed that. Has been studying up on hacking information and hopes to participate in more advanced hacking discussion.
╠══End of File══╣
Awaiting user input...

>
Reply With Quote
  #5    
Old July 6th, 2009, 12:09 PM
jakerman999's Avatar
jakerman999
looking for spriters
 
Join Date: Oct 2007
Location: Ingersoll
Age: 21
Gender: Male
Nature: Adamant
Send a message via Windows Live Messenger to jakerman999
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.
__________________
you must build -inal pylons.

jakerman999's PokePet

sharpshell the level 45 Kabutops!


I have a life, I bought it on e-bay.

support shiny gold!
Reply With Quote
  #6    
Old July 6th, 2009, 12:16 PM
HackMew's Avatar
HackMew
Mewtwo Strikes Back
 
Join Date: Jun 2006
Quote:
Originally Posted by jakerman999 View Post
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.
__________________
Reply With Quote
  #7    
Old July 14th, 2009, 10:58 PM
jakerman999's Avatar
jakerman999
looking for spriters
 
Join Date: Oct 2007
Location: Ingersoll
Age: 21
Gender: Male
Nature: Adamant
Send a message via Windows Live Messenger to jakerman999
Quote:
Originally Posted by HackMew View Post
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?
__________________
you must build -inal pylons.

jakerman999's PokePet

sharpshell the level 45 Kabutops!


I have a life, I bought it on e-bay.

support shiny gold!
Reply With Quote
  #8    
Old October 10th, 2009, 01:57 AM
ME0W's Avatar
ME0W
Still busy working on my hack.
 
Join Date: Aug 2009
Age: 18
Gender: Male
Nature: Calm
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...
__________________
Look at my new Title Screen!

Not bad don't you think?
My other one went nuts!
So I made a new one!

Quote:
Spoiler:

One of my favorite

quotes!


Mr. Flak: Oh, and Mr. Larkin, perhaps you'd
like to share with the rest of the class,
Patrick Henry's immortal last words.

Link Larkin: Kiss my ASS?

Man I love that!


Last edited by ME0W; October 10th, 2009 at 02:04 AM.
Reply With Quote
  #9    
Old October 10th, 2009, 02:20 AM
HackMew's Avatar
HackMew
Mewtwo Strikes Back
 
Join Date: Jun 2006
Quote:
Originally Posted by ME0W View Post
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.
__________________
Reply With Quote
  #10    
Old October 10th, 2009, 04:59 AM
ME0W's Avatar
ME0W
Still busy working on my hack.
 
Join Date: Aug 2009
Age: 18
Gender: Male
Nature: Calm
Quote:
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...
__________________
Look at my new Title Screen!

Not bad don't you think?
My other one went nuts!
So I made a new one!

Quote:
Spoiler:

One of my favorite

quotes!


Mr. Flak: Oh, and Mr. Larkin, perhaps you'd
like to share with the rest of the class,
Patrick Henry's immortal last words.

Link Larkin: Kiss my ASS?

Man I love that!

Reply With Quote
Reply
Quick Reply

Sponsored Links


Advertise here
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 09:50 AM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.