Skip to content

Commit

Permalink
Update template
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirdEyeSqueegee committed Sep 10, 2023
1 parent 1f4fd36 commit f01f46d
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 76 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
with:
message: "ci: formatting"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 10 additions & 18 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,16 @@
"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"
}
},
{
"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"
}
},
{
Expand All @@ -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": {
Expand All @@ -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"
},
Expand All @@ -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"
},
Expand Down
15 changes: 15 additions & 0 deletions EXCEPTIONS
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions cmake/Plugin.h.in
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion cmake/version.rc.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

namespace Hooks
{
void Install();
void Install() noexcept;
} // namespace Hooks
2 changes: 1 addition & 1 deletion include/Logging.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once

void InitializeLogging();
void InitializeLogging() noexcept;
59 changes: 32 additions & 27 deletions include/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@

#include <RE/Starfield.h>
#include <REL/Relocation.h>
#include <SFSE/Interfaces.h>
#include <SFSE/SFSE.h>

// clang-format off
Expand All @@ -107,10 +108,12 @@
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/msvc_sink.h>

#include "Plugin.h"

using namespace std::literals;
using namespace REL::literals;

// namespace logger = SFSE::log;
namespace logger = SFSE::log;

template <typename T>
class Singleton
Expand All @@ -132,29 +135,31 @@ class Singleton
}
};

// namespace stl
//{
// using namespace SFSE::stl;
//
// template <typename T>
// constexpr void write_thunk_call() noexcept
// {
// SFSE::AllocTrampoline(14);
// auto& trampoline{ SFSE::GetTrampoline() };
// T::func = trampoline.write_call<5>(T::address, T::Thunk);
// }
//
// template <typename TDest, typename TSource>
// constexpr void write_vfunc() noexcept
// {
// REL::Relocation<std::uintptr_t> vtbl{ TDest::VTABLE[0] };
// TSource::func = vtbl.write_vfunc(TSource::idx, TSource::Thunk);
// }
//
// template <typename T>
// constexpr void write_vfunc(const REL::VariantID variant_id) noexcept
// {
// REL::Relocation<std::uintptr_t> vtbl{ variant_id };
// T::func = vtbl.write_vfunc(T::idx, T::Thunk);
// }
// } // namespace stl
namespace stl
{
using namespace SFSE::stl;

template <typename T>
constexpr void write_thunk_call() noexcept
{
SFSE::AllocTrampoline(14);
auto& trampoline{ SFSE::GetTrampoline() };
T::func = trampoline.write_call<5>(T::address, T::Thunk);
}

template <typename TDest, typename TSource>
constexpr void write_vfunc() noexcept
{
REL::Relocation vtbl{ TDest::VTABLE[0] };
TSource::func = vtbl.write_vfunc(TSource::idx, TSource::Thunk);
}

// template <typename T>
// constexpr void write_vfunc(const REL::VariantID variant_id) noexcept
//{
// REL::Relocation<std::uintptr_t> 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
8 changes: 8 additions & 0 deletions include/Plugin.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion include/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Settings : public Singleton<Settings>
{
public:
static void LoadSettings();
static void LoadSettings() noexcept;

inline static bool debug_logging{};
};
12 changes: 2 additions & 10 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

namespace Hooks
{
void Install()
{
stl::write_thunk_call<MainUpdate>();
logger::info("Installed main update hook");
}

std::int32_t MainUpdate::thunk()
{
return func();
}
void Install() noexcept
{}
} // namespace Hooks
2 changes: 1 addition & 1 deletion src/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<spdlog::logger> log;
Expand Down
31 changes: 19 additions & 12 deletions src/Main.cpp
Original file line number Diff line number Diff line change
@@ -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;
}();
2 changes: 1 addition & 1 deletion src/Settings.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Settings.h"

void Settings::LoadSettings()
void Settings::LoadSettings() noexcept
{
logger::info("Loading settings");

Expand Down
6 changes: 3 additions & 3 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
]
}
Expand Down

0 comments on commit f01f46d

Please sign in to comment.