Start adding cheat_manager_load function
This commit is contained in:
parent
ecb5b08432
commit
cf66692b21
54
cheats.c
54
cheats.c
|
@ -16,6 +16,8 @@
|
||||||
#include "cheats.h"
|
#include "cheats.h"
|
||||||
#include "general.h"
|
#include "general.h"
|
||||||
#include "dynamic.h"
|
#include "dynamic.h"
|
||||||
|
#include <file/config_file.h>
|
||||||
|
#include <file/config_file_macros.h>
|
||||||
#include <compat/strl.h>
|
#include <compat/strl.h>
|
||||||
#include <compat/posix_string.h>
|
#include <compat/posix_string.h>
|
||||||
|
|
||||||
|
@ -40,7 +42,55 @@ void cheat_manager_apply_cheats(cheat_manager_t *handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cheat_manager_t *cheat_manager_new(void)
|
cheat_manager_t *cheat_manager_load(const char *path)
|
||||||
|
{
|
||||||
|
unsigned cheats = 0, i;
|
||||||
|
cheat_manager_t *cheat = NULL;
|
||||||
|
config_file_t *conf = config_file_new(path);
|
||||||
|
|
||||||
|
if (!conf)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
config_get_uint(conf, "cheats", &cheats);
|
||||||
|
|
||||||
|
if (cheats == 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
cheat = cheat_manager_new(cheats);
|
||||||
|
|
||||||
|
if (!cheat)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < cheats; i++)
|
||||||
|
{
|
||||||
|
char key[64];
|
||||||
|
char desc_key[256];
|
||||||
|
char code_key[256];
|
||||||
|
char enable_key[256];
|
||||||
|
char *tmp = NULL;
|
||||||
|
bool tmp_bool;
|
||||||
|
|
||||||
|
snprintf(key, sizeof(key), "cheat%u", i);
|
||||||
|
snprintf(desc_key, sizeof(desc_key), "cheat%u_desc", i);
|
||||||
|
snprintf(code_key, sizeof(code_key), "cheat%u_code", i);
|
||||||
|
snprintf(enable_key, sizeof(enable_key), "cheat%u_enable", i);
|
||||||
|
|
||||||
|
if (config_get_string(conf, desc_key, &tmp))
|
||||||
|
cheat->cheats[i].desc = strdup(tmp);
|
||||||
|
|
||||||
|
if (config_get_string(conf, code_key, &tmp))
|
||||||
|
cheat->cheats[i].code = strdup(tmp);
|
||||||
|
|
||||||
|
if (config_get_bool(conf, enable_key, &tmp_bool))
|
||||||
|
cheat->cheats[i].state = tmp_bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
config_file_free(conf);
|
||||||
|
|
||||||
|
return cheat;
|
||||||
|
}
|
||||||
|
|
||||||
|
cheat_manager_t *cheat_manager_new(unsigned size)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
cheat_manager_t *handle = NULL;
|
cheat_manager_t *handle = NULL;
|
||||||
|
@ -48,7 +98,7 @@ cheat_manager_t *cheat_manager_new(void)
|
||||||
if (!handle)
|
if (!handle)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
handle->buf_size = handle->size = 0;
|
handle->buf_size = handle->size = size;
|
||||||
handle->cheats = (struct item_cheat*)
|
handle->cheats = (struct item_cheat*)
|
||||||
calloc(handle->buf_size, sizeof(struct item_cheat));
|
calloc(handle->buf_size, sizeof(struct item_cheat));
|
||||||
|
|
||||||
|
|
4
cheats.h
4
cheats.h
|
@ -39,7 +39,9 @@ struct cheat_manager
|
||||||
|
|
||||||
typedef struct cheat_manager cheat_manager_t;
|
typedef struct cheat_manager cheat_manager_t;
|
||||||
|
|
||||||
cheat_manager_t *cheat_manager_new(void);
|
cheat_manager_t *cheat_manager_new(unsigned size);
|
||||||
|
|
||||||
|
cheat_manager_t *cheat_manager_load(const char *path);
|
||||||
|
|
||||||
bool cheat_manager_realloc(cheat_manager_t *handle, unsigned new_size);
|
bool cheat_manager_realloc(cheat_manager_t *handle, unsigned new_size);
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ void *menu_init(const void *data)
|
||||||
#ifdef HAVE_SHADER_MANAGER
|
#ifdef HAVE_SHADER_MANAGER
|
||||||
menu->shader = (struct gfx_shader*)calloc(1, sizeof(struct gfx_shader));
|
menu->shader = (struct gfx_shader*)calloc(1, sizeof(struct gfx_shader));
|
||||||
#endif
|
#endif
|
||||||
menu->cheats = cheat_manager_new();
|
menu->cheats = cheat_manager_new(0);
|
||||||
menu->push_start_screen = g_settings.menu_show_start_screen;
|
menu->push_start_screen = g_settings.menu_show_start_screen;
|
||||||
g_settings.menu_show_start_screen = false;
|
g_settings.menu_show_start_screen = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue