From a29b6ad45dbdebf3bdea244aa2025ea6e064f2dd Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Tue, 24 Mar 2026 14:27:07 -0500 Subject: [PATCH] refactor: cleanup UTF-16 digit parsing functionality --- .../Platform/Common/UI/UIScene.cpp | 15 +++++-------- .../Common/UI/UIScene_SkinSelectMenu.cpp | 21 ++++++++++++++----- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Minecraft.Client/Platform/Common/UI/UIScene.cpp b/Minecraft.Client/Platform/Common/UI/UIScene.cpp index e9bb40f96..a1b229a0b 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene.cpp @@ -1235,21 +1235,16 @@ std::size_t UIScene::GetCallbackUniqueId() { bool UIScene::isReadyToDelete() { return true; } int UIScene::parseSlotId(const char16_t* s) { - // must be nonnull, must start with 'slot_', first char after the underscore - // must be a digit - if (!s || - (s[0] != u's' || s[1] != u'l' || s[2] != u'o' || s[3] != u't' || - s[4] != u'_') || - (s[5] < u'0' || s[5] > u'9')) { + if (s == nullptr || + std::char_traits::compare(s, u"slot_", 5) != 0) { return -1; } + // keep consuming digits until we reach a non-digit. each digit scales the + // existing id value by 10 plus the actual digit value. (this is called a + // 'number' by the way) int i = 5; int id = 0; - - // keep consuming digits until we reach a non-digit. each digit scales the - // existing id value by 10 plus the actual digit value. (this is referred to - // as a 'number' by the way) while (s[i] >= u'0' && s[i] <= u'9') { id = id * 10 + (s[i] - u'0'); i++; diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_SkinSelectMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_SkinSelectMenu.cpp index ef0d82eaf..a1c56db02 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_SkinSelectMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_SkinSelectMenu.cpp @@ -595,11 +595,22 @@ void UIScene_SkinSelectMenu::InputActionOK(unsigned int iPad) { } void UIScene_SkinSelectMenu::customDraw(IggyCustomDrawCallbackRegion* region) { - // int characterId = -1; - // swscanf((wchar_t*)region->name,L"Character%d",&characterId); - // 4jcraft: fuck wchar_t - int characterId =region->name[9] - '0' < 0 ? -1 : region->name[9] - '0'; - if (characterId == -1) { + // 4jcraft: fuck wchar_t + int characterId = -1; + if (region->name != nullptr && + std::char_traits::length(region->name) > 9 && + std::char_traits::compare(region->name, u"Character", 9) == + 0) { + int i = 9; + characterId = 0; + + while (region->name[i] >= u'0' && region->name[i] <= u'9') { + characterId = characterId * 10 + (region->name[i] - u'0'); + i++; + } + } + + if (characterId == -1) { app.DebugPrintf("Invalid character to render found\n"); } else { // Setup GDraw, normal game render states and matrices