Debug missing assets

This commit is contained in:
Federico Cecchetto 2022-05-05 00:48:19 +02:00
parent eff45cecc3
commit 99360ac4d5
4 changed files with 55 additions and 31 deletions

View File

@ -1,27 +0,0 @@
local maps = {
"af_caves",
"af_chase",
"airport",
"arcadia",
"boneyard",
"cliffhanger",
"contingency",
"dc_whitehouse",
"dcburning",
"dcemp",
"ending",
"estate",
"favela",
"favela_escape",
"gulag",
"invasion",
"oilrig",
"roadkill",
"trainer",
"museum",
}
for i = 1, #maps do
local string = "LUA_MENU_SP_LOCATION_" .. maps[i]:upper()
game:addlocalizedstring(string, string)
end

View File

@ -4,9 +4,11 @@
#include "command.hpp" #include "command.hpp"
#include "game_console.hpp" #include "game_console.hpp"
#include "localized_strings.hpp"
#include <utils/hook.hpp> #include <utils/hook.hpp>
#include <utils/concurrency.hpp> #include <utils/concurrency.hpp>
#include <utils/string.hpp>
namespace fastfiles namespace fastfiles
{ {
@ -15,6 +17,7 @@ namespace fastfiles
namespace namespace
{ {
utils::hook::detour db_try_load_x_file_internal_hook; utils::hook::detour db_try_load_x_file_internal_hook;
utils::hook::detour db_find_xasset_header;
void db_try_load_x_file_internal(const char* zone_name, const int flags) void db_try_load_x_file_internal(const char* zone_name, const int flags)
{ {
@ -25,6 +28,41 @@ namespace fastfiles
}); });
return db_try_load_x_file_internal_hook.invoke<void>(zone_name, flags); return db_try_load_x_file_internal_hook.invoke<void>(zone_name, flags);
} }
game::XAssetHeader db_find_xasset_header_stub(game::XAssetType type, const char* name, int allow_create_default)
{
const auto start = game::Sys_Milliseconds();
const auto result = db_find_xasset_header.invoke<game::XAssetHeader>(type, name, allow_create_default);
const auto diff = game::Sys_Milliseconds() - start;
if (diff > 100)
{
game_console::print(
result.data == nullptr
? game_console::con_type_error
: game_console::con_type_warning,
"Waited %i msec for %sasset \"%s\", of type \"%s\"\n",
diff,
result.data == nullptr
? "missing "
: "",
name,
game::g_assetNames[type]
);
}
return result;
}
void add_missing_localized_strings()
{
for (auto map = &game::maps[0]; map->unk; ++map)
{
const auto str = utils::string::va("LUA_MENU_SP_LOCATION_%s",
utils::string::to_upper(map->name).data());
localized_strings::override(str, str);
}
}
} }
void enum_assets(const game::XAssetType type, const std::function<void(game::XAssetHeader)>& callback, const bool includeOverride) void enum_assets(const game::XAssetType type, const std::function<void(game::XAssetHeader)>& callback, const bool includeOverride)
@ -39,11 +77,10 @@ namespace fastfiles
std::string get_current_fastfile() std::string get_current_fastfile()
{ {
std::string fastfile_copy; std::string fastfile_copy;
current_fastfile.access([&](std::string& fastfile) return current_fastfile.access<std::string>([&](std::string& fastfile)
{ {
fastfile_copy = fastfile; return fastfile;
}); });
return fastfile_copy;
} }
class component final : public component_interface class component final : public component_interface
@ -51,7 +88,10 @@ namespace fastfiles
public: public:
void post_unpack() override void post_unpack() override
{ {
db_try_load_x_file_internal_hook.create(0x1404173B0, &db_try_load_x_file_internal); db_try_load_x_file_internal_hook.create(0x1404173B0, db_try_load_x_file_internal);
db_find_xasset_header.create(game::DB_FindXAssetHeader, db_find_xasset_header_stub);
add_missing_localized_strings();
command::add("loadzone", [](const command::params& params) command::add("loadzone", [](const command::params& params)
{ {

View File

@ -1118,6 +1118,15 @@ namespace game
DB_FileSysInterface_vtbl* vftbl; DB_FileSysInterface_vtbl* vftbl;
}; };
struct map_t
{
const char* name;
int id;
int unk;
};
static_assert(sizeof(map_t) == 0x10);
__declspec(align(8)) struct DiskFile __declspec(align(8)) struct DiskFile
{ {
DWORD status; DWORD status;

View File

@ -196,6 +196,8 @@ namespace game
WEAK symbol<DB_FileSysInterface*> g_fileSystem{0x1420B27E8}; WEAK symbol<DB_FileSysInterface*> g_fileSystem{0x1420B27E8};
WEAK symbol<map_t> maps{0x14097EE90};
namespace hks namespace hks
{ {
WEAK symbol<lua_State*> lua_state{0x1419D83E8}; WEAK symbol<lua_State*> lua_state{0x1419D83E8};