Add dumpSoundAlias command

This commit is contained in:
Federico Cecchetto 2022-08-02 00:59:16 +02:00
parent 33088d070b
commit d320db4ecd
2 changed files with 34 additions and 6 deletions

View File

@ -8,6 +8,7 @@
#include "filesystem.hpp" #include "filesystem.hpp"
#include "console.hpp" #include "console.hpp"
#include "scheduler.hpp" #include "scheduler.hpp"
#include "command.hpp"
#include <utils/io.hpp> #include <utils/io.hpp>
#include <utils/memory.hpp> #include <utils/memory.hpp>
@ -649,11 +650,11 @@ namespace sound
} }
} }
void dump_sound(game::snd_alias_list_t* asset) bool dump_sound(game::snd_alias_list_t* asset)
{ {
if (asset == nullptr) if (asset == nullptr)
{ {
return; return false;
} }
rapidjson::Document j; rapidjson::Document j;
@ -908,6 +909,7 @@ namespace sound
j.Accept(writer); j.Accept(writer);
utils::io::write_file(path, std::string{buffer.GetString(), buffer.GetLength()}, false); utils::io::write_file(path, std::string{buffer.GetString(), buffer.GetLength()}, false);
return true;
} }
game::XAssetHeader find_sound(const char* name) game::XAssetHeader find_sound(const char* name)
@ -953,6 +955,32 @@ namespace sound
snd_is_music_playing_hook.create(0x1407C58A0, snd_is_music_playing_stub); snd_is_music_playing_hook.create(0x1407C58A0, snd_is_music_playing_stub);
scheduler::once(clear, scheduler::pipeline::main); scheduler::once(clear, scheduler::pipeline::main);
command::add("dumpSoundAlias", [](const command::params& params)
{
if (params.size() < 2)
{
console::info("Usage: dumpSoundAlias <name>\n");
return;
}
const auto name = params.get(1);
const auto sound = game::DB_FindXAssetHeader(game::ASSET_TYPE_SOUND, name, false).sound;
if (sound == nullptr)
{
console::error("Sound %s does not exist\n", name);
return;
}
if (dump_sound(sound))
{
console::info("Sound dumped to dumps/sound/%s\n", name);
}
else
{
console::error("Failed to dump sound %s\n", name);
}
});
} }
}; };
} }

View File

@ -2,7 +2,7 @@
namespace sound namespace sound
{ {
void dump_sound(game::snd_alias_list_t* asset); bool dump_sound(game::snd_alias_list_t* asset);
game::XAssetHeader find_sound(const char* name); game::XAssetHeader find_sound(const char* name);
void clear(); void clear();