Skip to content

Commit

Permalink
Mysterium 2024 Console ModDLL hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Aug 6, 2024
1 parent 889e191 commit a612160
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Sources/ModDLLs/modConsoleCommander/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ static pmConsoleCommander cmdr;
#endif

extern "C" {
DLLEXPORT void InitGlobals(hsResMgr *resMgr, plFactory *factory, plTimerCallbackManager *timer, plTimerShare *time, plNetClientApp* nc);
DLLEXPORT void InitGlobals(hsResMgr* resMgr, plFactory* factory, plTimerCallbackManager* timer, plTimerShare* time, plNetClientApp* nc);
}

DLLEXPORT void InitGlobals(hsResMgr *resMgr, plFactory *factory, plTimerCallbackManager *timer, plTimerShare *time, plNetClientApp* nc)
DLLEXPORT void InitGlobals(hsResMgr* resMgr, plFactory* factory, plTimerCallbackManager* timer, plTimerShare* time, plNetClientApp* nc)
{
hsgResMgr::SetTheResMgr(resMgr);
plFactory::SetTheFactory(factory);
plgTimerCallbackMgr::SetTheTimerCallbackMgr(timer);
hsTimer::SetTheTimer(time);
plNetClientApp::SetInstance(nc);

cmdr.Init();
hsStatusMessage("Loaded the Console Commander");

cmdr.Init(factory);
}
149 changes: 146 additions & 3 deletions Sources/ModDLLs/modConsoleCommander/pmConsoleCommander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,163 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "pmConsoleCommander.h"

void pmConsoleCommander::Init()
#include <string_theory/string>
#include <string_theory/string_stream>

#include "plClassIndexMacros.h"
#include "plCreatableIndex.h"
#include "pnFactory/plFactory.h"
#include "plMessage/plConsoleMsg.h"

#define FACTORY_NEW(cls) static_cast<cls*>(plFactory::Create(CLASS_INDEX_SCOPED(cls)));

struct CommandEntry {
const ST::string label;
const ST::string cmd;
};

static const CommandEntry commands[] = {
{ ST_LITERAL("Respawn Avatar"), ST_LITERAL("Avatar.Spawn.Respawn") },

{ ST_LITERAL("Go to Reischu Apartment"), ST_LITERAL("Net.LinkWithOriginalBook ReischuApartment, Default:LinkInPointDefault:") },
{ ST_LITERAL("Reischu Day 0%"), ST_LITERAL("Net.ForceSetAgeTimeOfDay 0.0") },
{ ST_LITERAL("Reischu Day 25%"), ST_LITERAL("Net.ForceSetAgeTimeOfDay 0.25") },
{ ST_LITERAL("Reischu Day 50%"), ST_LITERAL("Net.ForceSetAgeTimeOfDay 0.50") },
{ ST_LITERAL("Reischu Day 75%"), ST_LITERAL("Net.ForceSetAgeTimeOfDay 0.75") },
{ ST_LITERAL("Reischu Day 100%"), ST_LITERAL("Net.ForceSetAgeTimeOfDay 0.99") },

{ ST_LITERAL("Go to Explorers Emporium"), ST_LITERAL("Net.LinkWithOriginalBook ExplorersEmporium, Default:LinkInPointDefault:") },

{ ST_LITERAL("Go to Venalem"), ST_LITERAL("Net.LinkWithOriginalBook Venalem, Default:LinkInPointDefault:") },

{ ST_LITERAL("Go to Descent"), ST_LITERAL("Net.LinkWithOriginalBook Descent, Default:LinkInPointDefault:") },
{ ST_LITERAL("Descent Elevator"), ST_LITERAL("Avatar.Spawn.Go 18") },
{ ST_LITERAL("Descent Floor"), ST_LITERAL("Avatar.Spawn.Go 4") },

{ ST_LITERAL("Go to Chiso"), ST_LITERAL("Net.LinkWithOriginalBook ChisoPreniv, Default:LinkInPointDefault:") },
{ ST_LITERAL("Go downstairs Chiso"), ST_LITERAL("Avatar.Spawn.Go 2") },

//{ ST_LITERAL("Go to Sakura Vale"), ST_LITERAL("Net.LinkWithOriginalBook SakuraVale, Default:LinkInPointDefault:") },

{ ST_LITERAL("H'uru Presentation"), ST_LITERAL("Game.ShowDialog M24Huru") },
{ ST_LITERAL("'One More Thing...'"), ST_LITERAL("Game.ShowDialog M24OMT") },
{ ST_LITERAL("Hide 'One More Thing...'"), ST_LITERAL("Game.HideDialog M24OMT") },
{ ST_LITERAL("Go to Relto"), ST_LITERAL("Net.LinkToMyPersonalAge") }
};

static ST::string RenderWebPage() {
const char endl = '\n';
ST::string_stream ss;
ss << ST_LITERAL(R"(<!doctype html>)") << endl;
ss << ST_LITERAL(R"(<html lang="en">)") << endl;
ss << ST_LITERAL(R"( <head>)") << endl;
ss << ST_LITERAL(R"( <meta charset="utf-8">)") << endl;
ss << ST_LITERAL(R"( <meta name="theme-color" content="#3e364e">)") << endl;
ss << ST_LITERAL(R"( <meta name="viewport" content="width=device-width,initial-scale=1.0,viewport-fit=cover">)") << endl;
ss << ST_LITERAL(R"( <title>Plasma Console Commander</title>)") << endl;
ss << ST_LITERAL(R"( <style>
body {
margin: 0;
font-family: system-ui, sans-serif;
background: black;
}
header {
background: #3e364e;
position: sticky;
top: 0;
padding: env(safe-area-inset-top, 0px) 0 0 0;
color: white;
text-align: center;
}
header h1 {
margin: 0;
line-height: 64px;
vertical-align: middle;
font-weight: 500;
text-shadow: 0 -1px 1px black;
}
main {
max-width: 820px;
margin: 0 auto;
padding: 1.5em;
}
@media screen and (min-width: 600px) {
main {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 0 1.5em;
}
}
button {
width: 100%;
padding: 1em;
font-weight: 500;
font-family: system-ui;
font-size: 1.25rem;
background: #231f2b;
color: palegreen;
border-radius: 10px;
margin-bottom: 1.5rem;
}
)");
ss << ST_LITERAL(R"( </style>)") << endl;
ss << ST_LITERAL(R"( </head>)") << endl;
ss << ST_LITERAL(R"( <body>)") << endl;

ss << ST_LITERAL(R"( <header>)") << endl;
ss << ST_LITERAL(R"( <h1>Console Commander</h1>)") << endl;
ss << ST_LITERAL(R"( </header>)") << endl;

ss << ST_LITERAL(R"( <main>)") << endl;

/*
ss << ST_LITERAL(R"( <form method="POST" action="/console">)") << endl;
ss << ST_LITERAL(R"( <input name="cmd" type="text">)") << endl;
ss << ST_LITERAL(R"( <input type="submit">)") << endl;
ss << ST_LITERAL(R"( </form>)") << endl;
*/

for (const CommandEntry& ce : commands) {
ss << ST_LITERAL(R"( <form method="POST" action="/console">)") << endl;
ss << ST_LITERAL(R"( <input type="hidden" name="cmd" value=")") << ce.cmd << ST_LITERAL(R"(">)") << endl;
ss << ST_LITERAL(R"( <button type="submit">)") << ce.label << ST_LITERAL(R"(</button>)") << endl;
ss << ST_LITERAL(R"( </form>)") << endl;
}

ss << ST_LITERAL(R"( </main>)") << endl;
ss << ST_LITERAL(R"( </body>)") << endl;
ss << ST_LITERAL(R"(</html>)") << endl;

return ss.to_string();
}

void pmConsoleCommander::Init(plFactory* factory)
{
fServer = new crow::SimpleApp();

CROW_ROUTE((*fServer), "/console").methods("GET"_method)([](){
return "Hello world";
ST::string page = RenderWebPage();
return page.to_std_string();
});


CROW_ROUTE((*fServer), "/console").methods("POST"_method)([](const crow::request& req){
auto params = req.get_body_params();
auto cmd = params.get("cmd");

hsStatusMessageF("Requesting to run console command: %s\n", cmd);
return "POSTED! Hello world";
plConsoleMsg* msg = FACTORY_NEW(plConsoleMsg);
msg->SetCmd(plConsoleMsg::kExecuteLine);
msg->SetString(cmd);
msg->Send(nullptr, true);

ST::string page = RenderWebPage();
return page.to_std_string();
});

hsThread::Start();
Expand Down
4 changes: 3 additions & 1 deletion Sources/ModDLLs/modConsoleCommander/pmConsoleCommander.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "hsThread.h"
#include "crow_all.h"

class plFactory;

class pmConsoleCommander : public hsThread
{
protected:
Expand All @@ -55,7 +57,7 @@ class pmConsoleCommander : public hsThread
public:
pmConsoleCommander() : fServer() { }

void Init();
void Init(plFactory* factory);

void Run() override;
void OnQuit() override;
Expand Down
2 changes: 2 additions & 0 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/plClient.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.device.audio-input</key>
<true/>
</dict>
Expand Down
2 changes: 2 additions & 0 deletions Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ void plClient::InitDLLs() {
(*initGlobals)(hsgResMgr::ResMgr(), plFactory::GetTheFactory(), plgTimerCallbackMgr::Mgr(),
hsTimer::GetTheTimer(), plNetClientApp::GetInstance());
fLoadedDLLs.emplace_back(mod);
} else {
hsStatusMessage(ST::format("Failed to load lib: {}", dlerror()).c_str());
}
}
}
Expand Down

0 comments on commit a612160

Please sign in to comment.