summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2019-12-28 23:46:49 +0300
committerAndrei Karas <akaras@inbox.ru>2020-01-09 09:37:39 +0300
commit0b3f5c363090123b025b8084419e242e1c2ebe8f (patch)
treeb5e227813ba0bf916df0e80ffecb7e38e9003b30
parent68bcca0b091bfa91d5505c5a44e888482a82c463 (diff)
downloadhercules-0b3f5c363090123b025b8084419e242e1c2ebe8f.tar.gz
hercules-0b3f5c363090123b025b8084419e242e1c2ebe8f.tar.bz2
hercules-0b3f5c363090123b025b8084419e242e1c2ebe8f.tar.xz
hercules-0b3f5c363090123b025b8084419e242e1c2ebe8f.zip
Fix reading water level from rsw version 2.2+
-rw-r--r--src/map/map.c23
-rw-r--r--src/plugins/mapcache.c23
2 files changed, 44 insertions, 2 deletions
diff --git a/src/map/map.c b/src/map/map.c
index 8d60d1672..9db868329 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -3769,8 +3769,29 @@ static int map_waterheight(char *mapname)
// read & convert fn
rsw = grfio_read(fn);
if (rsw) {
+ if (memcmp(rsw, "GRSW", 4) != 0) {
+ ShowWarning("Failed to find water level for %s (%s)\n", mapname, fn);
+ aFree(rsw);
+ return NO_WATER;
+ }
+ int major_version = rsw[4];
+ int minor_version = rsw[5];
+ if (major_version > 2 || (major_version == 2 && minor_version > 2)) {
+ ShowWarning("Failed to find water level for %s (%s)\n", mapname, fn);
+ aFree(rsw);
+ return NO_WATER;
+ }
+ if (major_version < 1 || (major_version == 1 && minor_version <= 4)) {
+ ShowWarning("Failed to find water level for %s (%s)\n", mapname, fn);
+ aFree(rsw);
+ return NO_WATER;
+ }
+ int offset = 166;
+ if (major_version == 2 && minor_version >= 2) {
+ offset = 167;
+ }
//Load water height from file
- int wh = (int) *(float*)(rsw+166);
+ int wh = (int)*(float*)(rsw + offset);
aFree(rsw);
return wh;
}
diff --git a/src/plugins/mapcache.c b/src/plugins/mapcache.c
index 5e44492f6..208f39abb 100644
--- a/src/plugins/mapcache.c
+++ b/src/plugins/mapcache.c
@@ -281,7 +281,28 @@ bool mapcache_cache_map(const char *mapname)
if (rsw == NULL) {
water_height = NO_WATER;
} else {
- water_height = (int)GetFloat(rsw + 166);
+ if (memcmp(rsw, "GRSW", 4) != 0) {
+ ShowError("mapcache_cache_map: file %s is not in rsw format\n", filepath);
+ aFree(rsw);
+ return false;
+ }
+ int major_version = rsw[4];
+ int minor_version = rsw[5];
+ if (major_version > 2 || (major_version == 2 && minor_version > 2)) {
+ ShowError("mapcache_cache_map: Unsupported version %d.%d for rsw file %s\n", major_version, minor_version, filepath);
+ aFree(rsw);
+ return false;
+ }
+ if (major_version < 1 || (major_version == 1 && minor_version <= 4)) {
+ ShowError("mapcache_cache_map: Unsupported version %d.%d for rsw file %s\n", major_version, minor_version, filepath);
+ aFree(rsw);
+ return false;
+ }
+ int offset = 166;
+ if (major_version == 2 && minor_version >= 2) {
+ offset = 167;
+ }
+ water_height = (int)GetFloat(rsw + offset);
aFree(rsw);
}