diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..4f00ccf --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,35 @@ +name: Format + +on: + push: + branches: main + +permissions: + contents: write + +jobs: + maintenance: + 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: Run Prettier + uses: actionsx/prettier@v3 + with: + args: --write "${{ github.workspace }}/*.json" + + - name: Add & Commit + uses: EndBug/add-and-commit@v9.1.3 + with: + message: "ci: formatting" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 375ab90..bb36aca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,14 @@ configure_file( ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Plugin.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/include/Plugin.h + @ONLY) + set(PUBLIC_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}") set(headers + include/Plugin.h include/Utility.h) set(sources diff --git a/CMakePresets.json b/CMakePresets.json index 621e1d0..4b4b93f 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -19,8 +19,8 @@ "hidden": true, "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", - "VCPKG_TARGET_TRIPLET": "x64-windows-static", - "VCPKG_HOST_TRIPLET": "x64-windows-static", + "VCPKG_TARGET_TRIPLET": "x64-windows", + "VCPKG_HOST_TRIPLET": "x64-windows", "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake" } }, @@ -28,15 +28,7 @@ "name": "win32", "hidden": true, "environment": { - "CommonLibSF_PLATFORM": "-DWIN32_LEAN_AND_MEAN -DNOMINMAX" - } - }, - { - "name": "win32-unicode", - "hidden": true, - "inherits": "win32", - "environment": { - "CommonLibSF_TEXT": "-DUNICODE -D_UNICODE" + "COMMONLIBSF_PLATFORM": "-DWIN32_LEAN_AND_MEAN -DNOMINMAX" } }, { @@ -53,14 +45,14 @@ "generator": "Ninja", "cmakeExecutable": "C:/Program Files/CMake/bin/", "environment": { - "CommonLibSF_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", - "CommonLibSF_LINKER": "/CGTHREADS:8 /MACHINE:x64" + "COMMONLIBSF_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", + "COMMONLIBSF_LINKER": "/CGTHREADS:8 /MACHINE:x64 /DEBUG:FULL" }, "cacheVariables": { - "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "/fp:fast /GL /GR- /Gw /O2 /Ob3 /Qpar", - "CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO": "/DEBUG:FULL /LTCG:INCREMENTAL /OPT:REF,ICF=4", + "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "/fp:fast /GL /GR- /Gw /O2 /Ob3 /Qpar /MD", + "CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO": "/LTCG:INCREMENTAL /OPT:REF,ICF=4", "CMAKE_CXX_FLAGS_DEBUG": "/Od /MDd", - "CMAKE_SHARED_LINKER_FLAGS_DEBUG": "/DEBUG:FULL /LTCG:INCREMENTAL /DEBUGTYPE:FIXUP" + "CMAKE_SHARED_LINKER_FLAGS_DEBUG": "/DEBUGTYPE:FIXUP" }, "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { @@ -72,7 +64,7 @@ }, { "name": "build-release-msvc", - "inherits": ["base", "vcpkg", "win32-unicode", "x64", "msvc"], + "inherits": ["base", "vcpkg", "x64", "msvc"], "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo" }, @@ -82,7 +74,7 @@ }, { "name": "build-debug-msvc", - "inherits": ["base", "vcpkg", "win32-unicode", "x64", "msvc"], + "inherits": ["base", "vcpkg", "x64", "msvc"], "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }, diff --git a/EXCEPTIONS b/EXCEPTIONS new file mode 100644 index 0000000..c4f7d80 --- /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 hereby grants 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/cmake/Plugin.h.in b/cmake/Plugin.h.in new file mode 100644 index 0000000..617439d --- /dev/null +++ b/cmake/Plugin.h.in @@ -0,0 +1,8 @@ +#pragma once + +namespace Plugin +{ + static constexpr auto Name = "PluginName"; + static constexpr auto Author = "AuthorName"; + static constexpr auto Version = 0u * 10000 + 0u * 100 + 1u; +} // namespace Plugin diff --git a/cmake/version.rc.in b/cmake/version.rc.in index 95029f0..bf2bfe8 100644 --- a/cmake/version.rc.in +++ b/cmake/version.rc.in @@ -20,7 +20,7 @@ BEGIN VALUE "FileDescription", "@PROJECT_DESCRIPTION@" VALUE "FileVersion", "@PROJECT_VERSION@" VALUE "InternalName", "@PROJECT_NAME@" - VALUE "LegalCopyright", "Apache License 2.0" + VALUE "LegalCopyright", "GNU General Public License 3.0" VALUE "ProductName", "@PROJECT_FRIENDLY_NAME@" VALUE "ProductVersion", "@PROJECT_VERSION@" END diff --git a/include/Hooks.h b/include/Hooks.h index d26f3be..aa2acc6 100644 --- a/include/Hooks.h +++ b/include/Hooks.h @@ -2,5 +2,5 @@ namespace Hooks { - void Install(); + void Install() noexcept; } // namespace Hooks 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 41f5e72..1b3ad5b 100644 --- a/include/PCH.h +++ b/include/PCH.h @@ -96,6 +96,7 @@ #include #include +#include #include // clang-format off @@ -107,10 +108,12 @@ #include #include +#include "Plugin.h" + using namespace std::literals; using namespace REL::literals; -// namespace logger = SFSE::log; +namespace logger = SFSE::log; template class Singleton @@ -132,29 +135,31 @@ class Singleton } }; -// namespace stl -//{ -// using namespace SFSE::stl; -// -// template -// constexpr void write_thunk_call() noexcept -// { -// SFSE::AllocTrampoline(14); -// auto& trampoline{ SFSE::GetTrampoline() }; -// T::func = trampoline.write_call<5>(T::address, T::Thunk); -// } -// -// template -// constexpr void write_vfunc() noexcept -// { -// REL::Relocation vtbl{ TDest::VTABLE[0] }; -// TSource::func = vtbl.write_vfunc(TSource::idx, TSource::Thunk); -// } -// -// template -// constexpr void write_vfunc(const REL::VariantID variant_id) noexcept -// { -// REL::Relocation vtbl{ variant_id }; -// T::func = vtbl.write_vfunc(T::idx, T::Thunk); -// } -// } // namespace stl +namespace stl +{ + using namespace SFSE::stl; + + template + constexpr void write_thunk_call() noexcept + { + SFSE::AllocTrampoline(14); + auto& trampoline{ SFSE::GetTrampoline() }; + T::func = trampoline.write_call<5>(T::address, T::Thunk); + } + + template + constexpr void write_vfunc() noexcept + { + REL::Relocation vtbl{ TDest::VTABLE[0] }; + TSource::func = vtbl.write_vfunc(TSource::idx, TSource::Thunk); + } + + // template + // constexpr void write_vfunc(const REL::VariantID variant_id) noexcept + //{ + // REL::Relocation vtbl{ variant_id }; + // T::func = vtbl.write_vfunc(T::idx, T::Thunk); + // } +} // namespace stl + +#define SFSEPluginVersion extern "C" __declspec(dllexport) constinit SFSE::PluginVersionData SFSEPlugin_Version diff --git a/include/Plugin.h b/include/Plugin.h new file mode 100644 index 0000000..617439d --- /dev/null +++ b/include/Plugin.h @@ -0,0 +1,8 @@ +#pragma once + +namespace Plugin +{ + static constexpr auto Name = "PluginName"; + static constexpr auto Author = "AuthorName"; + static constexpr auto Version = 0u * 10000 + 0u * 100 + 1u; +} // namespace Plugin diff --git a/include/Settings.h b/include/Settings.h index 9fbfe54..52ad6ef 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/Hooks.cpp b/src/Hooks.cpp index 7a825bc..b8b1266 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -2,14 +2,6 @@ namespace Hooks { - void Install() - { - stl::write_thunk_call(); - logger::info("Installed main update hook"); - } - - std::int32_t MainUpdate::thunk() - { - return func(); - } + void Install() noexcept + {} } // namespace Hooks diff --git a/src/Logging.cpp b/src/Logging.cpp index 0223343..e247f74 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -5,7 +5,7 @@ void InitializeLogging() noexcept auto path{ SFSE::log::log_directory() }; if (!path) stl::report_and_fail("Unable to lookup SFSE logs directory."); - *path /= SFSE::PluginDeclaration::GetSingleton()->GetName(); + *path /= Plugin::Name; *path += L".log"; std::shared_ptr log; diff --git a/src/Main.cpp b/src/Main.cpp index 3e29753..cd53e83 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,34 +1,41 @@ -#include "Events.h" #include "Hooks.h" #include "Logging.h" #include "Settings.h" -#include "SFSE/Interfaces.h" - -void Listener(SFSE::MessagingInterface::Message* message) +void Listener(SFSE::MessagingInterface::Message* message) noexcept { - if (message->type <=> SFSE::MessagingInterface::kDataLoaded == 0) + if (message->type <=> SFSE::MessagingInterface::kPostPostLoad == 0) { Settings::LoadSettings(); Hooks::Install(); } } -SFSEPluginLoad(const SFSE::LoadInterface* skse) +SFSEPluginLoad(const SFSE::LoadInterface* sfse) { InitializeLogging(); - const auto plugin{ SFSE::PluginDeclaration::GetSingleton() }; - const auto version{ plugin->GetVersion() }; - - logger::info("{} {} is loading...", plugin->GetName(), version); + logger::info("{} {} is loading...", Plugin::Name, Plugin::Version); - Init(skse); + Init(sfse); if (const auto messaging{ SFSE::GetMessagingInterface() }; !messaging->RegisterListener(Listener)) return false; - logger::info("{} has finished loading.", plugin->GetName()); + logger::info("{} has finished loading.", Plugin::Name); return true; } + +SFSEPluginVersion = []() noexcept { + SFSE::PluginVersionData data{}; + + data.PluginVersion(Plugin::Version); + data.PluginName(Plugin::Name); + data.AuthorName(Plugin::Author); + data.UsesSigScanning(false); + data.HasNoStructUse(true); + data.CompatibleVersions({ SFSE::RUNTIME_LATEST }); + + return data; +}(); diff --git a/src/Settings.cpp b/src/Settings.cpp index 4ef1133..49c5aaa 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"); diff --git a/vcpkg.json b/vcpkg.json index 79dd94d..0f92543 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -8,14 +8,14 @@ "default-registry": { "kind": "git", "repository": "https://github.com/microsoft/vcpkg", - "baseline": "7b5ca09708ae42dba9517d4e0a0c975d087f1061" + "baseline": "962e5e39f8a25f42522f51fffc574e05a3efd26b" }, "registries": [ { "kind": "git", "repository": "https://github.com/Starfield-Reverse-Engineering/Starfield-RE-vcpkg", - "baseline": "4afa6c12061c02adb56f996eb09e029d4a9b0fc8", - "packages": ["commonlibsf"] + "baseline": "1b77902da9c42009164aa7abf1612172ba1b72f7", + "packages": [ "commonlibsf" ] } ] }