diff --git a/android/jni/.gitignore b/android/jni/.gitignore old mode 100755 new mode 100644 diff --git a/gamefiles/main.json b/gamefiles/main.json index d49c4af9..1f9a9e13 100755 --- a/gamefiles/main.json +++ b/gamefiles/main.json @@ -12,19 +12,10 @@ "mountFile": [ { "file": "DIABDAT.zip", "append": true } ], - "saveDir": ".diablo", - "icon": { - "file":"res/icon.png" - }, - "cursor": { - "show": false - }, - "load": "settings.json", - "load": "res/actions.json", - "load": "res/fonts.json", - "load": "res/music.json", - "load": "res/palettes.json", - "load": "res/sounds.json", - "load": "res/textures.json", - "load": "ui/splashScreen.json" + "action": { + "name": "if.fileExists", + "param1": "ui_art/title.pcx", + "then": { "name": "load", "file": "ui/loadMain.json" }, + "else": { "name": "load", "file": "ui/dataMissing.json" } + } } \ No newline at end of file diff --git a/gamefiles/ui/dataMissing.json b/gamefiles/ui/dataMissing.json new file mode 100755 index 00000000..0a54940a --- /dev/null +++ b/gamefiles/ui/dataMissing.json @@ -0,0 +1,22 @@ +{ + "keyboard": { + "key": ["enter", " ", "esc"], + "action": { "name": "game.close" } + }, + "font": { + "id": "liberationSerif", + "file": "res/LiberationSerif-Regular.ttf" + }, + "button": { + "id": "quit", + "font": "liberationSerif", + "fontSize": 28, + "color": "0xFFFFFF", + "position": [320, 240], + "anchor": "none", + "horizontalAlign": "center", + "verticalAlign": "center", + "text": "Error loading DIABDAT.zip\nMake sure the game data is present.", + "onClick": "game.close" + } +} \ No newline at end of file diff --git a/gamefiles/ui/loadMain.json b/gamefiles/ui/loadMain.json new file mode 100755 index 00000000..bdc53115 --- /dev/null +++ b/gamefiles/ui/loadMain.json @@ -0,0 +1,17 @@ +{ + "saveDir": ".diablo", + "icon": { + "file":"res/icon.png" + }, + "cursor": { + "show": false + }, + "load": "settings.json", + "load": "res/actions.json", + "load": "res/fonts.json", + "load": "res/music.json", + "load": "res/palettes.json", + "load": "res/sounds.json", + "load": "res/textures.json", + "load": "ui/splashScreen.json" +} \ No newline at end of file diff --git a/src/Dun.cpp b/src/Dun.cpp index 0ac94e36..c5bc43cc 100755 --- a/src/Dun.cpp +++ b/src/Dun.cpp @@ -7,6 +7,11 @@ Dun::Dun(const std::string& filename) { sf::PhysFSStream file(filename); + if (file.hasError() == true) + { + return; + } + int16_t temp; file.read(&temp, 2); width = temp; diff --git a/src/Font2.h b/src/Font2.h index 48b8f65c..d73ad1d0 100755 --- a/src/Font2.h +++ b/src/Font2.h @@ -12,5 +12,12 @@ class Font2 : public sf::Font public: Font2(const std::shared_ptr& file_) : file(file_) {} - bool load() { return loadFromStream(*file); } + bool load() + { + if (file == nullptr || file->hasError() == true) + { + return false; + } + return loadFromStream(*file); + } }; diff --git a/src/LoadingScreen.cpp b/src/LoadingScreen.cpp index e057c34f..b1755341 100755 --- a/src/LoadingScreen.cpp +++ b/src/LoadingScreen.cpp @@ -16,7 +16,7 @@ void LoadingScreen::setProgress(int percent_) else { sf::Vector2f newSize(barSize); - newSize.x *= (percent_ / 100.0f); + newSize.x = std::round(newSize.x * (percent_ / 100.0f)); progressBar.setSize(newSize); } } diff --git a/src/Min.cpp b/src/Min.cpp index eceada45..220b7abd 100755 --- a/src/Min.cpp +++ b/src/Min.cpp @@ -5,6 +5,11 @@ Min::Min(const std::string& filename, size_t minSize) { sf::PhysFSStream file(filename); + if (file.hasError() == true) + { + return; + } + auto numPillars = file.getSize() / (minSize * 2); file.seek(0); diff --git a/src/Movie2.h b/src/Movie2.h index 3bae107a..f1d34923 100755 --- a/src/Movie2.h +++ b/src/Movie2.h @@ -24,6 +24,10 @@ class Movie2 : public UIObject bool load() { + if (file == nullptr || file->hasError() == true) + { + return false; + } bool ret = movie.openFromStream(*file); if (ret == true) { diff --git a/src/Music2.h b/src/Music2.h index b69e6990..3a10fad6 100755 --- a/src/Music2.h +++ b/src/Music2.h @@ -16,7 +16,14 @@ class Music2 : public sf::NonCopyable Music2(const char* file_) : file(std::make_unique(file_)), music(std::make_unique()) {} - bool load() { return music->openFromStream(*file); } + bool load() + { + if (file == nullptr || file->hasError() == true) + { + return false; + } + return music->openFromStream(*file); + } void play() { music->play(); } void pause() { music->pause(); } diff --git a/src/Palette.cpp b/src/Palette.cpp index b1edcf7d..f0ee6650 100755 --- a/src/Palette.cpp +++ b/src/Palette.cpp @@ -5,7 +5,7 @@ Palette::Palette(const char* file) { sf::PhysFSStream stream(file); - if (stream.getSize() < 768) + if (stream.hasError() == true || stream.getSize() < 768) { return; } diff --git a/src/Parser/ParseBitmapFont.cpp b/src/Parser/ParseBitmapFont.cpp index c2611863..89f968f6 100755 --- a/src/Parser/ParseBitmapFont.cpp +++ b/src/Parser/ParseBitmapFont.cpp @@ -29,6 +29,11 @@ namespace Parser else if (isValidString(elem, "textureId")) { img = parseTextureImg(game, elem); + auto imgSize = img.getSize(); + if (imgSize.x == 0 || imgSize.y == 0) + { + return; + } texture = std::make_shared(); texture->loadFromImage(img); texture->setSmooth(getBool(elem, "smooth")); diff --git a/src/Parser/ParseText.cpp b/src/Parser/ParseText.cpp index d788fa73..d71799e2 100755 --- a/src/Parser/ParseText.cpp +++ b/src/Parser/ParseText.cpp @@ -34,7 +34,7 @@ namespace Parser return nullptr; } - auto size = getUInt(elem, "fontSize"); + auto size = getUInt(elem, "fontSize", 12); auto text = std::make_unique(displayText, *font, size); text->setColor(getColor(elem, "color", sf::Color::White)); text->setHorizontalAlign(GameUtils::getHorizontalAlignment(getString(elem, "horizontalAlign"))); diff --git a/src/Sol.cpp b/src/Sol.cpp index c9eb34f1..2e9fed27 100755 --- a/src/Sol.cpp +++ b/src/Sol.cpp @@ -5,6 +5,11 @@ Sol::Sol(const std::string& path) { sf::PhysFSStream file(path); + if (file.hasError() == true) + { + return; + } + auto size = (unsigned)file.getSize(); data.resize(size);