Skip to content

Commit

Permalink
Unicode basic support
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiMiao committed May 2, 2021
1 parent 32d66ca commit 7d26e36
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 86 deletions.
2 changes: 1 addition & 1 deletion BH/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions BH/Drawing/Advanced/Keyhook/Keyhook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
72 changes: 36 additions & 36 deletions BH/Modules/Item/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -476,68 +476,68 @@ 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;
}
}
else if (code[0] == 'm' && code[1] == 'p') // mana potions
{
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;
}
}
else if (code[0] == 'r' && code[1] == 'v') // rejuv potions
{
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;
}
}
Expand Down Expand Up @@ -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 )
Expand All @@ -648,41 +648,41 @@ 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*/
if( code[0] == 'r' )
{
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;
}
}
}
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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()
);
}
Expand Down
40 changes: 20 additions & 20 deletions BH/Modules/Item/ItemDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions BH/Modules/ItemMover/ItemMover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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" : ""
);
}
}
Expand Down
44 changes: 22 additions & 22 deletions BH/Modules/Maphack/Maphack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -665,7 +665,7 @@ void Maphack::OnAutomapDraw() {
return;
for (list<LevelList*>::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));
Expand Down Expand Up @@ -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;
// }
Expand Down
Loading

0 comments on commit 7d26e36

Please sign in to comment.