Skip to content

Commit 4458ed6

Browse files
committed
Update BetterInventory to new amethyst things, fix resource loading based crash
1 parent 9a914c3 commit 4458ed6

5 files changed

Lines changed: 51 additions & 63 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(BetterInventory)
3-
set(MOD_VERSION "1.5.1")
3+
set(MOD_VERSION "1.5.2")
44

55
# Define only RelWithDebInfo as the available build configuration
66
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" CACHE STRING "Build configurations" FORCE)
@@ -47,13 +47,5 @@ add_custom_target(ClangFormat
4747
${CPP_SOURCES} ${H_FILES}
4848
)
4949

50-
# Copy resource packs to com.mojang/development_resource_packs
51-
# add_custom_target(CopyResources
52-
# COMMENT "Copying resources to ${DevResourcesFolder}/${PROJECT_NAME}"
53-
# COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/resources" "${DevResourcesFolder}/${PROJECT_NAME}"
54-
# )
55-
56-
# add_dependencies(${PROJECT_NAME} CopyResources)
57-
5850
# Write a mod.json file to provide meta data about the mod
5951
configure_file(mod.json.in "${AmethystFolder}/mods/${PROJECT_NAME}@${MOD_VERSION}/mod.json" @ONLY)

include/ShulkerRenderer.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
#pragma once
2-
#include <minecraft/src/common/world/item/ItemStack.h>
3-
#include <minecraft/src-client/common/client/gui/ScreenView.h>
4-
#include <minecraft/src-deps/core/string/StringHash.h>
5-
#include <minecraft/src-deps/core/resource/ResourceHelper.h>
6-
#include <minecraft/src-client/common/client/renderer/TexturePtr.h>
7-
#include <minecraft/src-client/common/client/renderer/BaseActorRenderContext.h>
8-
#include <minecraft/src-client/common/client/renderer/actor/ItemRenderer.h>
9-
#include <minecraft/src-client/common/client/gui/controls/renderers/HoverRenderer.h>
10-
#include <minecraft/src-client/common/client/renderer/NinesliceInfo.h>
11-
#include <amethyst/ui/NinesliceHelper.h>
2+
#include <minecraft/src/common/world/item/ItemStack.hpp>
3+
#include <minecraft/src-client/common/client/gui/ScreenView.hpp>
4+
#include <minecraft/src-deps/core/string/StringHash.hpp>
5+
#include <minecraft/src-deps/core/resource/ResourceHelper.hpp>
6+
#include <minecraft/src-client/common/client/renderer/TexturePtr.hpp>
7+
#include <minecraft/src-client/common/client/renderer/BaseActorRenderContext.hpp>
8+
#include <minecraft/src-client/common/client/renderer/actor/ItemRenderer.hpp>
9+
#include <minecraft/src-client/common/client/gui/controls/renderers/HoverRenderer.hpp>
10+
#include <minecraft/src-client/common/client/renderer/NinesliceInfo.hpp>
11+
#include <amethyst/ui/NinesliceHelper.hpp>
1212

1313
#define SHULKER_CACHE_SIZE 16
1414

1515
class ShulkerRenderer {
16+
private:
17+
mce::TexturePtr mBackgroundTexture;
18+
mce::TexturePtr mItemSlotTexture;
19+
1620
public:
1721
void Render(UIRenderContext* ctx, HoverRenderer* hoverRenderer, int index);
1822
};

include/dllmain.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,35 @@
44
#include <iostream>
55
#include <fstream>
66
#include <chrono>
7-
#include <amethyst/Log.h>
8-
#include <amethyst/Memory.h>
9-
#include <minecraft/src/common/world/item/ItemStack.h>
10-
#include <minecraft/src/common/world/item/ShulkerBoxBlockItem.h>
11-
#include <minecraft/src/common/world/item/ItemStackBase.h>
12-
#include <minecraft/src/common/nbt/CompoundTag.h>
13-
#include <minecraft/src/common/nbt/ListTag.h>
14-
#include <minecraft/src/common/nbt/CompoundTagVariant.h>
15-
#include <minecraft/src/common/nbt/ByteTag.h>
16-
#include <minecraft/src-client/common/client/renderer/actor/ItemRenderer.h>
17-
#include <minecraft/src-client/common/client/renderer/BaseActorRenderContext.h>
18-
#include <minecraft/src-client/common/client/gui/ScreenView.h>
19-
#include <minecraft/src/common/world/item/registry/ItemRegistryManager.h>
20-
#include <minecraft/src/common/world/item/registry/ItemRegistry.h>
21-
#include <minecraft/src/common/world/actor/player/PlayerInventory.h>
22-
#include <minecraft/src/common/world/Container.h>
23-
#include <minecraft/src-deps/core/resource/ResourceHelper.h>
24-
#include <minecraft/src-client/common/client/renderer/TexturePtr.h>
25-
#include <minecraft/src-client/common/client/gui/controls/renderers/HoverRenderer.h>
7+
#include <amethyst/Log.hpp>
8+
#include <amethyst/Memory.hpp>
9+
#include <minecraft/src/common/world/item/ItemStack.hpp>
10+
#include <minecraft/src/common/world/item/ShulkerBoxBlockItem.hpp>
11+
#include <minecraft/src/common/world/item/ItemStackBase.hpp>
12+
#include <minecraft/src/common/nbt/CompoundTag.hpp>
13+
#include <minecraft/src/common/nbt/ListTag.hpp>
14+
#include <minecraft/src/common/nbt/CompoundTagVariant.hpp>
15+
#include <minecraft/src/common/nbt/ByteTag.hpp>
16+
#include <minecraft/src-client/common/client/renderer/actor/ItemRenderer.hpp>
17+
#include <minecraft/src-client/common/client/renderer/BaseActorRenderContext.hpp>
18+
#include <minecraft/src-client/common/client/gui/ScreenView.hpp>
19+
#include <minecraft/src/common/world/item/registry/ItemRegistryManager.hpp>
20+
#include <minecraft/src/common/world/item/registry/ItemRegistry.hpp>
21+
#include <minecraft/src/common/world/actor/player/PlayerInventory.hpp>
22+
#include <minecraft/src/common/world/Container.hpp>
23+
#include <minecraft/src-deps/core/resource/ResourceHelper.hpp>
24+
#include <minecraft/src-client/common/client/renderer/TexturePtr.hpp>
25+
#include <minecraft/src-client/common/client/gui/controls/renderers/HoverRenderer.hpp>
2626
#include <chrono>
2727
#include <amethyst-deps/safetyhook.hpp>
28-
#include <amethyst/runtime/AmethystContext.h>
28+
#include <amethyst/runtime/AmethystContext.hpp>
2929
#include <typeindex>
30-
#include <minecraft/src/common/world/level/Level.h>
30+
#include <minecraft/src/common/world/level/Level.hpp>
3131

3232
#include "ShulkerRenderer.h"
3333

3434
#define ModFunction extern "C" __declspec(dllexport)
3535

36-
class CollisionTest {
37-
public:
38-
void Func1(const std::string&);
39-
void Func2(const std::string&);
40-
};
41-
4236
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
4337
return TRUE;
4438
}

src/ShulkerRenderer.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ extern ItemStack shulkerInventory[SHULKER_CACHE_SIZE][27];
55
// Texture loading
66
static HashedString flushString(0xA99285D21E94FC80, "ui_flush");
77

8-
static const auto itemSlotTexture = std::make_unique<mce::TexturePtr>();
9-
static const auto backgroundTexture = std::make_unique<mce::TexturePtr>();
10-
11-
static ResourceLocation itemSlotLocation("textures/gui/gui");
12-
static ResourceLocation backgroundLocation("textures/ui/purpleBorder");
13-
148
bool hasLoadedTexture = false;
159

1610
// Slot sizing
@@ -37,9 +31,13 @@ int countNewlines(const std::string& str) {
3731
void ShulkerRenderer::Render(UIRenderContext* ctx, HoverRenderer* hoverRenderer, int index) {
3832
// Only load inventory resources once
3933
if (!hasLoadedTexture) {
40-
ctx->getTexture(itemSlotTexture.get(), &itemSlotLocation, true);
41-
ctx->getTexture(backgroundTexture.get(), &backgroundLocation, true);
42-
hasLoadedTexture = true;
34+
ResourceLocation backgroundResource("textures/ui/purpleBorder");
35+
mBackgroundTexture = ctx->getTexture(&backgroundResource, true);
36+
37+
ResourceLocation itemSlotResource("textures/gui/gui");
38+
mItemSlotTexture = ctx->getTexture(&itemSlotResource, true);
39+
40+
hasLoadedTexture = true;
4341
}
4442

4543
float textHeight = (countNewlines(hoverRenderer->mFilteredContent) + 1) * 10.0f;
@@ -51,7 +49,7 @@ void ShulkerRenderer::Render(UIRenderContext* ctx, HoverRenderer* hoverRenderer,
5149

5250
// Draw the background panel
5351
RectangleArea background = {panelX - 4, panelX + panelWidth + 4, panelY - 4, panelY + panelHeight + 4};
54-
backgroundNineslice.Draw(background, backgroundTexture.get(), ctx);
52+
backgroundNineslice.Draw(background, &mBackgroundTexture, ctx);
5553
ctx->flushImages(mce::Color::WHITE, 1.0f, flushString);
5654

5755
// Draw the item slots
@@ -60,7 +58,7 @@ void ShulkerRenderer::Render(UIRenderContext* ctx, HoverRenderer* hoverRenderer,
6058
glm::tvec2<float> size(slotSize, slotSize);
6159
glm::tvec2<float> position(panelX + slotSize * x, panelY + textHeight + slotSize * y);
6260

63-
ctx->drawImage(*itemSlotTexture, &position, &size, &itemSlotUvPos, &itemSlotUvSize, 0);
61+
ctx->drawImage(mItemSlotTexture, &position, &size, &itemSlotUvPos, &itemSlotUvSize, 0);
6462
}
6563
}
6664

src/dllmain.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ static void HoverRenderer__renderHoverBox(HoverRenderer* self, MinecraftUIRender
8686
}
8787

8888
ModFunction void Initialize(AmethystContext* ctx) {
89-
ctx->mHookManager.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");
90-
ctx->mHookManager.CreateHook(&Item::appendFormattedHovertext, _Item_appendFormattedHoverText, &Item_appendFormattedHovertext);
89+
ctx->mHookManager.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");
90+
ctx->mHookManager.CreateHook<&Item::appendFormattedHovertext>(_Item_appendFormattedHoverText, &Item_appendFormattedHovertext);
9191

92-
ctx->mHookManager.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");
93-
ctx->mHookManager.CreateHook(&ShulkerBoxBlockItem::appendFormattedHovertext, _Shulker_appendFormattedHoverText, &Shulker_appendFormattedHovertext);
92+
ctx->mHookManager.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");
93+
ctx->mHookManager.CreateHook<&ShulkerBoxBlockItem::appendFormattedHovertext>(_Shulker_appendFormattedHoverText, &Shulker_appendFormattedHovertext);
9494

95-
ctx->mHookManager.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");
96-
ctx->mHookManager.CreateHook(&HoverRenderer::_renderHoverBox, _HoverRenderer__renderHoverBox, &HoverRenderer__renderHoverBox);
95+
ctx->mHookManager.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");
96+
ctx->mHookManager.CreateHook<&HoverRenderer::_renderHoverBox>(_HoverRenderer__renderHoverBox, &HoverRenderer__renderHoverBox);
9797
}

0 commit comments

Comments
 (0)