Giter Club home page Giter Club logo

celestemagictimer's Introduction

rhelmot's Celeste Magic Timer

This is an autosplitter for Celeste on Linux, working on all versions and also with Everest installed. I guess it could theoretically be made to work on other games but why would you do that?

This is a complicated piece of software! I am more than happy to help anyone who wants to use this learn this. There's a lot you can do with this program once you really know what you're doing.

The Tracer

The first component of the setup is the tracer. This is a program which reads Celeste's memory and dumps out information about the game state to a file, by default /dev/shm/autosplitterinfo. You can build it by typing make in the tracer folder.

The tracer can operate in two modes - one where it launches Celeste itself and thus does not require elevated privileges, and one where you launch it as root and it attaches to the Celeste process. These, along with the path where you want the autosplitter data dumped, are specified on the command line.

The way I've set it up is to have a loop always running in the background which is constantly trying to connect to any running Celeste instances. In order to do this securely, I've put the relevant paths in celeste_tracer_loop_mine.c and compiled it as a setuid binary - this means that it can be easily run with root privilege on login if you change the paths in the C source to work correctly on your computer.

How does it work?

Crawling the mono data structures. It's amazing; please don't ask.

The Timer

The timer folder contains python scripts that read the autosplitter info file and track splits. In order to use them, you'll need the dependencies from requirements.txt in the repository root: pip3 install --user -r requirements.txt. You can run the scripts with python3, e.g. python3 celeste_timer.py.

The most basic file is celeste_timer.py, which simply formats the data to text on the screen. This is useful for verifying that the tracer is working. This file is also a library which provides to the other scripts the ability to access this data, and also some primitives for manipulating splits.

The next-most important script is full_splits.py. This is a standard autosplitter program. It takes as input a path to a route file (a yaml dump which contains a celeste_timer.Route object serialized via pyyaml), and tracks your pb and gold splits. It uses the convention that routes should be stored in timer_data/<name>.route (I've provided a sample anypercent.route), pb data should be stored in timer_data/<name>.pb, and gold split data should be stored in timer_data/<name>.best. The timer will show you desktop notifications for split status and has keyboard shortcuts for resetting and skipping forward and backwards.

The next-most important script is edit_splits.py. This should allow you to create and open route files for editing.

The next-most important scripts are the make_*_splits.py files. These are programs which interactively construct a route file for you with some common templates.

Finally, we have stream.py, which is another autosplitter program which formats its data in a stream-friendly format. This one has much better coding standards, and should be used as a base if you want to write your own display program.

The Route Format

When using edit_splits.py, you are given the ability to create a sequence of "triggers" and "splits". During gameplay, the autosplitter keeps track of where in this sequence you are, starting at the beginning and proceeding past each trigger when its condition is met. Whenever you pass a split, the autosplitter will split. The display will show you the splits, but not the triggers.

When using subsplits, it's important to keep in mind that top level splits also serve as subsplits if they are preceded by a subsplit. For example, if you have the following route:

...
Ridge A
  Start
  Shrine
  Old Trail
  Cliff Face
Temple A
   ....

Your route file will look like the following:

...
- Trigger to indicate Start was completed
- Subsplit Start
- Trigger to indicate Shrine was completed
- Subsplit Shrine
- Trigger to indicate Old Trail was completed
- Subsplit Old Trail
- Trigger to indicate Cliff Face was completed
- Split Ridge A/Cliff Face
...

Since there are only splits wherever the autosplitter should actually split, and when you finish a split with subsplits you are capturing two different levels of timing at once, the final split in this sequence serves as both a subsplit and a normal split. When editing this split with edit_splits.py, you can put a slash in the name of the split to indicate that it has two names, first for the top level split and then for the subsplit.

Contributing

If you want to help out with this project, thank you!!! Feel free to submit pull requests for whatever you want and I'll review them. If you want suggestions for what kind of projects to work on, you can check out any of the open issues in the github Issues tab. Additionally, feel free to open issues asking for help understanding how the code works.

celestemagictimer's People

Contributors

afontenot avatar esawady avatar rhelmot avatar stacyharper avatar sushiinyourface avatar thomas-daniels avatar weyaaron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

celestemagictimer's Issues

Add command line toggle for split notifications

Right now, the notifications can only be disabled by editing the code. This is not desirable. We should add command-line flags to disable split notifications and to disable all notifications. One important nuance is that because there are a lot of different ways the autosplitter can be started, we should take care to do this in a way which doesn't require duplicating code across different entry points.

make_room_splits.py doesn't seem to be working

I have the autosplitter functional, and have verified that by running celeste_timer.py and stream.py, both of which do exactly what they are supposed to. However, when trying to make room splits, and following the instructions to go to the start of the chapter I want to make splits for and press enter, nothing happens. I've experimented with different places in the first room of the chapter, different chapters, and starting from a fresh file. None of these things seem to help at all, and I get no feedback from the script. Is this an issue with the code, or is it possibly something I'm doing wrong?

Add "Best Possible Time" calculation

As per title. There are already stubs in celeste_timer.py and stream.py where this should be implemented, I just haven't gotten around to it. There should also be a parameter for what level of splits it considers, so that e.g. you could track per-room splits but it only uses per-segment golds when calculating bpt.

Add current spawn point to tracer dump

Tracer should dump out SaveData.Instance.CurrentSession.RespawnPoint, maybe converted from floats to ints? This will allow splitting on summit flags.

Add alternative, more livesplit-like layout

I found an alternative linux timer for Celeste here - CAS by bfiedler. This timer uses an alternative timer layout. It looks a bit like this:
image

If we can implement this layout as an alternative (for example, we keep the original layout and make this accessible via an argument, like --alt) and add the features that we have on Celeste Magic Timer (for example, previous split times and notifications), that would be great!

Very frequent input/output errors on `read` in tracer

Happens with both tracer and tracer_loop. It attaches to the Celeste executable but very shortly after, I get read: Input/output error and it crashes. (tracer_loop starts a new instance shortly after but the read error just repeats then)

Not all reads are unsuccessful. Running the timer shortly shows sensible timings until the read error happens.

Ubuntu 20.10, Celeste 1.4.0.0 (I had Everest enabled at the time if that matters). Happy to provide more/better diagnosis of the problem, just not sure where and what to look for at the moment.

Does not work with custom maps

So I wanted to try and use this to split runs on custom maps. The setup works fine for base game chapters, even with the maps installed, but when I enter any custom map, the tracer debug log looks something like this:

For D-Sides:

savedata_addr = 0x7f5ac10f4530
mode_stats = (nil)
chapter = -1, mode = -1
savedata_addr = 0x7f5ac10f4530
mode_stats = (nil)
chapter = 12, mode = 0
savedata_addr = 0x7f5ac10f4530
Passed
areas_arr = 0x7f5ad78b01d0
area_stats = (nil)
read: Input/output error
Connected to Celeste.exe+Everest
ASI @ 0x7f5bd493f4d0
chapter = 12, mode = 0
savedata_addr = 0x7f5ac10f4530
chapter = 12, mode = 0
savedata_addr = 0x7f5ac10f4530
Passed
areas_arr = 0x7f5ad78b01d0
area_stats = (nil)
read: Input/output error
Connected to Celeste.exe+Everest
ASI @ 0x7f5bd493f4d0
chapter = 12, mode = 0
savedata_addr = 0x7f5ac10f4530
chapter = 12, mode = 0
savedata_addr = 0x7f5ac10f4530
Passed
areas_arr = 0x7f5ad78b01d0
area_stats = (nil)
read: Input/output error
Connected to Celeste.exe+Everest
ASI @ 0x7f5bd493f4d0
chapter = 12, mode = 0
savedata_addr = 0x7f5ac10f4530
chapter = 12, mode = 0
savedata_addr = 0x7f5ac10f4530
Passed
areas_arr = 0x7f5ad78b01d0
area_stats = (nil)
read: Input/output error
Connected to Celeste.exe+Everest
ASI @ 0x7f5bd493f4d0
chapter = 12, mode = 0
savedata_addr = 0x7f5ac10f4530
chapter = 12, mode = 0
savedata_addr = 0x7f5ac10f4530
Passed
areas_arr = 0x7f5ad78b01d0
area_stats = (nil)
read: Input/output error
Connected to Celeste.exe+Everest
ASI @ 0x7f5bd493f4d0
chapter = 12, mode = 0
savedata_addr = 0x7f5ac10f4530
chapter = 12, mode = 0
savedata_addr = 0x7f5ac10f4530
Passed
areas_arr = 0x7f5ad78b01d0
area_stats = (nil)
read: Input/output error

I don't think it crashes, but it repeats about once a second and never manages to read anything. It starts working again when leaving the custom map.

I also tried Strawberry Jam which it seems to like even less:

areas_arr = 0x7f13c308cb30
area_stats = 0x7f14a35e8dc0
Something is wrong
Connected to Celeste.exe+Everest
ASI @ 0x7f14dd7334d0
chapter = 41, mode = 0
savedata_addr = 0x7f12c28e7a30
chapter = 41, mode = 0
savedata_addr = 0x7f12c28e7a30
Passed
areas_arr = 0x7f13c308cb30
area_stats = 0x7f14a35e8dc0
Something is wrong
Connected to Celeste.exe+Everest
ASI @ 0x7f14dd7334d0
chapter = 41, mode = 0
savedata_addr = 0x7f12c28e7a30
chapter = 41, mode = 0
savedata_addr = 0x7f12c28e7a30
Passed
areas_arr = 0x7f13c308cb30
area_stats = 0x7f14a35e8dc0
Something is wrong
Connected to Celeste.exe+Everest
ASI @ 0x7f14dd7334d0
chapter = 41, mode = 0
savedata_addr = 0x7f12c28e7a30
chapter = 41, mode = 0
savedata_addr = 0x7f12c28e7a30
Passed

Change serialization to something other than pickle

Pickle is not desirable because it can be incompatible across python versions and can be used to execute arbitrary code on deserialization. Let's use something like json or yaml to serialize routes and splits.

It will be important to continue allowing loading of pickle data for a while as a deprecated function for backwards compatibility.

full_splits.py: restart chapter behaves differently for City

Steps to reproduce:

  • Run full_splits.py with a route for a chapter (I've attached my own city.route and site.route that split by subchapters, created using make_segment_splits.py, I don't think there's a big difference between them)
  • Go through the chapter far enough that at least the first split is finished.
  • Restart chapter.

Expected behavior:

  • Splits reset.

Actual behavior:

  • For at least Site and Ridge (didn't test this out with other chapters so far), the splits do reset nicely, so like this:
    1630252717_1758_29082021_702x112

  • For City, they don't. The autosplitter does recognize that the chapter time has gone to zero again, but it still thinks I'm in the middle of a run so it looks like this:
    1630252448_1754_29082021_730x104

Archive of my routes with city.route and site.route

Compare against average

It would be nice to track an average (all time average? rolling average with custom threshold?) of times so we could have a mode like livesplit where we compare against an average instead of the pb.

Add GUI

In the linux spirit, I don't think the GUI should be all-encompassing, as we have lots of different utility scripts to do lots of different things, but I think we definitely need a GUI for split rendering, so we can show something prettier than a terminal for streams.

Probably the best tool for the job is pywebview. Something like qt seems a bit overboard, though it would make communication with the GUI easier.

Tracer should dump map name as SID

This should fail gracefully on vanilla celeste. Should allow timing custom maps. May require a big old refactor of the timer to use SID instead of chapter index everywhere.

Setting up autosplitter resulted in crash on computer startup

I was playing around with the autosplitter, trying to set it up for myself. In all honesty, I didn't know exactly what I was doing, but I'm pretty sure the result shouldn't have happened regardless. I changed the paths in celeste_tracer_loop_mine.c to point to where the autosplitter was stored in my drive, then ran the makefile. After some trial and error, I ran the executable file in the tracer folder (which said it connected to celeste.exe, but could not find class savedata). The next time I powered up the system, it would constantly crash on startup. The solution to this was booting to a USB, then deleting the CelesteMagicTimer folder on my drive.

TL;DR: I tried to set up the splitter, and it resulted in my system crashing on startup

Add subsplits to split editor

The timer code supports arbitrarily deep subsplits, but the split editor can't do anything about it.

This is complicated because I'm not quite sure what the interface should look like. I would be okay with an interface which only lets you edit subsplits and subsubsplits, but there's still some thinking to be done. The editor works on a level with no abstraction away from the raw representation of the route, and the route represents subsplits kind of cryptically (albeit, imo, succinctly and correctly).

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.