Skip to content

Commit f76af24

Browse files
committed
clang support
1 parent ec693be commit f76af24

16 files changed

+308
-93
lines changed

CMakeLists.txt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
1+
# cmake --preset <clang|gcc>
2+
# cmake --build --preset <clang|gcc>
23
#
34
# ninja
45
# ninja install
@@ -105,14 +106,22 @@ target_compile_options(dsfix
105106
-msse2
106107
-msse
107108
-Wall
108-
-Werror
109+
# -Werror
109110
-Wno-array-bounds
110-
-Wextra
111+
# -Wextra
111112
-Wno-cast-function-type
112113
-Wno-unused-parameter
113114
-Wno-unused-but-set-variable
114115
)
115116
endif()
117+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
118+
message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
119+
target_compile_options(dsfix
120+
PRIVATE
121+
-Wno-microsoft-exception-spec
122+
-Wno-missing-exception-spec
123+
)
124+
endif()
116125
target_compile_definitions(dsfix
117126
PRIVATE
118127
-DUNICODE
@@ -127,13 +136,15 @@ set_target_properties(dsfix
127136
)
128137

129138
if(MSVC)
130-
find_path(d3dx9_include_dir "d3dx9.h"
131-
REQUIRED
132-
PATH_SUFFIXES "dxsdk-d3dx"
133-
)
134-
target_include_directories(dsfix PRIVATE ${d3dx9_include_dir})
135-
find_library(d3dx9_library "d3dx9.lib" REQUIRED)
136-
target_link_libraries(dsfix PRIVATE ${d3dx9_library})
139+
# find_path(d3dx9_include_dir "d3dx9.h"
140+
# REQUIRED
141+
# PATH_SUFFIXES "dxsdk-d3dx"
142+
# )
143+
# target_include_directories(dsfix PRIVATE ${d3dx9_include_dir})
144+
# find_library(d3dx9_library "d3dx9.lib" REQUIRED)
145+
# target_link_libraries(dsfix PRIVATE ${d3dx9_library})
146+
target_include_directories(dsfix PRIVATE "$ENV{d3dx_path}\\include")
147+
target_link_libraries(dsfix PRIVATE "$ENV{d3dx_path}\\release\\lib\\x86\\d3dx9.lib")
137148
endif()
138149

139150
install(

CMakePresets.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"version": 2,
3+
"configurePresets": [
4+
{
5+
"name": "gcc",
6+
"generator": "Ninja",
7+
"binaryDir": "build",
8+
"cacheVariables": {
9+
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
10+
}
11+
},
12+
{
13+
"name": "clang",
14+
"generator": "Ninja",
15+
"binaryDir": "build-clang",
16+
"cacheVariables": {
17+
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
18+
"CMAKE_C_COMPILER": "clang",
19+
"CMAKE_CXX_COMPILER": "clang++",
20+
"CMAKE_CXX_FLAGS": "-stdlib=libc++",
21+
"CMAKE_SHARED_LINKER_FLAGS": "-fuse-ld=lld",
22+
"CMAKE_EXE_LINKER_FLAGS": "-fuse-ld=lld"
23+
}
24+
},
25+
{
26+
"name": "msvc",
27+
"generator": "Visual Studio 17 2022",
28+
"binaryDir": "build-msvc",
29+
"architecture": "win32"
30+
}
31+
]
32+
}

DATA/DSfix.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ captureCursor 0
147147
# skip the intro logos
148148
skipIntro 0
149149

150+
# override the in-game language
151+
# none = no override
152+
# en-GB = English, fr = French, it = Italian, de = German, es = Spanish
153+
# ko = Korean, zh-tw = Chinese, pl = Polish, ru = Russian
154+
overrideLanguage none
155+
150156
# D3D adapter override
151157
# -1 = no override
152158
# N = use adapter N

Detouring.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,55 @@
11
#include "Detouring.h"
2+
#include "Settings.h"
23
#include "d3d9.h"
34
#include <MinHook.h>
45
#include <spdlog/spdlog.h>
56

67
decltype(Direct3DCreate9)* oDirect3DCreate9;
8+
decltype(GetUserDefaultLangID)* oGetUserDefaultLangID;
79

810
namespace {
911
void* Direct3DCreate9Handle;
12+
void* GetUserDefaultLangIDHandle;
1013
} // namespace
1114

15+
// en-GB = English, fr = French, it = Italian, de = German, es = Spanish
16+
// ko = Korean, zh-tw = Chinese, pl = Polish, ru = Russian
17+
LANGID hkGetUserDefaultLangID() {
18+
const auto& lang = Settings::get().getOverrideLanguage();
19+
if (lang == "en-GB")
20+
return MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK);
21+
else if (lang == "fr")
22+
return MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT);
23+
else if (lang == "it")
24+
return MAKELANGID(LANG_ITALIAN, SUBLANG_DEFAULT);
25+
else if (lang == "de")
26+
return MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT);
27+
else if (lang == "es")
28+
return MAKELANGID(LANG_SPANISH, SUBLANG_DEFAULT);
29+
else if (lang == "ko")
30+
return MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT);
31+
else if (lang == "zh-tw")
32+
return MAKELANGID(LANG_CHINESE_TRADITIONAL, SUBLANG_DEFAULT);
33+
else if (lang == "pl")
34+
return MAKELANGID(LANG_POLISH, SUBLANG_DEFAULT);
35+
else if (lang == "ru")
36+
return MAKELANGID(LANG_RUSSIAN, SUBLANG_DEFAULT);
37+
else
38+
return oGetUserDefaultLangID();
39+
}
40+
1241
void startDetour() {
1342
MH_Initialize();
1443
Direct3DCreate9Handle =
1544
reinterpret_cast<void*>(::GetProcAddress(GetModuleHandleW(L"d3d9.dll"), "Direct3DCreate9"));
1645
MH_CreateHook(Direct3DCreate9Handle, reinterpret_cast<void*>(&hkDirect3DCreate9),
1746
reinterpret_cast<void**>(&oDirect3DCreate9));
1847
MH_EnableHook(Direct3DCreate9Handle);
48+
GetUserDefaultLangIDHandle = reinterpret_cast<void*>(
49+
::GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetUserDefaultLangID"));
50+
MH_CreateHook(GetUserDefaultLangIDHandle, reinterpret_cast<void*>(&hkGetUserDefaultLangID),
51+
reinterpret_cast<void**>(&oGetUserDefaultLangID));
52+
MH_EnableHook(GetUserDefaultLangIDHandle);
1953
}
2054

2155
void endDetour() {

RenderstateManager.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ unsigned int getDOFResolution() {
2020
}
2121
} // namespace
2222

23-
RSManager RSManager::instance;
23+
RSManager::RSManager(IDirect3DDevice9* pDevice) : m_pDevice(pDevice) { onReset(); }
2424

2525
void RSManager::setupAA() {
2626
unsigned int rw = Settings::get().getRenderWidth();
@@ -35,7 +35,9 @@ void RSManager::setupAA() {
3535
new FXAA(m_pDevice.Get(), rw, rh, (FXAA::Quality)(Settings::get().getAAQuality() - 1)));
3636
smaa = nullptr;
3737
}
38+
doAA = true;
3839
} else {
40+
doAA = false;
3941
fxaa = nullptr;
4042
smaa = nullptr;
4143
}
@@ -53,17 +55,22 @@ void RSManager::setupSSAO() {
5355
unsigned int rw = Settings::get().getRenderWidth();
5456
unsigned int rh = Settings::get().getRenderHeight();
5557
ssao.reset(new SSAO(m_pDevice.Get(), rw, rh, Settings::get().getSsaoStrength() - 1, ssaoType));
58+
doSsao = true;
5659
} else {
5760
ssao = nullptr;
61+
doSsao = false;
5862
}
5963
}
6064

6165
void RSManager::setupDoF() {
6266
unsigned int dofRes = getDOFResolution();
63-
if (Settings::get().getDOFBlurAmount())
67+
if (Settings::get().getDOFBlurAmount()) {
6468
gauss.reset(new GAUSS(m_pDevice.Get(), dofRes * 16 / 9, dofRes));
65-
else
69+
doDofGauss = true;
70+
} else {
6671
gauss = nullptr;
72+
doDofGauss = false;
73+
}
6774
}
6875

6976
void RSManager::onReset() {

RenderstateManager.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
class RSManager {
1212
private:
13-
D3DVIEWPORT9 viewport;
13+
D3DVIEWPORT9 viewport = {};
1414
Microsoft::WRL::ComPtr<IDirect3DDevice9> m_pDevice;
1515
double lastPresentTime = 0;
16-
bool doAA = false;
16+
bool doAA = true;
1717
std::unique_ptr<SMAA> smaa;
1818
std::unique_ptr<FXAA> fxaa;
1919
bool doSsao = true;
@@ -36,7 +36,7 @@ class RSManager {
3636
unsigned int nrts = 0;
3737
// Count the number of times the 2 upper DoF rendertargets were set in doft[1]
3838
// & doft[2]
39-
std::array<unsigned int, 3> doft;
39+
std::array<unsigned int, 3> doft = {};
4040
// main rendertarget for this frame
4141
Microsoft::WRL::ComPtr<IDirect3DSurface9> mainRT;
4242
unsigned int mainRTuses = 0;
@@ -48,16 +48,10 @@ class RSManager {
4848
unsigned int isDof(unsigned int width, unsigned int height);
4949
void measureOcclusionScale();
5050
void frameTimeManagement();
51-
static RSManager instance;
5251

5352
public:
5453
~RSManager() = default;
55-
RSManager() = default;
56-
57-
static RSManager& get() { return instance; }
58-
59-
// DI
60-
void setD3DDevice(IDirect3DDevice9* pDevice) { m_pDevice = pDevice; }
54+
RSManager(IDirect3DDevice9* pDevice);
6155

6256
void setupAA();
6357
void setupSSAO();

Settings.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ SETTING(unsigned int, LogLevel, "logLevel", 0);
2525
SETTING(bool, DisableCursor, "disableCursor", false);
2626
SETTING(bool, CaptureCursor, "captureCursor", false);
2727

28+
// Language Options
29+
SETTING(std::string, OverrideLanguage, "overrideLanguage", "");
30+
2831
// Skipping Options
2932
SETTING(bool, SkipIntro, "skipIntro", false);
3033

d3d9dev.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ HRESULT APIENTRY hkIDirect3DDevice9::Present(CONST RECT* pSourceRect, CONST RECT
1616
HWND hDestWindowOverride,
1717
CONST RGNDATA* pDirtyRegion) {
1818
WindowManager::get().toggleCursorCapture();
19-
return RSManager::get().redirectPresent(pSourceRect, pDestRect, hDestWindowOverride,
20-
pDirtyRegion);
19+
return m_pRSManager->redirectPresent(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
2120
}
2221

2322
HRESULT APIENTRY hkIDirect3DDevice9::SetVertexShaderConstantF(UINT StartRegister,
@@ -31,7 +30,7 @@ HRESULT APIENTRY hkIDirect3DDevice9::SetRenderTarget(DWORD RenderTargetIndex,
3130
if (RenderTargetIndex != 0)
3231
return D3D_OK; // rendertargets > 0 are not actually used by the game - this
3332
// makes the log shorter
34-
return RSManager::get().redirectSetRenderTarget(RenderTargetIndex, pRenderTarget);
33+
return m_pRSManager->redirectSetRenderTarget(RenderTargetIndex, pRenderTarget);
3534
}
3635

3736
HRESULT APIENTRY hkIDirect3DDevice9::SetVertexShader(IDirect3DVertexShader9* pvShader) {
@@ -40,7 +39,7 @@ HRESULT APIENTRY hkIDirect3DDevice9::SetVertexShader(IDirect3DVertexShader9* pvS
4039

4140
HRESULT APIENTRY hkIDirect3DDevice9::SetViewport(CONST D3DVIEWPORT9* pViewport) {
4241
Settings::get().init();
43-
RSManager::get().setViewport(*pViewport);
42+
m_pRSManager->setViewport(*pViewport);
4443
return m_pD3Ddev->SetViewport(pViewport);
4544
}
4645

@@ -91,7 +90,7 @@ HRESULT APIENTRY hkIDirect3DDevice9::GetBackBuffer(UINT iSwapChain, UINT iBackBu
9190
}
9291

9392
HRESULT APIENTRY hkIDirect3DDevice9::EndScene() {
94-
Ui::get().onEndScene();
93+
m_pUi->onEndScene();
9594
return m_pD3Ddev->EndScene();
9695
}
9796

@@ -476,8 +475,8 @@ ULONG APIENTRY hkIDirect3DDevice9::Release() { return m_pD3Ddev->Release(); }
476475
HRESULT APIENTRY hkIDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParameters) {
477476
HRESULT hRet = m_pD3Ddev->Reset(pPresentationParameters);
478477
if (SUCCEEDED(hRet)) {
479-
Ui::get().onReset();
480-
RSManager::get().onReset();
478+
m_pUi->onReset();
479+
m_pRSManager->onReset();
481480
} else {
482481
spdlog::error(L"ERROR: Reset failed: code: {}, description: {}", DXGetErrorString9W(hRet),
483482
DXGetErrorDescription9W(hRet));
@@ -611,7 +610,7 @@ HRESULT APIENTRY hkIDirect3DDevice9::SetScissorRect(CONST RECT* pRect) {
611610
// SetScissorRect RECT[1024/ 0/2048/1024]
612611
// SetScissorRect RECT[ 0/1024/1024/2048]
613612
// SetScissorRect RECT[1024/1024/2048/2048]
614-
if (RSManager::get().isViewport(*pRect) ||
613+
if (m_pRSManager->isViewport(*pRect) ||
615614
(pRect->left == 0 && pRect->top == 0 && pRect->right == 1024 && pRect->bottom == 1024) ||
616615
(pRect->left == 1024 && pRect->top == 0 && pRect->right == 2048 && pRect->bottom == 1024) ||
617616
(pRect->left == 0 && pRect->top == 1024 && pRect->right == 1024 && pRect->bottom == 2048) ||
@@ -637,7 +636,7 @@ HRESULT APIENTRY hkIDirect3DDevice9::SetStreamSourceFreq(UINT StreamNumber, UINT
637636
}
638637

639638
HRESULT APIENTRY hkIDirect3DDevice9::SetTexture(DWORD Stage, IDirect3DBaseTexture9* pTexture) {
640-
return RSManager::get().redirectSetTexture(Stage, pTexture);
639+
return m_pRSManager->redirectSetTexture(Stage, pTexture);
641640
}
642641

643642
HRESULT APIENTRY hkIDirect3DDevice9::SetTextureStageState(DWORD Stage,
@@ -696,3 +695,11 @@ HRESULT APIENTRY hkIDirect3DDevice9::UpdateTexture(IDirect3DBaseTexture9* pSourc
696695
HRESULT APIENTRY hkIDirect3DDevice9::ValidateDevice(DWORD* pNumPasses) {
697696
return m_pD3Ddev->ValidateDevice(pNumPasses);
698697
}
698+
699+
float hkIDirect3DDevice9::getOcclusionScale() { return m_pRSManager->getOcclusionScale(); }
700+
701+
void hkIDirect3DDevice9::setUi(Ui* pUi) { m_pUi = pUi; }
702+
703+
IDirect3DDevice9* hkIDirect3DDevice9::getDevice() { return m_pD3Ddev.Get(); }
704+
705+
void hkIDirect3DDevice9::setRSManager(RSManager* pRSManager) { m_pRSManager = pRSManager; }

d3d9dev.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
#include <wrl.h>
44
#include "d3d9int.h"
55

6+
class RSManager;
7+
class Ui;
8+
69
interface hkIDirect3DDevice9 : public IDirect3DDevice9 {
710
private:
811
// callback interface
912
Microsoft::WRL::ComPtr<IDirect3DDevice9> m_pD3Ddev;
1013
Microsoft::WRL::ComPtr<IDirect3D9> m_pD3D9;
14+
RSManager* m_pRSManager;
15+
Ui* m_pUi;
1116

1217
public:
1318
// original interface
@@ -199,10 +204,12 @@ interface hkIDirect3DDevice9 : public IDirect3DDevice9 {
199204
(UINT Handle, CONST float* pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo);
200205
STDMETHOD(DeletePatch)(UINT Handle);
201206
STDMETHOD(CreateQuery)(D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery);
202-
207+
203208
hkIDirect3DDevice9(IDirect3DDevice9* pIDirect3DDevice9, IDirect3D9* pD3D9);
204-
205-
IDirect3DDevice9* getDevice() { return m_pD3Ddev.Get(); };
209+
IDirect3DDevice9* getDevice();
210+
void setRSManager(RSManager* pRSManager);
211+
float getOcclusionScale();
212+
void setUi(Ui* pUi);
206213

207214
virtual ~hkIDirect3DDevice9() = default;
208215
};

d3d9int.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
using namespace Microsoft;
1010

11-
class hkIDirect3DDevice9;
11+
struct hkIDirect3DDevice9;
1212

1313
WRL::ComPtr<hkIDirect3DDevice9> g_pD3DDevice;
1414

0 commit comments

Comments
 (0)