Skip to content

Commit

Permalink
Merge branch 'master' into csharp-api
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jun 29, 2024
2 parents e9021f2 + e792022 commit 56b0d2c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
66 changes: 66 additions & 0 deletions shared/sdk/RETypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -107,6 +170,7 @@ RETypes::RETypes() {

types_offset = 3;
re7_version = true;
#endif
}

spdlog::info("Initial ref: {:x}", (uintptr_t)*ref);
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion src/mods/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 56b0d2c

Please sign in to comment.