Skip to content

Commit

Permalink
Address resolvers (#18)
Browse files Browse the repository at this point in the history
* Update vcpkg to fix fresh build

* Add address resolvers

* Fix build, fix resolvers

* I fell for the oldest trick in the book
  • Loading branch information
NotNite authored Jan 1, 2024
1 parent 1012cc2 commit 0fe8a34
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 18 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ project(regenny)

if(CMKR_ROOT_PROJECT AND NOT CMKR_DISABLE_VCPKG)
include(FetchContent)
message(STATUS "Fetching vcpkg (2022.08.15)...")
FetchContent_Declare(vcpkg URL "https://github.com/microsoft/vcpkg/archive/refs/tags/2022.08.15.tar.gz")
message(STATUS "Fetching vcpkg (2023.12.12)...")
FetchContent_Declare(vcpkg URL "https://github.com/microsoft/vcpkg/archive/refs/tags/2023.12.12.tar.gz")
FetchContent_GetProperties(vcpkg)
if(NOT vcpkg_POPULATED)
FetchContent_Populate(vcpkg)
Expand Down Expand Up @@ -183,7 +183,6 @@ target_link_libraries(regenny PRIVATE
taocpp::pegtl
unofficial::nativefiledialog::nfd
spdlog::spdlog
utf8cpp
SDL2::SDL2
SDL2::SDL2main
nlohmann_json::nlohmann_json
Expand Down
3 changes: 1 addition & 2 deletions cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)
"""

[vcpkg]
version = "2022.08.15"
version = "2023.12.12"
packages = [
"imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]",
"fmt",
Expand Down Expand Up @@ -58,7 +58,6 @@ link-libraries = [
"taocpp::pegtl",
"unofficial::nativefiledialog::nfd",
"spdlog::spdlog",
"utf8cpp",
"SDL2::SDL2",
"SDL2::SDL2main",
"nlohmann_json::nlohmann_json",
Expand Down
2 changes: 1 addition & 1 deletion src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <glad/glad.h> // Initialize with gladLoadGL()
#include <imgui.h>
#include <imgui_impl_opengl3.h>
#include <imgui_impl_sdl.h>
#include <imgui_impl_sdl2.h>

#include "scope_guard.hpp"

Expand Down
39 changes: 30 additions & 9 deletions src/ReGenny.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <fmt/format.h>
#include <imgui.h>
#include <imgui_impl_opengl3.h>
#include <imgui_impl_sdl.h>
#include <imgui_impl_sdl2.h>
#include <imgui_internal.h>
#include <imgui_stdlib.h>
#include <nfd.h>
Expand Down Expand Up @@ -894,7 +894,7 @@ void ReGenny::rtti_sweep_ui() {
//m_ui.rtti_sweep_text += fmt::format("struct {:s}* @ {:s} + 0x{:x}\n", *tname, chain_string, i);
result.emplace_back(i, fmt::format("{:s}* @ {:s} + 0x{:x}\n", *tname, chain_string, i));
}

auto chain_copy = chain;
chain_copy.push_back({base, i});
const auto new_results = lookup(deref, 0x1000, chain_copy, class_name);
Expand Down Expand Up @@ -982,7 +982,7 @@ void ReGenny::rtti_ui() {

std::string demangled{};
demangled.reserve(tname->length());

// replace bad characters with underscores
for (auto&& c : *tname) {
if (std::find(bad_chars.begin(), bad_chars.end(), c) != bad_chars.end()) {
Expand Down Expand Up @@ -1105,6 +1105,13 @@ void ReGenny::memory_ui() {
}

void ReGenny::set_address() {
for (auto address : query_address_resolvers(m_ui.address)) {
auto addr_str = fmt::format("0x{:x}", address);
if (auto addr = parse_address(addr_str)) {
m_parsed_address = *addr;
}
}

if (auto addr = parse_address(m_ui.address)) {
m_parsed_address = *addr;
}
Expand Down Expand Up @@ -1175,7 +1182,7 @@ void ReGenny::reset_lua_state() {
};

auto create_overlay = lua.safe_script("return function(addr, t) return sdkgenny.StructOverlay(addr, t) end").get<sol::function>();

m_lua->new_usertype<ReGenny>("ReGennyClass",
sol::no_constructor,
"type", &ReGenny::type,
Expand All @@ -1191,14 +1198,14 @@ void ReGenny::reset_lua_state() {

return sol::make_object(s, create_overlay(rg->address(), dynamic_cast<sdkgenny::Struct*>(rg->type())));
},
"sdk", [](sol::this_state s, ReGenny* rg) {
"sdk", [](sol::this_state s, ReGenny* rg) {
if (rg->sdk() == nullptr) {
sol::make_object(s, sol::nil);
}

return sol::make_object(s, rg->sdk().get());
},
"process", [](sol::this_state s, ReGenny* rg) -> sol::object {
"process", [](sol::this_state s, ReGenny* rg) -> sol::object {
if (rg->process() == nullptr) {
sol::make_object(s, sol::nil);
}
Expand All @@ -1208,12 +1215,26 @@ void ReGenny::reset_lua_state() {
return sol::make_object(s, wp);
}
#endif

return sol::make_object(s, rg->process().get());
},
"add_address_resolver", [](sol::this_state s, ReGenny* rg, sol::function f) {
return sol::make_object(s, rg->add_address_resolver([f](std::string input) -> uintptr_t {
auto result = f(input);

if (result.get_type(0) == sol::type::number) {
return result.get<uintptr_t>(0);
}

return 0;
}));
},
"remove_address_resolver", [](ReGenny* rg, uint32_t id) {
rg->remove_address_resolver(id);
}
);

auto read_string = [](Process* p, uintptr_t addr, bool perform_strlen) -> std::string {
auto read_string = [](Process* p, uintptr_t addr, bool perform_strlen) -> std::string {
if (!perform_strlen) {
std::vector<uint8_t> bytes(256);
p->read(addr, bytes.data(), bytes.size());
Expand Down Expand Up @@ -1517,7 +1538,7 @@ void ReGenny::parse_file() try {

set_type();
} else {
throw std::runtime_error{"Failed to parse file."};
throw std::runtime_error{"Failed to parse file."};
}
} catch (const std::exception& e) {
spdlog::error(e.what());
Expand Down
18 changes: 18 additions & 0 deletions src/ReGenny.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ class ReGenny {
auto& process() const { return m_process; }
auto address() const { return m_address; }

auto add_address_resolver(std::function<uintptr_t(const std::string&)> resolver) {
auto id = m_address_resolvers.size();
m_address_resolvers[id] = std::move(resolver);
return id;
}
auto remove_address_resolver(uint32_t id) { m_address_resolvers.erase(id); }
auto query_address_resolvers(const std::string& name) {
auto addresses = std::vector<uintptr_t>{};
for (auto& resolver : m_address_resolvers | std::views::values) {
if (auto address = resolver(name)) {
addresses.push_back(address);
}
}

return addresses;
}

auto& eval_history_index() { return m_eval_history_index; }
auto& eval_history() const { return m_eval_history; }

Expand All @@ -53,6 +70,7 @@ class ReGenny {
uintptr_t m_address{};
bool m_is_address_valid{};
ParsedAddress m_parsed_address{};
std::map<uint32_t, std::function<uintptr_t(const std::string&)>> m_address_resolvers{};
std::chrono::steady_clock::time_point m_next_address_refresh_time{};

struct {
Expand Down
2 changes: 1 addition & 1 deletion src/node/Array.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <fmt/format.h>
#include <imgui.h>
#include <utf8.h>
#include <utf8cpp/utf8.h>

#include "Pointer.hpp"
#include "Struct.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/node/Pointer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <fmt/format.h>
#include <imgui.h>
#include <utf8.h>
#include <utf8cpp/utf8.h>

#include "Array.hpp"
#include "Struct.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/node/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <fmt/format.h>
#include <imgui.h>
#include <utf8.h>
#include <utf8cpp/utf8.h>

#include "Variable.hpp"

Expand Down

0 comments on commit 0fe8a34

Please sign in to comment.