Skip to content

Commit 1600686

Browse files
committed
Make the shulker box renderer properly use the @1.2.0 stuff
1 parent ef2d20a commit 1600686

4 files changed

Lines changed: 27 additions & 42 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set(MOD_VERSION "1.4.0")
55
# Define only RelWithDebInfo as the available build configuration
66
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" CACHE STRING "Build configurations" FORCE)
77
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo" FORCE)
8-
set(CMAKE_CXX_STANDARD 20)
8+
set(CMAKE_CXX_STANDARD 23)
99

1010
# Build into %appdata%/Amethyst
1111
set(DevResourcesFolder "$ENV{localappdata}/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/development_resource_packs/")
@@ -38,7 +38,6 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE MOD_VERSION="${MOD_VERSION}")
3838
# Link libraries
3939
target_link_libraries(${PROJECT_NAME} PRIVATE ${AMETHYST_API})
4040
target_link_libraries(${PROJECT_NAME} PRIVATE "${AmethystFolder}/lib/fmt.lib")
41-
target_link_libraries(${PROJECT_NAME} PRIVATE "${AmethystFolder}/lib/libMinHook.x64.lib")
4241
target_link_libraries(${PROJECT_NAME} PRIVATE "${AmethystFolder}/lib/libhat.lib")
4342

4443
# Code Style
@@ -54,4 +53,7 @@ add_custom_target(ClangFormat
5453
# COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/resources" "${DevResourcesFolder}/${PROJECT_NAME}"
5554
# )
5655

57-
# add_dependencies(${PROJECT_NAME} CopyResources)
56+
# add_dependencies(${PROJECT_NAME} CopyResources)
57+
58+
# Write a mod.json file to provide meta data about the mod
59+
configure_file(mod.json.in "${AmethystFolder}/mods/${PROJECT_NAME}@${MOD_VERSION}/mod.json" @ONLY)

include/dllmain.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <minecraft/src-client/common/client/renderer/TexturePtr.h>
2929
#include <minecraft/src-client/common/client/gui/controls/renderers/HoverRenderer.h>
3030
#include <chrono>
31+
#include <amethyst-deps/safetyhook.hpp>
3132

3233
#include "ShulkerRenderer.h"
3334

mod.json.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"meta": {
3+
"name": "@PROJECT_NAME@",
4+
"version": "@MOD_VERSION@",
5+
"author": "@MOD_AUTHOR@"
6+
}
7+
}

src/dllmain.cpp

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
ClientInstance* client;
44

5-
ShulkerBoxBlockItem::_appendFormattedHovertext _Shulker_appendFormattedHoverText;
6-
Item::_appendFormattedHovertext _Item_appendFormattedHovertext;
7-
HoverRenderer::__renderHoverBox __renderHoverBox;
8-
95
ShulkerRenderer shulkerRenderer;
106
ItemStack shulkerInventory[SHULKER_CACHE_SIZE][27];
117

8+
SafetyHookInline _Item_appendFormattedHoverText;
9+
SafetyHookInline _Shulker_appendFormattedHoverText;
10+
SafetyHookInline _HoverRenderer__renderHoverBox;
11+
1212
static void Item_appendFormattedHovertext(Item* self, const ItemStackBase& itemStack, Level& level, std::string& text, uint8_t a5) {
13-
_Item_appendFormattedHovertext(self, itemStack, level, text, a5);
14-
Item* item = itemStack.mItem;
13+
_Item_appendFormattedHoverText.call<void, Item*, const ItemStackBase&, Level&, std::string&, uint8_t>(self, itemStack, level, text, a5);
1514

15+
Item* item = itemStack.mItem;
1616
uint64_t max = item->getMaxDamage();
1717

1818
if (max != 0) {
@@ -35,6 +35,7 @@ static void Item_appendFormattedHovertext(Item* self, const ItemStackBase& itemS
3535
int index = 0;
3636

3737
static void Shulker_appendFormattedHovertext(ShulkerBoxBlockItem* self, const ItemStackBase& itemStack, Level& level, std::string& text, uint8_t someBool) {
38+
Log::Info("Shulker appendFormattedHovertext");
3839
// Use the appendFormattedHovertext for regular items, we don't want the list of items
3940
Item_appendFormattedHovertext(self, itemStack, level, text, someBool);
4041

@@ -66,7 +67,7 @@ static void Shulker_appendFormattedHovertext(ShulkerBoxBlockItem* self, const It
6667
}
6768
}
6869

69-
static void _renderHoverBox(HoverRenderer* self, MinecraftUIRenderContext* ctx, IClientInstance* client, RectangleArea* aabb, float someFloat) {
70+
static void HoverRenderer__renderHoverBox(HoverRenderer* self, MinecraftUIRenderContext* ctx, IClientInstance* client, RectangleArea* aabb, float someFloat) {
7071
// This is really bad code, it is relying on the fact that I have also hooked appendFormattedHovertext for items to append the item identifier
7172
// I have no idea where the currently hovered item is stored in the game! I can't find any references to it, so it might be set in some weird place?
7273

@@ -85,42 +86,16 @@ static void _renderHoverBox(HoverRenderer* self, MinecraftUIRenderContext* ctx,
8586
return;
8687
}
8788

88-
__renderHoverBox(self, ctx, client, aabb, someFloat);
89-
}
90-
91-
void OnStartJoinGame(ClientInstance* ci) {
92-
93-
}
94-
95-
void OnRenderUI(ScreenView* screen, UIRenderContext* ctx) {
96-
89+
_HoverRenderer__renderHoverBox.thiscall(self, ctx, client, aabb, someFloat);
9790
}
9891

9992
ModFunction void Initialize(HookManager* hookManager, Amethyst::EventManager* eventManager, InputManager * inputManager) {
100-
MH_Initialize();
101-
10293
hookManager->RegisterFunction(&Item::appendFormattedHovertext, "40 55 53 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 F1 4C 89 44 24 ? 4C 8B F2 48 8B D9");
94+
hookManager->CreateHook(&Item::appendFormattedHovertext, _Item_appendFormattedHoverText, &Item_appendFormattedHovertext);
10395

104-
hookManager->CreateHook(
105-
&Item::appendFormattedHovertext,
106-
&Item_appendFormattedHovertext, reinterpret_cast<void**>(&_Item_appendFormattedHovertext)
107-
);
108-
109-
/*hookManager.CreateHook(
110-
SigScan("40 53 55 56 57 41 56 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 44 24 ? 4D 8B F9 48 8B DA"),
111-
&Shulker_appendFormattedHovertext, reinterpret_cast<void**>(&_Shulker_appendFormattedHoverText)
112-
);
113-
114-
hookManager.CreateHook(
115-
SigScan("40 55 53 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 F1 4C 89 44 24 ? 4C 8B F2 48 8B D9"),
116-
&Item_appendFormattedHovertext, reinterpret_cast<void**>(&_Item_appendFormattedHovertext)
117-
);
118-
119-
hookManager.CreateHook(
120-
SigScan("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"),
121-
&_renderHoverBox, reinterpret_cast<void**>(&__renderHoverBox)
122-
);*/
96+
hookManager->RegisterFunction(&ShulkerBoxBlockItem::appendFormattedHovertext, "40 53 55 56 57 41 56 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 44 24 ? 4D 8B F9 48 8B DA");
97+
hookManager->CreateHook(&ShulkerBoxBlockItem::appendFormattedHovertext, _Shulker_appendFormattedHoverText, &Shulker_appendFormattedHovertext);
12398

124-
eventManager->onStartJoinGame.AddListener(OnStartJoinGame);
125-
eventManager->onRenderUI.AddListener(OnRenderUI);
99+
hookManager->RegisterFunction(&HoverRenderer::_renderHoverBox, "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");
100+
hookManager->CreateHook(&HoverRenderer::_renderHoverBox, _HoverRenderer__renderHoverBox, &HoverRenderer__renderHoverBox);
126101
}

0 commit comments

Comments
 (0)