Skip to content

Commit 9b54896

Browse files
authored
Merge pull request #37 from qudix/dev/hook
feat: hooks
2 parents 8e5f00c + f07a554 commit 9b54896

34 files changed

Lines changed: 1988 additions & 930 deletions

.clang-format

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ BinPackArguments: 'true'
2525
BinPackParameters: 'true'
2626
BitFieldColonSpacing: After
2727
BraceWrapping:
28-
AfterCaseLabel: 'true'
28+
AfterCaseLabel: 'false'
2929
AfterClass: 'true'
3030
AfterControlStatement: 'false'
3131
AfterEnum: 'true'
@@ -59,8 +59,8 @@ DerivePointerAlignment: 'false'
5959
DisableFormat: 'false'
6060
FixNamespaceComments: 'false'
6161
IncludeBlocks: Preserve
62-
IndentCaseBlocks: 'true'
63-
IndentCaseLabels: 'false'
62+
IndentCaseBlocks: 'false'
63+
IndentCaseLabels: 'true'
6464
IndentExternBlock: Indent
6565
IndentGotoLabels: 'false'
6666
IndentPPDirectives: AfterHash

.github/workflows/main_ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
windows:
2424
runs-on: windows-latest
2525
steps:
26-
- uses: actions/checkout@v2
26+
- uses: actions/checkout@v4
2727
with:
2828
path: main
2929

@@ -35,7 +35,7 @@ jobs:
3535
./vcpkg --version > ${{ github.workspace }}/vcpkg-version.txt
3636
3737
- name: Cache vcpkg
38-
uses: actions/cache@v2
38+
uses: actions/cache@v4
3939
id: vcpkg-cache
4040
env:
4141
cache-name: vcpkg-cache

CommonLibF4/cmake/sourcelist.cmake

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ set(SOURCES
430430
include/RE/VTABLE_IDs.h
431431
include/RE/msvc/memory.h
432432
include/RE/msvc/typeinfo.h
433+
include/REL/ASM.h
434+
include/REL/Hook.h
435+
include/REL/HookObject.h
436+
include/REL/HookStore.h
433437
include/REL/IAT.h
434438
include/REL/ID.h
435439
include/REL/IDDB.h
@@ -439,6 +443,8 @@ set(SOURCES
439443
include/REL/REL.h
440444
include/REL/Relocation.h
441445
include/REL/Segment.h
446+
include/REL/Trampoline.h
447+
include/REL/Utility.h
442448
include/REL/Version.h
443449
include/REX/PS4.h
444450
include/REX/PS4/SCEPAD.h
@@ -447,6 +453,7 @@ set(SOURCES
447453
include/REX/REX/EnumSet.h
448454
include/REX/REX/INI.h
449455
include/REX/REX/JSON.h
456+
include/REX/REX/LOG.h
450457
include/REX/REX/Setting.h
451458
include/REX/REX/Singleton.h
452459
include/REX/REX/TOML.h
@@ -483,7 +490,6 @@ set(SOURCES
483490
src/F4SE/InputMap.cpp
484491
src/F4SE/Interfaces.cpp
485492
src/F4SE/Logger.cpp
486-
src/F4SE/Trampoline.cpp
487493
src/RE/Bethesda/Actor.cpp
488494
src/RE/Bethesda/BGSInventoryItem.cpp
489495
src/RE/Bethesda/BSExtraData.cpp
@@ -522,10 +528,13 @@ set(SOURCES
522528
src/RE/NetImmerse/NiRect.cpp
523529
src/RE/NetImmerse/NiTransform.cpp
524530
src/RE/Scaleform/GFx/GFx_Player.cpp
531+
src/REL/HookObject.cpp
532+
src/REL/HookStore.cpp
525533
src/REL/IAT.cpp
526534
src/REL/IDDB.cpp
527535
src/REL/Module.cpp
528-
src/REL/Relocation.cpp
536+
src/REL/Trampoline.cpp
537+
src/REL/Utility.cpp
529538
src/REL/Version.cpp
530539
src/REX/REX.cpp
531540
src/REX/W32.cpp

CommonLibF4/include/F4SE/API.h

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace F4SE
44
{
55
using PluginHandle = std::uint32_t;
66

7+
class PreLoadInterface;
78
class LoadInterface;
89

910
struct PluginInfo;
@@ -16,17 +17,27 @@ namespace F4SE
1617
class ObjectInterface;
1718
class TrampolineInterface;
1819

19-
void Init(const LoadInterface* a_intfc, bool a_log = true) noexcept;
20-
21-
[[nodiscard]] std::string_view GetPluginName() noexcept;
22-
[[nodiscard]] std::string_view GetPluginAuthor() noexcept;
23-
[[nodiscard]] REL::Version GetPluginVersion() noexcept;
24-
25-
[[nodiscard]] REL::Version GetF4SEVersion() noexcept;
26-
[[nodiscard]] PluginHandle GetPluginHandle() noexcept;
27-
[[nodiscard]] std::uint32_t GetReleaseIndex() noexcept;
28-
[[nodiscard]] const PluginInfo* GetPluginInfo(std::string_view a_plugin) noexcept;
29-
[[nodiscard]] std::string_view GetSaveFolderName() noexcept;
20+
struct InitInfo
21+
{
22+
bool log{ true };
23+
const char* logName{ nullptr };
24+
const char* logPattern{ nullptr };
25+
bool trampoline{ false };
26+
std::size_t trampolineSize{ 0 };
27+
bool hook{ true };
28+
};
29+
30+
void Init(const PreLoadInterface* a_intfc, InitInfo a_info = {}) noexcept;
31+
void Init(const LoadInterface* a_intfc, InitInfo a_info = {}) noexcept;
32+
33+
[[nodiscard]] REL::Version GetF4SEVersion() noexcept;
34+
[[nodiscard]] std::string_view GetPluginName() noexcept;
35+
[[nodiscard]] std::string_view GetPluginAuthor() noexcept;
36+
[[nodiscard]] REL::Version GetPluginVersion() noexcept;
37+
[[nodiscard]] PluginHandle GetPluginHandle() noexcept;
38+
[[nodiscard]] const PluginInfo* GetPluginInfo(std::string_view a_plugin) noexcept;
39+
[[nodiscard]] std::uint32_t GetReleaseIndex() noexcept;
40+
[[nodiscard]] std::string_view GetSaveFolderName() noexcept;
3041

3142
[[nodiscard]] const MessagingInterface* GetMessagingInterface() noexcept;
3243
[[nodiscard]] const ScaleformInterface* GetScaleformInterface() noexcept;
@@ -35,6 +46,13 @@ namespace F4SE
3546
[[nodiscard]] const TaskInterface* GetTaskInterface() noexcept;
3647
[[nodiscard]] const ObjectInterface* GetObjectInterface() noexcept;
3748
[[nodiscard]] const TrampolineInterface* GetTrampolineInterface() noexcept;
49+
}
50+
51+
namespace F4SE
52+
{
53+
// DEPRECATED
54+
void Init(const LoadInterface* a_intfc, bool a_log) noexcept;
3855

56+
// DEPRECATED
3957
void AllocTrampoline(std::size_t a_size) noexcept;
4058
}

CommonLibF4/include/F4SE/Impl/PCH.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static_assert(
4444

4545
#include "REX/REX/Enum.h"
4646
#include "REX/REX/EnumSet.h"
47+
#include "REX/REX/LOG.h"
4748
#include "REX/W32/KERNEL32.h"
4849
#include "REX/W32/USER32.h"
4950

CommonLibF4/include/F4SE/Interfaces.h

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,56 @@ namespace F4SE
132132
[[nodiscard]] REL::Version RuntimeVersion() const noexcept { return MakeVersion(GetProxy().runtimeVersion); }
133133
};
134134

135+
class PreLoadInterface :
136+
public QueryInterface
137+
{
138+
public:
139+
enum : std::uint32_t
140+
{
141+
kInvalid = 0,
142+
kTrampoline = 7
143+
};
144+
145+
[[nodiscard]] void* QueryInterface(std::uint32_t a_id) const { return GetProxy().QueryInterface(a_id); }
146+
147+
template <class T>
148+
T* QueryInterface(std::uint32_t a_id) const noexcept
149+
{
150+
auto result = static_cast<T*>(QueryInterface(a_id));
151+
if (result && result->Version() > T::kVersion)
152+
REX::ERROR("interface definition is out of date");
153+
154+
return result;
155+
}
156+
};
157+
135158
class LoadInterface :
136159
public QueryInterface
137160
{
138161
public:
139162
enum : std::uint32_t
140163
{
141164
kInvalid = 0,
142-
kMessaging,
143-
kScaleform,
144-
kPapyrus,
145-
kSerialization,
146-
kTask,
147-
kObject,
148-
kTrampoline
165+
kMessaging = 1,
166+
kScaleform = 2,
167+
kPapyrus = 3,
168+
kSerialization = 4,
169+
kTask = 5,
170+
kObject = 6,
171+
kTrampoline = 7
149172
};
150173

151174
[[nodiscard]] void* QueryInterface(std::uint32_t a_id) const { return GetProxy().QueryInterface(a_id); }
175+
176+
template <class T>
177+
T* QueryInterface(std::uint32_t a_id) const noexcept
178+
{
179+
auto result = static_cast<T*>(QueryInterface(a_id));
180+
if (result && result->Version() > T::kVersion)
181+
REX::ERROR("interface definition is out of date");
182+
183+
return result;
184+
}
152185
};
153186

154187
class MessagingInterface
@@ -524,9 +557,9 @@ namespace F4SE
524557
}
525558

526559
#define F4SE_EXPORT extern "C" [[maybe_unused]] __declspec(dllexport)
527-
#define F4SEPluginPreload(...) F4SE_EXPORT bool F4SEPlugin_Preload(__VA_ARGS__)
528-
#define F4SEPluginLoad(...) F4SE_EXPORT bool F4SEPlugin_Load(__VA_ARGS__)
529-
#define F4SEPluginVersion F4SE_EXPORT constinit F4SE::PluginVersionData F4SEPlugin_Version
530-
#define F4SE_PLUGIN_PRELOAD F4SEPluginPreload
531-
#define F4SE_PLUGIN_LOAD F4SEPluginLoad
532-
#define F4SE_PLUGIN_VERSION F4SEPluginVersion
560+
#define F4SE_PLUGIN_PRELOAD(...) F4SE_EXPORT bool F4SEPlugin_Preload(__VA_ARGS__)
561+
#define F4SE_PLUGIN_LOAD(...) F4SE_EXPORT bool F4SEPlugin_Load(__VA_ARGS__)
562+
#define F4SE_PLUGIN_VERSION F4SE_EXPORT constinit F4SE::PluginVersionData F4SEPlugin_Version
563+
#define F4SEPluginPreload F4SE_PLUGIN_PRELOAD
564+
#define F4SEPluginLoad F4SE_PLUGIN_LOAD
565+
#define F4SEPluginVersion F4SE_PLUGIN_VERSION

CommonLibF4/include/F4SE/Logger.h

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,11 @@
2121
a_fmt, \
2222
std::forward<Args>(a_args)...); \
2323
} \
24-
}; \
25-
\
26-
template <class... Args> \
27-
a_func(spdlog::format_string_t<Args...>, Args&&...) -> a_func<Args...>;\
28-
\
29-
template <> \
30-
struct [[maybe_unused]] a_func<void> \
31-
{ \
32-
a_func() = delete; \
33-
\
34-
explicit a_func( \
35-
spdlog::string_view_t a_str, \
36-
std::source_location a_loc = std::source_location::current()) \
37-
{ \
38-
spdlog::log( \
39-
spdlog::source_loc{ \
40-
a_loc.file_name(), \
41-
static_cast<int>(a_loc.line()), \
42-
a_loc.function_name() }, \
43-
spdlog::level::a_type, \
44-
a_str); \
45-
} \
46-
}; \
47-
\
48-
a_func(spdlog::string_view_t) -> a_func<void>; \
49-
24+
};
5025

5126
namespace F4SE::log
5227
{
53-
// deprecated
28+
// DEPRECATED
5429
F4SE_MAKE_SOURCE_LOGGER(trace, trace);
5530
F4SE_MAKE_SOURCE_LOGGER(debug, debug);
5631
F4SE_MAKE_SOURCE_LOGGER(info, info);
@@ -61,14 +36,4 @@ namespace F4SE::log
6136
[[nodiscard]] std::optional<std::filesystem::path> log_directory();
6237
}
6338

64-
namespace F4SE
65-
{
66-
F4SE_MAKE_SOURCE_LOGGER(TRACE, trace);
67-
F4SE_MAKE_SOURCE_LOGGER(DEBUG, debug);
68-
F4SE_MAKE_SOURCE_LOGGER(INFO, info);
69-
F4SE_MAKE_SOURCE_LOGGER(WARN, warn);
70-
F4SE_MAKE_SOURCE_LOGGER(ERROR, err);
71-
F4SE_MAKE_SOURCE_LOGGER(CRITICAL, critical);
72-
}
73-
7439
#undef F4SE_MAKE_SOURCE_LOGGER

0 commit comments

Comments
 (0)