Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

III/VC cross-compile fixes #95

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f33f5c1
Remove unused dllmain.cpp file
TheComputerGuy96 Nov 7, 2024
c15fbc5
Use lowercase names for Windows headers
TheComputerGuy96 Nov 4, 2024
fe6f98c
Set Windows defines earlier
TheComputerGuy96 Nov 4, 2024
b5483bb
Use reinterpret_cast for function pointer casts
TheComputerGuy96 Nov 6, 2024
5890527
SilentPatchIII/VC/SA: Add GCC/Clang-compatible safebuffers equivalent
TheComputerGuy96 Nov 6, 2024
04f7433
SilentPatchIII/VC: Remove extern from ppUserFilesDir variable definit…
TheComputerGuy96 Nov 6, 2024
1af97ee
SilentPatchIII/VC/SA: Mark some function pointers as inline
TheComputerGuy96 Nov 7, 2024
940c689
DDraw: Use a pragma for DirectDrawCreateEx export on MSVC
TheComputerGuy96 Nov 4, 2024
acc4af2
DDraw: Cast the memcpy() source argument
TheComputerGuy96 Nov 4, 2024
80b4fa1
SilentPatch: Don't define certain Rw* functions if not needed
TheComputerGuy96 Nov 4, 2024
4ba23db
SilentPatch: Simplify RwIm2DRenderLine function pointer declaration
TheComputerGuy96 Nov 6, 2024
77f5e90
SilentPatch: Move RwEngineInstance definition to headers
TheComputerGuy96 Nov 13, 2024
50b1c13
SilentPatch: Define a replacement for _stricmp() on non-MSVC
TheComputerGuy96 Nov 4, 2024
d3e5495
SilentPatch: Move a header include in SVF
TheComputerGuy96 Nov 4, 2024
1b174a3
SilentPatch: Add missing cmath header include
TheComputerGuy96 Nov 6, 2024
d6f3ea8
SilentPatchIII: Add a missing functional header include
TheComputerGuy96 Nov 4, 2024
c2e58d3
SilentPatchIII: Add GCC-style inline assembly statements
TheComputerGuy96 Nov 4, 2024
815ee10
SilentPatchVC: Add GCC-style inline assembly statements
TheComputerGuy96 Nov 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DDraw/DDraw.def
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
LIBRARY DDRAW
EXPORTS
DirectDrawCreateEx=_DirectDrawCreateEx@16 @10
DirectDrawCreateEx = DirectDrawCreateEx@16
5 changes: 1 addition & 4 deletions DDraw/DDraw.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
<AdditionalOptions>/Zc:threadSafeInit- /Zc:strictStrings %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<ModuleDefinitionFile>ddraw.def</ModuleDefinitionFile>
<SubSystem>Windows</SubSystem>
<DelayLoadDLLs>shell32.dll;shlwapi.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<LargeAddressAware>true</LargeAddressAware>
Expand Down Expand Up @@ -113,7 +112,6 @@
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>ddraw.def</ModuleDefinitionFile>
<SubSystem>Windows</SubSystem>
<DelayLoadDLLs>shell32.dll;shlwapi.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<LargeAddressAware>true</LargeAddressAware>
Expand Down Expand Up @@ -143,7 +141,6 @@
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>ddraw.def</ModuleDefinitionFile>
<SubSystem>Windows</SubSystem>
<DelayLoadDLLs>shell32.dll;shlwapi.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<LargeAddressAware>true</LargeAddressAware>
Expand Down Expand Up @@ -172,4 +169,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
9 changes: 5 additions & 4 deletions DDraw/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include <windows.h>
#include <stdio.h>
#include <Shlwapi.h>
#include <ShlObj.h>
#include <shlwapi.h>
#include <shlobj.h>
#include "Utils/MemoryMgr.h"
#include "Utils/Patterns.h"
#include "Utils/ScopedUnprotect.hpp"
Expand All @@ -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)
{
Expand Down Expand Up @@ -199,7 +200,7 @@ static bool PatchIAT_ByPointers()
using namespace Memory::VP;

pOrgSystemParametersInfoA = SystemParametersInfoA;
memcpy( orgCode, pOrgSystemParametersInfoA, sizeof(orgCode) );
memcpy( orgCode, reinterpret_cast<void*>(pOrgSystemParametersInfoA), sizeof(orgCode) );
InjectHook( pOrgSystemParametersInfoA, SystemParametersInfoA_OverwritingHook, HookType::Jump );
return true;
}
Expand Down Expand Up @@ -232,4 +233,4 @@ extern "C" __declspec(dllexport)
uint32_t GetBuildNumber()
{
return (SILENTPATCH_REVISION_ID << 8) | SILENTPATCH_BUILD_ID;
}
}
4 changes: 2 additions & 2 deletions SilentPatch/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -379,4 +379,4 @@ namespace Common {
TXN_CATCH();
}
}
}
}
9 changes: 8 additions & 1 deletion SilentPatch/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

#include <cstdint>

// 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);
Expand All @@ -15,4 +22,4 @@ namespace Common
void III_VC_Common();
void III_VC_SetDelayedPatchesFunc( void(*func)() );
}
};
};
10 changes: 4 additions & 6 deletions SilentPatch/Common_ddraw.cpp
Original file line number Diff line number Diff line change
@@ -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 <windows.h>

#include <Shlwapi.h>
#include <ShlObj.h>
#include <shlwapi.h>
#include <shlobj.h>
#include "Utils/MemoryMgr.h"
#include "Utils/Patterns.h"

#pragma comment(lib, "shlwapi.lib")

extern char** ppUserFilesDir;

namespace Common {
char* GetMyDocumentsPath()
{
Expand Down
4 changes: 3 additions & 1 deletion SilentPatch/Common_ddraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <cstdint>

extern char** ppUserFilesDir;

namespace Common
{
namespace Patches
Expand All @@ -18,4 +20,4 @@ namespace Common

void DDraw_Common();
}
};
};
6 changes: 3 additions & 3 deletions SilentPatch/Desktop.cpp
Original file line number Diff line number Diff line change
@@ -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 <windows.h>

std::pair<uint32_t, uint32_t> GetDesktopResolution()
Expand All @@ -21,4 +21,4 @@ std::pair<uint32_t, uint32_t> GetDesktopResolution()
result.second = displaySettings.dmPelsHeight;
}
return result;
}
}
4 changes: 2 additions & 2 deletions SilentPatch/FriendlyMonitorNames.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "FriendlyMonitorNames.h"

// This API is Win7 only, so make sure we use dynamic imports
#define WIN32_LEAN_AND_MEAN

#define NOMINMAX
#define WINVER 0x0602
#define _WIN32_WINNT 0x0602

#include "FriendlyMonitorNames.h"

#include <windows.h>

#include <memory>
Expand Down
11 changes: 10 additions & 1 deletion SilentPatch/Maths.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

#include <rwcore.h>

// 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);

Expand Down Expand Up @@ -570,4 +579,4 @@ class CGeneral
return angle;
}

};
};
7 changes: 4 additions & 3 deletions SilentPatch/ParseUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "ParseUtils.hpp"

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <Windows.h>

#include "ParseUtils.hpp"

#include <windows.h>

static std::string WcharToUTF8(std::wstring_view str)
{
Expand Down
14 changes: 7 additions & 7 deletions SilentPatch/RWGTA.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "Utils/MemoryMgr.h"
#include "Utils/Patterns.h"

#define RwEngineInstance (*rwengine)

#include <rwcore.h>
#include "RWGTA.h"

Expand Down Expand Up @@ -52,6 +50,7 @@ void RwD3D8GetRenderState(RwUInt32 state, void* value)
fnRwD3D8GetRenderState(state, value);
}

#ifndef RwIm2DGetNearScreenZ
RwReal RwIm2DGetNearScreenZ()
{
return RWSRCGLOBAL(dOpenDevice).zBufferNear;
Expand All @@ -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; }
Expand All @@ -78,19 +78,19 @@ bool RWGTA::Patches::TryLocateRwD3D8() try
auto pfnRwD3D8SetRenderState = [] {
try {
// Everything except for III Steam
return static_cast<decltype(RwD3D8SetRenderState)*>(get_pattern("39 0C C5 ? ? ? ? 74 31", -8));
return reinterpret_cast<decltype(RwD3D8SetRenderState)*>(get_pattern("39 0C C5 ? ? ? ? 74 31", -8));
} catch (const hook::txn_exception&) {
// III Steam
return static_cast<decltype(RwD3D8SetRenderState)*>(get_pattern("8B 0C C5 ? ? ? ? 3B CA", -8));
return reinterpret_cast<decltype(RwD3D8SetRenderState)*>(get_pattern("8B 0C C5 ? ? ? ? 3B CA", -8));
}
}();
auto pfnRwD3D8GetRenderState = [] {
try {
// Everything except for III Steam
return static_cast<decltype(RwD3D8GetRenderState)*>(get_pattern("8B 0C C5 ? ? ? ? 89 0A C3", -8));
return reinterpret_cast<decltype(RwD3D8GetRenderState)*>(get_pattern("8B 0C C5 ? ? ? ? 89 0A C3", -8));
} catch (const hook::txn_exception&) {
// III Steam
return static_cast<decltype(RwD3D8GetRenderState)*>(get_pattern("8B 04 C5 ? ? ? ? 89 02 C3", -8));
return reinterpret_cast<decltype(RwD3D8GetRenderState)*>(get_pattern("8B 04 C5 ? ? ? ? 89 02 C3", -8));
}
}();

Expand All @@ -101,4 +101,4 @@ bool RWGTA::Patches::TryLocateRwD3D8() try
catch (const hook::txn_exception&)
{
return false;
}
}
4 changes: 4 additions & 0 deletions SilentPatch/RWGTA.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#define RwEngineInstance (*rwengine)

extern void** rwengine;

namespace RWGTA::Patches
{
bool TryLocateRwD3D8();
Expand Down
6 changes: 5 additions & 1 deletion SilentPatch/RWUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <rwcore.h>
#include <rpworld.h>

#define RwEngineInstance (*rwengine)

extern void** rwengine;

template<RwRenderState State>
class RwScopedRenderState
{
Expand Down Expand Up @@ -68,4 +72,4 @@ Pred RpGeometryForAllMaterials(RpGeometry* geometry, Pred callback)
break;
}
return callback;
}
}
8 changes: 6 additions & 2 deletions SilentPatch/SVF.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include "SVF.h"

#include <cstdint>
#include <algorithm>
#include <map>

#ifndef _MSC_VER
#include <cstring>
#define _stricmp strcasecmp
#endif

namespace SVF
{
Feature GetFeatureFromName( const char* featureName )
Expand Down Expand Up @@ -233,4 +237,4 @@ __declspec(dllexport) void DisableStockVehiclesForSpecialVehicleFeature( const c
SVF::DisableStockVehiclesForFeature( SVF::GetFeatureFromName(featureName) );
}

}
}
3 changes: 2 additions & 1 deletion SilentPatch/SVF.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cstdint>
#include <functional>
#include <string>

Expand Down Expand Up @@ -60,4 +61,4 @@ namespace SVF

void RegisterGetModelInfoCB(void*(*func)(const char*, int*));
void MarkModelNamesReady();
};
};
4 changes: 2 additions & 2 deletions SilentPatch/TheFLAUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "TheFLAUtils.h"

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>

#include "Utils/ModuleList.hpp"

Expand Down Expand Up @@ -39,4 +39,4 @@ bool FLAUtils::UsesEnhancedIMGs()
const auto func = reinterpret_cast<bool(*)()>(GetProcAddress( flaModule, "IsHandlingOfEnhancedIMGarchivesEnabled" ));
if ( func == nullptr ) return false;
return func();
}
}
4 changes: 3 additions & 1 deletion SilentPatch/Timer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef __TIMER
#define __TIMER

#include <cmath>

class CTimer
{
public:
Expand All @@ -16,4 +18,4 @@ class CTimer
static void Update_SilentPatch();
};

#endif
#endif
Loading