-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 242322a
Showing
36 changed files
with
7,835 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
vcpkg_installed | ||
Release | ||
Debug | ||
.vs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#include <Windows.h> | ||
#include <map> | ||
#include <fmt/core.h> | ||
#include "Action.h" | ||
#include "D2Structs.h" | ||
#include "D2Ptrs.h" | ||
#include "ItemFilter.h" | ||
|
||
typedef std::wstring(*TokenReplaceFunction)(ItemActionResult* action, Unit* pItem); | ||
|
||
static std::wstring GetItemName(ItemActionResult* action, Unit* pItem) { | ||
if (action->bItemNameSet) { | ||
return action->wsItemName; | ||
} else { | ||
return L"{Name}"; | ||
} | ||
} | ||
|
||
static std::wstring GetItemDesc(ItemActionResult* action, Unit* pItem) { | ||
if (action->bItemDescSet) { | ||
return action->wsItemDesc; | ||
} else { | ||
return L"{Description}"; | ||
} | ||
} | ||
|
||
static std::wstring GetRuneNumber(ItemActionResult* action, Unit* pItem) { | ||
if (!D2COMMON_ITEMS_CheckItemTypeId(pItem, ItemType::RUNE)) { | ||
return L""; | ||
} | ||
ItemsTxt pItemTxt = D2COMMON_ItemDataTbl->pItemsTxt[pItem->dwLineId]; | ||
return std::to_wstring(std::stoi(std::string(&pItemTxt.szCode[1], 3))); | ||
} | ||
|
||
static std::wstring Newline(ItemActionResult* action, Unit* pItem) { | ||
return L"\n"; | ||
} | ||
|
||
static std::wstring GetItemPrice(ItemActionResult* action, Unit* pItem) { | ||
int nPrice = 0; | ||
Unit* pPlayer = D2CLIENT_GetPlayerUnit(); | ||
if (pItem != NULL && pPlayer != NULL) { | ||
nPrice = D2COMMON_ITEMS_GetTransactionCost(pPlayer, pItem, D2CLIENT_GetDifficulty(), D2CLIENT_GetQuestFlags(), 0x201, 1); | ||
} | ||
return std::to_wstring(nPrice); | ||
} | ||
|
||
static std::wstring GetItemSockets(ItemActionResult* action, Unit* pItem) { | ||
return std::to_wstring(D2COMMON_STATLIST_GetUnitStatUnsigned(pItem, Stat::ITEM_NUMSOCKETS, 0)); | ||
} | ||
|
||
void HideAction::SetResult(ItemActionResult* action, Unit* pItem) { | ||
action->bHide = true; | ||
} | ||
|
||
void ShowAction::SetResult(ItemActionResult* action, Unit* pItem) { | ||
action->bHide = false; | ||
} | ||
|
||
void SetStyleAction::SetResult(ItemActionResult* action, Unit* pItem) { | ||
if (STYLES.contains(m_Value)) { | ||
for (auto act : STYLES[m_Value]) { | ||
act->SetResult(action, pItem); | ||
} | ||
} | ||
} | ||
|
||
void SetNameAction::SetResult(ItemActionResult* action, Unit* pItem) { | ||
std::map<std::wstring, TokenReplaceFunction> TOKEN_REPLACEMENT_FUNCTIONS = { | ||
{ L"{Name}", &GetItemName }, | ||
{ L"{Sockets}", &GetItemSockets }, | ||
{ L"{Price}", &GetItemPrice }, | ||
{ L"{Rune Number}", &GetRuneNumber }, | ||
{ L"{Newline}", &Newline } | ||
}; | ||
//we got here from a CONTINUE | ||
std::wstring result = m_Value; | ||
for (const auto& token : TOKEN_REPLACEMENT_FUNCTIONS) { | ||
replace(result, token.first, token.second(action, pItem)); | ||
} | ||
action->wsItemName = result; | ||
action->bItemNameSet = true; | ||
} | ||
|
||
void SetDescriptionAction::SetResult(ItemActionResult* action, Unit* pItem) { | ||
std::map<std::wstring, TokenReplaceFunction> TOKEN_REPLACEMENT_FUNCTIONS = { | ||
{ L"{Description}", &GetItemDesc }, | ||
{ L"{Sockets}", &GetItemSockets }, | ||
{ L"{Price}", &GetItemPrice }, | ||
{ L"{Rune Number}", &GetRuneNumber }, | ||
{ L"{Newline}", &Newline } | ||
}; | ||
//we got here from a CONTINUE | ||
std::wstring result = m_Value; | ||
for (const auto& token : TOKEN_REPLACEMENT_FUNCTIONS) { | ||
replace(result, token.first, token.second(action, pItem)); | ||
} | ||
action->wsItemDesc = result; | ||
action->bItemDescSet = true; | ||
} | ||
|
||
void SetBackgroundColorAction::SetResult(ItemActionResult* action, Unit* pItem) { | ||
action->bBackgroundPaletteIndexSet = true; | ||
action->nBackgroundPaletteIndex = m_PaletteIndex; | ||
} | ||
|
||
void SetInventoryColorAction::SetResult(ItemActionResult* action, Unit* pItem) { | ||
action->bInvBackgroundPaletteIndexSet = true; | ||
action->nInvBackgroundPaletteIndex = m_PaletteIndex; | ||
} | ||
|
||
void SetBorderColorAction::SetResult(ItemActionResult* action, Unit* pItem) { | ||
action->bBorderPaletteIndexSet = true; | ||
action->nBorderPaletteIndex = m_PaletteIndex; | ||
} | ||
|
||
void ChatNotifyAction::SetResult(ItemActionResult* action, Unit* pItem) { | ||
action->bChatAlert = true; | ||
} | ||
|
||
void PlayAlertAction::SetResult(ItemActionResult* action, Unit* pItem) { | ||
} | ||
|
||
void MinimapIconAction::SetResult(ItemActionResult* action, Unit* pItem) { | ||
action->bMinimapIcon = true; | ||
action->nMinimapIconPaletteIndex = m_PaletteIndex; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
#pragma once | ||
|
||
#include <Windows.h> | ||
#include <map> | ||
#include <string> | ||
#include "Utils.h" | ||
#include "D2Structs.h" | ||
|
||
|
||
struct ItemActionResult { | ||
std::vector<uint32_t> vMatchedRules; | ||
|
||
bool bHide = false; | ||
|
||
bool bBackgroundPaletteIndexSet = false; | ||
uint8_t nBackgroundPaletteIndex = 0; | ||
DrawMode eDrawModeAlt = DrawMode::TRANS_25; | ||
DrawMode eDrawModeHover = DrawMode::TRANS_50; | ||
|
||
bool bBorderPaletteIndexSet = false; | ||
uint8_t nBorderPaletteIndex = 0; | ||
|
||
bool bInvBackgroundPaletteIndexSet = false; | ||
uint8_t nInvBackgroundPaletteIndex = 0; | ||
|
||
bool bChatAlert = false; | ||
|
||
bool bItemNameSet = false; | ||
std::wstring wsItemName = L""; | ||
|
||
bool bItemDescSet = false; | ||
std::wstring wsItemDesc = L""; | ||
|
||
bool bMinimapIcon = false; | ||
uint8_t nMinimapIconPaletteIndex = 0; | ||
}; | ||
|
||
|
||
|
||
class Action { | ||
protected: | ||
std::wstring m_Value; | ||
public: | ||
Action(std::wstring value) : m_Value(value) {}; | ||
~Action() {}; | ||
virtual void SetResult(ItemActionResult* action, Unit* pItem) = 0; | ||
}; | ||
|
||
class HideAction : public Action { | ||
public: | ||
HideAction() : Action(L"") {} | ||
void SetResult(ItemActionResult* action, Unit* pItem); | ||
}; | ||
|
||
class ShowAction : public Action { | ||
public: | ||
ShowAction() : Action(L"") {} | ||
void SetResult(ItemActionResult* action, Unit* pItem); | ||
}; | ||
|
||
class ColorTextAction : public Action { | ||
public: | ||
ColorTextAction(std::wstring value) : Action(value) { | ||
std::map<std::wstring, std::wstring> COLOR_TO_PALETTE_IDX = { | ||
{ L"{White}", TEXT_WHITE }, | ||
{ L"{Red}", TEXT_RED }, | ||
{ L"{Green}", TEXT_GREEN }, | ||
{ L"{Blue}", TEXT_BLUE }, | ||
{ L"{Gold}", TEXT_GOLD }, | ||
{ L"{Gray}", TEXT_GRAY }, | ||
{ L"{Black}", TEXT_BLACK }, | ||
{ L"{Tan}", TEXT_TAN }, | ||
{ L"{Orange}", TEXT_ORANGE }, | ||
{ L"{Yellow}", TEXT_YELLOW }, | ||
{ L"{Purple}", TEXT_PURPLE }, | ||
{ L"{Dark Green}", TEXT_DARK_GREEN }, | ||
//Glide Only | ||
{ L"{Coral}", TEXT_CORAL }, | ||
{ L"{Sage}", TEXT_SAGE }, | ||
{ L"{Teal}", TEXT_TEAL }, | ||
{ L"{Light Gray}", TEXT_LIGHT_GRAY } | ||
}; | ||
for (auto const& color : COLOR_TO_PALETTE_IDX) { | ||
replace(m_Value, color.first, color.second); | ||
} | ||
} | ||
virtual void SetResult(ItemActionResult* action, Unit* pItem) = 0; | ||
}; | ||
|
||
class PaletteIndexAction : public Action { | ||
protected: | ||
uint8_t m_PaletteIndex = 0; | ||
public: | ||
PaletteIndexAction(std::wstring value) : Action(value) { | ||
std::map<std::wstring, uint8_t> COLOR_TO_PALETTE_IDX = { | ||
{ L"White", 0x20 }, | ||
{ L"Red", 0x0A }, | ||
{ L"Green", 0x84 }, | ||
{ L"Blue", 0x97 }, | ||
{ L"Gold", 0x0D }, | ||
{ L"Gray", 0xD0 }, | ||
{ L"Black", 0x00 }, | ||
{ L"Tan", 0x5A }, | ||
{ L"Orange", 0x60 }, | ||
{ L"Yellow", 0x0C }, | ||
{ L"Purple", 0x9B }, | ||
{ L"Dark Green", 0x76 }, | ||
{ L"Coral", 0x66 }, | ||
{ L"Sage", 0x82 }, | ||
{ L"Teal", 0xCB }, | ||
{ L"Light Gray", 0xD6 } | ||
}; | ||
if (COLOR_TO_PALETTE_IDX.contains(value)) { | ||
m_PaletteIndex = COLOR_TO_PALETTE_IDX[value]; | ||
} | ||
else { | ||
m_PaletteIndex = static_cast<uint8_t>(std::stoi(value, nullptr, 16)); | ||
} | ||
} | ||
virtual void SetResult(ItemActionResult* action, Unit* pItem) = 0; | ||
}; | ||
|
||
class SetStyleAction : public Action { | ||
public: | ||
SetStyleAction(std::wstring value) : Action(value) { } | ||
void SetResult(ItemActionResult* action, Unit* pItem); | ||
}; | ||
|
||
class SetNameAction : public ColorTextAction { | ||
public: | ||
SetNameAction(std::wstring value) : ColorTextAction(value) { } | ||
void SetResult(ItemActionResult* action, Unit* pItem); | ||
}; | ||
|
||
class SetDescriptionAction : public ColorTextAction { | ||
public: | ||
SetDescriptionAction(std::wstring value) : ColorTextAction(value) {} | ||
void SetResult(ItemActionResult* action, Unit* pItem); | ||
}; | ||
|
||
class SetBackgroundColorAction : public PaletteIndexAction { | ||
public: | ||
SetBackgroundColorAction(std::wstring value) : PaletteIndexAction(value) {} | ||
void SetResult(ItemActionResult* action, Unit* pItem); | ||
}; | ||
|
||
class SetInventoryColorAction : public PaletteIndexAction { | ||
public: | ||
SetInventoryColorAction(std::wstring value) : PaletteIndexAction(value) {} | ||
void SetResult(ItemActionResult* action, Unit* pItem); | ||
}; | ||
|
||
class SetBorderColorAction : public PaletteIndexAction { | ||
public: | ||
SetBorderColorAction(std::wstring value) : PaletteIndexAction(value) {} | ||
void SetResult(ItemActionResult* action, Unit* pItem); | ||
}; | ||
|
||
class ChatNotifyAction : public Action { | ||
public: | ||
ChatNotifyAction(std::wstring value) : Action(value) {} | ||
void SetResult(ItemActionResult* action, Unit* pItem); | ||
}; | ||
|
||
class PlayAlertAction : public Action { | ||
public: | ||
PlayAlertAction(std::wstring value) : Action(value) {} | ||
void SetResult(ItemActionResult* action, Unit* pItem); | ||
}; | ||
|
||
class MinimapIconAction : public PaletteIndexAction { | ||
public: | ||
MinimapIconAction(std::wstring value) : PaletteIndexAction(value) {} | ||
void SetResult(ItemActionResult* action, Unit* pItem); | ||
}; |
Oops, something went wrong.