diff --git a/source-code/PD-Loader.sln b/source-code/PD-Loader.sln index ee6d287..ae1f02a 100644 --- a/source-code/PD-Loader.sln +++ b/source-code/PD-Loader.sln @@ -19,6 +19,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DivaSound", "source\plugins EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DivaMovie", "source\plugins\DivaMovie\DivaMovie.vcxproj", "{1994C586-F73B-4EF2-BA3E-2A0FC3034B1A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ShaderPatch", "source\plugins\ShaderPatch\ShaderPatch.vcxproj", "{C07E495E-A16F-48FA-80E4-0296B5234F0B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -87,6 +89,14 @@ Global {1994C586-F73B-4EF2-BA3E-2A0FC3034B1A}.Release|x64.ActiveCfg = Release|x64 {1994C586-F73B-4EF2-BA3E-2A0FC3034B1A}.Release|x64.Build.0 = Release|x64 {1994C586-F73B-4EF2-BA3E-2A0FC3034B1A}.Release|x86.ActiveCfg = Release|x64 + {C07E495E-A16F-48FA-80E4-0296B5234F0B}.Debug|x64.ActiveCfg = Debug|x64 + {C07E495E-A16F-48FA-80E4-0296B5234F0B}.Debug|x64.Build.0 = Debug|x64 + {C07E495E-A16F-48FA-80E4-0296B5234F0B}.Debug|x86.ActiveCfg = Debug|Win32 + {C07E495E-A16F-48FA-80E4-0296B5234F0B}.Debug|x86.Build.0 = Debug|Win32 + {C07E495E-A16F-48FA-80E4-0296B5234F0B}.Release|x64.ActiveCfg = Release|x64 + {C07E495E-A16F-48FA-80E4-0296B5234F0B}.Release|x64.Build.0 = Release|x64 + {C07E495E-A16F-48FA-80E4-0296B5234F0B}.Release|x86.ActiveCfg = Release|Win32 + {C07E495E-A16F-48FA-80E4-0296B5234F0B}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/source-code/data/plugins/ShaderPatch.ini b/source-code/data/plugins/ShaderPatch.ini new file mode 100644 index 0000000..3b9e9ca --- /dev/null +++ b/source-code/data/plugins/ShaderPatch.ini @@ -0,0 +1,69 @@ +[Config] +# Patches to remove glitching with modern GPUs. +# Appropriate patches will automatically be selected based on your GPU. +Compat=1 + +# Lyb's toon shader improvements (24 sept 2019) +# Toon: Adjusts toon shader lighting +Toon=0 +# Specular Multiplier +Toon_Val1=0.9 +# Specular Offset +Toon_Val2=-0.5 + +# Lyb's toon shader improvements (24 sept 2019) +# Toon_Eyes: Adjusts toon shader eyes +Toon_Eyes=0 + +# Lyb's toon shader improvements (24 sept 2019) +# Toon_Hair: Adjusts toon shader hair +Toon_Hair=0 +# Diffuse Brightness +Toon_Hair_Val1=1.25 + +# Lyb's toon shader improvements (24 sept 2019) +# Toon_Lines: Adjusts toon shader outlines +Toon_Lines=0 +# ??? +Toon_Lines_Val1=0.75 +# Thickness Multiplier(?) +Toon_Lines_Val2=0.75 +# Thickness Offset(?) +Toon_Lines_Val3=0.75 + +# Debug patches: +# Nametags +# Adds comments with the shader file name to the shader text. Useful for debugging issues. +# `nametags_val1` and `nametags_val2` are a dirty hack to hide this in launcher (options ending in _val. must belong to a parent to be displayed) +# `nametags_val2` is a bit faster, but the tags are placed at the end of the file and you may not like this +Nametags_Val1=0 +Nametags_Val2=0 + +[Patches] +# Compatibility patches: +# Star Story (and etc.) stage corruption (Maxwell+) +blinn_per_vert\.0010010[23]00[01]\.fp=arch:GP,TU,GV,GM||cfg:compat||from:TEX tex_col, a_tex_color0, texture\[0\], 2D; ALIAS||to:TEX tex_col, a_tex_color0, texture[0], 2D; MUL tex_col, 1, tex_col; ALIAS +# Turing shading lines +esm_gauss\.0\.fp=arch:TU||cfg:compat||from:RCP sum.y, sum.y;(\r?\n) MUL||to:RCP sum.y, sum.y; ADD sum.x, sum.x, 0.000300;$1 MUL +# Turing NPR cloth noise +cloth_npr1\.fp=arch:TU||cfg:compat||from:SSG _tmp0.yw, ybr.xxzz;||to:TEMP _tmpForSSG; SGE _tmpForSSG.xz, ybr.xxzz, 0; SUB _tmpForSSG.xz, _tmpForSSG.xxzz, 1; SGT _tmpForSSG.yw, ybr.xxzz, 0; ADD _tmp0.yw, _tmpForSSG.xxzz, _tmpForSSG.yyww; + +# Lyb's toon shader improvements: +.*cloth_npr.*=cfg:toon||from:MAD tmp.y, lc.z, 1.2, -0.5;||to:MAD tmp.y, lc.z, , ; +.*skin_default.*=cfg:toon||from:MAD diff.xyz, spec, spec_ratio, diff;||to: +.*eye.*=cfg:toon_eyes||from:ADD o_color_f0.w, diff.x, diff.y;||to: +.*hair_npr1.*=cfg:toon_hair||from:MUL spec.x, tmp.x, 0.7;||to:MUL spec.x, tmp.x, 0.7; MUL diff, diff, ; +.*tone_map_npr1.*=cfg:toon_lines||from:MUL density.y, density.y, 0.25;||to:MUL density.y, density.y, ; +.*tone_map_npr1.*=cfg:toon_lines||from:MAD density.w, density.x, 0.7, 0.25;||to:MAD density.w, density.x, , ; + +# Debug patches: +# Nametags +# Adds comments with the shader file name to the shader text. Useful for debugging issues +# `nametags_val1` and `nametags_val2` are a dirty hack to hide this in launcher (options ending in _val. must belong to a parent to be displayed) +# `nametags_val2` is a bit faster, but the tags are placed at the end of the file and you may not like this +# Notes: +# * `(\r?\n)` is used to capture the line ending type used and ensure we're at the start of a line +# * `[^!]` ensures the comment is inserted after all start program lines (not sure if this even matters) +# * `[\s\S]` matches all characters *including* new lines +.*=cfg:nametags_val1||from:(\r?\n)([^!][\s\S]*)||to:$1#$1$2 +.*=cfg:nametags_val2||from:[\s\S]*?(\r?\n)[\s\S]*||to:$&$1# \ No newline at end of file diff --git a/source-code/source/plugins/DivaSound/src/PluginConfigApi.h b/source-code/dependencies/PluginConfigApi/PluginConfigApi.h similarity index 91% rename from source-code/source/plugins/DivaSound/src/PluginConfigApi.h rename to source-code/dependencies/PluginConfigApi/PluginConfigApi.h index d0ffd94..bb39dca 100644 --- a/source-code/source/plugins/DivaSound/src/PluginConfigApi.h +++ b/source-code/dependencies/PluginConfigApi/PluginConfigApi.h @@ -165,4 +165,12 @@ namespace PluginConfig PluginConfigOption* options; }; #pragma pack(pop) + + // note: this is actually the build date of PluginConfigApi -- make sure this isn't cached for CI + extern "C" __declspec(dllexport) LPCWSTR GetBuildDate(void) + { + WCHAR utf16buf[128]; + MultiByteToWideChar(CP_UTF8, 0, __DATE__, -1, utf16buf, 128); + return _wcsdup(utf16buf); + } } \ No newline at end of file diff --git a/source-code/source/plugins/DivaSound/DivaSound.vcxproj b/source-code/source/plugins/DivaSound/DivaSound.vcxproj index d49c39a..2e1569b 100644 --- a/source-code/source/plugins/DivaSound/DivaSound.vcxproj +++ b/source-code/source/plugins/DivaSound/DivaSound.vcxproj @@ -43,13 +43,9 @@ - $(VC_IncludePath);$(WindowsSDK_IncludePath);detours/include;miniaudio;bassasio - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;detours/lib;bassasio .dva - $(VC_IncludePath);$(WindowsSDK_IncludePath);detours/include;miniaudio;bassasio - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;detours/lib;bassasio .dva @@ -57,9 +53,11 @@ Level3 Disabled true + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\detours\include;miniaudio;bassasio detours.lib;syelog.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + ..\..\..\dependencies\detours\lib;bassasio @@ -70,11 +68,13 @@ true true stdcpp17 + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\detours\include;miniaudio;bassasio true true detours.lib;syelog.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + ..\..\..\dependencies\detours\lib;bassasio @@ -82,7 +82,6 @@ - diff --git a/source-code/source/plugins/DivaSound/DivaSound.vcxproj.filters b/source-code/source/plugins/DivaSound/DivaSound.vcxproj.filters index 99a4edb..3d3bf67 100644 --- a/source-code/source/plugins/DivaSound/DivaSound.vcxproj.filters +++ b/source-code/source/plugins/DivaSound/DivaSound.vcxproj.filters @@ -23,8 +23,5 @@ Header Files - - Header Files - \ No newline at end of file diff --git a/source-code/source/plugins/DivaSound/detours/include/detours.h b/source-code/source/plugins/DivaSound/detours/include/detours.h deleted file mode 100644 index 29e59c4..0000000 --- a/source-code/source/plugins/DivaSound/detours/include/detours.h +++ /dev/null @@ -1,1108 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// Core Detours Functionality (detours.h of detours.lib) -// -// Microsoft Research Detours Package, Version 4.0.1 -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// - -#pragma once -#ifndef _DETOURS_H_ -#define _DETOURS_H_ - -#define DETOURS_VERSION 0x4c0c1 // 0xMAJORcMINORcPATCH - -////////////////////////////////////////////////////////////////////////////// -// - -#ifdef DETOURS_INTERNAL - -#define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS 1 -#define _ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE 1 - -#pragma warning(disable:4068) // unknown pragma (suppress) - -#if _MSC_VER >= 1900 -#pragma warning(push) -#pragma warning(disable:4091) // empty typedef -#endif - -#include -#if (_MSC_VER < 1310) -#else -#pragma warning(push) -#if _MSC_VER > 1400 -#pragma warning(disable:6102 6103) // /analyze warnings -#endif -#include -#pragma warning(pop) -#endif - -#endif // DETOURS_INTERNAL - -////////////////////////////////////////////////////////////////////////////// -// - -#undef DETOURS_X64 -#undef DETOURS_X86 -#undef DETOURS_IA64 -#undef DETOURS_ARM -#undef DETOURS_ARM64 -#undef DETOURS_BITS -#undef DETOURS_32BIT -#undef DETOURS_64BIT - -#if defined(_X86_) -#define DETOURS_X86 -#define DETOURS_OPTION_BITS 64 - -#elif defined(_AMD64_) -#define DETOURS_X64 -#define DETOURS_OPTION_BITS 32 - -#elif defined(_IA64_) -#define DETOURS_IA64 -#define DETOURS_OPTION_BITS 32 - -#elif defined(_ARM_) -#define DETOURS_ARM - -#elif defined(_ARM64_) -#define DETOURS_ARM64 - -#else -#error Unknown architecture (x86, amd64, ia64, arm, arm64) -#endif - -#ifdef _WIN64 -#undef DETOURS_32BIT -#define DETOURS_64BIT 1 -#define DETOURS_BITS 64 -// If all 64bit kernels can run one and only one 32bit architecture. -//#define DETOURS_OPTION_BITS 32 -#else -#define DETOURS_32BIT 1 -#undef DETOURS_64BIT -#define DETOURS_BITS 32 -// If all 64bit kernels can run one and only one 32bit architecture. -//#define DETOURS_OPTION_BITS 32 -#endif - -#define VER_DETOURS_BITS DETOUR_STRINGIFY(DETOURS_BITS) - -////////////////////////////////////////////////////////////////////////////// -// - -#if (_MSC_VER < 1299) -//typedef LONG LONG_PTR; -//typedef ULONG ULONG_PTR; -#endif - -///////////////////////////////////////////////// SAL 2.0 Annotations w/o SAL. -// -// These definitions are include so that Detours will build even if the -// compiler doesn't have full SAL 2.0 support. -// -#ifndef DETOURS_DONT_REMOVE_SAL_20 - -#ifdef DETOURS_TEST_REMOVE_SAL_20 -#undef _Analysis_assume_ -#undef _Benign_race_begin_ -#undef _Benign_race_end_ -#undef _Field_range_ -#undef _Field_size_ -#undef _In_ -#undef _In_bytecount_ -#undef _In_count_ -#undef _In_opt_ -#undef _In_opt_bytecount_ -#undef _In_opt_count_ -#undef _In_opt_z_ -#undef _In_range_ -#undef _In_reads_ -#undef _In_reads_bytes_ -#undef _In_reads_opt_ -#undef _In_reads_opt_bytes_ -#undef _In_reads_or_z_ -#undef _In_z_ -#undef _Inout_ -#undef _Inout_opt_ -#undef _Inout_z_count_ -#undef _Out_ -#undef _Out_opt_ -#undef _Out_writes_ -#undef _Outptr_result_maybenull_ -#undef _Readable_bytes_ -#undef _Success_ -#undef _Writable_bytes_ -#undef _Pre_notnull_ -#endif - -#if defined(_Deref_out_opt_z_) && !defined(_Outptr_result_maybenull_) -#define _Outptr_result_maybenull_ _Deref_out_opt_z_ -#endif - -#if defined(_In_count_) && !defined(_In_reads_) -#define _In_reads_(x) _In_count_(x) -#endif - -#if defined(_In_opt_count_) && !defined(_In_reads_opt_) -#define _In_reads_opt_(x) _In_opt_count_(x) -#endif - -#if defined(_In_opt_bytecount_) && !defined(_In_reads_opt_bytes_) -#define _In_reads_opt_bytes_(x) _In_opt_bytecount_(x) -#endif - -#if defined(_In_bytecount_) && !defined(_In_reads_bytes_) -#define _In_reads_bytes_(x) _In_bytecount_(x) -#endif - -#ifndef _In_ -#define _In_ -#endif - -#ifndef _In_bytecount_ -#define _In_bytecount_(x) -#endif - -#ifndef _In_count_ -#define _In_count_(x) -#endif - -#ifndef _In_opt_ -#define _In_opt_ -#endif - -#ifndef _In_opt_bytecount_ -#define _In_opt_bytecount_(x) -#endif - -#ifndef _In_opt_count_ -#define _In_opt_count_(x) -#endif - -#ifndef _In_opt_z_ -#define _In_opt_z_ -#endif - -#ifndef _In_range_ -#define _In_range_(x,y) -#endif - -#ifndef _In_reads_ -#define _In_reads_(x) -#endif - -#ifndef _In_reads_bytes_ -#define _In_reads_bytes_(x) -#endif - -#ifndef _In_reads_opt_ -#define _In_reads_opt_(x) -#endif - -#ifndef _In_reads_opt_bytes_ -#define _In_reads_opt_bytes_(x) -#endif - -#ifndef _In_reads_or_z_ -#define _In_reads_or_z_ -#endif - -#ifndef _In_z_ -#define _In_z_ -#endif - -#ifndef _Inout_ -#define _Inout_ -#endif - -#ifndef _Inout_opt_ -#define _Inout_opt_ -#endif - -#ifndef _Inout_z_count_ -#define _Inout_z_count_(x) -#endif - -#ifndef _Out_ -#define _Out_ -#endif - -#ifndef _Out_opt_ -#define _Out_opt_ -#endif - -#ifndef _Out_writes_ -#define _Out_writes_(x) -#endif - -#ifndef _Outptr_result_maybenull_ -#define _Outptr_result_maybenull_ -#endif - -#ifndef _Writable_bytes_ -#define _Writable_bytes_(x) -#endif - -#ifndef _Readable_bytes_ -#define _Readable_bytes_(x) -#endif - -#ifndef _Success_ -#define _Success_(x) -#endif - -#ifndef _Pre_notnull_ -#define _Pre_notnull_ -#endif - -#ifdef DETOURS_INTERNAL - -#pragma warning(disable:4615) // unknown warning type (suppress with older compilers) - -#ifndef _Benign_race_begin_ -#define _Benign_race_begin_ -#endif - -#ifndef _Benign_race_end_ -#define _Benign_race_end_ -#endif - -#ifndef _Field_size_ -#define _Field_size_(x) -#endif - -#ifndef _Field_range_ -#define _Field_range_(x,y) -#endif - -#ifndef _Analysis_assume_ -#define _Analysis_assume_(x) -#endif - -#endif // DETOURS_INTERNAL -#endif // DETOURS_DONT_REMOVE_SAL_20 - -////////////////////////////////////////////////////////////////////////////// -// -#ifndef GUID_DEFINED -#define GUID_DEFINED -typedef struct _GUID -{ - DWORD Data1; - WORD Data2; - WORD Data3; - BYTE Data4[ 8 ]; -} GUID; - -#ifdef INITGUID -#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ - const GUID name \ - = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } -#else -#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ - const GUID name -#endif // INITGUID -#endif // !GUID_DEFINED - -#if defined(__cplusplus) -#ifndef _REFGUID_DEFINED -#define _REFGUID_DEFINED -#define REFGUID const GUID & -#endif // !_REFGUID_DEFINED -#else // !__cplusplus -#ifndef _REFGUID_DEFINED -#define _REFGUID_DEFINED -#define REFGUID const GUID * const -#endif // !_REFGUID_DEFINED -#endif // !__cplusplus - -#ifndef ARRAYSIZE -#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) -#endif - -// -////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/////////////////////////////////////////////////// Instruction Target Macros. -// -#define DETOUR_INSTRUCTION_TARGET_NONE ((PVOID)0) -#define DETOUR_INSTRUCTION_TARGET_DYNAMIC ((PVOID)(LONG_PTR)-1) -#define DETOUR_SECTION_HEADER_SIGNATURE 0x00727444 // "Dtr\0" - -extern const GUID DETOUR_EXE_RESTORE_GUID; -extern const GUID DETOUR_EXE_HELPER_GUID; - -#define DETOUR_TRAMPOLINE_SIGNATURE 0x21727444 // Dtr! -typedef struct _DETOUR_TRAMPOLINE DETOUR_TRAMPOLINE, *PDETOUR_TRAMPOLINE; - -/////////////////////////////////////////////////////////// Binary Structures. -// -#pragma pack(push, 8) -typedef struct _DETOUR_SECTION_HEADER -{ - DWORD cbHeaderSize; - DWORD nSignature; - DWORD nDataOffset; - DWORD cbDataSize; - - DWORD nOriginalImportVirtualAddress; - DWORD nOriginalImportSize; - DWORD nOriginalBoundImportVirtualAddress; - DWORD nOriginalBoundImportSize; - - DWORD nOriginalIatVirtualAddress; - DWORD nOriginalIatSize; - DWORD nOriginalSizeOfImage; - DWORD cbPrePE; - - DWORD nOriginalClrFlags; - DWORD reserved1; - DWORD reserved2; - DWORD reserved3; - - // Followed by cbPrePE bytes of data. -} DETOUR_SECTION_HEADER, *PDETOUR_SECTION_HEADER; - -typedef struct _DETOUR_SECTION_RECORD -{ - DWORD cbBytes; - DWORD nReserved; - GUID guid; -} DETOUR_SECTION_RECORD, *PDETOUR_SECTION_RECORD; - -typedef struct _DETOUR_CLR_HEADER -{ - // Header versioning - ULONG cb; - USHORT MajorRuntimeVersion; - USHORT MinorRuntimeVersion; - - // Symbol table and startup information - IMAGE_DATA_DIRECTORY MetaData; - ULONG Flags; - - // Followed by the rest of the IMAGE_COR20_HEADER -} DETOUR_CLR_HEADER, *PDETOUR_CLR_HEADER; - -typedef struct _DETOUR_EXE_RESTORE -{ - DWORD cb; - DWORD cbidh; - DWORD cbinh; - DWORD cbclr; - - PBYTE pidh; - PBYTE pinh; - PBYTE pclr; - - IMAGE_DOS_HEADER idh; - union { - IMAGE_NT_HEADERS inh; // all environments have this -#ifdef IMAGE_NT_OPTIONAL_HDR32_MAGIC // some environments do not have this - IMAGE_NT_HEADERS32 inh32; -#endif -#ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC // some environments do not have this - IMAGE_NT_HEADERS64 inh64; -#endif -#ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC // some environments do not have this - BYTE raw[sizeof(IMAGE_NT_HEADERS64) + - sizeof(IMAGE_SECTION_HEADER) * 32]; -#else - BYTE raw[0x108 + sizeof(IMAGE_SECTION_HEADER) * 32]; -#endif - }; - DETOUR_CLR_HEADER clr; - -} DETOUR_EXE_RESTORE, *PDETOUR_EXE_RESTORE; - -#ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC -C_ASSERT(sizeof(IMAGE_NT_HEADERS64) == 0x108); -#endif - -// The size can change, but assert for clarity due to the muddying #ifdefs. -#ifdef _WIN64 -C_ASSERT(sizeof(DETOUR_EXE_RESTORE) == 0x688); -#else -C_ASSERT(sizeof(DETOUR_EXE_RESTORE) == 0x678); -#endif - -typedef struct _DETOUR_EXE_HELPER -{ - DWORD cb; - DWORD pid; - DWORD nDlls; - CHAR rDlls[4]; -} DETOUR_EXE_HELPER, *PDETOUR_EXE_HELPER; - -#pragma pack(pop) - -#define DETOUR_SECTION_HEADER_DECLARE(cbSectionSize) \ -{ \ - sizeof(DETOUR_SECTION_HEADER),\ - DETOUR_SECTION_HEADER_SIGNATURE,\ - sizeof(DETOUR_SECTION_HEADER),\ - (cbSectionSize),\ - \ - 0,\ - 0,\ - 0,\ - 0,\ - \ - 0,\ - 0,\ - 0,\ - 0,\ -} - -/////////////////////////////////////////////////////////////// Helper Macros. -// -#define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x) -#define DETOURS_STRINGIFY_(x) #x - -///////////////////////////////////////////////////////////// Binary Typedefs. -// -typedef BOOL (CALLBACK *PF_DETOUR_BINARY_BYWAY_CALLBACK)( - _In_opt_ PVOID pContext, - _In_opt_ LPCSTR pszFile, - _Outptr_result_maybenull_ LPCSTR *ppszOutFile); - -typedef BOOL (CALLBACK *PF_DETOUR_BINARY_FILE_CALLBACK)( - _In_opt_ PVOID pContext, - _In_ LPCSTR pszOrigFile, - _In_ LPCSTR pszFile, - _Outptr_result_maybenull_ LPCSTR *ppszOutFile); - -typedef BOOL (CALLBACK *PF_DETOUR_BINARY_SYMBOL_CALLBACK)( - _In_opt_ PVOID pContext, - _In_ ULONG nOrigOrdinal, - _In_ ULONG nOrdinal, - _Out_ ULONG *pnOutOrdinal, - _In_opt_ LPCSTR pszOrigSymbol, - _In_opt_ LPCSTR pszSymbol, - _Outptr_result_maybenull_ LPCSTR *ppszOutSymbol); - -typedef BOOL (CALLBACK *PF_DETOUR_BINARY_COMMIT_CALLBACK)( - _In_opt_ PVOID pContext); - -typedef BOOL (CALLBACK *PF_DETOUR_ENUMERATE_EXPORT_CALLBACK)(_In_opt_ PVOID pContext, - _In_ ULONG nOrdinal, - _In_opt_ LPCSTR pszName, - _In_opt_ PVOID pCode); - -typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FILE_CALLBACK)(_In_opt_ PVOID pContext, - _In_opt_ HMODULE hModule, - _In_opt_ LPCSTR pszFile); - -typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK)(_In_opt_ PVOID pContext, - _In_ DWORD nOrdinal, - _In_opt_ LPCSTR pszFunc, - _In_opt_ PVOID pvFunc); - -// Same as PF_DETOUR_IMPORT_FUNC_CALLBACK but extra indirection on last parameter. -typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK_EX)(_In_opt_ PVOID pContext, - _In_ DWORD nOrdinal, - _In_opt_ LPCSTR pszFunc, - _In_opt_ PVOID* ppvFunc); - -typedef VOID * PDETOUR_BINARY; -typedef VOID * PDETOUR_LOADED_BINARY; - -//////////////////////////////////////////////////////////// Transaction APIs. -// -LONG WINAPI DetourTransactionBegin(VOID); -LONG WINAPI DetourTransactionAbort(VOID); -LONG WINAPI DetourTransactionCommit(VOID); -LONG WINAPI DetourTransactionCommitEx(_Out_opt_ PVOID **pppFailedPointer); - -LONG WINAPI DetourUpdateThread(_In_ HANDLE hThread); - -LONG WINAPI DetourAttach(_Inout_ PVOID *ppPointer, - _In_ PVOID pDetour); - -LONG WINAPI DetourAttachEx(_Inout_ PVOID *ppPointer, - _In_ PVOID pDetour, - _Out_opt_ PDETOUR_TRAMPOLINE *ppRealTrampoline, - _Out_opt_ PVOID *ppRealTarget, - _Out_opt_ PVOID *ppRealDetour); - -LONG WINAPI DetourDetach(_Inout_ PVOID *ppPointer, - _In_ PVOID pDetour); - -BOOL WINAPI DetourSetIgnoreTooSmall(_In_ BOOL fIgnore); -BOOL WINAPI DetourSetRetainRegions(_In_ BOOL fRetain); -PVOID WINAPI DetourSetSystemRegionLowerBound(_In_ PVOID pSystemRegionLowerBound); -PVOID WINAPI DetourSetSystemRegionUpperBound(_In_ PVOID pSystemRegionUpperBound); - -////////////////////////////////////////////////////////////// Code Functions. -// -PVOID WINAPI DetourFindFunction(_In_ LPCSTR pszModule, - _In_ LPCSTR pszFunction); -PVOID WINAPI DetourCodeFromPointer(_In_ PVOID pPointer, - _Out_opt_ PVOID *ppGlobals); -PVOID WINAPI DetourCopyInstruction(_In_opt_ PVOID pDst, - _Inout_opt_ PVOID *ppDstPool, - _In_ PVOID pSrc, - _Out_opt_ PVOID *ppTarget, - _Out_opt_ LONG *plExtra); -BOOL WINAPI DetourSetCodeModule(_In_ HMODULE hModule, - _In_ BOOL fLimitReferencesToModule); -PVOID WINAPI DetourAllocateRegionWithinJumpBounds(_In_ LPCVOID pbTarget, - _Out_ PDWORD pcbAllocatedSize); - -///////////////////////////////////////////////////// Loaded Binary Functions. -// -HMODULE WINAPI DetourGetContainingModule(_In_ PVOID pvAddr); -HMODULE WINAPI DetourEnumerateModules(_In_opt_ HMODULE hModuleLast); -PVOID WINAPI DetourGetEntryPoint(_In_opt_ HMODULE hModule); -ULONG WINAPI DetourGetModuleSize(_In_opt_ HMODULE hModule); -BOOL WINAPI DetourEnumerateExports(_In_ HMODULE hModule, - _In_opt_ PVOID pContext, - _In_ PF_DETOUR_ENUMERATE_EXPORT_CALLBACK pfExport); -BOOL WINAPI DetourEnumerateImports(_In_opt_ HMODULE hModule, - _In_opt_ PVOID pContext, - _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, - _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc); - -BOOL WINAPI DetourEnumerateImportsEx(_In_opt_ HMODULE hModule, - _In_opt_ PVOID pContext, - _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile, - _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK_EX pfImportFuncEx); - -_Writable_bytes_(*pcbData) -_Readable_bytes_(*pcbData) -_Success_(return != NULL) -PVOID WINAPI DetourFindPayload(_In_opt_ HMODULE hModule, - _In_ REFGUID rguid, - _Out_ DWORD *pcbData); - -_Writable_bytes_(*pcbData) -_Readable_bytes_(*pcbData) -_Success_(return != NULL) -PVOID WINAPI DetourFindPayloadEx(_In_ REFGUID rguid, - _Out_ DWORD * pcbData); - -DWORD WINAPI DetourGetSizeOfPayloads(_In_opt_ HMODULE hModule); - -///////////////////////////////////////////////// Persistent Binary Functions. -// - -PDETOUR_BINARY WINAPI DetourBinaryOpen(_In_ HANDLE hFile); - -_Writable_bytes_(*pcbData) -_Readable_bytes_(*pcbData) -_Success_(return != NULL) -PVOID WINAPI DetourBinaryEnumeratePayloads(_In_ PDETOUR_BINARY pBinary, - _Out_opt_ GUID *pGuid, - _Out_ DWORD *pcbData, - _Inout_ DWORD *pnIterator); - -_Writable_bytes_(*pcbData) -_Readable_bytes_(*pcbData) -_Success_(return != NULL) -PVOID WINAPI DetourBinaryFindPayload(_In_ PDETOUR_BINARY pBinary, - _In_ REFGUID rguid, - _Out_ DWORD *pcbData); - -PVOID WINAPI DetourBinarySetPayload(_In_ PDETOUR_BINARY pBinary, - _In_ REFGUID rguid, - _In_reads_opt_(cbData) PVOID pData, - _In_ DWORD cbData); -BOOL WINAPI DetourBinaryDeletePayload(_In_ PDETOUR_BINARY pBinary, _In_ REFGUID rguid); -BOOL WINAPI DetourBinaryPurgePayloads(_In_ PDETOUR_BINARY pBinary); -BOOL WINAPI DetourBinaryResetImports(_In_ PDETOUR_BINARY pBinary); -BOOL WINAPI DetourBinaryEditImports(_In_ PDETOUR_BINARY pBinary, - _In_opt_ PVOID pContext, - _In_opt_ PF_DETOUR_BINARY_BYWAY_CALLBACK pfByway, - _In_opt_ PF_DETOUR_BINARY_FILE_CALLBACK pfFile, - _In_opt_ PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbol, - _In_opt_ PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommit); -BOOL WINAPI DetourBinaryWrite(_In_ PDETOUR_BINARY pBinary, _In_ HANDLE hFile); -BOOL WINAPI DetourBinaryClose(_In_ PDETOUR_BINARY pBinary); - -/////////////////////////////////////////////////// Create Process & Load Dll. -// -typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEA)( - _In_opt_ LPCSTR lpApplicationName, - _Inout_opt_ LPSTR lpCommandLine, - _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, - _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, - _In_ BOOL bInheritHandles, - _In_ DWORD dwCreationFlags, - _In_opt_ LPVOID lpEnvironment, - _In_opt_ LPCSTR lpCurrentDirectory, - _In_ LPSTARTUPINFOA lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation); - -typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEW)( - _In_opt_ LPCWSTR lpApplicationName, - _Inout_opt_ LPWSTR lpCommandLine, - _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, - _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, - _In_ BOOL bInheritHandles, - _In_ DWORD dwCreationFlags, - _In_opt_ LPVOID lpEnvironment, - _In_opt_ LPCWSTR lpCurrentDirectory, - _In_ LPSTARTUPINFOW lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation); - -BOOL WINAPI DetourCreateProcessWithDllA(_In_opt_ LPCSTR lpApplicationName, - _Inout_opt_ LPSTR lpCommandLine, - _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, - _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, - _In_ BOOL bInheritHandles, - _In_ DWORD dwCreationFlags, - _In_opt_ LPVOID lpEnvironment, - _In_opt_ LPCSTR lpCurrentDirectory, - _In_ LPSTARTUPINFOA lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation, - _In_ LPCSTR lpDllName, - _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); - -BOOL WINAPI DetourCreateProcessWithDllW(_In_opt_ LPCWSTR lpApplicationName, - _Inout_opt_ LPWSTR lpCommandLine, - _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, - _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, - _In_ BOOL bInheritHandles, - _In_ DWORD dwCreationFlags, - _In_opt_ LPVOID lpEnvironment, - _In_opt_ LPCWSTR lpCurrentDirectory, - _In_ LPSTARTUPINFOW lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation, - _In_ LPCSTR lpDllName, - _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); - -#ifdef UNICODE -#define DetourCreateProcessWithDll DetourCreateProcessWithDllW -#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEW -#else -#define DetourCreateProcessWithDll DetourCreateProcessWithDllA -#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEA -#endif // !UNICODE - -BOOL WINAPI DetourCreateProcessWithDllExA(_In_opt_ LPCSTR lpApplicationName, - _Inout_opt_ LPSTR lpCommandLine, - _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, - _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, - _In_ BOOL bInheritHandles, - _In_ DWORD dwCreationFlags, - _In_opt_ LPVOID lpEnvironment, - _In_opt_ LPCSTR lpCurrentDirectory, - _In_ LPSTARTUPINFOA lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation, - _In_ LPCSTR lpDllName, - _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); - -BOOL WINAPI DetourCreateProcessWithDllExW(_In_opt_ LPCWSTR lpApplicationName, - _Inout_opt_ LPWSTR lpCommandLine, - _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, - _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, - _In_ BOOL bInheritHandles, - _In_ DWORD dwCreationFlags, - _In_opt_ LPVOID lpEnvironment, - _In_opt_ LPCWSTR lpCurrentDirectory, - _In_ LPSTARTUPINFOW lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation, - _In_ LPCSTR lpDllName, - _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); - -#ifdef UNICODE -#define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExW -#else -#define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExA -#endif // !UNICODE - -BOOL WINAPI DetourCreateProcessWithDllsA(_In_opt_ LPCSTR lpApplicationName, - _Inout_opt_ LPSTR lpCommandLine, - _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, - _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, - _In_ BOOL bInheritHandles, - _In_ DWORD dwCreationFlags, - _In_opt_ LPVOID lpEnvironment, - _In_opt_ LPCSTR lpCurrentDirectory, - _In_ LPSTARTUPINFOA lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation, - _In_ DWORD nDlls, - _In_reads_(nDlls) LPCSTR *rlpDlls, - _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); - -BOOL WINAPI DetourCreateProcessWithDllsW(_In_opt_ LPCWSTR lpApplicationName, - _Inout_opt_ LPWSTR lpCommandLine, - _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, - _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, - _In_ BOOL bInheritHandles, - _In_ DWORD dwCreationFlags, - _In_opt_ LPVOID lpEnvironment, - _In_opt_ LPCWSTR lpCurrentDirectory, - _In_ LPSTARTUPINFOW lpStartupInfo, - _Out_ LPPROCESS_INFORMATION lpProcessInformation, - _In_ DWORD nDlls, - _In_reads_(nDlls) LPCSTR *rlpDlls, - _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); - -#ifdef UNICODE -#define DetourCreateProcessWithDlls DetourCreateProcessWithDllsW -#else -#define DetourCreateProcessWithDlls DetourCreateProcessWithDllsA -#endif // !UNICODE - -BOOL WINAPI DetourProcessViaHelperA(_In_ DWORD dwTargetPid, - _In_ LPCSTR lpDllName, - _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); - -BOOL WINAPI DetourProcessViaHelperW(_In_ DWORD dwTargetPid, - _In_ LPCSTR lpDllName, - _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); - -#ifdef UNICODE -#define DetourProcessViaHelper DetourProcessViaHelperW -#else -#define DetourProcessViaHelper DetourProcessViaHelperA -#endif // !UNICODE - -BOOL WINAPI DetourProcessViaHelperDllsA(_In_ DWORD dwTargetPid, - _In_ DWORD nDlls, - _In_reads_(nDlls) LPCSTR *rlpDlls, - _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA); - -BOOL WINAPI DetourProcessViaHelperDllsW(_In_ DWORD dwTargetPid, - _In_ DWORD nDlls, - _In_reads_(nDlls) LPCSTR *rlpDlls, - _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW); - -#ifdef UNICODE -#define DetourProcessViaHelperDlls DetourProcessViaHelperDllsW -#else -#define DetourProcessViaHelperDlls DetourProcessViaHelperDllsA -#endif // !UNICODE - -BOOL WINAPI DetourUpdateProcessWithDll(_In_ HANDLE hProcess, - _In_reads_(nDlls) LPCSTR *rlpDlls, - _In_ DWORD nDlls); - -BOOL WINAPI DetourUpdateProcessWithDllEx(_In_ HANDLE hProcess, - _In_ HMODULE hImage, - _In_ BOOL bIs32Bit, - _In_reads_(nDlls) LPCSTR *rlpDlls, - _In_ DWORD nDlls); - -BOOL WINAPI DetourCopyPayloadToProcess(_In_ HANDLE hProcess, - _In_ REFGUID rguid, - _In_reads_bytes_(cbData) PVOID pvData, - _In_ DWORD cbData); -BOOL WINAPI DetourRestoreAfterWith(VOID); -BOOL WINAPI DetourRestoreAfterWithEx(_In_reads_bytes_(cbData) PVOID pvData, - _In_ DWORD cbData); -BOOL WINAPI DetourIsHelperProcess(VOID); -VOID CALLBACK DetourFinishHelperProcess(_In_ HWND, - _In_ HINSTANCE, - _In_ LPSTR, - _In_ INT); - -// -////////////////////////////////////////////////////////////////////////////// -#ifdef __cplusplus -} -#endif // __cplusplus - -//////////////////////////////////////////////// Detours Internal Definitions. -// -#ifdef __cplusplus -#ifdef DETOURS_INTERNAL - -#define NOTHROW -// #define NOTHROW (nothrow) - -////////////////////////////////////////////////////////////////////////////// -// -#if (_MSC_VER < 1299) -#include -typedef IMAGEHLP_MODULE IMAGEHLP_MODULE64; -typedef PIMAGEHLP_MODULE PIMAGEHLP_MODULE64; -typedef IMAGEHLP_SYMBOL SYMBOL_INFO; -typedef PIMAGEHLP_SYMBOL PSYMBOL_INFO; - -static inline -LONG InterlockedCompareExchange(_Inout_ LONG *ptr, _In_ LONG nval, _In_ LONG oval) -{ - return (LONG)::InterlockedCompareExchange((PVOID*)ptr, (PVOID)nval, (PVOID)oval); -} -#else -#pragma warning(push) -#pragma warning(disable:4091) // empty typedef -#include -#pragma warning(pop) -#endif - -#ifdef IMAGEAPI // defined by DBGHELP.H -typedef LPAPI_VERSION (NTAPI *PF_ImagehlpApiVersionEx)(_In_ LPAPI_VERSION AppVersion); - -typedef BOOL (NTAPI *PF_SymInitialize)(_In_ HANDLE hProcess, - _In_opt_ LPCSTR UserSearchPath, - _In_ BOOL fInvadeProcess); -typedef DWORD (NTAPI *PF_SymSetOptions)(_In_ DWORD SymOptions); -typedef DWORD (NTAPI *PF_SymGetOptions)(VOID); -typedef DWORD64 (NTAPI *PF_SymLoadModule64)(_In_ HANDLE hProcess, - _In_opt_ HANDLE hFile, - _In_ LPSTR ImageName, - _In_opt_ LPSTR ModuleName, - _In_ DWORD64 BaseOfDll, - _In_opt_ DWORD SizeOfDll); -typedef BOOL (NTAPI *PF_SymGetModuleInfo64)(_In_ HANDLE hProcess, - _In_ DWORD64 qwAddr, - _Out_ PIMAGEHLP_MODULE64 ModuleInfo); -typedef BOOL (NTAPI *PF_SymFromName)(_In_ HANDLE hProcess, - _In_ LPSTR Name, - _Out_ PSYMBOL_INFO Symbol); - -typedef struct _DETOUR_SYM_INFO -{ - HANDLE hProcess; - HMODULE hDbgHelp; - PF_ImagehlpApiVersionEx pfImagehlpApiVersionEx; - PF_SymInitialize pfSymInitialize; - PF_SymSetOptions pfSymSetOptions; - PF_SymGetOptions pfSymGetOptions; - PF_SymLoadModule64 pfSymLoadModule64; - PF_SymGetModuleInfo64 pfSymGetModuleInfo64; - PF_SymFromName pfSymFromName; -} DETOUR_SYM_INFO, *PDETOUR_SYM_INFO; - -PDETOUR_SYM_INFO DetourLoadImageHlp(VOID); - -#endif // IMAGEAPI - -#if defined(_INC_STDIO) && !defined(_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS) -#error detours.h must be included before stdio.h (or at least define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS earlier) -#endif -#define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS 1 - -#ifndef DETOUR_TRACE -#if DETOUR_DEBUG -#define DETOUR_TRACE(x) printf x -#define DETOUR_BREAK() __debugbreak() -#include -#include -#else -#define DETOUR_TRACE(x) -#define DETOUR_BREAK() -#endif -#endif - -#if 1 || defined(DETOURS_IA64) - -// -// IA64 instructions are 41 bits, 3 per bundle, plus 5 bit bundle template => 128 bits per bundle. -// - -#define DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE (3) - -#define DETOUR_IA64_TEMPLATE_OFFSET (0) -#define DETOUR_IA64_TEMPLATE_SIZE (5) - -#define DETOUR_IA64_INSTRUCTION_SIZE (41) -#define DETOUR_IA64_INSTRUCTION0_OFFSET (DETOUR_IA64_TEMPLATE_SIZE) -#define DETOUR_IA64_INSTRUCTION1_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE) -#define DETOUR_IA64_INSTRUCTION2_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE + DETOUR_IA64_INSTRUCTION_SIZE) - -C_ASSERT(DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE * DETOUR_IA64_INSTRUCTION_SIZE == 128); - -__declspec(align(16)) struct DETOUR_IA64_BUNDLE -{ - public: - union - { - BYTE data[16]; - UINT64 wide[2]; - }; - - enum { - A_UNIT = 1u, - I_UNIT = 2u, - M_UNIT = 3u, - B_UNIT = 4u, - F_UNIT = 5u, - L_UNIT = 6u, - X_UNIT = 7u, - }; - struct DETOUR_IA64_METADATA - { - ULONG nTemplate : 8; // Instruction template. - ULONG nUnit0 : 4; // Unit for slot 0 - ULONG nUnit1 : 4; // Unit for slot 1 - ULONG nUnit2 : 4; // Unit for slot 2 - }; - - protected: - static const DETOUR_IA64_METADATA s_rceCopyTable[33]; - - UINT RelocateBundle(_Inout_ DETOUR_IA64_BUNDLE* pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const; - - bool RelocateInstruction(_Inout_ DETOUR_IA64_BUNDLE* pDst, - _In_ BYTE slot, - _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const; - - // 120 112 104 96 88 80 72 64 56 48 40 32 24 16 8 0 - // f. e. d. c. b. a. 9. 8. 7. 6. 5. 4. 3. 2. 1. 0. - - // 00 - // f.e. d.c. b.a. 9.8. 7.6. 5.4. 3.2. 1.0. - // 0000 0000 0000 0000 0000 0000 0000 001f : Template [4..0] - // 0000 0000 0000 0000 0000 03ff ffff ffe0 : Zero [ 41.. 5] - // 0000 0000 0000 0000 0000 3c00 0000 0000 : Zero [ 45.. 42] - // 0000 0000 0007 ffff ffff c000 0000 0000 : One [ 82.. 46] - // 0000 0000 0078 0000 0000 0000 0000 0000 : One [ 86.. 83] - // 0fff ffff ff80 0000 0000 0000 0000 0000 : Two [123.. 87] - // f000 0000 0000 0000 0000 0000 0000 0000 : Two [127..124] - BYTE GetTemplate() const; - // Get 4 bit opcodes. - BYTE GetInst0() const; - BYTE GetInst1() const; - BYTE GetInst2() const; - BYTE GetUnit(BYTE slot) const; - BYTE GetUnit0() const; - BYTE GetUnit1() const; - BYTE GetUnit2() const; - // Get 37 bit data. - UINT64 GetData0() const; - UINT64 GetData1() const; - UINT64 GetData2() const; - - // Get/set the full 41 bit instructions. - UINT64 GetInstruction(BYTE slot) const; - UINT64 GetInstruction0() const; - UINT64 GetInstruction1() const; - UINT64 GetInstruction2() const; - void SetInstruction(BYTE slot, UINT64 instruction); - void SetInstruction0(UINT64 instruction); - void SetInstruction1(UINT64 instruction); - void SetInstruction2(UINT64 instruction); - - // Get/set bitfields. - static UINT64 GetBits(UINT64 Value, UINT64 Offset, UINT64 Count); - static UINT64 SetBits(UINT64 Value, UINT64 Offset, UINT64 Count, UINT64 Field); - - // Get specific read-only fields. - static UINT64 GetOpcode(UINT64 instruction); // 4bit opcode - static UINT64 GetX(UINT64 instruction); // 1bit opcode extension - static UINT64 GetX3(UINT64 instruction); // 3bit opcode extension - static UINT64 GetX6(UINT64 instruction); // 6bit opcode extension - - // Get/set specific fields. - static UINT64 GetImm7a(UINT64 instruction); - static UINT64 SetImm7a(UINT64 instruction, UINT64 imm7a); - static UINT64 GetImm13c(UINT64 instruction); - static UINT64 SetImm13c(UINT64 instruction, UINT64 imm13c); - static UINT64 GetSignBit(UINT64 instruction); - static UINT64 SetSignBit(UINT64 instruction, UINT64 signBit); - static UINT64 GetImm20a(UINT64 instruction); - static UINT64 SetImm20a(UINT64 instruction, UINT64 imm20a); - static UINT64 GetImm20b(UINT64 instruction); - static UINT64 SetImm20b(UINT64 instruction, UINT64 imm20b); - - static UINT64 SignExtend(UINT64 Value, UINT64 Offset); - - BOOL IsMovlGp() const; - - VOID SetInst(BYTE Slot, BYTE nInst); - VOID SetInst0(BYTE nInst); - VOID SetInst1(BYTE nInst); - VOID SetInst2(BYTE nInst); - VOID SetData(BYTE Slot, UINT64 nData); - VOID SetData0(UINT64 nData); - VOID SetData1(UINT64 nData); - VOID SetData2(UINT64 nData); - BOOL SetNop(BYTE Slot); - BOOL SetNop0(); - BOOL SetNop1(); - BOOL SetNop2(); - - public: - BOOL IsBrl() const; - VOID SetBrl(); - VOID SetBrl(UINT64 target); - UINT64 GetBrlTarget() const; - VOID SetBrlTarget(UINT64 target); - VOID SetBrlImm(UINT64 imm); - UINT64 GetBrlImm() const; - - UINT64 GetMovlGp() const; - VOID SetMovlGp(UINT64 gp); - - VOID SetStop(); - - UINT Copy(_Out_ DETOUR_IA64_BUNDLE *pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra = NULL) const; -}; -#endif // DETOURS_IA64 - -#ifdef DETOURS_ARM - -#define DETOURS_PFUNC_TO_PBYTE(p) ((PBYTE)(((ULONG_PTR)(p)) & ~(ULONG_PTR)1)) -#define DETOURS_PBYTE_TO_PFUNC(p) ((PBYTE)(((ULONG_PTR)(p)) | (ULONG_PTR)1)) - -#endif // DETOURS_ARM - -////////////////////////////////////////////////////////////////////////////// - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -#define DETOUR_OFFLINE_LIBRARY(x) \ -PVOID WINAPI DetourCopyInstruction##x(_In_opt_ PVOID pDst, \ - _Inout_opt_ PVOID *ppDstPool, \ - _In_ PVOID pSrc, \ - _Out_opt_ PVOID *ppTarget, \ - _Out_opt_ LONG *plExtra); \ - \ -BOOL WINAPI DetourSetCodeModule##x(_In_ HMODULE hModule, \ - _In_ BOOL fLimitReferencesToModule); \ - -DETOUR_OFFLINE_LIBRARY(X86) -DETOUR_OFFLINE_LIBRARY(X64) -DETOUR_OFFLINE_LIBRARY(ARM) -DETOUR_OFFLINE_LIBRARY(ARM64) -DETOUR_OFFLINE_LIBRARY(IA64) - -#undef DETOUR_OFFLINE_LIBRARY - -////////////////////////////////////////////////////////////////////////////// -// -// Helpers for manipulating page protection. -// - -_Success_(return != FALSE) -BOOL WINAPI DetourVirtualProtectSameExecuteEx(_In_ HANDLE hProcess, - _In_ PVOID pAddress, - _In_ SIZE_T nSize, - _In_ DWORD dwNewProtect, - _Out_ PDWORD pdwOldProtect); - -_Success_(return != FALSE) -BOOL WINAPI DetourVirtualProtectSameExecute(_In_ PVOID pAddress, - _In_ SIZE_T nSize, - _In_ DWORD dwNewProtect, - _Out_ PDWORD pdwOldProtect); -#ifdef __cplusplus -} -#endif // __cplusplus - -////////////////////////////////////////////////////////////////////////////// - -#define MM_ALLOCATION_GRANULARITY 0x10000 - -////////////////////////////////////////////////////////////////////////////// - -#endif // DETOURS_INTERNAL -#endif // __cplusplus - -#endif // _DETOURS_H_ -// -//////////////////////////////////////////////////////////////// End of File. diff --git a/source-code/source/plugins/DivaSound/detours/include/detver.h b/source-code/source/plugins/DivaSound/detours/include/detver.h deleted file mode 100644 index f0aae9b..0000000 --- a/source-code/source/plugins/DivaSound/detours/include/detver.h +++ /dev/null @@ -1,27 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// Common version parameters. -// -// Microsoft Research Detours Package, Version 4.0.1 -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// - -#define _USING_V110_SDK71_ 1 -#include "winver.h" -#if 0 -#include -#include -#else -#ifndef DETOURS_STRINGIFY -#define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x) -#define DETOURS_STRINGIFY_(x) #x -#endif - -#define VER_FILEFLAGSMASK 0x3fL -#define VER_FILEFLAGS 0x0L -#define VER_FILEOS 0x00040004L -#define VER_FILETYPE 0x00000002L -#define VER_FILESUBTYPE 0x00000000L -#endif -#define VER_DETOURS_BITS DETOUR_STRINGIFY(DETOURS_BITS) diff --git a/source-code/source/plugins/DivaSound/detours/include/syelog.h b/source-code/source/plugins/DivaSound/detours/include/syelog.h deleted file mode 100644 index 7cfa9f3..0000000 --- a/source-code/source/plugins/DivaSound/detours/include/syelog.h +++ /dev/null @@ -1,89 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// -// Detours Test Program (syelog.h of syelog.lib) -// -// Microsoft Research Detours Package -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// -#pragma once -#ifndef _SYELOGD_H_ -#define _SYELOGD_H_ -#include - -#pragma pack(push, 1) -#pragma warning(push) -#pragma warning(disable: 4200) - -////////////////////////////////////////////////////////////////////////////// -// -// -#define SYELOG_PIPE_NAMEA "\\\\.\\pipe\\syelog" -#define SYELOG_PIPE_NAMEW L"\\\\.\\pipe\\syelog" -#ifdef UNICODE -#define SYELOG_PIPE_NAME SYELOG_PIPE_NAMEW -#else -#define SYELOG_PIPE_NAME SYELOG_PIPE_NAMEA -#endif - -////////////////////////////////////////////////////////////////////////////// -// -#define SYELOG_MAXIMUM_MESSAGE 4086 // 4096 - sizeof(header stuff) - -typedef struct _SYELOG_MESSAGE -{ - USHORT nBytes; - BYTE nFacility; - BYTE nSeverity; - DWORD nProcessId; - FILETIME ftOccurance; - BOOL fTerminate; - CHAR szMessage[SYELOG_MAXIMUM_MESSAGE]; -} SYELOG_MESSAGE, *PSYELOG_MESSAGE; - - -// Facility Codes. -// -#define SYELOG_FACILITY_KERNEL 0x10 // OS Kernel -#define SYELOG_FACILITY_SECURITY 0x20 // OS Security -#define SYELOG_FACILITY_LOGGING 0x30 // OS Logging-internal -#define SYELOG_FACILITY_SERVICE 0x40 // User-mode system daemon -#define SYELOG_FACILITY_APPLICATION 0x50 // User-mode application -#define SYELOG_FACILITY_USER 0x60 // User self-generated. -#define SYELOG_FACILITY_LOCAL0 0x70 // Locally defined. -#define SYELOG_FACILITY_LOCAL1 0x71 // Locally defined. -#define SYELOG_FACILITY_LOCAL2 0x72 // Locally defined. -#define SYELOG_FACILITY_LOCAL3 0x73 // Locally defined. -#define SYELOG_FACILITY_LOCAL4 0x74 // Locally defined. -#define SYELOG_FACILITY_LOCAL5 0x75 // Locally defined. -#define SYELOG_FACILITY_LOCAL6 0x76 // Locally defined. -#define SYELOG_FACILITY_LOCAL7 0x77 // Locally defined. -#define SYELOG_FACILITY_LOCAL8 0x78 // Locally defined. -#define SYELOG_FACILITY_LOCAL9 0x79 // Locally defined. - -// Severity Codes. -// -#define SYELOG_SEVERITY_FATAL 0x00 // System is dead. -#define SYELOG_SEVERITY_ALERT 0x10 // Take action immediately. -#define SYELOG_SEVERITY_CRITICAL 0x20 // Critical condition. -#define SYELOG_SEVERITY_ERROR 0x30 // Error -#define SYELOG_SEVERITY_WARNING 0x40 // Warning -#define SYELOG_SEVERITY_NOTICE 0x50 // Significant condition. -#define SYELOG_SEVERITY_INFORMATION 0x60 // Informational -#define SYELOG_SEVERITY_AUDIT_FAIL 0x66 // Audit Failed -#define SYELOG_SEVERITY_AUDIT_PASS 0x67 // Audit Succeeeded -#define SYELOG_SEVERITY_DEBUG 0x70 // Debugging - -// Logging Functions. -// -VOID SyelogOpen(PCSTR pszIdentifier, BYTE nFacility); -VOID Syelog(BYTE nSeverity, PCSTR pszMsgf, ...); -VOID SyelogV(BYTE nSeverity, PCSTR pszMsgf, va_list args); -VOID SyelogClose(BOOL fTerminate); - -#pragma warning(pop) -#pragma pack(pop) - -#endif // _SYELOGD_H_ -// -///////////////////////////////////////////////////////////////// End of File. diff --git a/source-code/source/plugins/DivaSound/detours/lib/detours.lib b/source-code/source/plugins/DivaSound/detours/lib/detours.lib deleted file mode 100644 index 13ac97b..0000000 Binary files a/source-code/source/plugins/DivaSound/detours/lib/detours.lib and /dev/null differ diff --git a/source-code/source/plugins/DivaSound/detours/lib/syelog.lib b/source-code/source/plugins/DivaSound/detours/lib/syelog.lib deleted file mode 100644 index 215789f..0000000 Binary files a/source-code/source/plugins/DivaSound/detours/lib/syelog.lib and /dev/null differ diff --git a/source-code/source/plugins/Launcher/ConfigOption.h b/source-code/source/plugins/Launcher/ConfigOption.h index 6ec5782..2f40a26 100644 --- a/source-code/source/plugins/Launcher/ConfigOption.h +++ b/source-code/source/plugins/Launcher/ConfigOption.h @@ -151,7 +151,7 @@ ref class PluginConfigHandler public: Form^ form; - PluginConfigHandler(Panel^ optspanel, String^ title) + PluginConfigHandler(Panel^ optspanel, String^ title, float btnScaleSize) { form = gcnew Form(); @@ -168,10 +168,13 @@ public: form->BackColor = Drawing::Color::FromArgb(64, 64, 64); form->ForeColor = Drawing::Color::White; + form->Font = optspanel->Font; + optspanel->Left = 0; optspanel->Top = 0; Button^ OkBtn = gcnew Button(); + OkBtn->Scale(btnScaleSize); OkBtn->Text = L"OK"; OkBtn->Left = 4; OkBtn->Top = optspanel->Bottom + 4; @@ -517,9 +520,9 @@ public: textbox->Scale(ScaleWidth, ScaleHeight); // disable editing for utf8 mode because the ANSI hack used may not work correctly - if (_useUtf8) { - textbox->Enabled = false; - } + //if (_useUtf8) { + // textbox->Enabled = false; + //} tooltip->SetToolTip(label, gcnew String(_description)); tooltip->SetToolTip(textbox, gcnew String(_description)); @@ -540,8 +543,8 @@ public: virtual void SaveOption() { // disable saving for utf8 mode because the ANSI hack used may not work correctly - if (_useUtf8) - return; + //if (_useUtf8) + // return; System::String^ tempSysStr; std::wstring tempWStr; @@ -714,10 +717,10 @@ public: combobox->Scale(ScaleWidth, ScaleHeight); // disable editing for utf8 mode because the ANSI hack used may not work correctly - if (_useUtf8) { - label->Enabled = false; - combobox->Enabled = false; - } + //if (_useUtf8) { + // label->Enabled = false; + // combobox->Enabled = false; + //} tooltip->SetToolTip(label, gcnew String(_description)); tooltip->SetToolTip(combobox, gcnew String(_description)); @@ -741,8 +744,8 @@ public: virtual void SaveOption() { // disable saving for utf8 mode because the ANSI hack used may not work correctly - if (_useUtf8) - return; + //if (_useUtf8) + // return; System::String^ tempSysStr; std::wstring tempWStr; @@ -1088,9 +1091,11 @@ public: if (_configopts.size() > 0) { ToolTip^ paneltooltip = gcnew ToolTip(); - Panel^ configPanel = MakePanel((Col2Left + Col2Width + 64), 250, _configopts, paneltooltip, hasChanged); + Panel^ configPanel = MakePanel((Col2Left + Col2Width + 76), 250, _configopts, paneltooltip, hasChanged); configPanel->Scale(ScaleWidth, ScaleHeight); - PluginConfigHandler^ confighandler = gcnew PluginConfigHandler(configPanel, gcnew String(_friendlyName) + " Options"); + if (RootForm) + configPanel->Font = RootForm->Font; + PluginConfigHandler^ confighandler = gcnew PluginConfigHandler(configPanel, gcnew String(_friendlyName) + " Options", ScaleHeight); button->Click += gcnew System::EventHandler(confighandler, &PluginConfigHandler::OpenForm); panel->Controls->Add(button); @@ -1143,11 +1148,12 @@ Panel^ MakePanel(int width, int height, std::vector &cfg, Too { OptionMetaGroupStart* groupData = (OptionMetaGroupStart*)(cfg[i]); GroupBox^ groupbox = gcnew GroupBox(); - groupbox->Width = width - (ScaleWidth * 8); - groupbox->Height = ScaleHeight * groupData->_height; + groupbox->Width = width - (ScaleWidth * 28); + groupbox->Height = ScaleHeight * (groupData->_height); groupbox->Left = ScaleWidth * 4; groupbox->Top = ScaleHeight * curY; groupbox->Text = gcnew String(groupData->_friendlyName); + groupbox->ForeColor = Drawing::Color::White; // find the end of this group by simple iteration keeping track of indent level int level = 1; @@ -1163,9 +1169,9 @@ Panel^ MakePanel(int width, int height, std::vector &cfg, Too break; } - Panel^ groupPanel = MakePanel(groupbox->Width - (ScaleWidth * 8), groupbox->Height - (ScaleHeight * 10), std::vector(&(cfg[i + 1]), &(cfg[endidx])), tooltip, hasChanged); - groupPanel->Left = ScaleWidth * 12; - groupPanel->Top = ScaleHeight * (curY + 8); + Panel^ groupPanel = MakePanel(groupbox->Width - (ScaleWidth * 12), groupbox->Height - (ScaleHeight * 20), std::vector(&(cfg[i + 1]), &(cfg[endidx])), tooltip, hasChanged); + groupPanel->Left = ScaleWidth * 2; + groupPanel->Top = ScaleHeight * 14; groupbox->Controls->Add(groupPanel); outpanel->Controls->Add(groupbox); diff --git a/source-code/source/plugins/Launcher/Launcher.vcxproj b/source-code/source/plugins/Launcher/Launcher.vcxproj index f8c2f87..fef5717 100644 --- a/source-code/source/plugins/Launcher/Launcher.vcxproj +++ b/source-code/source/plugins/Launcher/Launcher.vcxproj @@ -111,7 +111,7 @@ Level3 Disabled _DEBUG;%(PreprocessorDefinitions) - ..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) stdcpp17 @@ -142,7 +142,7 @@ Level3 NDEBUG;%(PreprocessorDefinitions) - ..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) stdcpp17 @@ -168,7 +168,6 @@ - diff --git a/source-code/source/plugins/Launcher/PluginConfig.h b/source-code/source/plugins/Launcher/PluginConfig.h index b2d3e35..0d50ac7 100644 --- a/source-code/source/plugins/Launcher/PluginConfig.h +++ b/source-code/source/plugins/Launcher/PluginConfig.h @@ -52,7 +52,7 @@ namespace PluginConfig for (int i = 0; i < in.len; i++) { // basic check for validity - if (in.options[i].data == nullptr) + if (in.options[i].data == nullptr && in.options[i].cfgType != CONFIG_GROUP_END) break; outvec.push_back(GetConfigOption(in.options[i])); diff --git a/source-code/source/plugins/Launcher/PluginConfigApi.h b/source-code/source/plugins/Launcher/PluginConfigApi.h deleted file mode 100644 index d0ffd94..0000000 --- a/source-code/source/plugins/Launcher/PluginConfigApi.h +++ /dev/null @@ -1,168 +0,0 @@ -#pragma once -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#include -#include - -// resolution class to store and sort the width and height easily -class resolution -{ -public: - unsigned int width; - unsigned int height; - - resolution() - { - width = 0; - height = 0; - } - - resolution(unsigned int width, unsigned int height) - { - resolution::width = width; - resolution::height = height; - } - - bool operator ==(const resolution &res2) - { - return width == res2.width && height == res2.height; - } - - // in comparisons width takes priority because it's usually displayed first - bool operator <(const resolution &res2) - { - if (width == res2.width) - return height < res2.height; - else - return width < res2.width; - } - bool operator >(const resolution &res2) - { - if (width == res2.width) - return height > res2.height; - else - return width > res2.width; - } -}; - -namespace PluginConfig -{ -#pragma pack(push, 1) - enum ConfigType { - CONFIG_BOOLEAN, - CONFIG_NUMERIC, - CONFIG_STRING, - CONFIG_DROPDOWN_INDEX, - CONFIG_DROPDOWN_TEXT, - CONFIG_DROPDOWN_NUMBER, - CONFIG_RESOLUTION, - CONFIG_GROUP_START, - CONFIG_GROUP_END, - CONFIG_BUTTON, - CONFIG_SPACER - }; - - struct PluginConfigBooleanData { - LPCWSTR iniVarName; - LPCWSTR iniSectionName; - LPCWSTR iniFilePath; - LPCWSTR friendlyName; - LPCWSTR description; - bool defaultVal; - bool saveAsString; - }; - - struct PluginConfigNumericData { - LPCWSTR iniVarName; - LPCWSTR iniSectionName; - LPCWSTR iniFilePath; - LPCWSTR friendlyName; - LPCWSTR description; - int defaultVal; - int minVal; - int maxVal; - }; - - struct PluginConfigStringData { - LPCWSTR iniVarName; - LPCWSTR iniSectionName; - LPCWSTR iniFilePath; - LPCWSTR friendlyName; - LPCWSTR description; - LPCWSTR defaultVal; - bool useUtf8; - }; - - struct PluginConfigDropdownIndexData { - LPCWSTR iniVarName; - LPCWSTR iniSectionName; - LPCWSTR iniFilePath; - LPCWSTR friendlyName; - LPCWSTR description; - int defaultVal; - std::vector valueStrings; - }; - - struct PluginConfigDropdownTextData { - LPCWSTR iniVarName; - LPCWSTR iniSectionName; - LPCWSTR iniFilePath; - LPCWSTR friendlyName; - LPCWSTR description; - LPCWSTR defaultVal; - std::vector valueStrings; - bool editable; - bool useUtf8; - }; - - struct PluginConfigDropdownNumberData { - LPCWSTR iniVarName; - LPCWSTR iniSectionName; - LPCWSTR iniFilePath; - LPCWSTR friendlyName; - LPCWSTR description; - int defaultVal; - std::vector valueInts; - bool editable; - }; - - struct PluginConfigResolutionData { - LPCWSTR iniVarName; - LPCWSTR iniVarName2; - LPCWSTR iniSectionName; - LPCWSTR iniFilePath; - LPCWSTR friendlyName; - LPCWSTR description; - resolution defaultVal; - std::vector valueResolutions; - bool editable; - }; - - struct PluginConfigGroupData - { - LPCWSTR name; - int height; - }; - - struct PluginConfigButtonData { - LPCWSTR friendlyName; - LPCWSTR description; - void(*func)(); - }; - - struct PluginConfigSpacerData { - int height; - }; - - struct PluginConfigOption - { - ConfigType cfgType; - void* data; - }; - - struct PluginConfigArray - { - int len; - PluginConfigOption* options; - }; -#pragma pack(pop) -} \ No newline at end of file diff --git a/source-code/source/plugins/Launcher/framework.h b/source-code/source/plugins/Launcher/framework.h index 3fb94ae..086ba0d 100644 --- a/source-code/source/plugins/Launcher/framework.h +++ b/source-code/source/plugins/Launcher/framework.h @@ -311,6 +311,7 @@ struct PluginInfo { std::wstring filename; std::wstring name; std::wstring description; + std::wstring builddate; std::vector configopts; }; std::vector LoadPlugins() @@ -341,6 +342,7 @@ std::vector LoadPlugins() auto nameFunc = (LPCWSTR(*)())GetProcAddress(thisplugin.handle, "GetPluginName"); auto descFunc = (LPCWSTR(*)())GetProcAddress(thisplugin.handle, "GetPluginDescription"); + auto dateFunc = (LPCWSTR(*)())GetProcAddress(thisplugin.handle, "GetBuildDate"); auto optsFunc = (PluginConfig::PluginConfigArray(*)())GetProcAddress(thisplugin.handle, "GetPluginOptions"); if (nameFunc != NULL) @@ -353,6 +355,13 @@ std::vector LoadPlugins() else thisplugin.description = (thisplugin.filename + L" Plugin").c_str(); + if (dateFunc != NULL) + thisplugin.builddate = dateFunc(); + else + thisplugin.builddate = L"Unknown"; + + thisplugin.description += L"\n\nVersion: " + thisplugin.builddate; + if (optsFunc != NULL) thisplugin.configopts = PluginConfig::GetConfigOptionVec(optsFunc()); @@ -395,3 +404,16 @@ void(WINAPI * cuInit)(unsigned int flags) = (void(WINAPI*)(unsigned int flags))G // needed to close the OpenGL window (freeglut only) HMODULE glutModule = LoadLibraryW(L"glut32.dll"); void(__stdcall * glutMainLoopEventDynamic)() = (void(__stdcall*)())GetProcAddress(glutModule, "glutMainLoopEvent"); + + +using namespace PluginConfig; + +extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void) +{ + return L"Launcher"; +} + +extern "C" __declspec(dllexport) LPCWSTR GetPluginDescription(void) +{ + return L"PD Launcher is the window you currently have open.\nYou can disable it if you want, but you'll need to edit config.ini if you ever want to re-enable it."; +} \ No newline at end of file diff --git a/source-code/source/plugins/Launcher/ui.h b/source-code/source/plugins/Launcher/ui.h index ecab2f3..79ef930 100644 --- a/source-code/source/plugins/Launcher/ui.h +++ b/source-code/source/plugins/Launcher/ui.h @@ -58,7 +58,7 @@ namespace Launcher { int screenresY = 3; for (ConfigOptionBase* option : screenResolutionArray) { - option->hasChanged = ConfigHasChanged; + option->hasChanged = ResolutionConfigChanged; screenresY += option->AddToPanel(panel_ScreenRes, 12, screenresY, toolTip1); } ((ComboBox^)ComboBox::FromHandle(DisplayModeDropdown->mainControlHandle))->SelectedIndexChanged += gcnew System::EventHandler(this, &ui::DisplayTypeChangedHandler); @@ -74,7 +74,7 @@ namespace Launcher { int intresY = 3; for (ConfigOptionBase* option : internalResolutionArray) { - option->hasChanged = ConfigHasChanged; + option->hasChanged = ResolutionConfigChanged; intresY += option->AddToPanel(panel_IntRes, 12, intresY, toolTip1); } ((CheckBox^)CheckBox::FromHandle(InternalResolutionCheckbox->mainControlHandle))->CheckedChanged += gcnew System::EventHandler(this, &ui::InternalResEnabledChangedHandler); @@ -90,7 +90,7 @@ namespace Launcher { int optionsY = 3; for (ConfigOptionBase* option : optionsArray) { - option->hasChanged = ConfigHasChanged; + option->hasChanged = OptionsConfigChanged; optionsY += option->AddToPanel(panel_Patches, 12, optionsY, toolTip1); } this->panel_Patches->ResumeLayout(false); @@ -105,7 +105,7 @@ namespace Launcher { int playerdataY = 3; for (ConfigOptionBase* option : playerdataArray) { - option->hasChanged = ConfigHasChanged; + option->hasChanged = PlayerdataConfigChanged; playerdataY += option->AddToPanel(panel_Playerdata, 12, playerdataY, toolTip1); } this->panel_Playerdata->ResumeLayout(false); @@ -119,7 +119,7 @@ namespace Launcher { int componentsY = 3; for (ConfigOptionBase* component : componentsArray) { - component->hasChanged = ConfigHasChanged; + component->hasChanged = ComponentsConfigChanged; componentsY += component->AddToPanel(panel_Components, 12, componentsY, toolTip1); } this->panel_Components->ResumeLayout(false); @@ -134,7 +134,7 @@ namespace Launcher { int pluginsY = 3; for (ConfigOptionBase* option : AllPluginOpts) { - option->hasChanged = ConfigHasChanged; + option->hasChanged = new bool(false); pluginsY += option->AddToPanel(panel_Plugins, 12, pluginsY, toolTip1); } this->panel_Plugins->ResumeLayout(false); @@ -559,38 +559,61 @@ namespace Launcher { } #pragma endregion -private: System::Void SaveSettings() { - for (ConfigOptionBase* option : screenResolutionArray) +private: System::Void SaveSettings() { + if (*ResolutionConfigChanged) { - option->SaveOption(); + for (ConfigOptionBase* option : screenResolutionArray) + { + option->SaveOption(); + } + + for (ConfigOptionBase* option : internalResolutionArray) + { + option->SaveOption(); + } + + *ResolutionConfigChanged = false; } - for (ConfigOptionBase* option : internalResolutionArray) + if (*OptionsConfigChanged) { - option->SaveOption(); + for (ConfigOptionBase* option : optionsArray) + { + option->SaveOption(); + } + + *OptionsConfigChanged = false; } - for (ConfigOptionBase* option : optionsArray) + if (*PlayerdataConfigChanged) { - option->SaveOption(); + for (ConfigOptionBase* option : playerdataArray) + { + option->SaveOption(); + } + + *PlayerdataConfigChanged = false; } - for (ConfigOptionBase* option : playerdataArray) + if (*ComponentsConfigChanged) { - option->SaveOption(); - } + for (ConfigOptionBase* component : componentsArray) + { + component->SaveOption(); + } - for (ConfigOptionBase* component : componentsArray) - { - component->SaveOption(); + *ComponentsConfigChanged = false; } for (ConfigOptionBase* option : AllPluginOpts) { - option->SaveOption(); - } + if (*(option->hasChanged)) + { + option->SaveOption(); + } - *ConfigHasChanged = false; + *(option->hasChanged) = false; + } } private: System::Void Ui_Load(System::Object^ sender, System::EventArgs^ e){ } @@ -655,7 +678,7 @@ private: System::Void DisplayTypeChangedHandler(System::Object^ sender, System:: } } private: System::Void Ui_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) { - if (!*ConfigHasChanged) + if (!AnyConfigChanged()) return; switch (SkinnedMessageBox::Show(this, "Do you want to save your settings?", "PD Launcher", MessageBoxButtons::YesNoCancel, MessageBoxIcon::Question)) @@ -689,10 +712,21 @@ private: System::Void Ui_KeyDown(System::Object^ sender, System::Windows::Forms: if (e->KeyCode == Keys::Escape) this->Close(); } -private: bool* ConfigHasChanged = new bool(false);/* +private: bool* ResolutionConfigChanged = new bool(false); + bool* OptionsConfigChanged = new bool(false); + bool* PlayerdataConfigChanged = new bool(false); + bool* ComponentsConfigChanged = new bool(false); -private: System::Void ConfigChanged(System::Object^ sender, System::EventArgs^ e) { - *ConfigHasChanged = true; -}*/ +private: bool AnyConfigChanged() { + if (*ResolutionConfigChanged || *OptionsConfigChanged || *PlayerdataConfigChanged || *ComponentsConfigChanged) + return true; // fast case + + for (ConfigOptionBase* option : AllPluginOpts) + { + if (*(option->hasChanged)) return true; // slow case for iterating over individual plugins + } + + return false; +} }; } diff --git a/source-code/source/plugins/Patches/Patches.vcxproj b/source-code/source/plugins/Patches/Patches.vcxproj index 578fd8a..8bb8937 100644 --- a/source-code/source/plugins/Patches/Patches.vcxproj +++ b/source-code/source/plugins/Patches/Patches.vcxproj @@ -1,4 +1,4 @@ - + @@ -96,7 +96,7 @@ true pch.h stdcpp17 - ..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) Windows @@ -133,7 +133,7 @@ true - ..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) stdcpp17 diff --git a/source-code/source/plugins/Patches/dllmain.cpp b/source-code/source/plugins/Patches/dllmain.cpp index b3e1b21..eccbb20 100644 --- a/source-code/source/plugins/Patches/dllmain.cpp +++ b/source-code/source/plugins/Patches/dllmain.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "PluginConfigApi.h" void InjectCode(void* address, const std::vector data); void ApplyPatches(); @@ -317,3 +318,16 @@ void InjectCode(void* address, const std::vector data) memcpy(address, data.data(), byteCount); VirtualProtect(address, byteCount, oldProtect, nullptr); } + + +using namespace PluginConfig; + +extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void) +{ + return L"Patches"; +} + +extern "C" __declspec(dllexport) LPCWSTR GetPluginDescription(void) +{ + return L"Applies patches/tweaks to the game before it starts.\nThis plugin is required."; +} \ No newline at end of file diff --git a/source-code/source/plugins/Render/Render.vcxproj b/source-code/source/plugins/Render/Render.vcxproj index 32edb89..0ca8562 100644 --- a/source-code/source/plugins/Render/Render.vcxproj +++ b/source-code/source/plugins/Render/Render.vcxproj @@ -1,4 +1,4 @@ - + @@ -96,7 +96,7 @@ true - ..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories) + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories) stdcpp17 @@ -135,7 +135,7 @@ stdcpp17 - ..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories) + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories) Windows diff --git a/source-code/source/plugins/Render/dllmain.cpp b/source-code/source/plugins/Render/dllmain.cpp index 6c0809a..1c1e2fa 100644 --- a/source-code/source/plugins/Render/dllmain.cpp +++ b/source-code/source/plugins/Render/dllmain.cpp @@ -11,6 +11,8 @@ #include +#include "PluginConfigApi.h" + using namespace std::chrono; int hookedCreateWindow(const char* title, void(__cdecl* exit_function)(int)) @@ -238,3 +240,15 @@ BOOL APIENTRY DllMain(HMODULE hModule, return TRUE; } + +using namespace PluginConfig; + +extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void) +{ + return L"Render"; +} + +extern "C" __declspec(dllexport) LPCWSTR GetPluginDescription(void) +{ + return L"Applies window mode/size and FPS limiting."; +} \ No newline at end of file diff --git a/source-code/source/plugins/ShaderPatch/ShaderPatch.vcxproj b/source-code/source/plugins/ShaderPatch/ShaderPatch.vcxproj new file mode 100644 index 0000000..b015031 --- /dev/null +++ b/source-code/source/plugins/ShaderPatch/ShaderPatch.vcxproj @@ -0,0 +1,132 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {C07E495E-A16F-48FA-80E4-0296B5234F0B} + ShaderPatch + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + DynamicLibrary + true + v142 + MultiByte + + + DynamicLibrary + false + v142 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + .dva + + + .dva + + + + Level3 + Disabled + true + + + + + Level3 + Disabled + true + ..\..\..\dependencies\detours\include;..\..\..\dependencies\PluginConfigApi + + + ..\..\..\dependencies\detours\lib + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + ..\..\..\dependencies\detours\include;..\..\..\dependencies\PluginConfigApi + + + true + true + ..\..\..\dependencies\detours\lib + + + + + + + + + + + + \ No newline at end of file diff --git a/source-code/source/plugins/ShaderPatch/ShaderPatch.vcxproj.filters b/source-code/source/plugins/ShaderPatch/ShaderPatch.vcxproj.filters new file mode 100644 index 0000000..3d3bf67 --- /dev/null +++ b/source-code/source/plugins/ShaderPatch/ShaderPatch.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {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 + + + {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 + + + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/source-code/source/plugins/ShaderPatch/src/dllmain.cpp b/source-code/source/plugins/ShaderPatch/src/dllmain.cpp new file mode 100644 index 0000000..a86d1c8 --- /dev/null +++ b/source-code/source/plugins/ShaderPatch/src/dllmain.cpp @@ -0,0 +1,372 @@ +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include + +#include "framework.h" +#include "PluginConfigApi.h" +#include "detours.h" +#pragma comment(lib, "detours.lib") + +#include +#include + +void InjectCode(void* address, const std::vector data) +{ + const size_t byteCount = data.size() * sizeof(uint8_t); + + DWORD oldProtect; + VirtualProtect(address, byteCount, PAGE_EXECUTE_READWRITE, &oldProtect); + memcpy(address, data.data(), byteCount); + VirtualProtect(address, byteCount, oldProtect, nullptr); +} + +void NopBytes(void* address, unsigned int num) +{ + std::vector newbytes = {}; + + for (unsigned int i = 0; i < num; ++i) newbytes.push_back(0x90); + + InjectCode(address, newbytes); +} + + +void loadGpuName() +{ + NvAPI_QueryInterface = (void*(*)(unsigned int offset))GetProcAddress(LoadLibrary("nvapi64.dll"), "nvapi_QueryInterface"); + + if (NvAPI_QueryInterface == nullptr) + { + gpuName = "Other"; + return; + } + + NvAPI_Initialize = (int(*)())NvAPI_QueryInterface(0x0150E828); + NvAPI_Unload = (int(*)()) NvAPI_QueryInterface(0xD22BDD7E); + NvAPI_EnumPhysicalGPUs = (int(*)(int64_t** handle, int* count))NvAPI_QueryInterface(0xE5AC921F); + NvAPI_GPU_GetShortName = (int(*)(int64_t* handle, char* name))NvAPI_QueryInterface(0xD988F0F3); + + if (NvAPI_Initialize == nullptr || + NvAPI_Unload == nullptr || + NvAPI_EnumPhysicalGPUs == nullptr || + NvAPI_GPU_GetShortName == nullptr) + { + gpuName = "Unknown"; + return; + } + + int64_t* hdlGpu[64] = { 0 }; + int nGpu = 0; + + NvAPI_Initialize(); + NvAPI_EnumPhysicalGPUs(hdlGpu, &nGpu); + + //printf("[ShaderPatch] nGpu: %d\n", nGpu); + if (nGpu < 1) + { + gpuName = "Unknown"; + NvAPI_Unload(); + return; + } + + char nameBuf[64]; + NvAPI_GPU_GetShortName(hdlGpu[0], nameBuf); + NvAPI_Unload(); + + gpuName = nameBuf; + return; +} + + +void LoadConfig() +{ + std::ifstream fileStream(CONFIG_FILE_STRING); + + if (!fileStream.is_open()) + return; + + std::string line; + std::string section = "patches"; + std::string lastComment; + bool isInComment = false; + + // check for BOM + std::getline(fileStream, line); + if (line.size() >= 3 && line.rfind("\xEF\xBB\xBF", 0) == 0) + fileStream.seekg(3); + else + fileStream.seekg(0); + + while (std::getline(fileStream, line)) + { + // detect comments first to make comment exit logic easier + int commentStartPos; + if ((commentStartPos = 1, line.size() >= 1 && line[0] == '#') || (commentStartPos = 2, line.size() >= 2 && line.rfind("//", 0) == 0)) + { + line.erase(0, commentStartPos); + line = TrimString(line, " \t"); + if (isInComment) + { + lastComment += "\n" + line; + } + else + { + lastComment = line; + isInComment = true; + } + continue; + } + + isInComment = false; + + if (line.size() <= 0) // skip empty lines + { + lastComment = ""; // consume the last comment + continue; + } + + if (line[0] == '[') // section name + { + size_t endIdx = line.find(']'); + section = line.substr(1, endIdx - 1); + std::transform(section.begin(), section.end(), section.begin(), ::tolower); + lastComment = ""; // consume the last comment + continue; + } + + std::vector equalSplit = SplitString(line, "="); + if (equalSplit.size() < 2) + { + lastComment = ""; // consume the last comment + continue; + } + + if (section == "patches") + { + ShaderPatchInfo patch = ShaderPatchInfo(); + + patch.fileRegex = equalSplit[0]; + + std::vector rules = SplitString(equalSplit[1], "||"); + if (rules.size() < 1) continue; // probably will never trigger but whatever + + for (std::string &rule : rules) + { + if (rule.size() >= 5 && rule.rfind("arch:", 0) == 0) + { + rule.erase(0, 5); + patch.archs = SplitString(rule, ","); + } + else if (rule.size() >= 4 && rule.rfind("cfg:", 0) == 0) + { + rule.erase(0, 4); + // force cfg key to lower because ini shouldn't be case sensitive + std::transform(rule.begin(), rule.end(), rule.begin(), ::tolower); + patch.cfg = rule; + } + else if (rule.size() >= 5 && rule.rfind("from:", 0) == 0) + { + rule.erase(0, 5); + patch.dataRegex = rule; + } + else if (rule.size() >= 3 && rule.rfind("to:", 0) == 0) + { + rule.erase(0, 3); + patch.dataReplace = rule; + } + } + lastComment = ""; // consume the last comment + + patchesVec.push_back(patch); + } + else if (section == "config") + { + // force cfg key to lower because ini shouldn't be case sensitive + std::transform(equalSplit[0].begin(), equalSplit[0].end(), equalSplit[0].begin(), ::tolower); + equalSplit[1] = TrimString(equalSplit[1], " \t"); + + configMap.insert(std::pair(equalSplit[0], strpair(equalSplit[1], lastComment))); + lastComment = ""; // consume the last comment + } + } + + fileStream.close(); +} + + +void hookedLoadFromFarcThunk(FArchivedFile** ppFile) +{ + loadFromFarcThunk(ppFile); + + if (ppFile == nullptr || *ppFile == nullptr) + return; + + FArchivedFile &file = **ppFile; + + if (file.notLoadedFlag != 0) + return; + + std::string modifiedStr = ""; + + for (ShaderPatchInfo &patch : patchesVec) + { + bool archMatches = false; + if (patch.archs.size() > 0) + { + for (std::string &arch : patch.archs) + { + if (gpuName.size() >= arch.size() && gpuName.rfind(arch, 0) == 0) + { + archMatches = true; + break; + } + } + } + else + { + archMatches = true; + } + + bool cfgMatches = false; + if (patch.cfg.length() == 0 || // patch has no config setting + (configMap.find(patch.cfg) != configMap.end() && configMap[patch.cfg].first != "0")) // patch has a toggle and is not set to 0 + { + cfgMatches = true; + } + + if (archMatches && cfgMatches && std::regex_match(file.fileName.GetCharBuf(), patch.fileRegex)) + { + if (modifiedStr.length() == 0) + modifiedStr = std::string(file.data, file.dataSize); + + modifiedStr = std::regex_replace(modifiedStr, patch.dataRegex, patch.dataReplace); + modifiedStr = StringReplace(modifiedStr, "", file.fileName.GetCharBuf()); + + if (patch.cfg.length() > 0) // patch has a config setting + { + int valNum = 0; + std::string valKey; + while (valNum++, valKey = patch.cfg + "_val" + std::to_string(valNum), + configMap.find(valKey) != configMap.end()) // loop until there's no more config values set + { + modifiedStr = StringReplace(modifiedStr, "", configMap[valKey].first); + } + } + } + } + + if (modifiedStr.length() > 0) + { + free(file.data); + file.data = _strdup(modifiedStr.c_str()); + file.dataSize = modifiedStr.size(); + printf("[ShaderPatch] Patched %s\n", file.fileName.GetCharBuf()); + } +} + + +BOOL APIENTRY DllMain(HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved +) +{ + if (ul_reason_for_call == DLL_PROCESS_ATTACH) + { + // install a thunk to hook + InjectCode((void*)0x1405e5991, { 0x48, 0x83, 0xec, 0x20 }); // SUB RSP, 0x20 + InjectCode((void*)0x1405e5995, { 0xe8, 0x56, 0xe8, 0xb9, 0xff }); // CALL 0x1401841f0 + InjectCode((void*)0x1405e599a, { 0x48, 0x83, 0xc4, 0x20 }); // ADD RSP, 0x20 + InjectCode((void*)0x1405e599e, { 0xc3 }); // RET + InjectCode((void*)0x1405e534a, { 0xe8, 0x42, 0x06, 0x00, 0x00 }); // CALL 0x1405e5991 + + DisableThreadLibraryCalls(hModule); + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach(&(PVOID&)loadFromFarcThunk, (PVOID)hookedLoadFromFarcThunk); + DetourTransactionCommit(); + + loadGpuName(); + printf("[ShaderPatch] Detected GPU: %s\n", gpuName.c_str()); + //Sleep(2000); + + LoadConfig(); + } + return TRUE; +} + + +using namespace PluginConfig; + +extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void) +{ + return L"ShaderPatch"; +} + +extern "C" __declspec(dllexport) LPCWSTR GetPluginDescription(void) +{ + return L"Automatically patches shaders"; +} + +std::vector configVec; +extern "C" __declspec(dllexport) PluginConfigArray GetPluginOptions(void) +{ + LoadConfig(); + + for (std::map::iterator iter = configMap.begin(); iter != configMap.end(); ++iter) + { + std::string k = iter->first; + std::string v = iter->second.first; + std::string c = iter->second.second; + + if (k.size() < 6 || k.substr(k.size() - 5, 4) != "_val") + { + WCHAR utf16key[128]; + WCHAR utf16val[128]; + WCHAR utf16comment[512]; + + // count values to approximate the group size + int valNum = 0; + int valCount = 0; + std::string valKey; + while (valNum++, valKey = k + "_val" + std::to_string(valNum), + configMap.find(valKey) != configMap.end()) // loop until there's no more config values set + { + valCount++; + } + + + MultiByteToWideChar(CP_UTF8, 0, k.c_str(), -1, utf16key, 128); + MultiByteToWideChar(CP_UTF8, 0, c.c_str(), -1, utf16comment, 512); + LPCWSTR ttDup = _wcsdup(utf16comment); + + configVec.push_back({ CONFIG_GROUP_START, new PluginConfigGroupData{ _wcsdup(utf16key), 45 + valCount * 25 } }); + configVec.push_back({ CONFIG_BOOLEAN, new PluginConfigBooleanData{ _wcsdup(utf16key), L"config", CONFIG_FILE, L"Enable", ttDup, false, false } }); + + + valNum = 0; + while (valNum++, valKey = k + "_val" + std::to_string(valNum), + configMap.find(valKey) != configMap.end()) // loop until there's no more config values set + { + MultiByteToWideChar(CP_UTF8, 0, valKey.c_str(), -1, utf16key, 128); + MultiByteToWideChar(CP_UTF8, 0, configMap[valKey].first.c_str(), -1, utf16val, 128); + + std::wstring name; + if (configMap[valKey].second.size() > 0) + { + MultiByteToWideChar(CP_UTF8, 0, configMap[valKey].second.c_str(), -1, utf16comment, 512); + name = utf16comment; + name += L":"; +; } + else + { + name = std::wstring(L"Value ") + std::to_wstring(valNum) + L":"; + } + configVec.push_back({ CONFIG_STRING, new PluginConfigStringData{ _wcsdup(utf16key), L"config", CONFIG_FILE, _wcsdup(name.c_str()), ttDup, _wcsdup(utf16val), false } }); + } + + + configVec.push_back({ CONFIG_GROUP_END, NULL }); + configVec.push_back({ CONFIG_SPACER, new PluginConfigSpacerData{ 10 } }); + } + } + + return PluginConfigArray{ (int)configVec.size(), &configVec[0] }; +} \ No newline at end of file diff --git a/source-code/source/plugins/ShaderPatch/src/framework.h b/source-code/source/plugins/ShaderPatch/src/framework.h new file mode 100644 index 0000000..3f38996 --- /dev/null +++ b/source-code/source/plugins/ShaderPatch/src/framework.h @@ -0,0 +1,133 @@ +#pragma once +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include +#include +#include +#include +#include +#include + + +struct ShaderPatchInfo { + std::regex fileRegex; + std::regex dataRegex; + std::string dataReplace; + std::vector archs; + std::string cfg; +}; + +std::vector patchesVec; + +typedef std::pair strpair; +std::map configMap; + +#pragma pack(push, 1) +struct MsString { + union { + char* string_ptr; + char string_buf[16]; + }; + uint64_t unk; + uint64_t size; + + char* GetCharBuf() + { + if (size > 0xf && string_ptr != nullptr) + return string_ptr; + else + return string_buf; + }; +}; + +struct FArchivedFile { + uint8_t padding00[0x10]; + uint8_t notLoadedFlag; + uint8_t padding11[0x07]; + MsString farcPath; + MsString fileName; + uint8_t padding58[0x38]; + uint64_t dataSize; + char* data; +}; +#pragma pack(pop) + +void (__stdcall* loadFromFarcThunk)(FArchivedFile** file) = (void(__stdcall*)(FArchivedFile** file))0x1405e5991; + + +std::string gpuName; +void*(*NvAPI_QueryInterface)(unsigned int offset) = NULL; +int(*NvAPI_Initialize)() = NULL; +int(*NvAPI_Unload)() = NULL; +int(*NvAPI_EnumPhysicalGPUs)(int64_t** handle, int* count) = NULL; +int(*NvAPI_GPU_GetShortName)(int64_t* handle, char* name) = NULL; + + + +std::vector SplitString(const std::string& str, const std::string& delim) +{ + std::vector tokens; + size_t prev = 0, pos = 0; + do + { + pos = str.find(delim, prev); + if (pos == std::string::npos) + pos = str.length(); + + std::string token = str.substr(prev, pos - prev); + + if (!token.empty()) + tokens.push_back(token); + + prev = pos + delim.length(); + } while (pos < str.length() && prev < str.length()); + + return tokens; +} + +std::string TrimString(const std::string& str, const std::string& whitespace) +{ + const size_t strBegin = str.find_first_not_of(whitespace); + + if (strBegin == std::string::npos) + return ""; + + const size_t strEnd = str.find_last_not_of(whitespace); + const size_t strRange = strEnd - strBegin + 1; + + return str.substr(strBegin, strRange); +} + +std::string StringReplace(const std::string& str, const std::string& srch, const std::string& repl) +{ + size_t pos = 0; + std::string outstr = str; + + while (true) + { + pos = outstr.find(srch, pos); + if (pos == std::string::npos) + break; + + outstr.replace(pos, srch.length(), repl); + } + + return outstr; +} + + +std::wstring ExePath() { + WCHAR buffer[MAX_PATH]; + GetModuleFileNameW(NULL, buffer, MAX_PATH); + return std::wstring(buffer); +} + +std::wstring DirPath() { + std::wstring exepath = ExePath(); + std::wstring::size_type pos = exepath.find_last_of(L"\\/"); + return exepath.substr(0, pos); +} + +std::wstring CONFIG_FILE_STRING = DirPath() + L"\\plugins\\ShaderPatch.ini"; +LPCWSTR CONFIG_FILE = CONFIG_FILE_STRING.c_str(); + diff --git a/source-code/source/plugins/TLAC/Components/ScoreSaver.cpp b/source-code/source/plugins/TLAC/Components/ScoreSaver.cpp index ce7eb29..c684e44 100644 --- a/source-code/source/plugins/TLAC/Components/ScoreSaver.cpp +++ b/source-code/source/plugins/TLAC/Components/ScoreSaver.cpp @@ -1,4 +1,5 @@ #include "ScoreSaver.h" +#include "GameState.h" #include "../Constants.h" #include "../framework.h" #include "../Utilities/Operations.h" @@ -22,11 +23,6 @@ namespace TLAC::Components ScoreSaver::~ScoreSaver() { - for (int diff = 0; diff < 4; diff++) - { - *(DivaScore**)(PLAYER_DATA_ADDRESS + diff * 0x18 + 0x5d0) = 0; - *(DivaScore**)(PLAYER_DATA_ADDRESS + diff * 0x18 + 0x5d8) = 0; - } } const char* ScoreSaver::GetDisplayName() @@ -34,14 +30,8 @@ namespace TLAC::Components return "score_saver"; } - bool(__stdcall* ScoreSaver::divaInitResults)(void* cls) = (bool(__stdcall*)(void* cls))RESULTS_INIT_ADDRESS; - void ScoreSaver::Initialize(ComponentsManager*) + void ScoreSaver::initCache() { - DetourTransactionBegin(); - DetourUpdateThread(GetCurrentThread()); - DetourAttach(&(PVOID&)ScoreSaver::divaInitResults, (PVOID)(ScoreSaver::hookedInitResults)); - DetourTransactionCommit(); - // build the score cache UpdateScoreCache(); UpdateClearCounts(); @@ -54,6 +44,18 @@ namespace TLAC::Components } } + bool(__stdcall* ScoreSaver::divaInitResults)(void* cls) = (bool(__stdcall*)(void* cls))RESULTS_INIT_ADDRESS; + std::thread ScoreSaver::initThread; + void ScoreSaver::Initialize(ComponentsManager*) + { + DetourTransactionBegin(); + DetourUpdateThread(GetCurrentThread()); + DetourAttach(&(PVOID&)ScoreSaver::divaInitResults, (PVOID)(ScoreSaver::hookedInitResults)); + DetourTransactionCommit(); + + initThread = std::thread(initCache); + } + bool ScoreSaver::checkExistingScoreValid(int pv, int difficulty, int isEx) { WCHAR keyBase[32]; // needs to be big enough to store pv.999.diff.3.ex @@ -313,7 +315,12 @@ namespace TLAC::Components void ScoreSaver::Update() { - return; + if (*(GameState*)CURRENT_GAME_STATE_ADDRESS == GS_GAME && *(SubGameState*)CURRENT_GAME_SUB_STATE_ADDRESS == SUB_SELECTOR && initThread.joinable()) + { + // it's actually fine to let the init happen in the background after reaching game state, but this is probably safer + printf("[ScoreSaver] Waiting for initialisation..."); + initThread.join(); + } } void ScoreSaver::UpdateInput() diff --git a/source-code/source/plugins/TLAC/Components/ScoreSaver.h b/source-code/source/plugins/TLAC/Components/ScoreSaver.h index 8a7dc89..89236c5 100644 --- a/source-code/source/plugins/TLAC/Components/ScoreSaver.h +++ b/source-code/source/plugins/TLAC/Components/ScoreSaver.h @@ -3,6 +3,7 @@ #include "../Constants.h" #include #include +#include namespace TLAC::Components { @@ -109,10 +110,12 @@ namespace TLAC::Components static bool(__stdcall* divaInitResults)(void* cls); static bool hookedInitResults(void* cls); static void InjectCode(void* address, const std::vector data); + static void initCache(); static bool checkExistingScoreValid(int pv, int difficulty, int isEx); static int calculateCheck(int score, int cntCools, int cntFines, int percent, int combo, int clearRank, int allTimeRank, int allTimeModifiers, int allTimePercent); static WCHAR configPath[256]; static WCHAR rival_configPath[256]; + static std::thread initThread; }; } diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj b/source-code/source/plugins/TLAC/TLAC.vcxproj index 6d8cf0f..d09047a 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj @@ -99,7 +99,7 @@ stdcpp17 - ..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) Windows @@ -139,7 +139,7 @@ stdcpp17 - ..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) + ..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\detours\include;..\..\..\dependencies\freeglut\include;%(AdditionalIncludeDirectories) Windows @@ -225,6 +225,7 @@ + diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters index 33c5ee7..ad474b4 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters @@ -195,6 +195,9 @@ Header Files + + Header Files + diff --git a/source-code/source/plugins/TLAC/dllmain.cpp b/source-code/source/plugins/TLAC/dllmain.cpp index 4ed8162..6569cd1 100644 --- a/source-code/source/plugins/TLAC/dllmain.cpp +++ b/source-code/source/plugins/TLAC/dllmain.cpp @@ -5,6 +5,7 @@ #include #include "Constants.h" #include "framework.h" +#include "pluginconfig.h" #include "Input/Mouse/Mouse.h" #include "Input/Xinput/Xinput.h" #include "Input/Keyboard/Keyboard.h" diff --git a/source-code/source/plugins/TLAC/pluginconfig.h b/source-code/source/plugins/TLAC/pluginconfig.h new file mode 100644 index 0000000..69ae889 --- /dev/null +++ b/source-code/source/plugins/TLAC/pluginconfig.h @@ -0,0 +1,13 @@ +#include "PluginConfigApi.h" + +using namespace PluginConfig; + +extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void) +{ + return L"TLAC"; +} + +extern "C" __declspec(dllexport) LPCWSTR GetPluginDescription(void) +{ + return L"Provides keyboard/mouse/controller input, player data management, bug fixes for running on more PCs, etc.\nThis plugin is required."; +} \ No newline at end of file