mirror of
https://codeberg.org/Duvelcorp/MetaHunt.git
synced 2026-09-21 23:26:57 +00:00
060fc555fe
Collapse all legacy/scattered SavedVariables from absorbed standalone
addons (FeedOMatic, ZHunter/zButtons, SmartAmmo, AutoQuest, AntiDaze,
AutoStrip, MinimapButton) into two persisted globals with clean per-module
nesting under .modules.<id>.
Migration engine (api/savedvariables.lua):
- MTH_SV_EnsureSchema() with schemaVersion gate, idempotent + non-destructive
- Per-module migrators map old locations -> canonical nested stores
- Driven by an ADDON_LOADED("MetaHunt") handler so it runs only AFTER WoW
loads the real SavedVariables (fixes announce-every-session bug that ran
the migration on empty pre-load defaults)
- One-time player-facing chat announce, gated on real legacy data present
Framework/config:
- core-framework InitSavedVariables no longer runs migration at file-load;
unconditionally strips account-root module aliases
- config.lua stops re-creating root[module] aliases (was duplicating data
onto disk); canonical store stays under .modules.<id>
Modules:
- feedomatic: bind FOM_* globals as runtime aliases into nested store,
drop persisted duplicates and .legacy blob
- zhunter: ZHunterMod_Saved re-pointed at .modules.zhunter
- smartammo/autoquest/antidaze/autostrip/minimapbutton read nested store
TOC trimmed to MTH_SavedVariables + MTH_CharSavedVariables only.
Profiles unchanged (already snapshot/apply the nested .modules structure).
Also includes pet-scan refinements: canonical pet key derivation and
level-independent pet signature (schema v3).
241 lines
6.3 KiB
Lua
241 lines
6.3 KiB
Lua
------------------------------------------------------
|
|
-- MetaHunt: FeedOMatic Module Wrapper
|
|
-- Modern module abstraction for the FeedOMatic addon
|
|
------------------------------------------------------
|
|
|
|
local MTH_FeedOMatic = {
|
|
name = "feedomatic",
|
|
enabled = false,
|
|
events = {
|
|
"VARIABLES_LOADED",
|
|
"MTH_PET_LIVE_STATE_CHANGED",
|
|
"PET_ATTACK_START",
|
|
"PET_ATTACK_STOP",
|
|
"PET_STABLE_SHOW",
|
|
"PET_STABLE_UPDATE",
|
|
"TRADE_SKILL_SHOW",
|
|
"TRADE_SKILL_UPDATE",
|
|
"CHAT_MSG_SPELL_TRADESKILLS",
|
|
"CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS",
|
|
"UI_ERROR_MESSAGE",
|
|
"PET_BAR_SHOWGRID",
|
|
"PET_BAR_UPDATE",
|
|
"PET_UI_UPDATE",
|
|
"UNIT_HAPPINESS",
|
|
"PLAYER_REGEN_ENABLED",
|
|
},
|
|
initialized = false,
|
|
variablesLoadedProcessed = false,
|
|
}
|
|
|
|
local MTH_PETL_HOOK_BOUNDARY_KEY = "pet-lifecycle-hooks"
|
|
|
|
function MTH_FeedOMatic_OnUpdate(elapsed)
|
|
if not elapsed then
|
|
return
|
|
end
|
|
if not (MTH and MTH.IsModuleEnabled and MTH:IsModuleEnabled("feedomatic", false)) then
|
|
return
|
|
end
|
|
if type(FOM_OnUpdate) == "function" then
|
|
FOM_OnUpdate(elapsed)
|
|
end
|
|
end
|
|
|
|
local function MTH_FeedOMatic_GetRuntimeFrame()
|
|
return getglobal("MTH_FOM_OnUpdateFrame")
|
|
end
|
|
|
|
local function MTH_FeedOMatic_CaptureHookBoundary()
|
|
if not (MTH and MTH.CaptureHookBoundary) then
|
|
return
|
|
end
|
|
MTH:CaptureHookBoundary(MTH_PETL_HOOK_BOUNDARY_KEY, {
|
|
{ globalName = "PetAbandon", originalName = "MTH_PETL_Original_PetAbandon" },
|
|
})
|
|
end
|
|
|
|
local function MTH_FeedOMatic_RestoreHookBoundary()
|
|
if not (MTH and MTH.RestoreHookBoundary) then
|
|
return
|
|
end
|
|
MTH:RestoreHookBoundary(MTH_PETL_HOOK_BOUNDARY_KEY)
|
|
end
|
|
|
|
local function MTH_FeedOMatic_ApplyLegacyHooks()
|
|
local canTouchPetAbandon = true
|
|
if MTH and MTH.GetGlobalHookOwner then
|
|
local abandonOwner = MTH:GetGlobalHookOwner("PetAbandon")
|
|
if abandonOwner and abandonOwner ~= MTH_PETL_HOOK_BOUNDARY_KEY then
|
|
canTouchPetAbandon = false
|
|
end
|
|
end
|
|
|
|
local abandonHook = MTH_PetAbandonHook or FOM_PetAbandon
|
|
local abandonOriginal = MTH_PETL_Original_PetAbandon or FOM_Original_PetAbandon
|
|
if type(abandonHook) == "function" and type(abandonOriginal) == "function" then
|
|
if canTouchPetAbandon and (PetAbandon == abandonOriginal or PetAbandon == abandonHook) then
|
|
PetAbandon = abandonHook
|
|
end
|
|
end
|
|
end
|
|
|
|
local function MTH_FeedOMatic_CallLegacyOnEvent(evt, a1, a2, a3, a4, a5, a6, a7, a8, a9)
|
|
if type(FOM_OnEvent) ~= "function" then
|
|
return
|
|
end
|
|
|
|
local frame = MTH_FeedOMatic_GetRuntimeFrame()
|
|
if not frame then
|
|
return
|
|
end
|
|
|
|
local oldThis = this
|
|
local oldEvent = event
|
|
local oldArg1, oldArg2, oldArg3, oldArg4, oldArg5 = arg1, arg2, arg3, arg4, arg5
|
|
local oldArg6, oldArg7, oldArg8, oldArg9 = arg6, arg7, arg8, arg9
|
|
|
|
this = frame
|
|
event = evt
|
|
arg1, arg2, arg3, arg4, arg5 = a1, a2, a3, a4, a5
|
|
arg6, arg7, arg8, arg9 = a6, a7, a8, a9
|
|
|
|
local ok = pcall(function()
|
|
FOM_OnEvent(evt, a1)
|
|
end)
|
|
|
|
this = oldThis
|
|
event = oldEvent
|
|
arg1, arg2, arg3, arg4, arg5 = oldArg1, oldArg2, oldArg3, oldArg4, oldArg5
|
|
arg6, arg7, arg8, arg9 = oldArg6, oldArg7, oldArg8, oldArg9
|
|
end
|
|
|
|
local function MTH_FeedOMatic_EnsureVariablesLoaded(module)
|
|
if not module or module.variablesLoadedProcessed then
|
|
return
|
|
end
|
|
|
|
MTH_FeedOMatic_CallLegacyOnEvent("VARIABLES_LOADED")
|
|
module.variablesLoadedProcessed = true
|
|
end
|
|
|
|
local function MTH_FeedOMatic_SyncSavedVariables()
|
|
if not MTH or not MTH.GetModuleSavedVariables then
|
|
return
|
|
end
|
|
|
|
local moduleStore = MTH:GetModuleSavedVariables("feedomatic")
|
|
|
|
-- Bind each legacy FeedOMatic global to its clean nested location under
|
|
-- modules.feedomatic. The globals are runtime aliases only (NOT persisted via
|
|
-- the TOC any more); the real data lives in these nested tables inside
|
|
-- MTH_SavedVariables. Adopt any pre-existing runtime global on first bind.
|
|
local function bindGlobal(globalName, key)
|
|
local target = moduleStore[key]
|
|
if type(target) ~= "table" then
|
|
local globalValue = _G and _G[globalName] or nil
|
|
if type(globalValue) == "table" then
|
|
target = globalValue
|
|
else
|
|
target = {}
|
|
end
|
|
moduleStore[key] = target
|
|
end
|
|
if _G then
|
|
_G[globalName] = target
|
|
end
|
|
end
|
|
|
|
bindGlobal("FOM_Config", "settings")
|
|
bindGlobal("FOM_FoodQuality", "foodQuality")
|
|
bindGlobal("FOM_AddedFoods", "addedFoods")
|
|
bindGlobal("FOM_RemovedFoods", "removedFoods")
|
|
bindGlobal("FOM_Cooking", "cooking")
|
|
bindGlobal("FOM_QuestFood", "questFood")
|
|
bindGlobal("FOM_LocaleInfo", "localeInfo")
|
|
end
|
|
|
|
function MTH_FeedOMatic:init()
|
|
-- FeedOMatic initializes via its VARIABLES_LOADED event
|
|
-- This is called after the core MTH framework is loaded
|
|
MTH_FEED_WRAPPER_MODE = true
|
|
MTH_FOM_WRAPPER_MODE = MTH_FEED_WRAPPER_MODE
|
|
MTH_FeedOMatic_SyncSavedVariables()
|
|
|
|
if not self.initialized and not getglobal("FOM_METAHUNT_ONLOAD_DONE") and FOM_OnLoad then
|
|
local frame = MTH_FeedOMatic_GetRuntimeFrame()
|
|
if frame then
|
|
local oldThis = this
|
|
this = frame
|
|
pcall(function()
|
|
FOM_OnLoad()
|
|
end)
|
|
this = oldThis
|
|
FOM_METAHUNT_ONLOAD_DONE = true
|
|
end
|
|
end
|
|
|
|
MTH_FeedOMatic_CaptureHookBoundary()
|
|
|
|
self.initialized = true
|
|
if self.enabled then
|
|
MTH_FeedOMatic_EnsureVariablesLoaded(self)
|
|
end
|
|
end
|
|
|
|
function MTH_FeedOMatic:setEnabled(enabled)
|
|
if enabled then
|
|
if not self.initialized then
|
|
self:init()
|
|
end
|
|
MTH_FeedOMatic_ApplyLegacyHooks()
|
|
MTH_FeedOMatic_CaptureHookBoundary()
|
|
MTH_FeedOMatic_SyncSavedVariables()
|
|
MTH_FeedOMatic_EnsureVariablesLoaded(self)
|
|
if MTH_FOM_FeedButton then
|
|
MTH_FOM_FeedButton:Show()
|
|
end
|
|
else
|
|
-- Disable FeedOMatic functionality
|
|
MTH_FeedOMatic_RestoreHookBoundary()
|
|
if type(FOM_State) == "table" then
|
|
FOM_State.ShouldFeed = false
|
|
end
|
|
if MTH_FOM_FeedButton then
|
|
MTH_FOM_FeedButton:Hide()
|
|
end
|
|
end
|
|
end
|
|
|
|
function MTH_FeedOMatic:onEvent(event, arg1, arg2, arg3, arg4, arg5)
|
|
if event == "VARIABLES_LOADED" then
|
|
MTH_FeedOMatic_EnsureVariablesLoaded(self)
|
|
return
|
|
end
|
|
|
|
if event == "MTH_PET_LIVE_STATE_CHANGED" then
|
|
MTH_FeedOMatic_CallLegacyOnEvent("PET_BAR_UPDATE")
|
|
MTH_FeedOMatic_CallLegacyOnEvent("PET_UI_UPDATE")
|
|
MTH_FeedOMatic_CallLegacyOnEvent("UNIT_HAPPINESS", "pet")
|
|
return
|
|
end
|
|
|
|
MTH_FeedOMatic_CallLegacyOnEvent(event, arg1, arg2, arg3, arg4, arg5)
|
|
end
|
|
|
|
function MTH_FeedOMatic:cleanup()
|
|
-- Cleanup code when module is unloaded
|
|
MTH_FeedOMatic_RestoreHookBoundary()
|
|
if type(FOM_State) == "table" then
|
|
FOM_State.ShouldFeed = false
|
|
end
|
|
if MTH_FOM_FeedButton then
|
|
MTH_FOM_FeedButton:Hide();
|
|
end
|
|
end
|
|
|
|
-- Register with MTH
|
|
MTH:RegisterModule("feedomatic", MTH_FeedOMatic)
|
|
|
|
MTH_FOM_OnUpdate = MTH_FeedOMatic_OnUpdate
|