Trying to figure out strange .opus files in Made in Abyss

Nazosan

Well-Known Member
OP
Member
Joined
May 12, 2009
Messages
576
Trophies
1
XP
1,090
Country
United States
So I recently got the Made in Abyss game for the Switch. There is a lot about the game that I don't like and a lot I do, but the absolute worst of the do not likes has been solved thanks to some intrepid modders. Of course they're focused on the PC version and I'd like to bring over what I can to my Switch version. Luckily that particular mod works fine on the Switch. However, among the other things they have made mods for, there is a music mod that replaces game BGMs with music from the MiA soundtracks and this is incompatible for the silliest reason: the Switch version doesn't use the OGG Vorbis files that the PC version uses, but instead has a bunch of .opus files (they seem to be much smaller, so I guess it was so they could use much lower bitrates and get away with the quality not suffering quite as much since Opus is even better at bitrates below transparency than Vorbis.) To make matters worse, they aren't proper files. To begin with, they don't have a proper OGG container -- or at least don't seem to. I'm not sure if they even have proper headers at all because I see plaintext files with sample rate, total samples, and loop ranges listed out which they presumably shouldn't need (since they could have put loop tags in a proper Opus file as well.) However, I noticed also the first few bytes are the same across all the files:
Sample.jpg
Perhaps they are actually encrypted, but this doesn't really make sense for several reasons. 1. Anyone wanting to just grab the audio tracks via file rips could just grab the completely unprotected Vorbis files from the PC version. 2. It would mean they've applied an actual generic file encryption across the entire file which is insanely inefficient and messy when there are other formats that support audio block encryption that would be exponentially better to use here. 3. The entire team has had very little time and budget and it shows all across the game with virtually nothing actually being protected -- the actual PAK files themselves aren't encrypted (which makes it all the more insane if the Opus files are the only things that are... Like why would they not protect key game assets, but then protect this one thing you can easily just grab from the PC version?

The only thing I know for sure right now is that if I produce a proper Opus file with a proper container and all the game will not accept it. In fact, it clearly lacks any sanity checks because it outright crashed the entire Switch when I tried. I presume I could possibly produce headerless streams via ffmpeg, but I'm not 100% sure how (ffmpeg is such a pain to learn!) Presuming that's even what it wants...

The only thing I have that may be at all useful is the bottom of usoundnx.txt specifies that they are using "StreamPlayer" with the implication of the comment even being necessary that the PC version uses something else:
//ストリームプレイヤー
//※opusファイルを使用する場合に必要
// ストリームを使用するプレイヤーのIDを列挙する
streamplayer{
PLAYER_BGM
PLAYER_VOICE
}
Google Translate:
// stream player
//*Required when using opus files
// Enumerate the IDs of the players using the stream
Anyone have any thoughts on what it may take to be able to create replacement files?
 

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,284
Trophies
3
XP
12,058
Country
Poland
It looks like pretty standard opus file you can find in Switch games. They are not using standard opus header, but this is how they look in Switch games. Did you try to check if vgmstream doesn't support decoding them?
 

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,284
Trophies
3
XP
12,058
Country
Poland
Can you send one opus file? I have made an opus encoder for different game. They look very similar, only difference is one uint16_t data in main header and that frame header seems to be completely different.
 
Last edited by masagrator,

Nazosan

Well-Known Member
OP
Member
Joined
May 12, 2009
Messages
576
Trophies
1
XP
1,090
Country
United States
Oh, I was fooled by the fact that vgmstream's plugin in Foobar2000 wasn't working. However, when I looked it up they have a "test.exe" version for Windows that can be used to convert audio files and it does actually work and says "Nintendo Switch OPUS Header" for metadata.

I guess the only question then is how would I get audio into this particular format?
 

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,284
Trophies
3
XP
12,058
Country
Poland
Since we tested out some things on DM, I'm sharing here if anybody wants it:
source code:
https://github.com/masagrator/NXGameScripts/tree/main/Made In Abyss/OpusEncoder

usage:
Code:
NXAenc -i input.pcm -o output.opus

Usage: nxaenc OPTIONS
Options:
        -r sampleRate:  Sample rate (default: 48000)
        -c channels:    Number of channels (default: 2)
        -s frameSize:   Size of a frame in samples (default: 960)
        -f frameBytes:  Size of an encoded frame in bytes (default: 240)
        -i inputFile:   Path to input file of raw s16le audio (default: stdin)
        -o outputFile:  Path to output opus file (default: stdout)
Input file MUST be PCM raw audio file in s16le format 48kHz.
 

Attachments

  • NXAenc.zip
    16.4 KB · Views: 51
Last edited by masagrator,
  • Like
Reactions: hippy dave

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
36,798
Trophies
3
XP
28,348
Country
United Kingdom
"it clearly lacks any sanity checks"
Get used to that in game hacking. Any that exist are very rarely seen ones for some text engines, some games having out of bounds options, save hashing and technicalities/almost philosophical ponderings with anti cheat. That said wasting time on sanity checks when other useful to the game things can happen instead is a dubious thing to be doing -- companies won't crash and people won't get pelted with radiation ( https://hackaday.com/2015/10/26/killed-by-a-machine-the-therac-25/ ).

Seems the problem is solved but yeah semi custom formats are often made by stripping things down to raw streams and necessities rather than either trying to figure out some needlessly complicated library (never mind the all too common Johnny just graduated Java school and squeaked his way onto indie game dev porting operation scenario), dodging GPL concerns (OGG et al not having patents applied so gaining that but if the libraries to implement them) or implement unneeded functionality; being all things to all men in the media world is a tricky thing, especially as games likely only need the data*, frequency, number of channels (which usually means mono, stereo or joint, though some are making it up to 5.1) bit depth and maybe internal volume, looping functionality also useful if not embedded within the stream. Occasionally it can also be done to shave a few kilobytes off per stream.
I have seen a few regenerate stripped down things at runtime but that is rare.

*interleaved or not to dodge random reads becomes a concern in some cases.
 

Nazosan

Well-Known Member
OP
Member
Joined
May 12, 2009
Messages
576
Trophies
1
XP
1,090
Country
United States
"it clearly lacks any sanity checks"
Get used to that in game hacking.
I am. It was just worth mentioning that it outright crashed the system so I mentioned it.


Anyway, the Opus encoder works perfectly (though I need to see about tweaking options to maybe get better quality if the game will take it) but I still have to figure out how to modify the "Sound3DS" bfsar file so I can modify the loop data or changing tracks just doesn't really work out. I think it actually has all the files they used to build it still there in the game directory (now there's one for you FAST6191, Switch games are sometimes so lazily built that devs leave their own working files in sometimes, lol. I even found XCFs inside one once.) But I'm guessing Sound3DS could be a SDK thing and if so I presumably don't have access to it. This may require a separate thread even.
 

FAST6191

Techromancer
Editorial Team
Joined
Nov 21, 2005
Messages
36,798
Trophies
3
XP
28,348
Country
United Kingdom
Developer leftovers are always fun, sadly following a few high profile incidents several companies have mandated a scrub of such things so they are not necessarily as common as they used to be/would be expected. We did used to have a thread on the DS for it. https://gbatemp.net/threads/japanese-programming-madness.320192/

Best one so far probably still has to be one of the DS princess maker games that included basically full source code (or full as far as DS stuff goes -- there is some odd stuff with headers being part of the SDK).
 

eviltrainer

Member
Newcomer
Joined
Sep 13, 2009
Messages
24
Trophies
1
XP
64
Country
Brazil
Hey guys!

I'm completely new to the Switch modding scene, but I've beeb succesful in translating 2 games so far. Now, as I advanced to the 3rd one, I hit a wall when tried to port a translation from PC to Switch. By readinf this thread a few others here, it seems like when we face .opus file modding on Switch, we gotta use a game specific encoder tool, right?
The game I'm trying to mod is Resident Evil 0 and I'm trying to port both the translation and a fandub from the PC version into the Switch one. I succesfully managed to extract the gmd files and will start editing them with the PC texts (just replacing them don't work sadly). However, when it comes to the audio modding, I'm facing the issue of having the PC files in .ogg (.sngw actually) but the Switch ones are in that kinda proprietary Nintendo opus format. The NXAenc from @masagrator was the only tool that almost solved my issue, but I used the Made in Abyss fork that didn't convert the pcm correctly to opus.
Any help for dealing with this is much appreciated. Thanks in advance!
 

Nazosan

Well-Known Member
OP
Member
Joined
May 12, 2009
Messages
576
Trophies
1
XP
1,090
Country
United States
The problem I ran into wasn't actually OPUS. OPUS is actually an open standard audio format by the creators of Vorbis. The problem I ran into wasn't the OPUS audio itself, but the way it was actually packed, which was in a proprietary way.

I haven't messed with this game since I posted this a couple of years ago though, so I don't know what may or may not have arisen in all the time since. However, it should be noted that Resident Evil engine and Unreal Engine work very differently, so it is absolutely possible that the things for one simply won't work correctly with the other.
 

masagrator

The patches guy
Developer
Joined
Oct 14, 2018
Messages
6,284
Trophies
3
XP
12,058
Country
Poland
correctly to opus.
correctly to your opus*
Different header is enough to break compability, so it's important to alter code to match header. I have made few versions for each game because they differed in how header looked, I didn't change anything in audio encoder itself.
 

eviltrainer

Member
Newcomer
Joined
Sep 13, 2009
Messages
24
Trophies
1
XP
64
Country
Brazil
correctly to your opus*
Different header is enough to break compability, so it's important to alter code to match header. I have made few versions for each game because they differed in how header looked, I didn't change anything in audio encoder itself
Yeah, that's what I meant. Sorry.

Do you mind sharing how could I edit the header so I can make this work properly? I'm really noob at this so, sorry if I'm asking for something way too obvious lol
I imagine I'm supposed to use a hex editor or something, right?
Post automatically merged:

The problem I ran into wasn't actually OPUS. OPUS is actually an open standard audio format by the creators of Vorbis. The problem I ran into wasn't the OPUS audio itself, but the way it was actually packed, which was in a proprietary way.

I haven't messed with this game since I posted this a couple of years ago though, so I don't know what may or may not have arisen in all the time since. However, it should be noted that Resident Evil engine and Unreal Engine work very differently, so it is absolutely possible that the things for one simply won't work correctly with the other.
Yeah, that's exactly where I'm at right now: trying to figure out how to convert the vanilla sngw files from the PC fandub (actually ogg encapsulated as sngw) into the correct Nintendo opus header file.

1710176677889.png

Here's how the vanilla opus file looks like.

And here's how the PC version of the same audio looks like.
1710176826109.png


I only wish we had a NXAenc for Resident Evil games lol
 
Last edited by eviltrainer,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: Lesbians invented babies +2