diff options
Diffstat (limited to 'src/tool/mapcache.c')
-rw-r--r-- | src/tool/mapcache.c | 80 |
1 files changed, 17 insertions, 63 deletions
diff --git a/src/tool/mapcache.c b/src/tool/mapcache.c index 49f948709..2ead5edbb 100644 --- a/src/tool/mapcache.c +++ b/src/tool/mapcache.c @@ -1,18 +1,21 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder -#include "../common/cbasetypes.h" -#include "../common/grfio.h" -#include "../common/malloc.h" -#include "../common/mmo.h" -#include "../common/showmsg.h" +#define HERCULES_CORE -#include "../config/renewal.h" +#include "../config/core.h" // RENEWAL #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "../common/cbasetypes.h" +#include "../common/grfio.h" +#include "../common/malloc.h" +#include "../common/mmo.h" +#include "../common/showmsg.h" +#include "../common/utils.h" + #ifndef _WIN32 #include <unistd.h> #endif @@ -49,60 +52,10 @@ struct map_info { int32 len; }; - -/************************************* -* Big-endian compatibility functions * -*************************************/ - -// Converts an int16 from current machine order to little-endian -int16 MakeShortLE(int16 val) -{ - unsigned char buf[2]; - buf[0] = (unsigned char)( (val & 0x00FF) ); - buf[1] = (unsigned char)( (val & 0xFF00) >> 0x08 ); - return *((int16*)buf); -} - -// Converts an int32 from current machine order to little-endian -int32 MakeLongLE(int32 val) -{ - unsigned char buf[4]; - buf[0] = (unsigned char)( (val & 0x000000FF) ); - buf[1] = (unsigned char)( (val & 0x0000FF00) >> 0x08 ); - buf[2] = (unsigned char)( (val & 0x00FF0000) >> 0x10 ); - buf[3] = (unsigned char)( (val & 0xFF000000) >> 0x18 ); - return *((int32*)buf); -} - -// Reads an uint16 in little-endian from the buffer -uint16 GetUShort(const unsigned char* buf) -{ - return ( ((uint16)(buf[0])) ) - |( ((uint16)(buf[1])) << 0x08 ); -} - -// Reads an uint32 in little-endian from the buffer -uint32 GetULong(const unsigned char* buf) -{ - return ( ((uint32)(buf[0])) ) - |( ((uint32)(buf[1])) << 0x08 ) - |( ((uint32)(buf[2])) << 0x10 ) - |( ((uint32)(buf[3])) << 0x18 ); -} - -// Reads an int32 in little-endian from the buffer -int32 GetLong(const unsigned char* buf) -{ - return (int32)GetULong(buf); -} - -// Reads a float (32 bits) from the buffer -float GetFloat(const unsigned char* buf) -{ - uint32 val = GetULong(buf); - return *((float*)(void*)&val); -} - + /************************************* + * Big-endian compatibility functions * + * Moved to utils.h * + *************************************/ // Reads a map from GRF's GAT and RSW files int read_map(char *name, struct map_data *m) @@ -176,12 +129,13 @@ void cache_map(char *name, struct map_data *m) encode_zip(write_buf, &len, m->cells, m->xs*m->ys); // Fill the map header - if (strlen(name) > MAP_NAME_LENGTH) // It does not hurt to warn that there are maps with name longer than allowed. - ShowWarning ("Map name '%s' size '%d' is too long. Truncating to '%d'.\n", name, strlen(name), MAP_NAME_LENGTH); strncpy(info.name, name, MAP_NAME_LENGTH); + if (strlen(name) > MAP_NAME_LENGTH) // It does not hurt to warn that there are maps with name longer than allowed. + ShowWarning("Map name '%s' (length %"PRIuS") is too long. Truncating to '%s' (lentgh %d).\n", + name, strlen(name), info.name, MAP_NAME_LENGTH); info.xs = MakeShortLE(m->xs); info.ys = MakeShortLE(m->ys); - info.len = MakeLongLE(len); + info.len = MakeLongLE((uint32)len); // Append map header then compressed cells at the end of the file fseek(map_cache_fp, header.file_size, SEEK_SET); |