Skip to content

Commit

Permalink
Added 60 FPS mod, dds texture loading, tweak SSAO
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterTh committed Sep 22, 2012
1 parent faa4581 commit 392e4af
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 39 deletions.
8 changes: 8 additions & 0 deletions DATA/DSfix.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ smaaQuality 0
# 3 = high
ssaoStrength 0

# Set the maximum FPS (default 30)
# NOTE:
# - this requires in-memory modification of game code, and may get you banned from GFWL
# - there may be unintended side-effects in terms of gameplay
# - you need a very powerful system (especially CPU) in order to maintain 60 FPS
# Use this at your own risk!
maxFPS 30

############# Depth of field

# Depth of Field resolution override, possible values:
Expand Down
4 changes: 2 additions & 2 deletions DATA/README.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DSfix 1.5 by Durante -- README
==============================
DSfix by Durante -- README
==========================

**Please read this whole document before running anything!**

Expand Down
13 changes: 13 additions & 0 deletions DATA/VERSIONS.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
22-09-2012 -- version 1.5 beta
==============================
Bugfixes:
- fixed issue with SSAO being rendered on top of particle effects/fog/water, instead of below them
- improved method of determining when to apply SMAA/SSAO, better renderstate management
(may fix random display corruption issue)
- tweaked SSAO a bit
New features:
- Can load .dds texture overrides in addition to .png
- Can set the desired target FPS of the game in the .ini, thanks to Cl�ment Barnier!
(This now also works correctly together with the intro skip feature)


14-09-2012 -- version 1.4 beta
==============================
Bugfixes:
Expand Down
40 changes: 6 additions & 34 deletions DATA/dsfix/VSSAO.fx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

extern float scale = 1; //downsampling scale, 1 is highest quality but slowest
extern float aoRadiusMultiplier = 1.0; //Linearly multiplies the radius of the AO Sampling
extern float ThicknessModel = 80.0; //units in space the AO assumes objects' thicknesses are
extern float FOV = 90; //Field of View in Degrees
extern float ThicknessModel = 40.0; //units in space the AO assumes objects' thicknesses are
extern float FOV = 75; //Field of View in Degrees
extern float luminosity_threshold = 0.3;

#ifndef SSAO_STRENGTH_LOW
Expand All @@ -20,17 +20,17 @@ extern float luminosity_threshold = 0.3;
#endif

#ifdef SSAO_STRENGTH_LOW
extern float aoClamp = 0.7;
extern float aoStrengthMultiplier = 0.7;
extern float aoClamp = 0.75;
extern float aoStrengthMultiplier = 0.6;
#endif

#ifdef SSAO_STRENGTH_MEDIUM
extern float aoClamp = 0.45;
extern float aoClamp = 0.5;
extern float aoStrengthMultiplier = 0.8;
#endif

#ifdef SSAO_STRENGTH_HIGH
extern float aoClamp = 0.1;
extern float aoClamp = 0.2;
extern float aoStrengthMultiplier = 1.2;
#endif

Expand Down Expand Up @@ -283,48 +283,20 @@ technique t0
{
VertexShader = compile vs_3_0 FrameVS();
PixelShader = compile ps_3_0 ssao_Main();
ZEnable = false;
ZWriteEnable = false;
AlphaBlendEnable = false;
AlphaTestEnable = false;
StencilEnable = false;
Clipping = false;
CullMode = NONE;
}
pass p1
{
VertexShader = compile vs_3_0 FrameVS();
PixelShader = compile ps_3_0 HBlur();
ZEnable = false;
ZWriteEnable = false;
AlphaBlendEnable = false;
AlphaTestEnable = false;
StencilEnable = false;
Clipping = false;
CullMode = NONE;
}
pass p2
{
VertexShader = compile vs_3_0 FrameVS();
PixelShader = compile ps_3_0 VBlur();
ZEnable = false;
ZWriteEnable = false;
AlphaBlendEnable = false;
AlphaTestEnable = false;
StencilEnable = false;
Clipping = false;
CullMode = NONE;
}
pass p3
{
VertexShader = compile vs_1_1 FrameVS();
PixelShader = compile ps_2_0 Combine();
ZEnable = false;
ZWriteEnable = false;
AlphaBlendEnable = false;
AlphaTestEnable = false;
StencilEnable = false;
Clipping = false;
CullMode = NONE;
}
}
Binary file modified DSfix.v11.suo
Binary file not shown.
7 changes: 6 additions & 1 deletion DSfix.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@
<TargetMachine>MachineX86</TargetMachine>
<AdditionalLibraryDirectories>E:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ModuleDefinitionFile>DINPUT8.def</ModuleDefinitionFile>
<AdditionalDependencies>winmm.lib;detours.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>lib\GFWLCompatibility.lib;winmm.lib;detours.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<Midl>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
Expand Down Expand Up @@ -251,6 +254,7 @@
<ClCompile Include="Detouring.cpp" />
<ClCompile Include="dinputWrapper.cpp" />
<ClCompile Include="Effect.cpp" />
<ClCompile Include="FPS.cpp" />
<ClCompile Include="GAUSS.cpp" />
<ClCompile Include="Hud.cpp" />
<ClCompile Include="KeyActions.cpp" />
Expand Down Expand Up @@ -313,6 +317,7 @@
<ClInclude Include="Effect.h" />
<ClInclude Include="GAUSS.h" />
<ClInclude Include="Hash.h" />
<ClInclude Include="FPS.h" />
<ClInclude Include="Hud.h" />
<ClInclude Include="KeyActions.h" />
<ClInclude Include="SearchTex.h" />
Expand Down
77 changes: 77 additions & 0 deletions FPS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Dark Souls FPS fix by Clement Barnier
////////////////////////////////////////

#include "FPS.h"

#include <windows.h>

#include "Settings.h"
#include "main.h"

static DWORD originalBase = NULL;
static DWORD imageBase = NULL;

void enableGFWLCompatibility(void);

void writeToAddress(void* Data, DWORD Address, int Size) {
DWORD oldProtect;
VirtualProtect((LPVOID)Address, Size, PAGE_READWRITE, &oldProtect);
memcpy((void*)Address, Data, Size);
VirtualProtect((LPVOID)Address, Size, oldProtect, &oldProtect);
}

DWORD getAbsoluteAddress(DWORD offset) {
if (imageBase)
return imageBase + offset;
else
return NULL;
}

DWORD convertAddress(DWORD Address) {
return getAbsoluteAddress(Address - originalBase);
}

void applyFPSPatch() {
enableGFWLCompatibility();

// Get imageBase
originalBase = 0x0400000;
HANDLE exeHandle = GetModuleHandle(NULL);

if(exeHandle != NULL)
imageBase = (DWORD)exeHandle;

SDLOG(0, "FPS patch: image base %p\n", imageBase);

// Apply patch
DWORD address;
BYTE data16;
DWORD data;
DWORD64 data64;

// Desired max. FPS
double FPS = Settings::get().getMaxFPS();

// Gameplay FPS patch
address = convertAddress(0x012497F0);
float dt = 1/(float)FPS;
data = *(DWORD*)&dt;
writeToAddress(&data, address, sizeof(data));

// Target FPS patch (display ?)
address = convertAddress(0x01249958);
data64 = *(DWORD64*)&FPS;
writeToAddress(&data64, address, sizeof(data64));

// Max FPS patch
address = convertAddress(0x00644BBA);
data16 = (BYTE)FPS;
writeToAddress(&data16, address, sizeof(data16));

// Override FPS Divider
address = convertAddress(0x010275AE);
data = 1;
writeToAddress(&data, address, sizeof(data));

SDLOG(0, "FPS patch: patched to %4.1lf maximum FPS\n", FPS);
}
6 changes: 6 additions & 0 deletions FPS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Dark Souls FPS fix by Clement Barnier
////////////////////////////////////////

#pragma once

void applyFPSPatch();
15 changes: 13 additions & 2 deletions RenderstateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ HRESULT RSManager::redirectSetRenderTarget(DWORD RenderTargetIndex, IDirect3DSur
//if(takeScreenshot) D3DXSaveTextureToFile("0effect_pre.bmp", D3DXIFF_BMP, tex, NULL);
//if(takeScreenshot) D3DXSaveTextureToFile("0effect_z.bmp", D3DXIFF_BMP, zTex, NULL);
storeRenderState();
d3ddev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
d3ddev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
d3ddev->SetRenderState(D3DRS_STENCILENABLE, FALSE);
d3ddev->SetRenderState(D3DRS_CLIPPING, FALSE);
d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
d3ddev->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);
// perform SSAO
if(vssao && doVssao) {
Expand Down Expand Up @@ -386,7 +392,7 @@ HRESULT RSManager::redirectPresent(CONST RECT *pSourceRect, CONST RECT *pDestRec
}
if(timingIntroMode) {
skippedPresents++;
if(skippedPresents>=300) {
if(skippedPresents >= 300 * Settings::get().getMaxFPS()/30) {
SDLOG(1, "Intro mode ended (timeout)!\n");
timingIntroMode = false;
}
Expand Down Expand Up @@ -626,7 +632,12 @@ HRESULT RSManager::redirectD3DXCreateTextureFromFileInMemoryEx(LPDIRECT3DDEVICE9
char buffer[128];
sprintf_s(buffer, "dsfix/tex_override/%08x.png", hash);
if(fileExists(buffer)) {
SDLOG(3, "Texture override! hash: %8x\n", SrcDataSize, hash);
SDLOG(3, "Texture override (png)! hash: %8x\n", SrcDataSize, hash);
return D3DXCreateTextureFromFileEx(pDevice, buffer, D3DX_DEFAULT, D3DX_DEFAULT, MipLevels, Usage, Format, Pool, Filter, MipFilter, ColorKey, pSrcInfo, pPalette, ppTexture);
}
sprintf_s(buffer, "dsfix/tex_override/%08x.dds", hash);
if(fileExists(buffer)) {
SDLOG(3, "Texture override (dds)! hash: %8x\n", SrcDataSize, hash);
return D3DXCreateTextureFromFileEx(pDevice, buffer, D3DX_DEFAULT, D3DX_DEFAULT, MipLevels, Usage, Format, Pool, Filter, MipFilter, ColorKey, pSrcInfo, pPalette, ppTexture);
}
}
Expand Down
2 changes: 2 additions & 0 deletions Settings.def
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ SETTING(unsigned, SmaaQuality, "smaaQuality", 0);

SETTING(unsigned, SsaoStrength, "ssaoStrength", 0);

SETTING(unsigned, MaxFPS, "maxFPS", 30);

// Logging Options
SETTING(unsigned, LogLevel, "logLevel", 10);

Expand Down
Binary file added lib/GFWLCompatibility.lib
Binary file not shown.
3 changes: 3 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "KeyActions.h"
#include "Detouring.h"
#include "SaveManager.h"
#include "FPS.h"

#define VERSION "1.5"

Expand Down Expand Up @@ -68,6 +69,8 @@ bool WINAPI DllMain(HMODULE hDll, DWORD dwReason, PVOID pvReserved) {

earlyDetour();

if(Settings::get().getMaxFPS() != 30) applyFPSPatch();

return true;
} else if(dwReason == DLL_PROCESS_DETACH) {
Settings::get().shutdown();
Expand Down

0 comments on commit 392e4af

Please sign in to comment.