Skip to content

Commit

Permalink
disabled culling dvars, forced sv_punkbuster, general fixes
Browse files Browse the repository at this point in the history
- disabled culling dvars for now as they caused crashes and fps instability
- fixed a crash when disabling the CGaz / Compass module
- fixed a crash when disabling the d3d9ex module
- forced sv_punkbuster to 0 (randomly crashes the game)
  • Loading branch information
xoxor4d committed Jun 8, 2021
1 parent f737bf2 commit 169ebc0
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 43 deletions.
6 changes: 6 additions & 0 deletions src/Components/Modules/Mvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@ namespace Components

Mvm::Mvm()
{
Dvars::load_iw3mvm = Game::Dvar_RegisterBool(
/* name */ "load_iw3mvm",
/* desc */ "load iw3mvm on startup",
/* default */ false,
/* flags */ Game::dvar_flags::saved);

Dvars::cl_avidemo_streams = Game::Dvar_RegisterIntWrapper(
/* name */ "cl_avidemo_streams",
/* desc */ "just like mvm_streams",
Expand Down
6 changes: 0 additions & 6 deletions src/Components/Modules/QuickPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ namespace Components

QuickPatch::QuickPatch()
{
Dvars::load_iw3mvm = Game::Dvar_RegisterBool(
/* name */ "load_iw3mvm",
/* desc */ "load iw3mvm on startup",
/* default */ false,
/* flags */ Game::dvar_flags::saved);

// Force debug logging
Utils::Hook::Nop(0x4FCB9D, 8);

Expand Down
21 changes: 14 additions & 7 deletions src/Components/Modules/_CG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Components
/* scaY */ 0.8f,
/* font */ _CG::GetFontForStyle(Dvars::pm_hud_fontStyle->current.integer),
/* colr */ Dvars::pm_hud_fontColor->current.vector,
/* txt */ Utils::VA("viewMatrix:\n%.2lf %.2lf %.2lf %.2lf\n%.2lf %.2lf %.2lf %.2lf\n%.2lf %.2lf %.2lf %.2lf\n%.2lf %.2lf %.2lf %.2lf\n",
/* txt */ Utils::VA("viewMatrix:\n%.2lf %.2lf %.2lf %.2lf\n%.2lf %.2lf %.2lf %.2lf\n%.2lf %.2lf %.2lf %.2lf\n%.2lf %.2lf %.2lf %.2lf\n",
Game::Globals::viewMatrix.m[0][0], Game::Globals::viewMatrix.m[0][1], Game::Globals::viewMatrix.m[0][2], Game::Globals::viewMatrix.m[0][3],
Game::Globals::viewMatrix.m[1][0], Game::Globals::viewMatrix.m[1][1], Game::Globals::viewMatrix.m[1][2], Game::Globals::viewMatrix.m[1][3],
Game::Globals::viewMatrix.m[2][0], Game::Globals::viewMatrix.m[2][1], Game::Globals::viewMatrix.m[1][2], Game::Globals::viewMatrix.m[2][3],
Expand Down Expand Up @@ -79,11 +79,11 @@ namespace Components
// Pmove Speed Hud
if (Dvars::pm_hud_enable && Dvars::pm_hud_enable->current.enabled)
{
const char* movementType = Dvars::pm_movementType->current.integer == Game::PM_MTYPE::STOCK ? "Stock"
: Dvars::pm_movementType->current.integer == Game::PM_MTYPE::DEFRAG ? "Defrag" : "CS-Surf";
const char* movementType = Dvars::pm_movementType->current.integer == Game::PM_MTYPE::STOCK ? "Stock"
: Dvars::pm_movementType->current.integer == Game::PM_MTYPE::DEFRAG ? "Defrag" : "CS-Surf";

float xySpeed = sqrtf(Game::Globals::locPmove_playerVelocity.x * Game::Globals::locPmove_playerVelocity.x
+ Game::Globals::locPmove_playerVelocity.y * Game::Globals::locPmove_playerVelocity.y);
+ Game::Globals::locPmove_playerVelocity.y * Game::Globals::locPmove_playerVelocity.y);

Game::DrawTextWithEngine(
/* x */ Dvars::pm_hud_x->current.value,
Expand Down Expand Up @@ -120,7 +120,7 @@ namespace Components
/* font */ _CG::GetFontForStyle(Dvars::r_drawCollision_hud_fontStyle->current.integer),
/* colr */ Dvars::r_drawCollision_hud_fontColor->current.vector,
/* txt */ Utils::VA("Total amount of Brushes used for calculations: %d \n"
"Total amount of Polygons drawn: %d", Game::Globals::dbgColl_drawnBrushAmount, Game::Globals::dbgColl_drawnPlanesAmount));
"Total amount of Polygons drawn: %d", Game::Globals::dbgColl_drawnBrushAmount, Game::Globals::dbgColl_drawnPlanesAmount));
}
}

Expand All @@ -144,10 +144,17 @@ namespace Components
}

// mDd proxymod compass
Compass::main();
if (Components::active.Compass)
{
Compass::main();
}

// mDd proxymod CGaz
CGaz::main();
if (Components::active.CGaz)
{
CGaz::main();
}

}

// Hook call to CG_Drawcrosshair in CG_Draw2D ~ only active if cg_draw2d
Expand Down
9 changes: 8 additions & 1 deletion src/Components/Modules/_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ namespace Components
if (dedicated && !dedicated->current.integer)
{
auto sv_pure = Game::Dvar_FindVar("sv_pure");
auto sv_punkbuster = Game::Dvar_FindVar("sv_punkbuster");
auto r_zFeather = Game::Dvar_FindVar("r_zFeather");
auto r_distortion = Game::Dvar_FindVar("r_distortion");
auto r_fastSkin = Game::Dvar_FindVar("r_fastSkin");

if (sv_pure && sv_pure->current.enabled)
{
Game::Dvar_SetValue(sv_pure, false); // quick set the value
Game::Cmd_ExecuteSingleCommand(0, 0, "sv_pure 0\n"); // does this reset stats?
Game::Cmd_ExecuteSingleCommand(0, 0, "sv_pure 0\n");
}

if (sv_punkbuster && sv_punkbuster->current.enabled)
{
Game::Dvar_SetValue(sv_punkbuster, false); // quick set the value
Game::Cmd_ExecuteSingleCommand(0, 0, "sv_punkbuster 0\n");
}

// force depthbuffer
Expand Down
85 changes: 60 additions & 25 deletions src/Components/Modules/_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@ namespace Components
/* ---------------------------------------------------------- */
/* ------------ create dynamic rendering buffers ------------ */

IDirect3DDevice9* get_d3d_device()
{
if (Game::Globals::d3d9_device)
{
return Game::Globals::d3d9_device;
}
else
{
return *Game::dx9_device_ptr;
}
}

// Dynamic Indices
int R_AllocDynamicIndexBuffer(IDirect3DIndexBuffer9** ib, int sizeInBytes, const char* buffer_name, bool loadForRenderer)
{
if (!loadForRenderer) {
return 0;
}

HRESULT hr = Game::Globals::d3d9_device->CreateIndexBuffer(sizeInBytes, (D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY), D3DFMT_INDEX16, D3DPOOL_DEFAULT, ib, 0);
HRESULT hr = get_d3d_device()->CreateIndexBuffer(sizeInBytes, (D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY), D3DFMT_INDEX16, D3DPOOL_DEFAULT, ib, 0);
if (hr < 0)
{
const char* msg = Utils::function<const char* __stdcall(HRESULT)>(0x685F98)(hr); // R_ErrorDescription
Expand Down Expand Up @@ -50,7 +62,7 @@ namespace Components
return 0;
}

HRESULT hr = Game::Globals::d3d9_device->CreateVertexBuffer(sizeInBytes, (D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY), 0, D3DPOOL_DEFAULT, vb, 0);
HRESULT hr = get_d3d_device()->CreateVertexBuffer(sizeInBytes, (D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY), 0, D3DPOOL_DEFAULT, vb, 0);
if (hr < 0)
{
const char* msg = Utils::function<const char* __stdcall(HRESULT)>(0x685F98)(hr); // R_ErrorDescription
Expand Down Expand Up @@ -172,14 +184,15 @@ namespace Components

if (r_loadForRenderer)
{
HRESULT hr = Game::Globals::d3d9_device->CreateVertexBuffer(smodel_cache_vb_size, (D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY), 0, D3DPOOL_DEFAULT, &gfxBuf.smodelCacheVb, 0);
HRESULT hr = get_d3d_device()->CreateVertexBuffer(smodel_cache_vb_size, (D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY), 0, D3DPOOL_DEFAULT, &gfxBuf.smodelCacheVb, 0);
if (hr < 0)
{
const char* msg = Utils::function<const char* __stdcall(HRESULT)>(0x685F98)(hr); // R_ErrorDescription
msg = Utils::VA("DirectX didn't create a 0x%.8x dynamic vertex buffer: %s\n", smodel_cache_vb_size, msg);

Utils::function<void(const char*)>(0x576A30)(msg); // Sys_Error
}


Game::Com_PrintMessage(0, Utils::VA("D3D9: Created Vertexbuffer (smodelCacheVb) of size: 0x%.8x\n", smodel_cache_vb_size), 0);
}
Expand Down Expand Up @@ -340,23 +353,23 @@ namespace Components
/* maxVal */ 64,
/* flags */ Game::dvar_flags::saved | Game::dvar_flags::latched);

Dvars::r_cullWorld = Game::Dvar_RegisterBoolWrapper(
/* name */ "r_cullWorld",
/* desc */ "Culls invisible world surfaces. Disabling this can be useful for vertex manipulating shaders.",
/* default */ true,
/* flags */ Game::dvar_flags::latched);

Dvars::r_cullEntities = Game::Dvar_RegisterBoolWrapper(
/* name */ "r_cullEntities",
/* desc */ "Culls invisible entities. Disabling this can be useful for vertex manipulating shaders.",
/* default */ true,
/* flags */ Game::dvar_flags::latched);

Dvars::r_drawDynents = Game::Dvar_RegisterBoolWrapper(
/* name */ "r_drawDynents",
/* desc */ "Draw dynamic entities.",
/* default */ true,
/* flags */ Game::dvar_flags::none);
//Dvars::r_cullWorld = Game::Dvar_RegisterBoolWrapper(
// /* name */ "r_cullWorld",
// /* desc */ "Culls invisible world surfaces. Disabling this can be useful for vertex manipulating shaders.",
// /* default */ true,
// /* flags */ Game::dvar_flags::latched);

//Dvars::r_cullEntities = Game::Dvar_RegisterBoolWrapper(
// /* name */ "r_cullEntities",
// /* desc */ "Culls invisible entities. Disabling this can be useful for vertex manipulating shaders.",
// /* default */ true,
// /* flags */ Game::dvar_flags::latched);

//Dvars::r_drawDynents = Game::Dvar_RegisterBoolWrapper(
// /* name */ "r_drawDynents",
// /* desc */ "Draw dynamic entities.",
// /* default */ true,
// /* flags */ Game::dvar_flags::none);
}


Expand Down Expand Up @@ -473,6 +486,7 @@ namespace Components

/* ---------------------------------------------------------- */

#if 0 // disabled for now
// R_AddWorldSurfacesPortalWalk
__declspec(naked) void r_cull_world_stub_01()
{
Expand All @@ -484,16 +498,20 @@ namespace Components
cmp esi, ebp;
mov [esp + 10h], eax;

pushad;
push eax;
mov eax, Dvars::r_cullWorld;
cmp byte ptr[eax + 12], 1;
pop eax;

// jump if not culling world
jne SKIP;

popad;
jmp rtn_pt_stock;

SKIP:
popad;
jmp rtn_pt_skip;
}
}
Expand All @@ -509,16 +527,20 @@ namespace Components
fnstsw ax;
test ah, 41h;

pushad;
push eax;
mov eax, Dvars::r_cullWorld;
cmp byte ptr[eax + 12], 1;
pop eax;

// jump if not culling world
jne SKIP;

popad;
jmp rtn_pt_stock;

SKIP:
popad;
jmp rtn_pt_skip;
}
}
Expand All @@ -534,16 +556,20 @@ namespace Components
fnstsw ax;
test ah, 1;

pushad;
push eax;
mov eax, Dvars::r_cullWorld;
cmp byte ptr[eax + 12], 1;
pop eax;

// jump if not culling world
jne SKIP;

popad;
jmp rtn_pt_stock;

SKIP:
popad;
jmp rtn_pt_skip;
}
}
Expand All @@ -559,16 +585,20 @@ namespace Components
and [esp + 18h], edx;
cmp byte ptr[esi + eax], 0;

pushad;
push eax;
mov eax, Dvars::r_cullEntities;
cmp byte ptr[eax + 12], 1;
pop eax;

// jump if not culling world
jne SKIP;

popad;
jmp rtn_pt_stock;

SKIP:
popad;
jmp rtn_pt_skip;
}
}
Expand All @@ -580,19 +610,24 @@ namespace Components
const static uint32_t rtn_pt_stock = 0x62932D;
__asm
{
pushad;
push eax;
mov eax, Dvars::r_drawDynents;
cmp byte ptr[eax + 12], 1;
pop eax;

// jump if not culling world
jne SKIP;

popad;
call R_AddCellDynModelSurfacesInFrustumCmd_Func;

SKIP:
popad;
jmp rtn_pt_stock;
}
}
#endif


/* ---------------------------------------------------------- */
Expand Down Expand Up @@ -1239,22 +1274,22 @@ namespace Components

// R_AddWorldSurfacesPortalWalk :: less culling
// 0x60B02E -> jl to jmp // 0x7C -> 0xEB //Utils::Hook::Set<BYTE>(0x60B02E, 0xEB);
Utils::Hook::Nop(0x60B028, 6); Utils::Hook(0x60B028, r_cull_world_stub_01, HOOK_JUMP).install()->quick();
//Utils::Hook::Nop(0x60B028, 6); Utils::Hook(0x60B028, r_cull_world_stub_01, HOOK_JUMP).install()->quick(); // crashes on release

// R_AddAabbTreeSurfacesInFrustum_r :: disable all surface culling (bad fps)
// 0x643B08 -> nop //Utils::Hook::Nop(0x643B08, 6);
Utils::Hook(0x643B03, r_cull_world_stub_02, HOOK_JUMP).install()->quick();
//Utils::Hook(0x643B03, r_cull_world_stub_02, HOOK_JUMP).install()->quick();

// 0x643B39 -> jmp ^ // 0x74 -> 0xEB //Utils::Hook::Set<BYTE>(0x643B39, 0xEB);
Utils::Hook(0x643B34, r_cull_world_stub_03, HOOK_JUMP).install()->quick();
//Utils::Hook(0x643B34, r_cull_world_stub_03, HOOK_JUMP).install()->quick();

// R_AddCellSceneEntSurfacesInFrustumCmd :: active ents like destructible cars / players (disable all culling)
// 0x64D17A -> nop // 2 bytes //Utils::Hook::Nop(0x64D17A, 2);
Utils::Hook::Nop(0x64D172, 8); Utils::Hook(0x64D172, r_cull_entities_stub, HOOK_JUMP).install()->quick();
//Utils::Hook::Nop(0x64D172, 8); Utils::Hook(0x64D172, r_cull_entities_stub, HOOK_JUMP).install()->quick();

// R_AddWorkerCmd :: disable dynEnt models
// 0x629328 -> nop
Utils::Hook(0x629328, r_draw_dynents_stub, HOOK_JUMP).install()->quick();
//Utils::Hook(0x629328, r_draw_dynents_stub, HOOK_JUMP).install()->quick(); // popad makes it worse


/* ---------------------------------------------------------- */
Expand Down
3 changes: 1 addition & 2 deletions src/Game/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ namespace Game
int* wnd_SceneHeight = reinterpret_cast<int*>(0xCC9D0E4); // CC9D0E4
float* wnd_SceneAspect = reinterpret_cast<float*>(0xCC9D0FC); // CC9D0FC

IDirect3DDevice9* dx9_device = reinterpret_cast<IDirect3DDevice9*>(0xCC9D06C);
IDirect3DDevice9** dx9_device_ptr = reinterpret_cast<IDirect3DDevice9**>(0xCC9A408);
IDirect3DDevice9** dx9_device_ptr = reinterpret_cast<IDirect3DDevice9**>(0xCC9A408); // actual device

Game::Material* floatz_display = reinterpret_cast<Game::Material*>(0xFA5378);
GfxCmdBufSourceState* gfxCmdBufSourceState = reinterpret_cast<GfxCmdBufSourceState*>(0xD53F5F0);
Expand Down
1 change: 0 additions & 1 deletion src/Game/Functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ namespace Game
extern int* wnd_SceneHeight;
extern float* wnd_SceneAspect;

extern IDirect3DDevice9* dx9_device;
extern IDirect3DDevice9** dx9_device_ptr;

extern Game::Material* floatz_display;
Expand Down
2 changes: 1 addition & 1 deletion src/version.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* Automatically generated by premake5. */

#define IW3X_BUILDNUMBER 3419.0
#define IW3X_BUILDNUMBER 3421.0

0 comments on commit 169ebc0

Please sign in to comment.