-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add BSSystemFile, BSLog (#209)
- Loading branch information
1 parent
2b40bce
commit dea6da6
Showing
7 changed files
with
434 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#pragma once | ||
#include "RE/B/BSFixedString.h" | ||
#include "RE/B/BSLock.h" | ||
#include "RE/B/BSSystemFile.h" | ||
|
||
namespace RE | ||
{ | ||
class BSLog | ||
{ | ||
~BSLog(); | ||
BSLog() = delete; | ||
BSLog(const BSLog&) = delete; | ||
BSLog(BSLog&&) = delete; | ||
BSLog( | ||
const char* a_logName, | ||
const char* a_logFolderPath, | ||
bool a_timeStamped, | ||
std::uint32_t a_logNumber, | ||
std::uint32_t a_bufferSize, | ||
std::uint32_t a_blocks_allocated); | ||
|
||
void CycleLog(); | ||
void FlushBuffer(bool a_forceFlush); | ||
void FlushBufferToFile(bool a_forceFlush); | ||
void WriteEntry(const char* a_string, bool a_shouldFlush); | ||
void WriteData(char* data, std::uint32_t size, bool a_shouldFlush); | ||
|
||
static void MakeLogFilename(char* a_name, const char* a_dir, std::uint32_t a_logNumber, BSFixedString& r_fileName, bool a_appendLogNumber); | ||
static void GenerateTimeStamp(char* a_buffer); | ||
|
||
private: | ||
BSLog* ctor( | ||
const char* a_logName, | ||
const char* a_logFolderPath, | ||
bool a_timeStamped, | ||
std::uint32_t a_logNumber, | ||
std::uint32_t a_bufferSize, | ||
std::uint32_t a_blocks_allocated); | ||
void dtor(); | ||
|
||
public: | ||
// members | ||
BSFixedString logName; // 00 | ||
BSFixedString logFolderPath; // 08 | ||
uint32_t logNumber; // 10 | ||
uint32_t bytesAllocated; // 14 | ||
BSSpinLock writeLock; // 18 | ||
BSSystemFile sysfile; // 20 | ||
std::uint64_t unk30; // 30 | ||
std::uint64_t unk38; // 38 | ||
std::byte unk40[448]; // 40 -- likely a scrapheap | ||
bool isAllocated; // 200 | ||
std::uint8_t pad201; // 201 | ||
std::uint16_t pad202; // 202 | ||
std::uint32_t pad204; // 204 | ||
std::byte unk208[0x32]; // 208 | ||
int unk240; // 240 | ||
bool isInUse; // 244 | ||
bool isActive; // 245 | ||
bool timestamped; // 246 | ||
bool unk247; // 247 | ||
std::byte unk248[0x38]; // 248 | ||
}; | ||
static_assert(sizeof(BSLog) == 0x280); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#pragma once | ||
|
||
namespace RE | ||
{ | ||
class BSSystemFile | ||
{ | ||
public: | ||
enum class ErrorCode : std::uint32_t | ||
{ | ||
kOk = 0, | ||
kUnknownError = 1, | ||
kFileNotFound = 2, | ||
kAlreadyExists = 3, | ||
kPathNotFound = 4, | ||
kAccessDenied = 5, | ||
kOtherFileError = 6 | ||
}; | ||
enum class AccessMode : std::uint32_t | ||
{ | ||
kRead = 0, | ||
kReadWrite = 1, | ||
kWriteOnly = 2 | ||
}; | ||
enum class OpenMode : std::uint32_t | ||
{ | ||
kOpenExisting = 0, | ||
kOpenAlways = 1, | ||
kCreateAlways = 2, | ||
kTruncateExisting = 3, | ||
kCreateIfNotExist = 4 | ||
}; | ||
enum class ShareMode : std::uint32_t | ||
{ | ||
kExclusive = 0, | ||
kShareRead = 1, | ||
kShareWrite = 2, | ||
kShareReadWrite = 3 | ||
}; | ||
|
||
enum class SeekMode : std::uint32_t | ||
{ | ||
kBegin = 0, | ||
kCurrent = 1, | ||
kEnd = 2 | ||
}; | ||
|
||
~BSSystemFile(); | ||
BSSystemFile(); | ||
BSSystemFile( | ||
const char* a_path, | ||
AccessMode a_accessMode, | ||
OpenMode a_openMode, | ||
bool a_read, | ||
[[maybe_unused]] std::uint64_t a_unk1, | ||
bool a_write, | ||
ShareMode a_shareMode); | ||
|
||
explicit BSSystemFile(BSSystemFile& a_lhs); | ||
explicit BSSystemFile(BSSystemFile&& a_rhs); | ||
|
||
BSSystemFile& operator=(BSSystemFile& a_lhs); | ||
|
||
void Flush(); | ||
void Invalidate(); | ||
ErrorCode GetSize(std::uint64_t& r_size); | ||
ErrorCode GetErrorCode(); | ||
ErrorCode Read(void* a_buffer, std::uint64_t a_toRead, std::uint64_t& r_read); | ||
ErrorCode Seek(std::int64_t a_offset, SeekMode a_seekMode, std::uint64_t& r_newPosition); | ||
void SetErrorCode(ErrorCode a_errorCode); | ||
ErrorCode Truncate(std::uint64_t a_bytesToTruncate); | ||
ErrorCode Write(const void* a_buffer, std::uint64_t a_toWrite, std::uint64_t& r_written); | ||
|
||
static std::uint32_t RenameFile(const char* a_path, const char* a_replace); | ||
static std::uint32_t DeleteFileA(const char* a_path); | ||
|
||
private: | ||
void DoClose(); | ||
ErrorCode DoOpen(const char* a_path, AccessMode a_accessMode, OpenMode a_openMode, ShareMode a_shareMode); | ||
ErrorCode DoSeek(std::int64_t a_offset, SeekMode a_seekMode, std::uint64_t& r_newPosition); | ||
|
||
std::uint32_t flags; // 00 | ||
void* file; // 08 | ||
}; | ||
static_assert(sizeof(BSSystemFile) == 0x10); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "RE/B/BSLog.h" | ||
|
||
namespace RE | ||
{ | ||
BSLog::~BSLog() | ||
{ | ||
dtor(); | ||
} | ||
|
||
BSLog::BSLog( | ||
const char* a_logName, | ||
const char* a_logFolderPath, | ||
bool a_timeStamped, | ||
std::uint32_t a_logNumber, | ||
std::uint32_t a_bufferSize, | ||
std::uint32_t a_blocks_allocated) | ||
{ | ||
ctor(a_logName, a_logFolderPath, a_timeStamped, a_logNumber, a_bufferSize, a_blocks_allocated); | ||
} | ||
|
||
BSLog* BSLog::ctor(const char* a_logName, const char* a_logFolderPath, bool a_timeStamped, std::uint32_t a_logNumber, std::uint32_t a_bufferSize, std::uint32_t a_blocks_allocated) | ||
{ | ||
using func_t = decltype(&BSLog::ctor); | ||
REL::Relocation<func_t> func{ ID::BSLog::ctor }; | ||
return func(this, a_logName, a_logFolderPath, a_timeStamped, a_logNumber, a_bufferSize, a_blocks_allocated); | ||
} | ||
|
||
void BSLog::dtor() | ||
{ | ||
using func_t = decltype(&BSLog::dtor); | ||
REL::Relocation<func_t> func{ ID::BSLog::dtor }; | ||
return func(this); | ||
} | ||
|
||
void BSLog::CycleLog() | ||
{ | ||
using func_t = decltype(&BSLog::CycleLog); | ||
REL::Relocation<func_t> func{ ID::BSLog::CycleLog }; | ||
return func(this); | ||
} | ||
|
||
void BSLog::FlushBuffer(bool forceFlush) | ||
{ | ||
using func_t = decltype(&BSLog::FlushBuffer); | ||
REL::Relocation<func_t> func{ ID::BSLog::FlushBuffer }; | ||
return func(this, forceFlush); | ||
} | ||
|
||
void BSLog::FlushBufferToFile(bool forceFlush) | ||
{ | ||
using func_t = decltype(&BSLog::FlushBufferToFile); | ||
REL::Relocation<func_t> func{ ID::BSLog::FlushBufferToFile }; | ||
return func(this, forceFlush); | ||
} | ||
|
||
void BSLog::WriteEntry(const char* a_string, bool shouldFlush) | ||
{ | ||
using func_t = decltype(&BSLog::WriteEntry); | ||
REL::Relocation<func_t> func{ ID::BSLog::WriteEntry }; | ||
return func(this, a_string, shouldFlush); | ||
} | ||
|
||
void BSLog::WriteData(char* data, std::uint32_t size, bool shouldFlush) | ||
{ | ||
using func_t = decltype(&BSLog::WriteData); | ||
REL::Relocation<func_t> func{ ID::BSLog::WriteData }; | ||
return func(this, data, size, shouldFlush); | ||
} | ||
|
||
void BSLog::MakeLogFilename(char* a_name, const char* a_dir, std::uint32_t a_logNumber, BSFixedString& r_fileName, bool a_appendLogNumber) | ||
{ | ||
using func_t = decltype(&BSLog::MakeLogFilename); | ||
REL::Relocation<func_t> func{ ID::BSLog::MakeLogFilename }; | ||
return func(a_name, a_dir, a_logNumber, r_fileName, a_appendLogNumber); | ||
} | ||
|
||
void BSLog::GenerateTimeStamp(char* a_buffer) | ||
{ | ||
using func_t = decltype(&BSLog::GenerateTimeStamp); | ||
REL::Relocation<func_t> func{ ID::BSLog::GenerateTimeStamp }; | ||
return func(a_buffer); | ||
} | ||
|
||
} |
Oops, something went wrong.