From 6864fc171b08dea1c580f99c1e43d4429d1e092e Mon Sep 17 00:00:00 2001 From: furo Date: Fri, 10 May 2024 18:07:20 +0200 Subject: [PATCH 1/5] Include `map_create_pixelart` in release --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e57a270d..ad42e0ee7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3049,6 +3049,7 @@ if(TOOLS) demo_extract_chat dilate map_convert_07 + map_create_pixelart map_diff map_extract ) From d5b06a44826c1b2a0416227e5892f60ab569e01d Mon Sep 17 00:00:00 2001 From: furo Date: Fri, 10 May 2024 18:18:24 +0200 Subject: [PATCH 2/5] Use `IO_MAX_PATH_LENGTH` instead of `64` --- src/tools/map_create_pixelart.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tools/map_create_pixelart.cpp b/src/tools/map_create_pixelart.cpp index 9b9e258d3..3bbdd9f17 100644 --- a/src/tools/map_create_pixelart.cpp +++ b/src/tools/map_create_pixelart.cpp @@ -6,12 +6,12 @@ #include #include -bool CreatePixelArt(const char[3][64], const int[2], const int[2], int[2], const bool[2]); +bool CreatePixelArt(const char[3][IO_MAX_PATH_LENGTH], const int[2], const int[2], int[2], const bool[2]); void InsertCurrentQuads(CDataFileReader &, CMapItemLayerQuads *, CQuad *); int InsertPixelArtQuads(CQuad *, int &, const CImageInfo &, const int[2], const int[2], const bool[2]); bool LoadPng(CImageInfo *, const char *); -bool OpenMaps(const char[2][64], CDataFileReader &, CDataFileWriter &); +bool OpenMaps(const char[2][IO_MAX_PATH_LENGTH], CDataFileReader &, CDataFileWriter &); void SaveOutputMap(CDataFileReader &, CDataFileWriter &, CMapItemLayerQuads *, int, CQuad *, int); CMapItemLayerQuads *GetQuadLayer(CDataFileReader &, const int[2], int *); @@ -45,7 +45,7 @@ int main(int argc, const char **argv) return -1; } - char aFilenames[3][64]; + char aFilenames[3][IO_MAX_PATH_LENGTH]; str_copy(aFilenames[0], argv[3]); //input_map str_copy(aFilenames[1], argv[9]); //output_map str_copy(aFilenames[2], argv[1]); //image_file @@ -64,7 +64,7 @@ int main(int argc, const char **argv) return !CreatePixelArt(aFilenames, aLayerId, aStartingPos, aPixelSizes, aArtOptions); } -bool CreatePixelArt(const char aFilenames[3][64], const int aLayerId[2], const int aStartingPos[2], int aPixelSizes[2], const bool aArtOptions[2]) +bool CreatePixelArt(const char aFilenames[3][IO_MAX_PATH_LENGTH], const int aLayerId[2], const int aStartingPos[2], int aPixelSizes[2], const bool aArtOptions[2]) { CImageInfo Img; if(!LoadPng(&Img, aFilenames[2])) @@ -357,7 +357,7 @@ bool LoadPng(CImageInfo *pImg, const char *pFilename) return true; } -bool OpenMaps(const char pMapNames[2][64], CDataFileReader &InputMap, CDataFileWriter &OutputMap) +bool OpenMaps(const char pMapNames[2][IO_MAX_PATH_LENGTH], CDataFileReader &InputMap, CDataFileWriter &OutputMap) { IStorage *pStorage = CreateLocalStorage(); From 39dd6ea4998d4bb510ce80c2be3333da46186982 Mon Sep 17 00:00:00 2001 From: furo Date: Fri, 10 May 2024 18:20:33 +0200 Subject: [PATCH 3/5] Fix wrong filename used in `dbg_msg` --- src/tools/map_create_pixelart.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/map_create_pixelart.cpp b/src/tools/map_create_pixelart.cpp index 3bbdd9f17..6377d1ad1 100644 --- a/src/tools/map_create_pixelart.cpp +++ b/src/tools/map_create_pixelart.cpp @@ -59,7 +59,7 @@ int main(int argc, const char **argv) aArtOptions[1] = argc >= 11 ? str_toint(argv[11]) : false; //centralize dbg_msg("map_create_pixelart", "image_file='%s'; image_pixelsize='%dpx'; input_map='%s'; layergroup_id='#%d'; layer_id='#%d'; pos_x='#%dpx'; pos_y='%dpx'; quad_pixelsize='%dpx'; output_map='%s'; optimize='%d'; centralize='%d'", - aFilenames[2], aPixelSizes[0], aFilenames[1], aLayerId[0], aLayerId[1], aStartingPos[0], aStartingPos[1], aPixelSizes[1], aFilenames[2], aArtOptions[0], aArtOptions[1]); + aFilenames[2], aPixelSizes[0], aFilenames[0], aLayerId[0], aLayerId[1], aStartingPos[0], aStartingPos[1], aPixelSizes[1], aFilenames[1], aArtOptions[0], aArtOptions[1]); return !CreatePixelArt(aFilenames, aLayerId, aStartingPos, aPixelSizes, aArtOptions); } From 7cd9d8bbb44ccdee391a64d84ff1d99741bbba9f Mon Sep 17 00:00:00 2001 From: furo Date: Fri, 10 May 2024 18:42:55 +0200 Subject: [PATCH 4/5] Prevent using `map_create_pixelart` with the same input and output path --- src/tools/map_create_pixelart.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools/map_create_pixelart.cpp b/src/tools/map_create_pixelart.cpp index 6377d1ad1..5f8c89cdf 100644 --- a/src/tools/map_create_pixelart.cpp +++ b/src/tools/map_create_pixelart.cpp @@ -50,6 +50,12 @@ int main(int argc, const char **argv) str_copy(aFilenames[1], argv[9]); //output_map str_copy(aFilenames[2], argv[1]); //image_file + if(str_comp_filenames(aFilenames[0], aFilenames[1]) == 0) + { + dbg_msg("map_create_pixelart", "Invalid usage: you can not use the same map as input and output"); + return -1; + } + int aLayerId[2] = {str_toint(argv[4]), str_toint(argv[5])}; //layergroup_id, layer_id int aStartingPos[2] = {str_toint(argv[6]) * 32, str_toint(argv[7]) * 32}; //pos_x, pos_y int aPixelSizes[2] = {str_toint(argv[2]), str_toint(argv[8])}; //quad_pixelsize, img_pixelsize From 349162418418d0be96f3dbd56a457ad51bd7b339 Mon Sep 17 00:00:00 2001 From: furo Date: Fri, 10 May 2024 19:05:58 +0200 Subject: [PATCH 5/5] Fix crash when not specifying `optimize`, `centralize` or invalid amount of arguments --- src/tools/map_create_pixelart.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/map_create_pixelart.cpp b/src/tools/map_create_pixelart.cpp index 5f8c89cdf..5bc7c87f2 100644 --- a/src/tools/map_create_pixelart.cpp +++ b/src/tools/map_create_pixelart.cpp @@ -31,7 +31,7 @@ int main(int argc, const char **argv) CCmdlineFix CmdlineFix(&argc, &argv); log_set_global_logger_default(); - if(argc < 9 || argc > 12) + if(argc < 10 || argc > 12) { dbg_msg("map_create_pixelart", "Invalid arguments"); dbg_msg("map_create_pixelart", "Usage: %s [optimize=0|1] [centralize=0|1]", argv[0]); @@ -61,8 +61,8 @@ int main(int argc, const char **argv) int aPixelSizes[2] = {str_toint(argv[2]), str_toint(argv[8])}; //quad_pixelsize, img_pixelsize bool aArtOptions[3]; - aArtOptions[0] = argc >= 10 ? str_toint(argv[10]) : true; //optimize - aArtOptions[1] = argc >= 11 ? str_toint(argv[11]) : false; //centralize + aArtOptions[0] = argc > 10 ? str_toint(argv[10]) : true; //optimize + aArtOptions[1] = argc > 11 ? str_toint(argv[11]) : false; //centralize dbg_msg("map_create_pixelart", "image_file='%s'; image_pixelsize='%dpx'; input_map='%s'; layergroup_id='#%d'; layer_id='#%d'; pos_x='#%dpx'; pos_y='%dpx'; quad_pixelsize='%dpx'; output_map='%s'; optimize='%d'; centralize='%d'", aFilenames[2], aPixelSizes[0], aFilenames[0], aLayerId[0], aLayerId[1], aStartingPos[0], aStartingPos[1], aPixelSizes[1], aFilenames[1], aArtOptions[0], aArtOptions[1]);