Skip to content

Commit b516629

Browse files
committed
cpu check
1 parent 11f36e6 commit b516629

4 files changed

+43
-5
lines changed

atelier-sync-fix.vcxproj

+10-1
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseLowSettings|x64'" Label="Configuration">
3939
<ConfigurationType>DynamicLibrary</ConfigurationType>
4040
<UseDebugLibraries>false</UseDebugLibraries>
41-
<PlatformToolset>v143</PlatformToolset>
41+
<PlatformToolset>ClangCL</PlatformToolset>
4242
<WholeProgramOptimization>true</WholeProgramOptimization>
4343
<CharacterSet>Unicode</CharacterSet>
44+
<LLVMToolsVersion>17</LLVMToolsVersion>
4445
</PropertyGroup>
4546
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
4647
<ImportGroup Label="ExtensionSettings">
48+
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
4749
</ImportGroup>
4850
<ImportGroup Label="Shared">
4951
</ImportGroup>
@@ -100,6 +102,9 @@
100102
<SDLCheck>true</SDLCheck>
101103
<PreprocessorDefinitions>NDEBUG;RELEASELOW;%(PreprocessorDefinitions)</PreprocessorDefinitions>
102104
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
105+
<ExpandAttributedSource>false</ExpandAttributedSource>
106+
<AssemblerOutput>AssemblyCode</AssemblerOutput>
107+
<AdditionalOptions>-Ofast -mavx %(AdditionalOptions)</AdditionalOptions>
103108
</ClCompile>
104109
<Link>
105110
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -130,8 +135,12 @@
130135
</ItemGroup>
131136
<ItemGroup>
132137
<None Include=".gitignore" />
138+
<MASM Include="cpuid.asm">
139+
<FileType>Document</FileType>
140+
</MASM>
133141
</ItemGroup>
134142
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
135143
<ImportGroup Label="ExtensionTargets">
144+
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
136145
</ImportGroup>
137146
</Project>

atelier-sync-fix.vcxproj.filters

+8
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,13 @@
5656
<Filter Include="minhook">
5757
<UniqueIdentifier>{5c578b33-ea9f-4546-ac1b-108deee375d3}</UniqueIdentifier>
5858
</Filter>
59+
<Filter Include="assembly">
60+
<UniqueIdentifier>{22c862f7-39da-4332-9f47-841eef843de3}</UniqueIdentifier>
61+
</Filter>
62+
</ItemGroup>
63+
<ItemGroup>
64+
<MASM Include="cpuid.asm">
65+
<Filter>assembly</Filter>
66+
</MASM>
5967
</ItemGroup>
6068
</Project>

cpuid.asm

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
.code
3+
IsAMD PROC
4+
xor eax, eax
5+
cpuid
6+
cmp ecx, 444d4163h
7+
setz al
8+
ret
9+
10+
IsAMD ENDP
11+
end

impl.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
#include "Shaders/VolumeFog.h"
1515
#include "util.h"
1616

17+
1718
namespace atfix {
1819

20+
extern "C" bool IsAMD();
21+
1922
/** Hooking-related stuff */
2023
using PFN_ID3D11Device_CreateVertexShader = HRESULT(STDMETHODCALLTYPE*) (ID3D11Device*, const void*, SIZE_T, ID3D11ClassLinkage*, ID3D11VertexShader**);
2124
using PFN_ID3D11Device_CreatePixelShader = HRESULT(STDMETHODCALLTYPE*) (ID3D11Device*, const void*, SIZE_T, ID3D11ClassLinkage*, ID3D11PixelShader**);
@@ -56,23 +59,30 @@ HRESULT STDMETHODCALLTYPE ID3D11Device_CreateVertexShader(
5659
static constexpr std::array<uint32_t, 4> DefaultShader = { 0x49d8396e, 0x5b9dfd57, 0xb4f45dba, 0xe6d8b741 };
5760

5861
const uint32_t* hash = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(pShaderBytecode) + 4);
59-
62+
bool AMD = IsAMD();
6063
if (std::equal(ParticleShader1.begin(), ParticleShader1.end(), hash)) {
6164

6265
if (!Particle1B) {
6366
Particle1B = true;
6467
log("Particle found");
6568
}
66-
return procs->CreateVertexShader(pDevice, FIXED_PARTICLE_SHADER1, sizeof(FIXED_PARTICLE_SHADER1), pClassLinkage, ppVertexShader);
69+
if (AMD) {
70+
return procs->CreateVertexShader(pDevice, FIXED_PARTICLE_SHADER1, sizeof(FIXED_PARTICLE_SHADER1), pClassLinkage, ppVertexShader);
71+
} else {
72+
return procs->CreateVertexShader(pDevice, pShaderBytecode, BytecodeLength, pClassLinkage, ppVertexShader);
73+
}
6774

6875
} else if (std::equal(ParticleShader2.begin(), ParticleShader2.end(), hash)) {
6976

7077
if (!Particle2B) {
7178
Particle2B = true;
7279
log("Particle Iterate found");
7380
}
74-
return procs->CreateVertexShader(pDevice, FIXED_PARTICLE_SHADER2, sizeof(FIXED_PARTICLE_SHADER2), pClassLinkage, ppVertexShader);
75-
81+
if (AMD) {
82+
return procs->CreateVertexShader(pDevice, FIXED_PARTICLE_SHADER2, sizeof(FIXED_PARTICLE_SHADER2), pClassLinkage, ppVertexShader);
83+
} else {
84+
return procs->CreateVertexShader(pDevice, pShaderBytecode, BytecodeLength, pClassLinkage, ppVertexShader);
85+
}
7686
}
7787
#ifndef RELEASELOW
7888
else if (std::equal(VolumeFogShader.begin(), VolumeFogShader.end(), hash)) {

0 commit comments

Comments
 (0)