From bf58060a55075d03d93b4c5fe6e50279cb56cd36 Mon Sep 17 00:00:00 2001 From: Angad <66992519+ThirdEyeSqueegee@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:41:35 -0700 Subject: [PATCH] Updates --- .clang-format | 155 +++---------------- .github/workflows/clang-format.yml | 35 +++++ .github/workflows/prettier.yml | 31 ++++ .github/workflows/testbuild.yml | 37 +++++ CMakeLists.txt | 157 +++++++++++-------- CMakePresets.json | 18 +-- EXCEPTIONS | 15 ++ include/ENBAPI.h | 31 ++-- include/GammaController.h | 2 +- include/Hooks.h | 2 +- include/Logging.h | 2 +- include/PCH.h | 234 +++++++++++++++++------------ include/Settings.h | 2 +- src/GammaController.cpp | 83 ++++------ src/Hooks.cpp | 2 +- src/Logging.cpp | 4 +- src/Main.cpp | 5 +- src/Settings.cpp | 5 +- vcpkg.json | 8 +- 19 files changed, 432 insertions(+), 396 deletions(-) create mode 100644 .github/workflows/clang-format.yml create mode 100644 .github/workflows/prettier.yml create mode 100644 .github/workflows/testbuild.yml create mode 100644 EXCEPTIONS diff --git a/.clang-format b/.clang-format index 3c4e405..3706bd0 100644 --- a/.clang-format +++ b/.clang-format @@ -1,8 +1,7 @@ --- -BasedOnStyle: Microsoft -AccessModifierOffset: -4 +BasedOnStyle: WebKit AlignAfterOpenBracket: Align -AlignArrayOfStructures: None +AlignArrayOfStructures: Right AlignConsecutiveAssignments: Enabled: true AcrossEmptyLines: false @@ -27,118 +26,49 @@ AlignConsecutiveMacros: AcrossComments: false AlignCompound: false PadOperators: false -AlignEscapedNewlines: Left AlignOperands: Align AlignTrailingComments: Kind: Always OverEmptyLines: 0 -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: Empty -AllowShortCaseLabelsOnASingleLine: false AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortIfStatementsOnASingleLine: Never -AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false +AllowShortFunctionsOnASingleLine: Inline AlwaysBreakTemplateDeclarations: Yes AttributeMacros: - __declspec + - __cdecl + - __stdcall + - __fastcall - __try - __except - __assume - - __cdecl -BinPackArguments: true -BinPackParameters: true -BitFieldColonSpacing: Both BraceWrapping: AfterCaseLabel: false AfterClass: true - AfterControlStatement: Always + AfterControlStatement: MultiLine AfterEnum: true + AfterExternBlock: true AfterFunction: true AfterNamespace: true AfterObjCDeclaration: true AfterStruct: true - AfterUnion: false - AfterExternBlock: true + AfterUnion: 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 + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true BreakBeforeBraces: Custom -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 -DerivePointerAlignment: false -DisableFormat: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock -ExperimentalAutoDetectBinPacking: false +ColumnLimit: 180 FixNamespaceComments: true -IncludeBlocks: Preserve -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: 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 LineEnding: CRLF -MacroBlockBegin: "" -MacroBlockEnd: "" MaxEmptyLinesToKeep: 1 NamespaceIndentation: All -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PPIndentWidth: -1 -PackConstructorInitializers: BinPack PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakComment: 300 @@ -148,63 +78,20 @@ PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 PenaltyIndentedWhitespace: 0 -PenaltyReturnTypeOnItsOwnLine: 1000 -PointerAlignment: Left +PenaltyReturnTypeOnItsOwnLine: 60 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 -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 -UseTab: Never QualifierOrder: - inline - static - constexpr - const - volatile - - friend - restrict + - friend - type +SeparateDefinitionBlocks: Always +SpaceBeforeCpp11BracedList: false +SpaceInEmptyBlock: false +TabWidth: 4 +UseTab: Never +--- diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 0000000..affa2a0 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,35 @@ +name: clang-format + +on: + push: + branches: main + paths: + - "include/**" + - "src/**" + - ".clang-format" + workflow_dispatch: + +permissions: write-all + +jobs: + clang-format: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run clang-format + uses: DoozyX/clang-format-lint-action@v0.16.2 + with: + source: "." + extensions: "h,cpp" + clangFormatVersion: 16 + inplace: true + + - name: Add & Commit + uses: EndBug/add-and-commit@v9.1.3 + with: + message: "ci: formatting" + default_author: github_actions + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml new file mode 100644 index 0000000..e432fd9 --- /dev/null +++ b/.github/workflows/prettier.yml @@ -0,0 +1,31 @@ +name: Prettier + +on: + push: + branches: main + paths: + - "**.json" + - "**.yml" + workflow_dispatch: + +permissions: write-all + +jobs: + prettier: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run Prettier + uses: actionsx/prettier@v3 + with: + args: --write "**.json" "**.yml" + + - name: Add & Commit + uses: EndBug/add-and-commit@v9.1.3 + with: + message: "ci: formatting" + default_author: github_actions + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/testbuild.yml b/.github/workflows/testbuild.yml new file mode 100644 index 0000000..9ac0484 --- /dev/null +++ b/.github/workflows/testbuild.yml @@ -0,0 +1,37 @@ +name: Test Build + +on: + workflow_run: + workflows: clang-format + types: completed + workflow_dispatch: + +env: + VCPKG_COMMIT_ID: e44d60e6bf0964064bf69667cd9f3e91dc383c7c + +jobs: + test-build: + runs-on: windows-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + strategy: + matrix: + preset: + - debug + - release + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get CMake + uses: lukka/get-cmake@latest + + - name: Setup vcpkg + uses: lukka/run-vcpkg@v11.1 + with: + vcpkgGitCommitId: ${{ env.VCPKG_COMMIT_ID }} + + - name: Run CMake + uses: lukka/run-cmake@v10.6 + with: + configurePreset: build-${{ matrix.preset }}-msvc + buildPreset: ${{ matrix.preset }}-msvc diff --git a/CMakeLists.txt b/CMakeLists.txt index c81e4b0..353acca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,99 +5,130 @@ message("Using toolchain file ${CMAKE_TOOLCHAIN_FILE}.") ## Define project ######################################################################################################################## project( - DynamicGamma - VERSION 1.0.11 - LANGUAGES CXX) + DynamicGamma + VERSION 1.0.12 + LANGUAGES CXX +) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) - -message("\nCMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") -message("CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}") - -message("\nCMAKE_CXX_FLAGS_RELWITHDEBINFO: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") -message("CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO: ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}") - -message("\nCMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}") -message("CMAKE_SHARED_LINKER_FLAGS_DEBUG: ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF) include(GNUInstallDirs) configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in - ${CMAKE_CURRENT_BINARY_DIR}/version.rc - @ONLY) + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in + ${CMAKE_CURRENT_BINARY_DIR}/version.rc + @ONLY +) set(PUBLIC_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}") -set(headers - include/Settings.h - include/ENBAPI.h) -set(sources - src/Logging.cpp - src/Main.cpp - src/Hooks.cpp - src/Settings.cpp - src/GammaController.cpp +set( + headers + include/Settings.h + include/ENBAPI.h +) - ${CMAKE_CURRENT_BINARY_DIR}/version.rc) +set( + sources + src/Logging.cpp + src/Main.cpp + src/Hooks.cpp + src/Settings.cpp + src/GammaController.cpp + + ${CMAKE_CURRENT_BINARY_DIR}/version.rc +) source_group( - TREE ${CMAKE_CURRENT_SOURCE_DIR} - FILES - ${headers} - ${sources}) + TREE ${CMAKE_CURRENT_SOURCE_DIR} + FILES ${headers} ${sources} +) ######################################################################################################################## ## Configure target DLL ######################################################################################################################## find_package(CommonLibSSE CONFIG REQUIRED) -add_commonlibsse_plugin(${PROJECT_NAME} AUTHOR ThirdEyeSqueegee SOURCES ${headers} ${sources}) +add_commonlibsse_plugin( + ${PROJECT_NAME} + AUTHOR ThirdEyeSqueegee + SOURCES ${headers} ${sources} +) add_library("${PROJECT_NAME}::${PROJECT_NAME}" ALIAS "${PROJECT_NAME}") find_path(SIMPLEINI_INCLUDE_DIRS "SimpleIni.h") -target_include_directories(${PROJECT_NAME} - PRIVATE - $ - $ - $ - ${SIMPLEINI_INCLUDE_DIRS}) - -target_include_directories(${PROJECT_NAME} - PUBLIC - $) - -target_precompile_headers(${PROJECT_NAME} - PRIVATE - include/PCH.h - ${SIMPLEINI_INCLUDE_DIRS}/SimpleIni.h) - -install(DIRECTORY "${PUBLIC_HEADER_DIR}" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") - -install(TARGETS ${PROJECT_NAME} - DESTINATION "${CMAKE_INSTALL_LIBDIR}") +target_include_directories( + ${PROJECT_NAME} + PRIVATE + $ + $ + $ + ${SIMPLEINI_INCLUDE_DIRS} +) + +target_include_directories( + ${PROJECT_NAME} + PUBLIC + $ +) + +target_precompile_headers( + ${PROJECT_NAME} + PRIVATE + include/PCH.h + ${SIMPLEINI_INCLUDE_DIRS}/SimpleIni.h +) + +install( + DIRECTORY "${PUBLIC_HEADER_DIR}" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" +) + +install( + TARGETS ${PROJECT_NAME} + DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) ######################################################################################################################## ## Automatic plugin deployment ######################################################################################################################## if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(BUILD_NAME "Debug") + set(BUILD_NAME "Debug") else() - set(BUILD_NAME "Release") + set(BUILD_NAME "Release") endif() -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Plugin${BUILD_NAME}/skse/plugins") -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Plugin${BUILD_NAME}/skse/plugins") -add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Plugin${BUILD_NAME}/skse/plugins") +add_custom_command( + TARGET ${PROJECT_NAME} + POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Plugin${BUILD_NAME}/skse/plugins" +) +add_custom_command( + TARGET ${PROJECT_NAME} + POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Plugin${BUILD_NAME}/skse/plugins" +) +add_custom_command( + TARGET ${PROJECT_NAME} + POST_BUILD + COMMAND + ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}/contrib/Plugin${BUILD_NAME}/skse/plugins" +) + file(GLOB_RECURSE OUTPUT_DLLS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/**/*.dll") file(GLOB_RECURSE OUTPUT_PDBS "${CMAKE_CURRENT_SOURCE_DIR}/contrib/**/*.pdb") -set_property(TARGET ${PROJECT_NAME} - APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${OUTPUT_DLLS}") -set_property(TARGET ${PROJECT_NAME} - APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${OUTPUT_PDBS}") + +set_property( + TARGET ${PROJECT_NAME} + APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${OUTPUT_DLLS}" +) +set_property( + TARGET ${PROJECT_NAME} + APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${OUTPUT_PDBS}" +) diff --git a/CMakePresets.json b/CMakePresets.json index e3976e3..c316626 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -10,8 +10,9 @@ "name": "base", "hidden": true, "cacheVariables": { - "CMAKE_CXX_FLAGS": "$env{COMMONLIBSSE_COMPILER} $env{COMMONLIBSSE_PLATFORM} $env{COMMONLIBSSE_TEXT}", - "CMAKE_SHARED_LINKER_FLAGS": "$env{COMMONLIBSSE_LINKER}" + "CMAKE_CXX_FLAGS": "$env{COMMONLIBSSE_COMPILER} $env{COMMONLIBSSE_PLATFORM} $env{COMMONLIBSSE_TEXT} $penv{CXXFLAGS}", + "CMAKE_SHARED_LINKER_FLAGS": "$env{COMMONLIBSSE_LINKER}", + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$:Debug>DLL" } }, { @@ -54,13 +55,12 @@ "cmakeExecutable": "C:/Program Files/CMake/bin/", "environment": { "COMMONLIBSSE_COMPILER": "/cgthreads8 /diagnostics:caret /EHsc /fp:contract /fp:except- /guard:cf- /MP /permissive- /sdl /W4 /Zc:__cplusplus /Zc:enumTypes /Zc:lambda /Zc:preprocessor /Zc:referenceBinding /Zc:rvalueCast /Zc:templateScope /Zc:ternary", - "COMMONLIBSSE_LINKER": "/CGTHREADS:8 /MACHINE:x64" + "COMMONLIBSSE_LINKER": "/CGTHREADS:8 /MACHINE:x64 /DEBUG:FULL" }, "cacheVariables": { - "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "/fp:fast /GL /GR- /Gw /O2 /Ob3 /Qpar /Qpar-report:2 /Qvec-report:2", - "CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO": "/DEBUG:FULL /LTCG:INCREMENTAL /OPT:REF,ICF=4", - "CMAKE_CXX_FLAGS_DEBUG": "/Od /MDd", - "CMAKE_SHARED_LINKER_FLAGS_DEBUG": "/DEBUG:FULL /LTCG:INCREMENTAL /DEBUGTYPE:FIXUP" + "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "/fp:fast /GR- /Gw /O2 /Ob3 /Qpar", + "CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO": "/LTCG:INCREMENTAL /OPT:REF,ICF=4", + "CMAKE_SHARED_LINKER_FLAGS_DEBUG": "/DEBUGTYPE:FIXUP" }, "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { @@ -72,7 +72,7 @@ }, { "name": "build-release-msvc", - "inherits": [ "base", "vcpkg", "win32-unicode", "x64", "msvc" ], + "inherits": ["base", "vcpkg", "win32-unicode", "x64", "msvc"], "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo" }, @@ -82,7 +82,7 @@ }, { "name": "build-debug-msvc", - "inherits": [ "base", "vcpkg", "win32-unicode", "x64", "msvc" ], + "inherits": ["base", "vcpkg", "win32-unicode", "x64", "msvc"], "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }, diff --git a/EXCEPTIONS b/EXCEPTIONS new file mode 100644 index 0000000..f8abaf0 --- /dev/null +++ b/EXCEPTIONS @@ -0,0 +1,15 @@ +This Program is intended to be used with and to modify existing code (the "Modded Code"). The purpose of this exception is to address issues when an open source modding community interacts with potentially proprietary code. In addition, the modding community often uses libraries (the "Modding Libraries") under licenses that may be incompatible with the GPL ("Modding Library Licenses"). + +=== + +Modding Exception + +As an exception, the author gives You the additional right to link the code of this Program with the existing code that this Program is intended to be used with or modify and to distribute linked combinations including the two, subject to the limitations in this paragraph. Modded Code permitted under this exception may link to the code of this Program without causing the Modded Code and portion of the combined work corresponding to the Modded Code to be covered by the GNU General Public License. You must obey the GNU General Public License in all respects for all of the Program code and other code used in conjunction with the Program except the Modded Code covered by this exception. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to provide this exception without modification, you must delete this exception statement from your version and license this file solely under the GPL without exception. + +=== + +GPL-3.0 Linking Exception (with Corresponding Source) + +Additional permission under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or combining it with Modding Libraries (or a modified version thereof), containing parts covered by the terms of Modding Library Licenses, the licensors of this Program grant you additional permission to convey the resulting work. Corresponding Source for a non-source form of such a combination shall include the source code for the parts of Modding Libraries used as well as that of the covered work. diff --git a/include/ENBAPI.h b/include/ENBAPI.h index 3a2e87e..a067c22 100644 --- a/include/ENBAPI.h +++ b/include/ENBAPI.h @@ -45,11 +45,11 @@ class ENBRenderInfo }; using ENBSDKVersion = long (*)(); -using ENBVersion = long (*)(); +using ENBVersion = long (*)(); using ENBCallback = void(WINAPI*)(ENBCallbackType a_callback_type); -using ENBSetCallback = void (*)(ENBCallback a_callback_func); -using ENBGetParameter = BOOL (*)(const char* a_filename, const char* a_category, const char* a_keyname, ENBParameter* a_out); -using ENBSetParameter = BOOL (*)(const char* a_filename, const char* a_category, const char* a_keyname, ENBParameter* a_in); +using ENBSetCallback = void (*)(ENBCallback a_callback_func); +using ENBGetParameter = BOOL (*)(const char* a_filename, const char* a_category, const char* a_keyname, ENBParameter* a_out); +using ENBSetParameter = BOOL (*)(const char* a_filename, const char* a_category, const char* a_keyname, ENBParameter* a_in); using ENBGetRenderInfo = ENBRenderInfo* (*)(); class ENBAPI : public Singleton @@ -64,46 +64,37 @@ class ENBAPI : public Singleton inline static ENBSetParameter set_enb_param{}; inline static ENBGetRenderInfo get_enb_render_info{}; - static void FindD3D11() - { - d3d11_handle = GetModuleHandle(L"d3d11"); - } + static void FindD3D11() { d3d11_handle = GetModuleHandle(L"d3d11"); } static void LinkENBFunctions() { bool found1{}, found2{}, found3{}, found4{}, found5{}, found6{}; - if (const auto handle1{ GetProcAddress(d3d11_handle, "ENBGetSDKVersion") }) - { + if (const auto handle1{ GetProcAddress(d3d11_handle, "ENBGetSDKVersion") }) { logger::info("Linked ENBGetSDKVersion"); get_enb_sdk_version = reinterpret_cast(handle1); found1 = true; } - if (const auto handle2{ GetProcAddress(d3d11_handle, "ENBGetVersion") }) - { + if (const auto handle2{ GetProcAddress(d3d11_handle, "ENBGetVersion") }) { logger::info("Linked ENBGetVersion"); get_enb_version = reinterpret_cast(handle2); found2 = true; } - if (const auto handle3{ GetProcAddress(d3d11_handle, "ENBSetCallbackFunction") }) - { + if (const auto handle3{ GetProcAddress(d3d11_handle, "ENBSetCallbackFunction") }) { logger::info("Linked ENBSetCallbackFunction"); set_enb_callback = reinterpret_cast(handle3); found3 = true; } - if (const auto handle4{ GetProcAddress(d3d11_handle, "ENBGetParameter") }) - { + if (const auto handle4{ GetProcAddress(d3d11_handle, "ENBGetParameter") }) { logger::info("Linked ENBGetParameter"); get_enb_param = reinterpret_cast(handle4); found4 = true; } - if (const auto handle5{ GetProcAddress(d3d11_handle, "ENBSetParameter") }) - { + if (const auto handle5{ GetProcAddress(d3d11_handle, "ENBSetParameter") }) { logger::info("Linked ENBSetParameter"); set_enb_param = reinterpret_cast(handle5); found5 = true; } - if (const auto handle6{ GetProcAddress(d3d11_handle, "ENBGetRenderInfo") }) - { + if (const auto handle6{ GetProcAddress(d3d11_handle, "ENBGetRenderInfo") }) { logger::info("Linked ENBGetRenderInfo"); get_enb_render_info = reinterpret_cast(handle6); found6 = true; diff --git a/include/GammaController.h b/include/GammaController.h index a25376e..397cea2 100644 --- a/include/GammaController.h +++ b/include/GammaController.h @@ -5,7 +5,7 @@ class GammaController : public Singleton { public: - static void Init(); + static void Init() noexcept; static std::int32_t Thunk(); diff --git a/include/Hooks.h b/include/Hooks.h index ef47450..1e7dea2 100644 --- a/include/Hooks.h +++ b/include/Hooks.h @@ -2,5 +2,5 @@ namespace Hooks { - void Install(); + void Install() noexcept; } diff --git a/include/Logging.h b/include/Logging.h index 4bf0341..8b94908 100644 --- a/include/Logging.h +++ b/include/Logging.h @@ -1,3 +1,3 @@ #pragma once -void InitializeLogging(); +void InitializeLogging() noexcept; diff --git a/include/PCH.h b/include/PCH.h index 35d8cc8..200935f 100644 --- a/include/PCH.h +++ b/include/PCH.h @@ -1,104 +1,148 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include +/* +++++++++++++++++++++++++ C++23 Standard Library +++++++++++++++++++++++++ */ + +// Concepts library +#include + +// Utilities library +#include +#include +#include +#include #include #include #include #include -#include -#include #include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Dynamic memory management +#include +#include +#include +#include + +// Numeric limits +#include +#include +#include +#include +#include +#include + +// Error handling +#include +#include +#include +#include +#include +#include + +// Strings library +#include +#include +#include #include #include #include +#include +#include -#include -#include +// Containers library #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Iterators library +#include + +// Ranges library +#include + +// Algorithms library +#include +#include + +// Numerics library +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Localization library +#include +#include + +// Input/output library +#include #include -#include -#include -#include #include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include -#include -#include #include -#include -#include +#include #include -#include + +// Filesystem library +#include + +// Regular Expressions library +#include + +// Atomic Operations library +#include + +// Thread support library +#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ + +// clang-format off #include #include #include -// clang-format off #include #include #include @@ -116,8 +160,8 @@ template class Singleton { protected: - constexpr Singleton() = default; - constexpr ~Singleton() = default; + constexpr Singleton() noexcept = default; + constexpr ~Singleton() noexcept = default; public: constexpr Singleton(const Singleton&) = delete; @@ -125,7 +169,7 @@ class Singleton constexpr auto operator=(const Singleton&) = delete; constexpr auto operator=(Singleton&&) = delete; - static T* GetSingleton() + [[nodiscard]] static constexpr T* GetSingleton() noexcept { static T singleton; return std::addressof(singleton); @@ -136,8 +180,8 @@ template class EventSingleton : public RE::BSTEventSink { protected: - constexpr EventSingleton() = default; - constexpr ~EventSingleton() override = default; + constexpr EventSingleton() noexcept = default; + constexpr ~EventSingleton() noexcept override = default; public: constexpr EventSingleton(const EventSingleton&) = delete; @@ -145,66 +189,58 @@ class EventSingleton : public RE::BSTEventSink constexpr auto operator=(const EventSingleton&) = delete; constexpr auto operator=(EventSingleton&&) = delete; - static TDerived* GetSingleton() + [[nodiscard]] static constexpr TDerived* GetSingleton() noexcept { static TDerived singleton; return std::addressof(singleton); } - static void Register() + static constexpr void Register() noexcept { using TEventSource = RE::BSTEventSource; - auto name{ std::string(typeid(TEvent).name()) }; - const std::regex p{ "struct |RE::|SKSE::| * __ptr64" }; - name = std::regex_replace(name, p, ""); + const std::string dirty_name{ typeid(TEvent).name() }; + const std::regex p{ "struct |RE::|SKSE::| * __ptr64" }; + const auto name{ std::regex_replace(dirty_name, p, "") }; - if constexpr (std::is_base_of_v) - { + if constexpr (std::is_base_of_v) { const auto manager{ RE::BSInputDeviceManager::GetSingleton() }; manager->AddEventSink(GetSingleton()); logger::info("Registered {} handler", name); return; } - else if constexpr (std::is_base_of_v) - { + else if constexpr (std::is_base_of_v) { const auto ui{ RE::UI::GetSingleton() }; ui->AddEventSink(GetSingleton()); logger::info("Registered {} handler", name); return; } - else if constexpr (std::is_same_v) - { + else if constexpr (std::is_same_v) { SKSE::GetActionEventSource()->AddEventSink(GetSingleton()); logger::info("Registered {} handler", name); return; } - else if constexpr (std::is_same_v) - { + else if constexpr (std::is_same_v) { SKSE::GetCameraEventSource()->AddEventSink(GetSingleton()); logger::info("Registered {} handler", name); return; } - else if constexpr (std::is_same_v) - { + else if constexpr (std::is_same_v) { SKSE::GetCrosshairRefEventSource()->AddEventSink(GetSingleton()); logger::info("Registered {} handler", name); return; } - else if constexpr (std::is_same_v) - { + else if constexpr (std::is_same_v) { SKSE::GetModCallbackEventSource()->AddEventSink(GetSingleton()); logger::info("Registered {} handler", name); return; } - else if constexpr (std::is_same_v) - { + else if constexpr (std::is_same_v) { SKSE::GetNiNodeUpdateEventSource()->AddEventSink(GetSingleton()); logger::info("Registered {} handler", name); return; } - else if constexpr (std::is_base_of_v) - { + else if constexpr (std::is_base_of_v) { const auto holder{ RE::ScriptEventSourceHolder::GetSingleton() }; holder->AddEventSink(GetSingleton()); logger::info("Registered {} handler", name); @@ -220,7 +256,7 @@ namespace stl using namespace SKSE::stl; template - void write_thunk_call() + constexpr auto write_thunk_call() noexcept { SKSE::AllocTrampoline(14); auto& trampoline{ SKSE::GetTrampoline() }; @@ -228,14 +264,14 @@ namespace stl } template - void write_vfunc() + constexpr auto write_vfunc() noexcept { REL::Relocation vtbl{ TDest::VTABLE[0] }; TSource::func = vtbl.write_vfunc(TSource::idx, TSource::Thunk); } template - void write_vfunc(const REL::VariantID variant_id) + constexpr auto write_vfunc(const REL::VariantID variant_id) noexcept { REL::Relocation vtbl{ variant_id }; T::func = vtbl.write_vfunc(T::idx, T::Thunk); diff --git a/include/Settings.h b/include/Settings.h index 3b886cb..bb43080 100644 --- a/include/Settings.h +++ b/include/Settings.h @@ -3,7 +3,7 @@ class Settings : public Singleton { public: - static void LoadSettings(); + static void LoadSettings() noexcept; inline static bool debug_logging{}; diff --git a/src/GammaController.cpp b/src/GammaController.cpp index c4757d7..862ee39 100644 --- a/src/GammaController.cpp +++ b/src/GammaController.cpp @@ -7,7 +7,7 @@ constexpr auto map_menu{ RE::MapMenu::MENU_NAME }; constexpr auto mist_menu{ RE::MistMenu::MENU_NAME }; constexpr auto loading_menu{ RE::LoadingMenu::MENU_NAME }; -void GammaController::Init() +void GammaController::Init() noexcept { const auto ini_settings{ RE::INIPrefSettingCollection::GetSingleton() }; gamma_setting = ini_settings->GetSetting("fGamma:Display"sv); @@ -20,8 +20,7 @@ void GammaController::Init() control_global->value = 1.0f; control_global->SetFormEditorID("gammaglobal"); - if (const auto& [map, map_lock]{ RE::TESForm::GetAllFormsByEditorID() }; map) - { + if (const auto& [map, map_lock]{ RE::TESForm::GetAllFormsByEditorID() }; map) { const RE::BSReadLockGuard guard{ map_lock }; map->emplace(control_global->GetFormEditorID(), control_global); } @@ -32,12 +31,10 @@ void GammaController::Init() logger::info("Cached global {} with value {}", control_global->GetFormEditorID(), control_global->value); ENBAPI::FindD3D11(); - if (ENBAPI::d3d11_handle) - { + if (ENBAPI::d3d11_handle) { logger::info("Found d3d11.dll. Attempting to link ENB functions..."); ENBAPI::LinkENBFunctions(); - if (ENBAPI::linked_enb_functions) - { + if (ENBAPI::linked_enb_functions) { logger::info("Linked ENB functions"); const auto version{ ENBAPI::get_enb_version() }; logger::info("Current ENB version: v0.{}", version); @@ -65,12 +62,9 @@ std::int32_t GammaController::Thunk() frame_counter = 0; const auto current_gamma{ gamma_setting->GetFloat() }; - if (const auto ui{ RE::UI::GetSingleton() }) - { - if (ui->IsMenuOpen(main_menu) || ui->IsMenuOpen(map_menu) || ui->IsMenuOpen(mist_menu) || ui->IsMenuOpen(loading_menu)) - { - if (current_gamma <=> original_gamma != 0) - { + if (const auto ui{ RE::UI::GetSingleton() }) { + if (ui->IsMenuOpen(main_menu) || ui->IsMenuOpen(map_menu) || ui->IsMenuOpen(mist_menu) || ui->IsMenuOpen(loading_menu)) { + if (current_gamma <=> original_gamma != 0) { logger::debug("Open menu detected, resetting gamma"); const RE::BSReadLockGuard guard{ lock }; gamma_setting->data.f = original_gamma; @@ -78,30 +72,24 @@ std::int32_t GammaController::Thunk() return result; } } - if (control_global->value <=> 0.0f == 0) - { - if (current_gamma <=> original_gamma != 0) - { + if (control_global->value <=> 0.0f == 0) { + if (current_gamma <=> original_gamma != 0) { logger::debug("Global set to 0, resetting gamma"); const RE::BSReadLockGuard guard{ lock }; gamma_setting->data.f = original_gamma; } return result; } - if (const auto calendar{ RE::Calendar::GetSingleton() }) - { - if (const auto player{ RE::PlayerCharacter::GetSingleton() }) - { + if (const auto calendar{ RE::Calendar::GetSingleton() }) { + if (const auto player{ RE::PlayerCharacter::GetSingleton() }) { const auto game_hour{ calendar->GetHour() }; auto trunc_time{ std::floor(game_hour * 100) / 100 }; logger::debug("Current time: {:.2f}", trunc_time); logger::debug("Current gamma: {:.2f}", current_gamma); const auto* map{ &Settings::exterior_map }; - if (const auto parent_cell{ player->GetParentCell() }) - { - if (parent_cell->IsInteriorCell()) - { + if (const auto parent_cell{ player->GetParentCell() }) { + if (parent_cell->IsInteriorCell()) { logger::debug("Player is in interior cell {}", parent_cell->GetName()); map = &Settings::interior_map; } @@ -109,22 +97,21 @@ std::int32_t GammaController::Thunk() else logger::debug("Player is in exterior cell"); - if (!map->contains(trunc_time)) - { + if (!map->contains(trunc_time)) { logger::debug("{:.2f} not found in map, truncating...", trunc_time); trunc_time = std::floor(game_hour * 10) / 10; logger::debug("New trunc time: {:.2f}", trunc_time); - if (!map->contains(trunc_time)) - { + if (!map->contains(trunc_time)) { logger::debug("{:.2f} not found in map, truncating...", trunc_time); trunc_time = std::floor(trunc_time); logger::debug("New trunc time: {:.2f}", trunc_time); } } - if (const auto new_gamma{ map->at(trunc_time) }; current_gamma <=> new_gamma != 0) - { - const RE::BSReadLockGuard guard{ lock }; - gamma_setting->data.f = new_gamma; + if (map->contains(trunc_time)) { + if (const auto new_gamma{ map->at(trunc_time) }; current_gamma <=> new_gamma != 0) { + const RE::BSReadLockGuard guard{ lock }; + gamma_setting->data.f = new_gamma; + } } } } @@ -134,8 +121,7 @@ std::int32_t GammaController::Thunk() void WINAPI GammaController::ENBCallback(ENBCallbackType callback_type) { - if (callback_type <=> ENBCallbackType::BeginFrame == 0) - { + if (callback_type <=> ENBCallbackType::BeginFrame == 0) { call_counter++; if (call_counter <=> Settings::every_x_frames < 0) @@ -148,10 +134,8 @@ void WINAPI GammaController::ENBCallback(ENBCallbackType callback_type) ENBAPI::get_enb_param(nullptr, "ENBEFFECT.FX", "CC: Brightness", &brightness); std::memcpy(¤t_brightness, &brightness.data, sizeof current_brightness); - if (control_global->value <=> 0.0f == 0) - { - if (current_brightness <=> original_enb_brightness != 0) - { + if (control_global->value <=> 0.0f == 0) { + if (current_brightness <=> original_enb_brightness != 0) { logger::debug("Global set to 0, resetting brightness..."); std::memcpy(&brightness.data, &original_enb_brightness, sizeof original_enb_brightness); ENBAPI::set_enb_param(nullptr, "ENBEFFECT.FX", "CC: Brightness", &brightness); @@ -159,20 +143,16 @@ void WINAPI GammaController::ENBCallback(ENBCallbackType callback_type) return; } - if (const auto calendar{ RE::Calendar::GetSingleton() }) - { - if (const auto player{ RE::PlayerCharacter::GetSingleton() }) - { + if (const auto calendar{ RE::Calendar::GetSingleton() }) { + if (const auto player{ RE::PlayerCharacter::GetSingleton() }) { const auto game_hour{ calendar->GetHour() }; auto trunc_time{ std::floor(game_hour * 100) / 100 }; logger::debug("Current time: {:.2f}", trunc_time); logger::debug("Current brightness: {:.2f}", current_brightness); const auto* map{ &Settings::exterior_map }; - if (const auto parent_cell{ player->GetParentCell() }) - { - if (parent_cell->IsInteriorCell()) - { + if (const auto parent_cell{ player->GetParentCell() }) { + if (parent_cell->IsInteriorCell()) { logger::debug("Player is in interior cell {}", parent_cell->GetName()); map = &Settings::interior_map; } @@ -180,21 +160,18 @@ void WINAPI GammaController::ENBCallback(ENBCallbackType callback_type) else logger::debug("Player is in exterior cell"); - if (!map->contains(trunc_time)) - { + if (!map->contains(trunc_time)) { logger::debug("{:.2f} not found in map, truncating...", trunc_time); trunc_time = std::floor(game_hour * 10) / 10; logger::debug("New trunc time: {:.2f}", trunc_time); - if (!map->contains(trunc_time)) - { + if (!map->contains(trunc_time)) { logger::debug("{:.2f} not found in map, truncating...", trunc_time); trunc_time = std::floor(trunc_time); logger::debug("New trunc time: {:.2f}", trunc_time); } } const auto new_brightness{ map->at(trunc_time) }; - if (current_brightness <=> new_brightness != 0) - { + if (current_brightness <=> new_brightness != 0) { std::memcpy(&brightness.data, &new_brightness, sizeof new_brightness); ENBAPI::set_enb_param(nullptr, "ENBEFFECT.FX", "CC: Brightness", &brightness); logger::debug("Set new brightness {:.2f} for {:.2f}", new_brightness, trunc_time); diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 36ec2a4..32909f7 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -4,7 +4,7 @@ namespace Hooks { - void Install() + void Install() noexcept { stl::write_thunk_call(); logger::info("Installed main update hook"); diff --git a/src/Logging.cpp b/src/Logging.cpp index 14f285a..f52b957 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -1,6 +1,6 @@ #include "Logging.h" -void InitializeLogging() +void InitializeLogging() noexcept { auto path{ SKSE::log::log_directory() }; if (!path) @@ -19,5 +19,5 @@ void InitializeLogging() set_default_logger(std::move(log)); - spdlog::set_pattern("[%H:%M:%S.%e] [%l] [%t] [%s:%#] %v"); + spdlog::set_pattern("[%T.%e UTC%z] [%L] [%=5t] %v"); } diff --git a/src/Main.cpp b/src/Main.cpp index e4647a5..8f7c075 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -5,10 +5,9 @@ #include "SKSE/Interfaces.h" -void Listener(SKSE::MessagingInterface::Message* message) +void Listener(SKSE::MessagingInterface::Message* message) noexcept { - if (message->type <=> SKSE::MessagingInterface::kDataLoaded == 0) - { + if (message->type <=> SKSE::MessagingInterface::kDataLoaded == 0) { Settings::LoadSettings(); GammaController::Init(); if (!ENBAPI::linked_enb_functions) diff --git a/src/Settings.cpp b/src/Settings.cpp index e22bdd9..ee5f30c 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -1,6 +1,6 @@ #include "Settings.h" -void Settings::LoadSettings() +void Settings::LoadSettings() noexcept { logger::info("Loading settings"); @@ -11,8 +11,7 @@ void Settings::LoadSettings() debug_logging = ini.GetBoolValue("Log", "Debug"); - if (debug_logging) - { + if (debug_logging) { spdlog::get("Global")->set_level(spdlog::level::level_enum::debug); logger::debug("Debug logging enabled"); } diff --git a/vcpkg.json b/vcpkg.json index 94c8ddf..62227fa 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "dynamic-gamma", - "version-semver": "1.0.11", + "version-semver": "1.0.12", "dependencies": [ "commonlibsse-ng", "simpleini" @@ -11,7 +11,7 @@ "default-registry": { "kind": "git", "repository": "https://github.com/microsoft/vcpkg", - "baseline": "436a061a544c124200200517b9ee55c5bb1b7a26" + "baseline": "c6d6efed3e9b4242765bfe1b5c5befffd85f7b92" }, "registries": [ { @@ -19,9 +19,7 @@ "repository": "https://gitlab.com/colorglass/vcpkg-colorglass", "baseline": "6309841a1ce770409708a67a9ba5c26c537d2937", "packages": [ - "commonlibsse-ng", - "script-extender-common", - "skse" + "commonlibsse-ng" ] } ]