From 1a651243bb2c8e18baa9aac30ac52a62185074e7 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sun, 30 Mar 2014 23:14:12 -0700 Subject: Be stricter about most arrays --- src/admin/ladmin.cpp | 18 ++-- src/char/char.cpp | 44 +++++---- src/char/char.hpp | 4 +- src/char/int_party.cpp | 1 + src/char/int_storage.cpp | 4 +- src/char/inter.cpp | 6 +- src/generic/const_array.cpp | 3 - src/generic/const_array.hpp | 132 --------------------------- src/generic/enum.hpp | 39 ++++++-- src/generic/intern-pool.hpp | 1 + src/generic/matrix.hpp | 6 ++ src/io/cxxstdio.hpp | 1 - src/login/login.cpp | 34 ++++--- src/map/atcommand.hpp | 2 - src/map/battle.cpp | 44 ++++----- src/map/battle.hpp | 2 +- src/map/clif.cpp | 6 +- src/map/clif.hpp | 2 - src/map/intif.cpp | 1 + src/map/intif.hpp | 2 - src/map/magic-expr-eval.hpp | 4 +- src/map/magic-expr.cpp | 174 +++++++++++++++++------------------ src/map/magic-expr.hpp | 8 +- src/map/magic-stmt.cpp | 54 +++++------ src/map/magic-v2.cpp | 6 +- src/map/map.cpp | 31 ++++--- src/map/map.hpp | 22 ++--- src/map/mapflag.cpp | 64 ++++++------- src/map/mob.cpp | 30 +++--- src/map/npc.cpp | 18 ++-- src/map/npc.hpp | 8 +- src/map/pc.cpp | 21 +++-- src/map/script.cpp | 40 ++++---- src/map/script.hpp | 4 +- src/map/skill-pools.cpp | 2 +- src/map/skill.cpp | 16 ++-- src/map/skill.hpp | 15 ++- src/map/tmw.hpp | 2 - src/map/trade.cpp | 8 +- src/mmo/core.cpp | 2 +- src/mmo/core.hpp | 4 +- src/mmo/dumb_ptr.hpp | 2 - src/mmo/extract.hpp | 2 - src/mmo/mmo.hpp | 29 ++++-- src/mmo/utils.hpp | 1 - src/range/slice.cpp | 1 + src/range/slice.hpp | 74 +++++++++++++++ src/range/slice.tcc | 216 ++++++++++++++++++++++++++++++++++++++++++++ src/range/slice_test.cpp | 89 ++++++++++++++++++ src/strings/base.hpp | 2 + src/strings/pair.hpp | 4 +- 51 files changed, 802 insertions(+), 503 deletions(-) delete mode 100644 src/generic/const_array.cpp delete mode 100644 src/generic/const_array.hpp create mode 100644 src/range/slice.cpp create mode 100644 src/range/slice.hpp create mode 100644 src/range/slice.tcc create mode 100644 src/range/slice_test.cpp (limited to 'src') diff --git a/src/admin/ladmin.cpp b/src/admin/ladmin.cpp index f889b19..b56fd65 100644 --- a/src/admin/ladmin.cpp +++ b/src/admin/ladmin.cpp @@ -2840,34 +2840,36 @@ void term_func(void) //------------------------ // Main function of ladmin //------------------------ -int do_init(int argc, ZString *argv) +int do_init(Slice argv) { + ZString argv0 = argv.pop_front(); bool loaded_config_yet = false; - for (int i = 1; i < argc; ++i) + while (argv) { - if (argv[i].startswith('-')) + ZString argvi = argv.pop_front(); + if (argvi.startswith('-')) { - if (argv[i] == "--help") + if (argvi == "--help") { PRINTF("Usage: %s [--help] [--version] [files...]\n", - argv[0]); + argv0); exit(0); } - else if (argv[i] == "--version") + else if (argvi == "--version") { PRINTF("%s\n", CURRENT_VERSION_STRING); exit(0); } else { - FPRINTF(stderr, "Unknown argument: %s\n", argv[i]); + FPRINTF(stderr, "Unknown argument: %s\n", argvi); runflag = false; } } else { loaded_config_yet = true; - runflag &= load_config_file(argv[i], admin_confs); + runflag &= load_config_file(argvi, admin_confs); } } diff --git a/src/char/char.cpp b/src/char/char.cpp index b74df46..91ff2e2 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -46,11 +46,11 @@ #include "../poison.hpp" static -struct mmo_map_server server[MAX_MAP_SERVERS]; +Array server; static -Session *server_session[MAX_MAP_SERVERS]; +Array server_session; static -int server_freezeflag[MAX_MAP_SERVERS]; // Map-server anti-freeze system. Counter. 5 ok, 4...0 freezed +Array server_freezeflag; // Map-server anti-freeze system. Counter. 5 ok, 4...0 freezed static int anti_freeze_enable = 0; static @@ -313,6 +313,7 @@ AString mmo_char_tostr(struct CharPair *cp) } str_p += '\t'; + assert (p->global_reg_num < GLOBAL_REG_NUM); for (int i = 0; i < p->global_reg_num; i++) if (p->global_reg[i].str) str_p += STRPRINTF("%s,%d ", @@ -411,14 +412,14 @@ bool extract(XString str, CharPair *cp) if (inventory.size() > MAX_INVENTORY) return false; - std::copy(inventory.begin(), inventory.end(), p->inventory); + std::copy(inventory.begin(), inventory.end(), p->inventory.begin()); // number of inventory items is not saved - it just detects nameid 0 // cart was here - no longer supported for (struct skill_loader& sk : skills) { - if (sk.id > MAX_SKILL) + if (sk.id >= MAX_SKILL) return false; p->skill[sk.id].lv = sk.level; p->skill[sk.id].flags = sk.flags; @@ -426,7 +427,7 @@ bool extract(XString str, CharPair *cp) if (vars.size() > GLOBAL_REG_NUM) return false; - std::copy(vars.begin(), vars.end(), p->global_reg); + std::copy(vars.begin(), vars.end(), p->global_reg.begin()); p->global_reg_num = vars.size(); return true; @@ -964,8 +965,10 @@ int mmo_char_send006b(Session *s, struct char_session_data *sd) } static -int set_account_reg2(int acc, int num, struct global_reg *reg) +int set_account_reg2(int acc, Slice reg) { + size_t num = reg.size(); + assert (num < ACCOUNT_REG2_NUM); int c = 0; for (CharPair& cd : char_keys) { @@ -1309,7 +1312,7 @@ void parse_tologin(Session *ls) if (RFIFOREST(ls) < 4 || RFIFOREST(ls) < RFIFOW(ls, 2)) return; { - struct global_reg reg[ACCOUNT_REG2_NUM]; + Array reg; int j, p, acc; acc = RFIFOL(ls, 4); for (p = 8, j = 0; @@ -1319,7 +1322,7 @@ void parse_tologin(Session *ls) reg[j].str = stringish(RFIFO_STRING<32>(ls, p)); reg[j].value = RFIFOL(ls, p + 32); } - set_account_reg2(acc, j, reg); + set_account_reg2(acc, Slice(reg.begin(), j)); size_t len = RFIFOW(ls, 2); uint8_t buf[len]; @@ -1980,7 +1983,7 @@ void parse_frommap(Session *ms) if (RFIFOREST(ms) < 4 || RFIFOREST(ms) < RFIFOW(ms, 2)) return; { - struct global_reg reg[ACCOUNT_REG2_NUM]; + Array reg; int p, j; int acc = RFIFOL(ms, 4); for (p = 8, j = 0; @@ -1990,7 +1993,7 @@ void parse_frommap(Session *ms) reg[j].str = stringish(RFIFO_STRING<32>(ms, p)); reg[j].value = RFIFOL(ms, p + 32); } - set_account_reg2(acc, j, reg); + set_account_reg2(acc, Slice(reg.begin(), j)); // loginサーバーへ送る if (login_session) { @@ -2831,34 +2834,37 @@ bool char_confs(XString key, ZString value) return sum; } -int do_init(int argc, ZString *argv) +int do_init(Slice argv) { + ZString argv0 = argv.pop_front(); + bool loaded_config_yet = false; - for (int i = 1; i < argc; ++i) + while (argv) { - if (argv[i].startswith('-')) + ZString argvi = argv.pop_front(); + if (argvi.startswith('-')) { - if (argv[i] == "--help") + if (argvi == "--help") { PRINTF("Usage: %s [--help] [--version] [files...]\n", - argv[0]); + argv0); exit(0); } - else if (argv[i] == "--version") + else if (argvi == "--version") { PRINTF("%s\n", CURRENT_VERSION_STRING); exit(0); } else { - FPRINTF(stderr, "Unknown argument: %s\n", argv[i]); + FPRINTF(stderr, "Unknown argument: %s\n", argvi); runflag = false; } } else { loaded_config_yet = true; - runflag &= load_config_file(argv[i], char_confs); + runflag &= load_config_file(argvi, char_confs); } } diff --git a/src/char/char.hpp b/src/char/char.hpp index 377b1c6..f765b39 100644 --- a/src/char/char.hpp +++ b/src/char/char.hpp @@ -3,8 +3,6 @@ # include "../strings/fwd.hpp" -# include "../generic/const_array.hpp" - # include "../mmo/ip.hpp" # include "../mmo/mmo.hpp" @@ -17,7 +15,7 @@ struct mmo_map_server IP4Address ip; short port; int users; - MapName maps[MAX_MAP_PER_SERVER]; + Array maps; }; const CharPair *search_character(CharName character_name); diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp index c0bedde..864972d 100644 --- a/src/char/int_party.cpp +++ b/src/char/int_party.cpp @@ -381,6 +381,7 @@ void mapif_party_leaved(int party_id, int account_id, CharName name) static void mapif_party_membermoved(struct party *p, int idx) { + assert (idx < MAX_PARTY); unsigned char buf[29]; WBUFW(buf, 0) = 0x3825; diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp index 0794c8f..d2782b4 100644 --- a/src/char/int_storage.cpp +++ b/src/char/int_storage.cpp @@ -83,8 +83,10 @@ bool extract(XString str, struct storage *p) if (storage_items.size() > MAX_STORAGE) return false; - std::copy(storage_items.begin(), storage_items.end(), p->storage_); + std::copy(storage_items.begin(), storage_items.end(), p->storage_.begin()); + if (p->storage_amount != storage_items.size()) + PRINTF("WARNING: storage desync for %d\n", p->account_id); return true; } diff --git a/src/char/inter.cpp b/src/char/inter.cpp index c287844..0c41c86 100644 --- a/src/char/inter.cpp +++ b/src/char/inter.cpp @@ -35,7 +35,7 @@ AString accreg_txt = "save/accreg.txt"; struct accreg { int account_id, reg_num; - struct global_reg reg[ACCOUNT_REG_NUM]; + Array reg; }; static Map accreg_db; @@ -63,6 +63,7 @@ int inter_recv_packet_length[] = static AString inter_accreg_tostr(struct accreg *reg) { + assert(reg->reg_num < ACCOUNT_REG_NUM); MString str; str += STRPRINTF("%d\t", reg->account_id); for (int j = 0; j < reg->reg_num; j++) @@ -85,7 +86,7 @@ bool extract(XString str, struct accreg *reg) if (vars.size() > ACCOUNT_REG_NUM) return false; - std::copy(vars.begin(), vars.end(), reg->reg); + std::copy(vars.begin(), vars.end(), reg->reg.begin()); reg->reg_num = vars.size(); return true; } @@ -263,6 +264,7 @@ void mapif_account_reg_reply(Session *s, int account_id) } else { + assert (reg->reg_num < ACCOUNT_REG_NUM); int j, p; for (j = 0, p = 8; j < reg->reg_num; j++, p += 36) { diff --git a/src/generic/const_array.cpp b/src/generic/const_array.cpp deleted file mode 100644 index 0c09333..0000000 --- a/src/generic/const_array.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "const_array.hpp" - -#include "../poison.hpp" diff --git a/src/generic/const_array.hpp b/src/generic/const_array.hpp deleted file mode 100644 index 1c70f5d..0000000 --- a/src/generic/const_array.hpp +++ /dev/null @@ -1,132 +0,0 @@ -#ifndef TMWA_GENERIC_CONST_ARRAY_HPP -#define TMWA_GENERIC_CONST_ARRAY_HPP -// const_array.hpp - just a pointer-to-const and a length -// -// Copyright © 2011-2012 Ben Longbons -// -// This file is part of The Mana World (Athena server) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -# include "../sanity.hpp" - -# include - -# include -# include -# include - -# ifdef WORKAROUND_GCC46_COMPILER -// constexpr is buggy with templates in this version -// Is this still needed now that const_string is removed? -# define constexpr /* nothing */ -# endif - -// TODO see if I ever actually use this, and not the subclass -template -class const_array -{ - const T *d; - size_t n; -public: - typedef const T *iterator; - typedef std::reverse_iterator reverse_iterator; - - constexpr - const_array(std::nullptr_t) - : d(nullptr), n(0) - {} - - constexpr - const_array(const T *p, size_t z) - : d(p), n(z) - {} - - constexpr - const_array(const T *b, const T *e) - : d(b), n(e - b) - {} - - const_array(std::initializer_list list) - : d(list.begin()), n(list.size()) - {} - - // Implicit conversion from std::vector - const_array(const std::vector& v) - : d(v.data()), n(v.size()) - {} - - // but disallow conversion from a temporary - const_array(std::vector&&) = delete; - - // Oops. see src/warnings.hpp - constexpr - const T *data() const { return d; } - constexpr - size_t size() const { return n; } - constexpr - bool empty() const { return not n; } - constexpr explicit - operator bool() const { return n; } - - constexpr - std::pair cut(size_t o) const - { - return {const_array(d, o), const_array(d + o, n - o)}; - } - - constexpr - const_array first(size_t o) const - { - return cut(o).first; - } - - constexpr - const_array last(size_t l) const - { - return cut(size() - l).second; - } - - constexpr - const_array after(size_t o) const - { - return cut(o).second; - } - - constexpr - iterator begin() const { return d; } - constexpr - iterator end() const { return d + n; } - constexpr - reverse_iterator rbegin() const { return reverse_iterator(end()); } - constexpr - reverse_iterator rend() const { return reverse_iterator(begin()); } - - constexpr - const T& front() const { return *begin(); } - constexpr - const T& back() const { return *rbegin(); } - - // This probably shouldn't be used, but I'm adding it for porting. - T& operator[](size_t i) - { - return const_cast(d[i]); - } -}; - -# ifdef WORKAROUND_GCC46_COMPILER -# undef constexpr -# endif - -#endif // TMWA_GENERIC_CONST_ARRAY_HPP diff --git a/src/generic/enum.hpp b/src/generic/enum.hpp index 6f29981..29e5c36 100644 --- a/src/generic/enum.hpp +++ b/src/generic/enum.hpp @@ -3,6 +3,8 @@ # include "../sanity.hpp" +# include + # include # include "../compat/iter.hpp" @@ -10,17 +12,27 @@ template struct earray { + constexpr static + size_t size() + { + return static_cast(max); + } + // no ctor/dtor and one public member variable for easy initialization - T _data[size_t(max)]; + T _data[size()]; T& operator[](E v) { - return _data[size_t(v)]; + auto i = static_cast(v); + assert (i < size()); + return _data[i]; } const T& operator[](E v) const { - return _data[size_t(v)]; + auto i = static_cast(v); + assert (i < size()); + return _data[i]; } T *begin() @@ -30,7 +42,7 @@ struct earray T *end() { - return _data + size_t(max); + return _data + size(); } const T *begin() const @@ -40,7 +52,7 @@ struct earray const T *end() const { - return _data + size_t(max); + return _data + size(); } friend bool operator == (const earray& l, const earray& r) @@ -54,23 +66,30 @@ struct earray } }; -template +template class eptr { + constexpr static + size_t size() + { + return static_cast(max); + } + T *_data; public: eptr(std::nullptr_t=nullptr) : _data(nullptr) {} - template eptr(earray& arr) : _data(arr._data) {} - T& operator [](E v) + T& operator [](E v) const { - return _data[size_t(v)]; + auto i = static_cast(v); + assert (i < size()); + return _data[i]; } explicit operator bool() @@ -109,6 +128,8 @@ struct remove_enum }; +// This really should just go in a namespace +// that's how I use it anyway ... # define ENUM_BITWISE_OPERATORS(E) \ inline \ E operator & (E l, E r) \ diff --git a/src/generic/intern-pool.hpp b/src/generic/intern-pool.hpp index 69f20ef..f9c1e8f 100644 --- a/src/generic/intern-pool.hpp +++ b/src/generic/intern-pool.hpp @@ -29,6 +29,7 @@ public: ZString outtern(size_t sz) const { + assert (sz < names.size()); return names[sz]; } diff --git a/src/generic/matrix.hpp b/src/generic/matrix.hpp index 3530ba7..b337249 100644 --- a/src/generic/matrix.hpp +++ b/src/generic/matrix.hpp @@ -3,6 +3,8 @@ # include "../sanity.hpp" +# include + # include "../compat/memory.hpp" template @@ -34,10 +36,14 @@ public: T& ref(size_t x, size_t y) { + assert (x < _xs); + assert (y < _ys); return _data[x + y * _xs]; } const T& ref(size_t x, size_t y) const { + assert (x < _xs); + assert (y < _ys); return _data[x + y * _xs]; } diff --git a/src/io/cxxstdio.hpp b/src/io/cxxstdio.hpp index 9edeebb..66419df 100644 --- a/src/io/cxxstdio.hpp +++ b/src/io/cxxstdio.hpp @@ -26,7 +26,6 @@ # include "../compat/cast.hpp" -# include "../generic/const_array.hpp" # include "../generic/enum.hpp" # include "fwd.hpp" diff --git a/src/login/login.cpp b/src/login/login.cpp index c9b285f..ddc3d89 100644 --- a/src/login/login.cpp +++ b/src/login/login.cpp @@ -114,11 +114,11 @@ static int display_parse_fromchar = 0; // 0: no, 1: yes (without packet 0x2714), 2: all packets static -struct mmo_char_server server[MAX_SERVERS]; +Array server; static -Session *server_session[MAX_SERVERS]; +Array server_session; static -int server_freezeflag[MAX_SERVERS]; // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed +Array server_freezeflag; // Char-server anti-freeze system. Counter. 5 ok, 4...0 freezed static int anti_freeze_enable = 0; static @@ -158,13 +158,14 @@ void SessionDeleter::operator()(SessionData *) #pragma GCC diagnostic pop constexpr int AUTH_FIFO_SIZE = 256; -struct +struct AuthFifo { int account_id, login_id1, login_id2; IP4Address ip; SEX sex; int delflag; -} auth_fifo[AUTH_FIFO_SIZE]; +}; +Array auth_fifo; static int auth_fifo_pos = 0; @@ -184,7 +185,7 @@ struct AuthData IP4Address last_ip; // save of last IP of connection VString<254> memo; // a memo field int account_reg2_num; - struct global_reg account_reg2[ACCOUNT_REG2_NUM]; + Array account_reg2; }; static std::vector auth_data; @@ -447,6 +448,7 @@ AString mmo_auth_tostr(const AuthData *p) p->memo, p->ban_until_time); + assert (p->account_reg2_num < ACCOUNT_REG2_NUM); for (int i = 0; i < p->account_reg2_num; i++) if (p->account_reg2[i].str) str += STRPRINTF("%s,%d ", @@ -522,7 +524,7 @@ bool extract(XString line, AuthData *ad) if (vars.size() > ACCOUNT_REG2_NUM) return false; - std::copy(vars.begin(), vars.end(), ad->account_reg2); + std::copy(vars.begin(), vars.end(), ad->account_reg2.begin()); ad->account_reg2_num = vars.size(); return true; @@ -3827,34 +3829,36 @@ bool login_confs(XString key, ZString value) //------------------------------ // Main function of login-server //------------------------------ -int do_init(int argc, ZString *argv) +int do_init(Slice argv) { + ZString argv0 = argv.pop_front(); bool loaded_config_yet = false; - for (int i = 1; i < argc; ++i) + while (argv) { - if (argv[i].startswith('-')) + ZString argvi = argv.pop_front(); + if (argvi.startswith('-')) { - if (argv[i] == "--help") + if (argvi == "--help") { PRINTF("Usage: %s [--help] [--version] [files...]\n", - argv[0]); + argv0); exit(0); } - else if (argv[i] == "--version") + else if (argvi == "--version") { PRINTF("%s\n", CURRENT_VERSION_STRING); exit(0); } else { - FPRINTF(stderr, "Unknown argument: %s\n", argv[i]); + FPRINTF(stderr, "Unknown argument: %s\n", argvi); runflag = false; } } else { loaded_config_yet = true; - runflag &= load_config_file(argv[i], login_confs); + runflag &= load_config_file(argvi, login_confs); } } diff --git a/src/map/atcommand.hpp b/src/map/atcommand.hpp index 16d1efc..45759a6 100644 --- a/src/map/atcommand.hpp +++ b/src/map/atcommand.hpp @@ -3,8 +3,6 @@ # include "../strings/fwd.hpp" -# include "../generic/const_array.hpp" - # include "map.hpp" bool is_atcommand(Session *s, dumb_ptr sd, diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 7e563b8..49a0538 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -166,7 +166,7 @@ int battle_get_max_hp(dumb_ptr bl) int battle_get_str(dumb_ptr bl) { int str = 0; - eptr sc_data; + eptr sc_data; nullpo_ret(bl); sc_data = battle_get_sc_data(bl); @@ -189,7 +189,7 @@ int battle_get_str(dumb_ptr bl) int battle_get_agi(dumb_ptr bl) { int agi = 0; - eptr sc_data; + eptr sc_data; nullpo_ret(bl); sc_data = battle_get_sc_data(bl); @@ -211,7 +211,7 @@ int battle_get_agi(dumb_ptr bl) int battle_get_vit(dumb_ptr bl) { int vit = 0; - eptr sc_data; + eptr sc_data; nullpo_ret(bl); sc_data = battle_get_sc_data(bl); @@ -233,7 +233,7 @@ int battle_get_vit(dumb_ptr bl) int battle_get_int(dumb_ptr bl) { int int_ = 0; - eptr sc_data; + eptr sc_data; nullpo_ret(bl); sc_data = battle_get_sc_data(bl); @@ -255,7 +255,7 @@ int battle_get_int(dumb_ptr bl) int battle_get_dex(dumb_ptr bl) { int dex = 0; - eptr sc_data; + eptr sc_data; nullpo_ret(bl); sc_data = battle_get_sc_data(bl); @@ -277,7 +277,7 @@ int battle_get_dex(dumb_ptr bl) int battle_get_luk(dumb_ptr bl) { int luk = 0; - eptr sc_data; + eptr sc_data; nullpo_ret(bl); sc_data = battle_get_sc_data(bl); @@ -300,7 +300,7 @@ static int battle_get_flee(dumb_ptr bl) { int flee = 1; - eptr sc_data; + eptr sc_data; nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); @@ -329,7 +329,7 @@ static int battle_get_hit(dumb_ptr bl) { int hit = 1; - eptr sc_data; + eptr sc_data; nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); @@ -357,7 +357,7 @@ static int battle_get_flee2(dumb_ptr bl) { int flee2 = 1; - eptr sc_data; + eptr sc_data; nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); @@ -389,7 +389,7 @@ static int battle_get_critical(dumb_ptr bl) { int critical = 1; - eptr sc_data; + eptr sc_data; nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); @@ -415,7 +415,7 @@ int battle_get_critical(dumb_ptr bl) static int battle_get_baseatk(dumb_ptr bl) { - eptr sc_data; + eptr sc_data; int batk = 1; nullpo_retr(1, bl); @@ -442,7 +442,7 @@ int battle_get_baseatk(dumb_ptr bl) static int battle_get_atk(dumb_ptr bl) { - eptr sc_data; + eptr sc_data; int atk = 0; nullpo_ret(bl); @@ -518,7 +518,7 @@ int battle_get_atk_2(dumb_ptr bl) static int battle_get_matk1(dumb_ptr bl) { - eptr sc_data; + eptr sc_data; nullpo_ret(bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::MOB) @@ -563,7 +563,7 @@ int battle_get_matk2(dumb_ptr bl) */ int battle_get_def(dumb_ptr bl) { - eptr sc_data; + eptr sc_data; int def = 0; nullpo_ret(bl); @@ -599,7 +599,7 @@ int battle_get_def(dumb_ptr bl) */ int battle_get_mdef(dumb_ptr bl) { - eptr sc_data; + eptr sc_data; int mdef = 0; nullpo_ret(bl); @@ -634,7 +634,7 @@ int battle_get_mdef(dumb_ptr bl) */ int battle_get_def2(dumb_ptr bl) { - eptr sc_data; + eptr sc_data; int def2 = 1; nullpo_retr(1, bl); @@ -715,7 +715,7 @@ interval_t battle_get_adelay(dumb_ptr bl) return bl->is_player()->aspd * 2; else { - eptr sc_data = battle_get_sc_data(bl); + eptr sc_data = battle_get_sc_data(bl); interval_t adelay = std::chrono::seconds(4); int aspd_rate = 100; if (bl->bl_type == BL::MOB) @@ -743,7 +743,7 @@ interval_t battle_get_amotion(dumb_ptr bl) return bl->is_player()->amotion; else { - eptr sc_data = battle_get_sc_data(bl); + eptr sc_data = battle_get_sc_data(bl); interval_t amotion = std::chrono::seconds(2); int aspd_rate = 100; if (bl->bl_type == BL::MOB) @@ -846,7 +846,7 @@ int battle_get_stat(SP stat_id, dumb_ptr bl) } // StatusChange系の所得 -eptr battle_get_sc_data(dumb_ptr bl) +eptr battle_get_sc_data(dumb_ptr bl) { nullpo_retr(nullptr, bl); @@ -1064,7 +1064,7 @@ struct Damage battle_calc_mob_weapon_attack(dumb_ptr src, BF flag; int ac_flag = 0; ATK dmg_lv = ATK::ZERO; - eptr sc_data, t_sc_data; + eptr sc_data, t_sc_data; nullpo_retr(wd, src); nullpo_retr(wd, target); @@ -1337,7 +1337,7 @@ struct Damage battle_calc_pc_weapon_attack(dumb_ptr src, int div_; BF flag; ATK dmg_lv = ATK::ZERO; - eptr sc_data, t_sc_data; + eptr sc_data, t_sc_data; int atkmax_ = 0, atkmin_ = 0; //二刀流用 int watk, watk_; bool da = false; @@ -1959,7 +1959,7 @@ ATK battle_weapon_attack(dumb_ptr src, dumb_ptr target, tick_t tick) { dumb_ptr sd = NULL; - eptr t_sc_data = battle_get_sc_data(target); + eptr t_sc_data = battle_get_sc_data(target); struct Damage wd; nullpo_retr(ATK::ZERO, src); diff --git a/src/map/battle.hpp b/src/map/battle.hpp index fd452e8..5c62785 100644 --- a/src/map/battle.hpp +++ b/src/map/battle.hpp @@ -78,7 +78,7 @@ Race battle_get_race(dumb_ptr bl); MobMode battle_get_mode(dumb_ptr bl); int battle_get_stat(SP stat_id, dumb_ptr bl); -eptr battle_get_sc_data(dumb_ptr bl); +eptr battle_get_sc_data(dumb_ptr bl); short *battle_get_sc_count(dumb_ptr bl); Opt1 *battle_get_opt1(dumb_ptr bl); Opt2 *battle_get_opt2(dumb_ptr bl); diff --git a/src/map/clif.cpp b/src/map/clif.cpp index a5b02cd..3290013 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -2021,7 +2021,7 @@ int clif_misceffect(dumb_ptr bl, int type) int clif_changeoption(dumb_ptr bl) { uint8_t buf[32]; - eptr sc_data; + eptr sc_data; nullpo_ret(bl); @@ -2435,7 +2435,7 @@ int clif_damage(dumb_ptr src, dumb_ptr dst, int div, DamageType type, int damage2) { unsigned char buf[256]; - eptr sc_data; + eptr sc_data; nullpo_ret(src); nullpo_ret(dst); @@ -2800,7 +2800,7 @@ int clif_skill_damage(dumb_ptr src, dumb_ptr dst, int div, SkillID skill_id, int skill_lv, int type) { unsigned char buf[64]; - eptr sc_data; + eptr sc_data; nullpo_ret(src); nullpo_ret(dst); diff --git a/src/map/clif.hpp b/src/map/clif.hpp index c346f7d..571f68e 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -7,8 +7,6 @@ # include "../strings/fwd.hpp" -# include "../generic/const_array.hpp" - # include "../mmo/ip.hpp" # include "../mmo/timer.t.hpp" diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 7f7be73..b2b95fe 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -104,6 +104,7 @@ void intif_saveaccountreg(dumb_ptr sd) int j, p; nullpo_retv(sd); + assert (sd->status.account_reg_num < ACCOUNT_REG_NUM); WFIFOW(char_session, 0) = 0x3004; WFIFOL(char_session, 4) = sd->bl_id; diff --git a/src/map/intif.hpp b/src/map/intif.hpp index ac2740c..7028ed9 100644 --- a/src/map/intif.hpp +++ b/src/map/intif.hpp @@ -3,8 +3,6 @@ # include "../strings/fwd.hpp" -# include "../generic/const_array.hpp" - # include "map.hpp" int intif_parse(Session *); diff --git a/src/map/magic-expr-eval.hpp b/src/map/magic-expr-eval.hpp index 0783dc8..4de2f81 100644 --- a/src/map/magic-expr-eval.hpp +++ b/src/map/magic-expr-eval.hpp @@ -1,6 +1,8 @@ #ifndef TMWA_MAP_MAGIC_EXPR_EVAL_HPP #define TMWA_MAP_MAGIC_EXPR_EVAL_HPP +# include "../range/slice.hpp" + # include "../strings/zstring.hpp" # include "magic-interpreter.hpp" @@ -8,7 +10,7 @@ /* Helper definitions for dealing with functions and operations */ int magic_signature_check(ZString opname, ZString funname, ZString signature, - int args_nr, val_t *args, int line, int column); + Slice args, int line, int column); void magic_area_rect(map_local **m, int *x, int *y, int *width, int *height, area_t& area); diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index 1be1b0b..1881afc 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -261,7 +261,7 @@ void make_spell(val_t *v) } static -int fun_add(dumb_ptr, val_t *result, const_array args) +int fun_add(dumb_ptr, val_t *result, Slice args) { if (ARG_TYPE(0) == TYPE::INT && ARG_TYPE(1) == TYPE::INT) { @@ -296,21 +296,21 @@ int fun_add(dumb_ptr, val_t *result, const_array args) } static -int fun_sub(dumb_ptr, val_t *result, const_array args) +int fun_sub(dumb_ptr, val_t *result, Slice args) { RESULTINT = ARGINT(0) - ARGINT(1); return 0; } static -int fun_mul(dumb_ptr, val_t *result, const_array args) +int fun_mul(dumb_ptr, val_t *result, Slice args) { RESULTINT = ARGINT(0) * ARGINT(1); return 0; } static -int fun_div(dumb_ptr, val_t *result, const_array args) +int fun_div(dumb_ptr, val_t *result, Slice args) { if (!ARGINT(1)) return 1; /* division by zero */ @@ -319,7 +319,7 @@ int fun_div(dumb_ptr, val_t *result, const_array args) } static -int fun_mod(dumb_ptr, val_t *result, const_array args) +int fun_mod(dumb_ptr, val_t *result, Slice args) { if (!ARGINT(1)) return 1; /* division by zero */ @@ -328,35 +328,35 @@ int fun_mod(dumb_ptr, val_t *result, const_array args) } static -int fun_or(dumb_ptr, val_t *result, const_array args) +int fun_or(dumb_ptr, val_t *result, Slice args) { RESULTINT = ARGINT(0) || ARGINT(1); return 0; } static -int fun_and(dumb_ptr, val_t *result, const_array args) +int fun_and(dumb_ptr, val_t *result, Slice args) { RESULTINT = ARGINT(0) && ARGINT(1); return 0; } static -int fun_not(dumb_ptr, val_t *result, const_array args) +int fun_not(dumb_ptr, val_t *result, Slice args) { RESULTINT = !ARGINT(0); return 0; } static -int fun_neg(dumb_ptr, val_t *result, const_array args) +int fun_neg(dumb_ptr, val_t *result, Slice args) { RESULTINT = ~ARGINT(0); return 0; } static -int fun_gte(dumb_ptr, val_t *result, const_array args) +int fun_gte(dumb_ptr, val_t *result, Slice args) { if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { @@ -374,7 +374,7 @@ int fun_gte(dumb_ptr, val_t *result, const_array args) } static -int fun_lt(dumb_ptr env, val_t *result, const_array args) +int fun_lt(dumb_ptr env, val_t *result, Slice args) { fun_gte(env, result, args); RESULTINT = !RESULTINT; @@ -382,7 +382,7 @@ int fun_lt(dumb_ptr env, val_t *result, const_array args) } static -int fun_gt(dumb_ptr, val_t *result, const_array args) +int fun_gt(dumb_ptr, val_t *result, Slice args) { if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { @@ -400,7 +400,7 @@ int fun_gt(dumb_ptr, val_t *result, const_array args) } static -int fun_lte(dumb_ptr env, val_t *result, const_array args) +int fun_lte(dumb_ptr env, val_t *result, Slice args) { fun_gt(env, result, args); RESULTINT = !RESULTINT; @@ -408,7 +408,7 @@ int fun_lte(dumb_ptr env, val_t *result, const_array args) } static -int fun_eq(dumb_ptr, val_t *result, const_array args) +int fun_eq(dumb_ptr, val_t *result, Slice args) { if (ARG_TYPE(0) == TYPE::STRING || ARG_TYPE(1) == TYPE::STRING) { @@ -440,7 +440,7 @@ int fun_eq(dumb_ptr, val_t *result, const_array args) } static -int fun_ne(dumb_ptr env, val_t *result, const_array args) +int fun_ne(dumb_ptr env, val_t *result, Slice args) { fun_eq(env, result, args); RESULTINT = !RESULTINT; @@ -448,56 +448,56 @@ int fun_ne(dumb_ptr env, val_t *result, const_array args) } static -int fun_bitand(dumb_ptr, val_t *result, const_array args) +int fun_bitand(dumb_ptr, val_t *result, Slice args) { RESULTINT = ARGINT(0) & ARGINT(1); return 0; } static -int fun_bitor(dumb_ptr, val_t *result, const_array args) +int fun_bitor(dumb_ptr, val_t *result, Slice args) { RESULTINT = ARGINT(0) | ARGINT(1); return 0; } static -int fun_bitxor(dumb_ptr, val_t *result, const_array args) +int fun_bitxor(dumb_ptr, val_t *result, Slice args) { RESULTINT = ARGINT(0) ^ ARGINT(1); return 0; } static -int fun_bitshl(dumb_ptr, val_t *result, const_array args) +int fun_bitshl(dumb_ptr, val_t *result, Slice args) { RESULTINT = ARGINT(0) << ARGINT(1); return 0; } static -int fun_bitshr(dumb_ptr, val_t *result, const_array args) +int fun_bitshr(dumb_ptr, val_t *result, Slice args) { RESULTINT = ARGINT(0) >> ARGINT(1); return 0; } static -int fun_max(dumb_ptr, val_t *result, const_array args) +int fun_max(dumb_ptr, val_t *result, Slice args) { RESULTINT = max(ARGINT(0), ARGINT(1)); return 0; } static -int fun_min(dumb_ptr, val_t *result, const_array args) +int fun_min(dumb_ptr, val_t *result, Slice args) { RESULTINT = min(ARGINT(0), ARGINT(1)); return 0; } static -int fun_if_then_else(dumb_ptr, val_t *result, const_array args) +int fun_if_then_else(dumb_ptr, val_t *result, Slice args) { if (ARGINT(0)) magic_copy_var(result, &args[1]); @@ -606,7 +606,7 @@ int magic_location_in_area(map_local *m, int x, int y, dumb_ptr area) } static -int fun_is_in(dumb_ptr, val_t *result, const_array args) +int fun_is_in(dumb_ptr, val_t *result, Slice args) { RESULTINT = magic_location_in_area(ARGLOCATION(0).m, ARGLOCATION(0).x, @@ -615,7 +615,7 @@ int fun_is_in(dumb_ptr, val_t *result, const_array args) } static -int fun_skill(dumb_ptr, val_t *result, const_array args) +int fun_skill(dumb_ptr, val_t *result, Slice args) { if (ENTITY_TYPE(0) != BL::PC // don't convert to enum until after the range check @@ -633,18 +633,18 @@ int fun_skill(dumb_ptr, val_t *result, const_array args) } static -int fun_his_shroud(dumb_ptr, val_t *result, const_array args) +int fun_his_shroud(dumb_ptr, val_t *result, Slice args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->state.shroud_active); return 0; } -#define BATTLE_GETTER(name) \ -static \ -int fun_get_##name(dumb_ptr, val_t *result, const_array args) \ -{ \ - RESULTINT = battle_get_##name(ARGENTITY(0)); \ - return 0; \ +#define BATTLE_GETTER(name) \ +static \ +int fun_get_##name(dumb_ptr, val_t *result, Slice args) \ +{ \ + RESULTINT = battle_get_##name(ARGENTITY(0)); \ + return 0; \ } BATTLE_GETTER(str) @@ -659,28 +659,28 @@ BATTLE_GETTER(mdef) BATTLE_GETTER(def) BATTLE_GETTER(max_hp) static -int fun_get_dir(dumb_ptr, val_t *result, const_array args) +int fun_get_dir(dumb_ptr, val_t *result, Slice args) { RESULTDIR = battle_get_dir(ARGENTITY(0)); return 0; } -#define MMO_GETTER(name) \ -static \ -int fun_get_##name(dumb_ptr, val_t *result, const_array args) \ -{ \ - if (ENTITY_TYPE(0) == BL::PC) \ - RESULTINT = ARGPC(0)->status.name; \ - else \ - RESULTINT = 0; \ - return 0; \ +#define MMO_GETTER(name) \ +static \ +int fun_get_##name(dumb_ptr, val_t *result, Slice args) \ +{ \ + if (ENTITY_TYPE(0) == BL::PC) \ + RESULTINT = ARGPC(0)->status.name; \ + else \ + RESULTINT = 0; \ + return 0; \ } MMO_GETTER(sp) MMO_GETTER(max_sp) static -int fun_name_of(dumb_ptr, val_t *result, const_array args) +int fun_name_of(dumb_ptr, val_t *result, Slice args) { if (ARG_TYPE(0) == TYPE::ENTITY) { @@ -702,7 +702,7 @@ int fun_name_of(dumb_ptr, val_t *result, const_array args) /* [Freeyorp] I'm putting this one in as name_of seems to have issues with summoned or spawned mobs. */ static -int fun_mob_id(dumb_ptr, val_t *result, const_array args) +int fun_mob_id(dumb_ptr, val_t *result, Slice args) { if (ENTITY_TYPE(0) != BL::MOB) return 1; @@ -727,14 +727,14 @@ void COPY_LOCATION(location_t& dest, block_list& src) } static -int fun_location(dumb_ptr, val_t *result, const_array args) +int fun_location(dumb_ptr, val_t *result, Slice args) { COPY_LOCATION(RESULTLOCATION, *(ARGENTITY(0))); return 0; } static -int fun_random(dumb_ptr, val_t *result, const_array args) +int fun_random(dumb_ptr, val_t *result, Slice args) { int delta = ARGINT(0); if (delta < 0) @@ -752,7 +752,7 @@ int fun_random(dumb_ptr, val_t *result, const_array args) } static -int fun_random_dir(dumb_ptr, val_t *result, const_array args) +int fun_random_dir(dumb_ptr, val_t *result, Slice args) { if (ARGINT(0)) RESULTDIR = random_::choice({DIR::S, DIR::SW, DIR::W, DIR::NW, DIR::N, DIR::NE, DIR::E, DIR::SE}); @@ -762,14 +762,14 @@ int fun_random_dir(dumb_ptr, val_t *result, const_array args) } static -int fun_hash_entity(dumb_ptr, val_t *result, const_array args) +int fun_hash_entity(dumb_ptr, val_t *result, Slice args) { RESULTINT = ARGENTITY(0)->bl_id; return 0; } int // ret -1: not a string, ret 1: no such item, ret 0: OK -magic_find_item(const_array args, int index, struct item *item_, int *stackable) +magic_find_item(Slice args, int index, struct item *item_, int *stackable) { struct item_data *item_data; int must_add_sequentially; @@ -801,7 +801,7 @@ magic_find_item(const_array args, int index, struct item *item_, int *sta } static -int fun_count_item(dumb_ptr, val_t *result, const_array args) +int fun_count_item(dumb_ptr, val_t *result, Slice args) { dumb_ptr chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; int stackable; @@ -817,7 +817,7 @@ int fun_count_item(dumb_ptr, val_t *result, const_array args) } static -int fun_is_equipped(dumb_ptr, val_t *result, const_array args) +int fun_is_equipped(dumb_ptr, val_t *result, Slice args) { dumb_ptr chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; int stackable; @@ -843,28 +843,28 @@ int fun_is_equipped(dumb_ptr, val_t *result, const_array args) } static -int fun_is_married(dumb_ptr, val_t *result, const_array args) +int fun_is_married(dumb_ptr, val_t *result, Slice args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->status.partner_id); return 0; } static -int fun_is_dead(dumb_ptr, val_t *result, const_array args) +int fun_is_dead(dumb_ptr, val_t *result, Slice args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC && pc_isdead(ARGPC(0))); return 0; } static -int fun_is_pc(dumb_ptr, val_t *result, const_array args) +int fun_is_pc(dumb_ptr, val_t *result, Slice args) { RESULTINT = (ENTITY_TYPE(0) == BL::PC); return 0; } static -int fun_partner(dumb_ptr, val_t *result, const_array args) +int fun_partner(dumb_ptr, val_t *result, Slice args) { if (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->status.partner_id) { @@ -877,7 +877,7 @@ int fun_partner(dumb_ptr, val_t *result, const_array args) } static -int fun_awayfrom(dumb_ptr, val_t *result, const_array args) +int fun_awayfrom(dumb_ptr, val_t *result, Slice args) { location_t *loc = &ARGLOCATION(0); int dx = dirx[ARGDIR(1)]; @@ -896,14 +896,14 @@ int fun_awayfrom(dumb_ptr, val_t *result, const_array args) } static -int fun_failed(dumb_ptr, val_t *result, const_array args) +int fun_failed(dumb_ptr, val_t *result, Slice args) { RESULTINT = ARG_TYPE(0) == TYPE::FAIL; return 0; } static -int fun_npc(dumb_ptr, val_t *result, const_array args) +int fun_npc(dumb_ptr, val_t *result, Slice args) { NpcName name = stringish(ARGSTR(0)); RESULTENTITY = npc_name2id(name); @@ -911,7 +911,7 @@ int fun_npc(dumb_ptr, val_t *result, const_array args) } static -int fun_pc(dumb_ptr, val_t *result, const_array args) +int fun_pc(dumb_ptr, val_t *result, Slice args) { CharName name = stringish(ARGSTR(0)); RESULTENTITY = map_nick2sd(name); @@ -919,7 +919,7 @@ int fun_pc(dumb_ptr, val_t *result, const_array args) } static -int fun_distance(dumb_ptr, val_t *result, const_array args) +int fun_distance(dumb_ptr, val_t *result, Slice args) { if (ARGLOCATION(0).m != ARGLOCATION(1).m) RESULTINT = 0x7fffffff; @@ -930,7 +930,7 @@ int fun_distance(dumb_ptr, val_t *result, const_array args) } static -int fun_rdistance(dumb_ptr, val_t *result, const_array args) +int fun_rdistance(dumb_ptr, val_t *result, Slice args) { if (ARGLOCATION(0).m != ARGLOCATION(1).m) RESULTINT = 0x7fffffff; @@ -944,7 +944,7 @@ int fun_rdistance(dumb_ptr, val_t *result, const_array args) } static -int fun_anchor(dumb_ptr env, val_t *result, const_array args) +int fun_anchor(dumb_ptr env, val_t *result, Slice args) { dumb_ptr anchor = magic_find_anchor(ARGSTR(0)); @@ -964,7 +964,7 @@ int fun_anchor(dumb_ptr env, val_t *result, const_array args) } static -int fun_line_of_sight(dumb_ptr, val_t *result, const_array args) +int fun_line_of_sight(dumb_ptr, val_t *result, Slice args) { block_list e1, e2; @@ -1020,14 +1020,14 @@ void magic_random_location(location_t *dest, dumb_ptr area) } static -int fun_pick_location(dumb_ptr, val_t *result, const_array args) +int fun_pick_location(dumb_ptr, val_t *result, Slice args) { magic_random_location(&result->v.v_location, ARGAREA(0)); return 0; } static -int fun_read_script_int(dumb_ptr, val_t *result, const_array args) +int fun_read_script_int(dumb_ptr, val_t *result, Slice args) { dumb_ptr subject_p = ARGENTITY(0); VarName var_name = stringish(ARGSTR(1)); @@ -1041,7 +1041,7 @@ int fun_read_script_int(dumb_ptr, val_t *result, const_array args) } static -int fun_read_script_str(dumb_ptr, val_t *result, const_array args) +int fun_read_script_str(dumb_ptr, val_t *result, Slice args) { dumb_ptr subject_p = ARGENTITY(0); VarName var_name = stringish(ARGSTR(1)); @@ -1055,7 +1055,7 @@ int fun_read_script_str(dumb_ptr, val_t *result, const_array args) } static -int fun_rbox(dumb_ptr, val_t *result, const_array args) +int fun_rbox(dumb_ptr, val_t *result, Slice args) { location_t loc = ARGLOCATION(0); int radius = ARGINT(1); @@ -1071,7 +1071,7 @@ int fun_rbox(dumb_ptr, val_t *result, const_array args) } static -int fun_running_status_update(dumb_ptr, val_t *result, const_array args) +int fun_running_status_update(dumb_ptr, val_t *result, Slice args) { if (ENTITY_TYPE(0) != BL::PC && ENTITY_TYPE(0) != BL::MOB) return 1; @@ -1082,28 +1082,28 @@ int fun_running_status_update(dumb_ptr, val_t *result, const_array } static -int fun_status_option(dumb_ptr, val_t *result, const_array args) +int fun_status_option(dumb_ptr, val_t *result, Slice args) { RESULTINT = (bool((ARGPC(0))->status.option & static_cast