mirror of
https://github.com/libretro/RetroArch
synced 2025-04-11 00:44:20 +00:00
People don't like ioctl functions - so here goes
This commit is contained in:
parent
271a4a41ba
commit
42019bd02f
2
cheats.c
2
cheats.c
@ -99,7 +99,7 @@ void cheat_manager_apply_cheats(void)
|
|||||||
|
|
||||||
#ifdef HAVE_CHEEVOS
|
#ifdef HAVE_CHEEVOS
|
||||||
data_bool = idx != 0;
|
data_bool = idx != 0;
|
||||||
cheevos_ctl(CHEEVOS_CTL_APPLY_CHEATS, &data_bool);
|
cheevos_apply_cheats(&data_bool);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
179
cheevos.c
179
cheevos.c
@ -240,6 +240,9 @@ static cheevos_locals_t cheevos_locals =
|
|||||||
{0},
|
{0},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int cheats_are_enabled = 0;
|
||||||
|
static int cheats_were_enabled = 0;
|
||||||
|
|
||||||
/* forward declaration */
|
/* forward declaration */
|
||||||
|
|
||||||
int rarch_main_async_job_add(async_task_t task, void *payload);
|
int rarch_main_async_job_add(async_task_t task, void *payload);
|
||||||
@ -953,7 +956,7 @@ static int cheevos_parse(const char *json)
|
|||||||
|
|
||||||
if (jsonsax_parse(json, &handlers, (void*)&ud) != JSONSAX_OK)
|
if (jsonsax_parse(json, &handlers, (void*)&ud) != JSONSAX_OK)
|
||||||
{
|
{
|
||||||
cheevos_ctl(CHEEVOS_CTL_UNLOAD, NULL);
|
cheevos_unload();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1917,8 +1920,7 @@ static unsigned cheevos_find_game_id_nes(
|
|||||||
return cheevos_get_game_id(hash, &to);
|
return cheevos_get_game_id(hash, &to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cheevos_load(const void *data)
|
||||||
static bool cheevos_load(const void *data)
|
|
||||||
{
|
{
|
||||||
retro_ctx_memory_info_t mem_info;
|
retro_ctx_memory_info_t mem_info;
|
||||||
|
|
||||||
@ -2100,9 +2102,9 @@ static bool cheevos_load(const void *data)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_MENU
|
void cheevos_populate_menu(void *data)
|
||||||
static void cheevos_populate_menu(void *data)
|
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_MENU
|
||||||
unsigned i;
|
unsigned i;
|
||||||
const cheevo_t *end = NULL;
|
const cheevo_t *end = NULL;
|
||||||
cheevo_t *cheevo = NULL;
|
cheevo_t *cheevo = NULL;
|
||||||
@ -2165,97 +2167,92 @@ static void cheevos_populate_menu(void *data)
|
|||||||
cheevo->description, MENU_SETTINGS_CHEEVOS_START + i, 0, 0);
|
cheevo->description, MENU_SETTINGS_CHEEVOS_START + i, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
bool cheevos_ctl(enum cheevos_ctl_state state, void *data)
|
bool cheevos_get_description(cheevos_ctx_desc_t *desc)
|
||||||
{
|
{
|
||||||
static int cheats_are_enabled = 0;
|
cheevo_t *cheevos = cheevos_locals.core.cheevos;
|
||||||
static int cheats_were_enabled = 0;
|
|
||||||
settings_t *settings = config_get_ptr();
|
|
||||||
|
|
||||||
switch (state)
|
if (desc->idx >= cheevos_locals.core.count)
|
||||||
{
|
{
|
||||||
case CHEEVOS_CTL_GET_DESCRIPTION:
|
cheevos = cheevos_locals.unofficial.cheevos;
|
||||||
{
|
desc->idx -= cheevos_locals.unofficial.count;
|
||||||
cheevos_ctx_desc_t *desc = (cheevos_ctx_desc_t*)data;
|
|
||||||
cheevo_t *cheevos = cheevos_locals.core.cheevos;
|
|
||||||
|
|
||||||
if (desc->idx >= cheevos_locals.core.count)
|
|
||||||
{
|
|
||||||
cheevos = cheevos_locals.unofficial.cheevos;
|
|
||||||
desc->idx -= cheevos_locals.unofficial.count;
|
|
||||||
}
|
|
||||||
|
|
||||||
strncpy(desc->s, cheevos[desc->idx].description, desc->len);
|
|
||||||
desc->s[desc->len - 1] = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CHEEVOS_CTL_APPLY_CHEATS:
|
|
||||||
{
|
|
||||||
bool *data_bool = (bool*)data;
|
|
||||||
cheats_are_enabled = *data_bool;
|
|
||||||
cheats_were_enabled |= cheats_are_enabled;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CHEEVOS_CTL_LOAD:
|
|
||||||
if (!cheevos_load((const void*)data))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
break;
|
|
||||||
case CHEEVOS_CTL_UNLOAD:
|
|
||||||
if (!cheevos_locals.loaded)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
cheevos_free_cheevo_set(&cheevos_locals.core);
|
|
||||||
cheevos_free_cheevo_set(&cheevos_locals.unofficial);
|
|
||||||
|
|
||||||
cheevos_locals.loaded = 0;
|
|
||||||
break;
|
|
||||||
case CHEEVOS_CTL_TOGGLE_HARDCORE_MODE:
|
|
||||||
/* reset and deinit rewind to avoid cheat the score */
|
|
||||||
if (settings->cheevos.hardcore_mode_enable)
|
|
||||||
{
|
|
||||||
/* send reset core cmd to avoid any user savestate previusly loaded */
|
|
||||||
event_cmd_ctl(EVENT_CMD_RESET, NULL);
|
|
||||||
if (settings->rewind_enable)
|
|
||||||
event_cmd_ctl(EVENT_CMD_REWIND_DEINIT, NULL);
|
|
||||||
|
|
||||||
RARCH_LOG("%s\n", msg_hash_to_str(MSG_CHEEVOS_HARDCORE_MODE_ENABLE));
|
|
||||||
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEEVOS_HARDCORE_MODE_ENABLE), 0, 3 * 60, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (settings->rewind_enable)
|
|
||||||
event_cmd_ctl(EVENT_CMD_REWIND_INIT, NULL);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CHEEVOS_CTL_TEST:
|
|
||||||
if (!cheevos_locals.loaded)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!cheats_are_enabled && !cheats_were_enabled)
|
|
||||||
{
|
|
||||||
if (!settings->cheevos.enable)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
cheevos_test_cheevo_set(&cheevos_locals.core);
|
|
||||||
|
|
||||||
if (settings->cheevos.test_unofficial)
|
|
||||||
cheevos_test_cheevo_set(&cheevos_locals.unofficial);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CHEEVOS_CTL_POPULATE_MENU:
|
|
||||||
#ifdef HAVE_MENU
|
|
||||||
cheevos_populate_menu(data);
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
case CHEEVOS_CTL_SET_CHEATS:
|
|
||||||
cheats_were_enabled = cheats_are_enabled;
|
|
||||||
break;
|
|
||||||
case CHEEVOS_CTL_NONE:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strncpy(desc->s, cheevos[desc->idx].description, desc->len);
|
||||||
|
desc->s[desc->len - 1] = 0;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cheevos_apply_cheats(bool *data_bool)
|
||||||
|
{
|
||||||
|
cheats_are_enabled = *data_bool;
|
||||||
|
cheats_were_enabled |= cheats_are_enabled;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cheevos_unload(void)
|
||||||
|
{
|
||||||
|
if (!cheevos_locals.loaded)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
cheevos_free_cheevo_set(&cheevos_locals.core);
|
||||||
|
cheevos_free_cheevo_set(&cheevos_locals.unofficial);
|
||||||
|
|
||||||
|
cheevos_locals.loaded = 0;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cheevos_toggle_hardcore_mode(void)
|
||||||
|
{
|
||||||
|
settings_t *settings = config_get_ptr();
|
||||||
|
/* reset and deinit rewind to avoid cheat the score */
|
||||||
|
if (settings->cheevos.hardcore_mode_enable)
|
||||||
|
{
|
||||||
|
/* send reset core cmd to avoid any user savestate previusly loaded */
|
||||||
|
event_cmd_ctl(EVENT_CMD_RESET, NULL);
|
||||||
|
if (settings->rewind_enable)
|
||||||
|
event_cmd_ctl(EVENT_CMD_REWIND_DEINIT, NULL);
|
||||||
|
|
||||||
|
RARCH_LOG("%s\n", msg_hash_to_str(MSG_CHEEVOS_HARDCORE_MODE_ENABLE));
|
||||||
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEEVOS_HARDCORE_MODE_ENABLE), 0, 3 * 60, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (settings->rewind_enable)
|
||||||
|
event_cmd_ctl(EVENT_CMD_REWIND_INIT, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cheevos_test(void)
|
||||||
|
{
|
||||||
|
settings_t *settings = config_get_ptr();
|
||||||
|
if (!cheevos_locals.loaded)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!cheats_are_enabled && !cheats_were_enabled)
|
||||||
|
{
|
||||||
|
if (!settings->cheevos.enable)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
cheevos_test_cheevo_set(&cheevos_locals.core);
|
||||||
|
|
||||||
|
if (settings->cheevos.test_unofficial)
|
||||||
|
cheevos_test_cheevo_set(&cheevos_locals.unofficial);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cheevos_set_cheats(void)
|
||||||
|
{
|
||||||
|
cheats_were_enabled = cheats_are_enabled;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
39
cheevos.h
39
cheevos.h
@ -19,29 +19,6 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
enum cheevos_ctl_state
|
|
||||||
{
|
|
||||||
CHEEVOS_CTL_NONE = 0,
|
|
||||||
CHEEVOS_CTL_TEST,
|
|
||||||
CHEEVOS_CTL_LOAD,
|
|
||||||
|
|
||||||
CHEEVOS_CTL_APPLY_CHEATS,
|
|
||||||
|
|
||||||
/* Unload the achievements from memory. */
|
|
||||||
CHEEVOS_CTL_UNLOAD,
|
|
||||||
|
|
||||||
/* Toggle Hardcore Mode */
|
|
||||||
CHEEVOS_CTL_TOGGLE_HARDCORE_MODE,
|
|
||||||
|
|
||||||
/* Load the achievements into memory if
|
|
||||||
* the game has content. */
|
|
||||||
CHEEVOS_CTL_SET_CHEATS,
|
|
||||||
|
|
||||||
CHEEVOS_CTL_GET_DESCRIPTION,
|
|
||||||
|
|
||||||
CHEEVOS_CTL_POPULATE_MENU
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct cheevos_ctx_desc
|
typedef struct cheevos_ctx_desc
|
||||||
{
|
{
|
||||||
unsigned idx;
|
unsigned idx;
|
||||||
@ -49,6 +26,20 @@ typedef struct cheevos_ctx_desc
|
|||||||
size_t len;
|
size_t len;
|
||||||
} cheevos_ctx_desc_t;
|
} cheevos_ctx_desc_t;
|
||||||
|
|
||||||
bool cheevos_ctl(enum cheevos_ctl_state state, void *data);
|
bool cheevos_load(const void *data);
|
||||||
|
|
||||||
|
void cheevos_populate_menu(void *data);
|
||||||
|
|
||||||
|
bool cheevos_get_description(cheevos_ctx_desc_t *desc);
|
||||||
|
|
||||||
|
bool cheevos_apply_cheats(bool *data_bool);
|
||||||
|
|
||||||
|
bool cheevos_unload(void);
|
||||||
|
|
||||||
|
bool cheevos_toggle_hardcore_mode(void);
|
||||||
|
|
||||||
|
bool cheevos_test(void);
|
||||||
|
|
||||||
|
bool cheevos_set_cheats(void);
|
||||||
|
|
||||||
#endif /* __RARCH_CHEEVOS_H */
|
#endif /* __RARCH_CHEEVOS_H */
|
||||||
|
@ -396,7 +396,7 @@ static void event_init_controllers(void)
|
|||||||
static void event_deinit_core(bool reinit)
|
static void event_deinit_core(bool reinit)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_CHEEVOS
|
#ifdef HAVE_CHEEVOS
|
||||||
cheevos_ctl(CHEEVOS_CTL_UNLOAD, NULL);
|
cheevos_unload();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
core_ctl(CORE_CTL_RETRO_UNLOAD_GAME, NULL);
|
core_ctl(CORE_CTL_RETRO_UNLOAD_GAME, NULL);
|
||||||
@ -1089,7 +1089,7 @@ bool event_cmd_ctl(enum event_command cmd, void *data)
|
|||||||
runloop_msg_queue_push(msg_hash_to_str(MSG_RESET), 1, 120, true);
|
runloop_msg_queue_push(msg_hash_to_str(MSG_RESET), 1, 120, true);
|
||||||
|
|
||||||
#ifdef HAVE_CHEEVOS
|
#ifdef HAVE_CHEEVOS
|
||||||
cheevos_ctl(CHEEVOS_CTL_SET_CHEATS, NULL);
|
cheevos_set_cheats();
|
||||||
#endif
|
#endif
|
||||||
core_ctl(CORE_CTL_RETRO_RESET, NULL);
|
core_ctl(CORE_CTL_RETRO_RESET, NULL);
|
||||||
break;
|
break;
|
||||||
@ -1125,7 +1125,7 @@ bool event_cmd_ctl(enum event_command cmd, void *data)
|
|||||||
break;
|
break;
|
||||||
case EVENT_CMD_CHEEVOS_HARDCORE_MODE_TOGGLE:
|
case EVENT_CMD_CHEEVOS_HARDCORE_MODE_TOGGLE:
|
||||||
#ifdef HAVE_CHEEVOS
|
#ifdef HAVE_CHEEVOS
|
||||||
cheevos_ctl(CHEEVOS_CTL_TOGGLE_HARDCORE_MODE, NULL);
|
cheevos_toggle_hardcore_mode();
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case EVENT_CMD_REINIT:
|
case EVENT_CMD_REINIT:
|
||||||
|
@ -1441,11 +1441,11 @@ static bool load_content(
|
|||||||
{
|
{
|
||||||
const void *load_data = NULL;
|
const void *load_data = NULL;
|
||||||
|
|
||||||
cheevos_ctl(CHEEVOS_CTL_SET_CHEATS, NULL);
|
cheevos_set_cheats();
|
||||||
|
|
||||||
if (*content->elems[0].data)
|
if (*content->elems[0].data)
|
||||||
load_data = info;
|
load_data = info;
|
||||||
cheevos_ctl(CHEEVOS_CTL_LOAD, (void*)load_data);
|
cheevos_load(load_data);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ static int action_iterate_help(menu_handle_t *menu,
|
|||||||
desc_info.idx = menu->help_screen_id;
|
desc_info.idx = menu->help_screen_id;
|
||||||
desc_info.s = s;
|
desc_info.s = s;
|
||||||
desc_info.len = len;
|
desc_info.len = len;
|
||||||
cheevos_ctl(CHEEVOS_CTL_GET_DESCRIPTION, &desc_info);
|
cheevos_get_description(&desc_info);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -3836,7 +3836,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
|
|||||||
|
|
||||||
#ifdef HAVE_CHEEVOS
|
#ifdef HAVE_CHEEVOS
|
||||||
case DISPLAYLIST_ACHIEVEMENT_LIST:
|
case DISPLAYLIST_ACHIEVEMENT_LIST:
|
||||||
cheevos_ctl(CHEEVOS_CTL_POPULATE_MENU, info);
|
cheevos_populate_menu(info);
|
||||||
info->need_push = true;
|
info->need_push = true;
|
||||||
info->need_refresh = true;
|
info->need_refresh = true;
|
||||||
break;
|
break;
|
||||||
|
@ -1465,7 +1465,7 @@ int runloop_iterate(unsigned *sleep_ms)
|
|||||||
core_ctl(CORE_CTL_RETRO_RUN, NULL);
|
core_ctl(CORE_CTL_RETRO_RUN, NULL);
|
||||||
|
|
||||||
#ifdef HAVE_CHEEVOS
|
#ifdef HAVE_CHEEVOS
|
||||||
cheevos_ctl(CHEEVOS_CTL_TEST, NULL);
|
cheevos_test();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < settings->input.max_users; i++)
|
for (i = 0; i < settings->input.max_users; i++)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user