From 9154c0a678d353df6069559e5e8b599247949520 Mon Sep 17 00:00:00 2001 From: Ahmed Samy Date: Fri, 6 Dec 2013 23:08:08 +0200 Subject: [PATCH] mapio: fix load on new maps --- src/client/mapio.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/client/mapio.cpp b/src/client/mapio.cpp index e6780467..50bae75e 100644 --- a/src/client/mapio.cpp +++ b/src/client/mapio.cpp @@ -35,16 +35,20 @@ void Map::loadOtbm(const std::string& fileName) { try { - FileStreamPtr fin = g_resources.openFile(fileName); - if(!fin) - stdext::throw_exception(stdext::format("Unable to load map '%s'", fileName)); - - fin->cache(); if(!g_things.isOtbLoaded()) stdext::throw_exception("OTB isn't loaded yet to load a map."); - if(fin->getU32()) - stdext::throw_exception("Unknown file version detected"); + FileStreamPtr fin = g_resources.openFile(fileName); + if(!fin) + stdext::throw_exception(stdext::format("Unable to load map '%s'", fileName)); + fin->cache(); + + char identifier[4]; + if(fin->read(identifier, 1, 4) < 4) + stdext::throw_exception("Could not read file identifier"); + + if(memcmp(identifier, "OTBM", 4) != 0 && memcmp(identifier, "\0\0\0\0", 4) != 0) + stdext::throw_exception(stdext::format("Invalid file identifier detected: %s", identifier)); BinaryTreePtr root = fin->getBinaryTree(); if(root->getU8())