summaryrefslogtreecommitdiff
path: root/src/emap/init.c
blob: 0c5707e545d9035b1ff1fb1fadac98f72b6a386e (plain) (blame)
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
// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// Copyright (c) 2014 - 2015 Evol developers

#include "common/hercules.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "common/conf.h"
#include "common/HPMi.h"
#include "common/memmgr.h"
#include "common/mapindex.h"
#include "common/mmo.h"
#include "common/nullpo.h"
#include "common/socket.h"
#include "common/strlib.h"
#include "common/timer.h"
#include "map/channel.h"
#include "map/chat.h"
#include "map/chrif.h"
#include "map/clif.h"
#include "map/duel.h"
#include "map/elemental.h"
#include "map/homunculus.h"
#include "map/guild.h"
#include "map/instance.h"
#include "map/intif.h"
#include "map/irc-bot.h"
#include "map/itemdb.h"
#include "map/mail.h"
#include "map/mapreg.h"
#include "map/mercenary.h"
#include "map/mob.h"
#include "map/npc.h"
#include "map/party.h"
#include "map/pet.h"
#include "map/pc.h"
#include "map/script.h"
#include "map/storage.h"
#include "map/trade.h"
#include "map/quest.h"

#include "ecommon/config.h"
#include "ecommon/init.h"
#include "emap/atcommand.h"
#include "emap/battleground.h"
#include "emap/clif.h"
#include "emap/config.h"
#include "emap/craft.h"
#include "emap/craftconf.h"
#include "emap/hashtable.h"
#include "emap/itemdb.h"
#include "emap/lang.h"
#include "emap/mail.h"
#include "emap/map.h"
#include "emap/mob.h"
#include "emap/npc.h"
#include "emap/unit.h"
#include "emap/parse.h"
#include "emap/permission.h"
#include "emap/pc.h"
#include "emap/quest.h"
#include "emap/script.h"
#include "emap/script_buildins.h"
#include "emap/skill.h"
#include "emap/status.h"

#include "emap/data/skilld.h"

#include "plugins/HPMHooking.h"
#include "common/HPMDataCheck.h" /* should always be the last file included! (if you don't make it last, it'll intentionally break compile time) */

extern int langScriptId;
extern int mountScriptId;
bool isInit;

HPExport struct hplugin_info pinfo =
{
    "evol_map",
    SERVER_TYPE_MAP,
    "0.1",
    HPM_VERSION
};

HPExport void plugin_init (void)
{
    isInit = false;
    htreg_init();
    skilld_init();

    addAtcommand("setskill", setSkill);
    addAtcommand("slide", slide);
    addAtcommand("mapexit", mapExit);

    addScriptCommand("chatjoin", "i*", chatJoin);
    addScriptCommand("setcamnpc", "*", setCamNpc);
    addScriptCommand("setcam", "ii", setCam);
    addScriptCommand("movecam", "ii", moveCam);
    addScriptCommand("restorecam", "", restoreCam);
    addScriptCommand("npctalk3", "s", npcTalk3);
    addScriptCommand("closedialog", "", closeDialog);
    addScriptCommand("shop", "s", shop);
    addScriptCommand("getitemlink", "v*", getItemLink);
    addScriptCommand("getinvindexlink", "i", getInvIndexLink);
    addScriptCommand("l", "s*", l);
    addScriptCommand("lg", "s*", lg);
    addScriptCommand("requestlang", "", requestLang);
    addScriptCommand("requestitem", "", requestItem);
    addScriptCommand("requestitems", "*", requestItems);
    addScriptCommand("requestitemindex", "", requestItemIndex);
    addScriptCommand("requestitemsindex", "*", requestItemsIndex);
    addScriptCommand("requestcraft", "*", requestCraft);
    addScriptCommand("initcraft", "s", initCraft);
    addScriptCommand("dumpcraft", "i", dumpCraft);
    addScriptCommand("deletecraft", "i", deleteCraft);
    addScriptCommand("findcraftentry", "ii", findCraftEntry);
    addScriptCommand("usecraft", "i", useCraft);
    addScriptCommand("getcraftcode", "i", getCraftCode);
    addScriptCommand("getcraftslotid", "ii", getCraftSlotId);
    addScriptCommand("getcraftslotamount", "ii", getCraftSlotAmount);
    addScriptCommand("validatecraft", "i", validateCraft);
    addScriptCommand("getq", "i", getq);
    addScriptCommand("setq", "ii", setq);
    addScriptCommand("setnpcdir", "*", setNpcDir);
    addScriptCommand("npcsit", "*", npcSit);
    addScriptCommand("npcstand", "*", npcStand);
    addScriptCommand("npcwalkto", "ii", npcWalkTo);
    addScriptCommand("rif", "is*", rif);
    addScriptCommand("misceffect", "i*", miscEffect);
    addScriptCommand("setmapmask", "si", setMapMask);
    addScriptCommand("addmapmask", "si", addMapMask);
    addScriptCommand("removemapmask", "si", removeMapMask);
    addScriptCommand("getmapmask", "s", getMapMask);
    addScriptCommand("setnpcsex", "si", setNpcSex);
    addScriptCommand("showavatar", "*", showAvatar);
    addScriptCommand("setavatardir", "i", setAvatarDir);
    addScriptCommand("setavataraction", "i", setAvatarAction);
    addScriptCommand("clear", "", clear);
    addScriptCommand("changemusic", "ss", changeMusic);
    addScriptCommand("setnpcdialogtitle", "s", setNpcDialogTitle);
    addScriptCommand("getmapname", "", getMapName);
    addScriptCommand("unequipbyid", "i", unequipById);
    addScriptCommand("ispcdead", "", isPcDead);
    addScriptCommand("areatimer", "siiiii*", areaTimer);
    addScriptCommand("getareadropitem", "siiiiv*", getAreaDropItem);
    addScriptCommand("clientcommand", "s", clientCommand);
    addScriptCommand("isunitwalking", "?", isUnitWalking);
    addScriptCommand("failedrefindex", "i", failedRefIndex);
    addScriptCommand("downrefindex", "ii", downRefIndex);
    addScriptCommand("successrefindex", "ii", successRefIndex);
    addScriptCommand("successremovecardsindex", "i", successRemoveCardsIndex);
    addScriptCommand("failedremovecardsindex", "ii", failedRemoveCardsIndex);
    addScriptCommand("getcardbyindex", "ii", getCardByIndex);
    addScriptCommand("removecardbyindex", "ii", removeCardByIndex);
    addScriptCommand("isstr", "v", isStr);
    addScriptCommand("setbgteam", "ii", setBgTeam);
    addScriptCommand("checknpccell", "siii", checkNpcCell);
    addScriptCommand("setcells", "siiiiis", setCells);
    addScriptCommand("delcells", "s", delCells);
    addScriptCommand("setmount", "i", setMount);
    addScriptCommand("setskin", "s", setSkin);
    addScriptCommand("emotion", "i??", emotion);
    addScriptCommand("setlook", "ii", setLook);
    addScriptCommand("htnew", "", htNew);
    addScriptCommand("htget", "is?", htGet);
    addScriptCommand("htput", "isv", htPut);
    addScriptCommand("htclear", "i", htClear);
    addScriptCommand("htdelete", "i", htDelete);
    addScriptCommand("htsize", "i", htSize);
    addScriptCommand("htiterator", "i", htIterator);
    addScriptCommand("htinextkey", "i", htiNextKey);
    addScriptCommand("hticheck", "i", htiCheck);
    addScriptCommand("htidelete", "i", htiDelete);
    addScriptCommand("setfakecells", "iii??", setFakeCells);

    do_init_langs();

    addPacket(0x7530, 22, map_parse_version, hpClif_Parse);
    addPacket(0xb07, 26, map_parse_join_channel, hpClif_Parse);
    addPacket(0xb09, 26, map_parse_part_channel, hpClif_Parse);
    addPacket(0xb0c, -1, map_parse_pet_say, hpClif_Parse);
    addPacket(0xb0d, 3, map_parse_pet_emote, hpClif_Parse);
    addPacket(0xb0e, 4, map_parse_set_status, hpClif_Parse);
    addPacket(0xb0f, 2, map_parse_get_online_list, hpClif_Parse);
    addPacket(0xb11, 10, map_parse_pet_move, hpClif_Parse);
    addPacket(0xb12, 9, map_parse_pet_dir, hpClif_Parse);
    addPacket(0xb13, -1, map_parse_homun_say, hpClif_Parse);
    addPacket(0xb14, 3, map_parse_homun_emote, hpClif_Parse);
    addPacket(0xb15, 9, map_parse_homun_dir, hpClif_Parse);

    addHookPre(atcommand, msgfd, eatcommand_msgfd_pre);
    addHookPre(atcommand, msgsd, eatcommand_msgsd_pre);
    addHookPre(bg, team_warp, ebg_team_warp_pre);
    addHookPre(pc, can_Adopt, epc_can_Adopt_pre);
    addHookPre(pc, adoption, epc_adoption_pre);
    addHookPre(pc, readparam, epc_readparam_pre);
    addHookPre(pc, setregistry, epc_setregistry_pre);
    addHookPre(pc, equipitem_pos, epc_equipitem_pos_pre);
    addHookPre(pc, unequipitem_pos, epc_unequipitem_pos_pre);
    addHookPre(pc, can_attack, epc_can_attack_pre);
    addHookPre(pc, takeitem, epc_takeitem_pre);
    addHookPre(pc, validate_levels, epc_validate_levels_pre);
    addHookPre(pc, check_job_name, epc_check_job_name_pre);
    addHookPre(pc, delitem, epc_delitem_pre);
    addHookPre(pc, dropitem, epc_dropitem_pre);
    addHookPre(pc, insert_card, epc_insert_card_pre);
    addHookPre(pc, process_chat_message, epc_process_chat_message_pre);
    addHookPre(mob, deleteslave_sub, emob_deleteslave_sub_pre);
    addHookPre(mob, read_db_additional_fields, emob_read_db_additional_fields_pre);
    addHookPre(npc, parse_unknown_mapflag, enpc_parse_unknown_mapflag_pre);
    addHookPre(npc, buysellsel, enpc_buysellsel_pre);
    addHookPre(npc, db_checkid, enpc_db_checkid_pre);
    addHookPre(npc, duplicate_script_sub, enpc_duplicate_script_sub_pre);
    addHookPre(npc, unload, enpc_unload_pre);
    addHookPre(clif, quest_send_list, eclif_quest_send_list_pre);
    addHookPre(clif, quest_add, eclif_quest_add_pre);
    addHookPre(clif, charnameack, eclif_charnameack_pre);
    addHookPre(clif, getareachar_item, eclif_getareachar_item_pre);
    addHookPre(clif, dropflooritem, eclif_dropflooritem_pre);
    addHookPre(clif, disp_message, eclif_disp_message_pre);
    addHookPre(clif, sendlook, eclif_sendlook_pre);
    addHookPre(clif, send, eclif_send_pre);
    addHookPre(clif, sendbgemblem_area, eclif_sendbgemblem_area_pre);
    addHookPre(clif, sendbgemblem_single, eclif_sendbgemblem_single_pre);
    addHookPre(clif, set_unit_idle, eclif_set_unit_idle_pre);
    addHookPre(clif, set_unit_walking, eclif_set_unit_walking_pre);
    addHookPre(clif, send_actual, eclif_send_actual_pre);
    addHookPre(clif, pLoadEndAck, eclif_parse_LoadEndAck_pre);
    addHookPre(clif, spawn_unit, eclif_spawn_unit_pre);
    addHookPre(itemdb, is_item_usable, eitemdb_is_item_usable_pre);
    addHookPre(itemdb, readdb_additional_fields, eitemdb_readdb_additional_fields_pre);
    addHookPre(itemdb, destroy_item_data, edestroy_item_data_pre);
    addHookPre(unit, can_move, eunit_can_move_pre);
    addHookPre(unit, walktoxy, eunit_walktoxy_pre);
    addHookPre(mail, invalid_operation, email_invalid_operation_pre);
    addHookPre(map, list_final, edo_final_maps_pre);
    addHookPre(map, cell2gat, emap_cell2gat_pre);
    addHookPre(map, gat2cell, emap_gat2cell_pre);
    addHookPre(map, getcellp, emap_getcellp_pre);
    addHookPre(map, setgatcell, emap_setgatcell_pre);
    addHookPre(map, iwall_set, emap_iwall_set_pre);
    addHookPre(map, iwall_get, emap_iwall_get_pre);
    addHookPre(map, iwall_remove, emap_iwall_remove_pre);
    addHookPre(script, get_val_npc_num, eget_val_npcscope_num_pre);
    addHookPre(script, get_val_ref_num, eget_val_npcscope_num_pre);
    addHookPre(script, get_val_npc_str, eget_val_npcscope_str_pre);
    addHookPre(script, get_val_ref_str, eget_val_npcscope_str_pre);
    addHookPre(script, set_reg_npc_num, eset_reg_npcscope_num_pre);
    addHookPre(script, set_reg_ref_num, eset_reg_npcscope_num_pre);
    addHookPre(script, set_reg_npc_str, eset_reg_npcscope_str_pre);
    addHookPre(script, set_reg_ref_str, eset_reg_npcscope_str_pre);
    addHookPre(script, reload, escript_reload_pre);
    addHookPre(script, load_translations, escript_load_translations_pre);
    addHookPre(script, load_parameters, escript_load_parameters_pre);
    addHookPre(script, hardcoded_constants, escript_hardcoded_constants_pre);
    addHookPre(status, calc_pc_additional, estatus_calc_pc_additional_pre);
    addHookPre(status, set_viewdata, estatus_set_viewdata_pre);

    addHookPost(clif, addcards, eclif_addcards_post);
    addHookPost(clif, addcards2, eclif_addcards2_post);
    addHookPost(clif, getareachar_unit, eclif_getareachar_unit_post);
    addHookPost(clif, authok, eclif_authok_post);
    addHookPost(clif, changemap, eclif_changemap_post);
    addHookPost(clif, set_unit_idle, eclif_set_unit_idle_post);
    addHookPost(clif, pLoadEndAck, eclif_parse_LoadEndAck_post);
    addHookPost(clif, spawn, eclif_spawn_post);
    addHookPost(clif, damage, eclif_damage_post);
    addHookPost(clif, set_unit_walking, eclif_set_unit_walking_post);
    addHookPost(clif, move, eclif_move_post);
    addHookPost(status, init, estatus_init_post);
    addHookPost(status, set_viewdata, estatus_set_viewdata_post);
    addHookPost(status, read_job_db_sub, estatus_read_job_db_sub_post);
    addHookPost(status, calc_pc_, estatus_calc_pc__post);
    addHookPost(status, calc_speed, estatus_calc_speed_post);
    addHookPost(status, calc_def, estatus_calc_def_post);
    addHookPost(status, calc_fix_aspd, estatus_calc_fix_aspd_post);
    addHookPost(status, change_start, estatus_change_start_post);
    addHookPost(status, change_end_, estatus_change_end__post);
    addHookPost(status, readdb_scconfig, estatus_readdb_scconfig_post);
    addHookPost(map, addflooritem, emap_addflooritem_post);
    addHookPost(mob, read_db_mode_sub, emob_read_db_mode_sub_post);
    addHookPost(npc, get_viewdata, enpc_get_viewdata_post);
    addHookPost(skill, check_condition_castend, eskill_check_condition_castend_post);
    addHookPost(skill, get_index, eskill_get_index_post);
    addHookPost(pc, additem, epc_additem_post);
    addHookPost(pc, isequip, epc_isequip_post);
    addHookPost(pc, isUseitem, epc_isequip_post);
    addHookPost(pc, useitem, epc_useitem_post);
    addHookPost(pc, equipitem, epc_equipitem_post);
    addHookPost(pc, unequipitem, epc_unequipitem_post);
    addHookPost(pc, setnewpc, epc_setnewpc_post);
    addHookPost(pc, dead, epc_dead_post);
    addHookPost(pc, delitem, epc_delitem_post);
    addHookPost(pc, dropitem, epc_dropitem_post);
    addHookPost(pc, takeitem, epc_takeitem_post);
    addHookPost(pc, can_insert_card_into, epc_can_insert_card_into_post);
    addHookPost(pc, insert_card, epc_insert_card_post);

    skill->castend_nodamage_id_unknown = eskill_castend_nodamage_id_unknown;
    skill->additional_effect_unknown = eskill_additional_effect_unknown;
    skill->counter_additional_effect_unknown = eskill_counter_additional_effect_unknown;
    skill->attack_combo2_unknown = eskill_attack_combo2_unknown;
    skill->attack_post_unknown = eskill_attack_post_unknown;
    skill->timerskill_notarget_unknown = eskill_timerskill_notarget_unknown;
    skill->unitsetting1_unknown = eskill_unitsetting1_unknown;
    skill->unit_onplace_unknown = eskill_unit_onplace_unknown;
    skill->check_condition_castend_unknown = eskill_check_condition_castend_unknown;
    skill->get_requirement_unknown = eskill_get_requirement_unknown;
    skill->castend_pos2_unknown = eskill_castend_pos2_unknown;
    skill->validate_additional_fields = eskill_validate_additional_fields;

    langScriptId = script->add_str("Lang");
    mountScriptId = script->add_str("mount");

    isInit = true;
}

HPExport void server_preinit (void)
{
    interfaces_init_common();
    htreg_defaults();

    setDefaultMap();
    addMapInterConf("default_map", config_default_map);
    addMapInterConf("default_x", config_default_x);
    addMapInterConf("default_y", config_default_y);
    addMapInterConf("warn_missing_translation", config_warn_missing_translation);

    addHookPre(quest, read_db_sub, equest_read_db_sub_pre);

    addGroupPermission("send_gm", permission_send_gm_flag);
    addGroupPermission("show_client_version", permission_show_client_version_flag);
}

HPExport void server_online (void)
{
    do_init_craft();
    do_init_craftconf();
    common_online();
}

HPExport void plugin_final (void)
{
    do_final_langs();
    do_final_craft();
    do_final_craftconf();
    commonClean();
    htreg_final();
    isInit = false;
}