public
Description: WoW Addon - My fork of Ace's AddonLoader... cause I'm not willing to install an SVN client :)
Homepage: http://www.wowace.com/wiki/AddonLoader
Clone URL: git://github.com/tekkub/addonloader.git
Ace SVN r76425
tekkub (author)
Fri Jul 11 20:32:21 -0700 2008
commit  7c2cd5183cd7876986ecf6f4b1d3e9ba4d861241
tree    e314de1589d0c5aacedf518c743ebb3c6f18700b
parent  c36f969014169a107a926cb7456cb19f7b524921
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
21
22
23
24
25
26
27
28
 
 
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
 
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 
 
 
91
92
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
96
97
98
99
100
101
102
103
104
105
106
107
 
 
 
 
 
 
 
 
 
 
 
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
 
 
 
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
 
 
 
 
 
 
 
 
145
146
 
 
 
 
 
 
 
 
 
147
148
149
150
151
152
153
154
155
156
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
159
160
161
 
 
 
 
 
 
162
163
 
164
165
166
167
168
169
170
 
 
 
 
 
 
 
 
 
 
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
211
212
213
214
215
216
217
218
219
220
221
222
 
 
 
 
 
 
 
 
 
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
 
 
 
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
 
 
 
 
 
 
 
3
4
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
8
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
11
12
13
 
 
 
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
 
 
 
 
 
 
 
 
 
33
34
35
36
37
38
39
40
41
42
43
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
46
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
50
51
52
53
54
55
56
57
 
58
59
60
61
62
63
64
65
66
67
68
 
 
 
69
70
 
 
 
 
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
 
 
89
90
91
92
93
94
95
 
96
97
 
 
 
 
 
 
98
99
100
101
102
103
104
105
106
107
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 
 
 
 
 
 
 
 
 
 
 
134
135
136
137
138
139
140
141
142
143
144
145
 
146
147
148
 
 
 
 
 
 
 
 
149
150
151
0
@@ -1,237 +1,151 @@
0
---[[
0
- Copyright (C) 2007 Nymbia
0
-
0
- This program is free software; you can redistribute it and/or modify
0
- it under the terms of the GNU General Public License as published by
0
- the Free Software Foundation; either version 2 of the License, or
0
- (at your option) any later version.
0
-
0
- This program is distributed in the hope that it will be useful,
0
- but WITHOUT ANY WARRANTY; without even the implied warranty of
0
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0
- GNU General Public License for more details.
0
-
0
- You should have received a copy of the GNU General Public License along
0
- with this program; if not, write to the Free Software Foundation, Inc.,
0
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0
-]]
0
-local L = AceLibrary("AceLocale-2.2"):new("AddonLoader")
0
-
0
-AddonLoader = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceDB-2.0", "AceEvent-2.0", "AceModuleCore-2.0")
0
+AddonLoader = {}
0
 local AddonLoader = AddonLoader
0
-AddonLoader.slashes = {}
0
-
0
-AddonLoader:SetModuleMixins("AceEvent-2.0", "AceDB-2.0", "AceHook-2.1")
0
-AddonLoader:RegisterDB("AddonLoaderDB")
0
-local numaddons = GetNumAddOns()
0
-local GetAddOnInfo = GetAddOnInfo
0
-local GetAddOnMetadata = GetAddOnMetadata
0
+AddonLoader.events = {}
0
+AddonLoader.conditiontexts = {}
0
 
0
-local overridesvalidate = {
0
- L.None,
0
- L.Always,
0
- L.AuctionHouse,
0
- L.Arena,
0
- L.Bank,
0
- L.Battleground,
0
- L.Combat,
0
- L.Crafting,
0
- L.Group,
0
- L.Guild,
0
- L.Instance,
0
- L.Mailbox,
0
- L.Merchant,
0
- L.NotResting,
0
- L.PvPFlagged,
0
- L.Raid,
0
- L.Resting,
0
-}
0
 
0
-local overrides = {
0
- [L.Always] = 'X-LoadOn-Always',
0
- [L.AuctionHouse] = 'X-LoadOn-AuctionHouse',
0
- [L.Arena] = 'X-LoadOn-Arena',
0
- [L.Bank] = 'X-LoadOn-Bank',
0
- [L.Battleground] = 'X-LoadOn-Battleground',
0
- [L.Combat] = 'X-LoadOn-Combat',
0
- [L.Crafting] = 'X-LoadOn-Crafting',
0
- [L.Group] = 'X-LoadOn-Group',
0
- [L.Guild] = 'X-LoadOn-Guild',
0
- [L.Instance] = 'X-LoadOn-Instance',
0
- [L.Mailbox] = 'X-LoadOn-Mailbox',
0
- [L.Merchant] = 'X-LoadOn-Merchant',
0
- [L.NotResting] = 'X-LoadOn-NotResting',
0
- [L.PvPFlagged] = 'X-LoadOn-PvPFlagged',
0
- [L.Raid] = 'X-LoadOn-Raid',
0
- [L.Resting] = 'X-LoadOn-Resting',
0
-}
0
+local frame = CreateFrame("Frame", "AddonLoaderFrame")
0
+AddonLoader.frame = frame -- easy reference for use in X-LoadOn-Events
0
 
0
-local options = {
0
- type = 'group',
0
- args = {
0
- messages = {
0
- name = L["Messages"],
0
- desc = L["Show messages in the chat frame when addons are loaded"],
0
- type = 'toggle',
0
- get = function()
0
- return AddonLoader.db.profile.messages
0
- end,
0
- set = function(v)
0
- AddonLoader.db.profile.messages = v
0
- end,
0
- },
0
- overrides = {
0
- name = L["Overrides"],
0
- desc = L["Set alternate conditions for loading a given addon, overriding those in its toc file. NOTE: These settings do not take effect until a UI reload."],
0
- type = 'group',
0
- args = {}
0
- },
0
- },
0
-}
0
+function AddonLoader:Print(text)
0
+ DEFAULT_CHAT_FRAME:AddMessage("|cFF33FF99AddonLoader|r: ".. tostring(text))
0
+end
0
 
0
-function AddonLoader:ADDON_LOADED(addon)
0
- if addon=="ForkliftGnome" then -- Keep ForkliftGnome from doing the same work as AddonLoader (and generating errors!)
0
- ForkliftGnome.OnEnable = function() end
0
+function AddonLoader:AddCondition(condname, addonname, metatext)
0
+ if AddonLoader.conditions[condname] then
0
+ local cond = AddonLoader.conditions[condname]
0
+ for k, event in pairs(cond.events) do
0
+ if not AddonLoader.events[event] then
0
+ AddonLoader.events[event] = {}
0
+ frame:RegisterEvent(event)
0
+ end
0
+ if not AddonLoader.events[event][addonname] then
0
+ AddonLoader.events[event][addonname] = {}
0
+ end
0
+ AddonLoader.events[event][addonname][condname] = {
0
+ handler = cond.handler,
0
+ arg = metatext,
0
+ }
0
+ end
0
   end
0
 end
0
 
0
-function AddonLoader:OnInitialize()
0
- self:RegisterDefaults('profile', {
0
- messages = true,
0
- overrides = {
0
- ['*'] = false,
0
- },
0
- })
0
- self:RegisterChatCommand({'/addonloader','/aloader','/aload'}, options)
0
- self:RegisterEvent("ADDON_LOADED");
0
-end
0
+-- scan all addons and their metadata for X-LoadOn directives.
0
+function AddonLoader:ScanAddons()
0
+ for i = 1, GetNumAddOns() do
0
+ if IsAddOnLoadOnDemand(i) and not IsAddOnLoaded(i) then
0
+ -- scan metadata.
0
+ -- inject events with the correct handlers for all addons.
0
+ -- register for those events on our frame
0
+ local name = GetAddOnInfo(i)
0
+ for condname, cond in pairs(AddonLoader.conditions) do
0
+ local meta = GetAddOnMetadata(name, condname)
0
+ if meta then
0
 
0
-do
0
- local handleLoadAddOn
0
- do
0
- local loadattempted = {}
0
- function handleLoadAddOn(addon)
0
- if tonumber(addon) then
0
- addon = GetAddOnInfo(addon)
0
- end
0
- if loadattempted[addon] then
0
- return
0
- end
0
- loadattempted[addon] = true
0
- if options.args.overrides.args[addon] then
0
- if IsAddOnLoaded(addon) then
0
- if AddonLoader.db.profile.messages then
0
- AddonLoader:Print(L["Loaded %s."]:format(addon));
0
+ -- build the textblock as base for overrides
0
+ if not AddonLoader.conditiontexts[name] then
0
+ AddonLoader.conditiontexts[name] = ""
0
           end
0
- else
0
- local name, _,_, enabled = GetAddOnInfo(addon);
0
- if name and not enabled then
0
- -- don't complain
0
- else
0
- local _, reason = LoadAddOn(addon)
0
- AddonLoader:Print(L["Failed to load %s: %s."]:format(addon, reason));
0
- end
0
- end
0
- end
0
- for name, module in AddonLoader:IterateModules() do
0
- if not module.off then
0
- local t = module.addons
0
- if name == addon then
0
- module:Disable()
0
- elseif t and t[addon] then
0
- t[addon] = nil
0
- if not next(t) then
0
- module:Disable()
0
+ AddonLoader.conditiontexts[name] = AddonLoader.conditiontexts[name] .. condname..": "..meta.."\n"
0
+ -- special handling for hook and events
0
+ if condname == "X-LoadOn-Events" or condname == "X-LoadOn-Hooks" then
0
+ for item in meta:gmatch("[^ ,]+") do
0
+ local metaitem = GetAddOnMetadata(name, "X-LoadOn-"..item)
0
+ if metaitem then
0
+ AddonLoader.conditiontexts[name] = AddonLoader.conditiontexts[name].."X-LoadOn-"..item..": "..metaitem.."\n"
0
+ end
0
             end
0
- end
0
+ elseif condname == "X-LoadOn-Execute" then -- special handling for execute
0
+ for i = 2, 5 do
0
+ local metaitem = GetAddOnMetadata(name, "X-LoadOn-Execute"..i)
0
+ if metaitem then
0
+ AddonLoader.conditiontexts[name] = AddonLoader.conditiontexts[name].."X-LoadOn-Execute"..i..": "..metaitem.."\n"
0
+ end
0
+ end
0
+ end
0
+ AddonLoader:AddCondition(condname, name, meta)
0
         end
0
       end
0
- for _, v in ipairs(AddonLoader.slashes) do
0
- hash_SlashCmdList[v] = nil
0
- end
0
     end
0
   end
0
- local function get(addon)
0
- local value = AddonLoader.db.profile.overrides[addon]
0
- if not value then
0
- return L.None
0
+end
0
+
0
+-- this will be called at PLAYER_LOGIN at which point the saved vars should be present
0
+function AddonLoader:LoadOverrides()
0
+ if not AddonLoaderSV then
0
+ AddonLoaderSV = { -- overrides
0
+ overrides = {},
0
+ }
0
+ end
0
+ AddonLoader.originals = {}
0
+ for k, v in pairs(AddonLoader.conditiontexts) do
0
+ AddonLoader.originals[k] = v
0
+ end
0
+ for addon, conditiontext in pairs(AddonLoaderSV.overrides) do
0
+ -- we have an addon lets clear the events for this addon and override unconditionaly.
0
+ for event, addons in pairs(AddonLoader.events) do
0
+ addons[addon] = nil -- nuke
0
     end
0
- for k,v in pairs(overrides) do
0
- if v == value then
0
- return k
0
+ AddonLoader.conditiontexts[addon] = conditiontext
0
+ -- we have a conditiontext override lets do it.
0
+ for line in conditiontext:gmatch("[^\n]+") do
0
+ local condname, text = string.match(line, "^([^:]*): (.*)$")
0
+ if condname and text then
0
+ AddonLoader:AddCondition(condname, addon, text)
0
       end
0
- end
0
+ end
0
   end
0
- local function set(addon,v)
0
- if v == L.None then
0
- AddonLoader.db.profile.overrides[addon] = false
0
- else
0
- AddonLoader.db.profile.overrides[addon] = overrides[v]
0
- end
0
+end
0
+
0
+function AddonLoader:LoadAddOn(name)
0
+ -- Verify that the addon isn't disabled
0
+ local enabled = select(4, GetAddOnInfo(name))
0
+ if not enabled then return false end
0
+
0
+ -- Load the addon
0
+ if not AddonLoaderSV.silent then
0
+ AddonLoader:Print("Loading " .. name)
0
   end
0
-
0
- function AddonLoader:OnEnable(first)
0
- if not first then
0
- return
0
- end
0
- hooksecurefunc('LoadAddOn', handleLoadAddOn)
0
- local metadatafields = self.metadatafields
0
- local overrides = self.db.profile.overrides
0
- local options = options.args.overrides.args
0
- for i = 1, numaddons do
0
- if IsAddOnLoadOnDemand(i) then
0
- local name = GetAddOnInfo(i)
0
- local hasfield
0
- local alreadyloaded
0
- if overrides[name] and overrides[name] == 'X-LoadOn-Always' then
0
- metadatafields[overrides[name]](name)
0
- hasfield = true
0
- elseif overrides[name] then
0
- metadatafields[overrides[name]](name)
0
- local metadata = GetAddOnMetadata(i, 'X-LoadOn-Slash')
0
- if metadata then
0
- metadatafields['X-LoadOn-Slash'](name, metadata)
0
- end
0
- local metadata = GetAddOnMetadata(i, 'X-LoadOn-Execute')
0
- if metadata then
0
- metadatafields['X-LoadOn-Execute'](name, metadata)
0
- end
0
- hasfield = true
0
- else
0
- alreadyloaded = not not IsAddOnLoaded(i)
0
- for k,v in pairs(metadatafields) do
0
- local metadata = GetAddOnMetadata(i, k)
0
- if metadata then
0
- hasfield = true
0
- if not alreadyloaded then
0
- v(name, metadata)
0
- end
0
- end
0
+ local succ, err = LoadAddOn(name)
0
+ if not succ then
0
+ AddonLoader:Print("Error loading " .. name .. " (" .. err .. ")")
0
+ return false, err
0
+ end
0
+ return true
0
+end
0
+
0
+
0
+-- event handler
0
+local function OnEvent(this, event, ...)
0
+ if event == "PLAYER_LOGIN" then
0
+ AddonLoader:ScanAddons()
0
+ AddonLoader:LoadOverrides()
0
+ end
0
+ if AddonLoader.events[event] then
0
+ --- run the handlers
0
+ for name, conditions in pairs(AddonLoader.events[event]) do
0
+ if not IsAddOnLoaded(name) then
0
+ for condname, condition in pairs(conditions) do
0
+ if condition.handler(event, name, condition.arg, ...) then
0
+ AddonLoader:LoadAddOn(name)
0
+ break
0
           end
0
         end
0
- if hasfield then
0
- options[name] = {
0
- name = name,
0
- desc = L["Set the loading condition for %s. NOTE: Does not take effect until a UI reload."]:format(name),
0
- type = 'text',
0
- get = get,
0
- set = set,
0
- validate = overridesvalidate,
0
- disabled = alreadyloaded,
0
- passValue = name,
0
- }
0
+ end
0
+ -- we do a lazy cleanup here
0
+ -- if an addon gets loaded by means other than AddonLoader it will be removed from the events list upon next firing of the event.
0
+ if IsAddOnLoaded(name) then -- cleanup
0
+ AddonLoader.events[event][name] = nil
0
+ local found = next(AddonLoader.events[event])
0
+ if not found then
0
+ AddonLoader.events[event] = nil
0
+ frame:UnregisterEvent(event)
0
         end
0
       end
0
     end
0
- self.metadatafields = nil
0
   end
0
 end
0
 
0
-function AddonLoader.modulePrototype:Disable()
0
- self.off = true
0
- self.addons = nil
0
- self:UnregisterAllEvents()
0
- if self.UnhookAll then
0
- self:UnhookAll()
0
- end
0
-end
0
+frame:SetScript("OnEvent", OnEvent)
0
+frame:RegisterEvent("PLAYER_LOGIN")
0
+
...
 
1
2
3
4
5
6
 
 
7
8
9
10
11
12
13
 
 
14
 
15
16
17
18
19
20
 
21
22
 
23
24
 
 
 
25
26
27
28
29
30
 
...
1
2
 
 
 
 
 
3
4
5
 
 
 
 
 
 
6
7
8
9
10
 
 
 
11
 
12
13
 
14
15
 
16
17
18
19
 
 
 
20
 
21
0
@@ -1,30 +1,21 @@
0
+## Interface: 20400
0
 
0
-## Title: AddonLoader |cff7fff7f -Ace2-|r
0
-## Notes: Does automatic loading of Load-on-Demand addons that support AddonLoader. Use rMCP or ACP for a GUI. AddonLoader replaces ForkliftGnome.
0
-## Notes-zhTW: 自動載入支援 AddonLoader 的隨需求載入插件。使用 rMCP 或 ACP 作為圖形用戶介面。AddonLoader 取代 ForkliftGnome。
0
-## Author: Nymbia, Mikk
0
-## X-eMail: nymbia@gmail.com
0
+## Title: Addon Loader
0
+## Notes: Loadmanager for AddOns
0
 
0
-## Interface: 20200
0
-## Version: 1.0
0
-
0
-## LoadWith: ForkliftGnome
0
-## OptionalDeps: Ace2
0
-## X-Embeds: Ace2, Babble-2.2
0
+## Author: Ammo, Cladhaire, Joshborke
0
+## X-Credits: Nymbia, Mikk for the original AddonLoader
0
 
0
+## Version: 2.0
0
 ## X-Website: http://www.wowace.com/wiki/AddonLoader
0
-## X-Category: Miscellaneous
0
-## X-License: GPL v2
0
-## X-AceForum: 0
0
 
0
-## SavedVariables: AddonLoaderDB
0
+## SavedVariablesPerCharacter: AddonLoaderSV
0
 
0
-## # LoadOnDemand: 1
0
+AddonLoader.lua
0
 
0
-embeds.xml
0
+locale\enUS.lua
0
+locale\deDE.lua
0
+locale\esES.lua
0
 
0
-AddonLoader-enUS.lua
0
-AddonLoader-zhTW.lua
0
-AddonLoader.lua
0
 Conditions.lua
0
-
0
+Overrides.lua
...
1
2
 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
 
 
 
 
18
19
20
21
22
 
 
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
113
114
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
157
158
159
160
161
162
163
164
165
 
 
 
 
 
 
 
 
 
 
 
 
 
166
 
 
167
168
169
170
171
172
173
174
175
176
177
 
 
 
 
 
178
 
 
 
 
179
180
181
182
183
184
185
186
187
188
189
190
 
 
 
 
 
 
 
 
191
192
193
194
195
196
197
198
199
200
201
 
 
 
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
 
 
 
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
 
371
372
373
374
375
376
 
 
 
377
...
 
 
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
5
6
7
8
 
 
 
 
9
10
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
 
 
 
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
 
 
 
 
 
 
 
 
 
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
 
 
 
 
 
 
 
 
 
 
206
207
208
209
210
211
212
213
214
215
216
 
 
 
 
 
 
 
 
 
 
 
217
218
219
220
221
222
223
224
225
 
 
 
 
 
 
 
 
 
 
226
227
228
229
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
253
254
255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
257
 
 
 
 
 
258
259
260
261
0
@@ -1,376 +1,260 @@
0
---[[
0
- Copyright (C) 2007 Nymbia
0
+local function returnTrue() return true end
0
 
0
- This program is free software; you can redistribute it and/or modify
0
- it under the terms of the GNU General Public License as published by
0
- the Free Software Foundation; either version 2 of the License, or
0
- (at your option) any later version.
0
-
0
- This program is distributed in the hope that it will be useful,
0
- but WITHOUT ANY WARRANTY; without even the implied warranty of
0
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0
- GNU General Public License for more details.
0
-
0
- You should have received a copy of the GNU General Public License along
0
- with this program; if not, write to the Free Software Foundation, Inc.,
0
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0
-]]
0
+-- There should be a cleaner way to handle this
0
+local hookenv = setmetatable({}, {__index = getfenv(0)})
0
+function hookenv.LoadAddOn(name)
0
+ return AddonLoader:LoadAddOn(name)
0
+end
0
 
0
-local BZ = AceLibrary("Babble-Zone-2.2")
0
-local assert = assert
0
-local pcall = pcall
0
-local _G = getfenv(0)
0
+local delayFrame -- will be filled if needed with a frame for loading addons delayed.
0
+local BZ -- will be a reference to babble-zone-3.0 if needed
0
 
0
-local registerIntoModule
0
-do
0
- local function trigger(self)
0
- local t = self.addons
0
- self:Disable()
0
- for k in pairs(t) do
0
- LoadAddOn(k)
0
- end
0
- end
0
- function registerIntoModule(modulename, addon)
0
- if AddonLoader:HasModule(modulename) then
0
- local module = AddonLoader:GetModule(modulename)
0
- if module.off then -- this module already triggered
0
- LoadAddOn(addon)
0
- return nil, true
0
- end
0
- module.addons[addon] = true
0
- return module, true
0
- else
0
- local module = AddonLoader:NewModule(modulename)
0
- module.addons = {[addon] = true}
0
- module.Trigger = trigger
0
- return module, false
0
- end
0
- end
0
-end
0
-AddonLoader.metadatafields = {
0
- -- Standard Triggers
0
- ['X-LoadOn-AuctionHouse'] = function(addon, metadata)
0
- local module, exists = registerIntoModule('X-LoadOn-AuctionHouse', addon)
0
- if not exists then
0
- function module:AUCTION_HOUSE_SHOW()
0
- self:Trigger()
0
- end
0
- module:RegisterEvent('AUCTION_HOUSE_SHOW')
0
- end
0
- end,
0
- ['X-LoadOn-Arena'] = function(addon, metadata)
0
- local module, exists = registerIntoModule('X-LoadOn-Arena', addon)
0
- if not exists then
0
- function module:ZONE_CHANGED_NEW_AREA()
0
- if select(2, IsInInstance()) == "arena" then
0
- self:Trigger()
0
- end
0
- end
0
- module:RegisterEvent('ZONE_CHANGED_NEW_AREA')
0
- module:ZONE_CHANGED_NEW_AREA()
0
- end
0
- end,
0
- ['X-LoadOn-Bank'] = function(addon, metadata)
0
- local module, exists = registerIntoModule('X-LoadOn-Bank', addon)
0
- if not exists then
0
- function module:BANKFRAME_OPENED()
0
- self:Trigger()
0
- end
0
- module:RegisterEvent('BANKFRAME_OPENED')
0
- end
0
- end,
0
- ['X-LoadOn-Battleground'] = function(addon, metadata) --!!
0
- local module, exists = registerIntoModule('X-LoadOn-Battleground', addon)
0
- if not exists then
0
- function module:ZONE_CHANGED_NEW_AREA()
0
- if select(2, IsInInstance()) == "pvp" then
0
- self:Trigger()
0
- end
0
- end
0
- module:RegisterEvent('ZONE_CHANGED_NEW_AREA')
0
- module:ZONE_CHANGED_NEW_AREA()
0
- end
0
- end,
0
- ['X-LoadOn-Instance'] = function(addon, metadata) --!!
0
- local module, exists = registerIntoModule('X-LoadOn-Instance', addon)
0
- if not exists then
0
- function module:ZONE_CHANGED_NEW_AREA()
0
- local instanceType = select(2, IsInInstance())
0
- if instanceType == 'party' or instanceType == 'raid' then
0
- self:Trigger()
0
- end
0
- end
0
- module:RegisterEvent('ZONE_CHANGED_NEW_AREA')
0
- module:ZONE_CHANGED_NEW_AREA()
0
- end
0
- end,
0
- ['X-LoadOn-Combat'] = function(addon, metadata)
0
- local module, exists = registerIntoModule('X-LoadOn-Combat', addon)
0
- if not exists then
0
- function module:PLAYER_REGEN_DISABLED()
0
- self:Trigger()
0
+AddonLoader.conditions = {
0
+ ["X-LoadOn-Mailbox"] = {
0
+ events = {"MAIL_SHOW"},
0
+ handler = returnTrue
0
+ },
0
+ ["X-LoadOn-AuctionHouse"] = {
0
+ events = {"AUCTIONHOUSE_SHOW"},
0
+ handler = returnTrue
0
+ },
0
+ ["X-LoadOn-Bank"] = {
0
+ events = {"BANKFRAME_OPENED"},
0
+ handler = returnTrue
0
+ },
0
+ ["X-LoadOn-Arena"] = {
0
+ events = {"ZONE_CHANGED_NEW_AREA", "PLAYER_ENTERING_WORLD"},
0
+ handler = function() return select(2, IsInInstance()) == "arena" end,
0
+ },
0
+ ["X-LoadOn-Battleground"] = {
0
+ events = {"ZONE_CHANGED_NEW_AREA", "PLAYER_ENTERING_WORLD"},
0
+ handler = function() return select(2, IsInInstance()) == "pvp" end,
0
+ },
0
+ ["X-LoadOn-Instance"] = {
0
+ events = {"ZONE_CHANGED_NEW_AREA", "PLAYER_ENTERING_WORLD"},
0
+ handler = function()
0
+ local instanceType = select(2, IsInInstance())
0
+ return instanceType == "party" or instanceType == "raid"
0
+ end,
0
+ },
0
+ ["X-LoadOn-Combat"] = {
0
+ events = {"PLAYER_REGEN_DISABLED", "PLAYER_ENTERING_WORLD"},
0
+ handler = function( event, name, arg )
0
+ if event == "PLAYER_REGEN_DISABLED" then return true end
0
+ if event == "PLAYER_ENTERING_WORLD" then return InCombatLockdown() end
0
+ end,
0
+ },
0
+ ["X-LoadOn-Crafting"] = {
0
+ events = {"TRADE_SKILL_SHOW", "CRAFT_SHOW"},
0
+ handler = returnTrue,
0
+ },
0
+ ["X-LoadOn-Group"] = {
0
+ events = {"PARTY_MEMBERS_CHANGED","RAID_ROSTER_UPDATE", "PLAYER_ENTERING_WORLD"},
0
+ handler = function() return GetNumRaidMembers() > 0 or GetNumPartyMembers() > 0 end,
0
+ },
0
+ ["X-LoadOn-Merchant"] = {
0
+ events = {"MERCHANT_SHOW"},
0
+ handler = returnTrue,
0
+ },
0
+ ["X-LoadOn-PvPFlagged"] = {
0
+ events = {"UNIT_FACTION", "PLAYER_ENTERING_WORLD"},
0
+ handler = function() return UnitIsPVP("player") end,
0
+ },
0
+ ["X-LoadOn-Raid"] = {
0
+ events = {"RAID_ROSTER_UPDATE", "PLAYER_ENTERING_WORLD"},
0
+ handler = function() return GetNumRaidMembers() > 0 end,
0
+ },<