diff --git a/src/Offsets.h b/src/Offsets.h index 5b9bf33b..806d7bee 100644 --- a/src/Offsets.h +++ b/src/Offsets.h @@ -5804,6 +5804,12 @@ enum Offsets { // FriendList::IsFriend — `bool __thiscall(socialSingleton, uint64_t guid)` // (RET 8): true when one of the 50 slots holds the GUID. FUN_FRIEND_LIST_IS_FRIEND = 0x005AE810, + // FriendList::IsIgnored — `bool __thiscall(socialSingleton, uint64_t guid)` + // (RET 8): false for guid 0, else true when any of the 25 ignore slots at + // +0x650 holds the GUID. Scans all 25 (no stop at a zero slot): removing + // an ignore (0x005AF650) zeroes its slot and only re-sorts when no ignore + // name lookup is pending (+0x718 == 0), so the list can have holes. + FUN_FRIEND_LIST_IS_IGNORED = 0x005AE5A0, // SMSG_WHO opcode handler — opcode 0x63 (99) per the registration // in `FUN_005adc50`: `FUN_005ab650(99, FUN_005adf60, 0)`. Reads diff --git a/src/friendlist/FriendList.h b/src/friendlist/FriendList.h index 2c65829e..aadeae96 100644 --- a/src/friendlist/FriendList.h +++ b/src/friendlist/FriendList.h @@ -25,11 +25,13 @@ // (FUN_005AD060), and the count walker FUN_005AE490. // // The ignore list lives in the same singleton: a flat array of u64 GUIDs at -// `+0x650`, stride 8, up to 25 entries, terminated by the first zero GUID. -// Vanilla ignores are GUID-keyed, not name-keyed — GetIgnoreName (0x005AD460) -// reads the GUID via FUN_005AE570 (`social + 0x650 + index*8`) and resolves it -// to a name through the NameCache, and GetNumIgnores (0x005AD400 → the count -// walker FUN_005AE550) stops at the first zero GUID and caps at 25. +// `+0x650`, stride 8, up to 25 entries. Vanilla ignores are GUID-keyed, not +// name-keyed — GetIgnoreName (0x005AD460) reads the GUID via FUN_005AE570 +// (`social + 0x650 + index*8`) and resolves it to a name through the +// NameCache. GetNumIgnores (0x005AD400 → FUN_005AE550) stops at the first zero +// GUID, but the array is NOT always contiguous: removing an ignore zeroes its +// slot and re-sorts only when no ignore name lookup is pending, so membership +// checks must scan all 25 slots (as the engine's IsIgnored, 0x005AE5A0, does). namespace FriendList { @@ -139,20 +141,16 @@ inline uint64_t IgnoreGuidByIndex(int index) { social + OFF_IGNORE_LIST + index * IGNORE_ENTRY_STRIDE); } -// True if `guid` is on the ignore list. Walks the GUID array, stopping at the -// first zero entry (the list is contiguous — same terminate-on-zero contract -// GetNumIgnores relies on). +// True if `guid` is on the ignore list — the engine's own FriendList::IsIgnored, +// which scans all 25 slots because the list can hold zero-GUID holes. inline bool IsGuidIgnored(uint64_t guid) { - if (guid == 0) + const uint8_t *social = Social(); + if (social == nullptr || guid == 0) return false; - for (int i = 0; i < MAX_IGNORES; ++i) { - const uint64_t entry = IgnoreGuidByIndex(i); - if (entry == 0) - break; - if (entry == guid) - return true; - } - return false; + using IsIgnoredFn = bool(__fastcall *)(const void *social, void *edx, uint64_t guid); + auto fn = reinterpret_cast( + static_cast(Offsets::FUN_FRIEND_LIST_IS_IGNORED)); + return fn(social, nullptr, guid); } } // namespace FriendList diff --git a/src/friendlist/GetFriendInfo.cpp b/src/friendlist/GetFriendInfo.cpp index 02a1634e..e44bd988 100644 --- a/src/friendlist/GetFriendInfo.cpp +++ b/src/friendlist/GetFriendInfo.cpp @@ -78,8 +78,11 @@ void PushFriendInfo(void *L, const uint8_t *entry) { } if (const char *note = Notes::Get(guid)) // client-side note (see Notes.h) Game::Lua::SetFieldString(L, "notes", note); - Game::Lua::SetFieldBool(L, "afk", (status & FRIEND_STATUS_AFK) != 0); - Game::Lua::SetFieldBool(L, "dnd", (status & FRIEND_STATUS_DND) != 0); + // A logoff (SMSG_FRIEND_STATUS result 3 → SetFriendStatus, 0x005AEB30) + // clears only the online byte and leaves the status byte, so gate on + // `connected` — as the engine's GetFriendInfo does for its status text. + Game::Lua::SetFieldBool(L, "afk", connected && (status & FRIEND_STATUS_AFK) != 0); + Game::Lua::SetFieldBool(L, "dnd", connected && (status & FRIEND_STATUS_DND) != 0); Game::Lua::SetFieldBool(L, "mobile", false); Game::Lua::SetFieldBool(L, "referAFriend", false); Game::Lua::SetFieldNumber(L, "rafLinkType", 0); diff --git a/src/friendlist/IsFriend.cpp b/src/friendlist/IsFriend.cpp index f529ffde..91e90dda 100644 --- a/src/friendlist/IsFriend.cpp +++ b/src/friendlist/IsFriend.cpp @@ -13,48 +13,21 @@ // `C_FriendList.IsFriend(guid)` — is the given player on the friends list? // -// Matches the input GUID against each friend entry's GUID (+0x08) — the same -// GUID `SMSG_FRIEND_LIST` populates for online AND offline friends — and also -// falls back to a name compare (resolving the GUID through the NameCache) so -// the answer holds even if a build stores the GUID differently. As a -// ClassicAPI convenience the arg may also be a bare character name, since -// vanilla's friends list is fundamentally name-keyed (AddFriend(name)). See -// `FriendList.h` for the entry layout. +// A GUID goes to the engine's own FriendList::IsFriend (`IsGuidFriend`). The +// friend list keeps the GUID at +0x08 for online AND offline friends, so no +// name fallback is needed for GUID input. As a ClassicAPI convenience the arg +// may also be a bare character name, since vanilla's friends list is +// fundamentally name-keyed (AddFriend(name)). See `FriendList.h`. #include "FriendList.h" #include "Game.h" #include "guid/Guid.h" -#include "unit/Identity.h" #include -#include namespace FriendList::IsFriend { -namespace { - -bool IsFriendByGuidOrName(uint64_t guid, const char *name) { - const int count = FriendList::Count(); - for (int i = 0; i < count; ++i) { - const uint8_t *entry = FriendList::EntryByIndex(i); - if (entry == nullptr) - break; - if (guid != 0 && - *reinterpret_cast(entry + FriendList::OFF_FRIEND_GUID) == guid) - return true; - if (name != nullptr) { - const char *fname = *reinterpret_cast( - entry + FriendList::OFF_FRIEND_NAME); - if (fname != nullptr && _stricmp(fname, name) == 0) - return true; - } - } - return false; -} - -} // namespace - int __fastcall Script_IsFriend(void *L) { const char *arg = Game::Lua::IsString(L, 1) ? Game::Lua::ToString(L, 1) : nullptr; if (arg == nullptr || *arg == '\0') { @@ -63,13 +36,10 @@ int __fastcall Script_IsFriend(void *L) { } uint64_t guid = 0; - const char *name = nullptr; - if (Guid::Parse(arg, &guid) && guid != 0) - name = Unit::Identity::NameForGuid(guid); // GUID input → name for the fallback compare - else - name = arg; // not a GUID → treat the string as a character name + if (!Guid::Parse(arg, &guid) || guid == 0) + guid = FriendList::GuidForName(arg); // not a GUID → treat it as a character name - Game::Lua::PushBool(L, IsFriendByGuidOrName(guid, name)); + Game::Lua::PushBool(L, FriendList::IsGuidFriend(guid)); return 1; } diff --git a/src/friendlist/IsIgnored.cpp b/src/friendlist/IsIgnored.cpp index 831f86cf..8f070bae 100644 --- a/src/friendlist/IsIgnored.cpp +++ b/src/friendlist/IsIgnored.cpp @@ -37,12 +37,13 @@ namespace FriendList::IsIgnored { namespace { // True if any ignored GUID matches `guid`, or (when `name` is given) resolves -// to `name`. Single walk of the GUID array. +// to `name`. Single walk of all 25 slots, skipping zero holes (see +// `FriendList.h` — the array is not always contiguous). bool IgnoredByGuidOrName(uint64_t guid, const char *name) { for (int i = 0; i < FriendList::MAX_IGNORES; ++i) { const uint64_t entry = FriendList::IgnoreGuidByIndex(i); if (entry == 0) - break; // contiguous list — first zero is the end + continue; if (guid != 0 && entry == guid) return true; if (name != nullptr) { diff --git a/src/friendlist/Who.cpp b/src/friendlist/Who.cpp index 97afd1be..6669ab4a 100644 --- a/src/friendlist/Who.cpp +++ b/src/friendlist/Who.cpp @@ -39,12 +39,11 @@ #include "Game.h" #include "Offsets.h" +#include "time/Clock.h" #include #include -#include - namespace FriendList::Who { namespace { @@ -53,16 +52,16 @@ namespace { // silent-dropped. We mirror that on the client to avoid wasting // queries that won't get a response, and to give addons a clean // "did my query get sent?" signal via the bool return. -constexpr DWORD kCooldownMs = 5000; +constexpr uint32_t kCooldownMs = 5000; // Lost-response safety net. If a query's SMSG_WHO somehow never // arrives (network blip, server drop), `g_inFlight` would otherwise // stay positive forever and we'd never restore the routing flag. // On every new send we check this window first and force-reset if // the last send is older than this and the counter's still up. -constexpr DWORD kPendingWindowMs = 10000; +constexpr uint32_t kPendingWindowMs = 10000; -DWORD g_lastSendTick = 0; +uint32_t g_lastSendTick = 0; bool g_haveSent = false; // Count of /who queries we've initiated whose SMSG_WHO response we @@ -80,8 +79,7 @@ bool g_flagOverridden = false; bool OnCooldown() { if (!g_haveSent) return false; - const DWORD now = GetTickCount(); - return (now - g_lastSendTick) < kCooldownMs; + return Time::Clock::Elapsed(g_lastSendTick) < kCooldownMs; } void RestoreFlagIfOwned() { @@ -103,7 +101,7 @@ void ResetIfStuck() { return; if (!g_haveSent) return; - if ((GetTickCount() - g_lastSendTick) < kPendingWindowMs) + if (Time::Clock::Elapsed(g_lastSendTick) < kPendingWindowMs) return; g_inFlight = 0; RestoreFlagIfOwned(); @@ -253,7 +251,7 @@ int __fastcall Script_C_FriendList_SendWhoQueryByName(void *L) { Game::Lua::PushBoolean(L, 0); return 1; } - g_lastSendTick = GetTickCount(); + g_lastSendTick = Time::Clock::NowMs(); g_haveSent = true; g_inFlight++; Game::Lua::PushBoolean(L, 1);