Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add save state and screen access options to the web server #1643

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Giragast
Copy link

Web server GET options that allow for:

Save state access - load/save/delete/usage - NOT AVAILABLE for CLI/no-UI:

  • http://localhost:8080/api/v1/state/load?slot=0 - loads save state from slot 0, if available. Valid slots IDs are 0-9

  • http://localhost:8080/api/v1/state/load?name=examplename - loads named save TITLEPREFIX_examplename.sstate

  • http://localhost:8080/api/v1/state/save?slot=0 - saves current state in slot 0

  • http://localhost:8080/api/v1/state/save?name=examplename - creates/overwrites named save TITLEPREFIX_examplename.sstate

  • http://localhost:8080/api/v1/state/delete?slot=0 - deletes state in slot 0, if available

  • http://localhost:8080/api/v1/state/delete?name=examplename - deletes named save TITLEPREFIX_examplename.sstate

  • http://localhost:8080/api/v1/state/usage - outputs Json that lists all existing named saves for the active title, and booleans for which save slots are in use, e.g.

{
    "named": [
        {
            "filepath": "D:\\pcsx-redux\\SLUS01234_chapter1_boss_fight.sstate",
            "name": "chapter1_boss_fight"
        },
        {
            "filepath": "D:\\pcsx-redux\\SLUS01234_intro_start.sstate",
            "name": "intro_start"
        },
        {
            "filepath": "D:\\pcsx-redux\\SLUS01234_shotgun.sstate",
            "name": "shotgun"
        }
    ],
    "slots": [
        true,
        true,
        false,
        true,
        false,
        false,
        false,
        true,
        true,
        false
    ]
}

Screen access:

  • http://localhost:8080/api/v1/screen/save?filepath=d:\\screenshot.png - outputs a PNG screenshot to the given filepath.
  • http://localhost:8080/api/v1/screen/still - outputs a PNG with Content-Type: image/png. Example refreshing <img> use-case (will affect emulator performance):
<html>
<head>
<script type="text/javascript">
window.onload = function() {
    img = document.getElementById('refreshImage');
    img.src += "?";
    setInterval("img.src=img.src.replace(/\\?[0-9]*/, '?'+Math.floor(Math.random()*9999999+1));", 200);
}
</script>
</head>

<body>
<img id="refreshImage" src="http://localhost:8080/api/v1/screen/still" />
</body>
</html>

Copy link
Member

@nicolasnoble nicolasnoble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the review delay, I was busy overhauling the way we're distributing the emulator.

}
virtual bool execute(PCSX::WebClient* client, PCSX::RequestData& request) final {
if (PCSX::g_gui == nullptr) {
client->write("HTTP/1.1 400 Bad Request\r\n\r\nSave states unavailable in CLI/no-UI mode.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to move the savestate code to the general UI class instead of the GUI one, but that's for another PR.

message =
fmt::format("HTTP/1.1 200 OK\r\n\r\nState slot index {} {} successful.", slot, path);
} else {
message = fmt::format("HTTP/1.1 400 Bad Request\r\n\r\nState slot index {} {} failed.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically that's a 500 Internal Server Error :) The request was fine, the server didn't manage to handle it properly.

virtual ~StateExecutor() = default;
};

clip::image convertScreenshotToImage(PCSX::GPU::ScreenShot&& screenshot) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should either be static, or moved as methods of the ScreenExecutor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants