diff --git a/BinaryDecompiler/internal_includes/reflect.h b/BinaryDecompiler/internal_includes/reflect.h index 54238de8e..192b7291f 100644 --- a/BinaryDecompiler/internal_includes/reflect.h +++ b/BinaryDecompiler/internal_includes/reflect.h @@ -1,7 +1,7 @@ #ifndef REFLECT_H #define REFLECT_H -#include "hlslcc.h" +#include "../include/hlslcc.h" ResourceGroup ResourceTypeToResourceGroup(ResourceType); diff --git a/BinaryDecompiler/internal_includes/structs.h b/BinaryDecompiler/internal_includes/structs.h index a56486130..19403ca67 100644 --- a/BinaryDecompiler/internal_includes/structs.h +++ b/BinaryDecompiler/internal_includes/structs.h @@ -3,10 +3,10 @@ #include #include #include -#include "hlslcc.h" +#include "../include/hlslcc.h" -#include "internal_includes/tokens.h" -#include "internal_includes/reflect.h" +#include "tokens.h" +#include "reflect.h" enum{ MAX_SUB_OPERANDS = 3}; diff --git a/BinaryDecompiler/internal_includes/tokens.h b/BinaryDecompiler/internal_includes/tokens.h index 34ca6471a..dfe59b837 100644 --- a/BinaryDecompiler/internal_includes/tokens.h +++ b/BinaryDecompiler/internal_includes/tokens.h @@ -1,7 +1,7 @@ #ifndef TOKENS_H #define TOKENS_H -#include "hlslcc.h" +#include "../include/hlslcc.h" typedef enum { diff --git a/D3DCompiler/d3dcWrapper.cpp b/D3DCompiler/d3dcWrapper.cpp index 4c2d08bd0..73b8af8c9 100644 --- a/D3DCompiler/d3dcWrapper.cpp +++ b/D3DCompiler/d3dcWrapper.cpp @@ -4,7 +4,7 @@ #include #include -#include "util.h" +#include "../util.h" #define COMPILER_DLL_VERSION "46" #define COMPILER_DLL_VERSIONL L"46" diff --git a/D3D_Shaders/D3D_Shaders.vcxproj b/D3D_Shaders/D3D_Shaders.vcxproj index ee7b7eb04..6b00f9c18 100644 --- a/D3D_Shaders/D3D_Shaders.vcxproj +++ b/D3D_Shaders/D3D_Shaders.vcxproj @@ -57,40 +57,34 @@ - + - + true - $(SolutionDir);$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(VC_IncludePath);$(WindowsSDK_IncludePath); - $(OutDir);$(LibraryPath) + $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86);$(DXSDK_DIR)Lib\x86 true - $(SolutionDir);$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(VC_IncludePath);$(WindowsSDK_IncludePath); - $(OutDir);$(LibraryPath) + $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64);$(DXSDK_DIR)Lib\x64 false - $(SolutionDir);$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(VC_IncludePath);$(WindowsSDK_IncludePath) - $(OutDir);$(LibraryPath) + $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86);$(DXSDK_DIR)Lib\x86 false - $(SolutionDir);$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(VC_IncludePath);$(WindowsSDK_IncludePath); - $(OutDir);$(LibraryPath) + $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64);$(DXSDK_DIR)Lib\x64 - - Level3 Disabled WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) @@ -99,31 +93,25 @@ Console true - D3dcompiler.lib;%(AdditionalDependencies) - $(OutDir)$(TargetName)$(TargetExt) + d3dcompiler.lib;d3dx9.lib;%(AdditionalDependencies) - - Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + _DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) MultiThreadedDebug Console true - D3dcompiler.lib;%(AdditionalDependencies) - $(OutDir)D3D_Shaders.exe + d3dcompiler.lib;d3dx9.lib;%(AdditionalDependencies) Level3 - - MaxSpeed true true @@ -135,23 +123,16 @@ true true true - D3dcompiler.lib;%(AdditionalDependencies) - - - - - $(OutDir)$(TargetName)$(TargetExt) + d3dcompiler.lib;d3dx9.lib;%(AdditionalDependencies) Level3 - - MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) MultiThreaded @@ -159,12 +140,7 @@ true true true - D3dcompiler.lib;%(AdditionalDependencies) - - - - - $(OutDir)$(TargetName)$(TargetExt) + d3dcompiler.lib;d3dx9.lib;%(AdditionalDependencies) @@ -172,9 +148,12 @@ - - + + + + {00b6ba42-4050-488d-91be-a8cd7adaeb87} + diff --git a/D3D_Shaders/D3D_Shaders.vcxproj.filters b/D3D_Shaders/D3D_Shaders.vcxproj.filters index e7d7ea8de..54a20591f 100644 --- a/D3D_Shaders/D3D_Shaders.vcxproj.filters +++ b/D3D_Shaders/D3D_Shaders.vcxproj.filters @@ -9,10 +9,6 @@ {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hh;hpp;hxx;hm;inl;inc;xsd - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - @@ -26,11 +22,5 @@ Source Files - - Source Files - - - Source Files - \ No newline at end of file diff --git a/D3D_Shaders/Shaders.cpp b/D3D_Shaders/Shaders.cpp index 6f773c555..c375be16f 100644 --- a/D3D_Shaders/Shaders.cpp +++ b/D3D_Shaders/Shaders.cpp @@ -7,6 +7,8 @@ #include #include #include +#include "D3DCompiler.h" +#include "..\HLSLDecompiler\Assembler.h" using namespace std; @@ -49,6 +51,46 @@ static vector readFile(string fileName) { return buffer; } +void writeLUT(const unordered_map>& codeBin) +{ + FILE* f; + + fopen_s(&f, "lut.asm", "wb"); + if (!f) + return; + + for (auto it = codeBin.begin(); it != codeBin.end(); ++it) { + fputs(it->first.c_str(), f); + fputs(":->", f); + vector b = it->second; + int nextOperand = 1; + for (DWORD i = 0; i < b.size(); i++) { + if (i == 0) { + char hex[40]; + shader_ins* ins = (shader_ins*)&b[0]; + if (ins->_11_23 > 0) { + if (ins->extended) + sprintf_s(hex, "0x%08X: %d,%d,%d<>%d->", b[0], ins->opcode, ins->_11_23, ins->length, ins->extended); + else + sprintf_s(hex, "0x%08X: %d,%d,%d->", b[0], ins->opcode, ins->_11_23, ins->length); + } else { + if (ins->extended) + sprintf_s(hex, "0x%08X: %d,%d<>%d->", b[0], ins->opcode, ins->length, ins->extended); + else + sprintf_s(hex, "0x%08X: %d,%d->", b[0], ins->opcode, ins->length); + } + fputs(hex, f); + } else { + char hex[20]; + sprintf_s(hex, " 0x%08X", b[i]); + fputs(hex, f); + } + } + fputs("\n", f); + } + fclose(f); +} + int _tmain(int argc, _TCHAR* argv[]) { int shaderNo = 1; @@ -56,6 +98,7 @@ int _tmain(int argc, _TCHAR* argv[]) string pathName; vector files; FILE* f; + unordered_map> codeBin; char cwd[MAX_PATH]; char gamebuffer[10000]; @@ -90,7 +133,7 @@ int _tmain(int argc, _TCHAR* argv[]) string fileName = files[i]; vector ASM; - disassembler(&readFile(fileName), &ASM, NULL); + disassembler(&readFile(fileName), &ASM, NULL, codeBin); fileName.erase(fileName.size() - 3, 3); fileName.append("txt"); @@ -152,7 +195,7 @@ int _tmain(int argc, _TCHAR* argv[]) string fileName = files[i]; vector ASM; - disassembler(&readFile(fileName), &ASM, NULL); + disassembler(&readFile(fileName), &ASM, NULL, codeBin); fileName.erase(fileName.size() - 3, 3); fileName.append("txt"); @@ -172,7 +215,7 @@ int _tmain(int argc, _TCHAR* argv[]) } cout << endl; - writeLUT(); + writeLUT(codeBin); } return 0; } diff --git a/D3D_Shaders/stdafx.h b/D3D_Shaders/stdafx.h index 736138241..c7dffcfb1 100644 --- a/D3D_Shaders/stdafx.h +++ b/D3D_Shaders/stdafx.h @@ -7,90 +7,4 @@ #include "targetver.h" -#include -#include -#include "stdint.h" -#include "D3DCompiler.h" -#include -#include -#include - using namespace std; - -// VS2013 BUG WORKAROUND: Make sure this class has a unique type name! -class AssemblerParseError: public exception { -public: - string context, desc, msg; - int line_no; - - AssemblerParseError(string context, string desc) : - context(context), - desc(desc), - line_no(0) - { - update_msg(); - } - - void update_msg() - { - msg = "Assembly parse error"; - if (line_no > 0) - msg += string(" on line ") + to_string(line_no); - msg += ", " + desc + ":\n\"" + context + "\""; - } - - const char* what() const - { - return msg.c_str(); - } -}; - -struct shader_ins -{ - union { - struct { - // XXX Beware that bitfield packing is not defined in - // the C/C++ standards and this is relying on compiler - // specific packing. This approach is not recommended. - - unsigned opcode : 11; - unsigned _11_23 : 13; - unsigned length : 7; - unsigned extended : 1; - }; - DWORD op; - }; -}; -struct token_operand -{ - union { - struct { - // XXX Beware that bitfield packing is not defined in - // the C/C++ standards and this is relying on compiler - // specific packing. This approach is not recommended. - - unsigned comps_enum : 2; /* sm4_operands_comps */ - unsigned mode : 2; /* sm4_operand_mode */ - unsigned sel : 8; - unsigned file : 8; /* SM_FILE */ - unsigned num_indices : 2; - unsigned index0_repr : 3; /* sm4_operand_index_repr */ - unsigned index1_repr : 3; /* sm4_operand_index_repr */ - unsigned index2_repr : 3; /* sm4_operand_index_repr */ - unsigned extended : 1; - }; - DWORD op; - }; -}; - -vector stringToLines(const char* start, size_t size); -HRESULT disassembler(vector *buffer, vector *ret, const char *comment, - int hexdump = 0, bool d3dcompiler_46_compat = false, - bool disassemble_undecipherable_data = false, - bool patch_cb_offsets = false); -HRESULT disassemblerDX9(vector *buffer, vector *ret, const char *comment); -vector assembler(vector *asmFile, vector origBytecode, vector *parse_errors = NULL); -vector assemblerDX9(vector *asmFile); -void writeLUT(); -HRESULT AssembleFluganWithSignatureParsing(vector *assembly, vector *result_bytecode, vector *parse_errors = NULL); -vector AssembleFluganWithOptionalSignatureParsing(vector *assembly, bool assemble_signatures, vector *orig_bytecode, vector *parse_errors = NULL); diff --git a/DirectX10/DirectX10.vcxproj b/DirectX10/DirectX10.vcxproj index d6eff28b8..66ff1ea26 100644 --- a/DirectX10/DirectX10.vcxproj +++ b/DirectX10/DirectX10.vcxproj @@ -27,7 +27,6 @@ - @@ -38,7 +37,6 @@ - @@ -55,6 +53,9 @@ {258d0ad2-b762-41e3-a0c1-cf831d859da4} + + {00b6ba42-4050-488d-91be-a8cd7adaeb87} + {C9205DC6-7CE4-4939-9EFC-FE61483CCE01} @@ -281,4 +282,4 @@ - + \ No newline at end of file diff --git a/DirectX10/DirectX10.vcxproj.filters b/DirectX10/DirectX10.vcxproj.filters index b3df35af9..509b992cd 100644 --- a/DirectX10/DirectX10.vcxproj.filters +++ b/DirectX10/DirectX10.vcxproj.filters @@ -2,7 +2,6 @@ - @@ -17,7 +16,6 @@ - diff --git a/DirectX11/DirectX11.vcxproj b/DirectX11/DirectX11.vcxproj index 15286d920..aac099f42 100644 --- a/DirectX11/DirectX11.vcxproj +++ b/DirectX11/DirectX11.vcxproj @@ -30,22 +30,22 @@ {258d0ad2-b762-41e3-a0c1-cf831d859da4} - - {59a9b0c6-8302-48a9-96e0-126fb32fb9ed} + + {d05da837-8c74-40e0-8255-1345ca449648} {e0b52ae7-e160-4d32-bf3f-910b785e5a8e} + + {00b6ba42-4050-488d-91be-a8cd7adaeb87} + false + - - - - - + @@ -72,12 +72,6 @@ - - - - - - @@ -100,7 +94,6 @@ - @@ -177,48 +170,42 @@ false d3d11 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) - $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86) + $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86);$(DXSDK_DIR)Lib\x86 $(SolutionDir)x32\$(Configuration)\ $(ProjectDir)x32\$(Configuration)\ false d3d11 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) - $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64) + $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64);$(DXSDK_DIR)Lib\x64 $(SolutionDir)x64\$(Configuration)\ $(ProjectDir)x64\$(Configuration)\ false d3d11 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) - $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86) + $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86);$(DXSDK_DIR)Lib\x86 $(SolutionDir)x32\$(Configuration)\ $(ProjectDir)x32\$(Configuration)\ false d3d11 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) - $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64) + $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64);$(DXSDK_DIR)Lib\x64 $(SolutionDir)x64\$(Configuration)\ $(ProjectDir)x64\$(Configuration)\ false d3d11 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) - $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86) + $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86);$(DXSDK_DIR)Lib\x86 $(SolutionDir)x32\$(Configuration)\ $(ProjectDir)x32\$(Configuration)\ false d3d11 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) - $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64) + $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64);$(DXSDK_DIR)Lib\x64 $(SolutionDir)x64\$(Configuration)\ $(ProjectDir)x64\$(Configuration)\ @@ -238,7 +225,7 @@ Windows true d3d11Wrapper.def - ..\Nektra\NktHookLib_Debug.lib;..\pcre2\pcre2-8-32d.lib;$(OutDir)nvapi.lib;..\nvapi.lib;XINPUT9_1_0.lib;d3dcompiler.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;%(AdditionalDependencies) + ..\Nektra\NktHookLib_Debug.lib;..\pcre2\pcre2-8-32d.lib;$(OutDir)nvapi.lib;..\nvapi.lib;XINPUT9_1_0.lib;d3dcompiler.lib;d3dx9.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;%(AdditionalDependencies) _CreateDXGIFactory@8 @@ -264,7 +251,7 @@ call "$(SolutionDir)CopyToGames.bat" "$(TargetDir)" "$(TargetedSDKArchitecture)" Windows true d3d11Wrapper.def - ..\Nektra\NktHookLib64_Debug.lib;..\pcre2\pcre2-8-64d.lib;$(OutDir)nvapi64.lib;..\nvapi64.lib;XINPUT9_1_0.lib;d3dcompiler.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;%(AdditionalDependencies) + ..\Nektra\NktHookLib64_Debug.lib;..\pcre2\pcre2-8-64d.lib;$(OutDir)nvapi64.lib;..\nvapi64.lib;XINPUT9_1_0.lib;d3dcompiler.lib;d3dx9.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;%(AdditionalDependencies) CreateDXGIFactory @@ -295,7 +282,7 @@ call "$(SolutionDir)CopyToGames.bat" "$(TargetDir)" "$(TargetedSDKArchitecture)" true true d3d11Wrapper.def - ..\Nektra\NktHookLib.lib;..\pcre2\pcre2-8-32.lib;$(OutDir)nvapi.lib;..\nvapi.lib;XINPUT9_1_0.lib;d3dcompiler.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;%(AdditionalDependencies) + ..\Nektra\NktHookLib.lib;..\pcre2\pcre2-8-32.lib;$(OutDir)nvapi.lib;..\nvapi.lib;XINPUT9_1_0.lib;d3dcompiler.lib;d3dx9.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;%(AdditionalDependencies) _CreateDXGIFactory@8 @@ -328,7 +315,7 @@ call "$(SolutionDir)CopyToGames.bat" "$(TargetDir)" "$(TargetedSDKArchitecture)" true true d3d11Wrapper.def - ..\Nektra\NktHookLib.lib;..\pcre2\pcre2-8-32.lib;$(OutDir)nvapi.lib;..\nvapi.lib;XINPUT9_1_0.lib;d3dcompiler.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;%(AdditionalDependencies) + ..\Nektra\NktHookLib.lib;..\pcre2\pcre2-8-32.lib;$(OutDir)nvapi.lib;..\nvapi.lib;XINPUT9_1_0.lib;d3dcompiler.lib;d3dx9.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;%(AdditionalDependencies) _CreateDXGIFactory@8 @@ -359,7 +346,7 @@ xcopy "$(SolutionDir)Dependencies\*.*" "$(TargetDir)" /E /Y /s true true d3d11Wrapper.def - ..\Nektra\NktHookLib64.lib;..\pcre2\pcre2-8-64.lib;$(OutDir)nvapi64.lib;..\nvapi64.lib;XINPUT9_1_0.lib;d3dcompiler.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;%(AdditionalDependencies) + ..\Nektra\NktHookLib64.lib;..\pcre2\pcre2-8-64.lib;$(OutDir)nvapi64.lib;..\nvapi64.lib;XINPUT9_1_0.lib;d3dcompiler.lib;d3dx9.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;%(AdditionalDependencies) CreateDXGIFactory @@ -390,7 +377,7 @@ call "$(SolutionDir)CopyToGames.bat" "$(TargetDir)" "$(TargetedSDKArchitecture)" true true d3d11Wrapper.def - ..\Nektra\NktHookLib64.lib;..\pcre2\pcre2-8-64.lib;$(OutDir)nvapi64.lib;..\nvapi64.lib;XINPUT9_1_0.lib;d3dcompiler.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;Dbghelp.lib;%(AdditionalDependencies) + ..\Nektra\NktHookLib64.lib;..\pcre2\pcre2-8-64.lib;$(OutDir)nvapi64.lib;..\nvapi64.lib;XINPUT9_1_0.lib;d3dcompiler.lib;d3dx9.lib;DXGI.lib;Shlwapi.lib;Dbghelp.lib;Dbghelp.lib;%(AdditionalDependencies) CreateDXGIFactory @@ -403,4 +390,4 @@ xcopy "$(SolutionDir)Dependencies\*.*" "$(TargetDir)" /E /Y /s - + \ No newline at end of file diff --git a/DirectX11/DirectX11.vcxproj.filters b/DirectX11/DirectX11.vcxproj.filters index d19c836fd..9981df731 100644 --- a/DirectX11/DirectX11.vcxproj.filters +++ b/DirectX11/DirectX11.vcxproj.filters @@ -1,71 +1,160 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + - + + + {889aa926-57af-41da-97e0-b14b6d5129ea} + + + {61c044e9-2cf3-4560-bc82-ecb8d10c2911} + + + \ No newline at end of file diff --git a/DirectX11/HackerContext.cpp b/DirectX11/HackerContext.cpp index a0a8d701b..acea7a93b 100644 --- a/DirectX11/HackerContext.cpp +++ b/DirectX11/HackerContext.cpp @@ -24,6 +24,9 @@ #include "ShaderRegex.h" #include "FrameAnalysis.h" #include "profiling.h" +#include "Assembler.h" +#include "SignatureParser.h" + // ----------------------------------------------------------------------------------------------- diff --git a/DirectX11/HackerDevice.cpp b/DirectX11/HackerDevice.cpp index 3b38e6d0f..b62f9be5b 100644 --- a/DirectX11/HackerDevice.cpp +++ b/DirectX11/HackerDevice.cpp @@ -24,12 +24,12 @@ #include "util.h" #include "shader.h" #include "DecompileHLSL.h" +#include "SignatureParser.h" #include "HackerContext.h" #include "HackerDXGI.h" #include "D3D11Wrapper.h" #include "SpriteFont.h" -#include "D3D_Shaders\stdafx.h" #include "ResourceHash.h" #include "ShaderRegex.h" #include "CommandList.h" diff --git a/DirectX11/Hunting.cpp b/DirectX11/Hunting.cpp index b1c7861db..2fb340c94 100644 --- a/DirectX11/Hunting.cpp +++ b/DirectX11/Hunting.cpp @@ -11,11 +11,11 @@ #include "D3D11Wrapper.h" #include "util.h" #include "DecompileHLSL.h" +#include "SignatureParser.h" #include "Input.h" #include "Override.h" #include "Globals.h" #include "IniHandler.h" -#include "D3D_Shaders\stdafx.h" #include "CommandList.h" #include "profiling.h" #include "FrameAnalysis.h" diff --git a/DirectX11/ResourceHash.h b/DirectX11/ResourceHash.h index 331b8c172..4fc8267a2 100644 --- a/DirectX11/ResourceHash.h +++ b/DirectX11/ResourceHash.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include diff --git a/DirectX9/Direct3DDevice9Functions.h b/DirectX9/Direct3DDevice9Functions.h index e1845257e..e38bdbe39 100644 --- a/DirectX9/Direct3DDevice9Functions.h +++ b/DirectX9/Direct3DDevice9Functions.h @@ -1,11 +1,13 @@ #include -#include "../HLSLDecompiler/DecompileHLSL.h" #include +#include + +#include "Assembler.h" +#include "DecompileHLSL.h" #include "shader.h" #include "ShaderRegex.h" #include "HookedDeviceDX9.h" #include "d3d9Wrapper.h" -#include #define D3D_COMPILE_STANDARD_FILE_INCLUDE ((ID3DInclude*)(UINT_PTR)1) inline void D3D9Wrapper::IDirect3DDevice9::Delete() diff --git a/DirectX9/DirectX9.vcxproj b/DirectX9/DirectX9.vcxproj index 60bd9ea97..ce3bd4fd2 100644 --- a/DirectX9/DirectX9.vcxproj +++ b/DirectX9/DirectX9.vcxproj @@ -30,15 +30,14 @@ {258d0ad2-b762-41e3-a0c1-cf831d859da4} - - {59a9b0c6-8302-48a9-96e0-126fb32fb9ed} + + {d05da837-8c74-40e0-8255-1345ca449648} + + + {00b6ba42-4050-488d-91be-a8cd7adaeb87} - - - - @@ -76,8 +75,6 @@ - - @@ -136,7 +133,7 @@ - + @@ -213,7 +210,6 @@ true d3d9 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(LibraryPath) $(SolutionDir)x32\$(Configuration)\ $(ProjectDir)x32\$(Configuration)\ @@ -221,7 +217,6 @@ true d3d9 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(LibraryPath) $(SolutionDir)x64\$(Configuration)\ $(ProjectDir)x64\$(Configuration)\ @@ -229,7 +224,6 @@ false d3d9 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(LibraryPath) $(SolutionDir)x32\$(Configuration)\ $(ProjectDir)x32\$(Configuration)\ @@ -237,7 +231,6 @@ false d3d9 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(LibraryPath) $(SolutionDir)x64\$(Configuration)\ $(ProjectDir)x64\$(Configuration)\ @@ -245,7 +238,6 @@ false d3d9 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(LibraryPath) $(SolutionDir)x32\$(Configuration)\ $(ProjectDir)x32\$(Configuration)\ @@ -253,7 +245,6 @@ false d3d9 - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(LibraryPath) $(SolutionDir)x64\$(Configuration)\ $(ProjectDir)x64\$(Configuration)\ @@ -411,4 +402,4 @@ - + \ No newline at end of file diff --git a/DirectX9/DirectX9.vcxproj.filters b/DirectX9/DirectX9.vcxproj.filters index 03c5b465a..bca7781fd 100644 --- a/DirectX9/DirectX9.vcxproj.filters +++ b/DirectX9/DirectX9.vcxproj.filters @@ -1,105 +1,281 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + @@ -107,4 +283,12 @@ - + + + {105e2fb3-760d-44d1-8788-b17c89dc20c8} + + + {36c84501-e960-4ec8-9f5d-01b0705626e4} + + + \ No newline at end of file diff --git a/DirectX9/Hunting.cpp b/DirectX9/Hunting.cpp index e13e6e696..abb556615 100644 --- a/DirectX9/Hunting.cpp +++ b/DirectX9/Hunting.cpp @@ -7,7 +7,7 @@ #include "DecompileHLSL.h" #include "Override.h" #include "IniHandler.h" -#include "D3D_Shaders\stdafx.h" +#include "Assembler.h" #include "ConstantsTable.h" #define D3D_COMPILE_STANDARD_FILE_INCLUDE ((ID3DInclude*)(UINT_PTR)1) diff --git a/DirectX9/ResourceHash.h b/DirectX9/ResourceHash.h index 270f87664..39d536abb 100644 --- a/DirectX9/ResourceHash.h +++ b/DirectX9/ResourceHash.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/DirectXGI/DXGIWrapper.cpp b/DirectXGI/DXGIWrapper.cpp index 4428f144b..233b605b6 100644 --- a/DirectXGI/DXGIWrapper.cpp +++ b/DirectXGI/DXGIWrapper.cpp @@ -31,7 +31,7 @@ #include "DXGIWrapper.h" //#include "HackerDXGI.h" -#include "log.h" +#include "..\log.h" bool gLogDebug = false; diff --git a/DirectXGI/DirectXGI.vcxproj b/DirectXGI/DirectXGI.vcxproj index 2e02741b1..fe35905fb 100644 --- a/DirectXGI/DirectXGI.vcxproj +++ b/DirectXGI/DirectXGI.vcxproj @@ -33,8 +33,6 @@ - - diff --git a/DirectXGI/DirectXGI.vcxproj.filters b/DirectXGI/DirectXGI.vcxproj.filters index dee83745b..debe679ef 100644 --- a/DirectXGI/DirectXGI.vcxproj.filters +++ b/DirectXGI/DirectXGI.vcxproj.filters @@ -8,7 +8,5 @@ - - \ No newline at end of file diff --git a/D3D_Shaders/Assembler.cpp b/HLSLDecompiler/Assembler.cpp similarity index 93% rename from D3D_Shaders/Assembler.cpp rename to HLSLDecompiler/Assembler.cpp index 0d1724e42..4d83cb782 100644 --- a/D3D_Shaders/Assembler.cpp +++ b/HLSLDecompiler/Assembler.cpp @@ -1,6 +1,11 @@ -#include "stdafx.h" -#include "float.h" #include +#include + +#include "Assembler.h" +#include "D3Dcompiler.h" +#include "float.h" +#include "..\log.h" +#include "..\util.h" using namespace std; @@ -12,7 +17,48 @@ using namespace std; // for sscanf_s convinience. Explanation in DecompileHLSL.cpp #define UCOUNTOF(...) (unsigned)_countof(__VA_ARGS__) -static unordered_map> codeBin; +struct token_operand +{ + union { + struct { + // XXX Beware that bitfield packing is not defined in + // the C/C++ standards and this is relying on compiler + // specific packing. This approach is not recommended. + + unsigned comps_enum : 2; /* sm4_operands_comps */ + unsigned mode : 2; /* sm4_operand_mode */ + unsigned sel : 8; + unsigned file : 8; /* SM_FILE */ + unsigned num_indices : 2; + unsigned index0_repr : 3; /* sm4_operand_index_repr */ + unsigned index1_repr : 3; /* sm4_operand_index_repr */ + unsigned index2_repr : 3; /* sm4_operand_index_repr */ + unsigned extended : 1; + }; + DWORD op; + }; +}; + +inline AssemblerParseError::AssemblerParseError(string context, string desc) : + context(context), + desc(desc), + line_no(0) +{ + update_msg(); +} + +inline void AssemblerParseError::update_msg() +{ + msg = "Assembly parse error"; + if (line_no > 0) + msg += string(" on line ") + to_string(line_no); + msg += ", " + desc + ":\n\"" + context + "\""; +} + +inline const char* AssemblerParseError::what() const +{ + return msg.c_str(); +} static DWORD strToDWORD(string s) { @@ -173,46 +219,6 @@ static string convertD(DWORD v1, DWORD v2) return buf; } -void writeLUT() -{ - FILE* f; - - fopen_s(&f, "lut.asm", "wb"); - if (!f) - return; - - for (unordered_map>::iterator it = codeBin.begin(); it != codeBin.end(); ++it) { - fputs(it->first.c_str(), f); - fputs(":->", f); - vector b = it->second; - int nextOperand = 1; - for (DWORD i = 0; i < b.size(); i++) { - if (i == 0) { - char hex[40]; - shader_ins* ins = (shader_ins*)&b[0]; - if (ins->_11_23 > 0) { - if (ins->extended) - sprintf_s(hex, "0x%08X: %d,%d,%d<>%d->", b[0], ins->opcode, ins->_11_23, ins->length, ins->extended); - else - sprintf_s(hex, "0x%08X: %d,%d,%d->", b[0], ins->opcode, ins->_11_23, ins->length); - } else { - if (ins->extended) - sprintf_s(hex, "0x%08X: %d,%d<>%d->", b[0], ins->opcode, ins->length, ins->extended); - else - sprintf_s(hex, "0x%08X: %d,%d->", b[0], ins->opcode, ins->length); - } - fputs(hex, f); - } else { - char hex[20]; - sprintf_s(hex, " 0x%08X", b[i]); - fputs(hex, f); - } - } - fputs("\n", f); - } - fclose(f); -} - static void handleSwizzle(string s, token_operand* tOp, bool special = false) { if (special == true) { @@ -304,7 +310,7 @@ struct special_purpose_register // may interact with this, but this is at least passing all test cases. unsigned comps_enum; - char* name; + const char* name; }; static struct special_purpose_register special_purpose_registers[] = { @@ -1451,7 +1457,7 @@ static vector assemble_printf(string& s, vector& v, vector return v; } -static vector assemble_undecipherable_custom_data(string& s, vector& v, vector& w) +const vector assemble_undecipherable_custom_data(string& s, vector& v, vector& w) { uint32_t numOps, word, i; @@ -1473,7 +1479,7 @@ static vector assemble_undecipherable_custom_data(string& s, vector& assembleIns(string s) +static vector assembleIns(string s) { unsigned msaa_samples = 0; @@ -2278,7 +2284,7 @@ static vector& assembleIns(string s) return v; } -static string assembleAndCompare(string s, vector v) +static string assembleAndCompare(string s, vector v, unordered_map>& codeBin) { string s2; int numSpaces = 0; @@ -2800,7 +2806,7 @@ static inline void replace_cb_offsets_with_indices(string* line) *line += suffix; } -HRESULT disassembler(vector* buffer, vector* ret, const char* comment, +HRESULT disassembler(vector* buffer, vector* ret, const char* comment, unordered_map>& codeBin, int hexdump, bool d3dcompiler_46_compat, bool disassemble_undecipherable_data, bool patch_cb_offsets) @@ -2849,7 +2855,7 @@ HRESULT disassembler(vector* buffer, vector* ret, const char* commen asmBuffer = (char*)pDissassembly->GetBufferPointer(); asmSize = pDissassembly->GetBufferSize(); - byte* codeByteStart; + byte* codeByteStart = nullptr; int codeChunk = 0; for (DWORD i = 1; i <= numChunks; i++) { codeChunk = numChunks - i; @@ -2883,7 +2889,7 @@ HRESULT disassembler(vector* buffer, vector* ret, const char* commen codeStarted = true; v.push_back(*codeStart); codeStart += 2; - s = assembleAndCompare(s, v); + s = assembleAndCompare(s, v, codeBin); lines[i] = s; } } else if (s.find("{ {") < s.size()) { @@ -2906,7 +2912,7 @@ HRESULT disassembler(vector* buffer, vector* ret, const char* commen v.push_back(*codeStart); codeStart++; } - s = assembleAndCompare(s, v); + s = assembleAndCompare(s, v, codeBin); auto sLines = stringToLines(s.c_str(), s.size()); size_t startLine = i - sLines.size() + 1; for (size_t j = 0; j < sLines.size(); j++) { @@ -2948,9 +2954,9 @@ HRESULT disassembler(vector* buffer, vector* ret, const char* commen v.push_back(*(codeStart)++); for (uint32_t j = 1; j < len - 1; j++) v.push_back(*(codeStart)++); - s = assembleAndCompare(s, v); + s = assembleAndCompare(s, v, codeBin); } else { - s = assembleAndCompare(s, v); + s = assembleAndCompare(s, v, codeBin); } lines[i] = s; } @@ -3163,7 +3169,7 @@ vector assembler(vector* asmFile, vector origBytecode, size_t asmSize; asmBuffer = asmFile->data(); asmSize = asmFile->size(); - byte* codeByteStart; + byte* codeByteStart = nullptr; int codeChunk = 0; for (DWORD i = 1; i <= numChunks; i++) { codeChunk = numChunks - i; @@ -3251,3 +3257,204 @@ vector assembler(vector* asmFile, vector origBytecode, dwordBuffer[4] = hash[3]; return origBytecode; } + +HRESULT disassemblerDX9(vector* buffer, vector* ret, const char* comment) +{ + char* asmBuffer; + size_t asmSize; + vector asmBuf; + ID3DBlob* pDissassembly = NULL; + LPD3DXBUFFER pD3DXDissassembly = NULL; + HRESULT ok = D3DDisassemble(buffer->data(), buffer->size(), D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS, comment, &pDissassembly); + if (FAILED(ok)) + ok = D3DDisassemble(buffer->data(), buffer->size(), NULL, comment, &pDissassembly); + if (FAILED(ok)) + ok = D3DDisassemble(buffer->data(), buffer->size(), D3D_DISASM_DISABLE_DEBUG_INFO, comment, &pDissassembly); + if (FAILED(ok)) { + //below sometimes give an access violation for some reason + //ok = D3DXDisassembleShader((DWORD*)buffer->data(), false, NULL, &pD3DXDissassembly); + //if (FAILED(ok)) + return ok; + //asmBuffer = (char*)pD3DXDissassembly->GetBufferPointer(); + //asmSize = pD3DXDissassembly->GetBufferSize(); + } else { + asmBuffer = (char*)pDissassembly->GetBufferPointer(); + asmSize = pDissassembly->GetBufferSize(); + } + vector lines = stringToLines(asmBuffer, asmSize); + ret->clear(); + for (size_t i = 0; i < lines.size(); i++) { + for (size_t j = 0; j < lines[i].size(); j++) { + ret->insert(ret->end(), lines[i][j]); + } + ret->insert(ret->end(), '\n'); + } + if (pDissassembly) + pDissassembly->Release(); + if (pD3DXDissassembly) + pD3DXDissassembly->Release(); + return S_OK; +} + +vector assemblerDX9(vector* asmFile) +{ + vector ret; + LPD3DXBUFFER pAssembly; + HRESULT hr = D3DXAssembleShader(asmFile->data(), (UINT)asmFile->size(), NULL, NULL, 0, &pAssembly, NULL); + if (!FAILED(hr)) { + size_t size = pAssembly->GetBufferSize(); + LPVOID buffer = pAssembly->GetBufferPointer(); + ret.resize(size); + std::memcpy(ret.data(), buffer, size); + pAssembly->Release(); + // FIXME: Pass warnings back to the caller + } else { + // FIXME: Pass error messages back to the caller + throw std::invalid_argument("assembler: Bad shader assembly (FIXME: RETURN ERROR MESSAGES)"); + } + return ret; +} + +// Common routine to handle disassembling binary shaders to asm text. +// This is used whenever we need the Asm text. + + +// New version using Flugan's wrapper around D3DDisassemble to replace the +// problematic %f floating point values with %.9e, which is enough that a 32bit +// floating point value will be reproduced exactly: +string BinaryToAsmText(const void* pShaderBytecode, size_t BytecodeLength, + bool patch_cb_offsets, + bool disassemble_undecipherable_data, + int hexdump, bool d3dcompiler_46_compat) +{ + string comments; + vector byteCode(BytecodeLength); + vector disassembly; + HRESULT r; + + comments = "// using 3Dmigoto v" + string(VER_FILE_VERSION_STR) + " on " + LogTime() + "//\n"; + memcpy(byteCode.data(), pShaderBytecode, BytecodeLength); + +#if MIGOTO_DX == 9 + r = disassemblerDX9(&byteCode, &disassembly, comments.c_str()); +#elif MIGOTO_DX == 11 + unordered_map> codeBin; + r = disassembler(&byteCode, &disassembly, comments.c_str(), codeBin, hexdump, + d3dcompiler_46_compat, disassemble_undecipherable_data, patch_cb_offsets); +#endif // MIGOTO_DX + if (FAILED(r)) { + LogInfo(" disassembly failed. Error: %x\n", r); + return ""; + } + + return string(disassembly.begin(), disassembly.end()); +} + +// Get the shader model from the binary shader bytecode. +// +// This used to disassemble, then search for the text string, but if we are going to +// do all that work, we might as well use the James-Jones decoder to get it. +// The other reason to do it this way is that we have seen multiple shader versions +// in Unity games, and the old technique of searching for the first uncommented line +// would fail. + +// This is an interesting idea, but doesn't work well here because of project structure. +// for the moment, let's leave this here, but use the disassemble search approach. + +//static string GetShaderModel(const void *pShaderBytecode) +//{ +// Shader *shader = DecodeDXBC((uint32_t*)pShaderBytecode); +// if (shader == nullptr) +// return ""; +// +// string shaderModel; +// +// switch (shader->eShaderType) +// { +// case PIXEL_SHADER: +// shaderModel = "ps"; +// break; +// case VERTEX_SHADER: +// shaderModel = "vs"; +// break; +// case GEOMETRY_SHADER: +// shaderModel = "gs"; +// break; +// case HULL_SHADER: +// shaderModel = "hs"; +// break; +// case DOMAIN_SHADER: +// shaderModel = "ds"; +// break; +// case COMPUTE_SHADER: +// shaderModel = "cs"; +// break; +// default: +// return ""; // Failure. +// } +// +// shaderModel += "_" + shader->ui32MajorVersion; +// shaderModel += "_" + shader->ui32MinorVersion; +// +// delete shader; +// +// return shaderModel; +//} + +string GetShaderModel(const void* pShaderBytecode, size_t bytecodeLength) +{ + string asmText = BinaryToAsmText(pShaderBytecode, bytecodeLength, false); + if (asmText.empty()) + return ""; + + // Read shader model. This is the first not commented line. + char* pos = (char*)asmText.data(); + char* end = pos + asmText.size(); + while ((pos[0] == '/' || pos[0] == '\n') && pos < end) + { + while (pos[0] != 0x0a && pos < end) pos++; + pos++; + } + // Extract model. + char* eol = pos; + while (eol[0] != 0x0a && pos < end) eol++; + string shaderModel(pos, eol); + + return shaderModel; +} + +// Get shader type from asm, first non-commented line. CS, PS, VS. +// Not sure this works on weird Unity variant with embedded types. + + +// Specific variant to name files consistently, so we know they are Asm text. + +HRESULT CreateAsmTextFile(wchar_t* fileDirectory, UINT64 hash, const wchar_t* shaderType, + const void* pShaderBytecode, size_t bytecodeLength, bool patch_cb_offsets) +{ + string asmText = BinaryToAsmText(pShaderBytecode, bytecodeLength, patch_cb_offsets); + if (asmText.empty()) + { + return E_OUTOFMEMORY; + } + + wchar_t fullPath[MAX_PATH]; + swprintf_s(fullPath, MAX_PATH, L"%ls\\%016llx-%ls.txt", fileDirectory, hash, shaderType); + + HRESULT hr = CreateTextFile(fullPath, &asmText, false); + + if (SUCCEEDED(hr)) + LogInfoW(L" storing disassembly to %s\n", fullPath); + else + LogInfoW(L" error: %x, storing disassembly to %s\n", hr, fullPath); + + return hr; +} + +// Create a text file containing text for the string specified. Can be Asm or HLSL. +// If the file already exists and the caller did not specify overwrite (used +// for reassembled text), return that as an error to avoid overwriting previous +// work. + +// We previously would overwrite the file only after checking if the contents were different, +// this relaxes that to just being same file name. \ No newline at end of file diff --git a/HLSLDecompiler/Assembler.h b/HLSLDecompiler/Assembler.h new file mode 100644 index 000000000..5d6219b02 --- /dev/null +++ b/HLSLDecompiler/Assembler.h @@ -0,0 +1,51 @@ +#pragma once +#include "stdafx.h" +#include + +using namespace std; + +// VS2013 BUG WORKAROUND: Make sure this class has a unique type name! +class AssemblerParseError : public exception { +public: + string context, desc, msg; + int line_no; + + AssemblerParseError(std::string context, string desc); + + void update_msg(); + + const char* what() const; +}; + +struct shader_ins +{ + union { + struct { + // XXX Beware that bitfield packing is not defined in + // the C/C++ standards and this is relying on compiler + // specific packing. This approach is not recommended. + + unsigned opcode : 11; + unsigned _11_23 : 13; + unsigned length : 7; + unsigned extended : 1; + }; + DWORD op; + }; +}; + +HRESULT disassembler(vector* buffer, vector* ret, const char* comment, unordered_map>& codeBin, int hexdump = 0, bool d3dcompiler_46_compat = false, bool disassemble_undecipherable_data = false, bool patch_cb_offsets = false); + +vector assembler(vector* asmFile, vector origBytecode, vector* parse_errors = nullptr); + +HRESULT disassemblerDX9(vector* buffer, vector* ret, const char* comment); + +vector assemblerDX9(vector* asmFile); + +string BinaryToAsmText(const void* pShaderBytecode, size_t BytecodeLength, bool patch_cb_offsets, bool disassemble_undecipherable_data = true, int hexdump = 0, bool d3dcompiler_46_compat = true); + +string GetShaderModel(const void* pShaderBytecode, size_t bytecodeLength); + +HRESULT CreateAsmTextFile(wchar_t* fileDirectory, UINT64 hash, const wchar_t* shaderType, const void* pShaderBytecode, size_t bytecodeLength, bool patch_cb_offsets); + +vector stringToLines(const char* start, size_t size); diff --git a/HLSLDecompiler/DecompileHLSL.cpp b/HLSLDecompiler/DecompileHLSL.cpp index c20ee2aed..c7784eb99 100644 --- a/HLSLDecompiler/DecompileHLSL.cpp +++ b/HLSLDecompiler/DecompileHLSL.cpp @@ -18,22 +18,20 @@ // All sscanf that did not use %s or %c were switched to sscanf_s to avoid warnings. #include -#include #include -#include #include #include #include "DecompileHLSL.h" -#include "BinaryDecompiler\internal_includes\structs.h" -#include "BinaryDecompiler\internal_includes\decode.h" +#include "../BinaryDecompiler/internal_includes/structs.h" +#include "../BinaryDecompiler/internal_includes/decode.h" #include #include "assert.h" -#include "log.h" -#include "version.h" +#include "../log.h" +#include "../version.h" // MSVC insists we use MS's secure version of scanf, which in turn insists we // pass the size of each string/char array as an unsigned integer. We want to @@ -396,7 +394,7 @@ class Decompiler { string interpolation = ""; - for each (Declaration declaration in shader->asPhase[MAIN_PHASE].ppsDecl[0]) + for (Declaration declaration : shader->asPhase[MAIN_PHASE].ppsDecl[0]) { if (declaration.eOpcode == OPCODE_DCL_INPUT_PS) { @@ -3832,7 +3830,7 @@ class Decompiler // The swizzle is a bit more complicated than the mask here, // because it represents extra 32bit offsets in the structure, // which is one whole index in the "val" array in our fake type. - char* swiz_offset = ""; + const char* swiz_offset = ""; switch (swiz_offsets[component]) { case 0: break; case 4: swiz_offset = "+1"; break; @@ -3981,11 +3979,11 @@ class Decompiler string GetComponentStrFromInstruction(Instruction* instr, int opIndex) { assert(instr != NULL); - char* componentX = "x"; - char* componentY = "y"; - char* componentZ = "z"; - char* componentW = "w"; - char* component[] = { componentX, componentY, componentZ, componentW }; + const char* componentX = "x"; + const char* componentY = "y"; + const char* componentZ = "z"; + const char* componentW = "w"; + const char* component[] = { componentX, componentY, componentZ, componentW }; char buff[opcodeSize]; diff --git a/HLSLDecompiler/HLSLDecompiler.vcxproj b/HLSLDecompiler/HLSLDecompiler.vcxproj new file mode 100644 index 000000000..566bf527d --- /dev/null +++ b/HLSLDecompiler/HLSLDecompiler.vcxproj @@ -0,0 +1,171 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {00b6ba42-4050-488d-91be-a8cd7adaeb87} + Win32Proj + HLSLDecompiler + 10.0.17763.0 + + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + false + $(DXSDK_DIR)Include;$(IncludePath) + $(SolutionDir)x32\$(Configuration)\ + $(ProjectDir)x32\$(Configuration)\ + + + false + $(DXSDK_DIR)Include;$(IncludePath) + $(SolutionDir)x64\$(Configuration)\ + $(ProjectDir)x64\$(Configuration)\ + + + false + $(DXSDK_DIR)Include;$(IncludePath) + $(SolutionDir)x32\$(Configuration)\ + $(ProjectDir)x32\$(Configuration)\ + + + false + $(DXSDK_DIR)Include;$(IncludePath) + $(SolutionDir)x64\$(Configuration)\ + $(ProjectDir)x64\$(Configuration)\ + + + + Level3 + WIN32;DEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) + true + MultiThreadedDebug + + + Console + true + + + + + Level3 + DEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) + true + MultiThreadedDebug + + + Console + true + + + + + Level3 + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + + + Console + true + true + true + + + + + Level3 + true + true + NDEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) + MultiThreaded + + + Console + true + true + true + + + + + + + + + + + + + + + + + + {258d0ad2-b762-41e3-a0c1-cf831d859da4} + true + true + + + + + + \ No newline at end of file diff --git a/HLSLDecompiler/cmd_Decompiler/cmd_Decompiler.vcxproj.filters b/HLSLDecompiler/HLSLDecompiler.vcxproj.filters similarity index 56% rename from HLSLDecompiler/cmd_Decompiler/cmd_Decompiler.vcxproj.filters rename to HLSLDecompiler/HLSLDecompiler.vcxproj.filters index aa63fa76f..8ad62ae9b 100644 --- a/HLSLDecompiler/cmd_Decompiler/cmd_Decompiler.vcxproj.filters +++ b/HLSLDecompiler/HLSLDecompiler.vcxproj.filters @@ -3,52 +3,42 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - + + Source Files + + + Source Files + + + Source Files + + + Source Files + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - \ No newline at end of file diff --git a/D3D_Shaders/SignatureParser.cpp b/HLSLDecompiler/SignatureParser.cpp similarity index 97% rename from D3D_Shaders/SignatureParser.cpp rename to HLSLDecompiler/SignatureParser.cpp index 99e319002..57900141c 100644 --- a/D3D_Shaders/SignatureParser.cpp +++ b/HLSLDecompiler/SignatureParser.cpp @@ -1,7 +1,7 @@ -#include "stdafx.h" +#include "SignatureParser.h" -#include "log.h" -#include "shader.h" +#include "../log.h" +#include "../shader.h" #define SFI_RAW_STRUCT_BUF (1LL<<1) #define SFI_MIN_PRECISION (1LL<<4) @@ -43,7 +43,7 @@ static string next_line(string *shader, size_t *pos) struct format_type { uint32_t format; uint32_t min_precision; - char *name; + const char *name; }; static struct format_type format_names[] = { @@ -74,7 +74,7 @@ static void parse_format(char *format, uint32_t *format_number, uint32_t *min_pr struct svt { uint32_t val; - char *short_name; + const char *short_name; }; static struct svt system_value_abbreviations[] = { @@ -182,7 +182,7 @@ static uint32_t pad(uint32_t size, uint32_t multiple) return (multiple - size % multiple) % multiple; } -static void* serialise_signature_section(char *section24, char *section28, char *section32, int entry_size, +static void* serialise_signature_section(const char *section24, const char *section28, const char *section32, int entry_size, vector *entries, uint32_t name_len) { void *section; @@ -278,7 +278,7 @@ static void* serialise_signature_section(char *section24, char *section28, char return section; } -static void* parse_signature_section(char *section24, char *section28, char *section32, string *shader, size_t *pos, bool invert_used, uint64_t sfi) +static void* parse_signature_section(const char *section24, const char *section28, const char *section32, string *shader, size_t *pos, bool invert_used, uint64_t sfi) { string line; size_t old_pos = *pos; @@ -445,7 +445,7 @@ static void* serialise_subshader_feature_info_section(uint64_t flags) struct gf_sfi { uint64_t sfi; int len; - char *gf; + const char *gf; }; static struct gf_sfi global_flag_sfi_map[] = { @@ -462,7 +462,7 @@ static struct gf_sfi global_flag_sfi_map[] = { // "allResourcesBound" }; -static char *subshader_feature_comments[] = { +static const char *subshader_feature_comments[] = { // d3dcompiler_46: "Double-precision floating point", //"Early depth-stencil", // d3dcompiler46/47 produces this output for [force, but it does *NOT* map to an SFI flag @@ -553,7 +553,7 @@ static uint64_t parse_subshader_feature_info_comment(string *shader, size_t *pos return flags; } -static void* manufacture_empty_section(char *section_name) +static void* manufacture_empty_section(const char *section_name) { void *section; @@ -631,7 +631,7 @@ static bool parse_section(string *line, string *shader, size_t *pos, void **sect *section = parse_signature_section("ISGN", NULL, "ISG1", shader, pos, false, *sfi); } else if (!strncmp(line->c_str(), "// Output signature:", 20)) { LogInfo("Parsing Output Signature section...\n"); - char *section24 = "OSGN"; + const char *section24 = "OSGN"; if (is_geometry_shader_5(shader, *pos)) section24 = NULL; *section = parse_signature_section(section24, "OSG5", "OSG1", shader, pos, true, *sfi); diff --git a/HLSLDecompiler/SignatureParser.h b/HLSLDecompiler/SignatureParser.h new file mode 100644 index 000000000..88dc67eba --- /dev/null +++ b/HLSLDecompiler/SignatureParser.h @@ -0,0 +1,7 @@ +#pragma once +#include "stdafx.h" +#include "Assembler.h" + +HRESULT AssembleFluganWithSignatureParsing(vector* assembly, vector* result_bytecode, vector* parse_errors = nullptr); + +vector AssembleFluganWithOptionalSignatureParsing(vector* assembly, bool assemble_signatures, vector* orig_bytecode, vector* parse_errors = nullptr); diff --git a/HLSLDecompiler/cmd_Decompiler/stdafx.cpp b/HLSLDecompiler/stdafx.cpp similarity index 100% rename from HLSLDecompiler/cmd_Decompiler/stdafx.cpp rename to HLSLDecompiler/stdafx.cpp diff --git a/HLSLDecompiler/cmd_Decompiler/stdafx.h b/HLSLDecompiler/stdafx.h similarity index 71% rename from HLSLDecompiler/cmd_Decompiler/stdafx.h rename to HLSLDecompiler/stdafx.h index b005a839d..cd0521dcd 100644 --- a/HLSLDecompiler/cmd_Decompiler/stdafx.h +++ b/HLSLDecompiler/stdafx.h @@ -7,9 +7,13 @@ #include "targetver.h" -#include -#include - +#define NOMINMAX +#include +#include +#include +#include +#include +#include // TODO: reference additional headers your program requires here diff --git a/HLSLDecompiler/cmd_Decompiler/targetver.h b/HLSLDecompiler/targetver.h similarity index 100% rename from HLSLDecompiler/cmd_Decompiler/targetver.h rename to HLSLDecompiler/targetver.h diff --git a/NVAPI/NVAPI.vcxproj b/NVAPI/NVAPI.vcxproj index 4bca0f778..ac6e28490 100644 --- a/NVAPI/NVAPI.vcxproj +++ b/NVAPI/NVAPI.vcxproj @@ -112,14 +112,12 @@ - $(SolutionDir)crc32c-hw-1.0.5\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86) nvapi $(SolutionDir)x32\$(Configuration)\ $(ProjectDir)x32\$(Configuration)\ - $(SolutionDir)crc32c-hw-1.0.5\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64) nvapi64 $(SolutionDir)x64\$(Configuration)\ @@ -127,7 +125,6 @@ false - $(SolutionDir)crc32c-hw-1.0.5\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86) nvapi $(SolutionDir)x32\$(Configuration)\ @@ -135,7 +132,6 @@ false - $(SolutionDir)crc32c-hw-1.0.5\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86) nvapi $(SolutionDir)x32\$(Configuration)\ @@ -143,7 +139,6 @@ false - $(SolutionDir)crc32c-hw-1.0.5\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64) nvapi64 $(SolutionDir)x64\$(Configuration)\ @@ -151,7 +146,6 @@ false - $(SolutionDir)crc32c-hw-1.0.5\include;$(WindowsSDK_IncludePath);$(VC_IncludePath) $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64) nvapi64 $(SolutionDir)x64\$(Configuration)\ @@ -270,4 +264,4 @@ - + \ No newline at end of file diff --git a/StereovisionHacks.sln b/StereovisionHacks.sln index bf3b60a43..2a3756c1b 100644 --- a/StereovisionHacks.sln +++ b/StereovisionHacks.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27428.2011 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32428.217 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectX11", "DirectX11\DirectX11.vcxproj", "{92A679C7-A67F-4B16-B055-7A2F4C23DD80}" ProjectSection(ProjectDependencies) = postProject @@ -54,7 +54,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Nektra", "Nektra", "{0893CB Nektra\nkthooklib_debug.pdb = Nektra\nkthooklib_debug.pdb EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmd_Decompiler", "HLSLDecompiler\cmd_Decompiler\cmd_Decompiler.vcxproj", "{25E1F732-DCF5-428E-928D-D39C499CC95F}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmd_Decompiler", "cmd_Decompiler\cmd_Decompiler.vcxproj", "{25E1F732-DCF5-428E-928D-D39C499CC95F}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build Tools", "Build Tools", "{09915712-7D63-41F9-8110-D5667F1F9FCF}" ProjectSection(SolutionItems) = preProject @@ -82,6 +82,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DirectXTK_Desktop_2017", "D EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Injector", "Injector\Injector.vcxproj", "{8747D291-5845-4743-B3ED-FB418FCCC817}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HLSLDecompiler", "HLSLDecompiler\HLSLDecompiler.vcxproj", "{00B6BA42-4050-488D-91BE-A8CD7ADAEB87}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "crc32c-hw", "crc32c-hw-1.0.5\CRC32C-HW.vcxproj", "{D05DA837-8C74-40E0-8255-1345CA449648}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -92,18 +96,6 @@ Global Zip Release|x64 = Zip Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Debug|Win32.ActiveCfg = Debug|Win32 - {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Debug|x64.ActiveCfg = Debug|x64 - {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Release|Win32.ActiveCfg = Release|Win32 - {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Release|x64.ActiveCfg = Release|x64 - {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Zip Release|Win32.ActiveCfg = Zip Release|Win32 - {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Zip Release|x64.ActiveCfg = Zip Release|x64 - {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Debug|Win32.ActiveCfg = Debug|Win32 - {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Debug|x64.ActiveCfg = Debug|x64 - {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Release|Win32.ActiveCfg = Release|Win32 - {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Release|x64.ActiveCfg = Release|x64 - {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Zip Release|Win32.ActiveCfg = Zip Release|Win32 - {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Zip Release|x64.ActiveCfg = Zip Release|x64 {92A679C7-A67F-4B16-B055-7A2F4C23DD80}.Debug|Win32.ActiveCfg = Debug|Win32 {92A679C7-A67F-4B16-B055-7A2F4C23DD80}.Debug|Win32.Build.0 = Debug|Win32 {92A679C7-A67F-4B16-B055-7A2F4C23DD80}.Debug|x64.ActiveCfg = Debug|x64 @@ -116,6 +108,18 @@ Global {92A679C7-A67F-4B16-B055-7A2F4C23DD80}.Zip Release|Win32.Build.0 = Zip Release|Win32 {92A679C7-A67F-4B16-B055-7A2F4C23DD80}.Zip Release|x64.ActiveCfg = Zip Release|x64 {92A679C7-A67F-4B16-B055-7A2F4C23DD80}.Zip Release|x64.Build.0 = Zip Release|x64 + {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Debug|Win32.ActiveCfg = Debug|Win32 + {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Debug|x64.ActiveCfg = Debug|x64 + {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Release|Win32.ActiveCfg = Release|Win32 + {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Release|x64.ActiveCfg = Release|x64 + {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Zip Release|Win32.ActiveCfg = Zip Release|Win32 + {4265C0D8-8671-49C0-8EB5-EB940FD08482}.Zip Release|x64.ActiveCfg = Zip Release|x64 + {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Debug|Win32.ActiveCfg = Debug|Win32 + {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Debug|x64.ActiveCfg = Debug|x64 + {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Release|Win32.ActiveCfg = Release|Win32 + {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Release|x64.ActiveCfg = Release|x64 + {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Zip Release|Win32.ActiveCfg = Zip Release|Win32 + {C9205DC6-7CE4-4939-9EFC-FE61483CCE01}.Zip Release|x64.ActiveCfg = Zip Release|x64 {16459E48-9CD1-49FE-8703-D8B275CFCE1E}.Debug|Win32.ActiveCfg = Debug|Win32 {16459E48-9CD1-49FE-8703-D8B275CFCE1E}.Debug|x64.ActiveCfg = Debug|x64 {16459E48-9CD1-49FE-8703-D8B275CFCE1E}.Release|Win32.ActiveCfg = Release|Win32 @@ -177,6 +181,7 @@ Global {258D0AD2-B762-41E3-A0C1-CF831D859DA4}.Zip Release|x64.ActiveCfg = Zip Release|x64 {258D0AD2-B762-41E3-A0C1-CF831D859DA4}.Zip Release|x64.Build.0 = Zip Release|x64 {59A9B0C6-8302-48A9-96E0-126FB32FB9ED}.Debug|Win32.ActiveCfg = Debug|Win32 + {59A9B0C6-8302-48A9-96E0-126FB32FB9ED}.Debug|Win32.Build.0 = Debug|Win32 {59A9B0C6-8302-48A9-96E0-126FB32FB9ED}.Debug|x64.ActiveCfg = Debug|x64 {59A9B0C6-8302-48A9-96E0-126FB32FB9ED}.Release|Win32.ActiveCfg = Release|Win32 {59A9B0C6-8302-48A9-96E0-126FB32FB9ED}.Release|x64.ActiveCfg = Release|x64 @@ -216,6 +221,30 @@ Global {8747D291-5845-4743-B3ED-FB418FCCC817}.Zip Release|Win32.Build.0 = Zip Release|Win32 {8747D291-5845-4743-B3ED-FB418FCCC817}.Zip Release|x64.ActiveCfg = Zip Release|x64 {8747D291-5845-4743-B3ED-FB418FCCC817}.Zip Release|x64.Build.0 = Zip Release|x64 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Debug|Win32.ActiveCfg = Debug|Win32 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Debug|Win32.Build.0 = Debug|Win32 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Debug|x64.ActiveCfg = Debug|x64 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Debug|x64.Build.0 = Debug|x64 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Release|Win32.ActiveCfg = Release|Win32 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Release|Win32.Build.0 = Release|Win32 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Release|x64.ActiveCfg = Release|x64 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Release|x64.Build.0 = Release|x64 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Zip Release|Win32.ActiveCfg = Release|Win32 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Zip Release|Win32.Build.0 = Release|Win32 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Zip Release|x64.ActiveCfg = Release|x64 + {00B6BA42-4050-488D-91BE-A8CD7ADAEB87}.Zip Release|x64.Build.0 = Release|x64 + {D05DA837-8C74-40E0-8255-1345CA449648}.Debug|Win32.ActiveCfg = Debug|Win32 + {D05DA837-8C74-40E0-8255-1345CA449648}.Debug|Win32.Build.0 = Debug|Win32 + {D05DA837-8C74-40E0-8255-1345CA449648}.Debug|x64.ActiveCfg = Debug|x64 + {D05DA837-8C74-40E0-8255-1345CA449648}.Debug|x64.Build.0 = Debug|x64 + {D05DA837-8C74-40E0-8255-1345CA449648}.Release|Win32.ActiveCfg = Release|Win32 + {D05DA837-8C74-40E0-8255-1345CA449648}.Release|Win32.Build.0 = Release|Win32 + {D05DA837-8C74-40E0-8255-1345CA449648}.Release|x64.ActiveCfg = Release|x64 + {D05DA837-8C74-40E0-8255-1345CA449648}.Release|x64.Build.0 = Release|x64 + {D05DA837-8C74-40E0-8255-1345CA449648}.Zip Release|Win32.ActiveCfg = Release|Win32 + {D05DA837-8C74-40E0-8255-1345CA449648}.Zip Release|Win32.Build.0 = Release|Win32 + {D05DA837-8C74-40E0-8255-1345CA449648}.Zip Release|x64.ActiveCfg = Release|x64 + {D05DA837-8C74-40E0-8255-1345CA449648}.Zip Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/HLSLDecompiler/cmd_Decompiler/ReadMe.txt b/cmd_Decompiler/ReadMe.txt similarity index 100% rename from HLSLDecompiler/cmd_Decompiler/ReadMe.txt rename to cmd_Decompiler/ReadMe.txt diff --git a/HLSLDecompiler/cmd_Decompiler/cmd_Decompiler.cpp b/cmd_Decompiler/cmd_Decompiler.cpp similarity index 84% rename from HLSLDecompiler/cmd_Decompiler/cmd_Decompiler.cpp rename to cmd_Decompiler/cmd_Decompiler.cpp index fd56e7ff5..c94ec4b34 100644 --- a/HLSLDecompiler/cmd_Decompiler/cmd_Decompiler.cpp +++ b/cmd_Decompiler/cmd_Decompiler.cpp @@ -1,128 +1,19 @@ // cmd_Decompiler.cpp : Defines the entry point for the console application. // -#include "stdafx.h" - #include // console output #include -#include "DecompileHLSL.h" -#include "version.h" -#include "log.h" -#define MIGOTO_DX 9 // Selects the DX11 disassembler in util.h - the DX9 dis/assembler is not very - // interesting since it is just Microsoft's - we can add it later, but low priority. - // The DX9 decompiler is more interesting, which is unrelated to this flag. -#include "util.h" -#include "shader.h" - -#if MIGOTO_DX == 9 -#include -#endif - -using namespace std; - -static vector stringToLinesDX9(const char* start, size_t size) { - vector lines; - const char* pStart = start; - const char* pEnd = pStart; - const char* pRealEnd = pStart + size; - while (true) { - while (*pEnd != '\n' && pEnd < pRealEnd) { - pEnd++; - } - if (*pStart == 0) { - break; - } - string s(pStart, pEnd++); - pStart = pEnd; - lines.push_back(s); - if (pStart >= pRealEnd) { - break; - } - } - for (unsigned int i = 0; i < lines.size(); i++) { - string s = lines[i]; - // Bug fixed: This would not strip carriage returns from DOS - // style newlines if they were the only character on the line, - // corrupting the resulting shader binary. -DarkStarSword - if (s.size() >= 1 && s[s.size() - 1] == '\r') - s.erase(--s.end()); - - // Strip whitespace from the end of each line. This isn't - // strictly necessary, but the MS disassembler inserts an extra - // space after "ret ", "else " and "endif ", which has been a - // gotcha for trying to match it with ShaderRegex since it's - // easy to miss the fact that there is a space there and not - // understand why the pattern isn't matching. By removing - // excess spaces from the end of each line now we can make this - // gotcha go away. - while (s.size() >= 1 && s[s.size() - 1] == ' ') - s.erase(--s.end()); - - while (s.size() >= 1 && s[0] == ' ') - s.erase(s.begin()); - - lines[i] = s; - } - return lines; -} +#include "../version.h" +#include "../log.h" +#include "../util.h" +#include "../shader.h" +#include "../HLSLDecompiler/DecompileHLSL.h" +#include "../HLSLDecompiler/SignatureParser.h" -HRESULT disassemblerDX9(vector* buffer, vector* ret, const char* comment) -{ - char* asmBuffer; - size_t asmSize; - vector asmBuf; - ID3DBlob* pDissassembly = NULL; - LPD3DXBUFFER pD3DXDissassembly = NULL; - HRESULT ok = D3DDisassemble(buffer->data(), buffer->size(), D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS, comment, &pDissassembly); - if (FAILED(ok)) - ok = D3DDisassemble(buffer->data(), buffer->size(), NULL, comment, &pDissassembly); - if (FAILED(ok)) - ok = D3DDisassemble(buffer->data(), buffer->size(), D3D_DISASM_DISABLE_DEBUG_INFO, comment, &pDissassembly); - if (FAILED(ok)) { - //below sometimes give an access violation for some reason - //ok = D3DXDisassembleShader((DWORD*)buffer->data(), false, NULL, &pD3DXDissassembly); - //if (FAILED(ok)) - return ok; - //asmBuffer = (char*)pD3DXDissassembly->GetBufferPointer(); - //asmSize = pD3DXDissassembly->GetBufferSize(); - } else { - asmBuffer = (char*)pDissassembly->GetBufferPointer(); - asmSize = pDissassembly->GetBufferSize(); - } - vector lines = stringToLinesDX9(asmBuffer, asmSize); - ret->clear(); - for (size_t i = 0; i < lines.size(); i++) { - for (size_t j = 0; j < lines[i].size(); j++) { - ret->insert(ret->end(), lines[i][j]); - } - ret->insert(ret->end(), '\n'); - } - if (pDissassembly) - pDissassembly->Release(); - if (pD3DXDissassembly) - pD3DXDissassembly->Release(); - return S_OK; -} +#define D3D_COMPILE_STANDARD_FILE_INCLUDE ((ID3DInclude*)(UINT_PTR)1) -vector assemblerDX9(vector* asmFile) -{ - vector ret; - LPD3DXBUFFER pAssembly; - HRESULT hr = D3DXAssembleShader(asmFile->data(), (UINT)asmFile->size(), NULL, NULL, 0, &pAssembly, NULL); - if (!FAILED(hr)) { - size_t size = pAssembly->GetBufferSize(); - LPVOID buffer = pAssembly->GetBufferPointer(); - ret.resize(size); - std::memcpy(ret.data(), buffer, size); - pAssembly->Release(); - // FIXME: Pass warnings back to the caller - } else { - // FIXME: Pass error messages back to the caller - throw std::invalid_argument("assembler: Bad shader assembly (FIXME: RETURN ERROR MESSAGES)"); - } - return ret; -} +using namespace std; FILE* LogFile = stderr; // Log to stderr by default bool gLogDebug = false; @@ -721,7 +612,8 @@ static int process(string const* filename) { LogInfo("Translating %s...\n", filename->c_str()); auto srcBytes = assemblerDX9(&srcData); - hret = TranslateASMtoHLSL(srcBytes.data(), std::string(srcData.data()), &output, &model); + auto data = std::string(srcData.data()); + hret = TranslateASMtoHLSL(srcBytes.data(), data, &output, &model); } if (FAILED(hret)) return EXIT_FAILURE; diff --git a/HLSLDecompiler/cmd_Decompiler/cmd_Decompiler.vcxproj b/cmd_Decompiler/cmd_Decompiler.vcxproj similarity index 69% rename from HLSLDecompiler/cmd_Decompiler/cmd_Decompiler.vcxproj rename to cmd_Decompiler/cmd_Decompiler.vcxproj index 7d0405ea8..2375586ce 100644 --- a/HLSLDecompiler/cmd_Decompiler/cmd_Decompiler.vcxproj +++ b/cmd_Decompiler/cmd_Decompiler.vcxproj @@ -79,75 +79,74 @@ - + - + - + - + false - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath);$(DXSDK_DIR)Include + $(DXSDK_DIR)Include;$(IncludePath) $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86);$(DXSDK_DIR)Lib\x86 - $(SolutionDir)\x32\$(Configuration)\ - $(ProjectDir)\x32\$(Configuration)\ + $(SolutionDir)x32\$(Configuration)\ + $(ProjectDir)x32\$(Configuration)\ false - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath);$(DXSDK_DIR)Include + $(DXSDK_DIR)Include;$(IncludePath) $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64);$(DXSDK_DIR)Lib\x64 - $(SolutionDir)\x64\$(Configuration)\ - $(ProjectDir)\x64\$(Configuration)\ + $(SolutionDir)x64\$(Configuration)\ + $(ProjectDir)x64\$(Configuration)\ false - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath);$(DXSDK_DIR)Include + $(DXSDK_DIR)Include;$(IncludePath) $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86);$(DXSDK_DIR)Lib\x86 - $(SolutionDir)\x32\$(Configuration)\ - $(ProjectDir)\x32\$(Configuration)\ + $(SolutionDir)x32\$(Configuration)\ + $(ProjectDir)x32\$(Configuration)\ false - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath);$(DXSDK_DIR)Include + $(DXSDK_DIR)Include;$(IncludePath) $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64);$(DXSDK_DIR)Lib\x64 - $(SolutionDir)\x64\$(Configuration)\ - $(ProjectDir)\x64\$(Configuration)\ + $(SolutionDir)x64\$(Configuration)\ + $(ProjectDir)x64\$(Configuration)\ false - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath);$(DXSDK_DIR)Include + $(DXSDK_DIR)Include;$(IncludePath) $(WindowsSDK_LibraryPath_x86);$(VC_LibraryPath_x86);$(DXSDK_DIR)Lib\x86 - $(SolutionDir)\x32\$(Configuration)\ - $(ProjectDir)\x32\$(Configuration)\ + $(SolutionDir)x32\$(Configuration)\ + $(ProjectDir)x32\$(Configuration)\ false - $(SolutionDir)crc32c-hw-1.0.5\include;$(SolutionDir)BinaryDecompiler;$(SolutionDir)BinaryDecompiler\include;$(WindowsSDK_IncludePath);$(VC_IncludePath);$(DXSDK_DIR)Include + $(DXSDK_DIR)Include;$(IncludePath) $(WindowsSDK_LibraryPath_x64);$(VC_LibraryPath_x64);$(DXSDK_DIR)Lib\x64 - $(SolutionDir)\x64\$(Configuration)\ - $(ProjectDir)\x64\$(Configuration)\ + $(SolutionDir)x64\$(Configuration)\ + $(ProjectDir)x64\$(Configuration)\ - - Level3 Disabled - WIN32;NDEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) - $(SolutionDir);$(SolutionDir)HLSLDecompiler;$(SolutionDir)D3D_Shaders + WIN32;DEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) MultiThreadedDebug true true + + Console @@ -156,9 +155,7 @@ true - xcopy "$(WindowsSdkDir)redist\d3d\x86\d3dcompiler_47.dll" "$(TargetDir)" /E /Y - - + xcopy "$(WindowsSdkDir)redist\d3d\x86\d3dcompiler_47.dll" "$(TargetDir)" /E /Y Copy D3Dcompiler_46.dll @@ -166,23 +163,22 @@ - NotUsing Level3 Disabled - WIN32;NDEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) - $(SolutionDir);$(SolutionDir)HLSLDecompiler;$(SolutionDir)D3D_Shaders + DEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) MultiThreadedDebug Async + + + true Console true - d3dcompiler.lib;d3d9.lib;%(AdditionalDependencies) + d3dcompiler.lib;d3dx9.lib;%(AdditionalDependencies) - xcopy "$(WindowsSdkDir)redist\d3d\x64\d3dcompiler_47.dll" "$(TargetDir)" /E /Y - - + xcopy "$(WindowsSdkDir)redist\d3d\x64\d3dcompiler_47.dll" "$(TargetDir)" /E /Y Copy D3Dcompiler_46.dll @@ -191,14 +187,13 @@ Level3 - - MaxSpeed true true WIN32;NDEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) - $(SolutionDir);$(SolutionDir)HLSLDecompiler;$(SolutionDir)D3D_Shaders MultiThreaded + + Console @@ -208,9 +203,7 @@ d3dcompiler.lib;d3dx9.lib;%(AdditionalDependencies) - xcopy "$(WindowsSdkDir)redist\d3d\x86\d3dcompiler_47.dll" "$(TargetDir)" /E /Y - - + xcopy "$(WindowsSdkDir)redist\d3d\x86\d3dcompiler_47.dll" "$(TargetDir)" /E /Y Copy D3Dcompiler_46.dll @@ -219,13 +212,10 @@ Level3 - - MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) - $(SolutionDir);$(SolutionDir)HLSLDecompiler;$(SolutionDir)D3D_Shaders + NDEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) MultiThreaded Async false @@ -235,12 +225,10 @@ true true true - d3dcompiler.lib;d3d9.lib;%(AdditionalDependencies) + d3dcompiler.lib;d3dx9.lib;%(AdditionalDependencies) - xcopy "$(WindowsSdkDir)redist\d3d\x64\d3dcompiler_47.dll" "$(TargetDir)" /E /Y - - + xcopy "$(WindowsSdkDir)redist\d3d\x64\d3dcompiler_47.dll" "$(TargetDir)" /E /Y Copy D3Dcompiler_46.dll @@ -249,14 +237,13 @@ Level3 - - MaxSpeed true true WIN32;NDEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) - $(SolutionDir);$(SolutionDir)HLSLDecompiler;$(SolutionDir)D3D_Shaders MultiThreaded + + Console @@ -277,26 +264,23 @@ Level3 - - MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) - $(SolutionDir);$(SolutionDir)HLSLDecompiler;$(SolutionDir)D3D_Shaders + NDEBUG;_CONSOLE;_LIB;CRC32C_STATIC=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1;_USRDLL;%(PreprocessorDefinitions) MultiThreaded + + Console true true true - d3dcompiler.lib;d3d9.lib;%(AdditionalDependencies) + d3dcompiler.lib;d3dx9.lib;%(AdditionalDependencies) - xcopy "$(WindowsSdkDir)redist\d3d\x64\d3dcompiler_47.dll" "$(TargetDir)" /E /Y - - + xcopy "$(WindowsSdkDir)redist\d3d\x64\d3dcompiler_47.dll" "$(TargetDir)" /E /Y Copy D3Dcompiler_46.dll @@ -306,25 +290,15 @@ - - - - - - - - - - {258d0ad2-b762-41e3-a0c1-cf831d859da4} - - - {59a9b0c6-8302-48a9-96e0-126fb32fb9ed} + + {00b6ba42-4050-488d-91be-a8cd7adaeb87} + true diff --git a/cmd_Decompiler/cmd_Decompiler.vcxproj.filters b/cmd_Decompiler/cmd_Decompiler.vcxproj.filters new file mode 100644 index 000000000..cc448e3ec --- /dev/null +++ b/cmd_Decompiler/cmd_Decompiler.vcxproj.filters @@ -0,0 +1,26 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + + + + + + Header Files + + + + + Source Files + + + \ No newline at end of file diff --git a/cmd_Decompiler/targetver.h b/cmd_Decompiler/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/cmd_Decompiler/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/crc32c-hw-1.0.5/CRC32C-HW.vcxproj b/crc32c-hw-1.0.5/CRC32C-HW.vcxproj new file mode 100644 index 000000000..eb3685551 --- /dev/null +++ b/crc32c-hw-1.0.5/CRC32C-HW.vcxproj @@ -0,0 +1,164 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + 16.0 + Win32Proj + {d05da837-8c74-40e0-8255-1345ca449648} + CRC32CHW + 10.0.17763.0 + crc32c-hw + + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(ProjectDir)include;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(ProjectDir)include;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + true + $(ProjectDir)include;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + false + $(ProjectDir)include;$(VC_IncludePath);$(WindowsSDK_IncludePath); + + + + Level3 + true + CRC32C_STATIC;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + + + + + true + + + + + Level3 + true + true + true + CRC32C_STATIC;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreaded + + + + + true + true + true + + + + + Level3 + true + CRC32C_STATIC;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + + + + + true + + + + + Level3 + true + true + true + CRC32C_STATIC;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreaded + + + + + true + true + true + + + + + + \ No newline at end of file diff --git a/crc32c-hw-1.0.5/CRC32C-HW.vcxproj.filters b/crc32c-hw-1.0.5/CRC32C-HW.vcxproj.filters new file mode 100644 index 000000000..38c702080 --- /dev/null +++ b/crc32c-hw-1.0.5/CRC32C-HW.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/crc32c-hw-1.0.5/src/generated-constants.cpp b/crc32c-hw-1.0.5/src/generated-constants.cpp index 048a144af..74afd06f6 100644 --- a/crc32c-hw-1.0.5/src/generated-constants.cpp +++ b/crc32c-hw-1.0.5/src/generated-constants.cpp @@ -1,3 +1,5 @@ +#include + #define POLY 0x82f63b78 #define LONG_SHIFT 8192 #define SHORT_SHIFT 256 diff --git a/util.h b/util.h index 2b8711bd9..457e4178e 100644 --- a/util.h +++ b/util.h @@ -16,11 +16,9 @@ #include "version.h" #include "log.h" -#include "crc32c.h" +#include "crc32c-hw-1.0.5/include/crc32c.h" #include "util_min.h" -#include "D3D_Shaders\stdafx.h" - #if MIGOTO_DX == 11 #include "DirectX11\HookedDevice.h" #include "DirectX11\HookedContext.h" @@ -750,121 +748,6 @@ static const char* type_name_dx9(IUnknown *object) #endif // MIGOTO_DX == 9 // ----------------------------------------------------------------------------------------------- -// Common routine to handle disassembling binary shaders to asm text. -// This is used whenever we need the Asm text. - - -// New version using Flugan's wrapper around D3DDisassemble to replace the -// problematic %f floating point values with %.9e, which is enough that a 32bit -// floating point value will be reproduced exactly: -static string BinaryToAsmText(const void *pShaderBytecode, size_t BytecodeLength, - bool patch_cb_offsets, - bool disassemble_undecipherable_data = true, - int hexdump = 0, bool d3dcompiler_46_compat = true) -{ - string comments; - vector byteCode(BytecodeLength); - vector disassembly; - HRESULT r; - - comments = "// using 3Dmigoto v" + string(VER_FILE_VERSION_STR) + " on " + LogTime() + "//\n"; - memcpy(byteCode.data(), pShaderBytecode, BytecodeLength); - -#if MIGOTO_DX == 9 - r = disassemblerDX9(&byteCode, &disassembly, comments.c_str()); -#elif MIGOTO_DX == 11 - r = disassembler(&byteCode, &disassembly, comments.c_str(), hexdump, - d3dcompiler_46_compat, disassemble_undecipherable_data, patch_cb_offsets); -#endif // MIGOTO_DX - if (FAILED(r)) { - LogInfo(" disassembly failed. Error: %x\n", r); - return ""; - } - - return string(disassembly.begin(), disassembly.end()); -} - -// Get the shader model from the binary shader bytecode. -// -// This used to disassemble, then search for the text string, but if we are going to -// do all that work, we might as well use the James-Jones decoder to get it. -// The other reason to do it this way is that we have seen multiple shader versions -// in Unity games, and the old technique of searching for the first uncommented line -// would fail. - -// This is an interesting idea, but doesn't work well here because of project structure. -// for the moment, let's leave this here, but use the disassemble search approach. - -//static string GetShaderModel(const void *pShaderBytecode) -//{ -// Shader *shader = DecodeDXBC((uint32_t*)pShaderBytecode); -// if (shader == nullptr) -// return ""; -// -// string shaderModel; -// -// switch (shader->eShaderType) -// { -// case PIXEL_SHADER: -// shaderModel = "ps"; -// break; -// case VERTEX_SHADER: -// shaderModel = "vs"; -// break; -// case GEOMETRY_SHADER: -// shaderModel = "gs"; -// break; -// case HULL_SHADER: -// shaderModel = "hs"; -// break; -// case DOMAIN_SHADER: -// shaderModel = "ds"; -// break; -// case COMPUTE_SHADER: -// shaderModel = "cs"; -// break; -// default: -// return ""; // Failure. -// } -// -// shaderModel += "_" + shader->ui32MajorVersion; -// shaderModel += "_" + shader->ui32MinorVersion; -// -// delete shader; -// -// return shaderModel; -//} - -static string GetShaderModel(const void *pShaderBytecode, size_t bytecodeLength) -{ - string asmText = BinaryToAsmText(pShaderBytecode, bytecodeLength, false); - if (asmText.empty()) - return ""; - - // Read shader model. This is the first not commented line. - char *pos = (char *)asmText.data(); - char *end = pos + asmText.size(); - while ((pos[0] == '/' || pos[0] == '\n') && pos < end) - { - while (pos[0] != 0x0a && pos < end) pos++; - pos++; - } - // Extract model. - char *eol = pos; - while (eol[0] != 0x0a && pos < end) eol++; - string shaderModel(pos, eol); - - return shaderModel; -} - -// Create a text file containing text for the string specified. Can be Asm or HLSL. -// If the file already exists and the caller did not specify overwrite (used -// for reassembled text), return that as an error to avoid overwriting previous -// work. - -// We previously would overwrite the file only after checking if the contents were different, -// this relaxes that to just being same file name. - static HRESULT CreateTextFile(wchar_t *fullPath, string *asmText, bool overwrite) { FILE *f; @@ -889,34 +772,6 @@ static HRESULT CreateTextFile(wchar_t *fullPath, string *asmText, bool overwrite return S_OK; } -// Get shader type from asm, first non-commented line. CS, PS, VS. -// Not sure this works on weird Unity variant with embedded types. - - -// Specific variant to name files consistently, so we know they are Asm text. - -static HRESULT CreateAsmTextFile(wchar_t* fileDirectory, UINT64 hash, const wchar_t* shaderType, - const void *pShaderBytecode, size_t bytecodeLength, bool patch_cb_offsets) -{ - string asmText = BinaryToAsmText(pShaderBytecode, bytecodeLength, patch_cb_offsets); - if (asmText.empty()) - { - return E_OUTOFMEMORY; - } - - wchar_t fullPath[MAX_PATH]; - swprintf_s(fullPath, MAX_PATH, L"%ls\\%016llx-%ls.txt", fileDirectory, hash, shaderType); - - HRESULT hr = CreateTextFile(fullPath, &asmText, false); - - if (SUCCEEDED(hr)) - LogInfoW(L" storing disassembly to %s\n", fullPath); - else - LogInfoW(L" error: %x, storing disassembly to %s\n", hr, fullPath); - - return hr; -} - // Specific variant to name files, so we know they are HLSL text. static HRESULT CreateHLSLTextFile(UINT64 hash, string hlslText)