From 98af79137b06e4bcb02dbb2e1cb01c778b8ab54b Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Fri, 4 Sep 2026 20:50:58 -0500 Subject: [PATCH] feat(faction): add C_Reputation.GetFactionDataByID Keys the modern FactionData table by faction ID instead of by displayed-list position. Reuses the shared ReadFactionData chain and table builder, so it needs no new engine work. Unlike GetFactionInfoByID this is not limited to the player's reputation list: an unencountered faction fills cleanly with currentStanding 0 and atWarWith false, so any real faction's name, description and thresholds are readable. --- README.md | 2 +- docs/API.md | 22 ++++++++++++++++++++++ src/faction/Info.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bb1cfe77..11b40b2a 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ reference in **[docs/API.md](docs/API.md)**. | [EquipmentSet](docs/API.md#equipmentset) | `C_EquipmentSet.CanUseEquipmentSets`, `C_EquipmentSet.ClearIgnoredSlotsForSave`, `C_EquipmentSet.CreateEquipmentSet`, `C_EquipmentSet.DeleteEquipmentSet`, `C_EquipmentSet.EquipmentSetContainsLockedItems`, `C_EquipmentSet.GetEquipmentSetID`, `C_EquipmentSet.GetEquipmentSetIDs`, `C_EquipmentSet.GetEquipmentSetInfo`, `C_EquipmentSet.GetIgnoredSlots`, `C_EquipmentSet.GetItemIDs`, `C_EquipmentSet.GetItemLocations`, `C_EquipmentSet.GetNumEquipmentSets`, `C_EquipmentSet.IgnoreSlotForSave`, `C_EquipmentSet.IsSlotIgnoredForSave`, `C_EquipmentSet.ModifyEquipmentSet`, `C_EquipmentSet.SaveEquipmentSet`, `C_EquipmentSet.UnignoreSlotForSave`, `C_EquipmentSet.UseEquipmentSet` | | [Events](docs/API.md#events) | `C_EventUtils.IsEventValid`, `GetFramesRegisteredForEvent` | | [Expansion](docs/API.md#expansion) | `ClassicExpansionAtLeast`, `ClassicExpansionAtMost`, `GetClassicExpansionLevel` | -| [Faction](docs/API.md#faction) | `C_Reputation.GetFactionDataByIndex`, `C_Reputation.GetFactionStandings`, `C_Reputation.GetLastStandingChange`, `C_Reputation.GetWatchedFactionData`, `C_Reputation.SetWatchedFactionByID`, `GetFactionIDByIndex`, `GetFactionInfoByID`, `GetFactionParentID` | +| [Faction](docs/API.md#faction) | `C_Reputation.GetFactionDataByID`, `C_Reputation.GetFactionDataByIndex`, `C_Reputation.GetFactionStandings`, `C_Reputation.GetLastStandingChange`, `C_Reputation.GetWatchedFactionData`, `C_Reputation.SetWatchedFactionByID`, `GetFactionIDByIndex`, `GetFactionInfoByID`, `GetFactionParentID` | | [Focus](docs/API.md#focus) | `ClearFocus`, `FocusUnit` | | [Frame](docs/API.md#frame) | `region:SetPoint("point")` (one-arg form), `region:SetSize`, `region:GetSize`, `region:IsMouseOver`, `region:GetRect`, `region:IsDragging`, `GetMouseFoci`, `frame:SetShown`, `fontstring:GetStringHeight`, `fontstring:GetUnboundedStringWidth`, `fontstring:GetWrappedWidth`, `fontstring:GetNumLines`, `fontstring:GetLineHeight`, `fontstring:IsTruncated`, `fontstring:SetMaxLines`, `fontstring:GetMaxLines`, `fontstring:SetFormattedText`, `texture:SetRotation`, `texture:GetRotation`, `texture:SetVertexOffset`, `texture:GetVertexOffset`, `texture:SetColorTexture`, `texture:SetMask`, `frame:CreateMaskTexture`, `texture:AddMaskTexture`, `texture:RemoveMaskTexture`, `texture:GetNumMaskTextures`, `texture:GetMaskTexture`, `fontstring:SetRotation`, `fontstring:GetRotation`, `editBox:SetCursorPosition`, `editBox:GetCursorPosition`, `editBox:GetUTF8CursorPosition`, `editBox:ClearHighlightText`, `editBox:HasFocus`, `editBox:HasText`, `editBox:SetHighlightColor`, `editBox:GetHighlightColor`, `editBox:ClearHistory`, `frame:SetResizeBounds`, `frame:HookScript`, `frame:IsEventRegistered`, `frame:GetEffectiveAlpha`, `frame:SetAttribute`, `frame:SetAttributeNoHandler`, `frame:ClearAttribute`, `frame:GetAttribute`, `OnAttributeChanged` (script), `SetModernScriptArgs`, `GetModernScriptArgs`, `PreClick` (script), `PostClick` (script), `GetClickFrame` | | [FriendList](docs/API.md#friendlist) | `C_FriendList.GetFriendInfo`, `C_FriendList.GetFriendInfoByIndex`, `C_FriendList.GetNumFriends`, `C_FriendList.GetNumOnlineFriends`, `C_FriendList.GetNumWhoResults`, `C_FriendList.GetWhoInfo`, `C_FriendList.IsFriend`, `C_FriendList.IsIgnored`, `C_FriendList.IsIgnoredByGuid`, `C_FriendList.IsWhoQueryPending`, `C_FriendList.SendWhoQueryByName`, `C_FriendList.SetFriendNotes`, `C_FriendList.SetFriendNotesByIndex` | diff --git a/docs/API.md b/docs/API.md index 2a55fbd9..de333d23 100644 --- a/docs/API.md +++ b/docs/API.md @@ -158,6 +158,7 @@ build instructions. - [`GetFactionParentID(factionID)`](#getfactionparentidfactionid) - [`C_Reputation.GetFactionStandings()`](#c_reputationgetfactionstandings) - [`C_Reputation.GetWatchedFactionData()`](#c_reputationgetwatchedfactiondata) + - [`C_Reputation.GetFactionDataByID(factionID)`](#c_reputationgetfactiondatabyidfactionid) - [`C_Reputation.GetFactionDataByIndex(factionSortIndex)`](#c_reputationgetfactiondatabyindexfactionsortindex) - [`C_Reputation.SetWatchedFactionByID(factionID)`](#c_reputationsetwatchedfactionbyidfactionid) - [`C_Reputation.GetLastStandingChange()`](#c_reputationgetlaststandingchange) @@ -3861,6 +3862,27 @@ Implementation reads the watched `RepListID` from the player's `ReadFactionData` chain (Faction.dbc lookup, reaction band, rep slot flags, header/collapsed checks). +### `C_Reputation.GetFactionDataByID(factionID)` + +Returns a `FactionData` table for a faction by ID, or `nil` when the ID +has no `Faction.dbc` record. + +The table has the same shape as +[`C_Reputation.GetFactionDataByIndex`](#c_reputationgetfactiondatabyindexfactionsortindex) +— see that section for the full field list. + +The faction does not have to be in the player's reputation list. One the +character has never encountered fills cleanly, with `currentStanding` `0` +and `atWarWith` `false`, so you can read any faction's name, description, +and standing thresholds without walking the displayed list. + +```lua +local d = C_Reputation.GetFactionDataByID(69) -- Darnassus +if d then + print(d.name, d.currentStanding, d.nextReactionThreshold) +end +``` + ### `C_Reputation.GetFactionDataByIndex(factionSortIndex)` Returns a `FactionData` table for the faction at the given 1-based diff --git a/src/faction/Info.cpp b/src/faction/Info.cpp index ed70b850..95e3549d 100644 --- a/src/faction/Info.cpp +++ b/src/faction/Info.cpp @@ -407,6 +407,30 @@ static int __fastcall Script_C_Reputation_GetWatchedFactionData(void *L) { return 1; } +// `C_Reputation.GetFactionDataByID(factionID)` — modern table-shaped +// accessor keyed by faction ID rather than by displayed-list position. +// Returns nil when the ID has no `Faction.dbc` record. +// +// Unlike the index form, this doesn't need the faction to be in the +// player's displayed reputation list: `ReadFactionData` fills an +// unencountered faction cleanly (currentStanding 0, not at war), so a +// lookup works for any real faction. +static int __fastcall Script_C_Reputation_GetFactionDataByID(void *L) { + if (!Game::Lua::IsNumber(L, 1)) { + Game::Lua::Error(L, "Usage: C_Reputation.GetFactionDataByID(factionID)"); + return 0; + } + const int factionID = static_cast(Game::Lua::ToNumber(L, 1)); + + FactionData d; + if (!ReadFactionData(factionID, &d)) + return 0; // nil — no such faction + + Game::Lua::SetTop(L, 0); + PushFactionDataTable(L, d); + return 1; +} + // `C_Reputation.GetFactionDataByIndex(factionSortIndex)` — modern // table-shaped accessor over the displayed reputation list. 1-based // index covering the same range as vanilla's `GetFactionInfo(index)` @@ -479,6 +503,8 @@ static void RegisterLuaFunctions() { &Script_C_Reputation_GetWatchedFactionData); Game::Lua::RegisterTableFunction("C_Reputation", "GetFactionStandings", &Script_C_Reputation_GetFactionStandings); + Game::Lua::RegisterTableFunction("C_Reputation", "GetFactionDataByID", + &Script_C_Reputation_GetFactionDataByID); Game::Lua::RegisterTableFunction("C_Reputation", "GetFactionDataByIndex", &Script_C_Reputation_GetFactionDataByIndex); }