singleplayer mod stuff

This commit is contained in:
quaK 2022-08-20 16:27:41 +03:00
parent 9ef9f7e161
commit 21263f7826
4 changed files with 80 additions and 45 deletions

View File

@ -91,28 +91,56 @@ namespace fastfiles
return db_read_stream_file_hook.invoke<void>(a1, a2); return db_read_stream_file_hook.invoke<void>(a1, a2);
} }
void skip_extra_zones_stub(utils::hook::assembler& a) namespace mp
{ {
const auto skip = a.newLabel(); void skip_extra_zones_stub(utils::hook::assembler& a)
const auto original = a.newLabel(); {
const auto skip = a.newLabel();
const auto original = a.newLabel();
a.pushad64(); a.pushad64();
a.test(esi, game::DB_ZONE_CUSTOM); // allocFlags a.test(esi, game::DB_ZONE_CUSTOM); // allocFlags
a.jnz(skip); a.jnz(skip);
a.bind(original); a.bind(original);
a.popad64(); a.popad64();
a.mov(rdx, 0x8E2F80_b); a.mov(rdx, 0x8E2F80_b);
a.mov(rcx, rbp); a.mov(rcx, rbp);
a.call(0x840A20_b); a.call(0x840A20_b);
a.jmp(0x398070_b); a.jmp(0x398070_b);
a.bind(skip); a.bind(skip);
a.popad64(); a.popad64();
a.mov(r14d, game::DB_ZONE_CUSTOM); a.mov(r14d, game::DB_ZONE_CUSTOM);
a.not_(r14d); a.not_(r14d);
a.and_(esi, r14d); a.and_(esi, r14d);
a.jmp(0x39814F_b); a.jmp(0x39814F_b);
}
}
namespace sp
{
void skip_extra_zones_stub(utils::hook::assembler& a)
{
const auto skip = a.newLabel();
const auto original = a.newLabel();
a.pushad64();
a.test(ebp, game::DB_ZONE_CUSTOM); // allocFlags
a.jnz(skip);
a.bind(original);
a.popad64();
a.mov(r8d, 9);
a.mov(rdx, 0x782210_b);
a.jmp(0x1F4006_b);
a.bind(skip);
a.popad64();
a.mov(r15d, game::DB_ZONE_CUSTOM);
a.not_(r15d);
a.and_(ebp, r15d);
a.jmp(0x1F4023_b);
}
} }
utils::hook::detour sys_createfile_hook; utils::hook::detour sys_createfile_hook;
@ -164,7 +192,7 @@ namespace fastfiles
std::vector<game::XZoneInfo> data; std::vector<game::XZoneInfo> data;
merge(&data, zoneInfo, zoneCount); merge(&data, zoneInfo, zoneCount);
// code_pre_gfx_mp // code_pre_gfx
game::DB_LoadXAssets(data.data(), static_cast<std::uint32_t>(data.size()), syncMode); game::DB_LoadXAssets(data.data(), static_cast<std::uint32_t>(data.size()), syncMode);
} }
@ -174,9 +202,9 @@ namespace fastfiles
std::vector<game::XZoneInfo> data; std::vector<game::XZoneInfo> data;
merge(&data, zoneInfo, zoneCount); merge(&data, zoneInfo, zoneCount);
// code_post_gfx_mp // code_post_gfx
// ui_mp // ui
// common_mp // common
if (fastfiles::exists("mod")) if (fastfiles::exists("mod"))
{ {
@ -191,7 +219,7 @@ namespace fastfiles
std::vector<game::XZoneInfo> data; std::vector<game::XZoneInfo> data;
merge(&data, zoneInfo, zoneCount); merge(&data, zoneInfo, zoneCount);
// ui_mp // ui
game::DB_LoadXAssets(data.data(), static_cast<std::uint32_t>(data.size()), syncMode); game::DB_LoadXAssets(data.data(), static_cast<std::uint32_t>(data.size()), syncMode);
} }
@ -251,28 +279,29 @@ namespace fastfiles
// Fix compressor type on streamed file load // Fix compressor type on streamed file load
db_read_stream_file_hook.create(SELECT_VALUE(0x1FB9D0_b, 0x3A1BF0_b), db_read_stream_file_stub); db_read_stream_file_hook.create(SELECT_VALUE(0x1FB9D0_b, 0x3A1BF0_b), db_read_stream_file_stub);
// Add custom zone paths
sys_createfile_hook.create(game::Sys_CreateFile, sys_create_file_stub);
// load our custom pre_gfx zones
utils::hook::call(SELECT_VALUE(0x3862ED_b, 0x15C3FD_b), load_pre_gfx_zones);
utils::hook::call(SELECT_VALUE(0x3865E7_b, 0x15C75D_b), load_pre_gfx_zones);
// load our custom ui and common zones
utils::hook::call(SELECT_VALUE(0x5634AA_b, 0x686421_b), load_post_gfx_and_ui_and_common_zones);
// load our custom ui zones
utils::hook::call(SELECT_VALUE(0x3A5676_b, 0x17C6D2_b), load_ui_zones);
// Don't load extra zones with loadzone // Don't load extra zones with loadzone
if (!game::environment::is_sp()) if (game::environment::is_sp())
{ {
// TODO: SP? utils::hook::nop(0x1F3FF9_b, 13);
utils::hook::nop(0x398061_b, 15); utils::hook::jump(0x1F3FF9_b, utils::hook::assemble(sp::skip_extra_zones_stub), true);
utils::hook::jump(0x398061_b, utils::hook::assemble(skip_extra_zones_stub), true);
} }
else
if (!game::environment::is_sp())
{ {
// Add custom zone paths utils::hook::nop(0x398061_b, 15);
sys_createfile_hook.create(game::Sys_CreateFile, sys_create_file_stub); utils::hook::jump(0x398061_b, utils::hook::assemble(mp::skip_extra_zones_stub), true);
// load our custom pre_gfx zones
utils::hook::call(0x15C3FD_b, load_pre_gfx_zones);
utils::hook::call(0x15C75D_b, load_pre_gfx_zones);
// load our custom ui and common zones
utils::hook::call(0x686421_b, load_post_gfx_and_ui_and_common_zones);
// load our custom ui zones
utils::hook::call(0x17C6D2_b, load_ui_zones);
} }
command::add("loadzone", [](const command::params& params) command::add("loadzone", [](const command::params& params)

View File

@ -85,7 +85,7 @@ namespace filesystem
get_search_paths().insert("data"); get_search_paths().insert("data");
// fs_game flags // fs_game flags
utils::hook::set<uint32_t>(0x189275_b, 0); utils::hook::set<uint32_t>(SELECT_VALUE(0x40D2A5_b, 0x189275_b), 0);
} }
}; };
} }

View File

@ -84,7 +84,13 @@ namespace weapon
public: public:
void post_unpack() override void post_unpack() override
{ {
g_setup_level_weapon_def_hook.create(0x462630_b, g_setup_level_weapon_def_stub); if (!game::environment::is_sp())
{
g_setup_level_weapon_def_hook.create(0x462630_b, g_setup_level_weapon_def_stub);
// disable custom weapon index mismatch (fix for custom attachments) (NEEDS TESTING)
//utils::hook::set<uint8_t>(0x11B910_b, 0xC3); // CG_SetupCustomWeapon
}
#ifdef DEBUG #ifdef DEBUG
command::add("setWeaponFieldFloat", [](const command::params& params) command::add("setWeaponFieldFloat", [](const command::params& params)

View File

@ -166,7 +166,7 @@ namespace game
int createDefault)> DB_FindXAssetHeader{0x1F1120, 0x3950C0}; int createDefault)> DB_FindXAssetHeader{0x1F1120, 0x3950C0};
WEAK symbol<bool(const char* zone, int source)> DB_FileExists{0x1F0D50, 0x394DC0}; WEAK symbol<bool(const char* zone, int source)> DB_FileExists{0x1F0D50, 0x394DC0};
WEAK symbol<void(XZoneInfo* zoneInfo, unsigned int zoneCount, DBSyncMode syncMode)> DB_LoadXAssets{0x1F31E0, 0x397500}; WEAK symbol<void(XZoneInfo* zoneInfo, unsigned int zoneCount, DBSyncMode syncMode)> DB_LoadXAssets{0x1F31E0, 0x397500};
WEAK symbol<bool(const char* zoneName)> DB_IsLocalized{0x0, 0x396790}; WEAK symbol<bool(const char* zoneName)> DB_IsLocalized{0x1F23C0, 0x396790};
WEAK symbol<void(int clientNum, const char* menu, WEAK symbol<void(int clientNum, const char* menu,
int a3, int a4, unsigned int a5)> LUI_OpenMenu{0x3F20A0, 0x1E1210}; int a3, int a4, unsigned int a5)> LUI_OpenMenu{0x3F20A0, 0x1E1210};
@ -210,7 +210,7 @@ namespace game
WEAK symbol<bool()> Sys_IsDatabaseReady2{0x3AB100, 0x4F79C0}; WEAK symbol<bool()> Sys_IsDatabaseReady2{0x3AB100, 0x4F79C0};
WEAK symbol<bool(int, void const*, const netadr_s*)> Sys_SendPacket{0x0, 0x5BDA90}; WEAK symbol<bool(int, void const*, const netadr_s*)> Sys_SendPacket{0x0, 0x5BDA90};
WEAK symbol<bool(const char* path)> Sys_FileExists{0x0, 0x0}; WEAK symbol<bool(const char* path)> Sys_FileExists{0x0, 0x0};
WEAK symbol<HANDLE(Sys_Folder, const char* baseFilename)> Sys_CreateFile{0x0, 0x5B2860}; WEAK symbol<HANDLE(Sys_Folder, const char* baseFilename)> Sys_CreateFile{0x42C430, 0x5B2860};
WEAK symbol<const char*(const char*)> UI_GetMapDisplayName{0x0, 0x4DDEE0}; WEAK symbol<const char*(const char*)> UI_GetMapDisplayName{0x0, 0x4DDEE0};
WEAK symbol<const char*(const char*)> UI_GetGameTypeDisplayName{0x0, 0x4DD8C0}; WEAK symbol<const char*(const char*)> UI_GetGameTypeDisplayName{0x0, 0x4DD8C0};