USF Hacking? by Pandela at 10:07 AM EDT on September 12, 2022
Has anyone ever managed to edit the music sequence/routine inside of a usflib file? I've read that it is very similar to a psf, and the only psf editor I have found is PSFLab but that sadly has no source available that I can find.
There is no such thing because USF itself is not a sequence format but just a container for a trimmed down N64 ROM, which contains samples, sequences and playback routines in proprietary formats with varying complexity between different game developers. That's one of the reasons why USF cannot display/alter/mute single channels because it has zero control over the actual audio-generation process. USF emulates the audio part of a game. The USF player just "sees" whatever the emulation outputs.
You can refer to Subdrag's N64 Sound Tool source on GitHub to see which game uses which audio system. He and a few other individuals spend 10+ years reverse-engineering hundreds of games to make this kinda comprehensive (although not 100% accurate) list of game's audio engines. To edit any sequence you first have to learn which sequence/sample format a game uses. Some are well known, others are not. Sequences and samples are extracted from the ROMs directly instead of the USFs.
And to be clear PSFLab isn't about editing the sequence data, either. It's an emulator/debugger, the edit commands are for binary patching. The equivalent work for USF is generally done with a general purpose emulator, I used to use Project 64, ugetab used nemu, I think Mupen64plus might be used more recently.
You can edit the data in a USF, and that is sometimes used to fix sequences or change mixes to represent variations. But you'll be using a hex editor, and you'd need to carefully take into account PSF format and SR64 sparse patch if you're adding or removing (instead of just changing) bytes. Sometimes the sequence data for a song is in the .miniusf file, but more often that's just a song select and everything is packed somehow in the .usflib.
Is there anything USFs share in common that could help me in identifying the file structure more? Like which hex might indicate where a sequence is? I'm currently poking around the Glover (U) usflib
@WDLMaster I checked out the sound tool, it says it's an "Sng" and the unreleased beta version of Glover 2 (which also has full soundtrack from Glover 1) is in FLASng. Haven't looked into this much yet. https://github.com/derselbst/N64SoundTools/blob/master/N64MidiTool/Release/gameconfigmidi.ini#L6366-L6428
You won't find anything there because as I already mentioned, USF has no concept of sequences, streams, samples or anything like that. It is an emulator which actually runs an N64 ROM stripped of any non-audio code. It still contains all the sequences, streams and samples but the offsets are not the same as the ones listed in the Sound Tools. You have to locate the USF offsets yourself because USF only keeps a few chunks of data (stored as offset-size-pairs) relevant to audio and re-assembles them in memory in a way that represents the data as it would be in the original ROM with the exception that everything else is zeroed out.
May I ask why you desperately want to go the USF route instead of extracting the stuff directly from the original ROM? The tools are already there and (more or less) functioning including replacement of data inside the ROM.