I have a question about Pokémon Black & White script editing.
I know that:
- a/1/2/5 contains the overworld data.
- a/0/5/7 contains the scripts.
My question is: how is the overworld data calling up scripts from the script narc? I know that overworlds have hex data for ''script'' added, but I don't know how that corresponds with the data in the script narc (a/0/5/7).
I know for example that the overworld data is grouped per map. So all data of Route 2 is together in one part of the narc.
For example, the script hex data of the Lass on Route 2 is BA 0B. Which part of the script narc does that relate with? How is the script data arranged?
this is pretty much untouched as people haven't really investigated like they've done in gen3/4.
i'll help later today and over the weekend, I'm actually kinda interested in this
drayano and others have done some work on 0/5/7, I think that understanding the format of the script narc first will help understand the overworld->script fetch
as drayano said, using a Lua script to quickly fetch overworld position & map is verrry helpful. the script setup might be very similar to gen 4 as BW is essentially the same engine.
Yeah, well I'm currently working on my hack and I've made a lot of progress. I added new Trainers to certain routes etc. but my only question is: how are the scripts actually ''called'' by the overworlds? How does the overworld's script hex data correspond with the script narc?
I'm not really keen on ROM editing; I tend to stick with sav/RAM editing myself. As such I try to edit these scripts in game -- the best (and only) time to apply these changes is when the overworld loads. The overworld won't re-load if you view the party screen, so you have to physically leave the map.
I'll be taking a RAM editing approach instead of ROM editing, however it should be easy to apply the following to the ROM instead. Since I don't know how this stuff works at all I might as well catalog my learning process.
setup & learning the ropes:
I was able to find Drayano's example Desert Resort overworld at the offset 0x02250244 in my unmodified copy of English White. This area is right after eventdata_system.c, so we know this is the right place. (0x02250000).
now, I just start toying with the scripts that are loaded, by applying a cheat code right before the game interprets the script to show what's on the overworld. I apply an internal code of 13631494 (dec, which is 00D00006) at 02250244 to change up the sprite that's loaded.
shazam, I can edit the scripts without editing the ROM directly. Much quicker than editing the ROM in my opinion. So now that I've explained that, we can see that the overworld is present here and can be changed, but that stuff is already known.
establishing that this is the a/1/2/5 overworld data file:
now, by copying and searching, we see that the ROM mirrors the RAM:
0x083B4400 (ROM) - starting data - AC 04 00 00 04 1C 03 02
So, we now know that this data is loaded from the a/1/2/5 narc, but which file? 158, the map ID! duh...
Ok, so the map event file is loaded into the memory, and it then calls for reference scripts. That's the ultimate goal.
Script File and Memory Locations
So, we know that Darmanitan is what you encounter from the statue. So, knowing that it has to call the Pokemon Index Hex (0x022B) to get one to appear and the memory has to have the Scripts loaded already, we look for Darmanitan's hex further in the memory.
I find 2B 02 23 00 20 80 7B 01 23 80 09 00 23 80 08 00 01 00 11 later on, and search for that in a/0/5/7. Found a match in file 316. We find the 78 01 pokemonhex for each of them, so this is the right file.
Note that the entire script file for the map is loaded at offset 0x0225CB44 (there's a pointer at 0x0225C614 that points here). However, this isn't what we're looking for.
We instead look for 0x013C (the Script File number) after the overworld data. We find it at 0x022592C2. Change this on the fly, and you access different scripts!
Ok, so that's pretty cool. But just for fun, what's around this area? "zonedata.c", cool. Lets corrupt some crap.
Went into the ruins, and encountered a Pokemon.
yeeeeeee. Changed up the pads of WILD POKEMON. Zone data!
Back to our intentions:
The overworld data has to point to the script file somehow. We know that overworld_158 must point to script_316. So we search for 3C 01 in the overworld file...
not found. well fuck, gotta figure out wat do.
Last edited by Kaphotics; Jun 7th, 2012 at 06:18 PM.
That's some cool information, Kaphotics! Thanks for your time and interest!
However, you say:
I don't see how that's so obvious? How actually is a/0/5/7-316 related to 78 01 hex data? Also, where did you get 78 01 from?Found a match in file 316. We find the 78 01 pokemonhex for each of them, so this is the right file.
Moreover, I understand that 0x013C = 316, which corresponds with the script file in a/0/5/7. But where does it mention 0x013C in the overworld data?
You see, what I'm trying to achieve is the following.
For example, I want to add the National Dex at the beginning of the game. However, to add that function, I want to take a look at the original script data for both the National Dex event (after defeating the Elite Four), as well as the original Pokédex event at the very beginning of the game. It's nearly impossible to find that without any other information whatsoever. I did find the overworld trigger files, but I don't see how the corresponding script hex data calls the script from a/0/5/7. I can't see how it's related.
Another example, like I said in the first post: the script hex data of the Lass on Route 2 is BA 0B. But which part of the script narc does that relate with? How is the script data arranged?
If only each script had its own file in a/0/5/7, it would be a lot easier. However, 0xBBA gives 3002 and there aren't that many files available. To which part of a/0/5/7 does it relate, then?
Oh, I just pasted the darmanitan data starting at it's dex #. the whole string was
"78 01 2B 02 23 00 20 80 7B 01 23 80 09 00 23 80 08 00 01 00 11"
From the overworld data I just searched for the nearest 2B 02, and ^ came up. Once I saw the 78 01 right before it, it hinted that it could be right, so I went with it and found that data in the ROM, and it ended up being in a/0/5/7-316.
Just updated the post about 0x013C about how I couldn't find it in a/1/2/5...
Copying the zonedata from the RAM as it contained the data for the script number, and look for it in the ROM/narcs.
"00 10 16 00 67 00 3C 01 3D 01 A6 00 36 04 36 04 36 04 36 04 08 00 9E 00 9D 00 22 04 00 00 40 6D 67 00 00 00 05 00 00 00 00 00 00 00 04 00 00 00" is at 0x0225B92BE for a total size of 30 bytes. Andibad noted that "zonedata" is a/0/1/2 in this thread. This data I found is indeed at a/0/1/2, which is one large file. Looks like this controls the selection of data like scripts, pads, (encounter slots?) etc.
a/0/1/2 IS A VERY IMPORTANT FILE.
View as 48 bytes each, 427 lines. Remember that a/1/2/5 has 427 files? Each line corresponds to a certain overworld file!
Back checking now, we have our Desert Resort data at 0x1DA0, which is line 158. Bingo. So now you can get a list of what map overworlds reference what scripts. lolol
Now we know the meaning of the zonedata narc and part of it's structure; it determines what map uses what script!
Now that's one structure that would be VERY useful to catalog and have an editor for!
Getting to your question now that I have documented a lot of new stuff :P
Map 319 corresponds to Route 2. Thus Line 319 of zonedata will contain the script reference at 0x3BD0 of the zonedata narc.
00 01 06 00 00 007E 02 7F 02 5F 01 0E 04 0F 04 10 04 11 04 4E 00 3F 01 3F 01 0F 04 40 00 00 EC 00 00 00 00 FA 02 00 00 00 00 00 00 91 02 00 00"
As you can see, it's referencing scripts 027E and 027F (638 and 639). So, if you have an object on overworld_319, it would access the script index number of scriptfile_638.
Answered!Originally Posted by OP, question 1
That's half the puzzle so far (what scripts an overworld map uses, thus where to edit); we still need to know HOW to edit the scripts!slightly related tangent: I'm sure that a lot more cool stuff can come from editing the zonedata!
instead of finding what line of zonedata to look at, I separated my english white narc into pieces for each zone; just a quick reference of what each zone is.
alternatively, line separated pastebin (copy to notepad++ to get line numbers)
For the structure of the map's zonedata, (desert resort, v v v )
00 10 16 00 67 00 3C 01 3D 01 A6 00 36 04 36 04 36 04 36 04 08 00 9E 00 9D 00 22 04 00 00 40 6D 67 00 00 00 05 00 00 00 00 00 00 00 04 00 00 00
not 100% on this, might have made a mistake since I went hex by hex seeing what happened.
to allow people to bike everywhere, make 0x1E's 7th bit always 1.Code:0x00-0x01 - ?? 0x02-0x03 - Tile Set Load (?) 0x04-0x05 - Map Terrain load 0x06-0x07 - Script Set A? 0x08-0x09 - Script Set B? usually blank? 0x0A-0x0B - Text Script # Load 0x0C-0x0D - music set A? 0x0E-0x0F - music set B? 0x10-0x11 - music set C? 0x12-0x13 - music set D? 0x14-0x15 - Encounter Slot Table, 0xFFFF = no encounters 0x16-0x17 - Map # Load ~ (0-426) 0x18-0x19 - Map within Map ~ Currently loaded map is located within VALUE as a submap (Current Location). 0x1A-0x1B - ?? 0x1C-0x1D - controls camera angle 0x1E-0x1F - battle pads & background, other data: 7th bit: Bike not allowed (0 = true, 1 = false) 10th bit: Flying not allowed (0 = true, 1 = false) don't know exactly what the other bits do 0x20-0x21 - more camera angle crap, shifts the viewing position x y? 0x22-0x23 - always zero 0x24-0x25 - flyto-x coordinate 0x26-0x27 - always zero 0x28-0x29 - flyto z coordinate (auto drops to floor I think) 0x2A-0x2B - always zero 0x2C-0x2D - flyto-y coordinate 0x2E-0x2F - always zero
Last edited by Kaphotics; Jun 13th, 2012 at 04:05 PM.
trying to wrap my head around the basic structure of scripts...
picture below is notepad++ and the script file of 316 (for desert resort) split up into common pattern chunks.
I wasn't sure on the endianness of the structure so I assumed nothing; but it looks like there is 1 byte instructions and 02 00 is "end" just like in gen 4.
Last edited by Kaphotics; Jun 9th, 2012 at 01:41 AM.
mmk so toying with the known behavior of the script, I see that each darmanitan script has 2 references to Ragecandybar (hex 0x01F8),
after changing it to Life Orb (an item in my inventory), the game first checks if HEX is in your inventory, the second one is to remove HEX from your inventory. So I was able to encounter Darmanitan by consuming a life orb ^.^
In the above pattern map, the gold and dark blue highlights contain the part of the script. The rest of the script is almost exactly the same, bar some readlength data.
Looking at the first darmanitan script, we see "DE 03", which tells us to do something 0x03DE... which just so happens to be right where a 02 00 happens. So this is either a readlength or jumpforward XX for data instruction.
"28 00 77 40 02 00" (I didn't see this 02 00 at the time and didn't separate it out... oops!). However, there's another descending number that occurs before 03DE... "0397", this readlength points to some other data that is right below all 5 darmanitan scripts starting with 0x10; it also is right after 02 00.
So, this pretty much confirms that "02 00" means end line/script... there arent many occurrences of 02 00 that aren't "ends", so it should be a good starting fact when figuring structures out.
might as well look at scripts of a smaller map just to get my bearings... like in your starting room for starters.
detects if it is black or white (english for now), and displays the zonedata. tip: use the town map to see a whole load of map IDs rather than manually going to them; when you select a location the game pops up the zonedata!
Woow thank you so much for this helpful tool!
Thanks to you, I edited a script, so that a person at the Day Care @Route 3 gives away a Pokémon Egg!
There's one little problem, though.
You see, I copied the Egg event from Route 18 (where you could originally obtain a Larvesta Egg). It's completely working, however, that event takes 8 lines of text.
I edited a plain overworld that stands in the Day Care. So that overworld now has the new Egg Give Away script. However, she uses other text lines. I figured out that 3D 00 00 04 XX XX or 3C 00 00 04 XX calls up the textbox, with XX XX being the text line for that map. So it uses the text line of a certain a/0/0/3 file that's connected with the map.
My event uses 3D 00 00 04 00 00 till 3D 00 00 04 07 00, which is a total of 8 text lines. However, though I can change that, I still need 8 lines for my event. But I can't add new lines using PPTXT. How do I add new text lines to a certain a/0/0/3- PPTXT file?
Oh right I totally forgot about the dialog file! Zonedata determines which one is pulled up -- it's 0xA-0xB to decide which text file is loaded. I've updated my post with the zonedata structure with this info.
I didn't do anything related to translations so I have no experience with that narc, but I can help with that!
Text Script Codes -- With this you should be able to format your text to a readable string, and I don't think there's any sort of syntax for new line. After looking at the structure of what's displayed with PPTXT, it looks as if just pressing enter creates a new line. But that doesn't work!
I believe it's because PPTXT doesn't allow the change of line length, because it simply isn't expected with all the past use. I'mma take a look at the src
Last edited by Kaphotics; Jun 13th, 2012 at 07:44 PM.
e: forget that, why can't you just add to the end of a given file with pptxt then point the script straight there? i just tried adding some lines of text and it seemed to work ok.