update fastfile load code
This commit is contained in:
parent
3ffcd854db
commit
f45b25dde2
@ -112,24 +112,14 @@ namespace fastfiles
|
|||||||
namespace zone_loading
|
namespace zone_loading
|
||||||
{
|
{
|
||||||
utils::hook::detour db_is_patch_hook;
|
utils::hook::detour db_is_patch_hook;
|
||||||
utils::hook::detour db_read_stream_file_hook;
|
|
||||||
utils::hook::detour db_auth_load_inflate_hook;
|
|
||||||
utils::hook::detour db_auth_load_inflate_init_hook;
|
|
||||||
utils::hook::detour db_auth_load_inflate_end_hook;
|
|
||||||
utils::hook::detour db_patch_mem_fix_stream_alignment_hook;
|
|
||||||
|
|
||||||
game::db_z_stream_s db_zlib_stream;
|
|
||||||
char db_zlib_memory[0x20000];
|
|
||||||
|
|
||||||
bool is_reading_stream_file;
|
|
||||||
|
|
||||||
bool check_missing_content_func(const char* zone_name)
|
bool check_missing_content_func(const char* zone_name)
|
||||||
{
|
{
|
||||||
const char* lang_code = game::SEH_GetCurrentLanguageCode();
|
const char* lang_code = game::SEH_GetCurrentLanguageCode();
|
||||||
char buffer[0x100]{ 0 };
|
char buffer[0x100]{ 0 };
|
||||||
sprintf_s(buffer, "%s_", lang_code);
|
const auto len = sprintf_s(buffer, "%s_", lang_code);
|
||||||
|
|
||||||
if (!strncmp(zone_name, buffer, strlen(buffer)))
|
if (!strncmp(zone_name, buffer, len))
|
||||||
{
|
{
|
||||||
printf("Tried to load missing language zone: %s\n", zone_name);
|
printf("Tried to load missing language zone: %s\n", zone_name);
|
||||||
return true;
|
return true;
|
||||||
@ -168,93 +158,6 @@ namespace fastfiles
|
|||||||
a.and_(edi, r12d);
|
a.and_(edi, r12d);
|
||||||
a.jmp(0x3BAC06_b);
|
a.jmp(0x3BAC06_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void db_read_stream_file_stub(int a1, int a2)
|
|
||||||
{
|
|
||||||
if (!game::Sys_IsDatabaseThread()) // sanity check
|
|
||||||
{
|
|
||||||
__debugbreak();
|
|
||||||
}
|
|
||||||
|
|
||||||
is_reading_stream_file = true;
|
|
||||||
db_read_stream_file_hook.invoke<void>(a1, a2);
|
|
||||||
is_reading_stream_file = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T1, class T2>
|
|
||||||
void stream_copy(T1 dest, T2 src)
|
|
||||||
{
|
|
||||||
dest->next_in = static_cast<decltype(dest->next_in)>(src->next_in);
|
|
||||||
dest->avail_in = static_cast<decltype(dest->avail_in)>(src->avail_in);
|
|
||||||
dest->total_in = static_cast<decltype(dest->total_in)>(src->total_in);
|
|
||||||
dest->next_out = static_cast<decltype(dest->next_out)>(src->next_out);
|
|
||||||
dest->avail_out = static_cast<decltype(dest->avail_out)>(src->avail_out);
|
|
||||||
dest->total_out = static_cast<decltype(dest->total_out)>(src->total_out);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_custom_zone_read;
|
|
||||||
|
|
||||||
__int64 db_auth_load_inflate_stub(game::DB_ReadStream* stream)
|
|
||||||
{
|
|
||||||
if (!is_custom_zone_read) return db_auth_load_inflate_hook.invoke<__int64>(stream);
|
|
||||||
|
|
||||||
__int64 result{};
|
|
||||||
|
|
||||||
stream_copy(&db_zlib_stream, stream);
|
|
||||||
if (db_zlib_stream.avail_in)
|
|
||||||
{
|
|
||||||
result = game::db_inflate(&db_zlib_stream, Z_SYNC_FLUSH);
|
|
||||||
if (result == 1 && !db_zlib_stream.avail_out) result = 0;
|
|
||||||
}
|
|
||||||
stream_copy(stream, &db_zlib_stream);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void db_auth_load_inflate_init_stub(game::DB_ReadStream* stream, int isSecure, const char* filename)
|
|
||||||
{
|
|
||||||
is_custom_zone_read = false;
|
|
||||||
|
|
||||||
db_auth_load_inflate_init_hook.invoke<void>(stream, isSecure, filename);
|
|
||||||
|
|
||||||
if (stream->avail_in >= 4 &&
|
|
||||||
(stream->next_in[1] == 'I' && stream->next_in[2] == 'W' && stream->next_in[3] == 'C'))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_reading_stream_file || game::g_load->file->isSecure) return;
|
|
||||||
|
|
||||||
is_custom_zone_read = true;
|
|
||||||
|
|
||||||
memset(&db_zlib_stream, 0, sizeof(game::db_z_stream_s));
|
|
||||||
stream_copy(&db_zlib_stream, stream);
|
|
||||||
|
|
||||||
game::DB_Zip_InitThreadMemory(&db_zlib_stream, &db_zlib_memory, 0x20000);
|
|
||||||
game::db_inflateInit_(&db_zlib_stream, "1.1.4", 88);
|
|
||||||
|
|
||||||
stream_copy(stream, &db_zlib_stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
void db_auth_load_inflate_end_stub()
|
|
||||||
{
|
|
||||||
db_auth_load_inflate_end_hook.invoke<void>();
|
|
||||||
|
|
||||||
if (!is_custom_zone_read) return;
|
|
||||||
|
|
||||||
game::db_inflateEnd(&db_zlib_stream);
|
|
||||||
game::DB_Zip_ShutdownThreadMemory(&db_zlib_stream);
|
|
||||||
|
|
||||||
is_custom_zone_read = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned __int64 db_patch_mem_fix_stream_alignment_stub(int alignment) // probably unneeded
|
|
||||||
{
|
|
||||||
if (!is_custom_zone_read) return db_patch_mem_fix_stream_alignment_hook.invoke<unsigned __int64>(alignment);
|
|
||||||
|
|
||||||
*game::g_streamPos = (~alignment & (alignment + *game::g_streamPos));
|
|
||||||
return *game::g_streamPos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
using namespace zone_loading;
|
using namespace zone_loading;
|
||||||
|
|
||||||
@ -298,11 +201,9 @@ namespace fastfiles
|
|||||||
|
|
||||||
// Allow loading of unsigned fastfiles
|
// Allow loading of unsigned fastfiles
|
||||||
utils::hook::set<uint8_t>(0x9E8CAE_b, 0xEB); // DB_InflateInit
|
utils::hook::set<uint8_t>(0x9E8CAE_b, 0xEB); // DB_InflateInit
|
||||||
db_read_stream_file_hook.create(0x0A7F370_b, db_read_stream_file_stub);
|
|
||||||
db_auth_load_inflate_hook.create(0x9E6AE0_b, db_auth_load_inflate_stub);
|
// Skip signature validation
|
||||||
db_auth_load_inflate_init_hook.create(0x9E6970_b, db_auth_load_inflate_init_stub);
|
utils::hook::set(0x1409E6390, 0xC301B0); // signature
|
||||||
db_auth_load_inflate_end_hook.create(0x9E8CF0_b, db_auth_load_inflate_end_stub);
|
|
||||||
db_patch_mem_fix_stream_alignment_hook.create(0x0A0A80_b, db_patch_mem_fix_stream_alignment_stub);
|
|
||||||
|
|
||||||
command::add("loadzone", [](const command::params& params)
|
command::add("loadzone", [](const command::params& params)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user