Skip to content
Permalink
Browse files

Merge pull request #2526 from Asheraf/statusconfiglibconf

Convert sc_config to use libconfig
  • Loading branch information...
hemagx committed Sep 10, 2019
2 parents 307248a + 6ea8e59 commit 6dbabae7003990369d1c9ce965c3c4409c879499

Large diffs are not rendered by default.

This file was deleted.

@@ -13397,25 +13397,104 @@ static bool status_readdb_sizefix(char *fields[], int columns, int current)
return true;
}

static bool status_readdb_scconfig(char *fields[], int columns, int current)
static bool status_read_scdb_libconfig(void)
{
int val = 0;
char* type = fields[0];
struct config_t status_conf;
char filepath[256];
safesnprintf(filepath, sizeof(filepath), "%s/%s", map->db_path, "sc_config.conf");

nullpo_retr(false, fields);
if( !script->get_constant(type, &val) ){
ShowWarning("status_readdb_sc_conf: Invalid status type %s specified.\n", type);
if (libconfig->load_file(&status_conf, filepath) == CONFIG_FALSE) {
ShowError("status_read_scdb_libconfig: can't read %s\n", filepath);
return false;
}

status->dbs->sc_conf[val] = (int)strtol(fields[1], NULL, 0);
if (status->dbs->sc_conf[val] & SC_VISIBLE)
{
status->dbs->DisplayType[val] = true;
int i = 0;
int count = 0;
struct config_setting_t *it = NULL;

while ((it = libconfig->setting_get_elem(status_conf.root, i++)) != NULL) {
if (status->read_scdb_libconfig_sub(it, i - 1, filepath))
++count;
}

libconfig->destroy(&status_conf);
ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, filepath);
return true;
}

static bool status_read_scdb_libconfig_sub(struct config_setting_t *it, int idx, const char *source)
{
nullpo_retr(false, it);
nullpo_retr(false, source);

int i32;
const char *name = config_setting_name(it);

if (!script->get_constant(name, &i32) || i32 <= SC_NONE || i32 >= SC_MAX) {
ShowWarning("status_read_scdb_libconfig_sub: Invalid status type (%s) in \"%s\" entry #%d, skipping.\n", name, source, idx);
return false;
}

libconfig->setting_lookup_bool_real(it, "Visible", &status->dbs->DisplayType[i32]);

struct config_setting_t *fg = libconfig->setting_get_member(it, "Flags");
if (fg != NULL)
status->read_scdb_libconfig_sub_flag(fg, i32, source);

return true;
}

static bool status_read_scdb_libconfig_sub_flag(struct config_setting_t *it, int type, const char *source)
{
nullpo_retr(false, it);
nullpo_retr(false, source);
Assert_retr(false, type > SC_NONE && type < SC_MAX);

int i = 0;
struct config_setting_t *t = NULL;
while ((t = libconfig->setting_get_elem(it, i++)) != NULL) {
const char *flag = config_setting_name(t);
bool on = libconfig->setting_get_bool_real(t);
int j;

struct {
const char *name;
enum sc_conf_type value;
} flags[] = {
{ "NoDeathReset", SC_NO_REM_DEATH },
{ "NoSave", SC_NO_SAVE },
{ "NoDispelReset", SC_NO_DISPELL },
{ "NoClearanceReset", SC_NO_CLEARANCE },
{ "Buff", SC_BUFF },
{ "Debuff", SC_DEBUFF },
{ "NoMadoReset", SC_MADO_NO_RESET },
{ "NoAllReset", SC_NO_CLEAR }
};

ARR_FIND(0, ARRAYLENGTH(flags), j, strcmpi(flag, flags[j].name) == 0);
if (j != ARRAYLENGTH(flags)) {
if (strcmp(flag, flags[j].name) != 0) {
ShowWarning("status_read_scdb_libconfig_sub_flag: flag (%s) for status effect (%d) is casesensitive, correct it to (%s).", flag, type, flags[i].name);
}
if (on) {
status->dbs->sc_conf[type] |= flags[j].value;
} else {
status->dbs->sc_conf[type] &= ~flags[j].value;
}
} else {
if (!status->read_scdb_libconfig_sub_flag_additional(it, type, source))
ShowWarning("status_read_scdb_libconfig_sub_flag: invalid flag (%s) for status effect (%d).", flag, type);
}
}
return true;
}

static bool status_read_scdb_libconfig_sub_flag_additional(struct config_setting_t *it, int type, const char *source)
{
// to be used by plugins
return false;
}

/**
* Read status db
* job1.txt
@@ -13454,7 +13533,7 @@ static int status_readdb(void)
//
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_SINGLE_WEAPON_TYPE, MAX_SINGLE_WEAPON_TYPE, ARRAYLENGTH(status->dbs->atkmods), status->readdb_sizefix);
sv->readdb(map->db_path, "sc_config.txt", ',', 2, 2, SC_MAX, status->readdb_scconfig);
status->read_scdb_libconfig();
status->read_job_db();

pc->validate_levels();
@@ -13644,7 +13723,10 @@ void status_defaults(void)
status->natural_heal_timer = status_natural_heal_timer;
status->readdb_job2 = status_readdb_job2;
status->readdb_sizefix = status_readdb_sizefix;
status->readdb_scconfig = status_readdb_scconfig;
status->read_scdb_libconfig = status_read_scdb_libconfig;
status->read_scdb_libconfig_sub = status_read_scdb_libconfig_sub;
status->read_scdb_libconfig_sub_flag = status_read_scdb_libconfig_sub_flag;
status->read_scdb_libconfig_sub_flag_additional = status_read_scdb_libconfig_sub_flag_additional;
status->read_job_db = status_read_job_db;
status->read_job_db_sub = status_read_job_db_sub;
status->set_sc = status_set_sc;
@@ -50,7 +50,7 @@ struct pet_data;

/**
* SC configuration type
* @see db/sc_config.txt for more information
* @see db/sc_config.conf for more information
**/
typedef enum sc_conf_type {
SC_NO_REM_DEATH = 0x001,
@@ -2387,7 +2387,10 @@ struct status_interface {
int (*natural_heal_timer) (int tid, int64 tick, int id, intptr_t data);
bool (*readdb_job2) (char *fields[], int columns, int current);
bool (*readdb_sizefix) (char *fields[], int columns, int current);
bool (*readdb_scconfig) (char *fields[], int columns, int current);
bool (*read_scdb_libconfig) (void);
bool (*read_scdb_libconfig_sub) (struct config_setting_t *it, int idx, const char *source);
bool (*read_scdb_libconfig_sub_flag) (struct config_setting_t *it, int type, const char *source);
bool (*read_scdb_libconfig_sub_flag_additional) (struct config_setting_t *it, int type, const char *source);
void (*read_job_db) (void);
void (*read_job_db_sub) (int idx, const char *name, struct config_setting_t *jdb);
void (*set_sc) (uint16 skill_id, sc_type sc, int icon, unsigned int flag);
@@ -7934,8 +7934,14 @@ typedef bool (*HPMHOOK_pre_status_readdb_job2) (char **fields[], int *columns, i
typedef bool (*HPMHOOK_post_status_readdb_job2) (bool retVal___, char *fields[], int columns, int current);
typedef bool (*HPMHOOK_pre_status_readdb_sizefix) (char **fields[], int *columns, int *current);
typedef bool (*HPMHOOK_post_status_readdb_sizefix) (bool retVal___, char *fields[], int columns, int current);
typedef bool (*HPMHOOK_pre_status_readdb_scconfig) (char **fields[], int *columns, int *current);
typedef bool (*HPMHOOK_post_status_readdb_scconfig) (bool retVal___, char *fields[], int columns, int current);
typedef bool (*HPMHOOK_pre_status_read_scdb_libconfig) (void);
typedef bool (*HPMHOOK_post_status_read_scdb_libconfig) (bool retVal___);
typedef bool (*HPMHOOK_pre_status_read_scdb_libconfig_sub) (struct config_setting_t **it, int *idx, const char **source);
typedef bool (*HPMHOOK_post_status_read_scdb_libconfig_sub) (bool retVal___, struct config_setting_t *it, int idx, const char *source);
typedef bool (*HPMHOOK_pre_status_read_scdb_libconfig_sub_flag) (struct config_setting_t **it, int *type, const char **source);
typedef bool (*HPMHOOK_post_status_read_scdb_libconfig_sub_flag) (bool retVal___, struct config_setting_t *it, int type, const char *source);
typedef bool (*HPMHOOK_pre_status_read_scdb_libconfig_sub_flag_additional) (struct config_setting_t **it, int *type, const char **source);
typedef bool (*HPMHOOK_post_status_read_scdb_libconfig_sub_flag_additional) (bool retVal___, struct config_setting_t *it, int type, const char *source);
typedef void (*HPMHOOK_pre_status_read_job_db) (void);
typedef void (*HPMHOOK_post_status_read_job_db) (void);
typedef void (*HPMHOOK_pre_status_read_job_db_sub) (int *idx, const char **name, struct config_setting_t **jdb);
@@ -6456,8 +6456,14 @@ struct {
struct HPMHookPoint *HP_status_readdb_job2_post;
struct HPMHookPoint *HP_status_readdb_sizefix_pre;
struct HPMHookPoint *HP_status_readdb_sizefix_post;
struct HPMHookPoint *HP_status_readdb_scconfig_pre;
struct HPMHookPoint *HP_status_readdb_scconfig_post;
struct HPMHookPoint *HP_status_read_scdb_libconfig_pre;
struct HPMHookPoint *HP_status_read_scdb_libconfig_post;
struct HPMHookPoint *HP_status_read_scdb_libconfig_sub_pre;
struct HPMHookPoint *HP_status_read_scdb_libconfig_sub_post;
struct HPMHookPoint *HP_status_read_scdb_libconfig_sub_flag_pre;
struct HPMHookPoint *HP_status_read_scdb_libconfig_sub_flag_post;
struct HPMHookPoint *HP_status_read_scdb_libconfig_sub_flag_additional_pre;
struct HPMHookPoint *HP_status_read_scdb_libconfig_sub_flag_additional_post;
struct HPMHookPoint *HP_status_read_job_db_pre;
struct HPMHookPoint *HP_status_read_job_db_post;
struct HPMHookPoint *HP_status_read_job_db_sub_pre;
@@ -13227,8 +13233,14 @@ struct {
int HP_status_readdb_job2_post;
int HP_status_readdb_sizefix_pre;
int HP_status_readdb_sizefix_post;
int HP_status_readdb_scconfig_pre;
int HP_status_readdb_scconfig_post;
int HP_status_read_scdb_libconfig_pre;
int HP_status_read_scdb_libconfig_post;
int HP_status_read_scdb_libconfig_sub_pre;
int HP_status_read_scdb_libconfig_sub_post;
int HP_status_read_scdb_libconfig_sub_flag_pre;
int HP_status_read_scdb_libconfig_sub_flag_post;
int HP_status_read_scdb_libconfig_sub_flag_additional_pre;
int HP_status_read_scdb_libconfig_sub_flag_additional_post;
int HP_status_read_job_db_pre;
int HP_status_read_job_db_post;
int HP_status_read_job_db_sub_pre;
@@ -3300,7 +3300,10 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(status->natural_heal_timer, HP_status_natural_heal_timer) },
{ HP_POP(status->readdb_job2, HP_status_readdb_job2) },
{ HP_POP(status->readdb_sizefix, HP_status_readdb_sizefix) },
{ HP_POP(status->readdb_scconfig, HP_status_readdb_scconfig) },
{ HP_POP(status->read_scdb_libconfig, HP_status_read_scdb_libconfig) },
{ HP_POP(status->read_scdb_libconfig_sub, HP_status_read_scdb_libconfig_sub) },
{ HP_POP(status->read_scdb_libconfig_sub_flag, HP_status_read_scdb_libconfig_sub_flag) },
{ HP_POP(status->read_scdb_libconfig_sub_flag_additional, HP_status_read_scdb_libconfig_sub_flag_additional) },
{ HP_POP(status->read_job_db, HP_status_read_job_db) },
{ HP_POP(status->read_job_db_sub, HP_status_read_job_db_sub) },
{ HP_POP(status->set_sc, HP_status_set_sc) },
@@ -86386,29 +86386,110 @@ bool HP_status_readdb_sizefix(char *fields[], int columns, int current) {
}
return retVal___;
}
bool HP_status_readdb_scconfig(char *fields[], int columns, int current) {
bool HP_status_read_scdb_libconfig(void) {
int hIndex = 0;
bool retVal___ = false;
if (HPMHooks.count.HP_status_readdb_scconfig_pre > 0) {
bool (*preHookFunc) (char **fields[], int *columns, int *current);
if (HPMHooks.count.HP_status_read_scdb_libconfig_pre > 0) {
bool (*preHookFunc) (void);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_status_readdb_scconfig_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_status_readdb_scconfig_pre[hIndex].func;
retVal___ = preHookFunc(&fields, &columns, &current);
for (hIndex = 0; hIndex < HPMHooks.count.HP_status_read_scdb_libconfig_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_status_read_scdb_libconfig_pre[hIndex].func;
retVal___ = preHookFunc();
}
if (*HPMforce_return) {
*HPMforce_return = false;
return retVal___;
}
}
{
retVal___ = HPMHooks.source.status.readdb_scconfig(fields, columns, current);
retVal___ = HPMHooks.source.status.read_scdb_libconfig();
}
if (HPMHooks.count.HP_status_readdb_scconfig_post > 0) {
bool (*postHookFunc) (bool retVal___, char *fields[], int columns, int current);
for (hIndex = 0; hIndex < HPMHooks.count.HP_status_readdb_scconfig_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_status_readdb_scconfig_post[hIndex].func;
retVal___ = postHookFunc(retVal___, fields, columns, current);
if (HPMHooks.count.HP_status_read_scdb_libconfig_post > 0) {
bool (*postHookFunc) (bool retVal___);
for (hIndex = 0; hIndex < HPMHooks.count.HP_status_read_scdb_libconfig_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_status_read_scdb_libconfig_post[hIndex].func;
retVal___ = postHookFunc(retVal___);
}
}
return retVal___;
}
bool HP_status_read_scdb_libconfig_sub(struct config_setting_t *it, int idx, const char *source) {
int hIndex = 0;
bool retVal___ = false;
if (HPMHooks.count.HP_status_read_scdb_libconfig_sub_pre > 0) {
bool (*preHookFunc) (struct config_setting_t **it, int *idx, const char **source);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_status_read_scdb_libconfig_sub_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_status_read_scdb_libconfig_sub_pre[hIndex].func;
retVal___ = preHookFunc(&it, &idx, &source);
}
if (*HPMforce_return) {
*HPMforce_return = false;
return retVal___;
}
}
{
retVal___ = HPMHooks.source.status.read_scdb_libconfig_sub(it, idx, source);
}
if (HPMHooks.count.HP_status_read_scdb_libconfig_sub_post > 0) {
bool (*postHookFunc) (bool retVal___, struct config_setting_t *it, int idx, const char *source);
for (hIndex = 0; hIndex < HPMHooks.count.HP_status_read_scdb_libconfig_sub_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_status_read_scdb_libconfig_sub_post[hIndex].func;
retVal___ = postHookFunc(retVal___, it, idx, source);
}
}
return retVal___;
}
bool HP_status_read_scdb_libconfig_sub_flag(struct config_setting_t *it, int type, const char *source) {
int hIndex = 0;
bool retVal___ = false;
if (HPMHooks.count.HP_status_read_scdb_libconfig_sub_flag_pre > 0) {
bool (*preHookFunc) (struct config_setting_t **it, int *type, const char **source);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_status_read_scdb_libconfig_sub_flag_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_status_read_scdb_libconfig_sub_flag_pre[hIndex].func;
retVal___ = preHookFunc(&it, &type, &source);
}
if (*HPMforce_return) {
*HPMforce_return = false;
return retVal___;
}
}
{
retVal___ = HPMHooks.source.status.read_scdb_libconfig_sub_flag(it, type, source);
}
if (HPMHooks.count.HP_status_read_scdb_libconfig_sub_flag_post > 0) {
bool (*postHookFunc) (bool retVal___, struct config_setting_t *it, int type, const char *source);
for (hIndex = 0; hIndex < HPMHooks.count.HP_status_read_scdb_libconfig_sub_flag_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_status_read_scdb_libconfig_sub_flag_post[hIndex].func;
retVal___ = postHookFunc(retVal___, it, type, source);
}
}
return retVal___;
}
bool HP_status_read_scdb_libconfig_sub_flag_additional(struct config_setting_t *it, int type, const char *source) {
int hIndex = 0;
bool retVal___ = false;
if (HPMHooks.count.HP_status_read_scdb_libconfig_sub_flag_additional_pre > 0) {
bool (*preHookFunc) (struct config_setting_t **it, int *type, const char **source);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_status_read_scdb_libconfig_sub_flag_additional_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_status_read_scdb_libconfig_sub_flag_additional_pre[hIndex].func;
retVal___ = preHookFunc(&it, &type, &source);
}
if (*HPMforce_return) {
*HPMforce_return = false;
return retVal___;
}
}
{
retVal___ = HPMHooks.source.status.read_scdb_libconfig_sub_flag_additional(it, type, source);
}
if (HPMHooks.count.HP_status_read_scdb_libconfig_sub_flag_additional_post > 0) {
bool (*postHookFunc) (bool retVal___, struct config_setting_t *it, int type, const char *source);
for (hIndex = 0; hIndex < HPMHooks.count.HP_status_read_scdb_libconfig_sub_flag_additional_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_status_read_scdb_libconfig_sub_flag_additional_post[hIndex].func;
retVal___ = postHookFunc(retVal___, it, type, source);
}
}
return retVal___;

0 comments on commit 6dbabae

Please sign in to comment.
You can’t perform that action at this time.