Merge pull request #226 from diamante0018/logger

Logger improvements
This commit is contained in:
Dss0 2022-04-16 14:58:58 +02:00 committed by GitHub
commit f737b1be58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
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)

View File

@ -77,16 +77,14 @@ namespace Components
std::string Logger::Format(const char** message)
{
const size_t bufferSize = 0x10000;
Utils::Memory::Allocator allocator;
char* buffer = allocator.allocateArray<char>(bufferSize);
char buffer[4096] = {0};
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);
return buffer;
return {buffer};
}
void Logger::Flush()
@ -138,8 +136,8 @@ namespace Components
{
if (!data) return;
std::string buffer(data);
for (auto& addr : Logger::LoggingAddresses[gLog & 1])
const std::string buffer(data);
for (const auto& addr : Logger::LoggingAddresses[gLog & 1])
{
Network::SendCommand(addr, "print", buffer);
}
@ -373,9 +371,9 @@ namespace Components
Logger::MessageMutex.unlock();
// 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

@ -341,7 +341,7 @@ namespace Game
typedef int(__cdecl * FS_FOpenFileReadForThread_t)(const char *filename, int *file, int thread);
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;
typedef bool(__cdecl * FS_FileExists_t)(const char* file);