From 4706b28d0660a9f00afd1c14821a39e8f63ee544 Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Fri, 1 Mar 2024 13:34:55 +0000 Subject: [PATCH 01/14] Re-impl InputHandler::registerButton(Up/Down)Handler, also a 32 bit variation of fnv hashing --- .../src/amethyst/events/EventManager.h | 3 +++ .../common/client/game/ClientInstance.cpp | 10 ++++---- .../minecraft/src-deps/input/InputHandler.cpp | 24 ++++++++++++------- .../minecraft/src-deps/input/InputHandler.h | 13 +++++----- AmethystRuntime/src/AmethystRuntime.cpp | 17 +++++-------- AmethystRuntime/src/AmethystRuntime.h | 2 -- AmethystRuntime/src/hooks/Hooks.cpp | 16 ++++++------- AmethystRuntime/src/hooks/InputHooks.cpp | 16 ++++++++----- AmethystRuntime/src/mod/ModFunctions.h | 4 +--- 9 files changed, 56 insertions(+), 49 deletions(-) diff --git a/AmethystAPI/src/amethyst/events/EventManager.h b/AmethystAPI/src/amethyst/events/EventManager.h index 9497d89a..3f6f16e9 100644 --- a/AmethystAPI/src/amethyst/events/EventManager.h +++ b/AmethystAPI/src/amethyst/events/EventManager.h @@ -21,6 +21,8 @@ namespace Amethyst { Event registerItems; Event registerBlocks; + Event<> beforeModShutdown; + /* Clear any events that have been registered */ @@ -33,6 +35,7 @@ namespace Amethyst { update.Shutdown(); registerItems.Shutdown(); registerBlocks.Shutdown(); + beforeModShutdown.Shutdown(); } }; } // namespace Amethyst \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp b/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp index 37f2e709..b7cc2389 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp +++ b/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp @@ -6,12 +6,14 @@ // } BlockSource* ClientInstance::getRegion() { - using function = BlockSource*(__thiscall*)(ClientInstance*); - return reinterpret_cast(this->vtable[27])(this); + using function = BlockSource*(ClientInstance::*)(); + auto func = std::bit_cast(this->vtable[27]); + return (this->*func)(); } LocalPlayer* ClientInstance::getLocalPlayer() { - using function = LocalPlayer*(__thiscall*)(ClientInstance*); - return reinterpret_cast(this->vtable[28])(this); + using function = LocalPlayer*(ClientInstance::*)(); + auto func = std::bit_cast(this->vtable[28]); + return (this->*func)(); } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src-deps/input/InputHandler.cpp b/AmethystAPI/src/minecraft/src-deps/input/InputHandler.cpp index 0fa29d48..6cbf6eb0 100644 --- a/AmethystAPI/src/minecraft/src-deps/input/InputHandler.cpp +++ b/AmethystAPI/src/minecraft/src-deps/input/InputHandler.cpp @@ -1,15 +1,23 @@ #include "minecraft/src-deps/input/InputHandler.h" +#include "minecraft/src-deps/core/string/StringHash.h" -void InputHandler::registerButtonDownHandler(std::string a1, std::function a2, bool a3) +// This seems to be a 32 bit variation of a hashed string? +int StringToNameId(std::string& str) { + int hashed = -2128831035; + + for (char c : str) { + hashed = 16777619 * (hashed ^ c); + } + + return hashed; +} + +void InputHandler::registerButtonDownHandler(std::string buttonName, std::function handler, bool suspendable) { - using function = void(__thiscall*)(InputHandler*, std::string, std::function, bool); - static auto func = reinterpret_cast(SlideAddress(0x3AFC790)); - return func(this, a1, a2, a3); + this->mButtonDownHandlerMap.emplace(StringToNameId(buttonName), std::make_pair(suspendable, std::move(handler))); } -void InputHandler::registerButtonUpHandler(std::string a1, std::function a2, bool a3) +void InputHandler::registerButtonUpHandler(std::string buttonName, std::function handler, bool suspendable) { - using function = void(__thiscall*)(InputHandler*, std::string, std::function, bool); - static auto func = reinterpret_cast(SlideAddress(0x3AFCA10)); - return func(this, a1, a2, a3); + this->mButtonUpHandlerMap.emplace(StringToNameId(buttonName), std::make_pair(suspendable, std::move(handler))); } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src-deps/input/InputHandler.h b/AmethystAPI/src/minecraft/src-deps/input/InputHandler.h index af0a241c..c9fddf3b 100644 --- a/AmethystAPI/src/minecraft/src-deps/input/InputHandler.h +++ b/AmethystAPI/src/minecraft/src-deps/input/InputHandler.h @@ -2,6 +2,7 @@ #include "amethyst/Memory.h" #include #include +#include enum FocusImpact : char { Neutral = 0x0, @@ -14,13 +15,11 @@ using IClientInstance = ClientInstance; class InputHandler { public: - // Found in MinecraftInputHandler::_registerInputHandlers - // 0x3AFC790 - 1.20.51.1 - // 48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 49 8B F0 4C 8B F2 4C 8B F9 48 89 55 ? 4C 89 45 ? 45 33 ED 48 83 7A ? ? 72 ? 48 8B 12 BB ? ? ? ? 48 C7 C1 ? ? ? ? 48 FF C1 80 3C 0A ? 75 ? 48 85 C9 74 ? 0F 1F 40 ? 66 66 0F 1F 84 00 ? ? ? ? 0F BE 02 48 8D 52 ? 33 C3 69 D8 ? ? ? ? 48 83 E9 ? 75 ? 49 83 C7 ? 44 88 4D ? 48 8D 45 ? 48 89 45 ? 4C 89 6D ? 49 8B 48 ? 48 85 C9 74 ? 48 8B 01 48 8D 55 ? 48 8B 00 FF 15 ? ? ? ? 48 89 45 ? 4D 8B 27 4C 89 7D ? 4C 89 6D ? E8 ? ? ? ? 4C 8B C0 48 8B 08 48 8B 41 ? BA ? ? ? ? 49 8B C8 FF 15 ? ? ? ? 48 8B F8 48 85 C0 75 ? 48 C7 44 24 ? ? ? ? ? 48 8D 05 ? ? ? ? 48 89 44 24 ? 4C 8D 0D ? ? ? ? 44 8D 47 ? 48 8D 15 ? ? ? ? 48 8D 0D ? ? ? ? E8 ? ? ? ? 84 C0 74 ? C7 04 25 ? ? ? ? ? ? ? ? 48 89 7D ? 89 5F ? 0F B6 45 ? 88 47 ? 4C 89 6F ? 48 8B 4D ? 48 85 C9 74 ? 48 8D 45 ? 48 3B C8 75 ? 48 8B 01 48 8D 57 ? 48 8B 40 ? FF 15 ? ? ? ? 48 89 47 ? 48 8B 4D ? 48 85 C9 74 ? 48 8B 01 48 8D 55 ? 48 3B CA 0F 95 C2 48 8B 40 ? FF 15 ? ? ? ? EB ? 48 89 4F ? 4C 89 6D ? 4C 89 27 4C 89 67 ? 4C 89 67 ? 66 C7 47 ? ? ? 49 8B 07 48 8B 48 ? 48 89 4D ? 44 89 6D ? 80 79 ? ? 75 ? 8B 47 ? 48 89 4D ? 3B 41 ? 73 ? C7 45 ? ? ? ? ? 48 8B 09 EB ? 44 89 6D ? 48 8B 49 ? 80 79 ? ? 74 ? 48 B8 ? ? ? ? ? ? ? ? 49 39 47 ? 0F 84 ? ? ? ? 0F 10 45 ? 0F 29 45 ? 4C 8B C7 48 8D 55 ? 49 8B CF E8 ? ? ? ? 90 48 8B 4D ? 48 85 C9 74 ? 48 8B 01 48 8D 55 ? 48 3B CA 0F 95 C2 48 8B 40 ? FF 15 ? ? ? ? 90 49 8B CE E8 ? ? ? ? 90 48 8B 4E ? 48 85 C9 74 ? 48 8B 01 48 3B CE 0F 95 C2 48 8B 40 ? FF 15 ? ? ? ? 4C 89 6E ? 48 8B 4D ? 48 33 CC E8 ? ? ? ? 48 8B 9C 24 ? ? ? ? 48 81 C4 ? ? ? ? 41 5F 41 5E 41 5D 41 5C 5F 5E 5D C3 E8 ? ? ? ? 90 CC CC CC CC CC CC 48 89 5C 24 ? 55 - void registerButtonDownHandler(std::string buttonName, std::function handler, bool suspendable); + /* this + 0 */ std::byte padding0[24]; + /* this + 24 */ std::multimap>> mButtonDownHandlerMap; + /* this + 40 */ std::multimap>> mButtonUpHandlerMap; - // Found in MinecraftInputHandler::_registerInputHandlers - // 0x3AFCA10 - 1.20.51.1 - // 48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 49 8B F0 4C 8B F2 4C 8B F9 48 89 55 ? 4C 89 45 ? 45 33 ED 48 83 7A ? ? 72 ? 48 8B 12 BB ? ? ? ? 48 C7 C1 ? ? ? ? 48 FF C1 80 3C 0A ? 75 ? 48 85 C9 74 ? 0F 1F 40 ? 66 66 0F 1F 84 00 ? ? ? ? 0F BE 02 48 8D 52 ? 33 C3 69 D8 ? ? ? ? 48 83 E9 ? 75 ? 49 83 C7 ? 44 88 4D ? 48 8D 45 ? 48 89 45 ? 4C 89 6D ? 49 8B 48 ? 48 85 C9 74 ? 48 8B 01 48 8D 55 ? 48 8B 00 FF 15 ? ? ? ? 48 89 45 ? 4D 8B 27 4C 89 7D ? 4C 89 6D ? E8 ? ? ? ? 4C 8B C0 48 8B 08 48 8B 41 ? BA ? ? ? ? 49 8B C8 FF 15 ? ? ? ? 48 8B F8 48 85 C0 75 ? 48 C7 44 24 ? ? ? ? ? 48 8D 05 ? ? ? ? 48 89 44 24 ? 4C 8D 0D ? ? ? ? 44 8D 47 ? 48 8D 15 ? ? ? ? 48 8D 0D ? ? ? ? E8 ? ? ? ? 84 C0 74 ? C7 04 25 ? ? ? ? ? ? ? ? 48 89 7D ? 89 5F ? 0F B6 45 ? 88 47 ? 4C 89 6F ? 48 8B 4D ? 48 85 C9 74 ? 48 8D 45 ? 48 3B C8 75 ? 48 8B 01 48 8D 57 ? 48 8B 40 ? FF 15 ? ? ? ? 48 89 47 ? 48 8B 4D ? 48 85 C9 74 ? 48 8B 01 48 8D 55 ? 48 3B CA 0F 95 C2 48 8B 40 ? FF 15 ? ? ? ? EB ? 48 89 4F ? 4C 89 6D ? 4C 89 27 4C 89 67 ? 4C 89 67 ? 66 C7 47 ? ? ? 49 8B 07 48 8B 48 ? 48 89 4D ? 44 89 6D ? 80 79 ? ? 75 ? 8B 47 ? 48 89 4D ? 3B 41 ? 73 ? C7 45 ? ? ? ? ? 48 8B 09 EB ? 44 89 6D ? 48 8B 49 ? 80 79 ? ? 74 ? 48 B8 ? ? ? ? ? ? ? ? 49 39 47 ? 0F 84 ? ? ? ? 0F 10 45 ? 0F 29 45 ? 4C 8B C7 48 8D 55 ? 49 8B CF E8 ? ? ? ? 90 48 8B 4D ? 48 85 C9 74 ? 48 8B 01 48 8D 55 ? 48 3B CA 0F 95 C2 48 8B 40 ? FF 15 ? ? ? ? 90 49 8B CE E8 ? ? ? ? 90 48 8B 4E ? 48 85 C9 74 ? 48 8B 01 48 3B CE 0F 95 C2 48 8B 40 ? FF 15 ? ? ? ? 4C 89 6E ? 48 8B 4D ? 48 33 CC E8 ? ? ? ? 48 8B 9C 24 ? ? ? ? 48 81 C4 ? ? ? ? 41 5F 41 5E 41 5D 41 5C 5F 5E 5D C3 E8 ? ? ? ? 90 CC CC CC CC CC CC 48 89 5C 24 ? 48 89 74 24 +public: + void registerButtonDownHandler(std::string buttonName, std::function handler, bool suspendable); void registerButtonUpHandler(std::string buttonName, std::function handler, bool suspendable); }; \ No newline at end of file diff --git a/AmethystRuntime/src/AmethystRuntime.cpp b/AmethystRuntime/src/AmethystRuntime.cpp index 6ec1d0e9..03793a42 100644 --- a/AmethystRuntime/src/AmethystRuntime.cpp +++ b/AmethystRuntime/src/AmethystRuntime.cpp @@ -56,10 +56,7 @@ void AmethystRuntime::LoadModDlls() // Load all mod functions for (auto& mod : mLoadedMods) { Log::Info("[AmethystRuntime] Loading '{}'", mod.modName); - - _LoadModFunc(&mModRegisterInputs, mod, "RegisterInputs"); _LoadModFunc(&mModInitialize, mod, "Initialize"); - _LoadModFunc(&mModShutdown, mod, "Shutdown"); } } @@ -80,7 +77,7 @@ void AmethystRuntime::PromptDebugger() void AmethystRuntime::CreateOwnHooks() { - static bool hasRegisteredInputsBefore = false; + /*static bool hasRegisteredInputsBefore = false; if (!hasRegisteredInputsBefore) { for (auto& registerInputFunc : mModRegisterInputs) { @@ -88,9 +85,10 @@ void AmethystRuntime::CreateOwnHooks() } hasRegisteredInputsBefore = true; - } + }*/ CreateInputHooks(); + CreateModFunctionHooks(); } @@ -118,6 +116,9 @@ void AmethystRuntime::RunMods() void AmethystRuntime::Shutdown() { + // Prompt all mods to do any final code before shutdown + mEventManager.beforeModShutdown.Invoke(); + mEventManager.Shutdown(); // Remove any of the runtime mods hooks @@ -126,10 +127,6 @@ void AmethystRuntime::Shutdown() // Unload any input action callbacks from Mod Dlls mInputManager.Shutdown(); - // Prompt all mods to shutdown - for (auto& modShutdown : mModShutdown) - modShutdown(); - // Unload all mod Dlls for (auto& mod : mLoadedMods) { mod.Shutdown(); @@ -138,9 +135,7 @@ void AmethystRuntime::Shutdown() mLoadedMods.clear(); // Clear all mod functions - mModRegisterInputs.clear(); mModInitialize.clear(); - mModShutdown.clear(); } void AmethystRuntime::ResumeGameThread() diff --git a/AmethystRuntime/src/AmethystRuntime.h b/AmethystRuntime/src/AmethystRuntime.h index 52afb200..85857be1 100644 --- a/AmethystRuntime/src/AmethystRuntime.h +++ b/AmethystRuntime/src/AmethystRuntime.h @@ -83,7 +83,5 @@ class AmethystRuntime { public: // Mod Functions - std::vector mModRegisterInputs; std::vector mModInitialize; - std::vector mModShutdown; }; \ No newline at end of file diff --git a/AmethystRuntime/src/hooks/Hooks.cpp b/AmethystRuntime/src/hooks/Hooks.cpp index b0c4567a..2ca1c627 100644 --- a/AmethystRuntime/src/hooks/Hooks.cpp +++ b/AmethystRuntime/src/hooks/Hooks.cpp @@ -61,13 +61,13 @@ void* VanillaItems_registerItems( return result; } -void BlockDefinitionGroup_registerBlocks(BlockDefinitionGroup* self) { - Amethyst::EventManager* events = AmethystRuntime::getEventManager(); - - events->registerBlocks.Invoke(self); - - _BlockDefinitionGroup_registerBlocks.thiscall(self); -} +//void BlockDefinitionGroup_registerBlocks(BlockDefinitionGroup* self) { +// Amethyst::EventManager* events = AmethystRuntime::getEventManager(); +// +// events->registerBlocks.Invoke(self); +// +// _BlockDefinitionGroup_registerBlocks.thiscall(self); +//} void* LevelRenderer_renderLevel(LevelRenderer* self, ScreenContext* screenContext, FrameRenderObject* frameRenderObject) { Amethyst::EventManager* events = AmethystRuntime::getEventManager(); @@ -93,6 +93,6 @@ void CreateModFunctionHooks() { hookManager->CreateHook(&ClientInstance::onStartJoinGame, _ClientInstance_onStartJoinGame, &ClientInstance_onStartJoinGame); hookManager->CreateHook(&ClientInstance::requestLeaveGame, _ClientInstance_requestLeaveGame, &ClientInstance_requestLeaveGame); hookManager->CreateHook(&VanillaItems::registerItems, _VanillaItems_registerItems, &VanillaItems_registerItems); - hookManager->CreateHook(&BlockDefinitionGroup::registerBlocks, _BlockDefinitionGroup_registerBlocks, &BlockDefinitionGroup_registerBlocks); + //hookManager->CreateHook(&BlockDefinitionGroup::registerBlocks, _BlockDefinitionGroup_registerBlocks, &BlockDefinitionGroup_registerBlocks); hookManager->CreateHook(&LevelRenderer::renderLevel, _LevelRenderer_renderLevel, &LevelRenderer_renderLevel); } \ No newline at end of file diff --git a/AmethystRuntime/src/hooks/InputHooks.cpp b/AmethystRuntime/src/hooks/InputHooks.cpp index ebad715b..cf488b0a 100644 --- a/AmethystRuntime/src/hooks/InputHooks.cpp +++ b/AmethystRuntime/src/hooks/InputHooks.cpp @@ -41,17 +41,21 @@ static void _registerInputHandlers(MinecraftInputHandler* self) // Register a callback to minecraft which checks if the button has its own callback // If so call the mods callback else do nothing + auto it = self->mInputHandler->mButtonDownHandlerMap.begin(); + self->mInputHandler->registerButtonDownHandler( buttonName, [&input](FocusImpact focus, IClientInstance client) { - if (input.mButtonDownHandler == NULL) return; - input.mButtonDownHandler(focus, client); - }, - false); + Log::Info("pressed"); + }, false); + + self->mInputHandler->registerButtonUpHandler( buttonName, [&input](FocusImpact focus, IClientInstance client) { - if (input.mButtonUpHandler == NULL) return; - input.mButtonUpHandler(focus, client); + Log::Info("released"); + + /*if (input.mButtonUpHandler == NULL) return; + input.mButtonUpHandler(focus, client);*/ }, false); } diff --git a/AmethystRuntime/src/mod/ModFunctions.h b/AmethystRuntime/src/mod/ModFunctions.h index 523f8749..c526c6e7 100644 --- a/AmethystRuntime/src/mod/ModFunctions.h +++ b/AmethystRuntime/src/mod/ModFunctions.h @@ -5,6 +5,4 @@ #include #include -typedef void (*ModRegisterInputs)(InputManager* inputManager); -typedef void (*ModInitialize)(HookManager* hookManager, Amethyst::EventManager* eventManager, InputManager* inputManager); -typedef void (*ModShutdown)(); \ No newline at end of file +typedef void (*ModInitialize)(HookManager* hookManager, Amethyst::EventManager* eventManager, InputManager* inputManager); \ No newline at end of file From 082cd9e6701e772e72505e44bf962ec6373cb460 Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Fri, 1 Mar 2024 22:59:54 +0000 Subject: [PATCH 02/14] Tidy Work: Move more stuff to the member pointer syntax, add the occasional version label --- AmethystAPI/CMakeLists.txt | 3 + AmethystAPI/src/amethyst/HookManager.cpp | 35 --------- AmethystAPI/src/amethyst/InputManager.h | 27 ------- AmethystAPI/src/amethyst/Memory.h | 27 +------ AmethystAPI/src/amethyst/MinecraftVtables.cpp | 2 - AmethystAPI/src/amethyst/Utility.cpp | 2 +- .../src/amethyst/runtime/HookManager.cpp | 15 ++++ .../src/amethyst/{ => runtime}/HookManager.h | 2 +- .../src/amethyst/{ => runtime}/events/Event.h | 0 .../{ => runtime}/events/EventManager.h | 2 +- .../src/amethyst/runtime/input/InputAction.h | 18 +++++ .../amethyst/runtime/input/InputManager.cpp | 6 ++ .../src/amethyst/runtime/input/InputManager.h | 18 +++++ .../common/client/game/ClientInstance.cpp | 4 +- .../gui/controls/renderers/HoverRenderer.h | 2 +- .../common/client/renderer/Tessellator.cpp | 6 +- .../client/renderer/actor/ItemRenderer.cpp | 6 +- .../renderer/block/BlockTessellator.cpp | 8 +- .../renderer/game/LevelRendererPlayer.cpp | 6 +- .../minecraft/src-deps/input/InputHandler.cpp | 16 +++- .../minecraft/src-deps/input/InputHandler.h | 1 + .../src/common/world/actor/Actor.cpp | 24 +----- .../minecraft/src/common/world/actor/Actor.h | 12 ++- .../minecraft/src/common/world/item/Item.cpp | 6 +- .../src/common/world/item/ItemStackBase.cpp | 15 ++-- .../src/common/world/item/ItemStackBase.h | 10 +-- .../world/item/registry/ItemRegistry.cpp | 6 +- .../level/block/registry/BlockTypeRegistry.h | 21 ----- .../common/world/level/chunk/LevelChunk.cpp | 12 +-- .../src/common/world/level/chunk/LevelChunk.h | 2 +- AmethystRuntime/src/AmethystRuntime.cpp | 17 +---- AmethystRuntime/src/AmethystRuntime.h | 8 +- AmethystRuntime/src/hooks/InputHooks.cpp | 55 +++++++------- AmethystRuntime/src/input/RuntimeInput.cpp | 76 +++++++++---------- AmethystRuntime/src/input/RuntimeInput.h | 20 ++--- AmethystRuntime/src/mod/ModFunctions.h | 2 +- 36 files changed, 212 insertions(+), 280 deletions(-) delete mode 100644 AmethystAPI/src/amethyst/HookManager.cpp delete mode 100644 AmethystAPI/src/amethyst/InputManager.h create mode 100644 AmethystAPI/src/amethyst/runtime/HookManager.cpp rename AmethystAPI/src/amethyst/{ => runtime}/HookManager.h (98%) rename AmethystAPI/src/amethyst/{ => runtime}/events/Event.h (100%) rename AmethystAPI/src/amethyst/{ => runtime}/events/EventManager.h (97%) create mode 100644 AmethystAPI/src/amethyst/runtime/input/InputAction.h create mode 100644 AmethystAPI/src/amethyst/runtime/input/InputManager.cpp create mode 100644 AmethystAPI/src/amethyst/runtime/input/InputManager.h diff --git a/AmethystAPI/CMakeLists.txt b/AmethystAPI/CMakeLists.txt index c243cb5e..80b7a108 100644 --- a/AmethystAPI/CMakeLists.txt +++ b/AmethystAPI/CMakeLists.txt @@ -26,6 +26,9 @@ add_library(${PROJECT_NAME} STATIC src/minecraft/src/common/world/level/block/BlockLegacy.asm src/minecraft/src-deps/minecraftrenderer/renderer/MaterialPtr.asm src/minecraft/src/common/world/level/BlockSourceListener.h + src/amethyst/runtime/input/InputManager.h + src/amethyst/runtime/input/InputManager.cpp + src/amethyst/runtime/input/InputAction.h ) diff --git a/AmethystAPI/src/amethyst/HookManager.cpp b/AmethystAPI/src/amethyst/HookManager.cpp deleted file mode 100644 index fcaac5db..00000000 --- a/AmethystAPI/src/amethyst/HookManager.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "amethyst/HookManager.h" - -/* -Disables any hooks and un-caches any stored addresses -*/ -void HookManager::Shutdown() -{ - for (auto it = mHooks.rbegin(); it != mHooks.rend(); ++it) { - auto* hook = *it; - *hook = {}; - } - - mHooks.clear(); - mFuncHashToOriginalAddress.clear(); -} - -//void HookManager::CreateHookAbsolute(uintptr_t targetAddress, void* detour, void** original) -//{ -// LPVOID original_addr = reinterpret_cast(targetAddress); -// MH_STATUS status; -// -// status = MH_CreateHook(original_addr, detour, original); -// if (status != MH_OK) { -// Log::Error("MH_CreateHook failed: Reason: {}", MH_StatusToString(status)); -// throw std::exception(); -// } -// -// status = MH_EnableHook(original_addr); -// if (status != MH_OK) { -// Log::Error("MH_EnableHook failed: Reason: {}", MH_StatusToString(status)); -// throw std::exception(); -// } -// -// m_hooks.push_back(original_addr); -//} \ No newline at end of file diff --git a/AmethystAPI/src/amethyst/InputManager.h b/AmethystAPI/src/amethyst/InputManager.h deleted file mode 100644 index 6579c344..00000000 --- a/AmethystAPI/src/amethyst/InputManager.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include -#include -#include -#include "minecraft/src-deps/input/InputHandler.h" - -class InputManager { -public: - /** - * Creates a new input action and assigns the default key - * Needs to be called from mod function: RegisterInputs - * The game has to be reloaded to register a new input action - */ - virtual void RegisterInput(const std::string& actionName, int defaultButton, bool allowRemapping = true) = 0; - - /** - * Add a callback to the input action on the first frame that the button is pressed - * Should be called from mod function Initialize for hot-reloading button functionality - */ - virtual void AddButtonDownHandler(const std::string& actionName, std::function handler) = 0; - - /** - * Add a callback to the input action on the first frame that the button is released - * Should be called from mod function Initialize for hot-reloading button functionality - */ - virtual void AddButtonUpHandler(const std::string& actionName, std::function handler) = 0; -}; \ No newline at end of file diff --git a/AmethystAPI/src/amethyst/Memory.h b/AmethystAPI/src/amethyst/Memory.h index 6a85b7a2..5af89249 100644 --- a/AmethystAPI/src/amethyst/Memory.h +++ b/AmethystAPI/src/amethyst/Memory.h @@ -33,29 +33,4 @@ uintptr_t SigScan(std::string_view signature); * Finds the offset of a pointer in a struct/class * returns SIZE_MAX if it fails */ -size_t FindOffsetOfPointer(void* _base, void* _pointer, size_t maxSearchSize); - -template -typename std::conditional::value, std::add_const, std::remove_const>::type& -DirectAccess(Type* type, size_t offset) { - union { - size_t raw; - Type* source; - Ret* target; - } u; - u.source = type; - u.raw += offset; - return *u.target; -} - -#define AS_FIELD(type, name, fn) __declspec(property(get = fn, put = set##name)) type name -#define DEF_FIELD_RW(type, name) __declspec(property(get = get##name, put = set##name)) type name - -#define FAKE_FIELD(type, name) \ - AS_FIELD(type, name, get##name); \ - type& get##name() - -#define BUILD_ACCESS(ptr, type, name, offset) \ - AS_FIELD(type, name, get##name); \ - type& get##name() const { return DirectAccess(ptr, offset); } \ - void set##name(type v) const { DirectAccess(ptr, offset) = std::move(v); } \ No newline at end of file +size_t FindOffsetOfPointer(void* _base, void* _pointer, size_t maxSearchSize); \ No newline at end of file diff --git a/AmethystAPI/src/amethyst/MinecraftVtables.cpp b/AmethystAPI/src/amethyst/MinecraftVtables.cpp index ee245184..a51630c1 100644 --- a/AmethystAPI/src/amethyst/MinecraftVtables.cpp +++ b/AmethystAPI/src/amethyst/MinecraftVtables.cpp @@ -22,6 +22,4 @@ void InitializeVtablePtrs() { BlockItem_ctor = reinterpret_cast(SigScan("48 89 5C 24 ? 48 89 74 24 ? 48 89 4C 24 ? 57 48 83 EC ? 48 8B F2 48 8B F9 E8 ? ? ? ? 90 48 8D 05")); MaterialPtr_ctor = reinterpret_cast(SigScan("48 89 4C 24 ? 53 48 83 EC ? 4C 8B CA 48 8B D9 33 C0")); - -// mce::RenderMaterialGroup::switchable = reinterpret_cast(SlideAddress(0x572BBB0)); } \ No newline at end of file diff --git a/AmethystAPI/src/amethyst/Utility.cpp b/AmethystAPI/src/amethyst/Utility.cpp index 3a13af53..2cee571f 100644 --- a/AmethystAPI/src/amethyst/Utility.cpp +++ b/AmethystAPI/src/amethyst/Utility.cpp @@ -10,7 +10,7 @@ std::string GetAmethystFolder() errno_t err = _dupenv_s(&path, &path_length, "LocalAppData"); if (err) throw std::exception("Failed to get environment variable %LocalAppData%"); - if (path == NULL) throw std::exception("%LocalAppData% was null"); + if (path == nullptr) throw std::exception("%LocalAppData% was null"); std::string localAppDataFolder(path); free(path); diff --git a/AmethystAPI/src/amethyst/runtime/HookManager.cpp b/AmethystAPI/src/amethyst/runtime/HookManager.cpp new file mode 100644 index 00000000..f298f174 --- /dev/null +++ b/AmethystAPI/src/amethyst/runtime/HookManager.cpp @@ -0,0 +1,15 @@ +#include "HookManager.h" + +/* +Disables any hooks and un-caches any stored addresses +*/ +void HookManager::Shutdown() +{ + for (auto it = mHooks.rbegin(); it != mHooks.rend(); ++it) { + auto* hook = *it; + *hook = {}; + } + + mHooks.clear(); + mFuncHashToOriginalAddress.clear(); +} \ No newline at end of file diff --git a/AmethystAPI/src/amethyst/HookManager.h b/AmethystAPI/src/amethyst/runtime/HookManager.h similarity index 98% rename from AmethystAPI/src/amethyst/HookManager.h rename to AmethystAPI/src/amethyst/runtime/HookManager.h index a9d3fa08..f04a213a 100644 --- a/AmethystAPI/src/amethyst/HookManager.h +++ b/AmethystAPI/src/amethyst/runtime/HookManager.h @@ -1,5 +1,5 @@ #pragma once -#include +#include "amethyst-deps/safetyhook.hpp" #include "amethyst/Log.h" #include "amethyst/Memory.h" #include diff --git a/AmethystAPI/src/amethyst/events/Event.h b/AmethystAPI/src/amethyst/runtime/events/Event.h similarity index 100% rename from AmethystAPI/src/amethyst/events/Event.h rename to AmethystAPI/src/amethyst/runtime/events/Event.h diff --git a/AmethystAPI/src/amethyst/events/EventManager.h b/AmethystAPI/src/amethyst/runtime/events/EventManager.h similarity index 97% rename from AmethystAPI/src/amethyst/events/EventManager.h rename to AmethystAPI/src/amethyst/runtime/events/EventManager.h index 3f6f16e9..c28c29e0 100644 --- a/AmethystAPI/src/amethyst/events/EventManager.h +++ b/AmethystAPI/src/amethyst/runtime/events/EventManager.h @@ -1,5 +1,5 @@ #pragma once -#include "amethyst/events/Event.h" +#include "Event.h" #include "minecraft/src-client/common/client/game/ClientInstance.h" #include "minecraft/src-client/common/client/gui/ScreenView.h" #include "minecraft/src/common/world/item/registry/ItemRegistry.h" diff --git a/AmethystAPI/src/amethyst/runtime/input/InputAction.h b/AmethystAPI/src/amethyst/runtime/input/InputAction.h new file mode 100644 index 00000000..1af69e2c --- /dev/null +++ b/AmethystAPI/src/amethyst/runtime/input/InputAction.h @@ -0,0 +1,18 @@ +#pragma once +#include + +namespace Amethyst { + class InputAction { + public: + std::string mInputName; + int mDefaultButton; + bool mAllowRemapping; + + public: + InputAction(const std::string& inputName, int defaultButton, bool allowRemapping) { + mInputName = inputName; + mDefaultButton = defaultButton; + mAllowRemapping = allowRemapping; + } + }; +}; // namespace Amethyst \ No newline at end of file diff --git a/AmethystAPI/src/amethyst/runtime/input/InputManager.cpp b/AmethystAPI/src/amethyst/runtime/input/InputManager.cpp new file mode 100644 index 00000000..e08ae0ff --- /dev/null +++ b/AmethystAPI/src/amethyst/runtime/input/InputManager.cpp @@ -0,0 +1,6 @@ +#include "amethyst/runtime/input/InputManager.h" + +void Amethyst::InputManager::RegisterNewInput(const std::string& inputName, int defaultButton, bool allowRemapping) { + const InputAction inputAction(inputName, defaultButton, allowRemapping); + mInputActions.push_back(inputAction); +} diff --git a/AmethystAPI/src/amethyst/runtime/input/InputManager.h b/AmethystAPI/src/amethyst/runtime/input/InputManager.h new file mode 100644 index 00000000..4136b2ec --- /dev/null +++ b/AmethystAPI/src/amethyst/runtime/input/InputManager.h @@ -0,0 +1,18 @@ +#pragma once +#include "minecraft/src-deps/input/InputHandler.h" +#include "amethyst/runtime/input/InputAction.h" +#include + +/** + * Manages creating inputs for an Amethyst Mod + */ +namespace Amethyst { + class InputManager { + public: + void RegisterNewInput(const std::string& inputName, int defaultButton, bool allowRemapping); + void AddButtonDownListener(const std::string& inputName, std::function); + + private: + std::vector mInputActions; + }; +} \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp b/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp index b7cc2389..c3dd079a 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp +++ b/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp @@ -6,14 +6,14 @@ // } BlockSource* ClientInstance::getRegion() { - using function = BlockSource*(ClientInstance::*)(); + using function = decltype(&getRegion); auto func = std::bit_cast(this->vtable[27]); return (this->*func)(); } LocalPlayer* ClientInstance::getLocalPlayer() { - using function = LocalPlayer*(ClientInstance::*)(); + using function = decltype(&getLocalPlayer); auto func = std::bit_cast(this->vtable[28]); return (this->*func)(); } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src-client/common/client/gui/controls/renderers/HoverRenderer.h b/AmethystAPI/src/minecraft/src-client/common/client/gui/controls/renderers/HoverRenderer.h index bd4d86ef..d1108b0e 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/gui/controls/renderers/HoverRenderer.h +++ b/AmethystAPI/src/minecraft/src-client/common/client/gui/controls/renderers/HoverRenderer.h @@ -15,6 +15,6 @@ class HoverRenderer { glm::tvec2 mOffset; // this + 96 //hooks: - // 48 8B C4 48 89 58 ? 48 89 70 ? 48 89 78 ? 4C 89 70 ? 55 48 8D 68 ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 44 0F 29 40 ? 49 8B D9 + // 1.20.51.1 - 48 8B C4 48 89 58 ? 48 89 70 ? 48 89 78 ? 4C 89 70 ? 55 48 8D 68 ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 44 0F 29 40 ? 49 8B D9 void _renderHoverBox(MinecraftUIRenderContext*, IClientInstance*, RectangleArea*, float); }; \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src-client/common/client/renderer/Tessellator.cpp b/AmethystAPI/src/minecraft/src-client/common/client/renderer/Tessellator.cpp index 000b5b36..96906a87 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/renderer/Tessellator.cpp +++ b/AmethystAPI/src/minecraft/src-client/common/client/renderer/Tessellator.cpp @@ -1,7 +1,7 @@ #include "minecraft/src-client/common/client/renderer/Tessellator.h" void Tessellator::begin(mce::PrimitiveMode mode, int maxVertices) { - using function = void(Tessellator::*)(mce::PrimitiveMode, int); + using function = decltype(&begin); if (this->mTessellating) { throw std::exception("Already tessellating!"); @@ -22,7 +22,7 @@ void Tessellator::vertex(const Vec3& vec) { } mce::Mesh Tessellator::end(uint64_t a3, std::string_view debugName, int a5) { - using function = mce::Mesh(Tessellator::*)(uint64_t, std::string_view, int); + using function = decltype(&end); static auto func = std::bit_cast(SigScan("48 8B C4 48 89 58 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 44 0F 29 40 ? 44 0F 29 48 ? 44 0F 29 90 ? ? ? ? 44 0F 29 98 ? ? ? ? 44 0F 29 A0 ? ? ? ? 44 0F 29 A8 ? ? ? ? 44 0F 29 B0 ? ? ? ? 44 0F 29 B8 ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4D 8B F9")); return (this->*func)(a3, debugName, a5); } @@ -83,7 +83,7 @@ void Tessellator::beginOverride() { } void Tessellator::clear() { - using function = void(Tessellator::*)(); + using function = decltype(&clear); static auto func = std::bit_cast(SigScan("48 83 EC ? C7 81 ? ? ? ? ? ? ? ? 4C 8B C9")); (this->*func)(); } diff --git a/AmethystAPI/src/minecraft/src-client/common/client/renderer/actor/ItemRenderer.cpp b/AmethystAPI/src/minecraft/src-client/common/client/renderer/actor/ItemRenderer.cpp index f540c0a1..6842d2b4 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/renderer/actor/ItemRenderer.cpp +++ b/AmethystAPI/src/minecraft/src-client/common/client/renderer/actor/ItemRenderer.cpp @@ -2,7 +2,7 @@ void ItemRenderer::renderGuiItemNew(BaseActorRenderContext* renderContext, const ItemStack* item, uint32_t frame, float x, float y, bool forceEnchantmentFoil, float transparency, float lightMultiplyer, float scale) { - using function = void(__thiscall*)(ItemRenderer*, BaseActorRenderContext*, const ItemStack* item, uint32_t, float, float, bool, float, float, float); - static auto func = reinterpret_cast(SigScan("48 8B C4 53 55 56 57 41 54 41 55 41 56 41 57 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 84 24 ? ? ? ? 45 8B E1")); - func(this, renderContext, item, frame, x, y, forceEnchantmentFoil, transparency, lightMultiplyer, scale); + using function = decltype(&renderGuiItemNew); + static auto func = std::bit_cast(SigScan("48 8B C4 53 55 56 57 41 54 41 55 41 56 41 57 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 84 24 ? ? ? ? 45 8B E1")); + (this->*func)(renderContext, item, frame, x, y, forceEnchantmentFoil, transparency, lightMultiplyer, scale); } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src-client/common/client/renderer/block/BlockTessellator.cpp b/AmethystAPI/src/minecraft/src-client/common/client/renderer/block/BlockTessellator.cpp index f00895fe..85d30590 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/renderer/block/BlockTessellator.cpp +++ b/AmethystAPI/src/minecraft/src-client/common/client/renderer/block/BlockTessellator.cpp @@ -7,13 +7,13 @@ //} void BlockTessellator::appendTessellatedBlock(Tessellator *tessellator, const Block *block) { - using function = void(BlockTessellator::*)(Tessellator*, const Block*); + using function = decltype(&appendTessellatedBlock); static auto func = std::bit_cast(SigScan("48 8B C4 48 89 58 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 44 0F 29 40 ? 44 0F 29 48 ? 44 0F 29 90 ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4D 8B F8")); (this->*func)(tessellator, block); } int64_t BlockTessellator::tessellateInWorld(Tessellator &tessellator, const Block &block, const BlockPos &pos, bool a5, bool a6) { - using function = int64_t(__thiscall*)(BlockTessellator*, Tessellator&, const Block&, const BlockPos&, bool, bool); - static auto func = reinterpret_cast(SigScan("40 53 55 56 57 41 56 48 83 EC ? 80 79")); - return func(this, tessellator, block, pos, a5, a6); + using function = decltype(&tessellateInWorld); + static auto func = std::bit_cast(SigScan("40 53 55 56 57 41 56 48 83 EC ? 80 79")); + return (this->*func)(tessellator, block, pos, a5, a6); } diff --git a/AmethystAPI/src/minecraft/src-client/common/client/renderer/game/LevelRendererPlayer.cpp b/AmethystAPI/src/minecraft/src-client/common/client/renderer/game/LevelRendererPlayer.cpp index 12c7bd51..e39c7b47 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/renderer/game/LevelRendererPlayer.cpp +++ b/AmethystAPI/src/minecraft/src-client/common/client/renderer/game/LevelRendererPlayer.cpp @@ -1,7 +1,7 @@ #include "minecraft/src-client/common/client/renderer/game/LevelRendererPlayer.h" float LevelRendererPlayer::getFov(float originalFov, bool applyEffects) { - using function = float(__thiscall*)(LevelRendererPlayer*, float, bool); - static auto func = reinterpret_cast(SigScan("48 8B C4 48 89 58 ? 48 89 70 ? 57 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 44 0F 29 40 ? 44 0F 29 48 ? 48 8B 05")); - return func(this, originalFov, applyEffects); + using function = decltype(&getFov); + static auto func = std::bit_cast(SigScan("48 8B C4 48 89 58 ? 48 89 70 ? 57 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 44 0F 29 40 ? 44 0F 29 48 ? 48 8B 05")); + return (this->*func)(originalFov, applyEffects); } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src-deps/input/InputHandler.cpp b/AmethystAPI/src/minecraft/src-deps/input/InputHandler.cpp index 6cbf6eb0..fa74afa0 100644 --- a/AmethystAPI/src/minecraft/src-deps/input/InputHandler.cpp +++ b/AmethystAPI/src/minecraft/src-deps/input/InputHandler.cpp @@ -2,7 +2,7 @@ #include "minecraft/src-deps/core/string/StringHash.h" // This seems to be a 32 bit variation of a hashed string? -int StringToNameId(std::string& str) { +int StringToNameId(const std::string& str) { int hashed = -2128831035; for (char c : str) { @@ -20,4 +20,18 @@ void InputHandler::registerButtonDownHandler(std::string buttonName, std::functi void InputHandler::registerButtonUpHandler(std::string buttonName, std::function handler, bool suspendable) { this->mButtonUpHandlerMap.emplace(StringToNameId(buttonName), std::make_pair(suspendable, std::move(handler))); +} + +void InputHandler::unregisterHandlersByName(const std::string& buttonName) { + int hashedName = StringToNameId(buttonName); + + auto downHandlerRange = mButtonDownHandlerMap.equal_range(hashedName); + if (downHandlerRange.first != mButtonDownHandlerMap.end()) { + mButtonDownHandlerMap.erase(downHandlerRange.first, downHandlerRange.second); + } + + auto upHandlerRange = mButtonUpHandlerMap.equal_range(hashedName); + if (upHandlerRange.first != mButtonUpHandlerMap.end()) { + mButtonUpHandlerMap.erase(upHandlerRange.first, upHandlerRange.second); + } } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src-deps/input/InputHandler.h b/AmethystAPI/src/minecraft/src-deps/input/InputHandler.h index c9fddf3b..0ee5a66f 100644 --- a/AmethystAPI/src/minecraft/src-deps/input/InputHandler.h +++ b/AmethystAPI/src/minecraft/src-deps/input/InputHandler.h @@ -22,4 +22,5 @@ class InputHandler { public: void registerButtonDownHandler(std::string buttonName, std::function handler, bool suspendable); void registerButtonUpHandler(std::string buttonName, std::function handler, bool suspendable); + void unregisterHandlersByName(const std::string& buttonName); }; \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/actor/Actor.cpp b/AmethystAPI/src/minecraft/src/common/world/actor/Actor.cpp index a59bfd91..2c0ad9d6 100644 --- a/AmethystAPI/src/minecraft/src/common/world/actor/Actor.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/actor/Actor.cpp @@ -3,26 +3,4 @@ Vec3* Actor::getPosition() { return &mStateVectorComponent->mPos; -} - -template -const T* Actor::tryGetComponent() const -{ - const auto& registry = mEntityContext.getRegistry(); - return registry.try_get(mEntityContext.mEntity); -} - -template const ActorHeadRotationComponent* Actor::tryGetComponent() const; -template const ActorRotationComponent* Actor::tryGetComponent() const; -template const StateVectorComponent* Actor::tryGetComponent() const; - -template -T* Actor::tryGetComponent() -{ - auto& registry = mEntityContext.getRegistry(); - return registry.try_get(mEntityContext.mEntity); -} - -template ActorHeadRotationComponent* Actor::tryGetComponent(); -template ActorRotationComponent* Actor::tryGetComponent(); -template StateVectorComponent* Actor::tryGetComponent(); \ No newline at end of file +} \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/actor/Actor.h b/AmethystAPI/src/minecraft/src/common/world/actor/Actor.h index e342182f..e198639a 100644 --- a/AmethystAPI/src/minecraft/src/common/world/actor/Actor.h +++ b/AmethystAPI/src/minecraft/src/common/world/actor/Actor.h @@ -23,10 +23,18 @@ class Actor { Vec3* getPosition(); template - const T* tryGetComponent() const; + const T* tryGetComponent() const + { + const auto& registry = mEntityContext.getRegistry(); + return registry.try_get(mEntityContext.mEntity); + } template - T* tryGetComponent(); + T* tryGetComponent() + { + auto& registry = mEntityContext.getRegistry(); + return registry.try_get(mEntityContext.mEntity); + } }; static_assert(sizeof(Actor) == 1224); \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/item/Item.cpp b/AmethystAPI/src/minecraft/src/common/world/item/Item.cpp index 3350dddf..cdf3de0a 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/Item.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/item/Item.cpp @@ -12,9 +12,9 @@ Item::Item(const std::string& stringId, short numericalId) short Item::getDamageValue(CompoundTag* mUserData) const { - using function = short(__thiscall*)(const Item*, CompoundTag*); - static auto func = reinterpret_cast(SigScan("48 89 5C 24 ? 57 48 83 EC ? 48 8B DA 48 85 D2")); - return func(this, mUserData); + using function = decltype(&Item::getDamageValue); + static auto func = std::bit_cast(SigScan("48 89 5C 24 ? 57 48 83 EC ? 48 8B DA 48 85 D2")); + return (this->*func)(mUserData); } Item::~Item() { diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp index 0506b451..8450e334 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp @@ -1,20 +1,21 @@ #include "minecraft/src/common/world/item/ItemStackBase.h" -std::string& ItemStackBase::getRawNameId(std::string& str) const +std::string ItemStackBase::getRawNameId() const { - static auto function = reinterpret_cast<_getRawNameId>( + using function = decltype(&ItemStackBase::getRawNameId); + + static auto func = std::bit_cast( SigScan("48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 54 24 ? 57 48 83 EC ? 48 8B FA 48 8B E9 33 F6")); - // returns a ref to str param - return function(this, str); + return (this->*func)(); } void ItemStackBase::_loadItem(const CompoundTag* a1) { - using function = void(__thiscall*)(ItemStackBase*, const CompoundTag*); + using function = decltype(&ItemStackBase::_loadItem); - static auto func = reinterpret_cast( + static auto func = std::bit_cast( SigScan("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 ? ? ? ? 48 8B F2 48 89 54 24 ? 4C 8B F9 48 89 4C 24") ); - func(this, a1); + (this->*func)(a1); } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h index 7465f28e..e43ec2c5 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h @@ -17,11 +17,9 @@ class ItemStackBase { std::byte padding1[120]; public: - ItemStackBase() {}; - std::string& getRawNameId(std::string&) const; - void _loadItem(const CompoundTag*); + // 1.20.51.1 - 48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 54 24 ? 57 48 83 EC ? 48 8B FA 48 8B E9 33 F6 + std::string getRawNameId() const; -//hooks: - // 48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 54 24 ? 57 48 83 EC ? 48 8B FA 48 8B E9 33 F6 - typedef std::string&(__thiscall* _getRawNameId)(const ItemStackBase*, std::string&); + // 1.20.51.1 - 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 ? ? ? ? 48 8B F2 48 89 54 24 ? 4C 8B F9 48 89 4C 24 + void _loadItem(const CompoundTag*); }; \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/item/registry/ItemRegistry.cpp b/AmethystAPI/src/minecraft/src/common/world/item/registry/ItemRegistry.cpp index 9f7026bc..4d3c6afa 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/registry/ItemRegistry.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/item/registry/ItemRegistry.cpp @@ -2,11 +2,11 @@ void ItemRegistry::registerItem(SharedPtr item) { - using function = void(__thiscall*)(ItemRegistry*, SharedPtr); + using function = decltype(&ItemRegistry::registerItem); - static auto func = reinterpret_cast( + static auto func = std::bit_cast( SigScan("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 ? ? ? ? 48 8B FA 4C 8B E9 48 89 55 ? 33 DB") ); - func(this, item); + (this->*func)(item); } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/level/block/registry/BlockTypeRegistry.h b/AmethystAPI/src/minecraft/src/common/world/level/block/registry/BlockTypeRegistry.h index 8988dbd6..587b5e8c 100644 --- a/AmethystAPI/src/minecraft/src/common/world/level/block/registry/BlockTypeRegistry.h +++ b/AmethystAPI/src/minecraft/src/common/world/level/block/registry/BlockTypeRegistry.h @@ -51,27 +51,6 @@ class BlockTypeRegistry { // 1.20.51.1 - 48 89 5C 24 ? 57 48 83 EC ? 33 FF 45 33 C9 static const Block* getDefaultBlockState(const HashedString& name) { - /*auto* lookupResult = new LookupByNameImplReturnType(); - BlockTypeRegistry::_lookupByNameImpl(lookupResult, name, 0, DefaultBlockState); - - const Block* ret = nullptr; - - if (lookupResult != nullptr) { - // Client: - ret = reinterpret_cast(lookupResult->blockLegacy + 792); - - // Server: - //ret = &lookupResult->blockLegacy->getRenderBlock(); - } - - else { - Log::Info("Lookup for {} failed in getDefaultBlockState", name.getString()); - throw std::exception(); - } - - delete lookupResult; - return ret;*/ - using function = Block*(*)(const HashedString&); static auto func = reinterpret_cast(SigScan("48 89 5C 24 ? 57 48 83 EC ? 33 FF 45 33 C9")); return func(name); diff --git a/AmethystAPI/src/minecraft/src/common/world/level/chunk/LevelChunk.cpp b/AmethystAPI/src/minecraft/src/common/world/level/chunk/LevelChunk.cpp index 4d59e830..7fe078f4 100644 --- a/AmethystAPI/src/minecraft/src/common/world/level/chunk/LevelChunk.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/level/chunk/LevelChunk.cpp @@ -1,8 +1,8 @@ #include "minecraft/src/common/world/level/chunk/LevelChunk.h" -const Block* LevelChunk::getBlock(const ChunkBlockPos& pos) -{ - typedef const Block*(__thiscall * _getBlock)(LevelChunk * self, const ChunkBlockPos&); - static auto func = reinterpret_cast<_getBlock>(SlideAddress(0x3909E80)); // 1.20.30.02 - return func(this, pos); -} \ No newline at end of file +//const Block* LevelChunk::getBlock(const ChunkBlockPos& pos) +//{ +// typedef const Block*(__thiscall * _getBlock)(LevelChunk * self, const ChunkBlockPos&); +// static auto func = reinterpret_cast<_getBlock>(SlideAddress(0x3909E80)); // 1.20.30.02 +// return func(this, pos); +//} \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/level/chunk/LevelChunk.h b/AmethystAPI/src/minecraft/src/common/world/level/chunk/LevelChunk.h index e19b05fa..fa4c6c09 100644 --- a/AmethystAPI/src/minecraft/src/common/world/level/chunk/LevelChunk.h +++ b/AmethystAPI/src/minecraft/src/common/world/level/chunk/LevelChunk.h @@ -10,6 +10,6 @@ class LevelChunk { typedef BlockPos&(__thiscall* _getTopRainBlockPos)(LevelChunk* a1, ChunkBlockPos* a2, void* a3); // Found in BlockSource::getBlock(const BlockPos&) - // 0x3909E80 + // 1.20.30.02 - 0x3909E80 const Block* getBlock(const ChunkBlockPos& pos); }; \ No newline at end of file diff --git a/AmethystRuntime/src/AmethystRuntime.cpp b/AmethystRuntime/src/AmethystRuntime.cpp index 03793a42..ac186176 100644 --- a/AmethystRuntime/src/AmethystRuntime.cpp +++ b/AmethystRuntime/src/AmethystRuntime.cpp @@ -77,16 +77,6 @@ void AmethystRuntime::PromptDebugger() void AmethystRuntime::CreateOwnHooks() { - /*static bool hasRegisteredInputsBefore = false; - - if (!hasRegisteredInputsBefore) { - for (auto& registerInputFunc : mModRegisterInputs) { - registerInputFunc(getInputManager()); - } - - hasRegisteredInputsBefore = true; - }*/ - CreateInputHooks(); CreateModFunctionHooks(); @@ -96,7 +86,7 @@ void AmethystRuntime::RunMods() { // Invoke mods to initialize and setup hooks, etc.. for (auto& modInitialize : mModInitialize) - modInitialize(getHookManager(), getEventManager(), getInputManager()); + modInitialize(getHookManager(), getEventManager()); ResumeGameThread(); @@ -117,16 +107,11 @@ void AmethystRuntime::RunMods() void AmethystRuntime::Shutdown() { // Prompt all mods to do any final code before shutdown - mEventManager.beforeModShutdown.Invoke(); - mEventManager.Shutdown(); // Remove any of the runtime mods hooks mHookManager.Shutdown(); - // Unload any input action callbacks from Mod Dlls - mInputManager.Shutdown(); - // Unload all mod Dlls for (auto& mod : mLoadedMods) { mod.Shutdown(); diff --git a/AmethystRuntime/src/AmethystRuntime.h b/AmethystRuntime/src/AmethystRuntime.h index 85857be1..c0e22fda 100644 --- a/AmethystRuntime/src/AmethystRuntime.h +++ b/AmethystRuntime/src/AmethystRuntime.h @@ -18,6 +18,8 @@ namespace fs = std::filesystem; +typedef void (*ModInitialize)(HookManager* hookManager, Amethyst::EventManager* eventManager); + /* Entry: - Initialize console @@ -49,11 +51,6 @@ class AmethystRuntime { return &AmethystRuntime::getInstance()->mHookManager; } - static RuntimeInputManager* getInputManager() - { - return &AmethystRuntime::getInstance()->mInputManager; - } - static Amethyst::EventManager* getEventManager() { return &AmethystRuntime::getInstance()->mEventManager; @@ -77,7 +74,6 @@ class AmethystRuntime { private: Config mLauncherConfig; HookManager mHookManager; - RuntimeInputManager mInputManager; Amethyst::EventManager mEventManager; std::vector mLoadedMods; diff --git a/AmethystRuntime/src/hooks/InputHooks.cpp b/AmethystRuntime/src/hooks/InputHooks.cpp index cf488b0a..218731c4 100644 --- a/AmethystRuntime/src/hooks/InputHooks.cpp +++ b/AmethystRuntime/src/hooks/InputHooks.cpp @@ -4,9 +4,9 @@ SafetyHookInline _assignDefaultMapping; SafetyHookInline _addFullKeyboardGamePlayControls; SafetyHookInline __registerInputHandlers; -static void assignDefaultMapping(RemappingLayout* self, std::vector&& mapping) +void assignDefaultMapping(RemappingLayout* self, std::vector&& mapping) { - RuntimeInputManager* inputManager = AmethystRuntime::getInputManager(); + /*RuntimeInputManager* inputManager = AmethystRuntime::getInputManager(); for (auto& input : inputManager->mInputActions) { std::string keyName = "key." + input.mActionName; @@ -14,12 +14,12 @@ static void assignDefaultMapping(RemappingLayout* self, std::vector& mapping.emplace_back(keymapping); } - _assignDefaultMapping.call>(self, std::move(mapping)); + _assignDefaultMapping.call>(self, std::move(mapping));*/ } -static void addFullKeyboardGamePlayControls(VanillaClientInputMappingFactory* self, KeyboardInputMapping* keyboard, MouseInputMapping* mouse) +void addFullKeyboardGamePlayControls(VanillaClientInputMappingFactory* self, KeyboardInputMapping* keyboard, MouseInputMapping* mouse) { - _addFullKeyboardGamePlayControls + /*_addFullKeyboardGamePlayControls .call(self, keyboard, mouse); RuntimeInputManager* inputManager = AmethystRuntime::getInputManager(); @@ -28,37 +28,38 @@ static void addFullKeyboardGamePlayControls(VanillaClientInputMappingFactory* se std::string keyName = "key." + input.mActionName; std::string buttonName = "button." + input.mActionName; self->createKeyboardAndMouseBinding(keyboard, mouse, &buttonName, &keyName); - } + }*/ } -static void _registerInputHandlers(MinecraftInputHandler* self) +void _registerInputHandlers(MinecraftInputHandler* self) { - __registerInputHandlers.call(self); - RuntimeInputManager* inputManager = AmethystRuntime::getInputManager(); + //__registerInputHandlers.call(self); + //RuntimeInputManager* inputManager = AmethystRuntime::getInputManager(); + //InputHandler* inputHandler = self->mInputHandler.get(); - for (auto& input : inputManager->mInputActions) { - std::string buttonName = "button." + input.mActionName; + //for (auto& input : inputManager->mInputActions) { + // std::string buttonName = "button." + input.mActionName; - // Register a callback to minecraft which checks if the button has its own callback - // If so call the mods callback else do nothing - auto it = self->mInputHandler->mButtonDownHandlerMap.begin(); + // // Register a callback to minecraft which checks if the button has its own callback + // // If so call the mods callback else do nothing + // auto it = self->mInputHandler->mButtonDownHandlerMap.begin(); - self->mInputHandler->registerButtonDownHandler( - buttonName, [&input](FocusImpact focus, IClientInstance client) { - Log::Info("pressed"); - }, false); - + // self->mInputHandler->registerButtonDownHandler( + // buttonName, [&input](FocusImpact focus, IClientInstance client) { + // Log::Info("pressed"); + // }, false); + // self->mInputHandler->registerButtonUpHandler( + // buttonName, [&input, inputHandler, buttonName](FocusImpact focus, IClientInstance client) { + // Log::Info("released, unregistering"); - self->mInputHandler->registerButtonUpHandler( - buttonName, [&input](FocusImpact focus, IClientInstance client) { - Log::Info("released"); + // inputHandler->unregisterHandlersByName(buttonName); - /*if (input.mButtonUpHandler == NULL) return; - input.mButtonUpHandler(focus, client);*/ - }, - false); - } + // /*if (input.mButtonUpHandler == NULL) return; + // input.mButtonUpHandler(focus, client);*/ + // }, + // false); + //} } void CreateInputHooks() diff --git a/AmethystRuntime/src/input/RuntimeInput.cpp b/AmethystRuntime/src/input/RuntimeInput.cpp index a7d17017..9e7a00ed 100644 --- a/AmethystRuntime/src/input/RuntimeInput.cpp +++ b/AmethystRuntime/src/input/RuntimeInput.cpp @@ -1,40 +1,40 @@ #include "input/RuntimeInput.h" -void RuntimeInputManager::RegisterInput(const std::string& actionName, int defaultButton, bool allowRemapping) -{ - InputAction inputAction = {actionName, defaultButton, allowRemapping, NULL, NULL}; - mInputActions.push_back(inputAction); -} - -void RuntimeInputManager::AddButtonDownHandler(const std::string& actionName, std::function handler) -{ - for (auto& input : mInputActions) { - if (input.mActionName != actionName) continue; - input.mButtonDownHandler = handler; - return; - } - - std::string message = fmt::format("Input Action '{}' has not been registered. Ensure that you have restarted the game after registering a new input action", actionName); - throw std::exception(message.c_str()); -} - -void RuntimeInputManager::AddButtonUpHandler(const std::string& actionName, std::function handler) -{ - for (auto& input : mInputActions) { - if (input.mActionName != actionName) continue; - input.mButtonUpHandler = handler; - return; - } - - std::string message = fmt::format("Input Action '{}' has not been registered. Ensure that you have restarted the game after registering a new input action", actionName); - throw std::exception(message.c_str()); -} - -void RuntimeInputManager::Shutdown() -{ - // Destroy any references to callbacks in an unloaded Dll - for (auto& input : mInputActions) { - input.mButtonDownHandler = NULL; - input.mButtonUpHandler = NULL; - } -} +//void RuntimeInputManager::RegisterInput(const std::string& actionName, int defaultButton, bool allowRemapping) +//{ +// InputAction inputAction = {actionName, defaultButton, allowRemapping, NULL, NULL}; +// mInputActions.push_back(inputAction); +//} +// +//void RuntimeInputManager::AddButtonDownHandler(const std::string& actionName, std::function handler) +//{ +// for (auto& input : mInputActions) { +// if (input.mActionName != actionName) continue; +// input.mButtonDownHandler = handler; +// return; +// } +// +// std::string message = fmt::format("Input Action '{}' has not been registered. Ensure that you have restarted the game after registering a new input action", actionName); +// throw std::exception(message.c_str()); +//} +// +//void RuntimeInputManager::AddButtonUpHandler(const std::string& actionName, std::function handler) +//{ +// for (auto& input : mInputActions) { +// if (input.mActionName != actionName) continue; +// input.mButtonUpHandler = handler; +// return; +// } +// +// std::string message = fmt::format("Input Action '{}' has not been registered. Ensure that you have restarted the game after registering a new input action", actionName); +// throw std::exception(message.c_str()); +//} +// +//void RuntimeInputManager::Shutdown() +//{ +// // Destroy any references to callbacks in an unloaded Dll +// for (auto& input : mInputActions) { +// input.mButtonDownHandler = NULL; +// input.mButtonUpHandler = NULL; +// } +//} diff --git a/AmethystRuntime/src/input/RuntimeInput.h b/AmethystRuntime/src/input/RuntimeInput.h index 64b4c8b6..9dc3e097 100644 --- a/AmethystRuntime/src/input/RuntimeInput.h +++ b/AmethystRuntime/src/input/RuntimeInput.h @@ -11,13 +11,13 @@ struct InputAction { std::function mButtonUpHandler = NULL; }; -class RuntimeInputManager : public InputManager { -public: - std::vector mInputActions; - -public: - virtual void RegisterInput(const std::string& actionName, int defaultButton, bool allowRemapping = true) override; - virtual void AddButtonDownHandler(const std::string& actionName, std::function handler) override; - virtual void AddButtonUpHandler(const std::string& actionName, std::function handler) override; - void Shutdown(); -}; \ No newline at end of file +//class RuntimeInputManager : public InputManager { +//public: +// std::vector mInputActions; +// +//public: +// virtual void RegisterInput(const std::string& actionName, int defaultButton, bool allowRemapping = true) override; +// virtual void AddButtonDownHandler(const std::string& actionName, std::function handler) override; +// virtual void AddButtonUpHandler(const std::string& actionName, std::function handler) override; +// void Shutdown(); +//}; \ No newline at end of file diff --git a/AmethystRuntime/src/mod/ModFunctions.h b/AmethystRuntime/src/mod/ModFunctions.h index c526c6e7..2dc2d8ac 100644 --- a/AmethystRuntime/src/mod/ModFunctions.h +++ b/AmethystRuntime/src/mod/ModFunctions.h @@ -5,4 +5,4 @@ #include #include -typedef void (*ModInitialize)(HookManager* hookManager, Amethyst::EventManager* eventManager, InputManager* inputManager); \ No newline at end of file +typedef void (*ModInitialize)(HookManager* hookManager, Amethyst::EventManager* eventManager); \ No newline at end of file From b94d3d8c0c5bc6ab379e260cc6b56279b2f7103b Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Sat, 2 Mar 2024 13:32:24 +0000 Subject: [PATCH 03/14] Move to having a central AmethystContext , also fix some compilation issues! --- AmethystAPI/CMakeLists.txt | 4 ---- .../src/amethyst/runtime/AmethystContext.h | 18 +++++++++++++++ .../common/client/game/ClientInstance.cpp | 4 ++-- .../common/client/game/ClientInstance.h | 9 ++++---- .../common/client/renderer/Tessellator.cpp | 6 ++--- .../client/renderer/actor/ItemRenderer.cpp | 2 +- .../renderer/block/BlockTessellator.cpp | 4 ++-- .../renderer/game/LevelRendererPlayer.cpp | 2 +- AmethystRuntime/src/AmethystRuntime.cpp | 8 +++---- AmethystRuntime/src/AmethystRuntime.h | 20 +++++++++-------- AmethystRuntime/src/input/RuntimeInput.h | 22 +++++++++---------- AmethystRuntime/src/mod/ModFunctions.h | 8 ------- 12 files changed, 58 insertions(+), 49 deletions(-) create mode 100644 AmethystAPI/src/amethyst/runtime/AmethystContext.h delete mode 100644 AmethystRuntime/src/mod/ModFunctions.h diff --git a/AmethystAPI/CMakeLists.txt b/AmethystAPI/CMakeLists.txt index 80b7a108..d2ea3b5f 100644 --- a/AmethystAPI/CMakeLists.txt +++ b/AmethystAPI/CMakeLists.txt @@ -25,10 +25,6 @@ add_library(${PROJECT_NAME} STATIC src/minecraft/src/common/world/item/Item.asm src/minecraft/src/common/world/level/block/BlockLegacy.asm src/minecraft/src-deps/minecraftrenderer/renderer/MaterialPtr.asm - src/minecraft/src/common/world/level/BlockSourceListener.h - src/amethyst/runtime/input/InputManager.h - src/amethyst/runtime/input/InputManager.cpp - src/amethyst/runtime/input/InputAction.h ) diff --git a/AmethystAPI/src/amethyst/runtime/AmethystContext.h b/AmethystAPI/src/amethyst/runtime/AmethystContext.h new file mode 100644 index 00000000..28cf60c7 --- /dev/null +++ b/AmethystAPI/src/amethyst/runtime/AmethystContext.h @@ -0,0 +1,18 @@ +#pragma once +#include "minecraft/src-client/common/client/game/ClientInstance.h" +#include "amethyst/runtime/HookManager.h" +#include "amethyst/runtime/events/EventManager.h" + +class AmethystContext { +public: + /** + * Amethyst Specific stuff + */ + HookManager mHookManager; + Amethyst::EventManager mEventManager; + + /** + * Minecraft Specific stuff + */ + ClientInstance* mClientInstance = nullptr; +}; diff --git a/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp b/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp index c3dd079a..ac708e5b 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp +++ b/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.cpp @@ -6,14 +6,14 @@ // } BlockSource* ClientInstance::getRegion() { - using function = decltype(&getRegion); + using function = decltype(&ClientInstance::getRegion); auto func = std::bit_cast(this->vtable[27]); return (this->*func)(); } LocalPlayer* ClientInstance::getLocalPlayer() { - using function = decltype(&getLocalPlayer); + using function = decltype(&ClientInstance::getLocalPlayer); auto func = std::bit_cast(this->vtable[28]); return (this->*func)(); } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.h b/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.h index d517fbb3..45dd55c4 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.h +++ b/AmethystAPI/src/minecraft/src-client/common/client/game/ClientInstance.h @@ -45,12 +45,13 @@ class ClientInstance { /* this + 1384 */ std::byte padding1384[1848]; public: - // 1.20.51.1 - index 11 - // 40 55 53 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 45 8B F1 + // 1.20.51.1 - 48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 49 8B F9 49 8B D8 4C 8B E2 + ClientInstance(); + + // 1.20.51.1 - 40 55 53 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 45 8B F1 int64_t onStartJoinGame(ClientInstance*, int64_t, int64_t, int64_t); - // 1.20.51.1 - index: 13 - // 48 89 5C 24 ? 48 89 74 24 ? 55 57 41 54 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 45 0F B6 F0 44 0F B6 FA + // 1.20.51.1 - 48 89 5C 24 ? 48 89 74 24 ? 55 57 41 54 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 45 0F B6 F0 44 0F B6 FA void requestLeaveGame(char switchScreen, char sync); BlockSource* getRegion(); diff --git a/AmethystAPI/src/minecraft/src-client/common/client/renderer/Tessellator.cpp b/AmethystAPI/src/minecraft/src-client/common/client/renderer/Tessellator.cpp index 96906a87..cc37139b 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/renderer/Tessellator.cpp +++ b/AmethystAPI/src/minecraft/src-client/common/client/renderer/Tessellator.cpp @@ -1,7 +1,7 @@ #include "minecraft/src-client/common/client/renderer/Tessellator.h" void Tessellator::begin(mce::PrimitiveMode mode, int maxVertices) { - using function = decltype(&begin); + using function = decltype(&Tessellator::begin); if (this->mTessellating) { throw std::exception("Already tessellating!"); @@ -22,7 +22,7 @@ void Tessellator::vertex(const Vec3& vec) { } mce::Mesh Tessellator::end(uint64_t a3, std::string_view debugName, int a5) { - using function = decltype(&end); + using function = decltype(&Tessellator::end); static auto func = std::bit_cast(SigScan("48 8B C4 48 89 58 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 44 0F 29 40 ? 44 0F 29 48 ? 44 0F 29 90 ? ? ? ? 44 0F 29 98 ? ? ? ? 44 0F 29 A0 ? ? ? ? 44 0F 29 A8 ? ? ? ? 44 0F 29 B0 ? ? ? ? 44 0F 29 B8 ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4D 8B F9")); return (this->*func)(a3, debugName, a5); } @@ -83,7 +83,7 @@ void Tessellator::beginOverride() { } void Tessellator::clear() { - using function = decltype(&clear); + using function = decltype(&Tessellator::clear); static auto func = std::bit_cast(SigScan("48 83 EC ? C7 81 ? ? ? ? ? ? ? ? 4C 8B C9")); (this->*func)(); } diff --git a/AmethystAPI/src/minecraft/src-client/common/client/renderer/actor/ItemRenderer.cpp b/AmethystAPI/src/minecraft/src-client/common/client/renderer/actor/ItemRenderer.cpp index 6842d2b4..019231b2 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/renderer/actor/ItemRenderer.cpp +++ b/AmethystAPI/src/minecraft/src-client/common/client/renderer/actor/ItemRenderer.cpp @@ -2,7 +2,7 @@ void ItemRenderer::renderGuiItemNew(BaseActorRenderContext* renderContext, const ItemStack* item, uint32_t frame, float x, float y, bool forceEnchantmentFoil, float transparency, float lightMultiplyer, float scale) { - using function = decltype(&renderGuiItemNew); + using function = decltype(&ItemRenderer::renderGuiItemNew); static auto func = std::bit_cast(SigScan("48 8B C4 53 55 56 57 41 54 41 55 41 56 41 57 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 84 24 ? ? ? ? 45 8B E1")); (this->*func)(renderContext, item, frame, x, y, forceEnchantmentFoil, transparency, lightMultiplyer, scale); } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src-client/common/client/renderer/block/BlockTessellator.cpp b/AmethystAPI/src/minecraft/src-client/common/client/renderer/block/BlockTessellator.cpp index 85d30590..b381fa7d 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/renderer/block/BlockTessellator.cpp +++ b/AmethystAPI/src/minecraft/src-client/common/client/renderer/block/BlockTessellator.cpp @@ -7,13 +7,13 @@ //} void BlockTessellator::appendTessellatedBlock(Tessellator *tessellator, const Block *block) { - using function = decltype(&appendTessellatedBlock); + using function = decltype(&BlockTessellator::appendTessellatedBlock); static auto func = std::bit_cast(SigScan("48 8B C4 48 89 58 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 44 0F 29 40 ? 44 0F 29 48 ? 44 0F 29 90 ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4D 8B F8")); (this->*func)(tessellator, block); } int64_t BlockTessellator::tessellateInWorld(Tessellator &tessellator, const Block &block, const BlockPos &pos, bool a5, bool a6) { - using function = decltype(&tessellateInWorld); + using function = decltype(&BlockTessellator::tessellateInWorld); static auto func = std::bit_cast(SigScan("40 53 55 56 57 41 56 48 83 EC ? 80 79")); return (this->*func)(tessellator, block, pos, a5, a6); } diff --git a/AmethystAPI/src/minecraft/src-client/common/client/renderer/game/LevelRendererPlayer.cpp b/AmethystAPI/src/minecraft/src-client/common/client/renderer/game/LevelRendererPlayer.cpp index e39c7b47..436567d2 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/renderer/game/LevelRendererPlayer.cpp +++ b/AmethystAPI/src/minecraft/src-client/common/client/renderer/game/LevelRendererPlayer.cpp @@ -1,7 +1,7 @@ #include "minecraft/src-client/common/client/renderer/game/LevelRendererPlayer.h" float LevelRendererPlayer::getFov(float originalFov, bool applyEffects) { - using function = decltype(&getFov); + using function = decltype(&LevelRendererPlayer::getFov); static auto func = std::bit_cast(SigScan("48 8B C4 48 89 58 ? 48 89 70 ? 57 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 44 0F 29 40 ? 44 0F 29 48 ? 48 8B 05")); return (this->*func)(originalFov, applyEffects); } \ No newline at end of file diff --git a/AmethystRuntime/src/AmethystRuntime.cpp b/AmethystRuntime/src/AmethystRuntime.cpp index ac186176..3d9c9128 100644 --- a/AmethystRuntime/src/AmethystRuntime.cpp +++ b/AmethystRuntime/src/AmethystRuntime.cpp @@ -77,7 +77,7 @@ void AmethystRuntime::PromptDebugger() void AmethystRuntime::CreateOwnHooks() { - CreateInputHooks(); + //CreateInputHooks(); CreateModFunctionHooks(); } @@ -86,7 +86,7 @@ void AmethystRuntime::RunMods() { // Invoke mods to initialize and setup hooks, etc.. for (auto& modInitialize : mModInitialize) - modInitialize(getHookManager(), getEventManager()); + modInitialize(&mAmethystContext); ResumeGameThread(); @@ -107,10 +107,10 @@ void AmethystRuntime::RunMods() void AmethystRuntime::Shutdown() { // Prompt all mods to do any final code before shutdown - mEventManager.Shutdown(); + getEventManager()->Shutdown(); // Remove any of the runtime mods hooks - mHookManager.Shutdown(); + getEventManager()->Shutdown(); // Unload all mod Dlls for (auto& mod : mLoadedMods) { diff --git a/AmethystRuntime/src/AmethystRuntime.h b/AmethystRuntime/src/AmethystRuntime.h index c0e22fda..33d7cc09 100644 --- a/AmethystRuntime/src/AmethystRuntime.h +++ b/AmethystRuntime/src/AmethystRuntime.h @@ -1,14 +1,12 @@ #pragma once +#include #include "hooks/Hooks.h" #include "hooks/InputHooks.h" #include "input/RuntimeInput.h" #include "mod/Mod.h" -#include "mod/ModFunctions.h" #include -#include #include -#include -#include +#include #include #include #include @@ -16,9 +14,10 @@ #include #include + namespace fs = std::filesystem; -typedef void (*ModInitialize)(HookManager* hookManager, Amethyst::EventManager* eventManager); +typedef void (*ModInitialize)(AmethystContext* context); /* Entry: @@ -46,14 +45,18 @@ class AmethystRuntime { return instance; } + static AmethystContext* getContext() { + return &AmethystRuntime::getInstance()->mAmethystContext; + } + static HookManager* getHookManager() { - return &AmethystRuntime::getInstance()->mHookManager; + return &AmethystRuntime::getInstance()->mAmethystContext.mHookManager; } static Amethyst::EventManager* getEventManager() { - return &AmethystRuntime::getInstance()->mEventManager; + return &AmethystRuntime::getInstance()->mAmethystContext.mEventManager; } void Start(); @@ -73,9 +76,8 @@ class AmethystRuntime { private: Config mLauncherConfig; - HookManager mHookManager; - Amethyst::EventManager mEventManager; std::vector mLoadedMods; + AmethystContext mAmethystContext; public: // Mod Functions diff --git a/AmethystRuntime/src/input/RuntimeInput.h b/AmethystRuntime/src/input/RuntimeInput.h index 9dc3e097..8eedd5b2 100644 --- a/AmethystRuntime/src/input/RuntimeInput.h +++ b/AmethystRuntime/src/input/RuntimeInput.h @@ -1,15 +1,15 @@ #pragma once -#include -#include -#include - -struct InputAction { - const std::string mActionName; - int mDefaultKey = 0; - bool mAllowRemapping = 0; - std::function mButtonDownHandler = NULL; - std::function mButtonUpHandler = NULL; -}; +//#include +//#include +//#include +// +//struct InputAction { +// const std::string mActionName; +// int mDefaultKey = 0; +// bool mAllowRemapping = 0; +// std::function mButtonDownHandler = NULL; +// std::function mButtonUpHandler = NULL; +//}; //class RuntimeInputManager : public InputManager { //public: diff --git a/AmethystRuntime/src/mod/ModFunctions.h b/AmethystRuntime/src/mod/ModFunctions.h deleted file mode 100644 index 2dc2d8ac..00000000 --- a/AmethystRuntime/src/mod/ModFunctions.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -typedef void (*ModInitialize)(HookManager* hookManager, Amethyst::EventManager* eventManager); \ No newline at end of file From 2b684d21c733e79f4441f5b40ad5ce73232e028b Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Sat, 2 Mar 2024 22:16:57 +0000 Subject: [PATCH 04/14] Majority of stuff for ItemStackBase and ItemStack --- .../src/common/world/item/ItemInstance.h | 10 +++++ .../src/common/world/item/ItemStack.cpp | 13 +----- .../src/common/world/item/ItemStack.h | 13 ++++-- .../src/common/world/item/ItemStackBase.h | 40 +++++++++++++++---- .../minecraft/src/common/world/level/Tick.h | 7 ++++ AmethystRuntime/src/hooks/Hooks.cpp | 14 ++++++- 6 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 AmethystAPI/src/minecraft/src/common/world/item/ItemInstance.h create mode 100644 AmethystAPI/src/minecraft/src/common/world/level/Tick.h diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemInstance.h b/AmethystAPI/src/minecraft/src/common/world/item/ItemInstance.h new file mode 100644 index 00000000..68d2db27 --- /dev/null +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemInstance.h @@ -0,0 +1,10 @@ +#pragma once + +class ItemStackBase; + +class ItemInstance : public ItemStackBase { + +}; + +// ItemStackBase has ItemInstance as a member variable, so include has to be after declaration... +#include "minecraft/src/common/world/item/ItemStackBase.h" \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.cpp b/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.cpp index 76c996c0..d372e02b 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.cpp @@ -7,16 +7,5 @@ ItemStack::ItemStack() { // For whatever reason when this ctor is used in game, // the caller assigns the vtable for ItemStack over ItemStackBase - this->vtable = reinterpret_cast(SlideAddress(0x53C75F0)); // 1.20.51.1 -} - -void ItemStack::reinit(std::string_view name, int count, int auxValue) { - using function = void(__thiscall*)(ItemStack*, std::string_view, int, int); - reinterpret_cast(this->vtable[1])(this, name, count, auxValue); -} - -void ItemStack::reinit(const Item* item, int count, int auxValue) -{ - using function = void(__thiscall*)(ItemStack*, const Item*, int, int); - reinterpret_cast(this->vtable[3])(this, item, count, auxValue); + // reinterpret_cast(this) = reinterpret_cast(SlideAddress(0x53C75F0)); // 1.20.51.1 } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.h b/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.h index d133160b..0d4ccac9 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.h +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.h @@ -2,13 +2,18 @@ #include "minecraft/src/common/world/item/ItemStackBase.h" #include "amethyst/Memory.h" +class ItemStackNetIdVariant { + std::byte padding0[24]; +}; + +static_assert(sizeof(ItemStackNetIdVariant) == 24); + class ItemStack : public ItemStackBase { public: - ItemStack(); + ItemStackNetIdVariant mNetIdVariant; -//vfuncs: - void reinit(std::string_view name, int count, int auxValue); - void reinit(const Item*, int count, int auxValue); +public: + ItemStack(); }; static_assert(sizeof(ItemStack) == 0xA0); \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h index e43ec2c5..e73b8a75 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h @@ -1,20 +1,41 @@ #pragma once #include "amethyst/Memory.h" #include "minecraft/src/common/SharedPtr.h" +#include "minecraft/src/common/world/level/Tick.h" #include #include +#include class Item; class CompoundTag; +class BlockLegacy; +class Block; +class ItemInstance; class ItemStackBase { public: - uintptr_t** vtable; - WeakPtr mItem; // this + 8 - CompoundTag* mUserData; // this + 16 - std::byte padding0[10]; - byte count; // this + 34; - std::byte padding1[120]; + /* this + 8 */ WeakPtr mItem; + /* this + 16 */ CompoundTag* mUserData; + /* this + 24 */ const Block* mBlock; + /* this + 32 */ byte mCount; + /* this + 33 */ std::byte padding33[15]; + /* this + 48 */ bool mShowPickup; + /* this + 49 */ std::byte padding49[7]; + /* this + 56 */ std::vector mCanPlaceOn; + /* this + 80 */ size_t mCanPlaceOnHash; + /* this + 88 */ std::vector mCanDestroy; + /* this + 112 */ size_t mCanDestroyHash; + /* this + 120 */ Tick mBlockingTick; + /* this + 128 */ std::unique_ptr mChargedItem; + +public: + virtual ~ItemStackBase(); + virtual void reinit(const Item& item, int count, int auxValue); + virtual void reinit(const BlockLegacy& block, int count); + virtual void reinit(std::string_view name, int count, int auxValue); + virtual void setNull(std::optional reason); + virtual std::string toString() const; + virtual std::string toDebugString() const; public: // 1.20.51.1 - 48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 54 24 ? 57 48 83 EC ? 48 8B FA 48 8B E9 33 F6 @@ -22,4 +43,9 @@ class ItemStackBase { // 1.20.51.1 - 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 ? ? ? ? 48 8B F2 48 89 54 24 ? 4C 8B F9 48 89 4C 24 void _loadItem(const CompoundTag*); -}; \ No newline at end of file +}; + +static_assert(sizeof(ItemStackBase) == 0x88); + +// ItemInstance inherits from ItemStackBase but is also used as a member variable +#include "minecraft/src/common/world/item/ItemInstance.h" \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/level/Tick.h b/AmethystAPI/src/minecraft/src/common/world/level/Tick.h new file mode 100644 index 00000000..3d37ab15 --- /dev/null +++ b/AmethystAPI/src/minecraft/src/common/world/level/Tick.h @@ -0,0 +1,7 @@ +#pragma once +#include + +struct Tick { +public: + uint64_t tickID ; +}; \ No newline at end of file diff --git a/AmethystRuntime/src/hooks/Hooks.cpp b/AmethystRuntime/src/hooks/Hooks.cpp index 2ca1c627..f733920c 100644 --- a/AmethystRuntime/src/hooks/Hooks.cpp +++ b/AmethystRuntime/src/hooks/Hooks.cpp @@ -7,6 +7,7 @@ SafetyHookInline _Minecraft_update; SafetyHookInline _VanillaItems_registerItems; SafetyHookInline _BlockDefinitionGroup_registerBlocks; SafetyHookInline _LevelRenderer_renderLevel; +SafetyHookInline _ClientInstance_ClientInstance; void* ScreenView_setupAndRender(ScreenView* self, UIRenderContext* ctx) { @@ -77,6 +78,14 @@ void* LevelRenderer_renderLevel(LevelRenderer* self, ScreenContext* screenContex return _LevelRenderer_renderLevel.thiscall(self, screenContext, frameRenderObject); } +void* ClientInstance_ClientInstance(ClientInstance* self, uint64_t a2, uint64_t a3, uint64_t a4, char a5, void* a6, void* a7, uint64_t a8, void* a9) { + void* ret = _ClientInstance_ClientInstance.call(self, a2, a3, a4, a5, a6, a7, a8, a9); + + AmethystRuntime::getContext()->mClientInstance = self; + + return ret; +} + void CreateModFunctionHooks() { HookManager* hookManager = AmethystRuntime::getHookManager(); @@ -87,7 +96,7 @@ void CreateModFunctionHooks() { hookManager->RegisterFunction(&VanillaItems::registerItems, "40 55 53 56 57 41 54 41 56 41 57 48 8D AC 24 ? ? ? ? B8 ? ? ? ? E8 ? ? ? ? 48 2B E0 0F 29 B4 24"); hookManager->RegisterFunction(&BlockDefinitionGroup::registerBlocks, "48 89 5C 24 ? 48 89 6C 24 ? 56 57 41 54 41 56 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 84 24 ? ? ? ? 4C 8B F9"); hookManager->RegisterFunction(&LevelRenderer::renderLevel, "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 56 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 49 8B F0 48 8B DA 4C 8B F1"); - + hookManager->CreateHook(&ScreenView::setupAndRender, _ScreenView_setupAndRender, &ScreenView_setupAndRender); hookManager->CreateHook(&Minecraft::update, _Minecraft_update, &Minecraft_update); hookManager->CreateHook(&ClientInstance::onStartJoinGame, _ClientInstance_onStartJoinGame, &ClientInstance_onStartJoinGame); @@ -95,4 +104,7 @@ void CreateModFunctionHooks() { hookManager->CreateHook(&VanillaItems::registerItems, _VanillaItems_registerItems, &VanillaItems_registerItems); //hookManager->CreateHook(&BlockDefinitionGroup::registerBlocks, _BlockDefinitionGroup_registerBlocks, &BlockDefinitionGroup_registerBlocks); hookManager->CreateHook(&LevelRenderer::renderLevel, _LevelRenderer_renderLevel, &LevelRenderer_renderLevel); + + // C++ does not allow doing a reference to get the addresses of constructors... + hookManager->CreateHookAbsolute(_ClientInstance_ClientInstance, SigScan("48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 49 8B F9 49 8B D8 4C 8B E2"), &ClientInstance_ClientInstance); } \ No newline at end of file From 64869886ac7e0b3e932e40768022f8549f5a368b Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Sat, 2 Mar 2024 22:31:56 +0000 Subject: [PATCH 05/14] mPickupTime, mAuxValue, mCount --- .../src/minecraft/src/common/world/item/ItemStackBase.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h index e73b8a75..9ac387dd 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h @@ -5,6 +5,7 @@ #include #include #include +#include class Item; class CompoundTag; @@ -17,8 +18,10 @@ class ItemStackBase { /* this + 8 */ WeakPtr mItem; /* this + 16 */ CompoundTag* mUserData; /* this + 24 */ const Block* mBlock; - /* this + 32 */ byte mCount; - /* this + 33 */ std::byte padding33[15]; + /* this + 32 */ short mAuxValue; + /* this + 34 */ byte mCount; + /* this + 35 */ std::byte padding35[5]; + /* this + 40 */ std::chrono::steady_clock::time_point mPickupTime; /* this + 48 */ bool mShowPickup; /* this + 49 */ std::byte padding49[7]; /* this + 56 */ std::vector mCanPlaceOn; From e892708eec22f43eca49bfd597ed4c1c157c47c7 Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Sun, 3 Mar 2024 16:24:22 +0000 Subject: [PATCH 06/14] MinecraftInputHandler in MinecraftGame.. Add input handler to amethyst context --- .../src/amethyst/runtime/AmethystContext.h | 4 ++ .../amethyst/runtime/input/InputManager.cpp | 1 + .../src/amethyst/runtime/input/InputManager.h | 1 - .../common/client/game/MinecraftGame.h | 7 ++++ .../src/common/world/item/ItemStackBase.h | 20 ++++++++++ AmethystRuntime/src/AmethystRuntime.cpp | 2 +- AmethystRuntime/src/AmethystRuntime.h | 9 ++++- AmethystRuntime/src/hooks/InputHooks.cpp | 31 +++++++------- AmethystRuntime/src/input/RuntimeInput.cpp | 40 ------------------- AmethystRuntime/src/input/RuntimeInput.h | 23 ----------- 10 files changed, 57 insertions(+), 81 deletions(-) delete mode 100644 AmethystRuntime/src/input/RuntimeInput.cpp delete mode 100644 AmethystRuntime/src/input/RuntimeInput.h diff --git a/AmethystAPI/src/amethyst/runtime/AmethystContext.h b/AmethystAPI/src/amethyst/runtime/AmethystContext.h index 28cf60c7..fca4520a 100644 --- a/AmethystAPI/src/amethyst/runtime/AmethystContext.h +++ b/AmethystAPI/src/amethyst/runtime/AmethystContext.h @@ -1,7 +1,9 @@ #pragma once #include "minecraft/src-client/common/client/game/ClientInstance.h" +#include "minecraft/src-client/common/client/input/MinecraftInputHandler.h" #include "amethyst/runtime/HookManager.h" #include "amethyst/runtime/events/EventManager.h" +#include "amethyst/runtime/input/InputManager.h" class AmethystContext { public: @@ -10,9 +12,11 @@ class AmethystContext { */ HookManager mHookManager; Amethyst::EventManager mEventManager; + Amethyst::InputManager mInputManager; /** * Minecraft Specific stuff */ ClientInstance* mClientInstance = nullptr; + MinecraftInputHandler* mMcInputHandler = nullptr; }; diff --git a/AmethystAPI/src/amethyst/runtime/input/InputManager.cpp b/AmethystAPI/src/amethyst/runtime/input/InputManager.cpp index e08ae0ff..5ba286bf 100644 --- a/AmethystAPI/src/amethyst/runtime/input/InputManager.cpp +++ b/AmethystAPI/src/amethyst/runtime/input/InputManager.cpp @@ -3,4 +3,5 @@ void Amethyst::InputManager::RegisterNewInput(const std::string& inputName, int defaultButton, bool allowRemapping) { const InputAction inputAction(inputName, defaultButton, allowRemapping); mInputActions.push_back(inputAction); + Log::Info("made a new input action {} :)", inputName); } diff --git a/AmethystAPI/src/amethyst/runtime/input/InputManager.h b/AmethystAPI/src/amethyst/runtime/input/InputManager.h index 4136b2ec..672eea24 100644 --- a/AmethystAPI/src/amethyst/runtime/input/InputManager.h +++ b/AmethystAPI/src/amethyst/runtime/input/InputManager.h @@ -10,7 +10,6 @@ namespace Amethyst { class InputManager { public: void RegisterNewInput(const std::string& inputName, int defaultButton, bool allowRemapping); - void AddButtonDownListener(const std::string& inputName, std::function); private: std::vector mInputActions; diff --git a/AmethystAPI/src/minecraft/src-client/common/client/game/MinecraftGame.h b/AmethystAPI/src/minecraft/src-client/common/client/game/MinecraftGame.h index 655e4ba4..42f64968 100644 --- a/AmethystAPI/src/minecraft/src-client/common/client/game/MinecraftGame.h +++ b/AmethystAPI/src/minecraft/src-client/common/client/game/MinecraftGame.h @@ -1,7 +1,14 @@ #pragma once +#include // class MinecraftGame : public BedrockEngine::AppIsland, App, IMinecraftGame, LevelListener, // ResourcePackListener, OptionsObserver, ActiveDirectoryIdentityObserver +class MinecraftInputHandler; + class MinecraftGame { +public: + /* this + 0 */ uintptr_t** vtable; + /* this + 8 */ std::byte padding8[3320]; + /* this + 3328 */ std::unique_ptr mInput; }; \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h index 9ac387dd..9049d7d9 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h @@ -13,6 +13,26 @@ class BlockLegacy; class Block; class ItemInstance; +//is_virtual = True +// hide_vtable = True +// struct_size = 0x88 +// +//#(Type, Name, Size(in bytes), Offset(in bytes)) +// struct +// = [("WeakPtr", "mItem", 8, 8), +// ("CompoundTag*", "mUserData", 8, 16), +// ("short", "mAuxValue", 2, 32), +// ("byte", "mCount", 1, 34), +// ("bool", "mShowPickup", 1, 48), +// ("const Block*", "mBlock", 8, 24), +// ("std::vector", "mCanPlaceOn", 24, 56), +// ("std::vector", "mCanDestroy", 24, 88), +// ("std::unique_ptr", "mChargedItem", 8, 128), +// ("size_t", "mCanPlaceOnHash", 8, 80), +// ("Tick", "mBlockingTick", 8, 120), +// ("size_t", "mCanDestroyHash", 8, 112), +// ("std::chrono::steady_clock::time_point", "mPickupTime", 8, 40)] + class ItemStackBase { public: /* this + 8 */ WeakPtr mItem; diff --git a/AmethystRuntime/src/AmethystRuntime.cpp b/AmethystRuntime/src/AmethystRuntime.cpp index 3d9c9128..b62c1ba7 100644 --- a/AmethystRuntime/src/AmethystRuntime.cpp +++ b/AmethystRuntime/src/AmethystRuntime.cpp @@ -77,7 +77,7 @@ void AmethystRuntime::PromptDebugger() void AmethystRuntime::CreateOwnHooks() { - //CreateInputHooks(); + CreateInputHooks(); CreateModFunctionHooks(); } diff --git a/AmethystRuntime/src/AmethystRuntime.h b/AmethystRuntime/src/AmethystRuntime.h index 33d7cc09..c5937316 100644 --- a/AmethystRuntime/src/AmethystRuntime.h +++ b/AmethystRuntime/src/AmethystRuntime.h @@ -2,7 +2,6 @@ #include #include "hooks/Hooks.h" #include "hooks/InputHooks.h" -#include "input/RuntimeInput.h" #include "mod/Mod.h" #include #include @@ -45,7 +44,8 @@ class AmethystRuntime { return instance; } - static AmethystContext* getContext() { + static AmethystContext* getContext() + { return &AmethystRuntime::getInstance()->mAmethystContext; } @@ -59,6 +59,11 @@ class AmethystRuntime { return &AmethystRuntime::getInstance()->mAmethystContext.mEventManager; } + static Amethyst::InputManager* getInputManager() + { + return &AmethystRuntime::getInstance()->mAmethystContext.mInputManager; + } + void Start(); void Shutdown(); diff --git a/AmethystRuntime/src/hooks/InputHooks.cpp b/AmethystRuntime/src/hooks/InputHooks.cpp index 218731c4..df6808c9 100644 --- a/AmethystRuntime/src/hooks/InputHooks.cpp +++ b/AmethystRuntime/src/hooks/InputHooks.cpp @@ -6,34 +6,37 @@ SafetyHookInline __registerInputHandlers; void assignDefaultMapping(RemappingLayout* self, std::vector&& mapping) { - /*RuntimeInputManager* inputManager = AmethystRuntime::getInputManager(); + Amethyst::InputManager* inputManager = AmethystRuntime::getInputManager(); + _assignDefaultMapping.call(self, std::move(mapping)); - for (auto& input : inputManager->mInputActions) { - std::string keyName = "key." + input.mActionName; - Keymapping keymapping(keyName, {input.mDefaultKey}, input.mAllowRemapping); + for (auto& input : inputManager->mInputActions) + { + std::string keyName = "key." + input.mInputName; + Keymapping keymapping(keyName, {input.mDefaultButton}, input.mAllowRemapping); mapping.emplace_back(keymapping); } - _assignDefaultMapping.call>(self, std::move(mapping));*/ + Log::Info("assignDefaultMapping"); } void addFullKeyboardGamePlayControls(VanillaClientInputMappingFactory* self, KeyboardInputMapping* keyboard, MouseInputMapping* mouse) { - /*_addFullKeyboardGamePlayControls - .call(self, keyboard, mouse); + Amethyst::InputManager* inputManager = AmethystRuntime::getInputManager(); + _addFullKeyboardGamePlayControls.call(self, keyboard, mouse); - RuntimeInputManager* inputManager = AmethystRuntime::getInputManager(); + for (auto& input : inputManager->mInputActions) { + std::string keyName = "key." + input.mInputName; + std::string buttonName = "button." + input.mInputName; + self->createKeyboardAndMouseBinding(keyboard, mouse, &buttonName, &keyName); + } - for (auto& input : inputManager->mInputActions) { - std::string keyName = "key." + input.mActionName; - std::string buttonName = "button." + input.mActionName; - self->createKeyboardAndMouseBinding(keyboard, mouse, &buttonName, &keyName); - }*/ + Log::Info("addFullKeyboardGamePlayControls"); } void _registerInputHandlers(MinecraftInputHandler* self) { - //__registerInputHandlers.call(self); + __registerInputHandlers.call(self); + //RuntimeInputManager* inputManager = AmethystRuntime::getInputManager(); //InputHandler* inputHandler = self->mInputHandler.get(); diff --git a/AmethystRuntime/src/input/RuntimeInput.cpp b/AmethystRuntime/src/input/RuntimeInput.cpp deleted file mode 100644 index 9e7a00ed..00000000 --- a/AmethystRuntime/src/input/RuntimeInput.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "input/RuntimeInput.h" - -//void RuntimeInputManager::RegisterInput(const std::string& actionName, int defaultButton, bool allowRemapping) -//{ -// InputAction inputAction = {actionName, defaultButton, allowRemapping, NULL, NULL}; -// mInputActions.push_back(inputAction); -//} -// -//void RuntimeInputManager::AddButtonDownHandler(const std::string& actionName, std::function handler) -//{ -// for (auto& input : mInputActions) { -// if (input.mActionName != actionName) continue; -// input.mButtonDownHandler = handler; -// return; -// } -// -// std::string message = fmt::format("Input Action '{}' has not been registered. Ensure that you have restarted the game after registering a new input action", actionName); -// throw std::exception(message.c_str()); -//} -// -//void RuntimeInputManager::AddButtonUpHandler(const std::string& actionName, std::function handler) -//{ -// for (auto& input : mInputActions) { -// if (input.mActionName != actionName) continue; -// input.mButtonUpHandler = handler; -// return; -// } -// -// std::string message = fmt::format("Input Action '{}' has not been registered. Ensure that you have restarted the game after registering a new input action", actionName); -// throw std::exception(message.c_str()); -//} -// -//void RuntimeInputManager::Shutdown() -//{ -// // Destroy any references to callbacks in an unloaded Dll -// for (auto& input : mInputActions) { -// input.mButtonDownHandler = NULL; -// input.mButtonUpHandler = NULL; -// } -//} diff --git a/AmethystRuntime/src/input/RuntimeInput.h b/AmethystRuntime/src/input/RuntimeInput.h deleted file mode 100644 index 8eedd5b2..00000000 --- a/AmethystRuntime/src/input/RuntimeInput.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -//#include -//#include -//#include -// -//struct InputAction { -// const std::string mActionName; -// int mDefaultKey = 0; -// bool mAllowRemapping = 0; -// std::function mButtonDownHandler = NULL; -// std::function mButtonUpHandler = NULL; -//}; - -//class RuntimeInputManager : public InputManager { -//public: -// std::vector mInputActions; -// -//public: -// virtual void RegisterInput(const std::string& actionName, int defaultButton, bool allowRemapping = true) override; -// virtual void AddButtonDownHandler(const std::string& actionName, std::function handler) override; -// virtual void AddButtonUpHandler(const std::string& actionName, std::function handler) override; -// void Shutdown(); -//}; \ No newline at end of file From e18c2b2782655a7e6ac66c56c81a8665572d1aaa Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Fri, 8 Mar 2024 11:38:52 +0000 Subject: [PATCH 07/14] Better error handling for if a signature is not found in register function --- AmethystAPI/.gitignore | 3 +-- AmethystAPI/.idea/.gitignore | 8 ++++++++ AmethystAPI/.idea/AmethystAPI.iml | 2 ++ AmethystAPI/.idea/cmake.xml | 8 ++++++++ AmethystAPI/.idea/misc.xml | 4 ++++ AmethystAPI/.idea/modules.xml | 8 ++++++++ AmethystAPI/.idea/vcs.xml | 7 +++++++ AmethystAPI/CMakeLists.txt | 2 +- AmethystAPI/src/amethyst/Memory.cpp | 18 +++++++++++++----- AmethystAPI/src/amethyst/Memory.h | 5 +++++ .../src/amethyst/runtime/HookManager.h | 9 ++++++++- .../amethyst/runtime/input/InputManager.cpp | 7 +++++++ .../src/amethyst/runtime/input/InputManager.h | 7 ++++--- AmethystRuntime/src/AmethystRuntime.cpp | 3 ++- AmethystRuntime/src/hooks/InputHooks.cpp | 19 +++++++++---------- 15 files changed, 87 insertions(+), 23 deletions(-) create mode 100644 AmethystAPI/.idea/.gitignore create mode 100644 AmethystAPI/.idea/AmethystAPI.iml create mode 100644 AmethystAPI/.idea/cmake.xml create mode 100644 AmethystAPI/.idea/misc.xml create mode 100644 AmethystAPI/.idea/modules.xml create mode 100644 AmethystAPI/.idea/vcs.xml diff --git a/AmethystAPI/.gitignore b/AmethystAPI/.gitignore index 38e5744c..57c84b90 100644 --- a/AmethystAPI/.gitignore +++ b/AmethystAPI/.gitignore @@ -1,2 +1 @@ -/cmake-build-relwithdebinfo-visual-studio -/.idea \ No newline at end of file +/cmake-build-relwithdebinfo-visual-studio \ No newline at end of file diff --git a/AmethystAPI/.idea/.gitignore b/AmethystAPI/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/AmethystAPI/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/AmethystAPI/.idea/AmethystAPI.iml b/AmethystAPI/.idea/AmethystAPI.iml new file mode 100644 index 00000000..f08604bb --- /dev/null +++ b/AmethystAPI/.idea/AmethystAPI.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/AmethystAPI/.idea/cmake.xml b/AmethystAPI/.idea/cmake.xml new file mode 100644 index 00000000..a3749e6d --- /dev/null +++ b/AmethystAPI/.idea/cmake.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/AmethystAPI/.idea/misc.xml b/AmethystAPI/.idea/misc.xml new file mode 100644 index 00000000..79b3c948 --- /dev/null +++ b/AmethystAPI/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/AmethystAPI/.idea/modules.xml b/AmethystAPI/.idea/modules.xml new file mode 100644 index 00000000..dc9a612f --- /dev/null +++ b/AmethystAPI/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/AmethystAPI/.idea/vcs.xml b/AmethystAPI/.idea/vcs.xml new file mode 100644 index 00000000..c204906b --- /dev/null +++ b/AmethystAPI/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/AmethystAPI/CMakeLists.txt b/AmethystAPI/CMakeLists.txt index d2ea3b5f..4a0fdb8f 100644 --- a/AmethystAPI/CMakeLists.txt +++ b/AmethystAPI/CMakeLists.txt @@ -77,4 +77,4 @@ foreach(_source IN ITEMS ${SOURCES} ${HEADERS}) file(RELATIVE_PATH _source_path_rel "${CMAKE_CURRENT_SOURCE_DIR}/src" "${_source_path}") string(REPLACE "/" "\\" _group_path "${_source_path_rel}") source_group("${_group_path}" FILES "${_source}") -endforeach() \ No newline at end of file +endforeach() diff --git a/AmethystAPI/src/amethyst/Memory.cpp b/AmethystAPI/src/amethyst/Memory.cpp index b4448db7..6158541b 100644 --- a/AmethystAPI/src/amethyst/Memory.cpp +++ b/AmethystAPI/src/amethyst/Memory.cpp @@ -2,6 +2,7 @@ #include #include #include +#include uintptr_t GetMinecraftBaseAddress() { @@ -25,7 +26,7 @@ uintptr_t SlideAddress(uintptr_t offset) return GetMinecraftBaseAddress() + offset; } -uintptr_t SigScan(std::string_view signature) +std::optional SigScanSafe(std::string_view signature) { const auto parsed = hat::parse_signature(signature); if (!parsed.has_value()) { @@ -37,12 +38,19 @@ uintptr_t SigScan(std::string_view signature) const auto end = begin + GetMinecraftSize(); const auto result = hat::find_pattern(begin, end, parsed.value()); - if (!result.has_result()) { - Log::Error("Sigscan failed! {:s}", signature); - throw std::exception(); + if (!result.has_result()) return std::nullopt; + return reinterpret_cast(result.get()); +} + +uintptr_t SigScan(std::string_view signature) { + auto result = SigScanSafe(signature); + + if (!result.has_value()) { + std::string errorMessage = fmt::format("Failed to find signature \"{:s}\"", signature); + throw std::exception(errorMessage.c_str()); } - return reinterpret_cast(result.get()); + return result.value(); } size_t FindOffsetOfPointer(void* _base, void* _pointer, size_t maxSearchSize) diff --git a/AmethystAPI/src/amethyst/Memory.h b/AmethystAPI/src/amethyst/Memory.h index 5af89249..a37ce74e 100644 --- a/AmethystAPI/src/amethyst/Memory.h +++ b/AmethystAPI/src/amethyst/Memory.h @@ -24,6 +24,11 @@ Offsets an address from the game binary, with the position the game has been loa */ uintptr_t SlideAddress(uintptr_t offset); +/* +Finds an address of a function with its signature within the loaded game memory +*/ +std::optional SigScanSafe(std::string_view signature); + /* Finds an address of a function with its signature within the loaded game memory */ diff --git a/AmethystAPI/src/amethyst/runtime/HookManager.h b/AmethystAPI/src/amethyst/runtime/HookManager.h index f04a213a..1ead0445 100644 --- a/AmethystAPI/src/amethyst/runtime/HookManager.h +++ b/AmethystAPI/src/amethyst/runtime/HookManager.h @@ -40,7 +40,14 @@ class HookManager { // If the event has not yet been created, make it, else re-use if (mFuncHashToOriginalAddress.find(hash) == mFuncHashToOriginalAddress.end()) { - mFuncHashToOriginalAddress[hash] = SigScan(signature); + auto result = SigScanSafe(signature); + + if (!result.has_value()) { + std::string error = fmt::format("Failed to find function: \"{}\"\nUsing signature: \"{}\"", typeid(function).name(), signature); + throw std::exception(error.c_str()); + } + + mFuncHashToOriginalAddress[hash] = result.value(); } } diff --git a/AmethystAPI/src/amethyst/runtime/input/InputManager.cpp b/AmethystAPI/src/amethyst/runtime/input/InputManager.cpp index 5ba286bf..684407d2 100644 --- a/AmethystAPI/src/amethyst/runtime/input/InputManager.cpp +++ b/AmethystAPI/src/amethyst/runtime/input/InputManager.cpp @@ -5,3 +5,10 @@ void Amethyst::InputManager::RegisterNewInput(const std::string& inputName, int mInputActions.push_back(inputAction); Log::Info("made a new input action {} :)", inputName); } + +void Amethyst::InputManager::Shutdown() +{ + // Remove any input listeners + // Remove bindings in VanillaClientInputMappingFactory + // Remove any things in the RemappingLayout +} \ No newline at end of file diff --git a/AmethystAPI/src/amethyst/runtime/input/InputManager.h b/AmethystAPI/src/amethyst/runtime/input/InputManager.h index 672eea24..5a4f9dad 100644 --- a/AmethystAPI/src/amethyst/runtime/input/InputManager.h +++ b/AmethystAPI/src/amethyst/runtime/input/InputManager.h @@ -9,9 +9,10 @@ namespace Amethyst { class InputManager { public: - void RegisterNewInput(const std::string& inputName, int defaultButton, bool allowRemapping); - - private: std::vector mInputActions; + + public: + void RegisterNewInput(const std::string& inputName, int defaultButton, bool allowRemapping); + void Shutdown(); }; } \ No newline at end of file diff --git a/AmethystRuntime/src/AmethystRuntime.cpp b/AmethystRuntime/src/AmethystRuntime.cpp index b62c1ba7..1ee04206 100644 --- a/AmethystRuntime/src/AmethystRuntime.cpp +++ b/AmethystRuntime/src/AmethystRuntime.cpp @@ -77,7 +77,7 @@ void AmethystRuntime::PromptDebugger() void AmethystRuntime::CreateOwnHooks() { - CreateInputHooks(); + // CreateInputHooks(); CreateModFunctionHooks(); } @@ -98,6 +98,7 @@ void AmethystRuntime::RunMods() if (GetAsyncKeyState('R') & 0x8000) { Log::Info("\n========================= Beginning hot-reload! ========================="); + Shutdown(); return Start(); } diff --git a/AmethystRuntime/src/hooks/InputHooks.cpp b/AmethystRuntime/src/hooks/InputHooks.cpp index df6808c9..8eba3a1f 100644 --- a/AmethystRuntime/src/hooks/InputHooks.cpp +++ b/AmethystRuntime/src/hooks/InputHooks.cpp @@ -6,8 +6,8 @@ SafetyHookInline __registerInputHandlers; void assignDefaultMapping(RemappingLayout* self, std::vector&& mapping) { + Log::Info("assignDefaultMapping"); Amethyst::InputManager* inputManager = AmethystRuntime::getInputManager(); - _assignDefaultMapping.call(self, std::move(mapping)); for (auto& input : inputManager->mInputActions) { @@ -16,7 +16,7 @@ void assignDefaultMapping(RemappingLayout* self, std::vector&& mappi mapping.emplace_back(keymapping); } - Log::Info("assignDefaultMapping"); + _assignDefaultMapping.call(self, std::move(mapping)); } void addFullKeyboardGamePlayControls(VanillaClientInputMappingFactory* self, KeyboardInputMapping* keyboard, MouseInputMapping* mouse) @@ -29,8 +29,6 @@ void addFullKeyboardGamePlayControls(VanillaClientInputMappingFactory* self, Key std::string buttonName = "button." + input.mInputName; self->createKeyboardAndMouseBinding(keyboard, mouse, &buttonName, &keyName); } - - Log::Info("addFullKeyboardGamePlayControls"); } void _registerInputHandlers(MinecraftInputHandler* self) @@ -69,12 +67,13 @@ void CreateInputHooks() { HookManager* hookManager = AmethystRuntime::getHookManager(); - hookManager->RegisterFunction(&RemappingLayout::assignDefaultMapping, "48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8B EC 48 83 EC ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 4C 8B C2"); - hookManager->CreateHook(&RemappingLayout::assignDefaultMapping, _assignDefaultMapping, &assignDefaultMapping); + /*hookManager->RegisterFunction(&RemappingLayout::assignDefaultMapping, "48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8B EC 48 83 EC ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 4C 8B C2"); + hookManager->CreateHook(&RemappingLayout::assignDefaultMapping, _assignDefaultMapping, &assignDefaultMapping);*/ - hookManager->RegisterFunction(&VanillaClientInputMappingFactory::_addFullKeyboardGamePlayControls, "40 55 53 56 57 41 56 48 8B EC 48 83 EC ? 45 0F B6 F1"); - hookManager->CreateHook(&VanillaClientInputMappingFactory::_addFullKeyboardGamePlayControls, _addFullKeyboardGamePlayControls, &addFullKeyboardGamePlayControls); + /*hookManager->RegisterFunction(&VanillaClientInputMappingFactory::_addFullKeyboardGamePlayControls, "40 55 53 56 57 41 56 48 8B EC 48 83 EC ? 45 0F B6 F1"); + hookManager->CreateHook(&VanillaClientInputMappingFactory::_addFullKeyboardGamePlayControls, _addFullKeyboardGamePlayControls, &addFullKeyboardGamePlayControls);*/ - hookManager->RegisterFunction(&MinecraftInputHandler::_registerInputHandlers, "48 89 5C 24 ? 55 56 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B F1 48 8D 05"); - hookManager->CreateHook(&MinecraftInputHandler::_registerInputHandlers, __registerInputHandlers, &_registerInputHandlers); + // 48 89 5C 24 ? 55 56 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B F1 48 8D 05 + /*hookManager->RegisterFunction(&MinecraftInputHandler::_registerInputHandlers, "48 89 5C 24 ? 55 56 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B F1 48 8D 05"); + hookManager->CreateHook(&MinecraftInputHandler::_registerInputHandlers, __registerInputHandlers, &_registerInputHandlers);*/ } \ No newline at end of file From 8d2cd959d11b4afaa1ab779ba9b77a88e4b6430d Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Sat, 9 Mar 2024 14:24:11 +0000 Subject: [PATCH 08/14] Implement some stuff to do with ItemStackBase and ItemStack --- AmethystAPI/CMakeLists.txt | 2 +- AmethystAPI/src/amethyst/Log.h | 46 ++++++----- .../minecraft/src/common/nbt/CompoundTag.cpp | 16 +++- .../minecraft/src/common/nbt/CompoundTag.h | 5 ++ .../inventory/network/ItemStackNetIdVariant.h | 18 +++++ .../minecraft/src/common/world/item/Item.cpp | 12 ++- .../minecraft/src/common/world/item/Item.h | 3 +- .../src/common/world/item/ItemStack.cpp | 10 +-- .../src/common/world/item/ItemStack.h | 7 +- .../src/common/world/item/ItemStackBase.cpp | 78 ++++++++++++++++++- .../src/common/world/item/ItemStackBase.h | 25 +++--- .../minecraft/src/common/world/level/Tick.h | 6 +- 12 files changed, 177 insertions(+), 51 deletions(-) create mode 100644 AmethystAPI/src/minecraft/src/common/world/inventory/network/ItemStackNetIdVariant.h diff --git a/AmethystAPI/CMakeLists.txt b/AmethystAPI/CMakeLists.txt index 4a0fdb8f..79828589 100644 --- a/AmethystAPI/CMakeLists.txt +++ b/AmethystAPI/CMakeLists.txt @@ -17,7 +17,7 @@ set_property(GLOBAL PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.c" "src/*.asm") file(GLOB_RECURSE HEADERS "src/*.h" "src/*.hpp") - + # Create AmethystAPI as a .lib add_library(${PROJECT_NAME} STATIC ${SOURCES} diff --git a/AmethystAPI/src/amethyst/Log.h b/AmethystAPI/src/amethyst/Log.h index 4022373f..711201ec 100644 --- a/AmethystAPI/src/amethyst/Log.h +++ b/AmethystAPI/src/amethyst/Log.h @@ -5,24 +5,34 @@ #include namespace Log { -void InitializeConsole(); -void DestroyConsole(); + void InitializeConsole(); + void DestroyConsole(); -template -void Info(fmt::format_string fmt, T&&... args) { - std::string formatted_string = fmt::format(fmt, std::forward(args)...); - fmt::print("{}\n", formatted_string); -} + template + void Info(fmt::format_string fmt, T&&... args) { + std::string formatted_string = fmt::format(fmt, std::forward(args)...); + fmt::print("{}\n", formatted_string); + } -template -void Warning(fmt::format_string fmt, T&&... args) { - std::string formatted_string = fmt::format(fmt, std::forward(args)...); - fmt::print(fg(fmt::rgb(0xf5f556)) | fmt::emphasis::bold, "{}\n", formatted_string); -} + template + void Warning(fmt::format_string fmt, T&&... args) { + std::string formatted_string = fmt::format(fmt, std::forward(args)...); + fmt::print(fg(fmt::rgb(0xf5f556)) | fmt::emphasis::bold, "{}\n", formatted_string); + } -template -void Error(fmt::format_string fmt, T&&... args) { - std::string formatted_string = fmt::format(fmt, std::forward(args)...); - fmt::print(fg(fmt::rgb(0xf55762)) | fmt::emphasis::bold, "{}\n", formatted_string); -} -}; // namespace Log \ No newline at end of file + template + void Error(fmt::format_string fmt, T&&... args) { + std::string formatted_string = fmt::format(fmt, std::forward(args)...); + fmt::print(fg(fmt::rgb(0xf55762)) | fmt::emphasis::bold, "{}\n", formatted_string); + } + + template + inline void _Assert(const char* function, int line, fmt::format_string fmt, T&&... args) + { + std::string formatted_string = fmt::format(fmt, std::forward(args)...); + formatted_string += fmt::format("\n\tin: {}, line: {}", function, line); + throw std::exception(formatted_string.c_str()); + } + + #define Assert(...) _Assert(__FUNCTION__, __LINE__, __VA_ARGS__) + }; // namespace Log \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.cpp b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.cpp index dfabd61d..466ddd62 100644 --- a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.cpp +++ b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.cpp @@ -115,4 +115,18 @@ const std::string* CompoundTag::getString(std::string_view name) const void CompoundTag::putString(std::string name, std::string value) { StringTag stringTag(value); mTags[name].emplace(stringTag); -} \ No newline at end of file +} + +const IntTag* CompoundTag::getIntTag(std::string_view name) const { + return get(name); +} + +IntTag* CompoundTag::getIntTag(std::string_view name) { + return get(name); +} + +int CompoundTag::getInt(std::string_view name) const { + auto tag = getIntTag(name); + if (tag) return tag->data; + return 0; +} diff --git a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.h b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.h index 1978dfc4..a6c58596 100644 --- a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.h +++ b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.h @@ -3,6 +3,7 @@ #include "minecraft/src/common/nbt/ByteTag.h" #include "minecraft/src/common/nbt/ListTag.h" #include "minecraft/src/common/nbt/StringTag.h" +#include "minecraft/src/common/nbt/IntTag.h" #include #include @@ -33,6 +34,10 @@ class CompoundTag : public Tag { const std::string* getString(std::string_view name) const; void putString(std::string name, std::string value); + const IntTag* getIntTag(std::string_view name) const; + IntTag* getIntTag(std::string_view name); + int getInt(std::string_view name) const; + private: template const T* get(std::string_view) const; diff --git a/AmethystAPI/src/minecraft/src/common/world/inventory/network/ItemStackNetIdVariant.h b/AmethystAPI/src/minecraft/src/common/world/inventory/network/ItemStackNetIdVariant.h new file mode 100644 index 00000000..44f7cbb6 --- /dev/null +++ b/AmethystAPI/src/minecraft/src/common/world/inventory/network/ItemStackNetIdVariant.h @@ -0,0 +1,18 @@ +#pragma once +#include +#include + +class SomethingWithSize16 { + uint64_t a; + uint64_t b; +}; + +class ItemStackNetIdVariant { + // std::variant, TypedClientNetId, TypedClientNetId> mVariant; + std::variant mVariant; + +public: + ItemStackNetIdVariant() = default; +}; + +static_assert(sizeof(ItemStackNetIdVariant) == 24); \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/item/Item.cpp b/AmethystAPI/src/minecraft/src/common/world/item/Item.cpp index cdf3de0a..e1165215 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/Item.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/item/Item.cpp @@ -10,11 +10,11 @@ Item::Item(const std::string& stringId, short numericalId) } #pragma warning(pop) -short Item::getDamageValue(CompoundTag* mUserData) const +short Item::getDamageValue(CompoundTag* userData) const { - using function = decltype(&Item::getDamageValue); - static auto func = std::bit_cast(SigScan("48 89 5C 24 ? 57 48 83 EC ? 48 8B DA 48 85 D2")); - return (this->*func)(mUserData); + if (userData == nullptr) return 0; + if (!userData->contains("Damage")) return 0; + return (short)userData->getInt("Damage"); } Item::~Item() { @@ -28,6 +28,10 @@ void Item::addCreativeItem(ItemRegistryRef* a1, const Block* a2) func(a1, a2); } +const std::string& Item::getRawNameId() const { + return mRawNameId.getString(); +} + // //uint64_t Item::getMaxDamage() const //{ diff --git a/AmethystAPI/src/minecraft/src/common/world/item/Item.h b/AmethystAPI/src/minecraft/src/common/world/item/Item.h index d1bb9373..93e054ae 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/Item.h +++ b/AmethystAPI/src/minecraft/src/common/world/item/Item.h @@ -10,8 +10,8 @@ #include "minecraft/src/common/world/item/ItemCategory.h" #include "minecraft/src/common/world/item/registry/ItemRegistryRef.h" #include +#include "minecraft/src/common/nbt/CompoundTag.h" -class CompoundTag; class Level; class ItemStackBase; namespace Json { @@ -230,6 +230,7 @@ class Item { public: Item(const std::string&, short); short getDamageValue(CompoundTag* mUserData) const; + const std::string& getRawNameId() const; // 1.20.51.1 - 48 89 4C 24 ? 53 48 81 EC ? ? ? ? 48 8B D9 45 33 C9 static void addCreativeItem(ItemRegistryRef*, const Block*); diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.cpp b/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.cpp index d372e02b..edfc40dd 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.cpp @@ -1,11 +1,5 @@ #include "minecraft/src/common/world/item/ItemStack.h" -ItemStack::ItemStack() { - using function = void(__thiscall*)(ItemStack*); - static auto func = reinterpret_cast(SigScan("48 89 4C 24 ? 53 48 83 EC ? 48 8B D9 48 8D 05 ? ? ? ? 48 89 01 33 C0 48 89 41 ? 48 89 41 ? 48 89 41 ? C7 41 ? ? ? ? ? 48 89 41 ? 66 C7 41 ? ? ? 48 89 41 ? 48 89 41 ? 48 89 41 ? 48 89 41 ? 48 89 41 ? 48 89 41 ? 48 89 41 ? 48 89 41 ? 48 89 41 ? 48 89 81 ? ? ? ? 88 44 24")); - func(this); - - // For whatever reason when this ctor is used in game, - // the caller assigns the vtable for ItemStack over ItemStackBase - // reinterpret_cast(this) = reinterpret_cast(SlideAddress(0x53C75F0)); // 1.20.51.1 +ItemStack::ItemStack() : ItemStackBase() { + this->vtable = reinterpret_cast(SlideAddress(0x53F5CF8)); } \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.h b/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.h index 0d4ccac9..5aedef2b 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.h +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStack.h @@ -1,12 +1,7 @@ #pragma once #include "minecraft/src/common/world/item/ItemStackBase.h" #include "amethyst/Memory.h" - -class ItemStackNetIdVariant { - std::byte padding0[24]; -}; - -static_assert(sizeof(ItemStackNetIdVariant) == 24); +#include "minecraft/src/common/world/inventory/network/ItemStackNetIdVariant.h" class ItemStack : public ItemStackBase { public: diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp index 8450e334..334b1ff5 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp @@ -18,4 +18,80 @@ void ItemStackBase::_loadItem(const CompoundTag* a1) { ); (this->*func)(a1); -} \ No newline at end of file +} + +void ItemStackBase::reinit(const Item& item, int count, int auxValue) +{ + using function = void(ItemStackBase::*)(const Item&, int, int); + auto func = std::bit_cast(vtable[1]); + (this->*func)(item, count, auxValue); +} + +void ItemStackBase::reinit(const BlockLegacy& block, int count) +{ + using function = void (ItemStackBase::*)(const BlockLegacy&, int); + auto func = std::bit_cast(vtable[2]); + (this->*func)(block, count); +} + +void ItemStackBase::reinit(std::string_view name, int count, int auxValue) +{ + using function = void (ItemStackBase::*)(std::string_view, int, int); + auto func = std::bit_cast(vtable[3]); + (this->*func)(name, count, auxValue); +} + +void ItemStackBase::setNull(std::optional reason) +{ + using function = void(ItemStackBase::*)(std::optional); + auto func = std::bit_cast(vtable[4]); + (this->*func)(reason); +} + +std::string ItemStackBase::toString() const +{ + using function = std::string(ItemStackBase::*)() const; + auto func = std::bit_cast(vtable[5]); + return (this->*func)(); +} + +std::string ItemStackBase::toDebugString() const +{ + using function = std::string(ItemStackBase::*)() const; + auto func = std::bit_cast(vtable[6]); + return (this->*func)(); +} + +ItemStackBase::ItemStackBase() { + this->vtable = reinterpret_cast(SlideAddress(0x53F2C98)); + this->mUserData = nullptr; + this->mBlock = nullptr; + this->mAuxValue = 0b1000000000000000; + this->mCount = 0; + this->mValid = false; + this->mShowPickup = true; + this->mCanPlaceOnHash = 0; + this->mCanDestroyHash = 0; + this->mChargedItem = nullptr; + this->setNull(std::nullopt); +} + +ItemStackBase::~ItemStackBase() = default; + +ItemStackBase &ItemStackBase::operator=(const ItemStackBase& rhs) { + mCount = rhs.mCount; + mAuxValue = rhs.mAuxValue; + mItem = rhs.mItem; + mBlock = rhs.mBlock; + mValid = rhs.mValid; + mPickupTime = rhs.mPickupTime; + + mUserData = nullptr; + //if (rhs.mUserData) { + // mUserData = rhs.mUserData->clone(); + //} + + //_makeChargedItemFromUserData(); + //_cloneComponents(rhs); + return *this; +} diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h index 9049d7d9..16d2d7c9 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h @@ -6,6 +6,7 @@ #include #include #include +#include "minecraft/src/common/nbt/CompoundTag.h" class Item; class CompoundTag; @@ -35,15 +36,15 @@ class ItemInstance; class ItemStackBase { public: + /* this + 0 */ uintptr_t** vtable; /* this + 8 */ WeakPtr mItem; /* this + 16 */ CompoundTag* mUserData; /* this + 24 */ const Block* mBlock; - /* this + 32 */ short mAuxValue; + /* this + 32 */ unsigned short mAuxValue; /* this + 34 */ byte mCount; - /* this + 35 */ std::byte padding35[5]; + /* this + 35 */ bool mValid; /* this + 40 */ std::chrono::steady_clock::time_point mPickupTime; /* this + 48 */ bool mShowPickup; - /* this + 49 */ std::byte padding49[7]; /* this + 56 */ std::vector mCanPlaceOn; /* this + 80 */ size_t mCanPlaceOnHash; /* this + 88 */ std::vector mCanDestroy; @@ -52,15 +53,19 @@ class ItemStackBase { /* this + 128 */ std::unique_ptr mChargedItem; public: - virtual ~ItemStackBase(); - virtual void reinit(const Item& item, int count, int auxValue); - virtual void reinit(const BlockLegacy& block, int count); - virtual void reinit(std::string_view name, int count, int auxValue); - virtual void setNull(std::optional reason); - virtual std::string toString() const; - virtual std::string toDebugString() const; + /* Virtuals */ + ~ItemStackBase(); + void reinit(const Item& item, int count, int auxValue); + void reinit(const BlockLegacy& block, int count); + void reinit(std::string_view name, int count, int auxValue); + void setNull(std::optional reason); + std::string toString() const; + std::string toDebugString() const; public: + ItemStackBase(); + ItemStackBase& operator=(const ItemStackBase&); + // 1.20.51.1 - 48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 54 24 ? 57 48 83 EC ? 48 8B FA 48 8B E9 33 F6 std::string getRawNameId() const; diff --git a/AmethystAPI/src/minecraft/src/common/world/level/Tick.h b/AmethystAPI/src/minecraft/src/common/world/level/Tick.h index 3d37ab15..349e255d 100644 --- a/AmethystAPI/src/minecraft/src/common/world/level/Tick.h +++ b/AmethystAPI/src/minecraft/src/common/world/level/Tick.h @@ -3,5 +3,9 @@ struct Tick { public: - uint64_t tickID ; + uint64_t tickID; + + Tick() { + this->tickID = 0; + } }; \ No newline at end of file From 2cb2877cfeb2f966c54c01ffda4444e2c8b0ef86 Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Sun, 10 Mar 2024 19:17:59 +0000 Subject: [PATCH 09/14] Try fix the hash collision issue for functions with the name parameters and class name --- .../src/amethyst/runtime/HookManager.h | 72 +++++++++++------ .../minecraft/src/common/nbt/CompoundTag.cpp | 20 +++++ .../minecraft/src/common/nbt/CompoundTag.h | 4 + .../src/common/nbt/CompoundTagVariant.cpp | 51 +++++++++++- .../src/common/nbt/CompoundTagVariant.h | 78 +++++++++++++------ .../src/common/world/item/ItemStackBase.cpp | 15 ++-- AmethystRuntime/src/hooks/Hooks.cpp | 34 ++++---- 7 files changed, 203 insertions(+), 71 deletions(-) diff --git a/AmethystAPI/src/amethyst/runtime/HookManager.h b/AmethystAPI/src/amethyst/runtime/HookManager.h index 1ead0445..852f3af8 100644 --- a/AmethystAPI/src/amethyst/runtime/HookManager.h +++ b/AmethystAPI/src/amethyst/runtime/HookManager.h @@ -2,31 +2,61 @@ #include "amethyst-deps/safetyhook.hpp" #include "amethyst/Log.h" #include "amethyst/Memory.h" +#include "minecraft/src-deps/core/string/StringHash.h" #include #include +class function_id { +public: + template + static uint64_t hash_code() + { + HashedString hashed(__FUNCSIG__); + return hashed.getHash(); + } + + template + static std::string name() + { + std::string stringified = std::string(__FUNCSIG__); + std::string startReplace = std::string("function_id::name<"); + + size_t startPos = stringified.find(startReplace); + + if (startPos != std::string::npos) { + stringified = stringified.substr(startPos + startReplace.length()); + } + + if (stringified.size() >= 7) { + stringified.erase(stringified.size() - 7); + } + + return stringified; + } +}; + class HookManager { public: - template - void CreateHook(OriginalFn function, SafetyHookInline& trampoline, void* hook) - { - size_t hash = typeid(function).hash_code(); - - if (mFuncHashToOriginalAddress.find(hash) == mFuncHashToOriginalAddress.end()) - { - Log::Error("[AmethystAPI] '{}' has not registered!", typeid(function).name()); - throw std::exception(); - } - - uintptr_t original_addr = mFuncHashToOriginalAddress[hash]; - CreateHookAbsolute(trampoline, original_addr, hook); - } - + template + void CreateHook(OriginalFn function, SafetyHookInline& trampoline, void* hook) + { + size_t hash = function_id::template hash_code(); + + if (mFuncHashToOriginalAddress.find(hash) == mFuncHashToOriginalAddress.end()) { + // Log::Error("[AmethystAPI] '{}' has not registered!", typeid(function).name()); + throw std::exception(); + } + + uintptr_t original_addr = mFuncHashToOriginalAddress[hash]; + CreateHookAbsolute(trampoline, original_addr, hook); + } + /** * Directly hooks a function with an absolute address * CAUTION: This will not work if two mods want to hook the same function. For more compatibility, use HookManager::CreateHook */ - void CreateHookAbsolute(SafetyHookInline& safetyHookTrampoline, uintptr_t originalAddress, void* hook) { + void CreateHookAbsolute(SafetyHookInline& safetyHookTrampoline, uintptr_t originalAddress, void* hook) + { safetyHookTrampoline = safetyhook::create_inline((void*)originalAddress, hook); mHooks.push_back(&safetyHookTrampoline); } @@ -35,11 +65,10 @@ class HookManager { void RegisterFunction(Func function, std::string_view signature) { // Converts the function to a unique hashed number - size_t hash = typeid(function).hash_code(); + size_t hash = function_id::hash_code(); // If the event has not yet been created, make it, else re-use - if (mFuncHashToOriginalAddress.find(hash) == mFuncHashToOriginalAddress.end()) - { + if (mFuncHashToOriginalAddress.find(hash) == mFuncHashToOriginalAddress.end()) { auto result = SigScanSafe(signature); if (!result.has_value()) { @@ -55,11 +84,10 @@ class HookManager { void RegisterFunction(Func function, uintptr_t address) { // Converts the function to a unique hashed number - size_t hash = typeid(function).hash_code(); + size_t hash = function_id::hash_code(); // If the event has not yet been created, make it, else re-use - if (mFuncHashToOriginalAddress.find(hash) == mFuncHashToOriginalAddress.end()) - { + if (mFuncHashToOriginalAddress.find(hash) == mFuncHashToOriginalAddress.end()) { mFuncHashToOriginalAddress[hash] = address; } } diff --git a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.cpp b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.cpp index 466ddd62..848ba12b 100644 --- a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.cpp +++ b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.cpp @@ -58,6 +58,26 @@ bool CompoundTag::contains(std::string_view name, Tag::Type type) const return false; } +void CompoundTag::clear() +{ + mTags.clear(); +} + +void CompoundTag::deepCopy(const CompoundTag& other) +{ + clear(); + for (auto& it : other.mTags) { + mTags.emplace(it.first, it.second.copy()); + } +} + +std::unique_ptr CompoundTag::clone() const +{ + auto newCompound = std::make_unique(); + newCompound->deepCopy(*this); + return newCompound; +} + const ListTag* CompoundTag::getList(std::string_view name) const { return get(name); diff --git a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.h b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.h index a6c58596..0533a97e 100644 --- a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.h +++ b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTag.h @@ -21,6 +21,10 @@ class CompoundTag : public Tag { bool contains(std::string_view name) const; bool contains(std::string_view name, Tag::Type type) const; + void clear(); + void deepCopy(const CompoundTag& other); + std::unique_ptr clone() const; + const ListTag* getList(std::string_view name) const; ListTag* getList(std::string_view name); diff --git a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTagVariant.cpp b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTagVariant.cpp index 64e39ca5..5b434036 100644 --- a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTagVariant.cpp +++ b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTagVariant.cpp @@ -1 +1,50 @@ -#include "minecraft/src/common/nbt/CompoundTagVariant.h" \ No newline at end of file +#include "minecraft/src/common/nbt/CompoundTagVariant.h" + +CompoundTagVariant::CompoundTagVariant(Tag&& tag) +{ + emplace(std::move(tag)); +} + +Tag& CompoundTagVariant::emplace(Tag&& tag) +{ + switch (tag.getId()) { + case Tag::Type::End: + return emplace(reinterpret_cast(tag)); + + case Tag::Type::Byte: + return emplace(reinterpret_cast(tag)); + + case Tag::Type::Short: + return emplace(reinterpret_cast(tag)); + + case Tag::Type::Int: + return emplace(reinterpret_cast(tag)); + + case Tag::Type::Int64: + return emplace(reinterpret_cast(tag)); + + case Tag::Type::Float: + return emplace(reinterpret_cast(tag)); + + case Tag::Type::Double: + return emplace(reinterpret_cast(tag)); + + case Tag::Type::ByteArray: + return emplace(reinterpret_cast(tag)); + + case Tag::Type::String: + return emplace(reinterpret_cast(tag)); + + case Tag::Type::List: + return emplace(reinterpret_cast(tag)); + + case Tag::Type::Compound: + return emplace(reinterpret_cast(tag)); + + case Tag::Type::IntArray: + return emplace(reinterpret_cast(tag)); + + default: + return emplace(); + } +} \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTagVariant.h b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTagVariant.h index 731d6c60..112608cd 100644 --- a/AmethystAPI/src/minecraft/src/common/nbt/CompoundTagVariant.h +++ b/AmethystAPI/src/minecraft/src/common/nbt/CompoundTagVariant.h @@ -14,54 +14,82 @@ #include class CompoundTagVariant { -public: - std::variant mTagStorage; + typedef std::variant Variant; public: + Variant mTagStorage; + + CompoundTagVariant() {} + CompoundTagVariant(CompoundTagVariant&&) = default; + CompoundTagVariant(const CompoundTagVariant&) = delete; + CompoundTagVariant(Tag&&); + CompoundTagVariant& operator=(CompoundTagVariant&&) = default; + CompoundTagVariant& operator=(const CompoundTagVariant&) = delete; + Tag& emplace(Tag&&); + + CompoundTagVariant copy() const + { + return std::visit([](const auto& tag) { + return CompoundTagVariant(std::move(*tag.copy())); + }, + mTagStorage); + } + + const Tag* operator->() const + { + return get(); + } + + Tag* operator->() + { + return get(); + } + const Tag* get() const { return std::visit([](const auto& tag) -> const Tag* { return &tag; - }, mTagStorage); + }, + mTagStorage); } Tag* get() { return std::visit([](auto& tag) -> Tag* { return &tag; - }, mTagStorage); + }, + mTagStorage); } - template - const T* get() const + const Tag& operator*() const { - auto tag = std::get_if(&mTagStorage); + return *get(); + } - if (tag) { - return tag; - } - else { - return nullptr; - } + Tag& operator*() + { + return *get(); + } + + template + T& emplace(Type&&... args) + { + return mTagStorage.emplace(std::forward(args)...); } template - T* get() + const T* get() const { auto tag = std::get_if(&mTagStorage); - - if (tag) { - return tag; - } - else { - return nullptr; - } + if (!tag) return nullptr; + return tag; } - template - void emplace(Args&&... args) + template + T* get() { - mTagStorage.emplace(std::forward(args)...); + auto tag = std::get_if(&mTagStorage); + if (!tag) return nullptr; + return tag; } }; \ No newline at end of file diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp index 334b1ff5..e8bf999d 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp @@ -62,6 +62,7 @@ std::string ItemStackBase::toDebugString() const return (this->*func)(); } +// 1.20.51.1 Reimplementation - Complete ItemStackBase::ItemStackBase() { this->vtable = reinterpret_cast(SlideAddress(0x53F2C98)); this->mUserData = nullptr; @@ -78,6 +79,7 @@ ItemStackBase::ItemStackBase() { ItemStackBase::~ItemStackBase() = default; +// 1.20.51.1 Reimplementation - Incomplete ItemStackBase &ItemStackBase::operator=(const ItemStackBase& rhs) { mCount = rhs.mCount; mAuxValue = rhs.mAuxValue; @@ -86,12 +88,13 @@ ItemStackBase &ItemStackBase::operator=(const ItemStackBase& rhs) { mValid = rhs.mValid; mPickupTime = rhs.mPickupTime; - mUserData = nullptr; - //if (rhs.mUserData) { - // mUserData = rhs.mUserData->clone(); - //} + /*std::unique_ptr clonedData = nullptr; - //_makeChargedItemFromUserData(); - //_cloneComponents(rhs); + if (rhs.mUserData) { + clonedData = rhs.mUserData->clone(); + }*/ + + // setUserData(clonedData); + // _cloneComponents(rhs) return *this; } diff --git a/AmethystRuntime/src/hooks/Hooks.cpp b/AmethystRuntime/src/hooks/Hooks.cpp index f733920c..c9ce7370 100644 --- a/AmethystRuntime/src/hooks/Hooks.cpp +++ b/AmethystRuntime/src/hooks/Hooks.cpp @@ -90,21 +90,21 @@ void CreateModFunctionHooks() { HookManager* hookManager = AmethystRuntime::getHookManager(); hookManager->RegisterFunction(&ScreenView::setupAndRender, "48 8B C4 48 89 58 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4C 8B FA 48 89 54 24 ? 4C 8B E9 48 89 4C 24"); - hookManager->RegisterFunction(&Minecraft::update, "48 8B C4 48 89 58 ? 48 89 70 ? 48 89 78 ? 55 41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4C 8B E9 48"); - hookManager->RegisterFunction(&ClientInstance::onStartJoinGame, "40 55 53 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 45 8B F1"); - hookManager->RegisterFunction(&ClientInstance::requestLeaveGame, "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 54 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 45 0F B6 F0 44 0F B6 FA"); - hookManager->RegisterFunction(&VanillaItems::registerItems, "40 55 53 56 57 41 54 41 56 41 57 48 8D AC 24 ? ? ? ? B8 ? ? ? ? E8 ? ? ? ? 48 2B E0 0F 29 B4 24"); - hookManager->RegisterFunction(&BlockDefinitionGroup::registerBlocks, "48 89 5C 24 ? 48 89 6C 24 ? 56 57 41 54 41 56 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 84 24 ? ? ? ? 4C 8B F9"); - hookManager->RegisterFunction(&LevelRenderer::renderLevel, "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 56 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 49 8B F0 48 8B DA 4C 8B F1"); - - hookManager->CreateHook(&ScreenView::setupAndRender, _ScreenView_setupAndRender, &ScreenView_setupAndRender); - hookManager->CreateHook(&Minecraft::update, _Minecraft_update, &Minecraft_update); - hookManager->CreateHook(&ClientInstance::onStartJoinGame, _ClientInstance_onStartJoinGame, &ClientInstance_onStartJoinGame); - hookManager->CreateHook(&ClientInstance::requestLeaveGame, _ClientInstance_requestLeaveGame, &ClientInstance_requestLeaveGame); - hookManager->CreateHook(&VanillaItems::registerItems, _VanillaItems_registerItems, &VanillaItems_registerItems); - //hookManager->CreateHook(&BlockDefinitionGroup::registerBlocks, _BlockDefinitionGroup_registerBlocks, &BlockDefinitionGroup_registerBlocks); - hookManager->CreateHook(&LevelRenderer::renderLevel, _LevelRenderer_renderLevel, &LevelRenderer_renderLevel); - - // C++ does not allow doing a reference to get the addresses of constructors... - hookManager->CreateHookAbsolute(_ClientInstance_ClientInstance, SigScan("48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 49 8B F9 49 8B D8 4C 8B E2"), &ClientInstance_ClientInstance); + //hookManager->RegisterFunction(&Minecraft::update, "48 8B C4 48 89 58 ? 48 89 70 ? 48 89 78 ? 55 41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4C 8B E9 48"); + //hookManager->RegisterFunction(&ClientInstance::onStartJoinGame, "40 55 53 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 45 8B F1"); + //hookManager->RegisterFunction(&ClientInstance::requestLeaveGame, "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 54 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 45 0F B6 F0 44 0F B6 FA"); + //hookManager->RegisterFunction(&VanillaItems::registerItems, "40 55 53 56 57 41 54 41 56 41 57 48 8D AC 24 ? ? ? ? B8 ? ? ? ? E8 ? ? ? ? 48 2B E0 0F 29 B4 24"); + //hookManager->RegisterFunction(&BlockDefinitionGroup::registerBlocks, "48 89 5C 24 ? 48 89 6C 24 ? 56 57 41 54 41 56 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 84 24 ? ? ? ? 4C 8B F9"); + //hookManager->RegisterFunction(&LevelRenderer::renderLevel, "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 56 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 49 8B F0 48 8B DA 4C 8B F1"); + + //hookManager->CreateHook(&ScreenView::setupAndRender, _ScreenView_setupAndRender, &ScreenView_setupAndRender); + //hookManager->CreateHook(&Minecraft::update, _Minecraft_update, &Minecraft_update); + //hookManager->CreateHook(&ClientInstance::onStartJoinGame, _ClientInstance_onStartJoinGame, &ClientInstance_onStartJoinGame); + //hookManager->CreateHook(&ClientInstance::requestLeaveGame, _ClientInstance_requestLeaveGame, &ClientInstance_requestLeaveGame); + //hookManager->CreateHook(&VanillaItems::registerItems, _VanillaItems_registerItems, &VanillaItems_registerItems); + ////hookManager->CreateHook(&BlockDefinitionGroup::registerBlocks, _BlockDefinitionGroup_registerBlocks, &BlockDefinitionGroup_registerBlocks); + //hookManager->CreateHook(&LevelRenderer::renderLevel, _LevelRenderer_renderLevel, &LevelRenderer_renderLevel); + + //// C++ does not allow doing a reference to get the addresses of constructors... + //hookManager->CreateHookAbsolute(_ClientInstance_ClientInstance, SigScan("48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 49 8B F9 49 8B D8 4C 8B E2"), &ClientInstance_ClientInstance); } \ No newline at end of file From a5d1cc4005de293a5fd16580fb0a5edccf519940 Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Tue, 12 Mar 2024 18:17:12 +0000 Subject: [PATCH 10/14] Premove to 1.20.71.1 --- .../src/amethyst/runtime/HookManager.h | 9 ++++-- AmethystRuntime/src/hooks/Hooks.cpp | 30 +++++++++---------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/AmethystAPI/src/amethyst/runtime/HookManager.h b/AmethystAPI/src/amethyst/runtime/HookManager.h index 852f3af8..a31c5298 100644 --- a/AmethystAPI/src/amethyst/runtime/HookManager.h +++ b/AmethystAPI/src/amethyst/runtime/HookManager.h @@ -40,7 +40,8 @@ class HookManager { template void CreateHook(OriginalFn function, SafetyHookInline& trampoline, void* hook) { - size_t hash = function_id::template hash_code(); + //size_t hash = function_id::template hash_code(); + size_t hash = typeid(function).hash_code(); if (mFuncHashToOriginalAddress.find(hash) == mFuncHashToOriginalAddress.end()) { // Log::Error("[AmethystAPI] '{}' has not registered!", typeid(function).name()); @@ -65,7 +66,8 @@ class HookManager { void RegisterFunction(Func function, std::string_view signature) { // Converts the function to a unique hashed number - size_t hash = function_id::hash_code(); + // size_t hash = function_id::hash_code(); + size_t hash = typeid(function).hash_code(); // If the event has not yet been created, make it, else re-use if (mFuncHashToOriginalAddress.find(hash) == mFuncHashToOriginalAddress.end()) { @@ -84,7 +86,8 @@ class HookManager { void RegisterFunction(Func function, uintptr_t address) { // Converts the function to a unique hashed number - size_t hash = function_id::hash_code(); + //size_t hash = function_id::hash_code(); + size_t hash = typeid(function).hash_code(); // If the event has not yet been created, make it, else re-use if (mFuncHashToOriginalAddress.find(hash) == mFuncHashToOriginalAddress.end()) { diff --git a/AmethystRuntime/src/hooks/Hooks.cpp b/AmethystRuntime/src/hooks/Hooks.cpp index c9ce7370..b957b830 100644 --- a/AmethystRuntime/src/hooks/Hooks.cpp +++ b/AmethystRuntime/src/hooks/Hooks.cpp @@ -90,21 +90,21 @@ void CreateModFunctionHooks() { HookManager* hookManager = AmethystRuntime::getHookManager(); hookManager->RegisterFunction(&ScreenView::setupAndRender, "48 8B C4 48 89 58 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4C 8B FA 48 89 54 24 ? 4C 8B E9 48 89 4C 24"); - //hookManager->RegisterFunction(&Minecraft::update, "48 8B C4 48 89 58 ? 48 89 70 ? 48 89 78 ? 55 41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4C 8B E9 48"); - //hookManager->RegisterFunction(&ClientInstance::onStartJoinGame, "40 55 53 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 45 8B F1"); - //hookManager->RegisterFunction(&ClientInstance::requestLeaveGame, "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 54 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 45 0F B6 F0 44 0F B6 FA"); - //hookManager->RegisterFunction(&VanillaItems::registerItems, "40 55 53 56 57 41 54 41 56 41 57 48 8D AC 24 ? ? ? ? B8 ? ? ? ? E8 ? ? ? ? 48 2B E0 0F 29 B4 24"); - //hookManager->RegisterFunction(&BlockDefinitionGroup::registerBlocks, "48 89 5C 24 ? 48 89 6C 24 ? 56 57 41 54 41 56 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 84 24 ? ? ? ? 4C 8B F9"); - //hookManager->RegisterFunction(&LevelRenderer::renderLevel, "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 56 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 49 8B F0 48 8B DA 4C 8B F1"); - - //hookManager->CreateHook(&ScreenView::setupAndRender, _ScreenView_setupAndRender, &ScreenView_setupAndRender); - //hookManager->CreateHook(&Minecraft::update, _Minecraft_update, &Minecraft_update); - //hookManager->CreateHook(&ClientInstance::onStartJoinGame, _ClientInstance_onStartJoinGame, &ClientInstance_onStartJoinGame); - //hookManager->CreateHook(&ClientInstance::requestLeaveGame, _ClientInstance_requestLeaveGame, &ClientInstance_requestLeaveGame); - //hookManager->CreateHook(&VanillaItems::registerItems, _VanillaItems_registerItems, &VanillaItems_registerItems); - ////hookManager->CreateHook(&BlockDefinitionGroup::registerBlocks, _BlockDefinitionGroup_registerBlocks, &BlockDefinitionGroup_registerBlocks); - //hookManager->CreateHook(&LevelRenderer::renderLevel, _LevelRenderer_renderLevel, &LevelRenderer_renderLevel); + hookManager->RegisterFunction(&Minecraft::update, "48 8B C4 48 89 58 ? 48 89 70 ? 48 89 78 ? 55 41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? 48 81 EC ? ? ? ? 0F 29 70 ? 0F 29 78 ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 4C 8B E9 48"); + hookManager->RegisterFunction(&ClientInstance::onStartJoinGame, "40 55 53 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 45 8B F1"); + hookManager->RegisterFunction(&ClientInstance::requestLeaveGame, "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 54 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 45 0F B6 F0 44 0F B6 FA"); + hookManager->RegisterFunction(&VanillaItems::registerItems, "40 55 53 56 57 41 54 41 56 41 57 48 8D AC 24 ? ? ? ? B8 ? ? ? ? E8 ? ? ? ? 48 2B E0 0F 29 B4 24"); + hookManager->RegisterFunction(&BlockDefinitionGroup::registerBlocks, "48 89 5C 24 ? 48 89 6C 24 ? 56 57 41 54 41 56 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 84 24 ? ? ? ? 4C 8B F9"); + hookManager->RegisterFunction(&LevelRenderer::renderLevel, "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 56 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 49 8B F0 48 8B DA 4C 8B F1"); + + hookManager->CreateHook(&ScreenView::setupAndRender, _ScreenView_setupAndRender, &ScreenView_setupAndRender); + hookManager->CreateHook(&Minecraft::update, _Minecraft_update, &Minecraft_update); + hookManager->CreateHook(&ClientInstance::onStartJoinGame, _ClientInstance_onStartJoinGame, &ClientInstance_onStartJoinGame); + hookManager->CreateHook(&ClientInstance::requestLeaveGame, _ClientInstance_requestLeaveGame, &ClientInstance_requestLeaveGame); + hookManager->CreateHook(&VanillaItems::registerItems, _VanillaItems_registerItems, &VanillaItems_registerItems); + // hookManager->CreateHook(&BlockDefinitionGroup::registerBlocks, _BlockDefinitionGroup_registerBlocks, &BlockDefinitionGroup_registerBlocks); + hookManager->CreateHook(&LevelRenderer::renderLevel, _LevelRenderer_renderLevel, &LevelRenderer_renderLevel); //// C++ does not allow doing a reference to get the addresses of constructors... - //hookManager->CreateHookAbsolute(_ClientInstance_ClientInstance, SigScan("48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 49 8B F9 49 8B D8 4C 8B E2"), &ClientInstance_ClientInstance); + hookManager->CreateHookAbsolute(_ClientInstance_ClientInstance, SigScan("48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 49 8B F9 49 8B D8 4C 8B E2"), &ClientInstance_ClientInstance); } \ No newline at end of file From e387d481b4de91e2d8cad96ac3e1c99b1e939d72 Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Tue, 12 Mar 2024 21:03:19 +0000 Subject: [PATCH 11/14] Start work towards bringing better inv to 1.20.71.1 --- .../minecraft/src/common/world/item/Item.asm | 134 +++++++++--------- .../minecraft/src/common/world/item/Item.h | 9 +- .../src/common/world/item/ItemStackBase.cpp | 21 +-- .../src/common/world/item/ItemStackBase.h | 4 +- .../item/registry/ItemRegistryManager.cpp | 1 + AmethystRuntime/src/hooks/Hooks.cpp | 13 +- 6 files changed, 92 insertions(+), 90 deletions(-) diff --git a/AmethystAPI/src/minecraft/src/common/world/item/Item.asm b/AmethystAPI/src/minecraft/src/common/world/item/Item.asm index 6f9bda28..7e8c09d4 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/Item.asm +++ b/AmethystAPI/src/minecraft/src/common/world/item/Item.asm @@ -1,11 +1,8 @@ -; Auto-Generated by FrederoxDev/Ida-Tools/virtuals/order_dumper.py +; Automatically generated by FrederoxDev/Reverse-Tools/CxxParser/HeaderGenerator.py section .text extern Item_vtable -;global ??1Item@@UEAA@XZ -;??1Item@@UEAA@XZ: -; mov rax, [rel Item_vtable] -; jmp [rax + 0] +; Failed to find (index: 0, linux symbol: '_ZN4ItemD2Ev') global ?initServer@Item@@UEAA_NAEAVValue@Json@@AEBVSemVersion@@_NAEBVExperiments@@@Z ?initServer@Item@@UEAA_NAEAVValue@Json@@AEBVSemVersion@@_NAEBVExperiments@@@Z: @@ -107,298 +104,298 @@ global ?isUseable@Item@@UEBA_NXZ mov rax, [rel Item_vtable] jmp [rax + 160] +global ?isTrimAllowed@Item@@UEBA_NXZ +?isTrimAllowed@Item@@UEBA_NXZ: + mov rax, [rel Item_vtable] + jmp [rax + 168] + global ?getComponent@Item@@UEBAPEAVItemComponent@@AEBVHashedString@@@Z ?getComponent@Item@@UEBAPEAVItemComponent@@AEBVHashedString@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 168] + jmp [rax + 176] global ?getFood@Item@@UEBAPEAVIFoodItemComponent@@XZ ?getFood@Item@@UEBAPEAVIFoodItemComponent@@XZ: mov rax, [rel Item_vtable] - jmp [rax + 176] + jmp [rax + 184] global ?setMaxDamage@Item@@UEAAAEAV1@H@Z ?setMaxDamage@Item@@UEAAAEAV1@H@Z: mov rax, [rel Item_vtable] - jmp [rax + 184] + jmp [rax + 192] global ?setMaxUseDuration@Item@@UEAAAEAV1@H@Z ?setMaxUseDuration@Item@@UEAAAEAV1@H@Z: mov rax, [rel Item_vtable] - jmp [rax + 192] + jmp [rax + 200] global ?buildNetworkTag@Item@@UEBA?AV?$unique_ptr@VCompoundTag@@U?$default_delete@VCompoundTag@@@std@@@std@@XZ ?buildNetworkTag@Item@@UEBA?AV?$unique_ptr@VCompoundTag@@U?$default_delete@VCompoundTag@@@std@@@std@@XZ: mov rax, [rel Item_vtable] - jmp [rax + 200] + jmp [rax + 208] global ?initializeFromNetwork@Item@@UEAAXAEBVCompoundTag@@@Z ?initializeFromNetwork@Item@@UEAAXAEBVCompoundTag@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 208] + jmp [rax + 216] global ?validateFromNetwork@Item@@UEAA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@AEBVCompoundTag@@@Z ?validateFromNetwork@Item@@UEAA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@AEBVCompoundTag@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 216] + jmp [rax + 224] global ?getBlockShape@Item@@UEBA?AW4BlockShape@@XZ ?getBlockShape@Item@@UEBA?AW4BlockShape@@XZ: mov rax, [rel Item_vtable] - jmp [rax + 224] + jmp [rax + 232] global ?canBeDepleted@Item@@UEBA_NXZ ?canBeDepleted@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 232] + jmp [rax + 240] global ?canDestroySpecial@Item@@UEBA_NAEBVBlock@@@Z ?canDestroySpecial@Item@@UEBA_NAEBVBlock@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 240] + jmp [rax + 248] global ?getLevelDataForAuxValue@Item@@UEBAHH@Z ?getLevelDataForAuxValue@Item@@UEBAHH@Z: mov rax, [rel Item_vtable] - jmp [rax + 248] + jmp [rax + 256] global ?isStackedByData@Item@@UEBA_NXZ ?isStackedByData@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 256] + jmp [rax + 264] global ?getMaxDamage@Item@@UEBAFXZ ?getMaxDamage@Item@@UEBAFXZ: mov rax, [rel Item_vtable] - jmp [rax + 264] + jmp [rax + 272] global ?getAttackDamage@Item@@UEBAHXZ ?getAttackDamage@Item@@UEBAHXZ: mov rax, [rel Item_vtable] - jmp [rax + 272] + jmp [rax + 280] global ?isHandEquipped@Item@@UEBA_NXZ ?isHandEquipped@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 280] + jmp [rax + 288] global ?isGlint@Item@@UEBA_NAEBVItemStackBase@@@Z ?isGlint@Item@@UEBA_NAEBVItemStackBase@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 288] + jmp [rax + 296] global ?isPattern@Item@@UEBA_NXZ ?isPattern@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 296] + jmp [rax + 304] global ?getPatternIndex@Item@@UEBAHXZ ?getPatternIndex@Item@@UEBAHXZ: mov rax, [rel Item_vtable] - jmp [rax + 304] + jmp [rax + 312] global ?showsDurabilityInCreative@Item@@UEBA_NXZ ?showsDurabilityInCreative@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 312] + jmp [rax + 320] global ?isWearableThroughLootTable@Item@@UEBA_NPEBVCompoundTag@@@Z ?isWearableThroughLootTable@Item@@UEBA_NPEBVCompoundTag@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 320] + jmp [rax + 328] global ?canDestroyInCreative@Item@@UEBA_NXZ ?canDestroyInCreative@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 328] + jmp [rax + 336] global ?isDestructive@Item@@UEBA_NH@Z ?isDestructive@Item@@UEBA_NH@Z: mov rax, [rel Item_vtable] - jmp [rax + 336] + jmp [rax + 344] global ?isLiquidClipItem@Item@@UEBA_NXZ ?isLiquidClipItem@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 344] + jmp [rax + 352] global ?shouldInteractionWithBlockBypassLiquid@Item@@UEBA_NAEBVBlock@@@Z ?shouldInteractionWithBlockBypassLiquid@Item@@UEBA_NAEBVBlock@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 352] + jmp [rax + 360] global ?requiresInteract@Item@@UEBA_NXZ ?requiresInteract@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 360] + jmp [rax + 368] global ?appendFormattedHovertext@Item@@UEBAXAEBVItemStackBase@@AEAVLevel@@AEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z ?appendFormattedHovertext@Item@@UEBAXAEBVItemStackBase@@AEAVLevel@@AEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z: mov rax, [rel Item_vtable] - jmp [rax + 368] + jmp [rax + 376] global ?isValidRepairItem@Item@@UEBA_NAEBVItemStackBase@@0AEBVBaseGameVersion@@@Z ?isValidRepairItem@Item@@UEBA_NAEBVItemStackBase@@0AEBVBaseGameVersion@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 376] + jmp [rax + 384] global ?getEnchantSlot@Item@@UEBAHXZ ?getEnchantSlot@Item@@UEBAHXZ: mov rax, [rel Item_vtable] - jmp [rax + 384] + jmp [rax + 392] global ?getEnchantValue@Item@@UEBAHXZ ?getEnchantValue@Item@@UEBAHXZ: mov rax, [rel Item_vtable] - jmp [rax + 392] + jmp [rax + 400] global ?getArmorValue@Item@@UEBAHXZ ?getArmorValue@Item@@UEBAHXZ: mov rax, [rel Item_vtable] - jmp [rax + 400] + jmp [rax + 408] global ?getToughnessValue@Item@@UEBAHXZ ?getToughnessValue@Item@@UEBAHXZ: mov rax, [rel Item_vtable] - jmp [rax + 408] + jmp [rax + 416] global ?isComplex@Item@@UEBA_NXZ ?isComplex@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 416] + jmp [rax + 424] global ?isValidAuxValue@Item@@UEBA_NH@Z ?isValidAuxValue@Item@@UEBA_NH@Z: mov rax, [rel Item_vtable] - jmp [rax + 424] + jmp [rax + 432] global ?getDamageChance@Item@@UEBAHH@Z ?getDamageChance@Item@@UEBAHH@Z: mov rax, [rel Item_vtable] - jmp [rax + 432] + jmp [rax + 440] global ?getViewDamping@Item@@UEBAMXZ ?getViewDamping@Item@@UEBAMXZ: mov rax, [rel Item_vtable] - jmp [rax + 440] + jmp [rax + 448] global ?uniqueAuxValues@Item@@UEBA_NXZ ?uniqueAuxValues@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 448] + jmp [rax + 456] global ?isActorPlacerItem@Item@@UEBA_NXZ ?isActorPlacerItem@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 456] + jmp [rax + 464] global ?isMultiColorTinted@Item@@UEBA_NAEBVItemStack@@@Z ?isMultiColorTinted@Item@@UEBA_NAEBVItemStack@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 464] + jmp [rax + 472] global ?getColor@Item@@UEBA?AVColor@mce@@PEBVCompoundTag@@AEBVItemDescriptor@@@Z ?getColor@Item@@UEBA?AVColor@mce@@PEBVCompoundTag@@AEBVItemDescriptor@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 472] + jmp [rax + 480] global ?hasCustomColor@Item@@UEBA_NPEBVCompoundTag@@@Z ?hasCustomColor@Item@@UEBA_NPEBVCompoundTag@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 480] + jmp [rax + 488] global ?hasCustomColor@Item@@UEBA_NAEBVItemStackBase@@@Z ?hasCustomColor@Item@@UEBA_NAEBVItemStackBase@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 488] + jmp [rax + 496] global ?clearColor@Item@@UEBAXPEAVCompoundTag@@@Z ?clearColor@Item@@UEBAXPEAVCompoundTag@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 496] + jmp [rax + 504] global ?clearColor@Item@@UEBAXAEAVItemStackBase@@@Z ?clearColor@Item@@UEBAXAEAVItemStackBase@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 504] + jmp [rax + 512] global ?setColor@Item@@UEBAXAEAVItemStackBase@@AEBVColor@mce@@@Z ?setColor@Item@@UEBAXAEAVItemStackBase@@AEBVColor@mce@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 512] + jmp [rax + 520] global ?getBaseColor@Item@@UEBA?AVColor@mce@@AEBVItemStack@@@Z ?getBaseColor@Item@@UEBA?AVColor@mce@@AEBVItemStack@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 520] + jmp [rax + 528] global ?getSecondaryColor@Item@@UEBA?AVColor@mce@@AEBVItemStack@@@Z ?getSecondaryColor@Item@@UEBA?AVColor@mce@@AEBVItemStack@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 528] + jmp [rax + 536] global ?getActorIdentifier@Item@@UEBA?AUActorDefinitionIdentifier@@AEBVItemStack@@@Z ?getActorIdentifier@Item@@UEBA?AUActorDefinitionIdentifier@@AEBVItemStack@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 536] + jmp [rax + 544] global ?buildIdAux@Item@@UEBAHFPEBVCompoundTag@@@Z ?buildIdAux@Item@@UEBAHFPEBVCompoundTag@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 544] + jmp [rax + 552] global ?canUseOnSimTick@Item@@UEBA_NXZ ?canUseOnSimTick@Item@@UEBA_NXZ: mov rax, [rel Item_vtable] - jmp [rax + 552] + jmp [rax + 560] global ?use@Item@@UEBAAEAVItemStack@@AEAV2@AEAVPlayer@@@Z ?use@Item@@UEBAAEAVItemStack@@AEAV2@AEAVPlayer@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 560] + jmp [rax + 568] global ?dispense@Item@@UEBA_NAEAVBlockSource@@AEAVContainer@@HAEBVVec3@@E@Z ?dispense@Item@@UEBA_NAEAVBlockSource@@AEAVContainer@@HAEBVVec3@@E@Z: mov rax, [rel Item_vtable] - jmp [rax + 568] + jmp [rax + 576] global ?useTimeDepleted@Item@@UEBA?AW4ItemUseMethod@@AEAVItemStack@@PEAVLevel@@PEAVPlayer@@@Z ?useTimeDepleted@Item@@UEBA?AW4ItemUseMethod@@AEAVItemStack@@PEAVLevel@@PEAVPlayer@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 576] + jmp [rax + 584] global ?releaseUsing@Item@@UEBAXAEAVItemStack@@PEAVPlayer@@H@Z ?releaseUsing@Item@@UEBAXAEAVItemStack@@PEAVPlayer@@H@Z: mov rax, [rel Item_vtable] - jmp [rax + 584] + jmp [rax + 592] global ?getDestroySpeed@Item@@UEBAMAEBVItemStackBase@@AEBVBlock@@@Z ?getDestroySpeed@Item@@UEBAMAEBVItemStackBase@@AEBVBlock@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 592] + jmp [rax + 600] global ?hurtActor@Item@@UEBAXAEAVItemStack@@AEAVActor@@AEAVMob@@@Z ?hurtActor@Item@@UEBAXAEAVItemStack@@AEAVActor@@AEAVMob@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 600] + jmp [rax + 608] global ?hitActor@Item@@UEBAXAEAVItemStack@@AEAVActor@@AEAVMob@@@Z ?hitActor@Item@@UEBAXAEAVItemStack@@AEAVActor@@AEAVMob@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 608] + jmp [rax + 616] global ?hitBlock@Item@@UEBAXAEAVItemStack@@AEBVBlock@@AEBVBlockPos@@AEAVMob@@@Z ?hitBlock@Item@@UEBAXAEAVItemStack@@AEBVBlock@@AEBVBlockPos@@AEAVMob@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 616] + jmp [rax + 624] global ?mineBlock@Item@@UEBA_NAEAVItemStack@@AEBVBlock@@HHHPEAVActor@@@Z ?mineBlock@Item@@UEBA_NAEAVItemStack@@AEBVBlock@@HHHPEAVActor@@@Z: - mov rax, [rel Item_vtable] - jmp [rax + 624] - -global ?mineBlock@Item@@UEBA_NAEAVItemInstance@@AEBVBlock@@HHHPEAVActor@@@Z -?mineBlock@Item@@UEBA_NAEAVItemInstance@@AEBVBlock@@HHHPEAVActor@@@Z: mov rax, [rel Item_vtable] jmp [rax + 632] @@ -590,4 +587,5 @@ global ?_shouldAutoCalculatePlacePos@Item@@EEBA_NXZ global ?_useOn@Item@@EEBA?AVInteractionResult@@AEAVItemStack@@AEAVActor@@VBlockPos@@EAEBVVec3@@@Z ?_useOn@Item@@EEBA?AVInteractionResult@@AEAVItemStack@@AEAVActor@@VBlockPos@@EAEBVVec3@@@Z: mov rax, [rel Item_vtable] - jmp [rax + 936] \ No newline at end of file + jmp [rax + 936] + diff --git a/AmethystAPI/src/minecraft/src/common/world/item/Item.h b/AmethystAPI/src/minecraft/src/common/world/item/Item.h index 93e054ae..313ee41d 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/Item.h +++ b/AmethystAPI/src/minecraft/src/common/world/item/Item.h @@ -127,11 +127,12 @@ class Item { virtual bool isFood() const; virtual bool isThrowable() const; virtual bool isUseable() const; + virtual bool isTrimAllowed() const; virtual ItemComponent* getComponent(const HashedString&) const; virtual IFoodItemComponent* getFood() const; virtual Item& setMaxDamage(int maxDamage); virtual Item& setMaxUseDuration(int maxUseDuration); - virtual std::unique_ptr> buildNetworkTag() const; + virtual std::unique_ptr buildNetworkTag() const; virtual void initializeFromNetwork(const CompoundTag& tag); virtual std::vector validateFromNetwork(const CompoundTag&); virtual BlockShape getBlockShape() const; @@ -184,7 +185,6 @@ class Item { virtual void hurtActor(ItemStack& itemStack, Actor& actor, Mob& attacker) const; virtual void hitActor(ItemStack& itemStack, Actor& actor, Mob& attacker) const; virtual void hitBlock(ItemStack& instance, const Block& block, const BlockPos& blockPos, Mob& attacker) const; - virtual bool mineBlock(ItemInstance& instance, const Block& block, int x, int y, int z, Actor* owner) const; virtual bool mineBlock(ItemStack& instance, const Block& block, int x, int y, int z, Actor* owner) const; virtual std::string buildDescriptionName(const ItemStackBase&) const; virtual std::string buildDescriptionId(const ItemDescriptor&, const CompoundTag*) const; @@ -207,9 +207,9 @@ class Item { virtual bool shouldSendInteractionGameEvents() const; virtual bool useInterruptedByAttacking() const; virtual bool hasSameRelevantUserData(const ItemStackBase&, const ItemStackBase&) const; - virtual void initClient(Json::Value& data, const SemVersion& engineVersion, bool, const Experiments&); + virtual void initClient(Json::Value& data, const SemVersion& engineVersion, bool, const Experiments&); virtual Item& setIconInfo(const std::string& name, int index); - virtual ResolvedItemIconInfo getIconInfo(const ItemStackBase& retstr, int, bool) const; + virtual ResolvedItemIconInfo getIconInfo(const ItemStackBase&, int, bool) const; virtual std::string getInteractText(const Player&) const; virtual int getAnimationFrameFor(Mob* holder, bool asItemEntity, const ItemStack* item, bool shouldAnimate) const; virtual bool isEmissive(int auxValue) const; @@ -220,7 +220,6 @@ class Item { virtual float getFurnaceXPmultiplier(const ItemStackBase& instance) const; virtual std::string getAuxValuesDescription() const; virtual bool calculatePlacePos(ItemStackBase& instance, Actor& entity, unsigned char& face, BlockPos& pos) const; - private: virtual bool _checkUseOnPermissions(Actor& entity, ItemStackBase& item, const unsigned char& face, const BlockPos& pos) const; virtual bool _calculatePlacePos(ItemStackBase& instance, Actor& entity, unsigned char& face, BlockPos& pos) const; diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp index e8bf999d..b91c4ff1 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.cpp @@ -1,20 +1,21 @@ #include "minecraft/src/common/world/item/ItemStackBase.h" -std::string ItemStackBase::getRawNameId() const -{ - using function = decltype(&ItemStackBase::getRawNameId); - - static auto func = std::bit_cast( - SigScan("48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 54 24 ? 57 48 83 EC ? 48 8B FA 48 8B E9 33 F6")); - - return (this->*func)(); -} +//std::string ItemStackBase::getRawNameId() const +//{ +// using function = decltype(&ItemStackBase::getRawNameId); +// +// // known outdated for 1.20.71 +// static auto func = std::bit_cast( +// SigScan("48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 54 24 ? 57 48 83 EC ? 48 8B FA 48 8B E9 33 F6")); +// +// return (this->*func)(); +//} void ItemStackBase::_loadItem(const CompoundTag* a1) { using function = decltype(&ItemStackBase::_loadItem); static auto func = std::bit_cast( - SigScan("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 ? ? ? ? 48 8B F2 48 89 54 24 ? 4C 8B F9 48 89 4C 24") + SigScan("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 89 4C 24") ); (this->*func)(a1); diff --git a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h index 16d2d7c9..4f48786a 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h +++ b/AmethystAPI/src/minecraft/src/common/world/item/ItemStackBase.h @@ -67,9 +67,9 @@ class ItemStackBase { ItemStackBase& operator=(const ItemStackBase&); // 1.20.51.1 - 48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 48 89 54 24 ? 57 48 83 EC ? 48 8B FA 48 8B E9 33 F6 - std::string getRawNameId() const; + // std::string getRawNameId() const; - // 1.20.51.1 - 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 ? ? ? ? 48 8B F2 48 89 54 24 ? 4C 8B F9 48 89 4C 24 + // 1.20.71.1 - 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 89 4C 24 void _loadItem(const CompoundTag*); }; diff --git a/AmethystAPI/src/minecraft/src/common/world/item/registry/ItemRegistryManager.cpp b/AmethystAPI/src/minecraft/src/common/world/item/registry/ItemRegistryManager.cpp index 7ce75291..eedb2439 100644 --- a/AmethystAPI/src/minecraft/src/common/world/item/registry/ItemRegistryManager.cpp +++ b/AmethystAPI/src/minecraft/src/common/world/item/registry/ItemRegistryManager.cpp @@ -2,6 +2,7 @@ ItemRegistryRef ItemRegistryManager::getItemRegistry() { using function = ItemRegistryRef(*)(); + // 48 8B 19 48 8B F9 48 85 DB 0F 85 ? ? ? ? E8 ? ? ? ? 48 8B C8 8D 53 ? 48 8B 00 48 8B 40 ? FF 15 ? ? ? ? 48 8B D8 48 85 C0 75 ? 48 8D 05 ? ? ? ? 48 C7 44 24 ? ? ? ? ? 4C 8D 0D ? ? ? ? 48 89 44 24 ? 44 8D 43 ? 48 8D 15 ? ? ? ? 48 8D 0D ? ? ? ? E8 ? ? ? ? 84 C0 74 ? C7 04 25 ? ? ? ? ? ? ? ? 48 8B 4F ? 48 89 5C 24 ? 48 85 C9 75 ? FF 15 ? ? ? ? CC 48 8B 11 48 8B 42 ? 48 8D 54 24 ? FF 15 ? ? ? ? 48 89 1F 48 8B C3 48 8B 4C 24 ? 48 33 CC E8 ? ? ? ? 48 8B 5C 24 ? 48 83 C4 ? 5F C3 CC 40 55 static auto func = reinterpret_cast(SigScan("40 53 48 83 EC ? 48 83 3D ? ? ? ? ? 48 8B D9 74")); return func(); } \ No newline at end of file diff --git a/AmethystRuntime/src/hooks/Hooks.cpp b/AmethystRuntime/src/hooks/Hooks.cpp index b957b830..0de9c008 100644 --- a/AmethystRuntime/src/hooks/Hooks.cpp +++ b/AmethystRuntime/src/hooks/Hooks.cpp @@ -94,17 +94,20 @@ void CreateModFunctionHooks() { hookManager->RegisterFunction(&ClientInstance::onStartJoinGame, "40 55 53 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 45 8B F1"); hookManager->RegisterFunction(&ClientInstance::requestLeaveGame, "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 54 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 45 0F B6 F0 44 0F B6 FA"); hookManager->RegisterFunction(&VanillaItems::registerItems, "40 55 53 56 57 41 54 41 56 41 57 48 8D AC 24 ? ? ? ? B8 ? ? ? ? E8 ? ? ? ? 48 2B E0 0F 29 B4 24"); - hookManager->RegisterFunction(&BlockDefinitionGroup::registerBlocks, "48 89 5C 24 ? 48 89 6C 24 ? 56 57 41 54 41 56 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 84 24 ? ? ? ? 4C 8B F9"); hookManager->RegisterFunction(&LevelRenderer::renderLevel, "48 89 5C 24 ? 48 89 74 24 ? 55 57 41 56 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 85 ? ? ? ? 49 8B F0 48 8B DA 4C 8B F1"); + // Broken for 1.20.71.1 + //hookManager->RegisterFunction(&BlockDefinitionGroup::registerBlocks, "48 89 5C 24 ? 48 89 6C 24 ? 56 57 41 54 41 56 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 84 24 ? ? ? ? 4C 8B F9"); + + /* Make hooks */ hookManager->CreateHook(&ScreenView::setupAndRender, _ScreenView_setupAndRender, &ScreenView_setupAndRender); hookManager->CreateHook(&Minecraft::update, _Minecraft_update, &Minecraft_update); hookManager->CreateHook(&ClientInstance::onStartJoinGame, _ClientInstance_onStartJoinGame, &ClientInstance_onStartJoinGame); hookManager->CreateHook(&ClientInstance::requestLeaveGame, _ClientInstance_requestLeaveGame, &ClientInstance_requestLeaveGame); - hookManager->CreateHook(&VanillaItems::registerItems, _VanillaItems_registerItems, &VanillaItems_registerItems); + //hookManager->CreateHook(&VanillaItems::registerItems, _VanillaItems_registerItems, &VanillaItems_registerItems); // hookManager->CreateHook(&BlockDefinitionGroup::registerBlocks, _BlockDefinitionGroup_registerBlocks, &BlockDefinitionGroup_registerBlocks); - hookManager->CreateHook(&LevelRenderer::renderLevel, _LevelRenderer_renderLevel, &LevelRenderer_renderLevel); + //hookManager->CreateHook(&LevelRenderer::renderLevel, _LevelRenderer_renderLevel, &LevelRenderer_renderLevel); - //// C++ does not allow doing a reference to get the addresses of constructors... - hookManager->CreateHookAbsolute(_ClientInstance_ClientInstance, SigScan("48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 49 8B F9 49 8B D8 4C 8B E2"), &ClientInstance_ClientInstance); + // C++ does not allow doing a reference to get the addresses of constructors... + hookManager->CreateHookAbsolute(_ClientInstance_ClientInstance, SigScan("48 89 5C 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 ? 49 8B F9 49 8B D8 4C 8B E2"), &ClientInstance_ClientInstance); } \ No newline at end of file From 7e996a31587da94b7441cbee185318a6a8e04c89 Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Tue, 12 Mar 2024 23:11:57 +0000 Subject: [PATCH 12/14] Item & BlockType Registries in Level --- .../src/minecraft/src/common/world/level/Level.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/AmethystAPI/src/minecraft/src/common/world/level/Level.h b/AmethystAPI/src/minecraft/src/common/world/level/Level.h index 51b9bcb9..ed244fc4 100644 --- a/AmethystAPI/src/minecraft/src/common/world/level/Level.h +++ b/AmethystAPI/src/minecraft/src/common/world/level/Level.h @@ -1,5 +1,16 @@ #pragma once -class Level { +#include "minecraft/src/common/SharedPtr.h" +#include +#include + +class BlockTypeRegistry; +class Level { +public: + /* this + 0 */ uintptr_t** vtable; + /* this + 8 */ std::byte padding8[340]; + /* this + 348 */ const ItemRegistryRef mItemRegistry; + /* this + 364 */ std::weak_ptr mBlockRegistry; + /* this + 380 */ std::byte padding380[8620]; }; \ No newline at end of file From 89f16d8304dfebae25e4d0553e2109023dc93b23 Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Wed, 13 Mar 2024 16:08:51 +0000 Subject: [PATCH 13/14] Fix offset in level --- AmethystAPI/src/minecraft/src/common/world/level/Level.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/AmethystAPI/src/minecraft/src/common/world/level/Level.h b/AmethystAPI/src/minecraft/src/common/world/level/Level.h index ed244fc4..8d888a29 100644 --- a/AmethystAPI/src/minecraft/src/common/world/level/Level.h +++ b/AmethystAPI/src/minecraft/src/common/world/level/Level.h @@ -8,9 +8,7 @@ class BlockTypeRegistry; class Level { public: - /* this + 0 */ uintptr_t** vtable; - /* this + 8 */ std::byte padding8[340]; - /* this + 348 */ const ItemRegistryRef mItemRegistry; - /* this + 364 */ std::weak_ptr mBlockRegistry; - /* this + 380 */ std::byte padding380[8620]; + /* this + 0 */ std::byte padding0[840]; + /* this + 840 */ const ItemRegistryRef mItemRegistry; + /* this + 856 */ std::byte padding856[8144]; }; \ No newline at end of file From e145c409f69890ee7446d3b2685cf2f668e4644a Mon Sep 17 00:00:00 2001 From: FrederoxDev Date: Wed, 13 Mar 2024 16:34:41 +0000 Subject: [PATCH 14/14] Bump version up to 1.2.1 for 1.20.71.1 --- AmethystRuntime/CMakeLists.txt | 10 +++++++++- AmethystRuntime/src/AmethystRuntime.cpp | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/AmethystRuntime/CMakeLists.txt b/AmethystRuntime/CMakeLists.txt index 62fa31d6..bc6de7af 100644 --- a/AmethystRuntime/CMakeLists.txt +++ b/AmethystRuntime/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.12) project(AmethystRuntime) -set(MOD_VERSION "1.2.0") +set(MOD_VERSION "1.2.1") + +# Runtime Build Options +option(AMETHYST_INPUT_SYSTEM "Enables AmethystAPI's input system" OFF) # C++ Build Settings set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" CACHE STRING "Build configurations" FORCE) @@ -15,6 +18,11 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${AmethystFolder}/mods/${PROJ find_library(AMETHYST_API AmethystAPI PATHS "${AmethystFolder}/lib") include_directories(${AmethystFolder}/include "src/") +# Compile definitions +if (AMETHYST_INPUT_SYSTEM) + add_compile_definitions(AMETHYST_INPUT_SYSTEM) +endif() + # Project Files file(GLOB_RECURSE CPP_SOURCES "src/*.cpp") file(GLOB_RECURSE H_FILES "src/*.h" ) diff --git a/AmethystRuntime/src/AmethystRuntime.cpp b/AmethystRuntime/src/AmethystRuntime.cpp index 1ee04206..f62e33fc 100644 --- a/AmethystRuntime/src/AmethystRuntime.cpp +++ b/AmethystRuntime/src/AmethystRuntime.cpp @@ -77,7 +77,9 @@ void AmethystRuntime::PromptDebugger() void AmethystRuntime::CreateOwnHooks() { - // CreateInputHooks(); + #ifdef AMETHYST_INPUT_SYSTEM + CreateInputHooks(); + #endif CreateModFunctionHooks(); }