From 74252cc8d2e310dd05575e59aae90a79f7375d06 Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Tue, 24 Mar 2026 15:26:05 -0500 Subject: [PATCH] fix: slotId parsing in enchantment menu --- .../Platform/Common/UI/UIScene.cpp | 2 +- .../Common/UI/UIScene_EnchantingMenu.cpp | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Minecraft.Client/Platform/Common/UI/UIScene.cpp b/Minecraft.Client/Platform/Common/UI/UIScene.cpp index a1b229a0b..c50a82230 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene.cpp @@ -1235,7 +1235,7 @@ std::size_t UIScene::GetCallbackUniqueId() { bool UIScene::isReadyToDelete() { return true; } int UIScene::parseSlotId(const char16_t* s) { - if (s == nullptr || + if (s == nullptr || std::char_traits::length(s) <= 5 || std::char_traits::compare(s, u"slot_", 5) != 0) { return -1; } diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp index 55f171d5e..e0b0653f9 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp @@ -5,6 +5,8 @@ #include "../../Minecraft.Client/Minecraft.h" #include "UIScene_EnchantingMenu.h" +#include + UIScene_EnchantingMenu::UIScene_EnchantingMenu(int iPad, void* _initData, UILayer* parentLayer) : UIScene_AbstractContainerMenu(iPad, parentLayer) { @@ -253,13 +255,30 @@ void UIScene_EnchantingMenu::customDraw(IggyCustomDrawCallbackRegion* region) { // Finish GDraw and anything else that needs to be finalised ui.endCustomDraw(region); } else { - int slotId = parseSlotId(region->name); + int slotId = -1; + if (region->name != nullptr && + std::char_traits::length(region->name) > 11 && + std::char_traits::compare(region->name, u"slot_Button", 11) == + 0) { + int i = 11; + slotId = 0; + + while (region->name[i] >= u'0' && region->name[i] <= u'9') { + slotId = slotId * 10 + (region->name[i] - u'0'); + i++; + } + } + if (slotId >= 0) { // Setup GDraw, normal game render states and matrices CustomDrawData* customDrawRegion = ui.setupCustomDraw(this, region); delete customDrawRegion; - m_enchantButton[slotId - 1].render(region); + const char* namews = wstringtofilename(u16string_to_wstring(region->name)); + + std::println("render slot {} {}", namews, slotId); + + m_enchantButton[slotId].render(region); // Finish GDraw and anything else that needs to be finalised ui.endCustomDraw(region);