From beccc06cc40cee28c304183b2676ff00e4278aa4 Mon Sep 17 00:00:00 2001 From: Angad <66992519+ThirdEyeSqueegee@users.noreply.github.com> Date: Thu, 7 Sep 2023 13:47:56 -0700 Subject: [PATCH] chore: formatting, add todos, bump CMakePresets schema version (#9) Also fix license string in vcpkg.json --------- Co-authored-by: maintenance --- .github/make-directives.ps1 | 6 +- CMakeLists.txt | 4 +- CommonLibSF/.clang-format | 271 ++++++--- CommonLibSF/CMakeLists.txt | 8 +- CommonLibSF/CMakePresets.json | 442 +++++++------- CommonLibSF/cmake/build_stl_modules.props | 2 +- CommonLibSF/cmake/make-sourcelist.ps1 | 4 +- CommonLibSF/include/RE/Offsets.h | 3 +- CommonLibSF/include/RE/Offsets_NiRTTI.h | 3 +- CommonLibSF/include/RE/Offsets_RTTI.h | 3 +- CommonLibSF/include/RE/Offsets_VTABLE.h | 3 +- CommonLibSF/include/RE/RTTI.h | 198 +++--- CommonLibSF/include/REL/Relocation.h | 395 ++++++------ CommonLibSF/include/SFSE/API.h | 2 +- CommonLibSF/include/SFSE/IAT.h | 2 +- CommonLibSF/include/SFSE/Impl/DInputAPI.h | 588 +++++++++--------- CommonLibSF/include/SFSE/Impl/PCH.h | 520 ++++++++-------- CommonLibSF/include/SFSE/Impl/Stubs.h | 5 +- CommonLibSF/include/SFSE/Impl/WinAPI.h | 706 ++++++++++------------ CommonLibSF/include/SFSE/Impl/XInputAPI.h | 59 +- CommonLibSF/include/SFSE/InputMap.h | 20 +- CommonLibSF/include/SFSE/Interfaces.h | 70 ++- CommonLibSF/include/SFSE/Logger.h | 41 +- CommonLibSF/include/SFSE/Trampoline.h | 212 ++++--- CommonLibSF/include/SFSE/Version.h | 2 +- CommonLibSF/src/REL/Relocation.cpp | 38 +- CommonLibSF/src/SFSE/API.cpp | 35 +- CommonLibSF/src/SFSE/IAT.cpp | 43 +- CommonLibSF/src/SFSE/Impl/WinAPI.cpp | 408 ++++--------- CommonLibSF/src/SFSE/InputMap.cpp | 71 ++- CommonLibSF/src/SFSE/Interfaces.cpp | 16 +- CommonLibSF/src/SFSE/Logger.cpp | 11 +- CommonLibSF/src/SFSE/Trampoline.cpp | 41 +- CommonLibSF/vcpkg.json | 4 +- README.md | 25 +- build-clang-cl.bat | 2 +- build-msvc.bat | 2 +- make-sln-clang-cl.bat | 2 +- make-sln-msvc.bat | 2 +- 39 files changed, 2116 insertions(+), 2153 deletions(-) diff --git a/.github/make-directives.ps1 b/.github/make-directives.ps1 index 434f446f..6bc20646 100644 --- a/.github/make-directives.ps1 +++ b/.github/make-directives.ps1 @@ -11,7 +11,7 @@ function Normalize-Path { param ( [string]$in ) - + $out = $in -replace '\\', '/' while ($out.Contains('//')) { $out = $out -replace '//', '/' @@ -25,7 +25,7 @@ function Resolve-Files { $_generated = [System.Collections.ArrayList]::new(2048) try { - Get-ChildItem "$PathIn/include/RE" -Recurse -File -ErrorAction SilentlyContinue + Get-ChildItem "$PathIn/include/RE" -Recurse -File -ErrorAction SilentlyContinue | Where-Object { ($_.Extension -eq '.h') } | Resolve-Path -Relative | ForEach-Object { if (!$_.EndsWith('Starfield.h')) { Write-Host "`t<$_>" @@ -51,4 +51,4 @@ $generated = '#pragma once ' $generated += Resolve-Files $generated += "`n" -[IO.File]::WriteAllText("$PathIn/include/RE/Starfield.h", $generated) \ No newline at end of file +[IO.File]::WriteAllText("$PathIn/include/RE/Starfield.h", $generated) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34686469..9ecaecbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.26) # singleton target across multiple projects if(TARGET CommonLib) - return() + return() endif() # info @@ -16,4 +16,4 @@ if(${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) message(FATAL_ERROR "In-source builds are not allowed.") endif() -add_subdirectory(CommonLibSF) \ No newline at end of file +add_subdirectory(CommonLibSF) diff --git a/CommonLibSF/.clang-format b/CommonLibSF/.clang-format index f3d9e4db..b91dc34b 100644 --- a/CommonLibSF/.clang-format +++ b/CommonLibSF/.clang-format @@ -1,101 +1,210 @@ ---- +--- +BasedOnStyle: Microsoft AccessModifierOffset: -4 -AlignAfterOpenBracket: DontAlign -AlignConsecutiveAssignments: 'false' -AlignConsecutiveBitFields: 'false' -AlignConsecutiveDeclarations: 'true' -AlignConsecutiveMacros: 'false' +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false AlignEscapedNewlines: Left AlignOperands: Align -AlignTrailingComments: 'true' -AllowAllArgumentsOnNextLine: 'false' -AllowAllConstructorInitializersOnNextLine: 'false' -AllowAllParametersOfDeclarationOnNextLine: 'false' +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: Empty -AllowShortCaseLabelsOnASingleLine: 'false' -AllowShortEnumsOnASingleLine: 'true' -AllowShortFunctionsOnASingleLine: All +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None AllowShortIfStatementsOnASingleLine: Never AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: 'true' +AllowShortLoopsOnASingleLine: false AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: 'true' -AlwaysBreakTemplateDeclarations: 'Yes' -BinPackArguments: 'true' -BinPackParameters: 'true' -BitFieldColonSpacing: After +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: + - __declspec + - __try + - __except + - __assume + - __cdecl +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both BraceWrapping: - AfterCaseLabel: 'true' - AfterClass: 'true' - AfterControlStatement: 'false' - AfterEnum: 'true' - AfterFunction: 'true' - AfterNamespace: 'true' - AfterStruct: 'true' - AfterUnion: 'true' - AfterExternBlock: 'true' - BeforeCatch: 'false' - BeforeElse: 'false' - BeforeLambdaBody: 'false' - BeforeWhile: 'false' - IndentBraces: 'false' - SplitEmptyFunction: 'false' - SplitEmptyRecord: 'false' - SplitEmptyNamespace: 'false' -BreakBeforeBinaryOperators: None + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: false + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakAfterAttributes: Never +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: NonAssignment BreakBeforeBraces: Custom -BreakBeforeTernaryOperators: 'false' -BreakConstructorInitializers: AfterColon -BreakInheritanceList: AfterColon -BreakStringLiterals: 'true' -ColumnLimit: 0 -CompactNamespaces: 'false' -ConstructorInitializerAllOnOneLineOrOnePerLine: 'false' +BreakBeforeConceptDeclarations: Always +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 150 +CommentPragmas: "^ IWYU pragma:" +CompactNamespaces: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 -Cpp11BracedListStyle: 'false' -DeriveLineEnding: 'true' -DerivePointerAlignment: 'false' -DisableFormat: 'false' -FixNamespaceComments: 'false' +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true IncludeBlocks: Preserve -IndentCaseBlocks: 'true' -IndentCaseLabels: 'false' -IndentExternBlock: Indent -IndentGotoLabels: 'false' -IndentPPDirectives: AfterHash +IncludeCategories: + - Regex: .* + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: (Test)?$ +IncludeIsMainSourceRegex: "" +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true IndentWidth: 4 -IndentWrappedFunctionNames: 'true' -KeepEmptyLinesAtTheStartOfBlocks: 'false' +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: true +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature Language: Cpp -MaxEmptyLinesToKeep: 1 +LineEnding: CRLF +MacroBlockBegin: "" +MacroBlockEnd: "" +MaxEmptyLinesToKeep: 2 NamespaceIndentation: All +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PPIndentWidth: -1 +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 1000 PointerAlignment: Left -ReflowComments : 'false' -SortIncludes: 'true' -SortUsingDeclarations: 'true' -SpaceAfterCStyleCast: 'false' -SpaceAfterLogicalNot: 'false' -SpaceAfterTemplateKeyword: 'true' -SpaceBeforeAssignmentOperators: 'true' -SpaceBeforeCpp11BracedList: 'false' -SpaceBeforeCtorInitializerColon: 'true' -SpaceBeforeInheritanceColon: 'true' +QualifierAlignment: Custom +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Always +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements -SpaceBeforeRangeBasedForLoopColon: 'true' -SpaceBeforeSquareBrackets: 'false' -SpaceInEmptyBlock: 'false' -SpaceInEmptyParentheses: 'false' -SpacesBeforeTrailingComments: 2 -SpacesInAngles: 'false' -SpacesInCStyleCastParentheses: 'false' -SpacesInConditionalStatement: 'false' -SpacesInContainerLiterals: 'true' -SpacesInParentheses: 'false' -SpacesInSquareBrackets: 'false' +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDeclarationName: false + AfterFunctionDefinitionName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false Standard: Latest TabWidth: 4 -UseCRLF: 'true' UseTab: AlignWithSpaces - -... +QualifierOrder: + - inline + - static + - constexpr + - const + - volatile + - friend + - restrict + - type diff --git a/CommonLibSF/CMakeLists.txt b/CommonLibSF/CMakeLists.txt index 824b75ee..2eeb92e3 100644 --- a/CommonLibSF/CMakeLists.txt +++ b/CommonLibSF/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.26) # singleton target across multiple projects if(TARGET CommonLibSF) - return() + return() endif() # options if not defined @@ -60,9 +60,9 @@ target_compile_definitions( # FIXME: https://gitlab.kitware.com/cmake/cmake/-/issues/24922 set_property( - TARGET + TARGET ${PROJECT_NAME} - PROPERTY VS_USER_PROPS + PROPERTY VS_USER_PROPS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/build_stl_modules.props" ) @@ -119,7 +119,7 @@ target_link_libraries( Version.lib ) -if (SFSE_SUPPORT_XBYAK) +if (SFSE_SUPPORT_XBYAK) find_package(xbyak CONFIG REQUIRED) target_link_libraries( diff --git a/CommonLibSF/CMakePresets.json b/CommonLibSF/CMakePresets.json index d29863b0..2d4390ef 100644 --- a/CommonLibSF/CMakePresets.json +++ b/CommonLibSF/CMakePresets.json @@ -1,222 +1,222 @@ { - "version": 3, - "cmakeMinimumRequired": { - "major": 3, - "minor": 26, - "patch": 0 - }, - "configurePresets": [ - { - "name": "common", - "hidden": true, - "cacheVariables": { - "CMAKE_CXX_FLAGS": "$env{PROJECT_PLATFORM_FLAGS} $env{PROJECT_TEXT_FLAGS} $env{PROJECT_COMPILER_FLAGS} $penv{CXXFLAGS}" - }, - "vendor": { - "microsoft.com/VisualStudioSettings/CMake/1.0": { - "intelliSenseMode": "windows-msvc-x64", - "enableMicrosoftCodeAnalysis": true, - "enableClangTidyCodeAnalysis": true - } - } - }, - { - "name": "packaging-vcpkg", - "hidden": true, - "cacheVariables": { - "CMAKE_TOOLCHAIN_FILE": { - "type": "STRING", - "value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" - }, - "VCPKG_TARGET_TRIPLET": "x64-windows-static-md" - } - }, - { - "name": "buildtype-debug", - "hidden": true, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "buildtype-release", - "hidden": true, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" - } - }, - { - "name": "buildtype-relwithdebinfo", - "hidden": true, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "RelWithDebInfo" - } - }, - { - "name": "buildtype-minsizerel", - "hidden": true, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "MinSizeRel" - } - }, - { - "name": "x64", - "hidden": true, - "architecture": "x64", - "cacheVariables": { - "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$:Debug>DLL" - } - }, - { - "name": "generator-msvc", - "hidden": true, - "inherits": "x64", - "generator": "Visual Studio 17 2022" - }, - { - "name": "generator-ninja", - "hidden": true, - "generator": "Ninja" - }, - { - "name": "compiler-msvc", - "hidden": true, - "environment": { - "PROJECT_COMPILER_FLAGS": "/permissive- /Zc:preprocessor /EHsc /MP /W4 /WX /external:anglebrackets /external:W0 /bigobj", - "PROJECT_COMPILER": "msvc" - } - }, - { - "name": "compiler-clang", - "hidden": true, - "cacheVariables": { - "CMAKE_C_COMPILER": "clang", - "CMAKE_CXX_COMPILER": "clang++" - }, - "environment": { - "PROJECT_COMPILER": "clang", - "PROJECT_COMPILER_FLAGS": "-Wno-overloaded-virtual -Wno-delete-non-abstract-non-virtual-dtor -Wno-inconsistent-missing-override -Wno-reinterpret-base-class" - }, - "vendor": { - "microsoft.com/VisualStudioSettings/CMake/1.0": { - "intelliSenseMode": "windows-clang-x64" - } - } - }, - { - "name": "compiler-clang-cl", - "hidden": true, - "inherits": "compiler-clang", - "cacheVariables": { - "CMAKE_C_COMPILER": "clang-cl", - "CMAKE_CXX_COMPILER": "clang-cl" - }, - "environment": { - "CC": "clang-cl", - "CXX": "clang-cl", - "PROJECT_COMPILER_FLAGS": "/permissive- /EHsc /W4 /WX -Wno-overloaded-virtual -Wno-delete-non-abstract-non-virtual-dtor -Wno-inconsistent-missing-override -Wno-reinterpret-base-class -D__cpp_consteval" - } - }, - { - "name": "build-debug-msvc", - "inherits": [ - "common", - "packaging-vcpkg", - "buildtype-debug", - "generator-msvc", - "compiler-msvc" - ] - }, - { - "name": "build-debug-clang-cl", - "inherits": [ - "common", - "packaging-vcpkg", - "buildtype-debug", - "generator-ninja", - "compiler-clang-cl" - ] - }, - { - "name": "build-release-msvc", - "inherits": [ - "common", - "packaging-vcpkg", - "buildtype-release", - "generator-msvc", - "compiler-msvc" - ] - }, - { - "name": "build-release-clang-cl", - "inherits": [ - "common", - "packaging-vcpkg", - "buildtype-release", - "generator-ninja", - "compiler-clang-cl" - ] - }, - { - "name": "build-relwithdebinfo-msvc", - "inherits": [ - "common", - "packaging-vcpkg", - "buildtype-relwithdebinfo", - "generator-msvc", - "compiler-msvc" - ] - }, - { - "name": "build-relwithdebinfo-clang-cl", - "inherits": [ - "common", - "packaging-vcpkg", - "buildtype-relwithdebinfo", - "generator-ninja", - "compiler-clang-cl" - ] - }, - { - "name": "build-minsizerel-msvc", - "inherits": [ - "common", - "packaging-vcpkg", - "buildtype-minsizerel", - "generator-msvc", - "compiler-msvc" - ] - }, - { - "name": "build-minsizerel-clang-cl", - "inherits": [ - "common", - "packaging-vcpkg", - "buildtype-minsizerel", - "generator-ninja", - "compiler-clang-cl" - ] - }, - { - "name": "solution-msvc", - "inherits": [ - "common", - "packaging-vcpkg", - "buildtype-debug", - "generator-msvc", - "compiler-msvc" - ] - }, - { - "name": "solution-clang-cl", - "toolset": "ClangCL", - "inherits": [ - "common", - "packaging-vcpkg", - "buildtype-debug", - "generator-msvc", - "compiler-clang-cl" - ] - } - ] -} \ No newline at end of file + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 26, + "patch": 0 + }, + "configurePresets": [ + { + "name": "common", + "hidden": true, + "cacheVariables": { + "CMAKE_CXX_FLAGS": "$env{PROJECT_PLATFORM_FLAGS} $env{PROJECT_TEXT_FLAGS} $env{PROJECT_COMPILER_FLAGS} $penv{CXXFLAGS}" + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { + "intelliSenseMode": "windows-msvc-x64", + "enableMicrosoftCodeAnalysis": true, + "enableClangTidyCodeAnalysis": true + } + } + }, + { + "name": "packaging-vcpkg", + "hidden": true, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": { + "type": "STRING", + "value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + }, + "VCPKG_TARGET_TRIPLET": "x64-windows-static-md" + } + }, + { + "name": "buildtype-debug", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "buildtype-release", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "buildtype-relwithdebinfo", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "buildtype-minsizerel", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "MinSizeRel" + } + }, + { + "name": "x64", + "hidden": true, + "architecture": "x64", + "cacheVariables": { + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$:Debug>DLL" + } + }, + { + "name": "generator-msvc", + "hidden": true, + "inherits": "x64", + "generator": "Visual Studio 17 2022" + }, + { + "name": "generator-ninja", + "hidden": true, + "generator": "Ninja" + }, + { + "name": "compiler-msvc", + "hidden": true, + "environment": { + "PROJECT_COMPILER_FLAGS": "/permissive- /Zc:preprocessor /EHsc /MP /W4 /WX /external:anglebrackets /external:W0 /bigobj", + "PROJECT_COMPILER": "msvc" + } + }, + { + "name": "compiler-clang", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + }, + "environment": { + "PROJECT_COMPILER": "clang", + "PROJECT_COMPILER_FLAGS": "-Wno-overloaded-virtual -Wno-delete-non-abstract-non-virtual-dtor -Wno-inconsistent-missing-override -Wno-reinterpret-base-class" + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { + "intelliSenseMode": "windows-clang-x64" + } + } + }, + { + "name": "compiler-clang-cl", + "hidden": true, + "inherits": "compiler-clang", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl", + "CMAKE_CXX_COMPILER": "clang-cl" + }, + "environment": { + "CC": "clang-cl", + "CXX": "clang-cl", + "PROJECT_COMPILER_FLAGS": "/permissive- /EHsc /W4 /WX -Wno-overloaded-virtual -Wno-delete-non-abstract-non-virtual-dtor -Wno-inconsistent-missing-override -Wno-reinterpret-base-class -D__cpp_consteval" + } + }, + { + "name": "build-debug-msvc", + "inherits": [ + "common", + "packaging-vcpkg", + "buildtype-debug", + "generator-msvc", + "compiler-msvc" + ] + }, + { + "name": "build-debug-clang-cl", + "inherits": [ + "common", + "packaging-vcpkg", + "buildtype-debug", + "generator-ninja", + "compiler-clang-cl" + ] + }, + { + "name": "build-release-msvc", + "inherits": [ + "common", + "packaging-vcpkg", + "buildtype-release", + "generator-msvc", + "compiler-msvc" + ] + }, + { + "name": "build-release-clang-cl", + "inherits": [ + "common", + "packaging-vcpkg", + "buildtype-release", + "generator-ninja", + "compiler-clang-cl" + ] + }, + { + "name": "build-relwithdebinfo-msvc", + "inherits": [ + "common", + "packaging-vcpkg", + "buildtype-relwithdebinfo", + "generator-msvc", + "compiler-msvc" + ] + }, + { + "name": "build-relwithdebinfo-clang-cl", + "inherits": [ + "common", + "packaging-vcpkg", + "buildtype-relwithdebinfo", + "generator-ninja", + "compiler-clang-cl" + ] + }, + { + "name": "build-minsizerel-msvc", + "inherits": [ + "common", + "packaging-vcpkg", + "buildtype-minsizerel", + "generator-msvc", + "compiler-msvc" + ] + }, + { + "name": "build-minsizerel-clang-cl", + "inherits": [ + "common", + "packaging-vcpkg", + "buildtype-minsizerel", + "generator-ninja", + "compiler-clang-cl" + ] + }, + { + "name": "solution-msvc", + "inherits": [ + "common", + "packaging-vcpkg", + "buildtype-debug", + "generator-msvc", + "compiler-msvc" + ] + }, + { + "name": "solution-clang-cl", + "toolset": "ClangCL", + "inherits": [ + "common", + "packaging-vcpkg", + "buildtype-debug", + "generator-msvc", + "compiler-clang-cl" + ] + } + ] +} diff --git a/CommonLibSF/cmake/build_stl_modules.props b/CommonLibSF/cmake/build_stl_modules.props index a8184de9..d0cd0ba2 100644 --- a/CommonLibSF/cmake/build_stl_modules.props +++ b/CommonLibSF/cmake/build_stl_modules.props @@ -5,4 +5,4 @@ false - \ No newline at end of file + diff --git a/CommonLibSF/cmake/make-sourcelist.ps1 b/CommonLibSF/cmake/make-sourcelist.ps1 index 500ada6b..97cc7506 100644 --- a/CommonLibSF/cmake/make-sourcelist.ps1 +++ b/CommonLibSF/cmake/make-sourcelist.ps1 @@ -16,7 +16,7 @@ function Normalize-Path { param ( [string]$in ) - + $out = $in -replace '\\', '/' while ($out.Contains('//')) { $out = $out -replace '//', '/' @@ -28,7 +28,7 @@ function Resolve-Files { param ( [string[]]$range = @('include', 'src', 'test') ) - + process { Push-Location $PathIn $_generated = [System.Collections.ArrayList]::new(2048) diff --git a/CommonLibSF/include/RE/Offsets.h b/CommonLibSF/include/RE/Offsets.h index 41c7e864..daa06842 100644 --- a/CommonLibSF/include/RE/Offsets.h +++ b/CommonLibSF/include/RE/Offsets.h @@ -3,5 +3,4 @@ #include "REL/Relocation.h" namespace RE::Offset -{ -} +{} diff --git a/CommonLibSF/include/RE/Offsets_NiRTTI.h b/CommonLibSF/include/RE/Offsets_NiRTTI.h index fad7d07d..5608c592 100644 --- a/CommonLibSF/include/RE/Offsets_NiRTTI.h +++ b/CommonLibSF/include/RE/Offsets_NiRTTI.h @@ -3,5 +3,4 @@ #include "REL/Relocation.h" namespace RE -{ -} +{} diff --git a/CommonLibSF/include/RE/Offsets_RTTI.h b/CommonLibSF/include/RE/Offsets_RTTI.h index fad7d07d..5608c592 100644 --- a/CommonLibSF/include/RE/Offsets_RTTI.h +++ b/CommonLibSF/include/RE/Offsets_RTTI.h @@ -3,5 +3,4 @@ #include "REL/Relocation.h" namespace RE -{ -} +{} diff --git a/CommonLibSF/include/RE/Offsets_VTABLE.h b/CommonLibSF/include/RE/Offsets_VTABLE.h index fad7d07d..5608c592 100644 --- a/CommonLibSF/include/RE/Offsets_VTABLE.h +++ b/CommonLibSF/include/RE/Offsets_VTABLE.h @@ -3,5 +3,4 @@ #include "REL/Relocation.h" namespace RE -{ -} +{} diff --git a/CommonLibSF/include/RE/RTTI.h b/CommonLibSF/include/RE/RTTI.h index 1fa7f098..ed3c8b3b 100644 --- a/CommonLibSF/include/RE/RTTI.h +++ b/CommonLibSF/include/RE/RTTI.h @@ -11,17 +11,21 @@ namespace RE class __declspec(novtable) type_info { public: - virtual ~type_info(); // 00 + virtual ~type_info(); // 00 - [[nodiscard]] const char* mangled_name() const noexcept { return _name; } + [[nodiscard]] const char* mangled_name() const noexcept + { + return _name; + } private: // members - void* _data; // 08 - char _name[1]; // 10 + void* _data; // 08 + char _name[1]; // 10 }; + static_assert(sizeof(type_info) == 0x18); - } + } // namespace msvc namespace RTTI { @@ -30,27 +34,49 @@ namespace RE { public: using value_type = T; - using pointer = value_type*; - using reference = value_type&; + using pointer = value_type*; + using reference = value_type&; constexpr RVA() noexcept = default; - constexpr RVA(std::uint32_t a_rva) noexcept : - _rva(a_rva) + constexpr RVA(std::uint32_t a_rva) noexcept : _rva(a_rva) {} - [[nodiscard]] pointer get() const { return is_good() ? REL::Relocation{ REL::Offset(_rva) }.get() : nullptr; } - [[nodiscard]] std::uint32_t offset() const noexcept { return _rva; } - [[nodiscard]] reference operator*() const { return *get(); } - [[nodiscard]] pointer operator->() const { return get(); } - [[nodiscard]] explicit constexpr operator bool() const noexcept { return is_good(); } + [[nodiscard]] pointer get() const + { + return is_good() ? REL::Relocation{ REL::Offset(_rva) }.get() : nullptr; + } + + [[nodiscard]] std::uint32_t offset() const noexcept + { + return _rva; + } + + [[nodiscard]] reference operator*() const + { + return *get(); + } + + [[nodiscard]] pointer operator->() const + { + return get(); + } + + [[nodiscard]] explicit constexpr operator bool() const noexcept + { + return is_good(); + } protected: - [[nodiscard]] constexpr bool is_good() const noexcept { return _rva != 0; } + [[nodiscard]] constexpr bool is_good() const noexcept + { + return _rva != 0; + } // members - std::uint32_t _rva{ 0 }; // 00 + std::uint32_t _rva{ 0 }; // 00 }; + static_assert(sizeof(RVA) == 0x4); using TypeDescriptor = msvc::type_info; @@ -59,10 +85,11 @@ namespace RE { public: // members - std::int32_t mDisp; // 0 - std::int32_t pDisp; // 4 - std::int32_t vDisp; // 8 + std::int32_t mDisp; // 0 + std::int32_t pDisp; // 4 + std::int32_t vDisp; // 8 }; + static_assert(sizeof(PMD) == 0xC); struct BaseClassDescriptor @@ -70,22 +97,23 @@ namespace RE public: enum class Attribute : std::uint32_t { - kNone = 0, - kNotVisible = 1 << 0, - kAmbiguous = 1 << 1, - kPrivate = 1 << 2, + kNone = 0, + kNotVisible = 1 << 0, + kAmbiguous = 1 << 1, + kPrivate = 1 << 2, kPrivateOrProtectedBase = 1 << 3, - kVirtual = 1 << 4, - kNonPolymorphic = 1 << 5, + kVirtual = 1 << 4, + kNonPolymorphic = 1 << 5, kHasHierarchyDescriptor = 1 << 6 }; // members - RVA typeDescriptor; // 00 - std::uint32_t numContainedBases; // 04 - PMD pmd; // 08 - stl::enumeration attributes; // 14 + RVA typeDescriptor; // 00 + std::uint32_t numContainedBases; // 04 + PMD pmd; // 08 + stl::enumeration attributes; // 14 }; + static_assert(sizeof(BaseClassDescriptor) == 0x18); struct ClassHierarchyDescriptor @@ -93,18 +121,19 @@ namespace RE public: enum class Attribute { - kNoInheritance = 0, - kMultipleInheritance = 1 << 0, - kVirtualInheritance = 1 << 1, + kNoInheritance = 0, + kMultipleInheritance = 1 << 0, + kVirtualInheritance = 1 << 1, kAmbiguousInheritance = 1 << 2 }; // members - std::uint32_t signature; // 00 - stl::enumeration attributes; // 04 - std::uint32_t numBaseClasses; // 08 - RVA baseClassArray; // 0C + std::uint32_t signature; // 00 + stl::enumeration attributes; // 04 + std::uint32_t numBaseClasses; // 08 + RVA baseClassArray; // 0C }; + static_assert(sizeof(ClassHierarchyDescriptor) == 0x10); struct CompleteObjectLocator @@ -117,14 +146,15 @@ namespace RE }; // members - stl::enumeration signature; // 00 - std::uint32_t offset; // 04 - std::uint32_t ctorDispOffset; // 08 - RVA typeDescriptor; // 0C - RVA classDescriptor; // 10 + stl::enumeration signature; // 00 + std::uint32_t offset; // 04 + std::uint32_t ctorDispOffset; // 08 + RVA typeDescriptor; // 0C + RVA classDescriptor; // 10 }; + static_assert(sizeof(CompleteObjectLocator) == 0x14); - } + } // namespace RTTI inline void* RTDynamicCast(void* a_inptr, std::int32_t a_vfDelta, void* a_srcType, void* a_targetType, std::int32_t a_isReference) { @@ -136,110 +166,60 @@ namespace RE namespace detail { template - using remove_cvpr_t = - std::remove_cv_t< - std::remove_pointer_t< - std::remove_reference_t>>; + using remove_cvpr_t = std::remove_cv_t>>; template - struct target_is_valid : - std::disjunction< - std::is_polymorphic< - remove_cvpr_t>, - std::is_same< - void*, - std::remove_cv_t>> + struct target_is_valid : std::disjunction>, std::is_same>> {}; template - struct types_are_compat : - std::false_type + struct types_are_compat : std::false_type {}; template - struct types_are_compat : - std::is_pointer + struct types_are_compat : std::is_pointer {}; template - struct types_are_compat : - std::conjunction< - std::is_pointer, - std::is_const< - std::remove_pointer_t>> + struct types_are_compat : std::conjunction, std::is_const>> {}; template - struct types_are_compat : - std::conjunction< - std::is_pointer, - std::is_volatile< - std::remove_pointer_t>> + struct types_are_compat : std::conjunction, std::is_volatile>> {}; template - struct types_are_compat : - std::conjunction< - std::is_pointer, - std::is_const< - std::remove_pointer_t>, - std::is_volatile< - std::remove_pointer_t>> + struct types_are_compat + : std::conjunction, std::is_const>, std::is_volatile>> {}; template - struct implements_rtti : - std::false_type + struct implements_rtti : std::false_type {}; template - struct implements_rtti< - T, - std::void_t< - decltype(remove_cvpr_t::RTTI)>> : - std::true_type + struct implements_rtti::RTTI)>> : std::true_type {}; template - struct cast_is_valid : - std::conjunction< - types_are_compat< - To, - From>, - target_is_valid< - To>, - implements_rtti, - implements_rtti> + struct cast_is_valid : std::conjunction, target_is_valid, implements_rtti, implements_rtti> {}; template inline constexpr bool cast_is_valid_v = cast_is_valid::value; - } -} + } // namespace detail +} // namespace RE -template < - class To, - class From, - std::enable_if_t< - RE::detail::cast_is_valid_v< - To, - From*>, - int> = 0> +template , int> = 0> To starfield_cast(From* a_from) { REL::Relocation from{ RE::detail::remove_cvpr_t::RTTI }; REL::Relocation to{ RE::detail::remove_cvpr_t::RTTI }; - if (!from.get() || !to.get()) { + if (!from.get() || !to.get()) + { return nullptr; } - return static_cast( - RE::RTDynamicCast( - const_cast( - static_cast(a_from)), - 0, - from.get(), - to.get(), - false)); + return static_cast(RE::RTDynamicCast(const_cast(static_cast(a_from)), 0, from.get(), to.get(), false)); } diff --git a/CommonLibSF/include/REL/Relocation.h b/CommonLibSF/include/REL/Relocation.h index 16650a3b..4d5f2afb 100644 --- a/CommonLibSF/include/REL/Relocation.h +++ b/CommonLibSF/include/REL/Relocation.h @@ -1,19 +1,13 @@ #pragma once #define REL_MAKE_MEMBER_FUNCTION_POD_TYPE_HELPER_IMPL(a_nopropQual, a_propQual, ...) \ - template < \ - class R, \ - class Cls, \ - class... Args> \ + template \ struct member_function_pod_type \ { \ using type = R(__VA_ARGS__ Cls*, Args...) a_propQual; \ }; \ \ - template < \ - class R, \ - class Cls, \ - class... Args> \ + template \ struct member_function_pod_type \ { \ using type = R(__VA_ARGS__ Cls*, Args..., ...) a_propQual; \ @@ -29,19 +23,13 @@ REL_MAKE_MEMBER_FUNCTION_POD_TYPE_HELPER(&&, ##__VA_ARGS__) #define REL_MAKE_MEMBER_FUNCTION_NON_POD_TYPE_HELPER_IMPL(a_nopropQual, a_propQual, ...) \ - template < \ - class R, \ - class Cls, \ - class... Args> \ + template \ struct member_function_non_pod_type \ { \ using type = R&(__VA_ARGS__ Cls*, void*, Args...)a_propQual; \ }; \ \ - template < \ - class R, \ - class Cls, \ - class... Args> \ + template \ struct member_function_non_pod_type \ { \ using type = R&(__VA_ARGS__ Cls*, void*, Args..., ...)a_propQual; \ @@ -85,80 +73,49 @@ namespace REL // https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention template - struct meets_length_req : - std::disjunction< - std::bool_constant, - std::bool_constant, - std::bool_constant, - std::bool_constant> - { - }; + struct meets_length_req : std::disjunction, std::bool_constant, + std::bool_constant, std::bool_constant> + {}; template - struct meets_function_req : - std::conjunction< - std::is_trivially_constructible, - std::is_trivially_destructible, - std::is_trivially_copy_assignable, - std::negation< - std::is_polymorphic>> - { - }; + struct meets_function_req : std::conjunction, std::is_trivially_destructible, + std::is_trivially_copy_assignable, std::negation>> + {}; template - struct meets_member_req : - std::is_standard_layout - { - }; + struct meets_member_req : std::is_standard_layout + {}; template - struct is_x64_pod : - std::true_type - { - }; + struct is_x64_pod : std::true_type + {}; template - struct is_x64_pod< - T, - std::enable_if_t< - std::is_union_v>> : - std::false_type - { - }; + struct is_x64_pod>> : std::false_type + {}; template - struct is_x64_pod< - T, - std::enable_if_t< - std::is_class_v>> : - std::conjunction< - meets_length_req, - meets_function_req, - meets_member_req> - { - }; + struct is_x64_pod>> : std::conjunction, meets_function_req, meets_member_req> + {}; template static constexpr bool is_x64_pod_v = is_x64_pod::value; - template < - class F, - class First, - class... Rest> - decltype(auto) invoke_member_function_non_pod(F&& a_func, First&& a_first, Rest&&... a_rest) // + template + decltype(auto) invoke_member_function_non_pod(F&& a_func, First&& a_first, Rest&&... a_rest) // noexcept(std::is_nothrow_invocable_v) { using result_t = std::invoke_result_t; alignas(result_t) std::byte result[sizeof(result_t)]{}; using func_t = member_function_non_pod_type_t; - auto func = std::bit_cast(std::forward(a_func)); + auto func = std::bit_cast(std::forward(a_func)); return func(std::forward(a_first), std::addressof(result), std::forward(a_rest)...); } - } + } // namespace detail - inline constexpr std::uint8_t NOP = 0x90; + inline constexpr std::uint8_t NOP = 0x90; inline constexpr std::uint8_t NOP2[] = { 0x66, 0x90 }; inline constexpr std::uint8_t NOP3[] = { 0x0F, 0x1F, 0x00 }; inline constexpr std::uint8_t NOP4[] = { 0x0F, 0x1F, 0x40, 0x00 }; @@ -168,25 +125,31 @@ namespace REL inline constexpr std::uint8_t NOP8[] = { 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 }; inline constexpr std::uint8_t NOP9[] = { 0x66, 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 }; - inline constexpr std::uint8_t JMP8 = 0xEB; + inline constexpr std::uint8_t JMP8 = 0xEB; inline constexpr std::uint8_t JMP32 = 0xE9; - inline constexpr std::uint8_t RET = 0xC3; - inline constexpr std::uint8_t INT3 = 0xCC; + inline constexpr std::uint8_t RET = 0xC3; + inline constexpr std::uint8_t INT3 = 0xCC; template - std::invoke_result_t invoke(F&& a_func, Args&&... a_args) // - noexcept(std::is_nothrow_invocable_v) // + std::invoke_result_t invoke(F&& a_func, Args&&... a_args) // + noexcept(std::is_nothrow_invocable_v) // requires(std::invocable) { - if constexpr (std::is_member_function_pointer_v>) { - if constexpr (detail::is_x64_pod_v>) { // member functions == free functions in x64 + if constexpr (std::is_member_function_pointer_v>) + { + if constexpr (detail::is_x64_pod_v>) + { // member functions == free functions in x64 using func_t = detail::member_function_pod_type_t>; - auto func = stl::unrestricted_cast(std::forward(a_func)); + auto func = stl::unrestricted_cast(std::forward(a_func)); return func(std::forward(a_args)...); - } else { // shift args to insert result + } + else + { // shift args to insert result return detail::invoke_member_function_non_pod(std::forward(a_func), std::forward(a_args)...); } - } else { + } + else + { return std::forward(a_func)(std::forward(a_args)...); } } @@ -194,20 +157,11 @@ namespace REL inline void safe_write(std::uintptr_t a_dst, const void* a_src, std::size_t a_count) { std::uint32_t old{ 0 }; - auto success = - WinAPI::VirtualProtect( - reinterpret_cast(a_dst), - a_count, - (PAGE_EXECUTE_READWRITE), - std::addressof(old)); - if (success != 0) { + auto success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, (PAGE_EXECUTE_READWRITE), std::addressof(old)); + if (success != 0) + { std::memcpy(reinterpret_cast(a_dst), a_src, a_count); - success = - WinAPI::VirtualProtect( - reinterpret_cast(a_dst), - a_count, - old, - std::addressof(old)); + success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, old, std::addressof(old)); } assert(success != 0); @@ -228,20 +182,11 @@ namespace REL inline void safe_fill(std::uintptr_t a_dst, std::uint8_t a_value, std::size_t a_count) { std::uint32_t old{ 0 }; - auto success = - WinAPI::VirtualProtect( - reinterpret_cast(a_dst), - a_count, - (PAGE_EXECUTE_READWRITE), - std::addressof(old)); - if (success != 0) { + auto success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, (PAGE_EXECUTE_READWRITE), std::addressof(old)); + if (success != 0) + { std::fill_n(reinterpret_cast(a_dst), a_count, a_value); - success = - WinAPI::VirtualProtect( - reinterpret_cast(a_dst), - a_count, - old, - std::addressof(old)); + success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, old, std::addressof(old)); } assert(success != 0); @@ -250,60 +195,91 @@ namespace REL class Version { public: - using value_type = std::uint16_t; - using reference = value_type&; + using value_type = std::uint16_t; + using reference = value_type&; using const_reference = const value_type&; constexpr Version() noexcept = default; - explicit constexpr Version(std::array a_version) noexcept : - _impl(a_version) {} + explicit constexpr Version(std::array a_version) noexcept : _impl(a_version) + {} - constexpr Version(value_type a_v1, value_type a_v2 = 0, value_type a_v3 = 0, value_type a_v4 = 0) noexcept : - _impl{ a_v1, a_v2, a_v3, a_v4 } {} + constexpr Version(value_type a_v1, value_type a_v2 = 0, value_type a_v3 = 0, value_type a_v4 = 0) noexcept : _impl{ a_v1, a_v2, a_v3, a_v4 } + {} explicit constexpr Version(std::string_view a_version) { std::array powers{ 1, 1, 1, 1 }; std::size_t position = 0; - for (std::size_t i = 0; i < a_version.size(); ++i) { - if (a_version[i] == '.') { - if (++position == powers.size()) { + for (std::size_t i = 0; i < a_version.size(); ++i) + { + if (a_version[i] == '.') + { + if (++position == powers.size()) + { throw std::invalid_argument("Too many parts in version number."); } - } else { + } + else + { powers[position] *= 10; } } position = 0; - for (std::size_t i = 0; i < a_version.size(); ++i) { - if (a_version[i] == '.') { + for (std::size_t i = 0; i < a_version.size(); ++i) + { + if (a_version[i] == '.') + { ++position; - } else if (a_version[i] < '0' || a_version[i] > '9') { + } + else if (a_version[i] < '0' || a_version[i] > '9') + { throw std::invalid_argument("Invalid character in version number."); - } else { + } + else + { powers[position] /= 10; _impl[position] += static_cast((a_version[i] - '0') * powers[position]); } } } - [[nodiscard]] constexpr reference operator[](std::size_t a_idx) noexcept { return _impl[a_idx]; } + [[nodiscard]] constexpr reference operator[](std::size_t a_idx) noexcept + { + return _impl[a_idx]; + } - [[nodiscard]] constexpr const_reference operator[](std::size_t a_idx) const noexcept { return _impl[a_idx]; } + [[nodiscard]] constexpr const_reference operator[](std::size_t a_idx) const noexcept + { + return _impl[a_idx]; + } - [[nodiscard]] constexpr decltype(auto) begin() const noexcept { return _impl.begin(); } + [[nodiscard]] constexpr decltype(auto) begin() const noexcept + { + return _impl.begin(); + } - [[nodiscard]] constexpr decltype(auto) cbegin() const noexcept { return _impl.cbegin(); } + [[nodiscard]] constexpr decltype(auto) cbegin() const noexcept + { + return _impl.cbegin(); + } - [[nodiscard]] constexpr decltype(auto) end() const noexcept { return _impl.end(); } + [[nodiscard]] constexpr decltype(auto) end() const noexcept + { + return _impl.end(); + } - [[nodiscard]] constexpr decltype(auto) cend() const noexcept { return _impl.cend(); } + [[nodiscard]] constexpr decltype(auto) cend() const noexcept + { + return _impl.cend(); + } [[nodiscard]] std::strong_ordering constexpr compare(const Version& a_rhs) const noexcept { - for (std::size_t i = 0; i < _impl.size(); ++i) { - if ((*this)[i] != a_rhs[i]) { + for (std::size_t i = 0; i < _impl.size(); ++i) + { + if ((*this)[i] != a_rhs[i]) + { return (*this)[i] < a_rhs[i] ? std::strong_ordering::less : std::strong_ordering::greater; } } @@ -312,11 +288,8 @@ namespace REL [[nodiscard]] constexpr std::uint32_t pack() const noexcept { - return static_cast( - (_impl[0] & 0x0FF) << 24u | - (_impl[1] & 0x0FF) << 16u | - (_impl[2] & 0xFFF) << 4u | - (_impl[3] & 0x00F) << 0u); + return static_cast((_impl[0] & 0x0FF) << 24u | (_impl[1] & 0x0FF) << 16u | (_impl[2] & 0xFFF) << 4u + | (_impl[3] & 0x00F) << 0u); } [[nodiscard]] constexpr value_type major() const noexcept @@ -342,7 +315,8 @@ namespace REL [[nodiscard]] std::string string(std::string_view a_separator = "-"sv) const { std::string result; - for (auto&& ver : _impl) { + for (auto&& ver : _impl) + { result += std::to_string(ver); result.append(a_separator.data(), a_separator.size()); } @@ -353,7 +327,8 @@ namespace REL [[nodiscard]] std::wstring wstring(std::wstring_view a_separator = L"-"sv) const { std::wstring result; - for (auto&& ver : _impl) { + for (auto&& ver : _impl) + { result += std::to_wstring(ver); result.append(a_separator.data(), a_separator.size()); } @@ -363,12 +338,8 @@ namespace REL [[nodiscard]] static constexpr Version unpack(std::uint32_t a_packedVersion) noexcept { - return REL::Version{ - static_cast((a_packedVersion >> 24) & 0x0FF), - static_cast((a_packedVersion >> 16) & 0x0FF), - static_cast((a_packedVersion >> 4) & 0xFFF), - static_cast(a_packedVersion & 0x0F) - }; + return REL::Version{ static_cast((a_packedVersion >> 24) & 0x0FF), static_cast((a_packedVersion >> 16) & 0x0FF), + static_cast((a_packedVersion >> 4) & 0xFFF), static_cast(a_packedVersion & 0x0F) }; } private: @@ -380,8 +351,10 @@ namespace REL return a_lhs.compare(a_rhs) == std::strong_ordering::equal; } - [[nodiscard]] constexpr std::strong_ordering - operator<=>(const Version& a_lhs, const Version& a_rhs) noexcept { return a_lhs.compare(a_rhs); } + [[nodiscard]] constexpr std::strong_ordering operator<=>(const Version& a_lhs, const Version& a_rhs) noexcept + { + return a_lhs.compare(a_rhs); + } namespace literals { @@ -402,16 +375,19 @@ namespace REL { static_assert(C == '.' || (C >= '0' && C <= '9'), "Invalid character in semantic version literal."); static_assert(Index < 4, "Too many components in semantic version literal."); - if constexpr (C == '.') { + if constexpr (C == '.') + { read_version(result); return 1; - } else { + } + else + { auto position = read_version(result); result[Index] += (C - '0') * position; return position * 10; } } - } + } // namespace detail template [[nodiscard]] constexpr REL::Version operator""_v() noexcept @@ -425,32 +401,34 @@ namespace REL { return Version(std::string_view(str, len)); } - } + } // namespace literals [[nodiscard]] inline std::optional get_file_version(stl::zwstring a_filename) { std::uint32_t dummy{ 0 }; std::vector buf(GetFileVersionInfoSize(a_filename.data(), std::addressof(dummy))); - if (buf.empty()) { + if (buf.empty()) + { return std::nullopt; } - if (!GetFileVersionInfo(a_filename.data(), 0, static_cast(buf.size()), buf.data())) { + if (!GetFileVersionInfo(a_filename.data(), 0, static_cast(buf.size()), buf.data())) + { return std::nullopt; } void* verBuf{ nullptr }; std::uint32_t verLen{ 0 }; - if (!VerQueryValue(buf.data(), L"\\StringFileInfo\\040904B0\\ProductVersion", std::addressof(verBuf), - std::addressof(verLen))) { + if (!VerQueryValue(buf.data(), L"\\StringFileInfo\\040904B0\\ProductVersion", std::addressof(verBuf), std::addressof(verLen))) + { return std::nullopt; } Version version; - std::wistringstream ss( - std::wstring(static_cast(verBuf), verLen)); - std::wstring token; - for (std::size_t i = 0; i < 4 && std::getline(ss, token, L'.'); ++i) { + std::wistringstream ss(std::wstring(static_cast(verBuf), verLen)); + std::wstring token; + for (std::size_t i = 0; i < 4 && std::getline(ss, token, L'.'); ++i) + { version[i] = static_cast(std::stoi(token)); } @@ -475,18 +453,29 @@ namespace REL Segment() noexcept = default; - Segment(std::uintptr_t a_proxyBase, std::uintptr_t a_address, std::uintptr_t a_size) noexcept : - _proxyBase(a_proxyBase), - _address(a_address), - _size(a_size) {} + Segment(std::uintptr_t a_proxyBase, std::uintptr_t a_address, std::uintptr_t a_size) noexcept + : _proxyBase(a_proxyBase), _address(a_address), _size(a_size) + {} - [[nodiscard]] std::uintptr_t address() const noexcept { return _address; } + [[nodiscard]] std::uintptr_t address() const noexcept + { + return _address; + } - [[nodiscard]] std::size_t offset() const noexcept { return address() - _proxyBase; } + [[nodiscard]] std::size_t offset() const noexcept + { + return address() - _proxyBase; + } - [[nodiscard]] std::size_t size() const noexcept { return _size; } + [[nodiscard]] std::size_t size() const noexcept + { + return _size; + } - [[nodiscard]] void* pointer() const noexcept { return reinterpret_cast(address()); } + [[nodiscard]] void* pointer() const noexcept + { + return reinterpret_cast(address()); + } template [[nodiscard]] T* pointer() const noexcept @@ -509,19 +498,29 @@ namespace REL explicit Module(std::uintptr_t a_base); explicit Module(std::string_view a_filePath); - [[nodiscard]] constexpr auto base() const noexcept { return _base; } + [[nodiscard]] constexpr auto base() const noexcept + { + return _base; + } + template [[nodiscard]] constexpr auto* pointer() const noexcept { return std::bit_cast(base()); } - [[nodiscard]] constexpr auto segment(Segment::Name a_segment) noexcept { return _segments[a_segment]; } + + [[nodiscard]] constexpr auto segment(Segment::Name a_segment) noexcept + { + return _segments[a_segment]; + } + [[nodiscard]] static Module& get(const std::uintptr_t a_address) noexcept { static std::unordered_map managed; const auto base = AsAddress(a_address) & ~3; - if (!managed.contains(base)) { + if (!managed.contains(base)) + { managed.try_emplace(base, base); } @@ -535,16 +534,14 @@ namespace REL } private: - static constexpr std::array SEGMENTS{ - std::make_pair(".text"sv, IMAGE_SCN_MEM_EXECUTE), - std::make_pair(".idata"sv, static_cast(0)), - std::make_pair(".rdata"sv, static_cast(0)), - std::make_pair(".data"sv, static_cast(0)), - std::make_pair(".pdata"sv, static_cast(0)), - std::make_pair(".tls"sv, static_cast(0)), - std::make_pair(".text"sv, IMAGE_SCN_MEM_WRITE), - std::make_pair(".gfids"sv, static_cast(0)) - }; + static constexpr std::array SEGMENTS{ std::make_pair(".text"sv, IMAGE_SCN_MEM_EXECUTE), + std::make_pair(".idata"sv, static_cast(0)), + std::make_pair(".rdata"sv, static_cast(0)), + std::make_pair(".data"sv, static_cast(0)), + std::make_pair(".pdata"sv, static_cast(0)), + std::make_pair(".tls"sv, static_cast(0)), + std::make_pair(".text"sv, IMAGE_SCN_MEM_WRITE), + std::make_pair(".gfids"sv, static_cast(0)) }; std::uintptr_t _base; std::array _segments; @@ -554,8 +551,8 @@ namespace REL { public: constexpr Offset() = default; - constexpr Offset(std::ptrdiff_t a_offset) : - _offset(a_offset) + + constexpr Offset(std::ptrdiff_t a_offset) : _offset(a_offset) {} [[nodiscard]] constexpr std::uintptr_t offset() const noexcept @@ -576,25 +573,21 @@ namespace REL class Relocation { public: - using value_type = - std::conditional_t< - std::is_member_pointer_v || std::is_function_v>, - std::decay_t, T>; + using value_type = std::conditional_t || std::is_function_v>, std::decay_t, T>; constexpr Relocation() noexcept = default; - constexpr Relocation(const std::uintptr_t a_addr) noexcept : - _address(a_addr) + + constexpr Relocation(const std::uintptr_t a_addr) noexcept : _address(a_addr) {} - constexpr Relocation(Offset a_rva) noexcept : - _address(a_rva.address()) + + constexpr Relocation(Offset a_rva) noexcept : _address(a_rva.address()) {} - constexpr Relocation(Offset a_rva, std::ptrdiff_t a_offset) noexcept : - _address(a_rva.address() + a_offset) + + constexpr Relocation(Offset a_rva, std::ptrdiff_t a_offset) noexcept : _address(a_rva.address() + a_offset) {} template - [[nodiscard]] constexpr U get() const - noexcept(std::is_nothrow_copy_constructible_v) + [[nodiscard]] constexpr U get() const noexcept(std::is_nothrow_copy_constructible_v) { return std::bit_cast(_address); } @@ -603,7 +596,11 @@ namespace REL { return _address; } - [[nodiscard]] std::size_t offset() const noexcept { return _address - base(); } + + [[nodiscard]] std::size_t offset() const noexcept + { + return _address - base(); + } [[nodiscard]] constexpr decltype(auto) operator*() const noexcept requires(std::is_pointer_v) @@ -611,31 +608,31 @@ namespace REL return *get(); } - [[nodiscard]] constexpr auto operator->() const noexcept // + [[nodiscard]] constexpr auto operator->() const noexcept // requires(std::is_pointer_v) { return get(); } template - std::invoke_result_t operator()(Args&&... a_args) const // - noexcept(std::is_nothrow_invocable_v) // + std::invoke_result_t operator()(Args&&... a_args) const // + noexcept(std::is_nothrow_invocable_v) // requires(std::invocable) { return invoke(get(), std::forward(a_args)...); } - std::uintptr_t write_vfunc(std::size_t a_idx, std::uintptr_t a_newFunc) // + std::uintptr_t write_vfunc(std::size_t a_idx, std::uintptr_t a_newFunc) // requires(std::same_as) { - const auto addr = address() + (sizeof(void*) * a_idx); + const auto addr = address() + (sizeof(void*) * a_idx); const auto result = *std::bit_cast(addr); safe_write(addr, a_newFunc); return result; } template - std::uintptr_t write_vfunc(std::size_t a_idx, F a_newFunc) // + std::uintptr_t write_vfunc(std::size_t a_idx, F a_newFunc) // requires(std::same_as) { return write_vfunc(a_idx, stl::unrestricted_cast(a_newFunc)); @@ -645,14 +642,18 @@ namespace REL template void write_vfunc() { - REL::Relocation vtbl{ F::VTABLE[0] }; - T::func = vtbl.write_vfunc(idx, T::thunk); + REL::Relocation vtbl{ F::VTABLE[0] + * }; + T::func = vtbl.write_vfunc(idx, T::thunk); } **/ private: - [[nodiscard]] static std::uintptr_t base() { return Module::get().base(); } + [[nodiscard]] static std::uintptr_t base() + { + return Module::get().base(); + } std::uintptr_t _address{ 0 }; }; -} +} // namespace REL diff --git a/CommonLibSF/include/SFSE/API.h b/CommonLibSF/include/SFSE/API.h index c1f0a40b..ec06a11f 100644 --- a/CommonLibSF/include/SFSE/API.h +++ b/CommonLibSF/include/SFSE/API.h @@ -19,4 +19,4 @@ namespace SFSE Trampoline& GetTrampoline(); void AllocTrampoline(std::size_t a_size, bool a_trySFSEReserve = true); -} +} // namespace SFSE diff --git a/CommonLibSF/include/SFSE/IAT.h b/CommonLibSF/include/SFSE/IAT.h index 06e02545..13944ca1 100644 --- a/CommonLibSF/include/SFSE/IAT.h +++ b/CommonLibSF/include/SFSE/IAT.h @@ -28,4 +28,4 @@ namespace SFSE { return PatchIAT(stl::unrestricted_cast(a_newFunc), a_dll, a_function); } -} +} // namespace SFSE diff --git a/CommonLibSF/include/SFSE/Impl/DInputAPI.h b/CommonLibSF/include/SFSE/Impl/DInputAPI.h index 59480c7e..1bcd03cd 100644 --- a/CommonLibSF/include/SFSE/Impl/DInputAPI.h +++ b/CommonLibSF/include/SFSE/Impl/DInputAPI.h @@ -7,199 +7,199 @@ namespace RE::DirectInput8 { using DWORD = std::uint32_t; - using LONG = std::int32_t; - using WORD = std::uint16_t; - using BYTE = std::uint8_t; - using UINT = std::uint32_t; - using CHAR = char; + using LONG = std::int32_t; + using WORD = std::uint16_t; + using BYTE = std::uint8_t; + using UINT = std::uint32_t; + using CHAR = char; - using LPSTR = char*; + using LPSTR = char*; using LPCSTR = const char*; using UINT_PTR = std::uintptr_t; - using HANDLE = void*; - using LPDWORD = DWORD*; - using LPVOID = void*; - using LPLONG = LONG*; - using LPWORD = WORD*; - - using GUID = SFSE::WinAPI::GUID; - using LPGUID = GUID*; - using REFGUID = const GUID&; + using HANDLE = void*; + using LPDWORD = DWORD*; + using LPVOID = void*; + using LPLONG = LONG*; + using LPWORD = WORD*; + + using GUID = SFSE::WinAPI::GUID; + using LPGUID = GUID*; + using REFGUID = const GUID&; using FILETIME = SFSE::WinAPI::FILETIME; - using RECT = SFSE::WinAPI::RECT; - using POINT = SFSE::WinAPI::POINT; + using RECT = SFSE::WinAPI::RECT; + using POINT = SFSE::WinAPI::POINT; - using IID = GUID; - using REFIID = const IID&; - using LPIID = IID*; + using IID = GUID; + using REFIID = const IID&; + using LPIID = IID*; using D3DCOLOR = std::uint32_t; - using HRESULT = SFSE::WinAPI::HRESULT; - using HWND = SFSE::WinAPI::HWND; + using HRESULT = SFSE::WinAPI::HRESULT; + using HWND = SFSE::WinAPI::HWND; using HINSTANCE = SFSE::WinAPI::HINSTANCE; enum DIKey : uint32_t { - DIK_ESCAPE = 0x1, - DIK_1 = 0x2, - DIK_2 = 0x3, - DIK_3 = 0x4, - DIK_4 = 0x5, - DIK_5 = 0x6, - DIK_6 = 0x7, - DIK_7 = 0x8, - DIK_8 = 0x9, - DIK_9 = 0xA, - DIK_0 = 0xB, - DIK_MINUS = 0xC, - DIK_EQUALS = 0xD, - DIK_BACK = 0xE, - DIK_TAB = 0xF, - DIK_Q = 0x10, - DIK_W = 0x11, - DIK_E = 0x12, - DIK_R = 0x13, - DIK_T = 0x14, - DIK_Y = 0x15, - DIK_U = 0x16, - DIK_I = 0x17, - DIK_O = 0x18, - DIK_P = 0x19, - DIK_LBRACKET = 0x1A, - DIK_RBRACKET = 0x1B, - DIK_RETURN = 0x1C, - DIK_LCONTROL = 0x1D, - DIK_A = 0x1E, - DIK_S = 0x1F, - DIK_D = 0x20, - DIK_F = 0x21, - DIK_G = 0x22, - DIK_H = 0x23, - DIK_J = 0x24, - DIK_K = 0x25, - DIK_L = 0x26, - DIK_SEMICOLON = 0x27, - DIK_APOSTROPHE = 0x28, - DIK_GRAVE = 0x29, - DIK_LSHIFT = 0x2A, - DIK_BACKSLASH = 0x2B, - DIK_Z = 0x2C, - DIK_X = 0x2D, - DIK_C = 0x2E, - DIK_V = 0x2F, - DIK_B = 0x30, - DIK_N = 0x31, - DIK_M = 0x32, - DIK_COMMA = 0x33, - DIK_PERIOD = 0x34, - DIK_SLASH = 0x35, - DIK_RSHIFT = 0x36, - DIK_MULTIPLY = 0x37, - DIK_LMENU = 0x38, - DIK_SPACE = 0x39, - DIK_CAPITAL = 0x3A, - DIK_F1 = 0x3B, - DIK_F2 = 0x3C, - DIK_F3 = 0x3D, - DIK_F4 = 0x3E, - DIK_F5 = 0x3F, - DIK_F6 = 0x40, - DIK_F7 = 0x41, - DIK_F8 = 0x42, - DIK_F9 = 0x43, - DIK_F10 = 0x44, - DIK_NUMLOCK = 0x45, - DIK_SCROLL = 0x46, - DIK_NUMPAD7 = 0x47, - DIK_NUMPAD8 = 0x48, - DIK_NUMPAD9 = 0x49, - DIK_SUBTRACT = 0x4A, - DIK_NUMPAD4 = 0x4B, - DIK_NUMPAD5 = 0x4C, - DIK_NUMPAD6 = 0x4D, - DIK_ADD = 0x4E, - DIK_NUMPAD1 = 0x4F, - DIK_NUMPAD2 = 0x50, - DIK_NUMPAD3 = 0x51, - DIK_NUMPAD0 = 0x52, - DIK_DECIMAL = 0x53, - DIK_OEM_102 = 0x56, - DIK_F11 = 0x57, - DIK_F12 = 0x58, - DIK_F13 = 0x64, - DIK_F14 = 0x65, - DIK_F15 = 0x66, - DIK_KANA = 0x70, - DIK_ABNT_C1 = 0x73, - DIK_CONVERT = 0x79, - DIK_NOCONVERT = 0x7B, - DIK_YEN = 0x7D, - DIK_ABNT_C2 = 0x7E, + DIK_ESCAPE = 0x1, + DIK_1 = 0x2, + DIK_2 = 0x3, + DIK_3 = 0x4, + DIK_4 = 0x5, + DIK_5 = 0x6, + DIK_6 = 0x7, + DIK_7 = 0x8, + DIK_8 = 0x9, + DIK_9 = 0xA, + DIK_0 = 0xB, + DIK_MINUS = 0xC, + DIK_EQUALS = 0xD, + DIK_BACK = 0xE, + DIK_TAB = 0xF, + DIK_Q = 0x10, + DIK_W = 0x11, + DIK_E = 0x12, + DIK_R = 0x13, + DIK_T = 0x14, + DIK_Y = 0x15, + DIK_U = 0x16, + DIK_I = 0x17, + DIK_O = 0x18, + DIK_P = 0x19, + DIK_LBRACKET = 0x1A, + DIK_RBRACKET = 0x1B, + DIK_RETURN = 0x1C, + DIK_LCONTROL = 0x1D, + DIK_A = 0x1E, + DIK_S = 0x1F, + DIK_D = 0x20, + DIK_F = 0x21, + DIK_G = 0x22, + DIK_H = 0x23, + DIK_J = 0x24, + DIK_K = 0x25, + DIK_L = 0x26, + DIK_SEMICOLON = 0x27, + DIK_APOSTROPHE = 0x28, + DIK_GRAVE = 0x29, + DIK_LSHIFT = 0x2A, + DIK_BACKSLASH = 0x2B, + DIK_Z = 0x2C, + DIK_X = 0x2D, + DIK_C = 0x2E, + DIK_V = 0x2F, + DIK_B = 0x30, + DIK_N = 0x31, + DIK_M = 0x32, + DIK_COMMA = 0x33, + DIK_PERIOD = 0x34, + DIK_SLASH = 0x35, + DIK_RSHIFT = 0x36, + DIK_MULTIPLY = 0x37, + DIK_LMENU = 0x38, + DIK_SPACE = 0x39, + DIK_CAPITAL = 0x3A, + DIK_F1 = 0x3B, + DIK_F2 = 0x3C, + DIK_F3 = 0x3D, + DIK_F4 = 0x3E, + DIK_F5 = 0x3F, + DIK_F6 = 0x40, + DIK_F7 = 0x41, + DIK_F8 = 0x42, + DIK_F9 = 0x43, + DIK_F10 = 0x44, + DIK_NUMLOCK = 0x45, + DIK_SCROLL = 0x46, + DIK_NUMPAD7 = 0x47, + DIK_NUMPAD8 = 0x48, + DIK_NUMPAD9 = 0x49, + DIK_SUBTRACT = 0x4A, + DIK_NUMPAD4 = 0x4B, + DIK_NUMPAD5 = 0x4C, + DIK_NUMPAD6 = 0x4D, + DIK_ADD = 0x4E, + DIK_NUMPAD1 = 0x4F, + DIK_NUMPAD2 = 0x50, + DIK_NUMPAD3 = 0x51, + DIK_NUMPAD0 = 0x52, + DIK_DECIMAL = 0x53, + DIK_OEM_102 = 0x56, + DIK_F11 = 0x57, + DIK_F12 = 0x58, + DIK_F13 = 0x64, + DIK_F14 = 0x65, + DIK_F15 = 0x66, + DIK_KANA = 0x70, + DIK_ABNT_C1 = 0x73, + DIK_CONVERT = 0x79, + DIK_NOCONVERT = 0x7B, + DIK_YEN = 0x7D, + DIK_ABNT_C2 = 0x7E, DIK_NUMPADEQUALS = 0x8D, - DIK_PREVTRACK = 0x90, - DIK_AT = 0x91, - DIK_COLON = 0x92, - DIK_UNDERLINE = 0x93, - DIK_KANJI = 0x94, - DIK_STOP = 0x95, - DIK_AX = 0x96, - DIK_UNLABELED = 0x97, - DIK_NEXTTRACK = 0x99, - DIK_NUMPADENTER = 0x9C, - DIK_RCONTROL = 0x9D, - DIK_MUTE = 0xA0, - DIK_CALCULATOR = 0xA1, - DIK_PLAYPAUSE = 0xA2, - DIK_MEDIASTOP = 0xA4, - DIK_VOLUMEDOWN = 0xAE, - DIK_VOLUMEUP = 0xB0, - DIK_WEBHOME = 0xB2, - DIK_NUMPADCOMMA = 0xB3, - DIK_DIVIDE = 0xB5, - DIK_SYSRQ = 0xB7, - DIK_RMENU = 0xB8, - DIK_PAUSE = 0xC5, - DIK_HOME = 0xC7, - DIK_UP = 0xC8, - DIK_PRIOR = 0xC9, - DIK_LEFT = 0xCB, - DIK_RIGHT = 0xCD, - DIK_END = 0xCF, - DIK_DOWN = 0xD0, - DIK_NEXT = 0xD1, - DIK_INSERT = 0xD2, - DIK_DELETE = 0xD3, - DIK_LWIN = 0xDB, - DIK_RWIN = 0xDC, - DIK_APPS = 0xDD, - DIK_POWER = 0xDE, - DIK_SLEEP = 0xDF, - DIK_WAKE = 0xE3, - DIK_WEBSEARCH = 0xE5, + DIK_PREVTRACK = 0x90, + DIK_AT = 0x91, + DIK_COLON = 0x92, + DIK_UNDERLINE = 0x93, + DIK_KANJI = 0x94, + DIK_STOP = 0x95, + DIK_AX = 0x96, + DIK_UNLABELED = 0x97, + DIK_NEXTTRACK = 0x99, + DIK_NUMPADENTER = 0x9C, + DIK_RCONTROL = 0x9D, + DIK_MUTE = 0xA0, + DIK_CALCULATOR = 0xA1, + DIK_PLAYPAUSE = 0xA2, + DIK_MEDIASTOP = 0xA4, + DIK_VOLUMEDOWN = 0xAE, + DIK_VOLUMEUP = 0xB0, + DIK_WEBHOME = 0xB2, + DIK_NUMPADCOMMA = 0xB3, + DIK_DIVIDE = 0xB5, + DIK_SYSRQ = 0xB7, + DIK_RMENU = 0xB8, + DIK_PAUSE = 0xC5, + DIK_HOME = 0xC7, + DIK_UP = 0xC8, + DIK_PRIOR = 0xC9, + DIK_LEFT = 0xCB, + DIK_RIGHT = 0xCD, + DIK_END = 0xCF, + DIK_DOWN = 0xD0, + DIK_NEXT = 0xD1, + DIK_INSERT = 0xD2, + DIK_DELETE = 0xD3, + DIK_LWIN = 0xDB, + DIK_RWIN = 0xDC, + DIK_APPS = 0xDD, + DIK_POWER = 0xDE, + DIK_SLEEP = 0xDF, + DIK_WAKE = 0xE3, + DIK_WEBSEARCH = 0xE5, DIK_WEBFAVORITES = 0xE6, - DIK_WEBREFRESH = 0xE7, - DIK_WEBSTOP = 0xE8, - DIK_WEBFORWARD = 0xE9, - DIK_WEBBACK = 0xEA, - DIK_MYCOMPUTER = 0xEB, - DIK_MAIL = 0xEC, - DIK_MEDIASELECT = 0xED, - DIK_BACKSPACE = DIK_BACK, - DIK_NUMPADSTAR = DIK_MULTIPLY, - DIK_LALT = DIK_LMENU, - DIK_CAPSLOCK = DIK_CAPITAL, - DIK_NUMPADMINUS = DIK_SUBTRACT, - DIK_NUMPADPLUS = DIK_ADD, + DIK_WEBREFRESH = 0xE7, + DIK_WEBSTOP = 0xE8, + DIK_WEBFORWARD = 0xE9, + DIK_WEBBACK = 0xEA, + DIK_MYCOMPUTER = 0xEB, + DIK_MAIL = 0xEC, + DIK_MEDIASELECT = 0xED, + DIK_BACKSPACE = DIK_BACK, + DIK_NUMPADSTAR = DIK_MULTIPLY, + DIK_LALT = DIK_LMENU, + DIK_CAPSLOCK = DIK_CAPITAL, + DIK_NUMPADMINUS = DIK_SUBTRACT, + DIK_NUMPADPLUS = DIK_ADD, DIK_NUMPADPERIOD = DIK_DECIMAL, - DIK_NUMPADSLASH = DIK_DIVIDE, - DIK_RALT = DIK_RMENU, - DIK_UPARROW = DIK_UP, - DIK_PGUP = DIK_PRIOR, - DIK_LEFTARROW = DIK_LEFT, - DIK_RIGHTARROW = DIK_RIGHT, - DIK_DOWNARROW = DIK_DOWN, - DIK_PGDN = DIK_NEXT + DIK_NUMPADSLASH = DIK_DIVIDE, + DIK_RALT = DIK_RMENU, + DIK_UPARROW = DIK_UP, + DIK_PGUP = DIK_PRIOR, + DIK_LEFTARROW = DIK_LEFT, + DIK_RIGHTARROW = DIK_RIGHT, + DIK_DOWNARROW = DIK_DOWN, + DIK_PGDN = DIK_NEXT }; struct DIMOUSESTATE2__ @@ -209,21 +209,23 @@ namespace RE::DirectInput8 LONG lZ; BYTE rgbButtons[8]; }; + static_assert(sizeof(DIMOUSESTATE2__) == 0x14); - using DIMOUSESTATE2 = DIMOUSESTATE2__; + using DIMOUSESTATE2 = DIMOUSESTATE2__; using LPDIMOUSESTATE2 = DIMOUSESTATE2*; struct DIDEVICEOBJECTDATA__ { - DWORD dwOfs; // 00 - DWORD dwData; // 04 - DWORD dwTimeStamp; // 08 - DWORD dwSequence; // 0C - UINT_PTR uAppData; // 10 + DWORD dwOfs; // 00 + DWORD dwData; // 04 + DWORD dwTimeStamp; // 08 + DWORD dwSequence; // 0C + UINT_PTR uAppData; // 10 }; + static_assert(sizeof(DIDEVICEOBJECTDATA__) == 0x18); - using DIDEVICEOBJECTDATA = DIDEVICEOBJECTDATA__; - using LPDIDEVICEOBJECTDATA = DIDEVICEOBJECTDATA*; + using DIDEVICEOBJECTDATA = DIDEVICEOBJECTDATA__; + using LPDIDEVICEOBJECTDATA = DIDEVICEOBJECTDATA*; using LPCDIDEVICEOBJECTDATA = const DIDEVICEOBJECTDATA*; struct DIDEVICEINSTANCEA__ @@ -234,12 +236,13 @@ namespace RE::DirectInput8 DWORD dwDevType; CHAR tszInstanceName[MAX_PATH]; CHAR tszProductName[MAX_PATH]; - GUID guidFFDriver; // DIRECTINPUT_VERSION >= 0x0500 + GUID guidFFDriver; // DIRECTINPUT_VERSION >= 0x0500 WORD wUsagePage; WORD wUsage; }; - using DIDEVICEINSTANCEA = DIDEVICEINSTANCEA__; - using LPDIDEVICEINSTANCEA = DIDEVICEINSTANCEA*; + + using DIDEVICEINSTANCEA = DIDEVICEINSTANCEA__; + using LPDIDEVICEINSTANCEA = DIDEVICEINSTANCEA*; using LPCDIDEVICEINSTANCEA = const DIDEVICEINSTANCEA*; struct DIDEVICEOBJECTINSTANCEA__ @@ -250,7 +253,7 @@ namespace RE::DirectInput8 DWORD dwType; DWORD dwFlags; CHAR tszName[MAX_PATH]; - //#if(DIRECTINPUT_VERSION >= 0x0500) + // #if(DIRECTINPUT_VERSION >= 0x0500) DWORD dwFFMaxForce; DWORD dwFFForceResolution; WORD wCollectionNumber; @@ -260,10 +263,11 @@ namespace RE::DirectInput8 DWORD dwDimension; WORD wExponent; WORD wReportId; - //#endif /* DIRECTINPUT_VERSION >= 0x0500 */ + // #endif /* DIRECTINPUT_VERSION >= 0x0500 */ }; - using DIDEVICEOBJECTINSTANCEA = DIDEVICEOBJECTINSTANCEA__; - using LPDIDEVICEOBJECTINSTANCEA = DIDEVICEOBJECTINSTANCEA*; + + using DIDEVICEOBJECTINSTANCEA = DIDEVICEOBJECTINSTANCEA__; + using LPDIDEVICEOBJECTINSTANCEA = DIDEVICEOBJECTINSTANCEA*; using LPCDIDEVICEOBJECTINSTANCEA = const DIDEVICEOBJECTINSTANCEA*; using LPDIENUMDEVICEOBJECTSCALLBACKA = bool(__stdcall*)(LPCDIDEVICEOBJECTINSTANCEA, LPVOID); @@ -276,8 +280,8 @@ namespace RE::DirectInput8 DWORD dwHow; }; - using DIPROPHEADER = DIPROPHEADER__; - using LPDIPROPHEADER = DIPROPHEADER*; + using DIPROPHEADER = DIPROPHEADER__; + using LPDIPROPHEADER = DIPROPHEADER*; using LPCDIPROPHEADER = const DIPROPHEADER*; struct DIDEVCAPS__ @@ -288,16 +292,18 @@ namespace RE::DirectInput8 DWORD dwAxes; DWORD dwButtons; DWORD dwPOVs; - DWORD dwFFSamplePeriod; // -- fields here are Dinput >= 0x0500 + DWORD dwFFSamplePeriod; // -- fields here are Dinput >= 0x0500 DWORD dwFFMinTimeResolution; DWORD dwFirmwareRevision; DWORD dwHardwareRevision; DWORD dwFFDriverVersion; }; + static_assert(sizeof(DIDEVCAPS__) == 0x2C); - using DIDEVCAPS = DIDEVCAPS__; - using LPDIDEVCAPS = DIDEVCAPS*; + using DIDEVCAPS = DIDEVCAPS__; + using LPDIDEVCAPS = DIDEVCAPS*; using LPCDIDEVCAPS = const DIDEVCAPS*; + struct _DIDEVICEIMAGEINFOA { CHAR tszImagePath[MAX_PATH]; @@ -310,8 +316,9 @@ namespace RE::DirectInput8 RECT rcCalloutRect; DWORD dwTextAlign; }; - using DIDEVICEIMAGEINFOA = _DIDEVICEIMAGEINFOA; - using LPDIDEVICEIMAGEINFOA = DIDEVICEIMAGEINFOA*; + + using DIDEVICEIMAGEINFOA = _DIDEVICEIMAGEINFOA; + using LPDIDEVICEIMAGEINFOA = DIDEVICEIMAGEINFOA*; using LPCDIDEVICEIMAGEINFOA = const DIDEVICEIMAGEINFOA*; struct _DIOBJECTDATAFORMAT @@ -321,8 +328,9 @@ namespace RE::DirectInput8 DWORD dwType; DWORD dwFlags; }; - using DIOBJECTDATAFORMAT = _DIOBJECTDATAFORMAT; - using LPDIOBJECTDATAFORMAT = DIOBJECTDATAFORMAT*; + + using DIOBJECTDATAFORMAT = _DIOBJECTDATAFORMAT; + using LPDIOBJECTDATAFORMAT = DIOBJECTDATAFORMAT*; using LPCDIOBJECTDATAFORMAT = const DIOBJECTDATAFORMAT*; struct _DIDATAFORMAT @@ -334,8 +342,9 @@ namespace RE::DirectInput8 DWORD dwNumObjs; LPDIOBJECTDATAFORMAT rgodf; }; - using DIDATAFORMAT = _DIDATAFORMAT; - using LPDIDATAFORMAT = DIDATAFORMAT*; + + using DIDATAFORMAT = _DIDATAFORMAT; + using LPDIDATAFORMAT = DIDATAFORMAT*; using LPCDIDATAFORMAT = const DIDATAFORMAT*; struct DIENVELOPE__ @@ -346,8 +355,9 @@ namespace RE::DirectInput8 DWORD dwFadeLevel; DWORD dwFadeTime; /* Microseconds */ }; - using DIENVELOPE = DIENVELOPE__; - using LPDIENVELOPE = DIENVELOPE*; + + using DIENVELOPE = DIENVELOPE__; + using LPDIENVELOPE = DIENVELOPE*; using LPCDIENVELOPE = const DIENVELOPE*; struct DIEFFECTINFOA__ @@ -359,8 +369,9 @@ namespace RE::DirectInput8 DWORD dwDynamicParams; CHAR tszName[MAX_PATH]; }; - using DIEFFECTINFOA = DIEFFECTINFOA__; - using LPDIEFFECTINFOA = DIEFFECTINFOA*; + + using DIEFFECTINFOA = DIEFFECTINFOA__; + using LPDIEFFECTINFOA = DIEFFECTINFOA*; using LPCDIEFFECTINFOA = const DIEFFECTINFOA*; using LPDIENUMEFFECTSCALLBACKA = bool(__stdcall*)(LPCDIEFFECTINFOA, LPVOID); @@ -372,18 +383,19 @@ namespace RE::DirectInput8 DWORD dwDuration; /* Microseconds */ DWORD dwSamplePeriod; /* Microseconds */ DWORD dwGain; - DWORD dwTriggerButton; /* or DIEB_NOTRIGGER */ - DWORD dwTriggerRepeatInterval; /* Microseconds */ - DWORD cAxes; /* Number of axes */ - LPDWORD rgdwAxes; /* Array of axes */ - LPLONG rglDirection; /* Array of directions */ - LPDIENVELOPE lpEnvelope; /* Optional */ - DWORD cbTypeSpecificParams; /* Size of params */ - LPVOID lpvTypeSpecificParams; /* Pointer to params */ - DWORD dwStartDelay; /* Microseconds */ // -- fields here are Dinput >= 0x0600 + DWORD dwTriggerButton; /* or DIEB_NOTRIGGER */ + DWORD dwTriggerRepeatInterval; /* Microseconds */ + DWORD cAxes; /* Number of axes */ + LPDWORD rgdwAxes; /* Array of axes */ + LPLONG rglDirection; /* Array of directions */ + LPDIENVELOPE lpEnvelope; /* Optional */ + DWORD cbTypeSpecificParams; /* Size of params */ + LPVOID lpvTypeSpecificParams; /* Pointer to params */ + DWORD dwStartDelay; /* Microseconds */ // -- fields here are Dinput >= 0x0600 }; - using DIEFFECT = DIEFFECT__; - using LPDIEFFECT = DIEFFECT*; + + using DIEFFECT = DIEFFECT__; + using LPDIEFFECT = DIEFFECT*; using LPCDIEFFECT = const DIEFFECT*; struct DIEFFESCAPE__ @@ -395,9 +407,11 @@ namespace RE::DirectInput8 LPVOID lpvOutBuffer; DWORD cbOutBuffer; }; - using DIEFFESCAPE = DIEFFESCAPE__; - using LPDIEFFESCAPE = DIEFFESCAPE*; + + using DIEFFESCAPE = DIEFFESCAPE__; + using LPDIEFFESCAPE = DIEFFESCAPE*; using LPCDIEFFESCAPE = const DIEFFESCAPE*; + struct DIFILEEFFECT__ { DWORD dwSize; @@ -405,24 +419,28 @@ namespace RE::DirectInput8 LPCDIEFFECT lpDiEffect; CHAR szFriendlyName[MAX_PATH]; }; - using DIFILEEFFECT = DIFILEEFFECT__; - using LPDIFILEEFFECT = DIFILEEFFECT*; + + using DIFILEEFFECT = DIFILEEFFECT__; + using LPDIFILEEFFECT = DIFILEEFFECT*; using LPCDIFILEEFFECT = const DIFILEEFFECT*; + struct _DIACTIONA { UINT_PTR uAppData; DWORD dwSemantic; DWORD dwFlags; - union - { + + union { LPCSTR lptszActionName; UINT uResIdString; }; + GUID guidInstance; DWORD dwObjID; DWORD dwHow; }; - using DIACTIONA = _DIACTIONA; + + using DIACTIONA = _DIACTIONA; using LPDIACTIONA = DIACTIONA*; struct _DIACTIONFORMATA @@ -442,9 +460,11 @@ namespace RE::DirectInput8 DWORD dwCRC; CHAR tszActionMap[MAX_PATH]; }; - using DIACTIONFORMATA = _DIACTIONFORMATA; - using LPDIACTIONFORMATA = DIACTIONFORMATA*; + + using DIACTIONFORMATA = _DIACTIONFORMATA; + using LPDIACTIONFORMATA = DIACTIONFORMATA*; using LPCDIACTIONFORMATA = const DIACTIONFORMATA*; + struct _DIDEVICEIMAGEINFOHEADERA { DWORD dwSize; @@ -457,8 +477,9 @@ namespace RE::DirectInput8 DWORD dwBufferUsed; LPDIDEVICEIMAGEINFOA lprgImageInfoArray; }; - using DIDEVICEIMAGEINFOHEADERA = _DIDEVICEIMAGEINFOHEADERA; - using LPDIDEVICEIMAGEINFOHEADERA = DIDEVICEIMAGEINFOHEADERA*; + + using DIDEVICEIMAGEINFOHEADERA = _DIDEVICEIMAGEINFOHEADERA; + using LPDIDEVICEIMAGEINFOHEADERA = DIDEVICEIMAGEINFOHEADERA*; using LPCDIDEVICEIMAGEINFOHEADERA = const DIDEVICEIMAGEINFOHEADERA*; struct _DICOLORSET @@ -473,15 +494,16 @@ namespace RE::DirectInput8 D3DCOLOR cHighlightFill; D3DCOLOR cAreaFill; }; + using DICOLORSET = _DICOLORSET; - struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) - IUnknown + struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) IUnknown { virtual HRESULT QueryInterface(const GUID&, void**) noexcept = 0; - virtual std::uint32_t AddRef() noexcept = 0; - virtual std::uint32_t Release() noexcept = 0; + virtual std::uint32_t AddRef() noexcept = 0; + virtual std::uint32_t Release() noexcept = 0; }; + using LPUNKNOWN = IUnknown*; struct _DICONFIGUREDEVICESPARAMSA @@ -495,27 +517,29 @@ namespace RE::DirectInput8 DICOLORSET dics; IUnknown* lpUnkDDSTarget; }; + using DICONFIGUREDEVICESPARAMSA = _DICONFIGUREDEVICESPARAMSA; struct __declspec(novtable) IDirectInputEffect : public IUnknown { virtual HRESULT Initialize(HINSTANCE, DWORD, REFGUID) noexcept = 0; - virtual HRESULT GetEffectGuid(LPGUID) noexcept = 0; - virtual HRESULT GetParameters(LPDIEFFECT, DWORD) noexcept = 0; - virtual HRESULT SetParameters(LPCDIEFFECT, DWORD) noexcept = 0; - virtual HRESULT Start(std::uint32_t, std::uint32_t) noexcept = 0; - virtual HRESULT Stop() noexcept = 0; - virtual HRESULT GetEffectStatus(std::uint32_t*) noexcept = 0; - virtual HRESULT Download() noexcept = 0; - virtual HRESULT Unload() noexcept = 0; - virtual HRESULT Escape(LPDIEFFESCAPE) noexcept = 0; + virtual HRESULT GetEffectGuid(LPGUID) noexcept = 0; + virtual HRESULT GetParameters(LPDIEFFECT, DWORD) noexcept = 0; + virtual HRESULT SetParameters(LPCDIEFFECT, DWORD) noexcept = 0; + virtual HRESULT Start(std::uint32_t, std::uint32_t) noexcept = 0; + virtual HRESULT Stop() noexcept = 0; + virtual HRESULT GetEffectStatus(std::uint32_t*) noexcept = 0; + virtual HRESULT Download() noexcept = 0; + virtual HRESULT Unload() noexcept = 0; + virtual HRESULT Escape(LPDIEFFESCAPE) noexcept = 0; }; - using LPDIRECTINPUTEFFECT = IDirectInputEffect*; + + using LPDIRECTINPUTEFFECT = IDirectInputEffect*; using LPCDIRECTINPUTEFFECT = const IDirectInputEffect*; using LPDIENUMCREATEDEFFECTOBJECTSCALLBACK = bool(__stdcall*)(LPDIRECTINPUTEFFECT, void*); - using LPDICONFIGUREDEVICESCALLBACK = bool(__stdcall*)(IUnknown*, void*); - using LPDIENUMDEVICESCALLBACKA = bool(__stdcall*)(const DIDEVICEINSTANCEA*, void*); + using LPDICONFIGUREDEVICESCALLBACK = bool(__stdcall*)(IUnknown*, void*); + using LPDIENUMDEVICESCALLBACKA = bool(__stdcall*)(const DIDEVICEINSTANCEA*, void*); using LPDIENUMEFFECTSCALLBACKA = bool(__stdcall*)(const DIEFFECTINFOA*, void*); @@ -523,49 +547,49 @@ namespace RE::DirectInput8 struct __declspec(novtable) IDirectInputDevice8A : public IUnknown { - virtual HRESULT GetCapabilities(DIDEVCAPS*) noexcept = 0; - virtual HRESULT EnumObjects(LPDIENUMDEVICEOBJECTSCALLBACKA, void*, std::uint32_t) noexcept = 0; - virtual HRESULT GetProperty(std::uint32_t, DIPROPHEADER*) noexcept = 0; - virtual HRESULT SetProperty(std::uint32_t, const DIPROPHEADER*) noexcept = 0; - virtual HRESULT Acquire() noexcept = 0; - virtual HRESULT Unacquire() noexcept = 0; - virtual HRESULT GetDeviceState(std::uint32_t, void*) noexcept = 0; - virtual HRESULT GetDeviceData(std::uint32_t, DIDEVICEOBJECTDATA*, std::uint32_t*, std::uint32_t) noexcept = 0; - virtual HRESULT SetDataFormat(const DIDATAFORMAT*) noexcept = 0; - virtual HRESULT SetEventNotification(HANDLE) noexcept = 0; - virtual HRESULT SetCooperativeLevel(HWND, std::uint32_t) noexcept = 0; - virtual HRESULT GetObjectInfo(DIDEVICEOBJECTINSTANCEA*, std::uint32_t, std::uint32_t) noexcept = 0; - virtual HRESULT GetDeviceInfo(DIDEVICEINSTANCEA*) noexcept = 0; - virtual HRESULT RunControlPanel(HWND, std::uint32_t) noexcept = 0; - virtual HRESULT Initialize(HINSTANCE, std::uint32_t, const GUID&) noexcept = 0; - virtual HRESULT CreateEffect(const GUID&, const DIEFFECT*, IDirectInputEffect*, IUnknown*) noexcept = 0; - virtual HRESULT EnumEffects(LPDIENUMEFFECTSCALLBACKA, void*, std::uint32_t) noexcept = 0; - virtual HRESULT GetEffectInfo(DIEFFECTINFOA*, const GUID&) noexcept = 0; - virtual HRESULT GetForceFeedbackState(std::uint32_t*) noexcept = 0; - virtual HRESULT SendForceFeedbackCommand(std::uint32_t) noexcept = 0; - virtual HRESULT EnumCreatedEffectObjects(LPDIENUMCREATEDEFFECTOBJECTSCALLBACK, void*, std::uint32_t) noexcept = 0; - virtual HRESULT Escape(DIEFFESCAPE*) noexcept = 0; - virtual HRESULT Poll() noexcept = 0; + virtual HRESULT GetCapabilities(DIDEVCAPS*) noexcept = 0; + virtual HRESULT EnumObjects(LPDIENUMDEVICEOBJECTSCALLBACKA, void*, std::uint32_t) noexcept = 0; + virtual HRESULT GetProperty(std::uint32_t, DIPROPHEADER*) noexcept = 0; + virtual HRESULT SetProperty(std::uint32_t, const DIPROPHEADER*) noexcept = 0; + virtual HRESULT Acquire() noexcept = 0; + virtual HRESULT Unacquire() noexcept = 0; + virtual HRESULT GetDeviceState(std::uint32_t, void*) noexcept = 0; + virtual HRESULT GetDeviceData(std::uint32_t, DIDEVICEOBJECTDATA*, std::uint32_t*, std::uint32_t) noexcept = 0; + virtual HRESULT SetDataFormat(const DIDATAFORMAT*) noexcept = 0; + virtual HRESULT SetEventNotification(HANDLE) noexcept = 0; + virtual HRESULT SetCooperativeLevel(HWND, std::uint32_t) noexcept = 0; + virtual HRESULT GetObjectInfo(DIDEVICEOBJECTINSTANCEA*, std::uint32_t, std::uint32_t) noexcept = 0; + virtual HRESULT GetDeviceInfo(DIDEVICEINSTANCEA*) noexcept = 0; + virtual HRESULT RunControlPanel(HWND, std::uint32_t) noexcept = 0; + virtual HRESULT Initialize(HINSTANCE, std::uint32_t, const GUID&) noexcept = 0; + virtual HRESULT CreateEffect(const GUID&, const DIEFFECT*, IDirectInputEffect*, IUnknown*) noexcept = 0; + virtual HRESULT EnumEffects(LPDIENUMEFFECTSCALLBACKA, void*, std::uint32_t) noexcept = 0; + virtual HRESULT GetEffectInfo(DIEFFECTINFOA*, const GUID&) noexcept = 0; + virtual HRESULT GetForceFeedbackState(std::uint32_t*) noexcept = 0; + virtual HRESULT SendForceFeedbackCommand(std::uint32_t) noexcept = 0; + virtual HRESULT EnumCreatedEffectObjects(LPDIENUMCREATEDEFFECTOBJECTSCALLBACK, void*, std::uint32_t) noexcept = 0; + virtual HRESULT Escape(DIEFFESCAPE*) noexcept = 0; + virtual HRESULT Poll() noexcept = 0; virtual HRESULT SendDeviceData(std::uint32_t, const DIDEVICEOBJECTDATA*, std::uint32_t*, std::uint32_t) noexcept = 0; - virtual HRESULT EnumEffectsInFile(const char*, LPDIENUMEFFECTSINFILECALLBACK, void*, std::uint32_t) noexcept = 0; - virtual HRESULT WriteEffectToFile(const char*, std::uint32_t, DIFILEEFFECT*, std::uint32_t) noexcept = 0; - virtual HRESULT BuildActionMap(DIACTIONFORMATA*, const char*, std::uint32_t) noexcept = 0; - virtual HRESULT SetActionMap(DIACTIONFORMATA*, const char*, std::uint32_t) noexcept = 0; - virtual HRESULT GetImageInfo(DIDEVICEIMAGEINFOHEADERA*) noexcept = 0; + virtual HRESULT EnumEffectsInFile(const char*, LPDIENUMEFFECTSINFILECALLBACK, void*, std::uint32_t) noexcept = 0; + virtual HRESULT WriteEffectToFile(const char*, std::uint32_t, DIFILEEFFECT*, std::uint32_t) noexcept = 0; + virtual HRESULT BuildActionMap(DIACTIONFORMATA*, const char*, std::uint32_t) noexcept = 0; + virtual HRESULT SetActionMap(DIACTIONFORMATA*, const char*, std::uint32_t) noexcept = 0; + virtual HRESULT GetImageInfo(DIDEVICEIMAGEINFOHEADERA*) noexcept = 0; }; using LPDIENUMDEVICESBYSEMANTICSCBA = bool(__stdcall*)(const DIDEVICEINSTANCEA*, IDirectInputDevice8A*, DWORD, DWORD, LPVOID); struct __declspec(novtable) IDirectInput8A : public IUnknown { - virtual HRESULT CreateDevice(const GUID&, IDirectInputDevice8A**, IUnknown*) noexcept = 0; - virtual HRESULT EnumDevices(std::uint32_t, LPDIENUMDEVICESCALLBACKA, void*, std::uint32_t) noexcept = 0; - virtual HRESULT GetDeviceStatus(const GUID&) noexcept = 0; - virtual HRESULT RunControlPanel(HWND, std::uint32_t) noexcept = 0; - virtual HRESULT Initialize(HINSTANCE, std::uint32_t) noexcept = 0; - virtual HRESULT FindDevice(const GUID&, const char*, GUID*) noexcept = 0; + virtual HRESULT CreateDevice(const GUID&, IDirectInputDevice8A**, IUnknown*) noexcept = 0; + virtual HRESULT EnumDevices(std::uint32_t, LPDIENUMDEVICESCALLBACKA, void*, std::uint32_t) noexcept = 0; + virtual HRESULT GetDeviceStatus(const GUID&) noexcept = 0; + virtual HRESULT RunControlPanel(HWND, std::uint32_t) noexcept = 0; + virtual HRESULT Initialize(HINSTANCE, std::uint32_t) noexcept = 0; + virtual HRESULT FindDevice(const GUID&, const char*, GUID*) noexcept = 0; virtual HRESULT EnumDevicesBySemantics(const char*, LPDIACTIONFORMATA, LPDIENUMDEVICESBYSEMANTICSCBA, void*, std::uint32_t) noexcept = 0; - virtual HRESULT ConfigureDevices(LPDICONFIGUREDEVICESCALLBACK, DICONFIGUREDEVICESPARAMSA*, std::uint32_t, void*) noexcept = 0; + virtual HRESULT ConfigureDevices(LPDICONFIGUREDEVICESCALLBACK, DICONFIGUREDEVICESPARAMSA*, std::uint32_t, void*) noexcept = 0; }; -} +} // namespace RE::DirectInput8 diff --git a/CommonLibSF/include/SFSE/Impl/PCH.h b/CommonLibSF/include/SFSE/Impl/PCH.h index f8f6faa4..ebd7678f 100644 --- a/CommonLibSF/include/SFSE/Impl/PCH.h +++ b/CommonLibSF/include/SFSE/Impl/PCH.h @@ -53,9 +53,7 @@ #include #include -static_assert( - std::is_integral_v && sizeof(std::time_t) == sizeof(std::size_t), - "wrap std::time_t instead"); +static_assert(std::is_integral_v && sizeof(std::time_t) == sizeof(std::size_t), "wrap std::time_t instead"); #pragma warning(push) #include @@ -66,14 +64,14 @@ static_assert( #include "SFSE/Impl/WinAPI.h" #include "SFSE/Impl/XInputAPI.h" -#define AsAddress(ptr) std::bit_cast(ptr) +#define AsAddress(ptr) std::bit_cast(ptr) #define AsPointer(addr) std::bit_cast(addr) -#define stl_assert(cond, ...) \ - { \ - if (!((cond))) { \ - SFSE::stl::report_and_fail( \ - fmt::format(__VA_ARGS__)); \ - } \ +#define stl_assert(cond, ...) \ + { \ + if (!((cond))) \ + { \ + SFSE::stl::report_and_fail(fmt::format(__VA_ARGS__)); \ + } \ } namespace SFSE @@ -85,28 +83,19 @@ namespace SFSE template using basic_zstring = std::basic_string_view; - using zstring = basic_zstring; + using zstring = basic_zstring; using zwstring = basic_zstring; // owning pointer - template < - class T, - class = std::enable_if_t< - std::is_pointer_v>> + template >> using owner = T; // non-owning pointer - template < - class T, - class = std::enable_if_t< - std::is_pointer_v>> + template >> using observer = T; // non-null pointer - template < - class T, - class = std::enable_if_t< - std::is_pointer_v>> + template >> using not_null = T; namespace nttp @@ -114,18 +103,19 @@ namespace SFSE template struct string { - using char_type = CharT; - using pointer = char_type*; - using const_pointer = const char_type*; - using reference = char_type&; + using char_type = CharT; + using pointer = char_type*; + using const_pointer = const char_type*; + using reference = char_type&; using const_reference = const char_type&; - using size_type = std::size_t; + using size_type = std::size_t; static constexpr auto npos = static_cast(-1); consteval string(const_pointer a_string) noexcept { - for (size_type i = 0; i < N; ++i) { + for (size_type i = 0; i < N; ++i) + { c[i] = a_string[i]; } } @@ -142,12 +132,35 @@ namespace SFSE return c[a_pos]; } - [[nodiscard]] consteval const_reference back() const noexcept { return (*this)[size() - 1]; } - [[nodiscard]] consteval const_pointer data() const noexcept { return c; } - [[nodiscard]] consteval bool empty() const noexcept { return this->size() == 0; } - [[nodiscard]] consteval const_reference front() const noexcept { return (*this)[0]; } - [[nodiscard]] consteval size_type length() const noexcept { return N; } - [[nodiscard]] consteval size_type size() const noexcept { return length(); } + [[nodiscard]] consteval const_reference back() const noexcept + { + return (*this)[size() - 1]; + } + + [[nodiscard]] consteval const_pointer data() const noexcept + { + return c; + } + + [[nodiscard]] consteval bool empty() const noexcept + { + return this->size() == 0; + } + + [[nodiscard]] consteval const_reference front() const noexcept + { + return (*this)[0]; + } + + [[nodiscard]] consteval size_type length() const noexcept + { + return N; + } + + [[nodiscard]] consteval size_type size() const noexcept + { + return length(); + } template [[nodiscard]] consteval auto substr() const noexcept @@ -160,45 +173,47 @@ namespace SFSE template string(const CharT (&)[N]) -> string; - } + } // namespace nttp - template // - requires(std::invocable>) // + template // + requires(std::invocable>) // class scope_exit { public: // 1) template - explicit scope_exit(Fn&& a_fn) // - noexcept(std::is_nothrow_constructible_v || - std::is_nothrow_constructible_v) // - requires(!std::is_same_v, scope_exit> && - std::is_constructible_v) + explicit scope_exit(Fn&& a_fn) // + noexcept(std::is_nothrow_constructible_v || std::is_nothrow_constructible_v) // + requires(!std::is_same_v, scope_exit> && std::is_constructible_v) { static_assert(std::invocable); - if constexpr (!std::is_lvalue_reference_v && - std::is_nothrow_constructible_v) { + if constexpr (!std::is_lvalue_reference_v && std::is_nothrow_constructible_v) + { _fn.emplace(std::forward(a_fn)); - } else { + } + else + { _fn.emplace(a_fn); } } // 2) - scope_exit(scope_exit&& a_rhs) // - noexcept(std::is_nothrow_move_constructible_v || - std::is_nothrow_copy_constructible_v) // - requires(std::is_nothrow_move_constructible_v || - std::is_copy_constructible_v) + scope_exit(scope_exit&& a_rhs) // + noexcept(std::is_nothrow_move_constructible_v || std::is_nothrow_copy_constructible_v) // + requires(std::is_nothrow_move_constructible_v || std::is_copy_constructible_v) { static_assert(!(std::is_nothrow_move_constructible_v && !std::is_move_constructible_v)); static_assert(!(!std::is_nothrow_move_constructible_v && !std::is_copy_constructible_v)); - if (a_rhs.active()) { - if constexpr (std::is_nothrow_move_constructible_v) { + if (a_rhs.active()) + { + if constexpr (std::is_nothrow_move_constructible_v) + { _fn.emplace(std::forward(*a_rhs._fn)); - } else { + } + else + { _fn.emplace(a_rhs._fn); } a_rhs.release(); @@ -210,15 +225,22 @@ namespace SFSE ~scope_exit() noexcept { - if (_fn.has_value()) { + if (_fn.has_value()) + { (*_fn)(); } } - void release() noexcept { _fn.reset(); } + void release() noexcept + { + _fn.reset(); + } private: - [[nodiscard]] bool active() const noexcept { return _fn.has_value(); } + [[nodiscard]] bool active() const noexcept + { + return _fn.has_value(); + } std::optional> _fn; }; @@ -226,13 +248,11 @@ namespace SFSE template scope_exit(EF) -> scope_exit; - template < - class Enum, - class Underlying = std::underlying_type_t> + template > class enumeration { public: - using enum_type = Enum; + using enum_type = Enum; using underlying_type = Underlying; static_assert(std::is_enum_v, "enum_type must be an enum"); @@ -244,22 +264,20 @@ namespace SFSE constexpr enumeration(enumeration&&) noexcept = default; - template // NOLINTNEXTLINE(google-explicit-constructor) - constexpr enumeration(enumeration a_rhs) noexcept : - _impl(static_cast(a_rhs.get())) + template // NOLINTNEXTLINE(google-explicit-constructor) + constexpr enumeration(enumeration a_rhs) noexcept : _impl(static_cast(a_rhs.get())) {} template - constexpr enumeration(Args... a_values) noexcept // + constexpr enumeration(Args... a_values) noexcept // requires(std::same_as && ...) - : - _impl((static_cast(a_values) | ...)) + : _impl((static_cast(a_values) | ...)) {} ~enumeration() noexcept = default; constexpr enumeration& operator=(const enumeration&) noexcept = default; - constexpr enumeration& operator=(enumeration&&) noexcept = default; + constexpr enumeration& operator=(enumeration&&) noexcept = default; template constexpr enumeration& operator=(enumeration a_rhs) noexcept @@ -273,14 +291,28 @@ namespace SFSE return *this; } - [[nodiscard]] explicit constexpr operator bool() const noexcept { return _impl != static_cast(0); } + [[nodiscard]] explicit constexpr operator bool() const noexcept + { + return _impl != static_cast(0); + } + + [[nodiscard]] constexpr enum_type operator*() const noexcept + { + return get(); + } + + [[nodiscard]] constexpr enum_type get() const noexcept + { + return static_cast(_impl); + } - [[nodiscard]] constexpr enum_type operator*() const noexcept { return get(); } - [[nodiscard]] constexpr enum_type get() const noexcept { return static_cast(_impl); } - [[nodiscard]] constexpr underlying_type underlying() const noexcept { return _impl; } + [[nodiscard]] constexpr underlying_type underlying() const noexcept + { + return _impl; + } template - constexpr enumeration& set(Args... a_args) noexcept // + constexpr enumeration& set(Args... a_args) noexcept // requires(std::same_as && ...) { _impl |= (static_cast(a_args) | ...); @@ -288,7 +320,7 @@ namespace SFSE } template - constexpr enumeration& reset(Args... a_args) noexcept // + constexpr enumeration& reset(Args... a_args) noexcept // requires(std::same_as && ...) { _impl &= ~(static_cast(a_args) | ...); @@ -296,21 +328,21 @@ namespace SFSE } template - [[nodiscard]] constexpr bool any(Args... a_args) const noexcept // + [[nodiscard]] constexpr bool any(Args... a_args) const noexcept // requires(std::same_as && ...) { return (_impl & (static_cast(a_args) | ...)) != static_cast(0); } template - [[nodiscard]] constexpr bool all(Args... a_args) const noexcept // + [[nodiscard]] constexpr bool all(Args... a_args) const noexcept // requires(std::same_as && ...) { return (_impl & (static_cast(a_args) | ...)) == (static_cast(a_args) | ...); } template - [[nodiscard]] constexpr bool none(Args... a_args) const noexcept // + [[nodiscard]] constexpr bool none(Args... a_args) const noexcept // requires(std::same_as && ...) { return (_impl & (static_cast(a_args) | ...)) == static_cast(0); @@ -321,12 +353,9 @@ namespace SFSE }; template - enumeration(Args...) -> enumeration< - std::common_type_t, - std::underlying_type_t< - std::common_type_t>>; - } -} + enumeration(Args...) -> enumeration, std::underlying_type_t>>; + } // namespace stl +} // namespace SFSE #define SFSE_MAKE_LOGICAL_OP(a_op, a_result) \ template \ @@ -341,90 +370,78 @@ namespace SFSE return a_lhs.get() a_op a_rhs; \ } -#define SFSE_MAKE_ARITHMETIC_OP(a_op) \ - template \ - [[nodiscard]] constexpr auto operator a_op(enumeration a_enum, U a_shift) noexcept \ - -> enumeration \ - { \ - return static_cast(static_cast(a_enum.get()) a_op a_shift); \ - } \ - \ - template \ - constexpr auto operator a_op##=(enumeration& a_enum, U a_shift) noexcept \ - -> enumeration& \ - { \ - return a_enum = a_enum a_op a_shift; \ +#define SFSE_MAKE_ARITHMETIC_OP(a_op) \ + template \ + [[nodiscard]] constexpr auto operator a_op(enumeration a_enum, U a_shift) noexcept -> enumeration \ + { \ + return static_cast(static_cast(a_enum.get()) a_op a_shift); \ + } \ + \ + template \ + constexpr auto operator a_op##=(enumeration& a_enum, U a_shift) noexcept -> enumeration& \ + { \ + return a_enum = a_enum a_op a_shift; \ } -#define SFSE_MAKE_ENUMERATION_OP(a_op) \ - template \ - [[nodiscard]] constexpr auto operator a_op(enumeration a_lhs, enumeration a_rhs) noexcept \ - -> enumeration> \ - { \ - return static_cast(static_cast(a_lhs.get()) a_op static_cast(a_rhs.get())); \ - } \ - \ - template \ - [[nodiscard]] constexpr auto operator a_op(enumeration a_lhs, E a_rhs) noexcept \ - -> enumeration \ - { \ - return static_cast(static_cast(a_lhs.get()) a_op static_cast(a_rhs)); \ - } \ - \ - template \ - [[nodiscard]] constexpr auto operator a_op(E a_lhs, enumeration a_rhs) noexcept \ - -> enumeration \ - { \ - return static_cast(static_cast(a_lhs) a_op static_cast(a_rhs.get())); \ - } \ - \ - template \ - constexpr auto operator a_op##=(enumeration& a_lhs, enumeration a_rhs) noexcept \ - -> enumeration& \ - { \ - return a_lhs = a_lhs a_op a_rhs; \ - } \ - \ - template \ - constexpr auto operator a_op##=(enumeration& a_lhs, E a_rhs) noexcept \ - -> enumeration& \ - { \ - return a_lhs = a_lhs a_op a_rhs; \ - } \ - \ - template \ - constexpr auto operator a_op##=(E& a_lhs, enumeration a_rhs) noexcept \ - -> E& \ - { \ - return a_lhs = *(a_lhs a_op a_rhs); \ +#define SFSE_MAKE_ENUMERATION_OP(a_op) \ + template \ + [[nodiscard]] constexpr auto operator a_op(enumeration a_lhs, enumeration a_rhs) noexcept \ + -> enumeration> \ + { \ + return static_cast(static_cast(a_lhs.get()) a_op static_cast(a_rhs.get())); \ + } \ + \ + template \ + [[nodiscard]] constexpr auto operator a_op(enumeration a_lhs, E a_rhs) noexcept -> enumeration \ + { \ + return static_cast(static_cast(a_lhs.get()) a_op static_cast(a_rhs)); \ + } \ + \ + template \ + [[nodiscard]] constexpr auto operator a_op(E a_lhs, enumeration a_rhs) noexcept -> enumeration \ + { \ + return static_cast(static_cast(a_lhs) a_op static_cast(a_rhs.get())); \ + } \ + \ + template \ + constexpr auto operator a_op##=(enumeration& a_lhs, enumeration a_rhs) noexcept -> enumeration& \ + { \ + return a_lhs = a_lhs a_op a_rhs; \ + } \ + \ + template \ + constexpr auto operator a_op##=(enumeration& a_lhs, E a_rhs) noexcept -> enumeration& \ + { \ + return a_lhs = a_lhs a_op a_rhs; \ + } \ + \ + template \ + constexpr auto operator a_op##=(E& a_lhs, enumeration a_rhs) noexcept -> E& \ + { \ + return a_lhs = *(a_lhs a_op a_rhs); \ } -#define SFSE_MAKE_INCREMENTER_OP(a_op) \ - template \ - constexpr auto operator a_op##a_op(enumeration& a_lhs) noexcept \ - -> enumeration& \ - { \ - return a_lhs a_op## = static_cast(1); \ - } \ - \ - template \ - [[nodiscard]] constexpr auto operator a_op##a_op(enumeration& a_lhs, int) noexcept \ - -> enumeration \ - { \ - const auto tmp = a_lhs; \ - a_op##a_op a_lhs; \ - return tmp; \ +#define SFSE_MAKE_INCREMENTER_OP(a_op) \ + template \ + constexpr auto operator a_op##a_op(enumeration& a_lhs) noexcept -> enumeration& \ + { \ + return a_lhs a_op## = static_cast(1); \ + } \ + \ + template \ + [[nodiscard]] constexpr auto operator a_op##a_op(enumeration& a_lhs, int) noexcept -> enumeration \ + { \ + const auto tmp = a_lhs; \ + a_op##a_op a_lhs; \ + return tmp; \ } namespace SFSE { namespace stl { - template < - class E, - class U> - [[nodiscard]] constexpr auto operator~(enumeration a_enum) noexcept - -> enumeration + template + [[nodiscard]] constexpr auto operator~(enumeration a_enum) noexcept -> enumeration { return static_cast(~static_cast(a_enum.get())); } @@ -444,12 +461,11 @@ namespace SFSE SFSE_MAKE_ENUMERATION_OP(+); SFSE_MAKE_ENUMERATION_OP(-); - SFSE_MAKE_INCREMENTER_OP(+); // ++ - SFSE_MAKE_INCREMENTER_OP(-); // -- + SFSE_MAKE_INCREMENTER_OP(+); // ++ + SFSE_MAKE_INCREMENTER_OP(-); // -- template - class atomic_ref : - public std::atomic_ref + class atomic_ref : public std::atomic_ref { private: using super = std::atomic_ref; @@ -457,8 +473,8 @@ namespace SFSE public: using value_type = typename super::value_type; - explicit atomic_ref(volatile T& a_obj) noexcept(std::is_nothrow_constructible_v) : - super(const_cast(a_obj)) + explicit atomic_ref(volatile T& a_obj) noexcept(std::is_nothrow_constructible_v) + : super(const_cast(a_obj)) {} using super::super; @@ -489,9 +505,15 @@ namespace SFSE template struct ssizeof { - [[nodiscard]] constexpr operator std::ptrdiff_t() const noexcept { return value; } + [[nodiscard]] constexpr operator std::ptrdiff_t() const noexcept + { + return value; + } - [[nodiscard]] constexpr std::ptrdiff_t operator()() const noexcept { return value; } + [[nodiscard]] constexpr std::ptrdiff_t operator()() const noexcept + { + return value; + } static constexpr auto value = static_cast(sizeof(T)); }; @@ -503,13 +525,20 @@ namespace SFSE [[nodiscard]] auto adjust_pointer(U* a_ptr, std::ptrdiff_t a_adjust) noexcept { auto addr = a_ptr ? reinterpret_cast(a_ptr) + a_adjust : 0; - if constexpr (std::is_const_v && std::is_volatile_v) { + if constexpr (std::is_const_v && std::is_volatile_v) + { return reinterpret_cast*>(addr); - } else if constexpr (std::is_const_v) { + } + else if constexpr (std::is_const_v) + { return reinterpret_cast*>(addr); - } else if constexpr (std::is_volatile_v) { + } + else if constexpr (std::is_volatile_v) + { return reinterpret_cast*>(addr); - } else { + } + else + { return reinterpret_cast(addr); } } @@ -518,7 +547,8 @@ namespace SFSE bool emplace_vtable(T* a_ptr) { auto address = T::VTABLE[0].address(); - if (!address) { + if (!address) + { return false; } reinterpret_cast(a_ptr)[0] = address; @@ -534,7 +564,7 @@ namespace SFSE } template - [[nodiscard]] inline auto pun_bits(Args... a_args) // + [[nodiscard]] inline auto pun_bits(Args... a_args) // requires(std::same_as, bool> && ...) { constexpr auto ARGC = sizeof...(Args); @@ -543,89 +573,77 @@ namespace SFSE std::size_t i = 0; ((bits[i++] = a_args), ...); - if constexpr (ARGC <= std::numeric_limits::digits) { + if constexpr (ARGC <= std::numeric_limits::digits) + { return bits.to_ulong(); - } else if constexpr (ARGC <= std::numeric_limits::digits) { + } + else if constexpr (ARGC <= std::numeric_limits::digits) + { return bits.to_ullong(); - } else { + } + else + { static_assert(false && sizeof...(Args)); } } - [[nodiscard]] inline auto utf8_to_utf16(std::string_view a_in) noexcept - -> std::optional + [[nodiscard]] inline auto utf8_to_utf16(std::string_view a_in) noexcept -> std::optional { const auto cvt = [&](wchar_t* a_dst, std::size_t a_length) { - return WinAPI::MultiByteToWideChar( - CP_UTF8, - 0, - a_in.data(), - static_cast(a_in.length()), - a_dst, - static_cast(a_length)); + return WinAPI::MultiByteToWideChar(CP_UTF8, 0, a_in.data(), static_cast(a_in.length()), a_dst, static_cast(a_length)); }; const auto len = cvt(nullptr, 0); - if (len == 0) { + if (len == 0) + { return std::nullopt; } std::wstring out(len, '\0'); - if (cvt(out.data(), out.length()) == 0) { + if (cvt(out.data(), out.length()) == 0) + { return std::nullopt; } return out; } - [[nodiscard]] inline auto utf16_to_utf8(std::wstring_view a_in) noexcept - -> std::optional + [[nodiscard]] inline auto utf16_to_utf8(std::wstring_view a_in) noexcept -> std::optional { const auto cvt = [&](char* a_dst, std::size_t a_length) { - return WinAPI::WideCharToMultiByte( - CP_UTF8, - 0, - a_in.data(), - static_cast(a_in.length()), - a_dst, - static_cast(a_length), - nullptr, - nullptr); + return WinAPI::WideCharToMultiByte(CP_UTF8, 0, a_in.data(), static_cast(a_in.length()), a_dst, static_cast(a_length), + nullptr, nullptr); }; const auto len = cvt(nullptr, 0); - if (len == 0) { + if (len == 0) + { return std::nullopt; } std::string out(len, '\0'); - if (cvt(out.data(), out.length()) == 0) { + if (cvt(out.data(), out.length()) == 0) + { return std::nullopt; } return out; } - inline bool report_and_error(std::string_view a_msg, bool a_fail = true, - std::source_location a_loc = std::source_location::current()) + inline bool report_and_error(std::string_view a_msg, bool a_fail = true, std::source_location a_loc = std::source_location::current()) { const auto body = [&]() -> std::wstring { - const std::filesystem::path p = a_loc.file_name(); + const std::filesystem::path p = a_loc.file_name(); auto filename = p.lexically_normal().generic_string(); const std::regex r{ R"((?:^|[\\\/])(?:include|src)[\\\/](.*)$)" }; std::smatch matches; - if (std::regex_search(filename, matches, r)) { + if (std::regex_search(filename, matches, r)) + { filename = matches[1].str(); } - return utf8_to_utf16( - fmt::format( - "{}({}): {}"sv, - filename, - a_loc.line(), - a_msg)) - .value_or(L""s); + return utf8_to_utf16(fmt::format("{}({}): {}"sv, filename, a_loc.line(), a_msg)).value_or(L""s); }(); const auto caption = []() { @@ -634,46 +652,42 @@ namespace SFSE buf.reserve(maxPath); buf.resize(maxPath / 2); std::uint32_t result = 0; - do { + do + { buf.resize(buf.size() * 2); - result = GetModuleFileName( - WinAPI::GetCurrentModule(), - buf.data(), - static_cast(buf.size())); + result = GetModuleFileName(WinAPI::GetCurrentModule(), buf.data(), static_cast(buf.size())); } while (result && result == buf.size() && buf.size() <= (std::numeric_limits::max)()); - if (result && result != buf.size()) { + if (result && result != buf.size()) + { std::filesystem::path p(buf.begin(), buf.begin() + result); return p.filename().native(); - } else { + } + else + { return L""s; } }(); - spdlog::log( - spdlog::source_loc{ - a_loc.file_name(), - static_cast(a_loc.line()), - a_loc.function_name() }, - spdlog::level::critical, - a_msg); + spdlog::log(spdlog::source_loc{ a_loc.file_name(), static_cast(a_loc.line()), a_loc.function_name() }, spdlog::level::critical, + a_msg); - if (a_fail) { + if (a_fail) + { MessageBox(nullptr, body.c_str(), (caption.empty() ? nullptr : caption.c_str()), 0); WinAPI::TerminateProcess(WinAPI::GetCurrentProcess(), EXIT_FAILURE); } return true; } - [[noreturn]] inline void report_and_fail(std::string_view a_msg, - std::source_location a_loc = std::source_location::current()) + [[noreturn]] inline void report_and_fail(std::string_view a_msg, std::source_location a_loc = std::source_location::current()) { report_and_error(a_msg, true, a_loc); std::unreachable(); } template - [[nodiscard]] constexpr auto to_underlying(Enum a_val) noexcept // + [[nodiscard]] constexpr auto to_underlying(Enum a_val) noexcept // requires(std::is_enum_v) { return static_cast>(a_val); @@ -682,33 +696,35 @@ namespace SFSE template [[nodiscard]] To unrestricted_cast(From a_from) noexcept { - if constexpr (std::is_same_v< - std::remove_cv_t, - std::remove_cv_t>) { + if constexpr (std::is_same_v, std::remove_cv_t>) + { return To{ a_from }; // From != To - } else if constexpr (std::is_reference_v) { + } + else if constexpr (std::is_reference_v) + { return stl::unrestricted_cast(std::addressof(a_from)); // From: NOT reference - } else if constexpr (std::is_reference_v) { - return *stl::unrestricted_cast< - std::add_pointer_t< - std::remove_reference_t>>(a_from); + } + else if constexpr (std::is_reference_v) + { + return *stl::unrestricted_cast>>(a_from); // To: NOT reference - } else if constexpr (std::is_pointer_v && - std::is_pointer_v) { - return static_cast( - const_cast( - static_cast(a_from))); - } else if constexpr ((std::is_pointer_v && std::is_integral_v) || - (std::is_integral_v && std::is_pointer_v)) { + } + else if constexpr (std::is_pointer_v && std::is_pointer_v) + { + return static_cast(const_cast(static_cast(a_from))); + } + else if constexpr ((std::is_pointer_v && std::is_integral_v) || (std::is_integral_v && std::is_pointer_v)) + { return reinterpret_cast(a_from); - } else { - union - { + } + else + { + union { std::remove_cv_t> from; std::remove_cv_t> to; }; @@ -717,8 +733,8 @@ namespace SFSE return to; } } - } -} + } // namespace stl +} // namespace SFSE #undef SFSE_MAKE_INCREMENTER_OP #undef SFSE_MAKE_ENUMERATION_OP @@ -728,16 +744,16 @@ namespace SFSE namespace RE { using namespace std::literals; - namespace stl = SFSE::stl; + namespace stl = SFSE::stl; namespace WinAPI = SFSE::WinAPI; -} +} // namespace RE namespace REL { using namespace std::literals; - namespace stl = SFSE::stl; + namespace stl = SFSE::stl; namespace WinAPI = SFSE::WinAPI; -} +} // namespace REL #include "REL/Relocation.h" @@ -746,4 +762,4 @@ namespace REL #include "RE/Offsets_RTTI.h" #include "RE/Offsets_VTABLE.h" -#undef cdecl // Workaround for Clang. +#undef cdecl // Workaround for Clang. diff --git a/CommonLibSF/include/SFSE/Impl/Stubs.h b/CommonLibSF/include/SFSE/Impl/Stubs.h index ec55aa60..ceab1672 100644 --- a/CommonLibSF/include/SFSE/Impl/Stubs.h +++ b/CommonLibSF/include/SFSE/Impl/Stubs.h @@ -3,6 +3,7 @@ namespace SFSE { using PluginHandle = std::uint32_t; + enum : PluginHandle { kInvalidPluginHandle = static_cast(-1) @@ -39,5 +40,5 @@ namespace SFSE void* (*AllocateFromBranchPool)(PluginHandle, std::size_t); void* (*AllocateFromLocalPool)(PluginHandle, std::size_t); }; - } -} + } // namespace detail +} // namespace SFSE diff --git a/CommonLibSF/include/SFSE/Impl/WinAPI.h b/CommonLibSF/include/SFSE/Impl/WinAPI.h index 51c5d716..1af5f2ea 100644 --- a/CommonLibSF/include/SFSE/Impl/WinAPI.h +++ b/CommonLibSF/include/SFSE/Impl/WinAPI.h @@ -42,22 +42,24 @@ namespace SFSE::WinAPI { public: // members - void* DebugInfo; // 00 - std::int32_t LockCount; // 08 - std::int32_t RecursionCount; // 0C - void* OwningThread; // 10 - void* LockSemaphore; // 18 - std::uint64_t* SpinCount; // 20 + void* DebugInfo; // 00 + std::int32_t LockCount; // 08 + std::int32_t RecursionCount; // 0C + void* OwningThread; // 10 + void* LockSemaphore; // 18 + std::uint64_t* SpinCount; // 20 }; + static_assert(sizeof(CRITICAL_SECTION) == 0x28); struct _FILETIME { public: // members - std::uint32_t dwLowDateTime; // 00 - std::uint32_t dwHighDateTime; // 04 + std::uint32_t dwLowDateTime; // 00 + std::uint32_t dwHighDateTime; // 04 }; + static_assert(sizeof(_FILETIME) == 0x8); using FILETIME = _FILETIME; @@ -68,6 +70,7 @@ namespace SFSE::WinAPI std::uint16_t Data3; std::uint8_t Data4[8]; }; + static_assert(sizeof(_GUID) == 0x10); using GUID = _GUID; @@ -76,7 +79,7 @@ namespace SFSE::WinAPI struct HINSTANCE__; using HINSTANCE = HINSTANCE__*; - using HMODULE = HINSTANCE; + using HMODULE = HINSTANCE; struct HKEY__; using HKEY = HKEY__*; @@ -98,6 +101,7 @@ namespace SFSE::WinAPI char cFileName[MAX_PATH]; char cAlternateFileName[14]; }; + static_assert(sizeof(_WIN32_FIND_DATAA) == 0x140); using WIN32_FIND_DATAA = _WIN32_FIND_DATAA; @@ -116,6 +120,7 @@ namespace SFSE::WinAPI wchar_t cFileName[MAX_PATH]; wchar_t cAlternateFileName[14]; }; + static_assert(sizeof(_WIN32_FIND_DATAW) == 0x250); using WIN32_FIND_DATAW = _WIN32_FIND_DATAW; @@ -126,6 +131,7 @@ namespace SFSE::WinAPI std::int32_t right; std::int32_t bottom; }; + using RECT = tagRECT; struct tagPOINT @@ -133,258 +139,251 @@ namespace SFSE::WinAPI std::int32_t x; std::int32_t y; }; + using POINT = tagPOINT; using HRESULT = std::int32_t; enum VKEnum : std::uint32_t { - VK_LBUTTON = 0x1, - VK_RBUTTON = 0x2, - VK_CANCEL = 0x3, - VK_MBUTTON = 0x4, - VK_XBUTTON1 = 0x5, - VK_XBUTTON2 = 0x6, - VK_BACK = 0x8, - VK_TAB = 0x9, - VK_RESERVED_0A = 0xA, - VK_RESERVED_0B = 0xB, - VK_CLEAR = 0xC, - VK_RETURN = 0xD, - VK_SHIFT = 0x10, - VK_CONTROL = 0x11, - VK_MENU = 0x12, - VK_PAUSE = 0x13, - VK_CAPITAL = 0x14, - VK_KANA = 0x15, - VK_HANGUEL = 0x15, - VK_HANGUL = 0x15, - VK_IME_ON = 0x16, - VK_JUNJA = 0x17, - VK_FINAL = 0x18, - VK_HANJA = 0x19, - VK_KANJI = VK_HANJA, - VK_IME_OFF = 0x1A, - VK_ESCAPE = 0x1B, - VK_CONVERT = 0x1C, - VK_NONCONVERT = 0x1D, - VK_ACCEPT = 0x1E, - VK_MODECHANGE = 0x1F, - VK_SPACE = 0x20, - VK_PRIOR = 0x21, - VK_NEXT = 0x22, - VK_END = 0x23, - VK_HOME = 0x24, - VK_LEFT = 0x25, - VK_UP = 0x26, - VK_RIGHT = 0x27, - VK_DOWN = 0x28, - VK_SELECT = 0x29, - VK_PRINT = 0x2A, - VK_EXECUTE = 0x2B, - VK_SNAPSHOT = 0x2C, - VK_INSERT = 0x2D, - VK_DELETE = 0x2E, - VK_HELP = 0x2F, - VK_0 = 0x30, - VK_1 = 0x31, - VK_2 = 0x32, - VK_3 = 0x33, - VK_4 = 0x34, - VK_5 = 0x35, - VK_6 = 0x36, - VK_7 = 0x37, - VK_8 = 0x38, - VK_9 = 0x39, - VK_A = 0x41, - VK_B = 0x42, - VK_C = 0x43, - VK_D = 0x44, - VK_E = 0x45, - VK_F = 0x46, - VK_G = 0x47, - VK_H = 0x48, - VK_I = 0x49, - VK_J = 0x4A, - VK_K = 0x4B, - VK_L = 0x4C, - VK_M = 0x4D, - VK_N = 0x4E, - VK_O = 0x4F, - VK_P = 0x50, - VK_Q = 0x51, - VK_R = 0x52, - VK_S = 0x53, - VK_T = 0x54, - VK_U = 0x55, - VK_V = 0x56, - VK_W = 0x57, - VK_X = 0x58, - VK_Y = 0x59, - VK_Z = 0x5A, - VK_LWIN = 0x5B, - VK_RWIN = 0x5C, - VK_APPS = 0x5D, - VK_RESERVED_5E = 0x5E, - VK_SLEEP = 0x5F, - VK_NUMPAD0 = 0x60, - VK_NUMPAD1 = 0x61, - VK_NUMPAD2 = 0x62, - VK_NUMPAD3 = 0x63, - VK_NUMPAD4 = 0x64, - VK_NUMPAD5 = 0x65, - VK_NUMPAD6 = 0x66, - VK_NUMPAD7 = 0x67, - VK_NUMPAD8 = 0x68, - VK_NUMPAD9 = 0x69, - VK_MULTIPLY = 0x6A, - VK_ADD = 0x6B, - VK_SEPARATOR = 0x6C, - VK_SUBTRACT = 0x6D, - VK_DECIMAL = 0x6E, - VK_DIVIDE = 0x6F, - VK_F1 = 0x70, - VK_F2 = 0x71, - VK_F3 = 0x72, - VK_F4 = 0x73, - VK_F5 = 0x74, - VK_F6 = 0x75, - VK_F7 = 0x76, - VK_F8 = 0x77, - VK_F9 = 0x78, - VK_F10 = 0x79, - VK_F11 = 0x7A, - VK_F12 = 0x7B, - VK_F13 = 0x7C, - VK_F14 = 0x7D, - VK_F15 = 0x7E, - VK_F16 = 0x7F, - VK_F17 = 0x80, - VK_F18 = 0x81, - VK_F19 = 0x82, - VK_F20 = 0x83, - VK_F21 = 0x84, - VK_F22 = 0x85, - VK_F23 = 0x86, - VK_F24 = 0x87, - VK_NUMLOCK = 0x90, - VK_SCROLL = 0x91, - VK_OEMSPECIFIC_92 = 0x92, - VK_OEMSPECIFIC_93 = 0x93, - VK_OEMSPECIFIC_94 = 0x94, - VK_OEMSPECIFIC_95 = 0x95, - VK_OEMSPECIFIC_96 = 0x96, - VK_LSHIFT = 0xA0, - VK_RSHIFT = 0xA1, - VK_LCONTROL = 0xA2, - VK_RCONTROL = 0xA3, - VK_LMENU = 0xA4, - VK_RMENU = 0xA5, - VK_BROWSER_BACK = 0xA6, - VK_BROWSER_FORWARD = 0xA7, - VK_BROWSER_REFRESH = 0xA8, - VK_BROWSER_STOP = 0xA9, - VK_BROWSER_SEARCH = 0xAA, - VK_BROWSER_FAVORITES = 0xAB, - VK_BROWSER_HOME = 0xAC, - VK_VOLUME_MUTE = 0xAD, - VK_VOLUME_DOWN = 0xAE, - VK_VOLUME_UP = 0xAF, - VK_MEDIA_NEXT_TRACK = 0xB0, - VK_MEDIA_PREV_TRACK = 0xB1, - VK_MEDIA_STOP = 0xB2, - VK_MEDIA_PLAY_PAUSE = 0xB3, - VK_LAUNCH_MAIL = 0xB4, + VK_LBUTTON = 0x1, + VK_RBUTTON = 0x2, + VK_CANCEL = 0x3, + VK_MBUTTON = 0x4, + VK_XBUTTON1 = 0x5, + VK_XBUTTON2 = 0x6, + VK_BACK = 0x8, + VK_TAB = 0x9, + VK_RESERVED_0A = 0xA, + VK_RESERVED_0B = 0xB, + VK_CLEAR = 0xC, + VK_RETURN = 0xD, + VK_SHIFT = 0x10, + VK_CONTROL = 0x11, + VK_MENU = 0x12, + VK_PAUSE = 0x13, + VK_CAPITAL = 0x14, + VK_KANA = 0x15, + VK_HANGUEL = 0x15, + VK_HANGUL = 0x15, + VK_IME_ON = 0x16, + VK_JUNJA = 0x17, + VK_FINAL = 0x18, + VK_HANJA = 0x19, + VK_KANJI = VK_HANJA, + VK_IME_OFF = 0x1A, + VK_ESCAPE = 0x1B, + VK_CONVERT = 0x1C, + VK_NONCONVERT = 0x1D, + VK_ACCEPT = 0x1E, + VK_MODECHANGE = 0x1F, + VK_SPACE = 0x20, + VK_PRIOR = 0x21, + VK_NEXT = 0x22, + VK_END = 0x23, + VK_HOME = 0x24, + VK_LEFT = 0x25, + VK_UP = 0x26, + VK_RIGHT = 0x27, + VK_DOWN = 0x28, + VK_SELECT = 0x29, + VK_PRINT = 0x2A, + VK_EXECUTE = 0x2B, + VK_SNAPSHOT = 0x2C, + VK_INSERT = 0x2D, + VK_DELETE = 0x2E, + VK_HELP = 0x2F, + VK_0 = 0x30, + VK_1 = 0x31, + VK_2 = 0x32, + VK_3 = 0x33, + VK_4 = 0x34, + VK_5 = 0x35, + VK_6 = 0x36, + VK_7 = 0x37, + VK_8 = 0x38, + VK_9 = 0x39, + VK_A = 0x41, + VK_B = 0x42, + VK_C = 0x43, + VK_D = 0x44, + VK_E = 0x45, + VK_F = 0x46, + VK_G = 0x47, + VK_H = 0x48, + VK_I = 0x49, + VK_J = 0x4A, + VK_K = 0x4B, + VK_L = 0x4C, + VK_M = 0x4D, + VK_N = 0x4E, + VK_O = 0x4F, + VK_P = 0x50, + VK_Q = 0x51, + VK_R = 0x52, + VK_S = 0x53, + VK_T = 0x54, + VK_U = 0x55, + VK_V = 0x56, + VK_W = 0x57, + VK_X = 0x58, + VK_Y = 0x59, + VK_Z = 0x5A, + VK_LWIN = 0x5B, + VK_RWIN = 0x5C, + VK_APPS = 0x5D, + VK_RESERVED_5E = 0x5E, + VK_SLEEP = 0x5F, + VK_NUMPAD0 = 0x60, + VK_NUMPAD1 = 0x61, + VK_NUMPAD2 = 0x62, + VK_NUMPAD3 = 0x63, + VK_NUMPAD4 = 0x64, + VK_NUMPAD5 = 0x65, + VK_NUMPAD6 = 0x66, + VK_NUMPAD7 = 0x67, + VK_NUMPAD8 = 0x68, + VK_NUMPAD9 = 0x69, + VK_MULTIPLY = 0x6A, + VK_ADD = 0x6B, + VK_SEPARATOR = 0x6C, + VK_SUBTRACT = 0x6D, + VK_DECIMAL = 0x6E, + VK_DIVIDE = 0x6F, + VK_F1 = 0x70, + VK_F2 = 0x71, + VK_F3 = 0x72, + VK_F4 = 0x73, + VK_F5 = 0x74, + VK_F6 = 0x75, + VK_F7 = 0x76, + VK_F8 = 0x77, + VK_F9 = 0x78, + VK_F10 = 0x79, + VK_F11 = 0x7A, + VK_F12 = 0x7B, + VK_F13 = 0x7C, + VK_F14 = 0x7D, + VK_F15 = 0x7E, + VK_F16 = 0x7F, + VK_F17 = 0x80, + VK_F18 = 0x81, + VK_F19 = 0x82, + VK_F20 = 0x83, + VK_F21 = 0x84, + VK_F22 = 0x85, + VK_F23 = 0x86, + VK_F24 = 0x87, + VK_NUMLOCK = 0x90, + VK_SCROLL = 0x91, + VK_OEMSPECIFIC_92 = 0x92, + VK_OEMSPECIFIC_93 = 0x93, + VK_OEMSPECIFIC_94 = 0x94, + VK_OEMSPECIFIC_95 = 0x95, + VK_OEMSPECIFIC_96 = 0x96, + VK_LSHIFT = 0xA0, + VK_RSHIFT = 0xA1, + VK_LCONTROL = 0xA2, + VK_RCONTROL = 0xA3, + VK_LMENU = 0xA4, + VK_RMENU = 0xA5, + VK_BROWSER_BACK = 0xA6, + VK_BROWSER_FORWARD = 0xA7, + VK_BROWSER_REFRESH = 0xA8, + VK_BROWSER_STOP = 0xA9, + VK_BROWSER_SEARCH = 0xAA, + VK_BROWSER_FAVORITES = 0xAB, + VK_BROWSER_HOME = 0xAC, + VK_VOLUME_MUTE = 0xAD, + VK_VOLUME_DOWN = 0xAE, + VK_VOLUME_UP = 0xAF, + VK_MEDIA_NEXT_TRACK = 0xB0, + VK_MEDIA_PREV_TRACK = 0xB1, + VK_MEDIA_STOP = 0xB2, + VK_MEDIA_PLAY_PAUSE = 0xB3, + VK_LAUNCH_MAIL = 0xB4, VK_LAUNCH_MEDIA_SELECT = 0xB5, - VK_LAUNCH_APP1 = 0xB6, - VK_LAUNCH_APP2 = 0xB7, - VK_RESERVED_B8 = 0xB8, - VK_RESERVED_B9 = 0xB9, - VK_OEM_1 = 0xBA, - VK_OEM_PLUS = 0xBB, - VK_OEM_COMMA = 0xBC, - VK_OEM_MINUS = 0xBD, - VK_OEM_PERIOD = 0xBE, - VK_OEM_2 = 0xBF, - VK_OEM_3 = 0xC0, - VK_RESERVED_C1 = 0xC1, - VK_RESERVED_C2 = 0xC2, - VK_RESERVED_C3 = 0xC3, - VK_RESERVED_C4 = 0xC4, - VK_RESERVED_C5 = 0xC5, - VK_RESERVED_C6 = 0xC6, - VK_RESERVED_C7 = 0xC7, - VK_RESERVED_C8 = 0xC8, - VK_RESERVED_C9 = 0xC9, - VK_RESERVED_CA = 0xCA, - VK_RESERVED_CB = 0xCB, - VK_RESERVED_CC = 0xCC, - VK_RESERVED_CD = 0xCD, - VK_RESERVED_CE = 0xCE, - VK_RESERVED_CF = 0xCF, - VK_RESERVED_D0 = 0xD0, - VK_RESERVED_D1 = 0xD1, - VK_RESERVED_D2 = 0xD2, - VK_RESERVED_D3 = 0xD3, - VK_RESERVED_D4 = 0xD4, - VK_RESERVED_D5 = 0xD5, - VK_RESERVED_D6 = 0xD6, - VK_RESERVED_D7 = 0xD7, - VK_OEM_4 = 0xDB, - VK_OEM_5 = 0xDC, - VK_OEM_6 = 0xDD, - VK_OEM_7 = 0xDE, - VK_OEM_8 = 0xDF, - VK_RESERVED_E0 = 0xE0, - VK_OEMSPECIFIC_E1 = 0xE1, - VK_OEM_102 = 0xE2, - VK_OEMSPECIFIC_E3 = 0xE3, - VK_OEMSPECIFIC_E4 = 0xE4, - VK_PROCESSKEY = 0xE5, - VK_OEMSPECIFIC_E6 = 0xE6, - VK_PACKET = 0xE7, - VK_OEMSPECIFIC_E9 = 0xE9, - VK_OEMSPECIFIC_EA = 0xEA, - VK_OEMSPECIFIC_EB = 0xEB, - VK_OEMSPECIFIC_EC = 0xEC, - VK_OEMSPECIFIC_ED = 0xED, - VK_OEMSPECIFIC_EE = 0xEE, - VK_OEMSPECIFIC_EF = 0xEF, - VK_OEMSPECIFIC_F0 = 0xF0, - VK_OEMSPECIFIC_F1 = 0xF1, - VK_OEMSPECIFIC_F2 = 0xF2, - VK_OEMSPECIFIC_F3 = 0xF3, - VK_OEMSPECIFIC_F4 = 0xF4, - VK_OEMSPECIFIC_F5 = 0xF5, - VK_ATTN = 0xF6, - VK_CRSEL = 0xF7, - VK_EXSEL = 0xF8, - VK_EREOF = 0xF9, - VK_PLAY = 0xFA, - VK_ZOOM = 0xFB, - VK_NONAME = 0xFC, - VK_PA1 = 0xFD, - VK_OEM_CLEAR = 0xFE, - VK_RESERVED_FF = 0xFF + VK_LAUNCH_APP1 = 0xB6, + VK_LAUNCH_APP2 = 0xB7, + VK_RESERVED_B8 = 0xB8, + VK_RESERVED_B9 = 0xB9, + VK_OEM_1 = 0xBA, + VK_OEM_PLUS = 0xBB, + VK_OEM_COMMA = 0xBC, + VK_OEM_MINUS = 0xBD, + VK_OEM_PERIOD = 0xBE, + VK_OEM_2 = 0xBF, + VK_OEM_3 = 0xC0, + VK_RESERVED_C1 = 0xC1, + VK_RESERVED_C2 = 0xC2, + VK_RESERVED_C3 = 0xC3, + VK_RESERVED_C4 = 0xC4, + VK_RESERVED_C5 = 0xC5, + VK_RESERVED_C6 = 0xC6, + VK_RESERVED_C7 = 0xC7, + VK_RESERVED_C8 = 0xC8, + VK_RESERVED_C9 = 0xC9, + VK_RESERVED_CA = 0xCA, + VK_RESERVED_CB = 0xCB, + VK_RESERVED_CC = 0xCC, + VK_RESERVED_CD = 0xCD, + VK_RESERVED_CE = 0xCE, + VK_RESERVED_CF = 0xCF, + VK_RESERVED_D0 = 0xD0, + VK_RESERVED_D1 = 0xD1, + VK_RESERVED_D2 = 0xD2, + VK_RESERVED_D3 = 0xD3, + VK_RESERVED_D4 = 0xD4, + VK_RESERVED_D5 = 0xD5, + VK_RESERVED_D6 = 0xD6, + VK_RESERVED_D7 = 0xD7, + VK_OEM_4 = 0xDB, + VK_OEM_5 = 0xDC, + VK_OEM_6 = 0xDD, + VK_OEM_7 = 0xDE, + VK_OEM_8 = 0xDF, + VK_RESERVED_E0 = 0xE0, + VK_OEMSPECIFIC_E1 = 0xE1, + VK_OEM_102 = 0xE2, + VK_OEMSPECIFIC_E3 = 0xE3, + VK_OEMSPECIFIC_E4 = 0xE4, + VK_PROCESSKEY = 0xE5, + VK_OEMSPECIFIC_E6 = 0xE6, + VK_PACKET = 0xE7, + VK_OEMSPECIFIC_E9 = 0xE9, + VK_OEMSPECIFIC_EA = 0xEA, + VK_OEMSPECIFIC_EB = 0xEB, + VK_OEMSPECIFIC_EC = 0xEC, + VK_OEMSPECIFIC_ED = 0xED, + VK_OEMSPECIFIC_EE = 0xEE, + VK_OEMSPECIFIC_EF = 0xEF, + VK_OEMSPECIFIC_F0 = 0xF0, + VK_OEMSPECIFIC_F1 = 0xF1, + VK_OEMSPECIFIC_F2 = 0xF2, + VK_OEMSPECIFIC_F3 = 0xF3, + VK_OEMSPECIFIC_F4 = 0xF4, + VK_OEMSPECIFIC_F5 = 0xF5, + VK_ATTN = 0xF6, + VK_CRSEL = 0xF7, + VK_EXSEL = 0xF8, + VK_EREOF = 0xF9, + VK_PLAY = 0xFA, + VK_ZOOM = 0xFB, + VK_NONAME = 0xFC, + VK_PA1 = 0xFD, + VK_OEM_CLEAR = 0xFE, + VK_RESERVED_FF = 0xFF }; [[nodiscard]] bool FindClose(void* a_findFile) noexcept; - [[nodiscard]] void* FindFirstFile( - const char* a_fileName, - WIN32_FIND_DATAA* a_findFileData) noexcept; + [[nodiscard]] void* FindFirstFile(const char* a_fileName, WIN32_FIND_DATAA* a_findFileData) noexcept; - [[nodiscard]] void* FindFirstFile( - const wchar_t* a_fileName, - WIN32_FIND_DATAW* a_findFileData) noexcept; + [[nodiscard]] void* FindFirstFile(const wchar_t* a_fileName, WIN32_FIND_DATAW* a_findFileData) noexcept; - [[nodiscard]] bool FindNextFile( - void* a_findFile, - WIN32_FIND_DATAA* a_findFileData) noexcept; + [[nodiscard]] bool FindNextFile(void* a_findFile, WIN32_FIND_DATAA* a_findFileData) noexcept; - [[nodiscard]] bool FindNextFile( - void* a_findFile, - WIN32_FIND_DATAW* a_findFileData) noexcept; + [[nodiscard]] bool FindNextFile(void* a_findFile, WIN32_FIND_DATAW* a_findFileData) noexcept; bool FreeLibrary(HMODULE a_module) noexcept; @@ -394,83 +393,41 @@ namespace SFSE::WinAPI [[nodiscard]] std::uint32_t GetCurrentThreadID() noexcept; - [[nodiscard]] std::uint32_t GetEnvironmentVariable( - const char* a_name, - char* a_buffer, - std::uint32_t a_size) noexcept; - - [[nodiscard]] std::uint32_t GetEnvironmentVariable( - const wchar_t* a_name, - wchar_t* a_buffer, - std::uint32_t a_size) noexcept; - - [[nodiscard]] bool GetFileVersionInfo( - const char* a_filename, - std::uint32_t a_handle, - std::uint32_t a_len, - void* a_data) noexcept; - - [[nodiscard]] bool GetFileVersionInfo( - const wchar_t* a_filename, - std::uint32_t a_handle, - std::uint32_t a_len, - void* a_data) noexcept; - - [[nodiscard]] std::uint32_t GetFileVersionInfoSize( - const char* a_filename, - std::uint32_t* a_handle) noexcept; - - [[nodiscard]] std::uint32_t GetFileVersionInfoSize( - const wchar_t* a_filename, - std::uint32_t* a_handle) noexcept; - - [[nodiscard]] int GetKeyNameText( - std::int32_t a_lParam, - char* a_buffer, - int a_size) noexcept; - - [[nodiscard]] int GetKeyNameText( - std::int32_t a_lParam, - wchar_t* a_buffer, - int a_size) noexcept; + [[nodiscard]] std::uint32_t GetEnvironmentVariable(const char* a_name, char* a_buffer, std::uint32_t a_size) noexcept; + + [[nodiscard]] std::uint32_t GetEnvironmentVariable(const wchar_t* a_name, wchar_t* a_buffer, std::uint32_t a_size) noexcept; + + [[nodiscard]] bool GetFileVersionInfo(const char* a_filename, std::uint32_t a_handle, std::uint32_t a_len, void* a_data) noexcept; + + [[nodiscard]] bool GetFileVersionInfo(const wchar_t* a_filename, std::uint32_t a_handle, std::uint32_t a_len, void* a_data) noexcept; + + [[nodiscard]] std::uint32_t GetFileVersionInfoSize(const char* a_filename, std::uint32_t* a_handle) noexcept; + + [[nodiscard]] std::uint32_t GetFileVersionInfoSize(const wchar_t* a_filename, std::uint32_t* a_handle) noexcept; + + [[nodiscard]] int GetKeyNameText(std::int32_t a_lParam, char* a_buffer, int a_size) noexcept; + + [[nodiscard]] int GetKeyNameText(std::int32_t a_lParam, wchar_t* a_buffer, int a_size) noexcept; [[nodiscard]] std::int16_t GetKeyState(int nVirtKey) noexcept; [[nodiscard]] std::size_t GetMaxPath() noexcept; - [[nodiscard]] std::uint32_t GetModuleFileName( - void* a_module, - char* a_filename, - std::uint32_t a_size) noexcept; + [[nodiscard]] std::uint32_t GetModuleFileName(void* a_module, char* a_filename, std::uint32_t a_size) noexcept; - [[nodiscard]] std::uint32_t GetModuleFileName( - void* a_module, - wchar_t* a_filename, - std::uint32_t a_size) noexcept; + [[nodiscard]] std::uint32_t GetModuleFileName(void* a_module, wchar_t* a_filename, std::uint32_t a_size) noexcept; [[nodiscard]] HMODULE GetModuleHandle(const char* a_moduleName) noexcept; [[nodiscard]] HMODULE GetModuleHandle(const wchar_t* a_moduleName) noexcept; - [[nodiscard]] std::uint32_t GetPrivateProfileString( - const char* a_appName, - const char* a_keyName, - const char* a_default, - char* a_outString, - std::uint32_t a_size, - const char* a_fileName) noexcept; - - [[nodiscard]] std::uint32_t GetPrivateProfileString( - const wchar_t* a_appName, - const wchar_t* a_keyName, - const wchar_t* a_default, - wchar_t* a_outString, - std::uint32_t a_size, - const wchar_t* a_fileName) noexcept; - - [[nodiscard]] void* GetProcAddress( - void* a_module, - const char* a_procName) noexcept; + [[nodiscard]] std::uint32_t GetPrivateProfileString(const char* a_appName, const char* a_keyName, const char* a_default, char* a_outString, + std::uint32_t a_size, const char* a_fileName) noexcept; + + [[nodiscard]] std::uint32_t GetPrivateProfileString(const wchar_t* a_appName, const wchar_t* a_keyName, const wchar_t* a_default, + wchar_t* a_outString, std::uint32_t a_size, const wchar_t* a_fileName) noexcept; + + [[nodiscard]] void* GetProcAddress(void* a_module, const char* a_procName) noexcept; [[nodiscard]] std::string_view GetProcPath(HMODULE a_handle = 0) noexcept; @@ -480,83 +437,41 @@ namespace SFSE::WinAPI [[nodiscard]] HMODULE LoadLibrary(const wchar_t* a_libFileName) noexcept; - std::int32_t MessageBox( - void* a_wnd, - const char* a_text, - const char* a_caption, - unsigned int a_type) noexcept; + std::int32_t MessageBox(void* a_wnd, const char* a_text, const char* a_caption, unsigned int a_type) noexcept; - std::int32_t MessageBox( - void* a_wnd, - const wchar_t* a_text, - const wchar_t* a_caption, - unsigned int a_type) noexcept; + std::int32_t MessageBox(void* a_wnd, const wchar_t* a_text, const wchar_t* a_caption, unsigned int a_type) noexcept; - [[nodiscard]] int MultiByteToWideChar( - unsigned int a_codePage, - std::uint32_t a_flags, - const char* a_multiByteStr, - int a_multiByte, - wchar_t* a_wideCharStr, - int a_wideChar); + [[nodiscard]] int MultiByteToWideChar(unsigned int a_codePage, std::uint32_t a_flags, const char* a_multiByteStr, int a_multiByte, + wchar_t* a_wideCharStr, int a_wideChar); - void OutputDebugString( - const char* a_outputString) noexcept; + void OutputDebugString(const char* a_outputString) noexcept; - void OutputDebugString( - const wchar_t* a_outputString) noexcept; + void OutputDebugString(const wchar_t* a_outputString) noexcept; - long RegGetValueW(HKEY hkey, const char* subKey, const char* value, unsigned long flags, unsigned long* type, - void* data, unsigned long* length); + long RegGetValueW(HKEY hkey, const char* subKey, const char* value, unsigned long flags, unsigned long* type, void* data, unsigned long* length); - long RegGetValueW(HKEY hkey, const wchar_t* subKey, const wchar_t* value, unsigned long flags, unsigned long* type, - void* data, unsigned long* length); + long RegGetValueW(HKEY hkey, const wchar_t* subKey, const wchar_t* value, unsigned long flags, unsigned long* type, void* data, + unsigned long* length); [[nodiscard]] int ShowCursor(bool bShow) noexcept; - [[noreturn]] void TerminateProcess( - void* a_process, - unsigned int a_exitCode) noexcept; + [[noreturn]] void TerminateProcess(void* a_process, unsigned int a_exitCode) noexcept; [[nodiscard]] void* TlsGetValue(std::uint32_t a_tlsIndex) noexcept; - bool TlsSetValue( - std::uint32_t a_tlsIndex, - void* a_tlsValue) noexcept; - - bool VirtualFree( - void* a_address, - std::size_t a_size, - std::uint32_t a_freeType) noexcept; - - [[nodiscard]] bool VerQueryValue( - const void* a_block, - const char* a_subBlock, - void** a_buffer, - unsigned int* a_len) noexcept; - - [[nodiscard]] bool VerQueryValue( - const void* a_block, - const wchar_t* a_subBlock, - void** a_buffer, - unsigned int* a_len) noexcept; - - [[nodiscard]] bool VirtualProtect( - void* a_address, - std::size_t a_size, - std::uint32_t a_newProtect, - std::uint32_t* a_oldProtect) noexcept; - - [[nodiscard]] int WideCharToMultiByte( - unsigned int a_codePage, - std::uint32_t a_flags, - const wchar_t* a_wideCharStr, - int a_wideChar, - char* a_multiByteStr, - int a_multiByte, - const char* a_defaultChar, - int* a_usedDefaultChar); -} + bool TlsSetValue(std::uint32_t a_tlsIndex, void* a_tlsValue) noexcept; + + bool VirtualFree(void* a_address, std::size_t a_size, std::uint32_t a_freeType) noexcept; + + [[nodiscard]] bool VerQueryValue(const void* a_block, const char* a_subBlock, void** a_buffer, unsigned int* a_len) noexcept; + + [[nodiscard]] bool VerQueryValue(const void* a_block, const wchar_t* a_subBlock, void** a_buffer, unsigned int* a_len) noexcept; + + [[nodiscard]] bool VirtualProtect(void* a_address, std::size_t a_size, std::uint32_t a_newProtect, std::uint32_t* a_oldProtect) noexcept; + + [[nodiscard]] int WideCharToMultiByte(unsigned int a_codePage, std::uint32_t a_flags, const wchar_t* a_wideCharStr, int a_wideChar, + char* a_multiByteStr, int a_multiByte, const char* a_defaultChar, int* a_usedDefaultChar); +} // namespace SFSE::WinAPI namespace RE::DirectX { @@ -566,25 +481,26 @@ namespace RE::DirectX // members float m[4][4]; }; + static_assert(sizeof(XMFLOAT4X4) == 0x40); -} - -#define CP_UTF8 ::SFSE::WinAPI::CP_UTF8 -#define IMAGE_SCN_MEM_EXECUTE ::SFSE::WinAPI::IMAGE_SCN_MEM_EXECUTE -#define IMAGE_SCN_MEM_WRITE ::SFSE::WinAPI::IMAGE_SCN_MEM_WRITE -#define INVALID_HANDLE_VALUE ::SFSE::WinAPI::INVALID_HANDLE_VALUE -#define MAX_PATH ::SFSE::WinAPI::MAX_PATH -#define MEM_COMMIT ::SFSE::WinAPI::MEM_COMMIT -#define MEM_RESERVE ::SFSE::WinAPI::MEM_RESERVE -#define MEM_RELEASE ::SFSE::WinAPI::MEM_RELEASE +} // namespace RE::DirectX + +#define CP_UTF8 ::SFSE::WinAPI::CP_UTF8 +#define IMAGE_SCN_MEM_EXECUTE ::SFSE::WinAPI::IMAGE_SCN_MEM_EXECUTE +#define IMAGE_SCN_MEM_WRITE ::SFSE::WinAPI::IMAGE_SCN_MEM_WRITE +#define INVALID_HANDLE_VALUE ::SFSE::WinAPI::INVALID_HANDLE_VALUE +#define MAX_PATH ::SFSE::WinAPI::MAX_PATH +#define MEM_COMMIT ::SFSE::WinAPI::MEM_COMMIT +#define MEM_RESERVE ::SFSE::WinAPI::MEM_RESERVE +#define MEM_RELEASE ::SFSE::WinAPI::MEM_RELEASE #define PAGE_EXECUTE_READWRITE ::SFSE::WinAPI::PAGE_EXECUTE_READWRITE #define GetEnvironmentVariable ::SFSE::WinAPI::GetEnvironmentVariable #define GetFileVersionInfoSize ::SFSE::WinAPI::GetFileVersionInfoSize -#define GetModuleFileName ::SFSE::WinAPI::GetModuleFileName -#define VerQueryValue ::SFSE::WinAPI::VerQueryValue -#define GetFileVersionInfo ::SFSE::WinAPI::GetFileVersionInfo -#define GetModuleHandle ::SFSE::WinAPI::GetModuleHandle -#define LoadLibrary ::SFSE::WinAPI::LoadLibrary -#define MessageBox ::SFSE::WinAPI::MessageBox -#define OutputDebugString ::SFSE::WinAPI::OutputDebugString +#define GetModuleFileName ::SFSE::WinAPI::GetModuleFileName +#define VerQueryValue ::SFSE::WinAPI::VerQueryValue +#define GetFileVersionInfo ::SFSE::WinAPI::GetFileVersionInfo +#define GetModuleHandle ::SFSE::WinAPI::GetModuleHandle +#define LoadLibrary ::SFSE::WinAPI::LoadLibrary +#define MessageBox ::SFSE::WinAPI::MessageBox +#define OutputDebugString ::SFSE::WinAPI::OutputDebugString diff --git a/CommonLibSF/include/SFSE/Impl/XInputAPI.h b/CommonLibSF/include/SFSE/Impl/XInputAPI.h index 42280876..fa8b8631 100644 --- a/CommonLibSF/include/SFSE/Impl/XInputAPI.h +++ b/CommonLibSF/include/SFSE/Impl/XInputAPI.h @@ -13,13 +13,17 @@ namespace RE::XInput std::int16_t sThumbRX; std::int16_t sThumbRY; }; + using XINPUT_GAMEPAD = __XINPUT_GAMEPAD; + struct __XINPUT_STATE { std::uint32_t dwPacketNumber; __XINPUT_GAMEPAD Gamepad; }; + using XINPUT_STATE = __XINPUT_STATE; + struct __XINPUT_KEYSTROKE { std::uint16_t VirtualKey; @@ -28,12 +32,15 @@ namespace RE::XInput std::uint8_t UserIndex; std::uint8_t HidCode; }; + using XINPUT_KEYSTROKE = __XINPUT_KEYSTROKE; + struct __XINPUT_VIBRATION { std::uint16_t wLeftMotorSpeed; std::uint16_t wRightMotorSpeed; }; + using XINPUT_VIBRATION = __XINPUT_VIBRATION; struct __XINPUT_CAPABILITIES @@ -44,41 +51,33 @@ namespace RE::XInput XINPUT_GAMEPAD Gamepad; XINPUT_VIBRATION Vibration; }; + using XINPUT_CAPABILITIES = __XINPUT_CAPABILITIES; enum XInputButton : std::uint16_t { - XINPUT_GAMEPAD_DPAD_UP = 0x0001, - XINPUT_GAMEPAD_DPAD_DOWN = 0x0002, - XINPUT_GAMEPAD_DPAD_LEFT = 0x0004, - XINPUT_GAMEPAD_DPAD_RIGHT = 0x0008, - XINPUT_GAMEPAD_START = 0x0010, - XINPUT_GAMEPAD_BACK = 0x0020, - XINPUT_GAMEPAD_LEFT_THUMB = 0x0040, - XINPUT_GAMEPAD_RIGHT_THUMB = 0x0080, - XINPUT_GAMEPAD_LEFT_SHOULDER = 0x0100, + XINPUT_GAMEPAD_DPAD_UP = 0x0001, + XINPUT_GAMEPAD_DPAD_DOWN = 0x0002, + XINPUT_GAMEPAD_DPAD_LEFT = 0x0004, + XINPUT_GAMEPAD_DPAD_RIGHT = 0x0008, + XINPUT_GAMEPAD_START = 0x0010, + XINPUT_GAMEPAD_BACK = 0x0020, + XINPUT_GAMEPAD_LEFT_THUMB = 0x0040, + XINPUT_GAMEPAD_RIGHT_THUMB = 0x0080, + XINPUT_GAMEPAD_LEFT_SHOULDER = 0x0100, XINPUT_GAMEPAD_RIGHT_SHOULDER = 0x0200, - XINPUT_GAMEPAD_A = 0x1000, - XINPUT_GAMEPAD_B = 0x2000, - XINPUT_GAMEPAD_X = 0x4000, - XINPUT_GAMEPAD_Y = 0x8000 + XINPUT_GAMEPAD_A = 0x1000, + XINPUT_GAMEPAD_B = 0x2000, + XINPUT_GAMEPAD_X = 0x4000, + XINPUT_GAMEPAD_Y = 0x8000 }; - static constexpr std::uint16_t XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE = 7849; + + static constexpr std::uint16_t XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE = 7849; static constexpr std::uint16_t XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE = 8689; - static constexpr std::uint8_t XINPUT_GAMEPAD_TRIGGER_THRESHOLD = 30; + static constexpr std::uint8_t XINPUT_GAMEPAD_TRIGGER_THRESHOLD = 30; - static constexpr std::uint16_t XINPUT_BUTTON_MASK = XINPUT_GAMEPAD_DPAD_UP | - XINPUT_GAMEPAD_DPAD_DOWN | - XINPUT_GAMEPAD_DPAD_LEFT | - XINPUT_GAMEPAD_DPAD_RIGHT | - XINPUT_GAMEPAD_START | - XINPUT_GAMEPAD_BACK | - XINPUT_GAMEPAD_LEFT_THUMB | - XINPUT_GAMEPAD_RIGHT_THUMB | - XINPUT_GAMEPAD_LEFT_SHOULDER | - XINPUT_GAMEPAD_RIGHT_SHOULDER | - XINPUT_GAMEPAD_A | - XINPUT_GAMEPAD_B | - XINPUT_GAMEPAD_X | - XINPUT_GAMEPAD_Y; -} + static constexpr std::uint16_t XINPUT_BUTTON_MASK = + XINPUT_GAMEPAD_DPAD_UP | XINPUT_GAMEPAD_DPAD_DOWN | XINPUT_GAMEPAD_DPAD_LEFT | XINPUT_GAMEPAD_DPAD_RIGHT | XINPUT_GAMEPAD_START + | XINPUT_GAMEPAD_BACK | XINPUT_GAMEPAD_LEFT_THUMB | XINPUT_GAMEPAD_RIGHT_THUMB | XINPUT_GAMEPAD_LEFT_SHOULDER | XINPUT_GAMEPAD_RIGHT_SHOULDER + | XINPUT_GAMEPAD_A | XINPUT_GAMEPAD_B | XINPUT_GAMEPAD_X | XINPUT_GAMEPAD_Y; +} // namespace RE::XInput diff --git a/CommonLibSF/include/SFSE/InputMap.h b/CommonLibSF/include/SFSE/InputMap.h index 62973c66..342b4ee2 100644 --- a/CommonLibSF/include/SFSE/InputMap.h +++ b/CommonLibSF/include/SFSE/InputMap.h @@ -7,24 +7,24 @@ namespace SFSE enum { // first 256 for keyboard, then 8 mouse buttons, then mouse wheel up, wheel down, then 16 gamepad buttons - kMacro_KeyboardOffset = 0, // not actually used, just for self-documentation + kMacro_KeyboardOffset = 0, // not actually used, just for self-documentation kMacro_NumKeyboardKeys = 256, - kMacro_MouseButtonOffset = kMacro_NumKeyboardKeys, // 256 - kMacro_NumMouseButtons = 8, + kMacro_MouseButtonOffset = kMacro_NumKeyboardKeys, // 256 + kMacro_NumMouseButtons = 8, - kMacro_MouseWheelOffset = kMacro_MouseButtonOffset + kMacro_NumMouseButtons, // 264 + kMacro_MouseWheelOffset = kMacro_MouseButtonOffset + kMacro_NumMouseButtons, // 264 kMacro_MouseWheelDirections = 2, - kMacro_GamepadOffset = kMacro_MouseWheelOffset + kMacro_MouseWheelDirections, // 266 + kMacro_GamepadOffset = kMacro_MouseWheelOffset + kMacro_MouseWheelDirections, // 266 kMacro_NumGamepadButtons = 16, - kMaxMacros = kMacro_GamepadOffset + kMacro_NumGamepadButtons // 282 + kMaxMacros = kMacro_GamepadOffset + kMacro_NumGamepadButtons // 282 }; enum { - kGamepadButtonOffset_DPAD_UP = kMacro_GamepadOffset, // 266 + kGamepadButtonOffset_DPAD_UP = kMacro_GamepadOffset, // 266 kGamepadButtonOffset_DPAD_DOWN, kGamepadButtonOffset_DPAD_LEFT, kGamepadButtonOffset_DPAD_RIGHT, @@ -39,7 +39,7 @@ namespace SFSE kGamepadButtonOffset_X, kGamepadButtonOffset_Y, kGamepadButtonOffset_LT, - kGamepadButtonOffset_RT // 281 + kGamepadButtonOffset_RT // 281 }; std::uint32_t GamepadMaskToKeycode(std::uint32_t keyMask); @@ -49,5 +49,5 @@ namespace SFSE std::string GetKeyboardKeyName(std::uint32_t keyCode); std::string GetMouseButtonName(std::uint32_t keyCode); std::string GetGamepadButtonName(std::uint32_t a_keyCode); - } -} + } // namespace InputMap +} // namespace SFSE diff --git a/CommonLibSF/include/SFSE/Interfaces.h b/CommonLibSF/include/SFSE/Interfaces.h index fe0f86aa..7e4cf040 100644 --- a/CommonLibSF/include/SFSE/Interfaces.h +++ b/CommonLibSF/include/SFSE/Interfaces.h @@ -109,44 +109,74 @@ namespace SFSE kVersion = 1, }; - constexpr void PluginVersion(std::uint32_t a_version) noexcept { pluginVersion = a_version; } - constexpr void PluginName(std::string_view a_plugin) noexcept { SetCharBuffer(a_plugin, std::span{ pluginName }); } - constexpr void AuthorName(std::string_view a_name) noexcept { SetCharBuffer(a_name, std::span{ author }); } - constexpr void UsesSigScanning(bool a_value) noexcept { addressIndependence = !a_value; } - constexpr void UsesAddressLibrary(bool a_value) noexcept { addressIndependence = a_value; } - constexpr void HasNoStructUse(bool a_value) noexcept { structureCompatibility = !a_value; } - constexpr void IsLayoutDependent(bool a_value) noexcept { structureCompatibility = a_value; } + constexpr void PluginVersion(std::uint32_t a_version) noexcept + { + pluginVersion = a_version; + } + + constexpr void PluginName(std::string_view a_plugin) noexcept + { + SetCharBuffer(a_plugin, std::span{ pluginName }); + } + + constexpr void AuthorName(std::string_view a_name) noexcept + { + SetCharBuffer(a_name, std::span{ author }); + } + + constexpr void UsesSigScanning(bool a_value) noexcept + { + addressIndependence = !a_value; + } + + constexpr void UsesAddressLibrary(bool a_value) noexcept + { + addressIndependence = a_value; + } + + constexpr void HasNoStructUse(bool a_value) noexcept + { + structureCompatibility = !a_value; + } + + constexpr void IsLayoutDependent(bool a_value) noexcept + { + structureCompatibility = a_value; + } + constexpr void CompatibleVersions(std::initializer_list a_versions) noexcept { // must be zero-terminated assert(a_versions.size() < std::size(compatibleVersions) - 1); - std::ranges::transform( - a_versions, std::begin(compatibleVersions), - [](const REL::Version& a_version) noexcept { return a_version.pack(); }); + std::ranges::transform(a_versions, std::begin(compatibleVersions), + [](const REL::Version& a_version) noexcept { return a_version.pack(); }); + } + + constexpr void MinimumRequiredXSEVersion(REL::Version a_version) noexcept + { + xseMinimum = a_version.pack(); } - constexpr void MinimumRequiredXSEVersion(REL::Version a_version) noexcept { xseMinimum = a_version.pack(); } const std::uint32_t dataVersion{ kVersion }; - std::uint32_t pluginVersion = 0; + std::uint32_t pluginVersion = 0; char pluginName[256] = {}; - char author[256] = {}; + char author[256] = {}; std::uint32_t addressIndependence; std::uint32_t structureCompatibility; std::uint32_t compatibleVersions[16] = {}; - std::uint32_t xseMinimum = 0; - const std::uint32_t reservedNonBreaking = 0; - const std::uint32_t reservedBreaking = 0; + std::uint32_t xseMinimum = 0; + const std::uint32_t reservedNonBreaking = 0; + const std::uint32_t reservedBreaking = 0; private: - static constexpr void SetCharBuffer( - std::string_view a_src, - std::span a_dst) noexcept + static constexpr void SetCharBuffer(std::string_view a_src, std::span a_dst) noexcept { assert(a_src.size() < a_dst.size()); std::ranges::fill(a_dst, '\0'); std::ranges::copy(a_src, a_dst.begin()); } }; + static_assert(offsetof(PluginVersionData, dataVersion) == 0x000); static_assert(offsetof(PluginVersionData, pluginVersion) == 0x004); static_assert(offsetof(PluginVersionData, pluginName) == 0x008); @@ -158,4 +188,4 @@ namespace SFSE static_assert(offsetof(PluginVersionData, reservedNonBreaking) == 0x254); static_assert(offsetof(PluginVersionData, reservedBreaking) == 0x258); static_assert(sizeof(PluginVersionData) == 0x25C); -} // namespace SFSE +} // namespace SFSE diff --git a/CommonLibSF/include/SFSE/Logger.h b/CommonLibSF/include/SFSE/Logger.h index e1914ada..4f9f4385 100644 --- a/CommonLibSF/include/SFSE/Logger.h +++ b/CommonLibSF/include/SFSE/Logger.h @@ -1,29 +1,20 @@ #pragma once -#define SFSE_MAKE_SOURCE_LOGGER(a_func, a_type) \ - \ - template \ - struct [[maybe_unused]] a_func \ - { \ - a_func() = delete; \ - \ - explicit a_func( \ - fmt::format_string a_fmt, \ - Args&&... a_args, \ - std::source_location a_loc = std::source_location::current()) \ - { \ - spdlog::log( \ - spdlog::source_loc{ \ - a_loc.file_name(), \ - static_cast(a_loc.line()), \ - a_loc.function_name() }, \ - spdlog::level::a_type, \ - a_fmt, \ - std::forward(a_args)...); \ - } \ - }; \ - \ - template \ +#define SFSE_MAKE_SOURCE_LOGGER(a_func, a_type) \ + \ + template \ + struct [[maybe_unused]] a_func \ + { \ + a_func() = delete; \ + \ + explicit a_func(fmt::format_string a_fmt, Args&&... a_args, std::source_location a_loc = std::source_location::current()) \ + { \ + spdlog::log(spdlog::source_loc{ a_loc.file_name(), static_cast(a_loc.line()), a_loc.function_name() }, spdlog::level::a_type, \ + a_fmt, std::forward(a_args)...); \ + } \ + }; \ + \ + template \ a_func(fmt::format_string, Args&&...) -> a_func; namespace SFSE::log @@ -36,6 +27,6 @@ namespace SFSE::log SFSE_MAKE_SOURCE_LOGGER(critical, critical); [[nodiscard]] std::optional log_directory(); -} +} // namespace SFSE::log #undef SFSE_MAKE_SOURCE_LOGGER diff --git a/CommonLibSF/include/SFSE/Trampoline.h b/CommonLibSF/include/SFSE/Trampoline.h index af10e3a7..099a41d0 100644 --- a/CommonLibSF/include/SFSE/Trampoline.h +++ b/CommonLibSF/include/SFSE/Trampoline.h @@ -13,95 +13,106 @@ namespace SFSE { [[nodiscard]] constexpr std::size_t roundup(std::size_t a_number, std::size_t a_multiple) noexcept { - if (a_multiple == 0) { + if (a_multiple == 0) + { return 0; } const auto remainder = a_number % a_multiple; - return remainder == 0 ? - a_number : - a_number + a_multiple - remainder; + return remainder == 0 ? a_number : a_number + a_multiple - remainder; } [[nodiscard]] constexpr std::size_t rounddown(std::size_t a_number, std::size_t a_multiple) noexcept { - if (a_multiple == 0) { + if (a_multiple == 0) + { return 0; } const auto remainder = a_number % a_multiple; - return remainder == 0 ? - a_number : - a_number - remainder; + return remainder == 0 ? a_number : a_number - remainder; } - } + } // namespace detail class Trampoline { public: using deleter_type = std::function; - Trampoline() = default; + Trampoline() = default; Trampoline(const Trampoline&) = delete; - Trampoline(Trampoline&& a_rhs) { move_from(std::move(a_rhs)); } + Trampoline(Trampoline&& a_rhs) + { + move_from(std::move(a_rhs)); + } - explicit Trampoline(std::string_view a_name) : - _name(a_name) + explicit Trampoline(std::string_view a_name) : _name(a_name) {} - ~Trampoline() { release(); } + ~Trampoline() + { + release(); + } Trampoline& operator=(const Trampoline&) = delete; Trampoline& operator=(Trampoline&& a_rhs) { - if (this != std::addressof(a_rhs)) { + if (this != std::addressof(a_rhs)) + { move_from(std::move(a_rhs)); } return *this; } - void create(std::size_t a_size) { return create(a_size, nullptr); } + void create(std::size_t a_size) + { + return create(a_size, nullptr); + } void create(std::size_t a_size, void* a_module) { - if (a_size == 0) { + if (a_size == 0) + { stl::report_and_fail("cannot create a trampoline with a zero size"sv); } - if (!a_module) { + if (!a_module) + { const auto text = REL::Module::get().segment(REL::Segment::textx); - a_module = text.pointer() + text.size(); + a_module = text.pointer() + text.size(); } auto mem = do_create(a_size, reinterpret_cast(a_module)); - if (!mem) { + if (!mem) + { stl::report_and_fail("failed to create trampoline"sv); } - set_trampoline(mem, a_size, - [](void* a_mem, std::size_t) { - WinAPI::VirtualFree(a_mem, 0, MEM_RELEASE); - }); + set_trampoline(mem, a_size, [](void* a_mem, std::size_t) { WinAPI::VirtualFree(a_mem, 0, MEM_RELEASE); }); } - void set_trampoline(void* a_trampoline, std::size_t a_size) { set_trampoline(a_trampoline, a_size, {}); } + void set_trampoline(void* a_trampoline, std::size_t a_size) + { + set_trampoline(a_trampoline, a_size, {}); + } void set_trampoline(void* a_trampoline, std::size_t a_size, deleter_type a_deleter) { auto trampoline = static_cast(a_trampoline); - if (trampoline) { + if (trampoline) + { constexpr auto INT3 = static_cast(0xCC); std::memset(trampoline, INT3, a_size); } release(); - _deleter = std::move(a_deleter); - _data = trampoline; + _deleter = std::move(a_deleter); + _data = trampoline; _capacity = a_size; - _size = 0; + _size = 0; log_stats(); } @@ -123,24 +134,44 @@ namespace SFSE return static_cast(allocate(sizeof(T))); } - [[nodiscard]] constexpr std::size_t empty() const noexcept { return _capacity == 0; } - [[nodiscard]] constexpr std::size_t capacity() const noexcept { return _capacity; } - [[nodiscard]] constexpr std::size_t allocated_size() const noexcept { return _size; } - [[nodiscard]] constexpr std::size_t free_size() const noexcept { return _capacity - _size; } + [[nodiscard]] constexpr std::size_t empty() const noexcept + { + return _capacity == 0; + } + + [[nodiscard]] constexpr std::size_t capacity() const noexcept + { + return _capacity; + } + + [[nodiscard]] constexpr std::size_t allocated_size() const noexcept + { + return _size; + } + + [[nodiscard]] constexpr std::size_t free_size() const noexcept + { + return _capacity - _size; + } template std::uintptr_t write_branch(std::uintptr_t a_src, std::uintptr_t a_dst) { std::uint8_t data = 0; - if constexpr (N == 5) { + if constexpr (N == 5) + { // E9 cd // JMP rel32 data = 0xE9; - } else if constexpr (N == 6) { + } + else if constexpr (N == 6) + { // FF /4 // JMP r/m64 data = 0x25; - } else { + } + else + { static_assert(false && N, "invalid branch size"); } @@ -157,15 +188,20 @@ namespace SFSE std::uintptr_t write_call(std::uintptr_t a_src, std::uintptr_t a_dst) { std::uint8_t data = 0; - if constexpr (N == 5) { + if constexpr (N == 5) + { // E8 cd // CALL rel32 data = 0xE8; - } else if constexpr (N == 6) { + } + else if constexpr (N == 6) + { // FF /2 // CALL r/m64 data = 0x15; - } else { + } + else + { static_assert(false && N, "invalid call size"); } @@ -183,7 +219,8 @@ namespace SFSE [[nodiscard]] void* do_allocate(std::size_t a_size) { - if (a_size > free_size()) { + if (a_size > free_size()) + { stl::report_and_fail("Failed to handle allocation request"sv); } @@ -196,12 +233,14 @@ namespace SFSE void write_5branch(std::uintptr_t a_src, std::uintptr_t a_dst, std::uint8_t a_opcode) { #pragma pack(push, 1) + struct SrcAssembly { // jmp/call [rip + imm32] - std::uint8_t opcode; // 0 - 0xE9/0xE8 - std::int32_t disp; // 1 + std::uint8_t opcode; // 0 - 0xE9/0xE8 + std::int32_t disp; // 1 }; + static_assert(offsetof(SrcAssembly, opcode) == 0x0); static_assert(offsetof(SrcAssembly, disp) == 0x1); static_assert(sizeof(SrcAssembly) == 0x5); @@ -211,11 +250,12 @@ namespace SFSE struct TrampolineAssembly { // jmp [rip] - std::uint8_t jmp; // 0 - 0xFF - std::uint8_t modrm; // 1 - 0x25 - std::int32_t disp; // 2 - 0x00000000 - std::uint64_t addr; // 6 - [rip] + std::uint8_t jmp; // 0 - 0xFF + std::uint8_t modrm; // 1 - 0x25 + std::int32_t disp; // 2 - 0x00000000 + std::uint64_t addr; // 6 - [rip] }; + static_assert(offsetof(TrampolineAssembly, jmp) == 0x0); static_assert(offsetof(TrampolineAssembly, modrm) == 0x1); static_assert(offsetof(TrampolineAssembly, disp) == 0x2); @@ -224,41 +264,45 @@ namespace SFSE #pragma pack(pop) TrampolineAssembly* mem = nullptr; - if (const auto it = _5branches.find(a_dst); it != _5branches.end()) { + if (const auto it = _5branches.find(a_dst); it != _5branches.end()) + { mem = reinterpret_cast(it->second); - } else { + } + else + { mem = allocate(); _5branches.emplace(a_dst, reinterpret_cast(mem)); } - const auto disp = - reinterpret_cast(mem) - - reinterpret_cast(a_src + sizeof(SrcAssembly)); - if (!in_range(disp)) { // the trampoline should already be in range, so this should never happen + const auto disp = reinterpret_cast(mem) - reinterpret_cast(a_src + sizeof(SrcAssembly)); + if (!in_range(disp)) + { // the trampoline should already be in range, so this should never happen stl::report_and_fail("displacement is out of range"sv); } SrcAssembly assembly; assembly.opcode = a_opcode; - assembly.disp = static_cast(disp); + assembly.disp = static_cast(disp); REL::safe_write(a_src, &assembly, sizeof(assembly)); - mem->jmp = static_cast(0xFF); + mem->jmp = static_cast(0xFF); mem->modrm = static_cast(0x25); - mem->disp = static_cast(0); - mem->addr = static_cast(a_dst); + mem->disp = static_cast(0); + mem->addr = static_cast(a_dst); } void write_6branch(std::uintptr_t a_src, std::uintptr_t a_dst, std::uint8_t a_modrm) { #pragma pack(push, 1) + struct Assembly { // jmp/call [rip + imm32] - std::uint8_t opcode; // 0 - 0xFF - std::uint8_t modrm; // 1 - 0x25/0x15 - std::int32_t disp; // 2 + std::uint8_t opcode; // 0 - 0xFF + std::uint8_t modrm; // 1 - 0x25/0x15 + std::int32_t disp; // 2 }; + static_assert(offsetof(Assembly, opcode) == 0x0); static_assert(offsetof(Assembly, modrm) == 0x1); static_assert(offsetof(Assembly, disp) == 0x2); @@ -266,24 +310,26 @@ namespace SFSE #pragma pack(pop) std::uintptr_t* mem = nullptr; - if (const auto it = _6branches.find(a_dst); it != _6branches.end()) { + if (const auto it = _6branches.find(a_dst); it != _6branches.end()) + { mem = reinterpret_cast(it->second); - } else { + } + else + { mem = allocate(); _6branches.emplace(a_dst, reinterpret_cast(mem)); } - const auto disp = - reinterpret_cast(mem) - - reinterpret_cast(a_src + sizeof(Assembly)); - if (!in_range(disp)) { // the trampoline should already be in range, so this should never happen + const auto disp = reinterpret_cast(mem) - reinterpret_cast(a_src + sizeof(Assembly)); + if (!in_range(disp)) + { // the trampoline should already be in range, so this should never happen stl::report_and_fail("displacement is out of range"sv); } Assembly assembly; assembly.opcode = static_cast(0xFF); - assembly.modrm = a_modrm; - assembly.disp = static_cast(disp); + assembly.modrm = a_modrm; + assembly.disp = static_cast(disp); REL::safe_write(a_src, &assembly, sizeof(assembly)); *mem = a_dst; @@ -292,15 +338,20 @@ namespace SFSE template [[nodiscard]] std::uintptr_t write_branch(std::uintptr_t a_src, std::uintptr_t a_dst, std::uint8_t a_data) { - const auto disp = reinterpret_cast(a_src + N - 4); + const auto disp = reinterpret_cast(a_src + N - 4); const auto nextOp = a_src + N; - const auto func = nextOp + *disp; + const auto func = nextOp + *disp; - if constexpr (N == 5) { + if constexpr (N == 5) + { write_5branch(a_src, a_dst, a_data); - } else if constexpr (N == 6) { + } + else if constexpr (N == 6) + { write_6branch(a_src, a_dst, a_data); - } else { + } + else + { static_assert(false && N, "invalid branch size"); } @@ -311,17 +362,17 @@ namespace SFSE { _5branches = std::move(a_rhs._5branches); _6branches = std::move(a_rhs._6branches); - _name = std::move(a_rhs._name); + _name = std::move(a_rhs._name); _deleter = std::move(a_rhs._deleter); - _data = a_rhs._data; + _data = a_rhs._data; a_rhs._data = nullptr; - _capacity = a_rhs._capacity; + _capacity = a_rhs._capacity; a_rhs._capacity = 0; - _size = a_rhs._size; + _size = a_rhs._size; a_rhs._size = 0; } @@ -337,15 +388,16 @@ namespace SFSE void release() { - if (_data && _deleter) { + if (_data && _deleter) + { _deleter(_data, _capacity); } _5branches.clear(); _6branches.clear(); - _data = nullptr; + _data = nullptr; _capacity = 0; - _size = 0; + _size = 0; } std::map _5branches; @@ -356,4 +408,4 @@ namespace SFSE std::size_t _capacity{ 0 }; std::size_t _size{ 0 }; }; -} +} // namespace SFSE diff --git a/CommonLibSF/include/SFSE/Version.h b/CommonLibSF/include/SFSE/Version.h index a30c5e10..194048fc 100644 --- a/CommonLibSF/include/SFSE/Version.h +++ b/CommonLibSF/include/SFSE/Version.h @@ -7,4 +7,4 @@ namespace SFSE constexpr auto RUNTIME_LATEST = RUNTIME_SF_1_7_23; constexpr REL::Version SFSE_PACK_LATEST(0, 1, 0, 0); -} +} // namespace SFSE diff --git a/CommonLibSF/src/REL/Relocation.cpp b/CommonLibSF/src/REL/Relocation.cpp index c451776c..3e2c7a40 100644 --- a/CommonLibSF/src/REL/Relocation.cpp +++ b/CommonLibSF/src/REL/Relocation.cpp @@ -4,7 +4,7 @@ #define NOGDICAPMASKS #define NOVIRTUALKEYCODES -//#define NOWINMESSAGES +// #define NOWINMESSAGES #define NOWINSTYLES #define NOSYSMETRICS #define NOMENUS @@ -17,17 +17,17 @@ #define NOATOM #define NOCLIPBOARD #define NOCOLOR -//#define NOCTLMGR +// #define NOCTLMGR #define NODRAWTEXT #define NOGDI #define NOKERNEL -//#define NOUSER +// #define NOUSER #define NONLS -//#define NOMB +// #define NOMB #define NOMEMMGR #define NOMETAFILE #define NOMINMAX -//#define NOMSG +// #define NOMSG #define NOOPENFILE #define NOSCROLL #define NOSERVICE @@ -54,22 +54,20 @@ namespace REL _base = a_base; auto dosHeader = reinterpret_cast(_base); - auto ntHeader = stl::adjust_pointer<::IMAGE_NT_HEADERS64>(dosHeader, dosHeader->e_lfanew); - const auto* sections = IMAGE_FIRST_SECTION(ntHeader); - const auto size = std::min(ntHeader->FileHeader.NumberOfSections, _segments.size()); + auto ntHeader = stl::adjust_pointer<::IMAGE_NT_HEADERS64>(dosHeader, dosHeader->e_lfanew); + const auto* sections = IMAGE_FIRST_SECTION(ntHeader); + const auto size = std::min(ntHeader->FileHeader.NumberOfSections, _segments.size()); - for (std::size_t i = 0; i < size; ++i) { + for (std::size_t i = 0; i < size; ++i) + { const auto& section = sections[i]; - const auto it = std::find_if( - SEGMENTS.begin(), - SEGMENTS.end(), - [&](auto&& a_elem) { - constexpr auto size = std::extent_v; - const auto len = (std::min)(a_elem.first.size(), size); - return std::memcmp(a_elem.first.data(), section.Name, len) == 0 && - (section.Characteristics & a_elem.second) == a_elem.second; - }); - if (it != SEGMENTS.end()) { + const auto it = std::find_if(SEGMENTS.begin(), SEGMENTS.end(), [&](auto&& a_elem) { + constexpr auto size = std::extent_v; + const auto len = (std::min)(a_elem.first.size(), size); + return std::memcmp(a_elem.first.data(), section.Name, len) == 0 && (section.Characteristics & a_elem.second) == a_elem.second; + }); + if (it != SEGMENTS.end()) + { const auto idx = static_cast(std::distance(SEGMENTS.begin(), it)); _segments[idx] = Segment{ _base, _base + section.VirtualAddress, section.Misc.VirtualSize }; } @@ -83,4 +81,4 @@ namespace REL *this = Module(base); } -} +} // namespace REL diff --git a/CommonLibSF/src/SFSE/API.cpp b/CommonLibSF/src/SFSE/API.cpp index 85e17d7d..ba3e0853 100644 --- a/CommonLibSF/src/SFSE/API.cpp +++ b/CommonLibSF/src/SFSE/API.cpp @@ -26,26 +26,27 @@ namespace SFSE bool apiInit{ false }; private: - APIStorage() noexcept = default; + APIStorage() noexcept = default; APIStorage(const APIStorage&) = delete; - APIStorage(APIStorage&&) = delete; + APIStorage(APIStorage&&) = delete; ~APIStorage() noexcept = default; APIStorage& operator=(const APIStorage&) = delete; - APIStorage& operator=(APIStorage&&) = delete; + APIStorage& operator=(APIStorage&&) = delete; }; template T* QueryInterface(const LoadInterface* a_intfc, std::uint32_t a_id) { auto result = static_cast(a_intfc->QueryInterface(a_id)); - if (result && result->Version() > T::kVersion) { + if (result && result->Version() > T::kVersion) + { log::warn("interface definition is out of date"sv); } return result; } - } + } // namespace detail void Init(const LoadInterface* a_intfc) noexcept { @@ -54,18 +55,20 @@ namespace SFSE (void)REL::Module::get(); auto& storage = detail::APIStorage::get(); - const auto& intfc = *a_intfc; + const auto& intfc = *a_intfc; const std::scoped_lock l(storage.apiLock); - if (!storage.apiInit) { + if (!storage.apiInit) + { storage.pluginHandle = intfc.GetPluginHandle(); storage.trampolineInterface = detail::QueryInterface(a_intfc, LoadInterface::kTrampoline); - storage.messagingInterface = detail::QueryInterface(a_intfc, LoadInterface::kMessaging); + storage.messagingInterface = detail::QueryInterface(a_intfc, LoadInterface::kMessaging); storage.apiInit = true; - auto& regs = storage.apiInitRegs; - for (const auto& reg : regs) { + auto& regs = storage.apiInitRegs; + for (const auto& reg : regs) + { reg(); } regs.clear(); @@ -78,7 +81,8 @@ namespace SFSE { auto& storage = detail::APIStorage::get(); const std::scoped_lock l(storage.apiLock); - if (!storage.apiInit) { + if (!storage.apiInit) + { storage.apiInitRegs.push_back(a_fn); return; } @@ -116,10 +120,11 @@ namespace SFSE void AllocTrampoline(std::size_t a_size, bool a_trySFSEReserve) { auto& trampoline = GetTrampoline(); - if (auto intfc = GetTrampolineInterface(); - intfc && a_trySFSEReserve) { + if (auto intfc = GetTrampolineInterface(); intfc && a_trySFSEReserve) + { auto memory = intfc->AllocateFromBranchPool(a_size); - if (memory) { + if (memory) + { trampoline.set_trampoline(memory, a_size); return; } @@ -127,4 +132,4 @@ namespace SFSE trampoline.create(a_size); } -} +} // namespace SFSE diff --git a/CommonLibSF/src/SFSE/IAT.cpp b/CommonLibSF/src/SFSE/IAT.cpp index 9335ef1d..53ebc20f 100644 --- a/CommonLibSF/src/SFSE/IAT.cpp +++ b/CommonLibSF/src/SFSE/IAT.cpp @@ -6,7 +6,7 @@ #define NOGDICAPMASKS #define NOVIRTUALKEYCODES -//#define NOWINMESSAGES +// #define NOWINMESSAGES #define NOWINSTYLES #define NOSYSMETRICS #define NOMENUS @@ -19,17 +19,17 @@ #define NOATOM #define NOCLIPBOARD #define NOCOLOR -//#define NOCTLMGR +// #define NOCTLMGR #define NODRAWTEXT #define NOGDI #define NOKERNEL -//#define NOUSER +// #define NOUSER #define NONLS -//#define NOMB +// #define NOMB #define NOMEMMGR #define NOMETAFILE #define NOMINMAX -//#define NOMSG +// #define NOMSG #define NOOPENFILE #define NOSCROLL #define NOSERVICE @@ -68,31 +68,35 @@ namespace SFSE { assert(a_module); auto dosHeader = static_cast<::IMAGE_DOS_HEADER*>(a_module); - if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { + if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) + { log::error("Invalid DOS header"); return nullptr; } - auto ntHeader = stl::adjust_pointer<::IMAGE_NT_HEADERS>(dosHeader, dosHeader->e_lfanew); - auto& dataDir = ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]; + auto ntHeader = stl::adjust_pointer<::IMAGE_NT_HEADERS>(dosHeader, dosHeader->e_lfanew); + auto& dataDir = ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]; auto importDesc = stl::adjust_pointer<::IMAGE_IMPORT_DESCRIPTOR>(dosHeader, dataDir.VirtualAddress); - for (auto import = importDesc; import->Characteristics != 0; ++import) { + for (auto import = importDesc; import->Characteristics != 0; ++import) + { auto name = stl::adjust_pointer(dosHeader, import->Name); - if (a_dll.size() == strlen(name) && - _strnicmp(a_dll.data(), name, a_dll.size()) != 0) { + if (a_dll.size() == strlen(name) && _strnicmp(a_dll.data(), name, a_dll.size()) != 0) + { continue; } auto thunk = stl::adjust_pointer<::IMAGE_THUNK_DATA>(dosHeader, import->OriginalFirstThunk); - for (std::size_t i = 0; thunk[i].u1.Ordinal; ++i) { - if (IMAGE_SNAP_BY_ORDINAL(thunk[i].u1.Ordinal)) { + for (std::size_t i = 0; thunk[i].u1.Ordinal; ++i) + { + if (IMAGE_SNAP_BY_ORDINAL(thunk[i].u1.Ordinal)) + { continue; } auto importByName = stl::adjust_pointer(dosHeader, thunk[i].u1.AddressOfData); - if (a_function.size() == strlen(importByName->Name) && - _strnicmp(a_function.data(), importByName->Name, a_function.size()) == 0) { + if (a_function.size() == strlen(importByName->Name) && _strnicmp(a_function.data(), importByName->Name, a_function.size()) == 0) + { return stl::adjust_pointer<::IMAGE_THUNK_DATA>(dosHeader, import->FirstThunk) + i; } } @@ -107,13 +111,16 @@ namespace SFSE std::uintptr_t origAddr = 0; auto oldFunc = GetIATAddr(a_dll, a_function); - if (oldFunc) { + if (oldFunc) + { origAddr = *reinterpret_cast(oldFunc); REL::safe_write(oldFunc, a_newFunc); - } else { + } + else + { log::warn("Failed to patch {} ({})", a_dll, a_function); } return origAddr; } -} +} // namespace SFSE diff --git a/CommonLibSF/src/SFSE/Impl/WinAPI.cpp b/CommonLibSF/src/SFSE/Impl/WinAPI.cpp index 2c6ed294..8de828c8 100644 --- a/CommonLibSF/src/SFSE/Impl/WinAPI.cpp +++ b/CommonLibSF/src/SFSE/Impl/WinAPI.cpp @@ -28,138 +28,76 @@ namespace SFSE::WinAPI [[nodiscard]] bool FindClose(void* a_findFile) noexcept { - return static_cast( - ::FindClose(static_cast<::HMODULE>(a_findFile))); + return static_cast(::FindClose(static_cast<::HMODULE>(a_findFile))); } - [[nodiscard]] void* FindFirstFile( - const char* a_fileName, - WIN32_FIND_DATAA* a_findFileData) noexcept + [[nodiscard]] void* FindFirstFile(const char* a_fileName, WIN32_FIND_DATAA* a_findFileData) noexcept { - return static_cast( - ::FindFirstFileA( - static_cast<::LPCSTR>(a_fileName), - reinterpret_cast<::LPWIN32_FIND_DATAA>(a_findFileData))); + return static_cast(::FindFirstFileA(static_cast<::LPCSTR>(a_fileName), reinterpret_cast<::LPWIN32_FIND_DATAA>(a_findFileData))); } - [[nodiscard]] void* FindFirstFile( - const wchar_t* a_fileName, - WIN32_FIND_DATAW* a_findFileData) noexcept + [[nodiscard]] void* FindFirstFile(const wchar_t* a_fileName, WIN32_FIND_DATAW* a_findFileData) noexcept { - return static_cast( - ::FindFirstFileW( - static_cast<::LPCWSTR>(a_fileName), - reinterpret_cast<::LPWIN32_FIND_DATAW>(a_findFileData))); + return static_cast(::FindFirstFileW(static_cast<::LPCWSTR>(a_fileName), reinterpret_cast<::LPWIN32_FIND_DATAW>(a_findFileData))); } - [[nodiscard]] bool FindNextFile( - void* a_findFile, - WIN32_FIND_DATAA* a_findFileData) noexcept + [[nodiscard]] bool FindNextFile(void* a_findFile, WIN32_FIND_DATAA* a_findFileData) noexcept { - return static_cast( - ::FindNextFileA( - static_cast<::HANDLE>(a_findFile), - reinterpret_cast<::LPWIN32_FIND_DATAA>(a_findFileData))); + return static_cast(::FindNextFileA(static_cast<::HANDLE>(a_findFile), reinterpret_cast<::LPWIN32_FIND_DATAA>(a_findFileData))); } - [[nodiscard]] bool FindNextFile( - void* a_findFile, - WIN32_FIND_DATAW* a_findFileData) noexcept + [[nodiscard]] bool FindNextFile(void* a_findFile, WIN32_FIND_DATAW* a_findFileData) noexcept { - return static_cast( - ::FindNextFileW( - static_cast<::HANDLE>(a_findFile), - reinterpret_cast<::LPWIN32_FIND_DATAW>(a_findFileData))); + return static_cast(::FindNextFileW(static_cast<::HANDLE>(a_findFile), reinterpret_cast<::LPWIN32_FIND_DATAW>(a_findFileData))); } void* GetCurrentModule() noexcept { - return static_cast( - std::addressof(__ImageBase)); + return static_cast(std::addressof(__ImageBase)); } void* GetCurrentProcess() noexcept { - return static_cast( - ::GetCurrentProcess()); + return static_cast(::GetCurrentProcess()); } std::uint32_t GetCurrentThreadID() noexcept { - return static_cast( - ::GetCurrentThreadId()); + return static_cast(::GetCurrentThreadId()); } - [[nodiscard]] std::uint32_t GetEnvironmentVariable( - const char* a_name, - char* a_buffer, - std::uint32_t a_size) noexcept + [[nodiscard]] std::uint32_t GetEnvironmentVariable(const char* a_name, char* a_buffer, std::uint32_t a_size) noexcept { return static_cast( - ::GetEnvironmentVariableA( - static_cast<::LPCSTR>(a_name), - static_cast<::LPSTR>(a_buffer), - static_cast<::DWORD>(a_size))); + ::GetEnvironmentVariableA(static_cast<::LPCSTR>(a_name), static_cast<::LPSTR>(a_buffer), static_cast<::DWORD>(a_size))); } - [[nodiscard]] std::uint32_t GetEnvironmentVariable( - const wchar_t* a_name, - wchar_t* a_buffer, - std::uint32_t a_size) noexcept + [[nodiscard]] std::uint32_t GetEnvironmentVariable(const wchar_t* a_name, wchar_t* a_buffer, std::uint32_t a_size) noexcept { return static_cast( - ::GetEnvironmentVariableW( - static_cast<::LPCWSTR>(a_name), - static_cast<::LPWSTR>(a_buffer), - static_cast<::DWORD>(a_size))); + ::GetEnvironmentVariableW(static_cast<::LPCWSTR>(a_name), static_cast<::LPWSTR>(a_buffer), static_cast<::DWORD>(a_size))); } - bool GetFileVersionInfo( - const char* a_filename, - std::uint32_t a_handle, - std::uint32_t a_len, - void* a_data) noexcept + bool GetFileVersionInfo(const char* a_filename, std::uint32_t a_handle, std::uint32_t a_len, void* a_data) noexcept { - return static_cast( - ::GetFileVersionInfoA( - static_cast<::LPCSTR>(a_filename), - static_cast<::DWORD>(a_handle), - static_cast<::DWORD>(a_len), - static_cast<::LPVOID>(a_data))); + return static_cast(::GetFileVersionInfoA(static_cast<::LPCSTR>(a_filename), static_cast<::DWORD>(a_handle), static_cast<::DWORD>(a_len), + static_cast<::LPVOID>(a_data))); } - bool GetFileVersionInfo( - const wchar_t* a_filename, - std::uint32_t a_handle, - std::uint32_t a_len, - void* a_data) noexcept + bool GetFileVersionInfo(const wchar_t* a_filename, std::uint32_t a_handle, std::uint32_t a_len, void* a_data) noexcept { - return static_cast( - ::GetFileVersionInfoW( - static_cast<::LPCWSTR>(a_filename), - static_cast<::DWORD>(a_handle), - static_cast<::DWORD>(a_len), - static_cast<::LPVOID>(a_data))); + return static_cast(::GetFileVersionInfoW(static_cast<::LPCWSTR>(a_filename), static_cast<::DWORD>(a_handle), + static_cast<::DWORD>(a_len), static_cast<::LPVOID>(a_data))); } - std::uint32_t GetFileVersionInfoSize( - const char* a_filename, - std::uint32_t* a_handle) noexcept + std::uint32_t GetFileVersionInfoSize(const char* a_filename, std::uint32_t* a_handle) noexcept { - return static_cast( - ::GetFileVersionInfoSizeA( - static_cast<::LPCSTR>(a_filename), - reinterpret_cast<::LPDWORD>(a_handle))); + return static_cast(::GetFileVersionInfoSizeA(static_cast<::LPCSTR>(a_filename), reinterpret_cast<::LPDWORD>(a_handle))); } - std::uint32_t GetFileVersionInfoSize( - const wchar_t* a_filename, - std::uint32_t* a_handle) noexcept + std::uint32_t GetFileVersionInfoSize(const wchar_t* a_filename, std::uint32_t* a_handle) noexcept { - return static_cast( - ::GetFileVersionInfoSizeW( - static_cast<::LPCWSTR>(a_filename), - reinterpret_cast<::LPDWORD>(a_handle))); + return static_cast(::GetFileVersionInfoSizeW(static_cast<::LPCWSTR>(a_filename), reinterpret_cast<::LPDWORD>(a_handle))); } int GetKeyNameText(std::int32_t a_lParam, wchar_t* a_buffer, int a_size) noexcept @@ -182,98 +120,57 @@ namespace SFSE::WinAPI return static_cast(MAX_PATH); } - std::uint32_t GetModuleFileName( - void* a_module, - char* a_filename, - std::uint32_t a_size) noexcept + std::uint32_t GetModuleFileName(void* a_module, char* a_filename, std::uint32_t a_size) noexcept { return static_cast( - ::GetModuleFileNameA( - static_cast<::HMODULE>(a_module), - static_cast<::LPSTR>(a_filename), - static_cast<::DWORD>(a_size))); + ::GetModuleFileNameA(static_cast<::HMODULE>(a_module), static_cast<::LPSTR>(a_filename), static_cast<::DWORD>(a_size))); } - std::uint32_t GetModuleFileName( - void* a_module, - wchar_t* a_filename, - std::uint32_t a_size) noexcept + std::uint32_t GetModuleFileName(void* a_module, wchar_t* a_filename, std::uint32_t a_size) noexcept { return static_cast( - ::GetModuleFileNameW( - static_cast<::HMODULE>(a_module), - static_cast<::LPWSTR>(a_filename), - static_cast<::DWORD>(a_size))); + ::GetModuleFileNameW(static_cast<::HMODULE>(a_module), static_cast<::LPWSTR>(a_filename), static_cast<::DWORD>(a_size))); } HMODULE GetModuleHandle(const char* a_moduleName) noexcept { - return reinterpret_cast( - ::GetModuleHandleA( - static_cast<::LPCSTR>(a_moduleName))); + return reinterpret_cast(::GetModuleHandleA(static_cast<::LPCSTR>(a_moduleName))); } HMODULE GetModuleHandle(const wchar_t* a_moduleName) noexcept { - return reinterpret_cast( - ::GetModuleHandleW( - static_cast<::LPCWSTR>(a_moduleName))); + return reinterpret_cast(::GetModuleHandleW(static_cast<::LPCWSTR>(a_moduleName))); } - std::uint32_t GetPrivateProfileString( - const char* a_appName, - const char* a_keyName, - const char* a_default, - char* a_outString, - std::uint32_t a_size, - const char* a_fileName) noexcept + std::uint32_t GetPrivateProfileString(const char* a_appName, const char* a_keyName, const char* a_default, char* a_outString, + std::uint32_t a_size, const char* a_fileName) noexcept { - return static_cast( - ::GetPrivateProfileStringA( - static_cast<::LPCSTR>(a_appName), - static_cast<::LPCSTR>(a_keyName), - static_cast<::LPCSTR>(a_default), - static_cast<::LPSTR>(a_outString), - static_cast<::DWORD>(a_size), - static_cast<::LPCSTR>(a_fileName))); - } - - std::uint32_t GetPrivateProfileString( - const wchar_t* a_appName, - const wchar_t* a_keyName, - const wchar_t* a_default, - wchar_t* a_outString, - std::uint32_t a_size, - const wchar_t* a_fileName) noexcept + return static_cast(::GetPrivateProfileStringA(static_cast<::LPCSTR>(a_appName), static_cast<::LPCSTR>(a_keyName), + static_cast<::LPCSTR>(a_default), static_cast<::LPSTR>(a_outString), + static_cast<::DWORD>(a_size), static_cast<::LPCSTR>(a_fileName))); + } + + std::uint32_t GetPrivateProfileString(const wchar_t* a_appName, const wchar_t* a_keyName, const wchar_t* a_default, wchar_t* a_outString, + std::uint32_t a_size, const wchar_t* a_fileName) noexcept { - return static_cast( - ::GetPrivateProfileStringW( - static_cast<::LPCWSTR>(a_appName), - static_cast<::LPCWSTR>(a_keyName), - static_cast<::LPCWSTR>(a_default), - static_cast<::LPWSTR>(a_outString), - static_cast<::DWORD>(a_size), - static_cast<::LPCWSTR>(a_fileName))); + return static_cast(::GetPrivateProfileStringW(static_cast<::LPCWSTR>(a_appName), static_cast<::LPCWSTR>(a_keyName), + static_cast<::LPCWSTR>(a_default), static_cast<::LPWSTR>(a_outString), + static_cast<::DWORD>(a_size), static_cast<::LPCWSTR>(a_fileName))); } - void* GetProcAddress( - void* a_module, - const char* a_procName) noexcept + void* GetProcAddress(void* a_module, const char* a_procName) noexcept { - return reinterpret_cast( - ::GetProcAddress( - static_cast<::HMODULE>(a_module), - static_cast<::LPCSTR>(a_procName))); + return reinterpret_cast(::GetProcAddress(static_cast<::HMODULE>(a_module), static_cast<::LPCSTR>(a_procName))); } - std::string_view GetProcPath( - HMODULE a_handle) noexcept + std::string_view GetProcPath(HMODULE a_handle) noexcept { static std::string fileName(MAX_PATH + 1, ' '); auto res = GetModuleFileName(a_handle, fileName.data(), MAX_PATH + 1); - if (res == 0) { + if (res == 0) + { fileName = "[ProcessHost]"; - res = 13; + res = 13; } return { fileName.c_str(), res }; @@ -281,8 +178,7 @@ namespace SFSE::WinAPI bool IsDebuggerPresent() noexcept { - return static_cast( - ::IsDebuggerPresent()); + return static_cast(::IsDebuggerPresent()); } HMODULE LoadLibrary(const char* a_libFileName) noexcept @@ -295,73 +191,42 @@ namespace SFSE::WinAPI return reinterpret_cast(::LoadLibraryW(static_cast<::LPCWSTR>(a_libFileName))); } - std::int32_t MessageBox( - void* a_wnd, - const char* a_text, - const char* a_caption, - unsigned int a_type) noexcept + std::int32_t MessageBox(void* a_wnd, const char* a_text, const char* a_caption, unsigned int a_type) noexcept { return static_cast( - ::MessageBoxA( - static_cast<::HWND>(a_wnd), - static_cast<::LPCSTR>(a_text), - static_cast<::LPCSTR>(a_caption), - static_cast<::UINT>(a_type))); + ::MessageBoxA(static_cast<::HWND>(a_wnd), static_cast<::LPCSTR>(a_text), static_cast<::LPCSTR>(a_caption), static_cast<::UINT>(a_type))); } - std::int32_t MessageBox( - void* a_wnd, - const wchar_t* a_text, - const wchar_t* a_caption, - unsigned int a_type) noexcept + std::int32_t MessageBox(void* a_wnd, const wchar_t* a_text, const wchar_t* a_caption, unsigned int a_type) noexcept { - return static_cast( - ::MessageBoxW( - static_cast<::HWND>(a_wnd), - static_cast<::LPCWSTR>(a_text), - static_cast<::LPCWSTR>(a_caption), - static_cast<::UINT>(a_type))); + return static_cast(::MessageBoxW(static_cast<::HWND>(a_wnd), static_cast<::LPCWSTR>(a_text), static_cast<::LPCWSTR>(a_caption), + static_cast<::UINT>(a_type))); } - int MultiByteToWideChar( - unsigned int a_codePage, - std::uint32_t a_flags, - const char* a_multiByteStr, - int a_multiByte, - wchar_t* a_wideCharStr, - int a_wideChar) + int MultiByteToWideChar(unsigned int a_codePage, std::uint32_t a_flags, const char* a_multiByteStr, int a_multiByte, wchar_t* a_wideCharStr, + int a_wideChar) { - return ::MultiByteToWideChar( - static_cast<::UINT>(a_codePage), - static_cast<::DWORD>(a_flags), - static_cast<::LPCCH>(a_multiByteStr), - a_multiByte, - static_cast<::LPWSTR>(a_wideCharStr), - a_wideChar); + return ::MultiByteToWideChar(static_cast<::UINT>(a_codePage), static_cast<::DWORD>(a_flags), static_cast<::LPCCH>(a_multiByteStr), + a_multiByte, static_cast<::LPWSTR>(a_wideCharStr), a_wideChar); } - void OutputDebugString( - const char* a_outputString) noexcept + void OutputDebugString(const char* a_outputString) noexcept { - ::OutputDebugStringA( - static_cast<::LPCSTR>(a_outputString)); + ::OutputDebugStringA(static_cast<::LPCSTR>(a_outputString)); } - void OutputDebugString( - const wchar_t* a_outputString) noexcept + void OutputDebugString(const wchar_t* a_outputString) noexcept { - ::OutputDebugStringW( - static_cast<::LPCWSTR>(a_outputString)); + ::OutputDebugStringW(static_cast<::LPCWSTR>(a_outputString)); } - long RegGetValueW(HKEY hkey, const char* subKey, const char* value, unsigned long flags, unsigned long* type, - void* data, unsigned long* length) + long RegGetValueW(HKEY hkey, const char* subKey, const char* value, unsigned long flags, unsigned long* type, void* data, unsigned long* length) { return ::RegGetValueA(reinterpret_cast<::HKEY>(hkey), subKey, value, flags, type, data, length); } - long RegGetValueW(HKEY hkey, const wchar_t* subKey, const wchar_t* value, unsigned long flags, unsigned long* type, - void* data, unsigned long* length) + long RegGetValueW(HKEY hkey, const wchar_t* subKey, const wchar_t* value, unsigned long flags, unsigned long* type, void* data, + unsigned long* length) { return ::RegGetValueW(reinterpret_cast<::HKEY>(hkey), subKey, value, flags, type, data, length); } @@ -371,13 +236,9 @@ namespace SFSE::WinAPI return ::ShowCursor(static_cast<::BOOL>(bShow)); } - void TerminateProcess( - void* a_process, - unsigned int a_exitCode) noexcept + void TerminateProcess(void* a_process, unsigned int a_exitCode) noexcept { - ::TerminateProcess( - static_cast<::HANDLE>(a_process), - static_cast<::UINT>(a_exitCode)); + ::TerminateProcess(static_cast<::HANDLE>(a_process), static_cast<::UINT>(a_exitCode)); #if defined(__clang__) || defined(__GNUC__) __builtin_unreachable(); #elif defined(_MSC_VER) @@ -387,94 +248,43 @@ namespace SFSE::WinAPI void* TlsGetValue(std::uint32_t a_tlsIndex) noexcept { - return static_cast( - ::TlsGetValue( - static_cast<::DWORD>(a_tlsIndex))); - } - - bool TlsSetValue( - std::uint32_t a_tlsIndex, - void* a_tlsValue) noexcept - { - return static_cast( - ::TlsSetValue( - static_cast<::DWORD>(a_tlsIndex), - static_cast<::LPVOID>(a_tlsValue))); - } - - bool VirtualFree( - void* a_address, - std::size_t a_size, - std::uint32_t a_freeType) noexcept - { - return static_cast( - ::VirtualFree( - static_cast<::LPVOID>(a_address), - static_cast<::SIZE_T>(a_size), - static_cast<::DWORD>(a_freeType))); - } - - bool VerQueryValue( - const void* a_block, - const char* a_subBlock, - void** a_buffer, - unsigned int* a_len) noexcept - { - return static_cast( - ::VerQueryValueA( - static_cast<::LPCVOID>(a_block), - static_cast<::LPCSTR>(a_subBlock), - static_cast<::LPVOID*>(a_buffer), - static_cast<::PUINT>(a_len))); - } - - bool VerQueryValue( - const void* a_block, - const wchar_t* a_subBlock, - void** a_buffer, - unsigned int* a_len) noexcept - { - return static_cast( - ::VerQueryValueW( - static_cast<::LPCVOID>(a_block), - static_cast<::LPCWSTR>(a_subBlock), - static_cast<::LPVOID*>(a_buffer), - static_cast<::PUINT>(a_len))); - } - - bool VirtualProtect( - void* a_address, - std::size_t a_size, - std::uint32_t a_newProtect, - std::uint32_t* a_oldProtect) noexcept - { - return static_cast( - ::VirtualProtect( - static_cast<::LPVOID>(a_address), - static_cast<::SIZE_T>(a_size), - static_cast<::DWORD>(a_newProtect), - reinterpret_cast<::PDWORD>(a_oldProtect))); - } - - int WideCharToMultiByte( - unsigned int a_codePage, - std::uint32_t a_flags, - const wchar_t* a_wideCharStr, - int a_wideChar, - char* a_multiByteStr, - int a_multiByte, - const char* a_defaultChar, - int* a_usedDefaultChar) - { - return ::WideCharToMultiByte( - static_cast<::UINT>(a_codePage), - static_cast<::DWORD>(a_flags), - static_cast<::LPCWCH>(a_wideCharStr), - a_wideChar, - static_cast<::LPSTR>(a_multiByteStr), - a_multiByte, - static_cast<::LPCCH>(a_defaultChar), - static_cast<::LPBOOL>(a_usedDefaultChar)); - } - -} + return static_cast(::TlsGetValue(static_cast<::DWORD>(a_tlsIndex))); + } + + bool TlsSetValue(std::uint32_t a_tlsIndex, void* a_tlsValue) noexcept + { + return static_cast(::TlsSetValue(static_cast<::DWORD>(a_tlsIndex), static_cast<::LPVOID>(a_tlsValue))); + } + + bool VirtualFree(void* a_address, std::size_t a_size, std::uint32_t a_freeType) noexcept + { + return static_cast(::VirtualFree(static_cast<::LPVOID>(a_address), static_cast<::SIZE_T>(a_size), static_cast<::DWORD>(a_freeType))); + } + + bool VerQueryValue(const void* a_block, const char* a_subBlock, void** a_buffer, unsigned int* a_len) noexcept + { + return static_cast(::VerQueryValueA(static_cast<::LPCVOID>(a_block), static_cast<::LPCSTR>(a_subBlock), + static_cast<::LPVOID*>(a_buffer), static_cast<::PUINT>(a_len))); + } + + bool VerQueryValue(const void* a_block, const wchar_t* a_subBlock, void** a_buffer, unsigned int* a_len) noexcept + { + return static_cast(::VerQueryValueW(static_cast<::LPCVOID>(a_block), static_cast<::LPCWSTR>(a_subBlock), + static_cast<::LPVOID*>(a_buffer), static_cast<::PUINT>(a_len))); + } + + bool VirtualProtect(void* a_address, std::size_t a_size, std::uint32_t a_newProtect, std::uint32_t* a_oldProtect) noexcept + { + return static_cast(::VirtualProtect(static_cast<::LPVOID>(a_address), static_cast<::SIZE_T>(a_size), static_cast<::DWORD>(a_newProtect), + reinterpret_cast<::PDWORD>(a_oldProtect))); + } + + int WideCharToMultiByte(unsigned int a_codePage, std::uint32_t a_flags, const wchar_t* a_wideCharStr, int a_wideChar, char* a_multiByteStr, + int a_multiByte, const char* a_defaultChar, int* a_usedDefaultChar) + { + return ::WideCharToMultiByte(static_cast<::UINT>(a_codePage), static_cast<::DWORD>(a_flags), static_cast<::LPCWCH>(a_wideCharStr), a_wideChar, + static_cast<::LPSTR>(a_multiByteStr), a_multiByte, static_cast<::LPCCH>(a_defaultChar), + static_cast<::LPBOOL>(a_usedDefaultChar)); + } + +} // namespace SFSE::WinAPI diff --git a/CommonLibSF/src/SFSE/InputMap.cpp b/CommonLibSF/src/SFSE/InputMap.cpp index 703a5346..18d36f38 100644 --- a/CommonLibSF/src/SFSE/InputMap.cpp +++ b/CommonLibSF/src/SFSE/InputMap.cpp @@ -7,7 +7,8 @@ namespace SFSE std::uint32_t InputMap::GamepadMaskToKeycode(std::uint32_t keyMask) { using XInputButton = RE::XInput::XInputButton; - switch (keyMask) { + switch (keyMask) + { case XInputButton::XINPUT_GAMEPAD_DPAD_UP: return kGamepadButtonOffset_DPAD_UP; case XInputButton::XINPUT_GAMEPAD_DPAD_DOWN: @@ -36,12 +37,12 @@ namespace SFSE return kGamepadButtonOffset_X; case XInputButton::XINPUT_GAMEPAD_Y: return kGamepadButtonOffset_Y; - case 0x9: // Left Trigger game-defined ID + case 0x9: // Left Trigger game-defined ID return kGamepadButtonOffset_LT; - case 0xA: // Right Trigger game-defined ID + case 0xA: // Right Trigger game-defined ID return kGamepadButtonOffset_RT; default: - return kMaxMacros; // Invalid + return kMaxMacros; // Invalid } } @@ -49,7 +50,8 @@ namespace SFSE { using XInputButton = RE::XInput::XInputButton; - switch (keyCode) { + switch (keyCode) + { case kGamepadButtonOffset_DPAD_UP: return XInputButton::XINPUT_GAMEPAD_DPAD_UP; case kGamepadButtonOffset_DPAD_DOWN: @@ -79,21 +81,26 @@ namespace SFSE case kGamepadButtonOffset_Y: return XInputButton::XINPUT_GAMEPAD_Y; case kGamepadButtonOffset_LT: - return 0x9; // Left Trigger game-defined ID + return 0x9; // Left Trigger game-defined ID case kGamepadButtonOffset_RT: - return 0xA; // Right Trigger game-defined ID + return 0xA; // Right Trigger game-defined ID default: - return 0xFF; // Invalid + return 0xFF; // Invalid } } std::string InputMap::GetKeyName(std::uint32_t a_keyCode) { - if (a_keyCode >= kMacro_MouseButtonOffset && a_keyCode < kMacro_GamepadOffset) { + if (a_keyCode >= kMacro_MouseButtonOffset && a_keyCode < kMacro_GamepadOffset) + { return GetMouseButtonName(a_keyCode); - } else if (a_keyCode >= kMacro_GamepadOffset && a_keyCode < kMaxMacros) { + } + else if (a_keyCode >= kMacro_GamepadOffset && a_keyCode < kMaxMacros) + { return GetGamepadButtonName(a_keyCode); - } else { + } + else + { return GetKeyboardKeyName(a_keyCode); } } @@ -104,54 +111,56 @@ namespace SFSE using DIKey = RE::DirectInput8::DIKey; - switch (scancode) { - case DIKey::DIK_NUMPADENTER: // Numpad Enter + switch (scancode) + { + case DIKey::DIK_NUMPADENTER: // Numpad Enter scancode = 0x11C; break; - case DIKey::DIK_RCONTROL: // Right Control + case DIKey::DIK_RCONTROL: // Right Control scancode = 0x11D; break; - case DIKey::DIK_DIVIDE: // Numpad / + case DIKey::DIK_DIVIDE: // Numpad / scancode = 0x135; break; - case DIKey::DIK_RALT: // Right Alt + case DIKey::DIK_RALT: // Right Alt scancode = 0x138; break; - case DIKey::DIK_HOME: // Home + case DIKey::DIK_HOME: // Home scancode = 0x147; break; - case DIKey::DIK_UPARROW: // Up Arrow + case DIKey::DIK_UPARROW: // Up Arrow scancode = 0x148; break; - case DIKey::DIK_PGUP: // Page Up + case DIKey::DIK_PGUP: // Page Up scancode = 0x149; break; - case DIKey::DIK_LEFTARROW: // Left Arrow + case DIKey::DIK_LEFTARROW: // Left Arrow scancode = 0x14B; break; - case DIKey::DIK_RIGHTARROW: // Right Arrow + case DIKey::DIK_RIGHTARROW: // Right Arrow scancode = 0x14D; break; - case DIKey::DIK_END: // End + case DIKey::DIK_END: // End scancode = 0x14F; break; - case DIKey::DIK_DOWNARROW: // Down Arrow + case DIKey::DIK_DOWNARROW: // Down Arrow scancode = 0x150; break; - case DIKey::DIK_PGDN: // Page Down + case DIKey::DIK_PGDN: // Page Down scancode = 0x151; break; - case DIKey::DIK_INSERT: // Insert + case DIKey::DIK_INSERT: // Insert scancode = 0x152; break; - case DIKey::DIK_DELETE: // Delete + case DIKey::DIK_DELETE: // Delete scancode = 0x153; break; } std::int32_t lParam = scancode << 16; - if (scancode == 0x45) { + if (scancode == 0x45) + { lParam |= (0x1 << 24); } @@ -164,7 +173,8 @@ namespace SFSE std::string InputMap::GetMouseButtonName(std::uint32_t a_keyCode) { - switch (a_keyCode) { + switch (a_keyCode) + { case 256: return "Left Mouse Button"s; case 257: @@ -192,7 +202,8 @@ namespace SFSE std::string InputMap::GetGamepadButtonName(std::uint32_t a_keyCode) { - switch (a_keyCode) { + switch (a_keyCode) + { case kGamepadButtonOffset_DPAD_UP: return "Gamepad DPad Up"s; case kGamepadButtonOffset_DPAD_DOWN: @@ -229,4 +240,4 @@ namespace SFSE return ""s; } } -} +} // namespace SFSE diff --git a/CommonLibSF/src/SFSE/Interfaces.cpp b/CommonLibSF/src/SFSE/Interfaces.cpp index dee41d65..9b56878e 100644 --- a/CommonLibSF/src/SFSE/Interfaces.cpp +++ b/CommonLibSF/src/SFSE/Interfaces.cpp @@ -10,11 +10,11 @@ namespace SFSE { REL::Version QueryInterface::RuntimeVersion() const { - const auto packed = GetProxy()->runtimeVersion; - const auto major = static_cast((packed & 0xFF000000) >> 24); - const auto minor = static_cast((packed & 0x00FF0000) >> 16); + const auto packed = GetProxy()->runtimeVersion; + const auto major = static_cast((packed & 0xFF000000) >> 24); + const auto minor = static_cast((packed & 0x00FF0000) >> 16); const auto revision = static_cast((packed & 0x0000FFF0) >> 4); - const auto build = static_cast((packed & 0x0000000F) >> 0); + const auto build = static_cast((packed & 0x0000000F) >> 0); return { major, minor, revision, build }; } @@ -52,7 +52,8 @@ namespace SFSE bool MessagingInterface::Dispatch(std::uint32_t a_messageType, void* a_data, std::uint32_t a_dataLen, const char* a_receiver) const { auto result = GetProxy()->Dispatch(GetPluginHandle(), a_messageType, a_data, a_dataLen, a_receiver); - if (!result) { + if (!result) + { log::error("Failed to dispatch message to {}", (a_receiver ? a_receiver : "all listeners")); } return result; @@ -66,7 +67,8 @@ namespace SFSE bool MessagingInterface::RegisterListener(const char* a_sender, EventCallback a_callback) const { auto result = GetProxy()->RegisterListener(GetPluginHandle(), a_sender, std::bit_cast(a_callback)); - if (!result) { + if (!result) + { log::error("Failed to register messaging listener for {}", a_sender); } return result; @@ -98,4 +100,4 @@ namespace SFSE assert(this); return reinterpret_cast(this); } -} +} // namespace SFSE diff --git a/CommonLibSF/src/SFSE/Logger.cpp b/CommonLibSF/src/SFSE/Logger.cpp index 14ace39a..43ad678b 100644 --- a/CommonLibSF/src/SFSE/Logger.cpp +++ b/CommonLibSF/src/SFSE/Logger.cpp @@ -9,10 +9,11 @@ namespace SFSE { std::optional log_directory() { - wchar_t* buffer{ nullptr }; - const auto result = ::SHGetKnownFolderPath(::FOLDERID_Documents, ::KNOWN_FOLDER_FLAG::KF_FLAG_DEFAULT, nullptr, std::addressof(buffer)); + wchar_t* buffer{ nullptr }; + const auto result = ::SHGetKnownFolderPath(::FOLDERID_Documents, ::KNOWN_FOLDER_FLAG::KF_FLAG_DEFAULT, nullptr, std::addressof(buffer)); std::unique_ptr knownPath(buffer, ::CoTaskMemFree); - if (!knownPath || result != S_OK) { + if (!knownPath || result != S_OK) + { error("failed to get known folder path"sv); return std::nullopt; } @@ -21,5 +22,5 @@ namespace SFSE path /= "My Games\\Starfield\\SFSE\\Logs"; return path; } - } -} + } // namespace log +} // namespace SFSE diff --git a/CommonLibSF/src/SFSE/Trampoline.cpp b/CommonLibSF/src/SFSE/Trampoline.cpp index 8adca51c..b7abf942 100644 --- a/CommonLibSF/src/SFSE/Trampoline.cpp +++ b/CommonLibSF/src/SFSE/Trampoline.cpp @@ -6,7 +6,7 @@ #define NOGDICAPMASKS #define NOVIRTUALKEYCODES -//#define NOWINMESSAGES +// #define NOWINMESSAGES #define NOWINSTYLES #define NOSYSMETRICS #define NOMENUS @@ -19,17 +19,17 @@ #define NOATOM #define NOCLIPBOARD #define NOCOLOR -//#define NOCTLMGR +// #define NOCTLMGR #define NODRAWTEXT #define NOGDI #define NOKERNEL -//#define NOUSER +// #define NOUSER #define NONLS -//#define NOMB +// #define NOMB #define NOMEMMGR #define NOMETAFILE #define NOMINMAX -//#define NOMSG +// #define NOMSG #define NOOPENFILE #define NOSCROLL #define NOSERVICE @@ -47,7 +47,7 @@ #include #ifdef SFSE_SUPPORT_XBYAK -# include +#include #endif namespace SFSE @@ -67,7 +67,7 @@ namespace SFSE { constexpr std::size_t gigabyte = static_cast(1) << 30; constexpr std::size_t minRange = gigabyte * 2; - constexpr std::uintptr_t maxAddr = (std::numeric_limits::max)(); + constexpr std::uintptr_t maxAddr = (std::numeric_limits::max)(); ::DWORD granularity; ::SYSTEM_INFO si; @@ -79,24 +79,31 @@ namespace SFSE std::uintptr_t addr; ::MEMORY_BASIC_INFORMATION mbi; - do { - if (!::VirtualQuery(reinterpret_cast(min), std::addressof(mbi), sizeof(mbi))) { + do + { + if (!::VirtualQuery(reinterpret_cast(min), std::addressof(mbi), sizeof(mbi))) + { log::error("VirtualQuery failed with code: 0x{:08X}"sv, ::GetLastError()); return nullptr; } auto baseAddr = reinterpret_cast(mbi.BaseAddress); - min = baseAddr + mbi.RegionSize; + min = baseAddr + mbi.RegionSize; - if (mbi.State == MEM_FREE) { + if (mbi.State == MEM_FREE) + { addr = detail::roundup(baseAddr, granularity); // if rounding didn't advance us into the next region and the region is the required size - if (addr < min && (min - addr) >= a_size) { + if (addr < min && (min - addr) >= a_size) + { auto mem = ::VirtualAlloc(reinterpret_cast(addr), a_size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); - if (mem) { + if (mem) + { return mem; - } else { + } + else + { log::warn("VirtualAlloc failed with code: 0x{:08X}"sv, ::GetLastError()); } } @@ -108,9 +115,7 @@ namespace SFSE void Trampoline::log_stats() const { - auto pct = (static_cast(_size) / - static_cast(_capacity)) * - 100.0; + auto pct = (static_cast(_size) / static_cast(_capacity)) * 100.0; log::debug("{} => {}B / {}B ({:05.2f}%)"sv, _name, _size, _capacity, pct); } -} +} // namespace SFSE diff --git a/CommonLibSF/vcpkg.json b/CommonLibSF/vcpkg.json index df4d7d47..481d98b3 100644 --- a/CommonLibSF/vcpkg.json +++ b/CommonLibSF/vcpkg.json @@ -3,7 +3,7 @@ "name": "commonlibsf", "version-date": "2023-09-07", "port-version": 0, - "description": "CommonLibSF, the collaborative effort with advanced features for modern SFSE development.", + "description": "A collaborative reverse-engineered library for Starfield.", "homepage": "https://github.com/Starfield-Reverse-Engineering/CommonLibSF", "license": "GPL-3.0-or-later", "supports": "windows & x64", @@ -16,4 +16,4 @@ "spdlog", "xbyak" ] -} \ No newline at end of file +} diff --git a/README.md b/README.md index 03199993..dcf8fa40 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ A collaborative reverse-engineered library for Starfield. +[![C++23](https://img.shields.io/static/v1?label=standard&message=c%2B%2B23&color=blue&logo=c%2B%2B&&logoColor=red&style=flat)](https://en.cppreference.com/w/cpp/compiler_support) [![C++23](https://img.shields.io/static/v1?label=standard&message=c%2B%2B23&color=blue&logo=c%2B%2B&&logoColor=red&style=flat)](https://en.cppreference.com/w/cpp/compiler_support) ![Platform](https://img.shields.io/static/v1?label=platform&message=windows&color=dimgray&style=flat&logo=windows) [![Game version](https://img.shields.io/badge/game%20version-1.7.23-orange)](#Get-started) @@ -9,25 +10,31 @@ A collaborative reverse-engineered library for Starfield. [![Main CI](https://img.shields.io/github/actions/workflow/status/Starfield-Reverse-Engineering/CommonLibSF/main_ci.yml)](https://github.com/Starfield-Reverse-Engineering/CommonLibSF/actions/workflows/main_ci.yml) ## Build Dependencies -+ [CMake 3.26+](https://cmake.org/) - + Add this to your PATH -+ [PowerShell](https://github.com/PowerShell/PowerShell/releases/tag/v7.3.6) -+ [Vcpkg](https://github.com/microsoft/vcpkg) - + Add the environment variable VCPKG_ROOT with the value as the path to the folder containing vcpkg -+ [Visual Studio Community 2022](https://visualstudio.microsoft.com/) - + Desktop development with C++ - + *ClangCL toolset and build support if using clang-cl configuration +- [CMake 3.26+](https://cmake.org/) + - Add this to your PATH +- [PowerShell](https://github.com/PowerShell/PowerShell/releases/tag/v7.3.6) +- [Vcpkg](https://github.com/microsoft/vcpkg) + - Add the environment variable VCPKG_ROOT with the value as the path to the folder containing vcpkg +- [Visual Studio Community 2022](https://visualstudio.microsoft.com/) + - Desktop development with C++ + * \*ClangCL toolset and build support if using clang-cl configuration ## Get started + ### use example plugin template + (TODO) ### git submodule & linking in CMake + ```ps git submodule add https://github.com/Starfield-Reverse-Engineering/CommonLibSF.git extern/CommonLibSF git submodule update -f --init ``` + +TODO: vcpkg registry + You should have the following in CMakeLists.txt to compile and link successfully: ```cmake @@ -40,9 +47,11 @@ target_link_libraries( ``` ## End User Dependencies + [Starfield Script Extender](https://www.nexusmods.com/starfield/mods/106) ## Notes + CommonLib is incompatible with SFSE and is intended to replace it as a static dependency. However, you will still need the runtime component. ## License diff --git a/build-clang-cl.bat b/build-clang-cl.bat index 2849e93f..bc72704b 100644 --- a/build-clang-cl.bat +++ b/build-clang-cl.bat @@ -1,4 +1,4 @@ echo off rd /s /q "build" cmake -B "%cd%/build" -S "%cd%/CommonLibSF" --preset=build-release-clang-cl -cmake --build "%cd%/build" --config Release \ No newline at end of file +cmake --build "%cd%/build" --config Release diff --git a/build-msvc.bat b/build-msvc.bat index 7ad761ae..dd6eb25c 100644 --- a/build-msvc.bat +++ b/build-msvc.bat @@ -1,4 +1,4 @@ echo off rd /s /q "build" cmake -B "%cd%/build" -S "%cd%/CommonLibSF" --preset=build-release-msvc -cmake --build "%cd%/build" --config Release \ No newline at end of file +cmake --build "%cd%/build" --config Release diff --git a/make-sln-clang-cl.bat b/make-sln-clang-cl.bat index 8a710e77..2b7fd39f 100644 --- a/make-sln-clang-cl.bat +++ b/make-sln-clang-cl.bat @@ -1,3 +1,3 @@ echo off rd /s /q "build" -cmake -B "%cd%/build" -S "%cd%/CommonLibSF" --preset=solution-clang-cl \ No newline at end of file +cmake -B "%cd%/build" -S "%cd%/CommonLibSF" --preset=solution-clang-cl diff --git a/make-sln-msvc.bat b/make-sln-msvc.bat index deeaf508..8c64818f 100644 --- a/make-sln-msvc.bat +++ b/make-sln-msvc.bat @@ -1,3 +1,3 @@ echo off rd /s /q "build" -cmake -B "%cd%/build" -S "%cd%/CommonLibSF" --preset=solution-msvc \ No newline at end of file +cmake -B "%cd%/build" -S "%cd%/CommonLibSF" --preset=solution-msvc