rework log function and protocol
* remove some protocol ifdefs, replace with game features system
This commit is contained in:
parent
4c80d783d6
commit
c01b32b032
|
@ -52,8 +52,8 @@ void exitSignalHandler(int sig)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Application::Application(const std::string& appName)
|
|
||||||
|
|
||||||
|
Application::Application(const std::string& appName)
|
||||||
{
|
{
|
||||||
g_app = this;
|
g_app = this;
|
||||||
m_appName = appName;
|
m_appName = appName;
|
||||||
|
|
|
@ -45,7 +45,7 @@ bool ConfigManager::load(const std::string& file)
|
||||||
m_confsDoc = confsDoc;
|
m_confsDoc = confsDoc;
|
||||||
return true;
|
return true;
|
||||||
} catch(stdext::exception& e) {
|
} catch(stdext::exception& e) {
|
||||||
logError("could not load configurations: ", e.what());
|
logError("Unable to load configuration file: %s", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ void FileStream::cache()
|
||||||
m_cacheBuffer.resize(size);
|
m_cacheBuffer.resize(size);
|
||||||
int res = PHYSFS_read(m_fileHandle, &m_cacheBuffer[0], size, 1);
|
int res = PHYSFS_read(m_fileHandle, &m_cacheBuffer[0], size, 1);
|
||||||
if(res == -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);
|
PHYSFS_close(m_fileHandle);
|
||||||
m_fileHandle = nullptr;
|
m_fileHandle = nullptr;
|
||||||
|
@ -58,7 +58,7 @@ bool FileStream::close()
|
||||||
{
|
{
|
||||||
if(m_fileHandle) {
|
if(m_fileHandle) {
|
||||||
if(PHYSFS_isInit() && PHYSFS_close(m_fileHandle) == 0)
|
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;
|
m_fileHandle = nullptr;
|
||||||
return true;
|
return true;
|
||||||
|
@ -75,7 +75,7 @@ bool FileStream::flush()
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(PHYSFS_flush(m_fileHandle) == 0) {
|
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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -86,7 +86,7 @@ int FileStream::read(void *buffer, int size, int nmemb)
|
||||||
if(m_fileHandle) {
|
if(m_fileHandle) {
|
||||||
int res = PHYSFS_read(m_fileHandle, buffer, size, nmemb);
|
int res = PHYSFS_read(m_fileHandle, buffer, size, nmemb);
|
||||||
if(res == -1) {
|
if(res == -1) {
|
||||||
logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError());
|
logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -111,7 +111,7 @@ bool FileStream::write(void *buffer, int count)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(PHYSFS_write(m_fileHandle, buffer, 1, count) != count) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,12 +122,12 @@ bool FileStream::seek(int pos)
|
||||||
{
|
{
|
||||||
if(m_fileHandle) {
|
if(m_fileHandle) {
|
||||||
if(PHYSFS_seek(m_fileHandle, pos) == 0) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(pos > (int)m_cacheBuffer.size() || pos < 0) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
m_cacheReadPos = pos;
|
m_cacheReadPos = pos;
|
||||||
|
@ -156,10 +156,10 @@ uint8 FileStream::getU8()
|
||||||
uint8 v = 0;
|
uint8 v = 0;
|
||||||
if(m_fileHandle) {
|
if(m_fileHandle) {
|
||||||
if(PHYSFS_read(m_fileHandle, &v, 1, 1) != 1)
|
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 {
|
} else {
|
||||||
if(m_cacheReadPos+1 > m_cacheBuffer.size()) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,10 +174,10 @@ uint16 FileStream::getU16()
|
||||||
uint16 v = 0;
|
uint16 v = 0;
|
||||||
if(m_fileHandle) {
|
if(m_fileHandle) {
|
||||||
if(PHYSFS_readULE16(m_fileHandle, &v) == 0)
|
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 {
|
} else {
|
||||||
if(m_cacheReadPos+2 > m_cacheBuffer.size()) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,10 +192,10 @@ uint32 FileStream::getU32()
|
||||||
uint32 v = 0;
|
uint32 v = 0;
|
||||||
if(m_fileHandle) {
|
if(m_fileHandle) {
|
||||||
if(PHYSFS_readULE32(m_fileHandle, &v) == 0)
|
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 {
|
} else {
|
||||||
if(m_cacheReadPos+4 > m_cacheBuffer.size()) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,10 +210,10 @@ uint64 FileStream::getU64()
|
||||||
uint64 v = 0;
|
uint64 v = 0;
|
||||||
if(m_fileHandle) {
|
if(m_fileHandle) {
|
||||||
if(PHYSFS_readULE64(m_fileHandle, (PHYSFS_uint64*)&v) == 0)
|
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 {
|
} else {
|
||||||
if(m_cacheReadPos+8 > m_cacheBuffer.size()) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,12 +231,12 @@ std::string FileStream::getString()
|
||||||
char buffer[8192];
|
char buffer[8192];
|
||||||
if(m_fileHandle) {
|
if(m_fileHandle) {
|
||||||
if(PHYSFS_read(m_fileHandle, buffer, 1, len) == 0)
|
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
|
else
|
||||||
str = std::string(buffer, len);
|
str = std::string(buffer, len);
|
||||||
} else {
|
} else {
|
||||||
if(m_cacheReadPos+len > m_cacheBuffer.size()) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ std::string FileStream::getString()
|
||||||
m_cacheReadPos += len;
|
m_cacheReadPos += len;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logTraceError("operation failed on '", m_name, "': ", PHYSFS_getLastError());
|
logTraceError("operation failed on '%s': %s", m_name, PHYSFS_getLastError());
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -252,23 +252,23 @@ std::string FileStream::getString()
|
||||||
void FileStream::addU8(uint8 v)
|
void FileStream::addU8(uint8 v)
|
||||||
{
|
{
|
||||||
if(PHYSFS_write(m_fileHandle, &v, 1, 1) != 1)
|
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)
|
void FileStream::addU16(uint8 v)
|
||||||
{
|
{
|
||||||
if(PHYSFS_writeULE16(m_fileHandle, v) == 0)
|
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)
|
void FileStream::addU32(uint8 v)
|
||||||
{
|
{
|
||||||
if(PHYSFS_writeULE32(m_fileHandle, v) == 0)
|
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)
|
void FileStream::addU64(uint8 v)
|
||||||
{
|
{
|
||||||
if(PHYSFS_writeULE64(m_fileHandle, v) == 0)
|
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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ void Logger::setLogFile(const std::string& file)
|
||||||
{
|
{
|
||||||
m_outFile.open(file.c_str(), std::ios::out | std::ios::app);
|
m_outFile.open(file.c_str(), std::ios::out | std::ios::app);
|
||||||
if(!m_outFile.is_open() || !m_outFile.good()) {
|
if(!m_outFile.is_open() || !m_outFile.good()) {
|
||||||
logError("Unable to save log to '", file, "'");
|
logError("Unable to save log to '%s'", file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,17 +57,17 @@ private:
|
||||||
extern Logger g_logger;
|
extern Logger g_logger;
|
||||||
|
|
||||||
// specialized logging
|
// specialized logging
|
||||||
#define logDebug(...) g_logger.log(Fw::LogDebug, stdext::mkstr(__VA_ARGS__))
|
#define logDebug(...) g_logger.log(Fw::LogDebug, stdext::format(__VA_ARGS__))
|
||||||
#define logInfo(...) g_logger.log(Fw::LogInfo, stdext::mkstr(__VA_ARGS__))
|
#define logInfo(...) g_logger.log(Fw::LogInfo, stdext::format(__VA_ARGS__))
|
||||||
#define logWarning(...) g_logger.log(Fw::LogWarning, stdext::mkstr(__VA_ARGS__))
|
#define logWarning(...) g_logger.log(Fw::LogWarning, stdext::format(__VA_ARGS__))
|
||||||
#define logError(...) g_logger.log(Fw::LogError, stdext::mkstr(__VA_ARGS__))
|
#define logError(...) g_logger.log(Fw::LogError, stdext::format(__VA_ARGS__))
|
||||||
#define logFatal(...) g_logger.log(Fw::LogFatal, stdext::mkstr(__VA_ARGS__))
|
#define logFatal(...) g_logger.log(Fw::LogFatal, stdext::format(__VA_ARGS__))
|
||||||
|
|
||||||
#define logTrace() g_logger.logFunc(Fw::LogDebug, "", __PRETTY_FUNCTION__)
|
#define logTrace() g_logger.logFunc(Fw::LogDebug, "", __PRETTY_FUNCTION__)
|
||||||
#define logTraceDebug(...) g_logger.logFunc(Fw::LogDebug, 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::mkstr(__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::mkstr(__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::mkstr(__VA_ARGS__), __PRETTY_FUNCTION__)
|
#define logTraceError(...) g_logger.logFunc(Fw::LogError, stdext::format(__VA_ARGS__), __PRETTY_FUNCTION__)
|
||||||
|
|
||||||
#define logTraceCounter() { \
|
#define logTraceCounter() { \
|
||||||
static int __count = 0; \
|
static int __count = 0; \
|
||||||
|
|
|
@ -39,12 +39,12 @@ bool Module::load()
|
||||||
for(const std::string& depName : m_dependencies) {
|
for(const std::string& depName : m_dependencies) {
|
||||||
ModulePtr dep = g_modules.getModule(depName);
|
ModulePtr dep = g_modules.getModule(depName);
|
||||||
if(!dep) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!dep->isLoaded() && !dep->load()) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,13 +53,13 @@ bool Module::load()
|
||||||
m_loadCallback();
|
m_loadCallback();
|
||||||
|
|
||||||
m_loaded = true;
|
m_loaded = true;
|
||||||
logInfo("Loaded module '", m_name, "'");
|
logInfo("Loaded module '%s'", m_name);
|
||||||
g_modules.updateModuleLoadOrder(asModule());
|
g_modules.updateModuleLoadOrder(asModule());
|
||||||
|
|
||||||
for(const std::string& modName : m_loadLaterModules) {
|
for(const std::string& modName : m_loadLaterModules) {
|
||||||
ModulePtr dep = g_modules.getModule(modName);
|
ModulePtr dep = g_modules.getModule(modName);
|
||||||
if(!dep)
|
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())
|
else if(!dep->isLoaded())
|
||||||
dep->load();
|
dep->load();
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ void Module::unload()
|
||||||
if(m_unloadCallback)
|
if(m_unloadCallback)
|
||||||
m_unloadCallback();
|
m_unloadCallback();
|
||||||
m_loaded = false;
|
m_loaded = false;
|
||||||
logInfo("Unloaded module '", m_name, "'");
|
logInfo("Unloaded module '%s'", m_name);
|
||||||
g_modules.updateModuleLoadOrder(asModule());
|
g_modules.updateModuleLoadOrder(asModule());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ void ModuleManager::discoverModulesPath()
|
||||||
for(const std::string& dir : possibleModulesDirs) {
|
for(const std::string& dir : possibleModulesDirs) {
|
||||||
// try to add module directory
|
// try to add module directory
|
||||||
if(g_resources.addToSearchPath(dir, false)) {
|
if(g_resources.addToSearchPath(dir, false)) {
|
||||||
logInfo("Using modules directory '", dir.c_str(), "'");
|
logInfo("Using modules directory '%s'", dir.c_str());
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ void ModuleManager::discoverModulesPath()
|
||||||
for(const std::string& dir : possibleAddonsDirs) {
|
for(const std::string& dir : possibleAddonsDirs) {
|
||||||
// try to add module directory
|
// try to add module directory
|
||||||
if(g_resources.addToSearchPath(dir, true)) {
|
if(g_resources.addToSearchPath(dir, true)) {
|
||||||
logInfo("Using addons directory '", dir.c_str(), "'");
|
logInfo("Using addons directory '%s'", dir.c_str());
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -103,8 +103,6 @@ ModulePtr ModuleManager::discoverModule(const std::string& moduleFile)
|
||||||
OTMLNodePtr moduleNode = doc->at("Module");
|
OTMLNodePtr moduleNode = doc->at("Module");
|
||||||
|
|
||||||
std::string name = moduleNode->valueAt("name");
|
std::string name = moduleNode->valueAt("name");
|
||||||
//if(getModule(name))
|
|
||||||
// stdext::throw_exception("module '", name, "' already exists, cannot have duplicate module names");
|
|
||||||
|
|
||||||
bool push = false;
|
bool push = false;
|
||||||
module = getModule(name);
|
module = getModule(name);
|
||||||
|
@ -118,7 +116,7 @@ ModulePtr ModuleManager::discoverModule(const std::string& moduleFile)
|
||||||
if(push)
|
if(push)
|
||||||
m_modules.push_back(module);
|
m_modules.push_back(module);
|
||||||
} catch(stdext::exception& e) {
|
} 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;
|
return module;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +125,7 @@ void ModuleManager::ensureModuleLoaded(const std::string& moduleName)
|
||||||
{
|
{
|
||||||
ModulePtr module = g_modules.getModule(moduleName);
|
ModulePtr module = g_modules.getModule(moduleName);
|
||||||
if(!module || !module->load())
|
if(!module || !module->load())
|
||||||
logFatal("Unable to load '", moduleName, "' module");
|
logFatal("Unable to load '%s' module", moduleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModuleManager::unloadModules()
|
void ModuleManager::unloadModules()
|
||||||
|
|
|
@ -43,7 +43,7 @@ void ResourceManager::terminate()
|
||||||
bool ResourceManager::setupWriteDir(const std::string& appWriteDirName)
|
bool ResourceManager::setupWriteDir(const std::string& appWriteDirName)
|
||||||
{
|
{
|
||||||
std::string userDir = PHYSFS_getUserDir();
|
std::string userDir = PHYSFS_getUserDir();
|
||||||
std::string dirName = stdext::mkstr(".", appWriteDirName);
|
std::string dirName = stdext::format(".%s", appWriteDirName);
|
||||||
std::string writeDir = userDir + dirName;
|
std::string writeDir = userDir + dirName;
|
||||||
if(!PHYSFS_setWriteDir(writeDir.c_str())) {
|
if(!PHYSFS_setWriteDir(writeDir.c_str())) {
|
||||||
if(!PHYSFS_setWriteDir(userDir.c_str()))
|
if(!PHYSFS_setWriteDir(userDir.c_str()))
|
||||||
|
@ -150,7 +150,7 @@ FileStreamPtr ResourceManager::openFile(const std::string& fileName)
|
||||||
std::string fullPath = resolvePath(fileName);
|
std::string fullPath = resolvePath(fileName);
|
||||||
PHYSFS_File* file = PHYSFS_openRead(fullPath.c_str());
|
PHYSFS_File* file = PHYSFS_openRead(fullPath.c_str());
|
||||||
if(!file) {
|
if(!file) {
|
||||||
logTraceError("unable to open file '", fullPath, "': ", PHYSFS_getLastError());
|
logTraceError("unable to open file '%s': %s", fullPath, PHYSFS_getLastError());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return FileStreamPtr(new FileStream(fullPath, file));
|
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());
|
PHYSFS_File* file = PHYSFS_openAppend(fileName.c_str());
|
||||||
if(!file) {
|
if(!file) {
|
||||||
logTraceError("failed to append file '", fileName, "': ", PHYSFS_getLastError());
|
logTraceError("failed to append file '%s': %s", fileName, PHYSFS_getLastError());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return FileStreamPtr(new FileStream(fileName, file));
|
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());
|
PHYSFS_File* file = PHYSFS_openWrite(fileName.c_str());
|
||||||
if(!file) {
|
if(!file) {
|
||||||
logTraceError("failed to create file '", fileName, "': ", PHYSFS_getLastError());
|
logTraceError("failed to create file '%s': %s", fileName, PHYSFS_getLastError());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return FileStreamPtr(new FileStream(fileName, file));
|
return FileStreamPtr(new FileStream(fileName, file));
|
||||||
|
@ -211,7 +211,7 @@ std::string ResourceManager::resolvePath(const std::string& path)
|
||||||
fullPath += path;
|
fullPath += path;
|
||||||
}
|
}
|
||||||
if(!(boost::starts_with(fullPath, "/")))
|
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, "//", "/");
|
boost::replace_all(fullPath, "//", "/");
|
||||||
return fullPath;
|
return fullPath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,6 @@ bool FontManager::importFont(std::string fontFile)
|
||||||
OTMLNodePtr fontNode = doc->at("Font");
|
OTMLNodePtr fontNode = doc->at("Font");
|
||||||
|
|
||||||
std::string name = fontNode->valueAt("name");
|
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
|
// remove any font with the same name
|
||||||
for(auto it = m_fonts.begin(); it != m_fonts.end(); ++it) {
|
for(auto it = m_fonts.begin(); it != m_fonts.end(); ++it) {
|
||||||
|
@ -69,7 +67,7 @@ bool FontManager::importFont(std::string fontFile)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch(stdext::exception& e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +90,7 @@ FontPtr FontManager::getFont(const std::string& fontName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// when not found, fallback to default font
|
// when not found, fallback to default font
|
||||||
logError("font '", fontName, "' not found");
|
logError("font '%s' not found", fontName);
|
||||||
return getDefaultFont();
|
return getDefaultFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ Graphics::Graphics()
|
||||||
|
|
||||||
void Graphics::init()
|
void Graphics::init()
|
||||||
{
|
{
|
||||||
logInfo("GPU ", glGetString(GL_RENDERER));
|
logInfo("GPU %s", glGetString(GL_RENDERER));
|
||||||
logInfo("OpenGL ", glGetString(GL_VERSION));
|
logInfo("OpenGL %s", glGetString(GL_VERSION));
|
||||||
|
|
||||||
#if OPENGL_ES==2
|
#if OPENGL_ES==2
|
||||||
g_painterOGL2 = new PainterOGL2;
|
g_painterOGL2 = new PainterOGL2;
|
||||||
|
@ -56,7 +56,7 @@ void Graphics::init()
|
||||||
// init GL extensions
|
// init GL extensions
|
||||||
GLenum err = glewInit();
|
GLenum err = glewInit();
|
||||||
if(err != GLEW_OK)
|
if(err != GLEW_OK)
|
||||||
logFatal("Unable to init GLEW: ", glewGetErrorString(err));
|
logFatal("Unable to init GLEW: %s", glewGetErrorString(err));
|
||||||
|
|
||||||
// overwrite framebuffer API if needed
|
// overwrite framebuffer API if needed
|
||||||
if(GLEW_EXT_framebuffer_object && !GLEW_ARB_framebuffer_object) {
|
if(GLEW_EXT_framebuffer_object && !GLEW_ARB_framebuffer_object) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ ImagePtr Image::load(const std::string& file)
|
||||||
// load image file data
|
// load image file data
|
||||||
image = loadPNG(file);
|
image = loadPNG(file);
|
||||||
} catch(stdext::exception& e) {
|
} catch(stdext::exception& e) {
|
||||||
logError("unable to load image '", file, "': ", e.what());
|
logError("unable to load image '%s': %s", file, e.what());
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ bool ParticleManager::load(const std::string& filename)
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch(stdext::exception& e) {
|
} catch(stdext::exception& e) {
|
||||||
logError("could not load particles: ", e.what());
|
logError("could not load particles: %s", e.what());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ bool ShaderProgram::addShader(const ShaderPtr& shader) {
|
||||||
bool ShaderProgram::addShaderFromSourceCode(Shader::ShaderType shaderType, const std::string& sourceCode) {
|
bool ShaderProgram::addShaderFromSourceCode(Shader::ShaderType shaderType, const std::string& sourceCode) {
|
||||||
ShaderPtr shader(new Shader(shaderType));
|
ShaderPtr shader(new Shader(shaderType));
|
||||||
if(!shader->compileSourceCode(sourceCode)) {
|
if(!shader->compileSourceCode(sourceCode)) {
|
||||||
logError("failed to compile shader: ", shader->log());
|
logError("failed to compile shader: %s", shader->log());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return addShader(shader);
|
return addShader(shader);
|
||||||
|
@ -57,7 +57,7 @@ bool ShaderProgram::addShaderFromSourceCode(Shader::ShaderType shaderType, const
|
||||||
bool ShaderProgram::addShaderFromSourceFile(Shader::ShaderType shaderType, const std::string& sourceFile) {
|
bool ShaderProgram::addShaderFromSourceFile(Shader::ShaderType shaderType, const std::string& sourceFile) {
|
||||||
ShaderPtr shader(new Shader(shaderType));
|
ShaderPtr shader(new Shader(shaderType));
|
||||||
if(!shader->compileSourceFile(sourceFile)) {
|
if(!shader->compileSourceFile(sourceFile)) {
|
||||||
logError("failed to compile shader: ", shader->log());
|
logError("failed to compile shader: %s", shader->log());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return addShader(shader);
|
return addShader(shader);
|
||||||
|
|
|
@ -82,9 +82,10 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int
|
||||||
|
|
||||||
// checks texture max size
|
// checks texture max size
|
||||||
if(std::max(glSize.width(), glSize.height()) > g_graphics.getMaxTextureSize()) {
|
if(std::max(glSize.width(), glSize.height()) > g_graphics.getMaxTextureSize()) {
|
||||||
logError("loading texture with size ", width, "x", height, " failed, "
|
logError("loading texture with size %dx%d failed, "
|
||||||
"the maximum size allowed by the graphics card is ", g_graphics.getMaxTextureSize(), "x", g_graphics.getMaxTextureSize(), ",",
|
"the maximum size allowed by the graphics card is %dx%d,"
|
||||||
"to prevent crashes the texture will be displayed as a blank texture");
|
"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
|
//TODO: make a workaround, could be bilinear scaling the texture
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ TexturePtr TextureManager::getTexture(const std::string& fileName)
|
||||||
g_resources.loadFile(filePath, fin);
|
g_resources.loadFile(filePath, fin);
|
||||||
texture = loadPNG(fin);
|
texture = loadPNG(fin);
|
||||||
} catch(stdext::exception& e) {
|
} 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();
|
texture = g_graphics.getEmptyTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,21 +33,21 @@ void LuaException::generateLuaErrorMessage(const std::string& error, int traceLe
|
||||||
{
|
{
|
||||||
// append trace level to error message
|
// append trace level to error message
|
||||||
if(traceLevel >= 0)
|
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
|
else
|
||||||
m_what = stdext::mkstr("LUA ERROR: ", error);
|
m_what = stdext::format("LUA ERROR: %s", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaBadNumberOfArgumentsException::LuaBadNumberOfArgumentsException(int expected, int got)
|
LuaBadNumberOfArgumentsException::LuaBadNumberOfArgumentsException(int expected, int got)
|
||||||
{
|
{
|
||||||
std::string error = "attempt to call a function with wrong number of arguments";
|
std::string error = "attempt to call a function with wrong number of arguments";
|
||||||
if(expected >= 0 && got >= 0)
|
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);
|
generateLuaErrorMessage(error, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaBadValueCastException::LuaBadValueCastException(const std::string& luaTypeName, const std::string& cppTypeName)
|
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);
|
generateLuaErrorMessage(error, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,12 +163,12 @@ void LuaInterface::registerClassMemberField(const std::string& className,
|
||||||
|
|
||||||
if(getFunction) {
|
if(getFunction) {
|
||||||
pushCppFunction(getFunction);
|
pushCppFunction(getFunction);
|
||||||
setField(stdext::mkstr("get_", field));
|
setField(stdext::format("get_%s", field));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(setFunction) {
|
if(setFunction) {
|
||||||
pushCppFunction(setFunction);
|
pushCppFunction(setFunction);
|
||||||
setField(stdext::mkstr("set_", field));
|
setField(stdext::format("set_%s", field));
|
||||||
}
|
}
|
||||||
|
|
||||||
pop();
|
pop();
|
||||||
|
@ -324,9 +324,9 @@ void LuaInterface::loadFunction(const std::string& buffer, const std::string& so
|
||||||
|
|
||||||
std::string buf;
|
std::string buf;
|
||||||
if(boost::starts_with(buffer, "function"))
|
if(boost::starts_with(buffer, "function"))
|
||||||
buf = stdext::mkstr("__func = ", buffer);
|
buf = stdext::format("__func = %s", buffer);
|
||||||
else
|
else
|
||||||
buf = stdext::mkstr("__func = function(self)\n", buffer,"\nend");
|
buf = stdext::format("__func = function(self)\n%s\nend", buffer);
|
||||||
|
|
||||||
loadBuffer(buf, source);
|
loadBuffer(buf, source);
|
||||||
safeCall();
|
safeCall();
|
||||||
|
@ -343,7 +343,7 @@ void LuaInterface::evaluateExpression(const std::string& expression, const std::
|
||||||
{
|
{
|
||||||
// evaluates the expression
|
// evaluates the expression
|
||||||
if(!expression.empty()) {
|
if(!expression.empty()) {
|
||||||
std::string buffer = stdext::mkstr("__exp = (", expression, ")");
|
std::string buffer = stdext::format("__exp = (%s)", expression);
|
||||||
loadBuffer(buffer, source);
|
loadBuffer(buffer, source);
|
||||||
safeCall();
|
safeCall();
|
||||||
|
|
||||||
|
@ -480,7 +480,7 @@ int LuaInterface::protectedCall(int numArgs, int requestedResults)
|
||||||
throw LuaException("attempt to call a non function value", 0);
|
throw LuaException("attempt to call a non function value", 0);
|
||||||
}
|
}
|
||||||
} catch(LuaException &e) {
|
} catch(LuaException &e) {
|
||||||
logError("protected lua call failed: ", e.what());
|
logError("protected lua call failed: %s", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
// pushes nil values if needed
|
// pushes nil values if needed
|
||||||
|
@ -515,7 +515,7 @@ int LuaInterface::luaScriptLoader(lua_State* L)
|
||||||
g_lua.loadScript(fileName);
|
g_lua.loadScript(fileName);
|
||||||
return 1;
|
return 1;
|
||||||
} catch(LuaException& e) {
|
} 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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -531,7 +531,7 @@ int LuaInterface::luaScriptRunner(lua_State* L)
|
||||||
g_lua.call(0, LUA_MULTRET);
|
g_lua.call(0, LUA_MULTRET);
|
||||||
return g_lua.stackSize();
|
return g_lua.stackSize();
|
||||||
} catch(LuaException& e) {
|
} 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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -548,7 +548,7 @@ int LuaInterface::luaScriptsRunner(lua_State* L)
|
||||||
g_lua.loadScript(directory + "/" + fileName);
|
g_lua.loadScript(directory + "/" + fileName);
|
||||||
g_lua.call(0, 0);
|
g_lua.call(0, 0);
|
||||||
} catch(LuaException& e) {
|
} 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;
|
return 0;
|
||||||
|
@ -583,7 +583,7 @@ int LuaInterface::luaCppFunctionCallback(lua_State* L)
|
||||||
g_lua.m_cppCallbackDepth--;
|
g_lua.m_cppCallbackDepth--;
|
||||||
assert(numRets == g_lua.stackSize());
|
assert(numRets == g_lua.stackSize());
|
||||||
} catch(LuaException &e) {
|
} catch(LuaException &e) {
|
||||||
logError("lua cpp callback failed: ", e.what());
|
logError("lua cpp callback failed: %s", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
return numRets;
|
return numRets;
|
||||||
|
@ -1019,7 +1019,7 @@ void LuaInterface::pushObject(const LuaObjectPtr& obj)
|
||||||
new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj);
|
new(newUserdata(sizeof(LuaObjectPtr))) LuaObjectPtr(obj);
|
||||||
|
|
||||||
// set the userdata metatable
|
// set the userdata metatable
|
||||||
getGlobal(stdext::mkstr(obj->getClassName(), "_mt"));
|
getGlobal(stdext::format("%s_mt", obj->getClassName()));
|
||||||
assert(!isNil());
|
assert(!isNil());
|
||||||
setMetatable();
|
setMetatable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ bool luavalue_cast(int index, std::function<void(Args...)>& func) {
|
||||||
"did you forget to hold a reference for that function?", 0);
|
"did you forget to hold a reference for that function?", 0);
|
||||||
}
|
}
|
||||||
} catch(LuaException& e) {
|
} catch(LuaException& e) {
|
||||||
logError("lua function callback failed: ", e.what());
|
logError("lua function callback failed: %s", e.what());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return true;
|
return true;
|
||||||
|
@ -239,7 +239,7 @@ luavalue_cast(int index, std::function<Ret(Args...)>& func) {
|
||||||
"did you forget to hold a reference for that function?", 0);
|
"did you forget to hold a reference for that function?", 0);
|
||||||
}
|
}
|
||||||
} catch(LuaException& e) {
|
} catch(LuaException& e) {
|
||||||
logError("lua function callback failed: ", e.what());
|
logError("lua function callback failed: %s", e.what());
|
||||||
}
|
}
|
||||||
return Ret();
|
return Ret();
|
||||||
};
|
};
|
||||||
|
|
|
@ -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)
|
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());
|
RSA::decrypt((char*)m_buffer + m_readPos, size, p.c_str(), q.c_str(), d.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,14 +77,14 @@ OTMLNodePtr OTMLNode::at(const std::string& childTag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!res)
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
OTMLNodePtr OTMLNode::atIndex(int childIndex)
|
OTMLNodePtr OTMLNode::atIndex(int childIndex)
|
||||||
{
|
{
|
||||||
if(childIndex >= size() || childIndex < 0)
|
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];
|
return m_children[childIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ template<typename T>
|
||||||
T OTMLNode::value() {
|
T OTMLNode::value() {
|
||||||
T ret;
|
T ret;
|
||||||
if(!stdext::cast(m_value, ret))
|
if(!stdext::cast(m_value, ret))
|
||||||
throw OTMLException(shared_from_this(), stdext::mkstr("failed to cast node value to type '", stdext::demangle_type<T>(), "'"));
|
throw OTMLException(shared_from_this(), stdext::mkstr("failed to cast node value to type '%s'", stdext::demangle_type<T>()));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <bitset>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
|
@ -109,7 +109,7 @@ void crashHandler(int signum, siginfo_t* info, void* secret)
|
||||||
fout << ss.str();
|
fout << ss.str();
|
||||||
fout << "\n";
|
fout << "\n";
|
||||||
fout.close();
|
fout.close();
|
||||||
logInfo("Crash report saved to file ", fileName.c_str());
|
logInfo("Crash report saved to file %s", fileName.c_str());
|
||||||
} else
|
} else
|
||||||
logError("Failed to save crash report!");
|
logError("Failed to save crash report!");
|
||||||
|
|
||||||
|
|
|
@ -134,12 +134,13 @@ LONG CALLBACK ExceptionHandler(LPEXCEPTION_POINTERS e)
|
||||||
if(fout.is_open() && fout.good()) {
|
if(fout.is_open() && fout.good()) {
|
||||||
fout << ss.str();
|
fout << ss.str();
|
||||||
fout.close();
|
fout.close();
|
||||||
logInfo("Crash report saved to file ", fileName);
|
logInfo("Crash report saved to file %s", fileName);
|
||||||
} else
|
} else
|
||||||
logError("Failed to save crash report!");
|
logError("Failed to save crash report!");
|
||||||
|
|
||||||
// inform the user
|
// inform the user
|
||||||
std::string msg = stdext::format("The application has crashed.\n\n"
|
std::string msg = stdext::format(
|
||||||
|
"The application has crashed.\n\n"
|
||||||
"A crash report has been written to:\n"
|
"A crash report has been written to:\n"
|
||||||
"%s", fileName.c_str());
|
"%s", fileName.c_str());
|
||||||
MessageBox(NULL, msg.c_str(), "Application crashed", 0);
|
MessageBox(NULL, msg.c_str(), "Application crashed", 0);
|
||||||
|
|
|
@ -680,7 +680,7 @@ void WIN32Window::setMouseCursor(const std::string& file, const Point& hotSpot)
|
||||||
|
|
||||||
apng_data apng;
|
apng_data apng;
|
||||||
if(load_apng(fin, &apng) != 0) {
|
if(load_apng(fin, &apng) != 0) {
|
||||||
logTraceError("unable to load png file ", file);
|
logTraceError("unable to load png file %s", file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -416,7 +416,7 @@ void X11Window::internalCreateGLContext()
|
||||||
|
|
||||||
m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, attrList);
|
m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, EGL_NO_CONTEXT, attrList);
|
||||||
if(m_eglContext == EGL_NO_CONTEXT )
|
if(m_eglContext == EGL_NO_CONTEXT )
|
||||||
logFatal("Unable to create EGL context: ", eglGetError());
|
logFatal("Unable to create EGL context: %s", eglGetError());
|
||||||
#else
|
#else
|
||||||
m_glxContext = glXCreateContext(m_display, m_visual, NULL, True);
|
m_glxContext = glXCreateContext(m_display, m_visual, NULL, True);
|
||||||
|
|
||||||
|
@ -457,7 +457,7 @@ void X11Window::internalConnectGLContext()
|
||||||
#ifdef OPENGL_ES
|
#ifdef OPENGL_ES
|
||||||
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_window, NULL);
|
m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_window, NULL);
|
||||||
if(m_eglSurface == EGL_NO_SURFACE)
|
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))
|
if(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext))
|
||||||
logFatal("Unable to connect EGL context into X11 window");
|
logFatal("Unable to connect EGL context into X11 window");
|
||||||
#else
|
#else
|
||||||
|
@ -841,7 +841,7 @@ void X11Window::setMouseCursor(const std::string& file, const Point& hotSpot)
|
||||||
|
|
||||||
apng_data apng;
|
apng_data apng;
|
||||||
if(load_apng(fin, &apng) != 0) {
|
if(load_apng(fin, &apng) != 0) {
|
||||||
logTraceError("unable to load png file ", file);
|
logTraceError("unable to load png file %s", file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ bool OggSoundFile::prepareOgg()
|
||||||
|
|
||||||
vorbis_info* vi = ov_info(&m_vorbisFile, -1);
|
vorbis_info* vi = ov_info(&m_vorbisFile, -1);
|
||||||
if(!vi) {
|
if(!vi) {
|
||||||
logError("ogg file not supported: ", m_file->name());
|
logError("ogg file not supported: %s", m_file->name());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,14 +40,14 @@ bool SoundBuffer::fillBuffer(const SoundFilePtr& soundFile)
|
||||||
{
|
{
|
||||||
ALenum format = soundFile->getSampleFormat();
|
ALenum format = soundFile->getSampleFormat();
|
||||||
if(format == AL_UNDETERMINED) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataBuffer<char> samples(soundFile->getSize());
|
DataBuffer<char> samples(soundFile->getSize());
|
||||||
int read = soundFile->read(&samples[0], soundFile->getSize());
|
int read = soundFile->read(&samples[0], soundFile->getSize());
|
||||||
if(read <= 0) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ bool SoundBuffer::fillBuffer(ALenum sampleFormat, const DataBuffer<char>& data,
|
||||||
alBufferData(m_bufferId, sampleFormat, &data[0], size, rate);
|
alBufferData(m_bufferId, sampleFormat, &data[0], size, rate);
|
||||||
ALenum err = alGetError();
|
ALenum err = alGetError();
|
||||||
if(err != AL_NO_ERROR) {
|
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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -33,7 +33,7 @@ SoundFilePtr SoundFile::loadSoundFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
FileStreamPtr file = g_resources.openFile(filename);
|
FileStreamPtr file = g_resources.openFile(filename);
|
||||||
if(!file) {
|
if(!file) {
|
||||||
logTraceError("unable to open ", filename);
|
logTraceError("unable to open %s", filename);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ SoundFilePtr SoundFile::loadSoundFile(const std::string& filename)
|
||||||
if(oggSoundFile->prepareOgg())
|
if(oggSoundFile->prepareOgg())
|
||||||
soundFile = oggSoundFile;
|
soundFile = oggSoundFile;
|
||||||
} else
|
} else
|
||||||
logError("unknown sound file format ", filename);
|
logError("unknown sound file format %s", filename);
|
||||||
|
|
||||||
return soundFile;
|
return soundFile;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ void SoundManager::init()
|
||||||
|
|
||||||
m_context = alcCreateContext(m_device, NULL);
|
m_context = alcCreateContext(m_device, NULL);
|
||||||
if(!m_context) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
alcMakeContextCurrent(m_context);
|
alcMakeContextCurrent(m_context);
|
||||||
|
@ -136,7 +136,7 @@ void SoundManager::play(const std::string& filename)
|
||||||
|
|
||||||
SoundSourcePtr soundSource = createSoundSource(filename);
|
SoundSourcePtr soundSource = createSoundSource(filename);
|
||||||
if(!soundSource) {
|
if(!soundSource) {
|
||||||
logError("unable to play '", filename, "'");
|
logError("unable to play '%s'", filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ void SoundManager::playMusic(const std::string& filename, float fadetime)
|
||||||
|
|
||||||
m_musicSource = createSoundSource(filename);
|
m_musicSource = createSoundSource(filename);
|
||||||
if(!m_musicSource) {
|
if(!m_musicSource) {
|
||||||
logError("unable to play '", filename, "'");
|
logError("unable to play '%s'", filename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ SoundSourcePtr SoundManager::createSoundSource(const std::string& filename)
|
||||||
buffer->fillBuffer(soundFile);
|
buffer->fillBuffer(soundFile);
|
||||||
source->setBuffer(buffer);
|
source->setBuffer(buffer);
|
||||||
m_buffers[filename] = buffer;
|
m_buffers[filename] = buffer;
|
||||||
logWarning("uncached sound '", filename, "' requested to be played");
|
logWarning("uncached sound '%s' requested to be played", filename);
|
||||||
} else {
|
} else {
|
||||||
StreamSoundSourcePtr streamSource(new StreamSoundSource);
|
StreamSoundSourcePtr streamSource(new StreamSoundSource);
|
||||||
streamSource->setSoundFile(soundFile);
|
streamSource->setSoundFile(soundFile);
|
||||||
|
|
|
@ -143,12 +143,12 @@ bool StreamSoundSource::fillBufferAndQueue(ALuint buffer)
|
||||||
alBufferData(buffer, format, &bufferData[0], bytesRead, m_soundFile->getRate());
|
alBufferData(buffer, format, &bufferData[0], bytesRead, m_soundFile->getRate());
|
||||||
ALenum err = alGetError();
|
ALenum err = alGetError();
|
||||||
if(err != AL_NO_ERROR)
|
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);
|
alSourceQueueBuffers(m_sourceId, 1, &buffer);
|
||||||
err = alGetError();
|
err = alGetError();
|
||||||
if(err != AL_NO_ERROR)
|
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
|
// return false if there aren't more buffers to fill
|
||||||
|
|
|
@ -54,4 +54,6 @@ const static dumper::dumper_util dump;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using stdext::dump;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -51,7 +51,10 @@ T from_string(const std::string& str, T def = T()) { return unsafe_cast<T, std::
|
||||||
|
|
||||||
/// Cast non-class types like int, char, float, double and pointers
|
/// Cast non-class types like int, char, float, double and pointers
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename std::enable_if<std::is_integral<T>::value || std::is_pointer<T>::value || std::is_floating_point<T>::value, T>::type sprintf_cast(const T& t) { return t; }
|
typename std::enable_if<std::is_integral<T>::value ||
|
||||||
|
std::is_pointer<T>::value ||
|
||||||
|
std::is_floating_point<T>::value ||
|
||||||
|
std::is_enum<T>::value, T>::type sprintf_cast(const T& t) { return t; }
|
||||||
|
|
||||||
/// Cast any class or struct convertible to std::string
|
/// Cast any class or struct convertible to std::string
|
||||||
inline const char *sprintf_cast(const std::string& s) { return s.c_str(); }
|
inline const char *sprintf_cast(const std::string& s) { return s.c_str(); }
|
||||||
|
|
|
@ -93,7 +93,7 @@ bool UIAnchorLayout::updateWidget(const UIWidgetPtr& widget, UIAnchorGroup& anch
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(first == widget) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,7 @@ void UIManager::onWidgetDestroy(const UIWidgetPtr& widget)
|
||||||
g_lua.collectGarbage();
|
g_lua.collectGarbage();
|
||||||
for(const UIWidgetPtr& widget : backupList) {
|
for(const UIWidgetPtr& widget : backupList) {
|
||||||
if(widget->getUseCount() != 1)
|
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);
|
}, 1);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
@ -301,7 +301,7 @@ bool UIManager::importStyle(const std::string& file)
|
||||||
importStyleFromOTML(styleNode);
|
importStyleFromOTML(styleNode);
|
||||||
return true;
|
return true;
|
||||||
} catch(stdext::exception& e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,7 +325,7 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||||
/*
|
/*
|
||||||
auto it = m_styles.find(name);
|
auto it = m_styles.find(name);
|
||||||
if(it != m_styles.end())
|
if(it != m_styles.end())
|
||||||
logWarning("style '", name, "' is being redefined");
|
logWarning("style '%s' is being redefined", name);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
OTMLNodePtr originalStyle = getStyle(base);
|
OTMLNodePtr originalStyle = getStyle(base);
|
||||||
|
@ -382,7 +382,7 @@ UIWidgetPtr UIManager::loadUI(const std::string& file, const UIWidgetPtr& parent
|
||||||
|
|
||||||
return widget;
|
return widget;
|
||||||
} catch(stdext::exception& e) {
|
} 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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -393,7 +393,7 @@ UIWidgetPtr UIManager::createWidgetFromStyle(const std::string& styleName, const
|
||||||
try {
|
try {
|
||||||
return createWidgetFromOTML(node, parent);
|
return createWidgetFromOTML(node, parent);
|
||||||
} catch(stdext::exception& e) {
|
} 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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ UIWidget::~UIWidget()
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if(!m_destroyed)
|
if(!m_destroyed)
|
||||||
logWarning("widget '", m_id, "' was not explicitly destroyed");
|
logWarning("widget '%s' was not explicitly destroyed", m_id);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +500,7 @@ void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
|
||||||
}
|
}
|
||||||
m_firstOnStyle = false;
|
m_firstOnStyle = false;
|
||||||
} catch(stdext::exception& e) {
|
} 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;
|
m_loadingStyle = false;
|
||||||
}
|
}
|
||||||
|
@ -513,7 +513,7 @@ void UIWidget::addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedW
|
||||||
if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout())
|
if(UIAnchorLayoutPtr anchorLayout = getAnchoredLayout())
|
||||||
anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge);
|
anchorLayout->addAnchor(asUIWidget(), anchoredEdge, hookedWidgetId, hookedEdge);
|
||||||
else
|
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)
|
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::AnchorHorizontalCenter, hookedWidgetId, Fw::AnchorHorizontalCenter);
|
||||||
anchorLayout->addAnchor(asUIWidget(), Fw::AnchorVerticalCenter, hookedWidgetId, Fw::AnchorVerticalCenter);
|
anchorLayout->addAnchor(asUIWidget(), Fw::AnchorVerticalCenter, hookedWidgetId, Fw::AnchorVerticalCenter);
|
||||||
} else
|
} 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)
|
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::AnchorTop, hookedWidgetId, Fw::AnchorTop);
|
||||||
anchorLayout->addAnchor(asUIWidget(), Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom);
|
anchorLayout->addAnchor(asUIWidget(), Fw::AnchorBottom, hookedWidgetId, Fw::AnchorBottom);
|
||||||
} else
|
} 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()
|
void UIWidget::breakAnchors()
|
||||||
|
@ -710,7 +710,7 @@ void UIWidget::internalDestroy()
|
||||||
void UIWidget::destroy()
|
void UIWidget::destroy()
|
||||||
{
|
{
|
||||||
if(m_destroyed)
|
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
|
// hold itself reference
|
||||||
UIWidgetPtr self = asUIWidget();
|
UIWidgetPtr self = asUIWidget();
|
||||||
|
@ -799,7 +799,7 @@ void UIWidget::setLayout(const UILayoutPtr& layout)
|
||||||
bool UIWidget::setRect(const Rect& rect)
|
bool UIWidget::setRect(const Rect& rect)
|
||||||
{
|
{
|
||||||
if(rect.width() > 8192 || rect.height() > 8192) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
// only update if the rect really changed
|
// only update if the rect really changed
|
||||||
|
@ -830,7 +830,7 @@ void UIWidget::setStyle(const std::string& styleName)
|
||||||
{
|
{
|
||||||
OTMLNodePtr styleNode = g_ui.getStyle(styleName);
|
OTMLNodePtr styleNode = g_ui.getStyle(styleName);
|
||||||
if(!styleNode) {
|
if(!styleNode) {
|
||||||
logTraceError("unable to retrive style '", styleName, "': not a defined style");
|
logTraceError("unable to retrieve style '%s': not a defined style", styleName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
styleNode = styleNode->clone();
|
styleNode = styleNode->clone();
|
||||||
|
|
|
@ -41,7 +41,7 @@ void UIWidget::initBaseStyle()
|
||||||
|
|
||||||
// generate an unique id, this is need because anchored layouts find widgets by id
|
// generate an unique id, this is need because anchored layouts find widgets by id
|
||||||
static unsigned long id = 1;
|
static unsigned long id = 1;
|
||||||
m_id = stdext::mkstr("widget", id++);
|
m_id = stdext::format("widget %d", id++);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
|
void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
|
||||||
|
|
|
@ -288,6 +288,32 @@ namespace Otc
|
||||||
SpeakMonsterSay,
|
SpeakMonsterSay,
|
||||||
SpeakMonsterYell
|
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
|
#endif
|
||||||
|
|
|
@ -38,6 +38,7 @@ Game g_game;
|
||||||
Game::Game()
|
Game::Game()
|
||||||
{
|
{
|
||||||
resetGameStates();
|
resetGameStates();
|
||||||
|
setClientVersion(860);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::resetGameStates()
|
void Game::resetGameStates()
|
||||||
|
@ -1018,6 +1019,59 @@ bool Game::canPerformGameAction()
|
||||||
return m_localPlayer && !m_dead && m_protocolGame && m_protocolGame->isConnected() && checkBotProtection();
|
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)
|
void Game::setAttackingCreature(const CreaturePtr& creature)
|
||||||
{
|
{
|
||||||
CreaturePtr oldCreature = m_attackingCreature;
|
CreaturePtr oldCreature = m_attackingCreature;
|
||||||
|
|
|
@ -229,6 +229,18 @@ public:
|
||||||
//void reportRuleViolation2();
|
//void reportRuleViolation2();
|
||||||
// TODO: market related
|
// 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 canPerformGameAction();
|
||||||
bool canReportBugs() { return m_canReportBugs; }
|
bool canReportBugs() { return m_canReportBugs; }
|
||||||
bool checkBotProtection();
|
bool checkBotProtection();
|
||||||
|
@ -272,6 +284,9 @@ private:
|
||||||
bool m_canReportBugs;
|
bool m_canReportBugs;
|
||||||
std::vector<uint8> m_gmActions;
|
std::vector<uint8> m_gmActions;
|
||||||
std::string m_worldName;
|
std::string m_worldName;
|
||||||
|
std::bitset<Otc::LastGameFeature> m_features;
|
||||||
|
int m_clientVersion;
|
||||||
|
std::string m_rsa;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Game g_game;
|
extern Game g_game;
|
||||||
|
|
|
@ -41,7 +41,7 @@ ItemPtr Item::create(int id)
|
||||||
{
|
{
|
||||||
ItemPtr item = ItemPtr(new Item);
|
ItemPtr item = ItemPtr(new Item);
|
||||||
if(id < g_thingsType.getFirstItemId() || id > g_thingsType.getMaxItemid())
|
if(id < g_thingsType.getFirstItemId() || id > g_thingsType.getMaxItemid())
|
||||||
logTraceError("invalid item id ", id);
|
logTraceError("invalid item id %d", id);
|
||||||
else {
|
else {
|
||||||
item->setId(id);
|
item->setId(id);
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate)
|
||||||
void Item::setId(uint32 id)
|
void Item::setId(uint32 id)
|
||||||
{
|
{
|
||||||
if(id < g_thingsType.getFirstItemId() || id > g_thingsType.getMaxItemid()) {
|
if(id < g_thingsType.getFirstItemId() || id > g_thingsType.getMaxItemid()) {
|
||||||
logTraceError("invalid item id ", id);
|
logTraceError("invalid item id %d", id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_id = id;
|
m_id = id;
|
||||||
|
|
|
@ -48,7 +48,7 @@ bool SpriteManager::load(const std::string& file)
|
||||||
m_loaded = true;
|
m_loaded = true;
|
||||||
return true;
|
return true;
|
||||||
} catch(stdext::exception& e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ ImagePtr SpriteManager::getSpriteImage(int id)
|
||||||
uint16 coloredPixels = m_spritesFile->getU16();
|
uint16 coloredPixels = m_spritesFile->getU16();
|
||||||
|
|
||||||
if(writePos + transparentPixels*4 + coloredPixels*3 >= SPRITE_DATA_SIZE) {
|
if(writePos + transparentPixels*4 + coloredPixels*3 >= SPRITE_DATA_SIZE) {
|
||||||
logWarning("corrupt sprite id ", id);
|
logWarning("corrupt sprite id %d", id);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ void StaticText::compose()
|
||||||
text += " says:\n";
|
text += " says:\n";
|
||||||
m_color = Color(95, 247, 247);
|
m_color = Color(95, 247, 247);
|
||||||
} else {
|
} else {
|
||||||
logWarning("unknown speak type: ", m_messageType);
|
logWarning("Unknown speak type: %d", m_messageType);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint i = 0; i < m_messages.size(); ++i) {
|
for(uint i = 0; i < m_messages.size(); ++i) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ bool ThingsType::load(const std::string& file)
|
||||||
{
|
{
|
||||||
FileStreamPtr fin = g_resources.openFile(file);
|
FileStreamPtr fin = g_resources.openFile(file);
|
||||||
if(!fin) {
|
if(!fin) {
|
||||||
logError("unable to open dat file '", file, "'");
|
logError("unable to open dat file '%s'", file);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,6 @@ bool ThingsType::parseThingType(const FileStreamPtr& fin, ThingType& thingType)
|
||||||
else if(property == ThingType::IsRune)
|
else if(property == ThingType::IsRune)
|
||||||
thingType.m_properties[ThingType::IsStackable] = true;
|
thingType.m_properties[ThingType::IsStackable] = true;
|
||||||
#endif
|
#endif
|
||||||
#if PROTOCOL>=944
|
|
||||||
else if(property == ThingType::Market) {
|
else if(property == ThingType::Market) {
|
||||||
fin->getU16(); // category
|
fin->getU16(); // category
|
||||||
fin->getU16(); // trade as
|
fin->getU16(); // trade as
|
||||||
|
@ -115,7 +114,6 @@ bool ThingsType::parseThingType(const FileStreamPtr& fin, ThingType& thingType)
|
||||||
fin->getU16(); // restrict profession
|
fin->getU16(); // restrict profession
|
||||||
fin->getU16(); // level
|
fin->getU16(); // level
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!done)
|
if(!done)
|
||||||
|
|
|
@ -170,11 +170,11 @@ ThingPtr Tile::addThing(const ThingPtr& thing, int stackPos)
|
||||||
int priority = thing->getStackPriority();
|
int priority = thing->getStackPriority();
|
||||||
for(stackPos = 0; stackPos < (int)m_things.size(); ++stackPos) {
|
for(stackPos = 0; stackPos < (int)m_things.size(); ++stackPos) {
|
||||||
int otherPriority = m_things[stackPos]->getStackPriority();
|
int otherPriority = m_things[stackPos]->getStackPriority();
|
||||||
#if PROTOCOL<=810
|
if(!g_game.getFeature(Otc::GameReverseCreatureStack)) {
|
||||||
// older protocols stores creatures in reverse order
|
// older protocols stores creatures in reverse order
|
||||||
if(priority == 4 && otherPriority == 4)
|
if(priority == 4 && otherPriority == 4)
|
||||||
break;
|
break;
|
||||||
#endif
|
}
|
||||||
if(otherPriority > priority)
|
if(otherPriority > priority)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,14 +68,6 @@ namespace Proto {
|
||||||
constexpr int ClientOs = OsOtclientLinux;
|
constexpr int ClientOs = OsOtclientLinux;
|
||||||
#endif
|
#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 {
|
enum LoginServerOpts {
|
||||||
LoginServerError = 10,
|
LoginServerError = 10,
|
||||||
LoginServerMotd = 20,
|
LoginServerMotd = 20,
|
||||||
|
@ -95,13 +87,8 @@ namespace Proto {
|
||||||
GameServerLoginError = 20,
|
GameServerLoginError = 20,
|
||||||
GameServerLoginAdvice = 21,
|
GameServerLoginAdvice = 21,
|
||||||
GameServerLoginWait = 22,
|
GameServerLoginWait = 22,
|
||||||
#if PROTOCOL>=953
|
|
||||||
GameServerPing = 29,
|
|
||||||
GameServerPingBack = 30,
|
|
||||||
#else
|
|
||||||
GameServerPingBack = 29,
|
GameServerPingBack = 29,
|
||||||
GameServerPing = 30,
|
GameServerPing = 30,
|
||||||
#endif
|
|
||||||
GameServerChallange = 31,
|
GameServerChallange = 31,
|
||||||
GameServerDeath = 40,
|
GameServerDeath = 40,
|
||||||
|
|
||||||
|
@ -488,7 +475,7 @@ namespace Proto {
|
||||||
case Proto::ServerSpeakBroadcast: return Otc::SpeakBroadcast;
|
case Proto::ServerSpeakBroadcast: return Otc::SpeakBroadcast;
|
||||||
case Proto::ServerSpeakPrivateRedTo: return Otc::SpeakPrivateRed;
|
case Proto::ServerSpeakPrivateRedTo: return Otc::SpeakPrivateRed;
|
||||||
default:
|
default:
|
||||||
logError("unknown protocol speak type ", type);
|
logError("unknown protocol speak type %d", type);
|
||||||
return Otc::SpeakSay;
|
return Otc::SpeakSay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -510,7 +497,7 @@ namespace Proto {
|
||||||
case Otc::SpeakMonsterSay: return Proto::ServerSpeakMonsterSay;
|
case Otc::SpeakMonsterSay: return Proto::ServerSpeakMonsterSay;
|
||||||
case Otc::SpeakMonsterYell: return Proto::ServerSpeakMonsterYell;
|
case Otc::SpeakMonsterYell: return Proto::ServerSpeakMonsterYell;
|
||||||
default:
|
default:
|
||||||
logError("unknown protocol speak type desc ", type);
|
logError("unknown protocol speak type desc %d", type);
|
||||||
return Proto::ServerSpeakSay;
|
return Proto::ServerSpeakSay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -528,7 +515,7 @@ namespace Proto {
|
||||||
case Proto::MessageConsoleBlue: return "consoleBlue";
|
case Proto::MessageConsoleBlue: return "consoleBlue";
|
||||||
case Proto::MessageConsoleRed: return "consoleRed";
|
case Proto::MessageConsoleRed: return "consoleRed";
|
||||||
default:
|
default:
|
||||||
logError("unknown protocol text message type ", type);
|
logError("unknown protocol text message type %d", type);
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,11 +45,11 @@ void ProtocolGame::onConnect()
|
||||||
// must create local player before parsing anything
|
// must create local player before parsing anything
|
||||||
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
||||||
|
|
||||||
#if PROTOCOL>=854
|
if(g_game.getFeature(Otc::GameProtocolChecksum))
|
||||||
enableChecksum();
|
enableChecksum();
|
||||||
#else
|
|
||||||
|
if(!g_game.getFeature(Otc::GameChallangeOnLogin))
|
||||||
sendLoginPacket(0, 0);
|
sendLoginPacket(0, 0);
|
||||||
#endif
|
|
||||||
|
|
||||||
recv();
|
recv();
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,9 +66,15 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg)
|
||||||
parseLoginWait(msg);
|
parseLoginWait(msg);
|
||||||
break;
|
break;
|
||||||
case Proto::GameServerPing:
|
case Proto::GameServerPing:
|
||||||
|
if(g_game.getFeature(Otc::GameTrucatedPingOpcode))
|
||||||
|
parsePingBack(msg);
|
||||||
|
else
|
||||||
parsePing(msg);
|
parsePing(msg);
|
||||||
break;
|
break;
|
||||||
case Proto::GameServerPingBack:
|
case Proto::GameServerPingBack:
|
||||||
|
if(g_game.getFeature(Otc::GameTrucatedPingOpcode))
|
||||||
|
parsePing(msg);
|
||||||
|
else
|
||||||
parsePingBack(msg);
|
parsePingBack(msg);
|
||||||
break;
|
break;
|
||||||
case Proto::GameServerChallange:
|
case Proto::GameServerChallange:
|
||||||
|
@ -313,7 +319,8 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg)
|
||||||
prevOpcode = opcode;
|
prevOpcode = opcode;
|
||||||
}
|
}
|
||||||
} catch(stdext::exception& e) {
|
} 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)
|
void ProtocolGame::parseGMActions(const InputMessagePtr& msg)
|
||||||
{
|
{
|
||||||
std::vector<uint8> actions;
|
std::vector<uint8> 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());
|
actions.push_back(msg->getU8());
|
||||||
g_game.processGMActions(actions);
|
g_game.processGMActions(actions);
|
||||||
}
|
}
|
||||||
|
@ -379,9 +396,8 @@ void ProtocolGame::parseChallange(const InputMessagePtr& msg)
|
||||||
void ProtocolGame::parseDeath(const InputMessagePtr& msg)
|
void ProtocolGame::parseDeath(const InputMessagePtr& msg)
|
||||||
{
|
{
|
||||||
int penality = 100;
|
int penality = 100;
|
||||||
#if PROTOCOL>=862
|
if(g_game.getFeature(Otc::GamePenalityOnDeath))
|
||||||
penality = msg->getU8();
|
penality = msg->getU8();
|
||||||
#endif
|
|
||||||
g_game.processDeath(penality);
|
g_game.processDeath(penality);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,9 +461,8 @@ void ProtocolGame::parseTileAddThing(const InputMessagePtr& msg)
|
||||||
Position pos = getPosition(msg);
|
Position pos = getPosition(msg);
|
||||||
int stackPos = -1;
|
int stackPos = -1;
|
||||||
|
|
||||||
#if PROTOCOL>=854
|
if(g_game.getFeature(Otc::GameStackposOnTileAddThing))
|
||||||
stackPos = msg->getU8();
|
stackPos = msg->getU8();
|
||||||
#endif
|
|
||||||
|
|
||||||
ThingPtr thing = getThing(msg);
|
ThingPtr thing = getThing(msg);
|
||||||
g_map.addThing(thing, pos, stackPos);
|
g_map.addThing(thing, pos, stackPos);
|
||||||
|
@ -561,9 +576,8 @@ void ProtocolGame::parseOpenNpcTrade(const InputMessagePtr& msg)
|
||||||
std::vector<std::tuple<ItemPtr, std::string, int, int, int>> items;
|
std::vector<std::tuple<ItemPtr, std::string, int, int, int>> items;
|
||||||
std::string npcName;
|
std::string npcName;
|
||||||
|
|
||||||
#if PROTOCOL>=910
|
if(g_game.getFeature(Otc::GameNameOnNpcTrade))
|
||||||
npcName = msg->getString();
|
npcName = msg->getString();
|
||||||
#endif
|
|
||||||
|
|
||||||
int listCount = msg->getU8();
|
int listCount = msg->getU8();
|
||||||
for(int i = 0; i < listCount; ++i) {
|
for(int i = 0; i < listCount; ++i) {
|
||||||
|
@ -827,27 +841,32 @@ void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg)
|
||||||
{
|
{
|
||||||
double health = msg->getU16();
|
double health = msg->getU16();
|
||||||
double maxHealth = msg->getU16();
|
double maxHealth = msg->getU16();
|
||||||
#if PROTOCOL>=854
|
|
||||||
double freeCapacity = msg->getU32() / 100.0;
|
double freeCapacity;
|
||||||
#else
|
if(g_game.getFeature(Otc::GameDoubleFreeCapacity))
|
||||||
double freeCapacity = msg->getU16() / 100.0;
|
freeCapacity = msg->getU32() / 100.0;
|
||||||
#endif
|
else
|
||||||
#if PROTOCOL>=910
|
freeCapacity = msg->getU16() / 100.0;
|
||||||
msg->getU32(); // total capacity
|
|
||||||
#endif
|
double totalCapacity;
|
||||||
#if PROTOCOL>=870
|
if(g_game.getFeature(Otc::GameTotalCapacity))
|
||||||
double experience = msg->getU64();
|
totalCapacity = msg->getU32() / 100.0;
|
||||||
#else
|
|
||||||
double experience = msg->getU32();
|
double experience;
|
||||||
#endif
|
if(g_game.getFeature(Otc::GameDoubleExperience))
|
||||||
|
experience = msg->getU64();
|
||||||
|
else
|
||||||
|
experience = msg->getU32();
|
||||||
|
|
||||||
double level = msg->getU16();
|
double level = msg->getU16();
|
||||||
double levelPercent = msg->getU8();
|
double levelPercent = msg->getU8();
|
||||||
double mana = msg->getU16();
|
double mana = msg->getU16();
|
||||||
double maxMana = msg->getU16();
|
double maxMana = msg->getU16();
|
||||||
double magicLevel = msg->getU8();
|
double magicLevel = msg->getU8();
|
||||||
#if PROTOCOL>=910
|
|
||||||
|
if(g_game.getFeature(Otc::GameSkillsBase))
|
||||||
msg->getU8(); // base magic level
|
msg->getU8(); // base magic level
|
||||||
#endif
|
|
||||||
double magicLevelPercent = msg->getU8();
|
double magicLevelPercent = msg->getU8();
|
||||||
double soul = msg->getU8();
|
double soul = msg->getU8();
|
||||||
double stamina = msg->getU16();
|
double stamina = msg->getU16();
|
||||||
|
@ -861,21 +880,21 @@ void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg)
|
||||||
m_localPlayer->setStamina(stamina);
|
m_localPlayer->setStamina(stamina);
|
||||||
m_localPlayer->setSoul(soul);
|
m_localPlayer->setSoul(soul);
|
||||||
|
|
||||||
#if PROTOCOL>=910
|
if(g_game.getFeature(Otc::GameAdditionalPlayerStats)) {
|
||||||
int speed = msg->getU16();
|
int speed = msg->getU16();
|
||||||
msg->getU16(); // regeneration time
|
msg->getU16(); // regeneration time
|
||||||
|
|
||||||
m_localPlayer->setSpeed(speed);
|
m_localPlayer->setSpeed(speed);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolGame::parsePlayerSkills(const InputMessagePtr& msg)
|
void ProtocolGame::parsePlayerSkills(const InputMessagePtr& msg)
|
||||||
{
|
{
|
||||||
for(int skill = 0; skill < Otc::LastSkill; skill++) {
|
for(int skill = 0; skill < Otc::LastSkill; skill++) {
|
||||||
int level = msg->getU8();
|
int level = msg->getU8();
|
||||||
#if PROTOCOL>=910
|
if(g_game.getFeature(Otc::GameSkillsBase))
|
||||||
msg->getU8(); // base
|
msg->getU8(); // base
|
||||||
#endif
|
|
||||||
int levelPercent = msg->getU8();
|
int levelPercent = msg->getU8();
|
||||||
|
|
||||||
m_localPlayer->setSkill((Otc::Skill)skill, level, levelPercent);
|
m_localPlayer->setSkill((Otc::Skill)skill, level, levelPercent);
|
||||||
|
@ -890,9 +909,9 @@ void ProtocolGame::parsePlayerState(const InputMessagePtr& msg)
|
||||||
|
|
||||||
void ProtocolGame::parsePlayerCancelAttack(const InputMessagePtr& msg)
|
void ProtocolGame::parsePlayerCancelAttack(const InputMessagePtr& msg)
|
||||||
{
|
{
|
||||||
#if PROTOCOL>=860
|
if(g_game.getFeature(Otc::GameIdOnCancelAttack))
|
||||||
msg->getU32(); // unknown
|
msg->getU32(); // unknown
|
||||||
#endif
|
|
||||||
g_game.processAttackCancel();
|
g_game.processAttackCancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -982,14 +1001,14 @@ void ProtocolGame::parseOpenChannel(const InputMessagePtr& msg)
|
||||||
int channelId = msg->getU16();
|
int channelId = msg->getU16();
|
||||||
std::string name = msg->getString();
|
std::string name = msg->getString();
|
||||||
|
|
||||||
#if PROTOCOL>=944
|
if(g_game.getFeature(Otc::GameChannelPlayerList)) {
|
||||||
int joinedPlayers = msg->getU16();
|
int joinedPlayers = msg->getU16();
|
||||||
for(int i=0;i<joinedPlayers;++i)
|
for(int i=0;i<joinedPlayers;++i)
|
||||||
msg->getString(); // player name
|
msg->getString(); // player name
|
||||||
int invitedPlayers = msg->getU16();
|
int invitedPlayers = msg->getU16();
|
||||||
for(int i=0;i<invitedPlayers;++i)
|
for(int i=0;i<invitedPlayers;++i)
|
||||||
msg->getString(); // player name
|
msg->getString(); // player name
|
||||||
#endif
|
}
|
||||||
|
|
||||||
g_game.processOpenChannel(channelId, 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));
|
outfitList.push_back(std::make_tuple(outfitId, outfitName, outfitAddons));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PROTOCOL>=870
|
if(g_game.getFeature(Otc::GamePlayerMounts)) {
|
||||||
int mountCount = msg->getU8();
|
int mountCount = msg->getU8();
|
||||||
for(int i=0;i<mountCount;++i) {
|
for(int i=0;i<mountCount;++i) {
|
||||||
msg->getU16(); // mount type
|
msg->getU16(); // mount type
|
||||||
msg->getString(); // mount name
|
msg->getString(); // mount name
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
|
|
||||||
g_game.processOpenOutfitWindow(currentOutfit, outfitList);
|
g_game.processOpenOutfitWindow(currentOutfit, outfitList);
|
||||||
}
|
}
|
||||||
|
@ -1219,7 +1238,7 @@ void ProtocolGame::parseExtendedOpcode(const InputMessagePtr& msg)
|
||||||
try {
|
try {
|
||||||
callLuaField("onExtendedOpcode", opcode, buffer);
|
callLuaField("onExtendedOpcode", opcode, buffer);
|
||||||
} catch(stdext::exception& e) {
|
} 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)
|
void ProtocolGame::setTileDescription(const InputMessagePtr& msg, Position position)
|
||||||
{
|
{
|
||||||
#if PROTOCOL>=910
|
if(g_game.getFeature(Otc::GameEnvironmentEffect))
|
||||||
msg->getU16(); // environment effect
|
msg->getU16(); // environment effect
|
||||||
#endif
|
|
||||||
|
|
||||||
g_map.cleanTile(position);
|
g_map.cleanTile(position);
|
||||||
|
|
||||||
|
@ -1285,7 +1304,7 @@ void ProtocolGame::setTileDescription(const InputMessagePtr& msg, Position posit
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(stackPos >= 10)
|
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);
|
ThingPtr thing = getThing(msg);
|
||||||
g_map.addThing(thing, position, -1);
|
g_map.addThing(thing, position, -1);
|
||||||
|
@ -1326,9 +1345,8 @@ Outfit ProtocolGame::getOutfit(const InputMessagePtr& msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PROTOCOL>=870
|
if(g_game.getFeature(Otc::GamePlayerMounts))
|
||||||
msg->getU16(); // mount
|
msg->getU16(); // mount
|
||||||
#endif
|
|
||||||
|
|
||||||
return outfit;
|
return outfit;
|
||||||
}
|
}
|
||||||
|
@ -1370,16 +1388,16 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
|
||||||
uint id = msg->getU32();
|
uint id = msg->getU32();
|
||||||
|
|
||||||
int creatureType;
|
int creatureType;
|
||||||
#if PROTOCOL>=910
|
if(g_game.getFeature(Otc::GameCreatureType))
|
||||||
creatureType = msg->getU8();
|
creatureType = msg->getU8();
|
||||||
#else
|
else {
|
||||||
if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId)
|
if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId)
|
||||||
creatureType = Proto::CreatureTypePlayer;
|
creatureType = Proto::CreatureTypePlayer;
|
||||||
else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId)
|
else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId)
|
||||||
creatureType = Proto::CreatureTypeMonster;
|
creatureType = Proto::CreatureTypeMonster;
|
||||||
else
|
else
|
||||||
creatureType = Proto::CreatureTypeNpc;
|
creatureType = Proto::CreatureTypeNpc;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
std::string name = msg->getString();
|
std::string name = msg->getString();
|
||||||
|
|
||||||
|
@ -1422,12 +1440,12 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
|
||||||
int emblem = -1;
|
int emblem = -1;
|
||||||
bool passable = false;
|
bool passable = false;
|
||||||
|
|
||||||
#if PROTOCOL>=854
|
if(g_game.getFeature(Otc::GameCreatureAdditionalInfo)) {
|
||||||
if(!known)
|
if(!known)
|
||||||
emblem = msg->getU8();
|
emblem = msg->getU8();
|
||||||
|
|
||||||
passable = (msg->getU8() == 0);
|
passable = (msg->getU8() == 0);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
if(creature) {
|
if(creature) {
|
||||||
creature->setHealthPercent(healthPercent);
|
creature->setHealthPercent(healthPercent);
|
||||||
|
@ -1446,16 +1464,22 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
|
||||||
}
|
}
|
||||||
} else if(type == Proto::Creature) {
|
} else if(type == Proto::Creature) {
|
||||||
uint id = msg->getU32();
|
uint id = msg->getU32();
|
||||||
Otc::Direction direction = (Otc::Direction)msg->getU8();
|
|
||||||
#if PROTOCOL>=953
|
|
||||||
msg->getU8(); // passable
|
|
||||||
#endif
|
|
||||||
|
|
||||||
creature = g_map.getCreatureById(id);
|
creature = g_map.getCreatureById(id);
|
||||||
|
|
||||||
|
if(!creature)
|
||||||
|
logTraceError("invalid creature");
|
||||||
|
|
||||||
|
Otc::Direction direction = (Otc::Direction)msg->getU8();
|
||||||
if(creature)
|
if(creature)
|
||||||
creature->turn(direction);
|
creature->turn(direction);
|
||||||
else
|
|
||||||
logTraceError("invalid creature");
|
if(g_game.getFeature(Otc::GameCreaturePassableInfo)) {
|
||||||
|
bool passable = msg->getU8();
|
||||||
|
|
||||||
|
if(creature)
|
||||||
|
creature->setPassable(passable);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
stdext::throw_exception("invalid creature opcode");
|
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())
|
if(item->isStackable() || item->isFluidContainer() || item->isFluid())
|
||||||
item->setCountOrSubType(msg->getU8());
|
item->setCountOrSubType(msg->getU8());
|
||||||
|
|
||||||
#if PROTOCOL>=910
|
if(g_game.getFeature(Otc::GameItemAnimationPhase)) {
|
||||||
if(item->getAnimationPhases() > 1) {
|
if(item->getAnimationPhases() > 1) {
|
||||||
// 0xfe => random phase
|
// 0xfe => random phase
|
||||||
// 0xff => async?
|
// 0xff => async?
|
||||||
msg->getU8();
|
msg->getU8();
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ void ProtocolGame::sendExtendedOpcode(uint8 opcode, const std::string& buffer)
|
||||||
msg->addString(buffer);
|
msg->addString(buffer);
|
||||||
safeSend(msg);
|
safeSend(msg);
|
||||||
} else {
|
} 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?
|
msg->addU8(0); // is gm set?
|
||||||
paddingBytes -= 17;
|
paddingBytes -= 17;
|
||||||
|
|
||||||
#if PROTOCOL>=854
|
if(g_game.getFeature(Otc::GameProtocolChecksum))
|
||||||
enableChecksum();
|
enableChecksum();
|
||||||
|
|
||||||
|
if(g_game.getFeature(Otc::GameAccountNames)) {
|
||||||
msg->addString(m_accountName);
|
msg->addString(m_accountName);
|
||||||
paddingBytes -= 2 + m_accountName.length();
|
|
||||||
msg->addString(m_characterName);
|
msg->addString(m_characterName);
|
||||||
paddingBytes -= 2 + m_characterName.length();
|
|
||||||
msg->addString(m_accountPassword);
|
msg->addString(m_accountPassword);
|
||||||
paddingBytes -= 2 + m_accountPassword.length();
|
paddingBytes -= 6 + m_accountName.length() + m_characterName.length() + m_accountPassword.length();
|
||||||
|
} else {
|
||||||
msg->addU32(challangeTimestamp);
|
|
||||||
msg->addU8(challangeRandom);
|
|
||||||
paddingBytes -= 5;
|
|
||||||
#else // PROTOCOL>=810
|
|
||||||
msg->addU32(stdext::from_string<uint32>(m_accountName));
|
msg->addU32(stdext::from_string<uint32>(m_accountName));
|
||||||
msg->addString(m_characterName);
|
msg->addString(m_characterName);
|
||||||
msg->addString(m_accountPassword);
|
msg->addString(m_accountPassword);
|
||||||
|
|
||||||
paddingBytes -= 8 + m_characterName.length() + m_accountPassword.length();
|
paddingBytes -= 8 + m_characterName.length() + m_accountPassword.length();
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
if(g_game.getFeature(Otc::GameChallangeOnLogin)) {
|
||||||
|
msg->addU32(challangeTimestamp);
|
||||||
|
msg->addU8(challangeRandom);
|
||||||
|
paddingBytes -= 5;
|
||||||
|
}
|
||||||
|
|
||||||
// complete the 128 bytes for rsa encryption with zeros
|
// complete the 128 bytes for rsa encryption with zeros
|
||||||
msg->addPaddingBytes(paddingBytes);
|
msg->addPaddingBytes(paddingBytes);
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <otclient/core/thingstype.h>
|
#include <otclient/core/thingstype.h>
|
||||||
#include <otclient/core/spritemanager.h>
|
#include <otclient/core/spritemanager.h>
|
||||||
|
#include <otclient/core/game.h>
|
||||||
|
|
||||||
void ProtocolLogin::login(const std::string& host, int port, const std::string& accountName, const std::string& accountPassword)
|
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]);
|
msg->addU32(m_xteaKey[3]);
|
||||||
paddingBytes -= 16;
|
paddingBytes -= 16;
|
||||||
|
|
||||||
#if PROTOCOL>=854
|
if(g_game.getFeature(Otc::GameProtocolChecksum))
|
||||||
enableChecksum();
|
enableChecksum();
|
||||||
|
|
||||||
|
if(g_game.getFeature(Otc::GameAccountNames)) {
|
||||||
msg->addString(m_accountName);
|
msg->addString(m_accountName);
|
||||||
msg->addString(m_accountPassword);
|
msg->addString(m_accountPassword);
|
||||||
paddingBytes -= 4 + m_accountName.length() + m_accountPassword.length();
|
paddingBytes -= 4 + m_accountName.length() + m_accountPassword.length();
|
||||||
#elif PROTOCOL>=810
|
} else {
|
||||||
msg->addU32(stdext::from_string<uint32>(m_accountName));
|
msg->addU32(stdext::from_string<uint32>(m_accountName));
|
||||||
msg->addString(m_accountPassword);
|
msg->addString(m_accountPassword);
|
||||||
paddingBytes -= 6 + m_accountPassword.length();
|
paddingBytes -= 6 + m_accountPassword.length();
|
||||||
#endif
|
}
|
||||||
|
|
||||||
msg->addPaddingBytes(paddingBytes); // complete the 128 bytes for rsa encryption with zeros
|
msg->addPaddingBytes(paddingBytes); // complete the 128 bytes for rsa encryption with zeros
|
||||||
msg->encryptRSA(128, Proto::RSA);
|
msg->encryptRSA(128, Proto::RSA);
|
||||||
|
|
|
@ -72,15 +72,15 @@ void OTClient::init(const std::vector<std::string>& args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logInfo(stdext::format(
|
logInfo(
|
||||||
"%s %s (rev %s) built on %s",
|
"%s %s (rev %s) built on %s",
|
||||||
Otc::AppName,
|
Otc::AppName,
|
||||||
Otc::AppVersion,
|
Otc::AppVersion,
|
||||||
BUILD_REVISION,
|
BUILD_REVISION,
|
||||||
BUILD_DATE));
|
BUILD_DATE);
|
||||||
|
|
||||||
if(startupOptions.length() > 0)
|
if(startupOptions.length() > 0)
|
||||||
logInfo("Startup options:", startupOptions);
|
logInfo("Startup options: %s", startupOptions);
|
||||||
|
|
||||||
g_logger.setLogFile(stdext::format("%s.txt", Otc::AppCompactName));
|
g_logger.setLogFile(stdext::format("%s.txt", Otc::AppCompactName));
|
||||||
Application::init(args);
|
Application::init(args);
|
||||||
|
@ -104,7 +104,7 @@ void OTClient::init(const std::vector<std::string>& args)
|
||||||
try {
|
try {
|
||||||
g_lua.runScript("/otclientrc.lua");
|
g_lua.runScript("/otclientrc.lua");
|
||||||
} catch(LuaException& e) {
|
} catch(LuaException& e) {
|
||||||
logError("failed to load otclientrc.lua: ", e.what());
|
logError("failed to load otclientrc.lua: %s", e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue