[ZoneBuilder] Disable experimental entrypoint until bugs are fixed

This commit is contained in:
momo5502 2017-05-27 15:38:12 +02:00
parent 84e2a2a7be
commit 908343a381
2 changed files with 37 additions and 29 deletions

View File

@ -7,6 +7,11 @@ namespace Components
std::string ZoneBuilder::TraceZone; std::string ZoneBuilder::TraceZone;
std::vector<std::pair<Game::XAssetType, std::string>> ZoneBuilder::TraceAssets; std::vector<std::pair<Game::XAssetType, std::string>> ZoneBuilder::TraceAssets;
bool ZoneBuilder::MainThreadInterrupted;
DWORD ZoneBuilder::InterruptingThreadId;
bool ZoneBuilder::Terminate;
std::thread ZoneBuilder::CommandThread;
ZoneBuilder::Zone::Zone(std::string name) : indexStart(0), externalSize(0), ZoneBuilder::Zone::Zone(std::string name) : indexStart(0), externalSize(0),
// Reserve 100MB by default. // Reserve 100MB by default.
@ -738,25 +743,22 @@ namespace Components
} }
} }
bool ZoneBuilder::mainThreadInterrupted;
DWORD ZoneBuilder::interruptingThreadId;
void ZoneBuilder::AssumeMainThreadRole() void ZoneBuilder::AssumeMainThreadRole()
{ {
ZoneBuilder::mainThreadInterrupted = true; ZoneBuilder::MainThreadInterrupted = true;
ZoneBuilder::interruptingThreadId = GetCurrentThreadId(); ZoneBuilder::InterruptingThreadId = GetCurrentThreadId();
} }
void ZoneBuilder::ResetThreadRole() void ZoneBuilder::ResetThreadRole()
{ {
ZoneBuilder::mainThreadInterrupted = false; ZoneBuilder::MainThreadInterrupted = false;
ZoneBuilder::interruptingThreadId = 0x0; ZoneBuilder::InterruptingThreadId = 0x0;
} }
bool ZoneBuilder::IsThreadMainThreadHook() bool ZoneBuilder::IsThreadMainThreadHook()
{ {
// this is the thread that is interrupting so let it act as the main thread // this is the thread that is interrupting so let it act as the main thread
if (ZoneBuilder::mainThreadInterrupted && GetCurrentThreadId() == ZoneBuilder::interruptingThreadId) if (ZoneBuilder::MainThreadInterrupted && GetCurrentThreadId() == ZoneBuilder::InterruptingThreadId)
{ {
return true; return true;
} }
@ -770,19 +772,6 @@ namespace Components
return GetCurrentThreadId() == Utils::Hook::Get<DWORD>(0x1CDE7FC); return GetCurrentThreadId() == Utils::Hook::Get<DWORD>(0x1CDE7FC);
} }
DWORD WINAPI ZoneBuilder::CommandsThread(LPVOID)
{
while (1)
{
// Cbuf_Execute doesn't work outside the main thread so hijack it
ZoneBuilder::AssumeMainThreadRole();
Utils::Hook::Call<void(int, int)>(0x4E2C80)(0, 0); // Cbuf_Execute
ZoneBuilder::ResetThreadRole();
Sleep(200);
}
return 0;
}
static Game::XZoneInfo baseZones_old[] = { static Game::XZoneInfo baseZones_old[] = {
{ "code_pre_gfx_mp", Game::ZoneAllocFlags::DB_ZONE_CODE, 0 }, { "code_pre_gfx_mp", Game::ZoneAllocFlags::DB_ZONE_CODE, 0 },
{ "localized_code_pre_gfx_mp", Game::ZoneAllocFlags::DB_ZONE_CODE_LOC, 0 }, { "localized_code_pre_gfx_mp", Game::ZoneAllocFlags::DB_ZONE_CODE_LOC, 0 },
@ -838,8 +827,17 @@ namespace Components
//Utils::Hook::Call<void()>(0x464A90)(); // Com_ParseCommandLine //Utils::Hook::Call<void()>(0x464A90)(); // Com_ParseCommandLine
Utils::Hook::Call<void()>(0x43D140)(); // Com_EventLoop Utils::Hook::Call<void()>(0x43D140)(); // Com_EventLoop
DWORD id = 0x12345678; ZoneBuilder::Terminate = false;
CreateThread(0, 0, CommandsThread, 0, 0, &id); ZoneBuilder::CommandThread = std::thread([]()
{
while (!ZoneBuilder::Terminate)
{
ZoneBuilder::AssumeMainThreadRole();
Utils::Hook::Call<void(int, int)>(0x4E2C80)(0, 0); // Cbuf_Execute
ZoneBuilder::ResetThreadRole();
std::this_thread::sleep_for(1ms);
}
});
Command::Add("quit", [](Command::Params*) Command::Add("quit", [](Command::Params*)
{ {
@ -862,7 +860,7 @@ namespace Components
Game::DB_LoadXAssets(baseZones_old, ARRAYSIZE(baseZones_old), 0); Game::DB_LoadXAssets(baseZones_old, ARRAYSIZE(baseZones_old), 0);
} }
Logger::Print("Waiting for fastiles to load..."); Logger::Print("Waiting for fastiles to load...\n");
while (!Game::Sys_IsDatabaseReady()) while (!Game::Sys_IsDatabaseReady())
{ {
Utils::Hook::Call<void()>(0x43D140)(); // Com_EventLoop Utils::Hook::Call<void()>(0x43D140)(); // Com_EventLoop
@ -908,7 +906,7 @@ namespace Components
} }
Utils::Hook::Call<void()>(0x43D140)(); // Com_EventLoop Utils::Hook::Call<void()>(0x43D140)(); // Com_EventLoop
Sleep(1); std::this_thread::sleep_for(1ms);
frames++; frames++;
} }
@ -982,7 +980,7 @@ namespace Components
}, false, false); }, false, false);
if (replacementFound) return ret; if (replacementFound) return ret;
return ""s; return "";
} }
ZoneBuilder::ZoneBuilder() ZoneBuilder::ZoneBuilder()
@ -1090,6 +1088,7 @@ namespace Components
return result; return result;
}); });
#ifdef ENABLE_EXPERIMENTAL_ENTRYPOINT
// set new entry point // set new entry point
Utils::Hook(0x4513DA, ZoneBuilder::EntryPoint, HOOK_JUMP).install()->quick(); Utils::Hook(0x4513DA, ZoneBuilder::EntryPoint, HOOK_JUMP).install()->quick();
@ -1101,6 +1100,7 @@ namespace Components
// thread fuckery hooks // thread fuckery hooks
Utils::Hook(0x4C37D0, ZoneBuilder::IsThreadMainThreadHook, HOOK_JUMP).install()->quick(); Utils::Hook(0x4C37D0, ZoneBuilder::IsThreadMainThreadHook, HOOK_JUMP).install()->quick();
#endif
// remove overriding asset messages // remove overriding asset messages
Utils::Hook::Nop(0x5BC74E, 5); Utils::Hook::Nop(0x5BC74E, 5);
@ -1522,6 +1522,12 @@ namespace Components
ZoneBuilder::~ZoneBuilder() ZoneBuilder::~ZoneBuilder()
{ {
assert(ZoneBuilder::MemAllocator.empty()); assert(ZoneBuilder::MemAllocator.empty());
ZoneBuilder::Terminate = true;
if(ZoneBuilder::CommandThread.joinable())
{
ZoneBuilder::CommandThread.join();
}
} }
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS) #if defined(DEBUG) || defined(FORCE_UNIT_TESTS)

View File

@ -125,9 +125,11 @@ namespace Components
static void ResetThreadRole(); static void ResetThreadRole();
static bool IsThreadMainThreadHook(); static bool IsThreadMainThreadHook();
static DWORD WINAPI CommandsThread(LPVOID);
static bool mainThreadInterrupted; static bool MainThreadInterrupted;
static DWORD interruptingThreadId; static DWORD InterruptingThreadId;
static bool Terminate;
static std::thread CommandThread;
}; };
} }