From 83b3909756090c07535218d2dfc9506f86935a44 Mon Sep 17 00:00:00 2001 From: praydog Date: Fri, 28 Jun 2024 06:11:52 -0700 Subject: [PATCH 1/2] DD2: Fix RT pass manipulation not working --- src/mods/Graphics.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mods/Graphics.cpp b/src/mods/Graphics.cpp index d24a960c..5ca19ec0 100644 --- a/src/mods/Graphics.cpp +++ b/src/mods/Graphics.cpp @@ -725,7 +725,11 @@ void Graphics::setup_path_trace_hook() { const auto game = utility::get_executable(); const auto start1 = std::chrono::high_resolution_clock::now(); - const auto ref = utility::find_function_from_string_ref(game, "RayTraceSettings", true); + auto ref = utility::find_function_from_string_ref(game, "RayTraceSettings", true); + + if (!ref.has_value()) { + ref = utility::find_function_from_string_ref(game, "DXRDebug", true); + } if (!ref.has_value()) { spdlog::error("[Graphics] Failed to find function with RayTraceSettings string reference"); From e7920222aab44fb2d527393379bd1bdd95d73ff9 Mon Sep 17 00:00:00 2001 From: praydog Date: Fri, 28 Jun 2024 18:01:01 -0700 Subject: [PATCH 2/2] DD2: Fix type list not getting filled --- shared/sdk/RETypes.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/shared/sdk/RETypes.cpp b/shared/sdk/RETypes.cpp index 1b03c364..c0adac48 100644 --- a/shared/sdk/RETypes.cpp +++ b/shared/sdk/RETypes.cpp @@ -57,6 +57,69 @@ RETypes::RETypes() { bool re7_version = false; if (!ref) { +#if TDB_VER >= 73 + // This is the absolutely foolproof way of finding it + // We can probably completely replace it with this for all the games, but not doing that just yet to be safe + const auto via_object_ref = utility::scan(mod, "BA 55 FD 09 D2"); + + if (!via_object_ref) { + spdlog::error("Failed to find via object ref"); + fill_types_from_tdb(); + return; + } + + // now we do the scorched earth method where we exhaustively disassemble all possible paths + // looking for any kind of displacement. we will assume that this is the type list + // and then walk it. if we get an exception - continue. look for valid types in the list + utility::exhaustive_decode((uint8_t*)*via_object_ref, 1000, [&](utility::ExhaustionContext& ctx) -> utility::ExhaustionResult { + if (m_raw_types != nullptr) { + return utility::ExhaustionResult::BREAK; + } + + const auto disp = utility::resolve_displacement(ctx.addr); + + if (!disp.has_value()) { + return utility::ExhaustionResult::CONTINUE; + } + + try { + TypeList* potential_types = (TypeList*)*disp; + + if (potential_types->data == nullptr) { + return utility::ExhaustionResult::CONTINUE; + } + + if (potential_types->numAllocated < 0 || potential_types->numAllocated < 100 || potential_types->numAllocated > 9999999) { + return utility::ExhaustionResult::CONTINUE; + } + + for (auto i = 0; i < potential_types->numAllocated; ++i) try { + auto t = (*potential_types->data)[i]; + + if (t == nullptr || IsBadReadPtr(t, sizeof(REType))) { + continue; + } + + if (t->name != nullptr && (std::string_view{t->name} == "via.clr.ManagedObject" || std::string_view{t->name} == "via.Object")) { + m_raw_types = potential_types; + spdlog::info("Found TypeList: {:x}", (uintptr_t)m_raw_types); + break; + } + } catch(...) { + continue; + } + } catch (...) { + + } + + return utility::ExhaustionResult::CONTINUE; + }); + + if (m_raw_types != nullptr) { + refresh_map(); + return; + } +#else // Scan for RE7 version // mov edx, 8F7E7AEh (TypeInfoNone hash) pat = "BA AE E7 F7 08"; @@ -107,6 +170,7 @@ RETypes::RETypes() { types_offset = 3; re7_version = true; +#endif } spdlog::info("Initial ref: {:x}", (uintptr_t)*ref); @@ -228,6 +292,8 @@ void RETypes::fill_types_from_tdb() { m_types.insert(t->get_type()); m_type_list.push_back(t->get_type()); } + + spdlog::info("filled {} types from TDB", m_types.size()); } void RETypes::refresh_map() {