Skip to content

Commit f8291a4

Browse files
committed
SDK: Migration of rendering structures from upscaler branch
1 parent b9bde3c commit f8291a4

File tree

8 files changed

+805
-84
lines changed

8 files changed

+805
-84
lines changed

shared/sdk/Memory.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
namespace sdk {
88
namespace memory {
9-
void* allocate(size_t size) {
10-
static decltype(sdk::memory::allocate)* allocate_fn = []() -> decltype(sdk::memory::allocate)* {
9+
void* allocate(size_t size, bool zero_memory) {
10+
using allocate_fn_t = void* (*)(size_t);
11+
static allocate_fn_t allocate_fn = []() -> allocate_fn_t {
1112
spdlog::info("[via::memory::allocate] Finding allocate function...");
1213

1314
// this pattern literally works back to the very first version of the RE Engine!
@@ -23,7 +24,7 @@ void* allocate(size_t size) {
2324

2425
spdlog::info("[via::memory::allocate] Ref {:x}", (uintptr_t)*ref);
2526

26-
auto fn = (decltype(sdk::memory::allocate)*)utility::calculate_absolute(*ref + 6);
27+
auto fn = (allocate_fn_t)utility::calculate_absolute(*ref + 6);
2728

2829
if (!fn) {
2930
spdlog::error("[via::memory::allocate] Failed to calculate allocate function!");
@@ -35,7 +36,13 @@ void* allocate(size_t size) {
3536
return fn;
3637
}();
3738

38-
return allocate_fn(size);
39+
auto result = allocate_fn(size);
40+
41+
if (zero_memory && result != nullptr) {
42+
memset(result, 0, size);
43+
}
44+
45+
return result;
3946
}
4047

4148
void deallocate(void* ptr) {
@@ -105,5 +112,11 @@ void* reallocate(void* ptr, size_t old_size, size_t size) {
105112

106113
return new_mem;
107114
}
115+
116+
namespace detail {
117+
void* allocate_plugin_loader(size_t size) {
118+
return allocate(size);
119+
}
120+
}
121+
}
108122
}
109-
}

shared/sdk/Memory.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace sdk {
44
namespace memory {
5-
void* allocate(size_t size);
5+
void* allocate(size_t size, bool zero_memory = true);
66
void deallocate(void* ptr);
77

88
void* reallocate(void* ptr, size_t old_size, size_t size);
9+
10+
namespace detail {
11+
void* allocate_plugin_loader(size_t size);
12+
}
913
}
1014
}

shared/sdk/RETypeDB.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,18 @@ T* get_static_field(std::string_view type_name, std::string_view name, bool is_v
22402240
return get_native_field<T>((void*)nullptr, t, name, is_value_type);
22412241
}
22422242

2243+
template<typename T>
2244+
T get_enum_value(std::string_view type_name, std::string_view name) {
2245+
const auto field = get_static_field<T>(type_name, name, false);
2246+
2247+
if (field == nullptr) {
2248+
// spdlog::error("Cannot find enum value {:s}", name.data());
2249+
return T{};
2250+
}
2251+
2252+
return *field;
2253+
}
2254+
22432255
template <typename T>
22442256
T* get_native_singleton(std::string_view type_name) {
22452257
const auto t = sdk::find_type_definition(type_name);

0 commit comments

Comments
 (0)