-
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.
- Loading branch information
1 parent
c586f0a
commit 78d67a2
Showing
8 changed files
with
533 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,77 @@ | ||
#pragma once | ||
|
||
namespace RE | ||
{ | ||
namespace idLogging | ||
{ | ||
enum class Severity : std::uint8_t | ||
{ | ||
Trace = 0, | ||
Debug = 1, | ||
Info = 2, | ||
WARN = 3, | ||
ERROR = 4, | ||
FATAL = 5 | ||
}; | ||
|
||
struct ILogger | ||
{ | ||
SF_RTTI_VTABLE(idLogging__ILogger); | ||
~ILogger() = default; // 00 | ||
virtual bool ShouldLog(Severity severity) = 0; // 01 | ||
virtual void Log(const char* a_fileName, int a_line_number, Severity severity, const char* msg) = 0; // 02 | ||
void Printf(const char* a_fileName, int a_line_number, Severity severity, const char* a_fmt, ...) | ||
{ | ||
va_list args; | ||
va_start(args, a_fmt); | ||
char buffer[1064]; | ||
vsnprintf(buffer, 1024, a_fmt, args); | ||
va_end(args); | ||
Log(a_fileName, a_line_number, severity, buffer); | ||
} | ||
}; | ||
|
||
ILogger* GetLoggerSingleton(); | ||
} | ||
|
||
// in an anonymous namespace in the exe | ||
struct NetSocketLogger : public idLogging::ILogger | ||
{ | ||
SF_RTTI_VTABLE(__NetSocketLogger); | ||
~NetSocketLogger() = default; // 00 | ||
// override idLogging::ILogger | ||
bool ShouldLog([[maybe_unused]] idLogging::Severity severity) override { return false; } // 01 | ||
void Log(const char* a_fileName, int a_line_number, idLogging::Severity severity, const char* msg) override // 02 | ||
{ | ||
const char* severitystr; | ||
char outputString[1032]; | ||
switch (severity) // Trace, Debug, Info, WARN, ERROR, FATAL, UNKNOWN | ||
{ | ||
case idLogging::Severity::Trace: | ||
severitystr = "Trace"; | ||
break; | ||
case idLogging::Severity::Debug: | ||
|
||
severitystr = "Debug"; | ||
break; | ||
case idLogging::Severity::Info: | ||
severitystr = "Info"; | ||
break; | ||
case idLogging::Severity::WARN: | ||
severitystr = "WARN"; | ||
break; | ||
case idLogging::Severity::ERROR: | ||
severitystr = "ERROR"; | ||
break; | ||
case idLogging::Severity::FATAL: | ||
severitystr = "FATAL"; | ||
break; | ||
default: | ||
severitystr = "UNKNOWN"; | ||
break; | ||
} | ||
snprintf(outputString, 1024, "%s: %s - [%s (%d)]\n", severitystr, msg, a_fileName, a_line_number); | ||
WinAPI::OutputDebugString(outputString); | ||
} | ||
}; | ||
} |
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,43 @@ | ||
#pragma once | ||
|
||
namespace RE | ||
{ | ||
enum class netadrtype_t | ||
{ | ||
NA_BAD, // an address lookup failed | ||
NA_LOOPBACK, | ||
NA_BROADCAST, | ||
NA_IP | ||
}; | ||
|
||
struct netadr_t | ||
{ | ||
netadrtype_t type; // 00 | ||
std::byte ip[4]; // 04 | ||
std::uint32_t port; // 08 | ||
}; | ||
static_assert(sizeof(netadr_t) == 0xC); | ||
|
||
const char* NET_ErrorString(void); | ||
void Net_SockadrToNetadr(WinAPI::sockaddr* s, netadr_t* a); // They violated the naming convention here :( | ||
bool NET_WaitForData(std::uintptr_t socket, std::uint32_t timeoutMs); | ||
void Sys_InitNetworking(); | ||
|
||
class idTCP | ||
{ | ||
SF_RTTI_VTABLE(idTCP); | ||
|
||
virtual ~idTCP(); // 00 | ||
bool Listen(std::uint16_t port, bool blocking); // 'blocking' is ignored | ||
bool Accept(const idTCP& listener); | ||
std::int32_t Close(); | ||
std::int32_t Read(void* buffer, std::uint32_t size); | ||
std::int32_t Write(const void* buffer, std::uint32_t size, std::uint32_t timeoutMs); | ||
|
||
// members | ||
netadr_t address; // 08 | ||
std::uintptr_t socket; // 18 | ||
}; | ||
static_assert(sizeof(idTCP) == 0x20); | ||
|
||
} |
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
Oops, something went wrong.