public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { string platformIdentifier = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win-x64" : "linux-x64"; assembly_context.SetCustomNativeLibraryResolver((ctx, str) => { if (str.Contains("sourcesdkc")) { Console.WriteLine("loading sourcesdkc"); sourcesdkc = NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc"); Console.WriteLine($"loaded sourcesdkc: {sourcesdkc != IntPtr.Zero}"); return(sourcesdkc); } return(IntPtr.Zero); }); Test(() => Dbg.Msg("Msg(string)\n")); Test(() => Dbg.Warning("Warning(string)\n")); Test(() => Dbg.Warning_SpewCallStack(100, "Warning_SpewCallStack(int, string)\n")); Test(() => Dbg.DevMsg("DevMsg(string)\n")); Test(() => Dbg.DevWarning("DevWarning(string)\n")); Test(() => Dbg.ConColorMsg(new Color(255, 255, 0), "ConColorMsg(in Color, string)\n")); Test(() => Dbg.ConMsg("ConMsg(string)\n")); Test(() => Dbg.ConDMsg("ConDMsg(string)\n")); // Test(() => Dbg.COM_TimestampedLog("COM_TimestampedLog(format = %s)", "COM_TimestampedLog")); Test(() => { unsafe { string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "filesystem_stdio.so"; if (!interfaceh.Sys_LoadInterface(path, FileSystem.FILESYSTEM_INTERFACE_VERSION, out IntPtr module, out IntPtr fSPtr)) { Console.WriteLine("failed loading FS"); } if (!interfaceh.Sys_LoadInterface(path, BaseFileSystem.BASEFILESYSTEM_INTERFACE_VERSION, out module, out IntPtr baseFSPtr)) { Console.WriteLine("failed loading BFS"); } if (fSPtr == IntPtr.Zero || baseFSPtr == IntPtr.Zero) { Console.WriteLine("unloading it"); NativeLibrary.Free(module); Console.WriteLine("unloaded ???"); return; } FileSystem fileSystem = new(fSPtr); BaseFileSystem baseFileSystem = new(baseFSPtr); Console.WriteLine("get tier"); Console.WriteLine(fileSystem.GetTier()); if (interfaceh.Sys_LoadInterface("vguimatsurface", ISurface.VGUI_SURFACE_INTERFACE_VERSION, out IntPtr isurfaceModule, out IntPtr isurfaceInterface)) { ISurface surface = new(isurfaceInterface); Console.WriteLine(surface.GetTier()); } fileSystem.PrintSearchPaths(); Console.WriteLine("add new path"); fileSystem.AddSearchPath("garrysmod", "GAME", SearchPathAdd_t.PATH_ADD_TO_HEAD); fileSystem.PrintSearchPaths(); IntPtr fileHandle = baseFileSystem.Open("resource/GameMenu.res", "rb", "GAME"); if (fileHandle != IntPtr.Zero) { uint size = baseFileSystem.Size(fileHandle); byte *buffPtr = stackalloc byte[(int)size]; IntPtr buffIntPtr = new(buffPtr); baseFileSystem.Read(buffIntPtr, (int)size, fileHandle); Console.WriteLine("Printing file contents"); Console.WriteLine(Encoding.UTF8.GetString(buffPtr, (int)size)); baseFileSystem.Close(fileHandle); } else { Console.WriteLine("not found file"); } } }); assembly_context.SetCustomNativeLibraryResolver(null); Debug.Assert(!failed); lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); handle = lua.PushManagedFunction(DrawSomething); lua.SetField(-2, "DrawSomethingPLSWORK"); lua.Pop(); }