Path: blob/master/Core/Debugger/WebSocket/GameSubscriber.cpp
5654 views
// Copyright (c) 2018- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include "Common/System/System.h"18#include "Core/Config.h"19#include "Core/Debugger/WebSocket/GameSubscriber.h"20#include "Core/Debugger/WebSocket/WebSocketUtils.h"21#include "Core/ELF/ParamSFO.h"22#include "Core/System.h"2324DebuggerSubscriber *WebSocketGameInit(DebuggerEventHandlerMap &map) {25map["game.reset"] = &WebSocketGameReset;26map["game.status"] = &WebSocketGameStatus;27map["version"] = &WebSocketVersion;2829return nullptr;30}3132// Reset emulation (game.reset)33//34// Use this if you need to break on start and do something before the game starts.35//36// Parameters:37// - break: optional boolean, true to break CPU on start. Use cpu.resume afterward.38//39// Response (same event name) with no extra data or error.40void WebSocketGameReset(DebuggerRequest &req) {41if (PSP_GetBootState() != BootState::Complete)42return req.Fail("Game not running");4344bool needBreak = false;45if (!req.ParamBool("break", &needBreak, DebuggerParamType::OPTIONAL))46return;4748if (needBreak)49PSP_CoreParameter().startBreak = true;5051// We can only support async resets here. A lot of the stuff in init must happen on the EmuThread,52// and we are not on it here.53System_PostUIMessage(UIMessage::REQUEST_GAME_RESET);5455req.Respond();56}5758// Check game status (game.status)59//60// No parameters.61//62// Response (same event name):63// - game: null or an object with properties:64// - id: string disc ID (such as ULUS12345.)65// - version: string disc version.66// - title: string game title.67// - paused: boolean, true when gameplay is paused (not the same as stepping.)68void WebSocketGameStatus(DebuggerRequest &req) {69JsonWriter &json = req.Respond();70if (PSP_GetBootState() == BootState::Complete) {71json.pushDict("game");72json.writeString("id", g_paramSFO.GetDiscID());73json.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));74json.writeString("title", g_paramSFO.GetValueString("TITLE"));75json.pop();76} else {77json.writeNull("game");78}79json.writeBool("paused", GetUIState() == UISTATE_PAUSEMENU);80}8182// Notify debugger version info (version)83//84// Parameters:85// - name: string indicating name of app or tool.86// - version: string version.87//88// Response (same event name):89// - name: string, "PPSSPP" unless some special build.90// - version: string, typically starts with "v" and may have git build info.91void WebSocketVersion(DebuggerRequest &req) {92JsonWriter &json = req.Respond();9394std::string version = req.client->version;95if (!req.ParamString("version", &version, DebuggerParamType::OPTIONAL_LOOSE))96return;97std::string name = req.client->name;98if (!req.ParamString("name", &name, DebuggerParamType::OPTIONAL_LOOSE))99return;100101req.client->version = version;102req.client->name = name;103104json.writeString("name", "PPSSPP");105json.writeString("version", PPSSPP_GIT_VERSION);106}107108109