Skip to content

Commit

Permalink
Merge pull request #44 from youbetterdont/feature/caching-with-party-fix
Browse files Browse the repository at this point in the history
Improve party organization with auto-party
  • Loading branch information
planqi authored Mar 18, 2020
2 parents 8c76a28 + 31afe8b commit 9155473
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 22 deletions.
2 changes: 1 addition & 1 deletion BH/Constants.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#define BH_VERSION "BH 1.9.7"
#define BH_VERSION "BH 1.9.8alpha5"

#define CODE_PAGE 1252 // windows-1252 ANSI Latin 1; Western European (Windows)

Expand Down
10 changes: 10 additions & 0 deletions BH/Modules/Item/ItemDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,16 @@ namespace ItemDisplay {
}

void UninitializeItemRules() {
// RuleList contains every created rule. MapRuleList and IgnoreRuleList have a subset of rules.
// Deleting objects in RuleList is sufficient.
if (item_display_initialized) {
for (Rule *r : RuleList) {
for (Condition *condition : r->conditions) {
delete condition;
}
delete r;
}
}
item_display_initialized = false;
item_name_cache.ResetCache();
map_action_cache.ResetCache();
Expand Down
96 changes: 76 additions & 20 deletions BH/Modules/Party/Party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ void Party::OnLoad() {
LootHook->SetActive(0);
}

void Party::OnGameJoin() {
}

void Party::OnUnload() {

}
Expand Down Expand Up @@ -47,31 +50,50 @@ void Party::OnLoop() {

void Party::CheckParty() {
if(c == 0) {
bool valid = true;
std::map<std::string, bool> CurrentParty;
UnitAny* Me = *p_D2CLIENT_PlayerUnit;
RosterUnit* MyRoster = FindPlayerRoster(Me->dwUnitId);
BnetData* pData = (*p_D2LAUNCH_BnData);

for(RosterUnit* Party = (*p_D2CLIENT_PlayerUnitList);Party;Party = Party->pNext) {
WORD current_min_party_id = 0xFFFF;

// first pass: check that the data is sane
RosterUnit *Party = *p_D2CLIENT_PlayerUnitList; if (!Party) return;
do {
if(!_stricmp(Party->szName, MyRoster->szName))
continue;
if(!Party->wLevel || !Party) {
if(!Party->wLevel) {
//PrintText(1, "!Party->wLevel");
c++;
return;
}
if ((Party->wPartyId == INVALID_PARTY_ID && Party->dwPartyFlags & PARTY_IN_PARTY) ||
(Party->wPartyId != INVALID_PARTY_ID && Party->dwPartyFlags & PARTY_NOT_IN_PARTY)) {
// Avoid crashing when multiple players in a game have auto-party enabled
// (there seems to be a brief window in which the party data can be invalid)
valid = false;
continue;
c++; return;
}
} while (Party = Party->pNext);

// second pass: gather some info
Party = *p_D2CLIENT_PlayerUnitList; if (!Party) return;
do {
if(!_stricmp(Party->szName, MyRoster->szName))
continue;
current_min_party_id = min(Party->wPartyId, current_min_party_id);
} while (Party=Party->pNext);

// third pass: do stuff
Party = *p_D2CLIENT_PlayerUnitList; if (!Party) return;
do {
if(!_stricmp(Party->szName, MyRoster->szName))
continue;
if (pData && pData->nCharFlags & PLAYER_TYPE_HARDCORE) {
CurrentParty[Party->szName] = true;
if (Toggles["LootEnabled"].state) {
string s(Party->szName);
if (LootingPermission.find(s) == LootingPermission.end()) {
//PrintText(1, "Enabling loot for %s.", s.c_str());
BYTE PacketData[7] = {0x5d,1,1,0,0,0,0};
*reinterpret_cast<int*>(PacketData + 3) = Party->dwUnitId;
D2NET_SendPacket(7, 1, PacketData);
Expand All @@ -80,28 +102,62 @@ void Party::CheckParty() {
}
}
if ((Party->wPartyId == INVALID_PARTY_ID || Party->wPartyId != MyRoster->wPartyId) && Toggles["Enabled"].state) {
//PrintText(1, "Party->wPartyID=%hu, MyRoster->wPartyId=%hu, min_party_id=%hu",
// Party->wPartyId, MyRoster->wPartyId, current_min_party_id);
if(Party->dwPartyFlags & PARTY_INVITED_YOU) {
D2CLIENT_ClickParty(Party, 2);
c++;
return;
if (current_min_party_id != INVALID_PARTY_ID) {
if (Party->wPartyId == current_min_party_id) {
//PrintText(1, "Found the right party");
D2CLIENT_ClickParty(Party, 2);
c++;
return;
}
} else {
//PrintText(1, "PARTY_INVITED_YOU, clicking party");
D2CLIENT_ClickParty(Party, 2);
c++;
return;
}
}
if(Party->wPartyId == INVALID_PARTY_ID) {
if(Party->dwPartyFlags & PARTY_INVITED_BY_YOU)
//PrintText(1, "INVALID_PARTY_ID");
if(Party->dwPartyFlags & PARTY_INVITED_BY_YOU) {
//PrintText(1, "PARTY_INVITED_BY_YOU");
continue;
D2CLIENT_ClickParty(Party, 2);
c++;
return;
}
if (current_min_party_id != INVALID_PARTY_ID) {
if (MyRoster->wPartyId == current_min_party_id) {
//PrintText(1, "I'm in the right party, inviting another.");
D2CLIENT_ClickParty(Party, 2);
c++;
return;
}
} else {
//PrintText(1, "There's no master party, trying to form one.");
D2CLIENT_ClickParty(Party, 2);
c++;
return;
}
}
}
}

if (valid) {
for (auto it = LootingPermission.cbegin(); it != LootingPermission.cend(); ) {
if (CurrentParty.find((*it).first) == CurrentParty.end()) {
LootingPermission.erase(it++);
} else {
++it;
}
} while (Party = Party->pNext);
// Leave the party if we're in the wrong one
if (Toggles["Enabled"].state && current_min_party_id != INVALID_PARTY_ID
&& MyRoster->wPartyId != current_min_party_id && MyRoster->wPartyId != INVALID_PARTY_ID) {
//PrintText(1, "Not in the right party!");
//PrintText(1, "min_party_id=%hu, MyRoster->wPartyId=%hu", current_min_party_id, MyRoster->wPartyId);
D2CLIENT_LeaveParty();
c++;
return;
}
// Remove looting permissions for players no longer in the game
for (auto it = LootingPermission.cbegin(); it != LootingPermission.cend(); ) {
if (CurrentParty.find((*it).first) == CurrentParty.end()) {
//PrintText(1, "Removing %s from looting map.", ((*it).first).c_str());
LootingPermission.erase(it++);
} else {
++it;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion BH/Modules/Party/Party.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ class Party : public Module {
void OnLoop();
void OnKey(bool up, BYTE key, LPARAM lParam, bool* block);
void OnGameExit();
};
void OnGameJoin();
};

0 comments on commit 9155473

Please sign in to comment.