forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameObjectHooks.cpp
142 lines (125 loc) · 4.15 KB
/
GameObjectHooks.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
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
/*
* 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 "ElunaEventMgr.h"
#include "ElunaTemplate.h"
using namespace Hooks;
#define START_HOOK(EVENT, ENTRY) \
if (!IsEnabled())\
return;\
auto key = EntryKey<GameObjectEvents>(EVENT, ENTRY);\
if (!GameObjectEventBindings->HasBindingsFor(key))\
return;\
LOCK_ELUNA
#define START_HOOK_WITH_RETVAL(EVENT, ENTRY, RETVAL) \
if (!IsEnabled())\
return RETVAL;\
auto key = EntryKey<GameObjectEvents>(EVENT, ENTRY);\
if (!GameObjectEventBindings->HasBindingsFor(key))\
return RETVAL;\
LOCK_ELUNA
void Eluna::OnDummyEffect(WorldObject* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget)
{
START_HOOK(GAMEOBJECT_EVENT_ON_DUMMY_EFFECT, pTarget->GetEntry());
Push(pCaster);
Push(spellId);
Push(effIndex);
Push(pTarget);
CallAllFunctions(GameObjectEventBindings, key);
}
void Eluna::UpdateAI(GameObject* pGameObject, uint32 diff)
{
pGameObject->elunaEvents->Update(diff);
START_HOOK(GAMEOBJECT_EVENT_ON_AIUPDATE, pGameObject->GetEntry());
Push(pGameObject);
Push(diff);
CallAllFunctions(GameObjectEventBindings, key);
}
bool Eluna::OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest)
{
START_HOOK_WITH_RETVAL(GAMEOBJECT_EVENT_ON_QUEST_ACCEPT, pGameObject->GetEntry(), false);
Push(pPlayer);
Push(pGameObject);
Push(pQuest);
return CallAllFunctionsBool(GameObjectEventBindings, key);
}
bool Eluna::OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest, uint32 opt)
{
START_HOOK_WITH_RETVAL(GAMEOBJECT_EVENT_ON_QUEST_REWARD, pGameObject->GetEntry(), false);
Push(pPlayer);
Push(pGameObject);
Push(pQuest);
Push(opt);
return CallAllFunctionsBool(GameObjectEventBindings, key);
}
void Eluna::GetDialogStatus(const Player* pPlayer, const GameObject* pGameObject)
{
START_HOOK(GAMEOBJECT_EVENT_ON_DIALOG_STATUS, pGameObject->GetEntry());
Push(pPlayer);
Push(pGameObject);
CallAllFunctions(GameObjectEventBindings, key);
}
#ifndef CLASSIC
#ifndef TBC
void Eluna::OnDestroyed(GameObject* pGameObject, WorldObject* attacker)
{
START_HOOK(GAMEOBJECT_EVENT_ON_DESTROYED, pGameObject->GetEntry());
Push(pGameObject);
Push(attacker);
CallAllFunctions(GameObjectEventBindings, key);
}
void Eluna::OnDamaged(GameObject* pGameObject, WorldObject* attacker)
{
START_HOOK(GAMEOBJECT_EVENT_ON_DAMAGED, pGameObject->GetEntry());
Push(pGameObject);
Push(attacker);
CallAllFunctions(GameObjectEventBindings, key);
}
#endif
#endif
void Eluna::OnLootStateChanged(GameObject* pGameObject, uint32 state)
{
START_HOOK(GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE, pGameObject->GetEntry());
Push(pGameObject);
Push(state);
CallAllFunctions(GameObjectEventBindings, key);
}
void Eluna::OnGameObjectStateChanged(GameObject* pGameObject, uint32 state)
{
START_HOOK(GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED, pGameObject->GetEntry());
Push(pGameObject);
Push(state);
CallAllFunctions(GameObjectEventBindings, key);
}
void Eluna::OnSpawn(GameObject* pGameObject)
{
START_HOOK(GAMEOBJECT_EVENT_ON_SPAWN, pGameObject->GetEntry());
Push(pGameObject);
CallAllFunctions(GameObjectEventBindings, key);
}
void Eluna::OnAddToWorld(GameObject* pGameObject)
{
START_HOOK(GAMEOBJECT_EVENT_ON_ADD, pGameObject->GetEntry());
Push(pGameObject);
CallAllFunctions(GameObjectEventBindings, key);
}
void Eluna::OnRemoveFromWorld(GameObject* pGameObject)
{
START_HOOK(GAMEOBJECT_EVENT_ON_REMOVE, pGameObject->GetEntry());
Push(pGameObject);
CallAllFunctions(GameObjectEventBindings, key);
}
bool Eluna::OnGameObjectUse(Player* pPlayer, GameObject* pGameObject)
{
START_HOOK_WITH_RETVAL(GAMEOBJECT_EVENT_ON_USE, pGameObject->GetEntry(), false);
Push(pGameObject);
Push(pPlayer);
return CallAllFunctionsBool(GameObjectEventBindings, key);
}