[Debgging] Add read/write logger
- You can use the two comparison files (iw4_reads.log & zb_writes.log) to compare the two for differences - Move the hook in QuickPatches around to change the asset that you're logging
This commit is contained in:
@ -62,6 +62,14 @@ namespace Utils
|
||||
Stream::Stream() : criticalSectionState(0)
|
||||
{
|
||||
memset(this->blockSize, 0, sizeof(this->blockSize));
|
||||
#ifdef DEBUG
|
||||
|
||||
if(this->writeLog) return;
|
||||
if(fopen_s(&this->writeLog, "userraw/logs/zb_writes.log", "w"))
|
||||
{
|
||||
Components::Logger::Print("WARNING: Couldn't open write log. Writes from ZoneBuilder will not be logged.\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Stream::Stream(size_t size) : Stream()
|
||||
@ -77,6 +85,13 @@ namespace Utils
|
||||
{
|
||||
MessageBoxA(0, Utils::String::VA("Invalid critical section state '%i' for stream destruction!", this->criticalSectionState), "WARNING", MB_ICONEXCLAMATION);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if(this->writeLog)
|
||||
{
|
||||
fclose(this->writeLog);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
size_t Stream::length()
|
||||
@ -109,6 +124,9 @@ namespace Utils
|
||||
|
||||
this->buffer.append(static_cast<const char*>(_str), size * count);
|
||||
|
||||
// log the write for zonebuilder debugging
|
||||
SAVE_LOG_WRITE(size * count);
|
||||
|
||||
if (this->data() != data && this->isCriticalSection())
|
||||
{
|
||||
MessageBoxA(0, "Stream reallocation during critical operations not permitted!\nPlease increase the initial memory size or reallocate memory during non-critical sections!", "ERROR", MB_ICONERROR);
|
||||
@ -303,4 +321,38 @@ namespace Utils
|
||||
|
||||
return (this->criticalSectionState != 0);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
FILE* Stream::writeLog = nullptr;
|
||||
int Stream::structLevel = 0;
|
||||
|
||||
void Stream::enterStruct(const char* structName)
|
||||
{
|
||||
if(!this->writeLog) return;
|
||||
fprintf(this->writeLog, "%*s%s\n", this->structLevel++, "", structName);
|
||||
}
|
||||
|
||||
void Stream::leaveStruct()
|
||||
{
|
||||
if(!this->writeLog) return;
|
||||
this->structLevel--;
|
||||
|
||||
if(this->structLevel < 0) {
|
||||
Components::Logger::Print("Stream::exitStruct underflow! All following writes will not be logged!\n");
|
||||
fclose(this->writeLog);
|
||||
this->writeLog = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(this->writeLog, "%*s-----\n", this->structLevel, "");
|
||||
}
|
||||
|
||||
void Stream::logWrite(int writeLen)
|
||||
{
|
||||
if(!this->writeLog) return;
|
||||
fprintf(this->writeLog, "%*s%d\n", this->structLevel, "", writeLen);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -121,6 +121,14 @@ namespace Utils
|
||||
void leaveCriticalSection();
|
||||
bool isCriticalSection();
|
||||
|
||||
// for recording zb writes
|
||||
#ifdef DEBUG
|
||||
static FILE* writeLog;
|
||||
static int structLevel;
|
||||
void enterStruct(const char* structName);
|
||||
void leaveStruct();
|
||||
void logWrite(int writeLen);
|
||||
#endif
|
||||
|
||||
// This represents packed offset in streams:
|
||||
// - lowest 28 bits store the value/offset
|
||||
@ -143,8 +151,8 @@ namespace Utils
|
||||
Offset(Game::XFILE_BLOCK_TYPES _block, uint32_t _offset) : offset(_offset), block(_block) {};
|
||||
|
||||
// The game needs it to be incremented
|
||||
uint32_t getPackedOffset()
|
||||
{
|
||||
uint32_t getPackedOffset()
|
||||
{
|
||||
return this->packed + 1;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user