diff --git a/CMakeLists.txt b/CMakeLists.txt index e730477..4de87ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ add_compile_definitions( ) add_subdirectory(include) -add_subdirectory(src/thunker) +add_subdirectory(src/mc) add_subdirectory(src/client) if (MSVC) diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index c7f2110..4cb52d6 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -2,48 +2,33 @@ cmake_minimum_required(VERSION 3.28) project(selaura_client LANGUAGES CXX) add_library(selaura_client SHARED - main.cpp - client.cpp - platform/platform.cpp - memory/sdk/gui/ScreenView.cpp - memory/sdk/world/BaseLightTextureImageBuilder.cpp - memory/sdk/world/Dimension.cpp - memory/sdk/game/uri/GameArguments.cpp - memory/sdk/renderer/screen/MinecraftUIRenderContext.cpp - memory/sdk/renderer/bgfx/bgfx.cpp - memory/sdk/core/RenderItemInHandDescription.cpp - memory/sdk/client/ClientInstanceScreenModel.cpp - memory/sdk/game/ClientInstance.cpp - memory/sdk/game/MinecraftGame.cpp - memory/sdk/network/LoopbackPacketSender.cpp - memory/sdk/network/Packet.cpp - feature/impl/render/fullbright.cpp - feature/impl/render/paperdoll.cpp - feature/impl/render/enchant_glint.cpp - feature/impl/render/environment.cpp - command/impl/enable_command.cpp - command/impl/disable_command.cpp + dllmain.cpp + components/client.cpp + memory/scanner.cpp + memory/scan_target.cpp + memory/handle.cpp + patches/patch_manager.cpp ) target_include_directories(selaura_client PRIVATE - fmt - EnTT - spdlog - libhat - gsl - glm - safetyhook - glaze - magic_enum + fmt + EnTT + spdlog + libhat + gsl + glm + safetyhook + glaze + magic_enum ) target_link_libraries(selaura_client PRIVATE - EnTT::EnTT - spdlog - libhat - Microsoft.GSL::GSL - glm - safetyhook::safetyhook - glaze::glaze - magic_enum::magic_enum + EnTT::EnTT + spdlog + libhat + Microsoft.GSL::GSL + glm + safetyhook::safetyhook + glaze::glaze + magic_enum::magic_enum ) \ No newline at end of file diff --git a/src/client/api/stt.hpp b/src/client/api/stt.hpp new file mode 100644 index 0000000..73d602d --- /dev/null +++ b/src/client/api/stt.hpp @@ -0,0 +1,72 @@ +#pragma once +#include +#include + +namespace stt { + template + struct fn_traits; + + template + struct fn_traits { + using ret_t = Ret; + using args_t = std::tuple; + static constexpr bool is_member = false; + }; + + template + struct fn_traits { + using ret_t = Ret; + using class_t = Class; + using args_t = std::tuple; + static constexpr bool is_member = true; + }; + + template + struct fn_traits { + using ret_t = Ret; + using class_t = Class; + using args_t = std::tuple; + static constexpr bool is_member = true; + }; + + template + struct fn_traits : fn_traits {}; + + template + struct extends { + static constexpr bool value = std::is_base_of_v; + using type = Derived; + }; + + template + struct extends>> { + using traits = fn_traits; + static_assert(!std::is_void_v, "Member function pointer must have a class type"); + static constexpr bool value = std::is_base_of_v; + using type = Derived; + }; + + template + using extends_t = typename extends::type; + + template + constexpr bool extends_v = extends::value; + + template + struct is_callable : std::false_type {}; + + template + struct is_callable> : std::true_type {}; + + template + constexpr bool is_callable_v = is_callable::value; + + template + using ret_type_t = typename fn_traits::ret_t; + + template + using args_type_t = typename fn_traits::args_t; + + template + constexpr bool is_member_callable_v = fn_traits::is_member; +}; \ No newline at end of file diff --git a/src/client/client.cpp b/src/client/client.cpp deleted file mode 100644 index 12f6a93..0000000 --- a/src/client/client.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "client.hpp" - -#include "config/types.hpp" -#include "magic_enum/magic_enum_utility.hpp" -#include "memory/patcher.hpp" -#include "memory/sdk/network/PacketHandlerDispatcherInstance.hpp" - -namespace selaura { - void client::init() { - try { - auto start = std::chrono::steady_clock::now(); - - auto sink = std::make_shared(); - auto logger = std::make_shared("client_logger", sink); - spdlog::set_default_logger(logger); - - spdlog::set_pattern("[%T] [client/%^%l%$] %v"); - spdlog::flush_on(spdlog::level::info); - - selaura::patch_fns< - &MinecraftGame::update_hk, - &Dimension::Dimension_ctor_hk, - &mce::framebuilder::RenderItemInHandDescription::RenderItemInHandDescription_ctor_hk, - &ScreenView::setupAndRender_hk, - &BaseLightTextureImageBuilder::createBaseLightTextureData_hk, - &NetherLightTextureImageBuilder::createBaseLightTextureData_hk, - &GameArguments::_onUri_hk, - &Dimension::getTimeOfDay_hk, - &bgfx::d3d11::RendererContextD3D11::submit_hk, - &bgfx::d3d12::RendererContextD3D12::submit_hk, - &ClientInstanceScreenModel::executeCommand_hk, - &LoopbackPacketSender::send_hk - >(); - - magic_enum::enum_for_each([](auto val) { - constexpr MinecraftPacketIds id = val; - - const auto pkt = selaura::call_original<&MinecraftPackets::createPacket>(id); - if (!pkt) return; - - Packet* packet = pkt.get(); - selaura::patch_vtable_fn<&PacketHandlerDispatcherInstance::handle>(packet->mHandler, 1); - }); - - auto end = std::chrono::steady_clock::now(); - auto ms = std::chrono::duration(end - start).count(); - - spdlog::info("Completed injection in {} ms.", static_cast(ms)); - spdlog::info("Write \"help\" in the command line to see a list of commands."); - } catch (const std::exception& e) { - spdlog::info("std::exception: {}\n", e.what()); - this->unload(); - } catch (...) { - spdlog::info("Unknown exception occurred."); - this->unload(); - } - } - - void client::unload() { - } -}; \ No newline at end of file diff --git a/src/client/client.hpp b/src/client/client.hpp deleted file mode 100644 index eb647bf..0000000 --- a/src/client/client.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once -#include -#include -#include -#include - -#include -#include - -#include "event/event_manager.hpp" -#include "feature/feature_manager.hpp" -#include "command/command_handler.hpp" -#include "memory/signatures.hpp" - -#include "memory/sdk/game/MinecraftGame.hpp" - -namespace selaura { - template - concept one_of = (std::same_as || ...); - - template - struct client_base : std::enable_shared_from_this> { - using subsystems_tuple_t = std::tuple; - - client_base() : subsystems{} {} - - template - requires one_of - constexpr T& get() { - return std::get(subsystems); - } - - private: - subsystems_tuple_t subsystems; - }; - - - struct client : public client_base { - void init(); - void unload(); - }; - - inline std::shared_ptr& get() { - static std::shared_ptr instance = std::make_shared(); - return instance; - } - - inline MinecraftGame* minecraftGame; -}; \ No newline at end of file diff --git a/src/client/command/command.hpp b/src/client/command/command.hpp deleted file mode 100644 index 0150aae..0000000 --- a/src/client/command/command.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include -#include -#include -#include - -namespace selaura { - template - struct command_traits { - static constexpr auto command = hat::fixed_string { "unknown" }; - }; - - template - struct command { - virtual ~command() = default; - using details = command_traits; - - virtual const std::string execute(std::vector arguments) = 0; - }; -}; \ No newline at end of file diff --git a/src/client/command/command_handler.hpp b/src/client/command/command_handler.hpp deleted file mode 100644 index 779e71b..0000000 --- a/src/client/command/command_handler.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include - -#include "impl/disable_command.hpp" -#include "impl/enable_command.hpp" - -namespace selaura { - struct command_handler { - using default_commands_t = std::tuple< - enable_command, - disable_command - >; - - inline std::string execute(std::string_view command_str) { - std::istringstream stream(std::string{command_str}); - std::string verb; - stream >> verb; - - if (verb.empty()) - return "§cNo command entered."; - - std::vector args; - for (std::string arg; stream >> arg;) - args.emplace_back(std::move(arg)); - - return std::apply([&](auto&... cmds) -> std::string { - std::string result = "§cUnknown command: " + verb; - (..., ( - [&] { - using T = std::decay_t; - constexpr auto name = std::string_view{ command_traits::command.c_str() }; - - if (verb == name) - result = cmds.execute(args); - }() - )); - return result; - }, default_commands); - } - - private: - default_commands_t default_commands; - }; -}; \ No newline at end of file diff --git a/src/client/command/impl/disable_command.cpp b/src/client/command/impl/disable_command.cpp deleted file mode 100644 index 5b1ba1c..0000000 --- a/src/client/command/impl/disable_command.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "disable_command.hpp" - -#include -#include -#include -#include -#include -#include "../../client.hpp" - -namespace selaura { - const std::string disable_command::execute(std::vector arguments) { - if (arguments.empty()) - return "§cIncorrect syntax: .disable [module_name ...]"; - - auto& feature_manager = selaura::get()->get(); - std::vector disabled_modules; - - feature_manager.for_each([&](std::shared_ptr& f) { - const std::string_view name = selaura::feature_traits::name; - - auto it = std::ranges::find_if(arguments, [&](const std::string& arg) { - return arg.size() == name.size() && - std::equal(arg.begin(), arg.end(), name.begin(), name.end(), - [](char a, char b) { - return std::tolower(static_cast(a)) == - std::tolower(static_cast(b)); - }); - }); - - if (it != arguments.end()) { - f->set_enabled(false); - disabled_modules.emplace_back(name); - } - }); - - if (disabled_modules.empty()) { - return "§cNo matching modules found to disable."; - } - - std::string joined; - for (size_t i = 0; i < disabled_modules.size(); ++i) { - joined += disabled_modules[i]; - if (i + 1 < disabled_modules.size()) { - joined += ", "; - } - } - - return std::format("§aSuccessfully disabled modules: {}", joined); - } -} diff --git a/src/client/command/impl/disable_command.hpp b/src/client/command/impl/disable_command.hpp deleted file mode 100644 index bee58b9..0000000 --- a/src/client/command/impl/disable_command.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "../command.hpp" - -namespace selaura { - struct disable_command; - - template <> - struct command_traits { - static constexpr auto command = hat::fixed_string{ "disable" }; - }; - - struct disable_command : command { - virtual const std::string execute(std::vector arguments) override; - }; -}; \ No newline at end of file diff --git a/src/client/command/impl/enable_command.cpp b/src/client/command/impl/enable_command.cpp deleted file mode 100644 index 61b4abd..0000000 --- a/src/client/command/impl/enable_command.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "enable_command.hpp" - -#include -#include -#include -#include -#include -#include "../../client.hpp" - -namespace selaura { - const std::string enable_command::execute(std::vector arguments) { - if (arguments.empty()) - return "§cIncorrect syntax: .enable [module_name ...]"; - - auto& feature_manager = selaura::get()->get(); - std::vector enabled_modules; - - feature_manager.for_each([&](std::shared_ptr& f) { - const std::string_view name = selaura::feature_traits::name; - - auto it = std::ranges::find_if(arguments, [&](const std::string& arg) { - return arg.size() == name.size() && - std::equal(arg.begin(), arg.end(), name.begin(), name.end(), - [](char a, char b) { - return std::tolower(static_cast(a)) == - std::tolower(static_cast(b)); - }); - }); - - if (it != arguments.end()) { - f->set_enabled(true); - enabled_modules.emplace_back(name); - } - }); - - if (enabled_modules.empty()) { - return "§cNo matching modules found to enable."; - } - - std::string joined; - for (size_t i = 0; i < enabled_modules.size(); ++i) { - joined += enabled_modules[i]; - if (i + 1 < enabled_modules.size()) { - joined += ", "; - } - } - - return std::format("§aSuccessfully enabled modules: {}", joined); - } -} diff --git a/src/client/command/impl/enable_command.hpp b/src/client/command/impl/enable_command.hpp deleted file mode 100644 index c2656ec..0000000 --- a/src/client/command/impl/enable_command.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "../command.hpp" - -namespace selaura { - struct enable_command; - - template <> - struct command_traits { - static constexpr auto command = hat::fixed_string{ "enable" }; - }; - - struct enable_command : command { - virtual const std::string execute(std::vector arguments) override; - }; -}; \ No newline at end of file diff --git a/src/client/components/client.cpp b/src/client/components/client.cpp new file mode 100644 index 0000000..4934671 --- /dev/null +++ b/src/client/components/client.cpp @@ -0,0 +1,43 @@ +#pragma once +#include "client.hpp" + +alignas (selaura::client) char selaura_buffer[sizeof(selaura::client)]; + +namespace selaura { + client& get() { + return *std::launder(reinterpret_cast(selaura_buffer)); + } + + client::client() { + auto start = std::chrono::high_resolution_clock::now(); + + auto sink = std::make_shared(); + auto logger = std::make_shared("client_logger", sink); + spdlog::set_default_logger(logger); + + spdlog::set_pattern("[%T] [client/%^%l%$] %v"); + spdlog::flush_on(spdlog::level::info); + + this->get().init(); + + if (this->get().invalid_signatures) { + this->m_running = false; + return; + } + + + spdlog::info("d: {}", selaura::signature_runtime_value<&IMinecraftGame::update>::value); + + auto end = std::chrono::high_resolution_clock::now(); + auto ms = std::chrono::duration_cast(end - start).count(); + + spdlog::info("Injected [{}ms]", ms); + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + this->m_running = false; + } + + client::~client() { + + } +}; \ No newline at end of file diff --git a/src/client/components/client.hpp b/src/client/components/client.hpp new file mode 100644 index 0000000..93d8d62 --- /dev/null +++ b/src/client/components/client.hpp @@ -0,0 +1,29 @@ +#pragma once +#include "component.hpp" +#include +#include + +namespace selaura { + struct client { + client(); + ~client(); + + template + constexpr auto& get() { + return std::get(m_components); + } + + std::atomic m_running = true; + private: + selaura::components_t m_components{}; + }; + + client& get(); + + template + constexpr auto get() { + return selaura::get().get(); + } +}; + +extern char selaura_buffer[sizeof(selaura::client)]; \ No newline at end of file diff --git a/src/client/components/component.hpp b/src/client/components/component.hpp new file mode 100644 index 0000000..fb5a1f0 --- /dev/null +++ b/src/client/components/component.hpp @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include + +#include "client.hpp" +#include "../memory/scanner.hpp" + +namespace selaura { + struct client; + + struct component : std::enable_shared_from_this { + virtual ~component() = default; + std::atomic m_running = true; + std::weak_ptr owner; + }; + + using components_t = std::tuple; +}; \ No newline at end of file diff --git a/src/client/config/serializer.hpp b/src/client/config/serializer.hpp deleted file mode 100644 index 1a43916..0000000 --- a/src/client/config/serializer.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#include "types.hpp" - diff --git a/src/client/config/types.hpp b/src/client/config/types.hpp deleted file mode 100644 index 8429bdd..0000000 --- a/src/client/config/types.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include "../feature/feature.hpp" - -template -struct glz::meta> { - static constexpr auto value = glz::object( - &selaura::feature::get_name, "name", - &selaura::feature::get_description, "description", - &selaura::feature::is_enabled, "enabled", - &selaura::feature::get_hotkey, "hotkey", - &selaura::feature::settings, "settings" - ); -}; - -template <> -struct glz::meta> { - static constexpr auto value = glz::object( - &selaura::feature_setting::name, "name", - &selaura::feature_setting::value, "value", - &selaura::feature_setting::minimum_value, "min", - &selaura::feature_setting::maximum_value, "max", - &selaura::feature_setting::step, "step" - ); -}; - -template <> -struct glz::meta> { - static constexpr auto value = glz::object( - &selaura::feature_setting::name, "name", - &selaura::feature_setting::value, "value" - ); -}; - -template <> -struct glz::meta> { - static constexpr auto value = glz::object( - &selaura::feature_setting::name, "name", - &selaura::feature_setting::value, "value" - ); -}; - -template <> -struct glz::meta { - static constexpr auto value = glz::array( - &glm::vec4::x, &glm::vec4::y, &glm::vec4::z, &glm::vec4::w - ); -}; diff --git a/src/client/dllmain.cpp b/src/client/dllmain.cpp new file mode 100644 index 0000000..a11591b --- /dev/null +++ b/src/client/dllmain.cpp @@ -0,0 +1,43 @@ +#pragma once + +#ifdef SELAURA_WINDOWS +#include +#include +#include +#include + +#include "components/client.hpp" + +DWORD WINAPI start(LPVOID lpParam) { +//#ifdef _DEBUG + AllocConsole(); + + AttachConsole(GetCurrentProcessId()); + SetConsoleTitleA("Selaura Client Console"); + + FILE* fp; + freopen_s(&fp, "CONOUT$", "w", stdout); + freopen_s(&fp, "CONOUT$", "w", stderr); + freopen_s(&fp, "CONIN$", "r", stdin); +//#endif + + new (selaura_buffer) selaura::client(); + + while (selaura::get().m_running) { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + + selaura::get().~client(); + FreeLibraryAndExitThread(static_cast(lpParam), 1); +} + +BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) { + if (dwReason == DLL_PROCESS_ATTACH) { + DisableThreadLibraryCalls(hModule); + CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)start, hModule, 0, nullptr); + } + + else if (dwReason == DLL_PROCESS_DETACH) spdlog::info("Ejected"); + return TRUE; +} +#endif \ No newline at end of file diff --git a/src/client/event/event_manager.hpp b/src/client/event/event_manager.hpp deleted file mode 100644 index c5371db..0000000 --- a/src/client/event/event_manager.hpp +++ /dev/null @@ -1,172 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace selaura { - struct event_manager { - using subscription_token = std::uint64_t; - - template - using listener_t = std::function; - - template - struct listener_container { - struct listener_entry { - subscription_token token; - std::function callback; - void* instance = nullptr; - union { - void (*static_fn)(T&) = nullptr; - void* member_fn; - }; - }; - std::vector listeners; - subscription_token nextToken = 1; - std::mutex mutex; - }; - - template - void dispatch(T& event) { - auto& container = get_listener_container(); - std::vector::listener_entry> listenersCopy; - { - std::lock_guard lock(container.mutex); - listenersCopy = container.listeners; - } - for (const auto& entry : listenersCopy) { - entry.callback(event); - } - } - - template - void dispatch() { - T event{}; - dispatch(event); - } - - template - subscription_token subscribe(std::function listener) { - auto& container = get_listener_container(); - std::lock_guard lock(container.mutex); - subscription_token token = container.nextToken++; - typename listener_container::listener_entry entry; - entry.token = token; - entry.callback = listener; - entry.instance = nullptr; - entry.static_fn = listener; - - container.listeners.push_back(std::move(entry)); - - return token; - } - - template - subscription_token subscribe(Func listener) { - return subscribe(listener_t{listener}); - } - - template - subscription_token subscribe(void (C::* listener)(T&), C* instance) { - auto& container = get_listener_container(); - std::lock_guard lock(container.mutex); - subscription_token token = container.nextToken++; - typename listener_container::listener_entry entry; - entry.token = token; - entry.callback = [instance, listener](T& event) { (instance->*listener)(event); }; - entry.instance = static_cast(instance); - entry.member_fn = *reinterpret_cast(&listener); - - container.listeners.push_back(std::move(entry)); - - return token; - } - - template - void unsubscribe(const std::function& listener) { - auto& container = get_listener_container(); - std::lock_guard lock(container.mutex); - auto& entries = container.listeners; - - for (auto it = entries.begin(); it != entries.end(); ++it) { - if (it->instance != nullptr) - continue; - if (it->callback.target_type() != listener.target_type()) - continue; - if (auto ptr1 = it->callback.template target()) { - if (auto ptr2 = listener.template target()) { - if (*ptr1 == *ptr2) { - entries.erase(it); - return; - } - } - } - if (it->callback.template target() == listener.template target()) { - entries.erase(it); - return; - } - } - } - - template - void unsubscribe(Func listener) { - unsubscribe(listener_t{listener}); - } - - template - void unsubscribe(void (C::* listener)(T&), C* instance) { - auto& container = get_listener_container(); - std::lock_guard lock(container.mutex); - auto& entries = container.listeners; - - void* targetInstance = static_cast(instance); - void* targetMemberFunc = *reinterpret_cast(&listener); - - for (auto it = entries.begin(); it != entries.end(); ++it) { - if (it->instance == targetInstance && it->member_fn == targetMemberFunc) { - entries.erase(it); - return; - } - } - } - - template - subscription_token subscribe(void (*listener)(T&)) { - auto& container = get_listener_container(); - std::lock_guard lock(container.mutex); - subscription_token token = container.nextToken++; - container.listeners.push_back({ - token, - listener, - nullptr, - listener - }); - return token; - } - - template - void unsubscribe(void (*listener)(T&)) { - auto& container = get_listener_container(); - std::lock_guard lock(container.mutex); - auto& entries = container.listeners; - - for (auto it = entries.begin(); it != entries.end(); ++it) { - if (it->static_fn == listener && it->instance == nullptr) { - entries.erase(it); - return; - } - } - } - - private: - template - listener_container& get_listener_container() { - static listener_container container; - return container; - } - }; -} diff --git a/src/client/event/event_types.hpp b/src/client/event/event_types.hpp deleted file mode 100644 index 0f03f1d..0000000 --- a/src/client/event/event_types.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -#include "../memory/sdk/world/BaseLightTextureImageBuilder.hpp" -#include "../memory/sdk/renderer/screen/MinecraftUIRenderContext.hpp" -#include "../memory/sdk/network/Packet.hpp" -#include - -namespace selaura { - struct cancellable_event { - void cancel() { - this->cancelled = true; - } - - bool cancelled; - }; - - struct BaseLightTextureImageBuilder_event { - bool mNightvisionActive; - float mNightvisionScale; - }; - - struct RenderCustom_event { - gsl::not_null component; - }; - - struct RenderItemInHandDescription_event { - glm::vec3 color; - float alpha; - }; - - struct getTimeOfDay_event { - int time; - float overriden_time; - }; - - struct PacketRecieved_event { - Packet* packet; - }; - - struct PacketSent_event { - Packet* packet; - }; -}; \ No newline at end of file diff --git a/src/client/feature/feature.hpp b/src/client/feature/feature.hpp deleted file mode 100644 index 191971c..0000000 --- a/src/client/feature/feature.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once -#include -#include - -#include "setting.hpp" - -namespace selaura { - template - struct feature_traits { - static constexpr auto name = hat::fixed_string { "Unknown" }; - static constexpr auto description = hat::fixed_string { "Unknown" }; - - using settings = std::tuple<>; - }; - - template - struct feature { - virtual ~feature() = default; - using details = feature_traits; - using settings_type = typename details::settings; - - void set_enabled(bool state = true) { - this->enabled = state; - - if (this->enabled) { - on_enable(); - } else { - on_disable(); - } - } - [[nodiscard]] bool is_enabled() const { - return this->enabled; - } - - void toggle() { - set_enabled(!this->enabled); - } - - void set_hotkey(int hotkey = 0) { - this->hotkey = hotkey; - } - - [[nodiscard]] int get_hotkey() const { - return this->hotkey; - } - - virtual void on_enable() = 0; - virtual void on_disable() = 0; - settings_type settings{}; - private: - bool enabled = false; - int hotkey = 0; - }; -}; \ No newline at end of file diff --git a/src/client/feature/feature_manager.hpp b/src/client/feature/feature_manager.hpp deleted file mode 100644 index ab80ec0..0000000 --- a/src/client/feature/feature_manager.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#pragma once -#include -#include -#include -#include - -#include "impl/render/fullbright.hpp" -#include "impl/render/paperdoll.hpp" -#include "impl/render/enchant_glint.hpp" -#include "impl/render/environment.hpp" - -namespace selaura { - using feature_types = std::tuple< - fullbright, - paperdoll, - enchant_glint, - environment - >; - - template - auto make_features_impl(std::index_sequence) { - return std::make_tuple(std::make_shared>()...); - } - - template - auto make_features() { - constexpr auto size = std::tuple_size_v; - return make_features_impl(std::make_index_sequence{}); - } - - class feature_manager { - public: - using features_t = decltype(make_features()); - - feature_manager() - : features(make_features()) - {} - - template - void enable() { - if (auto f = get()) { - f->set_enabled(true); - } - } - - template - void disable() { - if (auto f = get()) { - f->set_enabled(false); - } - } - - template - std::shared_ptr get() { - return std::get>(features); - } - - features_t get_features() { - return features; - } - - template - void for_each(Func&& func) { - std::apply([&](std::shared_ptr&... ptrs) { - (func.template operator()(ptrs), ...); - }, features); - } - - private: - features_t features; - }; - -} diff --git a/src/client/feature/impl/render/enchant_glint.cpp b/src/client/feature/impl/render/enchant_glint.cpp deleted file mode 100644 index 0758328..0000000 --- a/src/client/feature/impl/render/enchant_glint.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "enchant_glint.hpp" -#include "../../../client.hpp" - -namespace selaura { - void enchant_glint::on_enable() { - auto& evm = selaura::get()->get(); - evm.subscribe(&enchant_glint::on_renderiteminhanddescription_event, this); - } - - void enchant_glint::on_disable() { - auto& evm = selaura::get()->get(); - evm.unsubscribe(&enchant_glint::on_renderiteminhanddescription_event, this); - } - - glm::vec4 enchant_glint::get_chroma_color(float speed, float saturation, float value) { - using clock = std::chrono::steady_clock; - using seconds_f = std::chrono::duration; - - float time = std::chrono::duration_cast(clock::now().time_since_epoch()).count(); - float hue = std::fmod(time * speed * 60.0f, 360.0f); - - float c = value * saturation; - float x = c * (1.0f - std::abs(std::fmod(hue / 60.0f, 2.0f) - 1.0f)); - float m = value - c; - - float r = 0, g = 0, b = 0; - switch (static_cast(hue / 60.0f)) { - case 0: r = c; g = x; b = 0; break; - case 1: r = x; g = c; b = 0; break; - case 2: r = 0; g = c; b = x; break; - case 3: r = 0; g = x; b = c; break; - case 4: r = x; g = 0; b = c; break; - case 5: r = c; g = 0; b = x; break; - } - - return glm::vec4(r + m, g + m, b + m, 1.0f); - } - - void enchant_glint::on_renderiteminhanddescription_event(selaura::RenderItemInHandDescription_event &event) { - auto& color = std::get<0>(this->settings).value; - auto& chroma = std::get<1>(this->settings).value; - auto& chroma_speed = std::get<2>(this->settings).value; - - if (chroma) { - auto chroma_col = get_chroma_color(chroma_speed); - event.color = { chroma_col.r, chroma_col.g, chroma_col.b }; - event.alpha = chroma_col.a; - } else { - event.color = {color.r / 255, color.g / 255, color.b / 255}; - event.alpha = color.a; - } - } - -}; \ No newline at end of file diff --git a/src/client/feature/impl/render/enchant_glint.hpp b/src/client/feature/impl/render/enchant_glint.hpp deleted file mode 100644 index d63b041..0000000 --- a/src/client/feature/impl/render/enchant_glint.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once -#include "../../feature.hpp" -#include "../../../event/event_types.hpp" -#include "spdlog/spdlog.h" - -namespace selaura { - - struct enchant_glint; - - template <> - struct feature_traits { - static constexpr auto name = hat::fixed_string{ "Enchantment Glint" }; - static constexpr auto description = hat::fixed_string{ "Modifies the color of the enchantment glint on items" }; - - using settings = std::tuple< - selaura::feature_setting, - selaura::feature_setting, - selaura::feature_setting - >; - }; - - struct enchant_glint : feature { - enchant_glint() { - std::get<0>(this->settings) = selaura::feature_setting("Color", {73, 36, 116, 1}); - std::get<1>(this->settings) = selaura::feature_setting("Chroma", true); - std::get<2>(this->settings) = selaura::feature_setting("Chroma Speeding", 1.0f, 0.0f, 5.0f, 0.1f); - } - - void on_enable() override; - void on_disable() override; - glm::vec4 get_chroma_color(float speed = 1.0f, float saturation = 1.0f, float value = 1.0f); - void on_renderiteminhanddescription_event(selaura::RenderItemInHandDescription_event& event); - }; - -}; \ No newline at end of file diff --git a/src/client/feature/impl/render/environment.cpp b/src/client/feature/impl/render/environment.cpp deleted file mode 100644 index 865330e..0000000 --- a/src/client/feature/impl/render/environment.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "environment.hpp" -#include "../../../client.hpp" - -namespace selaura { - void environment::on_enable() { - auto& evm = selaura::get()->get(); - evm.subscribe(&environment::on_timeofday_event, this); - } - - void environment::on_disable() { - auto& evm = selaura::get()->get(); - evm.unsubscribe(&environment::on_timeofday_event, this); - } - - void environment::on_timeofday_event(selaura::getTimeOfDay_event &event) { - auto& time = std::get<0>(this->settings).value; - auto& time_passage_speed_bool = std::get<1>(this->settings).value; - auto& time_passage_speed = std::get<2>(this->settings).value; - - if (time_passage_speed_bool) { - event.time *= time_passage_speed; - } else { - event.overriden_time = time; - } - } - -}; \ No newline at end of file diff --git a/src/client/feature/impl/render/environment.hpp b/src/client/feature/impl/render/environment.hpp deleted file mode 100644 index e888ee4..0000000 --- a/src/client/feature/impl/render/environment.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once -#include "../../feature.hpp" -#include "../../../event/event_types.hpp" -#include "spdlog/spdlog.h" - -namespace selaura { - - struct environment; - - template <> - struct feature_traits { - static constexpr auto name = hat::fixed_string{ "Environment" }; - static constexpr auto description = hat::fixed_string{ "Modifies in-game environment" }; - - using settings = std::tuple< - selaura::feature_setting, - selaura::feature_setting, - selaura::feature_setting - >; - }; - - struct environment : feature { - environment() { - std::get<0>(this->settings) = selaura::feature_setting("Time", 0.5f, 0.0f, 1.0f); - std::get<1>(this->settings) = selaura::feature_setting("Change Time Passage Speed", false); - std::get<2>(this->settings) = selaura::feature_setting("Time Passage Speed", 50.0f, 0.0f, 100.f); - } - - void on_enable() override; - void on_disable() override; - void on_timeofday_event(selaura::getTimeOfDay_event& event); - }; - -}; diff --git a/src/client/feature/impl/render/fullbright.cpp b/src/client/feature/impl/render/fullbright.cpp deleted file mode 100644 index 0243eb3..0000000 --- a/src/client/feature/impl/render/fullbright.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "fullbright.hpp" -#include "../../../client.hpp" - -namespace selaura { - void fullbright::on_enable() { - auto& evm = selaura::get()->get(); - evm.subscribe(&fullbright::on_baselighttextureimagebuilder_event, this); - } - - void fullbright::on_disable() { - auto& evm = selaura::get()->get(); - evm.unsubscribe(&fullbright::on_baselighttextureimagebuilder_event, this); - } - - void fullbright::on_baselighttextureimagebuilder_event(selaura::BaseLightTextureImageBuilder_event &event) { - auto& brightness = std::get<0>(this->settings).value; - - event.mNightvisionActive = true; - event.mNightvisionScale = brightness; - } - -}; \ No newline at end of file diff --git a/src/client/feature/impl/render/fullbright.hpp b/src/client/feature/impl/render/fullbright.hpp deleted file mode 100644 index aecc338..0000000 --- a/src/client/feature/impl/render/fullbright.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include "../../feature.hpp" -#include "../../../event/event_types.hpp" -#include "spdlog/spdlog.h" - -namespace selaura { - - struct fullbright; - - template <> - struct feature_traits { - static constexpr auto name = hat::fixed_string{ "Fullbright" }; - static constexpr auto description = hat::fixed_string{ "Maximizes world brightness" }; - - using settings = std::tuple< - selaura::feature_setting - >; - }; - - struct fullbright : feature { - fullbright() { - auto& brightness = std::get<0>(this->settings); - brightness = selaura::feature_setting("Brightness", 1.0f, 0.0f, 1.0f); - } - - void on_enable() override; - void on_disable() override; - void on_baselighttextureimagebuilder_event(selaura::BaseLightTextureImageBuilder_event& event); - }; - -}; diff --git a/src/client/feature/impl/render/paperdoll.cpp b/src/client/feature/impl/render/paperdoll.cpp deleted file mode 100644 index 4f68ba5..0000000 --- a/src/client/feature/impl/render/paperdoll.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "paperdoll.hpp" -#include "../../../client.hpp" - -namespace selaura { - void paperdoll::on_enable() { - auto& evm = selaura::get()->get(); - evm.subscribe(&paperdoll::on_rendercustom_event, this); - } - - void paperdoll::on_disable() { - auto& evm = selaura::get()->get(); - evm.unsubscribe(&paperdoll::on_rendercustom_event, this); - } - - void paperdoll::on_rendercustom_event(selaura::RenderCustom_event &event) { - auto& always_show = std::get<0>(this->settings).value; - auto& x = std::get<1>(this->settings).value; - auto& y = std::get<2>(this->settings).value; - - if (always_show && event.component->mOwner->name == "hud_player") { - HudPlayerRenderer* renderer = reinterpret_cast(event.component->renderer); - renderer->mRenderTime = 1.0f; - - event.component->mOwner->position.x = x; - event.component->mOwner->position.y = y; - } - } - -}; \ No newline at end of file diff --git a/src/client/feature/impl/render/paperdoll.hpp b/src/client/feature/impl/render/paperdoll.hpp deleted file mode 100644 index 3b91021..0000000 --- a/src/client/feature/impl/render/paperdoll.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once -#include "../../feature.hpp" -#include "../../../event/event_types.hpp" -#include "spdlog/spdlog.h" - -namespace selaura { - - struct paperdoll; - - template <> - struct feature_traits { - static constexpr auto name = hat::fixed_string{ "Paperdoll" }; - static constexpr auto description = hat::fixed_string{ "Modifies in-game paperdoll" }; - - using settings = std::tuple< - selaura::feature_setting, - selaura::feature_setting, - selaura::feature_setting - >; - }; - - struct paperdoll : feature { - paperdoll() { - std::get<0>(this->settings) = selaura::feature_setting("Always Show", true); - std::get<1>(this->settings) = selaura::feature_setting("Offset X", 15.0f); - std::get<2>(this->settings) = selaura::feature_setting("Offset Y", 15.0f); - } - - void on_enable() override; - void on_disable() override; - void on_rendercustom_event(selaura::RenderCustom_event& event); - }; - -}; diff --git a/src/client/feature/setting.hpp b/src/client/feature/setting.hpp deleted file mode 100644 index f1fe7dc..0000000 --- a/src/client/feature/setting.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once -#include -#include - -namespace selaura { - template - struct feature_setting; - - template <> - struct feature_setting { - feature_setting() = default; - std::string name; - - float value; - float minimum_value; - float maximum_value; - float step; - - feature_setting(std::string name, float default_value, float min = 0.0f, float max = 1.0f, float step = 1.0f) - : name(std::move(name)), value(default_value), minimum_value(min), maximum_value(max) {} - - }; - - template <> - struct feature_setting { - feature_setting() = default; - std::string name; - - bool value; - - feature_setting(std::string name, bool default_value) - : name(std::move(name)), value(default_value) {} - - }; - - template <> - struct feature_setting { - feature_setting() = default; - std::string name; - - glm::vec4 value; - - feature_setting(std::string name, glm::vec4 default_value) - : name(std::move(name)), value(default_value) {} - - }; -}; \ No newline at end of file diff --git a/src/client/main.cpp b/src/client/main.cpp deleted file mode 100644 index ee47f70..0000000 --- a/src/client/main.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include - -#include "client.hpp" -#include "platform/platform.hpp" - - -void init() { -#ifdef SELAURA_WINDOWS - AllocConsole(); - - AttachConsole(GetCurrentProcessId()); - SetConsoleTitleA("Selaura Client Console"); - - FILE* fp; - freopen_s(&fp, "CONOUT$", "w", stdout); - freopen_s(&fp, "CONOUT$", "w", stderr); - freopen_s(&fp, "CONIN$", "r", stdin); -#endif - selaura::get()->init(); -} - -#ifdef SELAURA_WINDOWS -BOOL APIENTRY DllMain(HMODULE hmodule, DWORD dw_reason, LPVOID lp_reserved) { - if (dw_reason == DLL_PROCESS_ATTACH) { - const auto& handle = selaura::get_dynamic_module("Minecraft.Windows.exe"); - if (!handle.valid()) return false; - DisableThreadLibraryCalls(static_cast(handle.native_handle)); - - std::thread(&init).detach(); - } - return true; -} -#endif - -#ifdef SELAURA_LINUX -extern "C" [[gnu::visibility("default")]] void mod_init() { - std::thread(&init).detach(); -} -#endif \ No newline at end of file diff --git a/src/client/memory/handle.cpp b/src/client/memory/handle.cpp new file mode 100644 index 0000000..5715e64 --- /dev/null +++ b/src/client/memory/handle.cpp @@ -0,0 +1,27 @@ +#include "handle.hpp" +#ifdef SELAURA_WINDOWS +#include +#include +#endif + +namespace selaura { + std::shared_ptr get_handle(std::string_view name) { + void* ptr; + std::span bytes; + +#ifdef SELAURA_WINDOWS + auto win_handle = GetModuleHandleA(name.data()); + ptr = reinterpret_cast(win_handle); + + MODULEINFO info; + if (!GetModuleInformation(GetCurrentProcess(), win_handle, &info, sizeof(info))) std::terminate(); + + bytes = { + reinterpret_cast(info.lpBaseOfDll), + info.SizeOfImage + }; +#endif + + return std::make_shared(ptr, bytes); + } +}; \ No newline at end of file diff --git a/src/client/memory/handle.hpp b/src/client/memory/handle.hpp new file mode 100644 index 0000000..97fc50e --- /dev/null +++ b/src/client/memory/handle.hpp @@ -0,0 +1,14 @@ +#pragma once +#include +#include +#include +#include + +namespace selaura { + struct handle { + void* ptr{}; + std::span bytes; + }; + + std::shared_ptr get_handle(std::string_view name); +}; \ No newline at end of file diff --git a/src/client/memory/patcher.hpp b/src/client/memory/patcher.hpp deleted file mode 100644 index 00b42fa..0000000 --- a/src/client/memory/patcher.hpp +++ /dev/null @@ -1,207 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -#include -#include "signatures.hpp" -#include "spdlog/spdlog.h" - -namespace selaura { - template - struct as_void_ptr; - - template - struct as_void_ptr { - static void* get() { return reinterpret_cast(Fn); } - }; - - template - struct as_void_ptr { - static void* get() { -#ifdef SELAURA_WINDOWS - union { - Ret(Class::*mpf)(Args...); - void* ptr; - } u{ Fn }; - return u.ptr; -#else - void* out = nullptr; - std::memcpy(&out, &Fn, sizeof(void*)); - return out; -#endif - } - }; - - template - struct as_void_ptr { - static void* get() { -#ifdef SELAURA_WINDOWS - union { - Ret(Class::*mpf)(Args...) const; - void* ptr; - } u{ Fn }; - return u.ptr; -#else - void* out = nullptr; - std::memcpy(&out, &Fn, sizeof(void*)); - return out; -#endif - } - }; - - template - struct fn_traits; - - template - struct fn_traits { - using return_type = Ret; - }; - - template - struct fn_traits { - using return_type = Ret; - }; - - template - struct fn_traits { - using return_type = Ret; - }; - - template - struct fn_pointer_traits; - - template - struct fn_pointer_traits { - using pointer_type = Ret(*)(Args...); - }; - - template - struct fn_pointer_traits { - using pointer_type = Ret(Class::*)(Args...); - }; - - template - struct fn_pointer_traits { - using pointer_type = Ret(Class::*)(Args...) const; - }; - - template - struct to_free_function; - - template - struct to_free_function { - using type = Ret(*)(Class*, Args...); - }; - - template - struct to_free_function { - using type = Ret(*)(const Class*, Args...); - }; - - - inline std::unordered_map hook_map; - - template - constexpr std::size_t fn_hash() { - if constexpr (std::is_pointer_v) { - return reinterpret_cast(fn); - } else if constexpr (std::is_member_function_pointer_v) { - std::size_t hash = 0xcbf29ce484222325; - const unsigned char* p = reinterpret_cast(&fn); - for (std::size_t i = 0; i < sizeof(fn); ++i) { - hash ^= p[i]; - hash *= 0x100000001b3; - } - return hash; - } else { - static_assert([] { return false; }(), "Unsupported Fn type in fn_hash"); - } - } - - template - void patch_fn(void* target) { - auto key = fn_hash(); - auto it = hook_map.find(key); - if (it == hook_map.end()) { - auto [inserted, _] = hook_map.emplace(key, - safetyhook::create_inline( - target, - selaura::as_void_ptr::get() - ) - ); - } - } - - template - void patch_fn() { - void* target = reinterpret_cast(selaura::resolve_signature()); - if (hook_map.contains(fn_hash())) return; - - auto hook = safetyhook::create_inline(target, selaura::as_void_ptr::get()); - hook_map.emplace(fn_hash(), std::move(hook)); - } - - template - void patch_vtable_fn(vptr* vtable, std::size_t index) { - void** obj = *reinterpret_cast(const_cast(static_cast(vtable))); - patch_fn(obj[index]); - } - - template - decltype(auto) call_fn(Args&&... args) { - using fn_t = decltype(fn); - using pointer_t = typename fn_pointer_traits::pointer_type; - - auto key = fn_hash(); - auto it = hook_map.find(key); - if (it == hook_map.end()) - throw std::runtime_error("Hook not found"); - - auto trampoline = it->second.trampoline().address(); - - pointer_t original; - std::memcpy(&original, &trampoline, sizeof(trampoline)); - - return std::invoke(original, std::forward(args)...); - } - - template - decltype(auto) call_original(Args&&... args) { - using fn_t = decltype(fn); - using pointer_t = typename selaura::fn_pointer_traits::pointer_type; - - void* target = reinterpret_cast(selaura::resolve_signature()); - pointer_t original; - std::memcpy(&original, &target, sizeof(original)); - - return std::invoke(original, std::forward(args)...); - } - - template - void patch_fns() { - auto futures = std::array{ - std::async(std::launch::async, [] { patch_fn(); })... - }; - - for (auto& fut : futures) { - fut.wait(); - } - } - - template - Ret call_virtual(T* instance, std::size_t index, Args&&... args) { - using Method = Ret(T::*)(Args...); - - void** vtable = *reinterpret_cast(instance); - void* func = vtable[index]; - - Method method; - std::memcpy(&method, &func, sizeof(void*)); - - return std::invoke(method, instance, std::forward(args)...); - } - -} diff --git a/src/client/memory/patterns/android/patterns.hpp b/src/client/memory/patterns/android/patterns.hpp new file mode 100644 index 0000000..c65d558 --- /dev/null +++ b/src/client/memory/patterns/android/patterns.hpp @@ -0,0 +1,17 @@ +#pragma once +#include "../../scan_target.hpp" +#include + +void hi(); + +namespace selaura { + template <> + struct scan_target<&hi, scanner_type::signature> { // MinecraftGame::update + constexpr static hat::fixed_string signature = "? ? ? FC ? ? ? A9 ? ? ? 91 ? ? ? A9 ? ? ? A9 ? ? ? A9 ? ? ? A9 ? ? ? A9 ? ? ? D1 ? ? ? D5 F3 03 00 AA ? ? ? F9 ? ? ? F8 ? ? ? F9 ? ? ? 95"; + constexpr static auto value = hat::compile_signature(); + }; + + using signature_types = std::tuple< + scan_target<&hi, scanner_type::signature> + >; +}; \ No newline at end of file diff --git a/src/client/memory/patterns/win/patterns.hpp b/src/client/memory/patterns/win/patterns.hpp new file mode 100644 index 0000000..b02fc4d --- /dev/null +++ b/src/client/memory/patterns/win/patterns.hpp @@ -0,0 +1,18 @@ +#pragma once +#include "../../scan_target.hpp" +#include +#include + +#include "../../mc/game/IMinecraftGame.hpp" + +namespace selaura { + template <> + struct scan_target<&IMinecraftGame::update, scanner_type::signature> { + constexpr static hat::fixed_string signature = "48 8B C4 48 89 58 10 48 89 70 18 48 89 78 20 55 41 54 41 55 41 56 41 57 48 8D A8 F8 F6"; + constexpr static auto value = hat::compile_signature(); + }; + + using signature_types = std::tuple< + scan_target<&IMinecraftGame::update, scanner_type::signature> + >; +}; \ No newline at end of file diff --git a/src/client/memory/scan_target.cpp b/src/client/memory/scan_target.cpp new file mode 100644 index 0000000..a31107f --- /dev/null +++ b/src/client/memory/scan_target.cpp @@ -0,0 +1,7 @@ +#include "scan_target.hpp" + +#ifdef SELAURA_WINDOWS +#include "patterns/win/patterns.hpp" +#elif SELAURA_LINUX + +#endif \ No newline at end of file diff --git a/src/client/memory/scan_target.hpp b/src/client/memory/scan_target.hpp new file mode 100644 index 0000000..906543c --- /dev/null +++ b/src/client/memory/scan_target.hpp @@ -0,0 +1,33 @@ +#pragma once +#include + +namespace selaura { + struct game_version { + int major; + int minor; + int patch; + + constexpr bool operator==(const game_version&) const = default; + }; + + enum class scanner_type : std::uint8_t { + signature, + offset + }; + + template + struct scan_target {}; + + template + struct scan_target_traits; + + template + struct scan_target_traits> { + static constexpr auto value = fn; + }; + + template + struct signature_runtime_value { + inline static std::uintptr_t value = 0; + }; +} diff --git a/src/client/memory/scanner.cpp b/src/client/memory/scanner.cpp new file mode 100644 index 0000000..4cad21f --- /dev/null +++ b/src/client/memory/scanner.cpp @@ -0,0 +1,28 @@ +#include "scanner.hpp" + +namespace selaura { + void scanner::start_scanning_thread() { + this->m_scanning_thread = std::thread([this]() { + this->game_handle = selaura::get_handle( +#ifdef SELAURA_WINDOWS + "Minecraft.Windows.exe" +#else + "libminecraftpe.so" +#endif + ); + this->resolve_all_async(signatures); + }); + } + + void scanner::kill_scanning_thread() { + if (this->m_scanning_thread.joinable()) { + this->m_scanning_thread.join(); + } + m_scanning_thread = std::thread(); + } + + void scanner::init() { + this->start_scanning_thread(); + this->kill_scanning_thread(); + } +}; \ No newline at end of file diff --git a/src/client/memory/scanner.hpp b/src/client/memory/scanner.hpp new file mode 100644 index 0000000..28db771 --- /dev/null +++ b/src/client/memory/scanner.hpp @@ -0,0 +1,75 @@ +#pragma once +#include +#include +#include + +#include +#include + +#include "handle.hpp" +#include "scan_target.hpp" + +#ifdef SELAURA_WINDOWS +#include "patterns/win/patterns.hpp" +#elif SELAURA_LINUX +#elif SELAURA_ANDROID +#include "patterns/android/patterns.hpp" +#endif + +template +constexpr std::string_view extract_type_name(std::string_view full) { + auto start = full.find('<') + 1; + auto end = full.rfind('>'); + return full.substr(start, end - start); +} + +template +constexpr std::string_view type_name() { +#if defined(__clang__) || defined(__GNUC__) + constexpr std::string_view func = __PRETTY_FUNCTION__; +#elif defined(_MSC_VER) + constexpr std::string_view func = __FUNCSIG__; +#else + return "unknown"; +#endif + return extract_type_name(func); +} + +namespace selaura { + struct scanner { + template + void resolve_signature() { + auto result = hat::find_pattern(this->game_handle->bytes, T::value); + + constexpr auto fn = scan_target_traits::value; + signature_runtime_value::value = reinterpret_cast(result.get()); + + if (signature_runtime_value::value == 0) { + spdlog::error("Invalid signature for function, gracefully ejecting!"); + spdlog::error("Broken signature was: {}", T::signature.c_str()); + this->invalid_signatures = true; + } + } + + template + void resolve_all_async(std::tuple&) { + std::vector> futures; + + (futures.emplace_back(std::async(std::launch::async, [this]() { + resolve_signature(); + })), ...); + + for (auto& fut : futures) fut.get(); + } + + void start_scanning_thread(); + void kill_scanning_thread(); + void init(); + + bool invalid_signatures = false; + private: + std::thread m_scanning_thread; + signature_types signatures{}; + std::shared_ptr game_handle; + }; +}; \ No newline at end of file diff --git a/src/client/memory/sdk/client/ClientInstanceScreenModel.cpp b/src/client/memory/sdk/client/ClientInstanceScreenModel.cpp deleted file mode 100644 index 6688243..0000000 --- a/src/client/memory/sdk/client/ClientInstanceScreenModel.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "./ClientInstanceScreenModel.hpp" -#include "../../patcher.hpp" - -void ClientInstanceScreenModel::executeCommand_hk(const std::string& command_line) { - selaura::call_fn<&ClientInstanceScreenModel::executeCommand_hk>(this, command_line); -} diff --git a/src/client/memory/sdk/client/ClientInstanceScreenModel.hpp b/src/client/memory/sdk/client/ClientInstanceScreenModel.hpp deleted file mode 100644 index f856483..0000000 --- a/src/client/memory/sdk/client/ClientInstanceScreenModel.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include - -struct ClientInstanceScreenModel -{ - void executeCommand_hk(const std::string& command_line); -}; diff --git a/src/client/memory/sdk/core/RenderItemInHandDescription.cpp b/src/client/memory/sdk/core/RenderItemInHandDescription.cpp deleted file mode 100644 index a91a798..0000000 --- a/src/client/memory/sdk/core/RenderItemInHandDescription.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "RenderItemInHandDescription.hpp" -#include "../../patcher.hpp" -#include "../../../client.hpp" -#include "../../../event/event_types.hpp" - -namespace mce::framebuilder { - void* RenderItemInHandDescription::RenderItemInHandDescription_ctor_hk(void* renderObject, void* itemFlags, void* material, void* glintTexture, void* worldMatrix, bool isDrawingUI, void* globalConstantBuffers, unsigned __int16 viewId, void* renderMetadata) { - auto data = selaura::call_fn<&RenderItemInHandDescription::RenderItemInHandDescription_ctor_hk>(this, renderObject, itemFlags, material, glintTexture, worldMatrix, isDrawingUI, globalConstantBuffers, viewId, renderMetadata); - - selaura::RenderItemInHandDescription_event event{ this->mGlintColor, this->mGlintAlpha }; - auto& ev = selaura::get()->get(); - ev.dispatch(event); - - this->mGlintColor = event.color; - this->mGlintAlpha = event.alpha; - - return data; - } -} diff --git a/src/client/memory/sdk/core/RenderItemInHandDescription.hpp b/src/client/memory/sdk/core/RenderItemInHandDescription.hpp deleted file mode 100644 index ce2bec9..0000000 --- a/src/client/memory/sdk/core/RenderItemInHandDescription.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include -#include - -namespace mce::framebuilder { - struct RenderItemInHandDescription { - std::byte pad[0x8C]; - glm::vec3 mGlintColor; - float mGlintAlpha; - glm::vec3 mOverlayColor; - float mOverlayAlpha; - glm::vec3 mChangeColor; - float mChangeAlpha; - glm::vec3 mMultiplicativeTintColor; - float mMultiplicativeTintColorAlpha; - - void* RenderItemInHandDescription_ctor_hk(void* renderObject, void* itemFlags, void* material, void* glintTexture, void* worldMatrix, bool isDrawingUI, void* globalConstantBuffers, unsigned __int16 viewId, void* renderMetadata); - }; -}; \ No newline at end of file diff --git a/src/client/memory/sdk/core/math/Color.hpp b/src/client/memory/sdk/core/math/Color.hpp deleted file mode 100644 index efe393b..0000000 --- a/src/client/memory/sdk/core/math/Color.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -namespace mce { - struct Color { - float r; - float g; - float b; - float a; - - Color(float r, float g, float b, float a) { - this->r = r; - this->g = g; - this->b = b; - this->a = a; - } - - Color(unsigned int color) { - this->r = static_cast((color & 0xFF000000) >> 24) / 255.0f; - this->g = static_cast((color & 0x00FF0000) >> 16) / 255.0f; - this->b = static_cast((color & 0x0000FF00) >> 8) / 255.0f; - this->a = static_cast((color & 0x000000FF)) / 255.0f; - } - - Color() { - this->r = 0.0f; - this->g = 0.0f; - this->b = 0.0f; - this->a = 0.0f; - } - }; -}; diff --git a/src/client/memory/sdk/game/ClientInstance.cpp b/src/client/memory/sdk/game/ClientInstance.cpp deleted file mode 100644 index c5dbef9..0000000 --- a/src/client/memory/sdk/game/ClientInstance.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "ClientInstance.hpp" - diff --git a/src/client/memory/sdk/game/ClientInstance.hpp b/src/client/memory/sdk/game/ClientInstance.hpp deleted file mode 100644 index 0c7c3ce..0000000 --- a/src/client/memory/sdk/game/ClientInstance.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -#include "../gui/gui/GuiData.hpp" - -struct ClientInstance { - std::byte pad[0x5B8]; - GuiData* guiData; -}; diff --git a/src/client/memory/sdk/game/MinecraftGame.cpp b/src/client/memory/sdk/game/MinecraftGame.cpp deleted file mode 100644 index 9d94e0d..0000000 --- a/src/client/memory/sdk/game/MinecraftGame.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "MinecraftGame.hpp" - -#include - -#include "../../patcher.hpp" -#include "../../../client.hpp" - -void MinecraftGame::update_hk() { - selaura::minecraftGame = this; - return selaura::call_fn<&MinecraftGame::update_hk>(this); -} - -ClientInstance* MinecraftGame::getPrimaryClientInstance() { - return clientInstance_map->at(0).get(); -} \ No newline at end of file diff --git a/src/client/memory/sdk/game/MinecraftGame.hpp b/src/client/memory/sdk/game/MinecraftGame.hpp deleted file mode 100644 index 3527b5d..0000000 --- a/src/client/memory/sdk/game/MinecraftGame.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include -#include -#include - -#include "ClientInstance.hpp" - -struct MinecraftGame { - std::byte pad[0x8F8]; - std::map>* clientInstance_map; - - void update_hk(); - ClientInstance* getPrimaryClientInstance(); -}; diff --git a/src/client/memory/sdk/game/uri/GameArguments.cpp b/src/client/memory/sdk/game/uri/GameArguments.cpp deleted file mode 100644 index da825ac..0000000 --- a/src/client/memory/sdk/game/uri/GameArguments.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "GameArguments.hpp" -#include "../../../patcher.hpp" - -void GameArguments::_onUri_hk(ActivationUri* uri) { - //if (uri->verb == "selaura") std::terminate(); - selaura::call_fn<&GameArguments::_onUri_hk>(this, uri); -} \ No newline at end of file diff --git a/src/client/memory/sdk/game/uri/GameArguments.hpp b/src/client/memory/sdk/game/uri/GameArguments.hpp deleted file mode 100644 index 0d09e88..0000000 --- a/src/client/memory/sdk/game/uri/GameArguments.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once -#include -#include - -struct ActivationUri { - std::string verb; - std::unordered_map arguments; -}; - -struct GameArguments { - void _onUri_hk(ActivationUri* uri); -}; \ No newline at end of file diff --git a/src/client/memory/sdk/gui/ScreenView.cpp b/src/client/memory/sdk/gui/ScreenView.cpp deleted file mode 100644 index bebdcb4..0000000 --- a/src/client/memory/sdk/gui/ScreenView.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "ScreenView.hpp" -#include "../../patcher.hpp" -#include "../renderer/screen/MinecraftUIRenderContext.hpp" - -void ScreenView::setupAndRender_hk(void* renderContext) { - static bool once = false; - if (!once && renderContext) { - selaura::patch_vtable_fn<&MinecraftUIRenderContext::renderCustom_hk>(renderContext, 26); - once = true; - } - - selaura::call_fn<&ScreenView::setupAndRender_hk>(this, renderContext); -} diff --git a/src/client/memory/sdk/gui/ScreenView.hpp b/src/client/memory/sdk/gui/ScreenView.hpp deleted file mode 100644 index 612d933..0000000 --- a/src/client/memory/sdk/gui/ScreenView.hpp +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -struct ScreenView { - void setupAndRender_hk(void* renderContext); -}; \ No newline at end of file diff --git a/src/client/memory/sdk/gui/controls/UIComponent.hpp b/src/client/memory/sdk/gui/controls/UIComponent.hpp deleted file mode 100644 index 198d187..0000000 --- a/src/client/memory/sdk/gui/controls/UIComponent.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "../gui/UIControl.hpp" - -class UIComponent { -public: - class UIControl* mOwner; - virtual void Function0(); -}; \ No newline at end of file diff --git a/src/client/memory/sdk/gui/controls/renderers/HudPlayerRenderer.hpp b/src/client/memory/sdk/gui/controls/renderers/HudPlayerRenderer.hpp deleted file mode 100644 index 9484e4a..0000000 --- a/src/client/memory/sdk/gui/controls/renderers/HudPlayerRenderer.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -struct HudPlayerRenderer { - std::byte pad[16]; -public: - float mRenderTime; - float mTick; -}; \ No newline at end of file diff --git a/src/client/memory/sdk/gui/controls/renderers/SplashTextRenderer.hpp b/src/client/memory/sdk/gui/controls/renderers/SplashTextRenderer.hpp deleted file mode 100644 index cc56722..0000000 --- a/src/client/memory/sdk/gui/controls/renderers/SplashTextRenderer.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include -#include - -#include "../../../renderer/screen/MinecraftUIRenderContext.hpp" - -struct SplashTextRenderer { - std::byte pad[0x20]; -public: - int mCurrentSplash; -private: - std::byte pad2[0xC]; -public: - std::vector mSplashes; -}; \ No newline at end of file diff --git a/src/client/memory/sdk/gui/gui/GuiData.hpp b/src/client/memory/sdk/gui/gui/GuiData.hpp deleted file mode 100644 index 4079ecd..0000000 --- a/src/client/memory/sdk/gui/gui/GuiData.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include -#include -#include - -#include "GuiMessage.hpp" - -struct GuiData { - std::byte pad[0x150]; - std::vector mGuiMessages; - - inline void displayClientMessage(const std::string& message, std::optional a2 = {}, bool a3 = false); -}; diff --git a/src/client/memory/sdk/gui/gui/GuiMessage.hpp b/src/client/memory/sdk/gui/gui/GuiMessage.hpp deleted file mode 100644 index 0e29fd3..0000000 --- a/src/client/memory/sdk/gui/gui/GuiMessage.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include -#include - -class GuiMessage { -public: - GuiMessage() = default; - std::byte pad[0x8]; - std::string mMessage; - std::byte pad2[0x24]; - std::string mTTSMessage; - std::string mUsername; - std::string mFullString; - std::byte pad3[0x24]; - std::string xuid; - std::byte pad4[0xA]; -}; \ No newline at end of file diff --git a/src/client/memory/sdk/gui/gui/UIControl.hpp b/src/client/memory/sdk/gui/gui/UIControl.hpp deleted file mode 100644 index 3b52847..0000000 --- a/src/client/memory/sdk/gui/gui/UIControl.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include -#include - -#include - -class UIControl { - std::byte pad[0x10]; -public: - glm::vec2 position; - uint64_t flags; - std::string name; -private: - std::byte pad2[0x8]; -public: - glm::vec2 bounds; -}; \ No newline at end of file diff --git a/src/client/memory/sdk/network/IPacketHandlerDispatcher.hpp b/src/client/memory/sdk/network/IPacketHandlerDispatcher.hpp deleted file mode 100644 index 72381d9..0000000 --- a/src/client/memory/sdk/network/IPacketHandlerDispatcher.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include - -struct Packet; - -struct IPacketHandlerDispatcher { - virtual ~IPacketHandlerDispatcher() = default; - virtual void handle(void* networkIdentifier, void* netEventCallback, std::shared_ptr&) const = 0; -}; diff --git a/src/client/memory/sdk/network/LoopbackPacketSender.cpp b/src/client/memory/sdk/network/LoopbackPacketSender.cpp deleted file mode 100644 index 3faa999..0000000 --- a/src/client/memory/sdk/network/LoopbackPacketSender.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "LoopbackPacketSender.hpp" -#include "../../patcher.hpp" -#include "../../../client.hpp" -#include "../../../event/event_types.hpp" - -#include "packet/TextPacket.hpp" - -void LoopbackPacketSender::send_hk(Packet* packet) { - selaura::PacketSent_event event{ packet }; - auto& ev = selaura::get()->get(); - ev.dispatch(event); - - if (packet->getId() == MinecraftPacketIds::Text) { - auto text_packet = reinterpret_cast(packet); - auto guiData = selaura::minecraftGame->getPrimaryClientInstance()->guiData; - - if (text_packet->mMessage.starts_with(".")) { - auto command = text_packet->mMessage.substr(1); - auto& command_handler = selaura::get()->get(); - - return selaura::call_original<&GuiData::displayClientMessage>(guiData, command_handler.execute(command), std::nullopt, false); - } - } - - return selaura::call_fn<&LoopbackPacketSender::send_hk>(this, packet); -} diff --git a/src/client/memory/sdk/network/LoopbackPacketSender.hpp b/src/client/memory/sdk/network/LoopbackPacketSender.hpp deleted file mode 100644 index 0d3859b..0000000 --- a/src/client/memory/sdk/network/LoopbackPacketSender.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once -#include "Packet.hpp" - -struct LoopbackPacketSender { - void send_hk(Packet* packet); -}; \ No newline at end of file diff --git a/src/client/memory/sdk/network/MinecraftPacketIds.hpp b/src/client/memory/sdk/network/MinecraftPacketIds.hpp deleted file mode 100644 index f48ed6e..0000000 --- a/src/client/memory/sdk/network/MinecraftPacketIds.hpp +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -enum class MinecraftPacketIds : int { - Text = 9 -}; diff --git a/src/client/memory/sdk/network/MinecraftPackets.hpp b/src/client/memory/sdk/network/MinecraftPackets.hpp deleted file mode 100644 index d42c1ec..0000000 --- a/src/client/memory/sdk/network/MinecraftPackets.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include -#include "Packet.hpp" - -struct MinecraftPackets { - static inline std::shared_ptr createPacket(MinecraftPacketIds id); -}; diff --git a/src/client/memory/sdk/network/Packet.cpp b/src/client/memory/sdk/network/Packet.cpp deleted file mode 100644 index ab6bf66..0000000 --- a/src/client/memory/sdk/network/Packet.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "Packet.hpp" -#include "../../patcher.hpp" - -MinecraftPacketIds Packet::getId() { - return selaura::call_virtual(this, 1); -} \ No newline at end of file diff --git a/src/client/memory/sdk/network/PacketHandlerDispatcherInstance.hpp b/src/client/memory/sdk/network/PacketHandlerDispatcherInstance.hpp deleted file mode 100644 index 095b73a..0000000 --- a/src/client/memory/sdk/network/PacketHandlerDispatcherInstance.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include - -#include "MinecraftPacketIds.hpp" -#include "packet/TextPacket.hpp" - -#include "../../patcher.hpp" -#include "../../../client.hpp" - -template -struct PacketHandlerDispatcherInstance; - -template <> -struct PacketHandlerDispatcherInstance { - void handle(void* networkIdentifier, void* netEventCallback, const std::shared_ptr& packet) { - selaura::call_fn<&PacketHandlerDispatcherInstance::handle>(this, networkIdentifier, netEventCallback, packet); - } -}; \ No newline at end of file diff --git a/src/client/memory/sdk/network/TextPacketType.hpp b/src/client/memory/sdk/network/TextPacketType.hpp deleted file mode 100644 index 2d3a0fb..0000000 --- a/src/client/memory/sdk/network/TextPacketType.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -enum class TextPacketType : int { - Raw = 0, - Chat = 1, - Translate = 2, - Popup = 3, - Jukebox = 4, - Tip = 5, - SystemMessage = 6, - Whisper = 7, - Announcement = 8, - TextObjectWhisper = 9, - TextObject = 10, - TextObjectAnnouncement = 11 -}; \ No newline at end of file diff --git a/src/client/memory/sdk/network/packet/TextPacket.hpp b/src/client/memory/sdk/network/packet/TextPacket.hpp deleted file mode 100644 index eb2ed41..0000000 --- a/src/client/memory/sdk/network/packet/TextPacket.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "../Packet.hpp" -#include "TextPacketType.hpp" - -struct TextPacket : public Packet { - TextPacketType mType; - std::string mAuthor; - std::string mMessage; - std::vector params; - bool mLocalize = false; - std::string mXuid; - std::string mPlatformId; - - TextPacket() = default; -}; \ No newline at end of file diff --git a/src/client/memory/sdk/renderer/bgfx/bgfx.cpp b/src/client/memory/sdk/renderer/bgfx/bgfx.cpp deleted file mode 100644 index 6b59ba8..0000000 --- a/src/client/memory/sdk/renderer/bgfx/bgfx.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "bgfx.hpp" -#include "../../../patcher.hpp" -#include - -#ifdef SELAURA_WINDOWS -void bgfx::d3d11::RendererContextD3D11::submit_hk(void *a1, void *a2, void *a3) { - selaura::call_fn<&bgfx::d3d11::RendererContextD3D11::submit_hk>(this, a1, a2, a3); -} - -void bgfx::d3d12::RendererContextD3D12::submit_hk(void *a1, void *a2, void *a3) { - selaura::call_fn<&bgfx::d3d12::RendererContextD3D12::submit_hk>(this, a1, a2, a3); -} -#endif \ No newline at end of file diff --git a/src/client/memory/sdk/renderer/bgfx/bgfx.hpp b/src/client/memory/sdk/renderer/bgfx/bgfx.hpp deleted file mode 100644 index 7bce6df..0000000 --- a/src/client/memory/sdk/renderer/bgfx/bgfx.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#ifdef SELAURA_WINDOWS -#include -#include -#include -#include -#endif - -#include - -namespace bgfx { -#ifdef SELAURA_WINDOWS - namespace d3d11 { - struct RendererContextD3D11 { - std::byte pad[0x228]; - IDXGISwapChain* swapChain; - - void submit_hk(void* a1, void* a2, void* a3); - }; - }; - namespace d3d12 { - struct RendererContextD3D12 { - std::byte pad[0x152]; - IDXGISwapChain* swapChain; - - void submit_hk(void* a1, void* a2, void* a3); - }; - }; -#endif -}; \ No newline at end of file diff --git a/src/client/memory/sdk/renderer/screen/MinecraftUIRenderContext.cpp b/src/client/memory/sdk/renderer/screen/MinecraftUIRenderContext.cpp deleted file mode 100644 index 47b5a91..0000000 --- a/src/client/memory/sdk/renderer/screen/MinecraftUIRenderContext.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "MinecraftUIRenderContext.hpp" -#include "../../../patcher.hpp" -#include "../../../../client.hpp" -#include "../../../../event/event_types.hpp" - -void MinecraftUIRenderContext::renderCustom_hk(gsl::not_null customRender, int pass, RectangleArea* renderAABB) { - selaura::RenderCustom_event event{ customRender }; - auto& ev = selaura::get()->get(); - ev.dispatch(event); - if (customRender->mOwner->name == "splash_text") { - selaura::call_fn<&MinecraftUIRenderContext::renderCustom_hk>(this, customRender, pass, renderAABB); - SplashTextRenderer* renderer = reinterpret_cast(customRender->renderer); - - renderer->mCurrentSplash = 0; - renderer->mSplashes[0] = "\u00a76Selaura Client \u00a76on top!\u00a7r"; - } - else if (customRender->mOwner->name == "vignette_rend") { - selaura::call_fn<&MinecraftUIRenderContext::renderCustom_hk>(this, customRender, pass, renderAABB); - } - else { - selaura::call_fn<&MinecraftUIRenderContext::renderCustom_hk>(this, customRender, pass, renderAABB); - } -} \ No newline at end of file diff --git a/src/client/memory/sdk/renderer/screen/MinecraftUIRenderContext.hpp b/src/client/memory/sdk/renderer/screen/MinecraftUIRenderContext.hpp deleted file mode 100644 index b66864b..0000000 --- a/src/client/memory/sdk/renderer/screen/MinecraftUIRenderContext.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include -#include - -#include "../../gui/controls/UIComponent.hpp" -#include "../../gui/controls/renderers/HudPlayerRenderer.hpp" -#include "../../gui/controls/renderers/SplashTextRenderer.hpp" - -class MinecraftCustomUIRenderer {}; - -struct RectangleArea { - float _x0; - float _x1; - float _y0; - float _y1; -}; - -class CustomRenderComponent : public UIComponent { - std::byte pad[8]; -public: - MinecraftCustomUIRenderer* renderer; -}; - -struct MinecraftUIRenderContext { - void renderCustom_hk(gsl::not_null customRender, int pass, RectangleArea* renderAABB); -}; \ No newline at end of file diff --git a/src/client/memory/sdk/world/BaseLightTextureImageBuilder.cpp b/src/client/memory/sdk/world/BaseLightTextureImageBuilder.cpp deleted file mode 100644 index b71ff90..0000000 --- a/src/client/memory/sdk/world/BaseLightTextureImageBuilder.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "BaseLightTextureImageBuilder.hpp" -#include "../../patcher.hpp" -#include "../../../client.hpp" -#include "../../../event/event_types.hpp" - -std::unique_ptr BaseLightTextureImageBuilder::createBaseLightTextureData_hk(void* clientInstance, const BaseLightData* base_light_data) { - auto data = selaura::call_fn<&BaseLightTextureImageBuilder::createBaseLightTextureData_hk>(this, clientInstance, base_light_data); - - selaura::BaseLightTextureImageBuilder_event event{ data->mNightvisionActive, data->mNightvisionScale }; - auto& ev = selaura::get()->get(); - ev.dispatch(event); - - data->mNightvisionActive = event.mNightvisionActive; - data->mNightvisionScale = event.mNightvisionScale; - - return std::move(data); -} - -std::unique_ptr NetherLightTextureImageBuilder::createBaseLightTextureData_hk(void* clientInstance, const BaseLightData* base_light_data) { - auto data = selaura::call_fn<&NetherLightTextureImageBuilder::createBaseLightTextureData_hk>(this, clientInstance, base_light_data); - - selaura::BaseLightTextureImageBuilder_event event{ data->mNightvisionActive, data->mNightvisionScale }; - auto& ev = selaura::get()->get(); - ev.dispatch(event); - - data->mNightvisionActive = event.mNightvisionActive; - data->mNightvisionScale = event.mNightvisionScale; - - return std::move(data); -} \ No newline at end of file diff --git a/src/client/memory/sdk/world/BaseLightTextureImageBuilder.hpp b/src/client/memory/sdk/world/BaseLightTextureImageBuilder.hpp deleted file mode 100644 index dde4bda..0000000 --- a/src/client/memory/sdk/world/BaseLightTextureImageBuilder.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include - -#include "../core/math/Color.hpp" - -struct BaseLightData { - mce::Color mSunriseColor; - float mGamma; - float mSkyDarken; - int mDimensionType; - float mDarkenWorldAmount; - float mPreviousDarkenWorldAmount; - bool mNightvisionActive; - float mNightvisionScale; - bool mUnderwaterVision; - float mUnderwaterScale; - float mSkyFlashTime; -}; - -struct BaseLightTextureImageBuilder { - std::unique_ptr createBaseLightTextureData_hk(void* clientInstance, const BaseLightData* base_light_data); -}; - -struct NetherLightTextureImageBuilder { - std::unique_ptr createBaseLightTextureData_hk(void* clientInstance, const BaseLightData* base_light_data); -}; \ No newline at end of file diff --git a/src/client/memory/sdk/world/Dimension.cpp b/src/client/memory/sdk/world/Dimension.cpp deleted file mode 100644 index b49315f..0000000 --- a/src/client/memory/sdk/world/Dimension.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "Dimension.hpp" -#include "../../patcher.hpp" -#include "../../../client.hpp" -#include "../../../event/event_types.hpp" - -void Dimension::Dimension_ctor_hk(void *level, void *dimId, DimensionHeightRange heightRange, void *callbackContext, std::string *name) { - if (heightRange.mMax == 128) { - heightRange.mMax = 256; // nether roof fix - } - - selaura::call_fn<&Dimension::Dimension_ctor_hk>(this, level, dimId, heightRange, callbackContext, name); -} - - -float Dimension::getTimeOfDay_hk(int time, float a) { - selaura::getTimeOfDay_event event{ time, -1 }; - auto& ev = selaura::get()->get(); - ev.dispatch(event); - - if (event.overriden_time != -1) { - return event.overriden_time; - } else { - return selaura::call_fn<&Dimension::getTimeOfDay_hk>(this, event.time, a); - } -} diff --git a/src/client/memory/sdk/world/Dimension.hpp b/src/client/memory/sdk/world/Dimension.hpp deleted file mode 100644 index 233b05c..0000000 --- a/src/client/memory/sdk/world/Dimension.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include - -struct DimensionHeightRange { - __int16 mMin; - __int16 mMax; -}; - - -struct Dimension { - void Dimension_ctor_hk(void* level, void* dimId, DimensionHeightRange heightRange, void* callbackContext, std::string* name); - float getTimeOfDay_hk(int time, float a); -}; \ No newline at end of file diff --git a/src/client/memory/signatures.hpp b/src/client/memory/signatures.hpp deleted file mode 100644 index d3f756e..0000000 --- a/src/client/memory/signatures.hpp +++ /dev/null @@ -1,118 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -#include -#include - -#include "../platform/platform.hpp" -#include "sdk/core/RenderItemInHandDescription.hpp" -#include "sdk/game/uri/GameArguments.hpp" - -#include "sdk/game/MinecraftGame.hpp" -#include "sdk/gui/ScreenView.hpp" -#include "sdk/renderer/bgfx/bgfx.hpp" -#include "sdk/world/BaseLightTextureImageBuilder.hpp" -#include "sdk/world/Dimension.hpp" -#include "sdk/client/ClientInstanceScreenModel.hpp" -#include "sdk/network/LoopbackPacketSender.hpp" -#include "sdk/network/MinecraftPackets.hpp" - -namespace selaura { - template - struct signature { - static_assert(sizeof(fn) == 0, "signature must be specialized for this tag type"); - }; - - template - constexpr auto get_signature = signature::value; - - template - T resolve_signature(std::string_view module_name = {}) { - static auto& handle = module_name.empty() - ? get_dynamic_module() - : get_dynamic_module(module_name); - - void* address = hat::find_pattern(handle.memory_view, signature::value).get(); - - if (!address) { - spdlog::error("Failed to resolve signature"); - return T{}; - } - - return reinterpret_cast(address); - } - - template <> - struct selaura::signature<&ScreenView::setupAndRender_hk> { - static constexpr auto value = hat::compile_signature<"48 8B C4 48 89 58 18 55 56 57 41 54 41 55 41 56 41 57 48 8D A8 98 FD">(); - }; - - template <> - struct selaura::signature<&BaseLightTextureImageBuilder::createBaseLightTextureData_hk> { - static constexpr auto value = hat::compile_signature<"48 89 5C 24 ? 48 89 54 24 ? 55 56 57 41 56 41 57 48 83 EC 40 4D 8B F1">(); - }; - - template <> - struct selaura::signature<&NetherLightTextureImageBuilder::createBaseLightTextureData_hk> { - static constexpr auto value = hat::compile_signature<"48 89 ? ? ? 48 89 ? ? ? 55 56 57 41 ? 41 ? 48 83 EC ? 49 8B ? 49 8B ? 48 8B ? 45 33">(); - }; - - template <> - struct selaura::signature<&GameArguments::_onUri_hk> { - static constexpr auto value = hat::compile_signature<"48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D AC 24 ? ? ? ? B8 ? ? ? ? E8 ? ? ? ? 48 2B E0 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4C 8B FA 48 8B F1">(); - }; - - template <> - struct selaura::signature<&bgfx::d3d11::RendererContextD3D11::submit_hk> { - static constexpr auto value = hat::compile_signature<"48 8B C4 55 53 56 57 41 54 41 55 41 56 41 57 48 81 EC ? ? ? ?">(); - }; - - template <> - struct selaura::signature<&bgfx::d3d12::RendererContextD3D12::submit_hk> { - static constexpr auto value = hat::compile_signature<"48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D AC 24 ? ? ? ? B8 ? ? ? ? E8 ? ? ? ? 48 2B E0 0F 29 B4 24 ? ? ? ? 0F 29 BC 24 ? ? ? ? 44 0F 29 84 24 ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4C 89 4C 24">(); - }; - - template <> - struct selaura::signature<&Dimension::getTimeOfDay_hk> { - static constexpr auto value = hat::compile_signature<"? ? ? ? ? ? 76 05 F7 EA C1 FA 09 8B C2">(); - }; - - template <> - struct selaura::signature<&Dimension::Dimension_ctor_hk> { - static constexpr auto value = hat::compile_signature<"48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 55 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 41 8B D9 41 8B F8">(); - }; - - template <> - struct selaura::signature<&mce::framebuilder::RenderItemInHandDescription::RenderItemInHandDescription_ctor_hk> { - static constexpr auto value = hat::compile_signature<"48 89 ? ? ? 48 89 ? ? ? 55 56 57 41 ? 41 ? 41 ? 41 ? 48 83 EC ? 4D 8B ? 4D 8B ? 4C 8B ? 48 8B ? 45 33">(); - }; - - template <> - struct selaura::signature<&MinecraftGame::update_hk> { - static constexpr auto value = hat::compile_signature<"48 8B C4 48 89 58 10 48 89 70 18 48 89 78 20 55 41 54 41 55 41 56 41 57 48 8D A8 F8 F6">(); - }; - - template <> - struct selaura::signature<&ClientInstanceScreenModel::executeCommand_hk> { - static constexpr auto value = hat::compile_signature<"48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4C 8B EA 48 8B F1 C7 44 24">(); - }; - - template <> - struct selaura::signature<&MinecraftPackets::createPacket> { - static constexpr auto value = hat::compile_signature<"48 89 5C 24 10 48 89 74 24 18 57 48 83 EC 50 48 8B 05 ? ? ? ? 48 33 C4 48 89 44 24 48 48 8B D9 48 89">(); - }; - - template <> - struct selaura::signature<&GuiData::displayClientMessage> { - static constexpr auto value = hat::compile_signature<"40 55 53 56 57 41 56 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 41 0F B6 ? 49 8B D8">(); - }; - - template <> - struct selaura::signature<&LoopbackPacketSender::send_hk> { - static constexpr auto value = hat::compile_signature<"48 83 EC ? 48 0F BE ? ? 48 83 C0 ? 74 27">(); - }; -}; diff --git a/src/client/patches/patch_manager.cpp b/src/client/patches/patch_manager.cpp new file mode 100644 index 0000000..457b427 --- /dev/null +++ b/src/client/patches/patch_manager.cpp @@ -0,0 +1,6 @@ +#include "patch_manager.hpp" +#include + +namespace selaura { + +}; \ No newline at end of file diff --git a/src/client/patches/patch_manager.hpp b/src/client/patches/patch_manager.hpp new file mode 100644 index 0000000..e7ccff1 --- /dev/null +++ b/src/client/patches/patch_manager.hpp @@ -0,0 +1,20 @@ +#pragma once +#include + +#include +#include + +#include "../api/stt.hpp" +#include "../memory/scan_target.hpp" + +namespace selaura { + + /* the recode plan: + struct selaura::patch<&IMinecraftGame::update> { + static void detour() { + spdlog::info("update called"); + }; + }; + */ + +}; \ No newline at end of file diff --git a/src/client/platform/platform.cpp b/src/client/platform/platform.cpp deleted file mode 100644 index ace0865..0000000 --- a/src/client/platform/platform.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "platform.hpp" - -selaura::dynamic_module& selaura::get_dynamic_module(std::string_view name) { - static dynamic_module mod{}; - if (mod.valid()) return mod; - -#ifdef SELAURA_WINDOWS - HMODULE handle = GetModuleHandleA(name.data()); - if (!handle) return mod; - - MODULEINFO moduleinfo; - if (!GetModuleInformation(GetCurrentProcess(), handle, &moduleinfo, sizeof(moduleinfo))) return mod; - - mod.native_handle = reinterpret_cast(handle); - mod.base_address = reinterpret_cast(moduleinfo.lpBaseOfDll); - mod.size = moduleinfo.SizeOfImage; - - mod.memory_view = std::span{reinterpret_cast(mod.base_address), mod.size}; -#else - void* handle = dlopen(name.data(), RTLD_NOLOAD); - if (!handle) return mod; - - mod.native_handle = reinterpret_cast(handle); - dl_iterate_phdr([](dl_phdr_info* info, size_t, void* mod_ptr) -> int { - auto* out = static_cast(mod_ptr); - if (!info->dlpi_name) return 0; - - if (std::strstr(info->dlpi_name, out->name_match)) { - out->base_address = info->dlpi_addr; - for (int i = 0; i < info->dlpi_phnum; ++i) { - if (info->dlpi_phdr[i].p_type == PT_LOAD) { - out->size = info->dlpi_phdr[i].p_memsz; - break; - } - } - out->memory_view = std::span{ - reinterpret_cast(out->base_address), - out->size - }; - return 1; - } - return 0; - }, &mod); -#endif - - return mod; -} - -selaura::dynamic_module& selaura::get_dynamic_module() { -#ifdef SELAURA_WINDOWS - return get_dynamic_module("Minecraft.Windows.exe"); -#else - return get_dynamic_module("libminecraftpe.so"); -#endif -} diff --git a/src/client/platform/platform.hpp b/src/client/platform/platform.hpp deleted file mode 100644 index ca05a76..0000000 --- a/src/client/platform/platform.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -#include -#include - -#ifdef SELAURA_WINDOWS -#include -#include -#else -#include -#include -#endif - -namespace selaura { - struct dynamic_module { - void* native_handle = nullptr; - std::span memory_view{}; - std::uintptr_t base_address; - std::size_t size; - - constexpr bool valid() const noexcept { - return native_handle != nullptr; - } - - template - constexpr T& at(std::ptrdiff_t offset) const noexcept { - static_assert(std::is_trivially_copyable_v, "T must be trivially copyable"); - return *reinterpret_cast(base_address + offset); - } - }; - - dynamic_module& get_dynamic_module(std::string_view name); - dynamic_module& get_dynamic_module(); -}; \ No newline at end of file diff --git a/src/mc/CMakeLists.txt b/src/mc/CMakeLists.txt new file mode 100644 index 0000000..25f742d --- /dev/null +++ b/src/mc/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.28) +project(mcsdk LANGUAGES CXX) + +add_library(mcsdk mcsdk.cpp) + +target_include_directories(mcsdk PRIVATE + fmt + EnTT + gsl + glm + glaze +) + +target_link_libraries(mcsdk PRIVATE + EnTT::EnTT + Microsoft.GSL::GSL + glm + glaze::glaze +) \ No newline at end of file diff --git a/src/mc/api/typed_storage.hpp b/src/mc/api/typed_storage.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/mc/game/IMinecraftGame.hpp b/src/mc/game/IMinecraftGame.hpp new file mode 100644 index 0000000..d0ee8b6 --- /dev/null +++ b/src/mc/game/IMinecraftGame.hpp @@ -0,0 +1,9 @@ +#pragma once +#include "../mcsdk.hpp" + +class IMinecraftGame { +public: + virtual MCSDK void initialize(int, char**) = 0; + virtual MCSDK ~IMinecraftGame() = default; + virtual MCSDK void update() = 0; +}; \ No newline at end of file diff --git a/src/mc/game/common/SubClientId.hpp b/src/mc/game/common/SubClientId.hpp new file mode 100644 index 0000000..019706d --- /dev/null +++ b/src/mc/game/common/SubClientId.hpp @@ -0,0 +1,12 @@ +#pragma once +#include "../../mcsdk.hpp" + +enum class SubClientId : uint8_t { + Server = 0, + PrimaryClient = 0, + Client2 = 1, + Client3 = 2, + Client4 = 3, + ExtraIdSlotStart = 100, + EditorUI = 101, +}; \ No newline at end of file diff --git a/src/client/memory/sdk/network/Compressibility.hpp b/src/mc/game/network/Compressibility.hpp similarity index 100% rename from src/client/memory/sdk/network/Compressibility.hpp rename to src/mc/game/network/Compressibility.hpp diff --git a/src/mc/game/network/IPacketHandlerDispatcher.hpp b/src/mc/game/network/IPacketHandlerDispatcher.hpp new file mode 100644 index 0000000..0d897b6 --- /dev/null +++ b/src/mc/game/network/IPacketHandlerDispatcher.hpp @@ -0,0 +1,10 @@ +#pragma once +#include "../../mcsdk.hpp" + +class Packet; + +class IPacketHandlerDispatcher { +public: + virtual MCSDK ~IPacketHandlerDispatcher() = default; + virtual MCSDK void handle(const void* networkIdentifier, void* netEventCallback, std::shared_ptr&) const = 0; +}; diff --git a/src/mc/game/network/MinecraftPacketIds.hpp b/src/mc/game/network/MinecraftPacketIds.hpp new file mode 100644 index 0000000..600e827 --- /dev/null +++ b/src/mc/game/network/MinecraftPacketIds.hpp @@ -0,0 +1,236 @@ +#pragma once + +enum class MinecraftPacketIds : int { + KeepAlive = 0, + Login = 1, + PlayStatus = 2, + ServerToClientHandshake = 3, + ClientToServerHandshake = 4, + Disconnect = 5, + ResourcePacksInfo = 6, + ResourcePackStack = 7, + ResourcePackClientResponse = 8, + Text = 9, + SetTime = 10, + StartGame = 11, + AddPlayer = 12, + AddActor = 13, + RemoveActor = 14, + AddItemActor = 15, + ServerPlayerPostMovePosition = 16, + TakeItemActor = 17, + MoveAbsoluteActor = 18, + MovePlayer = 19, + PassengerJumpDeprecated = 20, + UpdateBlock = 21, + AddPainting = 22, + TickSyncDeprecated = 23, + LevelSoundEventV1Deprecated = 24, + LevelEvent = 25, + TileEvent = 26, + ActorEvent = 27, + MobEffect = 28, + UpdateAttributes = 29, + InventoryTransaction = 30, + PlayerEquipment = 31, + MobArmorEquipment = 32, + Interact = 33, + BlockPickRequest = 34, + ActorPickRequest = 35, + PlayerAction = 36, + ActorFallDeprecated = 37, + HurtArmor = 38, + SetActorData = 39, + SetActorMotion = 40, + SetActorLink = 41, + SetHealth = 42, + SetSpawnPosition = 43, + Animate = 44, + Respawn = 45, + ContainerOpen = 46, + ContainerClose = 47, + PlayerHotbar = 48, + InventoryContent = 49, + InventorySlot = 50, + ContainerSetData = 51, + CraftingData = 52, + CraftingEventDeprecated = 53, + GuiDataPickItem = 54, + AdventureSettingsDeprecated = 55, + BlockActorData = 56, + PlayerInputDeprecated = 57, + FullChunkData = 58, + SetCommandsEnabled = 59, + SetDifficulty = 60, + ChangeDimension = 61, + SetPlayerGameType = 62, + PlayerList = 63, + SimpleEvent = 64, + LegacyTelemetryEvent = 65, + SpawnExperienceOrb = 66, + MapData = 67, + MapInfoRequest = 68, + RequestChunkRadius = 69, + ChunkRadiusUpdated = 70, + ItemFrameDropItemDeprecated = 71, + GameRulesChanged = 72, + Camera = 73, + BossEvent = 74, + ShowCredits = 75, + AvailableCommands = 76, + CommandRequest = 77, + CommandBlockUpdate = 78, + CommandOutput = 79, + UpdateTrade = 80, + UpdateEquip = 81, + ResourcePackDataInfo = 82, + ResourcePackChunkData = 83, + ResourcePackChunkRequest = 84, + Transfer = 85, + PlaySound = 86, + StopSound = 87, + SetTitle = 88, + AddBehaviorTree = 89, + StructureBlockUpdate = 90, + ShowStoreOffer = 91, + PurchaseReceipt = 92, + PlayerSkin = 93, + SubclientLogin = 94, + AutomationClientConnect = 95, + SetLastHurtBy = 96, + BookEdit = 97, + NPCRequest = 98, + PhotoTransfer = 99, + ShowModalForm = 100, + ModalFormResponse = 101, + ServerSettingsRequest = 102, + ServerSettingsResponse = 103, + ShowProfile = 104, + SetDefaultGameType = 105, + RemoveObjective = 106, + SetDisplayObjective = 107, + SetScore = 108, + LabTable = 109, + UpdateBlockSynced = 110, + MoveDeltaActor = 111, + SetScoreboardIdentity = 112, + SetLocalPlayerAsInit = 113, + UpdateSoftEnum = 114, + Ping = 115, + BlockPaletteDeprecated = 116, + ScriptCustomEvent = 117, + SpawnParticleEffect = 118, + AvailableActorIDList = 119, + LevelSoundEventV2Deprecated = 120, + NetworkChunkPublisherUpdate = 121, + BiomeDefinitionList = 122, + LevelSoundEvent = 123, + LevelEventGeneric = 124, + LecternUpdate = 125, + VideoStreamConnectDeprecated = 126, + AddEntityDeprecated = 127, + RemoveEntityDeprecated = 128, + ClientCacheStatus = 129, + OnScreenTextureAnimation = 130, + MapCreateLockedCopy = 131, + StructureTemplateDataExportRequest = 132, + StructureTemplateDataExportResponse = 133, + UnusedPlsUseMe = 134, + ClientCacheBlobStatusPacket = 135, + ClientCacheMissResponsePacket = 136, + EducationSettingsPacket = 137, + Emote = 138, + MultiplayerSettingsPacket = 139, + SettingsCommandPacket = 140, + AnvilDamage = 141, + CompletedUsingItem = 142, + NetworkSettings = 143, + PlayerAuthInputPacket = 144, + CreativeContent = 145, + PlayerEnchantOptions = 146, + ItemStackRequest = 147, + ItemStackResponse = 148, + PlayerArmorDamage = 149, + CodeBuilderPacket = 150, + UpdatePlayerGameType = 151, + EmoteList = 152, + PositionTrackingDBServerBroadcast = 153, + PositionTrackingDBClientRequest = 154, + DebugInfoPacket = 155, + PacketViolationWarning = 156, + MotionPredictionHints = 157, + TriggerAnimation = 158, + CameraShake = 159, + PlayerFogSetting = 160, + CorrectPlayerMovePredictionPacket = 161, + ItemRegistryPacket = 162, + FilterTextPacketDeprecated = 163, + ClientBoundDebugRendererPacket = 164, + SyncActorProperty = 165, + AddVolumeEntityPacket = 166, + RemoveVolumeEntityPacket = 167, + SimulationTypePacket = 168, + NpcDialoguePacket = 169, + EduUriResourcePacket = 170, + CreatePhotoPacket = 171, + UpdateSubChunkBlocks = 172, + PhotoInfoRequestDeprecated = 173, + SubChunkPacket = 174, + SubChunkRequestPacket = 175, + PlayerStartItemCooldown = 176, + ScriptMessagePacket = 177, + CodeBuilderSourcePacket = 178, + TickingAreasLoadStatus = 179, + DimensionDataPacket = 180, + AgentAction = 181, + ChangeMobProperty = 182, + LessonProgressPacket = 183, + RequestAbilityPacket = 184, + RequestPermissionsPacket = 185, + ToastRequest = 186, + UpdateAbilitiesPacket = 187, + UpdateAdventureSettingsPacket = 188, + DeathInfo = 189, + EditorNetworkPacket = 190, + FeatureRegistryPacket = 191, + ServerStats = 192, + RequestNetworkSettings = 193, + GameTestRequestPacket = 194, + GameTestResultsPacket = 195, + PlayerClientInputPermissions = 196, + ClientCheatAbilityPacketDeprecated = 197, + CameraPresets = 198, + UnlockedRecipes = 199, + TitleSpecificPacketsStart = 200, + TitleSpecificPacketsEnd = 299, + CameraInstruction = 300, + CompressedBiomeDefinitionListDeprecated = 301, + TrimData = 302, + OpenSign = 303, + AgentAnimation = 304, + RefreshEntitlementsPacket = 305, + PlayerToggleCrafterSlotRequestPacket = 306, + SetPlayerInventoryOptions = 307, + SetHudPacket = 308, + AwardAchievementPacket = 309, + ClientboundCloseScreen = 310, + ClientboundLoadingScreenPacketDeprecated = 311, + ServerboundLoadingScreenPacket = 312, + JigsawStructureDataPacket = 313, + CurrentStructureFeaturePacket = 314, + ServerboundDiagnosticsPacket = 315, + CameraAimAssist = 316, + ContainerRegistryCleanup = 317, + MovementEffect = 318, + SetMovementAuthorityModeDeprecated = 319, + CameraAimAssistPresets = 320, + ClientCameraAimAssist = 321, + ClientMovementPredictionSyncPacket = 322, + UpdateClientOptions = 323, + PlayerVideoCapturePacket = 324, + PlayerUpdateEntityOverridesPacket = 325, + PlayerLocation = 326, + ClientboundControlSchemeSetPacket = 327, + ServerScriptDebugDrawerPacket = 328, + EndId = 329, +}; \ No newline at end of file diff --git a/src/client/memory/sdk/network/NetworkPeer.hpp b/src/mc/game/network/NetworkPeer.hpp similarity index 85% rename from src/client/memory/sdk/network/NetworkPeer.hpp rename to src/mc/game/network/NetworkPeer.hpp index 88c2a23..bb04bac 100644 --- a/src/client/memory/sdk/network/NetworkPeer.hpp +++ b/src/mc/game/network/NetworkPeer.hpp @@ -1,6 +1,7 @@ #pragma once -namespace NetworkPeer { +class NetworkPeer { +public: enum class Reliability : int { Reliable = 0, ReliableOrdered = 1, diff --git a/src/client/memory/sdk/network/Packet.hpp b/src/mc/game/network/Packet.hpp similarity index 55% rename from src/client/memory/sdk/network/Packet.hpp rename to src/mc/game/network/Packet.hpp index b57ebf5..8fad90f 100644 --- a/src/client/memory/sdk/network/Packet.hpp +++ b/src/mc/game/network/Packet.hpp @@ -1,20 +1,23 @@ #pragma once -#include "MinecraftPacketIds.hpp" +#include "../../mcsdk.hpp" +#include "PacketPriority.hpp" +#include "NetworkPeer.hpp" +#include "../common/SubClientId.hpp" #include "IPacketHandlerDispatcher.hpp" -#include "../deps/raknet/PacketPriority.hpp" #include "Compressibility.hpp" -#include "NetworkPeer.hpp" -#include +#include "MinecraftPacketIds.hpp" -struct Packet { - virtual ~Packet() = default; +class Packet { +public: PacketPriority mPriority; NetworkPeer::Reliability mReliability; - uint8_t mClientSubId; + SubClientId mSenderSubId; bool mIsHandled; std::chrono::steady_clock::time_point mReceiveTimepoint; const IPacketHandlerDispatcher* mHandler; Compressibility mCompressible; - - MinecraftPacketIds getId(); -}; +public: + virtual MCSDK ~Packet() = default; + virtual MCSDK MinecraftPacketIds getId() const = 0; + virtual MCSDK std::string getName() const = 0; +}; \ No newline at end of file diff --git a/src/client/memory/sdk/deps/raknet/PacketPriority.hpp b/src/mc/game/network/PacketPriority.hpp similarity index 100% rename from src/client/memory/sdk/deps/raknet/PacketPriority.hpp rename to src/mc/game/network/PacketPriority.hpp diff --git a/src/mc/mcsdk.cpp b/src/mc/mcsdk.cpp new file mode 100644 index 0000000..e18fc27 --- /dev/null +++ b/src/mc/mcsdk.cpp @@ -0,0 +1,4 @@ +#include "mcsdk.hpp" + +#include "game/IMinecraftGame.hpp" +#include "game/network/Packet.hpp" \ No newline at end of file diff --git a/src/mc/mcsdk.hpp b/src/mc/mcsdk.hpp new file mode 100644 index 0000000..c05c047 --- /dev/null +++ b/src/mc/mcsdk.hpp @@ -0,0 +1,9 @@ +#pragma once +#include +#include + +#ifdef SELAURA_WINDOWS +#define MCSDK __declspec(dllimport) +#else +#define MCSDK +#endif diff --git a/src/thunker/CMakeLists.txt b/src/thunker/CMakeLists.txt deleted file mode 100644 index c716ec3..0000000 --- a/src/thunker/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 3.28) -project(thunker LANGUAGES CXX) - -file(GLOB_RECURSE THUNKER_SOURCES src/*.cpp) -add_library(thunker STATIC ${THUNKER_SOURCES}) - -target_compile_definitions(thunker PRIVATE THUNKER_BUILD_DLL) - -target_include_directories(thunker PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include -) \ No newline at end of file diff --git a/src/thunker/include/thunker.hpp b/src/thunker/include/thunker.hpp deleted file mode 100644 index 6f70f09..0000000 --- a/src/thunker/include/thunker.hpp +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/src/thunker/include/thunker/common.hpp b/src/thunker/include/thunker/common.hpp deleted file mode 100644 index fd0f50a..0000000 --- a/src/thunker/include/thunker/common.hpp +++ /dev/null @@ -1,76 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -namespace thunker { - inline void assert_fail_msg(const char* expr_str, const char* msg, const char* file, int line) { - std::fprintf(stderr, - "THUNKER_ASSERT FAILED: %s\nMessage: %s\nAt %s:%d\n", - expr_str, msg ? msg : "(no message)", file, line); - std::fflush(stderr); - assert(false); // triggers debugger breakpoint or abort - } -} - -#define THUNKER_ASSERT(cond, fmt_str, ...) \ - do { \ - if constexpr (std::is_constant_evaluated()) { \ - static_assert(cond, "Compile-time assertion failed: " #cond); \ - } else { \ - if (!(cond)) { \ - auto _msg = std::format(fmt_str, __VA_ARGS__); \ - thunker::assert_fail_msg(#cond, _msg.c_str(), __FILE__, __LINE__); \ - } \ - } \ - } while (0) - - -#if defined(_WIN64) - #define THUNKER_WINDOWS 1 -#elif defined(__ANDROID__) - #define THUNKER_ANDROID 1 -#elif defined(__linux__) && !defined(__ANDROID__) - #define THUNKER_LINUX 1 -#else - #error "thunker only supports Windows x64, Linux x64, Android x64, and Android arm64" -#endif - -#if (defined(_M_X64) || defined(__x86_64__)) - #define THUNKER_ARCH_X64 1 -#elif defined(__aarch64__) - #define THUNKER_ARCH_ARM64 1 -#else - #error "thunker only supports x64 and arm64 architectures" -#endif - -#if defined(THUNKER_WINDOWS) - - #if defined(THUNKER_STATIC) - #define THUNKER_DLLEXPORT - #define THUNKER_DLLIMPORT - #else - #if defined(THUNKER_BUILD_DLL) - #define THUNKER_DLLEXPORT __declspec(dllexport) - #define THUNKER_DLLIMPORT - #else - #define THUNKER_DLLEXPORT - #define THUNKER_DLLIMPORT __declspec(dllimport) - #endif - #endif - -#else - #define THUNKER_DLLEXPORT - #define THUNKER_DLLIMPORT -#endif - -#if defined(THUNKER_STATIC) - #define THUNKER_API -#elif defined(THUNKER_BUILD_DLL) - #define THUNKER_API THUNKER_DLLEXPORT -#else - #define THUNKER_API THUNKER_DLLIMPORT -#endif diff --git a/src/thunker/include/thunker/hook.hpp b/src/thunker/include/thunker/hook.hpp deleted file mode 100644 index 5df63cd..0000000 --- a/src/thunker/include/thunker/hook.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include -#include -#include - -#include "common.hpp" -#include "platform.hpp" - -namespace thunker { - struct THUNKER_API hook { - [[nodiscard]] bool patched() const { - return m_patched; - }; - - bool attach(); - bool detach(); - private: - std::uint8_t* m_target{}; - std::uint8_t* m_detour{}; - std::uint8_t* m_trampoline{}; - std::size_t m_patch_size{}; - - bool m_patched{}; - std::mutex mtx{}; - }; -}; \ No newline at end of file diff --git a/src/thunker/include/thunker/platform.hpp b/src/thunker/include/thunker/platform.hpp deleted file mode 100644 index bae2332..0000000 --- a/src/thunker/include/thunker/platform.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include "common.hpp" - -#if THUNKER_WINDOWS && THUNKER_ARCH_X64 -#include -#include -#endif - -namespace thunker { - inline bool make_memory_writable(void* addr, std::size_t size); - inline std::uint8_t* create_trampoline(void* target, std::size_t size); - inline void write_jump(void* src, void* dst); -}; \ No newline at end of file diff --git a/src/thunker/src/hook.cpp b/src/thunker/src/hook.cpp deleted file mode 100644 index e686c96..0000000 --- a/src/thunker/src/hook.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "thunker/hook.hpp" - -bool THUNKER_API thunker::hook::attach() { - std::lock_guard lock(mtx); - - m_trampoline = thunker::create_trampoline(m_target, m_patch_size); - - thunker::write_jump(m_target, m_detour); - - m_patched = true; - return true; -} - -bool THUNKER_API thunker::hook::detach() { - std::lock_guard lock(mtx); - - std::memcpy(m_target, m_trampoline, m_patch_size); - std::free(m_trampoline); - m_trampoline = nullptr; - - m_patched = false; - return true; -} \ No newline at end of file diff --git a/src/thunker/src/windows.cpp b/src/thunker/src/windows.cpp deleted file mode 100644 index 65d1dff..0000000 --- a/src/thunker/src/windows.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once -#include "thunker/platform.hpp" - -#if THUNKER_WINDOWS && THUNKER_ARCH_X64 -inline bool thunker::make_memory_writable(void* addr, std::size_t size) { - DWORD oldProtect; - BOOL result = VirtualProtect(addr, size, PAGE_EXECUTE_READWRITE, &oldProtect); - return result != 0; -} - -inline std::uint8_t* thunker::create_trampoline(void* target, std::size_t size) { - std::uint8_t* trampoline = (std::uint8_t*)VirtualAlloc(nullptr, size + 14, - MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); - if (!trampoline) return nullptr; - - std::memcpy(trampoline, target, size); - - // Write jump back to target+size at trampoline+size - std::uint8_t* jmp_addr = trampoline + size; - std::uint8_t* ret_addr = (std::uint8_t*)target + size; - - jmp_addr[0] = 0x48; - jmp_addr[1] = 0xB8; // mov rax, imm64 - *reinterpret_cast(jmp_addr + 2) = (std::uint64_t)ret_addr; - jmp_addr[10] = 0xFF; // jmp rax - jmp_addr[11] = 0xE0; - - return trampoline; -} - -inline void thunker::write_jump(void* src, void* dst) { - std::uint8_t* p = reinterpret_cast(src); - - // mov rax, dst - p[0] = 0x48; - p[1] = 0xB8; - *reinterpret_cast(p + 2) = reinterpret_cast(dst); - - // jmp rax - p[10] = 0xFF; - p[11] = 0xE0; - - p[12] = 0x90; - p[13] = 0x90; -} -#endif \ No newline at end of file