Cleaned up script command argument parsing (#3910)

* Cleaned up the way script commands parse arguments.
* script_isstring and script_isint will now properly check variable references.
* This allows script command arguments to contain variables without having to make source side adjustments.
* Reverted several script commands that reference the data directly.
Thanks to @Lemongrass3110!
This commit is contained in:
Aleos 2019-02-05 18:50:54 -05:00 committed by GitHub
parent 0fcc6c0028
commit 1f97beae27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 257 additions and 352 deletions

View File

@ -2318,13 +2318,13 @@ static void pc_bonus_item_drop(std::vector<s_add_drop> &drop, unsigned short nam
* @param script: Script to execute * @param script: Script to execute
* @param rate: Success chance * @param rate: Success chance
* @param dur: Duration * @param dur: Duration
* @param flag: Battle flag * @param flag: Battle flag/skill
* @param other_script: Secondary script to execute * @param other_script: Secondary script to execute
* @param pos: Item equip position * @param pos: Item equip position
* @param onskill: Skill used to trigger autobonus * @param onskill: Skill used to trigger autobonus
* @return True on success or false otherwise * @return True on success or false otherwise
*/ */
bool pc_addautobonus(std::vector<s_autobonus> &bonus, const char *script, short rate, unsigned int dur, short flag, const char *other_script, unsigned int pos, bool onskill) bool pc_addautobonus(std::vector<s_autobonus> &bonus, const char *script, short rate, unsigned int dur, uint16 flag, const char *other_script, unsigned int pos, bool onskill)
{ {
if (bonus.size() == MAX_PC_BONUS) { if (bonus.size() == MAX_PC_BONUS) {
ShowWarning("pc_addautobonus: Reached max (%d) number of autobonus per character!\n", MAX_PC_BONUS); ShowWarning("pc_addautobonus: Reached max (%d) number of autobonus per character!\n", MAX_PC_BONUS);

View File

@ -195,7 +195,8 @@ struct s_add_drop {
/// AutoBonus bonus struct /// AutoBonus bonus struct
struct s_autobonus { struct s_autobonus {
short rate,atk_type; short rate;
uint16 atk_type;
unsigned int duration; unsigned int duration;
char *bonus_script, *other_script; char *bonus_script, *other_script;
int active; int active;
@ -1070,7 +1071,7 @@ bool pc_adoption(struct map_session_data *p1_sd, struct map_session_data *p2_sd,
void pc_updateweightstatus(struct map_session_data *sd); void pc_updateweightstatus(struct map_session_data *sd);
bool pc_addautobonus(std::vector<s_autobonus> &bonus, const char *script, short rate, unsigned int dur, short atk_type, const char *o_script, unsigned int pos, bool onskill); bool pc_addautobonus(std::vector<s_autobonus> &bonus, const char *script, short rate, unsigned int dur, uint16 atk_type, const char *o_script, unsigned int pos, bool onskill);
void pc_exeautobonus(struct map_session_data* sd, std::vector<s_autobonus> *bonus, struct s_autobonus *autobonus); void pc_exeautobonus(struct map_session_data* sd, std::vector<s_autobonus> *bonus, struct s_autobonus *autobonus);
TIMER_FUNC(pc_endautobonus); TIMER_FUNC(pc_endautobonus);
void pc_delautobonus(struct map_session_data* sd, std::vector<s_autobonus> &bonus, bool restore); void pc_delautobonus(struct map_session_data* sd, std::vector<s_autobonus> &bonus, bool restore);

File diff suppressed because it is too large Load Diff

View File

@ -46,8 +46,8 @@
/// Pushes a copy of the data in the target index /// Pushes a copy of the data in the target index
#define script_pushcopy(st,i) push_copy((st)->stack, (st)->start + (i)) #define script_pushcopy(st,i) push_copy((st)->stack, (st)->start + (i))
#define script_isstring(st,i) data_isstring(script_getdata(st,i)) #define script_isstring(st,i) data_isstring(get_val(st, script_getdata(st,i)))
#define script_isint(st,i) data_isint(script_getdata(st,i)) #define script_isint(st,i) data_isint(get_val(st, script_getdata(st,i)))
#define script_getnum(st,val) conv_num(st, script_getdata(st,val)) #define script_getnum(st,val) conv_num(st, script_getdata(st,val))
#define script_getstr(st,val) conv_str(st, script_getdata(st,val)) #define script_getstr(st,val) conv_str(st, script_getdata(st,val))