mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-13 22:08:34 +00:00
Cheat support... Somewhat.
This commit is contained in:
parent
66464c2cce
commit
abd7bab43a
36
cheats.c
36
cheats.c
@ -219,9 +219,43 @@ void cheat_manager_free(cheat_manager_t *handle)
|
||||
free(handle);
|
||||
}
|
||||
|
||||
static void cheat_manager_update(cheat_manager_t *handle)
|
||||
{
|
||||
msg_queue_clear(g_extern.msg_queue);
|
||||
char msg[256];
|
||||
snprintf(msg, sizeof(msg), "Cheat: #%u [%s]: %s", handle->ptr, handle->cheats[handle->ptr].state ? "ON" : "OFF", handle->cheats[handle->ptr].desc);
|
||||
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
|
||||
SSNES_LOG("%s\n", msg);
|
||||
}
|
||||
|
||||
void cheat_manager_toggle(cheat_manager_t *handle)
|
||||
{
|
||||
handle->cheats[handle->ptr].state ^= true;
|
||||
psnes_cheat_set(handle->ptr, handle->cheats[handle->ptr].state, handle->cheats[handle->ptr].code);
|
||||
|
||||
unsigned index = 0;
|
||||
psnes_cheat_reset();
|
||||
for (unsigned i = 0; i < handle->size; i++)
|
||||
{
|
||||
if (handle->cheats[handle->ptr].state)
|
||||
psnes_cheat_set(index++, true, handle->cheats[handle->ptr].code);
|
||||
}
|
||||
|
||||
cheat_manager_update(handle);
|
||||
}
|
||||
|
||||
void cheat_manager_index_next(cheat_manager_t *handle)
|
||||
{
|
||||
handle->ptr = (handle->ptr + 1) % handle->size;
|
||||
cheat_manager_update(handle);
|
||||
}
|
||||
|
||||
void cheat_manager_index_prev(cheat_manager_t *handle)
|
||||
{
|
||||
if (handle->ptr == 0)
|
||||
handle->ptr = handle->size - 1;
|
||||
else
|
||||
handle->ptr--;
|
||||
|
||||
cheat_manager_update(handle);
|
||||
}
|
||||
|
||||
|
3
cheats.h
3
cheats.h
@ -23,7 +23,8 @@ typedef struct cheat_manager cheat_manager_t;
|
||||
cheat_manager_t* cheat_manager_new(const char *path);
|
||||
void cheat_manager_free(cheat_manager_t *handle);
|
||||
|
||||
void cheat_manager_index_offset(cheat_manager_t *handle, int offset);
|
||||
void cheat_manager_index_next(cheat_manager_t *handle);
|
||||
void cheat_manager_index_prev(cheat_manager_t *handle);
|
||||
void cheat_manager_toggle(cheat_manager_t *handle);
|
||||
|
||||
#endif
|
||||
|
@ -223,6 +223,9 @@ static const struct snes_keybind snes_keybinds_1[] = {
|
||||
{ SSNES_RESET, SDLK_h, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_SHADER_NEXT, SDLK_m, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_SHADER_PREV, SDLK_n, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_CHEAT_INDEX_PLUS, SDLK_y, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_CHEAT_INDEX_MINUS, SDLK_t, NO_BTN, AXIS_NONE },
|
||||
{ SSNES_CHEAT_TOGGLE, SDLK_u, NO_BTN, AXIS_NONE },
|
||||
{ -1 }
|
||||
};
|
||||
|
||||
|
30
ssnes.c
30
ssnes.c
@ -1192,7 +1192,7 @@ static void check_reset(void)
|
||||
static void check_shader_dir(void)
|
||||
{
|
||||
static bool old_pressed_next = false;
|
||||
static bool old_pressed_prev = true;
|
||||
static bool old_pressed_prev = false;
|
||||
|
||||
if (!g_extern.shader_dir.elems || !driver.video->xml_shader)
|
||||
return;
|
||||
@ -1235,6 +1235,31 @@ static void check_shader_dir(void)
|
||||
old_pressed_prev = pressed_prev;
|
||||
|
||||
}
|
||||
|
||||
static void check_cheats(void)
|
||||
{
|
||||
if (!g_extern.cheat)
|
||||
return;
|
||||
|
||||
static bool old_pressed_prev = false;
|
||||
static bool old_pressed_next = false;
|
||||
static bool old_pressed_toggle = false;
|
||||
|
||||
bool pressed_next = driver.input->key_pressed(driver.input_data, SSNES_CHEAT_INDEX_PLUS);
|
||||
bool pressed_prev = driver.input->key_pressed(driver.input_data, SSNES_CHEAT_INDEX_MINUS);
|
||||
bool pressed_toggle = driver.input->key_pressed(driver.input_data, SSNES_CHEAT_TOGGLE);
|
||||
|
||||
if (pressed_next && !old_pressed_next)
|
||||
cheat_manager_index_next(g_extern.cheat);
|
||||
else if (pressed_prev && !old_pressed_prev)
|
||||
cheat_manager_index_prev(g_extern.cheat);
|
||||
else if (pressed_toggle && !old_pressed_toggle)
|
||||
cheat_manager_toggle(g_extern.cheat);
|
||||
|
||||
old_pressed_prev = pressed_prev;
|
||||
old_pressed_next = pressed_next;
|
||||
old_pressed_toggle = pressed_toggle;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void do_state_checks(void)
|
||||
@ -1242,6 +1267,9 @@ static void do_state_checks(void)
|
||||
if (!g_extern.netplay)
|
||||
{
|
||||
check_reset();
|
||||
#ifdef HAVE_XML
|
||||
check_cheats();
|
||||
#endif
|
||||
check_pause();
|
||||
if (g_extern.is_paused)
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user