Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Backend/Debug/DebugBackend.bf
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ namespace RfgNetworking.Backend.Debug
SteamControllerWrapper.Init(steamApiContext.Controller, steamApiContext.Controller.Vtable);
steamApiContext.Controller = &SteamControllerWrapper;
}
Logger.Write(scope $"SW_CCSys_DynamicInit(CallbackCounterAndContext* callbackCounterAndContext: 0x{(int)(void*)callbackCounterAndContext:X})");
Logger.Write(scope $" -> CSteamAPIContext*(0x{(int)(void*)steamApiContext:X})");
Logger.WriteLine(scope $"SW_CCSys_DynamicInit(CallbackCounterAndContext* callbackCounterAndContext: 0x{(int)(void*)callbackCounterAndContext:X})");
Logger.WriteLine(scope $" -> CSteamAPIContext*(0x{(int)(void*)steamApiContext:X})");
Logger.Flush();
Logger.WriteLine("");
}
Expand Down
77 changes: 59 additions & 18 deletions src/Misc/Logger.bf
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,81 @@ namespace RfgNetworking.Misc
{
public static bool AutoFlush = true;

private static FileStream _fileStream;
private static StreamWriter _streamWriter = null;
private static Windows.FileHandle handle;

public static void Init()
{
_fileStream = new .();
_fileStream.Open("_RfgNetworkApiWrapper.log", FileMode.Create, .Write, .Read);
_streamWriter = new .(_fileStream, .UTF8, 4096, false);
var name = "_RfgNetworkApiWrapper.log";
handle = Windows.SafeCreateFile(name, Windows.GENERIC_WRITE, FileShare.ReadWrite, null, FileMode.OpenOrCreate, 128, Windows.Handle.NullHandle);
}

public static void Shutdown()
{
_streamWriter.WriteLine("\n********************");
_streamWriter.WriteLine("Log closed!");
_streamWriter.WriteLine("********************");
delete _streamWriter;
delete _fileStream;
WriteLine("********************");
WriteLine("Log closed");
WriteLine("********************");

}

private static void DumbFormat(String s, RfgNetworking.Win32.SystemTime* t){
var sMonth = scope String();
t.Month.ToString(sMonth);
if(sMonth.Length == 1){
sMonth.Insert(0, "0");
}
var sDay= scope String();
t.Day.ToString(sDay);
if(sDay.Length == 1){
sDay.Insert(0, "0");
}
var sHour= scope String();
t.Hour.ToString(sHour);
if(sHour.Length == 1){
sHour.Insert(0, "0");
}
var sMinute= scope String();
t.Minute.ToString(sMinute);
if(sMinute.Length == 1){
sMinute.Insert(0, "0");
}
var sSecond= scope String();
t.Second.ToString(sSecond);
if(sSecond.Length == 1){
sSecond.Insert(0, "0");
}

s.AppendF("{}-{}-{}-{}:{}:{}", t.Year, sMonth, sDay, sHour, sMinute, sSecond);
return;
}

public static void WriteLine(StringView fmt, params Object[] args)
{
_streamWriter.WriteLine(fmt, params args);
if (AutoFlush)
_streamWriter.Flush();
}
//var d = scope String();
//var c = new System.Globalization.CultureInfo("en-US");
//System.Globalization.CultureInfo.mDefaultCultureInfo = c;
//System.Globalization.CultureInfo.CurrentCulture = c;
//System.Globalization.CultureInfo.[Friend]sUserDefaultCulture = c;

public static void Write(StringView fmt, params Object[] args)
{
_streamWriter.Write(fmt, params args);

var t = new RfgNetworking.Win32.SystemTime();
RfgNetworking.Win32.Win32.GetLocalTime(t);
var str = scope String();
var time = scope String();
DumbFormat(time, t);
str.AppendF("[{}][sw_api] ", time);
str.AppendF(fmt, args);
str.Append("\n");
var strPtr = (char8*)str;
var ptr = (uint8*)strPtr;

int32 x = 0;
Windows.SetFilePointer(handle, 0, null, Windows.FILE_END);
Windows.WriteFile(handle, ptr, str.Length, out x, null);
}

public static void Flush()
{
_streamWriter.Flush();
}
}
}
15 changes: 15 additions & 0 deletions src/Win32/Memory.bf
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,20 @@ namespace RfgNetworking.Win32
{
[Import("kernel32.lib"), CLink, CallingConvention(.Stdcall)]
public static extern BOOL VirtualProtect(void* lpAddress, uint dwSize, PAGE_PROTECTION_FLAGS flNewProtect, out PAGE_PROTECTION_FLAGS lpflOldProtect);

[Import("kernel32.lib"), CLink, CallingConvention(.Stdcall)]
public static extern void GetLocalTime(SystemTime* lpSystemTime);
}

[CRepr]
public struct SystemTime{
public uint16 Year;
public uint16 Month;
public uint16 DayOfWeek;
public uint16 Day;
public uint16 Hour;
public uint16 Minute;
public uint16 Second;
public uint16 Milliseconds;
}
}