From 57e9d13e6a2d182a93fb32124e1334a5a6972e94 Mon Sep 17 00:00:00 2001 From: lonaasan Date: Fri, 6 Sep 2024 23:29:02 +0200 Subject: [PATCH 1/8] Added custom OpenSB help text categories and descriptions --- assets/opensb/help.config.patch | 8 +++++++- source/game/StarCommandProcessor.cpp | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/assets/opensb/help.config.patch b/assets/opensb/help.config.patch index 0feb345..15375e8 100644 --- a/assets/opensb/help.config.patch +++ b/assets/opensb/help.config.patch @@ -2,8 +2,14 @@ "basicHelpText": "Basic commands are: {}", "adminHelpText": "Admin commands are: {}", "debugHelpText": "Debug commands are: {}", + "openSbHelpText": "OpenSB commands are: {}", + "openSbDebugHelpText": "OpenSB Debug commands are: {}", - "debugCommands": { + "openSbDebugCommands": { "run": "Usage /run . Executes a script on the player and outputs the return value to chat." + }, + + "openSbCommands": { + "swap": "Usage /swap . Swaps the current character, case-insensitive, only substring required." } } diff --git a/source/game/StarCommandProcessor.cpp b/source/game/StarCommandProcessor.cpp index 14413b4..b5beb20 100644 --- a/source/game/StarCommandProcessor.cpp +++ b/source/game/StarCommandProcessor.cpp @@ -53,12 +53,14 @@ String CommandProcessor::help(ConnectionId connectionId, String const& argumentS auto assets = Root::singleton().assets(); auto basicCommands = assets->json("/help.config:basicCommands"); + auto openSbCommands = assets->json("/help.config:openSbCommands"); auto adminCommands = assets->json("/help.config:adminCommands"); auto debugCommands = assets->json("/help.config:debugCommands"); + auto openSbDebugCommands = assets->json("/help.config:openSbDebugCommands"); if (arguments.size()) { if (arguments.size() >= 1) { - if (auto helpText = basicCommands.optString(arguments[0]).orMaybe(adminCommands.optString(arguments[0])).orMaybe(debugCommands.optString(arguments[0]))) + if (auto helpText = basicCommands.optString(arguments[0]).orMaybe(openSbCommands.optString(arguments[0])).orMaybe(adminCommands.optString(arguments[0])).orMaybe(debugCommands.optString(arguments[0])).orMaybe(openSbDebugCommands.optString(arguments[0]))) return *helpText; } } @@ -74,12 +76,18 @@ String CommandProcessor::help(ConnectionId connectionId, String const& argumentS String basicHelpFormat = assets->json("/help.config:basicHelpText").toString(); res = res + strf(basicHelpFormat.utf8Ptr(), commandDescriptions(basicCommands)); + String openSbHelpFormat = assets->json("/help.config:openSbHelpText").toString(); + res = res + "\n" + strf(openSbHelpFormat.utf8Ptr(), commandDescriptions(openSbCommands)); + if (!adminCheck(connectionId, "")) { String adminHelpFormat = assets->json("/help.config:adminHelpText").toString(); res = res + "\n" + strf(adminHelpFormat.utf8Ptr(), commandDescriptions(adminCommands)); String debugHelpFormat = assets->json("/help.config:debugHelpText").toString(); res = res + "\n" + strf(debugHelpFormat.utf8Ptr(), commandDescriptions(debugCommands)); + + String openSbDebugHelpFormat = assets->json("/help.config:openSbDebugHelpText").toString(); + res = res + "\n" + strf(openSbDebugHelpFormat.utf8Ptr(), commandDescriptions(openSbDebugCommands)); } res = res + "\n" + basicCommands.getString("help"); From fc1b97c4bc055ceae3711d82f5831c5d357f3b9e Mon Sep 17 00:00:00 2001 From: floyd <78954063+floydinator-git@users.noreply.github.com> Date: Sat, 7 Sep 2024 00:03:07 -0400 Subject: [PATCH 2/8] Update StarAssets.cpp --- source/base/StarAssets.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/base/StarAssets.cpp b/source/base/StarAssets.cpp index c47b71c..a188291 100644 --- a/source/base/StarAssets.cpp +++ b/source/base/StarAssets.cpp @@ -124,6 +124,7 @@ Assets::Assets(Settings settings, StringList assetSources) { LuaCallbacks callbacks; callbacks.registerCallbackWithSignature("byExtension", bind(&Assets::scanExtension, this, _1)); callbacks.registerCallbackWithSignature("json", bind(&Assets::json, this, _1)); + callbacks.registerCallbackWithSignature("exists", bind(&Assets::assetExists, this, _1)); callbacks.registerCallback("bytes", [this](String const& path) -> String { auto assetBytes = bytes(path); From 98a395721ee0383bd2ed046235dd644909f2f943 Mon Sep 17 00:00:00 2001 From: lonaasan Date: Mon, 9 Sep 2024 09:53:11 +0200 Subject: [PATCH 3/8] [Small Addition] added respawnInWorld Command --- assets/opensb/help.config.patch | 3 +- .../frontend/StarClientCommandProcessor.cpp | 46 ++++++++++++++----- .../frontend/StarClientCommandProcessor.hpp | 1 + source/game/StarWorldClient.cpp | 12 +++++ source/game/StarWorldClient.hpp | 3 ++ 5 files changed, 52 insertions(+), 13 deletions(-) diff --git a/assets/opensb/help.config.patch b/assets/opensb/help.config.patch index 15375e8..b3f31a6 100644 --- a/assets/opensb/help.config.patch +++ b/assets/opensb/help.config.patch @@ -10,6 +10,7 @@ }, "openSbCommands": { - "swap": "Usage /swap . Swaps the current character, case-insensitive, only substring required." + "swap": "Usage /swap . Swaps the current character, case-insensitive, only substring required.", + "respawninworld": "Usage /respawnInWorld. Sets the respawn flag for the current world until you teleport away." } } diff --git a/source/frontend/StarClientCommandProcessor.cpp b/source/frontend/StarClientCommandProcessor.cpp index 2d98289..39b0d89 100644 --- a/source/frontend/StarClientCommandProcessor.cpp +++ b/source/frontend/StarClientCommandProcessor.cpp @@ -15,9 +15,9 @@ namespace Star { ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient, CinematicPtr cinematicOverlay, - MainInterfacePaneManager* paneManager, StringMap macroCommands) - : m_universeClient(std::move(universeClient)), m_cinematicOverlay(std::move(cinematicOverlay)), - m_paneManager(paneManager), m_macroCommands(std::move(macroCommands)) { + MainInterfacePaneManager* paneManager, StringMap macroCommands) + : m_universeClient(std::move(universeClient)), m_cinematicOverlay(std::move(cinematicOverlay)), + m_paneManager(paneManager), m_macroCommands(std::move(macroCommands)) { m_builtinCommands = { {"reload", bind(&ClientCommandProcessor::reload, this)}, {"whoami", bind(&ClientCommandProcessor::whoami, this)}, @@ -51,13 +51,14 @@ ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient, {"maketechavailable", bind(&ClientCommandProcessor::makeTechAvailable, this, _1)}, {"enabletech", bind(&ClientCommandProcessor::enableTech, this, _1)}, {"upgradeship", bind(&ClientCommandProcessor::upgradeShip, this, _1)}, - {"swap", bind(&ClientCommandProcessor::swap, this, _1)} + {"swap", bind(&ClientCommandProcessor::swap, this, _1)}, + {"respawnInWorld", bind(&ClientCommandProcessor::respawnInWorld, this)} }; } bool ClientCommandProcessor::adminCommandAllowed() const { return Root::singleton().configuration()->get("allowAdminCommandsFromAnyone").toBool() || - m_universeClient->mainPlayer()->isAdmin(); + m_universeClient->mainPlayer()->isAdmin(); } String ClientCommandProcessor::previewQuestPane(StringList const& arguments, function createPane) { @@ -128,7 +129,7 @@ String ClientCommandProcessor::reload() { String ClientCommandProcessor::whoami() { return strf("Client: You are {}. You are {}an Admin.", - m_universeClient->mainPlayer()->name(), m_universeClient->mainPlayer()->isAdmin() ? "" : "not "); + m_universeClient->mainPlayer()->name(), m_universeClient->mainPlayer()->isAdmin() ? "" : "not "); } String ClientCommandProcessor::gravity() { @@ -273,8 +274,8 @@ String ClientCommandProcessor::previewNewQuest(String const& argumentsString) { return "You must be an admin to use this command."; return previewQuestPane(arguments, [this](QuestPtr const& quest) { - return make_shared(m_universeClient->questManager(), quest, m_universeClient->mainPlayer()); - }); + return make_shared(m_universeClient->questManager(), quest, m_universeClient->mainPlayer()); + }); } String ClientCommandProcessor::previewQuestComplete(String const& argumentsString) { @@ -283,8 +284,8 @@ String ClientCommandProcessor::previewQuestComplete(String const& argumentsStrin return "You must be an admin to use this command."; return previewQuestPane(arguments, [this](QuestPtr const& quest) { - return make_shared(quest, m_universeClient->mainPlayer(), CinematicPtr{}); - }); + return make_shared(quest, m_universeClient->mainPlayer(), CinematicPtr{}); + }); } String ClientCommandProcessor::previewQuestFailed(String const& argumentsString) { @@ -293,8 +294,8 @@ String ClientCommandProcessor::previewQuestFailed(String const& argumentsString) return "You must be an admin to use this command."; return previewQuestPane(arguments, [this](QuestPtr const& quest) { - return make_shared(quest, m_universeClient->mainPlayer()); - }); + return make_shared(quest, m_universeClient->mainPlayer()); + }); } String ClientCommandProcessor::clearScannedObjects() { @@ -427,4 +428,25 @@ String ClientCommandProcessor::swap(String const& argumentsString) { return "Failed to swap player"; } +String ClientCommandProcessor::respawnInWorld() { + WorldClientPtr worldClient = m_universeClient->worldClient(); + + // Make sure we got the worldClient + if (!worldClient) { + return "Error: Unable to access world client."; + } + + if (worldClient->toggleRespawnInWorld()) { + // Convert boolean to string for the response + const std::string result = worldClient->respawnInWorld() ? "true" : "false"; + + return "Successfully switched respawn in this world to " + result; + } + else + return "Failed to switch respawn in this world!"; + + // This should never trigger, but its better to have it than not :3 + return "Something unforseen happend!"; } + +} \ No newline at end of file diff --git a/source/frontend/StarClientCommandProcessor.hpp b/source/frontend/StarClientCommandProcessor.hpp index b06f3d5..658242c 100644 --- a/source/frontend/StarClientCommandProcessor.hpp +++ b/source/frontend/StarClientCommandProcessor.hpp @@ -58,6 +58,7 @@ private: String enableTech(String const& argumentsString); String upgradeShip(String const& argumentsString); String swap(String const& argumentsString); + String respawnInWorld(); UniverseClientPtr m_universeClient; CinematicPtr m_cinematicOverlay; diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 9e0478a..afe71ac 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -2421,4 +2421,16 @@ void WorldClient::setupForceRegions() { } } +bool WorldClient::toggleRespawnInWorld() { + // Setting oldValue to check if m_respawnInWorld triggered correctly later + const bool oldValue = respawnInWorld(); + + m_respawnInWorld ^= true; + + if (respawnInWorld() != oldValue) { + return true; + } + return false; +} + } diff --git a/source/game/StarWorldClient.hpp b/source/game/StarWorldClient.hpp index e00a3b8..2f1cbc0 100644 --- a/source/game/StarWorldClient.hpp +++ b/source/game/StarWorldClient.hpp @@ -175,6 +175,9 @@ public: typedef std::function BroadcastCallback; BroadcastCallback& broadcastCallback(); + + bool toggleRespawnInWorld(); + private: static const float DropDist; From 732fc2a9d7e9a4c5e3cf01ac191a392462f3da8c Mon Sep 17 00:00:00 2001 From: lonaasan Date: Mon, 9 Sep 2024 11:27:14 +0200 Subject: [PATCH 4/8] [Revision] Applying the recommended changes from pull request #110 (return current value if no argument given, moving the methods to their correct location) --- .../frontend/StarClientCommandProcessor.cpp | 40 ++++++++++++------- .../frontend/StarClientCommandProcessor.hpp | 2 +- source/game/StarWorldClient.cpp | 22 +++++----- source/game/StarWorldClient.hpp | 4 +- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/source/frontend/StarClientCommandProcessor.cpp b/source/frontend/StarClientCommandProcessor.cpp index 39b0d89..0237735 100644 --- a/source/frontend/StarClientCommandProcessor.cpp +++ b/source/frontend/StarClientCommandProcessor.cpp @@ -52,7 +52,7 @@ ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient, {"enabletech", bind(&ClientCommandProcessor::enableTech, this, _1)}, {"upgradeship", bind(&ClientCommandProcessor::upgradeShip, this, _1)}, {"swap", bind(&ClientCommandProcessor::swap, this, _1)}, - {"respawnInWorld", bind(&ClientCommandProcessor::respawnInWorld, this)} + {"respawnInWorld", bind(&ClientCommandProcessor::respawnInWorld, this, _1)} }; } @@ -428,25 +428,37 @@ String ClientCommandProcessor::swap(String const& argumentsString) { return "Failed to swap player"; } -String ClientCommandProcessor::respawnInWorld() { +String ClientCommandProcessor::respawnInWorld(String const& argumentsString) { + auto arguments = m_parser.tokenizeToStringList(argumentsString); + + WorldClientPtr worldClient = m_universeClient->worldClient(); - // Make sure we got the worldClient - if (!worldClient) { - return "Error: Unable to access world client."; + + if (arguments.size() == 0) { + const std::string stringResult = worldClient->respawnInWorld() ? "true" : "false"; + return "Respawn in this world is currently " + stringResult; // return the current state of the respawn value when no argument is given + } + if (arguments.size() > 1) { + return "Too many arguments for this command!"; // we dont wanna have too much, right? } - if (worldClient->toggleRespawnInWorld()) { + // behold: probably one of the least efficient ways to convert a Star::String to a boolean + bool value; + if (arguments[0].toLower() == "true") { + value = true; + } else if(arguments[0].toLower() == "false") { + value = false; + } + else { + return "Invalid argument!"; // at least we get validation if it was not a boolean + } + + bool result = worldClient->setRespawnInWorld(value); // Convert boolean to string for the response - const std::string result = worldClient->respawnInWorld() ? "true" : "false"; + const std::string stringResult = result ? "true" : "false"; - return "Successfully switched respawn in this world to " + result; - } - else - return "Failed to switch respawn in this world!"; - - // This should never trigger, but its better to have it than not :3 - return "Something unforseen happend!"; + return "Successfully set respawn in this world to " + stringResult; } } \ No newline at end of file diff --git a/source/frontend/StarClientCommandProcessor.hpp b/source/frontend/StarClientCommandProcessor.hpp index 658242c..94dad5d 100644 --- a/source/frontend/StarClientCommandProcessor.hpp +++ b/source/frontend/StarClientCommandProcessor.hpp @@ -58,7 +58,7 @@ private: String enableTech(String const& argumentsString); String upgradeShip(String const& argumentsString); String swap(String const& argumentsString); - String respawnInWorld(); + String respawnInWorld(String const& argumentsString); UniverseClientPtr m_universeClient; CinematicPtr m_cinematicOverlay; diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index afe71ac..0d3e039 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -142,6 +142,16 @@ bool WorldClient::respawnInWorld() const { return m_respawnInWorld; } +bool WorldClient::setRespawnInWorld(bool value = NULL) { + + if (value != NULL) + m_respawnInWorld = value; + else + m_respawnInWorld ^= true; // dont know if we still want to set the respawn if no argument is given here + + return m_respawnInWorld; +} + void WorldClient::removeEntity(EntityId entityId, bool andDie) { auto entity = m_entityMap->entity(entityId); if (!entity) @@ -2421,16 +2431,4 @@ void WorldClient::setupForceRegions() { } } -bool WorldClient::toggleRespawnInWorld() { - // Setting oldValue to check if m_respawnInWorld triggered correctly later - const bool oldValue = respawnInWorld(); - - m_respawnInWorld ^= true; - - if (respawnInWorld() != oldValue) { - return true; - } - return false; -} - } diff --git a/source/game/StarWorldClient.hpp b/source/game/StarWorldClient.hpp index 2f1cbc0..9f15e0e 100644 --- a/source/game/StarWorldClient.hpp +++ b/source/game/StarWorldClient.hpp @@ -109,6 +109,8 @@ public: void reviveMainPlayer(); bool respawnInWorld() const; + bool setRespawnInWorld(bool value); + void removeEntity(EntityId entityId, bool andDie); WorldTemplateConstPtr currentTemplate() const; @@ -176,7 +178,7 @@ public: typedef std::function BroadcastCallback; BroadcastCallback& broadcastCallback(); - bool toggleRespawnInWorld(); + private: static const float DropDist; From 227585f1dc027dec43152a409dbadb26b19e2c3d Mon Sep 17 00:00:00 2001 From: lonaasan Date: Mon, 9 Sep 2024 11:35:40 +0200 Subject: [PATCH 5/8] [bugfix] removed check in setRespawnWorld due to the nature of NULL --- source/game/StarWorldClient.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 0d3e039..3e85c79 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -142,12 +142,9 @@ bool WorldClient::respawnInWorld() const { return m_respawnInWorld; } -bool WorldClient::setRespawnInWorld(bool value = NULL) { +bool WorldClient::setRespawnInWorld(bool value) { - if (value != NULL) - m_respawnInWorld = value; - else - m_respawnInWorld ^= true; // dont know if we still want to set the respawn if no argument is given here + m_respawnInWorld = value; return m_respawnInWorld; } From 95b13f670d8ce1de5c71c35ce475de165b53cc4f Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:32:23 +1000 Subject: [PATCH 6/8] code clean-up --- assets/opensb/help.config.patch | 2 +- .../frontend/StarClientCommandProcessor.cpp | 43 +++++-------------- source/game/StarWorldClient.cpp | 7 +-- source/game/StarWorldClient.hpp | 3 +- 4 files changed, 15 insertions(+), 40 deletions(-) diff --git a/assets/opensb/help.config.patch b/assets/opensb/help.config.patch index b3f31a6..ad1da12 100644 --- a/assets/opensb/help.config.patch +++ b/assets/opensb/help.config.patch @@ -11,6 +11,6 @@ "openSbCommands": { "swap": "Usage /swap . Swaps the current character, case-insensitive, only substring required.", - "respawninworld": "Usage /respawnInWorld. Sets the respawn flag for the current world until you teleport away." + "respawninworld": "Usage /respawninworld. Sets the respawn flag for the current world until you teleport away." } } diff --git a/source/frontend/StarClientCommandProcessor.cpp b/source/frontend/StarClientCommandProcessor.cpp index 0237735..8a7e543 100644 --- a/source/frontend/StarClientCommandProcessor.cpp +++ b/source/frontend/StarClientCommandProcessor.cpp @@ -15,9 +15,9 @@ namespace Star { ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient, CinematicPtr cinematicOverlay, - MainInterfacePaneManager* paneManager, StringMap macroCommands) - : m_universeClient(std::move(universeClient)), m_cinematicOverlay(std::move(cinematicOverlay)), - m_paneManager(paneManager), m_macroCommands(std::move(macroCommands)) { + MainInterfacePaneManager* paneManager, StringMap macroCommands) + : m_universeClient(std::move(universeClient)), m_cinematicOverlay(std::move(cinematicOverlay)), + m_paneManager(paneManager), m_macroCommands(std::move(macroCommands)) { m_builtinCommands = { {"reload", bind(&ClientCommandProcessor::reload, this)}, {"whoami", bind(&ClientCommandProcessor::whoami, this)}, @@ -58,7 +58,7 @@ ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient, bool ClientCommandProcessor::adminCommandAllowed() const { return Root::singleton().configuration()->get("allowAdminCommandsFromAnyone").toBool() || - m_universeClient->mainPlayer()->isAdmin(); + m_universeClient->mainPlayer()->isAdmin(); } String ClientCommandProcessor::previewQuestPane(StringList const& arguments, function createPane) { @@ -187,7 +187,7 @@ String ClientCommandProcessor::setGravity(String const& argumentsString) { return "You must be an admin to use this command."; m_universeClient->worldClient()->overrideGravity(lexicalCast(arguments.at(0))); - return strf("Gravity set to {}, the change is LOCAL ONLY", arguments.at(0)); + return strf("Gravity set to {} (This is client-side!)", arguments.at(0)); } String ClientCommandProcessor::resetGravity() { @@ -431,34 +431,13 @@ String ClientCommandProcessor::swap(String const& argumentsString) { String ClientCommandProcessor::respawnInWorld(String const& argumentsString) { auto arguments = m_parser.tokenizeToStringList(argumentsString); + if (arguments.size() == 0) + return strf("Respawn in this world is currently {}", worldClient->respawnInWorld() ? "true" : "false"); - WorldClientPtr worldClient = m_universeClient->worldClient(); - - - if (arguments.size() == 0) { - const std::string stringResult = worldClient->respawnInWorld() ? "true" : "false"; - return "Respawn in this world is currently " + stringResult; // return the current state of the respawn value when no argument is given - } - if (arguments.size() > 1) { - return "Too many arguments for this command!"; // we dont wanna have too much, right? - } - - // behold: probably one of the least efficient ways to convert a Star::String to a boolean - bool value; - if (arguments[0].toLower() == "true") { - value = true; - } else if(arguments[0].toLower() == "false") { - value = false; - } - else { - return "Invalid argument!"; // at least we get validation if it was not a boolean - } - - bool result = worldClient->setRespawnInWorld(value); - // Convert boolean to string for the response - const std::string stringResult = result ? "true" : "false"; - - return "Successfully set respawn in this world to " + stringResult; + bool respawnInWorld = Json::parse(arguments.at(0)).toBool(); + auto worldClient = m_universeClient->worldClient(); + worldClient->setRespawnInWorld(respawnInWorld); + return strf("Respawn in this world set to {} (This is client-side!)", respawnInWorld ? "true" : "false"); } } \ No newline at end of file diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 3e85c79..8abfcdf 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -142,11 +142,8 @@ bool WorldClient::respawnInWorld() const { return m_respawnInWorld; } -bool WorldClient::setRespawnInWorld(bool value) { - - m_respawnInWorld = value; - - return m_respawnInWorld; +void WorldClient::setRespawnInWorld(bool respawnInWorld) { + m_respawnInWorld = respawnInWorld; } void WorldClient::removeEntity(EntityId entityId, bool andDie) { diff --git a/source/game/StarWorldClient.hpp b/source/game/StarWorldClient.hpp index 9f15e0e..1616b10 100644 --- a/source/game/StarWorldClient.hpp +++ b/source/game/StarWorldClient.hpp @@ -108,8 +108,7 @@ public: bool mainPlayerDead() const; void reviveMainPlayer(); bool respawnInWorld() const; - - bool setRespawnInWorld(bool value); + void setRespawnInWorld(bool respawnInWorld); void removeEntity(EntityId entityId, bool andDie); From f59f6be5d33c64f8d0f335f6f6993f05a939afb5 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:35:08 +1000 Subject: [PATCH 7/8] oop --- source/frontend/StarClientCommandProcessor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/frontend/StarClientCommandProcessor.cpp b/source/frontend/StarClientCommandProcessor.cpp index 8a7e543..ac87397 100644 --- a/source/frontend/StarClientCommandProcessor.cpp +++ b/source/frontend/StarClientCommandProcessor.cpp @@ -430,12 +430,12 @@ String ClientCommandProcessor::swap(String const& argumentsString) { String ClientCommandProcessor::respawnInWorld(String const& argumentsString) { auto arguments = m_parser.tokenizeToStringList(argumentsString); - + auto worldClient = m_universeClient->worldClient(); + if (arguments.size() == 0) return strf("Respawn in this world is currently {}", worldClient->respawnInWorld() ? "true" : "false"); bool respawnInWorld = Json::parse(arguments.at(0)).toBool(); - auto worldClient = m_universeClient->worldClient(); worldClient->setRespawnInWorld(respawnInWorld); return strf("Respawn in this world set to {} (This is client-side!)", respawnInWorld ? "true" : "false"); } From 1f5e8a462908a7c6e7eac5b53c70749837d29c64 Mon Sep 17 00:00:00 2001 From: floydinator-git <78954063+floydinator-git@users.noreply.github.com> Date: Tue, 10 Sep 2024 23:04:09 -0400 Subject: [PATCH 8/8] Fix ImageMetadataDatabase::calculateImageSize calling Image::readPngMetadata on non-PNG images. --- source/core/StarImage.cpp | 6 ++++++ source/core/StarImage.hpp | 1 + source/game/StarImageMetadataDatabase.cpp | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/source/core/StarImage.cpp b/source/core/StarImage.cpp index 82e3b05..52c2370 100644 --- a/source/core/StarImage.cpp +++ b/source/core/StarImage.cpp @@ -17,6 +17,12 @@ void readPngData(png_structp pngPtr, png_bytep data, png_size_t length) { ((IODevice*)png_get_io_ptr(pngPtr))->readFull((char*)data, length); }; +bool Image::isPng(IODevicePtr device) { + png_byte header[8]; + device->readAbsolute(0, (char*)header, sizeof(header)); + return !png_sig_cmp(header, 0, sizeof(header)); +} + Image Image::readPng(IODevicePtr device) { png_byte header[8]; device->readFull((char*)header, sizeof(header)); diff --git a/source/core/StarImage.hpp b/source/core/StarImage.hpp index 478d074..aac0105 100644 --- a/source/core/StarImage.hpp +++ b/source/core/StarImage.hpp @@ -27,6 +27,7 @@ STAR_CLASS(Image); class Image { public: static Image readPng(IODevicePtr device); + static bool isPng(IODevicePtr device); // Returns the size and pixel format that would be constructed from the given // png file, without actually loading it. static tuple readPngMetadata(IODevicePtr device); diff --git a/source/game/StarImageMetadataDatabase.cpp b/source/game/StarImageMetadataDatabase.cpp index bf84e51..d04e984 100644 --- a/source/game/StarImageMetadataDatabase.cpp +++ b/source/game/StarImageMetadataDatabase.cpp @@ -174,7 +174,11 @@ Vec2U ImageMetadataDatabase::calculateImageSize(AssetPath const& path) const { imageSize = *size; } else { locker.unlock(); - imageSize = get<0>(Image::readPngMetadata(assets->openFile(path.basePath))); + auto file = assets->openFile(path.basePath); + if (Image::isPng(file)) + imageSize = get<0>(Image::readPngMetadata(file)); + else + imageSize = fallback(); locker.lock(); m_sizeCache[path.basePath] = imageSize; }