forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInstanceHooks.cpp
83 lines (72 loc) · 2.75 KB
/
InstanceHooks.cpp
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
/*
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/
#include "Hooks.h"
#include "HookHelpers.h"
#include "LuaEngine.h"
#include "BindingMap.h"
#include "ElunaIncludes.h"
#include "ElunaTemplate.h"
#include "ElunaInstanceAI.h"
using namespace Hooks;
#define START_HOOK(EVENT, AI) \
if (!IsEnabled())\
return;\
auto mapKey = EntryKey<InstanceEvents>(EVENT, AI->instance->GetId());\
auto instanceKey = EntryKey<InstanceEvents>(EVENT, AI->instance->GetInstanceId());\
if (!MapEventBindings->HasBindingsFor(mapKey) && !InstanceEventBindings->HasBindingsFor(instanceKey))\
return;\
LOCK_ELUNA;\
PushInstanceData(L, AI);\
Push(AI->instance)
#define START_HOOK_WITH_RETVAL(EVENT, AI, RETVAL) \
if (!IsEnabled())\
return RETVAL;\
auto mapKey = EntryKey<InstanceEvents>(EVENT, AI->instance->GetId());\
auto instanceKey = EntryKey<InstanceEvents>(EVENT, AI->instance->GetInstanceId());\
if (!MapEventBindings->HasBindingsFor(mapKey) && !InstanceEventBindings->HasBindingsFor(instanceKey))\
return RETVAL;\
LOCK_ELUNA;\
PushInstanceData(L, AI);\
Push(AI->instance)
void Eluna::OnInitialize(ElunaInstanceAI* ai)
{
START_HOOK(INSTANCE_EVENT_ON_INITIALIZE, ai);
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
}
void Eluna::OnLoad(ElunaInstanceAI* ai)
{
START_HOOK(INSTANCE_EVENT_ON_LOAD, ai);
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
}
void Eluna::OnUpdateInstance(ElunaInstanceAI* ai, uint32 diff)
{
START_HOOK(INSTANCE_EVENT_ON_UPDATE, ai);
Push(diff);
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
}
void Eluna::OnPlayerEnterInstance(ElunaInstanceAI* ai, Player* player)
{
START_HOOK(INSTANCE_EVENT_ON_PLAYER_ENTER, ai);
Push(player);
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
}
void Eluna::OnCreatureCreate(ElunaInstanceAI* ai, Creature* creature)
{
START_HOOK(INSTANCE_EVENT_ON_CREATURE_CREATE, ai);
Push(creature);
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
}
void Eluna::OnGameObjectCreate(ElunaInstanceAI* ai, GameObject* gameobject)
{
START_HOOK(INSTANCE_EVENT_ON_GAMEOBJECT_CREATE, ai);
Push(gameobject);
CallAllFunctions(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
}
bool Eluna::OnCheckEncounterInProgress(ElunaInstanceAI* ai)
{
START_HOOK_WITH_RETVAL(INSTANCE_EVENT_ON_CHECK_ENCOUNTER_IN_PROGRESS, ai, false);
return CallAllFunctionsBool(MapEventBindings, InstanceEventBindings, mapKey, instanceKey);
}