mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-15 23:50:38 +00:00
Addons can now choose the countdown text and its color for each range of time left. Cooldown:SetCountdownFormatter(formatter) and GetCountdownFormatter() take a NumericRuleFormatter from C_StringUtil.CreateNumericRuleFormatter(). Its breakpoints each give a threshold, an optional step, rounding (Enum.NumericRuleFormatRounding), min and max, a format string, and optional div/mod/step components, one for each format argument. Color codes in the format string pass through. The formatter is a full Lua userdata, the first in the DLL. Its block holds a pointer to a reference-counted native object. Every Lua object and every frame that uses it hold one reference, so the GC finalizer (__gc) and the frame's deleting destructor can run in any order. lua_newuserdata (0x6F4560, __fastcall, block at Udata + 0x10, read from the disassembly) is new in Offsets.h. lua_touserdata reuses FUN_FRAMESCRIPT_GET_OBJECT, which is that function. One metatable per Lua state lives in the registry. Its __metatable is false, and the identity check compares a value's metatable with it. 1.12 has no newproxy, so the only finalizer an allocation can run is ours. Thus no addon code can change a formatter while it formats. The text goes through 1.12's own str_format (0x7FD3D0). Its closure is made once per state and kept in the registry, because FormatNumber runs from addon timers and lua_pushcclosure allocates on each push. The rounding is x - fmod(x, step), plus a step away from zero when the rounding needs it. Only that arithmetic matches retail to the last bit: Up of 0.7 by 0.1 gives 0.7000000000000001 and of 0.6 gives 0.6, but ceil(x / step) * step gives 0.6000000000000001. The cooldown shares the formatter and gives it the unrounded seconds left. The formatter replaces the built-in text and both thresholds, and every gate stays. The cached countdown text is now a heap std::string, because a formatter's text has no length limit. The frame frees it, and its reference, in DeletingDestructor. A probe addon recorded 229 results in retail 12.1.5. The same probe on 1.18.1 matched 197 of them. The other results come from 1.12's own str_format (%e exponent digits, %q, %d past the int range, its error wording), from field storage on the object (not ported), and from addresses and times.