Fastfiles module

This commit is contained in:
Joelrau 2021-01-03 06:56:18 +02:00
parent 6bfb1731df
commit b75a77b351
4 changed files with 174 additions and 3 deletions

View File

@ -0,0 +1,75 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "command.hpp"
#include "game_console.hpp"
#include <utils/hook.hpp>
#include <utils/memory.hpp>
namespace fastfiles
{
namespace
{
utils::hook::detour db_try_load_x_file_internal_hook;
void db_try_load_x_file_internal(const char* zoneName, const int flags)
{
game_console::print(game_console::con_type_info, "Loading fastfile %s\n", zoneName);
return db_try_load_x_file_internal_hook.invoke<void>(zoneName, flags);
}
void reallocate_asset_pool(const game::XAssetType type, const unsigned int new_size)
{
const size_t element_size = game::DB_GetXAssetTypeSize(type);
auto* new_pool = utils::memory::get_allocator()->allocate(new_size * element_size);
std::memmove(new_pool, game::DB_XAssetPool[type], game::g_poolSize[type] * element_size);
game::DB_XAssetPool[type] = new_pool;
game::g_poolSize[type] = new_size;
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
db_try_load_x_file_internal_hook.create(
SELECT_VALUE(0x1401816F0, 0x1402741C0), &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;
}
const char* name = params.get(1);
game::DB_LoadXAssets(&name, 1u, game::DBSyncMode::DB_LOAD_SYNC);
});
command::add("materiallist", [](const command::params& params)
{
game::DB_EnumXAssets_FastFile(game::ASSET_TYPE_MATERIAL, [](const game::XAssetHeader header, void*)
{
if(header.material && header.material->name)
{
printf("%s\n", header.material->name);
}
}, 0, false);
});
if (!game::environment::is_sp())
{
reallocate_asset_pool(game::ASSET_TYPE_WEAPON, 320);
}
}
};
}
REGISTER_COMPONENT(fastfiles::component)

View File

@ -20,7 +20,7 @@ namespace redirect
auto* arguments = const_cast<char*>(utils::string::va("%s%s%s", self.get_path().data(),
(singleplayer ? " -singleplayer" : " -multiplayer"),
(mode.empty() ? "" : (" +"s + mode).data())));
(mode.empty() ? "" : (" +"s + mode).data())));
CreateProcessA(self.get_path().data(), arguments, nullptr, nullptr, false, NULL, nullptr, nullptr,
&startup_info, &process_info);

View File

@ -699,9 +699,87 @@ namespace game
dvar_limits domain;
};
struct Material
enum DBSyncMode
{
const char* name;
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,
};
enum XAssetType
{
ASSET_TYPE_PHYSPRESET = 0x0,
ASSET_TYPE_PHYSCOLLMAP = 0x1,
ASSET_TYPE_PHYSWATERPRESET = 0x2,
ASSET_TYPE_PHYSWORLDMAP = 0x3,
ASSET_TYPE_PHYSCONSTRAINT = 0x4,
ASSET_TYPE_XANIMPARTS = 0x5,
ASSET_TYPE_XMODELSURFS = 0x6,
ASSET_TYPE_XMODEL = 0x7,
ASSET_TYPE_MATERIAL = 0x8,
ASSET_TYPE_COMPUTESHADER = 0x9,
ASSET_TYPE_VERTEXSHADER = 0xA,
ASSET_TYPE_HULLSHADER = 0xB,
ASSET_TYPE_DOMAINSHADER = 0xC,
ASSET_TYPE_PIXELSHADER = 0xD,
ASSET_TYPE_VERTEXDECL = 0xE,
ASSET_TYPE_TECHNIQUE_SET = 0xF,
ASSET_TYPE_IMAGE = 0x10,
ASSET_TYPE_SOUND = 0x11,
ASSET_TYPE_SOUND_CURVE = 0x12,
ASSET_TYPE_LPF_CURVE = 0x13,
ASSET_TYPE_REVERB_CURVE = 0x14,
ASSET_TYPE_SOUND_CONTEXT = 0x15,
ASSET_TYPE_LOADED_SOUND = 0x16,
ASSET_TYPE_CLIPMAP = 0x17,
ASSET_TYPE_COMWORLD = 0x18,
ASSET_TYPE_GLASSWORLD = 0x19,
ASSET_TYPE_PATHDATA = 0x1A,
ASSET_TYPE_VEHICLE_TRACK = 0x1B,
ASSET_TYPE_MAP_ENTS = 0x1C,
ASSET_TYPE_FXWORLD = 0x1D,
ASSET_TYPE_GFXWORLD = 0x1E,
ASSET_TYPE_LIGHT_DEF = 0x1F,
ASSET_TYPE_UI_MAP = 0x20,
ASSET_TYPE_FONT = 0x21,
ASSET_TYPE_MENULIST = 0x22,
ASSET_TYPE_MENU = 0x23,
ASSET_TYPE_ANIMCLASS = 0x24,
ASSET_TYPE_LOCALIZE_ENTRY = 0x25,
ASSET_TYPE_ATTACHMENT = 0x26,
ASSET_TYPE_WEAPON = 0x27,
ASSET_TYPE_SNDDRIVER_GLOBALS = 0x28,
ASSET_TYPE_FX = 0x29,
ASSET_TYPE_IMPACT_FX = 0x2A,
ASSET_TYPE_SURFACE_FX = 0x2B,
ASSET_TYPE_AITYPE = 0x2C,
ASSET_TYPE_MPTYPE = 0x2D,
ASSET_TYPE_CHARACTER = 0x2E,
ASSET_TYPE_XMODELALIAS = 0x2F,
ASSET_TYPE_RAWFILE = 0x30,
ASSET_TYPE_SCRIPTFILE = 0x31,
ASSET_TYPE_STRINGTABLE = 0x32,
ASSET_TYPE_LEADERBOARD = 0x33,
ASSET_TYPE_STRUCTURED_DATA_DEF = 0x34,
ASSET_TYPE_TRACER = 0x35,
ASSET_TYPE_VEHICLE = 0x36,
ASSET_TYPE_ADDON_MAP_ENTS = 0x37,
ASSET_TYPE_NET_CONST_STRINGS = 0x38,
ASSET_TYPE_REVERB_PRESET = 0x39,
ASSET_TYPE_LUA_FILE = 0x3A,
ASSET_TYPE_SCRIPTABLE = 0x3B,
ASSET_TYPE_EQUIPMENT_SND_TABLE = 0x3C,
ASSET_TYPE_VECTORFIELD = 0x3D,
ASSET_TYPE_DOPPLER_PRESET = 0x3E,
ASSET_TYPE_PARTICLE_SIM_ANIMATION = 0x3F,
ASSET_TYPE_LASER = 0x40,
ASSET_TYPE_SKELETON_SCRIPT = 0x41,
ASSET_TYPE_CLUT = 0x42,
ASSET_TYPE_WATER_DEFAULT = 0x43,
ASSET_TYPE_COUNT = 0x44,
};
struct Glyph
@ -733,6 +811,11 @@ namespace game
GFX_DRAW_SCENE_STANDARD = 0x0,
};
struct Material
{
const char* name;
};
enum MaterialTechniqueType
{
TECHNIQUE_UNLIT = 8,
@ -748,6 +831,12 @@ namespace game
int forceTechType;
};
union XAssetHeader
{
void* data;
Material* material;
};
struct client_t
{

View File

@ -25,6 +25,10 @@ namespace game
WEAK symbol<void(int localClientNum, const char* message)> CG_GameMessage{ 0x1401A3050, 0x1400EE500 };
WEAK symbol<void(XAssetType type, void(__cdecl* func)(XAssetHeader, void*), void* inData, bool includeOverride)> DB_EnumXAssets_FastFile{ 0x14017D7C0, 0x14026EC10 };
WEAK symbol<int(XAssetType type)> DB_GetXAssetTypeSize{ 0x140151C20, 0x140240DF0 };
WEAK symbol<void(const char** zoneNames, unsigned int zoneCount, DBSyncMode syncMode)> DB_LoadXAssets{ 0x1402F8B50, 0x140270F30 };
WEAK symbol<dvar_t* (const char* name)> Dvar_FindVar{ 0x140370860, 0x1404BF8B0 };
WEAK symbol<void(char* buffer, int index)> Dvar_GetCombinedString{ 0x1402FB590, 0x1403D3290 };
WEAK symbol<void(const char* dvar, const char* buffer)> Dvar_SetCommand{ 0x1403730D0, 0x1404C2520 };
@ -92,6 +96,9 @@ namespace game
WEAK symbol<int> svs_numclients{ 0, 0x1496C4B0C };
WEAK symbol<client_t> svs_clients{ 0, 0x1496C4B10 };
WEAK symbol<void*> DB_XAssetPool{ 0x140804690, 0x1409B40D0 };
WEAK symbol<int> g_poolSize{ 0x140804140, 0x1409B4B90 };
WEAK symbol<GfxDrawMethod_s> gfxDrawMethod{ 0x14CDFAFE8, 0x14D80FD98 };
namespace mp