diff --git a/src/Client/DefScriptInterface.cpp b/src/Client/DefScriptInterface.cpp index 45b0af4..28d920f 100644 --- a/src/Client/DefScriptInterface.cpp +++ b/src/Client/DefScriptInterface.cpp @@ -90,10 +90,10 @@ DefReturnResult DefScriptPackage::SCSendChatMessage(CmdSet& Set){ if(ss.str()!=Set.arg[1]) // given lang is NOT a number { SCPDatabase *langdb = dbmgr.GetDB("language"); - uint32 dblang = langdb->GetFieldByStringValue("name",(char*)Set.arg[1].c_str()); + uint32 dblang = langdb->GetFieldByStringValue("name",Set.arg[1].c_str()); logdev("looking up language id for lang '%s', found %i",Set.arg[1].c_str(),dblang); // TODO: comment this out to enable using addon language??! - if(dblang != -1) + if(dblang != SCP_INVALID_INT) lang = dblang; } @@ -1237,7 +1237,7 @@ DefReturnResult DefScriptPackage::SCPreloadFile(CmdSet& Set) void DefScriptPackage::My_LoadUserPermissions(VarSet &vs) { - static char *prefix = "USERS::"; + static const char *prefix = "USERS::"; std::string sub,usr; for(uint32 i=0;iaddImage(driver->getTexture("data/misc/irrlichtlogo.png"), core::position2d(5,5)); - char *fn; + const char *fn; switch(gui->_driverType) { case video::EDT_DIRECT3D8: diff --git a/src/Client/GUI/SceneWorld.cpp b/src/Client/GUI/SceneWorld.cpp index 0d35923..0813909 100644 --- a/src/Client/GUI/SceneWorld.cpp +++ b/src/Client/GUI/SceneWorld.cpp @@ -668,7 +668,7 @@ void SceneWorld::UpdateTerrain(void) { for(uint32 i = 0; i < 10; i++) { - sprintf(fieldname_t,"file%u",i + 1); // starts with "file1" + sprintf(fieldname_t,"file%lu",i + 1); // starts with "file1" fieldId[i] = sounddb->GetFieldId(fieldname_t); } diff --git a/src/Client/PseuWoW.h b/src/Client/PseuWoW.h index f6a13ed..92442e8 100644 --- a/src/Client/PseuWoW.h +++ b/src/Client/PseuWoW.h @@ -148,7 +148,7 @@ private: bool _error; bool _createws, _creaters; // must create world/realm session? BigNumber _sessionkey; - char *_ver,*_ver_short; + const char *_ver,*_ver_short; SocketHandler _sh; CliRunnable *_cli; ZThread::Thread _clithread; diff --git a/src/Client/SCPDatabase.cpp b/src/Client/SCPDatabase.cpp index 349ac96..221691b 100644 --- a/src/Client/SCPDatabase.cpp +++ b/src/Client/SCPDatabase.cpp @@ -60,7 +60,7 @@ void SCPDatabase::DropTextData(void) fields.clear(); } -void *SCPDatabase::GetPtr(uint32 index, char *entry) +void *SCPDatabase::GetPtr(uint32 index, const char *entry) { std::map::iterator it = _indexes.find(index); if(it == _indexes.end()) @@ -84,7 +84,7 @@ void *SCPDatabase::GetPtrByField(uint32 index, uint32 entry) return (void*)&_intbuf[(_fields_per_row * target_row) + entry]; } -uint32 SCPDatabase::GetFieldByUint32Value(char *entry, uint32 val) +uint32 SCPDatabase::GetFieldByUint32Value(const char *entry, uint32 val) { std::map::iterator fi = _fielddefs.find(entry); if(fi == _fielddefs.end()) @@ -102,7 +102,7 @@ uint32 SCPDatabase::GetFieldByUint32Value(uint32 entry, uint32 val) return SCP_INVALID_INT; } -uint32 SCPDatabase::GetFieldByIntValue(char *entry, int32 val) +uint32 SCPDatabase::GetFieldByIntValue(const char *entry, int32 val) { std::map::iterator fi = _fielddefs.find(entry); if(fi == _fielddefs.end()) @@ -120,7 +120,7 @@ uint32 SCPDatabase::GetFieldByIntValue(uint32 entry, int32 val) return (int)SCP_INVALID_INT; } -uint32 SCPDatabase::GetFieldByStringValue(char *entry, char *val) +uint32 SCPDatabase::GetFieldByStringValue(const char *entry, const char *val) { std::map::iterator fi = _fielddefs.find(entry); if(fi == _fielddefs.end()) @@ -130,7 +130,7 @@ uint32 SCPDatabase::GetFieldByStringValue(char *entry, char *val) return GetFieldByStringValue(field_id,val); } -uint32 SCPDatabase::GetFieldByStringValue(uint32 entry, char *val) +uint32 SCPDatabase::GetFieldByStringValue(uint32 entry, const char *val) { for(uint32 row = 0; row < _rowcount; row++) if(!stricmp(GetStringByOffset(_intbuf[row * _fields_per_row + entry]), val)) @@ -138,7 +138,7 @@ uint32 SCPDatabase::GetFieldByStringValue(uint32 entry, char *val) return SCP_INVALID_INT; } -uint32 SCPDatabase::GetFieldType(char *entry) +uint32 SCPDatabase::GetFieldType(const char *entry) { std::map::iterator it = _fielddefs.find(entry); if(it != _fielddefs.end()) @@ -146,7 +146,7 @@ uint32 SCPDatabase::GetFieldType(char *entry) return SCP_INVALID_INT; } -uint32 SCPDatabase::GetFieldId(char *entry) +uint32 SCPDatabase::GetFieldId(const char *entry) { std::map::iterator it = _fielddefs.find(entry); if(it != _fielddefs.end()) @@ -159,7 +159,7 @@ SCPDatabase *SCPDatabaseMgr::GetDB(std::string n, bool create) return create ? _map.Get(n) : _map.GetNoCreate(n); } -uint32 SCPDatabaseMgr::AutoLoadFile(char *fn) +uint32 SCPDatabaseMgr::AutoLoadFile(const char *fn) { char *buf; uint32 size; @@ -241,7 +241,7 @@ uint32 SCPDatabaseMgr::AutoLoadFile(char *fn) // check the datatype that will be used for this string value -uint32 SCPDatabaseMgr::GetDataTypeFromString(char *s) +uint32 SCPDatabaseMgr::GetDataTypeFromString(const char *s) { bool isint = true, first = true; for(;*s;s++) // check every char until \0 is reached @@ -257,7 +257,7 @@ uint32 SCPDatabaseMgr::GetDataTypeFromString(char *s) return isint ? SCP_TYPE_INT : SCP_TYPE_FLOAT; } -bool SCPDatabaseMgr::Compact(char *dbname, char *outfile, uint32 compression) +bool SCPDatabaseMgr::Compact(const char *dbname, const char *outfile, uint32 compression) { logdebug("Compacting database '%s' into file '%s'", dbname, outfile); SCPDatabase *db = GetDB(dbname); @@ -587,7 +587,7 @@ void SCPDatabaseMgr::_FilterFiles(std::deque& files, std::string db DEBUG(logdebug("-> %u files belong to this DB",files.size())); } -uint32 SCPDatabaseMgr::SearchAndLoad(char *dbname, bool no_compiled) +uint32 SCPDatabaseMgr::SearchAndLoad(const char *dbname, bool no_compiled) { uint32 count = 0; std::deque goodfiles; @@ -668,7 +668,7 @@ uint32 SCPDatabaseMgr::SearchAndLoad(char *dbname, bool no_compiled) return count; } -void SCPDatabaseMgr::AddSearchPath(char *path) +void SCPDatabaseMgr::AddSearchPath(const char *path) { std::string p; @@ -700,7 +700,7 @@ void SCPDatabaseMgr::AddSearchPath(char *path) _paths.push_back(p); } -bool SCPDatabaseMgr::LoadCompactSCP(char *fn, char *dbname, uint32 nSourcefiles) +bool SCPDatabaseMgr::LoadCompactSCP(const char *fn, const char *dbname, uint32 nSourcefiles) { uint32 filesize = GetFileSize(fn); if(filesize < HEADER_SIZE) @@ -911,7 +911,7 @@ bool SCPDatabaseMgr::LoadCompactSCP(char *fn, char *dbname, uint32 nSourcefiles) } // used only for debugging -void SCPDatabase::DumpStructureToFile(char *fn) +void SCPDatabase::DumpStructureToFile(const char *fn) { std::ofstream f; f.open(fn); diff --git a/src/Client/SCPDatabase.h b/src/Client/SCPDatabase.h index 9b46b78..15c5676 100644 --- a/src/Client/SCPDatabase.h +++ b/src/Client/SCPDatabase.h @@ -45,32 +45,32 @@ public: void DropTextData(void); // access funcs - void *GetPtr(uint32 index, char *entry); + void *GetPtr(uint32 index, const char *entry); void *GetPtrByField(uint32 index, uint32 entry); inline char *GetStringByOffset(uint32 offs) { return (char*)(offs < _stringsize ? _stringbuf + offs : ""); } - inline char *GetString(uint32 index, char *entry) { return GetStringByOffset(GetUint32(index,entry)); } + inline char *GetString(uint32 index, const char *entry) { return GetStringByOffset(GetUint32(index,entry)); } inline char *GetString(uint32 index, uint32 entry) { return GetStringByOffset(GetUint32(index,entry)); } - inline uint32 GetUint32(uint32 index, char *entry) { uint32 *t = (uint32*)GetPtr(index,entry); return t ? *t : 0; } + inline uint32 GetUint32(uint32 index, const char *entry) { uint32 *t = (uint32*)GetPtr(index,entry); return t ? *t : 0; } inline uint32 GetUint32(uint32 index, uint32 entry) { uint32 *t = (uint32*)GetPtrByField(index,entry); return t ? *t : 0; } - inline int32 GetInt(uint32 index, char *entry) { int32 *t = (int32*)GetPtr(index,entry); return t ? *t : 0; } + inline int32 GetInt(uint32 index, const char *entry) { int32 *t = (int32*)GetPtr(index,entry); return t ? *t : 0; } inline int32 GetInt(uint32 index, uint32 entry) { int32 *t = (int32*)GetPtrByField(index,entry); return t ? *t : 0; } - inline float GetFloat(uint32 index, char *entry) { float *t = (float*)GetPtr(index,entry); return t ? *t : 0; } + inline float GetFloat(uint32 index, const char *entry) { float *t = (float*)GetPtr(index,entry); return t ? *t : 0; } inline float GetFloat(uint32 index, uint32 entry) { float *t = (float*)GetPtrByField(index,entry); return t ? *t : 0; } - uint32 GetFieldType(char *entry); - uint32 GetFieldId(char *entry); + uint32 GetFieldType(const char *entry); + uint32 GetFieldId(const char *entry); inline void *GetRowByIndex(uint32 index) { return GetPtrByField(index,0); } - uint32 GetFieldByUint32Value(char *entry, uint32 val); + uint32 GetFieldByUint32Value(const char *entry, uint32 val); uint32 GetFieldByUint32Value(uint32 entry, uint32 val); - uint32 GetFieldByIntValue(char *entry, int32 val); + uint32 GetFieldByIntValue(const char *entry, int32 val); uint32 GetFieldByIntValue(uint32 entry, int32 val); - uint32 GetFieldByStringValue(char *entry, char *val); - uint32 GetFieldByStringValue(uint32 entry, char *val); + uint32 GetFieldByStringValue(const char *entry, const char *val); + uint32 GetFieldByStringValue(uint32 entry, const char *val); // float value lookup not necessary inline uint32 GetFieldsCount(void) { return _fields_per_row; } inline uint32 GetRowsCount(void) { return _rowcount; } - void DumpStructureToFile(char *fn); + void DumpStructureToFile(const char *fn); private: // text data related SCPSourceList sources; @@ -97,13 +97,13 @@ class SCPDatabaseMgr public: SCPDatabaseMgr() : _compr(0) {} SCPDatabase *GetDB(std::string n, bool create = false); - uint32 AutoLoadFile(char *fn); + uint32 AutoLoadFile(const char *fn); inline void DropDB(std::string s) { _map.Delete(stringToLower(s)); } - bool Compact(char *dbname, char *outfile, uint32 compression = 0); - static uint32 GetDataTypeFromString(char *s); - uint32 SearchAndLoad(char*,bool); - void AddSearchPath(char*); - bool LoadCompactSCP(char*, char*, uint32); + bool Compact(const char *dbname, const char *outfile, uint32 compression = 0); + static uint32 GetDataTypeFromString(const char *s); + uint32 SearchAndLoad(const char*,bool); + void AddSearchPath(const char*); + bool LoadCompactSCP(const char*, const char*, uint32); void SetCompression(uint32 c) { _compr = c; } // min=0, max=9 uint32 GetCompression(void) { return _compr; } diff --git a/src/Client/World/CacheHandler.cpp b/src/Client/World/CacheHandler.cpp index 42afc0a..831b01a 100644 --- a/src/Client/World/CacheHandler.cpp +++ b/src/Client/World/CacheHandler.cpp @@ -55,7 +55,7 @@ bool PlayerNameCache::SaveToFile(void) return true; // no data to save, so we are fine logdebug("Saving PlayerNameCache..."); - char *fn="./cache/playernames.cache"; + const char *fn="./cache/playernames.cache"; std::fstream fh; fh.open(fn, std::ios_base::out | std::ios_base::binary); if(!fh) @@ -85,7 +85,7 @@ bool PlayerNameCache::SaveToFile(void) bool PlayerNameCache::ReadFromFile(void) { - char *fn="./cache/playernames.cache"; + const char *fn="./cache/playernames.cache"; log("Loading PlayerNameCache..."); bool success=true; std::fstream fh; @@ -139,7 +139,7 @@ uint32 PlayerNameCache::GetSize(void) void ItemProtoCache_InsertDataToSession(WorldSession *session) { logdetail("ItemProtoCache: Loading..."); - char* fn = "./cache/ItemPrototypes.cache"; + const char* fn = "./cache/ItemPrototypes.cache"; std::fstream fh; fh.open(fn, std::ios_base::in | std::ios_base::binary); if(!fh) @@ -288,7 +288,7 @@ void ItemProtoCache_WriteDataToCache(WorldSession *session) if (!session->objmgr.GetItemProtoCount()) return; - char* fn = "./cache/ItemPrototypes.cache"; + const char* fn = "./cache/ItemPrototypes.cache"; std::fstream fh; fh.open(fn, std::ios_base::out | std::ios_base::binary); if(!fh) @@ -411,7 +411,7 @@ void ItemProtoCache_WriteDataToCache(WorldSession *session) void CreatureTemplateCache_InsertDataToSession(WorldSession *session) { logdetail("CreatureTemplateCache: Loading..."); - char* fn = "./cache/CreatureTemplates.cache"; + const char* fn = "./cache/CreatureTemplates.cache"; std::fstream fh; fh.open(fn, std::ios_base::in | std::ios_base::binary); if(!fh) @@ -482,7 +482,7 @@ void CreatureTemplateCache_WriteDataToCache(WorldSession *session) if (!session->objmgr.GetCreatureTemplateCount()) return; - char* fn = "./cache/CreatureTemplates.cache"; + const char* fn = "./cache/CreatureTemplates.cache"; std::fstream fh; fh.open(fn, std::ios_base::out | std::ios_base::binary); if(!fh) @@ -526,7 +526,7 @@ void CreatureTemplateCache_WriteDataToCache(WorldSession *session) void GOTemplateCache_InsertDataToSession(WorldSession *session) { logdetail("GOTemplateCache: Loading..."); - char* fn = "./cache/GOTemplates.cache"; + const char* fn = "./cache/GOTemplates.cache"; std::fstream fh; fh.open(fn, std::ios_base::in | std::ios_base::binary); if(!fh) @@ -594,7 +594,7 @@ void GOTemplateCache_WriteDataToCache(WorldSession *session) if (!session->objmgr.GetGOTemplateCount()) return; - char* fn = "./cache/GOTemplates.cache"; + const char* fn = "./cache/GOTemplates.cache"; std::fstream fh; fh.open(fn, std::ios_base::out | std::ios_base::binary); if(!fh) diff --git a/src/Client/World/MapMgr.cpp b/src/Client/World/MapMgr.cpp index bdcdde2..1c08cd5 100644 --- a/src/Client/World/MapMgr.cpp +++ b/src/Client/World/MapMgr.cpp @@ -6,7 +6,7 @@ void MakeMapFilename(char *fn, uint32 m, uint32 x, uint32 y) { - sprintf(fn,"./data/maps/%u_%u_%u.adt",m,x,y); + sprintf(fn,"./data/maps/%lu_%lu_%lu.adt",m,x,y); } bool TileExistsInFile(uint32 m, uint32 x, uint32 y) @@ -38,7 +38,7 @@ void MapMgr::Update(float x, float y, uint32 m) Flush(); // we teleported to a new map, drop all loaded maps WDTFile *wdt = new WDTFile(); char buf[100]; - sprintf(buf,"data/maps/%u.wdt",m); + sprintf(buf,"data/maps/%lu.wdt",m); if(!wdt->Load(buf)) { logerror("MAPMGR: Could not load WDT file '%s'",buf); diff --git a/src/Client/World/UpdateData.cpp b/src/Client/World/UpdateData.cpp index 6fa759d..c4bbffe 100644 --- a/src/Client/World/UpdateData.cpp +++ b/src/Client/World/UpdateData.cpp @@ -573,7 +573,7 @@ bool IsFloatField(uint8 ty, uint32 f) }; if(ty & TYPE_OBJECT) - for(uint32 i = 0; floats_object[i] != (-1); i++) + for(uint32 i = 0; floats_object[i] != (uint32)(-1); i++) if(floats_object[i] == f) return true; /* @@ -587,23 +587,23 @@ bool IsFloatField(uint8 ty, uint32 f) return true; */ if(ty & TYPE_UNIT) - for(uint32 i = 0; floats_unit[i] != (-1); i++) + for(uint32 i = 0; floats_unit[i] != (uint32)(-1); i++) if(floats_unit[i] == f) return true; if(ty & TYPE_PLAYER) - for(uint32 i = 0; floats_player[i] != (-1); i++) + for(uint32 i = 0; floats_player[i] != (uint32)(-1); i++) if(floats_player[i] == f) return true; if(ty & TYPE_GAMEOBJECT) - for(uint32 i = 0; floats_gameobject[i] != (-1); i++) + for(uint32 i = 0; floats_gameobject[i] != (uint32)(-1); i++) if(floats_gameobject[i] == f) return true; if(ty & TYPE_DYNAMICOBJECT) - for(uint32 i = 0; floats_dynobject[i] != (-1); i++) + for(uint32 i = 0; floats_dynobject[i] != (uint32)(-1); i++) if(floats_dynobject[i] == f) return true; if(ty & TYPE_CORPSE) - for(uint32 i = 0; floats_corpse[i] != (-1); i++) + for(uint32 i = 0; floats_corpse[i] != (uint32)(-1); i++) if(floats_corpse[i] == f) return true; diff --git a/src/Client/World/WorldSession.cpp b/src/Client/World/WorldSession.cpp index fef7f00..e45a0c3 100644 --- a/src/Client/World/WorldSession.cpp +++ b/src/Client/World/WorldSession.cpp @@ -245,7 +245,7 @@ void WorldSession::HandleWorldPacket(WorldPacket *packet) catch (ByteBufferException bbe) { char errbuf[200]; - sprintf(errbuf,"attempt to \"%s\" %u bytes at position %u out of total %u bytes. (wpos=%u)", bbe.action, bbe.readsize, bbe.rpos, bbe.cursize, bbe.wpos); + sprintf(errbuf,"attempt to \"%s\" %lu bytes at position %lu out of total %lu bytes. (wpos=%lu)", bbe.action, bbe.readsize, bbe.rpos, bbe.cursize, bbe.wpos); logerror("Exception while handling opcode %u [%s]!",packet->GetOpcode(),GetOpcodeName(packet->GetOpcode())); logerror("WorldSession: ByteBufferException"); logerror("ByteBuffer reported: %s", errbuf); @@ -441,7 +441,7 @@ void WorldSession::_DoTimedActions(void) } } -std::string WorldSession::DumpPacket(WorldPacket& pkt, int errpos, char *errstr) +std::string WorldSession::DumpPacket(WorldPacket& pkt, int errpos, const char *errstr) { static std::map opstore; std::stringstream s; @@ -1584,7 +1584,7 @@ void WorldSession::_HandleWhoOpcode(WorldPacket& recvPacket) for(uint8 i = strlen(racename); strlen(racename) < 12; i++) racename[i] = ' '; char tmp[12]; - sprintf(tmp,"%u",wle.level); + sprintf(tmp,"%lu",wle.level); std::string lvl_str = tmp; while(lvl_str.length() < 3) lvl_str = " " + lvl_str; diff --git a/src/Client/World/WorldSession.h b/src/Client/World/WorldSession.h index 6a57fb2..d99fa5e 100644 --- a/src/Client/World/WorldSession.h +++ b/src/Client/World/WorldSession.h @@ -85,7 +85,7 @@ public: inline World *GetWorld(void) { return _world; } std::string GetOrRequestPlayerName(uint64); - std::string DumpPacket(WorldPacket& pkt, int errpos = -1, char *errstr = NULL); + std::string DumpPacket(WorldPacket& pkt, int errpos = -1, const char *errstr = NULL); inline uint32 GetCharsCount(void) { return _charList.size(); } inline CharacterListExt& GetCharFromList(uint32 id) { return _charList[id]; } diff --git a/src/Client/main.cpp b/src/Client/main.cpp index a508a34..a01c87e 100644 --- a/src/Client/main.cpp +++ b/src/Client/main.cpp @@ -92,7 +92,7 @@ int main(int argc, char* argv[]) std::set_new_handler(_new_handler); log_prepare("logfile.txt","a"); logcustom(0,LGREEN,"+----------------------------------+"); - logcustom(0,LGREEN,"| (C) 2006-2008 Snowstorm Software |"); + logcustom(0,LGREEN,"| (C) 2006-2009 Snowstorm Software |"); logcustom(0,LGREEN,"| http://www.mangosclient.org |"); logcustom(0,LGREEN,"+----------------------------------+"); logcustom(0,GREEN,"Platform: %s",PLATFORM_NAME); diff --git a/src/shared/log.cpp b/src/shared/log.cpp index 1baaab6..208fadb 100644 --- a/src/shared/log.cpp +++ b/src/shared/log.cpp @@ -10,7 +10,7 @@ FILE *logfile = NULL; uint8 loglevel = 0; bool logtime = false; -void log_prepare(char *fn, char *mode = NULL) +void log_prepare(const char *fn, const char *mode = NULL) { if(!mode) mode = "a"; @@ -49,7 +49,7 @@ void log(const char *str, ...) if(logfile) { - fprintf(logfile, getDateString().c_str()); + fprintf(logfile, "%s", getDateString().c_str()); va_start(ap, str); vfprintf(logfile, str, ap); fprintf(logfile, "\n" ); @@ -76,7 +76,7 @@ void logdetail(const char *str, ...) if(logfile) { - fprintf(logfile, getDateString().c_str()); + fprintf(logfile, "%s", getDateString().c_str()); va_start(ap, str); vfprintf(logfile, str, ap); fprintf(logfile, "\n" ); @@ -104,7 +104,7 @@ void logdebug(const char *str, ...) if(logfile) { - fprintf(logfile, getDateString().c_str()); + fprintf(logfile, "%s", getDateString().c_str()); va_start(ap, str); vfprintf(logfile, str, ap); fprintf(logfile, "\n" ); @@ -132,7 +132,7 @@ void logdev(const char *str, ...) if(logfile) { - fprintf(logfile, getDateString().c_str()); + fprintf(logfile, "%s", getDateString().c_str()); va_start(ap, str); vfprintf(logfile, str, ap); fprintf(logfile, "\n" ); @@ -157,7 +157,7 @@ void logerror(const char *str, ...) if(logfile) { - fprintf(logfile, getDateString().c_str()); + fprintf(logfile, "%s", getDateString().c_str()); va_start(ap, str); vfprintf(logfile, str, ap); fprintf(logfile, "\n" ); @@ -182,7 +182,7 @@ void logcritical(const char *str, ...) if(logfile) { - fprintf(logfile, getDateString().c_str()); + fprintf(logfile, "%s", getDateString().c_str()); va_start(ap, str); vfprintf(logfile, str, ap); fprintf(logfile, "\n" ); @@ -209,7 +209,7 @@ void logcustom(uint8 lvl, Color color, const char *str, ...) if(logfile) { - fprintf(logfile, getDateString().c_str()); + fprintf(logfile, "%s", getDateString().c_str()); va_start(ap, str); vfprintf(logfile, str, ap); fprintf(logfile, "\n" ); diff --git a/src/shared/log.h b/src/shared/log.h index a3be212..b264ed4 100644 --- a/src/shared/log.h +++ b/src/shared/log.h @@ -20,7 +20,7 @@ enum Color WHITE }; -void log_prepare(char *fn, char *mode); +void log_prepare(const char *fn, const char *mode); void log_setloglevel(uint8 lvl); void log_setlogtime(bool b); void log(const char *str, ...); diff --git a/src/shared/tools.cpp b/src/shared/tools.cpp index e22089d..1bb2dcf 100644 --- a/src/shared/tools.cpp +++ b/src/shared/tools.cpp @@ -6,14 +6,14 @@ #include #include "tools.h" -#if PLATFORM == PLATFORM_WIN32 +#if PLATFORM == PLATFORM_WIN32 # include -# include +# include # include # include #else -# include -# include +# include +# include # if defined(__FreeBSD__) || defined(__APPLE_CC__) # include # endif @@ -69,15 +69,15 @@ std::string toString(uint64 num){ std::string getDateString(void) { - time_t t = time(NULL); - tm* aTm = localtime(&t); - char str[30]; - // YYYY year - // MM month (2 digits 01-12) - // DD day (2 digits 01-31) - // HH hour (2 digits 00-23) - // MM minutes (2 digits 00-59) - // SS seconds (2 digits 00-59) + time_t t = time(NULL); + tm* aTm = localtime(&t); + char str[30]; + // YYYY year + // MM month (2 digits 01-12) + // DD day (2 digits 01-31) + // HH hour (2 digits 00-23) + // MM minutes (2 digits 00-59) + // SS seconds (2 digits 00-59) sprintf(str,"%-4d-%02d-%02d %02d:%02d:%02d ",aTm->tm_year+1900,aTm->tm_mon+1,aTm->tm_mday,aTm->tm_hour,aTm->tm_min,aTm->tm_sec); return std::string(str); } @@ -85,7 +85,7 @@ std::string getDateString(void) std::string GetTimeString(void) { time_t t = time(NULL); - tm* aTm = localtime(&t); + tm* aTm = localtime(&t); char str[15]; sprintf(str,"%02d:%02d:%02d", aTm->tm_hour,aTm->tm_min,aTm->tm_sec); return std::string(str); @@ -110,7 +110,7 @@ std::string toHexDump(uint8* array, uint32 size, bool spaces, uint32 per_line) { if(array[i]) { - sprintf(buf,(array[i]<=0x0F)?"0%X":"%X",(uint32)array[i]); + sprintf(buf,(array[i]<=0x0F)?"0%lX":"%lX",(uint32)array[i]); ss << buf; } else @@ -132,41 +132,41 @@ std::deque GetFileList(std::string path) { std::deque files; -# ifndef _WIN32 // TODO: fix this function for linux if needed - const char *p = path.c_str(); - DIR * dirp; - struct dirent * dp; - dirp = opendir(p); - while (dirp) - { - errno = 0; - if ((dp = readdir(dirp)) != NULL) - files.push_back(std::string(dp->d_name)); - else - break; - } - if(dirp) - closedir(dirp); - -# else - - if(path.at(path.length()-1)!='/') - path += "/"; - path += "*.*"; - const char *p = path.c_str(); - WIN32_FIND_DATA fil; - HANDLE hFil=FindFirstFile(p,&fil); - if(hFil!=INVALID_HANDLE_VALUE) - { - if( !(fil.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) - files.push_back(std::string(fil.cFileName)); - while(FindNextFile(hFil,&fil)) - { - if( !(fil.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) - files.push_back(std::string(fil.cFileName)); - } - } - +# ifndef _WIN32 // TODO: fix this function for linux if needed + const char *p = path.c_str(); + DIR * dirp; + struct dirent * dp; + dirp = opendir(p); + while (dirp) + { + errno = 0; + if ((dp = readdir(dirp)) != NULL) + files.push_back(std::string(dp->d_name)); + else + break; + } + if(dirp) + closedir(dirp); + +# else + + if(path.at(path.length()-1)!='/') + path += "/"; + path += "*.*"; + const char *p = path.c_str(); + WIN32_FIND_DATA fil; + HANDLE hFil=FindFirstFile(p,&fil); + if(hFil!=INVALID_HANDLE_VALUE) + { + if( !(fil.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) + files.push_back(std::string(fil.cFileName)); + while(FindNextFile(hFil,&fil)) + { + if( !(fil.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) + files.push_back(std::string(fil.cFileName)); + } + } + # endif return files; @@ -251,14 +251,14 @@ std::string _PathToFileName(std::string str) std::string NormalizeFilename(std::string s) { uint32 p; - while( (p = s.find('\\')) != std::string::npos)//Replace \ by / - { - s.replace(p,1,"/"); - } - while( (p = s.find(' ')) != std::string::npos)//Replace space by _ - { - s.replace(p,1,"_"); - } + while( (p = s.find('\\')) != std::string::npos)//Replace \ by / + { + s.replace(p,1,"/"); + } + while( (p = s.find(' ')) != std::string::npos)//Replace space by _ + { + s.replace(p,1,"_"); + } std::transform(s.begin(), s.end(), s.begin(), tolower); return s; } @@ -268,7 +268,7 @@ std::string FilesizeFormat(uint32 b) char buf[15]; if (b < 1024) { - sprintf(buf,"%u B",b); + sprintf(buf,"%lu B",b); } else if(b < 1024*1024) { diff --git a/src/tools/stuffextract/Locale.cpp b/src/tools/stuffextract/Locale.cpp index 63b60cb..a0d522c 100644 --- a/src/tools/stuffextract/Locale.cpp +++ b/src/tools/stuffextract/Locale.cpp @@ -5,8 +5,8 @@ bool locale_set=false; char my_locale[5]; -char *cconf = "WTF/config.wtf"; -char *cconfentry = "SET locale \""; +const char *cconf = "WTF/config.wtf"; +const char *cconfentry = "SET locale \""; void SetLocale(char *loc) { diff --git a/src/tools/stuffextract/MPQFile.cpp b/src/tools/stuffextract/MPQFile.cpp index 40a4546..6588b09 100644 --- a/src/tools/stuffextract/MPQFile.cpp +++ b/src/tools/stuffextract/MPQFile.cpp @@ -12,13 +12,13 @@ MPQFile::~MPQFile() Close(); } -bool MPQFile::HasFile(char *fn) +bool MPQFile::HasFile(const char *fn) { return SFileHasFile(_mpq,fn); } // get size of a file within an mpq archive -ByteBuffer MPQFile::ReadFile(char *fn) +ByteBuffer MPQFile::ReadFile(const char *fn) { ByteBuffer bb; HANDLE fh; @@ -31,7 +31,7 @@ ByteBuffer MPQFile::ReadFile(char *fn) return bb; } -uint32 MPQFile::GetFileSize(char *fn) +uint32 MPQFile::GetFileSize(const char *fn) { HANDLE fh; if(!SFileOpenFileEx(_mpq, fn, 0, &fh)) diff --git a/src/tools/stuffextract/MPQFile.h b/src/tools/stuffextract/MPQFile.h index 649ad17..0387651 100644 --- a/src/tools/stuffextract/MPQFile.h +++ b/src/tools/stuffextract/MPQFile.h @@ -12,9 +12,9 @@ public: MPQFile(const char*); ~MPQFile(); inline bool IsOpen(void) { return _isopen; } - ByteBuffer ReadFile(char*); - uint32 GetFileSize(char*); - bool HasFile(char*); + ByteBuffer ReadFile(const char*); + uint32 GetFileSize(const char*); + bool HasFile(const char*); void Close(void); private: diff --git a/src/tools/stuffextract/MPQHelper.cpp b/src/tools/stuffextract/MPQHelper.cpp index 94440a8..cc7e5a0 100644 --- a/src/tools/stuffextract/MPQHelper.cpp +++ b/src/tools/stuffextract/MPQHelper.cpp @@ -7,7 +7,7 @@ #define DATADIR "Data" -MPQHelper::MPQHelper(char *archive) +MPQHelper::MPQHelper(const char *archive) { // TODO: check which files are needed and which are not + recheck for correct ordering std::string dir = "Data/"; @@ -25,7 +25,7 @@ MPQHelper::MPQHelper(char *archive) for(uint32 i=1; i<=MAX_PATCH_NUMBER; i++) { char buf[200]; - sprintf(buf,"%spatch-%u%s",dir.c_str(),i,ext.c_str()); + sprintf(buf,"%spatch-%lu%s",dir.c_str(),i,ext.c_str()); _patches.push_front(buf); } _patches.push_front(ldir+"speech-"+GetLocale()+ext); @@ -40,7 +40,7 @@ MPQHelper::MPQHelper(char *archive) for(uint32 i=1; i<=MAX_PATCH_NUMBER; i++) { char buf[200]; - sprintf(buf,"%spatch-%s-%u%s",ldir.c_str(),GetLocale(),i,ext.c_str()); + sprintf(buf,"%spatch-%s-%lu%s",ldir.c_str(),GetLocale(),i,ext.c_str()); //if(FileExists(buf)) _patches.push_front(buf); } @@ -64,7 +64,7 @@ MPQHelper::~MPQHelper() } } -ByteBuffer MPQHelper::ExtractFile(char* fn) +ByteBuffer MPQHelper::ExtractFile(const char* fn) { ByteBuffer bb; for(std::list::iterator i = _files.begin(); i != _files.end(); i++) @@ -80,7 +80,7 @@ ByteBuffer MPQHelper::ExtractFile(char* fn) return bb; // will be empty if returned here } -bool MPQHelper::FileExists(char *fn) +bool MPQHelper::FileExists(const char *fn) { for(std::list::iterator i = _files.begin(); i != _files.end(); i++) { diff --git a/src/tools/stuffextract/MPQHelper.h b/src/tools/stuffextract/MPQHelper.h index 39cbef3..d041467 100644 --- a/src/tools/stuffextract/MPQHelper.h +++ b/src/tools/stuffextract/MPQHelper.h @@ -8,10 +8,10 @@ class MPQFile; class MPQHelper { public: - MPQHelper(char*); + MPQHelper(const char*); ~MPQHelper(); - ByteBuffer ExtractFile(char*); - bool FileExists(char*); + ByteBuffer ExtractFile(const char*); + bool FileExists(const char*); private: std::list _files; std::list _patches; diff --git a/src/tools/stuffextract/StormLib/SFileOpenFileEx.cpp b/src/tools/stuffextract/StormLib/SFileOpenFileEx.cpp index dae3121..515b119 100644 --- a/src/tools/stuffextract/StormLib/SFileOpenFileEx.cpp +++ b/src/tools/stuffextract/StormLib/SFileOpenFileEx.cpp @@ -166,7 +166,7 @@ int WINAPI SFileEnumLocales( // szFileName - Name of file to look for // TODO: Test for archives > 4GB -BOOL WINAPI SFileHasFile(HANDLE hMPQ, char * szFileName) +BOOL WINAPI SFileHasFile(HANDLE hMPQ, const char * szFileName) { TMPQArchive * ha = (TMPQArchive *)hMPQ; int nError = ERROR_SUCCESS; diff --git a/src/tools/stuffextract/StormLib/SFileReadFile.cpp b/src/tools/stuffextract/StormLib/SFileReadFile.cpp index 27fd1e0..6363bbd 100644 --- a/src/tools/stuffextract/StormLib/SFileReadFile.cpp +++ b/src/tools/stuffextract/StormLib/SFileReadFile.cpp @@ -25,7 +25,7 @@ struct TID2Ext { DWORD dwID; - char * szExt; + const char * szExt; }; //----------------------------------------------------------------------------- @@ -630,7 +630,7 @@ static TID2Ext id2ext[] = BOOL WINAPI SFileGetFileName(HANDLE hFile, char * szFileName) { TMPQFile * hf = (TMPQFile *)hFile; // MPQ File handle - char * szExt = "xxx"; // Default extension + const char * szExt = "xxx"; // Default extension DWORD dwFirstBytes[2]; // The first 4 bytes of the file DWORD dwFilePos; // Saved file position int nError = ERROR_SUCCESS; diff --git a/src/tools/stuffextract/StormLib/StormLib.h b/src/tools/stuffextract/StormLib/StormLib.h index 4316ba8..47c1858 100644 --- a/src/tools/stuffextract/StormLib/StormLib.h +++ b/src/tools/stuffextract/StormLib/StormLib.h @@ -529,7 +529,7 @@ BOOL WINAPI SFileRenameFile(HANDLE hMPQ, const char * szOldFileName, const char BOOL WINAPI SFileSetFileLocale(HANDLE hFile, LCID lcNewLocale); // Retrieving info about the file -BOOL WINAPI SFileHasFile(HANDLE hMPQ, char * szFileName); +BOOL WINAPI SFileHasFile(HANDLE hMPQ, const char * szFileName); BOOL WINAPI SFileGetFileName(HANDLE hFile, char * szFileName); DWORD_PTR WINAPI SFileGetFileInfo(HANDLE hMpqOrFile, DWORD dwInfoType); diff --git a/src/tools/stuffextract/StuffExtract.cpp b/src/tools/stuffextract/StuffExtract.cpp index 0e61343..9c0d732 100644 --- a/src/tools/stuffextract/StuffExtract.cpp +++ b/src/tools/stuffextract/StuffExtract.cpp @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) { char input[200]; printf("StuffExtract [version %u]\n",SE_VERSION); - printf("Use -help or -? to display help about command line arguments and config.\n\n",SE_VERSION); + printf("Use -help or -? to display help about command line arguments and config.\n\n"); ProcessCmdArgs(argc, argv); PrintConfig(); if(!GetLocale()) @@ -205,7 +205,7 @@ std::string AutoGetDataString(DBCFile::Iterator& it, const char* format, uint32 // output a formatted scp file -void OutSCP(char *fn, SCPStorageMap& scp, std::string dbName="") +void OutSCP(const char *fn, SCPStorageMap& scp, std::string dbName="") { std::fstream f; f.open(fn, std::ios_base::out); @@ -232,7 +232,7 @@ void OutSCP(char *fn, SCPStorageMap& scp, std::string dbName="") } } -void OutMD5(char *path, MD5FileMap& fm) +void OutMD5(const char *path, MD5FileMap& fm) { if(!doMd5) return; @@ -331,7 +331,7 @@ bool ConvertDBC(void) for(DBCFile::Iterator ix = EmotesTextData.begin(); ix != EmotesTextData.end(); ++ix) { textid = (*ix).getUInt(EMOTESTEXTDATA_TEXTID); - if(textid == (*it).getInt(field)) + if(textid == (*it).getUInt(field)) { fname = EmotesTextFieldNames[field]; for(uint8 stringpos=EMOTESTEXTDATA_STRING1; stringpos<=EMOTESTEXTDATA_STRING8; stringpos++) // we have 8 locales, so... @@ -482,7 +482,7 @@ bool ConvertDBC(void) { // lookup for model path DBCFile::Iterator itm = CreatureModelData.begin(); - for(; itm != CreatureDisplayInfo.end() && itm->getInt(CREATUREMODELDATA_ID) != modelid;) ++itm; + for(; itm != CreatureDisplayInfo.end() && itm->getUInt(CREATUREMODELDATA_ID) != modelid;) ++itm; std::string str = itm->getString(CREATUREMODELDATA_FILE); uint32 pathend = str.find_last_of("/\\"); @@ -625,7 +625,7 @@ void ExtractMaps(void) // extract the WDT file that stores tile information char wdt_name[300], wdt_out[300]; sprintf(wdt_name,"World\\Maps\\%s\\%s.wdt",it->second.c_str(),it->second.c_str()); - sprintf(wdt_out,MAPSDIR"/%u.wdt",it->first); + sprintf(wdt_out,MAPSDIR"/%lu.wdt",it->first); const ByteBuffer& wdt_bb = mpq.ExtractFile(wdt_name); std::fstream wdt_fh; wdt_fh.open(wdt_out, std::ios_base::out|std::ios_base::binary); @@ -648,8 +648,8 @@ void ExtractMaps(void) { uint32 olddeps; uint32 depdiff; - sprintf(namebuf,"World\\Maps\\%s\\%s_%u_%u.adt",it->second.c_str(),it->second.c_str(),x,y); - sprintf(outbuf,MAPSDIR"/%u_%u_%u.adt",it->first,x,y); + sprintf(namebuf,"World\\Maps\\%s\\%s_%lu_%lu.adt",it->second.c_str(),it->second.c_str(),x,y); + sprintf(outbuf,MAPSDIR"/%lu_%lu_%lu.adt",it->first,x,y); if(mpq.FileExists(namebuf)) { const ByteBuffer& bb = mpq.ExtractFile(namebuf); @@ -683,7 +683,7 @@ void ExtractMaps(void) memcpy(md5ptr, h.GetDigest(), MD5_DIGEST_LENGTH); } extr++; - printf("[%u:%u] %s; %u new deps.\n",extr,it->first,namebuf,depdiff); + printf("[%lu:%lu] %s; %lu new deps.\n",extr,it->first,namebuf,depdiff); } } } @@ -692,7 +692,7 @@ void ExtractMaps(void) printf("\n"); } - printf("\nDONE - %u maps extracted, %u total dependencies.\n",extrtotal, texNames.size() + modelNames.size() + wmoNames.size()); + printf("\nDONE - %lu maps extracted, %u total dependencies.\n",extrtotal, texNames.size() + modelNames.size() + wmoNames.size()); OutMD5(MAPSDIR,md5map); } @@ -951,7 +951,7 @@ void ExtractSoundFiles(void) printf("\n"); } -void ADT_ExportStringSetByOffset(const uint8* data, uint32 off, std::set& st, char* stop) +void ADT_ExportStringSetByOffset(const uint8* data, uint32 off, std::set& st,const char* stop) { data += ((uint32*)data)[off]; // seek to correct absolute offset data += 28; // move ptr to real start of data diff --git a/src/tools/stuffextract/StuffExtract.h b/src/tools/stuffextract/StuffExtract.h index b430999..8e58ccf 100644 --- a/src/tools/stuffextract/StuffExtract.h +++ b/src/tools/stuffextract/StuffExtract.h @@ -32,8 +32,8 @@ int main(int argc, char *argv[]); void ProcessCmdArgs(int argc, char *argv[]); void PrintConfig(void); void PrintHelp(void); -void OutSCP(char*, SCPStorageMap&, std::string); -void OutMD5(char*, MD5FileMap&); +void OutSCP(const char*, SCPStorageMap&, std::string); +void OutMD5(const char*, MD5FileMap&); bool ConvertDBC(void); void ExtractMaps(void); void ExtractMapDependencies(void); @@ -41,7 +41,7 @@ void ExtractSoundFiles(void); void FetchTexturesFromModel(ByteBuffer); -void ADT_ExportStringSetByOffset(const uint8*, uint32, std::set&, char*); +void ADT_ExportStringSetByOffset(const uint8*, uint32, std::set&, const char*); void ADT_FillTextureData(const uint8*,std::set&); void ADT_FillWMOData(const uint8*,std::set&); void ADT_FillModelData(const uint8*,std::set&);