Ni no Kuni™ II: Revenant Kingdom

Ni no Kuni™ II: Revenant Kingdom

View Stats:
Zeigy Jun 24, 2018 @ 1:11pm
Music mods?
Anyone know how I can mod my own mp3 music into the game? I need to change the battle music...I need to...
< >
Showing 1-9 of 9 comments
Remnant Jun 24, 2018 @ 6:47pm 
I'd love to know as well, because man the music in this game is a disappoitment. It's actually one of the reason I stopped playing.
Deity Jun 25, 2018 @ 12:56am 
I'm pretty sure thats not possible you would have to change the code since they didnt add a way to mod the game.
0x57A1CFA117 Oct 8, 2023 @ 4:54pm 
Sorry to necro this, but I only recently got the game and figured I'd contribute what I've learned so far so if anyone else comes across this thread looking for information, it can be found (also, I don't think there's any other threads for modding, thus I don't think there's a thread with more up-to-date information).

I too need to change the music. There are like 4 or 5 areas (really actually like 3, Evermore, Goldpaw, and the Overworld) that you hear SOOOO damn much for soooo long working through trying to complete all the quests and get all of the people to your kingdom, that the music just starts to really get to you. I'd mute the music but it'd just be too damn quiet with just sound effects; so replacing them with something more subtle would be ideal! So I set out to figure out how to modify the game files. Looking back, I've made a bunch of progress thinking about what I've learned, but it doesn't feel like it since I still can't edit the files. Anyhow, I detailed my little foray into modifying the game files below.

NOTE: None of the reset of the information in this post, so far, contains enough information to successfully work with the files of the game. It is more of a timeline of events and my thoughts during said timeline that others may learn and either use it as a springboard for them to further the efforts, or use some of the solutions, to the problems I faced, to be able to try other projects. If you're not interested in the timeline, you can safely skip reading :)



So the first file I decided to look at was the conspicuously named file:

cpk_list.cfg.bin

for me, it's installed here:

F:\Program Files (x86)\Steam\steamapps\common\Ni no Kuni II Revenant Kingdom\data

I decided to take a look at the file via notepad. It's a great little tool for being an unbiased viewer. What I mean by that is, it's not going to convert anything for you, it's not going to present anything to you differently unless it has to (i.e. non-printable ascii characters). It'll give you the best raw view of a file contents short of something like a hex viewer only it's less memory-footprint.

To my surprise there looked to be plenty of readable (i.e. English words) text in it. Scrolling right some more, the text kept going and that's when I thought it looked kind've resembled column headers in an Excel spreadsheet (in flat-file databasing terms, the field names of a record). I copy and pasted that into a text editor so I wouldn't lose it (I used Sublime Text Editor because I don't have to save a file for it to recover if the power goes out or the system crashes, etc. But something like Notepad++ probably does that). I looked at some of the text closer and saw a couple of interesting segments of text. I saw LAYLA; this reminded me of the Eric Clapton song. Not wholly relevant. However, I know devs sometimes will codename stuff internally because of some meaning to them. I also found the acronym CPK in the file contents (in addition to being in the filename) so with these two in hand, I did a quick search (using start.duckduckgo.com) and found out, CPK and LAYLA (I later learned to be part of a bigger name: CRYLAYLA) are references to the Crysis engine. Makes sense, and I don't know why I didn't even think to just go there when the damn bootup screen of the game mentioned Crysis LOL D'oh! *forehead slap* In any case, I found some projects on GitHub for handling cpk files. The first one, I found here:

hxxps:/github.com/kamikat/cpktools (replace the x's in hxxps with t)

Unfortunately, this project's last updates were done, at earliest, 8 years ago. NNK2 came out in 2018 I think? So that's 6 years ago, the tools from the repo likely wouldn't work given there was a 2 year span between the tool's last updates and the release of NNK2 and surely the Crysis engine would have had a release between the 8 years and the 6 years ago NNK2 was released (even with a game that can take a few years to develop, the developers may have upgraded the engine during the development cycle). I decided to try the repo code anyhow. Unfortunately, it requires Python 2, I use Python 3 for all my Python coding now a days and py.exe's set up was only detecting my Python 3 installs. I spent an hour or two that night trying to locate where Py.exe was looking for detecting the Python installs I had since I had multiple 3 versions and multiple 2 versions, yet only two versions of the 3 edition were being listed. I eventually gave up. The next day, today, I decided to give it another go, and found it to be using the registry key:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\<versions>

(In hindsight, I probably could use used procmon.exe from sysinternals -- now owned by Microsoft to catch the locations), this registry key was not mentioned anywhere in the py launcher's documentation -- at least that I saw; unless I missed something. I added in my Python 2.7 install and finally py.exe --list was showing my 2.7 install. now I had to install the bitarray package. That was the next super-tricky thing to figure out, I had to figure out how far back, in versions of the bitarray package, I had to go to find a package version that was for Python 2.7. I started reading through the project's closed issue page on GitHub to see if the author mentioned anywhere anything referencing Python 2.x so I could at least have a rough release date to work from when trying to determine which version to try (since there's regular updates). I found issue 74, the author referenced in a reply that the problem, the user was experiencing, would be solved in the "upcoming 1.1.0 release". Jackpot! I got a version to try. I was looking for the wheel file since since pip, back in Python 2 days, started to REALLY have SEVERE issues with forced security checks on SSL connections (due to urllib I think?) and thus would error out. Unfortunately, all that was available for download on pypi.org for Bitarry's releases at that time were 7-zip files. So I grabbed that and unpacked it. Then I was able to do:

py -2.7.64 -E setup.py install

This installed bitarray... Yay, ok now FINALLY I can try to repo project. I then did:

py -2.7.64 -E <path to where I unpacked the cpktools I got from the url pasted earlier>\cpkunpack.py cpk_list.cfg.bin

and unfortunately, got this:

Read cpk_list.cfg.bin... Traceback (most recent call last): File "c:\utils\cpkunpack.py", line 640, in <module> for frame in readframe(infile): File "c:\utils\cpkunpack.py", line 169, in readframe typename = identify(header) File "c:\utils\cpkunpack.py", line 54, in identify raise Exception('Unable to recognize frame for "%s"' % repr(header)); Exception: Unable to recognize frame for "'e\xc8\x01\x00\xf0\xa7#\x00Z\xb0\xa1\x00\x11w\x03\x00'"

I initially thought that maybe I needed a slightly newer version of bitarray as maybe there was some sort of bug, but then looking at the call stack I could tell that it failed inside of the cpktools project inside of a function called identify trying to determine the "frame". It's when I realized that the tool, to confirm my suspicions, was probably right; it was too old and the file format had been updated / changed and the old project couldn't work with what I was trying to present to it.

I then did more searching and came across this project:

hxxps:/github.com/ConnorKrammer/cpk-tools/tree/master

GREAT! The about blurb even says it's for working with CRIWARE's CPK archive format and the last updated time looks about 6 years ago, should be new enough to maybe work with the files. Unfortunately, they had no releases, so I had to compile from source. Pleasantly surprised, it went off without a hitch pretty well compiling it under Visual Studio 2022. It did want me to update the solution file, and for some reason one of the project's target platforms was set to .NET Framework 4.7.2 So one of the project built ok but the others didn't -- they needed to also be set to that, or I needed to set the project with 4.7.2 down to the version the others were at. Either way, no big deal, I set the others to 4.7.2 and everything built. I ran the GUI and opened the bin file. Unfortunately, it didn't show anything. So I thought, about the stuttering problem, and how the stuttering fix on the newest version of NNK2 just causes NNK2 to close right down during one of the boot up screens. I decided to try opening one of the effect files. So I tried to open data/common/effect/posteffect/ee00000/ee00000.cpk

With this file, it showed the "filenames" inside of the cpk file, things were looking up! Unfortunately, when I told it to unpack, that's when Windows immediately kicked the "CriPakGUI has stopped working" error. That's where I left it. I may try to debug it at some point given I have the source and was able to build the entire solution without a hitch, but I kind've need a break at the moment.
Last edited by 0x57A1CFA117; Oct 8, 2023 @ 4:54pm
0x57A1CFA117 Oct 8, 2023 @ 6:18pm 
Ok, so I found out that the game is primarily written in Lua. I decided to revisit that GUI cpk tool project I had the closest results with. Apparently, it was because the line:

dstpath = Tools.GetSafePath(dstpath);

was mangling the path, and then:

string dstdir = System.IO.Path.GetDirectory(dstpath);

was returning an empty string setting up the condition for the call:

if (!Directory.Exists(dstdir))
to return true (meaning the directory doesn't exist; yeah, why would an empty string representing a directory name exist? lol)
and then the line Directory.CreateDirectory(dstdir) to faile since it's trying to create a directory using a string that is completely empty... oops lol

Ah well, easy fix. I rem'ed out the line for dstpath = ToolsGetSafePath(dstpath) -- line 196
in MainWindow.xaml.cs and that caused it to be able to extract correctly (I suppose I should do a pull request to the GitHub repo, but eh.)

I decided to try going after something a little more interesting, the files in the script directory. This time I chose script.cpk. And bullseye! We have a file unpacked with all of the files in the relative directories from where I specified as the destination directory!
The base unpacked directory path, for me is this:

F:\Program Files (x86)\Steam\steamapps\common\Ni no Kuni II Revenant Kingdom\data\common\script\script.cpk_unpacked
(We'll call this BASE_script_unpacked)

I took a look at cb00010.lua.bin inside of <BASE_script_unpacked>\data\common\script\lua\action

Obviously, looking at the filename, the file is lua script code of some kind. However, looking at it in Notepad, the MAGIC NUMBER of the file showed LuaR I wasn't sure what the R was I kept thinking maybe Lua has established other file types for more complex projects or something. I was thinking it was something like Lua-Rust or something. So I started looking for decompilers and found some stack overflow threads where someone suggested different tools depending on the version number. This is where I found out the first byte after the Lua MAGIC NUMBER is the version of Lua used to compile the script into bytecode. Ok, so the R in hex is 52 this means version 5.2 of Lua, now I have a target to find a decompiler for. I used unluac located here:

hxxps:/sourceforge.net/projects/unluac/

and was successfully able to decode the entire lua.bin file into human-readable text! Essentially the source code! Obviously, not to the engine, but I guess all the other stuff. There looks like there may have been some obfuscation that went on with bits like:

... while isEndAnime == false do isEndAnime = funcLuaActionCommand(2363801020, g_obj_hdl_animeHdl) ...

Hard to believe that a human would have no problems using something like 2363801020

But there ya go. All the way down to the Lua source :)

Additonally, the game uses xq32 file (which I think is bone / skeletal / mesh data)


I suppose the only final question that remains, and one I'm not sure I really feel like doing, is decompiling all of the cpk files and then decoding all of the lua.bin files (even if I can do it programatically -- because, then I still have to figure out how to replace the music files and pack it back up lol)

My thought would be to write in functions to sideload mods (even if it's just music files) to override behaviors of the game, that way you don't have to keep decompiling and re-compiling
Last edited by 0x57A1CFA117; Oct 8, 2023 @ 6:19pm
0x57A1CFA117 Oct 8, 2023 @ 8:52pm 
One last update, for the music...
That's found, at least for me in:

F:\Program Files (x86)\Steam\steamapps\common\Ni no Kuni II Revenant Kingdom\data\dx11\sound

Using vgmstream-cli, located here:

hxxps:/github.com/vgmstream/vgmstream

I can convert the AFS2 file formatted audio files into WAV (not sure how to re-encode).
I converted the bgm.awb (~487MB) file to wav (~137MB huh??? Less tracks maybe is the reason?) using the tool, and sure enough, I can play it in VLC and the first song is the song you hear when you get to the main screen when you start the game. Best of all, I don't think this was one of the directories were created, upon unpacking, when I started fiddling with the game files. Which means modifying the music should be a bit straight forward! :)
DarkCraft Feb 28, 2024 @ 2:35pm 
Originally posted by 0x57A1CFA117:
One last update, for the music...
That's found, at least for me in:

F:\Program Files (x86)\Steam\steamapps\common\Ni no Kuni II Revenant Kingdom\data\dx11\sound

Using vgmstream-cli, located here:

hxxps:/github.com/vgmstream/vgmstream

I can convert the AFS2 file formatted audio files into WAV (not sure how to re-encode).
I converted the bgm.awb (~487MB) file to wav (~137MB huh??? Less tracks maybe is the reason?) using the tool, and sure enough, I can play it in VLC and the first song is the song you hear when you get to the main screen when you start the game. Best of all, I don't think this was one of the directories were created, upon unpacking, when I started fiddling with the game files. Which means modifying the music should be a bit straight forward! :)

https://www.balkanpesbox.com/forum/topic/4072-eternity-audio-tool/

and consider that's if you modify the size of a file in a cpk you need to patch the cpk_list.cfg.bin (otherwhise the file won't load)
DarkCraft Feb 28, 2024 @ 2:36pm 
oh and for the lua code : https://github.com/HansWessels/unluac
(function like funcluacommand is natif function (so compiled function))
0x57A1CFA117 Feb 28, 2024 @ 3:40pm 
Originally posted by Cheaty:
https://www.balkanpesbox.com/forum/topic/4072-eternity-audio-tool/

and consider that's if you modify the size of a file in a cpk you need to patch the cpk_list.cfg.bin (otherwhise the file won't load)

Well I suppose so yeah, I never said that what I presented was meant as a step-by-step tutorial for doing the modifications. It was more of a "here are my findings, learn from them what you will and go forth from there to learn more and maybe package a tool up in a nice neat package."


Originally posted by Cheaty:
oh and for the lua code : https://github.com/HansWessels/unluac
(function like funcluacommand is natif function (so compiled function))

What was wrong with the link to unluac I posted? It is shown as being last updated 8 years ago, the repo you posted says that one was 9 years ago and references it being a fork. In fact, the repo I posted, checking it just now, it has an update of Dec. 25th last year. In fact, going into the unstable directory, it's had updates throughout the years, I guess they just never moved it out of the Unstable directory.

I may be mis-interpreting the reasoning for the last bit but my comment about the obfuscation wasn't about the function name, it was about the argument being passed to the function
DarkCraft Feb 29, 2024 @ 2:33am 
Originally posted by 0x57A1CFA117:
Originally posted by Cheaty:
https://www.balkanpesbox.com/forum/topic/4072-eternity-audio-tool/

and consider that's if you modify the size of a file in a cpk you need to patch the cpk_list.cfg.bin (otherwhise the file won't load)

Well I suppose so yeah, I never said that what I presented was meant as a step-by-step tutorial for doing the modifications. It was more of a "here are my findings, learn from them what you will and go forth from there to learn more and maybe package a tool up in a nice neat package."


Originally posted by Cheaty:
oh and for the lua code : https://github.com/HansWessels/unluac
(function like funcluacommand is natif function (so compiled function))

What was wrong with the link to unluac I posted? It is shown as being last updated 8 years ago, the repo you posted says that one was 9 years ago and references it being a fork. In fact, the repo I posted, checking it just now, it has an update of Dec. 25th last year. In fact, going into the unstable directory, it's had updates throughout the years, I guess they just never moved it out of the Unstable directory.

I may be mis-interpreting the reasoning for the last bit but my comment about the obfuscation wasn't about the function name, it was about the argument being passed to the function

ah sorry i didn't see that you have already posted an unluac link (but i already have a tool to patch cpk_list to edit cpk) (I have already modified ykw4 script that's also use script.cpk lua code (it's also a game by level5))
Last edited by DarkCraft; Feb 29, 2024 @ 2:34am
< >
Showing 1-9 of 9 comments
Per page: 1530 50