Logger improvements

This commit is contained in:
Diavolo 2022-04-16 10:01:25 +02:00
parent 5f5f082fdf
commit f71946a56b
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
3 changed files with 10 additions and 12 deletions

View File

@ -28,7 +28,7 @@ namespace Components
if (!rawfile || Game::DB_IsXAssetDefault(Game::XAssetType::ASSET_TYPE_RAWFILE, this->filePath.data())) return; if (!rawfile || Game::DB_IsXAssetDefault(Game::XAssetType::ASSET_TYPE_RAWFILE, this->filePath.data())) return;
this->buffer.resize(Game::DB_GetRawFileLen(rawfile)); this->buffer.resize(Game::DB_GetRawFileLen(rawfile));
Game::DB_GetRawBuffer(rawfile, const_cast<char*>(this->buffer.data()), this->buffer.size()); Game::DB_GetRawBuffer(rawfile, this->buffer.data(), static_cast<int>(this->buffer.size()));
} }
FileSystem::FileReader::FileReader(const std::string& file) : handle(0), name(file) FileSystem::FileReader::FileReader(const std::string& file) : handle(0), name(file)

View File

@ -77,16 +77,14 @@ namespace Components
std::string Logger::Format(const char** message) std::string Logger::Format(const char** message)
{ {
const size_t bufferSize = 0x10000; char buffer[4096] = {0};
Utils::Memory::Allocator allocator;
char* buffer = allocator.allocateArray<char>(bufferSize);
va_list ap = reinterpret_cast<char*>(const_cast<char**>(&message[1])); va_list ap = reinterpret_cast<char*>(const_cast<char**>(&message[1]));
//va_start(ap, *message);
_vsnprintf_s(buffer, bufferSize, bufferSize, *message, ap); _vsnprintf_s(buffer, _TRUNCATE, *message, ap);
va_end(ap); va_end(ap);
return buffer; return {buffer};
} }
void Logger::Flush() void Logger::Flush()
@ -138,8 +136,8 @@ namespace Components
{ {
if (!data) return; if (!data) return;
std::string buffer(data); const std::string buffer(data);
for (auto& addr : Logger::LoggingAddresses[gLog & 1]) for (const auto& addr : Logger::LoggingAddresses[gLog & 1])
{ {
Network::SendCommand(addr, "print", buffer); Network::SendCommand(addr, "print", buffer);
} }
@ -373,9 +371,9 @@ namespace Components
Logger::MessageMutex.unlock(); Logger::MessageMutex.unlock();
// Flush the console log // Flush the console log
if (int fh = *reinterpret_cast<int*>(0x1AD8F28)) if (const auto logfile = *reinterpret_cast<int*>(0x1AD8F28))
{ {
Game::FS_FCloseFile(fh); Game::FS_FCloseFile(logfile);
} }
} }
} }

View File

@ -329,7 +329,7 @@ namespace Game
typedef int(__cdecl * FS_FOpenFileReadForThread_t)(const char *filename, int *file, int thread); typedef int(__cdecl * FS_FOpenFileReadForThread_t)(const char *filename, int *file, int thread);
extern FS_FOpenFileReadForThread_t FS_FOpenFileReadForThread; extern FS_FOpenFileReadForThread_t FS_FOpenFileReadForThread;
typedef int(__cdecl * FS_FCloseFile_t)(int fh); typedef int(__cdecl * FS_FCloseFile_t)(int stream);
extern FS_FCloseFile_t FS_FCloseFile; extern FS_FCloseFile_t FS_FCloseFile;
typedef bool(__cdecl * FS_FileExists_t)(const char* file); typedef bool(__cdecl * FS_FileExists_t)(const char* file);