summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c108
-rw-r--r--src/char/int_auction.c12
-rw-r--r--src/char/int_elemental.c4
-rw-r--r--src/char/int_guild.c50
-rw-r--r--src/char/int_homun.c7
-rw-r--r--src/char/int_mail.c12
-rw-r--r--src/char/int_mercenary.c6
-rw-r--r--src/char/int_party.c14
-rw-r--r--src/char/int_pet.c6
-rw-r--r--src/char/int_quest.c8
-rw-r--r--src/char/int_storage.c8
-rw-r--r--src/char/inter.c24
-rw-r--r--src/char/loginif.c9
-rw-r--r--src/char/pincode.c15
-rw-r--r--src/login/account_sql.c47
-rw-r--r--src/login/ipban_sql.c13
-rw-r--r--src/login/login.c36
-rw-r--r--src/login/loginlog_sql.c5
-rw-r--r--src/map/pc.c335
-rw-r--r--src/map/pc.h2
-rw-r--r--src/map/skill.c4
-rw-r--r--src/map/status.c406
-rw-r--r--src/map/status.h13
-rw-r--r--src/map/unit.c9
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc32
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc8
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.Hooks.inc138
27 files changed, 864 insertions, 467 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 83bb36a34..756b7397a 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -39,6 +39,7 @@
#include "../common/malloc.h"
#include "../common/mapindex.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/strlib.h"
@@ -317,6 +318,7 @@ static int char_db_setoffline(DBKey key, DBData *data, va_list ap)
{
struct online_char_data* character = (struct online_char_data*)DB->data2ptr(data);
int server_id = va_arg(ap, int);
+ nullpo_ret(character);
if (server_id == -1) {
character->char_id = -1;
character->server = -1;
@@ -336,12 +338,13 @@ static int char_db_kickoffline(DBKey key, DBData *data, va_list ap)
{
struct online_char_data* character = (struct online_char_data*)DB->data2ptr(data);
int server_id = va_arg(ap, int);
+ nullpo_ret(character);
if (server_id > -1 && character->server != server_id)
return 0;
//Kick out any connected characters, and set them offline as appropriate.
- if (character->server > -1)
+ if (character->server > -1 && character->server < MAX_MAP_SERVERS)
mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 1);
else if (character->waiting_disconnect == INVALID_TIMER)
chr->set_char_offline(character->char_id, character->account_id);
@@ -404,7 +407,8 @@ int char_mmo_char_tosql(int char_id, struct mmo_charstatus* p)
int errors = 0; //If there are any errors while saving, "cp" will not be updated at the end.
StringBuf buf;
- if (char_id!=p->char_id) return 0;
+ nullpo_ret(p);
+ if (char_id != p->char_id) return 0;
cp = idb_ensure(chr->char_db_, char_id, chr->create_charstatus);
@@ -1008,6 +1012,9 @@ int char_mmo_chars_fromsql(struct char_session_data* sd, uint8* buf)
time_t unban_time = 0;
char sex[2];
+ nullpo_ret(sd);
+ nullpo_ret(buf);
+
stmt = SQL->StmtMalloc(inter->sql_handle);
if( stmt == NULL ) {
SqlStmt_ShowDebug(stmt);
@@ -1075,6 +1082,8 @@ int char_mmo_chars_fromsql(struct char_session_data* sd, uint8* buf)
}
for( i = 0; i < MAX_CHARS && SQL_SUCCESS == SQL->StmtNextRow(stmt); i++ ) {
+ if (p.slot >= MAX_CHARS)
+ continue;
p.last_point.map = mapindex->name2id(last_map);
sd->found_char[p.slot] = p.char_id;
sd->unban_time[p.slot] = unban_time;
@@ -1122,6 +1131,8 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every
int account_id;
char sex[2];
+ nullpo_ret(p);
+
memset(p, 0, sizeof(struct mmo_charstatus));
if (save_log) ShowInfo("Char load request (%d)\n", char_id);
@@ -1325,8 +1336,9 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 7, SQLDT_UINT, &tmp_item.expire_time, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 8, SQLDT_UCHAR, &tmp_item.bound, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 9, SQLDT_UINT64, &tmp_item.unique_id, 0, NULL, NULL)
- )
+ ) {
SqlStmt_ShowDebug(stmt);
+ }
for( i = 0; i < MAX_SLOTS; ++i )
if( SQL_ERROR == SQL->StmtBindColumn(stmt, 10+i, SQLDT_SHORT, &tmp_item.card[i], 0, NULL, NULL) )
SqlStmt_ShowDebug(stmt);
@@ -1348,8 +1360,9 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_USHORT, &tmp_skill.id , 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_UCHAR , &tmp_skill.lv , 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UCHAR , &tmp_skill.flag, 0, NULL, NULL)
- )
+ ) {
SqlStmt_ShowDebug(stmt);
+ }
if( tmp_skill.flag != SKILL_FLAG_PERM_GRANTED )
tmp_skill.flag = SKILL_FLAG_PERMANENT;
@@ -1370,8 +1383,10 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every
|| SQL_ERROR == SQL->StmtExecute(stmt)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_friend.account_id, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &tmp_friend.char_id, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_STRING, &tmp_friend.name, sizeof(tmp_friend.name), NULL, NULL) )
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_STRING, &tmp_friend.name, sizeof(tmp_friend.name), NULL, NULL)
+ ) {
SqlStmt_ShowDebug(stmt);
+ }
for( i = 0; i < MAX_FRIENDS && SQL_SUCCESS == SQL->StmtNextRow(stmt); ++i )
memcpy(&p->friends[i], &tmp_friend, sizeof(tmp_friend));
@@ -1414,8 +1429,10 @@ int char_mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_every
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &p->bank_vault, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_USHORT, &p->mod_exp, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_USHORT, &p->mod_drop, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &p->mod_death, 0, NULL, NULL) )
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 3, SQLDT_USHORT, &p->mod_death, 0, NULL, NULL)
+ ) {
SqlStmt_ShowDebug(stmt);
+ }
if( SQL_SUCCESS == SQL->StmtNextRow(stmt) )
strcat(t_msg, " accdata");
@@ -1473,7 +1490,8 @@ bool char_char_slotchange(struct char_session_data *sd, int fd, unsigned short f
/* update both at once */
if( SQL_SUCCESS != SQL->QueryStr(inter->sql_handle, "START TRANSACTION")
|| SQL_SUCCESS != SQL->Query(inter->sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, from, sd->found_char[to])
- || SQL_SUCCESS != SQL->Query(inter->sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, to, sd->found_char[from]) )
+ || SQL_SUCCESS != SQL->Query(inter->sql_handle, "UPDATE `%s` SET `char_num`='%d' WHERE `char_id`='%d' LIMIT 1", char_db, to, sd->found_char[from])
+ )
Sql_ShowDebug(inter->sql_handle);
else
result = true;
@@ -1508,12 +1526,17 @@ int char_rename_char_sql(struct char_session_data *sd, int char_id)
struct mmo_charstatus char_dat;
char esc_name[NAME_LENGTH*2+1];
+ nullpo_retr(2, sd);
+
if( sd->new_name[0] == 0 ) // Not ready for rename
return 2;
if( !chr->mmo_char_fromsql(char_id, &char_dat, false) ) // Only the short data is needed.
return 2;
+ if (sd->account_id != char_dat.account_id) // Try rename not own char
+ return 2;
+
if( char_dat.rename == 0 )
return 1;
@@ -1556,8 +1579,11 @@ int char_check_char_name(char * name, char * esc_name)
{
int i;
+ nullpo_retr(-2, name);
+ nullpo_retr(-2, esc_name);
+
// check length of character name
- if( name[0] == '\0' )
+ if (name[0] == '\0')
return -2; // empty character name
/**
* The client does not allow you to create names with less than 4 characters, however,
@@ -2027,6 +2053,7 @@ void char_mmo_char_send_ban_list(int fd, struct char_session_data *sd) {
int i;
time_t now = time(NULL);
+ nullpo_retv(sd);
ARR_FIND(0, MAX_CHARS, i, sd->unban_time[i]);
if( i != MAX_CHARS ) {
int c;
@@ -2063,6 +2090,7 @@ void char_mmo_char_send_ban_list(int fd, struct char_session_data *sd) {
// [Ind/Hercules] notify client about charselect window data
//----------------------------------------
void char_mmo_char_send_slots_info(int fd, struct char_session_data* sd) {
+ nullpo_retv(sd);
WFIFOHEAD(fd,29);
WFIFOW(fd,0) = 0x82d;
WFIFOW(fd,2) = 29;
@@ -2080,6 +2108,7 @@ void char_mmo_char_send_slots_info(int fd, struct char_session_data* sd) {
int char_mmo_char_send_characters(int fd, struct char_session_data* sd)
{
int j, offset = 0;
+ nullpo_ret(sd);
#if PACKETVER >= 20100413
offset += 3;
#endif
@@ -2201,6 +2230,8 @@ static void char_auth_ok(int fd, struct char_session_data *sd)
{
struct online_char_data* character;
+ nullpo_retv(sd);
+
if( (character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id)) != NULL ) {
// check if character is not online already. [Skotlex]
if (character->server > -1) {
@@ -2356,7 +2387,8 @@ void char_parse_fromlogin_account_data(int fd)
void char_parse_fromlogin_login_pong(int fd)
{
RFIFOSKIP(fd,2);
- session[fd]->flag.ping = 0;
+ if (session[fd])
+ session[fd]->flag.ping = 0;
}
void char_changesex(int account_id, int sex)
@@ -2870,7 +2902,7 @@ void char_update_fame_list(int type, int index, int fame) {
mapif->sendall(buf, 8);
}
-//Loads a character's name and stores it in the buffer given (must be NAME_LENGTH in size)
+//Loads a character's name and stores it in the buffer given (must be NAME_LENGTH in size) and not NULL
//Returns 1 on found, 0 on not found (buffer is filled with Unknown char name)
int char_loadName(int char_id, char* name)
{
@@ -2943,6 +2975,7 @@ void mapif_on_disconnect(int id)
}
void mapif_on_parse_accinfo(int account_id, int u_fd, int u_aid, int u_group, int map_fd) {
+ Assert_retv(chr->login_fd > 0);
WFIFOHEAD(chr->login_fd,22);
WFIFOW(chr->login_fd,0) = 0x2740;
WFIFOL(chr->login_fd,2) = account_id;
@@ -2964,7 +2997,7 @@ void char_parse_frommap_skillid2idx(int fd)
int i;
int j = RFIFOW(fd, 2) - 4;
- memset(&skillid2idx, 0, sizeof(skillid2idx));
+ memset(&skillid2idx, 0, sizeof(skillid2idx));
if( j )
j /= 4;
for(i = 0; i < j; i++) {
@@ -3348,6 +3381,8 @@ void char_ban(int account_id, int char_id, time_t *unban_time, short year, short
struct tm *tmtime;
SqlStmt* stmt = SQL->StmtMalloc(inter->sql_handle);
+ nullpo_retv(unban_time);
+
if (*unban_time == 0 || *unban_time < time(NULL))
timestamp = time(NULL); // new ban
else
@@ -3363,13 +3398,12 @@ void char_ban(int account_id, int char_id, time_t *unban_time, short year, short
timestamp = mktime(tmtime);
if( SQL_SUCCESS != SQL->StmtPrepare(stmt,
- "UPDATE `%s` SET `unban_time` = ? WHERE `char_id` = ? LIMIT 1",
- char_db)
+ "UPDATE `%s` SET `unban_time` = ? WHERE `char_id` = ? LIMIT 1",
+ char_db)
|| SQL_SUCCESS != SQL->StmtBindParam(stmt, 0, SQLDT_LONG, (void*)&timestamp, sizeof(timestamp))
|| SQL_SUCCESS != SQL->StmtBindParam(stmt, 1, SQLDT_INT, (void*)&char_id, sizeof(char_id))
|| SQL_SUCCESS != SQL->StmtExecute(stmt)
-
- ) {
+ ) {
SqlStmt_ShowDebug(stmt);
}
@@ -3388,12 +3422,14 @@ void char_unban(int char_id, int *result)
/* handled by char server, so no redirection */
if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `unban_time` = '0' WHERE `char_id` = '%d' LIMIT 1", char_db, char_id) ) {
Sql_ShowDebug(inter->sql_handle);
- *result = 1;
+ if (result)
+ *result = 1;
}
}
void char_ask_name_ack(int fd, int acc, const char* name, int type, int result)
{
+ nullpo_retv(name);
WFIFOHEAD(fd,34);
WFIFOW(fd, 0) = 0x2b0f;
WFIFOL(fd, 2) = acc;
@@ -3499,6 +3535,10 @@ void char_parse_frommap_fame_list(int fd)
default: size = 0; list = NULL; break;
}
+ if (!list) {
+ RFIFOSKIP(fd, 11);
+ return;
+ }
ARR_FIND(0, size, player_pos, list[player_pos].id == cid);// position of the player
ARR_FIND(0, size, fame_pos, list[fame_pos].fame <= fame);// where the player should be
@@ -3624,6 +3664,7 @@ void char_parse_frommap_ping(int fd)
void char_map_auth_ok(int fd, int account_id, struct char_auth_node* node, struct mmo_charstatus* cd)
{
+ nullpo_retv(cd);
WFIFOHEAD(fd,25 + sizeof(struct mmo_charstatus));
WFIFOW(fd,0) = 0x2afd;
WFIFOW(fd,2) = 25 + sizeof(struct mmo_charstatus);
@@ -4391,6 +4432,7 @@ void char_parse_char_connect(int fd, struct char_session_data* sd, uint32 ipl)
void char_send_map_info(int fd, int i, uint32 subnet_map_ip, struct mmo_charstatus *cd)
{
+ nullpo_retv(cd);
WFIFOHEAD(fd,28);
WFIFOW(fd,0) = 0x71;
WFIFOL(fd,2) = cd->char_id;
@@ -4413,6 +4455,7 @@ int char_search_default_maps_mapserver(struct mmo_charstatus *cd)
{
int i;
int j;
+ nullpo_retr(-1, cd);
if ((i = chr->search_mapserver((j=mapindex->name2id(MAP_PRONTERA)),-1,-1)) >= 0) {
cd->last_point.x = 273;
cd->last_point.y = 354;
@@ -4505,6 +4548,7 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl)
//Have to switch over to the DB instance otherwise data won't propagate [Kevin]
cd = (struct mmo_charstatus *)idb_get(chr->char_db_, char_id);
+ nullpo_retv(cd);
if( cd->sex == 99 )
cd->sex = sd->sex;
@@ -4658,7 +4702,7 @@ void char_parse_char_delete_char(int fd, struct char_session_data* sd, unsigned
int i;
#if PACKETVER >= 20110309
- if( pincode->enabled ){ // hack check
+ if (pincode->enabled) { // hack check
struct online_char_data* character;
character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id);
if( character && character->pincode_enable == -1 ){
@@ -4874,33 +4918,33 @@ void char_parse_char_login_map_server(int fd)
void char_parse_char_pincode_check(int fd, struct char_session_data* sd)
{
- if( RFIFOL(fd,2) == sd->account_id )
- pincode->check( fd, sd );
+ if (RFIFOL(fd,2) == sd->account_id)
+ pincode->check(fd, sd);
- RFIFOSKIP(fd,10);
+ RFIFOSKIP(fd, 10);
}
void char_parse_char_pincode_window(int fd, struct char_session_data* sd)
{
- if( RFIFOL(fd,2) == sd->account_id )
- pincode->sendstate( fd, sd, PINCODE_NOTSET );
+ if (RFIFOL(fd,2) == sd->account_id)
+ pincode->sendstate(fd, sd, PINCODE_NOTSET);
- RFIFOSKIP(fd,6);
+ RFIFOSKIP(fd, 6);
}
void char_parse_char_pincode_change(int fd, struct char_session_data* sd)
{
- if( RFIFOL(fd,2) == sd->account_id )
- pincode->change( fd, sd );
+ if (RFIFOL(fd,2) == sd->account_id)
+ pincode->change(fd, sd);
- RFIFOSKIP(fd,14);
+ RFIFOSKIP(fd, 14);
}
void char_parse_char_pincode_first_pin(int fd, struct char_session_data* sd)
{
- if( RFIFOL(fd,2) == sd->account_id )
- pincode->setnew( fd, sd );
- RFIFOSKIP(fd,10);
+ if (RFIFOL(fd,2) == sd->account_id)
+ pincode->setnew (fd, sd);
+ RFIFOSKIP(fd, 10);
}
void char_parse_char_request_chars(int fd, struct char_session_data* sd)
@@ -5155,6 +5199,7 @@ int mapif_sendall(unsigned char *buf, unsigned int len)
{
int i, c;
+ nullpo_ret(buf);
c = 0;
for(i = 0; i < ARRAYLENGTH(chr->server); i++) {
int fd;
@@ -5173,6 +5218,7 @@ int mapif_sendallwos(int sfd, unsigned char *buf, unsigned int len)
{
int i, c;
+ nullpo_ret(buf);
c = 0;
for(i = 0; i < ARRAYLENGTH(chr->server); i++) {
int fd;
@@ -5189,6 +5235,7 @@ int mapif_sendallwos(int sfd, unsigned char *buf, unsigned int len)
int mapif_send(int fd, unsigned char *buf, unsigned int len)
{
+ nullpo_ret(buf);
if (fd >= 0) {
int i;
ARR_FIND( 0, ARRAYLENGTH(chr->server), i, fd == chr->server[i].fd );
@@ -5241,6 +5288,7 @@ static int char_send_accounts_tologin_sub(DBKey key, DBData *data, va_list ap)
struct online_char_data* character = DB->data2ptr(data);
int* i = va_arg(ap, int*);
+ nullpo_ret(character);
if(character->server > -1)
{
WFIFOL(chr->login_fd,8+(*i)*4) = character->account_id;
@@ -5307,6 +5355,7 @@ static int char_waiting_disconnect(int tid, int64 tick, int id, intptr_t data) {
static int char_online_data_cleanup_sub(DBKey key, DBData *data, va_list ap)
{
struct online_char_data *character= DB->data2ptr(data);
+ nullpo_ret(character);
if (character->fd != -1)
return 0; //Character still connected
if (character->server == -2) //Unknown server.. set them offline
@@ -5955,6 +6004,7 @@ void char_defaults(void)
memset(chr->userid, 0, sizeof(chr->userid));
memset(chr->passwd, 0, sizeof(chr->passwd));
+ memset(chr->server_name, 0, sizeof(chr->server_name));
chr->ip = 0;
chr->port = 6121;
diff --git a/src/char/int_auction.c b/src/char/int_auction.c
index 57eae641d..f2ec347cd 100644
--- a/src/char/int_auction.c
+++ b/src/char/int_auction.c
@@ -17,6 +17,7 @@
#include "../common/db.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/sql.h"
@@ -33,7 +34,7 @@ static int inter_auction_count(int char_id, bool buy)
for( auction = dbi_first(iter); dbi_exists(iter); auction = dbi_next(iter) )
{
- if( (buy && auction->buyer_id == char_id) || (!buy && auction->seller_id == char_id) )
+ if ((buy && auction->buyer_id == char_id) || (!buy && auction->seller_id == char_id))
i++;
}
dbi_destroy(iter);
@@ -160,7 +161,10 @@ static int inter_auction_end_timer(int tid, int64 tick, int id, intptr_t data) {
void inter_auction_delete(struct auction_data *auction)
{
- unsigned int auction_id = auction->auction_id;
+ unsigned int auction_id;
+ nullpo_retv(auction);
+
+ auction_id = auction->auction_id;
if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `auction_id` = '%d'", auction_db, auction_id) )
Sql_ShowDebug(inter->sql_handle);
@@ -240,6 +244,8 @@ void mapif_auction_sendlist(int fd, int char_id, short count, short pages, unsig
{
int len = (sizeof(struct auction_data) * count) + 12;
+ nullpo_retv(buf);
+
WFIFOHEAD(fd, len);
WFIFOW(fd,0) = 0x3850;
WFIFOW(fd,2) = len;
@@ -297,6 +303,8 @@ void mapif_auction_register(int fd, struct auction_data *auction)
{
int len = sizeof(struct auction_data) + 4;
+ nullpo_retv(auction);
+
WFIFOHEAD(fd,len);
WFIFOW(fd,0) = 0x3851;
WFIFOW(fd,2) = len;
diff --git a/src/char/int_elemental.c b/src/char/int_elemental.c
index d14d1e1e0..3a5022fe4 100644
--- a/src/char/int_elemental.c
+++ b/src/char/int_elemental.c
@@ -15,6 +15,7 @@
#include "mapif.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/sql.h"
@@ -26,6 +27,7 @@ struct inter_elemental_interface inter_elemental_s;
bool mapif_elemental_save(struct s_elemental* ele) {
bool flag = true;
+ nullpo_retr(false, ele);
if( ele->elemental_id == 0 ) { // Create new DB entry
if( SQL_ERROR == SQL->Query(inter->sql_handle,
"INSERT INTO `%s` (`char_id`,`class`,`mode`,`hp`,`sp`,`max_hp`,`max_sp`,`atk1`,`atk2`,`matk`,`aspd`,`def`,`mdef`,`flee`,`hit`,`life_time`)"
@@ -53,6 +55,7 @@ bool mapif_elemental_save(struct s_elemental* ele) {
bool mapif_elemental_load(int ele_id, int char_id, struct s_elemental *ele) {
char* data;
+ nullpo_retr(false, ele);
memset(ele, 0, sizeof(struct s_elemental));
ele->elemental_id = ele_id;
ele->char_id = char_id;
@@ -105,6 +108,7 @@ bool mapif_elemental_delete(int ele_id) {
void mapif_elemental_send(int fd, struct s_elemental *ele, unsigned char flag) {
int size = sizeof(struct s_elemental) + 5;
+ nullpo_retv(ele);
WFIFOHEAD(fd,size);
WFIFOW(fd,0) = 0x387c;
WFIFOW(fd,2) = size;
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index 20db452af..3ba51e1f0 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -18,6 +18,7 @@
#include "../common/db.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/strlib.h"
@@ -50,6 +51,8 @@ int inter_guild_save_timer(int tid, int64 tick, int id, intptr_t data) {
for( g = DB->data2ptr(iter->first(iter, &key)); dbi_exists(iter); g = DB->data2ptr(iter->next(iter, &key)) )
{
+ if (!g)
+ continue;
if( state == 0 && g->guild_id == last_id )
state++; //Save next guild in the list.
else
@@ -114,6 +117,7 @@ int inter_guild_tosql(struct guild *g,int flag)
char new_guild = 0;
int i=0;
+ nullpo_ret(g);
if (g->guild_id<=0 && g->guild_id != -1) return 0;
#ifdef NOISY
@@ -253,7 +257,7 @@ int inter_guild_tosql(struct guild *g,int flag)
//printf("- Insert guild %d to guild_position\n",g->guild_id);
for(i=0;i<MAX_GUILDPOSITION;i++){
struct guild_position *p = &g->position[i];
- if (!p->modified)
+ if (!p || !p->modified)
continue;
SQL->EscapeStringLen(inter->sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH));
if( SQL_ERROR == SQL->Query(inter->sql_handle, "REPLACE INTO `%s` (`guild_id`,`position`,`name`,`mode`,`exp_mode`) VALUES ('%d','%d','%s','%d','%d')",
@@ -521,6 +525,7 @@ int inter_guild_castle_tosql(struct guild_castle *gc)
StringBuf buf;
int i;
+ nullpo_ret(gc);
StrBuf->Init(&buf);
StrBuf->Printf(&buf, "REPLACE INTO `%s` SET `castle_id`='%d', `guild_id`='%d', `economy`='%d', `defense`='%d', "
"`triggerE`='%d', `triggerD`='%d', `nextTime`='%d', `payTime`='%d', `createTime`='%d', `visibleC`='%d'",
@@ -593,6 +598,7 @@ struct guild_castle* inter_guild_castle_fromsql(int castle_id)
// Read exp_guild.txt
bool inter_guild_exp_parse_row(char* split[], int column, int current) {
int64 exp = strtoll(split[0], NULL, 10);
+ nullpo_retr(true, split);
if (exp < 0 || exp >= UINT_MAX) {
ShowError("exp_guild: Invalid exp %"PRId64" (valid range: 0 - %u) at line %d\n", exp, UINT_MAX, current);
@@ -729,6 +735,7 @@ int inter_guild_sql_init(void)
int inter_guild_db_final(DBKey key, DBData *data, va_list ap)
{
struct guild *g = DB->data2ptr(data);
+ nullpo_ret(g);
if (g->save_flag&GS_MASK) {
inter_guild->tosql(g, g->save_flag&GS_MASK);
return 1;
@@ -749,6 +756,7 @@ int inter_guild_search_guildname(char *str)
int guild_id;
char esc_name[NAME_LENGTH*2+1];
+ nullpo_retr(-1, str);
SQL->EscapeStringLen(inter->sql_handle, esc_name, str, safestrnlen(str, NAME_LENGTH));
//Lookup guilds with the same name
if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT guild_id FROM `%s` WHERE name='%s'", guild_db, esc_name) )
@@ -776,6 +784,7 @@ int inter_guild_search_guildname(char *str)
static bool inter_guild_check_empty(struct guild *g)
{
int i;
+ nullpo_ret(g);
ARR_FIND( 0, g->max_member, i, g->member[i].account_id > 0 );
if( i < g->max_member)
return false; // not empty
@@ -788,16 +797,17 @@ static bool inter_guild_check_empty(struct guild *g)
unsigned int inter_guild_nextexp(int level) {
if (level == 0)
return 1;
- if (level <= 0 || level >= MAX_GUILDLEVEL)
+ if (level <= 0 || level > MAX_GUILDLEVEL)
return 0;
return inter_guild->exp[level-1];
}
-int inter_guild_checkskill(struct guild *g,int id)
+int inter_guild_checkskill(struct guild *g, int id)
{
int idx = id - GD_SKILLBASE;
+ nullpo_ret(g);
if(idx < 0 || idx >= MAX_GUILDSKILL)
return 0;
@@ -810,6 +820,7 @@ int inter_guild_calcinfo(struct guild *g)
unsigned int nextexp;
struct guild before = *g; // Save guild current values
+ nullpo_ret(g);
if(g->guild_lv<=0)
g->guild_lv = 1;
nextexp = inter_guild->nextexp(g->guild_lv);
@@ -872,6 +883,7 @@ int inter_guild_calcinfo(struct guild *g)
int mapif_guild_created(int fd, int account_id, struct guild *g)
{
+ nullpo_ret(g);
WFIFOHEAD(fd, 10);
WFIFOW(fd,0)=0x3830;
WFIFOL(fd,2)=account_id;
@@ -905,6 +917,7 @@ int mapif_guild_noinfo(int fd, int guild_id)
int mapif_guild_info(int fd, struct guild *g)
{
unsigned char buf[8+sizeof(struct guild)];
+ nullpo_ret(g);
WBUFW(buf,0)=0x3831;
WBUFW(buf,2)=4+sizeof(struct guild);
memcpy(buf+4,g,sizeof(struct guild));
@@ -932,6 +945,10 @@ int mapif_guild_memberadded(int fd, int guild_id, int account_id, int char_id, i
int mapif_guild_withdraw(int guild_id,int account_id,int char_id,int flag, const char *name, const char *mes)
{
unsigned char buf[55+NAME_LENGTH];
+
+ nullpo_ret(name);
+ nullpo_ret(mes);
+
WBUFW(buf, 0)=0x3834;
WBUFL(buf, 2)=guild_id;
WBUFL(buf, 6)=account_id;
@@ -948,6 +965,8 @@ int mapif_guild_withdraw(int guild_id,int account_id,int char_id,int flag, const
int mapif_guild_memberinfoshort(struct guild *g, int idx)
{
unsigned char buf[19];
+ nullpo_ret(g);
+ Assert_ret(idx >= 0 && idx < MAX_GUILD);
WBUFW(buf, 0)=0x3835;
WBUFL(buf, 2)=g->guild_id;
WBUFL(buf, 6)=g->member[idx].account_id;
@@ -975,6 +994,7 @@ int mapif_guild_broken(int guild_id, int flag)
int mapif_guild_message(int guild_id, int account_id, char *mes, int len, int sfd)
{
unsigned char buf[512];
+ nullpo_ret(mes);
if (len > 500)
len = 500;
WBUFW(buf,0)=0x3837;
@@ -990,6 +1010,7 @@ int mapif_guild_message(int guild_id, int account_id, char *mes, int len, int sf
int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int len)
{
unsigned char buf[2048];
+ nullpo_ret(data);
if (len > 2038)
len = 2038;
WBUFW(buf, 0)=0x3839;
@@ -1005,6 +1026,7 @@ int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int l
int mapif_guild_memberinfochanged(int guild_id, int account_id, int char_id, int type, const void *data, int len)
{
unsigned char buf[2048];
+ nullpo_ret(data);
if (len > 2030)
len = 2030;
WBUFW(buf, 0)=0x383a;
@@ -1034,6 +1056,8 @@ int mapif_guild_skillupack(int guild_id, uint16 skill_id, int account_id)
int mapif_guild_alliance(int guild_id1, int guild_id2, int account_id1, int account_id2, int flag, const char *name1, const char *name2)
{
unsigned char buf[19+2*NAME_LENGTH];
+ nullpo_ret(name1);
+ nullpo_ret(name2);
WBUFW(buf, 0)=0x383d;
WBUFL(buf, 2)=guild_id1;
WBUFL(buf, 6)=guild_id2;
@@ -1050,6 +1074,8 @@ int mapif_guild_alliance(int guild_id1, int guild_id2, int account_id1, int acco
int mapif_guild_position(struct guild *g, int idx)
{
unsigned char buf[12 + sizeof(struct guild_position)];
+ nullpo_ret(g);
+ Assert_ret(idx >= 0 && idx < MAX_GUILDPOSITION);
WBUFW(buf,0)=0x383b;
WBUFW(buf,2)=sizeof(struct guild_position)+12;
WBUFL(buf,4)=g->guild_id;
@@ -1063,6 +1089,7 @@ int mapif_guild_position(struct guild *g, int idx)
int mapif_guild_notice(struct guild *g)
{
unsigned char buf[256];
+ nullpo_ret(g);
WBUFW(buf,0)=0x383e;
WBUFL(buf,2)=g->guild_id;
memcpy(WBUFP(buf,6),g->mes1,MAX_GUILDMES1);
@@ -1075,6 +1102,7 @@ int mapif_guild_notice(struct guild *g)
int mapif_guild_emblem(struct guild *g)
{
unsigned char buf[12 + sizeof(g->emblem_data)];
+ nullpo_ret(g);
WBUFW(buf,0)=0x383f;
WBUFW(buf,2)=g->emblem_len+12;
WBUFL(buf,4)=g->guild_id;
@@ -1087,6 +1115,7 @@ int mapif_guild_emblem(struct guild *g)
int mapif_guild_master_changed(struct guild *g, int aid, int cid)
{
unsigned char buf[14];
+ nullpo_ret(g);
WBUFW(buf,0)=0x3843;
WBUFL(buf,2)=g->guild_id;
WBUFL(buf,6)=aid;
@@ -1102,6 +1131,7 @@ int mapif_guild_castle_dataload(int fd, int sz, int *castle_ids)
int len = 4 + num * sizeof(*gc);
int i;
+ nullpo_ret(castle_ids);
WFIFOHEAD(fd, len);
WFIFOW(fd, 0) = 0x3840;
WFIFOW(fd, 2) = len;
@@ -1125,6 +1155,8 @@ int mapif_parse_CreateGuild(int fd,int account_id,char *name,struct guild_member
#ifdef NOISY
ShowInfo("Creating Guild (%s)\n", name);
#endif
+ nullpo_ret(name);
+ nullpo_ret(master);
if(inter_guild->search_guildname(name) != 0){
ShowInfo("int_guild: guild with same name exists [%s]\n",name);
mapif->guild_created(fd,account_id,NULL);
@@ -1217,6 +1249,7 @@ int mapif_parse_GuildAddMember(int fd, int guild_id, struct guild_member *m)
struct guild * g;
int i;
+ nullpo_ret(m);
g = inter_guild->fromsql(guild_id);
if(g==NULL){
// Failed to add
@@ -1262,6 +1295,7 @@ int mapif_parse_GuildLeave(int fd, int guild_id, int account_id, int char_id, in
return 0;
}
+ nullpo_ret(mes);
// Find the member
ARR_FIND( 0, g->max_member, i, g->member[i].account_id == account_id && g->member[i].char_id == char_id );
if( i == g->max_member )
@@ -1426,6 +1460,7 @@ int mapif_parse_GuildBasicInfoChange(int fd, int guild_id, int type, const void
if( g == NULL )
return 0;
+ nullpo_ret(data);
switch(type) {
case GBI_EXP:
value = *((const int16 *)data);
@@ -1478,6 +1513,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int
int i;
struct guild * g;
+ nullpo_ret(data);
g = inter_guild->fromsql(guild_id);
if(g==NULL)
return 0;
@@ -1588,6 +1624,7 @@ int inter_guild_charname_changed(int guild_id, int account_id, int char_id, char
struct guild *g;
int i, flag = 0;
+ nullpo_ret(name);
g = inter_guild->fromsql(guild_id);
if( g == NULL )
{
@@ -1625,6 +1662,7 @@ int mapif_parse_GuildPosition(int fd, int guild_id, int idx, struct guild_positi
// Could make some improvement in speed, because only change guild_position
struct guild * g;
+ nullpo_ret(p);
g = inter_guild->fromsql(guild_id);
if(g==NULL || idx<0 || idx>=MAX_GUILDPOSITION)
return 0;
@@ -1664,6 +1702,7 @@ int mapif_parse_GuildDeleteAlliance(struct guild *g, int guild_id, int account_i
int i;
char name[NAME_LENGTH];
+ nullpo_retr(-1, g);
ARR_FIND( 0, MAX_GUILDALLIANCE, i, g->alliance[i].guild_id == guild_id );
if( i == MAX_GUILDALLIANCE )
return -1;
@@ -1726,6 +1765,8 @@ int mapif_parse_GuildNotice(int fd, int guild_id, const char *mes1, const char *
{
struct guild *g;
+ nullpo_ret(mes1);
+ nullpo_ret(mes2);
g = inter_guild->fromsql(guild_id);
if(g==NULL)
return 0;
@@ -1740,6 +1781,7 @@ int mapif_parse_GuildEmblem(int fd, int len, int guild_id, int dummy, const char
{
struct guild * g;
+ nullpo_ret(data);
g = inter_guild->fromsql(guild_id);
if(g==NULL)
return 0;
@@ -1804,6 +1846,7 @@ int mapif_parse_GuildMasterChange(int fd, int guild_id, const char* name, int le
struct guild_member gm;
int pos;
+ nullpo_ret(name);
g = inter_guild->fromsql(guild_id);
if(g==NULL || len > NAME_LENGTH)
@@ -1888,6 +1931,7 @@ void inter_guild_defaults(void)
inter_guild->guild_db = NULL;
inter_guild->castle_db = NULL;
+ memset(inter_guild->exp, 0, sizeof(inter_guild->exp));
inter_guild->save_timer = inter_guild_save_timer;
inter_guild->removemember_tosql = inter_guild_removemember_tosql;
diff --git a/src/char/int_homun.c b/src/char/int_homun.c
index dd23261c2..9f91de252 100644
--- a/src/char/int_homun.c
+++ b/src/char/int_homun.c
@@ -15,6 +15,7 @@
#include "mapif.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/sql.h"
@@ -34,6 +35,7 @@ void inter_homunculus_sql_final(void)
void mapif_homunculus_created(int fd, int account_id, struct s_homunculus *sh, unsigned char flag)
{
+ nullpo_retv(sh);
WFIFOHEAD(fd, sizeof(struct s_homunculus)+9);
WFIFOW(fd,0) = 0x3890;
WFIFOW(fd,2) = sizeof(struct s_homunculus)+9;
@@ -53,6 +55,7 @@ void mapif_homunculus_deleted(int fd, int flag)
void mapif_homunculus_loaded(int fd, int account_id, struct s_homunculus *hd)
{
+ nullpo_retv(hd);
WFIFOHEAD(fd, sizeof(struct s_homunculus)+9);
WFIFOW(fd,0) = 0x3891;
WFIFOW(fd,2) = sizeof(struct s_homunculus)+9;
@@ -81,6 +84,7 @@ void mapif_homunculus_saved(int fd, int account_id, bool flag)
void mapif_homunculus_renamed(int fd, int account_id, int char_id, unsigned char flag, char* name)
{
+ nullpo_retv(name);
WFIFOHEAD(fd, NAME_LENGTH+12);
WFIFOW(fd, 0) = 0x3894;
WFIFOL(fd, 2) = account_id;
@@ -95,6 +99,7 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
bool flag = true;
char esc_name[NAME_LENGTH*2+1];
+ nullpo_ret(hd);
SQL->EscapeStringLen(inter->sql_handle, esc_name, hd->name, strnlen(hd->name, NAME_LENGTH));
if( hd->hom_id == 0 )
@@ -158,6 +163,7 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
char* data;
size_t len;
+ nullpo_ret(hd);
memset(hd, 0, sizeof(*hd));
if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `homun_id`,`char_id`,`class`,`prev_class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`rename_flag`, `vaporize` FROM `%s` WHERE `homun_id`='%u'", homunculus_db, homun_id) )
@@ -247,6 +253,7 @@ bool mapif_homunculus_rename(char *name)
{
int i;
+ nullpo_ret(name);
// Check Authorized letters/symbols in the name of the homun
if( char_name_option == 1 )
{// only letters/symbols in char_name_letters are authorized
diff --git a/src/char/int_mail.c b/src/char/int_mail.c
index 17fb9d424..cd2fa0deb 100644
--- a/src/char/int_mail.c
+++ b/src/char/int_mail.c
@@ -15,6 +15,7 @@
#include "mapif.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/sql.h"
@@ -30,6 +31,7 @@ static int inter_mail_fromsql(int char_id, struct mail_data* md)
char *data;
StringBuf buf;
+ nullpo_ret(md);
memset(md, 0, sizeof(struct mail_data));
md->amount = 0;
md->full = false;
@@ -114,6 +116,7 @@ int inter_mail_savemessage(struct mail_message* msg)
SqlStmt* stmt;
int j;
+ nullpo_ret(msg);
// build message save query
StrBuf->Init(&buf);
StrBuf->Printf(&buf, "INSERT INTO `%s` (`send_name`, `send_id`, `dest_name`, `dest_id`, `title`, `message`, `time`, `status`, `zeny`, `amount`, `nameid`, `refine`, `attribute`, `identify`, `unique_id`", mail_db);
@@ -151,6 +154,7 @@ static bool inter_mail_loadmessage(int mail_id, struct mail_message* msg)
{
int j;
StringBuf buf;
+ nullpo_ret(msg);
memset(msg, 0, sizeof(struct mail_message)); // Initialize data
StrBuf->Init(&buf);
@@ -203,6 +207,7 @@ static bool inter_mail_loadmessage(int mail_id, struct mail_message* msg)
void mapif_mail_sendinbox(int fd, int char_id, unsigned char flag, struct mail_data *md)
{
+ nullpo_retv(md);
//FIXME: dumping the whole structure like this is unsafe [ultramage]
WFIFOHEAD(fd, sizeof(struct mail_data) + 9);
WFIFOW(fd,0) = 0x3848;
@@ -263,6 +268,7 @@ static bool inter_mail_DeleteAttach(int mail_id)
void mapif_mail_sendattach(int fd, int char_id, struct mail_message *msg)
{
+ nullpo_retv(msg);
WFIFOHEAD(fd, sizeof(struct item) + 12);
WFIFOW(fd,0) = 0x384a;
WFIFOW(fd,2) = sizeof(struct item) + 12;
@@ -402,6 +408,7 @@ void mapif_mail_send(int fd, struct mail_message* msg)
{
int len = sizeof(struct mail_message) + 4;
+ nullpo_retv(msg);
WFIFOHEAD(fd,len);
WFIFOW(fd,0) = 0x384d;
WFIFOW(fd,2) = len;
@@ -449,6 +456,11 @@ void mapif_parse_mail_send(int fd)
void inter_mail_sendmail(int send_id, const char* send_name, int dest_id, const char* dest_name, const char* title, const char* body, int zeny, struct item *item)
{
struct mail_message msg;
+ nullpo_retv(send_name);
+ nullpo_retv(dest_name);
+ nullpo_retv(title);
+ nullpo_retv(body);
+ nullpo_retv(item);
memset(&msg, 0, sizeof(struct mail_message));
msg.send_id = send_id;
diff --git a/src/char/int_mercenary.c b/src/char/int_mercenary.c
index 2bd94b97e..3321627c0 100644
--- a/src/char/int_mercenary.c
+++ b/src/char/int_mercenary.c
@@ -15,6 +15,7 @@
#include "mapif.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/sql.h"
@@ -27,6 +28,7 @@ bool inter_mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status)
{
char* data;
+ nullpo_ret(status);
if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith` FROM `%s` WHERE `char_id` = '%d'", mercenary_owner_db, char_id) )
{
Sql_ShowDebug(inter->sql_handle);
@@ -53,6 +55,7 @@ bool inter_mercenary_owner_fromsql(int char_id, struct mmo_charstatus *status)
bool inter_mercenary_owner_tosql(int char_id, struct mmo_charstatus *status)
{
+ nullpo_ret(status);
if( SQL_ERROR == SQL->Query(inter->sql_handle, "REPLACE INTO `%s` (`char_id`, `merc_id`, `arch_calls`, `arch_faith`, `spear_calls`, `spear_faith`, `sword_calls`, `sword_faith`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
mercenary_owner_db, char_id, status->mer_id, status->arch_calls, status->arch_faith, status->spear_calls, status->spear_faith, status->sword_calls, status->sword_faith) )
{
@@ -78,6 +81,7 @@ bool mapif_mercenary_save(struct s_mercenary* merc)
{
bool flag = true;
+ nullpo_ret(merc);
if( merc->mercenary_id == 0 )
{ // Create new DB entry
if( SQL_ERROR == SQL->Query(inter->sql_handle,
@@ -105,6 +109,7 @@ bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc)
{
char* data;
+ nullpo_ret(merc);
memset(merc, 0, sizeof(struct s_mercenary));
merc->mercenary_id = merc_id;
merc->char_id = char_id;
@@ -148,6 +153,7 @@ void mapif_mercenary_send(int fd, struct s_mercenary *merc, unsigned char flag)
{
int size = sizeof(struct s_mercenary) + 5;
+ nullpo_retv(merc);
WFIFOHEAD(fd,size);
WFIFOW(fd,0) = 0x3870;
WFIFOW(fd,2) = size;
diff --git a/src/char/int_party.c b/src/char/int_party.c
index bf950ec42..79bd1139c 100644
--- a/src/char/int_party.c
+++ b/src/char/int_party.c
@@ -18,6 +18,7 @@
#include "../common/malloc.h"
#include "../common/mapindex.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/sql.h"
@@ -29,6 +30,7 @@ struct inter_party_interface inter_party_s;
static int inter_party_check_lv(struct party_data *p) {
int i;
unsigned int lv;
+ nullpo_ret(p);
p->min_lv = UINT_MAX;
p->max_lv = 0;
for(i=0;i<MAX_PARTY;i++){
@@ -54,6 +56,7 @@ static int inter_party_check_lv(struct party_data *p) {
static void inter_party_calc_state(struct party_data *p)
{
int i;
+ nullpo_retv(p);
p->min_lv = UINT_MAX;
p->max_lv = 0;
p->party.count =
@@ -109,6 +112,7 @@ int inter_party_tosql(struct party *p, int flag, int index)
if( p == NULL || p->party_id == 0 )
return 0;
+ Assert_ret(index >= 0 && index < MAX_PARTY);
party_id = p->party_id;
#ifdef NOISY
@@ -295,6 +299,7 @@ struct party_data* inter_party_search_partyname(const char *const str)
// Returns whether this party can keep having exp share or not.
int inter_party_check_exp_share(struct party_data *const p)
{
+ nullpo_ret(p);
return (p->party.count < 2 || p->max_lv - p->min_lv <= party_share_level);
}
@@ -318,6 +323,7 @@ int inter_party_check_empty(struct party_data *p)
// Create a party whether or not
int mapif_party_created(int fd, int account_id, int char_id, struct party *p)
{
+ nullpo_ret(p);
WFIFOHEAD(fd, 39);
WFIFOW(fd,0)=0x3820;
WFIFOL(fd,2)=account_id;
@@ -353,6 +359,7 @@ void mapif_party_noinfo(int fd, int party_id, int char_id)
void mapif_party_info(int fd, struct party* p, int char_id)
{
unsigned char buf[8 + sizeof(struct party)];
+ nullpo_retv(p);
WBUFW(buf,0) = 0x3821;
WBUFW(buf,2) = 8 + sizeof(struct party);
WBUFL(buf,4) = char_id;
@@ -381,6 +388,7 @@ int mapif_party_memberadded(int fd, int party_id, int account_id, int char_id, i
int mapif_party_optionchanged(int fd, struct party *p, int account_id, int flag)
{
unsigned char buf[16];
+ nullpo_ret(p);
WBUFW(buf,0)=0x3823;
WBUFL(buf,2)=p->party_id;
WBUFL(buf,6)=account_id;
@@ -411,6 +419,8 @@ int mapif_party_membermoved(struct party *p, int idx)
{
unsigned char buf[20];
+ nullpo_ret(p);
+ Assert_ret(idx >= 0 && idx < MAX_PARTY);
WBUFW(buf,0) = 0x3825;
WBUFL(buf,2) = p->party_id;
WBUFL(buf,6) = p->member[idx].account_id;
@@ -438,6 +448,7 @@ int mapif_party_broken(int party_id, int flag)
int mapif_party_message(int party_id, int account_id, char *mes, int len, int sfd)
{
unsigned char buf[512];
+ nullpo_ret(mes);
WBUFW(buf,0)=0x3827;
WBUFW(buf,2)=len+12;
WBUFL(buf,4)=party_id;
@@ -456,6 +467,8 @@ int mapif_parse_CreateParty(int fd, char *name, int item, int item2, struct part
{
struct party_data *p;
int i;
+ nullpo_ret(name);
+ nullpo_ret(leader);
if( (p=inter_party->search_partyname(name))!=NULL){
mapif->party_created(fd,leader->account_id,leader->char_id,NULL);
return 0;
@@ -523,6 +536,7 @@ int mapif_parse_PartyAddMember(int fd, int party_id, struct party_member *member
struct party_data *p;
int i;
+ nullpo_ret(member);
p = inter_party->fromsql(party_id);
if( p == NULL || p->size == MAX_PARTY ) {
mapif->party_memberadded(fd, party_id, member->account_id, member->char_id, 1);
diff --git a/src/char/int_pet.c b/src/char/int_pet.c
index b37037844..b01777771 100644
--- a/src/char/int_pet.c
+++ b/src/char/int_pet.c
@@ -15,6 +15,7 @@
#include "mapif.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/sql.h"
@@ -29,6 +30,7 @@ int inter_pet_tosql(int pet_id, struct s_pet* p)
//`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`)
char esc_name[NAME_LENGTH*2+1];// escaped pet name
+ nullpo_ret(p);
SQL->EscapeStringLen(inter->sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH));
p->hungry = cap_value(p->hungry, 0, 100);
p->intimate = cap_value(p->intimate, 0, 1000);
@@ -70,6 +72,7 @@ int inter_pet_fromsql(int pet_id, struct s_pet* p)
#ifdef NOISY
ShowInfo("Loading pet (%d)...\n",pet_id);
#endif
+ nullpo_ret(p);
memset(p, 0, sizeof(struct s_pet));
//`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`)
@@ -145,6 +148,7 @@ int mapif_pet_created(int fd, int account_id, struct s_pet *p)
int mapif_pet_info(int fd, int account_id, struct s_pet *p)
{
+ nullpo_ret(p);
WFIFOHEAD(fd, sizeof(struct s_pet) + 9);
WFIFOW(fd, 0) =0x3881;
WFIFOW(fd, 2) =sizeof(struct s_pet) + 9;
@@ -193,6 +197,7 @@ int mapif_delete_pet_ack(int fd, int flag)
int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id,
short pet_equip, short intimate, short hungry, char rename_flag, char incubate, char *pet_name)
{
+ nullpo_ret(pet_name);
memset(inter_pet->pt, 0, sizeof(struct s_pet));
safestrncpy(inter_pet->pt->name, pet_name, NAME_LENGTH);
if(incubate == 1)
@@ -254,6 +259,7 @@ int mapif_save_pet(int fd, int account_id, struct s_pet *data)
{
//here process pet save request.
int len;
+ nullpo_ret(data);
RFIFOHEAD(fd);
len=RFIFOW(fd, 2);
if (sizeof(struct s_pet) != len-8) {
diff --git a/src/char/int_quest.c b/src/char/int_quest.c
index dd3d4e1bf..036229edd 100644
--- a/src/char/int_quest.c
+++ b/src/char/int_quest.c
@@ -16,6 +16,7 @@
#include "../common/db.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/sql.h"
@@ -66,8 +67,9 @@ struct quest *mapif_quests_fromsql(int char_id, int *count)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &tmp_quest.state, 0, NULL, NULL)
|| SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UINT, &tmp_quest.time, 0, NULL, NULL)
- )
+ ) {
sqlerror = SQL_ERROR;
+ }
StrBuf->Destroy(&buf);
@@ -249,8 +251,10 @@ void mapif_send_quests(int fd, int char_id, struct quest *tmp_questlog, int num_
WFIFOW(fd,2) = num_quests*sizeof(struct quest)+8;
WFIFOL(fd,4) = char_id;
- if (num_quests > 0)
+ if (num_quests > 0) {
+ nullpo_retv(tmp_questlog);
memcpy(WFIFOP(fd,8), tmp_questlog, sizeof(struct quest)*num_quests);
+ }
WFIFOSET(fd,num_quests*sizeof(struct quest)+8);
}
diff --git a/src/char/int_storage.c b/src/char/int_storage.c
index db49eb46e..7afafc406 100644
--- a/src/char/int_storage.c
+++ b/src/char/int_storage.c
@@ -16,6 +16,7 @@
#include "mapif.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/sql.h"
@@ -28,6 +29,7 @@ struct inter_storage_interface inter_storage_s;
/// Save storage data to sql
int inter_storage_tosql(int account_id, struct storage_data* p)
{
+ nullpo_ret(p);
chr->memitemdata_to_sql(p->items, MAX_STORAGE, account_id, TABLE_STORAGE);
return 0;
}
@@ -40,6 +42,7 @@ int inter_storage_fromsql(int account_id, struct storage_data* p)
int i;
int j;
+ nullpo_ret(p);
memset(p, 0, sizeof(struct storage_data)); //clean up memory
p->storage_amount = 0;
@@ -82,6 +85,7 @@ int inter_storage_fromsql(int account_id, struct storage_data* p)
/// Save guild_storage data to sql
int inter_storage_guild_storage_tosql(int guild_id, struct guild_storage* p)
{
+ nullpo_ret(p);
chr->memitemdata_to_sql(p->items, MAX_GUILD_STORAGE, guild_id, TABLE_GUILD_STORAGE);
ShowInfo ("guild storage save to DB - guild: %d\n", guild_id);
return 0;
@@ -95,6 +99,7 @@ int inter_storage_guild_storage_fromsql(int guild_id, struct guild_storage* p)
int i;
int j;
+ nullpo_ret(p);
memset(p, 0, sizeof(struct guild_storage)); //clean up memory
p->storage_amount = 0;
p->guild_id = guild_id;
@@ -297,7 +302,8 @@ int mapif_parse_ItemBoundRetrieve_sub(int fd)
for( j = 0; j < MAX_SLOTS; ++j )
SQL->StmtBindColumn(stmt, 10+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL);
- while( SQL_SUCCESS == SQL->StmtNextRow(stmt) ) {
+ while( SQL_SUCCESS == SQL->StmtNextRow(stmt)) {
+ Assert_retb(i >= MAX_INVENTORY);
memcpy(&items[i],&item,sizeof(struct item));
i++;
}
diff --git a/src/char/inter.c b/src/char/inter.c
index eb14f1593..ec06df0f9 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -27,6 +27,7 @@
#include "../common/db.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/strlib.h"
@@ -97,6 +98,7 @@ bool inter_msg_config_read(const char *cfg_name, bool allow_override)
FILE *fp;
static int called = 1;
+ nullpo_ret(cfg_name);
if ((fp = fopen(cfg_name, "r")) == NULL) {
ShowError("Messages file not found: %s\n", cfg_name);
return 1;
@@ -384,6 +386,7 @@ void inter_vmsg_to_fd(int fd, int u_fd, int aid, char* msg, va_list ap)
va_list apcopy;
int len = 1;/* yes we start at 1 */
+ nullpo_retv(msg);
va_copy(apcopy, ap);
len += vsnprintf(msg_out, 512, msg, apcopy);
va_end(apcopy);
@@ -484,6 +487,12 @@ void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int acc
const char *email, const char *last_ip, const char *lastlogin, const char *pin_code, const char *birthdate,
int group_id, int logincount, int state)
{
+ nullpo_retv(userid);
+ nullpo_retv(user_pass);
+ nullpo_retv(email);
+ nullpo_retv(last_ip);
+ nullpo_retv(lastlogin);
+ nullpo_retv(birthdate);
if (map_fd <= 0 || !session_isActive(map_fd))
return; // check if we have a valid fd
@@ -546,6 +555,7 @@ void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int acc
**/
void inter_savereg(int account_id, int char_id, const char *key, unsigned int index, intptr_t val, bool is_string)
{
+ nullpo_retv(key);
/* to login server we go! */
if( key[0] == '#' && key[1] == '#' ) {/* global account reg */
if( session_isValid(chr->login_fd) )
@@ -769,6 +779,7 @@ static int inter_config_read(const char* cfgName)
char line[1024], w1[1024], w2[1024];
FILE* fp;
+ nullpo_retr(1, cfgName);
fp = fopen(cfgName, "r");
if(fp == NULL) {
ShowError("File not found: %s\n", cfgName);
@@ -916,6 +927,8 @@ int mapif_broadcast(unsigned char *mes, int len, unsigned int fontColor, short f
{
unsigned char *buf = (unsigned char*)aMalloc((len)*sizeof(unsigned char));
+ nullpo_ret(mes);
+ Assert_ret(len >= 16);
WBUFW(buf,0) = 0x3800;
WBUFW(buf,2) = len;
WBUFL(buf,4) = fontColor;
@@ -934,8 +947,12 @@ int mapif_broadcast(unsigned char *mes, int len, unsigned int fontColor, short f
int mapif_wis_message(struct WisData *wd)
{
unsigned char buf[2048];
+ nullpo_ret(wd);
//if (wd->len > 2047-56) wd->len = 2047-56; //Force it to fit to avoid crashes. [Skotlex]
- if( wd->len >= sizeof(wd->msg) - 1 ) wd->len = sizeof(wd->msg) - 1;
+ if (wd->len < 0)
+ wd->len = 0;
+ if (wd->len >= sizeof(wd->msg) - 1)
+ wd->len = sizeof(wd->msg) - 1;
WBUFW(buf, 0) = 0x3801;
WBUFW(buf, 2) = 56 +wd->len;
@@ -951,6 +968,7 @@ int mapif_wis_message(struct WisData *wd)
void mapif_wis_response(int fd, unsigned char *src, int flag)
{
unsigned char buf[27];
+ nullpo_retv(src);
WBUFW(buf, 0)=0x3802;
memcpy(WBUFP(buf, 2),src,24);
WBUFB(buf,26)=flag;
@@ -960,6 +978,7 @@ void mapif_wis_response(int fd, unsigned char *src, int flag)
// Wis sending result
int mapif_wis_end(struct WisData *wd, int flag)
{
+ nullpo_ret(wd);
mapif->wis_response(wd->fd, wd->src, flag);
return 0;
}
@@ -968,6 +987,7 @@ int mapif_wis_end(struct WisData *wd, int flag)
// Account registry transfer to map-server
static void mapif_account_reg(int fd, unsigned char *src)
{
+ nullpo_retv(src);
WBUFW(src,0)=0x3804; //NOTE: writing to RFIFO
mapif->sendallwos(fd, src, WBUFW(src,2));
}
@@ -1005,6 +1025,7 @@ int inter_check_ttl_wisdata_sub(DBKey key, DBData *data, va_list ap)
{
int64 tick;
struct WisData *wd = DB->data2ptr(data);
+ nullpo_ret(wd);
tick = va_arg(ap, int64);
if (DIFF_TICK(tick, wd->tick) > WISDATA_TTL && wis_delnum < WISDELLIST_MAX)
@@ -1208,6 +1229,7 @@ int mapif_parse_RegistryRequest(int fd)
void mapif_namechange_ack(int fd, int account_id, int char_id, int type, int flag, const char *const name)
{
+ nullpo_retv(name);
WFIFOHEAD(fd, NAME_LENGTH+13);
WFIFOW(fd, 0) = 0x3806;
WFIFOL(fd, 2) = account_id;
diff --git a/src/char/loginif.c b/src/char/loginif.c
index 5247e6c3e..f53d9bb71 100644
--- a/src/char/loginif.c
+++ b/src/char/loginif.c
@@ -14,6 +14,7 @@
#include "../common/cbasetypes.h"
#include "../common/core.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/timer.h"
@@ -88,6 +89,7 @@ void do_final_loginif(void)
void loginif_block_account(int account_id, int flag)
{
+ Assert_retv(chr->login_fd != -1);
WFIFOHEAD(chr->login_fd,10);
WFIFOW(chr->login_fd,0) = 0x2724;
WFIFOL(chr->login_fd,2) = account_id;
@@ -97,6 +99,7 @@ void loginif_block_account(int account_id, int flag)
void loginif_ban_account(int account_id, short year, short month, short day, short hour, short minute, short second)
{
+ Assert_retv(chr->login_fd != -1);
WFIFOHEAD(chr->login_fd,18);
WFIFOW(chr->login_fd, 0) = 0x2725;
WFIFOL(chr->login_fd, 2) = account_id;
@@ -111,6 +114,7 @@ void loginif_ban_account(int account_id, short year, short month, short day, sho
void loginif_unban_account(int account_id)
{
+ Assert_retv(chr->login_fd != -1);
WFIFOHEAD(chr->login_fd,6);
WFIFOW(chr->login_fd,0) = 0x272a;
WFIFOL(chr->login_fd,2) = account_id;
@@ -119,6 +123,7 @@ void loginif_unban_account(int account_id)
void loginif_changesex(int account_id)
{
+ Assert_retv(chr->login_fd != -1);
WFIFOHEAD(chr->login_fd,6);
WFIFOW(chr->login_fd,0) = 0x2727;
WFIFOL(chr->login_fd,2) = account_id;
@@ -127,6 +132,8 @@ void loginif_changesex(int account_id)
void loginif_auth(int fd, struct char_session_data* sd, uint32 ipl)
{
+ Assert_retv(chr->login_fd != -1);
+ nullpo_retv(sd);
WFIFOHEAD(chr->login_fd,23);
WFIFOW(chr->login_fd,0) = 0x2712; // ask login-server to authenticate an account
WFIFOL(chr->login_fd,2) = sd->account_id;
@@ -140,6 +147,7 @@ void loginif_auth(int fd, struct char_session_data* sd, uint32 ipl)
void loginif_send_users_count(int users)
{
+ Assert_retv(chr->login_fd != -1);
WFIFOHEAD(chr->login_fd,6);
WFIFOW(chr->login_fd,0) = 0x2714;
WFIFOL(chr->login_fd,2) = users;
@@ -148,6 +156,7 @@ void loginif_send_users_count(int users)
void loginif_connect_to_server(void)
{
+ Assert_retv(chr->login_fd != -1);
WFIFOHEAD(chr->login_fd,86);
WFIFOW(chr->login_fd,0) = 0x2710;
memcpy(WFIFOP(chr->login_fd,2), chr->userid, NAME_LENGTH);
diff --git a/src/char/pincode.c b/src/char/pincode.c
index b8b30a1b8..c3d2b2298 100644
--- a/src/char/pincode.c
+++ b/src/char/pincode.c
@@ -11,6 +11,7 @@
#include "char.h"
#include "../common/cbasetypes.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/random.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
@@ -18,9 +19,10 @@
struct pincode_interface pincode_s;
-void pincode_handle ( int fd, struct char_session_data* sd ) {
+void pincode_handle (int fd, struct char_session_data* sd) {
struct online_char_data* character = (struct online_char_data*)idb_get(chr->online_char_db, sd->account_id);
+ nullpo_retv(sd);
if( character && character->pincode_enable > pincode->charselect ){
character->pincode_enable = pincode->charselect * 2;
}else{
@@ -44,6 +46,7 @@ void pincode_handle ( int fd, struct char_session_data* sd ) {
void pincode_check(int fd, struct char_session_data* sd) {
char pin[5] = "\0\0\0\0";
+ nullpo_retv(sd);
safestrncpy(pin, (char*)RFIFOP(fd, 6), sizeof(pin));
pincode->decrypt(sd->pincode_seed, pin);
if( pincode->compare( fd, sd, pin ) ){
@@ -55,6 +58,8 @@ void pincode_check(int fd, struct char_session_data* sd) {
}
int pincode_compare(int fd, struct char_session_data* sd, char* pin) {
+ nullpo_ret(sd);
+ nullpo_ret(pin);
if( strcmp( sd->pincode, pin ) == 0 ){
sd->pincode_try = 0;
return 1;
@@ -70,6 +75,7 @@ int pincode_compare(int fd, struct char_session_data* sd, char* pin) {
void pincode_change(int fd, struct char_session_data* sd) {
char oldpin[5] = "\0\0\0\0", newpin[5] = "\0\0\0\0";
+ nullpo_retv(sd);
safestrncpy(oldpin, (char*)RFIFOP(fd,6), sizeof(oldpin));
pincode->decrypt(sd->pincode_seed,oldpin);
if( !pincode->compare( fd, sd, oldpin ) )
@@ -85,6 +91,7 @@ void pincode_change(int fd, struct char_session_data* sd) {
void pincode_setnew(int fd, struct char_session_data* sd) {
char newpin[5] = "\0\0\0\0";
+ nullpo_retv(sd);
safestrncpy(newpin, (char*)RFIFOP(fd,6), sizeof(newpin));
pincode->decrypt(sd->pincode_seed,newpin);
pincode->update( sd->account_id, newpin );
@@ -102,6 +109,7 @@ void pincode_setnew(int fd, struct char_session_data* sd) {
// 7 = char select window shows a button - client sends 0x8c5
// 8 = pincode was incorrect
void pincode_sendstate(int fd, struct char_session_data* sd, uint16 state) {
+ nullpo_retv(sd);
WFIFOHEAD(fd, 12);
WFIFOW(fd, 0) = 0x8b9;
WFIFOL(fd, 2) = sd->pincode_seed = rnd() % 0xFFFF;
@@ -111,6 +119,8 @@ void pincode_sendstate(int fd, struct char_session_data* sd, uint16 state) {
}
void pincode_notifyLoginPinUpdate(int account_id, char* pin) {
+ nullpo_retv(pin);
+ Assert_retv(chr->login_fd != -1);
WFIFOHEAD(chr->login_fd,11);
WFIFOW(chr->login_fd,0) = 0x2738;
WFIFOL(chr->login_fd,2) = account_id;
@@ -129,6 +139,7 @@ void pincode_decrypt(unsigned int userSeed, char* pin) {
int i;
char tab[10] = {0,1,2,3,4,5,6,7,8,9};
+ nullpo_retv(pin);
for (i = 1; i < 10; i++) {
int pos;
userSeed = pincode->baseSeed + userSeed * pincode->multiplier;
@@ -149,6 +160,8 @@ void pincode_decrypt(unsigned int userSeed, char* pin) {
bool pincode_config_read(char *w1, char *w2) {
+ nullpo_ret(w1);
+ nullpo_ret(w2);
while ( true ) {
if ( strcmpi(w1, "pincode_enabled") == 0 ) {
pincode->enabled = atoi(w2);
diff --git a/src/login/account_sql.c b/src/login/account_sql.c
index f745d3d13..8975250b8 100644
--- a/src/login/account_sql.c
+++ b/src/login/account_sql.c
@@ -13,6 +13,7 @@
#include "../common/console.h"
#include "../common/malloc.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
#include "../common/sql.h"
@@ -136,6 +137,7 @@ static bool account_db_sql_init(AccountDB* self)
const char* database;
const char* codepage;
+ nullpo_ret(db);
db->accounts = SQL->Malloc();
sql_handle = db->accounts;
@@ -181,6 +183,7 @@ static void account_db_sql_destroy(AccountDB* self)
{
AccountDB_SQL* db = (AccountDB_SQL*)self;
+ nullpo_retv(db);
SQL->Free(db->accounts);
db->accounts = NULL;
aFree(db);
@@ -192,6 +195,9 @@ static bool account_db_sql_get_property(AccountDB* self, const char* key, char*
AccountDB_SQL* db = (AccountDB_SQL*)self;
const char* signature;
+ nullpo_ret(db);
+ nullpo_ret(key);
+ nullpo_ret(buf);
signature = "engine.";
if( strncmpi(key, signature, strlen(signature)) == 0 )
{
@@ -282,7 +288,9 @@ static bool account_db_sql_set_property(AccountDB* self, const char* key, const
AccountDB_SQL* db = (AccountDB_SQL*)self;
const char* signature;
-
+ nullpo_ret(db);
+ nullpo_ret(key);
+ nullpo_ret(value);
signature = "sql.";
if( strncmp(key, signature, strlen(signature)) == 0 )
{
@@ -360,6 +368,8 @@ static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc)
// decide on the account id to assign
int account_id;
+ nullpo_ret(db);
+ nullpo_ret(acc);
if( acc->account_id != -1 )
{// caller specifies it manually
account_id = acc->account_id;
@@ -410,6 +420,7 @@ static bool account_db_sql_remove(AccountDB* self, const int account_id)
Sql* sql_handle = db->accounts;
bool result = false;
+ nullpo_ret(db);
if( SQL_SUCCESS != SQL->QueryStr(sql_handle, "START TRANSACTION")
|| SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->account_db, account_id)
|| SQL_SUCCESS != SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `account_id` = %d", db->global_acc_reg_num_db, account_id)
@@ -442,11 +453,13 @@ static bool account_db_sql_load_num(AccountDB* self, struct mmo_account* acc, co
static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, const char* userid)
{
AccountDB_SQL* db = (AccountDB_SQL*)self;
- Sql* sql_handle = db->accounts;
+ Sql* sql_handle;
char esc_userid[2*NAME_LENGTH+1];
int account_id;
char* data;
+ nullpo_ret(db);
+ sql_handle = db->accounts;
SQL->EscapeString(sql_handle, esc_userid, userid);
// get the list of account IDs for this user ID
@@ -481,8 +494,10 @@ static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, co
static AccountDBIterator* account_db_sql_iterator(AccountDB* self)
{
AccountDB_SQL* db = (AccountDB_SQL*)self;
- AccountDBIterator_SQL* iter = (AccountDBIterator_SQL*)aCalloc(1, sizeof(AccountDBIterator_SQL));
+ AccountDBIterator_SQL* iter;
+ nullpo_retr(NULL, db);
+ iter = (AccountDBIterator_SQL*)aCalloc(1, sizeof(AccountDBIterator_SQL));
// set up the vtable
iter->vtable.destroy = &account_db_sql_iter_destroy;
iter->vtable.next = &account_db_sql_iter_next;
@@ -507,10 +522,14 @@ static void account_db_sql_iter_destroy(AccountDBIterator* self)
static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account* acc)
{
AccountDBIterator_SQL* iter = (AccountDBIterator_SQL*)self;
- AccountDB_SQL* db = (AccountDB_SQL*)iter->db;
- Sql* sql_handle = db->accounts;
+ AccountDB_SQL* db;
+ Sql* sql_handle;
char* data;
+ nullpo_ret(iter);
+ db = (AccountDB_SQL*)iter->db;
+ nullpo_ret(db);
+ sql_handle = db->accounts;
// get next account ID
if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `account_id` FROM `%s` WHERE `account_id` > '%d' ORDER BY `account_id` ASC LIMIT 1",
db->account_db, iter->last_account_id) )
@@ -539,9 +558,12 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account
static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id)
{
- Sql* sql_handle = db->accounts;
+ Sql* sql_handle;
char* data;
+ nullpo_ret(db);
+ nullpo_ret(acc);
+ sql_handle = db->accounts;
// retrieve login entry for the specified account
if( SQL_ERROR == SQL->Query(sql_handle,
"SELECT `account_id`,`userid`,`user_pass`,`sex`,`email`,`group_id`,`state`,`unban_time`,`expiration_time`,`logincount`,`lastlogin`,`last_ip`,`birthdate`,`character_slots`,`pincode`,`pincode_change` FROM `%s` WHERE `account_id` = %d",
@@ -581,10 +603,14 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc
static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new)
{
- Sql* sql_handle = db->accounts;
- SqlStmt* stmt = SQL->StmtMalloc(sql_handle);
+ Sql* sql_handle;
+ SqlStmt* stmt;
bool result = false;
+ nullpo_ret(db);
+ sql_handle = db->accounts;
+ stmt = SQL->StmtMalloc(sql_handle);
+
// try
do
{
@@ -666,6 +692,7 @@ void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
int count = RFIFOW(fd, 12);
+ nullpo_retv(db);
if (count) {
int cursor = 14, i;
char key[32], sval[254];
@@ -709,12 +736,14 @@ void mmo_save_accreg2(AccountDB* self, int fd, int account_id, int char_id) {
}
void mmo_send_accreg2(AccountDB* self, int fd, int account_id, int char_id) {
- Sql* sql_handle = ((AccountDB_SQL*)self)->accounts;
+ Sql* sql_handle;
AccountDB_SQL* db = (AccountDB_SQL*)self;
char* data;
int plen = 0;
size_t len;
+ nullpo_retv(db);
+ sql_handle = ((AccountDB_SQL*)self)->accounts;
if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `key`, `index`, `value` FROM `%s` WHERE `account_id`='%d'", db->global_acc_reg_str_db, account_id) )
Sql_ShowDebug(sql_handle);
diff --git a/src/login/ipban_sql.c b/src/login/ipban_sql.c
index bfc90ad11..f995450ce 100644
--- a/src/login/ipban_sql.c
+++ b/src/login/ipban_sql.c
@@ -14,6 +14,7 @@
#include "../common/cbasetypes.h"
#include "../common/db.h"
#include "../common/malloc.h"
+#include "../common/nullpo.h"
#include "../common/sql.h"
#include "../common/socket.h"
#include "../common/strlib.h"
@@ -118,6 +119,8 @@ bool ipban_config_read(const char* key, const char* value)
{
const char* signature;
+ nullpo_ret(key);
+ nullpo_ret(value);
if( ipban_inited )
return false;// settings can only be changed before init
@@ -220,8 +223,8 @@ bool ipban_check(uint32 ip)
return true;
}
- if( SQL_ERROR == SQL->NextRow(sql_handle) )
- return true;// Shouldn't happen, but just in case...
+ if( SQL_SUCCESS != SQL->NextRow(sql_handle) )
+ return false;
SQL->GetData(sql_handle, 0, &data, NULL);
matches = atoi(data);
@@ -244,9 +247,11 @@ void ipban_log(uint32 ip)
if( failures >= login_config.dynamic_pass_failure_ban_limit )
{
uint8* p = (uint8*)&ip;
- if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`list`,`btime`,`rtime`,`reason`) VALUES ('%u.%u.%u.*', NOW() , NOW() + INTERVAL %d MINUTE ,'Password error ban')",
- ipban_table, p[3], p[2], p[1], login_config.dynamic_pass_failure_ban_duration) )
+ if (SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s`(`list`,`btime`,`rtime`,`reason`) VALUES ('%u.%u.%u.*', NOW() , NOW() + INTERVAL %d MINUTE ,'Password error ban')",
+ ipban_table, p[3], p[2], p[1], login_config.dynamic_pass_failure_ban_duration))
+ {
Sql_ShowDebug(sql_handle);
+ }
}
}
diff --git a/src/login/login.c b/src/login/login.c
index 846f24027..95cbab70d 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -19,6 +19,7 @@
#include "../common/db.h"
#include "../common/malloc.h"
#include "../common/md5calc.h"
+#include "../common/nullpo.h"
#include "../common/random.h"
#include "../common/showmsg.h"
#include "../common/socket.h"
@@ -98,6 +99,7 @@ static int login_online_db_setoffline(DBKey key, DBData *data, va_list ap)
{
struct online_login_data* p = DB->data2ptr(data);
int server_id = va_arg(ap, int);
+ nullpo_ret(p);
if( server_id == -1 )
{
p->char_server = -1;
@@ -118,6 +120,7 @@ static int login_online_db_setoffline(DBKey key, DBData *data, va_list ap)
static int login_online_data_cleanup_sub(DBKey key, DBData *data, va_list ap)
{
struct online_login_data *character= DB->data2ptr(data);
+ nullpo_ret(character);
if (character->char_server == -2) //Unknown server.. set them offline
login->remove_online_user(character->account_id);
return 0;
@@ -136,6 +139,7 @@ int charif_sendallwos(int sfd, uint8* buf, size_t len)
{
int i, c;
+ nullpo_ret(buf);
for( i = 0, c = 0; i < ARRAYLENGTH(server); ++i )
{
int fd = server[i].fd;
@@ -155,6 +159,7 @@ int charif_sendallwos(int sfd, uint8* buf, size_t len)
/// Initializes a server structure.
void chrif_server_init(int id)
{
+ Assert_retv(id >= 0 && id < MAX_SERVERS);
memset(&server[id], 0, sizeof(server[id]));
server[id].fd = -1;
}
@@ -163,7 +168,8 @@ void chrif_server_init(int id)
/// Destroys a server structure.
void chrif_server_destroy(int id)
{
- if( server[id].fd != -1 )
+ Assert_retv(id >= 0 && id < MAX_SERVERS);
+ if (server[id].fd != -1)
{
do_close(server[id].fd);
server[id].fd = -1;
@@ -183,6 +189,7 @@ void chrif_server_reset(int id)
/// Called when the connection to Char Server is disconnected.
void chrif_on_disconnect(int id)
{
+ Assert_retv(id >= 0 && id < MAX_SERVERS);
ShowStatus("Char-server '%s' has disconnected.\n", server[id].name);
chrif_server_reset(id);
}
@@ -207,6 +214,9 @@ bool login_check_encrypted(const char* str1, const char* str2, const char* passw
{
char tmpstr[64+1], md5str[32+1];
+ nullpo_ret(str1);
+ nullpo_ret(str2);
+ nullpo_ret(passwd);
safesnprintf(tmpstr, sizeof(tmpstr), "%s%s", str1, str2);
MD5_String(tmpstr, md5str);
@@ -215,6 +225,8 @@ bool login_check_encrypted(const char* str1, const char* str2, const char* passw
bool login_check_password(const char* md5key, int passwdenc, const char* passwd, const char* refpass)
{
+ nullpo_ret(passwd);
+ nullpo_ret(refpass);
if(passwdenc == 0)
{
return (0==strcmp(passwd, refpass));
@@ -248,6 +260,7 @@ int login_lan_config_read(const char *lancfgName)
int line_num = 0;
char line[1024], w1[64], w2[64], w3[64], w4[64];
+ nullpo_ret(lancfgName);
if((fp = fopen(lancfgName, "r")) == NULL) {
ShowWarning("LAN Support configuration file is not found: %s\n", lancfgName);
return 1;
@@ -348,6 +361,7 @@ void login_fromchar_parse_auth(int fd, int id, const char *const ip)
}
else
{// authentication not found
+ nullpo_retv(ip);
ShowStatus("Char-server '%s': authentication of the account %d REFUSED (ip: %s).\n", server[id].name, account_id, ip);
login->fromchar_auth_ack(fd, account_id, login_id1, login_id2, sex, request_id, NULL);
}
@@ -1008,6 +1022,9 @@ int login_mmo_auth_new(const char* userid, const char* pass, const char sex, con
int64 tick = timer->gettick();
struct mmo_account acc;
+ nullpo_retr(3, userid);
+ nullpo_retr(3, pass);
+ nullpo_retr(3, last_ip);
//Account Registration Flood Protection by [Kevin]
if( new_reg_tick == 0 )
new_reg_tick = timer->gettick();
@@ -1065,6 +1082,7 @@ int login_mmo_auth(struct login_session_data* sd, bool isServer) {
size_t len;
char ip[16];
+ nullpo_ret(sd);
ip2str(session[sd->fd]->client_addr, ip);
// DNS Blacklist check
@@ -1206,6 +1224,7 @@ void login_connection_problem(int fd, uint8 status)
void login_kick(struct login_session_data* sd)
{
uint8 buf[6];
+ nullpo_retv(sd);
WBUFW(buf,0) = 0x2734;
WBUFL(buf,2) = sd->account_id;
charif_sendallwos(-1, buf, 6);
@@ -1214,13 +1233,15 @@ void login_kick(struct login_session_data* sd)
void login_auth_ok(struct login_session_data* sd)
{
int fd = sd->fd;
- uint32 ip = session[fd]->client_addr;
+ uint32 ip;
uint8 server_num, n;
uint32 subnet_char_ip;
struct login_auth_node* node;
int i;
+ nullpo_retv(sd);
+ ip = session[fd]->client_addr;
if( runflag != LOGINSERVER_ST_RUNNING )
{
// players can only login while running
@@ -1336,9 +1357,12 @@ void login_auth_ok(struct login_session_data* sd)
void login_auth_failed(struct login_session_data* sd, int result)
{
- int fd = sd->fd;
- uint32 ip = session[fd]->client_addr;
+ int fd;
+ uint32 ip;
+ nullpo_retv(sd);
+ fd = sd->fd;
+ ip = session[fd]->client_addr;
if (login_config.log_login)
{
const char* error;
@@ -1738,7 +1762,9 @@ void login_set_defaults()
int login_config_read(const char* cfgName)
{
char line[1024], w1[1024], w2[1024];
- FILE* fp = fopen(cfgName, "r");
+ FILE* fp;
+ nullpo_retr(1, cfgName);
+ fp = fopen(cfgName, "r");
if (fp == NULL) {
ShowError("Configuration file (%s) not found.\n", cfgName);
return 1;
diff --git a/src/login/loginlog_sql.c b/src/login/loginlog_sql.c
index 5654b4c5b..8ed6e395a 100644
--- a/src/login/loginlog_sql.c
+++ b/src/login/loginlog_sql.c
@@ -11,6 +11,7 @@
#include "../common/cbasetypes.h"
#include "../common/mmo.h"
+#include "../common/nullpo.h"
#include "../common/socket.h"
#include "../common/sql.h"
#include "../common/strlib.h"
@@ -67,6 +68,8 @@ void login_log(uint32 ip, const char* username, int rcode, const char* message)
char esc_message[255*2+1];
int retcode;
+ nullpo_retv(username);
+ nullpo_retv(message);
if( !enabled )
return;
@@ -137,6 +140,8 @@ bool loginlog_config_read(const char* key, const char* value)
{
const char* signature;
+ nullpo_ret(key);
+ nullpo_ret(value);
signature = "sql.";
if( strncmpi(key, signature, strlen(signature)) == 0 )
{
diff --git a/src/map/pc.c b/src/map/pc.c
index f28a4cfdd..0905df61b 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -4558,14 +4558,15 @@ int pc_useitem(struct map_session_data *sd,int n) {
amount = sd->status.inventory[n].amount;
item_script = sd->inventory_data[n]->script;
//Check if the item is to be consumed immediately [Skotlex]
- if( sd->inventory_data[n]->flag.delay_consume )
+ if (sd->inventory_data[n]->flag.delay_consume || sd->inventory_data[n]->flag.keepafteruse)
clif->useitemack(sd,n,amount,true);
else {
- if (sd->status.inventory[n].expire_time == 0 && !(sd->inventory_data[n]->flag.keepafteruse)) {
- clif->useitemack(sd,n,amount-1,true);
- pc->delitem(sd,n,1,1,0,LOG_TYPE_CONSUME); // Rental Usable Items are not deleted until expiration
- } else
- clif->useitemack(sd,n,0,false);
+ if (sd->status.inventory[n].expire_time == 0) {
+ clif->useitemack(sd, n, amount - 1, true);
+ pc->delitem(sd, n, 1, 1, 0, LOG_TYPE_CONSUME); // Rental Usable Items are not deleted until expiration
+ } else {
+ clif->useitemack(sd, n, 0, false);
+ }
}
if(sd->status.inventory[n].card[0]==CARD0_CREATE &&
pc->famerank(MakeDWord(sd->status.inventory[n].card[2],sd->status.inventory[n].card[3]), MAPID_ALCHEMIST))
@@ -5868,6 +5869,138 @@ const char* job_name(int class_)
}
}
+int pc_check_job_name(const char *name) {
+ int i, len;
+ struct {
+ const char *name;
+ int id;
+ } names[] = {
+ { "Novice", JOB_NOVICE },
+ { "Swordsman", JOB_SWORDMAN },
+ { "Magician", JOB_MAGE },
+ { "Archer", JOB_ARCHER },
+ { "Acolyte", JOB_ACOLYTE },
+ { "Merchant", JOB_MERCHANT },
+ { "Thief", JOB_THIEF },
+ { "Knight", JOB_KNIGHT },
+ { "Priest", JOB_PRIEST },
+ { "Wizard", JOB_WIZARD },
+ { "Blacksmith", JOB_BLACKSMITH },
+ { "Hunter", JOB_HUNTER },
+ { "Assassin", JOB_ASSASSIN },
+ { "Crusader", JOB_CRUSADER },
+ { "Monk", JOB_MONK },
+ { "Sage", JOB_SAGE },
+ { "Rogue", JOB_ROGUE },
+ { "Alchemist", JOB_ALCHEMIST },
+ { "Bard", JOB_BARD },
+ { "Dancer", JOB_DANCER },
+ { "Super_Novice", JOB_SUPER_NOVICE },
+ { "Gunslinger", JOB_GUNSLINGER },
+ { "Ninja", JOB_NINJA },
+ { "Novice_High", JOB_NOVICE_HIGH },
+ { "Swordsman_High", JOB_SWORDMAN_HIGH },
+ { "Magician_High", JOB_MAGE_HIGH },
+ { "Archer_High", JOB_ARCHER_HIGH },
+ { "Acolyte_High", JOB_ACOLYTE_HIGH },
+ { "Merchant_High", JOB_MERCHANT_HIGH },
+ { "Thief_High", JOB_THIEF_HIGH },
+ { "Lord_Knight", JOB_LORD_KNIGHT },
+ { "High_Priest", JOB_HIGH_PRIEST },
+ { "High_Wizard", JOB_HIGH_WIZARD },
+ { "Whitesmith", JOB_WHITESMITH },
+ { "Sniper", JOB_SNIPER },
+ { "Assassin_Cross", JOB_ASSASSIN_CROSS },
+ { "Paladin", JOB_PALADIN },
+ { "Champion", JOB_CHAMPION },
+ { "Professor", JOB_PROFESSOR },
+ { "Stalker", JOB_STALKER },
+ { "Creator", JOB_CREATOR },
+ { "Clown", JOB_CLOWN },
+ { "Gypsy", JOB_GYPSY },
+ { "Baby_Novice", JOB_BABY },
+ { "Baby_Swordsman", JOB_BABY_SWORDMAN },
+ { "Baby_Magician", JOB_BABY_MAGE },
+ { "Baby_Archer", JOB_BABY_ARCHER },
+ { "Baby_Acolyte", JOB_BABY_ACOLYTE },
+ { "Baby_Merchant", JOB_BABY_MERCHANT },
+ { "Baby_Thief", JOB_BABY_THIEF },
+ { "Baby_Knight", JOB_BABY_KNIGHT },
+ { "Baby_Priest", JOB_BABY_PRIEST },
+ { "Baby_Wizard", JOB_BABY_WIZARD },
+ { "Baby_Blacksmith", JOB_BABY_BLACKSMITH },
+ { "Baby_Hunter", JOB_BABY_HUNTER },
+ { "Baby_Assassin", JOB_BABY_ASSASSIN },
+ { "Baby_Crusader", JOB_BABY_CRUSADER },
+ { "Baby_Monk", JOB_BABY_MONK },
+ { "Baby_Sage", JOB_BABY_SAGE },
+ { "Baby_Rogue", JOB_BABY_ROGUE },
+ { "Baby_Alchemist", JOB_BABY_ALCHEMIST },
+ { "Baby_Bard", JOB_BABY_BARD },
+ { "Baby_Dancer", JOB_BABY_DANCER },
+ { "Super_Baby", JOB_SUPER_BABY },
+ { "Taekwon", JOB_TAEKWON },
+ { "Star_Gladiator", JOB_STAR_GLADIATOR },
+ { "Soul_Linker", JOB_SOUL_LINKER },
+ { "Gangsi", JOB_GANGSI },
+ { "Death_Knight", JOB_DEATH_KNIGHT },
+ { "Dark_Collector", JOB_DARK_COLLECTOR },
+ { "Rune_Knight", JOB_RUNE_KNIGHT },
+ { "Warlock", JOB_WARLOCK },
+ { "Ranger", JOB_RANGER },
+ { "Arch_Bishop", JOB_ARCH_BISHOP },
+ { "Mechanic", JOB_MECHANIC },
+ { "Guillotine_Cross", JOB_GUILLOTINE_CROSS },
+ { "Rune_Knight_Trans", JOB_RUNE_KNIGHT_T },
+ { "Warlock_Trans", JOB_WARLOCK_T },
+ { "Ranger_Trans", JOB_RANGER_T },
+ { "Arch_Bishop_Trans", JOB_ARCH_BISHOP_T },
+ { "Mechanic_Trans", JOB_MECHANIC_T },
+ { "Guillotine_Cross_Trans", JOB_GUILLOTINE_CROSS_T },
+ { "Royal_Guard", JOB_ROYAL_GUARD },
+ { "Sorcerer", JOB_SORCERER },
+ { "Minstrel", JOB_MINSTREL },
+ { "Wanderer", JOB_WANDERER },
+ { "Sura", JOB_SURA },
+ { "Genetic", JOB_GENETIC },
+ { "Shadow_Chaser", JOB_SHADOW_CHASER },
+ { "Royal_Guard_Trans", JOB_ROYAL_GUARD_T },
+ { "Sorcerer_Trans", JOB_SORCERER_T },
+ { "Minstrel_Trans", JOB_MINSTREL_T },
+ { "Wanderer_Trans", JOB_WANDERER_T },
+ { "Sura_Trans", JOB_SURA_T },
+ { "Genetic_Trans", JOB_GENETIC_T },
+ { "Shadow_Chaser_Trans", JOB_SHADOW_CHASER_T },
+ { "Baby_Rune_Knight", JOB_BABY_RUNE },
+ { "Baby_Warlock", JOB_BABY_WARLOCK },
+ { "Baby_Ranger", JOB_BABY_RANGER },
+ { "Baby_Arch_Bishop", JOB_BABY_BISHOP },
+ { "Baby_Mechanic", JOB_BABY_MECHANIC },
+ { "Baby_Guillotine_Cross", JOB_BABY_CROSS },
+ { "Baby_Royal_Guard", JOB_BABY_GUARD },
+ { "Baby_Sorcerer", JOB_BABY_SORCERER },
+ { "Baby_Minstrel", JOB_BABY_MINSTREL },
+ { "Baby_Wanderer", JOB_BABY_WANDERER },
+ { "Baby_Sura", JOB_BABY_SURA },
+ { "Baby_Genetic", JOB_BABY_GENETIC },
+ { "Baby_Shadow_Chaser", JOB_BABY_CHASER },
+ { "Expanded_Super_Novice", JOB_SUPER_NOVICE_E },
+ { "Expanded_Super_Baby", JOB_SUPER_BABY_E },
+ { "Kagerou", JOB_KAGEROU },
+ { "Oboro", JOB_OBORO },
+ { "Rebellion", JOB_REBELLION },
+ };
+
+ len = ARRAYLENGTH(names);
+
+ ARR_FIND(0, len, i, strcmpi(names[i].name, name) == 0);
+
+ if ( i == len )
+ return -1;
+
+ return names[i].id;
+}
+
int pc_follow_timer(int tid, int64 tick, int id, intptr_t data) {
struct map_session_data *sd;
struct block_list *tbl;
@@ -8958,6 +9091,9 @@ void pc_equipitem_pos(struct map_session_data *sd, struct item_data *id, int pos
/*==========================================
* Equip item on player sd at req_pos from inventory index n
+ * Return:
+ * 0 = fail
+ * 1 = success
*------------------------------------------*/
int pc_equipitem(struct map_session_data *sd,int n,int req_pos)
{
@@ -9089,7 +9225,7 @@ int pc_equipitem(struct map_session_data *sd,int n,int req_pos)
}
sd->npc_item_flag = iflag;
- return 0;
+ return 1;
}
void pc_unequipitem_pos(struct map_session_data *sd, int n, int pos)
@@ -9155,6 +9291,9 @@ void pc_unequipitem_pos(struct map_session_data *sd, int n, int pos)
* 0 - only unequip
* 1 - calculate status after unequipping
* 2 - force unequip
+ * Return:
+ * 0 = fail
+ * 1 = success
*------------------------------------------*/
int pc_unequipitem(struct map_session_data *sd,int n,int flag) {
int i,iflag;
@@ -9280,7 +9419,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int flag) {
}
sd->npc_item_flag = iflag;
- return 0;
+ return 1;
}
/*==========================================
@@ -10041,151 +10180,27 @@ void pc_read_skill_tree(void) {
#else
const char *config_filename = "db/pre-re/skill_tree.conf"; // FIXME hardcoded name
#endif
- int i = 0, jnamelen = 0;
+ int i = 0;
struct s_mapiterator *iter;
struct map_session_data *sd;
- struct {
- const char *name;
- int id;
- } jnames[] = {
- { "Novice", JOB_NOVICE },
- { "Swordsman", JOB_SWORDMAN },
- { "Magician", JOB_MAGE },
- { "Archer", JOB_ARCHER },
- { "Acolyte", JOB_ACOLYTE },
- { "Merchant", JOB_MERCHANT },
- { "Thief", JOB_THIEF },
- { "Knight", JOB_KNIGHT },
- { "Priest", JOB_PRIEST },
- { "Wizard", JOB_WIZARD },
- { "Blacksmith", JOB_BLACKSMITH },
- { "Hunter", JOB_HUNTER },
- { "Assassin", JOB_ASSASSIN },
- { "Crusader", JOB_CRUSADER },
- { "Monk", JOB_MONK },
- { "Sage", JOB_SAGE },
- { "Rogue", JOB_ROGUE },
- { "Alchemist", JOB_ALCHEMIST },
- { "Bard", JOB_BARD },
- { "Dancer", JOB_DANCER },
- { "Super_Novice", JOB_SUPER_NOVICE },
- { "Gunslinger", JOB_GUNSLINGER },
- { "Ninja", JOB_NINJA },
- { "Novice_High", JOB_NOVICE_HIGH },
- { "Swordsman_High", JOB_SWORDMAN_HIGH },
- { "Magician_High", JOB_MAGE_HIGH },
- { "Archer_High", JOB_ARCHER_HIGH },
- { "Acolyte_High", JOB_ACOLYTE_HIGH },
- { "Merchant_High", JOB_MERCHANT_HIGH },
- { "Thief_High", JOB_THIEF_HIGH },
- { "Lord_Knight", JOB_LORD_KNIGHT },
- { "High_Priest", JOB_HIGH_PRIEST },
- { "High_Wizard", JOB_HIGH_WIZARD },
- { "Whitesmith", JOB_WHITESMITH },
- { "Sniper", JOB_SNIPER },
- { "Assassin_Cross", JOB_ASSASSIN_CROSS },
- { "Paladin", JOB_PALADIN },
- { "Champion", JOB_CHAMPION },
- { "Professor", JOB_PROFESSOR },
- { "Stalker", JOB_STALKER },
- { "Creator", JOB_CREATOR },
- { "Clown", JOB_CLOWN },
- { "Gypsy", JOB_GYPSY },
- { "Baby_Novice", JOB_BABY },
- { "Baby_Swordsman", JOB_BABY_SWORDMAN },
- { "Baby_Magician", JOB_BABY_MAGE },
- { "Baby_Archer", JOB_BABY_ARCHER },
- { "Baby_Acolyte", JOB_BABY_ACOLYTE },
- { "Baby_Merchant", JOB_BABY_MERCHANT },
- { "Baby_Thief", JOB_BABY_THIEF },
- { "Baby_Knight", JOB_BABY_KNIGHT },
- { "Baby_Priest", JOB_BABY_PRIEST },
- { "Baby_Wizard", JOB_BABY_WIZARD },
- { "Baby_Blacksmith", JOB_BABY_BLACKSMITH },
- { "Baby_Hunter", JOB_BABY_HUNTER },
- { "Baby_Assassin", JOB_BABY_ASSASSIN },
- { "Baby_Crusader", JOB_BABY_CRUSADER },
- { "Baby_Monk", JOB_BABY_MONK },
- { "Baby_Sage", JOB_BABY_SAGE },
- { "Baby_Rogue", JOB_BABY_ROGUE },
- { "Baby_Alchemist", JOB_BABY_ALCHEMIST },
- { "Baby_Bard", JOB_BABY_BARD },
- { "Baby_Dancer", JOB_BABY_DANCER },
- { "Super_Baby", JOB_SUPER_BABY },
- { "Taekwon", JOB_TAEKWON },
- { "Star_Gladiator", JOB_STAR_GLADIATOR },
- { "Soul_Linker", JOB_SOUL_LINKER },
- { "Gangsi", JOB_GANGSI },
- { "Death_Knight", JOB_DEATH_KNIGHT },
- { "Dark_Collector", JOB_DARK_COLLECTOR },
- { "Rune_Knight", JOB_RUNE_KNIGHT },
- { "Warlock", JOB_WARLOCK },
- { "Ranger", JOB_RANGER },
- { "Arch_Bishop", JOB_ARCH_BISHOP },
- { "Mechanic", JOB_MECHANIC },
- { "Guillotine_Cross", JOB_GUILLOTINE_CROSS },
- { "Rune_Knight_Trans", JOB_RUNE_KNIGHT_T },
- { "Warlock_Trans", JOB_WARLOCK_T },
- { "Ranger_Trans", JOB_RANGER_T },
- { "Arch_Bishop_Trans", JOB_ARCH_BISHOP_T },
- { "Mechanic_Trans", JOB_MECHANIC_T },
- { "Guillotine_Cross_Trans", JOB_GUILLOTINE_CROSS_T },
- { "Royal_Guard", JOB_ROYAL_GUARD },
- { "Sorcerer", JOB_SORCERER },
- { "Minstrel", JOB_MINSTREL },
- { "Wanderer", JOB_WANDERER },
- { "Sura", JOB_SURA },
- { "Genetic", JOB_GENETIC },
- { "Shadow_Chaser", JOB_SHADOW_CHASER },
- { "Royal_Guard_Trans", JOB_ROYAL_GUARD_T },
- { "Sorcerer_Trans", JOB_SORCERER_T },
- { "Minstrel_Trans", JOB_MINSTREL_T },
- { "Wanderer_Trans", JOB_WANDERER_T },
- { "Sura_Trans", JOB_SURA_T },
- { "Genetic_Trans", JOB_GENETIC_T },
- { "Shadow_Chaser_Trans", JOB_SHADOW_CHASER_T },
- { "Baby_Rune_Knight", JOB_BABY_RUNE },
- { "Baby_Warlock", JOB_BABY_WARLOCK },
- { "Baby_Ranger", JOB_BABY_RANGER },
- { "Baby_Arch_Bishop", JOB_BABY_BISHOP },
- { "Baby_Mechanic", JOB_BABY_MECHANIC },
- { "Baby_Guillotine_Cross", JOB_BABY_CROSS },
- { "Baby_Royal_Guard", JOB_BABY_GUARD },
- { "Baby_Sorcerer", JOB_BABY_SORCERER },
- { "Baby_Minstrel", JOB_BABY_MINSTREL },
- { "Baby_Wanderer", JOB_BABY_WANDERER },
- { "Baby_Sura", JOB_BABY_SURA },
- { "Baby_Genetic", JOB_BABY_GENETIC },
- { "Baby_Shadow_Chaser", JOB_BABY_CHASER },
- { "Expanded_Super_Novice", JOB_SUPER_NOVICE_E },
- { "Expanded_Super_Baby", JOB_SUPER_BABY_E },
- { "Kagerou", JOB_KAGEROU },
- { "Oboro", JOB_OBORO },
- { "Rebellion", JOB_REBELLION },
- };
if (libconfig->read_file(&skill_tree_conf, config_filename)) {
ShowError("can't read %s\n", config_filename);
return;
}
-
- jnamelen = ARRAYLENGTH(jnames);
-
+
while ((skt = libconfig->setting_get_elem(skill_tree_conf.root,i++))) {
int k;
const char *name = config_setting_name(skt);
- ARR_FIND(0, jnamelen, k, strcmpi(jnames[k].name,name) == 0 );
-
- if( k == jnamelen ) {
- ShowWarning("pc_read_skill_tree: '%s' unknown job name!\n",name);
+ if ( (k = pc->check_job_name(name)) == -1 ) {
+ ShowWarning("pc_read_skill_tree: '%s' unknown job name!\n", name);
continue;
}
-
-
+
if( ( skills = libconfig->setting_get_member(skt,"skills") ) ) {
int c = 0;
- int idx = pc->class2idx(jnames[k].id);
+ int idx = pc->class2idx(k);
while ((sk = libconfig->setting_get_elem(skills,c++))) {
const char *sk_name = config_setting_name(sk);
@@ -10199,7 +10214,7 @@ void pc_read_skill_tree(void) {
ShowWarning("pc_read_skill_tree: Unable to load skill %d (%s) into '%s's tree. Maximum number of skills per class has been reached.\n", skill_id, sk_name, name);
continue;
} else if (pc->skill_tree[idx][skidx].id) {
- ShowNotice("pc_read_skill_tree: Overwriting %d for '%s' (%d)\n", skill_id, name, jnames[k].id);
+ ShowNotice("pc_read_skill_tree: Overwriting %d for '%s' (%d)\n", skill_id, name, k);
}
pc->skill_tree[idx][skidx].id = skill_id;
@@ -10243,46 +10258,42 @@ void pc_read_skill_tree(void) {
while( (skt = libconfig->setting_get_elem(skill_tree_conf.root,i++)) ) {
int k, idx;
const char *name = config_setting_name(skt);
-
-
- ARR_FIND(0, jnamelen, k, strcmpi(jnames[k].name,name) == 0 );
- if( k == jnamelen ) {
- ShowWarning("pc_read_skill_tree: '%s' unknown job name!\n",name);
+ if ( (k = pc->check_job_name(name)) == -1 ) {
+ ShowWarning("pc_read_skill_tree: '%s' unknown job name!\n", name);
continue;
}
- idx = pc->class2idx(jnames[k].id);
+
+ idx = pc->class2idx(k);
if( ( inherit = libconfig->setting_get_member(skt,"inherit") ) ) {
const char *iname;
int v = 0;
- while ((iname = libconfig->setting_get_string_elem(inherit, v++))) {
+ while ( (iname = libconfig->setting_get_string_elem(inherit, v++)) ) {
int b = 0, a, d, f, fidx;
- ARR_FIND(0, jnamelen, b, strcmpi(jnames[b].name,iname) == 0 );
-
- if( b == jnamelen ) {
- ShowWarning("pc_read_skill_tree: '%s' trying to inherit unknown '%s'!\n",name,iname);
+ if ( (b = pc->check_job_name(iname)) == -1 ) {
+ ShowWarning("pc_read_skill_tree: '%s' trying to inherit unknown '%s'!\n", name, iname);
continue;
}
-
- fidx = pc->class2idx(jnames[b].id);
-
- ARR_FIND( 0, MAX_SKILL_TREE, d, pc->skill_tree[fidx][d].id == 0 );
- for( f = 0; f < d; f++ ) {
-
- ARR_FIND( 0, MAX_SKILL_TREE, a, pc->skill_tree[idx][a].id == 0 || pc->skill_tree[idx][a].id == pc->skill_tree[fidx][f].id );
+ fidx = pc->class2idx(b);
+
+ ARR_FIND(0, MAX_SKILL_TREE, d, pc->skill_tree[fidx][d].id == 0);
+
+ for ( f = 0; f < d; f++ ) {
- if( a == MAX_SKILL_TREE ) {
- ShowWarning("pc_read_skill_tree: '%s' can't inherit '%s', skill tree is full!\n", name,iname);
+ ARR_FIND(0, MAX_SKILL_TREE, a, pc->skill_tree[idx][a].id == 0 || pc->skill_tree[idx][a].id == pc->skill_tree[fidx][f].id);
+
+ if ( a == MAX_SKILL_TREE ) {
+ ShowWarning("pc_read_skill_tree: '%s' can't inherit '%s', skill tree is full!\n", name, iname);
break;
- } else if ( pc->skill_tree[idx][a].id || ( pc->skill_tree[idx][a].id == NV_TRICKDEAD && ((pc->jobid2mapid(jnames[k].id)&(MAPID_BASEMASK|JOBL_2))!=MAPID_NOVICE) ) ) /* we skip trickdead for non-novices */
+ } else if ( pc->skill_tree[idx][a].id || (pc->skill_tree[idx][a].id == NV_TRICKDEAD && ((pc->jobid2mapid(k)&(MAPID_BASEMASK | JOBL_2)) != MAPID_NOVICE)) ) /* we skip trickdead for non-novices */
continue;/* skip */
memcpy(&pc->skill_tree[idx][a], &pc->skill_tree[fidx][f], sizeof(pc->skill_tree[fidx][f]));
pc->skill_tree[idx][a].inherited = 1;
}
-
+
}
}
@@ -11287,4 +11298,6 @@ void pc_defaults(void) {
pc->autotrade_start = pc_autotrade_start;
pc->autotrade_prepare = pc_autotrade_prepare;
pc->autotrade_populate = pc_autotrade_populate;
+
+ pc->check_job_name = pc_check_job_name;
}
diff --git a/src/map/pc.h b/src/map/pc.h
index 9e9aa4673..39b705b8f 100644
--- a/src/map/pc.h
+++ b/src/map/pc.h
@@ -1035,6 +1035,8 @@ struct pc_interface {
void (*autotrade_start) (struct map_session_data *sd);
void (*autotrade_prepare) (struct map_session_data *sd);
void (*autotrade_populate) (struct map_session_data *sd);
+
+ int (*check_job_name) (const char *name);
};
struct pc_interface *pc;
diff --git a/src/map/skill.c b/src/map/skill.c
index 3140b720c..4c8ecb40f 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -4866,7 +4866,7 @@ int skill_castend_id(int tid, int64 tick, int id, intptr_t data) {
if( sd && ud->skilltimer != INVALID_TIMER && (pc->checkskill(sd,SA_FREECAST) > 0 || ud->skill_id == LG_EXEEDBREAK) )
{// restore original walk speed
ud->skilltimer = INVALID_TIMER;
- status_calc_bl(&sd->bl, SCB_SPEED);
+ status_calc_bl(&sd->bl, SCB_SPEED|SCB_ASPD);
}
ud->skilltimer = INVALID_TIMER;
@@ -9878,7 +9878,7 @@ int skill_castend_pos(int tid, int64 tick, int id, intptr_t data)
if( sd && ud->skilltimer != INVALID_TIMER && ( pc->checkskill(sd,SA_FREECAST) > 0 || ud->skill_id == LG_EXEEDBREAK ) )
{// restore original walk speed
ud->skilltimer = INVALID_TIMER;
- status_calc_bl(&sd->bl, SCB_SPEED);
+ status_calc_bl(&sd->bl, SCB_SPEED|SCB_ASPD);
}
ud->skilltimer = INVALID_TIMER;
diff --git a/src/map/status.c b/src/map/status.c
index a7c809c6d..91ab19558 100644
--- a/src/map/status.c
+++ b/src/map/status.c
@@ -2081,64 +2081,42 @@ int status_calc_pet_(struct pet_data *pd, enum e_status_calc_opt opt)
return 1;
}
-/// Helper function for status_base_pc_maxhp(), used to pre-calculate the hp_sigma_val[] array
-void status_calc_sigma(void)
-{
- int i,j;
+unsigned int status_get_base_maxsp(struct map_session_data* sd, struct status_data *st) {
+ uint64 val = pc->class2idx(sd->status.class_);
- for(i = 0; i < CLASS_COUNT; i++)
- {
- unsigned int k = 0;
- status->hp_sigma_val[i][0] = status->hp_sigma_val[i][1] = 0;
- for(j = 2; j <= MAX_LEVEL; j++)
- {
- k += (status->hp_coefficient[i]*j + 50) / 100;
- status->hp_sigma_val[i][j] = k;
- if (k >= INT_MAX)
- break; //Overflow protection. [Skotlex]
- }
- for(; j <= MAX_LEVEL; j++)
- status->hp_sigma_val[i][j] = INT_MAX;
- }
+ val = status->SP_table[val][sd->status.base_level];
+
+ if ( sd->class_&JOBL_UPPER )
+ val += val * 25 / 100;
+ else if ( sd->class_&JOBL_BABY )
+ val = val * 70 / 100;
+ if ( (sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && pc->famerank(sd->status.char_id, MAPID_TAEKWON) )
+ val *= 3; //Triple max SP for top ranking Taekwons over level 90.
+
+ val += val * st->int_ / 100;
+
+ return (unsigned int)cap_value(val, 0, UINT_MAX);
}
-/// Calculates base MaxHP value according to class and base level
-/// The recursive equation used to calculate level bonus is (using integer operations)
-/// f(0) = 35 | f(x+1) = f(x) + A + (x + B)*C/D
-/// which reduces to something close to
-/// f(x) = 35 + x*(A + B*C/D) + sum(i=2..x){ i*C/D }
-unsigned int status_base_pc_maxhp(struct map_session_data *sd, struct status_data *st) {
+unsigned int status_get_base_maxhp(struct map_session_data *sd, struct status_data *st) {
uint64 val = pc->class2idx(sd->status.class_);
- val = 35 + sd->status.base_level*(int64)status->hp_coefficient2[val]/100 + status->hp_sigma_val[val][sd->status.base_level];
- if((sd->class_&MAPID_UPPERMASK) == MAPID_NINJA || (sd->class_&MAPID_UPPERMASK) == MAPID_GUNSLINGER || (sd->class_&MAPID_UPPERMASK) == MAPID_REBELLION)
- val += 100; //Since their HP can't be approximated well enough without this.
- if((sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && pc->famerank(sd->status.char_id, MAPID_TAEKWON))
- val *= 3; //Triple max HP for top ranking Taekwons over level 90.
- if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.base_level >= 99)
- val += 2000; //Supernovice lvl99 hp bonus.
-
- val += val * st->vit/100; // +1% per each point of VIT
+ val = status->HP_table[val][sd->status.base_level];
- if (sd->class_&JOBL_UPPER)
- val += val * 25/100; //Trans classes get a 25% hp bonus
- else if (sd->class_&JOBL_BABY)
- val -= val * 30/100; //Baby classes get a 30% hp penalty
- return (unsigned int)cap_value(val,0,UINT_MAX);
-}
+ if ( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.base_level >= 99 )
+ val += 2000; //Supernovice lvl99 hp bonus.
+ if ( (sd->class_&MAPID_THIRDMASK) == MAPID_SUPER_NOVICE_E && sd->status.base_level >= 150 )
+ val += 2000; //Extented Supernovice lvl150 hp bonus.
-unsigned int status_base_pc_maxsp(struct map_session_data* sd, struct status_data *st) {
- uint64 val;
+ if ( sd->class_&JOBL_UPPER )
+ val += val * 25 / 100; //Trans classes get a 25% hp bonus
+ else if ( sd->class_&JOBL_BABY )
+ val = val * 70 / 100; //Baby classes get a 30% hp penalty
- val = 10 + sd->status.base_level*(int64)status->sp_coefficient[pc->class2idx(sd->status.class_)]/100;
- val += val * st->int_/100;
+ if ( (sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && pc->famerank(sd->status.char_id, MAPID_TAEKWON) )
+ val *= 3; //Triple max HP for top ranking Taekwons over level 90.
- if (sd->class_&JOBL_UPPER)
- val += val * 25/100;
- else if (sd->class_&JOBL_BABY)
- val -= val * 30/100;
- if ((sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && pc->famerank(sd->status.char_id, MAPID_TAEKWON))
- val *= 3; //Triple max SP for top ranking Taekwons over level 90.
+ val += val * st->vit / 100; // +1% per each point of VIT
return (unsigned int)cap_value(val,0,UINT_MAX);
}
@@ -2630,7 +2608,7 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
// Basic MaxHP value
//We hold the standard Max HP here to make it faster to recalculate on vit changes.
- sd->status.max_hp = status->base_pc_maxhp(sd,bstatus);
+ sd->status.max_hp = status->get_base_maxhp(sd,bstatus);
//This is done to handle underflows from negative Max HP bonuses
i64 = sd->status.max_hp + (int)bstatus->max_hp;
bstatus->max_hp = (unsigned int)cap_value(i64, 0, INT_MAX);
@@ -2655,7 +2633,7 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
// ----- SP MAX CALCULATION -----
// Basic MaxSP value
- sd->status.max_sp = status->base_pc_maxsp(sd,bstatus);
+ sd->status.max_sp = status->get_base_maxsp(sd,bstatus);
//This is done to handle underflows from negative Max SP bonuses
i64 = sd->status.max_sp + (int)bstatus->max_sp;
bstatus->max_sp = (unsigned int)cap_value(i64, 0, INT_MAX);
@@ -2842,17 +2820,12 @@ int status_calc_pc_(struct map_session_data* sd, enum e_status_calc_opt opt) {
else if (pc_isridingdragon(sd))
bstatus->aspd_rate += 250-50*pc->checkskill(sd,RK_DRAGONTRAINING);
#else // needs more info
- if((skill_lv=pc->checkskill(sd,SA_ADVANCEDBOOK))>0 && sd->status.weapon == W_BOOK)
- bstatus->aspd_rate += 5*skill_lv;
- if((skill_lv = pc->checkskill(sd,SG_DEVIL)) > 0 && !pc->nextjobexp(sd))
- bstatus->aspd_rate += 30*skill_lv;
- if((skill_lv=pc->checkskill(sd,GS_SINGLEACTION))>0 &&
- (sd->status.weapon >= W_REVOLVER && sd->status.weapon <= W_GRENADE))
- bstatus->aspd_rate += ((skill_lv+1)/2) * 10;
- if (pc_isridingpeco(sd))
- bstatus->aspd_rate -= 500-100*pc->checkskill(sd,KN_CAVALIERMASTERY);
- else if (pc_isridingdragon(sd))
- bstatus->aspd_rate -= 250-50*pc->checkskill(sd,RK_DRAGONTRAINING);
+ if ( (skill_lv = pc->checkskill(sd, SG_DEVIL)) > 0 && !pc->nextjobexp(sd) )
+ bstatus->aspd_rate += 30 * skill_lv;
+ if ( pc_isridingpeco(sd) )
+ bstatus->aspd_rate -= 500 - 100 * pc->checkskill(sd, KN_CAVALIERMASTERY);
+ else if ( pc_isridingdragon(sd) )
+ bstatus->aspd_rate -= 250 - 50 * pc->checkskill(sd, RK_DRAGONTRAINING);
#endif
bstatus->adelay = 2*bstatus->amotion;
@@ -3656,7 +3629,7 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) {
if(flag&SCB_MAXHP) {
if( bl->type&BL_PC ) {
- st->max_hp = status->base_pc_maxhp(sd,st);
+ st->max_hp = status->get_base_maxhp(sd,st);
if (sd)
st->max_hp += bst->max_hp - sd->status.max_hp;
@@ -3677,7 +3650,7 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) {
if(flag&SCB_MAXSP) {
if( bl->type&BL_PC ) {
- st->max_sp = status->base_pc_maxsp(sd,st);
+ st->max_sp = status->get_base_maxsp(sd,st);
if (sd)
st->max_sp += bst->max_sp - sd->status.max_sp;
@@ -3744,19 +3717,14 @@ void status_calc_bl_main(struct block_list *bl, /*enum scb_flag*/int flag) {
amotion = status->base_amotion_pc(sd, st);
#ifndef RENEWAL_ASPD
st->aspd_rate = status->calc_aspd_rate(bl, sc, bst->aspd_rate);
-
- if(st->aspd_rate != 1000)
- amotion = amotion*st->aspd_rate/1000;
-#else
- // aspd = baseaspd + floor(sqrt((agi^2/2) + (dex^2/5))/4 + (potskillbonus*agi/200))
- amotion -= (int)(sqrt((pow(st->agi, 2) / 2) + (pow(st->dex, 2) / 5)) / 4 + ((float)status->calc_aspd(bl, sc, 1) * st->agi / 200)) * 10;
-
- if ( (status->calc_aspd(bl, sc, 2) + st->aspd_rate2) != 0 ) // RE ASPD percertage modifier
- amotion -= ((amotion - ((sd->class_&JOBL_THIRD) ? battle_config.max_third_aspd : battle_config.max_aspd))
- * (status->calc_aspd(bl, sc, 2) + st->aspd_rate2) / 10 + 5) / 10;
-
+#endif
if ( st->aspd_rate != 1000 ) // absolute percentage modifier
- amotion = (200 - (200 - amotion / 10) * st->aspd_rate / 1000) * 10;
+ amotion = amotion * st->aspd_rate / 1000;
+ if ( sd && sd->ud.skilltimer != INVALID_TIMER && pc->checkskill(sd, SA_FREECAST) > 0 )
+ amotion = amotion * 5 * (pc->checkskill(sd, SA_FREECAST) + 10) / 100;
+#ifdef RENEWAL_ASPD
+ amotion += (max(0xc3 - amotion, 2) * (st->aspd_rate2 + status->calc_aspd(bl, sc, 2))) / 100;
+ amotion = 10 * (200 - amotion) + sd->bonus.aspd_add;
#endif
amotion = status->calc_fix_aspd(bl, sc, amotion);
st->amotion = cap_value(amotion, ((sd->class_&JOBL_THIRD) ? battle_config.max_third_aspd : battle_config.max_aspd), 2000);
@@ -4011,31 +3979,30 @@ int status_check_visibility(struct block_list *src, struct block_list *target) {
// Basic ASPD value
int status_base_amotion_pc(struct map_session_data *sd, struct status_data *st) {
int amotion;
-#ifdef RENEWAL_ASPD
- short mod = -1;
-
- switch ( sd->weapontype2 ) { // adjustment for dual wielding
- case W_DAGGER:
- mod = 0;
- break; // 0, 1, 1
- case W_1HSWORD:
- case W_1HAXE:
- mod = 1;
- if ( (sd->class_&MAPID_THIRDMASK) == MAPID_GUILLOTINE_CROSS ) // 0, 2, 3
- mod = sd->weapontype2 / W_1HSWORD + W_1HSWORD / sd->weapontype2;
- }
-
- amotion = (sd->status.weapon < MAX_WEAPON_TYPE && mod < 0)
- ? (status->aspd_base[pc->class2idx(sd->status.class_)][sd->status.weapon]) // single weapon
- : ((status->aspd_base[pc->class2idx(sd->status.class_)][sd->weapontype2] // dual-wield
- + status->aspd_base[pc->class2idx(sd->status.class_)][sd->weapontype2]) * 6 / 10 + 10 * mod
- - status->aspd_base[pc->class2idx(sd->status.class_)][sd->weapontype2]
- + status->aspd_base[pc->class2idx(sd->status.class_)][sd->weapontype1]);
-
+#ifdef RENEWAL_ASPD /* [malufett/Hercules] */
+ float temp;
+ int skill_lv, val = 0;
+ amotion = status->aspd_base[pc->class2idx(sd->status.class_)][sd->weapontype1];
+ if ( sd->status.weapon > MAX_WEAPON_TYPE )
+ amotion += status->aspd_base[pc->class2idx(sd->status.class_)][sd->weapontype2] / 4;
if ( sd->status.shield )
- amotion += (2000 - status->aspd_base[pc->class2idx(sd->status.class_)][W_FIST]) +
- (status->aspd_base[pc->class2idx(sd->status.class_)][MAX_WEAPON_TYPE] - 2000);
-
+ amotion += status->aspd_base[pc->class2idx(sd->status.class_)][MAX_WEAPON_TYPE];
+ switch ( sd->status.weapon ) {
+ case W_BOW: case W_MUSICAL:
+ case W_WHIP: case W_REVOLVER:
+ case W_RIFLE: case W_GATLING:
+ case W_SHOTGUN: case W_GRENADE:
+ temp = st->dex * st->dex / 7.0f + st->agi * st->agi * 0.5f;
+ break;
+ default:
+ temp = st->dex * st->dex / 5.0f + st->agi * st->agi * 0.5f;
+ }
+ temp = (float)(sqrt(temp) * 0.25f) + 0xc4;
+ if ( (skill_lv = pc->checkskill(sd, SA_ADVANCEDBOOK)) > 0 && sd->status.weapon == W_BOOK )
+ val += (skill_lv - 1) / 2 + 1;
+ if ( (skill_lv = pc->checkskill(sd, GS_SINGLEACTION)) > 0 )
+ val += ((skill_lv + 1) / 2);
+ amotion = ((int)(temp + ((float)(status->calc_aspd(&sd->bl, &sd->sc, 1) + val) * st->agi / 200)) - min(amotion, 200));
#else
// base weapon delay
amotion = (sd->status.weapon < MAX_WEAPON_TYPE)
@@ -4044,13 +4011,14 @@ int status_base_amotion_pc(struct map_session_data *sd, struct status_data *st)
// percentual delay reduction from stats
amotion -= amotion * (4 * st->agi + st->dex) / 1000;
-#endif
+
// raw delay adjustment from bAspd bonus
amotion += sd->bonus.aspd_add;
/* angra manyu disregards aspd_base and similar */
if ( sd->equip_index[EQI_HAND_R] >= 0 && sd->status.inventory[sd->equip_index[EQI_HAND_R]].nameid == ITEMID_ANGRA_MANYU )
return 0;
+#endif
return amotion;
}
@@ -4595,6 +4563,9 @@ unsigned short status_calc_batk(struct block_list *bl, struct status_change *sc,
#ifndef RENEWAL
if(sc->data[SC_LKCONCENTRATION])
batk += batk * sc->data[SC_LKCONCENTRATION]->val2/100;
+#else
+ if ( sc->data[SC_NOEQUIPWEAPON] && bl->type != BL_PC )
+ batk -= batk * sc->data[SC_NOEQUIPWEAPON]->val2 / 100;
#endif
if(sc->data[SC_SKE])
batk += batk * 3;
@@ -4674,7 +4645,7 @@ unsigned short status_calc_watk(struct block_list *bl, struct status_change *sc,
if(sc->data[SC_LKCONCENTRATION])
watk += watk * sc->data[SC_LKCONCENTRATION]->val2/100;
#endif
- if(sc->data[SC_INCATKRATE])
+ if(sc->data[SC_INCATKRATE] && bl->type != BL_MOB)
watk += watk * sc->data[SC_INCATKRATE]->val1/100;
if(sc->data[SC_PROVOKE])
watk += watk * sc->data[SC_PROVOKE]->val3/100;
@@ -4684,8 +4655,10 @@ unsigned short status_calc_watk(struct block_list *bl, struct status_change *sc,
watk += watk * sc->data[SC_HLIF_FLEET]->val3/100;
if(sc->data[SC_CURSE])
watk -= watk * 25/100;
+#ifndef RENEWAL
if(sc->data[SC_NOEQUIPWEAPON] && bl->type != BL_PC)
watk -= watk * sc->data[SC_NOEQUIPWEAPON]->val2/100;
+#endif
if(sc->data[SC__ENERVATION])
watk -= watk * sc->data[SC__ENERVATION]->val2 / 100;
if(sc->data[SC_RUSH_WINDMILL])
@@ -12086,33 +12059,178 @@ int status_get_sc_type(sc_type type) {
* size_fix.txt - size adjustment table for weapons
* refine_db.txt - refining data table
*------------------------------------------*/
-bool status_readdb_job1(char* fields[], int columns, int current)
-{// Job-specific values (weight, HP, SP, ASPD)
- int idx, class_;
- unsigned int i;
-
- class_ = atoi(fields[0]);
+void status_read_job_db(void) { /* [malufett/Hercules] */
+ int i = 0;
+ config_t job_db_conf;
+ config_setting_t *jdb = NULL;
+ const char *config_filename = "db/"DBPATH"job_db.conf";
+ struct {
+ const char *name;
+ int id;
+ } wnames[] = {
+ { "Fist", W_FIST },
+ { "Dagger", W_DAGGER },
+ { "Sword", W_1HSWORD },
+ { "TwoHandSword", W_2HSWORD },
+ { "Spear", W_1HSPEAR },
+ { "TwoHandSpear", W_2HSPEAR },
+ { "Axe", W_1HAXE },
+ { "TwoHandAxe", W_2HAXE },
+ { "Mace", W_MACE },
+ { "TwoHandMace", W_2HMACE },
+ { "Rod", W_STAFF },
+ { "Bow", W_BOW },
+ { "Knuckle", W_KNUCKLE },
+ { "Instrument", W_MUSICAL },
+ { "Whip", W_WHIP },
+ { "Book", W_BOOK },
+ { "Katar", W_KATAR },
+ { "Revolver", W_REVOLVER },
+ { "Rifle", W_RIFLE },
+ { "GatlingGun", W_GATLING },
+ { "Shotgun", W_SHOTGUN },
+ { "GrenadeLauncher", W_GRENADE },
+ { "FuumaShuriken", W_HUUMA },
+ { "TwoHandRod", W_2HSTAFF },
+#ifdef RENEWAL_ASPD
+ { "Shield", MAX_WEAPON_TYPE }
+#endif
+ };
- if(!pc->db_checkid(class_))
- {
- ShowWarning("status_readdb_job1: Invalid job class %d specified.\n", class_);
- return false;
+ if ( libconfig->read_file(&job_db_conf, config_filename) ) {
+ ShowError("can't read %s\n", config_filename);
+ return;
}
- idx = pc->class2idx(class_);
+ while ( (jdb = libconfig->setting_get_elem(job_db_conf.root, i++)) ) {
+ int class_, idx, i32 = 0;
+ config_setting_t *temp = NULL;
+ const char *name = config_setting_name(jdb);
- status->max_weight_base[idx] = atoi(fields[1]);
- status->hp_coefficient[idx] = atoi(fields[2]);
- status->hp_coefficient2[idx] = atoi(fields[3]);
- status->sp_coefficient[idx] = atoi(fields[4]);
-#ifdef RENEWAL_ASPD
- for(i = 0; i <= MAX_WEAPON_TYPE; i++)
-#else
- for(i = 0; i < MAX_WEAPON_TYPE; i++)
-#endif
- {
- status->aspd_base[idx][i] = atoi(fields[i+5]);
+ if ( (class_ = pc->check_job_name(name)) == -1 ) {
+ ShowWarning("pc_read_job_db: '%s' unknown job name!\n", name);
+ continue;
+ }
+
+ idx = pc->class2idx(class_);
+ if ( (temp = libconfig->setting_get_member(jdb, "Inherit")) ) {
+ int nidx = 0, iidx, w;
+ const char *iname;
+ while ( (iname = libconfig->setting_get_string_elem(temp, nidx++)) ) {
+ int iclass, ave, total = 0;
+ if ( (iclass = pc->check_job_name(iname)) == -1 ) {
+ ShowWarning("status_read_job_db: '%s' trying to inherit unknown '%s'!\n", name, iname);
+ continue;
+ }
+ iidx = pc->class2idx(iclass);
+ status->max_weight_base[idx] = status->max_weight_base[iidx];
+ memcpy(&status->aspd_base[idx], &status->aspd_base[iidx], sizeof(status->aspd_base[iidx]));
+ for ( w = 1; w <= MAX_LEVEL && status->HP_table[iidx][w]; w++ ) {
+ status->HP_table[idx][w] = status->HP_table[iidx][w];
+ total += status->HP_table[idx][w];
+ }
+ ave = total / (w - 1);
+ for ( ; w <= pc->max_level[idx][0]; w++ ) {
+ status->HP_table[idx][w] = min(ave * w, battle_config.max_hp);
+ }
+ for ( w = 1; w <= MAX_LEVEL && status->SP_table[iidx][w]; w++ ) {
+ status->SP_table[idx][w] = status->SP_table[iidx][w];
+ total += status->SP_table[idx][w];
+ }
+ ave = total / (w - 1);
+ for ( ; w <= pc->max_level[idx][0]; w++ ) {
+ status->SP_table[idx][w] = min(ave * w, battle_config.max_sp);
+ }
+ }
+ }
+ if ( (temp = libconfig->setting_get_member(jdb, "InheritHP")) ) {
+ int nidx = 0, iidx;
+ const char *iname;
+ while ( (iname = libconfig->setting_get_string_elem(temp, nidx++)) ) {
+ int iclass, w, ave, total = 0;
+ if ( (iclass = pc->check_job_name(iname)) == -1 ) {
+ ShowWarning("status_read_job_db: '%s' trying to inherit unknown '%s' HP!\n", name, iname);
+ continue;
+ }
+ iidx = pc->class2idx(iclass);
+ for ( w = 1; w <= MAX_LEVEL && status->HP_table[iidx][w]; w++ ) {
+ status->HP_table[idx][w] = status->HP_table[iidx][w];
+ total += status->HP_table[idx][w];
+ }
+ ave = total / (w - 1);
+ for ( ; w <= pc->max_level[idx][0]; w++ ) {
+ status->HP_table[idx][w] = min(ave * w, battle_config.max_hp);
+ }
+ }
+ }
+ if ( (temp = libconfig->setting_get_member(jdb, "InheritSP")) ) {
+ int nidx = 0, iidx, ave, total = 0;
+ const char *iname;
+ while ( (iname = libconfig->setting_get_string_elem(temp, nidx++)) ) {
+ int iclass, w;
+ if ( (iclass = pc->check_job_name(iname)) == -1 ) {
+ ShowWarning("status_read_job_db: '%s' trying to inherit unknown '%s' SP!\n", name, iname);
+ continue;
+ }
+ iidx = pc->class2idx(iclass);
+ for ( w = 1; w <= MAX_LEVEL && status->SP_table[iidx][w]; w++ ) {
+ status->SP_table[idx][w] = status->SP_table[iidx][w];
+ total += status->SP_table[idx][w];
+ }
+ ave = total / (w - 1);
+ for ( ; w <= pc->max_level[idx][0]; w++ ) {
+ status->SP_table[idx][w] = min(ave * w, battle_config.max_sp);
+ }
+ }
+ }
+
+ if ( libconfig->setting_lookup_int(jdb, "Weight", &i32) )
+ status->max_weight_base[idx] = i32;
+ else if ( !status->max_weight_base[idx] )
+ status->max_weight_base[idx] = 20000;
+
+ if ( (temp = libconfig->setting_get_member(jdb, "BaseASPD")) ) {
+ int widx = 0;
+ config_setting_t *wpn = NULL;
+ while ( (wpn = libconfig->setting_get_elem(temp, widx++)) ) {
+ int w, wlen = ARRAYLENGTH(wnames);
+ const char *wname = config_setting_name(wpn);
+
+ ARR_FIND(0, wlen, w, strcmp(wnames[w].name, wname) == 0);
+ if ( w != wlen ) {
+ status->aspd_base[idx][wnames[w].id] = libconfig->setting_get_int(wpn);
+ } else {
+ ShowWarning("status_read_job_db: unknown weapon type '%s'!\n", wname);
+ }
+ }
+ }
+
+ if ( (temp = libconfig->setting_get_member(jdb, "HPTable")) ) {
+ int level = 0, ave, total = 0;
+ config_setting_t *hp = NULL;
+ while ( (hp = libconfig->setting_get_elem(temp, level++)) ) {
+ status->HP_table[idx][level] = i32 = min(libconfig->setting_get_int(hp), battle_config.max_hp);
+ total += i32 - status->HP_table[idx][level - 1];
+ }
+ ave = total / (level - 1);
+ for ( ; level <= pc->max_level[idx][0]; level++ ) { /* limit only to possible maximum level of the given class */
+ status->HP_table[idx][level] = min(ave * level, battle_config.max_hp); /* some are still empty? then let's use the average increase */
+ }
+ }
+
+ if ( (temp = libconfig->setting_get_member(jdb, "SPTable")) ) {
+ int level = 0, ave, total = 0;
+ config_setting_t *sp = NULL;
+ while ( (sp = libconfig->setting_get_elem(temp, level++)) ) {
+ status->SP_table[idx][level] = i32 = min(libconfig->setting_get_int(sp), battle_config.max_sp);
+ total += i32 - status->SP_table[idx][level - 1];
+ }
+ ave = total / (level - 1);
+ for ( ; level <= pc->max_level[idx][0]; level++ ) {
+ status->SP_table[idx][level] = min(ave * level, battle_config.max_sp);
+ }
+ }
}
- return true;
+ libconfig->destroy(&job_db_conf);
}
bool status_readdb_job2(char* fields[], int columns, int current)
@@ -12207,15 +12325,21 @@ int status_readdb(void)
// initialize databases to default
//
if( runflag == MAPSERVER_ST_RUNNING ) {//not necessary during boot
- // reset job_db1.txt data
+ // reset job_db.conf data
memset(status->max_weight_base, 0, sizeof(status->max_weight_base));
- memset(status->hp_coefficient, 0, sizeof(status->hp_coefficient));
- memset(status->hp_coefficient2, 0, sizeof(status->hp_coefficient2));
- memset(status->sp_coefficient, 0, sizeof(status->sp_coefficient));
- memset(status->aspd_base, 0, sizeof(status->aspd_base));
+ memset(status->HP_table, 0, sizeof(status->HP_table));
+ memset(status->SP_table, 0, sizeof(status->SP_table));
// reset job_db2.txt data
memset(status->job_bonus,0,sizeof(status->job_bonus)); // Job-specific stats bonus
}
+ for ( i = 0; i < CLASS_COUNT; i++ ) {
+ for ( j = 0; j < MAX_WEAPON_TYPE; j++ )
+ status->aspd_base[i][j] = 2000;
+#ifdef RENEWAL_ASPD
+ status->aspd_base[i][MAX_WEAPON_TYPE] = 0;
+#endif
+ }
+
// size_fix.txt
for(i = 0; i < ARRAYLENGTH(status->atkmods); i++)
for(j = 0; j < MAX_WEAPON_TYPE; j++)
@@ -12232,17 +12356,11 @@ int status_readdb(void)
// read databases
//
-
-
-#ifdef RENEWAL_ASPD
- sv->readdb(map->db_path, "re/job_db1.txt", ',', 6+MAX_WEAPON_TYPE, 6+MAX_WEAPON_TYPE, -1, status->readdb_job1);
-#else
- sv->readdb(map->db_path, "pre-re/job_db1.txt", ',', 5+MAX_WEAPON_TYPE, 5+MAX_WEAPON_TYPE, -1, status->readdb_job1);
-#endif
sv->readdb(map->db_path, "job_db2.txt", ',', 1, 1+MAX_LEVEL, -1, status->readdb_job2);
sv->readdb(map->db_path, DBPATH"size_fix.txt", ',', MAX_WEAPON_TYPE, MAX_WEAPON_TYPE, ARRAYLENGTH(status->atkmods), status->readdb_sizefix);
sv->readdb(map->db_path, DBPATH"refine_db.txt", ',', 4+MAX_REFINE, 4+MAX_REFINE, ARRAYLENGTH(status->refine_info), status->readdb_refine);
sv->readdb(map->db_path, "sc_config.txt", ',', 2, 2, SC_MAX, status->readdb_scconfig);
+ status->read_job_db();
return 0;
}
@@ -12260,7 +12378,6 @@ int do_init_status(bool minimal) {
status->initChangeTables();
status->initDummyData();
status->readdb();
- status->calc_sigma();
status->natural_heal_prev_tick = timer->gettick();
status->data_ers = ers_new(sizeof(struct status_change_entry),"status.c::data_ers",ERS_OPT_NONE);
timer->add_interval(status->natural_heal_prev_tick + NATURAL_HEAL_INTERVAL, status->natural_heal_timer, 0, 0, NATURAL_HEAL_INTERVAL);
@@ -12285,10 +12402,8 @@ void status_defaults(void) {
status->current_equip_card_id = 0; //To prevent card-stacking (from jA) [Skotlex]
memset(status->max_weight_base,0,sizeof(status->max_weight_base)
- + sizeof(status->hp_coefficient)
- + sizeof(status->hp_coefficient2)
- + sizeof(status->hp_sigma_val)
- + sizeof(status->sp_coefficient)
+ + sizeof(status->HP_table)
+ + sizeof(status->SP_table)
+ sizeof(status->aspd_base)
+ sizeof(status->Skill2SCTable)
+ sizeof(status->IconChangeTable)
@@ -12396,9 +12511,8 @@ void status_defaults(void) {
status->initDummyData = initDummyData;
status->base_amotion_pc = status_base_amotion_pc;
status->base_atk = status_base_atk;
- status->calc_sigma = status_calc_sigma;
- status->base_pc_maxhp = status_base_pc_maxhp;
- status->base_pc_maxsp = status_base_pc_maxsp;
+ status->get_base_maxhp = status_get_base_maxhp;
+ status->get_base_maxsp = status_get_base_maxsp;
status->calc_npc_ = status_calc_npc_;
status->calc_str = status_calc_str;
status->calc_agi = status_calc_agi;
@@ -12428,9 +12542,9 @@ void status_defaults(void) {
status->display_remove = status_display_remove;
status->natural_heal = status_natural_heal;
status->natural_heal_timer = status_natural_heal_timer;
- status->readdb_job1 = status_readdb_job1;
status->readdb_job2 = status_readdb_job2;
status->readdb_sizefix = status_readdb_sizefix;
status->readdb_refine = status_readdb_refine;
status->readdb_scconfig = status_readdb_scconfig;
+ status->read_job_db = status_read_job_db;
}
diff --git a/src/map/status.h b/src/map/status.h
index f0624587e..98d5d415c 100644
--- a/src/map/status.h
+++ b/src/map/status.h
@@ -1982,10 +1982,8 @@ struct status_interface {
int current_equip_card_id;
/* */
int max_weight_base[CLASS_COUNT];
- int hp_coefficient[CLASS_COUNT];
- int hp_coefficient2[CLASS_COUNT];
- int hp_sigma_val[CLASS_COUNT][MAX_LEVEL+1];
- int sp_coefficient[CLASS_COUNT];
+ int HP_table[CLASS_COUNT][MAX_LEVEL + 1];
+ int SP_table[CLASS_COUNT][MAX_LEVEL + 1];
int aspd_base[CLASS_COUNT][MAX_WEAPON_TYPE+1]; // +1 for RENEWAL_ASPD
sc_type Skill2SCTable[MAX_SKILL]; // skill -> status
int IconChangeTable[SC_MAX]; // status -> "icon" (icon is a bit of a misnomer, since there exist values with no icon associated)
@@ -2082,9 +2080,8 @@ struct status_interface {
void (*initDummyData) (void);
int (*base_amotion_pc) (struct map_session_data *sd, struct status_data *st);
unsigned short (*base_atk) (const struct block_list *bl, const struct status_data *st);
- void (*calc_sigma) (void);
- unsigned int (*base_pc_maxhp) (struct map_session_data *sd, struct status_data *st);
- unsigned int (*base_pc_maxsp) (struct map_session_data *sd, struct status_data *st);
+ unsigned int (*get_base_maxhp) (struct map_session_data *sd, struct status_data *st);
+ unsigned int (*get_base_maxsp) (struct map_session_data *sd, struct status_data *st);
int (*calc_npc_) (struct npc_data *nd, enum e_status_calc_opt opt);
unsigned short (*calc_str) (struct block_list *bl, struct status_change *sc, int str);
unsigned short (*calc_agi) (struct block_list *bl, struct status_change *sc, int agi);
@@ -2114,11 +2111,11 @@ struct status_interface {
void (*display_remove) (struct map_session_data *sd, enum sc_type type);
int (*natural_heal) (struct block_list *bl, va_list args);
int (*natural_heal_timer) (int tid, int64 tick, int id, intptr_t data);
- bool (*readdb_job1) (char *fields[], int columns, int current);
bool (*readdb_job2) (char *fields[], int columns, int current);
bool (*readdb_sizefix) (char *fields[], int columns, int current);
bool (*readdb_refine) (char *fields[], int columns, int current);
bool (*readdb_scconfig) (char *fields[], int columns, int current);
+ void (*read_job_db) (void);
};
struct status_interface *status;
diff --git a/src/map/unit.c b/src/map/unit.c
index 2e96e9c20..2dba10aeb 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -1604,7 +1604,7 @@ int unit_skilluse_id2(struct block_list *src, int target_id, uint16 skill_id, ui
unit->setdir(src, map->calc_dir(src, target->x, target->y));
ud->skilltimer = timer->add( tick+casttime, skill->castend_id, src->id, 0 );
if( sd && (pc->checkskill(sd,SA_FREECAST) > 0 || skill_id == LG_EXEEDBREAK) )
- status_calc_bl(&sd->bl, SCB_SPEED);
+ status_calc_bl(&sd->bl, SCB_SPEED|SCB_ASPD);
} else
skill->castend_id(ud->skilltimer,tick,src->id,0);
@@ -1747,8 +1747,9 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, ui
if( casttime > 0 ) {
unit->setdir(src, map->calc_dir(src, skill_x, skill_y));
ud->skilltimer = timer->add( tick+casttime, skill->castend_pos, src->id, 0 );
- if( (sd && pc->checkskill(sd,SA_FREECAST) > 0) || skill_id == LG_EXEEDBREAK)
- status_calc_bl(&sd->bl, SCB_SPEED);
+ if ( (sd && pc->checkskill(sd, SA_FREECAST) > 0) || skill_id == LG_EXEEDBREAK ) {
+ status_calc_bl(&sd->bl, SCB_SPEED|SCB_ASPD);
+ }
} else {
ud->skilltimer = INVALID_TIMER;
skill->castend_pos(ud->skilltimer,tick,src->id,0);
@@ -2231,7 +2232,7 @@ int unit_skillcastcancel(struct block_list *bl,int type)
ud->skilltimer = INVALID_TIMER;
if( sd && pc->checkskill(sd,SA_FREECAST) > 0 )
- status_calc_bl(&sd->bl, SCB_SPEED);
+ status_calc_bl(&sd->bl, SCB_SPEED|SCB_ASPD);
if( sd ) {
switch( skill_id ) {
diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
index 651b8efc3..d7a6cf672 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
@@ -3989,6 +3989,8 @@ struct {
struct HPMHookPoint *HP_pc_autotrade_prepare_post;
struct HPMHookPoint *HP_pc_autotrade_populate_pre;
struct HPMHookPoint *HP_pc_autotrade_populate_post;
+ struct HPMHookPoint *HP_pc_check_job_name_pre;
+ struct HPMHookPoint *HP_pc_check_job_name_post;
struct HPMHookPoint *HP_pet_init_pre;
struct HPMHookPoint *HP_pet_init_post;
struct HPMHookPoint *HP_pet_final_pre;
@@ -4979,12 +4981,10 @@ struct {
struct HPMHookPoint *HP_status_base_amotion_pc_post;
struct HPMHookPoint *HP_status_base_atk_pre;
struct HPMHookPoint *HP_status_base_atk_post;
- struct HPMHookPoint *HP_status_calc_sigma_pre;
- struct HPMHookPoint *HP_status_calc_sigma_post;
- struct HPMHookPoint *HP_status_base_pc_maxhp_pre;
- struct HPMHookPoint *HP_status_base_pc_maxhp_post;
- struct HPMHookPoint *HP_status_base_pc_maxsp_pre;
- struct HPMHookPoint *HP_status_base_pc_maxsp_post;
+ struct HPMHookPoint *HP_status_get_base_maxhp_pre;
+ struct HPMHookPoint *HP_status_get_base_maxhp_post;
+ struct HPMHookPoint *HP_status_get_base_maxsp_pre;
+ struct HPMHookPoint *HP_status_get_base_maxsp_post;
struct HPMHookPoint *HP_status_calc_npc__pre;
struct HPMHookPoint *HP_status_calc_npc__post;
struct HPMHookPoint *HP_status_calc_str_pre;
@@ -5043,8 +5043,6 @@ struct {
struct HPMHookPoint *HP_status_natural_heal_post;
struct HPMHookPoint *HP_status_natural_heal_timer_pre;
struct HPMHookPoint *HP_status_natural_heal_timer_post;
- struct HPMHookPoint *HP_status_readdb_job1_pre;
- struct HPMHookPoint *HP_status_readdb_job1_post;
struct HPMHookPoint *HP_status_readdb_job2_pre;
struct HPMHookPoint *HP_status_readdb_job2_post;
struct HPMHookPoint *HP_status_readdb_sizefix_pre;
@@ -5053,6 +5051,8 @@ struct {
struct HPMHookPoint *HP_status_readdb_refine_post;
struct HPMHookPoint *HP_status_readdb_scconfig_pre;
struct HPMHookPoint *HP_status_readdb_scconfig_post;
+ struct HPMHookPoint *HP_status_read_job_db_pre;
+ struct HPMHookPoint *HP_status_read_job_db_post;
struct HPMHookPoint *HP_storage_reconnect_pre;
struct HPMHookPoint *HP_storage_reconnect_post;
struct HPMHookPoint *HP_storage_delitem_pre;
@@ -9196,6 +9196,8 @@ struct {
int HP_pc_autotrade_prepare_post;
int HP_pc_autotrade_populate_pre;
int HP_pc_autotrade_populate_post;
+ int HP_pc_check_job_name_pre;
+ int HP_pc_check_job_name_post;
int HP_pet_init_pre;
int HP_pet_init_post;
int HP_pet_final_pre;
@@ -10186,12 +10188,10 @@ struct {
int HP_status_base_amotion_pc_post;
int HP_status_base_atk_pre;
int HP_status_base_atk_post;
- int HP_status_calc_sigma_pre;
- int HP_status_calc_sigma_post;
- int HP_status_base_pc_maxhp_pre;
- int HP_status_base_pc_maxhp_post;
- int HP_status_base_pc_maxsp_pre;
- int HP_status_base_pc_maxsp_post;
+ int HP_status_get_base_maxhp_pre;
+ int HP_status_get_base_maxhp_post;
+ int HP_status_get_base_maxsp_pre;
+ int HP_status_get_base_maxsp_post;
int HP_status_calc_npc__pre;
int HP_status_calc_npc__post;
int HP_status_calc_str_pre;
@@ -10250,8 +10250,6 @@ struct {
int HP_status_natural_heal_post;
int HP_status_natural_heal_timer_pre;
int HP_status_natural_heal_timer_post;
- int HP_status_readdb_job1_pre;
- int HP_status_readdb_job1_post;
int HP_status_readdb_job2_pre;
int HP_status_readdb_job2_post;
int HP_status_readdb_sizefix_pre;
@@ -10260,6 +10258,8 @@ struct {
int HP_status_readdb_refine_post;
int HP_status_readdb_scconfig_pre;
int HP_status_readdb_scconfig_post;
+ int HP_status_read_job_db_pre;
+ int HP_status_read_job_db_post;
int HP_storage_reconnect_pre;
int HP_storage_reconnect_post;
int HP_storage_delitem_pre;
diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
index 5cbc20541..05ceb4ab1 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
@@ -2026,6 +2026,7 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(pc->autotrade_start, HP_pc_autotrade_start) },
{ HP_POP(pc->autotrade_prepare, HP_pc_autotrade_prepare) },
{ HP_POP(pc->autotrade_populate, HP_pc_autotrade_populate) },
+ { HP_POP(pc->check_job_name, HP_pc_check_job_name) },
/* pet */
{ HP_POP(pet->init, HP_pet_init) },
{ HP_POP(pet->final, HP_pet_final) },
@@ -2527,9 +2528,8 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(status->initDummyData, HP_status_initDummyData) },
{ HP_POP(status->base_amotion_pc, HP_status_base_amotion_pc) },
{ HP_POP(status->base_atk, HP_status_base_atk) },
- { HP_POP(status->calc_sigma, HP_status_calc_sigma) },
- { HP_POP(status->base_pc_maxhp, HP_status_base_pc_maxhp) },
- { HP_POP(status->base_pc_maxsp, HP_status_base_pc_maxsp) },
+ { HP_POP(status->get_base_maxhp, HP_status_get_base_maxhp) },
+ { HP_POP(status->get_base_maxsp, HP_status_get_base_maxsp) },
{ HP_POP(status->calc_npc_, HP_status_calc_npc_) },
{ HP_POP(status->calc_str, HP_status_calc_str) },
{ HP_POP(status->calc_agi, HP_status_calc_agi) },
@@ -2559,11 +2559,11 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(status->display_remove, HP_status_display_remove) },
{ HP_POP(status->natural_heal, HP_status_natural_heal) },
{ HP_POP(status->natural_heal_timer, HP_status_natural_heal_timer) },
- { HP_POP(status->readdb_job1, HP_status_readdb_job1) },
{ HP_POP(status->readdb_job2, HP_status_readdb_job2) },
{ HP_POP(status->readdb_sizefix, HP_status_readdb_sizefix) },
{ HP_POP(status->readdb_refine, HP_status_readdb_refine) },
{ HP_POP(status->readdb_scconfig, HP_status_readdb_scconfig) },
+ { HP_POP(status->read_job_db, HP_status_read_job_db) },
/* storage */
{ HP_POP(storage->reconnect, HP_storage_reconnect) },
{ HP_POP(storage->delitem, HP_storage_delitem) },
diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
index 3b2c3f08f..8f7c4f0b4 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
@@ -53389,6 +53389,33 @@ void HP_pc_autotrade_populate(struct map_session_data *sd) {
}
return;
}
+int HP_pc_check_job_name(const char *name) {
+ int hIndex = 0;
+ int retVal___ = 0;
+ if( HPMHooks.count.HP_pc_check_job_name_pre ) {
+ int (*preHookFunc) (const char *name);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_pc_check_job_name_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_pc_check_job_name_pre[hIndex].func;
+ retVal___ = preHookFunc(name);
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.pc.check_job_name(name);
+ }
+ if( HPMHooks.count.HP_pc_check_job_name_post ) {
+ int (*postHookFunc) (int retVal___, const char *name);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_pc_check_job_name_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_pc_check_job_name_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, name);
+ }
+ }
+ return retVal___;
+}
/* pet */
int HP_pet_init(bool minimal) {
int hIndex = 0;
@@ -66962,40 +66989,14 @@ unsigned short HP_status_base_atk(const struct block_list *bl, const struct stat
}
return retVal___;
}
-void HP_status_calc_sigma(void) {
- int hIndex = 0;
- if( HPMHooks.count.HP_status_calc_sigma_pre ) {
- void (*preHookFunc) (void);
- *HPMforce_return = false;
- for(hIndex = 0; hIndex < HPMHooks.count.HP_status_calc_sigma_pre; hIndex++ ) {
- preHookFunc = HPMHooks.list.HP_status_calc_sigma_pre[hIndex].func;
- preHookFunc();
- }
- if( *HPMforce_return ) {
- *HPMforce_return = false;
- return;
- }
- }
- {
- HPMHooks.source.status.calc_sigma();
- }
- if( HPMHooks.count.HP_status_calc_sigma_post ) {
- void (*postHookFunc) (void);
- for(hIndex = 0; hIndex < HPMHooks.count.HP_status_calc_sigma_post; hIndex++ ) {
- postHookFunc = HPMHooks.list.HP_status_calc_sigma_post[hIndex].func;
- postHookFunc();
- }
- }
- return;
-}
-unsigned int HP_status_base_pc_maxhp(struct map_session_data *sd, struct status_data *st) {
+unsigned int HP_status_get_base_maxhp(struct map_session_data *sd, struct status_data *st) {
int hIndex = 0;
unsigned int retVal___ = 0;
- if( HPMHooks.count.HP_status_base_pc_maxhp_pre ) {
+ if( HPMHooks.count.HP_status_get_base_maxhp_pre ) {
unsigned int (*preHookFunc) (struct map_session_data *sd, struct status_data *st);
*HPMforce_return = false;
- for(hIndex = 0; hIndex < HPMHooks.count.HP_status_base_pc_maxhp_pre; hIndex++ ) {
- preHookFunc = HPMHooks.list.HP_status_base_pc_maxhp_pre[hIndex].func;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_status_get_base_maxhp_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_status_get_base_maxhp_pre[hIndex].func;
retVal___ = preHookFunc(sd, st);
}
if( *HPMforce_return ) {
@@ -67004,25 +67005,25 @@ unsigned int HP_status_base_pc_maxhp(struct map_session_data *sd, struct status_
}
}
{
- retVal___ = HPMHooks.source.status.base_pc_maxhp(sd, st);
+ retVal___ = HPMHooks.source.status.get_base_maxhp(sd, st);
}
- if( HPMHooks.count.HP_status_base_pc_maxhp_post ) {
+ if( HPMHooks.count.HP_status_get_base_maxhp_post ) {
unsigned int (*postHookFunc) (unsigned int retVal___, struct map_session_data *sd, struct status_data *st);
- for(hIndex = 0; hIndex < HPMHooks.count.HP_status_base_pc_maxhp_post; hIndex++ ) {
- postHookFunc = HPMHooks.list.HP_status_base_pc_maxhp_post[hIndex].func;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_status_get_base_maxhp_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_status_get_base_maxhp_post[hIndex].func;
retVal___ = postHookFunc(retVal___, sd, st);
}
}
return retVal___;
}
-unsigned int HP_status_base_pc_maxsp(struct map_session_data *sd, struct status_data *st) {
+unsigned int HP_status_get_base_maxsp(struct map_session_data *sd, struct status_data *st) {
int hIndex = 0;
unsigned int retVal___ = 0;
- if( HPMHooks.count.HP_status_base_pc_maxsp_pre ) {
+ if( HPMHooks.count.HP_status_get_base_maxsp_pre ) {
unsigned int (*preHookFunc) (struct map_session_data *sd, struct status_data *st);
*HPMforce_return = false;
- for(hIndex = 0; hIndex < HPMHooks.count.HP_status_base_pc_maxsp_pre; hIndex++ ) {
- preHookFunc = HPMHooks.list.HP_status_base_pc_maxsp_pre[hIndex].func;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_status_get_base_maxsp_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_status_get_base_maxsp_pre[hIndex].func;
retVal___ = preHookFunc(sd, st);
}
if( *HPMforce_return ) {
@@ -67031,12 +67032,12 @@ unsigned int HP_status_base_pc_maxsp(struct map_session_data *sd, struct status_
}
}
{
- retVal___ = HPMHooks.source.status.base_pc_maxsp(sd, st);
+ retVal___ = HPMHooks.source.status.get_base_maxsp(sd, st);
}
- if( HPMHooks.count.HP_status_base_pc_maxsp_post ) {
+ if( HPMHooks.count.HP_status_get_base_maxsp_post ) {
unsigned int (*postHookFunc) (unsigned int retVal___, struct map_session_data *sd, struct status_data *st);
- for(hIndex = 0; hIndex < HPMHooks.count.HP_status_base_pc_maxsp_post; hIndex++ ) {
- postHookFunc = HPMHooks.list.HP_status_base_pc_maxsp_post[hIndex].func;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_status_get_base_maxsp_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_status_get_base_maxsp_post[hIndex].func;
retVal___ = postHookFunc(retVal___, sd, st);
}
}
@@ -67828,33 +67829,6 @@ int HP_status_natural_heal_timer(int tid, int64 tick, int id, intptr_t data) {
}
return retVal___;
}
-bool HP_status_readdb_job1(char *fields[], int columns, int current) {
- int hIndex = 0;
- bool retVal___ = false;
- if( HPMHooks.count.HP_status_readdb_job1_pre ) {
- bool (*preHookFunc) (char *fields[], int *columns, int *current);
- *HPMforce_return = false;
- for(hIndex = 0; hIndex < HPMHooks.count.HP_status_readdb_job1_pre; hIndex++ ) {
- preHookFunc = HPMHooks.list.HP_status_readdb_job1_pre[hIndex].func;
- retVal___ = preHookFunc(fields, &columns, &current);
- }
- if( *HPMforce_return ) {
- *HPMforce_return = false;
- return retVal___;
- }
- }
- {
- retVal___ = HPMHooks.source.status.readdb_job1(fields, columns, current);
- }
- if( HPMHooks.count.HP_status_readdb_job1_post ) {
- bool (*postHookFunc) (bool retVal___, char *fields[], int *columns, int *current);
- for(hIndex = 0; hIndex < HPMHooks.count.HP_status_readdb_job1_post; hIndex++ ) {
- postHookFunc = HPMHooks.list.HP_status_readdb_job1_post[hIndex].func;
- retVal___ = postHookFunc(retVal___, fields, &columns, &current);
- }
- }
- return retVal___;
-}
bool HP_status_readdb_job2(char *fields[], int columns, int current) {
int hIndex = 0;
bool retVal___ = false;
@@ -67963,6 +67937,32 @@ bool HP_status_readdb_scconfig(char *fields[], int columns, int current) {
}
return retVal___;
}
+void HP_status_read_job_db(void) {
+ int hIndex = 0;
+ if( HPMHooks.count.HP_status_read_job_db_pre ) {
+ void (*preHookFunc) (void);
+ *HPMforce_return = false;
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_status_read_job_db_pre; hIndex++ ) {
+ preHookFunc = HPMHooks.list.HP_status_read_job_db_pre[hIndex].func;
+ preHookFunc();
+ }
+ if( *HPMforce_return ) {
+ *HPMforce_return = false;
+ return;
+ }
+ }
+ {
+ HPMHooks.source.status.read_job_db();
+ }
+ if( HPMHooks.count.HP_status_read_job_db_post ) {
+ void (*postHookFunc) (void);
+ for(hIndex = 0; hIndex < HPMHooks.count.HP_status_read_job_db_post; hIndex++ ) {
+ postHookFunc = HPMHooks.list.HP_status_read_job_db_post[hIndex].func;
+ postHookFunc();
+ }
+ }
+ return;
+}
/* storage */
void HP_storage_reconnect(void) {
int hIndex = 0;