Skip to content

Commit ae09a28

Browse files
authored
Merge branch 'praydog:master' into master
2 parents a08ca2e + 82cbd4b commit ae09a28

12 files changed

Lines changed: 116 additions & 6 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ FetchContent_Declare(
114114
)
115115
FetchContent_MakeAvailable(directxtk12)
116116

117-
message(STATUS "Fetching safetyhook (4faf792c2d66cbf06f2c942561d053aafd79006b)...")
117+
message(STATUS "Fetching safetyhook (b046e123dc69821f2c375161e0adef3c6d9c9db4)...")
118118
FetchContent_Declare(
119119
safetyhook
120120
GIT_REPOSITORY
121121
https://github.com/cursey/safetyhook
122122
GIT_TAG
123-
4faf792c2d66cbf06f2c942561d053aafd79006b
123+
b046e123dc69821f2c375161e0adef3c6d9c9db4
124124
)
125125
FetchContent_MakeAvailable(safetyhook)
126126

cmake.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ condition = "build-framework-dependencies"
114114

115115
[fetch-content.safetyhook]
116116
git = "https://github.com/cursey/safetyhook"
117-
tag = "4faf792c2d66cbf06f2c942561d053aafd79006b"
117+
tag = "b046e123dc69821f2c375161e0adef3c6d9c9db4"
118118

119119
[target.imgui]
120120
type = "static"

include/reframework/API.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#endif
88

99
#define REFRAMEWORK_PLUGIN_VERSION_MAJOR 1
10-
#define REFRAMEWORK_PLUGIN_VERSION_MINOR 9
10+
#define REFRAMEWORK_PLUGIN_VERSION_MINOR 10
1111
#define REFRAMEWORK_PLUGIN_VERSION_PATCH 0
1212

1313
#define REFRAMEWORK_RENDERER_D3D11 0
@@ -254,6 +254,8 @@ typedef struct {
254254

255255
void* (*get_init_data)(REFrameworkFieldHandle);
256256
void* (*get_data_raw)(REFrameworkFieldHandle, void* obj, bool is_value_type);
257+
258+
unsigned int (*get_index)(REFrameworkFieldHandle);
257259
} REFrameworkTDBField;
258260

259261
typedef struct {

include/reframework/API.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,11 @@ class API {
696696
return fn(*this, obj, is_value_type);
697697
}
698698

699+
uint32_t get_index() const {
700+
static const auto fn = API::s_instance->sdk()->field->get_index;
701+
return fn(*this);
702+
}
703+
699704
template <typename T> T& get_data(void* object = nullptr, bool is_value_type = false) const { return *(T*)get_data_raw(object, is_value_type); }
700705
};
701706

shared/sdk/REContext.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,25 @@ namespace sdk {
260260
}
261261
}
262262
if (!method_inside_invoke_tbl) {
263-
spdlog::info("[VM::update_pointers] Unable to find method inside invoke table.");
263+
spdlog::info("[VM::update_pointers] Unable to find method inside invoke table. Trying fallback scan...");
264+
const auto anchor = utility::scan(mod, "8D 56 FF 48 8B CF E8 ? ? ? ?");
265+
266+
if (!anchor) {
267+
spdlog::info("[VM::update_pointers] Unable to find anchor for invoke table.");
268+
return;
269+
}
270+
271+
const auto lea_rdx = utility::scan_reverse(*anchor, 0x100, "48 8D 15 ? ? ? ?");
272+
273+
if (!lea_rdx) {
274+
spdlog::info("[VM::update_pointers] Unable to find lea rdx for invoke table.");
275+
return;
276+
}
277+
278+
s_invoke_tbl = (sdk::InvokeMethod*)utility::resolve_displacement(*lea_rdx).value_or(0);
279+
280+
spdlog::info("[VM::update_pointers] s_invoke_tbl: {:x}", (uintptr_t)s_invoke_tbl);
281+
264282
return;
265283
}
266284

shared/sdk/RETypeDB.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,12 @@ void* REField::get_data_raw(void* object, bool is_value_type) const {
349349

350350
return nullptr;
351351
}
352+
353+
uint32_t sdk::REField::get_index() const {
354+
auto tdb = RETypeDB::get();
355+
356+
return (uint32_t)(((uintptr_t)this - (uintptr_t)tdb->fields) / sizeof(sdk::REField));
357+
}
352358
} // namespace sdk
353359

354360
// methods

shared/sdk/RETypeDB.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ struct REField : public sdk::REField_ {
10071007
bool is_literal() const;
10081008

10091009
void* get_data_raw(void* object = nullptr, bool is_value_type = false) const;
1010+
uint32_t get_index() const;
10101011

10111012
template <typename T> T& get_data(void* object = nullptr, bool is_value_type = false) const { return *(T*)get_data_raw(object); }
10121013
};

src/mods/Graphics.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ void Graphics::on_draw_ui() {
177177
}
178178

179179
if (interception_node_open) {
180+
if (ImGui::InputText(std::format("Replace Shader", i).c_str(), intercepted.replace_with_name.data(), intercepted.replace_with_name.size())) {
181+
intercepted.replace_with_hash = sdk::murmur_hash::calc32_as_utf8(intercepted.replace_with_name.data());
182+
}
183+
180184
for (auto& replacement : intercepted.replacement_shaders) {
181185
i++;
182186
ImGui::PushID(std::format("Shader {}", i).c_str());
@@ -1110,7 +1114,7 @@ sdk::renderer::PipelineState* Graphics::find_pipeline_state_hook(void* shader_re
11101114
auto& graphics = Graphics::get();
11111115

11121116
const auto og = graphics->m_find_pipeline_state_hook->get_original<decltype(find_pipeline_state_hook)>();
1113-
const auto result = og(shader_resource, murmur_hash, unk);
1117+
auto result = og(shader_resource, murmur_hash, unk);
11141118

11151119
if (!graphics->m_shader_playground->value()) {
11161120
return result;
@@ -1135,6 +1139,15 @@ sdk::renderer::PipelineState* Graphics::find_pipeline_state_hook(void* shader_re
11351139
if (intercepted_shader == nullptr) {
11361140
return result;
11371141
}
1142+
1143+
if (intercepted_shader->replace_with_hash != 0 || std::string_view{intercepted_shader->replace_with_name} == "None") {
1144+
const auto replacement = og(shader_resource, intercepted_shader->replace_with_hash, unk);
1145+
1146+
if (replacement != nullptr) {
1147+
result = replacement;
1148+
}
1149+
}
1150+
11381151
uint32_t i = 1;
11391152

11401153
for (auto& replacement_shader : intercepted_shader->replacement_shaders) {

src/mods/Graphics.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ class Graphics : public Mod {
9797
}();
9898

9999
uint32_t hash{ 0 };
100+
101+
std::string replace_with_name = []() {
102+
std::string result{};
103+
result.resize(1024);
104+
return result;
105+
}();
106+
107+
uint32_t replace_with_hash{ 0 };
100108
};
101109

102110
std::array<InterceptedShader, 8> m_intercepted_shaders{};

src/mods/PluginLoader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ REFrameworkTDBField g_tdb_field_data {
371371

372372
[](REFrameworkFieldHandle field) { return REFIELD(field)->get_init_data(); },
373373
[](REFrameworkFieldHandle field, void* obj, bool is_value_type) { return REFIELD(field)->get_data_raw(obj, is_value_type); },
374+
375+
[](REFrameworkFieldHandle field) { return REFIELD(field)->get_index(); },
374376
};
375377

376378
REFrameworkTDBProperty g_tdb_property_data {

0 commit comments

Comments
 (0)