Rewrite cheat code

This commit is contained in:
twinaphex 2015-12-01 03:00:31 +01:00
parent 39b8971fae
commit dbb3d8f770
3 changed files with 21 additions and 18 deletions

View File

@ -169,24 +169,25 @@ bool cheat_manager_save(const char *path)
return ret;
}
cheat_manager_t *cheat_manager_load(const char *path)
bool cheat_manager_load(const char *path)
{
unsigned cheats = 0, i;
cheat_manager_t *cheat = NULL;
config_file_t *conf = config_file_new(path);
cheat_manager_t *cheat;
config_file_t *conf = config_file_new(path);
global_t *global = global_get_ptr();
if (!conf)
return NULL;
return false;
config_get_uint(conf, "cheats", &cheats);
if (cheats == 0)
return NULL;
return false;
cheat = cheat_manager_new(cheats);
if (!cheat)
return NULL;
return false;
for (i = 0; i < cheats; i++)
{
@ -217,7 +218,9 @@ cheat_manager_t *cheat_manager_load(const char *path)
config_file_free(conf);
return cheat;
global->cheat = cheat;
return true;
}
cheat_manager_t *cheat_manager_new(unsigned size)
@ -288,8 +291,10 @@ bool cheat_manager_realloc(unsigned new_size)
return true;
}
void cheat_manager_free(cheat_manager_t *handle)
void cheat_manager_free(void)
{
global_t *global = global_get_ptr();
cheat_manager_t *handle = global->cheat;
if (!handle)
return;
@ -409,9 +414,10 @@ void cheat_manager_state_checks(
void cheat_manager_state_free(void)
{
global_t *global = global_get_ptr();
global_t *global;
cheat_manager_free();
global = global_get_ptr();
if (global->cheat)
cheat_manager_free(global->cheat);
global->cheat = NULL;
}

View File

@ -29,7 +29,7 @@ unsigned cheat_manager_get_size(void);
cheat_manager_t *cheat_manager_new(unsigned size);
cheat_manager_t *cheat_manager_load(const char *path);
bool cheat_manager_load(const char *path);
/**
* cheat_manager_save:
@ -45,7 +45,7 @@ bool cheat_manager_realloc(unsigned new_size);
void cheat_manager_set_code(unsigned index, const char *str);
void cheat_manager_free(cheat_manager_t *handle);
void cheat_manager_free(void);
void cheat_manager_index_next(cheat_manager_t *handle);

View File

@ -713,12 +713,9 @@ static int generic_action_ok(const char *path,
}
break;
case ACTION_OK_LOAD_CHEAT_FILE:
if (global->cheat)
cheat_manager_free(global->cheat);
cheat_manager_free();
global->cheat = cheat_manager_load(action_path);
if (!global->cheat)
if (!cheat_manager_load(action_path))
goto error;
break;
case ACTION_OK_APPEND_DISK_IMAGE: