Skip to content

Commit

Permalink
Debugger: Add current game info.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Jun 8, 2018
1 parent 77131e7 commit 3dac5f2
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -1408,6 +1408,8 @@ add_library(${CoreLibName} ${CoreLinkType}
Core/Debugger/WebSocket/CPUCoreSubscriber.h Core/Debugger/WebSocket/CPUCoreSubscriber.h
Core/Debugger/WebSocket/GameBroadcaster.cpp Core/Debugger/WebSocket/GameBroadcaster.cpp
Core/Debugger/WebSocket/GameBroadcaster.h Core/Debugger/WebSocket/GameBroadcaster.h
Core/Debugger/WebSocket/GameSubscriber.cpp
Core/Debugger/WebSocket/GameSubscriber.h
Core/Debugger/WebSocket/LogBroadcaster.cpp Core/Debugger/WebSocket/LogBroadcaster.cpp
Core/Debugger/WebSocket/LogBroadcaster.h Core/Debugger/WebSocket/LogBroadcaster.h
Core/Debugger/WebSocket/SteppingBroadcaster.cpp Core/Debugger/WebSocket/SteppingBroadcaster.cpp
Expand Down
2 changes: 2 additions & 0 deletions Core/Core.vcxproj
Expand Up @@ -187,6 +187,7 @@
<ClCompile Include="Debugger\WebSocket.cpp" /> <ClCompile Include="Debugger\WebSocket.cpp" />
<ClCompile Include="Debugger\WebSocket\CPUCoreSubscriber.cpp" /> <ClCompile Include="Debugger\WebSocket\CPUCoreSubscriber.cpp" />
<ClCompile Include="Debugger\WebSocket\GameBroadcaster.cpp" /> <ClCompile Include="Debugger\WebSocket\GameBroadcaster.cpp" />
<ClCompile Include="Debugger\WebSocket\GameSubscriber.cpp" />
<ClCompile Include="Debugger\WebSocket\LogBroadcaster.cpp" /> <ClCompile Include="Debugger\WebSocket\LogBroadcaster.cpp" />
<ClCompile Include="Debugger\WebSocket\SteppingBroadcaster.cpp" /> <ClCompile Include="Debugger\WebSocket\SteppingBroadcaster.cpp" />
<ClCompile Include="Debugger\WebSocket\WebSocketUtils.cpp" /> <ClCompile Include="Debugger\WebSocket\WebSocketUtils.cpp" />
Expand Down Expand Up @@ -539,6 +540,7 @@
<ClInclude Include="..\ext\udis86\udis86.h" /> <ClInclude Include="..\ext\udis86\udis86.h" />
<ClInclude Include="AVIDump.h" /> <ClInclude Include="AVIDump.h" />
<ClInclude Include="Debugger\WebSocket.h" /> <ClInclude Include="Debugger\WebSocket.h" />
<ClInclude Include="Debugger\WebSocket\GameSubscriber.h" />
<ClInclude Include="Debugger\WebSocket\WebSocketUtils.h" /> <ClInclude Include="Debugger\WebSocket\WebSocketUtils.h" />
<ClInclude Include="Debugger\WebSocket\CPUCoreSubscriber.h" /> <ClInclude Include="Debugger\WebSocket\CPUCoreSubscriber.h" />
<ClInclude Include="Debugger\WebSocket\GameBroadcaster.h" /> <ClInclude Include="Debugger\WebSocket\GameBroadcaster.h" />
Expand Down
6 changes: 6 additions & 0 deletions Core/Core.vcxproj.filters
Expand Up @@ -713,6 +713,9 @@
<ClCompile Include="Debugger\WebSocket\WebSocketUtils.cpp"> <ClCompile Include="Debugger\WebSocket\WebSocketUtils.cpp">
<Filter>Debugger\WebSocket</Filter> <Filter>Debugger\WebSocket</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Debugger\WebSocket\GameSubscriber.cpp">
<Filter>Debugger\WebSocket</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="ELF\ElfReader.h"> <ClInclude Include="ELF\ElfReader.h">
Expand Down Expand Up @@ -1313,6 +1316,9 @@
<ClInclude Include="Debugger\WebSocket\WebSocketUtils.h"> <ClInclude Include="Debugger\WebSocket\WebSocketUtils.h">
<Filter>Debugger\WebSocket</Filter> <Filter>Debugger\WebSocket</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Debugger\WebSocket\GameSubscriber.h">
<Filter>Debugger\WebSocket</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="CMakeLists.txt" /> <None Include="CMakeLists.txt" />
Expand Down
2 changes: 2 additions & 0 deletions Core/Debugger/WebSocket.cpp
Expand Up @@ -44,6 +44,7 @@
#include "Core/Debugger/WebSocket/SteppingBroadcaster.h" #include "Core/Debugger/WebSocket/SteppingBroadcaster.h"


#include "Core/Debugger/WebSocket/CPUCoreSubscriber.h" #include "Core/Debugger/WebSocket/CPUCoreSubscriber.h"
#include "Core/Debugger/WebSocket/GameSubscriber.h"


typedef void *(*SubscriberInit)(DebuggerEventHandlerMap &map); typedef void *(*SubscriberInit)(DebuggerEventHandlerMap &map);
typedef void (*Subscribershutdown)(void *p); typedef void (*Subscribershutdown)(void *p);
Expand All @@ -54,6 +55,7 @@ struct SubscriberInfo {


static const std::vector<SubscriberInfo> subscribers({ static const std::vector<SubscriberInfo> subscribers({
{ &WebSocketCPUCoreInit, nullptr }, { &WebSocketCPUCoreInit, nullptr },
{ &WebSocketGameInit, nullptr },
}); });


// To handle webserver restart, keep track of how many running. // To handle webserver restart, keep track of how many running.
Expand Down
74 changes: 65 additions & 9 deletions Core/Debugger/WebSocket/GameBroadcaster.cpp
Expand Up @@ -17,22 +17,78 @@


#include "Core/Debugger/WebSocket/GameBroadcaster.h" #include "Core/Debugger/WebSocket/GameBroadcaster.h"
#include "Core/Debugger/WebSocket/WebSocketUtils.h" #include "Core/Debugger/WebSocket/WebSocketUtils.h"
#include "Core/ELF/ParamSFO.h"
#include "Core/System.h" #include "Core/System.h"


struct GameStatusEvent {
const char *ev;

operator std::string() {
JsonWriter j;
j.begin();
j.writeString("event", ev);
if (PSP_IsInited()) {
j.pushDict("game");
j.writeString("id", g_paramSFO.GetDiscID());
j.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));
j.writeString("title", g_paramSFO.GetValueString("TITLE"));
j.pop();
} else {
j.writeRaw("game", "null");
}
j.end();
return j.str();
}
};

// Game started (game.start)
//
// Sent unexpectedly with these properties:
// - game: null or an object with properties:
// - id: string disc ID (such as ULUS12345.)
// - version: string disc version.
// - title: string game title.

// Game quit / ended (game.quit)
//
// Sent unexpectedly with these properties:
// - game: null

// Game paused (game.pause)
//
// Note: this is not the same as stepping. This means the user went to the pause menu.
//
// Sent unexpectedly with these properties:
// - game: null or an object with properties:
// - id: string disc ID (such as ULUS12345.)
// - version: string disc version.
// - title: string game title.

// Game resumed (game.pause)
//
// Note: this is not the same as stepping. This means the user resumed from the pause menu.
//
// Sent unexpectedly with these properties:
// - game: null or an object with properties:
// - id: string disc ID (such as ULUS12345.)
// - version: string disc version.
// - title: string game title.
void GameBroadcaster::Broadcast(net::WebSocketServer *ws) { void GameBroadcaster::Broadcast(net::WebSocketServer *ws) {
// TODO: This is ugly. Implement proper information instead. // TODO: This is ugly. Callbacks instead?
// TODO: Should probably include info about which game, etc.
GlobalUIState state = GetUIState(); GlobalUIState state = GetUIState();
if (prevState_ != state) { if (prevState_ != state) {
if (state == UISTATE_PAUSEMENU) { if (state == UISTATE_PAUSEMENU) {
ws->Send(R"({"event":"game.pause"})"); ws->Send(GameStatusEvent{"game.pause"});
prevState_ = state;
} else if (state == UISTATE_INGAME && prevState_ == UISTATE_PAUSEMENU) { } else if (state == UISTATE_INGAME && prevState_ == UISTATE_PAUSEMENU) {
ws->Send(R"({"event":"game.resume"})"); ws->Send(GameStatusEvent{"game.resume"});
} else if (state == UISTATE_INGAME) { prevState_ = state;
ws->Send(R"({"event":"game.start"})"); } else if (state == UISTATE_INGAME && PSP_IsInited()) {
} else if (state == UISTATE_MENU) { ws->Send(GameStatusEvent{"game.start"});
ws->Send(R"({"event":"game.quit"})"); prevState_ = state;
} else if (state == UISTATE_MENU && !PSP_IsInited() && !PSP_IsQuitting()) {
ws->Send(GameStatusEvent{"game.quit"});
prevState_ = state;
} }
prevState_ = state;
} }
} }
51 changes: 51 additions & 0 deletions Core/Debugger/WebSocket/GameSubscriber.cpp
@@ -0,0 +1,51 @@
// Copyright (c) 2018- PPSSPP Project.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.

// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include "Core/Debugger/WebSocket/GameSubscriber.h"
#include "Core/Debugger/WebSocket/WebSocketUtils.h"
#include "Core/ELF/ParamSFO.h"
#include "Core/System.h"

void *WebSocketGameInit(DebuggerEventHandlerMap &map) {
map["game.status"] = &WebSocketGameStatus;

return nullptr;
}

// Check game status (game.status)
//
// No parameters.
//
// Response (same event name):
// - game: null or an object with properties:
// - id: string disc ID (such as ULUS12345.)
// - version: string disc version.
// - title: string game title.
// - paused: boolean, true when gameplay is paused (not the same as stepping.)
void WebSocketGameStatus(DebuggerRequest &req) {
JsonWriter &json = req.Respond();
if (PSP_IsInited()) {
json.pushDict("game");
json.writeString("id", g_paramSFO.GetDiscID());
json.writeString("version", g_paramSFO.GetValueString("DISC_VERSION"));
json.writeString("title", g_paramSFO.GetValueString("TITLE"));
json.pop();
} else {
json.writeRaw("game", "null");
}
json.writeBool("paused", GetUIState() == UISTATE_PAUSEMENU);
}
24 changes: 24 additions & 0 deletions Core/Debugger/WebSocket/GameSubscriber.h
@@ -0,0 +1,24 @@
// Copyright (c) 2018- PPSSPP Project.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.

// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#pragma once

#include "Core/Debugger/WebSocket/WebSocketUtils.h"

void *WebSocketGameInit(DebuggerEventHandlerMap &map);

void WebSocketGameStatus(DebuggerRequest &req);
4 changes: 4 additions & 0 deletions Core/System.cpp
Expand Up @@ -385,6 +385,10 @@ bool PSP_IsInited() {
return pspIsInited && !pspIsQuitting; return pspIsInited && !pspIsQuitting;
} }


bool PSP_IsQuitting() {
return pspIsQuitting;
}

void PSP_Shutdown() { void PSP_Shutdown() {
// Do nothing if we never inited. // Do nothing if we never inited.
if (!pspIsInited && !pspIsIniting && !pspIsQuitting) { if (!pspIsInited && !pspIsIniting && !pspIsQuitting) {
Expand Down
1 change: 1 addition & 0 deletions Core/System.h
Expand Up @@ -66,6 +66,7 @@ bool PSP_InitStart(const CoreParameter &coreParam, std::string *error_string);
bool PSP_InitUpdate(std::string *error_string); bool PSP_InitUpdate(std::string *error_string);
bool PSP_IsIniting(); bool PSP_IsIniting();
bool PSP_IsInited(); bool PSP_IsInited();
bool PSP_IsQuitting();
void PSP_Shutdown(); void PSP_Shutdown();


void PSP_BeginHostFrame(); void PSP_BeginHostFrame();
Expand Down
1 change: 1 addition & 0 deletions android/jni/Android.mk
Expand Up @@ -303,6 +303,7 @@ EXEC_AND_LIB_FILES := \
$(SRC)/Core/Debugger/WebSocket.cpp \ $(SRC)/Core/Debugger/WebSocket.cpp \
$(SRC)/Core/Debugger/WebSocket/CPUCoreSubscriber.cpp \ $(SRC)/Core/Debugger/WebSocket/CPUCoreSubscriber.cpp \
$(SRC)/Core/Debugger/WebSocket/GameBroadcaster.cpp \ $(SRC)/Core/Debugger/WebSocket/GameBroadcaster.cpp \
$(SRC)/Core/Debugger/WebSocket/GameSubscriber.cpp \
$(SRC)/Core/Debugger/WebSocket/LogBroadcaster.cpp \ $(SRC)/Core/Debugger/WebSocket/LogBroadcaster.cpp \
$(SRC)/Core/Debugger/WebSocket/SteppingBroadcaster.cpp \ $(SRC)/Core/Debugger/WebSocket/SteppingBroadcaster.cpp \
$(SRC)/Core/Debugger/WebSocket/WebSocketUtils.cpp \ $(SRC)/Core/Debugger/WebSocket/WebSocketUtils.cpp \
Expand Down

0 comments on commit 3dac5f2

Please sign in to comment.