Merge pull request #340 from diamante0018/fix-pipeline

[Scheduler] Use old hook for renderer pipeline & Fix crash in Renderer
This commit is contained in:
Dss0 2022-06-30 17:49:03 +02:00 committed by GitHub
commit bb74cca69a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 49 deletions

View File

@ -177,7 +177,7 @@ namespace Components
auto entities = Game::g_entities; auto entities = Game::g_entities;
for (auto i = 0u; i < 0x800u; i++) for (std::size_t i = 0; i < Game::MAX_GENTITIES; ++i)
{ {
auto* ent = &entities[i]; auto* ent = &entities[i];
@ -229,7 +229,7 @@ namespace Components
auto scene = Game::scene; auto scene = Game::scene;
for (auto i = 0; i < scene->sceneModelCount; i++) for (auto i = 0; i < scene->sceneModelCount; ++i)
{ {
if (!scene->sceneModel[i].model) if (!scene->sceneModel[i].model)
continue; continue;
@ -255,23 +255,27 @@ namespace Components
if (!val) return; if (!val) return;
// Ingame only auto clientNum = Game::CG_GetClientNum();
int clientNum = Game::CG_GetClientNum(); Game::gentity_t* clientEntity = &Game::g_entities[clientNum];
if (!Game::CL_IsCgameInitialized() ||
clientNum >= 18 || // Ingame only & player only
clientNum < 0 || if (!Game::CL_IsCgameInitialized() || clientEntity->client == nullptr)
Game::g_entities[clientNum].client == nullptr) { {
return; return;
} }
Game::gentity_t* clientEntity = &Game::g_entities[clientNum];
float playerPosition[3]{ clientEntity->r.currentOrigin[0], clientEntity->r.currentOrigin[1], clientEntity->r.currentOrigin[2] }; float playerPosition[3]{ clientEntity->r.currentOrigin[0], clientEntity->r.currentOrigin[1], clientEntity->r.currentOrigin[2] };
const auto mapName = Dvar::Var("mapname").get<const char*>(); const auto mapName = Dvar::Var("mapname").get<const char*>();
auto scene = Game::scene; auto scene = Game::scene;
auto world = Game::DB_FindXAssetEntry(Game::XAssetType::ASSET_TYPE_GFXWORLD, Utils::String::VA("maps/mp/%s.d3dbsp", mapName))->asset.header.gfxWorld; auto gfxAsset = Game::DB_FindXAssetEntry(Game::XAssetType::ASSET_TYPE_GFXWORLD, Utils::String::VA("maps/mp/%s.d3dbsp", mapName));
if (gfxAsset == nullptr)
{
return;
}
auto world = gfxAsset->asset.header.gfxWorld;
auto drawDistance = r_playerDrawDebugDistance.get<int>(); auto drawDistance = r_playerDrawDebugDistance.get<int>();
auto sqrDist = drawDistance * drawDistance; auto sqrDist = drawDistance * drawDistance;
@ -297,7 +301,6 @@ namespace Components
} }
} }
break; break;
case 2: case 2:
for (auto i = 0; i < scene->sceneDObjCount; i++) for (auto i = 0; i < scene->sceneDObjCount; i++)
{ {
@ -320,7 +323,6 @@ namespace Components
} }
} }
break; break;
case 3: case 3:
// Static models // Static models
for (size_t i = 0; i < world->dpvs.smodelCount; i++) for (size_t i = 0; i < world->dpvs.smodelCount; i++)
@ -344,6 +346,8 @@ namespace Components
} }
} }
break; break;
default:
break;
} }
} }
@ -353,41 +357,45 @@ namespace Components
if (!val) return; if (!val) return;
// Ingame only auto clientNum = Game::CG_GetClientNum();
int clientNum = Game::CG_GetClientNum(); Game::gentity_t* clientEntity = &Game::g_entities[clientNum];
if (!Game::CL_IsCgameInitialized() ||
clientNum >= 18 ||
clientNum < 0 ||
Game::g_entities[clientNum].client == nullptr) {
// Ingame only & player only
if (!Game::CL_IsCgameInitialized() || clientEntity->client == nullptr)
{
return; return;
} }
Game::gentity_t* clientEntity = &Game::g_entities[clientNum];
float playerPosition[3]{ clientEntity->r.currentOrigin[0], clientEntity->r.currentOrigin[1], clientEntity->r.currentOrigin[2] }; float playerPosition[3]{ clientEntity->r.currentOrigin[0], clientEntity->r.currentOrigin[1], clientEntity->r.currentOrigin[2] };
const auto mapName = Dvar::Var("mapname").get<const char*>(); const auto mapName = Dvar::Var("mapname").get<const char*>();
auto scene = Game::scene; auto scene = Game::scene;
auto world = Game::DB_FindXAssetEntry(Game::XAssetType::ASSET_TYPE_GFXWORLD, Utils::String::VA("maps/mp/%s.d3dbsp", mapName))->asset.header.gfxWorld; auto gfxAsset = Game::DB_FindXAssetEntry(Game::XAssetType::ASSET_TYPE_GFXWORLD, Utils::String::VA("maps/mp/%s.d3dbsp", mapName));
if (gfxAsset == nullptr)
{
return;
}
auto world = gfxAsset->asset.header.gfxWorld;
auto drawDistance = r_playerDrawDebugDistance.get<int>(); auto drawDistance = r_playerDrawDebugDistance.get<int>();
auto sqrDist = drawDistance * drawDistance; auto sqrDist = drawDistance * drawDistance;
switch (val) { switch (val)
{
case 1: case 1:
for (auto i = 0; i < scene->sceneModelCount; i++) for (auto i = 0; i < scene->sceneModelCount; i++)
{ {
if (!scene->sceneModel[i].model) if (!scene->sceneModel[i].model)
continue; continue;
if (Utils::Maths::Vec3SqrDistance(playerPosition, scene->sceneModel[i].placement.base.origin) < sqrDist) if (Utils::Maths::Vec3SqrDistance(playerPosition, scene->sceneModel[i].placement.base.origin) < static_cast<float>(sqrDist))
{ {
Game::R_AddDebugString(sceneModelsColor, scene->sceneModel[i].placement.base.origin, 1.0, scene->sceneModel[i].model->name); Game::R_AddDebugString(sceneModelsColor, scene->sceneModel[i].placement.base.origin, 1.0, scene->sceneModel[i].model->name);
} }
} }
break; break;
case 2: case 2:
for (auto i = 0; i < scene->sceneDObjCount; i++) for (auto i = 0; i < scene->sceneDObjCount; i++)
{ {
@ -395,7 +403,7 @@ namespace Components
{ {
for (int j = 0; j < scene->sceneDObj[i].obj->numModels; j++) for (int j = 0; j < scene->sceneDObj[i].obj->numModels; j++)
{ {
if (Utils::Maths::Vec3SqrDistance(playerPosition, scene->sceneDObj[i].placement.origin) < sqrDist) if (Utils::Maths::Vec3SqrDistance(playerPosition, scene->sceneDObj[i].placement.origin) < static_cast<float>(sqrDist))
{ {
Game::R_AddDebugString(dobjsColor, scene->sceneDObj[i].placement.origin, 1.0, scene->sceneDObj[i].obj->models[j]->name); Game::R_AddDebugString(dobjsColor, scene->sceneDObj[i].placement.origin, 1.0, scene->sceneDObj[i].obj->models[j]->name);
} }
@ -403,7 +411,6 @@ namespace Components
} }
} }
break; break;
case 3: case 3:
// Static models // Static models
for (size_t i = 0; i < world->dpvs.smodelCount; i++) for (size_t i = 0; i < world->dpvs.smodelCount; i++)
@ -412,13 +419,15 @@ namespace Components
if (staticModel.model) if (staticModel.model)
{ {
const auto dist = Utils::Maths::Vec3SqrDistance(playerPosition, staticModel.placement.origin); const auto dist = Utils::Maths::Vec3SqrDistance(playerPosition, staticModel.placement.origin);
if (dist < sqrDist) if (dist < static_cast<float>(sqrDist))
{ {
Game::R_AddDebugString(staticModelsColor, staticModel.placement.origin, 1.0, staticModel.model->name); Game::R_AddDebugString(staticModelsColor, staticModel.placement.origin, 1.0, staticModel.model->name);
} }
} }
} }
break; break;
default:
break;
} }
} }
@ -467,14 +476,14 @@ namespace Components
Utils::Hook(0x536A80, Renderer::BackendFrameStub, HOOK_JUMP).install()->quick(); Utils::Hook(0x536A80, Renderer::BackendFrameStub, HOOK_JUMP).install()->quick();
// Begin device recovery (not D3D9Ex) // Begin device recovery (not D3D9Ex)
Utils::Hook(0x508298, []() Utils::Hook(0x508298, []
{ {
Game::DB_BeginRecoverLostDevice(); Game::DB_BeginRecoverLostDevice();
Renderer::BeginRecoverDeviceSignal(); Renderer::BeginRecoverDeviceSignal();
}, HOOK_CALL).install()->quick(); }, HOOK_CALL).install()->quick();
// End device recovery (not D3D9Ex) // End device recovery (not D3D9Ex)
Utils::Hook(0x508355, []() Utils::Hook(0x508355, []
{ {
Renderer::EndRecoverDeviceSignal(); Renderer::EndRecoverDeviceSignal();
Game::DB_EndRecoverLostDevice(); Game::DB_EndRecoverLostDevice();

View File

@ -67,9 +67,9 @@ namespace Components
Pipelines[type].execute(); Pipelines[type].execute();
} }
void Scheduler::REndFrame_Hk() void Scheduler::CL_DrawScreen_Hk()
{ {
Utils::Hook::Call<void()>(0x50AB20)(); Utils::Hook::Call<void()>(0x5AC950)();
Execute(Pipeline::RENDERER); Execute(Pipeline::RENDERER);
} }
@ -165,9 +165,7 @@ namespace Components
} }
}); });
Utils::Hook(0x4DBE9A, REndFrame_Hk, HOOK_CALL).install()->quick(); Utils::Hook(0x5ACB99, CL_DrawScreen_Hk, HOOK_CALL).install()->quick();
Utils::Hook(0x518D5C, REndFrame_Hk, HOOK_CALL).install()->quick();
Utils::Hook(0x5ACBA3, REndFrame_Hk, HOOK_CALL).install()->quick();
// Hook G_Glass_Update so we may fix TLS issues // Hook G_Glass_Update so we may fix TLS issues
Utils::Hook(0x416049, ServerFrame_Hk, HOOK_CALL).install()->quick(); Utils::Hook(0x416049, ServerFrame_Hk, HOOK_CALL).install()->quick();

View File

@ -59,7 +59,7 @@ namespace Components
static void Execute(Pipeline type); static void Execute(Pipeline type);
static void REndFrame_Hk(); static void CL_DrawScreen_Hk();
static void ServerFrame_Hk(); static void ServerFrame_Hk();
static void ClientFrame_Hk(int localClientNum); static void ClientFrame_Hk(int localClientNum);
static void MainFrame_Hk(); static void MainFrame_Hk();

View File

@ -142,14 +142,6 @@ namespace Components
} }
} }
void Toast::CL_DrawScreen_Stub(int localClientNum)
{
Utils::Hook::Call<void(int)>(0x5AC950)(localClientNum);
Handler();
}
Toast::Toast() Toast::Toast()
{ {
if (Dedicated::IsEnabled() || Monitor::IsEnabled() || ZoneBuilder::IsEnabled()) if (Dedicated::IsEnabled() || Monitor::IsEnabled() || ZoneBuilder::IsEnabled())
@ -157,7 +149,7 @@ namespace Components
return; return;
} }
Utils::Hook(0x5ACB99, CL_DrawScreen_Stub, HOOK_CALL).install()->quick(); Scheduler::Loop(Handler, Scheduler::Pipeline::RENDERER);
#ifdef TEST_TOAST #ifdef TEST_TOAST
Command::Add("testtoast", []([[maybe_unused]] Command::Params* params) Command::Add("testtoast", []([[maybe_unused]] Command::Params* params)

View File

@ -23,7 +23,6 @@ namespace Components
static void Handler(); static void Handler();
static void Draw(UIToast* toast); static void Draw(UIToast* toast);
static void CL_DrawScreen_Stub(int localClientNum);
static std::queue<UIToast> Queue; static std::queue<UIToast> Queue;
static std::mutex Mutex; static std::mutex Mutex;

View File

@ -1143,8 +1143,8 @@ namespace Game
extern int* demoRecording; extern int* demoRecording;
extern int* serverMessageSequence; extern int* serverMessageSequence;
constexpr auto MAX_GENTITIES = 2048u; constexpr std::size_t MAX_GENTITIES = 2048;
constexpr auto ENTITYNUM_NONE = MAX_GENTITIES - 1; constexpr std::size_t ENTITYNUM_NONE = MAX_GENTITIES - 1;
extern gentity_t* g_entities; extern gentity_t* g_entities;
extern netadr_t* connectedHost; extern netadr_t* connectedHost;