diff --git a/src/openrct2-ui/UiContext.Android.cpp b/src/openrct2-ui/UiContext.Android.cpp index 6c633de740..b0dac35ba0 100644 --- a/src/openrct2-ui/UiContext.Android.cpp +++ b/src/openrct2-ui/UiContext.Android.cpp @@ -60,7 +60,7 @@ namespace OpenRCT2::Ui std::string ShowFileDialog(SDL_Window* window, const FileDialogDesc& desc) override { - STUB(); + LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__); return nullptr; } @@ -68,7 +68,7 @@ namespace OpenRCT2::Ui std::string ShowDirectoryDialog(SDL_Window* window, const std::string& title) override { LOG_INFO(title.c_str()); - STUB(); + LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__); return "/sdcard/rct2"; } @@ -79,7 +79,7 @@ namespace OpenRCT2::Ui void OpenURL(const std::string& url) override { - STUB(); + LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__); } bool HasFilePicker() const override diff --git a/src/openrct2-ui/UiContext.Linux.cpp b/src/openrct2-ui/UiContext.Linux.cpp index c1b3b85b58..e605d89f5c 100644 --- a/src/openrct2-ui/UiContext.Linux.cpp +++ b/src/openrct2-ui/UiContext.Linux.cpp @@ -22,6 +22,7 @@ # include # include # include +# include namespace OpenRCT2::Ui { diff --git a/src/openrct2-ui/UiContext.macOS.mm b/src/openrct2-ui/UiContext.macOS.mm index 5e211f2fb6..543c9e641a 100644 --- a/src/openrct2-ui/UiContext.macOS.mm +++ b/src/openrct2-ui/UiContext.macOS.mm @@ -49,7 +49,7 @@ namespace OpenRCT2::Ui bool IsSteamOverlayAttached() override { - STUB(); + LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__); return false; } diff --git a/src/openrct2/CommandLineSprite.cpp b/src/openrct2/CommandLineSprite.cpp index f62df01455..30b94954d4 100644 --- a/src/openrct2/CommandLineSprite.cpp +++ b/src/openrct2/CommandLineSprite.cpp @@ -15,6 +15,7 @@ #include "core/Imaging.h" #include "core/Json.hpp" #include "core/Path.hpp" +#include "core/String.hpp" #include "drawing/Drawing.h" #include "drawing/ImageImporter.h" #include "object/ObjectLimits.h" @@ -270,7 +271,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc) if (argc == 0) return -1; - if (_strcmpi(argv[0], "details") == 0) + if (String::IEquals(argv[0], "details")) { if (argc < 2) { @@ -317,7 +318,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc) return 1; } - if (_strcmpi(argv[0], "export") == 0) + if (String::IEquals(argv[0], "export")) { if (argc < 4) { @@ -351,7 +352,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc) return 1; } - if (_strcmpi(argv[0], "exportall") == 0) + if (String::IEquals(argv[0], "exportall")) { if (argc < 3) { @@ -396,7 +397,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc) return 1; } - if (_strcmpi(argv[0], "exportalldat") == 0) + if (String::IEquals(argv[0], "exportalldat")) { if (argc < 3) { @@ -457,7 +458,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc) return 1; } - if (_strcmpi(argv[0], "create") == 0) + if (String::IEquals(argv[0], "create")) { if (argc < 2) { @@ -472,7 +473,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc) return 1; } - if (_strcmpi(argv[0], "append") == 0) + if (String::IEquals(argv[0], "append")) { if (argc != 3 && argc != 5) { @@ -524,7 +525,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc) return 1; } - if (_strcmpi(argv[0], "build") == 0) + if (String::IEquals(argv[0], "build")) { if (argc < 3) { @@ -612,7 +613,7 @@ int32_t CommandLineForSprite(const char** argv, int32_t argc) return 1; } - if (_strcmpi(argv[0], "combine") == 0) + if (String::IEquals(argv[0], "combine")) { return CommandLineForSpriteCombine(argv, argc); } diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 734ac5914f..5d1e8072a9 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -21,6 +21,7 @@ #include "actions/ResultWithMessage.h" #include "audio/audio.h" #include "core/Path.hpp" +#include "core/String.hpp" #include "entity/EntityList.h" #include "entity/EntityRegistry.h" #include "entity/Guest.h" @@ -263,7 +264,7 @@ namespace Editor if (!loadSuccess) return false; - if (_stricmp(extension, ".sv4") == 0 || _stricmp(extension, ".sv6") == 0 || _stricmp(extension, ".sv7") == 0) + if (String::IEquals(extension, ".sv4") || String::IEquals(extension, ".sv6") || String::IEquals(extension, ".sv7") == 0) { loadedFromSave = true; } diff --git a/src/openrct2/common.h b/src/openrct2/common.h index 3750f0cf0a..962fd38370 100644 --- a/src/openrct2/common.h +++ b/src/openrct2/common.h @@ -37,30 +37,6 @@ using colour_t = uint8_t; // Gets the name of a symbol as a C string #define nameof(symbol) #symbol -#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) -# include -# define STUB() LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__) -# define _strcmpi _stricmp -# define _stricmp(x, y) strcasecmp((x), (y)) -# define _strnicmp(x, y, n) strncasecmp((x), (y), (n)) - -# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -# define RCT2_ENDIANNESS __ORDER_LITTLE_ENDIAN__ -# define LOBYTE(w) (static_cast(w)) -# define HIBYTE(w) (static_cast((static_cast(w) >> 8) & 0xFF)) -# endif // __BYTE_ORDER__ - -# ifndef RCT2_ENDIANNESS -# error Unknown endianness! -# endif // RCT2_ENDIANNESS - -#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) - -// BSD and macOS have MAP_ANON instead of MAP_ANONYMOUS -#ifndef MAP_ANONYMOUS -# define MAP_ANONYMOUS MAP_ANON -#endif - #define OPENRCT2_MASTER_SERVER_URL "https://servers.openrct2.io" // Time (represented as number of 100-nanosecond intervals since 0001-01-01T00:00:00Z) diff --git a/src/openrct2/core/String.cpp b/src/openrct2/core/String.cpp index ccdd7d0fbf..e9a27b68c3 100644 --- a/src/openrct2/core/String.cpp +++ b/src/openrct2/core/String.cpp @@ -33,6 +33,11 @@ #include "String.hpp" #include "StringBuilder.h" +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +# include +# define _stricmp(x, y) strcasecmp((x), (y)) +#endif + namespace String { std::string ToStd(const utf8* str) diff --git a/src/openrct2/core/String.hpp b/src/openrct2/core/String.hpp index 49389b0804..5213823813 100644 --- a/src/openrct2/core/String.hpp +++ b/src/openrct2/core/String.hpp @@ -57,8 +57,20 @@ namespace String int32_t Compare(const std::string& a, const std::string& b, bool ignoreCase = false); int32_t Compare(const utf8* a, const utf8* b, bool ignoreCase = false); bool Equals(std::string_view a, std::string_view b, bool ignoreCase = false); + inline bool IEquals(std::string_view a, std::string_view b) + { + return Equals(a, b, true); + } bool Equals(const std::string& a, const std::string& b, bool ignoreCase = false); + inline bool IEquals(const std::string& a, const std::string& b) + { + return Equals(a, b, true); + } bool Equals(const utf8* a, const utf8* b, bool ignoreCase = false); + inline bool IEquals(const utf8* a, const utf8* b) + { + return Equals(a, b, true); + } bool StartsWith(std::string_view str, std::string_view match, bool ignoreCase = false); bool EndsWith(std::string_view str, std::string_view match, bool ignoreCase = false); bool Contains(std::string_view haystack, std::string_view needle, bool ignoreCase = false); diff --git a/src/openrct2/core/ZipAndroid.cpp b/src/openrct2/core/ZipAndroid.cpp index 6b1083fa9a..13cf768e4f 100644 --- a/src/openrct2/core/ZipAndroid.cpp +++ b/src/openrct2/core/ZipAndroid.cpp @@ -121,17 +121,17 @@ public: void SetFileData(std::string_view path, std::vector&& data) override { - STUB(); + LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__); } void DeleteFile(std::string_view) override { - STUB(); + LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__); } void RenameFile(std::string_view, std::string_view) override { - STUB(); + LOG_WARNING("Function %s at %s:%d is a stub.", __PRETTY_FUNCTION__, __FILE__, __LINE__); } }; diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index 158c34039b..8e29f6c081 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -17,6 +17,7 @@ #include "../core/DataSerialiser.h" #include "../core/Guard.hpp" #include "../core/Numerics.hpp" +#include "../core/String.hpp" #include "../entity/Balloon.h" #include "../entity/EntityRegistry.h" #include "../entity/MoneyEffect.h" @@ -587,8 +588,10 @@ int32_t Guest::GetEasterEggNameId() const FormatStringLegacy(buffer, sizeof(buffer), STR_STRINGID, ft.Data()); for (uint32_t i = 0; i < std::size(gPeepEasterEggNames); i++) - if (_stricmp(buffer, gPeepEasterEggNames[i]) == 0) + { + if (String::IEquals(buffer, gPeepEasterEggNames[i])) return static_cast(i); + } return -1; } @@ -733,7 +736,7 @@ int32_t Guest::CheckEasterEggName(int32_t index) const FormatNameTo(ft); FormatStringLegacy(buffer, sizeof(buffer), STR_STRINGID, ft.Data()); - return _stricmp(buffer, gPeepEasterEggNames[index]) == 0; + return String::IEquals(buffer, gPeepEasterEggNames[index]); } void Guest::Loc68F9F3() diff --git a/src/openrct2/interface/Screenshot.cpp b/src/openrct2/interface/Screenshot.cpp index 24ec108206..0f06bd9ff3 100644 --- a/src/openrct2/interface/Screenshot.cpp +++ b/src/openrct2/interface/Screenshot.cpp @@ -21,6 +21,7 @@ #include "../core/File.h" #include "../core/Imaging.h" #include "../core/Path.hpp" +#include "../core/String.hpp" #include "../drawing/Drawing.h" #include "../drawing/X8DrawingEngine.h" #include "../localisation/Formatter.h" @@ -574,7 +575,7 @@ int32_t CommandLineForScreenshot(const char** argv, int32_t argc, ScreenshotOpti } } - bool giantScreenshot = (argc == 5) && _stricmp(argv[2], "giant") == 0; + bool giantScreenshot = (argc == 5) && String::IEquals(argv[2], "giant"); if (argc != 4 && argc != 8 && !giantScreenshot) { std::printf("Usage: openrct2 screenshot [ ]\n"); diff --git a/src/openrct2/network/Socket.cpp b/src/openrct2/network/Socket.cpp index 0446594d25..29fc1bb6b4 100644 --- a/src/openrct2/network/Socket.cpp +++ b/src/openrct2/network/Socket.cpp @@ -49,8 +49,10 @@ #include #include #include + #include #include #include + #include #include "../common.h" using SOCKET = int32_t; #define SOCKET_ERROR -1 diff --git a/src/openrct2/platform/Platform.Linux.cpp b/src/openrct2/platform/Platform.Linux.cpp index c86c36e9a6..30e4b5d149 100644 --- a/src/openrct2/platform/Platform.Linux.cpp +++ b/src/openrct2/platform/Platform.Linux.cpp @@ -14,6 +14,7 @@ # include # include # include +# include # include # if defined(__FreeBSD__) || defined(__NetBSD__) # include diff --git a/src/openrct2/platform/Platform.Posix.cpp b/src/openrct2/platform/Platform.Posix.cpp index 381d96100f..88c229fc33 100644 --- a/src/openrct2/platform/Platform.Posix.cpp +++ b/src/openrct2/platform/Platform.Posix.cpp @@ -29,6 +29,7 @@ # include # include # include +# include // The name of the mutex used to prevent multiple instances of the game from running static constexpr const utf8* SINGLE_INSTANCE_MUTEX_NAME = u8"openrct2.lock"; diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 9bbbb40242..b7c77b55f5 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -172,7 +172,7 @@ namespace RCT2 if (!path.empty()) { auto extension = Path::GetExtension(path); - _isSV7 = _stricmp(extension.c_str(), ".sv7") == 0; + _isSV7 = String::IEquals(extension, ".sv7"); } chunkReader.ReadChunk(&_s6.Objects, sizeof(_s6.Objects)); diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 935e12821e..214d157e05 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -860,11 +860,11 @@ static uint8_t vehicle_sounds_update_get_pan_volume(OpenRCT2::Audio::VehicleSoun if (pan_y > 0) { pan_y = (0x400 - pan_y) / 4; - vol1 = LOBYTE(pan_y); - if (static_cast(HIBYTE(pan_y)) != 0) + vol1 = LoByte(pan_y); + if (static_cast(HiByte(pan_y)) != 0) { vol1 = 0xFF; - if (static_cast(HIBYTE(pan_y)) < 0) + if (static_cast(HiByte(pan_y)) < 0) { vol1 = 0; } @@ -878,11 +878,11 @@ static uint8_t vehicle_sounds_update_get_pan_volume(OpenRCT2::Audio::VehicleSoun if (pan_x > 0) { pan_x = (0x400 - pan_x) / 4; - vol2 = LOBYTE(pan_x); - if (static_cast(HIBYTE(pan_x)) != 0) + vol2 = LoByte(pan_x); + if (static_cast(HiByte(pan_x)) != 0) { vol2 = 0xFF; - if (static_cast(HIBYTE(pan_x)) < 0) + if (static_cast(HiByte(pan_x)) < 0) { vol2 = 0; } diff --git a/src/openrct2/title/TitleSequence.cpp b/src/openrct2/title/TitleSequence.cpp index 4f349eb584..69261a2e0f 100644 --- a/src/openrct2/title/TitleSequence.cpp +++ b/src/openrct2/title/TitleSequence.cpp @@ -342,7 +342,7 @@ namespace OpenRCT2::Title if (token[0] != 0) { - if (_stricmp(token, "LOAD") == 0) + if (String::IEquals(token, "LOAD")) { auto saveIndex = SAVE_INDEX_INVALID; const std::string relativePath = parts[1].data(); @@ -356,48 +356,48 @@ namespace OpenRCT2::Title } command = LoadParkCommand{ saveIndex }; } - else if (_stricmp(token, "LOCATION") == 0) + else if (String::IEquals(token, "LOCATION")) { uint8_t locationX = atoi(parts[1].data()) & 0xFF; uint8_t locationY = atoi(parts[2].data()) & 0xFF; command = SetLocationCommand{ locationX, locationY }; } - else if (_stricmp(token, "ROTATE") == 0) + else if (String::IEquals(token, "ROTATE")) { uint8_t rotations = atoi(parts[1].data()) & 0xFF; command = RotateViewCommand{ rotations }; } - else if (_stricmp(token, "ZOOM") == 0) + else if (String::IEquals(token, "ZOOM")) { uint8_t zoom = atoi(parts[1].data()) & 0xFF; command = SetZoomCommand{ zoom }; } - else if (_stricmp(token, "SPEED") == 0) + else if (String::IEquals(token, "SPEED")) { uint8_t speed = std::max(1, std::min(4, atoi(parts[1].data()) & 0xFF)); command = SetSpeedCommand{ speed }; } - else if (_stricmp(token, "FOLLOW") == 0) + else if (String::IEquals(token, "FOLLOW")) { auto entityID = EntityId::FromUnderlying(atoi(parts[1].data()) & 0xFFFF); auto followCommand = FollowEntityCommand{ entityID }; SafeStrCpy(followCommand.Follow.SpriteName, parts[2].data(), USER_STRING_MAX_LENGTH); command = followCommand; } - else if (_stricmp(token, "WAIT") == 0) + else if (String::IEquals(token, "WAIT")) { uint16_t milliseconds = atoi(parts[1].data()) & 0xFFFF; command = WaitCommand{ milliseconds }; } - else if (_stricmp(token, "RESTART") == 0) + else if (String::IEquals(token, "RESTART")) { command = RestartCommand{}; } - else if (_stricmp(token, "END") == 0) + else if (String::IEquals(token, "END")) { command = EndCommand{}; } - else if (_stricmp(token, "LOADSC") == 0) + else if (String::IEquals(token, "LOADSC")) { auto loadScenarioCommand = LoadScenarioCommand{}; SafeStrCpy(loadScenarioCommand.Scenario, parts[1].data(), sizeof(loadScenarioCommand.Scenario)); @@ -446,12 +446,12 @@ namespace OpenRCT2::Title if (!whitespace) { if (part == 0 - && ((cindex == 4 && _strnicmp(parts[0].data(), "LOAD", 4) == 0) - || (cindex == 6 && _strnicmp(parts[0].data(), "LOADSC", 6) == 0))) + && ((cindex == 4 && String::StartsWith(parts[0].data(), "LOAD", true)) + || (cindex == 6 && String::StartsWith(parts[0].data(), "LOADSC", true)))) { load = true; } - else if (part == 0 && cindex == 6 && _strnicmp(parts[0].data(), "FOLLOW", 6) == 0) + else if (part == 0 && cindex == 6 && String::StartsWith(parts[0].data(), "FOLLOW", true)) { sprite = true; } diff --git a/src/openrct2/title/TitleSequenceManager.cpp b/src/openrct2/title/TitleSequenceManager.cpp index 5a4d157d37..acb7e2e5f7 100644 --- a/src/openrct2/title/TitleSequenceManager.cpp +++ b/src/openrct2/title/TitleSequenceManager.cpp @@ -186,7 +186,7 @@ namespace TitleSequenceManager { return a.PredefinedIndex < b.PredefinedIndex; } - return _strcmpi(a.Name.c_str(), b.Name.c_str()) < 0; + return String::Compare(a.Name, b.Name, true) < 0; }); } diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index ef3809a0b2..03ea13c960 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -68,3 +68,13 @@ template constexpr auto EnumValue(TEnum enumerator) noexcept { return static_cast>(enumerator); } + +constexpr uint8_t HiByte(uint16_t value) +{ + return static_cast(value >> 8); +} + +constexpr uint8_t LoByte(uint16_t value) +{ + return static_cast(value & 0xFFU); +} diff --git a/test/tests/Pathfinding.cpp b/test/tests/Pathfinding.cpp index 71fbe3038e..b956ead827 100644 --- a/test/tests/Pathfinding.cpp +++ b/test/tests/Pathfinding.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -57,7 +58,7 @@ protected: for (auto& ride : GetRideManager()) { auto thisName = ride.GetName(); - if (!_strnicmp(thisName.c_str(), name, sizeof(thisName))) + if (String::StartsWith(thisName, u8string{ name }, true)) { return &ride; }