From e473825c76cc9a28feac97023e3442ebbe29123c Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Tue, 24 Mar 2026 15:45:59 -0500 Subject: [PATCH] fix: off-by-one in enchantment buttons --- .../Common/UI/UIScene_EnchantingMenu.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp index e0b0653f9..78fca71e5 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_EnchantingMenu.cpp @@ -258,8 +258,8 @@ void UIScene_EnchantingMenu::customDraw(IggyCustomDrawCallbackRegion* region) { 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) { + std::char_traits::compare(region->name, u"slot_Button", + 11) == 0) { int i = 11; slotId = 0; @@ -270,15 +270,19 @@ void UIScene_EnchantingMenu::customDraw(IggyCustomDrawCallbackRegion* region) { } if (slotId >= 0) { + // 4jcraft: sanity check because this code is utter trash garbage + assert(slotId != 0 && + "4J shitcode - attempted to access m_enchantButton with " + "slot_Button0. this shouldn't happen; if you're reading " + "this then go bug someone on GitHub or something"); + // Setup GDraw, normal game render states and matrices CustomDrawData* customDrawRegion = ui.setupCustomDraw(this, region); delete customDrawRegion; - const char* namews = wstringtofilename(u16string_to_wstring(region->name)); - - std::println("render slot {} {}", namews, slotId); - - m_enchantButton[slotId].render(region); + // 4jcraft: NOTE: if slotId == 0 this is UB, but it never is in + // practice, plus added the assertion above as a sanity check + m_enchantButton[slotId - 1].render(region); // Finish GDraw and anything else that needs to be finalised ui.endCustomDraw(region);