Skip to content

Commit

Permalink
add ilvl, weight filter, fix shifts stats + ED, add github action
Browse files Browse the repository at this point in the history
  • Loading branch information
dschu012 committed Jun 21, 2024
1 parent 30e4c60 commit ce5ca0f
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 19 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build-branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build Branch

on:
workflow_dispatch:
push:
branches:
- master

jobs:
build:
runs-on: windows-latest
steps:
- name: Setup MSBuild.exe
uses: microsoft/[email protected]
- uses: actions/checkout@master
- name: MSBuild
run: msbuild /t:d2lootfilter:Rebuild /p:Configuration=Release /p:CustomDefinitions=`"SHA=\`"($env:GITHUB_SHA.substring(0,7))\`"`" /property:Platform=x86 d2lootfilter.sln
- name: Release
uses: marvinpinto/[email protected]
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: true
title: "Latest Development Build"
files: Release/d2lootfilter.dll
18 changes: 18 additions & 0 deletions Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ static std::wstring GetItemDesc(ActionResult& action, Unit* pItem) {
}
}

static std::wstring GetItemLevel(ActionResult& action, Unit* pItem) {
return std::to_wstring(pItem->pItemData->dwItemLevel);
}

static std::wstring GetPotionNumber(ActionResult& action, Unit* pItem) {
if(D2COMMON_ITEMS_CheckItemTypeId(pItem, ItemType::HEALING_POTION)
|| D2COMMON_ITEMS_CheckItemTypeId(pItem, ItemType::MANA_POTION)) {
Expand Down Expand Up @@ -152,6 +156,7 @@ void SetNameAction::SetResult(ActionResult& action, Unit* pItem) const {
{ L"{Name}", &GetItemName },
{ L"{Sockets}", &GetItemSockets },
{ L"{Price}", &GetItemPrice },
{ L"{Item Level}", &GetItemLevel },
{ L"{Rune Number}", &GetRuneNumber },
{ L"{Potion Number}", &GetPotionNumber },
{ L"{Newline}", &Newline }
Expand All @@ -170,6 +175,7 @@ void SetDescriptionAction::SetResult(ActionResult& action, Unit* pItem) const {
{ L"{Description}", &GetItemDesc },
{ L"{Sockets}", &GetItemSockets },
{ L"{Price}", &GetItemPrice },
{ L"{Item Level}", &GetItemLevel },
{ L"{Rune Number}", &GetRuneNumber },
{ L"{Newline}", &Newline }
};
Expand Down Expand Up @@ -211,4 +217,16 @@ void PlayAlertAction::SetResult(ActionResult& action, Unit* pItem) const {
void MinimapIconAction::SetResult(ActionResult& action, Unit* pItem) const {
action.bMinimapIcon = true;
action.nMinimapIconPaletteIndex = m_PaletteIndex;
}

void WeightAction::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
for (auto stat : CustomStats) {
replace(m_Value, stat.first, stat.second);
}
m_Expression = Parser::Parse(m_Value.c_str());
m_Expression->SetVariables(variables);
}

void WeightAction::SetResult(ActionResult& action, Unit* pItem) const {
action.nWeight += m_Expression->Evaluate(pItem);
}
18 changes: 17 additions & 1 deletion Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ struct ActionResult {

bool bMinimapIcon = false;
uint8_t nMinimapIconPaletteIndex = 0;

int32_t nWeight = 0;
};


enum class ActionType : uint8_t {
NONE, SHOW, HIDE, CONTINUE, SET_STYLE, SET_NAME,
SET_DESCRIPTION, SET_BG_COLOR, SET_INVENTORY_COLOR,
SET_BORDER_COLOR, CHAT_NOTIFY, PLAY_ALERT, MINIMAP_ICON
SET_BORDER_COLOR, CHAT_NOTIFY, PLAY_ALERT, MINIMAP_ICON,
WEIGHT
};

class Action {
Expand All @@ -51,6 +54,7 @@ class Action {
Action(std::wstring_view value = {}, ActionType type = ActionType::NONE) : m_Value(value), m_Type(type) {};
virtual ~Action() = default;
ActionType GetType() const { return m_Type; }
virtual void Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {};
virtual void SetResult(ActionResult& action, Unit* pItem) const = 0;
};

Expand Down Expand Up @@ -166,6 +170,17 @@ class MinimapIconAction : public PaletteIndexAction {
static std::unique_ptr<Action> MakeInstance(std::wstring_view value = {}) { return std::make_unique<MinimapIconAction>(value); }
};

class WeightAction : public Action {
protected:
std::unique_ptr<Expression> m_Expression;
public:
WeightAction(std::wstring_view value = L"") : Action(value, ActionType::WEIGHT) {};
void Initialize(const utility::string_umap<std::wstring, int32_t>& variables) override;
void SetResult(ActionResult& action, Unit* pItem) const override;

static std::unique_ptr<Action> MakeInstance(std::wstring_view value = {}) { return std::make_unique<WeightAction>(value); }
};

class ActionFactory {
public:
static std::unique_ptr<Action> MakeInstance(std::wstring_view action, std::wstring_view value = {}) {
Expand All @@ -180,6 +195,7 @@ class ActionFactory {
{ L"ChatNotify", ChatNotifyAction::MakeInstance },
{ L"PlayAlert", PlayAlertAction::MakeInstance },
{ L"MinimapIcon", MinimapIconAction::MakeInstance },
{ L"Weight", WeightAction::MakeInstance },
};

if (auto search = lookup.find(action); search != lookup.end()) {
Expand Down
11 changes: 11 additions & 0 deletions Condition.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Condition.h"
#include "Utils.h"
#include "Globals.h"
#include <algorithm>

bool CodeCondition::Evaluate(Unit* pItem) {
Expand Down Expand Up @@ -358,3 +359,13 @@ void OwnedCondition::Initialize(const utility::string_umap<std::wstring, int32_t
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
};

bool HasWeightCondition::Evaluate(Unit* pItem) {
m_Left.SetValue(ITEM_ACTIONS[pItem->dwUnitId].nWeight);
return m_Expression->Evaluate(pItem);
}

void HasWeightCondition::Initialize(const utility::string_umap<std::wstring, int32_t>& variables) {
m_Expression = Parser::Parse(m_Value.c_str(), &m_Left);
m_Expression->SetVariables(variables);
}
21 changes: 18 additions & 3 deletions Condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ enum class ConditionType : uint8_t {
NONE, CODE, TYPE, PLAYERCLASS, CLASS, RARITY, ETHEREAL, RUNEWORD, PREFIX, SUFFIX,
ITEM_LEVEL, QUALITY, AREA_LEVEL, CHARACTER_LEVEL, DIFFICULTY,
RUNE, ID, GOLD, STATS, DEFENSE, ARMOR, WEAPON, PRICE, MODE,
IDENTIFIED, SOCKETS, WIDTH, HEIGHT, RANDOM, OWNED
IDENTIFIED, SOCKETS, WIDTH, HEIGHT, RANDOM, OWNED,
HASWEIGHT
};

static const wchar_t* CONDITIONS[] = { L"", L"Code", L"Type", L"PlayerClass", L"Class", L"Rarity", L"Ethereal", L"Runeword", L"Prefix", L"Suffix", L"ItemLevel", L"Quality", L"AreaLevel", L"CharacterLevel",
L"Difficulty", L"Rune", L"Id", L"Gold", L"Stats", L"Defense", L"Armor", L"Weapon", L"Price", L"Mode", L"Identified", L"Sockets", L"Width", L"Height", L"Random", L"Owned" };
L"Difficulty", L"Rune", L"Id", L"Gold", L"Stats", L"Defense", L"Armor", L"Weapon", L"Price", L"Mode", L"Identified", L"Sockets", L"Width", L"Height", L"Random", L"Owned", L"HasWeight" };

class Condition {
protected:
Expand Down Expand Up @@ -407,6 +408,19 @@ class OwnedCondition : public Condition {
static std::unique_ptr<Condition> MakeInstance(std::wstring_view value = {}) { return std::make_unique<OwnedCondition>(value); }
};

class HasWeightCondition : public Condition {
protected:
Variable m_Left;
std::unique_ptr<Expression> m_Expression;
public:
HasWeightCondition(std::wstring_view value = {}) : Condition(value, ConditionType::HASWEIGHT) {};
bool Evaluate(Unit* pItem) override;
void Initialize(const utility::string_umap<std::wstring, int32_t>& variables) override;
std::wstring ToString(Unit* pItem) const override { return std::format(L"{} {}", CONDITIONS[static_cast<uint8_t>(m_Type)], m_Expression->ToString(pItem)); };

static std::unique_ptr<Condition> MakeInstance(std::wstring_view value = {}) { return std::make_unique<HasWeightCondition>(value); }
};

class ConditionFactory {
public:
static std::unique_ptr<Condition> MakeInstance(std::wstring_view condition, std::wstring_view value = {}) {
Expand Down Expand Up @@ -439,7 +453,8 @@ class ConditionFactory {
{ L"Width", WidthCondition::MakeInstance },
{ L"Height", HeightCondition::MakeInstance },
{ L"Random", RandomCondition::MakeInstance },
{ L"Owned", OwnedCondition::MakeInstance }
{ L"Owned", OwnedCondition::MakeInstance },
{ L"HasWeight", HasWeightCondition::MakeInstance },
};

if (auto search = lookup.find(condition); search != lookup.end()) {
Expand Down
24 changes: 24 additions & 0 deletions Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ void Configuration::InitalizeConditionVariables() {
InitializeClass();
InitializeRaritiesAndQualities();
InitializeOther();
InitalizeActionVariables();

/*
for (auto &rule : GlobalRules) {
Expand All @@ -172,6 +173,28 @@ void Configuration::InitalizeConditionVariables() {
*/
}

void Configuration::InitalizeActionVariables() {
utility::string_umap<std::wstring, int32_t> variables;
for (auto& rule : GlobalRules) {
for (auto& action : rule.second.GetActions()) {
switch (action->GetType()) {
default:
action->Initialize(variables);
break;
}
}
}
for (auto& style : GlobalStyles) {
for (auto& action : style.second) {
switch (action->GetType()) {
default:
action->Initialize(variables);
break;
}
}
}
}

void Configuration::InitializeTypesCodesAndRunes() {
static utility::string_umap<std::wstring, int32_t> names;
static utility::string_umap<std::wstring, int32_t> codes;
Expand Down Expand Up @@ -296,6 +319,7 @@ void Configuration::InitializeOther() {
case ConditionType::HEIGHT:
case ConditionType::RANDOM:
case ConditionType::OWNED:
case ConditionType::HASWEIGHT:
condition->Initialize(variables);
break;
default:
Expand Down
1 change: 1 addition & 0 deletions Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Configuration {
void InitializeClass();
void InitializeRaritiesAndQualities();
void InitializeOther();
void InitalizeActionVariables();
public:
friend class ItemFilter;

Expand Down
4 changes: 4 additions & 0 deletions D2Ptrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ FUNCPTR(D2COMMON, AbsScreenToMap, void __stdcall, (long* ptMouseX, long* ptMouse
//1.14d 004B3870 near here.
F2(D2COMMON, ITEMS_GetTransactionCost, int, __stdcall, (Unit* pPlayer, Unit* pItem, uint8_t nDifficulty, BitBuffer* pQuestFlags, int nVendorId, int nTransactionType), -10775 , -10107, 0x22FDC0);
F2(D2COMMON, ITEMS_CheckItemTypeId, BOOL, __stdcall, (Unit* pItem, ItemType nItemType), -10731, -10744, 0x229BB0);

//TODO FIND IN 1.14
F2(D2COMMON, STATLIST_GetStatListFromUnitStateOrFlag, StatListEx*, __stdcall, (const Unit* pUnit, int32_t nState, int32_t nFlag), -10483, -10930, 0);
F2(D2COMMON, STATLIST_GetStatValue, int32_t, __stdcall, (const StatListEx* pStatList, Stat nStatId, uint16_t nLayer), -10466, -10680, 0);
F2(D2COMMON, STATLIST_GetUnitStatUnsigned, uint32_t, __stdcall, (const Unit* pUnit, Stat nStatId, uint16_t nLayer), -10520, -10973, 0x225480);
//todo check 1.14d
F2(D2COMMON, DATATBLS_LoadAllTxts, void, __stdcall, (void* pMemPool, int a2, int a3), -10576, -10943, 0x219300);
Expand Down
18 changes: 17 additions & 1 deletion Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,23 @@ int32_t Call::EvaluateChargedSkill(Unit* pItem, Stat stat, const std::vector<int
int32_t Call::EvaluateStat(Unit* pItem, Stat stat, const std::vector<int32_t>& args) const {
int32_t layer = 0;
if (args.size() > 0) layer = args[0];
return D2COMMON_STATLIST_GetUnitStatUnsigned(pItem, stat, layer);
int32_t value = D2COMMON_STATLIST_GetUnitStatUnsigned(pItem, stat, layer);
if (stat == Stat::ITEM_MAXDAMAGE_PERCENT
|| stat == Stat::ITEM_MINDAMAGE_PERCENT) {
auto pStatList = D2COMMON_STATLIST_GetStatListFromUnitStateOrFlag(pItem, NULL, 0x40);
return D2COMMON_STATLIST_GetStatValue(pStatList, stat, layer);
}
if (stat == Stat::HITPOINTS
|| stat == Stat::MAXHP
|| stat == Stat::MANA
|| stat == Stat::MAXMANA
|| stat == Stat::STAMINA
|| stat == Stat::MAXSTAMINA
|| stat == Stat::ITEM_HP_PERLEVEL
|| stat == Stat::ITEM_MANA_PERLEVEL) {
value = value >> 8;
}
return value;
}

int32_t Call::Evaluate(Unit* pItem) const {
Expand Down
4 changes: 3 additions & 1 deletion Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,6 @@ static std::unordered_map<T, Key> reverse_map(const std::unordered_map<Key, T, H

const std::unordered_map<int32_t, std::wstring> ItemTypesLookup = reverse_map(ItemTypes);
const std::unordered_map<int32_t, std::wstring> RaritiesLookup = reverse_map(Rarities);
const std::unordered_map<int32_t, std::wstring> QualitiesLookup = reverse_map(Qualities);
const std::unordered_map<int32_t, std::wstring> QualitiesLookup = reverse_map(Qualities);

std::unordered_map<uint32_t, ActionResult> ITEM_ACTIONS;
4 changes: 3 additions & 1 deletion Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ extern const std::unordered_map<int32_t, std::wstring> RaritiesLookup;
extern const utility::string_umap<std::wstring, int32_t> Qualities;
extern const std::unordered_map<int32_t, std::wstring> QualitiesLookup;

extern const utility::string_umap<std::wstring, std::wstring> CustomStats;
extern const utility::string_umap<std::wstring, std::wstring> CustomStats;

extern std::unordered_map<uint32_t, ActionResult> ITEM_ACTIONS;
20 changes: 13 additions & 7 deletions ItemFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <queue>

static std::queue<uint32_t> AUTOMAP_ITEMS;
static std::unordered_map<uint32_t, ActionResult> ITEM_ACTIONS;

const char* CMD_RELOAD = "/reload";
const char* CMD_FILTERLEVEL = "/fl";
Expand Down Expand Up @@ -309,11 +308,16 @@ void __stdcall ItemFilter::DrawDebugInfo(Unit* pItem, uint32_t nXStart, uint32_t
std::vector<std::wstring> lines;
std::wostringstream os;
os << L"Matched Lines #: " << TEXT_GREEN;
for (auto& match : actions->vMatchedRules) {
if (&match != &actions->vMatchedRules.front()) {
os << L", ";
if (actions->vMatchedRules.size() > 0) {
for (auto& match : actions->vMatchedRules) {
if (&match != &actions->vMatchedRules.front()) {
os << L", ";
}
os << match;
}
os << match;
}
else {
os << TEXT_RED << L"None";
}
ItemsTxt* pItemTxt = GetItemsTxt(pItem);

Expand Down Expand Up @@ -346,6 +350,8 @@ void __stdcall ItemFilter::DrawDebugInfo(Unit* pItem, uint32_t nXStart, uint32_t
if (actions->bInvBackgroundPaletteIndexSet) {
lines.push_back(std::format(L"Inventory Color: {}{:#04x}", TEXT_WHITE, actions->nInvBackgroundPaletteIndex));
}
lines.push_back(std::format(L"Weight: {}{}", TEXT_WHITE, actions->nWeight));

auto width = 0;
for (auto& line : lines) {
uint32_t w, fileNo;
Expand Down Expand Up @@ -417,8 +423,8 @@ void __stdcall ItemFilter::DrawGroundItemRect(DWORD retAddress, BOOL isHovered,

void __stdcall ItemFilter::DrawInventoryItemRect(Unit* pItem, uint32_t nXStart, uint32_t nYStart, uint32_t nXEnd, uint32_t nYEnd, uint8_t nPaletteIndex, DrawMode eDrawMode) {
//0x08: red, 0xea: blue, 0x76: green.
if (nPaletteIndex == 0xEA
&& HasActions(pItem)) {
if ((nPaletteIndex == 0xEA || nPaletteIndex == 0x8A)
&& HasActions(pItem)) {
nPaletteIndex = ITEM_ACTIONS[pItem->dwUnitId].bInvBackgroundPaletteIndexSet ? ITEM_ACTIONS[pItem->dwUnitId].nInvBackgroundPaletteIndex : nPaletteIndex;
}
//call original
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ The operators are as followed. If no operator is specified `=` is implied.
| Sockets `<Operator> <Number>` | Number of sockets |
| Width `<Operator> <Number>` | Width of item in inventory |
| Height `<Operator> <Number>` | Height of item in inventory |
| Stats `<Expression>` | Expression that evaluates to true or false to filter an item based on stats. More details can be found in [Stats](#Stats) |
| Stats `<Expression>` | Expression that evaluates to true or false to filter an item based on stats. More details can be found in [Stats]
(#Stats) |
| HasWeight `<Expression>` | Expression that evaluates to true or false to filter an item based "Weight" (see Actions) |


### Stats
Expand Down Expand Up @@ -154,6 +156,7 @@ e.x. `Max(Stat(39), Stat(43), Stat(41), Stat(45)) > 0` can be used to filter the
| SetBorderColor `<Value>` | Sets the border color of the item when on the ground. Value is a pallette index color. |
| ChatNotify `<Boolean>` | Notify when the item drops in chat. True or False |
| MinimapIcon `<Value>` | Sets the color of the item on your minimap when on the ground. Value is a pallette index color. |
| Weight `<Expression>` | Add's a "Weight" to an item. Let's you filter items based on combination of stats. (i.e. `Weight "Barbarian +%d to Warcries" * 100` would make a Warcry weapon w/ +3 warcry's have a weight of 300 while a +2 would have 200). All weights are added together and then can be filtered on w/ `HasWeight` |

### Styles

Expand Down
8 changes: 4 additions & 4 deletions d2lootfilter.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand All @@ -52,11 +52,11 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetName>d2lootfilter</TargetName>
<TargetName>BH</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetName>d2lootfilter</TargetName>
<TargetName>BH</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down

0 comments on commit ce5ca0f

Please sign in to comment.