1 |
root |
1.1 |
/*****************************************************************************/ |
2 |
|
|
/* Crossfire plugin support - (C) 2001 by Yann Chachkoff. */ |
3 |
|
|
/* This code is placed under the GPL. */ |
4 |
|
|
/*****************************************************************************/ |
5 |
|
|
|
6 |
|
|
/*****************************************************************************/ |
7 |
|
|
/* Headers needed. */ |
8 |
|
|
/*****************************************************************************/ |
9 |
|
|
|
10 |
|
|
#ifndef PLUGIN_H_ |
11 |
|
|
#define PLUGIN_H_ |
12 |
|
|
|
13 |
|
|
/*****************************************************************************/ |
14 |
|
|
/* This one does not exist under Win32. */ |
15 |
|
|
/*****************************************************************************/ |
16 |
|
|
#ifndef WIN32 |
17 |
|
|
#include <dlfcn.h> |
18 |
|
|
#endif |
19 |
|
|
|
20 |
|
|
#undef MODULEAPI |
21 |
|
|
#ifdef WIN32 |
22 |
|
|
#ifdef PYTHON_PLUGIN_EXPORTS |
23 |
|
|
#define MODULEAPI __declspec(dllexport) |
24 |
|
|
#else |
25 |
|
|
#define MODULEAPI __declspec(dllimport) |
26 |
|
|
#endif |
27 |
|
|
#else |
28 |
|
|
#define MODULEAPI |
29 |
|
|
#endif |
30 |
|
|
|
31 |
|
|
#include <global.h> |
32 |
|
|
#include <object.h> |
33 |
|
|
|
34 |
|
|
#ifdef HAVE_TIME_H |
35 |
|
|
#include <time.h> |
36 |
|
|
#endif |
37 |
|
|
#include <../random_maps/random_map.h> |
38 |
|
|
#include <../random_maps/rproto.h> |
39 |
|
|
|
40 |
|
|
|
41 |
|
|
/*****************************************************************************/ |
42 |
|
|
/* This one does not exist under Win32. */ |
43 |
|
|
/*****************************************************************************/ |
44 |
|
|
#ifndef WIN32 |
45 |
|
|
#include <dirent.h> |
46 |
|
|
#endif |
47 |
|
|
|
48 |
|
|
/*****************************************************************************/ |
49 |
|
|
/* Event ID codes. I sorted them to present local events first, but it is */ |
50 |
|
|
/* just a 'cosmetic' thing. */ |
51 |
|
|
/*****************************************************************************/ |
52 |
|
|
/*****************************************************************************/ |
53 |
|
|
/* Local events. Those are always linked to a specific object. */ |
54 |
|
|
/*****************************************************************************/ |
55 |
root |
1.2 |
// how about making this an enum |
56 |
root |
1.1 |
#define EVENT_NONE 0 /* No event. This exists only to reserve the "0". */ |
57 |
|
|
#define EVENT_APPLY 1 /* Object applied-unapplied. */ |
58 |
|
|
#define EVENT_ATTACK 2 /* Monster attacked or Scripted Weapon used. */ |
59 |
|
|
#define EVENT_DEATH 3 /* Player or monster dead. */ |
60 |
|
|
#define EVENT_DROP 4 /* Object dropped on the floor. */ |
61 |
|
|
#define EVENT_PICKUP 5 /* Object picked up. */ |
62 |
|
|
#define EVENT_SAY 6 /* Someone speaks. */ |
63 |
|
|
#define EVENT_STOP 7 /* Thrown object stopped. */ |
64 |
|
|
#define EVENT_TIME 8 /* Triggered each time the object can react/move. */ |
65 |
|
|
#define EVENT_THROW 9 /* Object is thrown. */ |
66 |
|
|
#define EVENT_TRIGGER 10 /* Button pushed, lever pulled, etc. */ |
67 |
|
|
#define EVENT_CLOSE 11 /* Container closed. */ |
68 |
|
|
#define EVENT_TIMER 12 /* Timer connected triggered it. */ |
69 |
root |
1.2 |
#define EVENT_MOVE 28 /* Monster move */ |
70 |
root |
1.1 |
/*****************************************************************************/ |
71 |
|
|
/* Global events. Those are never linked to a specific object. */ |
72 |
|
|
/*****************************************************************************/ |
73 |
|
|
#define EVENT_BORN 13 /* A new character has been created. */ |
74 |
|
|
#define EVENT_CLOCK 14 /* Global time event. */ |
75 |
|
|
#define EVENT_CRASH 15 /* Triggered when the server crashes. Not recursive*/ |
76 |
|
|
#define EVENT_PLAYER_DEATH 16 /* Global Death event */ |
77 |
|
|
#define EVENT_GKILL 17 /* Triggered when anything got killed by anyone. */ |
78 |
|
|
#define EVENT_LOGIN 18 /* Player login. */ |
79 |
|
|
#define EVENT_LOGOUT 19 /* Player logout. */ |
80 |
|
|
#define EVENT_MAPENTER 20 /* A player entered a map. */ |
81 |
|
|
#define EVENT_MAPLEAVE 21 /* A player left a map. */ |
82 |
|
|
#define EVENT_MAPRESET 22 /* A map is resetting. */ |
83 |
|
|
#define EVENT_REMOVE 23 /* A Player character has been removed. */ |
84 |
|
|
#define EVENT_SHOUT 24 /* A player 'shout' something. */ |
85 |
root |
1.2 |
#define EVENT_TELL 25 /* A player 'tell' something. */ |
86 |
|
|
#define EVENT_MUZZLE 26 /* A player was Muzzled (no_shout set). */ |
87 |
root |
1.1 |
#define EVENT_KICK 27 /* A player was Kicked by a DM */ |
88 |
root |
1.2 |
#define EVENT_FREE_OB 29 /* Object destroyed */ |
89 |
root |
1.4 |
#define EVENT_MAPLOAD 30 /* Original map has been loaded */ |
90 |
|
|
#define EVENT_MAPOUT 31 /* Map has been swapped out */ |
91 |
|
|
#define EVENT_MAPIN 32 /* Temporary map has been swapped in */ |
92 |
root |
1.2 |
/* should add FREE_MAP, FREE_PLAYER */ |
93 |
root |
1.1 |
|
94 |
root |
1.4 |
#define NR_EVENTS 33 |
95 |
root |
1.1 |
|
96 |
|
|
#include <stdarg.h> |
97 |
|
|
|
98 |
|
|
#define CFAPI_NONE 0 |
99 |
|
|
#define CFAPI_INT 1 |
100 |
|
|
#define CFAPI_LONG 2 |
101 |
|
|
#define CFAPI_CHAR 3 |
102 |
|
|
#define CFAPI_STRING 4 |
103 |
|
|
#define CFAPI_POBJECT 5 |
104 |
|
|
#define CFAPI_PMAP 6 |
105 |
|
|
#define CFAPI_FLOAT 7 |
106 |
|
|
#define CFAPI_DOUBLE 8 |
107 |
|
|
#define CFAPI_PARCH 9 |
108 |
|
|
#define CFAPI_FUNC 10 |
109 |
|
|
#define CFAPI_PPLAYER 11 |
110 |
|
|
#define CFAPI_PPARTY 12 |
111 |
|
|
#define CFAPI_PREGION 13 |
112 |
elmex |
1.3 |
#define CFAPI_INT16 14 |
113 |
root |
1.1 |
|
114 |
|
|
typedef void* (*f_plug_api) (int* type, ...); |
115 |
|
|
typedef int (*f_plug_postinit) (void); |
116 |
|
|
typedef int (*f_plug_init)(const char* iversion, f_plug_api gethooksptr); |
117 |
|
|
|
118 |
|
|
#ifndef WIN32 |
119 |
|
|
#define LIBPTRTYPE void* |
120 |
|
|
#else |
121 |
|
|
#define LIBPTRTYPE HMODULE |
122 |
|
|
#endif |
123 |
|
|
|
124 |
|
|
typedef struct _crossfire_plugin |
125 |
|
|
{ |
126 |
|
|
f_plug_api eventfunc; /* Event Handler function */ |
127 |
|
|
f_plug_api propfunc; /* Plugin getProperty function */ |
128 |
|
|
f_plug_postinit closefunc; /* Plugin Termination function */ |
129 |
|
|
LIBPTRTYPE libptr; /* Pointer to the plugin library */ |
130 |
|
|
char id[MAX_BUF]; /* Plugin identification string */ |
131 |
|
|
char fullname[MAX_BUF]; /* Plugin full name */ |
132 |
|
|
f_plug_api gevent[NR_EVENTS]; /* Global events registered */ |
133 |
|
|
struct _crossfire_plugin *next; |
134 |
|
|
struct _crossfire_plugin *prev; |
135 |
|
|
} crossfire_plugin; |
136 |
|
|
|
137 |
|
|
extern int plugin_number; |
138 |
|
|
extern crossfire_plugin* plugins_list; |
139 |
|
|
|
140 |
|
|
#ifdef WIN32 |
141 |
|
|
|
142 |
|
|
#define plugins_dlopen(fname) LoadLibrary(fname) |
143 |
|
|
#define plugins_dlclose(lib) FreeLibrary(lib) |
144 |
|
|
#define plugins_dlsym(lib,name) GetProcAddress(lib,name) |
145 |
|
|
|
146 |
|
|
#else /*WIN32 */ |
147 |
|
|
|
148 |
|
|
#define plugins_dlopen(fname) dlopen(fname,RTLD_NOW|RTLD_GLOBAL) |
149 |
|
|
#define plugins_dlclose(lib) dlclose(lib) |
150 |
|
|
#define plugins_dlsym(lib,name) dlsym(lib,name) |
151 |
|
|
#define plugins_dlerror() dlerror() |
152 |
|
|
#endif /* WIN32 */ |
153 |
|
|
|
154 |
|
|
|
155 |
|
|
/* OBJECT-RELATED HOOKS */ |
156 |
|
|
|
157 |
|
|
#define CFAPI_OBJECT_PROP_OB_ABOVE 1 |
158 |
|
|
#define CFAPI_OBJECT_PROP_OB_BELOW 2 |
159 |
|
|
#define CFAPI_OBJECT_PROP_NEXT_ACTIVE_OB 3 |
160 |
|
|
#define CFAPI_OBJECT_PROP_PREV_ACTIVE_OB 4 |
161 |
|
|
#define CFAPI_OBJECT_PROP_INVENTORY 5 |
162 |
|
|
#define CFAPI_OBJECT_PROP_ENVIRONMENT 6 |
163 |
|
|
#define CFAPI_OBJECT_PROP_HEAD 7 |
164 |
|
|
#define CFAPI_OBJECT_PROP_CONTAINER 8 |
165 |
|
|
#define CFAPI_OBJECT_PROP_MAP 9 |
166 |
|
|
#define CFAPI_OBJECT_PROP_COUNT 10 |
167 |
|
|
#define CFAPI_OBJECT_PROP_REFCOUNT 11 |
168 |
|
|
#define CFAPI_OBJECT_PROP_NAME 12 |
169 |
|
|
#define CFAPI_OBJECT_PROP_NAME_PLURAL 13 |
170 |
|
|
#define CFAPI_OBJECT_PROP_TITLE 14 |
171 |
|
|
#define CFAPI_OBJECT_PROP_RACE 15 |
172 |
|
|
#define CFAPI_OBJECT_PROP_SLAYING 16 |
173 |
|
|
#define CFAPI_OBJECT_PROP_SKILL 17 |
174 |
|
|
#define CFAPI_OBJECT_PROP_MESSAGE 18 |
175 |
|
|
#define CFAPI_OBJECT_PROP_LORE 19 |
176 |
|
|
#define CFAPI_OBJECT_PROP_X 20 |
177 |
|
|
#define CFAPI_OBJECT_PROP_Y 21 |
178 |
|
|
#define CFAPI_OBJECT_PROP_SPEED 22 |
179 |
|
|
#define CFAPI_OBJECT_PROP_SPEED_LEFT 23 |
180 |
|
|
#define CFAPI_OBJECT_PROP_NROF 24 |
181 |
|
|
#define CFAPI_OBJECT_PROP_DIRECTION 25 |
182 |
|
|
#define CFAPI_OBJECT_PROP_FACING 26 |
183 |
|
|
#define CFAPI_OBJECT_PROP_TYPE 27 |
184 |
|
|
#define CFAPI_OBJECT_PROP_SUBTYPE 28 |
185 |
|
|
#define CFAPI_OBJECT_PROP_CLIENT_TYPE 29 |
186 |
|
|
#define CFAPI_OBJECT_PROP_RESIST 30 |
187 |
|
|
#define CFAPI_OBJECT_PROP_ATTACK_TYPE 31 |
188 |
|
|
#define CFAPI_OBJECT_PROP_PATH_ATTUNED 32 |
189 |
|
|
#define CFAPI_OBJECT_PROP_PATH_REPELLED 33 |
190 |
|
|
#define CFAPI_OBJECT_PROP_PATH_DENIED 34 |
191 |
|
|
#define CFAPI_OBJECT_PROP_MATERIAL 35 |
192 |
|
|
#define CFAPI_OBJECT_PROP_MATERIAL_NAME 36 |
193 |
|
|
#define CFAPI_OBJECT_PROP_MAGIC 37 |
194 |
|
|
#define CFAPI_OBJECT_PROP_VALUE 38 |
195 |
|
|
#define CFAPI_OBJECT_PROP_LEVEL 39 |
196 |
|
|
#define CFAPI_OBJECT_PROP_LAST_HEAL 40 |
197 |
|
|
#define CFAPI_OBJECT_PROP_LAST_SP 41 |
198 |
|
|
#define CFAPI_OBJECT_PROP_LAST_GRACE 42 |
199 |
|
|
#define CFAPI_OBJECT_PROP_LAST_EAT 43 |
200 |
|
|
#define CFAPI_OBJECT_PROP_INVISIBLE_TIME 44 |
201 |
|
|
#define CFAPI_OBJECT_PROP_PICK_UP 45 |
202 |
|
|
#define CFAPI_OBJECT_PROP_ITEM_POWER 46 |
203 |
|
|
#define CFAPI_OBJECT_PROP_GEN_SP_ARMOUR 47 |
204 |
|
|
#define CFAPI_OBJECT_PROP_WEIGHT 48 |
205 |
|
|
#define CFAPI_OBJECT_PROP_WEIGHT_LIMIT 49 |
206 |
|
|
#define CFAPI_OBJECT_PROP_CARRYING 50 |
207 |
|
|
#define CFAPI_OBJECT_PROP_GLOW_RADIUS 51 |
208 |
|
|
#define CFAPI_OBJECT_PROP_PERM_EXP 52 |
209 |
|
|
#define CFAPI_OBJECT_PROP_CURRENT_WEAPON 53 |
210 |
|
|
#define CFAPI_OBJECT_PROP_ENEMY 54 |
211 |
|
|
#define CFAPI_OBJECT_PROP_ATTACKED_BY 55 |
212 |
|
|
#define CFAPI_OBJECT_PROP_RUN_AWAY 56 |
213 |
|
|
#define CFAPI_OBJECT_PROP_CHOSEN_SKILL 57 |
214 |
|
|
#define CFAPI_OBJECT_PROP_HIDDEN 58 |
215 |
|
|
#define CFAPI_OBJECT_PROP_MOVE_STATUS 59 |
216 |
|
|
#define CFAPI_OBJECT_PROP_MOVE_TYPE 60 |
217 |
|
|
#define CFAPI_OBJECT_PROP_SPELL_ITEM 61 |
218 |
|
|
#define CFAPI_OBJECT_PROP_EXP_MULTIPLIER 62 |
219 |
|
|
#define CFAPI_OBJECT_PROP_ARCHETYPE 63 |
220 |
|
|
#define CFAPI_OBJECT_PROP_OTHER_ARCH 64 |
221 |
|
|
#define CFAPI_OBJECT_PROP_CUSTOM_NAME 65 |
222 |
|
|
#define CFAPI_OBJECT_PROP_ANIM_SPEED 66 |
223 |
|
|
#define CFAPI_OBJECT_PROP_FRIENDLY 67 |
224 |
|
|
#define CFAPI_OBJECT_PROP_SHORT_NAME 68 |
225 |
|
|
#define CFAPI_OBJECT_PROP_BASE_NAME 69 |
226 |
|
|
#define CFAPI_OBJECT_PROP_MAGICAL 70 |
227 |
|
|
#define CFAPI_OBJECT_PROP_LUCK 71 |
228 |
|
|
#define CFAPI_OBJECT_PROP_EXP 72 |
229 |
|
|
#define CFAPI_OBJECT_PROP_OWNER 73 |
230 |
|
|
#define CFAPI_OBJECT_PROP_PRESENT 74 |
231 |
|
|
#define CFAPI_OBJECT_PROP_CHEATER 75 |
232 |
|
|
#define CFAPI_OBJECT_PROP_MERGEABLE 76 |
233 |
|
|
#define CFAPI_OBJECT_PROP_PICKABLE 77 |
234 |
|
|
#define CFAPI_OBJECT_PROP_FLAGS 78 |
235 |
|
|
#define CFAPI_OBJECT_PROP_STR 79 |
236 |
|
|
#define CFAPI_OBJECT_PROP_DEX 80 |
237 |
|
|
#define CFAPI_OBJECT_PROP_CON 81 |
238 |
|
|
#define CFAPI_OBJECT_PROP_WIS 82 |
239 |
|
|
#define CFAPI_OBJECT_PROP_INT 83 |
240 |
|
|
#define CFAPI_OBJECT_PROP_POW 84 |
241 |
|
|
#define CFAPI_OBJECT_PROP_CHA 85 |
242 |
|
|
#define CFAPI_OBJECT_PROP_WC 86 |
243 |
|
|
#define CFAPI_OBJECT_PROP_AC 87 |
244 |
|
|
#define CFAPI_OBJECT_PROP_HP 88 |
245 |
|
|
#define CFAPI_OBJECT_PROP_SP 89 |
246 |
|
|
#define CFAPI_OBJECT_PROP_GP 90 |
247 |
|
|
#define CFAPI_OBJECT_PROP_FP 91 |
248 |
|
|
#define CFAPI_OBJECT_PROP_MAXHP 92 |
249 |
|
|
#define CFAPI_OBJECT_PROP_MAXSP 93 |
250 |
|
|
#define CFAPI_OBJECT_PROP_MAXGP 94 |
251 |
|
|
#define CFAPI_OBJECT_PROP_DAM 95 |
252 |
|
|
#define CFAPI_OBJECT_PROP_GOD 96 |
253 |
|
|
#define CFAPI_OBJECT_PROP_ARCH_NAME 97 |
254 |
|
|
#define CFAPI_OBJECT_PROP_INVISIBLE 98 |
255 |
|
|
#define CFAPI_OBJECT_PROP_FACE 99 |
256 |
|
|
#define CFAPI_OBJECT_ANIMATION 100 |
257 |
|
|
#define CFAPI_PLAYER_PROP_IP 150 |
258 |
|
|
#define CFAPI_PLAYER_PROP_MARKED_ITEM 151 |
259 |
|
|
#define CFAPI_PLAYER_PROP_PARTY 152 |
260 |
|
|
|
261 |
|
|
#define CFAPI_MAP_PROP_FLAGS 0 |
262 |
|
|
#define CFAPI_MAP_PROP_DIFFICULTY 1 |
263 |
|
|
#define CFAPI_MAP_PROP_PATH 2 |
264 |
|
|
#define CFAPI_MAP_PROP_TMPNAME 3 |
265 |
|
|
#define CFAPI_MAP_PROP_NAME 4 |
266 |
|
|
#define CFAPI_MAP_PROP_RESET_TIME 5 |
267 |
|
|
#define CFAPI_MAP_PROP_RESET_TIMEOUT 6 |
268 |
|
|
#define CFAPI_MAP_PROP_PLAYERS 7 |
269 |
|
|
#define CFAPI_MAP_PROP_LIGHT 8 |
270 |
|
|
#define CFAPI_MAP_PROP_DARKNESS 9 |
271 |
|
|
#define CFAPI_MAP_PROP_WIDTH 10 |
272 |
|
|
#define CFAPI_MAP_PROP_HEIGHT 11 |
273 |
|
|
#define CFAPI_MAP_PROP_ENTER_X 12 |
274 |
|
|
#define CFAPI_MAP_PROP_ENTER_Y 13 |
275 |
|
|
#define CFAPI_MAP_PROP_TEMPERATURE 14 |
276 |
|
|
#define CFAPI_MAP_PROP_PRESSURE 15 |
277 |
|
|
#define CFAPI_MAP_PROP_HUMIDITY 16 |
278 |
|
|
#define CFAPI_MAP_PROP_WINDSPEED 17 |
279 |
|
|
#define CFAPI_MAP_PROP_WINDDIR 18 |
280 |
|
|
#define CFAPI_MAP_PROP_SKY 19 |
281 |
|
|
#define CFAPI_MAP_PROP_WPARTX 20 |
282 |
|
|
#define CFAPI_MAP_PROP_WPARTY 21 |
283 |
|
|
#define CFAPI_MAP_PROP_MESSAGE 22 |
284 |
|
|
#define CFAPI_MAP_PROP_NEXT 23 |
285 |
|
|
#define CFAPI_MAP_PROP_REGION 24 |
286 |
|
|
|
287 |
|
|
#define CFAPI_ARCH_PROP_NAME 0 |
288 |
|
|
#define CFAPI_ARCH_PROP_NEXT 1 |
289 |
|
|
#define CFAPI_ARCH_PROP_HEAD 2 |
290 |
|
|
#define CFAPI_ARCH_PROP_MORE 3 |
291 |
|
|
#define CFAPI_ARCH_PROP_CLONE 4 |
292 |
|
|
|
293 |
|
|
#define CFAPI_PARTY_PROP_NAME 0 |
294 |
|
|
#define CFAPI_PARTY_PROP_NEXT 1 |
295 |
|
|
#define CFAPI_PARTY_PROP_PASSWORD 2 |
296 |
|
|
#define CFAPI_PARTY_PROP_PLAYER 3 |
297 |
|
|
|
298 |
|
|
#define CFAPI_REGION_PROP_NAME 0 |
299 |
|
|
#define CFAPI_REGION_PROP_NEXT 1 |
300 |
|
|
#define CFAPI_REGION_PROP_PARENT 2 |
301 |
|
|
#define CFAPI_REGION_PROP_LONGNAME 3 |
302 |
|
|
#define CFAPI_REGION_PROP_MESSAGE 4 |
303 |
|
|
|
304 |
|
|
/*****************************************************************************/ |
305 |
|
|
/* Exportable functions. Any plugin should define all those. */ |
306 |
|
|
/* initPlugin is called when the plugin initialization process starts.*/ |
307 |
|
|
/* endPlugin is called before the plugin gets unloaded from memory. */ |
308 |
|
|
/* getPluginProperty is currently unused. */ |
309 |
|
|
/* registerHook is used to transmit hook pointers from server to plugin.*/ |
310 |
|
|
/* triggerEvent is called whenever an event occurs. */ |
311 |
|
|
/*****************************************************************************/ |
312 |
|
|
/*extern MODULEAPI CFParm* initPlugin(CFParm* PParm); |
313 |
|
|
extern MODULEAPI CFParm* endPlugin(CFParm* PParm); |
314 |
|
|
extern MODULEAPI CFParm* getPluginProperty(CFParm* PParm); |
315 |
|
|
extern MODULEAPI CFParm* registerHook(CFParm* PParm); |
316 |
|
|
extern MODULEAPI CFParm* triggerEvent(CFParm* PParm); |
317 |
|
|
*/ |
318 |
|
|
|
319 |
|
|
typedef struct _hook_entry |
320 |
|
|
{ |
321 |
|
|
f_plug_api func; |
322 |
|
|
int fid; |
323 |
|
|
char fname[256]; |
324 |
|
|
} hook_entry; |
325 |
|
|
|
326 |
|
|
#endif /*PLUGIN_H_*/ |