diff --git a/data/ui_scripts/patches/__init__.lua b/data/ui_scripts/patches/__init__.lua index 9002be83..e69de29b 100644 --- a/data/ui_scripts/patches/__init__.lua +++ b/data/ui_scripts/patches/__init__.lua @@ -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 diff --git a/src/client/component/fastfiles.cpp b/src/client/component/fastfiles.cpp index f0426f56..cdef6d79 100644 --- a/src/client/component/fastfiles.cpp +++ b/src/client/component/fastfiles.cpp @@ -4,9 +4,11 @@ #include "command.hpp" #include "game_console.hpp" +#include "localized_strings.hpp" #include #include +#include namespace fastfiles { @@ -15,6 +17,7 @@ namespace fastfiles namespace { 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) { @@ -25,6 +28,41 @@ namespace fastfiles }); return db_try_load_x_file_internal_hook.invoke(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(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& callback, const bool includeOverride) @@ -39,11 +77,10 @@ namespace fastfiles std::string get_current_fastfile() { std::string fastfile_copy; - current_fastfile.access([&](std::string& fastfile) + return current_fastfile.access([&](std::string& fastfile) { - fastfile_copy = fastfile; + return fastfile; }); - return fastfile_copy; } class component final : public component_interface @@ -51,7 +88,10 @@ namespace fastfiles public: 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) { diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index b05e5a50..83eeb55e 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -1118,6 +1118,15 @@ namespace game 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 { DWORD status; diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index 142d5c7b..9b0dbbf5 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -196,6 +196,8 @@ namespace game WEAK symbol g_fileSystem{0x1420B27E8}; + WEAK symbol maps{0x14097EE90}; + namespace hks { WEAK symbol lua_state{0x1419D83E8};