diff --git a/desktop_version/CMakeLists.txt b/desktop_version/CMakeLists.txt index 1ebc5862..f8ab0850 100644 --- a/desktop_version/CMakeLists.txt +++ b/desktop_version/CMakeLists.txt @@ -117,6 +117,7 @@ SET(VVV_SRC src/XMLUtils.cpp src/main.cpp src/Network.c + src/ThirdPartyDeps.c ) IF(NOT CUSTOM_LEVEL_SUPPORT STREQUAL "DISABLED") LIST(APPEND VVV_SRC src/editor.cpp) @@ -232,6 +233,8 @@ ADD_LIBRARY(tinyxml2-static STATIC ${XML2_SRC}) ADD_LIBRARY(physfs-static STATIC ${PFS_SRC} ${PFSP_SRC}) ADD_LIBRARY(lodepng-static STATIC ${PNG_SRC}) +TARGET_COMPILE_DEFINITIONS(lodepng-static PRIVATE -DLODEPNG_NO_COMPILE_ALLOCATORS) + # Static Dependencies TARGET_LINK_LIBRARIES(VVVVVV physfs-static tinyxml2-static lodepng-static) diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index df78da55..ecbca62f 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -235,7 +235,7 @@ void FILESYSTEM_loadFileToMemory( size_t *len, bool addnull ) { - if (strcmp(name, "levels/special/stdin.vvvvvv") == 0) + if (SDL_strcmp(name, "levels/special/stdin.vvvvvv") == 0) { // this isn't *technically* necessary when piping directly from a file, but checking for that is annoying static std::vector STDIN_BUFFER; @@ -255,7 +255,7 @@ void FILESYSTEM_loadFileToMemory( } ++length; - *mem = static_cast(malloc(length)); // STDIN_BUFFER.data() causes double-free + *mem = static_cast(SDL_malloc(length)); // STDIN_BUFFER.data() causes double-free std::copy(STDIN_BUFFER.begin(), STDIN_BUFFER.end(), reinterpret_cast(*mem)); return; } @@ -272,12 +272,12 @@ void FILESYSTEM_loadFileToMemory( } if (addnull) { - *mem = (unsigned char *) malloc(length + 1); + *mem = (unsigned char *) SDL_malloc(length + 1); (*mem)[length] = 0; } else { - *mem = (unsigned char*) malloc(length); + *mem = (unsigned char*) SDL_malloc(length); } int success = PHYSFS_readBytes(handle, *mem, length); if (success == -1) @@ -289,7 +289,7 @@ void FILESYSTEM_loadFileToMemory( void FILESYSTEM_freeMemory(unsigned char **mem) { - free(*mem); + SDL_free(*mem); *mem = NULL; } @@ -331,7 +331,7 @@ std::vector FILESYSTEM_getLevelDirFileNames() for (i = fileList; *i != NULL; i++) { - if (strcmp(*i, "data") == 0) + if (SDL_strcmp(*i, "data") == 0) { continue; /* FIXME: lolwut -flibit */ } @@ -369,18 +369,19 @@ static void PLATFORM_migrateSaveData(char* output) DIR *subDir = NULL; struct dirent *subDe = NULL; char subDirLocation[MAX_PATH]; - const char *homeDir = getenv("HOME"); + const char *homeDir = SDL_getenv("HOME"); if (homeDir == NULL) { /* Uhh, I don't want to get near this. -flibit */ return; } - strcpy(oldDirectory, homeDir); + const char oldPath[] = #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) || defined(__DragonFly__) - strcat(oldDirectory, "/.vvvvvv/"); + "/.vvvvvv/"; #elif defined(__APPLE__) - strcat(oldDirectory, "/Documents/VVVVVV/"); + "/Documents/VVVVVV/"; #endif + SDL_snprintf(oldDirectory, sizeof(oldDirectory), "%s%s", homeDir, oldPath); dir = opendir(oldDirectory); if (!dir) { @@ -391,47 +392,37 @@ static void PLATFORM_migrateSaveData(char* output) printf("Migrating old savedata to new location...\n"); for (de = readdir(dir); de != NULL; de = readdir(dir)) { - if ( strcmp(de->d_name, "..") == 0 || - strcmp(de->d_name, ".") == 0 ) + if ( SDL_strcmp(de->d_name, "..") == 0 || + SDL_strcmp(de->d_name, ".") == 0 ) { continue; } #define COPY_SAVEFILE(name) \ - else if (strcmp(de->d_name, name) == 0) \ + else if (SDL_strcmp(de->d_name, name) == 0) \ { \ - strcpy(oldLocation, oldDirectory); \ - strcat(oldLocation, name); \ - strcpy(newLocation, output); \ - strcat(newLocation, "saves/"); \ - strcat(newLocation, name); \ + SDL_snprintf(oldLocation, sizeof(oldLocation), "%s%s", oldDirectory, name); \ + SDL_snprintf(newLocation, sizeof(newLocation), "%ssaves/%s", output, name); \ PLATFORM_copyFile(oldLocation, newLocation); \ } COPY_SAVEFILE("unlock.vvv") COPY_SAVEFILE("tsave.vvv") COPY_SAVEFILE("qsave.vvv") #undef COPY_SAVEFILE - else if (strstr(de->d_name, ".vvvvvv.vvv") != NULL) + else if (SDL_strstr(de->d_name, ".vvvvvv.vvv") != NULL) { - strcpy(oldLocation, oldDirectory); - strcat(oldLocation, de->d_name); - strcpy(newLocation, output); - strcat(newLocation, "saves/"); - strcat(newLocation, de->d_name); + SDL_snprintf(oldLocation, sizeof(oldLocation), "%s%s", oldDirectory, de->d_name); + SDL_snprintf(newLocation, sizeof(newLocation), "%ssaves/%s", output, de->d_name); PLATFORM_copyFile(oldLocation, newLocation); } - else if (strstr(de->d_name, ".vvvvvv") != NULL) + else if (SDL_strstr(de->d_name, ".vvvvvv") != NULL) { - strcpy(oldLocation, oldDirectory); - strcat(oldLocation, de->d_name); - strcpy(newLocation, output); - strcat(newLocation, "levels/"); - strcat(newLocation, de->d_name); + SDL_snprintf(oldLocation, sizeof(oldLocation), "%s%s", oldDirectory, de->d_name); + SDL_snprintf(newLocation, sizeof(newLocation), "%slevels/%s", output, de->d_name); PLATFORM_copyFile(oldLocation, newLocation); } - else if (strcmp(de->d_name, "Saves") == 0) + else if (SDL_strcmp(de->d_name, "Saves") == 0) { - strcpy(subDirLocation, oldDirectory); - strcat(subDirLocation, "Saves/"); + SDL_snprintf(subDirLocation, sizeof(subDirLocation), "%sSaves/", oldDirectory); subDir = opendir(subDirLocation); if (!subDir) { @@ -444,13 +435,10 @@ static void PLATFORM_migrateSaveData(char* output) subDe = readdir(subDir) ) { #define COPY_SAVEFILE(name) \ - (strcmp(subDe->d_name, name) == 0) \ + (SDL_strcmp(subDe->d_name, name) == 0) \ { \ - strcpy(oldLocation, subDirLocation); \ - strcat(oldLocation, name); \ - strcpy(newLocation, output); \ - strcat(newLocation, "saves/"); \ - strcat(newLocation, name); \ + SDL_snprintf(oldLocation, sizeof(oldLocation), "%s%s", subDirLocation, name); \ + SDL_snprintf(newLocation, sizeof(newLocation), "%ssaves/%s", output, name); \ PLATFORM_copyFile(oldLocation, newLocation); \ } if COPY_SAVEFILE("unlock.vvv") @@ -466,39 +454,9 @@ static void PLATFORM_migrateSaveData(char* output) char fileSearch[MAX_PATH]; /* Same place, different layout. */ - strcpy(oldDirectory, output); + SDL_strlcpy(oldDirectory, output, sizeof(oldDirectory)); - /* In theory we don't need to worry about this, thanks case insensitivity! - sprintf(fileSearch, "%s\\Saves\\*.vvv", oldDirectory); - hFind = FindFirstFile(fileSearch, &findHandle); - if (hFind == INVALID_HANDLE_VALUE) - { - printf("Could not find directory %s\\Saves\\\n", oldDirectory); - } - else do - { - if ((findHandle.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) - { - #define COPY_SAVEFILE(name) \ - (strcmp(findHandle.cFileName, name) == 0) \ - { \ - strcpy(oldLocation, oldDirectory); \ - strcat(oldLocation, "Saves\\"); \ - strcat(oldLocation, name); \ - strcpy(newLocation, output); \ - strcat(newLocation, "saves\\"); \ - strcat(newLocation, name); \ - PLATFORM_copyFile(oldLocation, newLocation); \ - } - if COPY_SAVEFILE("unlock.vvv") - else if COPY_SAVEFILE("tsave.vvv") - else if COPY_SAVEFILE("qsave.vvv") - #undef COPY_SAVEFILE - } - } while (FindNextFile(hFind, &findHandle)); - */ - - sprintf(fileSearch, "%s\\*.vvvvvv", oldDirectory); + SDL_snprintf(fileSearch, sizeof(fileSearch), "%s\\*.vvvvvv", oldDirectory); hFind = FindFirstFile(fileSearch, &findHandle); if (hFind == INVALID_HANDLE_VALUE) { @@ -508,11 +466,8 @@ static void PLATFORM_migrateSaveData(char* output) { if ((findHandle.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { - strcpy(oldLocation, oldDirectory); - strcat(oldLocation, findHandle.cFileName); - strcpy(newLocation, output); - strcat(newLocation, "levels\\"); - strcat(newLocation, findHandle.cFileName); + SDL_snprintf(oldLocation, sizeof(oldLocation), "%s%s", oldDirectory, findHandle.cFileName); + SDL_snprintf(newLocation, sizeof(newLocation), "%slevels\\%s", output, findHandle.cFileName); PLATFORM_copyFile(oldLocation, newLocation); } } while (FindNextFile(hFind, &findHandle)); @@ -536,13 +491,13 @@ static void PLATFORM_copyFile(const char *oldLocation, const char *newLocation) fseek(file, 0, SEEK_END); length = ftell(file); fseek(file, 0, SEEK_SET); - data = (char*) malloc(length); + data = (char*) SDL_malloc(length); bytes_read = fread(data, 1, length, file); fclose(file); if (bytes_read != length) { printf("An error occurred when reading from %s\n", oldLocation); - free(data); + SDL_free(data); return; } @@ -551,12 +506,12 @@ static void PLATFORM_copyFile(const char *oldLocation, const char *newLocation) if (!file) { printf("Could not write to %s\n", newLocation); - free(data); + SDL_free(data); return; } bytes_written = fwrite(data, 1, length, file); fclose(file); - free(data); + SDL_free(data); /* WTF did we just do */ printf("Copied:\n\tOld: %s\n\tNew: %s\n", oldLocation, newLocation); diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 726a6e15..9df88cb7 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -21,11 +21,6 @@ #include "UtilityClass.h" #include "XMLUtils.h" -// lol, Win32 -flibit -#ifdef _WIN32 -#define strcasecmp stricmp -#endif - static bool GetButtonFromString(const char *pText, SDL_GameControllerButton *button) { if (*pText == '0' || @@ -35,7 +30,7 @@ static bool GetButtonFromString(const char *pText, SDL_GameControllerButton *but *button = SDL_CONTROLLER_BUTTON_A; return true; } - if (strcmp(pText, "1") == 0 || + if (SDL_strcmp(pText, "1") == 0 || *pText == 'b' || *pText == 'B') { @@ -57,43 +52,43 @@ static bool GetButtonFromString(const char *pText, SDL_GameControllerButton *but return true; } if (*pText == '4' || - strcasecmp(pText, "BACK") == 0) + SDL_strcasecmp(pText, "BACK") == 0) { *button = SDL_CONTROLLER_BUTTON_BACK; return true; } if (*pText == '5' || - strcasecmp(pText, "GUIDE") == 0) + SDL_strcasecmp(pText, "GUIDE") == 0) { *button = SDL_CONTROLLER_BUTTON_GUIDE; return true; } if (*pText == '6' || - strcasecmp(pText, "START") == 0) + SDL_strcasecmp(pText, "START") == 0) { *button = SDL_CONTROLLER_BUTTON_START; return true; } if (*pText == '7' || - strcasecmp(pText, "LS") == 0) + SDL_strcasecmp(pText, "LS") == 0) { *button = SDL_CONTROLLER_BUTTON_LEFTSTICK; return true; } if (*pText == '8' || - strcasecmp(pText, "RS") == 0) + SDL_strcasecmp(pText, "RS") == 0) { *button = SDL_CONTROLLER_BUTTON_RIGHTSTICK; return true; } if (*pText == '9' || - strcasecmp(pText, "LB") == 0) + SDL_strcasecmp(pText, "LB") == 0) { *button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER; return true; } - if (strcmp(pText, "10") == 0 || - strcasecmp(pText, "RB") == 0) + if (SDL_strcmp(pText, "10") == 0 || + SDL_strcasecmp(pText, "RB") == 0) { *button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; return true; @@ -550,7 +545,7 @@ void Game::loadcustomlevelstats() } // If the two arrays happen to differ in length, just go with the smallest one - for (size_t i = 0; i < std::min(customlevelnames.size(), customlevelscores.size()); i++) + for (int i = 0; i < VVV_min(customlevelnames.size(), customlevelscores.size()); i++) { CustomLevelStat stat = {customlevelnames[i], customlevelscores[i]}; customlevelstats.push_back(stat); @@ -4457,7 +4452,7 @@ void Game::unlocknum( int t ) if (TextString.length()) \ { \ std::vector values = split(TextString, ','); \ - for (size_t i = 0; i < SDL_min(SDL_arraysize(DEST), values.size()); i++) \ + for (int i = 0; i < VVV_min(SDL_arraysize(DEST), values.size()); i++) \ { \ DEST[i] = help.Int(values[i].c_str()); \ } \ diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 5728737a..982be25b 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -412,7 +412,7 @@ void Graphics::bigprint( int _x, int _y, std::string _s, int r, int g, int b, b if (cen) { - _x = std::max(160 - (int((len(_s)/ 2.0)*sc)), 0 ); + _x = VVV_max(160 - (int((len(_s)/ 2.0)*sc)), 0 ); } int bfontpos = 0; @@ -978,13 +978,13 @@ void Graphics::cutscenebarstimer() if (showcutscenebars) { cutscenebarspos += 25; - cutscenebarspos = std::min(cutscenebarspos, 361); + cutscenebarspos = VVV_min(cutscenebarspos, 361); } else if (cutscenebarspos > 0) { //disappearing cutscenebarspos -= 25; - cutscenebarspos = std::max(cutscenebarspos, 0); + cutscenebarspos = VVV_max(cutscenebarspos, 0); } } @@ -1381,10 +1381,10 @@ bool Graphics::Hitest(SDL_Surface* surface1, point p1, SDL_Surface* surface2, po if(intersection) { - int r3_left = SDL_max(r1_left, r2_left); - int r3_top = SDL_min(r1_top, r2_top); - int r3_right = SDL_min(r1_right, r2_right); - int r3_bottom= SDL_max(r1_bottom, r2_bottom); + int r3_left = VVV_max(r1_left, r2_left); + int r3_top = VVV_min(r1_top, r2_top); + int r3_right = VVV_min(r1_right, r2_right); + int r3_bottom= VVV_max(r1_bottom, r2_bottom); //for every pixel inside rectangle for(int x = r3_left; x < r3_right; x++) @@ -2971,7 +2971,7 @@ void Graphics::bigrprint(int x, int y, std::string& t, int r, int g, int b, bool if (cen) { - x = std::max(160 - (int((len(t)/ 2.0)*sc)), 0 ); + x = VVV_max(160 - (int((len(t)/ 2.0)*sc)), 0 ); } else { diff --git a/desktop_version/src/GraphicsResources.cpp b/desktop_version/src/GraphicsResources.cpp index 52fa5d42..2873c960 100644 --- a/desktop_version/src/GraphicsResources.cpp +++ b/desktop_version/src/GraphicsResources.cpp @@ -67,7 +67,7 @@ static SDL_Surface* LoadImage(const char *filename, bool noBlend = true, bool no 0 ); SDL_FreeSurface( loadedImage ); - free(data); + SDL_free(data); if (noBlend) { SDL_SetSurfaceBlendMode(optimizedImage, SDL_BLENDMODE_BLEND); diff --git a/desktop_version/src/GraphicsUtil.cpp b/desktop_version/src/GraphicsUtil.cpp index b601dbdb..1953136c 100644 --- a/desktop_version/src/GraphicsUtil.cpp +++ b/desktop_version/src/GraphicsUtil.cpp @@ -336,20 +336,20 @@ SDL_Surface* ApplyFilter( SDL_Surface* _src ) Uint8 green = (pixel & _src->format->Gmask) >> 8; Uint8 blue = (pixel & _src->format->Bmask) >> 0; - Uint32 pixelOffset = ReadPixel(_src, std::min(x+redOffset, 319), sampley) ; + Uint32 pixelOffset = ReadPixel(_src, VVV_min(x+redOffset, 319), sampley) ; Uint8 red = (pixelOffset & _src->format->Rmask) >> 16 ; if(isscrolling && sampley > 220 && ((rand() %10) < 4)) { - red = std::min(int(red+(fRandom() * 0.6) * 254) , 255); - green = std::min(int(green+(fRandom() * 0.6) * 254) , 255); - blue = std::min(int(blue+(fRandom() * 0.6) * 254) , 255); + red = VVV_min(int(red+(fRandom() * 0.6) * 254) , 255); + green = VVV_min(int(green+(fRandom() * 0.6) * 254) , 255); + blue = VVV_min(int(blue+(fRandom() * 0.6) * 254) , 255); } else { - red = std::min(int(red+(fRandom() * 0.2) * 254) , 255); - green = std::min(int(green+(fRandom() * 0.2) * 254) , 255); - blue = std::min(int(blue+(fRandom() * 0.2) * 254) , 255); + red = VVV_min(int(red+(fRandom() * 0.2) * 254) , 255); + green = VVV_min(int(green+(fRandom() * 0.2) * 254) , 255); + blue = VVV_min(int(blue+(fRandom() * 0.2) * 254) , 255); } @@ -363,9 +363,9 @@ SDL_Surface* ApplyFilter( SDL_Surface* _src ) int distX = static_cast((SDL_abs (160.0f -x ) / 160.0f) *16); int distY = static_cast((SDL_abs (120.0f -y ) / 120.0f)*32); - red = std::max(red - ( distX +distY), 0); - green = std::max(green - ( distX +distY), 0); - blue = std::max(blue - ( distX +distY), 0); + red = VVV_max(red - ( distX +distY), 0); + green = VVV_max(green - ( distX +distY), 0); + blue = VVV_max(blue - ( distX +distY), 0); Uint32 finalPixel = ((red<<16) + (green<<8) + (blue<<0)) | (pixel &_src->format->Amask); DrawPixel(_ret,x,y, finalPixel); diff --git a/desktop_version/src/KeyPoll.cpp b/desktop_version/src/KeyPoll.cpp index 7fd072c2..16fab84b 100644 --- a/desktop_version/src/KeyPoll.cpp +++ b/desktop_version/src/KeyPoll.cpp @@ -45,13 +45,13 @@ KeyPoll::KeyPoll() pressedbackspace=false; useFullscreenSpaces = false; - if (strcmp(SDL_GetPlatform(), "Mac OS X") == 0) + if (SDL_strcmp(SDL_GetPlatform(), "Mac OS X") == 0) { useFullscreenSpaces = true; const char *hint = SDL_GetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES); if (hint != NULL) { - useFullscreenSpaces = (strcmp(hint, "1") == 0); + useFullscreenSpaces = (SDL_strcmp(hint, "1") == 0); } } diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index f4591cfa..c7bcdd10 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -472,8 +472,7 @@ int mapclass::finalat(int x, int y) //Special case: animated tiles if (final_mapcol == 1) { - // Windows hits fRandom() == 1 frequently! For fuck sake! -flibit - return 737 + (std::min(int(fRandom() * 12), 11) * 40); + return 737 + (int(fRandom() * 11) * 40); } else { @@ -713,7 +712,6 @@ int mapclass::area(int _rx, int _ry) else { int lookup = (_rx - 100) + ((_ry - 100) * 20); - //lookup = std::max(0,lookup); if(_rx-100>=0 && _rx-100<20 && _ry-100>=0 && _ry-100<20){ return areamap[lookup]; } diff --git a/desktop_version/src/Maths.h b/desktop_version/src/Maths.h index 108a60ee..bee72192 100644 --- a/desktop_version/src/Maths.h +++ b/desktop_version/src/Maths.h @@ -25,4 +25,28 @@ struct point int y; }; +inline int VVV_min(const int a, const int b) +{ + if (a < b) + { + return a; + } + else + { + return b; + } +} + +inline int VVV_max(const int a, const int b) +{ + if (a > b) + { + return a; + } + else + { + return b; + } +} + #endif /* MATHGAME_H */ diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 20b8bf5e..e2b00bfb 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -315,7 +315,7 @@ static void menurender() graphics.Print( 40, 30, "the following patrons", tr, tg, tb, true); int startidx = game.current_credits_list_index; - int endidx = std::min(startidx + 9, (int)SDL_arraysize(Credits::superpatrons)); + int endidx = VVV_min(startidx + 9, (int)SDL_arraysize(Credits::superpatrons)); int xofs = 80 - 16; int yofs = 40 + 20; @@ -333,7 +333,7 @@ static void menurender() graphics.Print( -1, 20, "and also by", tr, tg, tb, true); int startidx = game.current_credits_list_index; - int endidx = std::min(startidx + 14, (int)SDL_arraysize(Credits::patrons)); + int endidx = VVV_min(startidx + 14, (int)SDL_arraysize(Credits::patrons)); int maxheight = 10 * 14; int totalheight = (endidx - startidx) * 10; @@ -354,7 +354,7 @@ static void menurender() graphics.Print( 40, 30, "GitHub from", tr, tg, tb, true); int startidx = game.current_credits_list_index; - int endidx = std::min(startidx + 9, (int)SDL_arraysize(Credits::githubfriends)); + int endidx = VVV_min(startidx + 9, (int)SDL_arraysize(Credits::githubfriends)); int maxheight = 14 * 9; int totalheight = (endidx - startidx) * 14; diff --git a/desktop_version/src/Screen.cpp b/desktop_version/src/Screen.cpp index 20554d39..7fe53ec9 100644 --- a/desktop_version/src/Screen.cpp +++ b/desktop_version/src/Screen.cpp @@ -130,7 +130,7 @@ void Screen::LoadIcon() ); SDL_SetWindowIcon(m_window, icon); SDL_FreeSurface(icon); - free(data); + SDL_free(data); } void Screen::ResizeScreen(int x, int y) diff --git a/desktop_version/src/ThirdPartyDeps.c b/desktop_version/src/ThirdPartyDeps.c new file mode 100644 index 00000000..adb2b7c6 --- /dev/null +++ b/desktop_version/src/ThirdPartyDeps.c @@ -0,0 +1,18 @@ +#include + +// Handle third-party dependencies' needs here + +void* lodepng_malloc(size_t size) +{ + return SDL_malloc(size); +} + +void* lodepng_realloc(void* ptr, size_t new_size) +{ + return SDL_realloc(ptr, new_size); +} + +void lodepng_free(void* ptr) +{ + SDL_free(ptr); +} diff --git a/desktop_version/src/UtilityClass.cpp b/desktop_version/src/UtilityClass.cpp index 361be6da..ce4f52d3 100644 --- a/desktop_version/src/UtilityClass.cpp +++ b/desktop_version/src/UtilityClass.cpp @@ -228,13 +228,20 @@ bool is_number(const char* str) return true; } +static bool VVV_isxdigit(const unsigned char digit) +{ + return (digit >= 'a' && digit <= 'z') + || (digit >= 'A' && digit <= 'Z') + || SDL_isdigit(digit); +} + bool is_positive_num(const std::string& str, bool hex) { for (size_t i = 0; i < str.length(); i++) { if (hex) { - if (!isxdigit(static_cast(str[i]))) + if (!VVV_isxdigit(static_cast(str[i]))) { return false; } diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index dcd166fc..6ca04175 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -159,11 +159,11 @@ std::string find_tag(const std::string& buf, const std::string& start, const std uint32_t character = 0; if (hex) { - sscanf(number.c_str(), "%" SCNx32, &character); + SDL_sscanf(number.c_str(), "%" SCNx32, &character); } else { - sscanf(number.c_str(), "%" SCNu32, &character); + SDL_sscanf(number.c_str(), "%" SCNu32, &character); } uint32_t utf32[] = {character, 0}; std::string utf8; @@ -1630,7 +1630,7 @@ bool editorclass::load(std::string& _path) reset(); static const char *levelDir = "levels/"; - if (_path.compare(0, strlen(levelDir), levelDir) != 0) + if (_path.compare(0, SDL_strlen(levelDir), levelDir) != 0) { _path = levelDir + _path; } diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index a48980c8..ae0db7c5 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -83,7 +83,7 @@ int main(int argc, char *argv[]) for (int i = 1; i < argc; ++i) { -#define ARG(name) (strcmp(argv[i], name) == 0) +#define ARG(name) (SDL_strcmp(argv[i], name) == 0) #define ARG_INNER(code) \ if (i + 1 < argc) \ { \