From c01b32b03255989497ca5331de898804e6a39a1b Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 28 May 2012 19:04:44 -0300 Subject: [PATCH] rework log function and protocol * remove some protocol ifdefs, replace with game features system --- src/framework/application.cpp | 2 +- src/framework/core/configmanager.cpp | 2 +- src/framework/core/filestream.cpp | 44 ++-- src/framework/core/logger.cpp | 2 +- src/framework/core/logger.h | 18 +- src/framework/core/module.cpp | 10 +- src/framework/core/modulemanager.cpp | 10 +- src/framework/core/resourcemanager.cpp | 10 +- src/framework/graphics/fontmanager.cpp | 6 +- src/framework/graphics/graphics.cpp | 6 +- src/framework/graphics/image.cpp | 2 +- src/framework/graphics/particlemanager.cpp | 2 +- src/framework/graphics/shaderprogram.cpp | 4 +- src/framework/graphics/texture.cpp | 7 +- src/framework/graphics/texturemanager.cpp | 2 +- src/framework/luascript/luaexception.cpp | 8 +- src/framework/luascript/luainterface.cpp | 22 +- src/framework/luascript/luavaluecasts.h | 4 +- src/framework/net/inputmessage.cpp | 1 + src/framework/otml/otmlnode.cpp | 4 +- src/framework/otml/otmlnode.h | 2 +- src/framework/pch.h | 1 + src/framework/platform/unixcrashhandler.cpp | 2 +- src/framework/platform/win32crashhandler.cpp | 9 +- src/framework/platform/win32window.cpp | 2 +- src/framework/platform/x11window.cpp | 6 +- src/framework/sound/oggsoundfile.cpp | 2 +- src/framework/sound/soundbuffer.cpp | 6 +- src/framework/sound/soundfile.cpp | 4 +- src/framework/sound/soundmanager.cpp | 8 +- src/framework/sound/streamsoundsource.cpp | 4 +- src/framework/stdext/dumper.h | 2 + src/framework/stdext/string.h | 5 +- src/framework/ui/uianchorlayout.cpp | 2 +- src/framework/ui/uimanager.cpp | 10 +- src/framework/ui/uiwidget.cpp | 16 +- src/framework/ui/uiwidgetbasestyle.cpp | 2 +- src/otclient/const.h | 26 +++ src/otclient/core/game.cpp | 56 ++++- src/otclient/core/game.h | 15 ++ src/otclient/core/item.cpp | 4 +- src/otclient/core/spritemanager.cpp | 4 +- src/otclient/core/statictext.cpp | 2 +- src/otclient/core/thingstype.cpp | 4 +- src/otclient/core/tile.cpp | 10 +- src/otclient/net/protocolcodes.h | 19 +- src/otclient/net/protocolgame.cpp | 10 +- src/otclient/net/protocolgameparse.cpp | 204 +++++++++++-------- src/otclient/net/protocolgamesend.cpp | 42 ++-- src/otclient/net/protocollogin.cpp | 24 ++- src/otclient/otclient.cpp | 8 +- 51 files changed, 394 insertions(+), 283 deletions(-) diff --git a/src/framework/application.cpp b/src/framework/application.cpp index 46640f09..afbffc90 100644 --- a/src/framework/application.cpp +++ b/src/framework/application.cpp @@ -52,8 +52,8 @@ void exitSignalHandler(int sig) break; } } -Application::Application(const std::string& appName) +Application::Application(const std::string& appName) { g_app = this; m_appName = appName; diff --git a/src/framework/core/configmanager.cpp b/src/framework/core/configmanager.cpp index 0974501a..bc7bfe90 100644 --- a/src/framework/core/configmanager.cpp +++ b/src/framework/core/configmanager.cpp @@ -45,7 +45,7 @@ bool ConfigManager::load(const std::string& file) m_confsDoc = confsDoc; return true; } catch(stdext::exception& e) { - logError("could not load configurations: ", e.what()); + logError("Unable to load configuration file: %s", e.what()); return false; } } diff --git a/src/framework/core/filestream.cpp b/src/framework/core/filestream.cpp index 4e05703e..02fee053 100644 --- a/src/framework/core/filestream.cpp +++ b/src/framework/core/filestream.cpp @@ -48,7 +48,7 @@ void FileStream::cache() m_cacheBuffer.resize(size); int res = PHYSFS_read(m_fileHandle, &m_cacheBuffer[0], size, 1); if(res == -1) - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); PHYSFS_close(m_fileHandle); m_fileHandle = nullptr; @@ -58,7 +58,7 @@ bool FileStream::close() { if(m_fileHandle) { if(PHYSFS_isInit() && PHYSFS_close(m_fileHandle) == 0) - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); m_fileHandle = nullptr; return true; @@ -75,7 +75,7 @@ bool FileStream::flush() return false; if(PHYSFS_flush(m_fileHandle) == 0) { - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); return false; } return true; @@ -86,7 +86,7 @@ int FileStream::read(void *buffer, int size, int nmemb) if(m_fileHandle) { int res = PHYSFS_read(m_fileHandle, buffer, size, nmemb); if(res == -1) { - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); return 0; } return res; @@ -111,7 +111,7 @@ bool FileStream::write(void *buffer, int count) return false; if(PHYSFS_write(m_fileHandle, buffer, 1, count) != count) { - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); return false; } @@ -122,12 +122,12 @@ bool FileStream::seek(int pos) { if(m_fileHandle) { if(PHYSFS_seek(m_fileHandle, pos) == 0) { - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); return false; } } else { if(pos > (int)m_cacheBuffer.size() || pos < 0) { - logTraceError("operation failed on '", m_name, "': seek pos cannot be greater than file length"); + logTraceError("operation failed on '%s': seek pos cannot be greater than file length", m_name); return false; } m_cacheReadPos = pos; @@ -156,10 +156,10 @@ uint8 FileStream::getU8() uint8 v = 0; if(m_fileHandle) { if(PHYSFS_read(m_fileHandle, &v, 1, 1) != 1) - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); } else { if(m_cacheReadPos+1 > m_cacheBuffer.size()) { - logTraceError("operation failed on '", m_name, "': reached file eof"); + logTraceError("operation failed on '%s': reached file eof", m_name); return 0; } @@ -174,10 +174,10 @@ uint16 FileStream::getU16() uint16 v = 0; if(m_fileHandle) { if(PHYSFS_readULE16(m_fileHandle, &v) == 0) - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); } else { if(m_cacheReadPos+2 > m_cacheBuffer.size()) { - logTraceError("operation failed on '", m_name, "': reached file eof"); + logTraceError("operation failed on '%s': reached file eof", m_name); return 0; } @@ -192,10 +192,10 @@ uint32 FileStream::getU32() uint32 v = 0; if(m_fileHandle) { if(PHYSFS_readULE32(m_fileHandle, &v) == 0) - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); } else { if(m_cacheReadPos+4 > m_cacheBuffer.size()) { - logTraceError("operation failed on '", m_name, "': reached file eof"); + logTraceError("operation failed on '%s': reached file eof", m_name); return 0; } @@ -210,10 +210,10 @@ uint64 FileStream::getU64() uint64 v = 0; if(m_fileHandle) { if(PHYSFS_readULE64(m_fileHandle, (PHYSFS_uint64*)&v) == 0) - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); } else { if(m_cacheReadPos+8 > m_cacheBuffer.size()) { - logTraceError("operation failed on '", m_name, "': reached file eof"); + logTraceError("operation failed on '%s': reached file eof", m_name); return 0; } @@ -231,12 +231,12 @@ std::string FileStream::getString() char buffer[8192]; if(m_fileHandle) { if(PHYSFS_read(m_fileHandle, buffer, 1, len) == 0) - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); else str = std::string(buffer, len); } else { if(m_cacheReadPos+len > m_cacheBuffer.size()) { - logTraceError("operation failed on '", m_name, "': reached file eof"); + logTraceError("operation failed on '%s': reached file eof", m_name); return 0; } @@ -244,7 +244,7 @@ std::string FileStream::getString() m_cacheReadPos += len; } } else { - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); } return str; } @@ -252,23 +252,23 @@ std::string FileStream::getString() void FileStream::addU8(uint8 v) { if(PHYSFS_write(m_fileHandle, &v, 1, 1) != 1) - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); } void FileStream::addU16(uint8 v) { if(PHYSFS_writeULE16(m_fileHandle, v) == 0) - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); } void FileStream::addU32(uint8 v) { if(PHYSFS_writeULE32(m_fileHandle, v) == 0) - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); } void FileStream::addU64(uint8 v) { if(PHYSFS_writeULE64(m_fileHandle, v) == 0) - logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError()); + logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError()); } diff --git a/src/framework/core/logger.cpp b/src/framework/core/logger.cpp index 8c316b6f..18e8062d 100644 --- a/src/framework/core/logger.cpp +++ b/src/framework/core/logger.cpp @@ -89,7 +89,7 @@ void Logger::setLogFile(const std::string& file) { m_outFile.open(file.c_str(), std::ios::out | std::ios::app); if(!m_outFile.is_open() || !m_outFile.good()) { - logError("Unable to save log to '", file, "'"); + logError("Unable to save log to '%s'", file); return; } diff --git a/src/framework/core/logger.h b/src/framework/core/logger.h index f4ed2be8..092622bd 100644 --- a/src/framework/core/logger.h +++ b/src/framework/core/logger.h @@ -57,17 +57,17 @@ private: extern Logger g_logger; // specialized logging -#define logDebug(...) g_logger.log(Fw::LogDebug, stdext::mkstr(__VA_ARGS__)) -#define logInfo(...) g_logger.log(Fw::LogInfo, stdext::mkstr(__VA_ARGS__)) -#define logWarning(...) g_logger.log(Fw::LogWarning, stdext::mkstr(__VA_ARGS__)) -#define logError(...) g_logger.log(Fw::LogError, stdext::mkstr(__VA_ARGS__)) -#define logFatal(...) g_logger.log(Fw::LogFatal, stdext::mkstr(__VA_ARGS__)) +#define logDebug(...) g_logger.log(Fw::LogDebug, stdext::format(__VA_ARGS__)) +#define logInfo(...) g_logger.log(Fw::LogInfo, stdext::format(__VA_ARGS__)) +#define logWarning(...) g_logger.log(Fw::LogWarning, stdext::format(__VA_ARGS__)) +#define logError(...) g_logger.log(Fw::LogError, stdext::format(__VA_ARGS__)) +#define logFatal(...) g_logger.log(Fw::LogFatal, stdext::format(__VA_ARGS__)) #define logTrace() g_logger.logFunc(Fw::LogDebug, "", __PRETTY_FUNCTION__) -#define logTraceDebug(...) g_logger.logFunc(Fw::LogDebug, stdext::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__) -#define logTraceInfo(...) g_logger.logFunc(Fw::LogInfo, stdext::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__) -#define logTraceWarning(...) g_logger.logFunc(Fw::LogWarning, stdext::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__) -#define logTraceError(...) g_logger.logFunc(Fw::LogError, stdext::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__) +#define logTraceDebug(...) g_logger.logFunc(Fw::LogDebug, stdext::format(__VA_ARGS__), __PRETTY_FUNCTION__) +#define logTraceInfo(...) g_logger.logFunc(Fw::LogInfo, stdext::format(__VA_ARGS__), __PRETTY_FUNCTION__) +#define logTraceWarning(...) g_logger.logFunc(Fw::LogWarning, stdext::format(__VA_ARGS__), __PRETTY_FUNCTION__) +#define logTraceError(...) g_logger.logFunc(Fw::LogError, stdext::format(__VA_ARGS__), __PRETTY_FUNCTION__) #define logTraceCounter() { \ static int __count = 0; \ diff --git a/src/framework/core/module.cpp b/src/framework/core/module.cpp index 51dbfba8..d77abce8 100644 --- a/src/framework/core/module.cpp +++ b/src/framework/core/module.cpp @@ -39,12 +39,12 @@ bool Module::load() for(const std::string& depName : m_dependencies) { ModulePtr dep = g_modules.getModule(depName); if(!dep) { - logError("Unable to load module '", m_name, "' because dependency '", depName, "' was not found"); + logError("Unable to load module '%s' because dependency '%s' was not found", m_name, depName); return false; } if(!dep->isLoaded() && !dep->load()) { - logError("Unable to load module '", m_name, "' because dependency '", depName, "' has failed to laod"); + logError("Unable to load module '%s' because dependency '%s' has failed to load", m_name, depName); return false; } } @@ -53,13 +53,13 @@ bool Module::load() m_loadCallback(); m_loaded = true; - logInfo("Loaded module '", m_name, "'"); + logInfo("Loaded module '%s'", m_name); g_modules.updateModuleLoadOrder(asModule()); for(const std::string& modName : m_loadLaterModules) { ModulePtr dep = g_modules.getModule(modName); if(!dep) - logError("Unable to find module '", modName, "' required by '", m_name, "'"); + logError("Unable to find module '%s' required by '%s'", modName, m_name); else if(!dep->isLoaded()) dep->load(); } @@ -73,7 +73,7 @@ void Module::unload() if(m_unloadCallback) m_unloadCallback(); m_loaded = false; - logInfo("Unloaded module '", m_name, "'"); + logInfo("Unloaded module '%s'", m_name); g_modules.updateModuleLoadOrder(asModule()); } } diff --git a/src/framework/core/modulemanager.cpp b/src/framework/core/modulemanager.cpp index e3861189..32e3d644 100644 --- a/src/framework/core/modulemanager.cpp +++ b/src/framework/core/modulemanager.cpp @@ -70,7 +70,7 @@ void ModuleManager::discoverModulesPath() for(const std::string& dir : possibleModulesDirs) { // try to add module directory if(g_resources.addToSearchPath(dir, false)) { - logInfo("Using modules directory '", dir.c_str(), "'"); + logInfo("Using modules directory '%s'", dir.c_str()); found = true; break; } @@ -88,7 +88,7 @@ void ModuleManager::discoverModulesPath() for(const std::string& dir : possibleAddonsDirs) { // try to add module directory if(g_resources.addToSearchPath(dir, true)) { - logInfo("Using addons directory '", dir.c_str(), "'"); + logInfo("Using addons directory '%s'", dir.c_str()); found = true; break; } @@ -103,8 +103,6 @@ ModulePtr ModuleManager::discoverModule(const std::string& moduleFile) OTMLNodePtr moduleNode = doc->at("Module"); std::string name = moduleNode->valueAt("name"); - //if(getModule(name)) - // stdext::throw_exception("module '", name, "' already exists, cannot have duplicate module names"); bool push = false; module = getModule(name); @@ -118,7 +116,7 @@ ModulePtr ModuleManager::discoverModule(const std::string& moduleFile) if(push) m_modules.push_back(module); } catch(stdext::exception& e) { - logError("Unable to discover module from file '", moduleFile, "': ", e.what()); + logError("Unable to discover module from file '%s': %s", moduleFile, e.what()); } return module; } @@ -127,7 +125,7 @@ void ModuleManager::ensureModuleLoaded(const std::string& moduleName) { ModulePtr module = g_modules.getModule(moduleName); if(!module || !module->load()) - logFatal("Unable to load '", moduleName, "' module"); + logFatal("Unable to load '%s' module", moduleName); } void ModuleManager::unloadModules() diff --git a/src/framework/core/resourcemanager.cpp b/src/framework/core/resourcemanager.cpp index 4a7bc96d..492d039b 100644 --- a/src/framework/core/resourcemanager.cpp +++ b/src/framework/core/resourcemanager.cpp @@ -43,7 +43,7 @@ void ResourceManager::terminate() bool ResourceManager::setupWriteDir(const std::string& appWriteDirName) { std::string userDir = PHYSFS_getUserDir(); - std::string dirName = stdext::mkstr(".", appWriteDirName); + std::string dirName = stdext::format(".%s", appWriteDirName); std::string writeDir = userDir + dirName; if(!PHYSFS_setWriteDir(writeDir.c_str())) { if(!PHYSFS_setWriteDir(userDir.c_str())) @@ -150,7 +150,7 @@ FileStreamPtr ResourceManager::openFile(const std::string& fileName) std::string fullPath = resolvePath(fileName); PHYSFS_File* file = PHYSFS_openRead(fullPath.c_str()); if(!file) { - logTraceError("unable to open file '", fullPath, "': ", PHYSFS_getLastError()); + logTraceError("unable to open file '%s': %s", fullPath, PHYSFS_getLastError()); return nullptr; } return FileStreamPtr(new FileStream(fullPath, file)); @@ -160,7 +160,7 @@ FileStreamPtr ResourceManager::appendFile(const std::string& fileName) { PHYSFS_File* file = PHYSFS_openAppend(fileName.c_str()); if(!file) { - logTraceError("failed to append file '", fileName, "': ", PHYSFS_getLastError()); + logTraceError("failed to append file '%s': %s", fileName, PHYSFS_getLastError()); return nullptr; } return FileStreamPtr(new FileStream(fileName, file)); @@ -170,7 +170,7 @@ FileStreamPtr ResourceManager::createFile(const std::string& fileName) { PHYSFS_File* file = PHYSFS_openWrite(fileName.c_str()); if(!file) { - logTraceError("failed to create file '", fileName, "': ", PHYSFS_getLastError()); + logTraceError("failed to create file '%s': %s", fileName, PHYSFS_getLastError()); return nullptr; } return FileStreamPtr(new FileStream(fileName, file)); @@ -211,7 +211,7 @@ std::string ResourceManager::resolvePath(const std::string& path) fullPath += path; } if(!(boost::starts_with(fullPath, "/"))) - logTraceWarning("the following file path is not fully resolved: ", path); + logTraceWarning("the following file path is not fully resolved: %s", path); boost::replace_all(fullPath, "//", "/"); return fullPath; } diff --git a/src/framework/graphics/fontmanager.cpp b/src/framework/graphics/fontmanager.cpp index 7cbfa1a4..2b07d206 100644 --- a/src/framework/graphics/fontmanager.cpp +++ b/src/framework/graphics/fontmanager.cpp @@ -48,8 +48,6 @@ bool FontManager::importFont(std::string fontFile) OTMLNodePtr fontNode = doc->at("Font"); std::string name = fontNode->valueAt("name"); - //if(fontExists(name)) - // stdext::throw_exception("font '", name, "' already exists, cannot have duplicate font names"); // remove any font with the same name for(auto it = m_fonts.begin(); it != m_fonts.end(); ++it) { @@ -69,7 +67,7 @@ bool FontManager::importFont(std::string fontFile) return true; } catch(stdext::exception& e) { - logError("Unable to load font from file '", fontFile, "': ", e.what()); + logError("Unable to load font from file '%s': %s", fontFile, e.what()); return false; } } @@ -92,7 +90,7 @@ FontPtr FontManager::getFont(const std::string& fontName) } // when not found, fallback to default font - logError("font '", fontName, "' not found"); + logError("font '%s' not found", fontName); return getDefaultFont(); } diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index c2eb92cd..b54e6cc2 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -45,8 +45,8 @@ Graphics::Graphics() void Graphics::init() { - logInfo("GPU ", glGetString(GL_RENDERER)); - logInfo("OpenGL ", glGetString(GL_VERSION)); + logInfo("GPU %s", glGetString(GL_RENDERER)); + logInfo("OpenGL %s", glGetString(GL_VERSION)); #if OPENGL_ES==2 g_painterOGL2 = new PainterOGL2; @@ -56,7 +56,7 @@ void Graphics::init() // init GL extensions GLenum err = glewInit(); if(err != GLEW_OK) - logFatal("Unable to init GLEW: ", glewGetErrorString(err)); + logFatal("Unable to init GLEW: %s", glewGetErrorString(err)); // overwrite framebuffer API if needed if(GLEW_EXT_framebuffer_object && !GLEW_ARB_framebuffer_object) { diff --git a/src/framework/graphics/image.cpp b/src/framework/graphics/image.cpp index 260042d7..3df1c4b8 100644 --- a/src/framework/graphics/image.cpp +++ b/src/framework/graphics/image.cpp @@ -46,7 +46,7 @@ ImagePtr Image::load(const std::string& file) // load image file data image = loadPNG(file); } catch(stdext::exception& e) { - logError("unable to load image '", file, "': ", e.what()); + logError("unable to load image '%s': %s", file, e.what()); } return image; } diff --git a/src/framework/graphics/particlemanager.cpp b/src/framework/graphics/particlemanager.cpp index 8968411a..fca6d4ba 100644 --- a/src/framework/graphics/particlemanager.cpp +++ b/src/framework/graphics/particlemanager.cpp @@ -39,7 +39,7 @@ bool ParticleManager::load(const std::string& filename) } return true; } catch(stdext::exception& e) { - logError("could not load particles: ", e.what()); + logError("could not load particles: %s", e.what()); return false; } } diff --git a/src/framework/graphics/shaderprogram.cpp b/src/framework/graphics/shaderprogram.cpp index a08e8d4d..6fa29cc2 100644 --- a/src/framework/graphics/shaderprogram.cpp +++ b/src/framework/graphics/shaderprogram.cpp @@ -48,7 +48,7 @@ bool ShaderProgram::addShader(const ShaderPtr& shader) { bool ShaderProgram::addShaderFromSourceCode(Shader::ShaderType shaderType, const std::string& sourceCode) { ShaderPtr shader(new Shader(shaderType)); if(!shader->compileSourceCode(sourceCode)) { - logError("failed to compile shader: ", shader->log()); + logError("failed to compile shader: %s", shader->log()); return false; } return addShader(shader); @@ -57,7 +57,7 @@ bool ShaderProgram::addShaderFromSourceCode(Shader::ShaderType shaderType, const bool ShaderProgram::addShaderFromSourceFile(Shader::ShaderType shaderType, const std::string& sourceFile) { ShaderPtr shader(new Shader(shaderType)); if(!shader->compileSourceFile(sourceFile)) { - logError("failed to compile shader: ", shader->log()); + logError("failed to compile shader: %s", shader->log()); return false; } return addShader(shader); diff --git a/src/framework/graphics/texture.cpp b/src/framework/graphics/texture.cpp index 801384bc..9b9aae0b 100644 --- a/src/framework/graphics/texture.cpp +++ b/src/framework/graphics/texture.cpp @@ -82,9 +82,10 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int // checks texture max size if(std::max(glSize.width(), glSize.height()) > g_graphics.getMaxTextureSize()) { - logError("loading texture with size ", width, "x", height, " failed, " - "the maximum size allowed by the graphics card is ", g_graphics.getMaxTextureSize(), "x", g_graphics.getMaxTextureSize(), ",", - "to prevent crashes the texture will be displayed as a blank texture"); + logError("loading texture with size %dx%d failed, " + "the maximum size allowed by the graphics card is %dx%d," + "to prevent crashes the texture will be displayed as a blank texture", + width, height, g_graphics.getMaxTextureSize(), g_graphics.getMaxTextureSize()); //TODO: make a workaround, could be bilinear scaling the texture return 0; } diff --git a/src/framework/graphics/texturemanager.cpp b/src/framework/graphics/texturemanager.cpp index 7b130e1b..3a76dc35 100644 --- a/src/framework/graphics/texturemanager.cpp +++ b/src/framework/graphics/texturemanager.cpp @@ -57,7 +57,7 @@ TexturePtr TextureManager::getTexture(const std::string& fileName) g_resources.loadFile(filePath, fin); texture = loadPNG(fin); } catch(stdext::exception& e) { - logError("unable to load texture '", fileName, "': ", e.what()); + logError("unable to load texture '%s': %s", fileName, e.what()); texture = g_graphics.getEmptyTexture(); } diff --git a/src/framework/luascript/luaexception.cpp b/src/framework/luascript/luaexception.cpp index c1c89980..3ba990a7 100644 --- a/src/framework/luascript/luaexception.cpp +++ b/src/framework/luascript/luaexception.cpp @@ -33,21 +33,21 @@ void LuaException::generateLuaErrorMessage(const std::string& error, int traceLe { // append trace level to error message if(traceLevel >= 0) - m_what = stdext::mkstr("LUA ERROR: ", g_lua.traceback(error, traceLevel)); + m_what = stdext::format("LUA ERROR: %s", g_lua.traceback(error, traceLevel)); else - m_what = stdext::mkstr("LUA ERROR: ", error); + m_what = stdext::format("LUA ERROR: %s", error); } LuaBadNumberOfArgumentsException::LuaBadNumberOfArgumentsException(int expected, int got) { std::string error = "attempt to call a function with wrong number of arguments"; if(expected >= 0 && got >= 0) - error = stdext::mkstr(error, " (expected ", expected, ", but got ", got, ")"); + error = stdext::format("%s (expected %d, but got %d)", error, expected, got); generateLuaErrorMessage(error, 1); } LuaBadValueCastException::LuaBadValueCastException(const std::string& luaTypeName, const std::string& cppTypeName) { - std::string error = stdext::mkstr("attempt to cast a '", luaTypeName, "' lua value to '", cppTypeName, "'"); + std::string error = stdext::format("attempt to cast a '%s' lua value to '%s'", luaTypeName, cppTypeName); generateLuaErrorMessage(error, 0); } diff --git a/src/framework/luascript/luainterface.cpp b/src/framework/luascript/luainterface.cpp index 07340d01..42afca01 100644 --- a/src/framework/luascript/luainterface.cpp +++ b/src/framework/luascript/luainterface.cpp @@ -163,12 +163,12 @@ void LuaInterface::registerClassMemberField(const std::string& className, if(getFunction) { pushCppFunction(getFunction); - setField(stdext::mkstr("get_", field)); + setField(stdext::format("get_%s", field)); } if(setFunction) { pushCppFunction(setFunction); - setField(stdext::mkstr("set_", field)); + setField(stdext::format("set_%s", field)); } pop(); @@ -324,9 +324,9 @@ void LuaInterface::loadFunction(const std::string& buffer, const std::string& so std::string buf; if(boost::starts_with(buffer, "function")) - buf = stdext::mkstr("__func = ", buffer); + buf = stdext::format("__func = %s", buffer); else - buf = stdext::mkstr("__func = function(self)\n", buffer,"\nend"); + buf = stdext::format("__func = function(self)\n%s\nend", buffer); loadBuffer(buf, source); safeCall(); @@ -343,7 +343,7 @@ void LuaInterface::evaluateExpression(const std::string& expression, const std:: { // evaluates the expression if(!expression.empty()) { - std::string buffer = stdext::mkstr("__exp = (", expression, ")"); + std::string buffer = stdext::format("__exp = (%s)", expression); loadBuffer(buffer, source); safeCall(); @@ -480,7 +480,7 @@ int LuaInterface::protectedCall(int numArgs, int requestedResults) throw LuaException("attempt to call a non function value", 0); } } catch(LuaException &e) { - logError("protected lua call failed: ", e.what()); + logError("protected lua call failed: %s", e.what()); } // pushes nil values if needed @@ -515,7 +515,7 @@ int LuaInterface::luaScriptLoader(lua_State* L) g_lua.loadScript(fileName); return 1; } catch(LuaException& e) { - logError("failed to load script file '", fileName, "' :'", e.what()); + logError("failed to load script file '%s': %s", fileName, e.what()); return 0; } } @@ -531,7 +531,7 @@ int LuaInterface::luaScriptRunner(lua_State* L) g_lua.call(0, LUA_MULTRET); return g_lua.stackSize(); } catch(LuaException& e) { - logError("failed to load script file '", fileName, "' :'", e.what()); + logError("failed to load script file '%s': %s", fileName, e.what()); return 0; } } @@ -548,7 +548,7 @@ int LuaInterface::luaScriptsRunner(lua_State* L) g_lua.loadScript(directory + "/" + fileName); g_lua.call(0, 0); } catch(LuaException& e) { - logError("failed to load script file '", fileName, "' :'", e.what()); + logError("failed to load script file '%s': %s", fileName, e.what()); } } return 0; @@ -583,7 +583,7 @@ int LuaInterface::luaCppFunctionCallback(lua_State* L) g_lua.m_cppCallbackDepth--; assert(numRets == g_lua.stackSize()); } catch(LuaException &e) { - logError("lua cpp callback failed: ", e.what()); + logError("lua cpp callback failed: %s", e.what()); } return numRets; @@ -1019,7 +1019,7 @@ void LuaInterface::pushObject(const LuaObjectPtr& obj) new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj); // set the userdata metatable - getGlobal(stdext::mkstr(obj->getClassName(), "_mt")); + getGlobal(stdext::format("%s_mt", obj->getClassName())); assert(!isNil()); setMetatable(); } diff --git a/src/framework/luascript/luavaluecasts.h b/src/framework/luascript/luavaluecasts.h index fae0751f..d1351629 100644 --- a/src/framework/luascript/luavaluecasts.h +++ b/src/framework/luascript/luavaluecasts.h @@ -205,7 +205,7 @@ bool luavalue_cast(int index, std::function& func) { "did you forget to hold a reference for that function?", 0); } } catch(LuaException& e) { - logError("lua function callback failed: ", e.what()); + logError("lua function callback failed: %s", e.what()); } }; return true; @@ -239,7 +239,7 @@ luavalue_cast(int index, std::function& func) { "did you forget to hold a reference for that function?", 0); } } catch(LuaException& e) { - logError("lua function callback failed: ", e.what()); + logError("lua function callback failed: %s", e.what()); } return Ret(); }; diff --git a/src/framework/net/inputmessage.cpp b/src/framework/net/inputmessage.cpp index e56f2ca9..771ee61a 100644 --- a/src/framework/net/inputmessage.cpp +++ b/src/framework/net/inputmessage.cpp @@ -86,6 +86,7 @@ std::string InputMessage::getString() void InputMessage::decryptRSA(int size, const std::string& p, const std::string& q, const std::string& d) { + checkRead(size); RSA::decrypt((char*)m_buffer + m_readPos, size, p.c_str(), q.c_str(), d.c_str()); } diff --git a/src/framework/otml/otmlnode.cpp b/src/framework/otml/otmlnode.cpp index 450f74f2..7160fe08 100644 --- a/src/framework/otml/otmlnode.cpp +++ b/src/framework/otml/otmlnode.cpp @@ -77,14 +77,14 @@ OTMLNodePtr OTMLNode::at(const std::string& childTag) } } if(!res) - throw OTMLException(shared_from_this(), stdext::mkstr("child node with tag '", childTag, "' not found")); + throw OTMLException(shared_from_this(), stdext::format("child node with tag '%s' not found", childTag)); return res; } OTMLNodePtr OTMLNode::atIndex(int childIndex) { if(childIndex >= size() || childIndex < 0) - throw OTMLException(shared_from_this(), stdext::mkstr("child node with index '", childIndex, "' not found")); + throw OTMLException(shared_from_this(), stdext::mkstr("child node with index '%d' not found", childIndex)); return m_children[childIndex]; } diff --git a/src/framework/otml/otmlnode.h b/src/framework/otml/otmlnode.h index 60f40ff5..bd75172d 100644 --- a/src/framework/otml/otmlnode.h +++ b/src/framework/otml/otmlnode.h @@ -108,7 +108,7 @@ template T OTMLNode::value() { T ret; if(!stdext::cast(m_value, ret)) - throw OTMLException(shared_from_this(), stdext::mkstr("failed to cast node value to type '", stdext::demangle_type(), "'")); + throw OTMLException(shared_from_this(), stdext::mkstr("failed to cast node value to type '%s'", stdext::demangle_type())); return ret; } diff --git a/src/framework/pch.h b/src/framework/pch.h index 3946f1b6..e167b528 100644 --- a/src/framework/pch.h +++ b/src/framework/pch.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include diff --git a/src/framework/platform/unixcrashhandler.cpp b/src/framework/platform/unixcrashhandler.cpp index 22794042..ce8dbd2e 100644 --- a/src/framework/platform/unixcrashhandler.cpp +++ b/src/framework/platform/unixcrashhandler.cpp @@ -109,7 +109,7 @@ void crashHandler(int signum, siginfo_t* info, void* secret) fout << ss.str(); fout << "\n"; fout.close(); - logInfo("Crash report saved to file ", fileName.c_str()); + logInfo("Crash report saved to file %s", fileName.c_str()); } else logError("Failed to save crash report!"); diff --git a/src/framework/platform/win32crashhandler.cpp b/src/framework/platform/win32crashhandler.cpp index 39dc8c83..0af021c9 100644 --- a/src/framework/platform/win32crashhandler.cpp +++ b/src/framework/platform/win32crashhandler.cpp @@ -134,14 +134,15 @@ LONG CALLBACK ExceptionHandler(LPEXCEPTION_POINTERS e) if(fout.is_open() && fout.good()) { fout << ss.str(); fout.close(); - logInfo("Crash report saved to file ", fileName); + logInfo("Crash report saved to file %s", fileName); } else logError("Failed to save crash report!"); // inform the user - std::string msg = stdext::format("The application has crashed.\n\n" - "A crash report has been written to:\n" - "%s", fileName.c_str()); + std::string msg = stdext::format( + "The application has crashed.\n\n" + "A crash report has been written to:\n" + "%s", fileName.c_str()); MessageBox(NULL, msg.c_str(), "Application crashed", 0); // this seems to silently close the application diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index 87b6c7bf..70bf5aa8 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -680,7 +680,7 @@ void WIN32Window::setMouseCursor(const std::string& file, const Point& hotSpot) apng_data apng; if(load_apng(fin, &apng) != 0) { - logTraceError("unable to load png file ", file); + logTraceError("unable to load png file %s", file); return; } diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index cb916fc2..8df61040 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -416,7 +416,7 @@ void X11Window::internalCreateGLContext() m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, attrList); if(m_eglContext == EGL_NO_CONTEXT ) - logFatal("Unable to create EGL context: ", eglGetError()); + logFatal("Unable to create EGL context: %s", eglGetError()); #else m_glxContext = glXCreateContext(m_display, m_visual, NULL, True); @@ -457,7 +457,7 @@ void X11Window::internalConnectGLContext() #ifdef OPENGL_ES m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_window, NULL); if(m_eglSurface == EGL_NO_SURFACE) - logFatal("Unable to create EGL surface: ", eglGetError()); + logFatal("Unable to create EGL surface: %s", eglGetError()); if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext)) logFatal("Unable to connect EGL context into X11 window"); #else @@ -841,7 +841,7 @@ void X11Window::setMouseCursor(const std::string& file, const Point& hotSpot) apng_data apng; if(load_apng(fin, &apng) != 0) { - logTraceError("unable to load png file ", file); + logTraceError("unable to load png file %s", file); return; } diff --git a/src/framework/sound/oggsoundfile.cpp b/src/framework/sound/oggsoundfile.cpp index a7010dc6..9f81b683 100644 --- a/src/framework/sound/oggsoundfile.cpp +++ b/src/framework/sound/oggsoundfile.cpp @@ -39,7 +39,7 @@ bool OggSoundFile::prepareOgg() vorbis_info* vi = ov_info(&m_vorbisFile, -1); if(!vi) { - logError("ogg file not supported: ", m_file->name()); + logError("ogg file not supported: %s", m_file->name()); return false; } diff --git a/src/framework/sound/soundbuffer.cpp b/src/framework/sound/soundbuffer.cpp index f72c1f1b..92120c2d 100644 --- a/src/framework/sound/soundbuffer.cpp +++ b/src/framework/sound/soundbuffer.cpp @@ -40,14 +40,14 @@ bool SoundBuffer::fillBuffer(const SoundFilePtr& soundFile) { ALenum format = soundFile->getSampleFormat(); if(format == AL_UNDETERMINED) { - logError("unable to determine sample format for '", soundFile->getName(), "'"); + logError("unable to determine sample format for '%s'", soundFile->getName()); return false; } DataBuffer samples(soundFile->getSize()); int read = soundFile->read(&samples[0], soundFile->getSize()); if(read <= 0) { - logError("unable to fill audio buffer data for '", soundFile->getName(), "'"); + logError("unable to fill audio buffer data for '%s'", soundFile->getName()); return false; } @@ -59,7 +59,7 @@ bool SoundBuffer::fillBuffer(ALenum sampleFormat, const DataBuffer& data, alBufferData(m_bufferId, sampleFormat, &data[0], size, rate); ALenum err = alGetError(); if(err != AL_NO_ERROR) { - logError("unable to fill audio buffer data: ", alGetString(err)); + logError("unable to fill audio buffer data: %s", alGetString(err)); return false; } return true; diff --git a/src/framework/sound/soundfile.cpp b/src/framework/sound/soundfile.cpp index 509c761e..10f87a22 100644 --- a/src/framework/sound/soundfile.cpp +++ b/src/framework/sound/soundfile.cpp @@ -33,7 +33,7 @@ SoundFilePtr SoundFile::loadSoundFile(const std::string& filename) { FileStreamPtr file = g_resources.openFile(filename); if(!file) { - logTraceError("unable to open ", filename); + logTraceError("unable to open %s", filename); return nullptr; } @@ -50,7 +50,7 @@ SoundFilePtr SoundFile::loadSoundFile(const std::string& filename) if(oggSoundFile->prepareOgg()) soundFile = oggSoundFile; } else - logError("unknown sound file format ", filename); + logError("unknown sound file format %s", filename); return soundFile; } diff --git a/src/framework/sound/soundmanager.cpp b/src/framework/sound/soundmanager.cpp index 37151f24..cb49cc33 100644 --- a/src/framework/sound/soundmanager.cpp +++ b/src/framework/sound/soundmanager.cpp @@ -42,7 +42,7 @@ void SoundManager::init() m_context = alcCreateContext(m_device, NULL); if(!m_context) { - logError("unable to create audio context: ", alcGetString(m_device, alcGetError(m_device))); + logError("unable to create audio context: %s", alcGetString(m_device, alcGetError(m_device))); return; } alcMakeContextCurrent(m_context); @@ -136,7 +136,7 @@ void SoundManager::play(const std::string& filename) SoundSourcePtr soundSource = createSoundSource(filename); if(!soundSource) { - logError("unable to play '", filename, "'"); + logError("unable to play '%s'", filename); return; } @@ -175,7 +175,7 @@ void SoundManager::playMusic(const std::string& filename, float fadetime) m_musicSource = createSoundSource(filename); if(!m_musicSource) { - logError("unable to play '", filename, "'"); + logError("unable to play '%s'", filename); return; } @@ -218,7 +218,7 @@ SoundSourcePtr SoundManager::createSoundSource(const std::string& filename) buffer->fillBuffer(soundFile); source->setBuffer(buffer); m_buffers[filename] = buffer; - logWarning("uncached sound '", filename, "' requested to be played"); + logWarning("uncached sound '%s' requested to be played", filename); } else { StreamSoundSourcePtr streamSource(new StreamSoundSource); streamSource->setSoundFile(soundFile); diff --git a/src/framework/sound/streamsoundsource.cpp b/src/framework/sound/streamsoundsource.cpp index ffffa1aa..64bd7402 100644 --- a/src/framework/sound/streamsoundsource.cpp +++ b/src/framework/sound/streamsoundsource.cpp @@ -143,12 +143,12 @@ bool StreamSoundSource::fillBufferAndQueue(ALuint buffer) alBufferData(buffer, format, &bufferData[0], bytesRead, m_soundFile->getRate()); ALenum err = alGetError(); if(err != AL_NO_ERROR) - logError("unable to refill audio buffer for '", m_soundFile->getName(), "': ", alGetString(err)); + logError("unable to refill audio buffer for '%s': %s", m_soundFile->getName(), alGetString(err)); alSourceQueueBuffers(m_sourceId, 1, &buffer); err = alGetError(); if(err != AL_NO_ERROR) - logError("unable to queue audio buffer for '", m_soundFile->getName(), "': ", alGetString(err)); + logError("unable to queue audio buffer for '%s': %s", m_soundFile->getName(), alGetString(err)); } // return false if there aren't more buffers to fill diff --git a/src/framework/stdext/dumper.h b/src/framework/stdext/dumper.h index fc690db3..a0147d3f 100644 --- a/src/framework/stdext/dumper.h +++ b/src/framework/stdext/dumper.h @@ -54,4 +54,6 @@ const static dumper::dumper_util dump; } +using stdext::dump; + #endif diff --git a/src/framework/stdext/string.h b/src/framework/stdext/string.h index d05eacfe..a00a3505 100644 --- a/src/framework/stdext/string.h +++ b/src/framework/stdext/string.h @@ -51,7 +51,10 @@ T from_string(const std::string& str, T def = T()) { return unsafe_cast -typename std::enable_if::value || std::is_pointer::value || std::is_floating_point::value, T>::type sprintf_cast(const T& t) { return t; } +typename std::enable_if::value || + std::is_pointer::value || + std::is_floating_point::value || + std::is_enum::value, T>::type sprintf_cast(const T& t) { return t; } /// Cast any class or struct convertible to std::string inline const char *sprintf_cast(const std::string& s) { return s.c_str(); } diff --git a/src/framework/ui/uianchorlayout.cpp b/src/framework/ui/uianchorlayout.cpp index 23aa6783..534fe457 100644 --- a/src/framework/ui/uianchorlayout.cpp +++ b/src/framework/ui/uianchorlayout.cpp @@ -93,7 +93,7 @@ bool UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch return false; if(first == widget) { - logError("child '", widget->getId(), "' of parent widget '", parentWidget->getId(), "' is recursively anchored to itself, please fix this"); + logError("child '%s' of parent widget '%s' is recursively anchored to itself, please fix this", widget->getId(), parentWidget->getId()); return false; } diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index 9f6eeb47..295779ab 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -285,7 +285,7 @@ void UIManager::onWidgetDestroy(const UIWidgetPtr& widget) g_lua.collectGarbage(); for(const UIWidgetPtr& widget : backupList) { if(widget->getUseCount() != 1) - logWarning("widget '", widget->getId(), "' destroyed but still have ", widget->getUseCount()-1, " reference(s) left"); + logWarning("widget '%s' destroyed but still have %d reference(s) left", widget->getId(), widget->getUseCount()-1); } }, 1); }, 1000); @@ -301,7 +301,7 @@ bool UIManager::importStyle(const std::string& file) importStyleFromOTML(styleNode); return true; } catch(stdext::exception& e) { - logError("Failed to import UI styles from '", file, "': ", e.what()); + logError("Failed to import UI styles from '%s': %s", file, e.what()); return false; } } @@ -325,7 +325,7 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode) /* auto it = m_styles.find(name); if(it != m_styles.end()) - logWarning("style '", name, "' is being redefined"); + logWarning("style '%s' is being redefined", name); */ OTMLNodePtr originalStyle = getStyle(base); @@ -382,7 +382,7 @@ UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent return widget; } catch(stdext::exception& e) { - logError("failed to load UI from '", file, "': ", e.what()); + logError("failed to load UI from '%s': %s", file, e.what()); return nullptr; } } @@ -393,7 +393,7 @@ UIWidgetPtr UIManager::createWidgetFromStyle(const std::string& styleName, const try { return createWidgetFromOTML(node, parent); } catch(stdext::exception& e) { - logError("failed to create widget from style '", styleName, "': ", e.what()); + logError("failed to create widget from style '%s': %s", styleName, e.what()); return nullptr; } } diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 000e84b8..0a74ea95 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -47,7 +47,7 @@ UIWidget::~UIWidget() { #ifdef DEBUG if(!m_destroyed) - logWarning("widget '", m_id, "' was not explicitly destroyed"); + logWarning("widget '%s' was not explicitly destroyed", m_id); #endif } @@ -500,7 +500,7 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode) } m_firstOnStyle = false; } catch(stdext::exception& e) { - logError("Failed to apply style to widget '", m_id, "' style: ", e.what()); + logError("failed to apply style to widget '%s': %s", m_id, e.what()); } m_loadingStyle = false; } @@ -513,7 +513,7 @@ void UIWidget::addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedW if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout()) anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge); else - logError("cannot add anchors to widget ", m_id, ": the parent doesn't use anchors layout"); + logError("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id); } void UIWidget::removeAnchor(Fw::AnchorEdge anchoredEdge) @@ -530,7 +530,7 @@ void UIWidget::centerIn(const std::string& hookedWidgetId) anchorLayout->addAnchor(asUIWidget(), Fw::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter); anchorLayout->addAnchor(asUIWidget(), Fw::AnchorVerticalCenter, hookedWidgetId, Fw::AnchorVerticalCenter); } else - logError("cannot add anchors to widget ", m_id, ": the parent doesn't use anchors layout"); + logError("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id); } void UIWidget::fill(const std::string& hookedWidgetId) @@ -544,7 +544,7 @@ void UIWidget::fill(const std::string& hookedWidgetId) anchorLayout->addAnchor(asUIWidget(), Fw::AnchorTop, hookedWidgetId, Fw::AnchorTop); anchorLayout->addAnchor(asUIWidget(), Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom); } else - logError("cannot add anchors to widget ", m_id, ": the parent doesn't use anchors layout"); + logError("cannot add anchors to widget '%s': the parent doesn't use anchors layout", m_id); } void UIWidget::breakAnchors() @@ -710,7 +710,7 @@ void UIWidget::internalDestroy() void UIWidget::destroy() { if(m_destroyed) - logWarning("attempt to destroy widget '", m_id, "' two times"); + logWarning("attempt to destroy widget '%s' two times", m_id); // hold itself reference UIWidgetPtr self = asUIWidget(); @@ -799,7 +799,7 @@ void UIWidget::setLayout(const UILayoutPtr& layout) bool UIWidget::setRect(const Rect& rect) { if(rect.width() > 8192 || rect.height() > 8192) { - logError("attempt to set huge rect size (", rect,") for ", m_id); + logError("attempt to set huge rect size (%s) for %s", stdext::to_string(rect), m_id); return false; } // only update if the rect really changed @@ -830,7 +830,7 @@ void UIWidget::setStyle(const std::string& styleName) { OTMLNodePtr styleNode = g_ui.getStyle(styleName); if(!styleNode) { - logTraceError("unable to retrive style '", styleName, "': not a defined style"); + logTraceError("unable to retrieve style '%s': not a defined style", styleName); return; } styleNode = styleNode->clone(); diff --git a/src/framework/ui/uiwidgetbasestyle.cpp b/src/framework/ui/uiwidgetbasestyle.cpp index 003ab647..edc6ab90 100644 --- a/src/framework/ui/uiwidgetbasestyle.cpp +++ b/src/framework/ui/uiwidgetbasestyle.cpp @@ -41,7 +41,7 @@ void UIWidget::initBaseStyle() // generate an unique id, this is need because anchored layouts find widgets by id static unsigned long id = 1; - m_id = stdext::mkstr("widget", id++); + m_id = stdext::format("widget %d", id++); } void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode) diff --git a/src/otclient/const.h b/src/otclient/const.h index 4553cf92..3fe4f4ed 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -288,6 +288,32 @@ namespace Otc SpeakMonsterSay, SpeakMonsterYell }; + + enum GameFeature { + GameExtendedOpcode = 0, + GameProtocolChecksum, + GameAccountNames, + GameChallangeOnLogin, + GameStackposOnTileAddThing, + GamePenalityOnDeath, + GameNameOnNpcTrade, + GameDoubleFreeCapacity, + GameDoubleExperience, + GameTotalCapacity, + GameSkillsBase, + GameAdditionalPlayerStats, + GameIdOnCancelAttack, + GameChannelPlayerList, + GamePlayerMounts, + GameEnvironmentEffect, + GameCreatureType, + GameCreatureAdditionalInfo, + GameCreaturePassableInfo, + GameItemAnimationPhase, + GameTrucatedPingOpcode, + GameReverseCreatureStack, + LastGameFeature + }; } #endif diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 682af373..3a637e88 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -38,6 +38,7 @@ Game g_game; Game::Game() { resetGameStates(); + setClientVersion(860); } void Game::resetGameStates() @@ -1018,6 +1019,59 @@ bool Game::canPerformGameAction() return m_localPlayer && !m_dead && m_protocolGame && m_protocolGame->isConnected() && checkBotProtection(); } +void Game::setClientVersion(int clientVersion) +{ + if(isOnline()) { + logError("Unable to change client version while online"); + return; + } + + //TODO: check supported versions + + m_features.reset(); + + if(clientVersion >= 854) { + enableFeature(Otc::GameProtocolChecksum); + enableFeature(Otc::GameAccountNames); + enableFeature(Otc::GameChallangeOnLogin); + enableFeature(Otc::GameStackposOnTileAddThing); + enableFeature(Otc::GameDoubleFreeCapacity); + enableFeature(Otc::GameCreatureAdditionalInfo); + enableFeature(Otc::GameReverseCreatureStack); + } + + if(clientVersion >= 860) { + enableFeature(Otc::GameIdOnCancelAttack); + } + + if(clientVersion >= 862) { + enableFeature(Otc::GamePenalityOnDeath); + } + + if(clientVersion >= 870) { + enableFeature(Otc::GameDoubleExperience); + enableFeature(Otc::GamePlayerMounts); + } + + if(clientVersion >= 910) { + enableFeature(Otc::GameNameOnNpcTrade); + enableFeature(Otc::GameTotalCapacity); + enableFeature(Otc::GameSkillsBase); + enableFeature(Otc::GameAdditionalPlayerStats); + enableFeature(Otc::GameChannelPlayerList); + enableFeature(Otc::GameEnvironmentEffect); + enableFeature(Otc::GameCreatureType); + enableFeature(Otc::GameItemAnimationPhase); + } + + if(clientVersion >= 953) { + enableFeature(Otc::GameCreaturePassableInfo); + enableFeature(Otc::GameTrucatedPingOpcode); + } + + m_clientVersion = clientVersion; +} + void Game::setAttackingCreature(const CreaturePtr& creature) { CreaturePtr oldCreature = m_attackingCreature; @@ -1032,4 +1086,4 @@ void Game::setFollowingCreature(const CreaturePtr& creature) m_followingCreature = creature; g_lua.callGlobalField("g_game", "onFollowingCreatureChange", creature, oldCreature); -} +} \ No newline at end of file diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index 7a6de5c9..23d626fb 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -229,6 +229,18 @@ public: //void reportRuleViolation2(); // TODO: market related + // dynamic support for game features + void enableFeature(Otc::GameFeature feature) { m_features.set(feature, true); } + void disableFeature(Otc::GameFeature feature) { m_features.set(feature, false); } + void setFeature(Otc::GameFeature feature) { m_features.set(feature, false); } + bool getFeature(Otc::GameFeature feature) { return m_features.test(feature); } + + void setClientVersion(int clientVersion); + int getClientVersion() { return m_clientVersion; } + + void setRSA(const std::string& rsa); + std::string getRSA() { return m_rsa; } + bool canPerformGameAction(); bool canReportBugs() { return m_canReportBugs; } bool checkBotProtection(); @@ -272,6 +284,9 @@ private: bool m_canReportBugs; std::vector m_gmActions; std::string m_worldName; + std::bitset m_features; + int m_clientVersion; + std::string m_rsa; }; extern Game g_game; diff --git a/src/otclient/core/item.cpp b/src/otclient/core/item.cpp index d5b297b0..1ad48520 100644 --- a/src/otclient/core/item.cpp +++ b/src/otclient/core/item.cpp @@ -41,7 +41,7 @@ ItemPtr Item::create(int id) { ItemPtr item = ItemPtr(new Item); if(id < g_thingsType.getFirstItemId() || id > g_thingsType.getMaxItemid()) - logTraceError("invalid item id ", id); + logTraceError("invalid item id %d", id); else { item->setId(id); } @@ -190,7 +190,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate) void Item::setId(uint32 id) { if(id < g_thingsType.getFirstItemId() || id > g_thingsType.getMaxItemid()) { - logTraceError("invalid item id ", id); + logTraceError("invalid item id %d", id); return; } m_id = id; diff --git a/src/otclient/core/spritemanager.cpp b/src/otclient/core/spritemanager.cpp index 3f80b021..5ffffcad 100644 --- a/src/otclient/core/spritemanager.cpp +++ b/src/otclient/core/spritemanager.cpp @@ -48,7 +48,7 @@ bool SpriteManager::load(const std::string& file) m_loaded = true; return true; } catch(stdext::exception& e) { - logError("Failed to load sprites from '", file, "': ", e.what()); + logError("Failed to load sprites from '%s': %s", file, e.what()); return false; } } @@ -98,7 +98,7 @@ ImagePtr SpriteManager::getSpriteImage(int id) uint16 coloredPixels = m_spritesFile->getU16(); if(writePos + transparentPixels*4 + coloredPixels*3 >= SPRITE_DATA_SIZE) { - logWarning("corrupt sprite id ", id); + logWarning("corrupt sprite id %d", id); return nullptr; } diff --git a/src/otclient/core/statictext.cpp b/src/otclient/core/statictext.cpp index 53619467..98a07ff6 100644 --- a/src/otclient/core/statictext.cpp +++ b/src/otclient/core/statictext.cpp @@ -106,7 +106,7 @@ void StaticText::compose() text += " says:\n"; m_color = Color(95, 247, 247); } else { - logWarning("unknown speak type: ", m_messageType); + logWarning("Unknown speak type: %d", m_messageType); } for(uint i = 0; i < m_messages.size(); ++i) { diff --git a/src/otclient/core/thingstype.cpp b/src/otclient/core/thingstype.cpp index 698f063e..1fea99ab 100644 --- a/src/otclient/core/thingstype.cpp +++ b/src/otclient/core/thingstype.cpp @@ -33,7 +33,7 @@ bool ThingsType::load(const std::string& file) { FileStreamPtr fin = g_resources.openFile(file); if(!fin) { - logError("unable to open dat file '", file, "'"); + logError("unable to open dat file '%s'", file); return false; } @@ -106,7 +106,6 @@ bool ThingsType::parseThingType(const FileStreamPtr& fin, ThingType& thingType) else if(property == ThingType::IsRune) thingType.m_properties[ThingType::IsStackable] = true; #endif -#if PROTOCOL>=944 else if(property == ThingType::Market) { fin->getU16(); // category fin->getU16(); // trade as @@ -115,7 +114,6 @@ bool ThingsType::parseThingType(const FileStreamPtr& fin, ThingType& thingType) fin->getU16(); // restrict profession fin->getU16(); // level } -#endif } if(!done) diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index 22b3b849..4b025c4c 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -170,11 +170,11 @@ ThingPtr Tile::addThing(const ThingPtr& thing, int stackPos) int priority = thing->getStackPriority(); for(stackPos = 0; stackPos < (int)m_things.size(); ++stackPos) { int otherPriority = m_things[stackPos]->getStackPriority(); -#if PROTOCOL<=810 - // older protocols stores creatures in reverse order - if(priority == 4 && otherPriority == 4) - break; -#endif + if(!g_game.getFeature(Otc::GameReverseCreatureStack)) { + // older protocols stores creatures in reverse order + if(priority == 4 && otherPriority == 4) + break; + } if(otherPriority > priority) break; } diff --git a/src/otclient/net/protocolcodes.h b/src/otclient/net/protocolcodes.h index b63c0b31..f9159dc8 100644 --- a/src/otclient/net/protocolcodes.h +++ b/src/otclient/net/protocolcodes.h @@ -68,14 +68,6 @@ namespace Proto { constexpr int ClientOs = OsOtclientLinux; #endif -#if PROTOCOL>=860 - constexpr int NumViolationReasons = 20; -#elif PROTOCOL>=854 - constexpr int NumViolationReasons = 19; -#elif PROTOCOL>=810 - constexpr int NumViolationReasons = 32; -#endif - enum LoginServerOpts { LoginServerError = 10, LoginServerMotd = 20, @@ -95,13 +87,8 @@ namespace Proto { GameServerLoginError = 20, GameServerLoginAdvice = 21, GameServerLoginWait = 22, -#if PROTOCOL>=953 - GameServerPing = 29, - GameServerPingBack = 30, -#else GameServerPingBack = 29, GameServerPing = 30, -#endif GameServerChallange = 31, GameServerDeath = 40, @@ -488,7 +475,7 @@ namespace Proto { case Proto::ServerSpeakBroadcast: return Otc::SpeakBroadcast; case Proto::ServerSpeakPrivateRedTo: return Otc::SpeakPrivateRed; default: - logError("unknown protocol speak type ", type); + logError("unknown protocol speak type %d", type); return Otc::SpeakSay; } } @@ -510,7 +497,7 @@ namespace Proto { case Otc::SpeakMonsterSay: return Proto::ServerSpeakMonsterSay; case Otc::SpeakMonsterYell: return Proto::ServerSpeakMonsterYell; default: - logError("unknown protocol speak type desc ", type); + logError("unknown protocol speak type desc %d", type); return Proto::ServerSpeakSay; } } @@ -528,7 +515,7 @@ namespace Proto { case Proto::MessageConsoleBlue: return "consoleBlue"; case Proto::MessageConsoleRed: return "consoleRed"; default: - logError("unknown protocol text message type ", type); + logError("unknown protocol text message type %d", type); return "unknown"; } } diff --git a/src/otclient/net/protocolgame.cpp b/src/otclient/net/protocolgame.cpp index f169f212..de92eee0 100644 --- a/src/otclient/net/protocolgame.cpp +++ b/src/otclient/net/protocolgame.cpp @@ -45,11 +45,11 @@ void ProtocolGame::onConnect() // must create local player before parsing anything m_localPlayer = LocalPlayerPtr(new LocalPlayer); -#if PROTOCOL>=854 - enableChecksum(); -#else - sendLoginPacket(0, 0); -#endif + if(g_game.getFeature(Otc::GameProtocolChecksum)) + enableChecksum(); + + if(!g_game.getFeature(Otc::GameChallangeOnLogin)) + sendLoginPacket(0, 0); recv(); } diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index 420eca14..ed58c537 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -66,10 +66,16 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) parseLoginWait(msg); break; case Proto::GameServerPing: - parsePing(msg); + if(g_game.getFeature(Otc::GameTrucatedPingOpcode)) + parsePingBack(msg); + else + parsePing(msg); break; case Proto::GameServerPingBack: - parsePingBack(msg); + if(g_game.getFeature(Otc::GameTrucatedPingOpcode)) + parsePing(msg); + else + parsePingBack(msg); break; case Proto::GameServerChallange: parseChallange(msg); @@ -313,7 +319,8 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) prevOpcode = opcode; } } catch(stdext::exception& e) { - logError("Network exception (", msg->getUnreadSize(), " bytes unread, last opcode is ", opcode, ", prev opcode is ", prevOpcode, "): ", e.what()); + logError("Network exception (%d bytes unread, last opcode is %d, prev opcode is %d): %s", + msg->getUnreadSize(), opcode, prevOpcode, e.what()); } } @@ -331,7 +338,17 @@ void ProtocolGame::parseInitGame(const InputMessagePtr& msg) void ProtocolGame::parseGMActions(const InputMessagePtr& msg) { std::vector actions; - for(int i = 0; i < Proto::NumViolationReasons; ++i) + + int numViolationReasons; + + if(g_game.getClientVersion() >= 860) + numViolationReasons = 20; + else if(g_game.getClientVersion() >= 854) + numViolationReasons = 19; + else + numViolationReasons = 32; + + for(int i = 0; i < numViolationReasons; ++i) actions.push_back(msg->getU8()); g_game.processGMActions(actions); } @@ -379,9 +396,8 @@ void ProtocolGame::parseChallange(const InputMessagePtr& msg) void ProtocolGame::parseDeath(const InputMessagePtr& msg) { int penality = 100; -#if PROTOCOL>=862 - penality = msg->getU8(); -#endif + if(g_game.getFeature(Otc::GamePenalityOnDeath)) + penality = msg->getU8(); g_game.processDeath(penality); } @@ -445,9 +461,8 @@ void ProtocolGame::parseTileAddThing(const InputMessagePtr& msg) Position pos = getPosition(msg); int stackPos = -1; -#if PROTOCOL>=854 - stackPos = msg->getU8(); -#endif + if(g_game.getFeature(Otc::GameStackposOnTileAddThing)) + stackPos = msg->getU8(); ThingPtr thing = getThing(msg); g_map.addThing(thing, pos, stackPos); @@ -561,9 +576,8 @@ void ProtocolGame::parseOpenNpcTrade(const InputMessagePtr& msg) std::vector> items; std::string npcName; -#if PROTOCOL>=910 - npcName = msg->getString(); -#endif + if(g_game.getFeature(Otc::GameNameOnNpcTrade)) + npcName = msg->getString(); int listCount = msg->getU8(); for(int i = 0; i < listCount; ++i) { @@ -827,27 +841,32 @@ void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg) { double health = msg->getU16(); double maxHealth = msg->getU16(); -#if PROTOCOL>=854 - double freeCapacity = msg->getU32() / 100.0; -#else - double freeCapacity = msg->getU16() / 100.0; -#endif -#if PROTOCOL>=910 - msg->getU32(); // total capacity -#endif -#if PROTOCOL>=870 - double experience = msg->getU64(); -#else - double experience = msg->getU32(); -#endif + + double freeCapacity; + if(g_game.getFeature(Otc::GameDoubleFreeCapacity)) + freeCapacity = msg->getU32() / 100.0; + else + freeCapacity = msg->getU16() / 100.0; + + double totalCapacity; + if(g_game.getFeature(Otc::GameTotalCapacity)) + totalCapacity = msg->getU32() / 100.0; + + double experience; + if(g_game.getFeature(Otc::GameDoubleExperience)) + experience = msg->getU64(); + else + experience = msg->getU32(); + double level = msg->getU16(); double levelPercent = msg->getU8(); double mana = msg->getU16(); double maxMana = msg->getU16(); double magicLevel = msg->getU8(); -#if PROTOCOL>=910 - msg->getU8(); // base magic level -#endif + + if(g_game.getFeature(Otc::GameSkillsBase)) + msg->getU8(); // base magic level + double magicLevelPercent = msg->getU8(); double soul = msg->getU8(); double stamina = msg->getU16(); @@ -861,21 +880,21 @@ void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg) m_localPlayer->setStamina(stamina); m_localPlayer->setSoul(soul); -#if PROTOCOL>=910 - int speed = msg->getU16(); - msg->getU16(); // regeneration time + if(g_game.getFeature(Otc::GameAdditionalPlayerStats)) { + int speed = msg->getU16(); + msg->getU16(); // regeneration time - m_localPlayer->setSpeed(speed); -#endif + m_localPlayer->setSpeed(speed); + } } void ProtocolGame::parsePlayerSkills(const InputMessagePtr& msg) { for(int skill = 0; skill < Otc::LastSkill; skill++) { int level = msg->getU8(); -#if PROTOCOL>=910 - msg->getU8(); // base -#endif + if(g_game.getFeature(Otc::GameSkillsBase)) + msg->getU8(); // base + int levelPercent = msg->getU8(); m_localPlayer->setSkill((Otc::Skill)skill, level, levelPercent); @@ -890,9 +909,9 @@ void ProtocolGame::parsePlayerState(const InputMessagePtr& msg) void ProtocolGame::parsePlayerCancelAttack(const InputMessagePtr& msg) { -#if PROTOCOL>=860 - msg->getU32(); // unknown -#endif + if(g_game.getFeature(Otc::GameIdOnCancelAttack)) + msg->getU32(); // unknown + g_game.processAttackCancel(); } @@ -982,14 +1001,14 @@ void ProtocolGame::parseOpenChannel(const InputMessagePtr& msg) int channelId = msg->getU16(); std::string name = msg->getString(); -#if PROTOCOL>=944 - int joinedPlayers = msg->getU16(); - for(int i=0;igetString(); // player name - int invitedPlayers = msg->getU16(); - for(int i=0;igetString(); // player name -#endif + if(g_game.getFeature(Otc::GameChannelPlayerList)) { + int joinedPlayers = msg->getU16(); + for(int i=0;igetString(); // player name + int invitedPlayers = msg->getU16(); + for(int i=0;igetString(); // player name + } g_game.processOpenChannel(channelId, name); } @@ -1116,13 +1135,13 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg) outfitList.push_back(std::make_tuple(outfitId, outfitName, outfitAddons)); } -#if PROTOCOL>=870 - int mountCount = msg->getU8(); - for(int i=0;igetU16(); // mount type - msg->getString(); // mount name + if(g_game.getFeature(Otc::GamePlayerMounts)) { + int mountCount = msg->getU8(); + for(int i=0;igetU16(); // mount type + msg->getString(); // mount name + } } -#endif g_game.processOpenOutfitWindow(currentOutfit, outfitList); } @@ -1219,7 +1238,7 @@ void ProtocolGame::parseExtendedOpcode(const InputMessagePtr& msg) try { callLuaField("onExtendedOpcode", opcode, buffer); } catch(stdext::exception& e) { - logError("Network exception in extended opcode ", opcode, ": ", e.what()); + logError("Network exception in extended opcode %d: %s", opcode, e.what()); } } } @@ -1271,9 +1290,9 @@ int ProtocolGame::setFloorDescription(const InputMessagePtr& msg, int x, int y, void ProtocolGame::setTileDescription(const InputMessagePtr& msg, Position position) { -#if PROTOCOL>=910 - msg->getU16(); // environment effect -#endif + if(g_game.getFeature(Otc::GameEnvironmentEffect)) + msg->getU16(); // environment effect + g_map.cleanTile(position); @@ -1285,7 +1304,7 @@ void ProtocolGame::setTileDescription(const InputMessagePtr& msg, Position posit } else { if(stackPos >= 10) - logTraceError("too many things, stackpos=", stackPos, " pos=", position); + logTraceError("too many things, stackpos=%d, pos=%s", stackPos, stdext::to_string(position)); ThingPtr thing = getThing(msg); g_map.addThing(thing, position, -1); @@ -1326,9 +1345,8 @@ Outfit ProtocolGame::getOutfit(const InputMessagePtr& msg) } } -#if PROTOCOL>=870 - msg->getU16(); // mount -#endif + if(g_game.getFeature(Otc::GamePlayerMounts)) + msg->getU16(); // mount return outfit; } @@ -1370,16 +1388,16 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) uint id = msg->getU32(); int creatureType; -#if PROTOCOL>=910 - creatureType = msg->getU8(); -#else - if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId) - creatureType = Proto::CreatureTypePlayer; - else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId) - creatureType = Proto::CreatureTypeMonster; - else - creatureType = Proto::CreatureTypeNpc; -#endif + if(g_game.getFeature(Otc::GameCreatureType)) + creatureType = msg->getU8(); + else { + if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId) + creatureType = Proto::CreatureTypePlayer; + else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId) + creatureType = Proto::CreatureTypeMonster; + else + creatureType = Proto::CreatureTypeNpc; + } std::string name = msg->getString(); @@ -1422,12 +1440,12 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) int emblem = -1; bool passable = false; -#if PROTOCOL>=854 - if(!known) - emblem = msg->getU8(); + if(g_game.getFeature(Otc::GameCreatureAdditionalInfo)) { + if(!known) + emblem = msg->getU8(); - passable = (msg->getU8() == 0); -#endif + passable = (msg->getU8() == 0); + } if(creature) { creature->setHealthPercent(healthPercent); @@ -1446,16 +1464,22 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) } } else if(type == Proto::Creature) { uint id = msg->getU32(); - Otc::Direction direction = (Otc::Direction)msg->getU8(); -#if PROTOCOL>=953 - msg->getU8(); // passable -#endif - creature = g_map.getCreatureById(id); + + if(!creature) + logTraceError("invalid creature"); + + Otc::Direction direction = (Otc::Direction)msg->getU8(); if(creature) creature->turn(direction); - else - logTraceError("invalid creature"); + + if(g_game.getFeature(Otc::GameCreaturePassableInfo)) { + bool passable = msg->getU8(); + + if(creature) + creature->setPassable(passable); + } + } else { stdext::throw_exception("invalid creature opcode"); } @@ -1475,13 +1499,13 @@ ItemPtr ProtocolGame::getItem(const InputMessagePtr& msg, int id) if(item->isStackable() || item->isFluidContainer() || item->isFluid()) item->setCountOrSubType(msg->getU8()); -#if PROTOCOL>=910 - if(item->getAnimationPhases() > 1) { - // 0xfe => random phase - // 0xff => async? - msg->getU8(); + if(g_game.getFeature(Otc::GameItemAnimationPhase)) { + if(item->getAnimationPhases() > 1) { + // 0xfe => random phase + // 0xff => async? + msg->getU8(); + } } -#endif return item; } diff --git a/src/otclient/net/protocolgamesend.cpp b/src/otclient/net/protocolgamesend.cpp index 68c25284..e9135776 100644 --- a/src/otclient/net/protocolgamesend.cpp +++ b/src/otclient/net/protocolgamesend.cpp @@ -40,7 +40,7 @@ void ProtocolGame::sendExtendedOpcode(uint8 opcode, const std::string& buffer) msg->addString(buffer); safeSend(msg); } else { - logError("unable to send extended opcode ", (int)opcode, ", extended opcodes are not enabled"); + logError("Unable to send extended opcode %d, extended opcodes are not enabled", opcode); } } @@ -65,26 +65,26 @@ void ProtocolGame::sendLoginPacket(uint challangeTimestamp, uint8 challangeRando msg->addU8(0); // is gm set? paddingBytes -= 17; -#if PROTOCOL>=854 - enableChecksum(); - - msg->addString(m_accountName); - paddingBytes -= 2 + m_accountName.length(); - msg->addString(m_characterName); - paddingBytes -= 2 + m_characterName.length(); - msg->addString(m_accountPassword); - paddingBytes -= 2 + m_accountPassword.length(); - - msg->addU32(challangeTimestamp); - msg->addU8(challangeRandom); - paddingBytes -= 5; -#else // PROTOCOL>=810 - msg->addU32(stdext::from_string(m_accountName)); - msg->addString(m_characterName); - msg->addString(m_accountPassword); - - paddingBytes -= 8 + m_characterName.length() + m_accountPassword.length(); -#endif + if(g_game.getFeature(Otc::GameProtocolChecksum)) + enableChecksum(); + + if(g_game.getFeature(Otc::GameAccountNames)) { + msg->addString(m_accountName); + msg->addString(m_characterName); + msg->addString(m_accountPassword); + paddingBytes -= 6 + m_accountName.length() + m_characterName.length() + m_accountPassword.length(); + } else { + msg->addU32(stdext::from_string(m_accountName)); + msg->addString(m_characterName); + msg->addString(m_accountPassword); + paddingBytes -= 8 + m_characterName.length() + m_accountPassword.length(); + } + + if(g_game.getFeature(Otc::GameChallangeOnLogin)) { + msg->addU32(challangeTimestamp); + msg->addU8(challangeRandom); + paddingBytes -= 5; + } // complete the 128 bytes for rsa encryption with zeros msg->addPaddingBytes(paddingBytes); diff --git a/src/otclient/net/protocollogin.cpp b/src/otclient/net/protocollogin.cpp index 5c9f3f7f..ce5ae156 100644 --- a/src/otclient/net/protocollogin.cpp +++ b/src/otclient/net/protocollogin.cpp @@ -26,6 +26,7 @@ #include #include #include +#include void ProtocolLogin::login(const std::string& host, int port, const std::string& accountName, const std::string& accountPassword) { @@ -105,17 +106,18 @@ void ProtocolLogin::sendLoginPacket() msg->addU32(m_xteaKey[3]); paddingBytes -= 16; -#if PROTOCOL>=854 - enableChecksum(); - - msg->addString(m_accountName); - msg->addString(m_accountPassword); - paddingBytes -= 4 + m_accountName.length() + m_accountPassword.length(); -#elif PROTOCOL>=810 - msg->addU32(stdext::from_string(m_accountName)); - msg->addString(m_accountPassword); - paddingBytes -= 6 + m_accountPassword.length(); -#endif + if(g_game.getFeature(Otc::GameProtocolChecksum)) + enableChecksum(); + + if(g_game.getFeature(Otc::GameAccountNames)) { + msg->addString(m_accountName); + msg->addString(m_accountPassword); + paddingBytes -= 4 + m_accountName.length() + m_accountPassword.length(); + } else { + msg->addU32(stdext::from_string(m_accountName)); + msg->addString(m_accountPassword); + paddingBytes -= 6 + m_accountPassword.length(); + } msg->addPaddingBytes(paddingBytes); // complete the 128 bytes for rsa encryption with zeros msg->encryptRSA(128, Proto::RSA); diff --git a/src/otclient/otclient.cpp b/src/otclient/otclient.cpp index f445bb05..445527b6 100644 --- a/src/otclient/otclient.cpp +++ b/src/otclient/otclient.cpp @@ -72,15 +72,15 @@ void OTClient::init(const std::vector& args) } } - logInfo(stdext::format( + logInfo( "%s %s (rev %s) built on %s", Otc::AppName, Otc::AppVersion, BUILD_REVISION, - BUILD_DATE)); + BUILD_DATE); if(startupOptions.length() > 0) - logInfo("Startup options:", startupOptions); + logInfo("Startup options: %s", startupOptions); g_logger.setLogFile(stdext::format("%s.txt", Otc::AppCompactName)); Application::init(args); @@ -104,7 +104,7 @@ void OTClient::init(const std::vector& args) try { g_lua.runScript("/otclientrc.lua"); } catch(LuaException& e) { - logError("failed to load otclientrc.lua: ", e.what()); + logError("failed to load otclientrc.lua: %s", e.what()); } } }