Closed wschroede closed 3 years ago
The original purpose of the flag log, was to see how and when certain collections of flags are affected by in-game events, so that the state of such events could be set or cleared in the flag editor when setting up a save file for practice, though this use has been largely superseded by savestates. This use-case doesn't require knowing any memory addresses. That, and the fact that flag indices are mostly version-agnostic where as memory addresses are not, is the reason why flags aren't labeled by addresses.
gz defines each flag record as a contiguous series of bits that is accessed as an array of words with an associated word-size, though this might not correspond with the way the game accesses flags in all cases. The word index is the flag index divided by the word size in bits, and the bit index is the flag index modulo the word size in bits, in order of least significant bit first. See https://github.com/glankk/gz/blob/master/src/gz/flags.c for the relevant source code. Flag records are defined here. Each record has a word-size in bytes, a length in number of words, an address, and a label. If you want to manually compute the address of the word containing a flag, you must take the address of the associated struct from the linker script corresponding to your version (found here), add the offset of the record in the struct (defined in z64.h), then add the word index multiplied by the word size.
Cloudmodding has some information regarding flags that might be useful to you; https://wiki.cloudmodding.com/oot/Actor_List_(Variables) has information about how certain actors (specifically chests, but others as well) relate to flag indices. https://wiki.cloudmodding.com/oot/Save_Format explains explains how and where flags are stored, though I believe it might have a slightly different interpretation of how the flags are accessed than gz does in some cases, so beware of that.
I was expecting the Flag Log to report the memory address, flag size, and flag offset in the log but I didn't see that info. Also in the example of a chest I also checked the actor menu and couldn't find the flag associated with the chest. I dug around in the source code some but thought it might be smarter if I just asked. If this information isn't really displayed anywhere is there a good way for me to manually find the flag with info given in the debug menus? Thanks in advance!