News:

As a consequence of the forum being updated and repaired, the chatbox has been lost.
However, you can still come say hi on our Discord server!

Main Menu

Basic Room Scripting Guide [GS2]

Started by Salanewt, 07, February, 2015, 12:41:13 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Salanewt

Yep. A scripting guide that will cover some of the basics for things like object interaction/placement and events. I'm going to try doing this in a format where other people can easily contribute and I can directly link to their comments. Same applies to other topics (such as the one Atrius posted about adding/removing PCs a while back) and stuff. Please note that this guide mostly applies to GS2, but it can certainly be helpful for GS1 if you know where to look. Special thanks to Fox for much of his work with the hacking documentation he created, which is where a lot of the information from this guide comes from in one form or another, and the same to Atrius for similar reasons (the editor especially, but even with other things).


Basic Scripting Guide

Lesson 1: Introduction (Basic Code and Flags)

In order to do many things with scripting, you'll need to have at least a basic understanding of assembly. Mainly Thumb. While this isn't necessarily required for everything, the big thing that this is needed for are flags. I think there's a Thumb guide floating around in the downloads section that briefly details most (if not all) of the instructions the GBA uses, but for now I'll only go over a few of them. I would either grab that guide if you don't already have it or grab an assembly compiler. Or both. The section below is spoilered for those who already have a basic understanding of how it works, but still need the guide for other reasons.

[spoiler=Basic Assembly/Code Tips]First off, registers are basically used to store information that may be used at any point within a function, such as values or addresses. The standard registers are r0-r7, but higher registers are commonly used to store information for longer periods of time and/or across functions. They can go as high as R16 for the GBA's assembly format, although the highest few registers are usually labeled differently (PC, SP, LR, etc.) and serve very specific purposes; 0-7 are the practical ones that you can use for almost anything, although 8-12 can be used from time to time when you need more registers to store data.

Then you have hex/decimal differences and endianness/endian, which refers to the way data is organized and/or read. Decimal values are obvious, but hexadecimal will generally start with a prefix (such as "0x" or "x"). Endian works like so; 12345678 will be read in that order in big endian (32-bit), but as 78 56 34 12 in little endian (8-bit). I will generally refer to such arrangements as #-bit, which refers to how long such a value would be in binary (e.g. a single byte has 8 binary bits of either 0 or 1, so it is 8-bit).

PUSH and POP basically start and end most functions, and can temporarily clear out certain registers for the duration of the function. One way to explain this would be like shifting papers around in a file, but I don't need to get too technical about it (I'll explain more about it with some future examples).

MOV and ADD are fairly self-explanatory, but come in different formats. SUB and MUL too.

LSL/LSR/ASR each shift data, and are commonly used for basic multiplication and division calculations. These are especially useful for calculating numbers higher than 255; can be pretty handy with MOV and ADD. I'll explain more later, but a programmer's calculator will make things much easier.

BL basically branches to a function, and then links back to the next instruction once that function has been fully executed. This is especially useful when you have multiple scripts that share the same function. Branching is relative to the instruction's position.

BX is branch and exchange, which basically works by branching to whatever address a specific register holds. Great for branching over really long distances.

And finally, standard branches. There are two kinds; standard branches (B) and conditional (such as BEQ/branch if equal, and so forth). The latter are typically used after CMP (compare, which has different formats), whereas the former can simply be used for whatever purposes you need them to fulfill.

I'll be a bit more specific about some of these points later, but you can read up on some things here if you want to know more now.[/spoiler]

Now for flags. Flags are crucial for any sort of event that is not persistent. GS2 generally uses the following flags for the following purposes (and they can all be viewed and toggled through the debug menu):

Quote from: Flag Purposes000 - 1FF = General Data that includes practically everything you could use anywhere in the game. Character/Djinn flags, and what not.
 180 - 1FF = Area flags (Flags are set when you visit the entrance room of an area.) I'm guessing there are unused flags mixed up in this bunch.
200 - 2FF = Room-based flag bank. These are reset back to 0 when you switch between rooms.
300 - 3FF = Area-based flag bank. These are reset back to 0 when you switch between areas.
400 - 41F = Shop flags. Each flag is for each shop, and they are set when you visit them the first time. The order of these flags match the Shop list in the editor.
420 - 5FF = Probably unused?
600 - 782? = Enemy flags. These are set on first-kill of an enemy. Each enemy has a flag. (?)
783? - 7FF = Probably unused?
800 - ??? = Story flags. (Cutscenes/etc.) Not sure where this ends, but I know the A80 section has story flags for Anemos Inner Sanctum.
E00 - FFF = Treasure flags (in some capacity or another, including Mimics).

And the following functions deal with flags, including setting and clearing them. There are a couple more, but these are the main ones the guide will be using (especially the first one).

Quote from: Flag Functions08016CE4 = read_flag(flag_number) as Boolean
08016CFC = write_flag(flag_number)
08016D18 = clear_flag(flag_number)
08016D34 = toggle_flag(flag_number) as Boolean //Returns 1 if toggled on, else 0 if toggled off.




Lesson 2: Triggering Events [WIP - Will finish later, need sleep]

So in order to actually have a script do anything, you have to be able to trigger it. There are about three (or four) different ways to do this, although I'll mainly focus on the first two for now and I will be using a room that you normally can't access in the game. YAMTEST2 is actually supposed to use it though, as a couple of the tile-based scripts exist in the code but have no method of triggering them normally. You can change the 16-bit value at #080F21C4 to x0141 if you want to fix this yourself, which might just make the next parts of the guide a little easier to follow along with.

[spoiler=Long Lost Room!][/spoiler]

Interaction: The most common trigger method. This largely includes talking to NPCs or using utility spells, and is possibly one of the easiest ways to trigger a script. This is also a pretty simple thing change, but keep in mind that a lot of the utility spells are specifically coded to do certain things (i.e. Lift lifts things), so you'll have to keep that in mind when changing utility interaction.

Tile: Scripts that only work if you're standing within the right event tile. Spells like Sand, Hover, and Cloak generally work like this. Unfortunately, these sort of triggering tiles are created outside of the room code section, so adding new ones may require you to play around with map data a bit.

Entrance/Exit: Basically scripts that are executed upon entering a room. Can also activate upon leaving a room. Examples include almost any cutscene that happens on entering/exiting a room, and visual effects on objects in the room (such as pre-frozen pillars, or palette swapped NPCs).

Environmental: I'll admit that I haven't done much with these before. I'm using this as sort of a blanket term for triggers that work a little differently, but time sometimes plays a role as well. I think Reveal works this way, and the Gabomba pounding puzzle has a time counter that basically loops Akafubu's dialogue until the circuits line up.


And now for a basic lesson on what I have covered up to this point. Sweet. Well anyway, when you select a sprite on a map, it will display a window like the ones below:

[spoiler=Image][/spoiler]

For this example, our goal will be to change the utility spell that is required to interact with this flame (in either script). Each image has a certain value that is underlined; if you convert it from hex to decimal, it will match the ID of a spell from the ability list. In this case, the first script matches Douse and the second matches Pound. If I recall correctly, the "15" that comes after this denotes utility usage. How the game uses this information is it will allow any ability with matching utility effects to be used on that object, but only if the original ability has that effect; this is how the game lets both Whirlwind and Gale do the same thing, but Gale will stop working if you change Whirlwind's utility effect. Anyway, in order to change it (at the time of this post), you will need to go into the code. How do you do that? Simple, you click on the gray button that says "Map" and select "Code Pointers" instead. Oh, and the code for each of these will basically remove the object from the map.

[spoiler=NPC Data][/spoiler]

NPC/object entries. How NPC entries are organized is that each one has a certain amount of space where their data can be found. They start with sprite ID, but it also includes coordinates and such. This table ends with the highlighted "FFFF" at the bottom of the boxed info, meaning that there are only four objects on this map. If you remove this in a portion of map code with multiple NPC sections (generally when the code is shared between multiple rooms), then this will happen.

[spoiler=FFFF Gone][/spoiler]

Moving on.

[spoiler=Event Data][/spoiler]

Now this is where the events are organized. I think how they work is basically "interaction type -> interaction source -> flag (I think can't remember 100%) -> pointer". The "interaction type" data is basically what can be seen in the left columns as seen in the "NPC Data" image. The "interaction source" value basically defines what that event should be assigned to (either NPCs/objects, which I can't remember 100% where these IDs are assigned but they are all together along with entrances and such, or tiles on the map like in the very first image). If you change the corresponding utility interaction byte to match the ID of a different utility (don't forget hex/decimal conversions), then that ability has to be used instead. Keep in mind that the images display the code in 16-bit, but this arrangement can be changed in the editor; look for matching values to figure out exactly what to change.

So with this knowledge, you can essentially change any event so that it requires a certain utility spell. You can play around with this a bit by looking at other objects (such as standard NPCs) and doing a little more than this.




Lesson 3 - Idle Scripting

Okay, so this section will deal with how to change an object's idle script/behaviour. There are two options for assigning one to an NPC; you can use a preset, or you can code one from scratch. I'll explain that in a bit, but for now we'll go to room 133. Starting with images, and focusing on the father figure of the island. Yeah.

[spoiler=Pops][/spoiler]

So as you can see here, I'm hovering the cursor over that one value to reveal that it's the "idle behaviour" for that NPC. I'm also viewing "NPCs 2" and "Events 2" because this room shares its code with a few others, and these are the NPCs and events that are assigned to this one. We also need to view the map code to be able to see what to do here. Oh, and hit the 32-bit radio button!

[spoiler=Event Data][/spoiler]

Right. I already covered how to get here in the previous section, but now I'm going to go over something new here. The first 32-bit string contains a 16-bit sprite ID and something else, while the second 32-bit string contains the idle script ID (if preset) or pointer (if custom). There are four objects, and Pops is object two of four in this room (address is #0200C964). If you want a preset, all you need to do is grab a value from the following list and write it in:

Quote from: Presets
0 - Hides from view
1 - Stand still, only rotates if speaking to the player (or other similar occurrences)
2 - Randomly walks within a certain radius; can be pushed a certain distance away, but will try to return "home" (rough base coordinates) if pushed to bounds of radius
3 - Similar to 2, but seems to move slightly smaller distances before stopping to rest
4 - Similar to 2 and 3, but never stops moving
5 - Same as 1 (? - Need confirmation)
6 - Rotates to always face the player
7 - Same as 1, but no collision (can walk through object) and doesn't render shadow; can still interact with the object in certain ways, like talking
8 - Similar to 1, but constantly quivers

I think I have them all, but I could be wrong. Values 9+ all seemed to be the same as 1 for some reason, but there could be other differences that I failed to notice.

However, if you want a custom script, then you'll have to code one in yourself and type in its address instead. I'm going to do a couple things for the first example script; turn Pops into a sparrow and expand the amount of space I have to work with in this room. Hit "Tools" to do the second yourself if you want, but just keep in mind that you should probably keep a backup just in case. You probably won't need too much space either, the image provides the limit that I'll be using for this one script.

[spoiler=SPACE!][/spoiler]

Next, you need to decide where you want your new script to go; I'm putting mine at #0200CF18, but you can put yours wherever if you have enough space for it. If you've been following along, then you should know to replace the "idle script" value with the address in the NPC's object data. Don't worry if the pointer goes to nothing, it will be treated the same way as idle script 1 if there is actually no script to follow.

I would view this in 32-bit to make reading it a bit easier, and I also recommend using VBA's memory viewer and a .txt file when planning out a custom script; much faster than repeatedly changing and saving values in the editor.

[spoiler=Scripting Code/Format - Long]Every [] and <> is a 32-bit value; The number of arguments are in ()s or {}s, and are explained in their descriptions in <>s
E.g. [27](1) = 00000027 000000## for instruction [27], which sets an object's sprite animation to ##

Some of these are pretty simple, but some of them are also pretty complicated; I'll focus on the simpler ones for now.
(blank) = Unknown
(?) = I'm not 100% sure on the details and/or am not sure how many arguments are used, info grabbed from other files/docs
(???) = Theorized
Going to work on filling in the blanks later on, want to focus more on basics right now
Quote from: Scripting Code
[00](1) - Wait until <#> frames
[01](0) - Wait until finished
[02](3) - Set position to absolute <x><z><y>; set to ground if <z>=1
[03](0) - Set position to absolute 0, 0, 0 (coordinates), and to ground
[04](3) - Set destination to <x><z><y>
[05](3) - Set relative destination to <x><z><y>
[06](?) - Set direction(?)
[07](?) -
[08](2) - Set destination relative to stack values, <a><b>(?)
[09](3) - Set random destination from <a> to <b>, with a max distance of <c> (larger numbers are more visible); ignore collision
[0A](3) - Set random destination from <a> to <b>, with a max distance of <c> (larger numbers are more visible)
[0B](0) - Positioning-related(???)
[0C](0) - Camera-related(???)
[0D](2) - Jump <#> times (xFFFF = limitless) to <arg> (or beginning if left blank) as defined by another instruction earlier in the code(?Looking for <arg> now?)
[0E](?) - Jump; finds <0>(?)
[0F](1) - Jump if flag /= 0
[10](1) - Jump if flag = 0
[11](?) - End script if <17>, end <49>(?)
[12](1) - Read flag
[13](1) - Read and set flag (flag on)
[14](1) - Read and clear flag (flag off)
[15](1) - Read & toggle flag (reverses flag)
----
[16]{2} - Variable set; {} = ()
[17]{2} - Variable add; {} + () will equal a new {}
[18]{2} - Variable if equal(?)
{00} - Change script(?)
{01} - Change position in script
{02} - Relative direction(?)
{03} - Relative direction(?)
{04} - Relative direction(?)
{05} - <x> coordinate
{06} - <z> coordinate
{07} - <y> coordinate
{08}
{09} - Sprite <x scale> (stretch/skew); shadow and collision not to scale
{0A} - Sprite <z scale> (stretch/skew); shadow and collision not to scale
{0B} - Sprite <y scale> (stretch/skew); shadow and collision not to scale
{0C} - Relative <x> destination
{0D} - Relative <z> destination
{0E} - Relative <y> destination
{0F} - Movement <speed> a
{10} - Movement <speed> b
{11}
{12}
{13}
{14}
{15}
{16}
{17}
{18}
{19}
{1A}
{1B}
{1C}
{1D}
{1E}
{1F}
{20}
{21}
{22}
{23}
{24}
{25}
{26}
{27}
{28}
---
[19](?) - Normal movement; also player state
[1A](?) - Overworld movement; also player state
[1B](?) - Climbing wall; also player state
[1C](?) - Climbing rope; also player state
[1D](?) - Walking rope; also player state
[1E](?) - Sand movement; also player state
[1F](?) - Overworld feature; ignore collision
[20](?) - Ship movement; also player state
[21](?) - Hover Ship movement; also player state
[22](?) - Sand overworld movement; also player state
[23](?) - Hover movement; also player state
[24](?) - Slippery movement; also player state
[25](?) - No movement; menus/psynergy shortcuts available
[26](0) - Delete self (can't interact with it)
[27](1) - Set <animation>
[28](1) - Adds 2 to index in script; pointless(?)
[29](1) - Plays <audio clip>
[2A](1) - Plays <audio clip> if there are at least two nearby objects(?); audio can be muted if not on screen, but the script will still continue
[2B](0) - Set new script <address>
[2C](0) - Sprite off/Invisibility; no shadow
[2D](0) - Sprite on/Visibility
[2E](0)
[2F](0)
[30](2) - Set destination to <x><y>
[31](?) - End script if <17>, end <49>(?)
[32](?) - End script if <17>, end <49>(?)
[33](?) - End script if <17>, end <49>(?)
[34](?) - End script if <17>, end <49>(?)
[35](?) - End script if <17>, end <49>(?)
May be more here...
[/spoiler]

Okay, so I guess there's no better time to go over a custom script than after I have gone over some of this stuff! I'll use one that I made just for that swallow; it's small enough so I can go over it pretty quickly and so you can enter it in yourself if you want.

[spoiler=Captain Sparrow!][/spoiler]

I took the liberty of colour-coding it; black lines are standard instructions, blue are arguments (each argument belongs to the most recent instruction in the script), and gray means it is not a part of the script. On top of this, I'll briefly summarize what this script in particular does.

Going by what the list above says, the bird will move to a random location within a given radius, wait 22 ticks before changing to animation #1, wait 296 ticks before changing to animation 3,  and then play audio clips x104 and x106 if it's on screen with two(?) objects (with five ticks between each clip) before looping back to the start of the script (xFFFF means that it will jump to a certain position forever, and the fact that a position has never been set means that it will loop to the beginning). Here's a video if that doesn't help much.

[spoiler=Video]
[/spoiler]

So yeah, I feel confident enough with this section to move onto something else for a bit. I'll certainly revisit scripting again later on, but I have covered the basics and even provided a decent example of what you can do with this knowledge. On top of that, it should be pretty simple to do things never before seen in GS if this bird is anything to go by... Like a phone ringing at an inn, or a couple dancing at a street festival.




Lesson 4: Adding New Objects + Assigning Stuff

Okay, the plan this time is to go over expanding the object and event lists and adding new entries to them. In order to help you understand if you don't already, I'll need to introduce you to two assembly instructions (or at least these versions of them): LDR and BX. The image below shows you the basic for how to find a pointer, but I'll clarify a bit; an orange box indicates the pointer that the code reads (using LDR, which in this case reads a 32-bit value/pointer from the address specified in the disassembler) and branches to (using BX), a green box indicates NPC, and a red indicated events. It appears that every map's code begins with seven LDR branches, and the NPC/events pointers are always 4 and 5 (respectively). The image simply shows how to follow them to find the NPC/object list, but you can do the same thing to locate the other one. Well anyway, on to room 202.

[spoiler=Long (or is it wide?) image][/spoiler]

So now you should know where those pointers are located. All you really need to do from this point is go to the "Code Hex" part of the editor, and then use the "Resize" option from the tools menu to make the map code bigger when you go to edit the pointers themselves (which should appear near the LDR/BX instructions for them). Oh, and you'll have to copy+paste all of the existing NPC/event data and move them to their new locations of you want to keep any of the old stuff, but that isn't really mandatory (just make sure you end them with xFFFF when there are no more entries in a list). Likely with the import/export tools, though I have to admit I have little experience with using those.

Okay, so now the next step will be to add a new NPC. I'll just leave all of the existing ones for dead and start anew in the guide, but that isn't at all necessary should you wish to keep them. First step, if you are relocating the object bank, would be to expand the size of the map code like so:

[spoiler=Resize][/spoiler]

The next step would be to change where the game reads the object bank. If you were following along and found the LDR commands like in the first image, then what you should do is return to that spot and change the pointer (and it needs to be exact). I would normally recommend not placing the object table directly after the existing event table so you can add new events without having to move either table again, but in this case it doesn't matter much.

[spoiler=Repoint (very thin orange box)][/spoiler]

And then go to that place and add some data for each new NPC you want; you need to plan out the table in code before you can play with them on the map. I'm just going to add three new objects here, but you can add more or fewer if you wish. More might be better though, or else there's little point in even moving this in the first place.

[spoiler=Object code][/spoiler]

So I blundered here because I wanted to add three new NPCs that could be played around with on the map, but I forgot to account for the fact that the first two objects in the original table seem to be lash pegs. They tend to work a bit differently from other objects (I think either used in event code or map initialization, but I don't have a whole lot of experience dealing with the pegs in particular). It doesn't really matter for the purposes of this guide at least.

[spoiler=Senator][/spoiler]

So I mostly just added random data into these entries because the bulk of it can be changed again by selecting the object on the map. Anyway, the goal now is to give this senator a couple new scripts because he is apparently a locked door with people arguing inside of him and a plant. But first...

Script format review! You can look at this image to see how the event section looks if you need a little refresher, because we're finally going to go over what everything is! Or at least the image is.

[spoiler=Event Format][/spoiler]

Quote from: BonkInteraction/etc. Code = I covered some of this earlier, but I'll specify and maybe even merge the two sections at some point
- Blank (00s) = No specific interaction, NPCs typically do this for simple dialogue and the like
- ##15 = Requires something to interact with it, most often utility spells

Flag = I haven't done a whole lot with this, but this is basically how you play with flags and stuff; may also tie in with yes/no options (which are text/dialogue commands)

ID = The script will be assigned to whatever object/tile has this ID

Script/Dialogue = The nice thing about this is that, like idle scripting, you can just write the ID of a line of text and the NPC will say it with no other scripting required. However, that's only really good for simple dialogue for the most part, as a lot of the time you will need to do some basic assembly if you want anything new or exciting.

Okay. So now the goal is to go over how to assign scripts to the new NPC. The way IDs work in this section is that it lumps all of the tile scripts (which include entrance/exit warps) and objects together; they are based on the order they are listed in the code, meaning that object IDs continue off of entrances and exits. The editor does not give you these IDs in its interfaces, unfortunately, which means that the first thing you need to do is locate the Entrance and Exit Initialization portions of code. Both of which may be located through the Code Pointers list as usual.

I won't go through the entrance/exit formats yet (especially since Atrius made a topic about them a while ago), but the entrance section ends in a similar way to the object list by using a bunch of xFFs. In room 202, which is the one I'm working with right now, there is only one entrance script. There are also six exits. Since IDs seem to start at 1 unless I'm missing something, 1+6 = 7; the first object will start right after that at 8. Now to go to the actual code for what I did...

[spoiler=IDs][/spoiler]

I mentioned earlier that I forgot to account for the lash pegs or whatever, so I added three objects and changed the senator NPC into the third object of the map. All you need to do to find your object is to keep everything I have mentioned in mind, like I did in the picture.

Note: If you're struggling to find an object on the map in here, you can temporarily change its sprite ID to one not normally found on the map, convert the ID to hex in a calculator, and then check each object in the NPC/object section until you find it. Assuming the editor shows it on the map of course.

Okay, so now we know what their ID is. All we need to do now is scour the event list to remove any that they already have (which, while not necessary, will allow me to work with a clean slate for the remainder of this lesson).

TO BE CONTINUED!


And now for the basics of NPC scripting! I was going to make a couple new scripts from scratch, but there just happens to be an NPC in the senate building that does some of what I wanted to do... And is also a good point to end this post and move everything else to a new one, where I really will start covering assembly. So I'll be using him instead and splitting assembly stuff to another post. - May or may not go through with this part, depending on how much I can do with what I am working with.


Coming Soon-ish:

Upcoming goals for this lesson:
- Assign dialogue (both spoken and mind reading) to new NPC
 - Will also cover how to assign events to specific objects (tiles are easy enough to figure out if your copy of the editor displays them, so only objects for this part)
 - Also perhaps an emote bubble or two, but I can't guarantee that
 - May also make use of yes/no options, or at least assigning the results you get for each option
- And finally, the new NPC will use a flag to decide what to say; first time using flags in this guide







Oh right, I'm also planning on reorganizing this post sometime to make it more compact and easier to understand. Might flesh out a couple key points as well, or even restructure the entire thing. Yup.

All future lessons will be in another post. Mainly because this one is getting terribly long. Will update with a link when I actually make the post, but all I will guarantee for the next part is a brief introduction to thumb assembly (which may be vital to a lot of your scripting needs).
Oh yeah baby, £ me harder.

Fusion is just a cheap tactic to make weak Adepts stronger.

Yoshi's Lighthouse is a hacking website in progress. Why not check it out if you like Yoshi or the Mario & Luigi games?

Mion Sonozaki

Waiting diligently for the next part of the guide. :)

Salanewt

Groovy. I just added a small update, but I need to do a couple things right now. The plan is to continue later, so taking a bit of a break will help me decide what to go over next. Want to cover some of the basics first before making more specific guides like adding NPCs or boss fights.

Oh, and I want to cover the basics of the non-assembly scripting format too. Might do that next, which would let me come up with a custom movement script for an NPC.
Oh yeah baby, £ me harder.

Fusion is just a cheap tactic to make weak Adepts stronger.

Yoshi's Lighthouse is a hacking website in progress. Why not check it out if you like Yoshi or the Mario & Luigi games?

Caledor

I know I'm not going to use this (just 'cause I'm not intrested in story editing) but a high praise for this is almost mandatory. Thank you for your efforts in making this guide, Squirtle.

Atrius (He/Him)

Great work, Lord Squirtle!

QuoteOh, and I want to cover the basics of the non-assembly scripting format too. Might do that next, which would let me come up with a custom movement script for an NPC.
The editor's idlescripting.ini might help a bit with that.  I also managed to dig a couple old .txt files up from my GS hacking folder that might help, I've attached them.  Looking through my memory locations list, looks like 0x0802F204 is where the pointers to the ASM functions for each scripting command are.
[sprite=220,4,0]I'm shaking my head in general disapproval of everything[/sprite]

Daddy Poi's Oily Gorillas

QuoteThey can go as high as R16 for the GBA's assembly format
I guess you are counting the CPSR?

Quoteare usually labeled differently (PC, SP, LR, etc.)
Might be worth noting that this might be the case because they have a specific purpose?

QuotePUSH and POP basically start and end most functions
Well, not exactly "start" and "end" them, but they often appear there when you need more registers than r0-r3... Since the game assumes r0-r3 are always free, where-as, the rest aren't, so those variables would need to be withheld first (aka: Pushed to the stack to be popped back in), when used in a function...
And even so, The return address can often still be put in the stack anyway...

QuoteAnd finally, standard branches. There are two kinds; standard branches (B) and conditional (such as BEQ/branch if equal, and so forth). The latter are typically used after CMP (compare, which has different formats), whereas the former can simply be used for whatever purposes you need them to fulfill.
Typically, yes. But I believe cmp just alters the Z flag in the CPSR flags. (And other instructions can altar these flags too.) When a conditional branch is executed, these flags are checked to determine whether to mae the jump or continue pass the branch.

QuoteThis table ends with the highlighted "FFFF" at the bottom of the boxed info, meaning that there are only four objects on this map.
Perhaps it's also worth mentioning the 0s following are part o the last "table end" entry? Although, it probably wouldn't hurt if that space was removed, so....



QuoteThe editor's idlescripting.ini might help a bit with that.  I also managed to dig a couple old .txt files up from my GS hacking folder that might help, I've attached them.  Looking through my memory locations list, looks like 0x0802F204 is where the pointers to the ASM functions for each scripting command are.
Yeah, I believe I actually looked at the INI when recording related data in my doc/wikia. Don't under-estimate my documentation. :)
Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)

Salanewt

#6
Caledor: Thanks! I just hope I don't screw it up.

Atrius: Aw sweet, thanks! Just downloaded your files, as I'm sure they will help me immensely. Especially because I have only really played around with idle scripts a couple times before, so this and the data/hacking doc will help me plan out a nice little process for customizing a new one.

Fox: On the code stuff, yeah. I'm going to go into a little more detail with the registers and instructions when I actually start using them for things, since only a basic understanding of what they are is needed until I start using them in sample functions. I might just rename that first section to "Introduction" so I can justify not explaining this stuff right off the bat. On that note though, I'll likely rephrase the register stuff a tiny bit so the section is a little more specific in how they work.


Oh yeah, the next update will probably include a custom idle animation. Want to make it a bit creative, so I'm going to brainstorm ideas and try something out with a clean ROM before I make a post.


Edit: Micro update on big/little endian and #-bit/binary terminology, since not everyone reading this may understand what the random references to this might be. Also tweaked a couple sentences and sub-headers to be clearer.



Very tiny edit: I added a small explanation and a picture to show what happens when you remove the "end of object" identifier in a room that shares its map code with other rooms. The results are as you would expect, but I figure it should make things a little easier to remember. Also added a bit of Section 3, but I'm going to add to it later.
Oh yeah baby, £ me harder.

Fusion is just a cheap tactic to make weak Adepts stronger.

Yoshi's Lighthouse is a hacking website in progress. Why not check it out if you like Yoshi or the Mario & Luigi games?

Mion Sonozaki

Bumping.

Our lord and savior of GS2 hacking has updated his guide!

Salanewt

#8
Heh, um, thanks for the compliment!

Also another small update, this time with some scripting commands (going to update later with a brand new custom script for a bird). I have to admit that I'm a tad confused about how the jumping ones work, so I just hope I can get it soon so I can have an example script available for viewing.

Edit: Also kind of lost on how the "set random destination" ones work at the moment. Those are the main ones I would like to figure out, but I'll keep trying.
Oh yeah baby, £ me harder.

Fusion is just a cheap tactic to make weak Adepts stronger.

Yoshi's Lighthouse is a hacking website in progress. Why not check it out if you like Yoshi or the Mario & Luigi games?

Daddy Poi's Oily Gorillas

#9
So, is this going to include everything about Map Code?

In that case, there are many questions I could ask...

Are the 7 public functions at the start of Map Code only called on map loading?
And what checks do the seven functions make? Etc. In the idea that an automated management system could be made/coded(?)
Since the first one is general init, and the next six are more specific, it could be possible that the latter six might do, though...

Checks I've noticed:
-Map #
-Door #
-Flag #

And what unique things do they have?
-The seventh function has tile assigning function calls, what it's main purpose is for...
-Many functions return pointers for what their main purpose is for.
-Table modding based on condition, instead of assigning a new table...

Functions used by the six latter functions.... (Besides flag checks)
080D3118 = setPosition(npcSlot,x,y) (With height check.) (7th function)

Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.


The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)

Salanewt

Map code, hm... It will cover a fair amount, but I'm probably not going to go into too much detail on some things for a while yet. The stuff in your post sounds fairly advanced compared to what is being covered in the first post, so I'll probably wait until the first 9 lessons are all finished (and if I can figure out how it works, I haven't really looked into it before). Which reminds me, there isn't a new update yet but I have updated the first post with point-form notes on the guide's structure for the next little bit.

That being said, I definitely want to go into more detail on tiles and tile scripting at some point. Especially if I can make a basic Cloak puzzle like in GS1. Probably some camera stuff too. Oh, and maybe the ability to alter weather effects or move treasures around. 
Oh yeah baby, £ me harder.

Fusion is just a cheap tactic to make weak Adepts stronger.

Yoshi's Lighthouse is a hacking website in progress. Why not check it out if you like Yoshi or the Mario & Luigi games?

Mion Sonozaki

#11
Glad to see the plan for the guide coming along. Keep up the good work!

Looking forward to Shop Keepers.

I hope I will learn how to enable certain shopkeepers only after a flag is set. So if you return to Daily after Isaac's party, it has a new shopkeeper with better items, for example.

Salanewt

Thanks!

I think I'm planning something like that, though I was thinking of just upgrading a shop's inventory after a certain flag is set rather than swapping one out. I'll have to wait and see how section 4 goes, since I may just put a small flag guide in there with a new NPC.

On that note, I may or may not make a LttP-style fortuneteller for the shop/whatever section. I think maybe the Tarot Parrot! Might also split it into two parts, no idea.
Oh yeah baby, £ me harder.

Fusion is just a cheap tactic to make weak Adepts stronger.

Yoshi's Lighthouse is a hacking website in progress. Why not check it out if you like Yoshi or the Mario & Luigi games?

Salanewt

Very minor update tacked on to lesson 4, and I'm also changing the structure slightly. Lesson 5 will be a brief introduction to assembly, including a very basic function or two. The rest of this tentative. May not necessarily be in this post either, but here's a general idea for the outline.

Lesson 5: Assembly Intro

Most (if not all) of the upcoming sections will expand on this one in some way




Lesson 6: Items, Gold, and Shopping - Coming after Lesson 5 is complete (not including chests, as that is handled a tad differently)

Will include about four scripts/functions
- Free item if the character does not have one already
- Item trade (i.e. Bottle to Hermes Water)
- Somewhat random trade for money (also including yes/no dialogue options)
- New shopkeeper... somewhere




Lesson 7/8: Either battles or psynergy stuff

- Battles will cover both tile and object-based activation, as well as a tiny primer and/or link to the section about changing battle tunes
- Psynergy includes stuff like bestowing or removing individual spells, though I'll probably tie in a class check of some kind to make this section a bit longer
- The topic that is not covered in this part will be in the next one




Lesson 9: Basic cutscenes (haven't done this before, so it will be a learning experience for almost everyone for sure)

- Will include movement scripts, dialogue, emote bubbles, and maybe more
- This and the next may be in new posts (not sure about 4-7, probably not 4 at the very least)




Lesson 10: Team alteration

- Will add to the topic that Atrius made about adding/removing PCs from the party




Additional goals include clarifying on a couple earlier details and expanding one or two areas; all other sections (if there are more) will be in new posts, as I'm going to cap this one at lesson 10 (or lower).
Oh yeah baby, £ me harder.

Fusion is just a cheap tactic to make weak Adepts stronger.

Yoshi's Lighthouse is a hacking website in progress. Why not check it out if you like Yoshi or the Mario & Luigi games?