Skip to content

Commit 34dbcde

Browse files
committed
feat: further refactoring
1 parent 707ba88 commit 34dbcde

65 files changed

Lines changed: 1585 additions & 1401 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/REL/FHookStore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "REL/IHook.h"
44
#include "REX/BASE.h"
5-
#include "REX/REX/TSingleton.h"
5+
#include "REX/TSingleton.h"
66

77
namespace REL
88
{

include/REL/IAT.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "REX/BASE.h"
44

5-
#include "REX/REX/CAST.h"
5+
#include "REX/CAST.h"
66
#include "REX/W32/BASE.h"
77

88
namespace REL

include/REL/ID.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "REX/REX/FModule.h"
3+
#include "REX/FModule.h"
44

55
#include "REL/IDDB.h"
66

include/REL/IDDB.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
#include "REX/BASE.h"
44

5-
#include "REX/REX/FMemoryMap.h"
6-
#include "REX/REX/TSingleton.h"
5+
#include "REX/FMemoryMap.h"
6+
#include "REX/TSingleton.h"
77

88
namespace REL
99
{

include/REL/Offset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "REX/REX/FModule.h"
3+
#include "REX/FModule.h"
44

55
namespace REL
66
{

include/REL/Pattern.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#include "REX/BASE.h"
44

5-
#include "REX/REX/FModule.h"
6-
#include "REX/REX/LOG.h"
7-
#include "REX/REX/TStaticString.h"
5+
#include "REX/FModule.h"
6+
#include "REX/LOG.h"
7+
#include "REX/TStaticString.h"
88

99
namespace REL
1010
{
@@ -145,7 +145,7 @@ namespace REL
145145
if (!this->match(a_address)) {
146146
const auto mod = REX::FModule::GetExecutingModule();
147147
const auto modVersion = mod.GetFileVersion();
148-
REX::IMPL::FAIL(
148+
REX::FAIL(
149149
a_loc,
150150
"A pattern has failed to match.\n"
151151
"This means the plugin is incompatible with either the "

include/REL/Relocation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include "REL/Trampoline.h"
99
#include "REL/Utility.h"
1010

11-
#include "REX/REX/CAST.h"
12-
#include "REX/REX/FModule.h"
11+
#include "REX/CAST.h"
12+
#include "REX/FModule.h"
1313

1414
#define REL_MAKE_MEMBER_FUNCTION_POD_TYPE_HELPER_IMPL(a_nopropQual, a_propQual, ...) \
1515
template < \

include/REL/THook.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "REL/Trampoline.h"
1010
#include "REL/Utility.h"
1111

12-
#include "REX/REX/LOG.h"
12+
#include "REX/LOG.h"
1313

1414
namespace REL
1515
{

include/REL/Trampoline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include "REX/BASE.h"
4-
#include "REX/REX/CAST.h"
4+
#include "REX/CAST.h"
55

66
#ifdef COMMONLIB_OPTION_XBYAK
77
namespace Xbyak

include/REX/CAST.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#pragma once
2+
3+
#include "REX/BASE.h"
4+
5+
namespace REX
6+
{
7+
template <class T, class U>
8+
[[nodiscard]] auto ADJUST_POINTER(U* a_ptr, std::ptrdiff_t a_adjust) noexcept
9+
{
10+
auto addr = a_ptr ? reinterpret_cast<std::uintptr_t>(a_ptr) + a_adjust : 0;
11+
if constexpr (std::is_const_v<U> && std::is_volatile_v<U>) {
12+
return reinterpret_cast<std::add_cv_t<T>*>(addr);
13+
} else if constexpr (std::is_const_v<U>) {
14+
return reinterpret_cast<std::add_const_t<T>*>(addr);
15+
} else if constexpr (std::is_volatile_v<U>) {
16+
return reinterpret_cast<std::add_volatile_t<T>*>(addr);
17+
} else {
18+
return reinterpret_cast<T*>(addr);
19+
}
20+
}
21+
22+
template <class T>
23+
void EMPLACE_VTABLE(T* a_ptr)
24+
{
25+
reinterpret_cast<std::uintptr_t*>(a_ptr)[0] = T::VTABLE[0].address();
26+
}
27+
28+
template <class T>
29+
void MEM_WRITE_ZERO(volatile T* a_ptr, std::size_t a_size = sizeof(T))
30+
{
31+
std::fill_n(reinterpret_cast<volatile char*>(a_ptr), a_size, '\0');
32+
}
33+
34+
template <class T1, class T2>
35+
[[nodiscard]] T1 UNRESTRICTED_CAST(T2 a_from)
36+
{
37+
if constexpr (std::is_same_v<
38+
std::remove_cv_t<T2>,
39+
std::remove_cv_t<T1>>) {
40+
return T1{ a_from };
41+
42+
// From != To
43+
} else if constexpr (std::is_reference_v<T2>) {
44+
return unrestricted_cast<T1>(std::addressof(a_from));
45+
46+
// From: NOT reference
47+
} else if constexpr (std::is_reference_v<T1>) {
48+
return *unrestricted_cast<
49+
std::add_pointer_t<
50+
std::remove_reference_t<T1>>>(a_from);
51+
52+
// To: NOT reference
53+
} else if constexpr (std::is_pointer_v<T2> &&
54+
std::is_pointer_v<T1>) {
55+
return static_cast<T1>(
56+
const_cast<void*>(
57+
static_cast<const volatile void*>(a_from)));
58+
} else if constexpr ((std::is_pointer_v<T2> && std::is_integral_v<T1>) ||
59+
(std::is_integral_v<T2> && std::is_pointer_v<T1>)) {
60+
return reinterpret_cast<T1>(a_from);
61+
} else {
62+
union
63+
{
64+
std::remove_cv_t<std::remove_reference_t<T2>> from;
65+
std::remove_cv_t<std::remove_reference_t<T1>> to;
66+
};
67+
68+
from = std::forward<T2>(a_from);
69+
return to;
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)