From 7d26e36626bd2287a56cc77bfe598a55a8ea23ec Mon Sep 17 00:00:00 2001 From: cai_miao Date: Sun, 2 May 2021 14:07:39 +0900 Subject: [PATCH] Unicode basic support --- BH/Constants.h | 2 +- BH/Drawing/Advanced/Keyhook/Keyhook.cpp | 6 +-- BH/Modules/Item/Item.cpp | 72 ++++++++++++------------- BH/Modules/Item/ItemDisplay.cpp | 40 +++++++------- BH/Modules/ItemMover/ItemMover.cpp | 4 +- BH/Modules/Maphack/Maphack.cpp | 44 +++++++-------- BH/Modules/ScreenInfo/ScreenInfo.cpp | 4 +- 7 files changed, 86 insertions(+), 86 deletions(-) diff --git a/BH/Constants.h b/BH/Constants.h index 968d7a64..f7fb86de 100644 --- a/BH/Constants.h +++ b/BH/Constants.h @@ -2,7 +2,7 @@ #define BH_VERSION "BH 1.9.10-b3" -#define CODE_PAGE 1252 // windows-1252 ANSI Latin 1; Western European (Windows) +#define CODE_PAGE CP_UTF8 // windows-1252 ANSI Latin 1; Western European (Windows) enum TextColor { Disabled=-1, diff --git a/BH/Drawing/Advanced/Keyhook/Keyhook.cpp b/BH/Drawing/Advanced/Keyhook/Keyhook.cpp index 4031f09e..b2b92127 100644 --- a/BH/Drawing/Advanced/Keyhook/Keyhook.cpp +++ b/BH/Drawing/Advanced/Keyhook/Keyhook.cpp @@ -46,9 +46,9 @@ void Keyhook::OnDraw() { bool IsInRange = InRange(*p_D2CLIENT_MouseX, *p_D2CLIENT_MouseY); if (name.length() > 0) { if(IsInRange) - prefix = name + "\377c7 "; + prefix = name + "ÿc7 "; else - prefix = name + "\377c4 "; + prefix = name + "ÿc4 "; } string text = prefix + keyCode.literalName; @@ -86,7 +86,7 @@ unsigned int Keyhook::GetXSize() { KeyCode keyCode = GetKeyCode(GetKey()); string prefix = ""; if (name.length() > 0) - prefix = name + ":�c4 "; + prefix = name + ":ÿc4 "; string text = prefix + keyCode.literalName; DWORD width, fileNo; wchar_t* wString = AnsiToUnicode(text.c_str()); diff --git a/BH/Modules/Item/Item.cpp b/BH/Modules/Item/Item.cpp index 99abe25b..e578d06e 100644 --- a/BH/Modules/Item/Item.cpp +++ b/BH/Modules/Item/Item.cpp @@ -390,17 +390,17 @@ void __fastcall Item::ItemNamePatch(wchar_t *name, UnitAny *item) } // Some common color codes for text strings (see TextColor enum): - // \xFF" "c; (purple) - // \xFF" "c0 (white) - // \xFF" "c1 (red) - // \xFF" "c2 (green) - // \xFF" "c3 (blue) - // \xFF" "c4 (gold) - // \xFF" "c5 (gray) - // \xFF" "c6 (black) - // \xFF" "c7 (tan) - // \xFF" "c8 (orange) - // \xFF" "c9 (yellow) + // ÿc; (purple) + // ÿc0 (white) + // ÿc1 (red) + // ÿc2 (green) + // ÿc3 (blue) + // ÿc4 (gold) + // ÿc5 (gray) + // ÿc6 (black) + // ÿc7 (tan) + // ÿc8 (orange) + // ÿc9 (yellow) /* Test code to display item codes */ //string test3 = test_code; @@ -419,12 +419,12 @@ void Item::OrigGetItemName(UnitAny *item, string &itemName, char *code) // We will also strip ilvls from these items if (code[0] == 't' && code[1] == 's' && code[2] == 'c') // town portal scroll { - itemName = "\xFF" "c2**\xFF" "c0TP"; + itemName = "ÿc2**ÿc0TP"; displayItemLevel = false; } else if (code[0] == 'i' && code[1] == 's' && code[2] == 'c') // identify scroll { - itemName = "\xFF" "c2**\xFF" "c0ID"; + itemName = "ÿc2**ÿc0ID"; displayItemLevel = false; } else if (code[0] == 'v' && code[1] == 'p' && code[2] == 's') // stamina potion @@ -476,27 +476,27 @@ void Item::OrigGetItemName(UnitAny *item, string &itemName, char *code) { if (code[2] == '1') { - itemName = "\xFF" "c1**\xFF" "c0Min Heal"; + itemName = "ÿc1**ÿc0Min Heal"; displayItemLevel = false; } else if (code[2] == '2') { - itemName = "\xFF" "c1**\xFF" "c0Lt Heal"; + itemName = "ÿc1**ÿc0Lt Heal"; displayItemLevel = false; } else if (code[2] == '3') { - itemName = "\xFF" "c1**\xFF" "c0Heal"; + itemName = "ÿc1**ÿc0Heal"; displayItemLevel = false; } else if (code[2] == '4') { - itemName = "\xFF" "c1**\xFF" "c0Gt Heal"; + itemName = "ÿc1**ÿc0Gt Heal"; displayItemLevel = false; } else if (code[2] == '5') { - itemName = "\xFF" "c1**\xFF" "c0Sup Heal"; + itemName = "ÿc1**ÿc0Sup Heal"; displayItemLevel = false; } } @@ -504,27 +504,27 @@ void Item::OrigGetItemName(UnitAny *item, string &itemName, char *code) { if (code[2] == '1') { - itemName = "\xFF" "c3**\xFF" "c0Min Mana"; + itemName = "ÿc3**ÿc0Min Mana"; displayItemLevel = false; } else if (code[2] == '2') { - itemName = "\xFF" "c3**\xFF" "c0Lt Mana"; + itemName = "ÿc3**ÿc0Lt Mana"; displayItemLevel = false; } else if (code[2] == '3') { - itemName = "\xFF" "c3**\xFF" "c0Mana"; + itemName = "ÿc3**ÿc0Mana"; displayItemLevel = false; } else if (code[2] == '4') { - itemName = "\xFF" "c3**\xFF" "c0Gt Mana"; + itemName = "ÿc3**ÿc0Gt Mana"; displayItemLevel = false; } else if (code[2] == '5') { - itemName = "\xFF" "c3**\xFF" "c0Sup Mana"; + itemName = "ÿc3**ÿc0Sup Mana"; displayItemLevel = false; } } @@ -532,12 +532,12 @@ void Item::OrigGetItemName(UnitAny *item, string &itemName, char *code) { if (code[2] == 's') { - itemName = "\xFF" "c;**\xFF" "c0Rejuv"; + itemName = "ÿc;**ÿc0Rejuv"; displayItemLevel = false; } else if (code[2] == 'l') { - itemName = "\xFF" "c;**\xFF" "c0Full"; + itemName = "ÿc;**ÿc0Full"; displayItemLevel = false; } } @@ -633,13 +633,13 @@ void Item::OrigGetItemName(UnitAny *item, string &itemName, char *code) //if( (code[0] == 'g' && code[1] == 'l' ) || // (code[0] == 's' && code[1] == 'k' && code[2] == 'l' ) ) //{ - // itemName = "\xFF" "c:" + itemName; + // itemName = "ÿc:" + itemName; //} ///*Perfect Gems*/ //if( (code[0] == 'g' && code[1] == 'p' ) || // (code[0] == 's' && code[1] == 'k' && code[2] == 'p' ) ) //{ - // itemName = "\xFF" "c<" + itemName; + // itemName = "ÿc<" + itemName; //} /*Ethereal*/ if( item->pItemData->dwFlags & 0x400000 ) @@ -648,7 +648,7 @@ void Item::OrigGetItemName(UnitAny *item, string &itemName, char *code) if( (code[0] == 'u' ) || (code[0] == 'p' && code[1] == 'a' && code[2] >= 'b') ) { - itemName = "\xFF" "c;" + itemName; + itemName = "ÿc;" + itemName; } } /*Runes*/ @@ -656,33 +656,33 @@ void Item::OrigGetItemName(UnitAny *item, string &itemName, char *code) { if( code[1] == '0' ) { - itemName = "\xFF" "c0" + itemName; + itemName = "ÿc0" + itemName; } else if( code[1] == '1' ) { if( code[2] <= '6') { - itemName = "\xFF" "c4" + itemName; + itemName = "ÿc4" + itemName; } else { - itemName = "\xFF" "c8" + itemName; + itemName = "ÿc8" + itemName; } } else if( code[1] == '2' ) { if( code[2] <= '2' ) { - itemName = "\xFF" "c8" + itemName; + itemName = "ÿc8" + itemName; } else { - itemName = "\xFF" "c1" + itemName; + itemName = "ÿc1" + itemName; } } else if( code[1] == '3' ) { - itemName = "\xFF" "c1" + itemName; + itemName = "ÿc1" + itemName; } } } @@ -718,7 +718,7 @@ void __stdcall Item::OnProperties(wchar_t * wTxt) auto chars_written = MultiByteToWideChar(CODE_PAGE, MB_PRECOMPOSED, desc.c_str(), -1, wDesc, 128); swprintf_s(wTxt + aLen, MAXLEN - aLen, L"%s%s\n", - (chars_written > 0) ? wDesc : L"\377c1 Descirption string too long!", + (chars_written > 0) ? wDesc : L"ÿc1 Descirption string too long!", GetColorCode(TextColor::White).c_str()); } } @@ -760,7 +760,7 @@ void __stdcall Item::OnProperties(wchar_t * wTxt) base, GetColorCode(TextColor::DarkGreen).c_str(), min, max_no_ed, - ebugged ? L"\377c5 Ebug" : L"", + ebugged ? L"ÿc5 Ebug" : L"", GetColorCode(TextColor::White).c_str() ); } diff --git a/BH/Modules/Item/ItemDisplay.cpp b/BH/Modules/Item/ItemDisplay.cpp index e3815062..4e0361d2 100644 --- a/BH/Modules/Item/ItemDisplay.cpp +++ b/BH/Modules/Item/ItemDisplay.cpp @@ -16,22 +16,22 @@ // All colors here must also be defined in MAP_COLOR_REPLACEMENTS #define COLOR_REPLACEMENTS \ - {"WHITE", "\377c0"}, \ - {"RED", "\377c1"}, \ - {"GREEN", "\377c2"}, \ - {"BLUE", "\377c3"}, \ - {"GOLD", "\377c4"}, \ - {"GRAY", "\377c5"}, \ - {"BLACK", "\377c6"}, \ - {"TAN", "\377c7"}, \ - {"ORANGE", "\377c8"}, \ - {"YELLOW", "\377c9"}, \ - {"PURPLE", "\377c;"}, \ - {"DARK_GREEN", "\377c:"}, \ - {"CORAL", "\377c\x06"}, \ - {"SAGE", "\377c\x07"}, \ - {"TEAL", "\377c\x09"}, \ - {"LIGHT_GRAY", "\xFF" "c\x0C"} + {"WHITE", "ÿc0"}, \ + {"RED", "ÿc1"}, \ + {"GREEN", "ÿc2"}, \ + {"BLUE", "ÿc3"}, \ + {"GOLD", "ÿc4"}, \ + {"GRAY", "ÿc5"}, \ + {"BLACK", "ÿc6"}, \ + {"TAN", "ÿc7"}, \ + {"ORANGE", "ÿc8"}, \ + {"YELLOW", "ÿc9"}, \ + {"PURPLE", "ÿc;"}, \ + {"DARK_GREEN", "ÿc:"}, \ + {"CORAL", "ÿc\x06"}, \ + {"SAGE", "ÿc\x07"}, \ + {"TEAL", "ÿc\x09"}, \ + {"LIGHT_GRAY", "ÿc\x0C"} #define MAP_COLOR_WHITE 0x20 @@ -338,13 +338,13 @@ void SubstituteNameVariables(UnitItemInfo *uInfo, string &name, const string &ac // Revert to non-glide colors here if (*p_D2GFX_VideoMode != VIDEO_MODE_GLIDE) { if (replacements[n].key == "CORAL") { - replacements[n].value = "\377c1"; // red + replacements[n].value = "ÿc1"; // red } else if (replacements[n].key == "SAGE") { - replacements[n].value = "\377c2"; // green + replacements[n].value = "ÿc2"; // green } else if (replacements[n].key == "TEAL") { - replacements[n].value = "\377c3"; // blue + replacements[n].value = "ÿc3"; // blue } else if (replacements[n].key == "LIGHT_GRAY") { - replacements[n].value = "\377c5"; // gray + replacements[n].value = "ÿc5"; // gray } } diff --git a/BH/Modules/ItemMover/ItemMover.cpp b/BH/Modules/ItemMover/ItemMover.cpp index 40a993bd..d3fe5f10 100644 --- a/BH/Modules/ItemMover/ItemMover.cpp +++ b/BH/Modules/ItemMover/ItemMover.cpp @@ -572,7 +572,7 @@ void ItemMover::OnGamePacketRecv(BYTE* packet, bool* block) { ) { PrintText(color, "%s%s", item.name.c_str(), - (*BH::MiscToggles2)["Verbose Notifications"].state ? " \377c5drop" : "" + (*BH::MiscToggles2)["Verbose Notifications"].state ? " ÿc5drop" : "" ); } if ((*BH::MiscToggles2)["Item Close Notifications"].state && @@ -581,7 +581,7 @@ void ItemMover::OnGamePacketRecv(BYTE* packet, bool* block) { ) { PrintText(color, "%s%s", item.name.c_str(), - (*BH::MiscToggles2)["Verbose Notifications"].state ? " \377c5close" : "" + (*BH::MiscToggles2)["Verbose Notifications"].state ? " ÿc5close" : "" ); } } diff --git a/BH/Modules/Maphack/Maphack.cpp b/BH/Modules/Maphack/Maphack.cpp index 821a5827..dddc930b 100644 --- a/BH/Modules/Maphack/Maphack.cpp +++ b/BH/Modules/Maphack/Maphack.cpp @@ -74,22 +74,22 @@ void Maphack::ReadConfig() { BH::config->ReadAssoc("Missile Color", missileColors); BH::config->ReadAssoc("Monster Color", monsterColors); - TextColorMap["\377c0"] = 0x20; // white - TextColorMap["\377c1"] = 0x0A; // red - TextColorMap["\377c2"] = 0x84; // green - TextColorMap["\377c3"] = 0x97; // blue - TextColorMap["\377c4"] = 0x0D; // gold - TextColorMap["\377c5"] = 0xD0; // gray - TextColorMap["\377c6"] = 0x00; // black - TextColorMap["\377c7"] = 0x5A; // tan - TextColorMap["\377c8"] = 0x60; // orange - TextColorMap["\377c9"] = 0x0C; // yellow - TextColorMap["\377c;"] = 0x9B; // purple - TextColorMap["\377c:"] = 0x76; // dark green - TextColorMap["\377c\x06"] = 0x66; // coral - TextColorMap["\377c\x07"] = 0x82; // sage - TextColorMap["\377c\x09"] = 0xCB; // teal - TextColorMap["\377c\x0C"] = 0xD6; // light gray + TextColorMap["ÿc0"] = 0x20; // white + TextColorMap["ÿc1"] = 0x0A; // red + TextColorMap["ÿc2"] = 0x84; // green + TextColorMap["ÿc3"] = 0x97; // blue + TextColorMap["ÿc4"] = 0x0D; // gold + TextColorMap["ÿc5"] = 0xD0; // gray + TextColorMap["ÿc6"] = 0x00; // black + TextColorMap["ÿc7"] = 0x5A; // tan + TextColorMap["ÿc8"] = 0x60; // orange + TextColorMap["ÿc9"] = 0x0C; // yellow + TextColorMap["ÿc;"] = 0x9B; // purple + TextColorMap["ÿc:"] = 0x76; // dark green + TextColorMap["ÿc\x06"] = 0x66; // coral + TextColorMap["ÿc\x07"] = 0x82; // sage + TextColorMap["ÿc\x09"] = 0xCB; // teal + TextColorMap["ÿc\x0C"] = 0xD6; // light gray BH::config->ReadAssoc("Monster Color", MonsterColors); for (auto it = MonsterColors.cbegin(); it != MonsterColors.cend(); it++) { @@ -499,8 +499,8 @@ void Maphack::OnAutomapDraw() { } //Determine immunities - string szImmunities[] = { "\377c7i", "\377c8i", "\377c1i", "\377c9i", "\377c3i", "\377c2i" }; - string szResistances[] = { "\377c7r", "\377c8r", "\377c1r", "\377c9r", "\377c3r", "\377c2r" }; + string szImmunities[] = { "ÿc7i", "ÿc8i", "ÿc1i", "ÿc9i", "ÿc3i", "ÿc2i" }; + string szResistances[] = { "ÿc7r", "ÿc8r", "ÿc1r", "ÿc9r", "ÿc3r", "ÿc2r" }; DWORD dwImmunities[] = { STAT_DMGREDUCTIONPCT, STAT_MAGICDMGREDUCTIONPCT, @@ -523,7 +523,7 @@ void Maphack::OnAutomapDraw() { //Determine Enchantments string enchantText; if (Toggles["Monster Enchantments"].state) { - string szEnchantments[] = {"\377c3m", "\377c1e", "\377c9e", "\377c3e"}; + string szEnchantments[] = {"ÿc3m", "ÿc1e", "ÿc9e", "ÿc3e"}; for (int n = 0; n < 9; n++) { if (unit->pMonsterData->fBoss) { @@ -665,7 +665,7 @@ void Maphack::OnAutomapDraw() { return; for (list::iterator it = automapLevels.begin(); it != automapLevels.end(); it++) { if (player->pAct->dwAct == (*it)->act) { - string tombStar = ((*it)->levelId == player->pAct->pMisc->dwStaffTombLevel) ? "\377c2*" : "\377c4"; + string tombStar = ((*it)->levelId == player->pAct->pMisc->dwStaffTombLevel) ? "ÿc2*" : "ÿc4"; POINT unitLoc; Hook::ScreenToAutomap(&unitLoc, (*it)->x, (*it)->y); char* name = UnicodeToAnsi(D2CLIENT_GetLevelName((*it)->levelId)); @@ -750,13 +750,13 @@ void Maphack::OnGamePacketRecv(BYTE *packet, bool *block) { // if(packet[6+(packet[0]-0xa7)] == 100) { // UnitAny* pUnit = D2CLIENT_FindServerSideUnit(*(DWORD*)&packet[2], 0); // if(pUnit) - // PrintText(1, "Alert: \377c4Player \377c2%s \377c4drank a \377c1Health \377c4potion!", pUnit->pPlayerData->szName); + // PrintText(1, "Alert: ÿc4Player ÿc2%s ÿc4drank a ÿc1Health ÿc4potion!", pUnit->pPlayerData->szName); // } else if (packet[6+(packet[0]-0xa7)] == 105) { // UnitAny* pUnit = D2CLIENT_FindServerSideUnit(*(DWORD*)&packet[2], 0); // if(pUnit) // if(pUnit->dwTxtFileNo == 1) // if(D2COMMON_GetUnitState(pUnit, 30)) - // PrintText(1, "Alert: \377c4ES Sorc \377c2%s \377c4drank a \377c3Mana \377c4Potion!", pUnit->pPlayerData->szName); + // PrintText(1, "Alert: ÿc4ES Sorc ÿc2%s ÿc4drank a ÿc3Mana ÿc4Potion!", pUnit->pPlayerData->szName); // } else if (packet[6+(packet[0]-0xa7)] == 102) {//remove portal delay // *block = true; // } diff --git a/BH/Modules/ScreenInfo/ScreenInfo.cpp b/BH/Modules/ScreenInfo/ScreenInfo.cpp index 62df1734..3a00e36e 100644 --- a/BH/Modules/ScreenInfo/ScreenInfo.cpp +++ b/BH/Modules/ScreenInfo/ScreenInfo.cpp @@ -575,7 +575,7 @@ void ScreenInfo::OnGameExit() { }); BH::drops.clear(); - drops = regex_replace(drops, regex("\xFF" "c."), ""); + drops = regex_replace(drops, regex("ÿc."), ""); drops = regex_replace(drops, regex("\n"), " "); automap["GAMESTOLVL"] = szGamesToLevel; @@ -586,7 +586,7 @@ void ScreenInfo::OnGameExit() { automap["LASTXPPERSECLONG"] = to_string(lastExpPerSecond); automap["LASTGAMETIME"] = szLastGameTime; automap["LASTGAMETIMESEC"] = to_string(lastGameLength); - automap["DROPS"] = regex_replace(drops, regex("\xFF" "c."), ""); + automap["DROPS"] = regex_replace(drops, regex("ÿc."), ""); int idx = 0; for (int i = 0; i < 8; i++) {