[General]: Attempt to fix a crash for Bisaknosp (#745)

This commit is contained in:
Edo 2023-01-30 12:43:24 +00:00 committed by GitHub
parent d00ba58658
commit dedfb36ad2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 49 additions and 31 deletions

View File

@ -89,6 +89,36 @@ namespace Components
}
}
void Dedicated::Com_ClampMsec(const int msec)
{
if (msec > 500 && msec < 500000)
{
Game::Com_PrintWarning(Game::CON_CHANNEL_SYSTEM, "Hitch warning: %i msec frame time\n", msec);
}
}
__declspec(naked) void Dedicated::Com_ClampMsec_Stub()
{
using namespace Game;
__asm
{
pushad
push ecx
call Com_ClampMsec
add esp, 0x4
popad
// Game's code
mov edx, dword ptr com_sv_running
push 0x47DDB8
ret
}
}
void Dedicated::TransmitGuids()
{
std::string list = Utils::String::VA("%c", 20);
@ -224,6 +254,9 @@ namespace Components
// Post initialization point
Utils::Hook(0x60BFBF, PostInitializationStub, HOOK_JUMP).install()->quick();
Utils::Hook(0x47DDB2, Com_ClampMsec_Stub, HOOK_JUMP).install()->quick(); // Com_Frame_Try_Block_Function
Utils::Hook::Nop(0x47DDB2 + 5, 1);
// Transmit custom data
Scheduler::Loop([]
{

View File

@ -23,6 +23,9 @@ namespace Components
static void PostInitialization();
static void PostInitializationStub();
static void Com_ClampMsec(int msec);
static void Com_ClampMsec_Stub();
static void TransmitGuids();
static void TimeWrapStub(Game::errorParm_t code, const char* message);

View File

@ -6,8 +6,6 @@ namespace Components
std::vector<Script::ScriptFunction> Script::CustomScrFunctions;
std::vector<Script::ScriptMethod> Script::CustomScrMethods;
int Script::LastFrameTime = -1;
std::unordered_map<const char*, const char*> Script::ReplacedFunctions;
const char* Script::ReplacedPos = nullptr;
@ -393,26 +391,6 @@ namespace Components
Utils::Hook(0x61E92E, VMExecuteInternalStub, HOOK_JUMP).install()->quick();
Utils::Hook::Nop(0x61E933, 1);
Scheduler::Loop([]
{
if (!Game::SV_Loaded())
return;
const auto nowMs = Game::Sys_Milliseconds();
if (LastFrameTime != -1)
{
const auto timeTaken = (nowMs - LastFrameTime) * static_cast<int>((*Game::com_timescale)->current.value);
if (timeTaken >= 500)
{
Logger::Print(Game::CON_CHANNEL_PARSERSCRIPT, "Hitch warning: {} msec frame time\n", timeTaken);
}
}
LastFrameTime = nowMs;
}, Scheduler::Pipeline::SERVER);
#ifdef _DEBUG
AddFunction("DebugBox", []
{

View File

@ -57,8 +57,6 @@ namespace Components
static std::vector<ScriptFunction> CustomScrFunctions;
static std::vector<ScriptMethod> CustomScrMethods;
static int LastFrameTime;
static std::unordered_map<std::string, int> ScriptMainHandles;
static std::unordered_map<std::string, int> ScriptInitHandles;

View File

@ -27,7 +27,7 @@ namespace Components
}
else
{
Logger::Debug("Successfully fetched motd");
Logger::Print("Successfully fetched motd");
}
}
@ -77,7 +77,7 @@ namespace Components
Changelog::LoadChangelog();
if (Terminate) return;
std::string data = Utils::Cache::GetFile("/iw4/motd.txt");
const auto data = Utils::Cache::GetFile("/iw4/motd.txt");
if (!data.empty())
{
Localization::Set("MPUI_MOTD_TEXT", data);
@ -90,7 +90,7 @@ namespace Components
// Sleep for 3 minutes
for (int i = 0; i < 180 && !Terminate; ++i)
{
std::this_thread::sleep_for(1s);
Game::Sys_Sleep(1);
}
}
}

View File

@ -373,12 +373,14 @@ namespace Components
{
std::thread([]
{
Com_InitThreadData();
// check natpmpstate
// state 4 is no more devices to query
while (Utils::Hook::Get<int>(0x66CE200) < 4)
{
Utils::Hook::Call<void()>(0x4D7030)();
std::this_thread::sleep_for(500ms);
Game::Sys_Sleep(500);
}
}).detach();
}, HOOK_JUMP).install()->quick();

View File

@ -5,7 +5,7 @@
namespace Components
{
bool Session::Terminate;
volatile bool Session::Terminate;
std::thread Session::Thread;
std::recursive_mutex Session::Mutex;
@ -144,11 +144,13 @@ namespace Components
Session::Terminate = false;
Session::Thread = std::thread([]()
{
Com_InitThreadData();
while (!Session::Terminate)
{
Session::RunFrame();
Session::HandleSignatures();
std::this_thread::sleep_for(20ms);
Game::Sys_Sleep(20);
}
});
}

View File

@ -38,7 +38,7 @@ namespace Components
static void Handle(const std::string& packet, const Network::NetworkCallback& callback);
private:
static bool Terminate;
static volatile bool Terminate;
static std::thread Thread;
static std::recursive_mutex Mutex;
static std::unordered_map<Network::Address, Frame> Sessions;

View File

@ -35,6 +35,7 @@ namespace Game
const dvar_t** com_developer = reinterpret_cast<const dvar_t**>(0x1AD78E8);
const dvar_t** com_developer_script = reinterpret_cast<const dvar_t**>(0x1AD8F10);
const dvar_t** com_timescale = reinterpret_cast<const dvar_t**>(0x1AD7920);
const dvar_t** com_maxFrameTime = reinterpret_cast<const dvar_t**>(0x1AD78F4);
const dvar_t** com_sv_running = reinterpret_cast<const dvar_t**>(0x1AD7934);
const dvar_t** dev_timescale = reinterpret_cast<const dvar_t**>(0x1AD8F20);

View File

@ -87,6 +87,7 @@ namespace Game
extern const dvar_t** com_developer;
extern const dvar_t** com_developer_script;
extern const dvar_t** com_timescale;
extern const dvar_t** com_maxFrameTime;
extern const dvar_t** com_sv_running;
extern const dvar_t** dev_timescale;