summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c25
-rw-r--r--src/char/int_guild.c2
-rw-r--r--src/common/HPM.c4
-rw-r--r--src/common/HPM.h2
-rw-r--r--src/common/mmo.h3
-rw-r--r--src/login/login.c12
-rw-r--r--src/map/atcommand.c18
-rw-r--r--src/map/chrif.c6
-rw-r--r--src/map/clif.c16
-rw-r--r--src/map/guild.c2
-rw-r--r--src/map/script.c40
-rw-r--r--src/map/script.h1
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc4
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc1
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.Hooks.inc26
-rw-r--r--src/plugins/constdb2doc.c197
16 files changed, 310 insertions, 49 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 09f74034c..d05d13d4b 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -2637,11 +2637,11 @@ int char_parse_fromlogin(int fd) {
}
}
- while(RFIFOREST(fd) >= 2) {
+ while (RFIFOREST(fd) >= 2) {
uint16 command = RFIFOW(fd,0);
if (VECTOR_LENGTH(HPM->packets[hpParse_FromLogin]) > 0) {
- int result = HPM->parse_packets(fd,hpParse_FromLogin);
+ int result = HPM->parse_packets(fd,command,hpParse_FromLogin);
if (result == 1)
continue;
if (result == 2)
@@ -3926,16 +3926,17 @@ int char_parse_frommap(int fd)
return 0;
}
- while(RFIFOREST(fd) >= 2) {
+ while (RFIFOREST(fd) >= 2) {
+ int packet_id = RFIFOW(fd,0);
if (VECTOR_LENGTH(HPM->packets[hpParse_FromMap]) > 0) {
- int result = HPM->parse_packets(fd,hpParse_FromMap);
+ int result = HPM->parse_packets(fd,packet_id,hpParse_FromMap);
if (result == 1)
continue;
if (result == 2)
return 0;
}
- switch(RFIFOW(fd,0)) {
+ switch (packet_id) {
case 0x2b0a:
if( RFIFOREST(fd) < RFIFOW(fd, 2) )
return 0;
@@ -5106,21 +5107,21 @@ int char_parse_char(int fd)
return 0;
}
- while( RFIFOREST(fd) >= 2 ) {
- //For use in packets that depend on an sd being present [Skotlex]
- #define FIFOSD_CHECK(rest) do { if(RFIFOREST(fd) < (rest)) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,(rest)); return 0; } } while (0)
+ while (RFIFOREST(fd) >= 2) {
+ cmd = RFIFOW(fd,0);
+
+//For use in packets that depend on an sd being present [Skotlex]
+#define FIFOSD_CHECK(rest) do { if(RFIFOREST(fd) < (rest)) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,(rest)); return 0; } } while (0)
if (VECTOR_LENGTH(HPM->packets[hpParse_Char]) > 0) {
- int result = HPM->parse_packets(fd,hpParse_Char);
+ int result = HPM->parse_packets(fd,cmd,hpParse_Char);
if (result == 1)
continue;
if (result == 2)
return 0;
}
- cmd = RFIFOW(fd,0);
-
- switch( cmd ) {
+ switch (cmd) {
// request to connect
// 0065 <account id>.L <login id1>.L <login id2>.L <???>.W <sex>.B
case 0x65:
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index 03a1d368d..60efeac94 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -1201,7 +1201,7 @@ int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member
g->member[0].modified = GS_MEMBER_MODIFIED;
// Set default positions
- g->position[0].mode = GPERM_BOTH;
+ g->position[0].mode = GPERM_ALL;
strcpy(g->position[0].name,"GuildMaster");
strcpy(g->position[MAX_GUILDPOSITION-1].name,"Newbie");
g->position[0].modified = g->position[MAX_GUILDPOSITION-1].modified = GS_POSITION_MODIFIED;
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 62ef54499..d9c3262d7 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -718,13 +718,13 @@ CPCMD(plugins)
* @retval 1 OK
* @retval 2 incomplete packet
*/
-unsigned char hplugins_parse_packets(int fd, enum HPluginPacketHookingPoints point)
+unsigned char hplugins_parse_packets(int fd, int packet_id, enum HPluginPacketHookingPoints point)
{
struct HPluginPacket *packet = NULL;
int i;
int16 length;
- ARR_FIND(0, VECTOR_LENGTH(HPM->packets[point]), i, VECTOR_INDEX(HPM->packets[point], i).cmd == RFIFOW(fd,0));
+ ARR_FIND(0, VECTOR_LENGTH(HPM->packets[point]), i, VECTOR_INDEX(HPM->packets[point], i).cmd == packet_id);
if (i == VECTOR_LENGTH(HPM->packets[point]))
return 0;
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 215161a86..109549aad 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -157,7 +157,7 @@ struct HPM_interface {
void (*share) (void *value, const char *name);
void (*config_read) (void);
char *(*pid2name) (unsigned int pid);
- unsigned char (*parse_packets) (int fd, enum HPluginPacketHookingPoints point);
+ unsigned char (*parse_packets) (int fd, int packet_id, enum HPluginPacketHookingPoints point);
void (*load_sub) (struct hplugin *plugin);
bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID);
/* for custom config parsing */
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 37fc63e29..6f573a571 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -749,7 +749,8 @@ enum { //Change Member Infos
enum guild_permission { // Guild permissions
GPERM_INVITE = 0x01,
GPERM_EXPEL = 0x10,
- GPERM_BOTH = GPERM_INVITE|GPERM_EXPEL,
+ GPERM_ALL = GPERM_INVITE|GPERM_EXPEL,
+ GPERM_MASK = GPERM_ALL,
};
enum {
diff --git a/src/login/login.c b/src/login/login.c
index 7ed0ada89..d4768df86 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -808,18 +808,18 @@ int login_parse_fromchar(int fd)
ipl = server[id].ip;
sockt->ip2str(ipl, ip);
- while( RFIFOREST(fd) >= 2 ) {
+ while (RFIFOREST(fd) >= 2) {
uint16 command = RFIFOW(fd,0);
if (VECTOR_LENGTH(HPM->packets[hpParse_FromChar]) > 0) {
- int result = HPM->parse_packets(fd,hpParse_FromChar);
+ int result = HPM->parse_packets(fd,command,hpParse_FromChar);
if (result == 1)
continue;
if (result == 2)
return 0;
}
- switch( command ) {
+ switch (command) {
case 0x2712: // request from char-server to authenticate an account
if( RFIFOREST(fd) < 23 )
@@ -1619,18 +1619,18 @@ int login_parse_login(int fd)
sd->fd = fd;
}
- while( RFIFOREST(fd) >= 2 ) {
+ while (RFIFOREST(fd) >= 2) {
uint16 command = RFIFOW(fd,0);
if (VECTOR_LENGTH(HPM->packets[hpParse_Login]) > 0) {
- int result = HPM->parse_packets(fd,hpParse_Login);
+ int result = HPM->parse_packets(fd,command,hpParse_Login);
if (result == 1)
continue;
if (result == 2)
return 0;
}
- switch( command ) {
+ switch (command) {
case 0x0200: // New alive packet: structure: 0x200 <account.userid>.24B. used to verify if client is always alive.
if (RFIFOREST(fd) < 26)
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 08119457d..bc539837d 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -260,24 +260,28 @@ ACMD(send)
if (type >= MIN_PACKET_DB && type <= MAX_PACKET_DB) {
int off = 2;
+ if (clif->packet(type) == NULL) {
+ // unknown packet - ERROR
+ safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,905), type); // Unknown packet: 0x%x
+ clif->message(fd, atcmd_output);
+ return false;
+ }
+
if (len) {
// show packet length
safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,904), type, clif->packet(type)->len); // Packet 0x%x length: %d
clif->message(fd, atcmd_output);
return true;
}
-
+
len = clif->packet(type)->len;
- if (len == 0) {
- // unknown packet - ERROR
- safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,905), type); // Unknown packet: 0x%x
- clif->message(fd, atcmd_output);
- return false;
- } else if (len == -1) {
+
+ if (len == -1) {
// dynamic packet
len = SHRT_MAX-4; // maximum length
off = 4;
}
+
WFIFOHEAD(sd->fd, len);
WFIFOW(sd->fd,0)=TOW(type);
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 1f7fbe96e..258d550d4 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -1394,16 +1394,16 @@ int chrif_parse(int fd) {
}
while (RFIFOREST(fd) >= 2) {
+ cmd = RFIFOW(fd,0);
+
if (VECTOR_LENGTH(HPM->packets[hpChrif_Parse]) > 0) {
- int result = HPM->parse_packets(fd,hpChrif_Parse);
+ int result = HPM->parse_packets(fd,cmd,hpChrif_Parse);
if (result == 1)
continue;
if (result == 2)
return 0;
}
- cmd = RFIFOW(fd,0);
-
if (cmd < 0x2af8 || cmd >= 0x2af8 + ARRAYLENGTH(chrif->packet_len_table) || chrif->packet_len_table[cmd-0x2af8] == 0) {
int result = intif->parse(fd); // Passed on to the intif
diff --git a/src/map/clif.c b/src/map/clif.c
index a95834791..2ec9626f1 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -18743,21 +18743,21 @@ int clif_parse(int fd) {
if (RFIFOREST(fd) < 2)
return 0;
+ if (sd)
+ parse_cmd_func = sd->parse_cmd_func;
+ else
+ parse_cmd_func = clif->parse_cmd;
+
+ cmd = parse_cmd_func(fd,sd);
+
if (VECTOR_LENGTH(HPM->packets[hpClif_Parse]) > 0) {
- int result = HPM->parse_packets(fd,hpClif_Parse);
+ int result = HPM->parse_packets(fd,cmd,hpClif_Parse);
if (result == 1)
continue;
if (result == 2)
return 0;
}
- if( sd )
- parse_cmd_func = sd->parse_cmd_func;
- else
- parse_cmd_func = clif->parse_cmd;
-
- cmd = parse_cmd_func(fd,sd);
-
// filter out invalid / unsupported packets
if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x (0x%04x), %"PRIuS" bytes received), disconnecting session #%d.\n",
diff --git a/src/map/guild.c b/src/map/guild.c
index cba05638f..f4f0c0528 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -1117,7 +1117,7 @@ int guild_change_position(int guild_id,int idx,int mode,int exp_mode,const char
nullpo_ret(name);
exp_mode = cap_value(exp_mode, 0, battle_config.guild_exp_limit);
- p.mode=mode&GPERM_BOTH; // Invite and Expel
+ p.mode=mode&GPERM_MASK;
p.exp_mode=exp_mode;
safestrncpy(p.name,name,NAME_LENGTH);
return intif->guild_position(guild_id,idx,&p);
diff --git a/src/map/script.c b/src/map/script.c
index 66b144b96..64bdba592 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2318,6 +2318,15 @@ void read_constdb(void)
ShowWarning("read_constdb: Invalid constant name %s. Skipping.\n", name);
continue;
}
+ if (strcmp(name, "comment__") == 0) {
+ const char *comment = libconfig->setting_get_string(t);
+ if (comment == NULL)
+ continue;
+ if (*comment == '\0')
+ comment = NULL;
+ script->constdb_comment(comment);
+ continue;
+ }
if (config_setting_is_aggregate(t)) {
int i32;
if (!libconfig->setting_lookup_int(t, "Value", &i32)) {
@@ -2338,9 +2347,22 @@ void read_constdb(void)
}
script->set_constant(name, value, is_parameter, is_deprecated);
}
+ script->constdb_comment(NULL);
libconfig->destroy(&constants_conf);
}
+/**
+ * Sets the current constdb comment.
+ *
+ * This function does nothing (used by plugins only)
+ *
+ * @param comment The comment to set (NULL to unset)
+ */
+void script_constdb_comment(const char *comment)
+{
+ (void)comment;
+}
+
// Standard UNIX tab size is 8
#define TAB_SIZE 8
#define update_tabstop(tabstop,chars) \
@@ -20808,9 +20830,11 @@ void script_label_add(int key, int pos) {
**/
void script_hardcoded_constants(void)
{
+ script->constdb_comment("Boolean");
script->set_constant("true", 1, false, false);
script->set_constant("false", 0, false, false);
- /* server defines */
+
+ script->constdb_comment("Server defines");
script->set_constant("PACKETVER",PACKETVER,false, false);
script->set_constant("MAX_LEVEL",MAX_LEVEL,false, false);
script->set_constant("MAX_STORAGE",MAX_STORAGE,false, false);
@@ -20822,7 +20846,7 @@ void script_hardcoded_constants(void)
script->set_constant("MAX_CHAT_USERS",MAX_CHAT_USERS,false, false);
script->set_constant("MAX_REFINE",MAX_REFINE,false, false);
- /* status options */
+ script->constdb_comment("status options");
script->set_constant("Option_Nothing",OPTION_NOTHING,false, false);
script->set_constant("Option_Sight",OPTION_SIGHT,false, false);
script->set_constant("Option_Hide",OPTION_HIDE,false, false);
@@ -20848,11 +20872,11 @@ void script_hardcoded_constants(void)
script->set_constant("Option_Hanbok",OPTION_HANBOK,false, false);
script->set_constant("Option_Oktoberfest",OPTION_OKTOBERFEST,false, false);
- /* status option compounds */
+ script->constdb_comment("status option compounds");
script->set_constant("Option_Dragon",OPTION_DRAGON,false, false);
script->set_constant("Option_Costume",OPTION_COSTUME,false, false);
- /* send_target */
+ script->constdb_comment("send_target");
script->set_constant("ALL_CLIENT",ALL_CLIENT,false, false);
script->set_constant("ALL_SAMEMAP",ALL_SAMEMAP,false, false);
script->set_constant("AREA",AREA,false, false);
@@ -20886,7 +20910,7 @@ void script_hardcoded_constants(void)
script->set_constant("BG_AREA_WOS",BG_AREA_WOS,false, false);
script->set_constant("BG_QUEUE",BG_QUEUE,false, false);
- /* LOOK_ constants, use in setlook/changelook script commands */
+ script->constdb_comment("LOOK_ constants, use in setlook/changelook script commands");
script->set_constant("LOOK_BASE", LOOK_BASE, false, false);
script->set_constant("LOOK_HAIR", LOOK_HAIR, false, false);
script->set_constant("LOOK_WEAPON", LOOK_WEAPON, false, false);
@@ -20902,7 +20926,7 @@ void script_hardcoded_constants(void)
script->set_constant("LOOK_ROBE", LOOK_ROBE, false, false);
script->set_constant("LOOK_BODY2", LOOK_BODY2, false, false);
- /* Equip Position in Bits, use with *getiteminfo type 5, or @inventorylist_equip */
+ script->constdb_comment("Equip Position in Bits, use with *getiteminfo type 5, or @inventorylist_equip");
script->set_constant("EQP_HEAD_LOW", EQP_HEAD_LOW, false, false);
script->set_constant("EQP_HEAD_MID", EQP_HEAD_MID, false, false);
script->set_constant("EQP_HEAD_TOP", EQP_HEAD_TOP, false, false);
@@ -20925,7 +20949,7 @@ void script_hardcoded_constants(void)
script->set_constant("EQP_SHADOW_ACC_R", EQP_SHADOW_ACC_R, false, false);
script->set_constant("EQP_SHADOW_ACC_L", EQP_SHADOW_ACC_L, false, false);
- /* Renewal */
+ script->constdb_comment("Renewal");
#ifdef RENEWAL
script->set_constant("RENEWAL", 1, false, false);
#else
@@ -20961,6 +20985,7 @@ void script_hardcoded_constants(void)
#else
script->set_constant("RENEWAL_ASPD", 0, false, false);
#endif
+ script->constdb_comment(NULL);
}
/**
@@ -21138,6 +21163,7 @@ void script_defaults(void) {
script->parse_expr = parse_expr;
script->parse_line = parse_line;
script->read_constdb = read_constdb;
+ script->constdb_comment = script_constdb_comment;
script->print_line = script_print_line;
script->errorwarning_sub = script_errorwarning_sub;
script->set_reg = set_reg;
diff --git a/src/map/script.h b/src/map/script.h
index ab8c294e1..351ccd02a 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -724,6 +724,7 @@ struct script_interface {
const char* (*parse_expr) (const char *p);
const char* (*parse_line) (const char *p);
void (*read_constdb) (void);
+ void (*constdb_comment) (const char *comment);
const char* (*print_line) (StringBuf *buf, const char *p, const char *mark, int line);
void (*errorwarning_sub) (StringBuf *buf, const char *src, const char *file, int start_line, const char *error_msg, const char *error_pos);
int (*set_reg) (struct script_state *st, struct map_session_data *sd, int64 num, const char *name, const void *value, struct reg_db *ref);
diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
index d909e9892..f5ac1e70a 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
@@ -4628,6 +4628,8 @@ struct {
struct HPMHookPoint *HP_script_parse_line_post;
struct HPMHookPoint *HP_script_read_constdb_pre;
struct HPMHookPoint *HP_script_read_constdb_post;
+ struct HPMHookPoint *HP_script_constdb_comment_pre;
+ struct HPMHookPoint *HP_script_constdb_comment_post;
struct HPMHookPoint *HP_script_print_line_pre;
struct HPMHookPoint *HP_script_print_line_post;
struct HPMHookPoint *HP_script_errorwarning_sub_pre;
@@ -10473,6 +10475,8 @@ struct {
int HP_script_parse_line_post;
int HP_script_read_constdb_pre;
int HP_script_read_constdb_post;
+ int HP_script_constdb_comment_pre;
+ int HP_script_constdb_comment_post;
int HP_script_print_line_pre;
int HP_script_print_line_post;
int HP_script_errorwarning_sub_pre;
diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
index db30c8c02..f7ee233c3 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
@@ -2368,6 +2368,7 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(script->parse_expr, HP_script_parse_expr) },
{ HP_POP(script->parse_line, HP_script_parse_line) },
{ HP_POP(script->read_constdb, HP_script_read_constdb) },
+ { HP_POP(script->constdb_comment, HP_script_constdb_comment) },
{ HP_POP(script->print_line, HP_script_print_line) },
{ HP_POP(script->errorwarning_sub, HP_script_errorwarning_sub) },
{ HP_POP(script->set_reg, HP_script_set_reg) },
diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
index 11bf66481..5dfdb8c2a 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
@@ -61731,6 +61731,32 @@ void HP_script_read_constdb(void) {
}
return;
}
+void HP_script_constdb_comment(const char *comment) {
+ int hIndex = 0;
+ if( HPMHooks.count.HP_script_constdb_comment_pre ) {
+ void (*preHookFunc) (const char *comment);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_script_constdb_comment_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_script_constdb_comment_pre[hIndex].func;
+ preHookFunc(comment);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return;
+ }
+ }
+ {
+ HPMHooks.source.script.constdb_comment(comment);
+ }
+ if( HPMHooks.count.HP_script_constdb_comment_post ) {
+ void (*postHookFunc) (const char *comment);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_script_constdb_comment_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_script_constdb_comment_post[hIndex].func;
+ postHookFunc(comment);
+ }
+ }
+ return;
+}
const char* HP_script_print_line(StringBuf *buf, const char *p, const char *mark, int line) {
int hIndex = 0;
const char* retVal___ = NULL;
diff --git a/src/plugins/constdb2doc.c b/src/plugins/constdb2doc.c
new file mode 100644
index 000000000..1d5f37ad5
--- /dev/null
+++ b/src/plugins/constdb2doc.c
@@ -0,0 +1,197 @@
+/**
+ * This file is part of Hercules.
+ * http://herc.ws - http://github.com/HerculesWS/Hercules
+ *
+ * Copyright (C) 2016 Hercules Dev Team
+ * Copyright (C) 2016 Haru <haru@dotalux.com>
+ *
+ * Hercules is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/// db/constants.conf -> doc/constants.md generator plugin
+
+#include "common/hercules.h"
+//#include "common/memmgr.h"
+#include "common/nullpo.h"
+#include "common/strlib.h"
+#include "map/itemdb.h"
+#include "map/mob.h"
+#include "map/script.h"
+#include "map/skill.h"
+
+#include "common/HPMDataCheck.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sys/stat.h>
+
+#define OUTPUTFILENAME "doc" PATHSEP_STR "constants.md"
+
+HPExport struct hplugin_info pinfo = {
+ "constdb2doc", // Plugin name
+ SERVER_TYPE_MAP, // Which server types this plugin works with?
+ "0.1", // Plugin version
+ HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
+};
+
+FILE *out_fp;
+bool torun = false;
+
+/// To override script_constdb_comment
+void constdb2doc_constdb_comment(const char *comment)
+{
+ nullpo_retv(out_fp);
+ if (comment == NULL)
+ fprintf(out_fp, "\n");
+ else
+ fprintf(out_fp, "\n### %s\n\n", comment);
+}
+
+/// To override script_set_constant, called by script_read_constdb
+void constdb2doc_script_set_constant(const char *name, int value, bool is_parameter, bool is_deprecated)
+{
+ nullpo_retv(out_fp);
+
+ if (is_parameter)
+ fprintf(out_fp, "- `%s`: [param]%s\n", name, is_deprecated ? " **(DEPRECATED)**" : "");
+ else
+ fprintf(out_fp, "- `%s`: %d%s\n", name, value, is_deprecated ? " **(DEPRECATED)**" : "");
+}
+
+void constdb2doc_constdb(void)
+{
+ void (*script_set_constant) (const char* name, int value, bool is_parameter, bool is_deprecated) = NULL;
+ void (*script_constdb_comment) (const char *comment) = NULL;
+
+ nullpo_retv(out_fp);
+
+ /* Link */
+ script_set_constant = script->set_constant;
+ script->set_constant = constdb2doc_script_set_constant;
+ script_constdb_comment = script->constdb_comment;
+ script->constdb_comment = constdb2doc_constdb_comment;
+
+ /* Run */
+ fprintf(out_fp, "## Constants (db/constants.conf)\n\n");
+ script->read_constdb();
+ fprintf(out_fp, "\n");
+
+ fprintf(out_fp, "## Hardcoded Constants (source)\n\n");
+ script->hardcoded_constants();
+ fprintf(out_fp, "\n");
+
+ /* Unlink */
+ script->set_constant = script_set_constant;
+ script->constdb_comment = script_constdb_comment;
+}
+
+void constdb2doc_skilldb(void)
+{
+ int i;
+
+ nullpo_retv(out_fp);
+
+ fprintf(out_fp, "## Skills (db/"DBPATH"skill_db.txt)\n\n");
+ for (i = 1; i < MAX_SKILL_DB; i++) {
+ if (skill->dbs->db[i].name[0] != '\0')
+ fprintf(out_fp, "- `%s`: %d\n", skill->dbs->db[i].name, skill->dbs->db[i].nameid);
+ }
+ fprintf(out_fp, "\n");
+}
+
+void constdb2doc_mobdb(void)
+{
+ int i;
+
+ nullpo_retv(out_fp);
+
+ fprintf(out_fp, "## Mobs (db/"DBPATH"mob_db.txt)\n\n");
+ for (i = 0; i < MAX_MOB_DB; i++) {
+ struct mob_db *md = mob->db(i);
+ if (md == mob->dummy || md->sprite[0] == '\0')
+ continue;
+ fprintf(out_fp, "- `%s`: %d\n", md->sprite, i);
+ }
+ fprintf(out_fp, "\n");
+}
+
+/// Cloned from itemdb_search
+struct item_data *constdb2doc_itemdb_search(int nameid)
+{
+ if (nameid >= 0 && nameid < ARRAYLENGTH(itemdb->array))
+ return itemdb->array[nameid];
+
+ return idb_get(itemdb->other, nameid);
+}
+
+void constdb2doc_itemdb(void)
+{
+ int i;
+
+ nullpo_retv(out_fp);
+
+ fprintf(out_fp, "## Items (db/"DBPATH"item_db.conf)\n");
+ for (i = 0; i < ARRAYLENGTH(itemdb->array); i++) {
+ struct item_data *id = constdb2doc_itemdb_search(i);
+ if (id == NULL || id->name[0] == '\0')
+ continue;
+ fprintf(out_fp, "- `%s`: %d\n", id->name, id->nameid);
+ }
+ fprintf(out_fp, "\n");
+}
+
+void do_constdb2doc(void)
+{
+ /* File Type Detector */
+ if ((out_fp = fopen(OUTPUTFILENAME, "wt+")) == NULL) {
+ ShowError("do_constdb2doc: Unable to open output file.\n");
+ return;
+ }
+
+ fprintf(out_fp,
+ "# Constants\n\n"
+ "> This document contains all the constants available to the script engine.\n\n");
+
+ constdb2doc_constdb();
+
+ constdb2doc_skilldb();
+
+ constdb2doc_mobdb();
+
+ constdb2doc_itemdb();
+
+ fprintf(out_fp, "> End of list\n");
+
+ fclose(out_fp);
+}
+CPCMD(constdb2doc) {
+ do_constdb2doc();
+}
+CMDLINEARG(constdb2doc)
+{
+ map->minimal = torun = true;
+ return true;
+}
+HPExport void server_preinit(void) {
+ addArg("--constdb2doc", false, constdb2doc, NULL);
+}
+HPExport void plugin_init(void) {
+ addCPCommand("server:tools:constdb2doc", constdb2doc);
+}
+HPExport void server_online(void) {
+ if (torun)
+ do_constdb2doc();
+}