Skip to content

Commit d33fc67

Browse files
committed
Add project files.
1 parent bd1927b commit d33fc67

4 files changed

Lines changed: 304 additions & 0 deletions

File tree

UT3-dx10.cpp

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#include <windows.h>
2+
#include <strsafe.h>
3+
#include <dxgi.h>
4+
5+
constexpr DWORD offsetD3DX10Check = 0xE7BDC5;
6+
constexpr DWORD offsetDenominatorFix = 0xE7CF51;
7+
constexpr DWORD offsetNumeratorSet = 0xE7CF6D;
8+
constexpr BYTE badDenominator[]{ 0xB8, 0x01, 0x00, 0x00, 0x00, 0x89, 0x44, 0x24, 0x6C };
9+
constexpr BYTE badNumerator[] { 0xC7, 0x44, 0x24, 0x6C, 0x3C, 0x00, 0x00, 0x00 };
10+
11+
int WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd )
12+
{
13+
const TCHAR extraArgs[] = TEXT(" -d3d10 -msaa");
14+
TCHAR path[MAX_PATH + ARRAYSIZE( extraArgs ) + 1];
15+
GetCurrentDirectory( MAX_PATH, path );
16+
StringCbCat( path, sizeof( path ), TEXT( "\\UT3.exe" ) );
17+
StringCbCat( path, sizeof( path ), extraArgs );
18+
19+
STARTUPINFOW si{};
20+
si.cb = sizeof( si );
21+
PROCESS_INFORMATION pi{};
22+
if ( !CreateProcess( nullptr, path, nullptr, nullptr, false, CREATE_SUSPENDED, nullptr, nullptr, &si, &pi ) )
23+
return -1;
24+
25+
CONTEXT context{};
26+
context.ContextFlags = CONTEXT_INTEGER;
27+
GetThreadContext( pi.hThread, &context );
28+
29+
PBYTE pBaseAddr = nullptr;
30+
ReadProcessMemory( pi.hProcess, reinterpret_cast<PVOID>( context.Ebx + 8 ), &pBaseAddr, sizeof( pBaseAddr ), nullptr );
31+
32+
// Patch incorrect check for D3DX10CheckVersion
33+
if ( BYTE inst = 0; ReadProcessMemory( pi.hProcess, pBaseAddr + offsetD3DX10Check, &inst, sizeof( inst ), nullptr ) && inst == 0x75 /*jnz*/ )
34+
{
35+
DWORD old;
36+
VirtualProtectEx( pi.hProcess, pBaseAddr + offsetD3DX10Check, sizeof( inst ), PAGE_READWRITE, &old );
37+
inst = 0x74;
38+
WriteProcessMemory( pi.hProcess, pBaseAddr + offsetD3DX10Check, &inst, sizeof( inst ), nullptr );
39+
VirtualProtectEx( pi.hProcess, pBaseAddr + offsetD3DX10Check, sizeof( inst ), old, &old );
40+
}
41+
42+
// Patch hardcoded 60Hz refresh
43+
if ( IDXGIFactory1 *pDxgiFactory; SUCCEEDED( CreateDXGIFactory1( IID_PPV_ARGS( &pDxgiFactory ) ) ) )
44+
{
45+
IDXGIAdapter* adapter;
46+
for ( UINT adapterIdx = 0; SUCCEEDED( pDxgiFactory->EnumAdapters( adapterIdx, &adapter ) ); ++adapterIdx )
47+
{
48+
DXGI_ADAPTER_DESC adesc;
49+
adapter->GetDesc( &adesc );
50+
if ( adesc.VendorId == 0x1414 && adesc.DeviceId == 0x8c ) // skip microsoft basic driver
51+
{
52+
adapter->Release();
53+
continue;
54+
}
55+
56+
IDXGIOutput *output = nullptr;
57+
for ( UINT outputIdx = 0; SUCCEEDED( adapter->EnumOutputs( outputIdx, &output ) ); outputIdx++ )
58+
{
59+
// Get desktop's refresh rate
60+
DXGI_MODE_DESC search {}, monitor {};
61+
search.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
62+
DXGI_OUTPUT_DESC desc;
63+
output->GetDesc( &desc );
64+
search.Width = desc.DesktopCoordinates.right - desc.DesktopCoordinates.left;
65+
search.Height = desc.DesktopCoordinates.bottom - desc.DesktopCoordinates.top;
66+
output->FindClosestMatchingMode( &search, &monitor, nullptr );
67+
output->Release();
68+
69+
// There is not enough space to patch denominator inline, create thunk
70+
if ( BYTE denominator[ARRAYSIZE( badDenominator )]; ReadProcessMemory( pi.hProcess, pBaseAddr + offsetDenominatorFix, denominator, sizeof( denominator ), nullptr ) && !memcmp( denominator, badDenominator, sizeof( denominator ) ) )
71+
{
72+
BYTE fix[]{ 0xB8, 0x01, 0x00, 0x00, 0x00, 0xC7, 0x44, 0x24, 0x70, 0x00, 0x00, 0x00, 0x00, 0xE9, 0x00, 0x00, 0x00, 0x00 };
73+
*reinterpret_cast<UINT *>( fix + 9 ) = monitor.RefreshRate.Denominator;
74+
75+
PVOID addr = VirtualAllocEx( pi.hProcess, nullptr, sizeof( fix ), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
76+
*reinterpret_cast<DWORD *>( fix + 14 ) = reinterpret_cast<DWORD>( pBaseAddr + offsetDenominatorFix + sizeof( denominator ) ) - ( reinterpret_cast<DWORD>( addr ) + sizeof( fix ) );
77+
WriteProcessMemory( pi.hProcess, addr, fix, sizeof( fix ), nullptr );
78+
79+
memset( denominator, 0x90, sizeof( denominator ) );
80+
denominator[0] = 0xE9;
81+
*reinterpret_cast<DWORD *>( denominator + 1 ) = reinterpret_cast<DWORD>( addr ) - reinterpret_cast<DWORD>( pBaseAddr + offsetDenominatorFix + 5 );
82+
DWORD old, old2;
83+
VirtualProtectEx( pi.hProcess, pBaseAddr + offsetDenominatorFix, sizeof( denominator ), PAGE_READWRITE, &old );
84+
WriteProcessMemory( pi.hProcess, pBaseAddr + offsetDenominatorFix, denominator, sizeof( denominator ), nullptr );
85+
VirtualProtectEx( pi.hProcess, pBaseAddr + offsetDenominatorFix, sizeof( denominator ), old, &old2 );
86+
87+
VirtualProtectEx( pi.hProcess, addr, sizeof( fix ), old, &old2 );
88+
}
89+
90+
BYTE numerator[ARRAYSIZE( badNumerator )];
91+
ReadProcessMemory( pi.hProcess, pBaseAddr + offsetNumeratorSet, numerator, sizeof( numerator ), nullptr );
92+
if ( !memcmp( numerator, badNumerator, sizeof( numerator ) ) )
93+
{
94+
*reinterpret_cast<UINT *>( numerator + 4 ) = monitor.RefreshRate.Numerator;
95+
96+
DWORD old;
97+
VirtualProtectEx( pi.hProcess, pBaseAddr + offsetNumeratorSet, sizeof( numerator ), PAGE_READWRITE, &old );
98+
WriteProcessMemory( pi.hProcess, pBaseAddr + offsetNumeratorSet, numerator, sizeof( numerator ), nullptr );
99+
VirtualProtectEx( pi.hProcess, pBaseAddr + offsetNumeratorSet, sizeof( numerator ), old, &old );
100+
}
101+
102+
break; // Grab info from first display only
103+
}
104+
105+
adapter->Release();
106+
break; // UT3 uses first adapter returned from DXGI
107+
}
108+
109+
pDxgiFactory->Release();
110+
}
111+
112+
ResumeThread( pi.hThread );
113+
CloseHandle( pi.hProcess );
114+
CloseHandle( pi.hThread );
115+
return 0;
116+
}

UT3-dx10.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.12.35309.182
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UT3-dx10", "UT3-dx10.vcxproj", "{C1878BAA-525B-4C10-AD8D-49A8095CCB59}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|x86 = Debug|x86
10+
Release|x86 = Release|x86
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{C1878BAA-525B-4C10-AD8D-49A8095CCB59}.Debug|x86.ActiveCfg = Debug|Win32
14+
{C1878BAA-525B-4C10-AD8D-49A8095CCB59}.Debug|x86.Build.0 = Debug|Win32
15+
{C1878BAA-525B-4C10-AD8D-49A8095CCB59}.Release|x86.ActiveCfg = Release|Win32
16+
{C1878BAA-525B-4C10-AD8D-49A8095CCB59}.Release|x86.Build.0 = Release|Win32
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {A0F17A99-2641-4B43-A88D-2EF131C7F21C}
23+
EndGlobalSection
24+
EndGlobal

UT3-dx10.vcxproj

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>17.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{c1878baa-525b-4c10-ad8d-49a8095ccb59}</ProjectGuid>
25+
<RootNamespace>UT3dx10</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<SDLCheck>true</SDLCheck>
77+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
78+
<ConformanceMode>true</ConformanceMode>
79+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
80+
<LanguageStandard>stdcpp17</LanguageStandard>
81+
</ClCompile>
82+
<Link>
83+
<SubSystem>Windows</SubSystem>
84+
<GenerateDebugInformation>true</GenerateDebugInformation>
85+
<AdditionalDependencies>dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
86+
</Link>
87+
</ItemDefinitionGroup>
88+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
89+
<ClCompile>
90+
<WarningLevel>Level3</WarningLevel>
91+
<FunctionLevelLinking>true</FunctionLevelLinking>
92+
<IntrinsicFunctions>true</IntrinsicFunctions>
93+
<SDLCheck>true</SDLCheck>
94+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
95+
<ConformanceMode>true</ConformanceMode>
96+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
97+
<LanguageStandard>stdcpp17</LanguageStandard>
98+
<DebugInformationFormat>None</DebugInformationFormat>
99+
</ClCompile>
100+
<Link>
101+
<SubSystem>Windows</SubSystem>
102+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
103+
<OptimizeReferences>true</OptimizeReferences>
104+
<GenerateDebugInformation>false</GenerateDebugInformation>
105+
<AdditionalDependencies>dxgi.lib;%(AdditionalDependencies)</AdditionalDependencies>
106+
</Link>
107+
</ItemDefinitionGroup>
108+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
109+
<ClCompile>
110+
<WarningLevel>Level3</WarningLevel>
111+
<SDLCheck>true</SDLCheck>
112+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
113+
<ConformanceMode>true</ConformanceMode>
114+
</ClCompile>
115+
<Link>
116+
<SubSystem>Console</SubSystem>
117+
<GenerateDebugInformation>true</GenerateDebugInformation>
118+
</Link>
119+
</ItemDefinitionGroup>
120+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
121+
<ClCompile>
122+
<WarningLevel>Level3</WarningLevel>
123+
<FunctionLevelLinking>true</FunctionLevelLinking>
124+
<IntrinsicFunctions>true</IntrinsicFunctions>
125+
<SDLCheck>true</SDLCheck>
126+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
127+
<ConformanceMode>true</ConformanceMode>
128+
</ClCompile>
129+
<Link>
130+
<SubSystem>Console</SubSystem>
131+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
132+
<OptimizeReferences>true</OptimizeReferences>
133+
<GenerateDebugInformation>true</GenerateDebugInformation>
134+
</Link>
135+
</ItemDefinitionGroup>
136+
<ItemGroup>
137+
<ClCompile Include="UT3-dx10.cpp" />
138+
</ItemGroup>
139+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
140+
<ImportGroup Label="ExtensionTargets">
141+
</ImportGroup>
142+
</Project>

UT3-dx10.vcxproj.filters

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="UT3-dx10.cpp">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>

0 commit comments

Comments
 (0)