RobLoach / RobLoach/SDL_libretro

Load RetroArch-format cheat files (.cht)

Open
#166 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C
Stars
2
Forks
0
Avg merge
16h 55m
Merged PRs (30d)
12

Description

The cheat API is currently raw-only: SDL_Libretro_SetCheat() / SDL_Libretro_ResetCheats() (include/SDL_libretro.h:266-267) forward directly to retro_cheat_set / retro_cheat_reset, so every application must parse cheat databases itself. The de-facto ecosystem format is RetroArch's .cht INI-style file (cheat0_desc, cheat0_code, cheat0_enable, cheats = N), and the repo already vendors an INI parser (include/SDL_ini.h) used by the config system.

Suggested Implementation

bool SDL_Libretro_LoadCheats(SDL_Libretro* lr, const char* path);
bool SDL_Libretro_LoadCheats_IO(SDL_Libretro* lr, SDL_IOStream* src, bool closeio);
unsigned SDL_Libretro_GetCheatCount(const SDL_Libretro* lr);
bool SDL_Libretro_GetCheat(const SDL_Libretro* lr, unsigned index, const char** desc, const char** code, bool* enabled);
bool SDL_Libretro_SetCheatEnabled(SDL_Libretro* lr, unsigned index, bool enabled);
  • Parse with SDL_ini.h (cheats = N, then cheatN_desc / cheatN_code / cheatN_enable keys); store a deep-copied cheat list on the context so cheats can be listed and toggled after load (the menu system #129 would surface this list).
  • On load and on toggle, replay the enabled set to the core via the existing SetCheat path; clear the list in ResetCheats and on game unload.
  • Optionally auto-load <content>.cht from the save directory via SDL_Libretro_GetSavePath() when a game loads, mirroring how SRAM auto-restore works.

QA

  • Unit tests: parse a sample .cht (including quoted values and a disabled entry), assert count/desc/code/enabled round-trip, assert the test core (test/test_core.c) received retro_cheat_set calls for enabled cheats only, and toggling replays correctly.
  • Malformed file returns false with an SDL error and leaves prior cheats untouched.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with include/SDL_libretro.h and the existing SDL_Libretro_SetCheat(), ResetCheats(), and game-unload paths, then read include/SDL_ini.h for the parser API. Inspect test/test_core.c and run the existing tests before adding coverage for quoted values, disabled entries, malformed files, and replayed toggles. Done means the listed APIs preserve cheats, apply enabled entries to the core, and leave prior state intact on load failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.