diff --git a/DDraw/DDraw.def b/DDraw/DDraw.def
index 7eb9b71..6e837db 100644
--- a/DDraw/DDraw.def
+++ b/DDraw/DDraw.def
@@ -1,3 +1,3 @@
LIBRARY DDRAW
EXPORTS
- DirectDrawCreateEx=_DirectDrawCreateEx@16 @10
\ No newline at end of file
+ DirectDrawCreateEx = DirectDrawCreateEx@16
diff --git a/DDraw/DDraw.vcxproj b/DDraw/DDraw.vcxproj
index b2b3976..1d4c13d 100644
--- a/DDraw/DDraw.vcxproj
+++ b/DDraw/DDraw.vcxproj
@@ -83,7 +83,6 @@
/Zc:threadSafeInit- /Zc:strictStrings %(AdditionalOptions)
- ddraw.def
Windows
shell32.dll;shlwapi.dll;%(DelayLoadDLLs)
true
@@ -113,7 +112,6 @@
true
true
- ddraw.def
Windows
shell32.dll;shlwapi.dll;%(DelayLoadDLLs)
true
@@ -143,7 +141,6 @@
true
true
- ddraw.def
Windows
shell32.dll;shlwapi.dll;%(DelayLoadDLLs)
true
@@ -172,4 +169,4 @@
-
\ No newline at end of file
+
diff --git a/DDraw/dllmain.cpp b/DDraw/dllmain.cpp
index 9f098f1..f68182a 100644
--- a/DDraw/dllmain.cpp
+++ b/DDraw/dllmain.cpp
@@ -4,8 +4,8 @@
#include
#include
-#include
-#include
+#include
+#include
#include "Utils/MemoryMgr.h"
#include "Utils/Patterns.h"
#include "Utils/ScopedUnprotect.hpp"
@@ -14,6 +14,7 @@
#include "Desktop.h"
#pragma comment(lib, "shlwapi.lib")
+#pragma comment(linker, "/EXPORT:DirectDrawCreateEx=_DirectDrawCreateEx@16")
extern "C" HRESULT WINAPI DirectDrawCreateEx(GUID FAR *lpGUID, LPVOID *lplpDD, REFIID iid, IUnknown FAR *pUnkOuter)
{
@@ -197,7 +198,7 @@ static bool PatchIAT()
static bool PatchIAT_ByPointers()
{
pOrgSystemParametersInfoA = SystemParametersInfoA;
- memcpy( orgCode, pOrgSystemParametersInfoA, sizeof(orgCode) );
+ memcpy( orgCode, reinterpret_cast(pOrgSystemParametersInfoA), sizeof(orgCode) );
Memory::VP::InjectHook( pOrgSystemParametersInfoA, SystemParametersInfoA_OverwritingHook, Memory::HookType::Jump );
return true;
}
@@ -230,4 +231,4 @@ extern "C" __declspec(dllexport)
uint32_t GetBuildNumber()
{
return (SILENTPATCH_REVISION_ID << 8) | SILENTPATCH_BUILD_ID;
-}
\ No newline at end of file
+}
diff --git a/SilentPatch/Common.cpp b/SilentPatch/Common.cpp
index e64f88b..0851950 100644
--- a/SilentPatch/Common.cpp
+++ b/SilentPatch/Common.cpp
@@ -34,7 +34,7 @@ namespace HandlingNameLoadFix
// ============= Corona lines rendering fix =============
namespace CoronaLinesFix
{
- static decltype(RwIm2DRenderLine)* orgRwIm2DRenderLine;
+ static RwIm2DRenderLineFunction orgRwIm2DRenderLine;
static RwBool RenderLine_SetRecipZ( RwIm2DVertex *vertices, RwInt32 numVertices, RwInt32 vert1, RwInt32 vert2 )
{
const RwReal nearScreenZ = RwIm2DGetNearScreenZ();
@@ -379,4 +379,4 @@ namespace Common {
TXN_CATCH();
}
}
-}
\ No newline at end of file
+}
diff --git a/SilentPatch/Common.h b/SilentPatch/Common.h
index 8565cf8..3b8b203 100644
--- a/SilentPatch/Common.h
+++ b/SilentPatch/Common.h
@@ -2,6 +2,13 @@
#include
+// Workaround for old MSVC inline function bugs
+#if defined(_MSC_VER) && _MSC_VER < 1930
+#define STATIC_INLINE static
+#else
+#define STATIC_INLINE static inline
+#endif
+
namespace ExtraCompSpecularity
{
void ReadExtraCompSpecularityExceptions(const wchar_t* pPath);
@@ -15,4 +22,4 @@ namespace Common
void III_VC_Common();
void III_VC_SetDelayedPatchesFunc( void(*func)() );
}
-};
\ No newline at end of file
+};
diff --git a/SilentPatch/Common_ddraw.cpp b/SilentPatch/Common_ddraw.cpp
index 62e1240..d5c1dd2 100644
--- a/SilentPatch/Common_ddraw.cpp
+++ b/SilentPatch/Common_ddraw.cpp
@@ -1,22 +1,20 @@
-#include "Common_ddraw.h"
-
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define NOMINMAX
+#include "Common_ddraw.h"
+
#include
-#include
-#include
+#include
+#include
#include "Utils/MemoryMgr.h"
#include "Utils/Patterns.h"
#pragma comment(lib, "shlwapi.lib")
-extern char** ppUserFilesDir;
-
namespace Common {
char* GetMyDocumentsPath()
{
@@ -249,4 +247,4 @@ namespace Common {
TXN_CATCH();
}
}
-}
\ No newline at end of file
+}
diff --git a/SilentPatch/Common_ddraw.h b/SilentPatch/Common_ddraw.h
index 577df68..be179cc 100644
--- a/SilentPatch/Common_ddraw.h
+++ b/SilentPatch/Common_ddraw.h
@@ -2,6 +2,8 @@
#include
+extern char** ppUserFilesDir;
+
namespace Common
{
namespace Patches
@@ -18,4 +20,4 @@ namespace Common
void DDraw_Common();
}
-};
\ No newline at end of file
+};
diff --git a/SilentPatch/Desktop.cpp b/SilentPatch/Desktop.cpp
index d4a69c0..e769d9d 100644
--- a/SilentPatch/Desktop.cpp
+++ b/SilentPatch/Desktop.cpp
@@ -1,11 +1,11 @@
-#include "Desktop.h"
-
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define NOMINMAX
+#include "Desktop.h"
+
#include
std::pair GetDesktopResolution()
@@ -21,4 +21,4 @@ std::pair GetDesktopResolution()
result.second = displaySettings.dmPelsHeight;
}
return result;
-}
\ No newline at end of file
+}
diff --git a/SilentPatch/FriendlyMonitorNames.cpp b/SilentPatch/FriendlyMonitorNames.cpp
index a219e6c..8610e32 100644
--- a/SilentPatch/FriendlyMonitorNames.cpp
+++ b/SilentPatch/FriendlyMonitorNames.cpp
@@ -1,5 +1,3 @@
-#include "FriendlyMonitorNames.h"
-
// This API is Win7 only, so make sure we use dynamic imports
#define WIN32_LEAN_AND_MEAN
@@ -7,6 +5,8 @@
#define WINVER 0x0602
#define _WIN32_WINNT 0x0602
+#include "FriendlyMonitorNames.h"
+
#include
#include
diff --git a/SilentPatch/Maths.h b/SilentPatch/Maths.h
index c25c5ee..7f76c97 100644
--- a/SilentPatch/Maths.h
+++ b/SilentPatch/Maths.h
@@ -6,6 +6,15 @@
#include
+// FIXME: Common.h might be a better place for this (but SA doesn't include it)
+#ifdef _MSC_VER
+#define NOBUFFERCHECKS __declspec(safebuffers)
+#elif defined(__GNUC__) && !defined(__clang__)
+#define NOBUFFERCHECKS __attribute__((optimize("-fno-stack-protector")))
+#else
+#define NOBUFFERCHECKS __attribute__((no_stack_protector))
+#endif
+
constexpr double RAD_TO_DEG (180.0/M_PI);
constexpr double DEG_TO_RAD (M_PI/180.0);
@@ -570,4 +579,4 @@ public:
return angle;
}
-};
\ No newline at end of file
+};
diff --git a/SilentPatch/ParseUtils.cpp b/SilentPatch/ParseUtils.cpp
index 1988733..2ec3431 100644
--- a/SilentPatch/ParseUtils.cpp
+++ b/SilentPatch/ParseUtils.cpp
@@ -1,8 +1,9 @@
-#include "ParseUtils.hpp"
-
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
-#include
+
+#include "ParseUtils.hpp"
+
+#include
static std::string WcharToUTF8(std::wstring_view str)
{
diff --git a/SilentPatch/RWGTA.cpp b/SilentPatch/RWGTA.cpp
index 551db45..245777e 100644
--- a/SilentPatch/RWGTA.cpp
+++ b/SilentPatch/RWGTA.cpp
@@ -1,8 +1,6 @@
#include "Utils/MemoryMgr.h"
#include "Utils/Patterns.h"
-#define RwEngineInstance (*rwengine)
-
#include
#include "RWGTA.h"
@@ -52,6 +50,7 @@ void RwD3D8GetRenderState(RwUInt32 state, void* value)
fnRwD3D8GetRenderState(state, value);
}
+#ifndef RwIm2DGetNearScreenZ
RwReal RwIm2DGetNearScreenZ()
{
return RWSRCGLOBAL(dOpenDevice).zBufferNear;
@@ -66,6 +65,7 @@ RwBool RwRenderStateSet(RwRenderState state, void *value)
{
return RWSRCGLOBAL(dOpenDevice).fpRenderStateSet(state, value);
}
+#endif
// Unreachable stub
RwBool RwMatrixDestroy(RwMatrix* /*mpMat*/) { assert(!"Unreachable!"); return TRUE; }
@@ -78,19 +78,19 @@ bool RWGTA::Patches::TryLocateRwD3D8() try
auto pfnRwD3D8SetRenderState = [] {
try {
// Everything except for III Steam
- return static_cast(get_pattern("39 0C C5 ? ? ? ? 74 31", -8));
+ return reinterpret_cast(get_pattern("39 0C C5 ? ? ? ? 74 31", -8));
} catch (const hook::txn_exception&) {
// III Steam
- return static_cast(get_pattern("8B 0C C5 ? ? ? ? 3B CA", -8));
+ return reinterpret_cast(get_pattern("8B 0C C5 ? ? ? ? 3B CA", -8));
}
}();
auto pfnRwD3D8GetRenderState = [] {
try {
// Everything except for III Steam
- return static_cast(get_pattern("8B 0C C5 ? ? ? ? 89 0A C3", -8));
+ return reinterpret_cast(get_pattern("8B 0C C5 ? ? ? ? 89 0A C3", -8));
} catch (const hook::txn_exception&) {
// III Steam
- return static_cast(get_pattern("8B 04 C5 ? ? ? ? 89 02 C3", -8));
+ return reinterpret_cast(get_pattern("8B 04 C5 ? ? ? ? 89 02 C3", -8));
}
}();
@@ -101,4 +101,4 @@ bool RWGTA::Patches::TryLocateRwD3D8() try
catch (const hook::txn_exception&)
{
return false;
-}
\ No newline at end of file
+}
diff --git a/SilentPatch/RWGTA.h b/SilentPatch/RWGTA.h
index e184dc9..8a3c34c 100644
--- a/SilentPatch/RWGTA.h
+++ b/SilentPatch/RWGTA.h
@@ -1,5 +1,9 @@
#pragma once
+#define RwEngineInstance (*rwengine)
+
+extern void** rwengine;
+
namespace RWGTA::Patches
{
bool TryLocateRwD3D8();
diff --git a/SilentPatch/RWUtils.hpp b/SilentPatch/RWUtils.hpp
index abe0653..11ce366 100644
--- a/SilentPatch/RWUtils.hpp
+++ b/SilentPatch/RWUtils.hpp
@@ -3,6 +3,10 @@
#include
#include
+#define RwEngineInstance (*rwengine)
+
+extern void** rwengine;
+
template
class RwScopedRenderState
{
@@ -68,4 +72,4 @@ Pred RpGeometryForAllMaterials(RpGeometry* geometry, Pred callback)
break;
}
return callback;
-}
\ No newline at end of file
+}
diff --git a/SilentPatch/SVF.cpp b/SilentPatch/SVF.cpp
index e48016c..afe424e 100644
--- a/SilentPatch/SVF.cpp
+++ b/SilentPatch/SVF.cpp
@@ -1,9 +1,13 @@
#include "SVF.h"
-#include
#include
#include