Fastfiles + lui components

This commit is contained in:
Federico Cecchetto 2021-04-29 23:47:05 +02:00
parent 73e5e4b635
commit d48cadac89
5 changed files with 146 additions and 1 deletions

View File

@ -0,0 +1,73 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "fastfiles.hpp"
#include "command.hpp"
#include "game_console.hpp"
#include <utils/hook.hpp>
#include <utils/concurrency.hpp>
namespace fastfiles
{
static utils::concurrency::container<std::string> current_fastfile;
namespace
{
utils::hook::detour db_try_load_x_file_internal_hook;
void db_try_load_x_file_internal(const char* zone_name, const int flags)
{
game_console::print(game_console::con_type_info, "Loading fastfile %s\n", zone_name);
current_fastfile.access([&](std::string& fastfile)
{
fastfile = zone_name;
});
return db_try_load_x_file_internal_hook.invoke<void>(zone_name, flags);
}
}
std::string get_current_fastfile()
{
std::string fastfile_copy;
current_fastfile.access([&](std::string& fastfile)
{
fastfile_copy = fastfile;
});
return fastfile_copy;
}
class component final : public component_interface
{
public:
void post_unpack() override
{
db_try_load_x_file_internal_hook.create(game::base_address + 0x4173B0, &db_try_load_x_file_internal);
command::add("loadzone", [](const command::params& params)
{
if (params.size() < 2)
{
game_console::print(game_console::con_type_info, "usage: loadzone <zone>\n");
return;
}
game::XZoneInfo info{};
info.name = params.get(1);
info.allocFlags = 1;
info.freeFlags = 0;
game::DB_LoadXAssets(&info, 1u, game::DBSyncMode::DB_LOAD_SYNC);
});
command::add("g_poolSizes", []()
{
for (auto i = 0; i < game::ASSET_TYPE_COUNT; i++)
{
game_console::print(game_console::con_type_info, "g_poolSize[%i]: %i // %s\n", i, game::g_poolSize[i], game::g_assetNames[i]);
}
});
}
};
}
REGISTER_COMPONENT(fastfiles::component)

View File

@ -0,0 +1,8 @@
#pragma once
#include "game/game.hpp"
namespace fastfiles
{
std::string get_current_fastfile();
}

43
src/component/lui.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "command.hpp"
#include "game_console.hpp"
#include <utils/hook.hpp>
namespace lui
{
class component final : public component_interface
{
public:
void post_unpack() override
{
command::add("lui_open", [](const command::params& params)
{
if (params.size() <= 1)
{
game_console::print(game_console::con_type_info, "usage: lui_open <name>\n");
return;
}
game::LUI_OpenMenu(0, params[1], 0, 0, 0);
});
command::add("lui_open_popup", [](const command::params& params)
{
if (params.size() <= 1)
{
game_console::print(game_console::con_type_info, "usage: lui_open_popup <name>\n");
return;
}
game::LUI_OpenMenu(0, params[1], 1, 0, 0);
});
}
};
}
REGISTER_COMPONENT(lui::component)

View File

@ -538,6 +538,23 @@ namespace game
unsigned int nextPoolEntry;
};
enum DBSyncMode
{
DB_LOAD_ASYNC = 0x0,
DB_LOAD_SYNC = 0x1,
DB_LOAD_ASYNC_WAIT_ALLOC = 0x2,
DB_LOAD_ASYNC_FORCE_FREE = 0x3,
DB_LOAD_ASYNC_NO_SYNC_THREADS = 0x4,
DB_LOAD_SYNC_SKIP_ALWAYS_LOADED = 0x5,
};
struct XZoneInfo
{
const char* name;
int allocFlags;
int freeFlags;
};
enum scr_string_t
{
scr_string_t_dummy = 0x0,

View File

@ -17,6 +17,7 @@ namespace game
WEAK symbol<void(XAssetType type, void(__cdecl* func)(game::XAssetHeader, void*), const void* inData, bool includeOverride)>
DB_EnumXAssets_Internal{0x4129F0};
WEAK symbol<const char*(const XAsset* asset)> DB_GetXAssetName{0x3E4090};
WEAK symbol<void(XZoneInfo* zoneInfo, unsigned int zoneCount, DBSyncMode syncMode)> DB_LoadXAssets{0x414FF0};
WEAK symbol<dvar_t*(const char* name)> Dvar_FindVar{0x618F90};
WEAK symbol<void(char* buffer, int index)> Dvar_GetCombinedString{0x5A75D0};
@ -40,6 +41,8 @@ namespace game
WEAK symbol<char*(char* string)> I_CleanStr{0x620660};
WEAK symbol<void(int clientNum, const char* menu, int a3, int a4, unsigned int a5)> LUI_OpenMenu{0x5F0EE0};
WEAK symbol<Material*(const char* material)> Material_RegisterHandle{0x759BA0};
WEAK symbol<const float* (const float* v)> Scr_AllocVector{0x5C3220};
@ -75,6 +78,7 @@ namespace game
WEAK symbol<CmdArgs> cmd_args{0xAD17A60};
WEAK symbol<const char*> g_assetNames{0xBEF280};
WEAK symbol<int> g_poolSize{0xBF2E40};
WEAK symbol<gentity_s> g_entities{0x52DDDA0};