Skip to content

Commit

Permalink
Improvements & Fixes
Browse files Browse the repository at this point in the history
-Fix vertex buffers memory leak
-Prevent DX7 PackStaticVertexBuffers from loading unneeded vertex buffers
-Calculate correctly instanced geometry drawed triangles
-Show per frame drawed tris on toggle frame
-Close GD3D11 settings menu when detecting pressed escape key
  • Loading branch information
SaiyansKing committed Oct 16, 2021
1 parent c5dfcb0 commit f4c9997
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 5 deletions.
15 changes: 15 additions & 0 deletions D3D11Engine/D3D11GraphicsEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,9 @@ XRESULT D3D11GraphicsEngine::DrawSkeletalMesh( SkeletalVobInfo* vi,

// Draw the mesh
GetContext()->DrawIndexed( numIndices, 0, 0 );

Engine::GAPI->GetRendererState().RendererInfo.FrameDrawnTriangles +=
numIndices / 3;
}
}

Expand Down Expand Up @@ -1541,6 +1544,9 @@ XRESULT D3D11GraphicsEngine::DrawInstanced(
// Draw the batch
GetContext()->DrawIndexedInstanced( numIndices, numInstances, 0, 0, 0 );

Engine::GAPI->GetRendererState().RendererInfo.FrameDrawnTriangles +=
(numIndices / 3) * numInstances;

return XR_SUCCESS;
}

Expand Down Expand Up @@ -1575,6 +1581,9 @@ XRESULT D3D11GraphicsEngine::DrawInstanced(
GetContext()->DrawIndexedInstanced( numIndices, numInstances, indexOffset, 0,
startInstanceNum );

Engine::GAPI->GetRendererState().RendererInfo.FrameDrawnTriangles +=
(numIndices / 3) * numInstances;

Engine::GAPI->GetRendererState().RendererInfo.FrameDrawnVobs++;

return XR_SUCCESS;
Expand Down Expand Up @@ -5226,6 +5235,12 @@ void D3D11GraphicsEngine::DrawUnderwaterEffects() {
"PS_PFX_UnderwaterFinal" );
}

/** Returns the settings window availability */
bool D3D11GraphicsEngine::HasSettingsWindow()
{
return (UIView && !UIView->GetSettingsDialog()->IsHidden());
}

/** Creates the main UI-View */
void D3D11GraphicsEngine::CreateMainUIView() {
if ( !UIView ) {
Expand Down
3 changes: 3 additions & 0 deletions D3D11Engine/D3D11GraphicsEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ class D3D11GraphicsEngine : public D3D11GraphicsEngineBase {
/** Returns the UI-View */
D2DView* GetUIView() { return UIView.get(); }

/** Returns the settings window availability */
bool HasSettingsWindow();

/** Creates the main UI-View */
void CreateMainUIView();

Expand Down
3 changes: 0 additions & 3 deletions D3D11Engine/D3D7/MyDirect3DDevice7.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ class MyDirect3DDevice7 : public IDirect3DDevice7 {
FakeDeviceDesc.dwVertexProcessingCaps = (D3DVTXPCAPS_TEXGEN|D3DVTXPCAPS_MATERIALSOURCE7|D3DVTXPCAPS_DIRECTIONALLIGHTS|D3DVTXPCAPS_POSITIONALLIGHTS|D3DVTXPCAPS_LOCALVIEWER);
}

~MyDirect3DDevice7() {
}

/*** IUnknown methods ***/
HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppvObj ) {
DebugWrite( "MyDirect3DDevice7::QueryInterface" );
Expand Down
3 changes: 3 additions & 0 deletions D3D11Engine/D3D7/MyDirect3DVertexBuffer7.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class MyDirect3DVertexBuffer7 : public IDirect3DVertexBuffer7 {
RefCount = 1;
}

~MyDirect3DVertexBuffer7() {
delete VertexBuffer;
}

/*** IUnknown methods ***/
HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppvObj ) {
Expand Down
2 changes: 1 addition & 1 deletion D3D11Engine/DLLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ BOOL WINAPI DllMain( HINSTANCE hInst, DWORD reason, LPVOID ) {
// Check for right version
VersionCheck::CheckExecutable();
CheckPlatformSupport();
HookedFunctions::OriginalFunctions.InitHooks();

Engine::GAPI = nullptr;
Engine::GraphicsEngine = nullptr;

// Create GothicAPI here to make all hooks work
Engine::CreateGothicAPI();
HookedFunctions::OriginalFunctions.InitHooks();

EnableCrashingOnCrashes();
//SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
Expand Down
14 changes: 13 additions & 1 deletion D3D11Engine/GothicAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2583,10 +2583,13 @@ LRESULT GothicAPI::OnWindowMessage( HWND hWnd, UINT msg, WPARAM wParam, LPARAM l
LogInfo() << ss.str();
}
break;
}

#endif
case VK_F11:
if ( ( GetAsyncKeyState( VK_CONTROL ) & 0x8000 ) && !GMPModeActive ) {
if ( reinterpret_cast<D3D11GraphicsEngine*>(Engine::GraphicsEngine)->HasSettingsWindow() )
Engine::GraphicsEngine->OnUIEvent( BaseGraphicsEngine::EUIEvent::UI_OpenSettings );

Engine::AntTweakBar->SetActive( !Engine::AntTweakBar->GetActive() );
SetEnableGothicInput( !Engine::AntTweakBar->GetActive() );
} else {
Expand All @@ -2598,6 +2601,15 @@ LRESULT GothicAPI::OnWindowMessage( HWND hWnd, UINT msg, WPARAM wParam, LPARAM l
}
break;

case VK_ESCAPE:
if ( Engine::AntTweakBar->GetActive() ) {
Engine::AntTweakBar->SetActive( false );
SetEnableGothicInput( true );
}
if ( reinterpret_cast<D3D11GraphicsEngine*>(Engine::GraphicsEngine)->HasSettingsWindow() )
Engine::GraphicsEngine->OnUIEvent( BaseGraphicsEngine::EUIEvent::UI_OpenSettings );
break;

case VK_NUMPAD1:
if ( !Engine::AntTweakBar->GetActive() && !GMPModeActive && Engine::GAPI->GetRendererState().RendererSettings.AllowNumpadKeys )
SpawnVegetationBoxAt( GetCameraPosition() );
Expand Down
20 changes: 20 additions & 0 deletions D3D11Engine/HookedFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void HookedFunctionInfo::InitHooks() {
PatchAddr( 0x005CA683, "\x90\x90" );

LogInfo() << "Patching: Improve loading times by disabling some unnecessary features";
PatchAddr( 0x005A4FE0, "\xC3\x90\x90" );
PatchAddr( 0x0055848A, "\xE9\xE2\x01\x00\x00\x90" );
PatchAddr( 0x005F7F7C, "\x1F" );
PatchAddr( 0x005F8D40, "\x1F" );
Expand All @@ -124,6 +125,15 @@ void HookedFunctionInfo::InitHooks() {
PatchAddr( 0x0051E5B5, "\xEB\x22" );
PatchAddr( 0x0051E62A, "\x8D\x24\x24\x8B\x4A\x30\x8B\x04\xA9\x8B\x48\x40\x83\xC0\x38\x85\xC9\x74\x28\x33\xF6\x85\xC9\x7E\x22\x8B\x18\x8B\xFB\x8D\x1B\x39\x17\x74\x0A\x46\x83\xC7\x04\x3B\xF1\x7C\xF4\xEB\x0E\x49\x3B\xF1\x89\x48\x08\x74\x06\x8B\x04\x8B\x89\x04\xB3\x8B\x42\x38\x45\x3B\xE8\x7C\xC0\xEB\x65\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90" );

LogInfo() << "Patching: Show correct tris on toggle frame";
{
char* trisHndl[5];
DWORD trisHandle = reinterpret_cast<DWORD>(&Engine::GAPI->GetRendererState().RendererInfo.FrameDrawnTriangles);
memcpy( trisHndl, &trisHandle, 4 );
PatchAddr( 0x0063DA2E, "\xA1\xD0\x5E\x8C\x00\x90\x90\x90\x90\x90\x90" );
PatchAddr( 0x0063DA2F, trisHndl );
}

// Show DirectX11 as currently used graphic device
{
PatchAddr( 0x0071F8DF, "\x55\x56\xBE\x00\x00\x00\x00\x90\x90\x90\x90" );
Expand Down Expand Up @@ -190,6 +200,7 @@ void HookedFunctionInfo::InitHooks() {

#ifndef BUILD_SPACER_NET
LogInfo() << "Patching: Improve loading times by disabling some unnecessary features";
PatchAddr( 0x005C6E30, "\xC3\x90\x90\x90\x90\x90" );
PatchAddr( 0x00571256, "\xE9\xC6\x02\x00\x00\x90" );
PatchAddr( 0x006C8748, "\x90\x90\x90\x90\x90\x90" );
PatchAddr( 0x00530D75, "\x90\x90" );
Expand All @@ -200,6 +211,15 @@ void HookedFunctionInfo::InitHooks() {
PatchAddr( 0x00530F7A, "\x8D\xA4\x24\x00\x00\x00\x00\x8B\x4A\x30\x8B\x04\xA9\x8B\x48\x40\x83\xC0\x38\x85\xC0\x74\x28\x33\xF6\x85\xC9\x7E\x22\x8B\x18\x8B\xFB\x8D\x1B\x39\x17\x74\x0A\x46\x83\xC7\x04\x3B\xF1\x7C\xF4\xEB\x0E\x49\x3B\xF1\x89\x48\x08\x74\x06\x8B\x04\x8B\x89\x04\xB3\x8B\x42\x38\x45\x3B\xE8\x7C\xC0\xEB\x61\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90" );
#endif

LogInfo() << "Patching: Show correct tris on toggle frame";
{
char* trisHndl[5];
DWORD trisHandle = reinterpret_cast<DWORD>(&Engine::GAPI->GetRendererState().RendererInfo.FrameDrawnTriangles);
memcpy( trisHndl, &trisHandle, 4 );
PatchAddr( 0x006C80F2, "\x36\x8B\x3D\x08\x2F\x98\x00" );
PatchAddr( 0x006C80F5, trisHndl );
}

// Show DirectX11 as currently used graphic device
{
PatchAddr( 0x006581AD, "\x57\xBD\x00\x00\x00\x00\x90" );
Expand Down

0 comments on commit f4c9997

Please sign in to comment.