Code Monkey home page Code Monkey logo

gdreplayformat's Introduction

Geometry Dash Replay Format

This format is pretty simple so this'll be the documentation until someone with more than a quarter of a brain fixes this up.

The Basics

  • GDReplayFormat is a macro format meant to work for ALL bots, which means all GDR files can be read and used by all bots
  • .gdr.json files are in JSON and .gdr are in msgpack.
  • Bot developers like you can add your own fields to GDR (like position data/frame fixes if you want) using the Extensions feature

Replay

std::string author; // author of the macro, most likely the GD username of the user
std::string description; // description of the macro, not necessary
float duration; // full macro duration time (Example: 64.729)
float gameVersion; // corresponding game version (Example: 2.204)
float version = 1.0; // GDR version (SHOULD NOT BE CHANGED)
float framerate = 240.f; // macro framerate (240 by default)
int seed = 0; // random trigger seed for the level, used to manipulate random triggers
int coins = 0; // amount of coins done by macro
bool ldm = false; // if the macro author used low detail mode to record
gdr::Bot botInfo; // Refer to Bot section
gdr::Level levelInfo; // Refer to Level section
std::vector<gdr::Input> inputs; // refer to Input section

Bot

std::string name; // name of the bot (SHOULD NOT BE SET MORE THAN ONCE)
std::string version; // version of the bot (SHOULD NOT BE SET MORE THAN ONCE)

Level

uint32_t id; // Level ID of the level being botted
std::string name; // Name of the level being botted

Input

uint32_t frame; // frame (time * framerate) of the input
int button; // PlayerButton of the input
bool player2; // if it is a player 2 input
bool down; // if it is a hold or release input

Adding to your project

Assuming you are using CPM as it is already in all Geode mods

Add CPM dependency (make sure it is added AFTER the add_subdirectory line and BEFORE the setup_geode_mod line)

CPMAddPackage("gh:maxnut/GDReplayFormat#commithash") # REPLACE commithash with a specific commit hash
target_link_libraries(${PROJECT_NAME} libGDR)

Add this to your geode mod and add your bot's name and version to the Replay

#include <gdr/gdr.hpp>

struct MyInput : gdr::Input {
    MyInput() = default;

    MyInput(int frame, int button, bool player2, bool down)
        : Input(frame, button, player2, down) {}   
};

struct MyMacro : gdr::Replay<MyMacro, MyInput> {
    MyMacro() : Replay("MyBot", "1.0") {}
};

Importing and Exporting

Using .gdr

Exporting

MyMacro macro;

std::ofstream f("path/to/macro.gdr", std::ios::binary);
auto data = macro.exportData(false);

f.write(reinterpret_cast<const char *>(data.data()), data.size());
f.close();

Importing

MyMacro macro;

std::ifstream f("path/to/macro.gdr", std::ios::binary);

f.seekg(0, std::ios::end);
size_t fileSize = f.tellg();
f.seekg(0, std::ios::beg);

std::vector<std::uint8_t> macroData(fileSize);

f.read(reinterpret_cast<char *>(macroData.data()), fileSize);
f.close();

macro = MyMacro::importData(macroData);

Using .gdr.json

Exporting

MyMacro macro;

std::ofstream f("path/to/macro.gdr.json", std::ios::binary);
auto data = macro.exportData(true);

f.write(reinterpret_cast<const char *>(data.data()), data.size());
f.close();

Importing

MyMacro macro;

std::ifstream f("path/to/macro.gdr.json", std::ios::binary);

f.seekg(0, std::ios::end);
size_t fileSize = f.tellg();
f.seekg(0, std::ios::beg);

std::vector<std::uint8_t> macroData(fileSize);

f.read(reinterpret_cast<char *>(macroData.data()), fileSize);
f.close();

macro = MyMacro::importData(macroData);

Extensions

The GDR Extensions system allows any bot to add it's own fields to a whole macro or the individual inputs in a macro for it's own use while still keeping GDR standardized and usable for every other bot that may use it. The most common use of this system is to add position and velocity data to inputs to allow frame corrections.

Adding your own extensions

Put simply, if you want to add X position to an input in my macros, you need to add it to your Input struct and add a way to save/parse it, like this:

struct MyInput : Input {
	float xpos;

	MyInput() = default;

	MyInput(int frame, int button, bool player2, bool down, float xpos)
		: Input(frame, button, player2, down), xpos(xpos) {}

	void parseExtension(gdr::json::object_t obj) override {
		xpos = obj["xpos"];
	}

	gdr::json::object_t saveExtension() const override {
		return { {"xpos", xpos} };
	}
};

Now, if you wanted to add a field (for this example, we will use Attempts) to your whole macro, the process would be very similar:

struct MyReplay : Replay<MyReplay, MyInput> {
	int attempts;

	MyReplay() : Replay("TestBot", "1.0") {}

	void parseExtension(gdr::json::object_t obj) override {
		attempts = obj["attempts"];
	}

	gdr::json::object_t saveExtension() const override {
		return { {"attempts", attempts} };
	}
};

These extensions can be accessed the same way you access regular fields

Bots using GDR

Credits

maxnut: For starting the whole repo and format in the first place and being the biggest contributor

camila314: For fixing up most of the format and doing the testing i think

ninXout: For writing this "documentation" you are seeing here (also open for dms on discord at @ninxout if you have questions about gdr)

Absolute, fig, decks, CattoDev, kepe, and mat: For being supportive of this idea, and willing to put the format in their own bots immediately.

gdreplayformat's People

Contributors

maxnut avatar ninxout avatar camila314 avatar firemario211 avatar

Stargazers

Flainn avatar Armando Hinojosa avatar  avatar Midair avatar  avatar SpaghettDev avatar

Watchers

Absolute avatar mat avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.