Register - Login
Views: 95751727
Main - Memberlist - Active users - Calendar - Wiki - IRC Chat - Online users
Ranks - Rules/FAQ - Stats - Latest Posts - Color Chart - Smilies
11-14-18 12:10:07 AM

Jul - SM64 Hacking (Archive) - How to properly read level scripts? New poll - New thread - New reply
Next newer thread | Next older thread
Doogie1012
Member
Level: 14


Posts: 20/35
EXP: 12553
For next: 518

Since: 10-21-08


Since last post: 8.0 years
Last activity: 5.0 years

Posted on 12-31-08 04:51:26 AM (last edited by Doogie1012 at 12-31-08 04:52 AM) Link | Quote
In my Mario 64 Editor I am currently working on making my level scanner actually jump when it needs to and scan ram segments etc.

Currently it just scans from start to finish which provides inaccurate commands (false postitives).

(Bom-Omb's Battlefield)
405D44 - 06 08 0000 15 000660

Command = 06, Jump to offset in ram segment
Length Byte = 08
Ram Segment No. = 15
Offset = 000660

To be able to allow my level scanner to jump to this location I need to know where Ram Segment Number 15 is loaded, unfortunately my hex editor can only search for 3 hex values at once (17 0C 00).

Based on results from my level scanner this bank is not loaded at the entry-point of the level.

(Just to be clear, everything here is hex, so the Ram Segment is 15 in hex and 21 in dec)
VL-Tone
Member
Super Mario 64 forum moderator
Level: 51


Posts: 370/621
EXP: 994178
For next: 19760

Since: 07-27-07

From: Montreal, Canada

Since last post: 1.0 years
Last activity: 31 days

Posted on 01-03-09 11:35:21 AM (last edited by VL-Tone at 01-03-09 11:49 AM) Link | Quote
RAM segments might contain different things depending on the level. To know what's in it, you need to read the level script in order from the start and then collect the pointers associated with RAM segments (or banks) by looking for commands 0x17, 0x18, 0x00 and 0x01. The two latter commands (0x00 and 0x01) will both load data in a RAM segment and jump to a specific offset in that bank. I could look out for what's in the 0x15 bank for BBB, but it would be better if you could figure out by yourself, as this value shouldn't be hard-coded in your program.

To correctly load a level you have to read level script data in order, starting with the main menu "hub" script. Take a look at this document for some explanations on how it works. The "official" entry point where you should start is at 108A10.
108A10/0000:  1B 04 00 00

108A14/0004: 03 04 00 02
108A18/0008: 34 04 00 00
108A1C/000C: 13 04 00 00
108A20/0010: 00 10 00 14 00 26 9E A0 00 26 A3 A0 14 00 00 00 --Loads Level Script data from 269EA0-26A3A0 into segment 0x14, jumps to offset 0x000000
108A30/0020: 05 08 00 00 10 00 00 00 --Jumps to segment 0x10? What's in segment 0x10?


TT64 though starts reading at 269EA0 at the beginning of bank 0x14 as defined by the 0x00 command found in the little script found at 108A10. The content of bank 0x10 is unknown, but it doesn't matter since the 0x00 command just before will jump to the level script. Bank 0x10 may well be containing the little 108A14 script, so the thing simply loops when you exit the level script (so you get back to the menu).

The 0x0C commands found in bank 0x15 (later if you follow the script) are a conditional jump which will jump according to the current level number. So when reading commands, ignore all 0x0C commands except the one corresponding to the level you want to read.

You should experiment with the TT64 script dumping commands to see how the levels are loaded. Particularly, the "Level script select" category which shows the level as read starting in the menu hub script.

It's important to read/load starting from the menu hub script because some stuff is loaded from there that will be used by the level ( 0x17 and 0x22 commands amongst other things).

The level-specific scripts go back to bank 0x15 using the 0x06 command to read things like 0x22 and 0x21 commands. The thing is, some of these "sub-banks" containing 0x22 and 0x21 commands are shared by multiple levels, so if you change something there, it might have repercussions on other levels, including a possible crash if you change a 0x22 command to refer to a bank that is not used by all levels that depend on this command. TT64 indicates which commands are "shared" with a little "s" in the command list. Those with an "x" are also part of bank 0x15 (or some other bank external to the current level script) but are exclusive to this particular level ie.: they're not shared.

It all reminds me of when I started to comprehend the level script structure a few years ago. As you understand more and more you'll see that complex level manipulations are not that easy to pull off (and from I saw I think you're not even starting to deal with objects (0x42 and 0x43) which are found inside the MIO0 banks).

Edit: I've changed the title of this thread so that it can be used as a more general topic about reading level scripts, and so that newbies (aka n00b) don't think you can create a new thread just for a very specific question that could be asked in an existing thread.



Just a little note: I'm moving tomorrow to a nice new apartment, and my internet connection won't be available until tuesday night.
Doogie1012
Member
Level: 14


Posts: 27/35
EXP: 12553
For next: 518

Since: 10-21-08


Since last post: 8.0 years
Last activity: 5.0 years

Posted on 03-06-09 02:42:48 AM Link | Quote
I've been busy (and lazy), So I haven't been able to develop my program since this discussion much. Before I start to program my 'buffer-stores-ram segment' array, I just wanted to know how to make the program differentiate two commands which use the same number id. (aka switch between reading commands as a Level Script Command or a Geometry Command)
VL-Tone
Member
Super Mario 64 forum moderator
Level: 51


Posts: 409/621
EXP: 994178
For next: 19760

Since: 07-27-07

From: Montreal, Canada

Since last post: 1.0 years
Last activity: 31 days

Posted on 03-15-09 01:26:12 PM Link | Quote
Originally posted by Doogie1012
I've been busy (and lazy), So I haven't been able to develop my program since this discussion much. Before I start to program my 'buffer-stores-ram segment' array, I just wanted to know how to make the program differentiate two commands which use the same number id. (aka switch between reading commands as a Level Script Command or a Geometry Command)


It's simply a matter of switching to geo layout commands when the level script calls for them (with 0x22 or 0x1F commands). When you encounter the geo layout "end" command (I think it's 0x01, check to be sure), just go back to where you were in the level script.

TT64 builds a table of unique geo layout offsets while reading level scripts and encountering 0x22 and 0x1F commands, then reads/load all geo layouts one after the other after having read all level scripts. But reading geo layouts while reading the level scripts could give you the same results.

You should really try to read scripts by following all the jump/goto/gosub commands instead of linearly read the content of banks. You should take a look at this document and start reading your data from there (either at 108A10 or 269EA0), then follow the jump commands. (Don't forget that the 0x0C jump command is conditional on the current level).
Next newer thread | Next older thread
Jul - SM64 Hacking (Archive) - How to properly read level scripts? New poll - New thread - New reply




Rusted Logic

Acmlmboard - commit 220d144 [2018-11-04]
©2000-2018 Acmlm, Xkeeper, Inuyasha, et al.

27 database queries, 2 query cache hits.
Query execution time: 0.179155 seconds
Script execution time: 0.011745 seconds
Total render time: 0.190900 seconds