Skip to content

KiliLoje/logic-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logic Parser for RetroAchievement

RetroAchievement implements its achievement system through RAIntegration
It uses a string encoding to store the logic for an achievement.
I highly recommend that you check the RetroAchievement Dev Docs before using this parser.

How to Use

  • main.c is only used for printing logic as readable data to the terminal. Unless that's what you want to do, do not add this file your project.

  • achievement.h is where the achievement structs and enums are stored. It is included by parser.h so you have to download it.

  • parser.h and parser.c is where the main logic for the parsing resides.

Add the following line to any C-based script to gain access to the parsing functions.

#include "path/to/achievement.h"

Then you can use get_achievement(char *achievement, size_t len) to get the whole achievement parsed.
It returns an object of type struct ACHIEVEMENT *

Parsing Structure

  • NUMERAL is a hand side of any comparison or operation, it has a type, a size, and a value.
    Since RAIntegration is a 32-bit DLL, the internal accumulator is 32-bit, so a numeral's value cannot go beyond that.
struct NUMERAL
{
  Type type;
  Size size;
  int32_t value;
};

  • CONDITION represents any line of logic, with a left and right hand side. It can either represents a comparison or an operation.
    Each condition is indexed following a 1 based indexation
struct CONDITION
{
  int id;
  Flag flag;
  Operator op; // either an operator or a comparator, such as '=' or '+'
  int hit_target

  struct NUMERAL lhs;
  struct NUMERAL rhs;
};

  • GROUP represents a set of CONDITION. Each achievement must have a Core group (represented here by a GROUP where GROUP.id == 0) and an arbitrary number of Alt Groups.

Note

Any achievement is unlocked when every condition in its Core Group AND in at least one Alt Group is true

struct GROUP
{
  int id;
  size_t condition_count;
  struct CONDITION *conditions[];
};

  • ACHIEVEMENT represents a set of GROUP. Each of them has an id, title, and description which are currently not supported.
struct ACHIEVEMENT
{
  int id;
  char *title;
  char *description;

  size_t group_count;
<<<<<<< HEAD
  struct GROUP *groups;
};

  • LEADERBOARD represents an array of 4 ACHIEVEMENT called respectively START, CANCEL, SUBMIT and VALUE

Note

Each of these aren't technically achievements, but they can be represented as is
when START is true, the leaderboard start a new entry
when CANCEL is true, the leaderboard cancel any on going entries
when SUBMIT is true, the leaderboard submit the entry to retroachievements
VALUE is the part that require the format. It doesn't act like a regular achievement, as it isn't true or false. It is just measuring a value.

struct LEADERBOARD
{
  int id;
  char *title;
  char *description;
  Format format;
  int lower_is_better;

  struct ACHIEVEMENT *start;
  struct ACHIEVEMENT *cancel;
  struct ACHIEVEMENT *submit;
  struct ACHIEVEMENT *value;
};

About

logic parser in C for retroachievement

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages