diff --git a/README.md b/README.md index 64969264..aeeb7f32 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ reference in **[docs/API.md](docs/API.md)**. | [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` | | [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`, `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` | +| [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` | | [GameObject](docs/API.md#gameobject) | `C_GameObjectInfo.GetGameObjectInfoByID`, `C_GameObjectInfo.RequestLoadGameObjectByID`, `ClosestGameObjectPosition` | | [Glue](docs/API.md#glue) | `C_Glue.IsOnGlueScreen` | diff --git a/docs/API.md b/docs/API.md index 5db8bbf1..935fccd1 100644 --- a/docs/API.md +++ b/docs/API.md @@ -202,6 +202,7 @@ build instructions. - [`editBox:HasText()`](#editboxhastext) - [`editBox:SetHighlightColor(r, g, b [, a])`](#editboxsethighlightcolorr-g-b--a) - [`editBox:GetHighlightColor()`](#editboxgethighlightcolor) + - [`editBox:ClearHistory()`](#editboxclearhistory) - [`frame:SetResizeBounds(minWidth, minHeight [, maxWidth, maxHeight])`](#framesetresizeboundsminwidth-minheight--maxwidth-maxheight) - [`frame:HookScript(scriptType, handler)`](#framehookscriptscripttype-handler) - [`frame:IsEventRegistered(event)`](#frameiseventregisteredevent) @@ -4699,6 +4700,12 @@ ChatFrameEditBox:SetHighlightColor(1, 0, 0) -- red selection Returns the selection-highlight color as four numbers: `r, g, b, a`, each `0` to `1`. +### `editBox:ClearHistory()` + +Removes every line from the up/down input history. The history line limit +(`SetHistoryLines`) stays, so the box keeps recording new lines afterward. +Does nothing when the box has no history. + ### `frame:SetResizeBounds(minWidth, minHeight [, maxWidth, maxHeight])` The modern rename of vanilla's `SetMinResize` / `SetMaxResize` pair. diff --git a/src/Offsets.h b/src/Offsets.h index e615e013..0a90c69c 100644 --- a/src/Offsets.h +++ b/src/Offsets.h @@ -7621,6 +7621,17 @@ enum Offsets { // the generic region color accessors. The blinking caret is a SEPARATE // region at +0x3d4, deliberately left alone. OFF_EDITBOX_HIGHLIGHT_REGION = 0x350, + // Input-history ring buffer: max lines (ring capacity) at +0x388 (what + // GetHistoryLines reads), write position at +0x38c, container + // {size@+0x390, alloc@+0x394, data@+0x398} of {char* text, int exec} + // entries. AddHistoryLine writes at +0x38c and advances modulo +0x388. + OFF_EDITBOX_HISTORY_MAX = 0x388, + // `void __thiscall(editbox, int maxLines)` — the SetHistoryLines internal + // (FUN_0077cd90). Reallocates the history ring to maxLines; maxLines == 0 + // frees the whole buffer and zeroes the container. ClearHistory calls it + // with 0 then the saved max — empties every entry and resets the write + // position while keeping the limit (so recording still works after). + FUN_EDITBOX_SET_HISTORY_MAX = 0x0077cd90, // --- FontString measure internals (GetStringWidth icon fix + GetStringHeight) --- // CSimpleFontString::GetStringWidthInternal — `float(__fastcall)(fs /*ecx*/)`, diff --git a/src/editbox/Methods.cpp b/src/editbox/Methods.cpp index 56876ec6..b19064f7 100644 --- a/src/editbox/Methods.cpp +++ b/src/editbox/Methods.cpp @@ -22,6 +22,7 @@ // HasFocus — does this box own keyboard focus // HasText — is the box non-empty // Set/GetHighlightColor — the text-selection highlight color +// ClearHistory — empty the up/down input history // // The engine already stores and manipulates all of this; we just expose it. // Every method is registered on the EditBox method registry, so — like any @@ -48,6 +49,7 @@ using CollapseSelection_t = void(__thiscall *)(void *editbox); using CountChars_t = int(__thiscall *)(void *editbox, int startByte, int byteCount); using RegionSetColor_t = void(__thiscall *)(void *region, const uint32_t *colorBGRA); using RegionGetColor_t = void(__thiscall *)(void *region, uint32_t *outBGRA); +using SetHistoryMax_t = void(__thiscall *)(void *editbox, int maxLines); // A Lua color arg (0..1) clamped and scaled to a 0..255 byte, matching the // engine's own float->byte color conversion (truncating, like Texture's @@ -197,6 +199,27 @@ int __fastcall Script_GetHighlightColor(void *L) { return 4; } +// Empties the up/down input history, keeping the line limit so the box keeps +// recording afterward. The engine's SetHistoryLines internal frees the whole +// ring at max 0, so clear = free (0) then reallocate at the saved max — which +// drops every entry and resets the write position. No-op when history was +// never enabled (max 0). +int __fastcall Script_ClearHistory(void *L) { + void *eb = Game::Lua::ResolveObject(L, 1); + if (eb == nullptr) { + Game::Lua::Error(L, "Usage: EditBox:ClearHistory()"); + return 0; + } + const int max = Game::Read(eb, Offsets::OFF_EDITBOX_HISTORY_MAX); + if (max > 0) { + auto setMax = reinterpret_cast( + Offsets::FUN_EDITBOX_SET_HISTORY_MAX); + setMax(eb, 0); + setMax(eb, max); + } + return 0; +} + const Game::Lua::FrameMethodEntry g_methods[] = { {"SetCursorPosition", &Script_SetCursorPosition}, {"GetCursorPosition", &Script_GetCursorPosition}, @@ -206,6 +229,7 @@ const Game::Lua::FrameMethodEntry g_methods[] = { {"HasText", &Script_HasText}, {"SetHighlightColor", &Script_SetHighlightColor}, {"GetHighlightColor", &Script_GetHighlightColor}, + {"ClearHistory", &Script_ClearHistory}, }; void RegisterLuaFunctions() {