From 7e34556d36be9401b76ac0edd99967b99dcffa76 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 10:07:32 +0500 Subject: [PATCH 001/235] Color.h partial dbg.h Solution Project .editorconfig .gitignore --- .editorconfig | 11 ++++ .gitignore | 3 + SourceSDK.sln | 43 ++++++++++++++ SourceSDK/SourceSDK.csproj | 7 +++ SourceSDK/src/Color.cs | 49 +++++++++++++++ SourceSDK/src/tier0/dbg.cs | 119 +++++++++++++++++++++++++++++++++++++ 6 files changed, 232 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 SourceSDK.sln create mode 100644 SourceSDK/SourceSDK.csproj create mode 100644 SourceSDK/src/Color.cs create mode 100644 SourceSDK/src/tier0/dbg.cs diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..df19f33 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +[*] +end_of_line = crlf +charset = utf-8 +indent_style = tab +indent_size = tab +trim_trailing_whitespace = true +insert_final_newline = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac16142 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vs +bin +obj diff --git a/SourceSDK.sln b/SourceSDK.sln new file mode 100644 index 0000000..870a9ed --- /dev/null +++ b/SourceSDK.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30914.41 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceSDK", "SourceSDK\SourceSDK.csproj", "{D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B1D17ED4-01E4-43C6-A8B2-EDF2BF351349}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + .gitignore = .gitignore + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|x64.ActiveCfg = Debug|Any CPU + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|x64.Build.0 = Debug|Any CPU + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|x86.ActiveCfg = Debug|Any CPU + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|x86.Build.0 = Debug|Any CPU + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|Any CPU.Build.0 = Release|Any CPU + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|x64.ActiveCfg = Release|Any CPU + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|x64.Build.0 = Release|Any CPU + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|x86.ActiveCfg = Release|Any CPU + {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BF1CCF79-0F81-4BF5-AB82-F21D369099C3} + EndGlobalSection +EndGlobal diff --git a/SourceSDK/SourceSDK.csproj b/SourceSDK/SourceSDK.csproj new file mode 100644 index 0000000..f208d30 --- /dev/null +++ b/SourceSDK/SourceSDK.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/SourceSDK/src/Color.cs b/SourceSDK/src/Color.cs new file mode 100644 index 0000000..00df08a --- /dev/null +++ b/SourceSDK/src/Color.cs @@ -0,0 +1,49 @@ +using System.Runtime.InteropServices; + +namespace SourceSDK +{ + /// + /// Color struct + /// + /// + /// Tier0.Dbg.ConColorMsg(new Color(255, 0, 255), "message\n"); + /// + /// + /// "public/Color.h" + /// + public struct Color + { + /// + /// Red + /// + [MarshalAs(UnmanagedType.U1)] + public byte r; + /// + /// Green + /// + [MarshalAs(UnmanagedType.U1)] + public byte g; + /// + /// Blue + /// + [MarshalAs(UnmanagedType.U1)] + public byte b; + /// + /// Alpha + /// + [MarshalAs(UnmanagedType.U1)] + public byte a; + + /// Red + /// Green + /// Blue + /// Alpha + public Color(byte r, byte g, byte b, byte a = 255) + { + this.r = r; + this.g = g; + this.b = b; + this.a = a; + } + } +} diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs new file mode 100644 index 0000000..dcc189d --- /dev/null +++ b/SourceSDK/src/tier0/dbg.cs @@ -0,0 +1,119 @@ +using System.Runtime.InteropServices; + +namespace SourceSDK.Tier0 +{ + /// + /// "public/tier0/dbg.h" + /// + class Dbg + { + #region + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void Msg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void DMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string groupName, int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void MsgV([MarshalAs(UnmanagedType.LPUTF8Str)] string msg, System.ArgIterator arglist); + #endregion + #region + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void Warning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void DWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string groupName, int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void WarningV([MarshalAs(UnmanagedType.LPUTF8Str)] string msg, System.ArgIterator arglist); + #endregion + #region + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void Log([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void DLog([MarshalAs(UnmanagedType.LPUTF8Str)] string groupName, int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void LogV([MarshalAs(UnmanagedType.LPUTF8Str)] string msg, System.ArgIterator arglist); + #endregion + #region + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void Error([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void ErrorV([MarshalAs(UnmanagedType.LPUTF8Str)] string msg, System.ArgIterator arglist); + #endregion + #region + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevMsg(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevWarning(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevLog(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + + [DllImport("tier0", EntryPoint = "?DevMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", EntryPoint = "?DevWarning@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", EntryPoint = "?DevLog@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevLog([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConColorMsg(int level, in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConMsg(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConWarning(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConLog(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + + [DllImport("tier0", EntryPoint = "?ConColorMsg@@YAXAEBVColor@@PEBDZZ", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", EntryPoint = "?ConMsg@@YAXPBDZZ", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConLog([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConDColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConDMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConDWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConDLog([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void NetMsg(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void NetWarning(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void NetLog(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + #endregion + } +} From ec0dcfe3f4bc44ad317c59794dd81b838a1e6a2c Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 10:10:13 +0500 Subject: [PATCH 002/235] remove x86, x64 target platforms (use Any CPU) --- SourceSDK.sln | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/SourceSDK.sln b/SourceSDK.sln index 870a9ed..21269fc 100644 --- a/SourceSDK.sln +++ b/SourceSDK.sln @@ -14,25 +14,13 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|x64.ActiveCfg = Debug|Any CPU - {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|x64.Build.0 = Debug|Any CPU - {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|x86.ActiveCfg = Debug|Any CPU - {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|x86.Build.0 = Debug|Any CPU {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|Any CPU.ActiveCfg = Release|Any CPU {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|Any CPU.Build.0 = Release|Any CPU - {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|x64.ActiveCfg = Release|Any CPU - {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|x64.Build.0 = Release|Any CPU - {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|x86.ActiveCfg = Release|Any CPU - {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 503cf7c867a0f7c2744091ae11122a1fbc6d04a2 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 10:13:05 +0500 Subject: [PATCH 003/235] add COM_TimestampedLog --- SourceSDK/src/tier0/dbg.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs index dcc189d..0ebf216 100644 --- a/SourceSDK/src/tier0/dbg.cs +++ b/SourceSDK/src/tier0/dbg.cs @@ -114,6 +114,11 @@ class Dbg [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void NetLog(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + // TODO: ValidateSpew + #endregion + + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void COM_TimestampedLog([MarshalAs(UnmanagedType.LPUTF8Str)] string fmt); } } From 8ce7a2fe1e3e2da5bc2d3b889b9324872576e92a Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 10:30:30 +0500 Subject: [PATCH 004/235] ci test.lua SourceSDK.Test change visibility of Dbg to public change from net5.0 to net5 --- .github/workflows/build.yml | 100 +++++++++++++++++++++++++++ .github/workflows/test.lua | 17 +++++ SourceSDK.Test/SourceSDK.Test.csproj | 12 ++++ SourceSDK.Test/TestModule.cs | 23 ++++++ SourceSDK.Test/nuget.config | 8 +++ SourceSDK.sln | 8 +++ SourceSDK/SourceSDK.csproj | 8 +-- SourceSDK/src/tier0/dbg.cs | 2 +- 8 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/test.lua create mode 100644 SourceSDK.Test/SourceSDK.Test.csproj create mode 100644 SourceSDK.Test/TestModule.cs create mode 100644 SourceSDK.Test/nuget.config diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..04220fc --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,100 @@ +name: Build & Test +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] +jobs: + linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.100 + - name: Restore solution + run: dotnet restore SourceSDK.sln + - name: Install Steam and Garry's Mod Dedicated Server + run: | + wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz + tar -xvzf steamcmd_linux.tar.gz + rm -rfv steamcmd_linux.tar.gz + ./steamcmd.sh +login anonymous +force_install_dir gmod "+app_update 4020 -beta x86-64 validate" +quit + - name: Install GmodDotNet + run: | + wget https://gleb-krasilich.fra1.digitaloceanspaces.com/GmodNETStorage/storage/gmod-dot-net-linux.0.7.0-beta.2.30293992.master.tar.gz -O gmoddotnet.tar.gz + mkdir ./gmod/garrysmod/lua/bin + tar -xvzf gmoddotnet.tar.gz -C ./gmod/garrysmod/lua/bin + rm -rfv gmoddotnet.tar.gz + - name: Build Module + run: dotnet publish HashCalc/HashCalc.csproj --configuration Release --framework net5 -o ./gmod/garrysmod/lua/bin/Modules/HashCalc + - name: Copy test.lua + run: cp .github/workflows/test.lua ./gmod/garrysmod/lua/autorun + - name: Run Garry's Mod + run: ./srcds_run_x64 -game garrysmod -systemtest -condebug +sv_hibernate_think 1 || true + working-directory: ./gmod/ + timeout-minutes: 1 + continue-on-error: true + - name: Print log + run: cat gmod/garrysmod/console.log + - name: Tests successfull? + uses: andstor/file-existence-action@v1 + with: + files: "gmod/garrysmod/data/success.txt" + allow_failure: true + windows-build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core SDK + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.100 + - name: Restore solution + run: dotnet restore SourceSDK.sln + - name: Install Steam and Garry's Mod Dedicated Server + shell: bash + run: | + curl https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip -O -L + powershell -Command 'Expand-Archive -LiteralPath ./steamcmd.zip -DestinationPath ./' + ./steamcmd.exe +login anonymous +force_install_dir gmod "+app_update 4020 -beta x86-64 validate" +quit || true + - name: Install GmodDotNet + shell: bash + run: | + curl -o gmoddotnet.zip https://gleb-krasilich.fra1.digitaloceanspaces.com/GmodNETStorage/storage/gmod-dot-net-windows.0.7.0-beta.2.30293992.master.zip -O -L + mkdir ./gmod/garrysmod/lua/bin + powershell -Command 'Expand-Archive -LiteralPath ./gmoddotnet.zip -DestinationPath ./gmod/garrysmod/lua/bin' + - name: Build Solution + run: dotnet publish SourceSDK.sln + - name: Build Module + run: dotnet publish SourceSDK.Test/SourceSDK.Test.csproj --configuration Release --framework net5 -o ./gmod/garrysmod/lua/bin/Modules/SourceSDKTest + - name: Copy test.lua + run: cp .github/workflows/test.lua ./gmod/garrysmod/lua/autorun + - name: Run Garry's Mod + shell: bash + run: | + powershell -Command './gmod/srcds_win64.exe -console -systemtest -condebug -game "garrysmod" +exec "server.cfg" +gamemode sandbox +map gm_construct +maxplayers 16 +sv_hibernate_think 1' + powershell -Command 'Wait-Process -Name srcds_win64' + continue-on-error: true + - name: Print log + shell: bash + run: cat gmod/garrysmod/console.log + - name: Tests successfull? + id: check_files + uses: andstor/file-existence-action@v1 + with: + files: "gmod/garrysmod/data/success.txt" + allow_failure: true + macos-build: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.100 + - name: Restore solution + run: dotnet restore SourceSDK.sln + - name: Build Solution + run: dotnet publish SourceSDK.sln --configuration Release --framework net5 diff --git a/.github/workflows/test.lua b/.github/workflows/test.lua new file mode 100644 index 0000000..f59feb6 --- /dev/null +++ b/.github/workflows/test.lua @@ -0,0 +1,17 @@ +hook.Add("Tick", "CloseServer", engine.CloseServer) +require("dotnet") + +local function run_test() + local module_loaded = dotnet.load("SourceSDKTest") + assert(module_loaded) + + -- uhm + + local module_unloaded = dotnet.unload("SourceSDKTest") + assert(module_unloaded) +end + +run_test() + +print("tests are successful!") +file.Write("success.txt", "done") diff --git a/SourceSDK.Test/SourceSDK.Test.csproj b/SourceSDK.Test/SourceSDK.Test.csproj new file mode 100644 index 0000000..230ba3f --- /dev/null +++ b/SourceSDK.Test/SourceSDK.Test.csproj @@ -0,0 +1,12 @@ + + + net5 + SourceSDKTest + + + + + + + + diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs new file mode 100644 index 0000000..8a40e71 --- /dev/null +++ b/SourceSDK.Test/TestModule.cs @@ -0,0 +1,23 @@ +using GmodNET.API; +using SourceSDK; +using SourceSDK.Tier0; + +namespace SourceSDKTest +{ + public class TestModule : IModule + { + public string ModuleName => "SourceSDKTest"; + + public string ModuleVersion => "0.0.1"; + + public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) + { + Dbg.ConColorMsg(new Color(255, 255, 0), "ConColorMsg(in Color, string)\n"); + } + + public void Unload(ILua lua) + { + + } + } +} diff --git a/SourceSDK.Test/nuget.config b/SourceSDK.Test/nuget.config new file mode 100644 index 0000000..d0286a3 --- /dev/null +++ b/SourceSDK.Test/nuget.config @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/SourceSDK.sln b/SourceSDK.sln index 21269fc..31c3631 100644 --- a/SourceSDK.sln +++ b/SourceSDK.sln @@ -9,8 +9,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig .gitignore = .gitignore + .github\workflows\build.yml = .github\workflows\build.yml + .github\workflows\test.lua = .github\workflows\test.lua EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceSDK.Test", "SourceSDK.Test\SourceSDK.Test.csproj", "{FA6CC35B-83AD-4FA7-9BFD-B77A6DAE735B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +25,10 @@ Global {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Debug|Any CPU.Build.0 = Debug|Any CPU {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|Any CPU.ActiveCfg = Release|Any CPU {D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}.Release|Any CPU.Build.0 = Release|Any CPU + {FA6CC35B-83AD-4FA7-9BFD-B77A6DAE735B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA6CC35B-83AD-4FA7-9BFD-B77A6DAE735B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA6CC35B-83AD-4FA7-9BFD-B77A6DAE735B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA6CC35B-83AD-4FA7-9BFD-B77A6DAE735B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SourceSDK/SourceSDK.csproj b/SourceSDK/SourceSDK.csproj index f208d30..99301e6 100644 --- a/SourceSDK/SourceSDK.csproj +++ b/SourceSDK/SourceSDK.csproj @@ -1,7 +1,5 @@ - - - net5.0 - - + + net5 + diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs index 0ebf216..d3bfa46 100644 --- a/SourceSDK/src/tier0/dbg.cs +++ b/SourceSDK/src/tier0/dbg.cs @@ -5,7 +5,7 @@ namespace SourceSDK.Tier0 /// /// "public/tier0/dbg.h" /// - class Dbg + public class Dbg { #region [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] From 6746f8f868b6b4998a5a38e8113fcad1afe9c253 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 10:34:34 +0500 Subject: [PATCH 005/235] fix linux Build Module step --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 04220fc..6074330 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,7 +28,7 @@ jobs: tar -xvzf gmoddotnet.tar.gz -C ./gmod/garrysmod/lua/bin rm -rfv gmoddotnet.tar.gz - name: Build Module - run: dotnet publish HashCalc/HashCalc.csproj --configuration Release --framework net5 -o ./gmod/garrysmod/lua/bin/Modules/HashCalc + run: dotnet publish SourceSDK.Test/SourceSDK.Test.csproj --configuration Release --framework net5 -o ./gmod/garrysmod/lua/bin/Modules/SourceSDKTest - name: Copy test.lua run: cp .github/workflows/test.lua ./gmod/garrysmod/lua/autorun - name: Run Garry's Mod From 42994ce1e278700db2966508ef8643ed1b553322 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 11:57:45 +0500 Subject: [PATCH 006/235] platform based entry points --- SourceSDK/src/tier0/dbg.cs | 50 +++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs index d3bfa46..cb2581e 100644 --- a/SourceSDK/src/tier0/dbg.cs +++ b/SourceSDK/src/tier0/dbg.cs @@ -1,3 +1,5 @@ +using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace SourceSDK.Tier0 @@ -7,6 +9,46 @@ namespace SourceSDK.Tier0 /// public class Dbg { + static Dbg() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + ConColorMsg_Color_string_delegate = Windows.ConColorMsg; + }else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + ConColorMsg_Color_string_delegate = Linux.ConColorMsg; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + ConColorMsg_Color_string_delegate = OSX.ConColorMsg; + } + } + + internal class Windows + { + [DllImport("tier0", EntryPoint = "?ConColorMsg@@YAXAEBVColor@@PEBDZZ", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + } + internal class Linux + { + [DllImport("tier0", EntryPoint = "ConColorMsg", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + } + internal class OSX + { + [DllImport("tier0", EntryPoint = "empty", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + } + + internal class Delegates + { + internal delegate void void_string(string str); + internal delegate void void_inColor_string(in Color clr, string msg); + } + + internal static Delegates.void_inColor_string ConColorMsg_Color_string_delegate; + + #region [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Msg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); @@ -78,9 +120,11 @@ public class Dbg [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void ConLog(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", EntryPoint = "?ConColorMsg@@YAXAEBVColor@@PEBDZZ", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg) + { + ConColorMsg_Color_string_delegate(clr, msg); + } [DllImport("tier0", EntryPoint = "?ConMsg@@YAXPBDZZ", CallingConvention = CallingConvention.Cdecl)] public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); From 4c1a4b98e55c7466aa6192d6f86de36a8ca6e6e0 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 12:00:35 +0500 Subject: [PATCH 007/235] update entry point for linux --- SourceSDK/src/tier0/dbg.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs index cb2581e..ec4c9c6 100644 --- a/SourceSDK/src/tier0/dbg.cs +++ b/SourceSDK/src/tier0/dbg.cs @@ -31,7 +31,7 @@ internal class Windows } internal class Linux { - [DllImport("tier0", EntryPoint = "ConColorMsg", CallingConvention = CallingConvention.Cdecl)] + [DllImport("tier0", EntryPoint = "_Z11ConColorMsgRK5ColorPKcz", CallingConvention = CallingConvention.Cdecl)] public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); } internal class OSX From b07dc7cad30d8819cfe854f25ed930e6708248bc Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 13:01:58 +0500 Subject: [PATCH 008/235] test ConColorMsg(int, in Color, string) --- SourceSDK.Test/TestModule.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 8a40e71..e8ca84a 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -13,6 +13,7 @@ public class TestModule : IModule public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { Dbg.ConColorMsg(new Color(255, 255, 0), "ConColorMsg(in Color, string)\n"); + Dbg.ConColorMsg(0, new Color(255, 0, 0), "ConColorMsg(int, in Color, string)\n"); } public void Unload(ILua lua) From eca89c59b623eb1c65c3df1959fc8ba547690c1a Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 13:02:37 +0500 Subject: [PATCH 009/235] osx ci change --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6074330..a3477f1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -97,4 +97,4 @@ jobs: - name: Restore solution run: dotnet restore SourceSDK.sln - name: Build Solution - run: dotnet publish SourceSDK.sln --configuration Release --framework net5 + run: dotnet publish SourceSDK.sln From 9d1d5527f89f0fcdce005cfd4a3ba39a03642f90 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 19:18:28 +0500 Subject: [PATCH 010/235] many changes --- SourceSDK.Test/TestModule.cs | 33 ++++++++++++- SourceSDK/src/tier0/dbg.cs | 93 +++++++----------------------------- 2 files changed, 47 insertions(+), 79 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index e8ca84a..0d53694 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -1,6 +1,7 @@ using GmodNET.API; using SourceSDK; using SourceSDK.Tier0; +using System; namespace SourceSDKTest { @@ -10,10 +11,38 @@ public class TestModule : IModule public string ModuleVersion => "0.0.1"; + internal void Test(Action action) + { + try + { + action(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { - Dbg.ConColorMsg(new Color(255, 255, 0), "ConColorMsg(in Color, string)\n"); - Dbg.ConColorMsg(0, new Color(255, 0, 0), "ConColorMsg(int, in Color, string)\n"); + Test(() => Dbg.Msg("Msg(string)\n")); + Test(() => Dbg.DMsg("group", 0, "DMsg(string, int, string)\n")); + + Test(() => Dbg.Warning("Warning(string)\n")); + Test(() => Dbg.DWarning("group", 0, "DWarning(string, int, string)\n")); + + Test(() => Dbg.Error("Error(string)\n")); + + Test(() => { Dbg.DevMsg("DevMsg(string)\n"); }); + Test(() => { Dbg.DevWarning("DevWarning(string)\n"); }); + Test(() => { Dbg.DevLog("DevLog(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("%s", "COM_TimestampedLog"); }); } public void Unload(ILua lua) diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs index ec4c9c6..975cc92 100644 --- a/SourceSDK/src/tier0/dbg.cs +++ b/SourceSDK/src/tier0/dbg.cs @@ -13,14 +13,15 @@ static Dbg() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - ConColorMsg_Color_string_delegate = Windows.ConColorMsg; - }else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + ConColorMsg = Windows.ConColorMsg; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - ConColorMsg_Color_string_delegate = Linux.ConColorMsg; + ConColorMsg = Linux.ConColorMsg; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - ConColorMsg_Color_string_delegate = OSX.ConColorMsg; + ConColorMsg = OSX.ConColorMsg; } } @@ -36,67 +37,46 @@ internal class Linux } internal class OSX { - [DllImport("tier0", EntryPoint = "empty", CallingConvention = CallingConvention.Cdecl)] + [DllImport("tier0", EntryPoint = "todo", CallingConvention = CallingConvention.Cdecl)] public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); } - internal class Delegates + public static class Delegates { - internal delegate void void_string(string str); - internal delegate void void_inColor_string(in Color clr, string msg); + public delegate void void_string(string str); + public delegate void void_inColor_string(in Color clr, string msg); } - internal static Delegates.void_inColor_string ConColorMsg_Color_string_delegate; #region + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Msg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void DMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string groupName, int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void MsgV([MarshalAs(UnmanagedType.LPUTF8Str)] string msg, System.ArgIterator arglist); #endregion + #region + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Warning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void DWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string groupName, int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void WarningV([MarshalAs(UnmanagedType.LPUTF8Str)] string msg, System.ArgIterator arglist); #endregion - #region - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void Log([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void DLog([MarshalAs(UnmanagedType.LPUTF8Str)] string groupName, int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void LogV([MarshalAs(UnmanagedType.LPUTF8Str)] string msg, System.ArgIterator arglist); - #endregion #region + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Error([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ErrorV([MarshalAs(UnmanagedType.LPUTF8Str)] string msg, System.ArgIterator arglist); #endregion - #region - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevMsg(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevWarning(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevLog(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + #region [DllImport("tier0", EntryPoint = "?DevMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); @@ -108,61 +88,20 @@ internal class Delegates public static extern void DevLog([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConColorMsg(int level, in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + public static Delegates.void_inColor_string ConColorMsg; - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConMsg(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConWarning(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConLog(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg) - { - ConColorMsg_Color_string_delegate(clr, msg); - } [DllImport("tier0", EntryPoint = "?ConMsg@@YAXPBDZZ", CallingConvention = CallingConvention.Cdecl)] public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConLog([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConDColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void ConDMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConDWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConDLog([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void NetMsg(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void NetWarning(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void NetLog(int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - // TODO: ValidateSpew #endregion [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void COM_TimestampedLog([MarshalAs(UnmanagedType.LPUTF8Str)] string fmt); + public static extern void COM_TimestampedLog([MarshalAs(UnmanagedType.LPUTF8Str)] string fmt, params string[] dotdotdot); } } From d9fb93213cbd108c791ec11bc6c6d9feb8fe61d4 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 19:19:56 +0500 Subject: [PATCH 011/235] failed --- SourceSDK.Test/TestModule.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 0d53694..ae8fa8f 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -2,6 +2,7 @@ using SourceSDK; using SourceSDK.Tier0; using System; +using System.Diagnostics; namespace SourceSDKTest { @@ -11,6 +12,7 @@ public class TestModule : IModule public string ModuleVersion => "0.0.1"; + private bool failed; internal void Test(Action action) { try @@ -20,6 +22,7 @@ internal void Test(Action action) catch (Exception e) { Console.WriteLine(e); + failed = true; } } @@ -43,6 +46,8 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { Dbg.ConDMsg("ConDMsg(string)\n"); }); Test(() => { Dbg.COM_TimestampedLog("%s", "COM_TimestampedLog"); }); + + Debug.Assert(!failed); } public void Unload(ILua lua) From 2d12f4ce09cf49a4b87a5b748b330ef2e01400e7 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 19:26:27 +0500 Subject: [PATCH 012/235] remove DMsg, DWarning --- SourceSDK.Test/TestModule.cs | 2 -- SourceSDK/src/tier0/dbg.cs | 14 -------------- 2 files changed, 16 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index ae8fa8f..4a26495 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -29,10 +29,8 @@ internal void Test(Action action) public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { Test(() => Dbg.Msg("Msg(string)\n")); - Test(() => Dbg.DMsg("group", 0, "DMsg(string, int, string)\n")); Test(() => Dbg.Warning("Warning(string)\n")); - Test(() => Dbg.DWarning("group", 0, "DWarning(string, int, string)\n")); Test(() => Dbg.Error("Error(string)\n")); diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs index 975cc92..079f85d 100644 --- a/SourceSDK/src/tier0/dbg.cs +++ b/SourceSDK/src/tier0/dbg.cs @@ -49,34 +49,21 @@ public static class Delegates - #region [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Msg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void DMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string groupName, int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - #endregion - #region [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Warning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void DWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string groupName, int level, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - #endregion - #region [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Error([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - #endregion - #region [DllImport("tier0", EntryPoint = "?DevMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); @@ -99,7 +86,6 @@ public static class Delegates // TODO: ValidateSpew - #endregion [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void COM_TimestampedLog([MarshalAs(UnmanagedType.LPUTF8Str)] string fmt, params string[] dotdotdot); From 84e06f018e91acd1f1080f1f7c50598effaa63bf Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 19:27:53 +0500 Subject: [PATCH 013/235] add timeout minutes --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a3477f1..b38d0a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,6 +77,7 @@ jobs: powershell -Command './gmod/srcds_win64.exe -console -systemtest -condebug -game "garrysmod" +exec "server.cfg" +gamemode sandbox +map gm_construct +maxplayers 16 +sv_hibernate_think 1' powershell -Command 'Wait-Process -Name srcds_win64' continue-on-error: true + timeout-minutes: 1 - name: Print log shell: bash run: cat gmod/garrysmod/console.log From a4bf2a5592d862cb45cbb4f709e6739b251247d8 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 20:36:24 +0500 Subject: [PATCH 014/235] disable Dev* tests --- SourceSDK.Test/TestModule.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 4a26495..b37fff6 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -34,9 +34,9 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.Error("Error(string)\n")); - Test(() => { Dbg.DevMsg("DevMsg(string)\n"); }); - Test(() => { Dbg.DevWarning("DevWarning(string)\n"); }); - Test(() => { Dbg.DevLog("DevLog(string)\n"); }); + // Test(() => { Dbg.DevMsg("DevMsg(string)\n"); }); + // Test(() => { Dbg.DevWarning("DevWarning(string)\n"); }); + // Test(() => { Dbg.DevLog("DevLog(string)\n"); }); Test(() => Dbg.ConColorMsg(new Color(255, 255, 0), "ConColorMsg(in Color, string)\n")); From ed77a1a42c2639361a0e6dc9ffdca7b44014c358 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 20:43:05 +0500 Subject: [PATCH 015/235] disable everything except ConColorMsg --- SourceSDK.Test/TestModule.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index b37fff6..86cd772 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -12,7 +12,7 @@ public class TestModule : IModule public string ModuleVersion => "0.0.1"; - private bool failed; + private bool failed = false; internal void Test(Action action) { try @@ -28,11 +28,11 @@ internal void Test(Action action) public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { - Test(() => Dbg.Msg("Msg(string)\n")); + // Test(() => Dbg.Msg("Msg(string)\n")); - Test(() => Dbg.Warning("Warning(string)\n")); + // Test(() => Dbg.Warning("Warning(string)\n")); - Test(() => Dbg.Error("Error(string)\n")); + // Test(() => Dbg.Error("Error(string)\n")); // Test(() => { Dbg.DevMsg("DevMsg(string)\n"); }); // Test(() => { Dbg.DevWarning("DevWarning(string)\n"); }); @@ -40,10 +40,10 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl 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.ConMsg("ConMsg(string)\n"); }); + // Test(() => { Dbg.ConDMsg("ConDMsg(string)\n"); }); - Test(() => { Dbg.COM_TimestampedLog("%s", "COM_TimestampedLog"); }); + // Test(() => { Dbg.COM_TimestampedLog("%s", "COM_TimestampedLog"); }); Debug.Assert(!failed); } From 205fa963f86c49217ed54e64bde4579c1f0d6944 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 20:46:08 +0500 Subject: [PATCH 016/235] enable first 3 --- SourceSDK.Test/TestModule.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 86cd772..7f2df49 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -28,11 +28,11 @@ internal void Test(Action action) public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { - // Test(() => Dbg.Msg("Msg(string)\n")); + Test(() => Dbg.Msg("Msg(string)\n")); - // Test(() => Dbg.Warning("Warning(string)\n")); + Test(() => Dbg.Warning("Warning(string)\n")); - // Test(() => Dbg.Error("Error(string)\n")); + Test(() => Dbg.Error("Error(string)\n")); // Test(() => { Dbg.DevMsg("DevMsg(string)\n"); }); // Test(() => { Dbg.DevWarning("DevWarning(string)\n"); }); From 2213de7581b20c9e478a1fbfd247c4ab46fe2680 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 20:50:18 +0500 Subject: [PATCH 017/235] disable Error --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 7f2df49..71a876a 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -32,7 +32,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.Warning("Warning(string)\n")); - Test(() => Dbg.Error("Error(string)\n")); + // Test(() => Dbg.Error("Error(string)\n")); // Test(() => { Dbg.DevMsg("DevMsg(string)\n"); }); // Test(() => { Dbg.DevWarning("DevWarning(string)\n"); }); From 1a7ae122d5d4253496095cdb812addc789783cdf Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 20:56:11 +0500 Subject: [PATCH 018/235] enable everything else --- SourceSDK.Test/TestModule.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 71a876a..06258d2 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -32,18 +32,19 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.Warning("Warning(string)\n")); + // Error() kills gmod // Test(() => Dbg.Error("Error(string)\n")); - // Test(() => { Dbg.DevMsg("DevMsg(string)\n"); }); - // Test(() => { Dbg.DevWarning("DevWarning(string)\n"); }); - // Test(() => { Dbg.DevLog("DevLog(string)\n"); }); + Test(() => { Dbg.DevMsg("DevMsg(string)\n"); }); + Test(() => { Dbg.DevWarning("DevWarning(string)\n"); }); + Test(() => { Dbg.DevLog("DevLog(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.ConMsg("ConMsg(string)\n"); }); + Test(() => { Dbg.ConDMsg("ConDMsg(string)\n"); }); - // Test(() => { Dbg.COM_TimestampedLog("%s", "COM_TimestampedLog"); }); + Test(() => { Dbg.COM_TimestampedLog("%s", "COM_TimestampedLog"); }); Debug.Assert(!failed); } From ffbc316becf09cdf17faaf110052d8fb2c8daed5 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 21:28:27 +0500 Subject: [PATCH 019/235] update "EntryPoint"s for DevLog, ConMsg --- SourceSDK/src/tier0/dbg.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs index 079f85d..05b31dd 100644 --- a/SourceSDK/src/tier0/dbg.cs +++ b/SourceSDK/src/tier0/dbg.cs @@ -71,14 +71,14 @@ public static class Delegates [DllImport("tier0", EntryPoint = "?DevWarning@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", EntryPoint = "?DevLog@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] + [DllImport("tier0", EntryPoint = "?DevLog@@YAXPBDZZ", CallingConvention = CallingConvention.Cdecl)] public static extern void DevLog([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); public static Delegates.void_inColor_string ConColorMsg; - [DllImport("tier0", EntryPoint = "?ConMsg@@YAXPBDZZ", CallingConvention = CallingConvention.Cdecl)] + [DllImport("tier0", EntryPoint = "?ConMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] From d93af4061ae70b83787d9145f2ce95d47fb2f19a Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 22:14:11 +0500 Subject: [PATCH 020/235] remove not existing methods add linux EntryPoints --- SourceSDK/src/tier0/dbg.cs | 63 ++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs index 05b31dd..1afd6ce 100644 --- a/SourceSDK/src/tier0/dbg.cs +++ b/SourceSDK/src/tier0/dbg.cs @@ -7,38 +7,67 @@ namespace SourceSDK.Tier0 /// /// "public/tier0/dbg.h" /// - public class Dbg + public static class Dbg { static Dbg() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { + DevMsg = Windows.DevMsg; + DevWarning = Windows.DevWarning; ConColorMsg = Windows.ConColorMsg; + ConMsg = Windows.ConMsg; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { + DevMsg = Linux.DevMsg; + DevWarning = Linux.DevWarning; ConColorMsg = Linux.ConColorMsg; + ConMsg = Linux.ConMsg; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - ConColorMsg = OSX.ConColorMsg; + // TODO + } + else + { + throw new PlatformNotSupportedException(); } } internal class Windows { + [DllImport("tier0", EntryPoint = "?DevMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", EntryPoint = "?DevWarning@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", EntryPoint = "?ConColorMsg@@YAXAEBVColor@@PEBDZZ", CallingConvention = CallingConvention.Cdecl)] public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", EntryPoint = "?ConMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); } internal class Linux { + [DllImport("tier0", EntryPoint = "_Z6DevMsgPKcz", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", EntryPoint = "_Z10DevWarningPKcz", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", EntryPoint = "_Z11ConColorMsgRK5ColorPKcz", CallingConvention = CallingConvention.Cdecl)] public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", EntryPoint = "_Z6ConMsgPKcz", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); } internal class OSX { - [DllImport("tier0", EntryPoint = "todo", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + } public static class Delegates @@ -47,46 +76,26 @@ public static class Delegates public delegate void void_inColor_string(in Color clr, string msg); } - - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Msg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Warning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Error([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", EntryPoint = "?DevMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", EntryPoint = "?DevWarning@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", EntryPoint = "?DevLog@@YAXPBDZZ", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevLog([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + public static Delegates.void_string DevMsg; + public static Delegates.void_string DevWarning; public static Delegates.void_inColor_string ConColorMsg; - - - [DllImport("tier0", EntryPoint = "?ConMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + public static Delegates.void_string ConMsg; [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void ConDMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - // TODO: ValidateSpew - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void COM_TimestampedLog([MarshalAs(UnmanagedType.LPUTF8Str)] string fmt, params string[] dotdotdot); } From c10e55d4376e7f5f31bca22ef4f87a31a6834acf Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 22:16:44 +0500 Subject: [PATCH 021/235] fix test --- SourceSDK.Test/TestModule.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 06258d2..af997db 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -37,7 +37,6 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { Dbg.DevMsg("DevMsg(string)\n"); }); Test(() => { Dbg.DevWarning("DevWarning(string)\n"); }); - Test(() => { Dbg.DevLog("DevLog(string)\n"); }); Test(() => Dbg.ConColorMsg(new Color(255, 255, 0), "ConColorMsg(in Color, string)\n")); From acf12411fece27e0bb375e31285fbe21932dbd07 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 22:30:05 +0500 Subject: [PATCH 022/235] add OSX --- SourceSDK/src/tier0/dbg.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs index 1afd6ce..6f36a37 100644 --- a/SourceSDK/src/tier0/dbg.cs +++ b/SourceSDK/src/tier0/dbg.cs @@ -67,7 +67,18 @@ internal class Linux } internal class OSX { - + [DllImport("tier0", EntryPoint = "__Z6DevMsgPKcz", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", EntryPoint = "__Z10DevWarningPKcz", CallingConvention = CallingConvention.Cdecl)] + public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + + [DllImport("tier0", EntryPoint = "__Z11ConColorMsgRK5ColorPKcz", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + + [DllImport("tier0", EntryPoint = "__Z6ConMsgPKcz", CallingConvention = CallingConvention.Cdecl)] + public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); } public static class Delegates From 2015c21ef4739fa0c0b31f862b7092f6d408c045 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 22:30:23 +0500 Subject: [PATCH 023/235] OSX --- SourceSDK/src/tier0/dbg.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs index 6f36a37..50c3cb2 100644 --- a/SourceSDK/src/tier0/dbg.cs +++ b/SourceSDK/src/tier0/dbg.cs @@ -27,7 +27,10 @@ static Dbg() } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - // TODO + DevMsg = OSX.DevMsg; + DevWarning = OSX.DevWarning; + ConColorMsg = OSX.ConColorMsg; + ConMsg = OSX.ConMsg; } else { From 714186ef9b08dfc43cf25e90fa232473b6da4883 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 4 Feb 2021 22:46:22 +0500 Subject: [PATCH 024/235] add Warning_SpewCallStack --- SourceSDK.Test/TestModule.cs | 2 ++ SourceSDK/src/tier0/dbg.cs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index af997db..48a7dca 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -32,6 +32,8 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.Warning("Warning(string)\n")); + Test(() => Dbg.Warning_SpewCallStack(100, "Warning_SpewCallStack(int, string)")); + // Error() kills gmod // Test(() => Dbg.Error("Error(string)\n")); diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/src/tier0/dbg.cs index 50c3cb2..aa2d657 100644 --- a/SourceSDK/src/tier0/dbg.cs +++ b/SourceSDK/src/tier0/dbg.cs @@ -96,6 +96,9 @@ public static class Delegates [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Warning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] + public static extern void Warning_SpewCallStack(int maxCallStackLength, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void Error([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); From d0a34182b19255d96b0a98ff2c3681773f1b6401 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 5 Feb 2021 22:51:24 +0500 Subject: [PATCH 025/235] rename src to public add interfaceh.cs | + CreateInterfaceFn | + Sys_GetFactory() --- SourceSDK/{src => public}/Color.cs | 0 SourceSDK/{src => public}/tier0/dbg.cs | 0 SourceSDK/tier1/interfaceh.cs | 17 +++++++++++++++++ 3 files changed, 17 insertions(+) rename SourceSDK/{src => public}/Color.cs (100%) rename SourceSDK/{src => public}/tier0/dbg.cs (100%) create mode 100644 SourceSDK/tier1/interfaceh.cs diff --git a/SourceSDK/src/Color.cs b/SourceSDK/public/Color.cs similarity index 100% rename from SourceSDK/src/Color.cs rename to SourceSDK/public/Color.cs diff --git a/SourceSDK/src/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs similarity index 100% rename from SourceSDK/src/tier0/dbg.cs rename to SourceSDK/public/tier0/dbg.cs diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs new file mode 100644 index 0000000..129232a --- /dev/null +++ b/SourceSDK/tier1/interfaceh.cs @@ -0,0 +1,17 @@ +using System; +using System.Runtime.InteropServices; + +namespace SourceSDK.tier1 +{ + class interfaceh + { + public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; + public delegate IntPtr CreateInterfaceFn(string name, int returnCode); + + public static CreateInterfaceFn Sys_GetFactory(IntPtr module) + { + IntPtr createInterfaceFnPtr = NativeLibrary.GetExport(module, CREATEINTERFACE_PROCNAME); + return Marshal.GetDelegateForFunctionPointer(createInterfaceFnPtr); + } + } +} From e37f960d24bbdf982255e81e360cd4698c78a581 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 5 Feb 2021 22:53:57 +0500 Subject: [PATCH 026/235] add Sys_GetFactory(string module) --- SourceSDK/tier1/interfaceh.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index 129232a..efbbb04 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -13,5 +13,9 @@ public static CreateInterfaceFn Sys_GetFactory(IntPtr module) IntPtr createInterfaceFnPtr = NativeLibrary.GetExport(module, CREATEINTERFACE_PROCNAME); return Marshal.GetDelegateForFunctionPointer(createInterfaceFnPtr); } + public static CreateInterfaceFn Sys_GetFactory(string module) + { + return Sys_GetFactory(NativeLibrary.Load(module)); + } } } From 79b6ec82acf41b33a3bf16532cbebcf6c8026d05 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 5 Feb 2021 23:00:37 +0500 Subject: [PATCH 027/235] tier1 -> Tier1 public static class interfaceh move delegate test --- SourceSDK.Test/TestModule.cs | 9 +++++++++ SourceSDK/tier1/interfaceh.cs | 7 +++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 48a7dca..3a033ad 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -1,8 +1,10 @@ using GmodNET.API; using SourceSDK; using SourceSDK.Tier0; +using SourceSDK.Tier1; using System; using System.Diagnostics; +using System.Runtime.InteropServices; namespace SourceSDKTest { @@ -47,6 +49,13 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { Dbg.COM_TimestampedLog("%s", "COM_TimestampedLog"); }); + Test(() => + { + string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "FileSystem_Stdio.dll" : "filesystem_stdio.so"; + CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); + Console.WriteLine(factory); + }); + Debug.Assert(!failed); } diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index efbbb04..bd5f5ce 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -1,13 +1,12 @@ using System; using System.Runtime.InteropServices; -namespace SourceSDK.tier1 +namespace SourceSDK.Tier1 { - class interfaceh + public delegate IntPtr CreateInterfaceFn(string name, int returnCode); + public static class interfaceh { public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; - public delegate IntPtr CreateInterfaceFn(string name, int returnCode); - public static CreateInterfaceFn Sys_GetFactory(IntPtr module) { IntPtr createInterfaceFnPtr = NativeLibrary.GetExport(module, CREATEINTERFACE_PROCNAME); From 6b3275830ece3f1c919864a4f82e3904d6109202 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 14:56:02 +0500 Subject: [PATCH 028/235] windows: fix filesystem dll name add test --- SourceSDK.Test/TestModule.cs | 5 +++-- SourceSDK/public/appframework/iappsystem.cs | 13 +++++++++++++ SourceSDK/public/filesystemh.cs | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 SourceSDK/public/appframework/iappsystem.cs create mode 100644 SourceSDK/public/filesystemh.cs diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 3a033ad..5838167 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -51,9 +51,10 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { - string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "FileSystem_Stdio.dll" : "filesystem_stdio.so"; + string path = "filesystem_stdio." + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : ".so"); CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); - Console.WriteLine(factory); + IFileSystem fsys = Marshal.PtrToStructure(factory("VFileSystem022", 0)); + Console.WriteLine(fsys.IsSteam()); }); Debug.Assert(!failed); diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs new file mode 100644 index 0000000..7119288 --- /dev/null +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SourceSDK.appframework +{ + public interface IAppSystem + { + //TODO + } +} diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs new file mode 100644 index 0000000..4a31013 --- /dev/null +++ b/SourceSDK/public/filesystemh.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SourceSDK +{ + + public struct IFileSystem + { + public static class Delegates + { + public delegate bool rBool(); + } + + public Delegates.rBool IsSteam; + } +} From a7679eef4b20a62139dc107e5235f781cd16a899 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 15:10:43 +0500 Subject: [PATCH 029/235] fix dll path --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 5838167..79adcca 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -51,7 +51,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { - string path = "filesystem_stdio." + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".dll" : ".so"); + string path = "filesystem_stdio." + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "dll" : "so"); CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); IFileSystem fsys = Marshal.PtrToStructure(factory("VFileSystem022", 0)); Console.WriteLine(fsys.IsSteam()); From 75b66d418550540117df5bd5a03384298e24f9ac Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 15:16:48 +0500 Subject: [PATCH 030/235] add UnmanagedFunctionPointer --- SourceSDK/public/filesystemh.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 4a31013..5130af3 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -1,16 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace SourceSDK { - public struct IFileSystem { public static class Delegates { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate bool rBool(); } From 4f70a12a45a6d1bd6b9d246c03fd4622872c1549 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 15:20:55 +0500 Subject: [PATCH 031/235] add debug stuff --- SourceSDK.Test/TestModule.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 79adcca..ab83cfa 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -52,8 +52,13 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { string path = "filesystem_stdio." + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "dll" : "so"); + Console.WriteLine("Getting factory"); CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); - IFileSystem fsys = Marshal.PtrToStructure(factory("VFileSystem022", 0)); + Console.WriteLine("Creating"); + IntPtr fsysPtr = factory("VFileSystem022", 0); + Console.WriteLine("Marshal.PtrToStructure"); + IFileSystem fsys = Marshal.PtrToStructure(fsysPtr); + Console.WriteLine("fsys.IsSteam()"); Console.WriteLine(fsys.IsSteam()); }); From ea605181e8446211ca3dd6f6174a425b8995dabc Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 15:29:36 +0500 Subject: [PATCH 032/235] fix using int instead of IntPtr --- SourceSDK.Test/TestModule.cs | 2 +- SourceSDK/tier1/interfaceh.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index ab83cfa..639c616 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -55,7 +55,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("Getting factory"); CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); Console.WriteLine("Creating"); - IntPtr fsysPtr = factory("VFileSystem022", 0); + IntPtr fsysPtr = factory("VFileSystem022", IntPtr.Zero); Console.WriteLine("Marshal.PtrToStructure"); IFileSystem fsys = Marshal.PtrToStructure(fsysPtr); Console.WriteLine("fsys.IsSteam()"); diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index bd5f5ce..f1aa093 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -3,7 +3,7 @@ namespace SourceSDK.Tier1 { - public delegate IntPtr CreateInterfaceFn(string name, int returnCode); + public delegate IntPtr CreateInterfaceFn(string name, IntPtr returnCode); public static class interfaceh { public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; From 3ca74de7b524ba0c18a03c31c8d0ceda4b208d07 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 15:37:56 +0500 Subject: [PATCH 033/235] use path --- SourceSDK.Test/TestModule.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 639c616..23a5431 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -51,11 +51,20 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { - string path = "filesystem_stdio." + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "dll" : "so"); + string path; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + path = "bin/win64/filesystem_stdio.dll"; + } + else + { + path = "bin/linux64/filesystem_stdio.so"; + } Console.WriteLine("Getting factory"); CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); Console.WriteLine("Creating"); IntPtr fsysPtr = factory("VFileSystem022", IntPtr.Zero); + Console.WriteLine(fsysPtr); Console.WriteLine("Marshal.PtrToStructure"); IFileSystem fsys = Marshal.PtrToStructure(fsysPtr); Console.WriteLine("fsys.IsSteam()"); From 903df3d3169edc7251eb959e408d040525ac4bca Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 15:44:45 +0500 Subject: [PATCH 034/235] add throw if createInterfaceFnPtr==0 more checks --- SourceSDK.Test/TestModule.cs | 5 ++++- SourceSDK/tier1/interfaceh.cs | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 23a5431..d8c247f 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -60,8 +60,11 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { path = "bin/linux64/filesystem_stdio.so"; } + Console.WriteLine("Getting lib handle"); + IntPtr handle = NativeLibrary.Load(path); + Console.WriteLine(handle); Console.WriteLine("Getting factory"); - CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); + CreateInterfaceFn factory = interfaceh.Sys_GetFactory(handle); Console.WriteLine("Creating"); IntPtr fsysPtr = factory("VFileSystem022", IntPtr.Zero); Console.WriteLine(fsysPtr); diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index f1aa093..39e295b 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -10,6 +10,10 @@ public static class interfaceh public static CreateInterfaceFn Sys_GetFactory(IntPtr module) { IntPtr createInterfaceFnPtr = NativeLibrary.GetExport(module, CREATEINTERFACE_PROCNAME); + if (createInterfaceFnPtr == IntPtr.Zero) + { + throw new EntryPointNotFoundException("CreateInterface was not found"); + } return Marshal.GetDelegateForFunctionPointer(createInterfaceFnPtr); } public static CreateInterfaceFn Sys_GetFactory(string module) From 9efb0937b27ba08ae7f74ed486f7d647b554e996 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 15:51:18 +0500 Subject: [PATCH 035/235] use IntPtr for CreateInterfaceFn(name) --- SourceSDK.Test/TestModule.cs | 2 +- SourceSDK/tier1/interfaceh.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index d8c247f..df9c181 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -66,7 +66,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("Getting factory"); CreateInterfaceFn factory = interfaceh.Sys_GetFactory(handle); Console.WriteLine("Creating"); - IntPtr fsysPtr = factory("VFileSystem022", IntPtr.Zero); + IntPtr fsysPtr = factory(Marshal.StringToHGlobalAnsi("VFileSystem022"), IntPtr.Zero); Console.WriteLine(fsysPtr); Console.WriteLine("Marshal.PtrToStructure"); IFileSystem fsys = Marshal.PtrToStructure(fsysPtr); diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index 39e295b..7b53d04 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -3,7 +3,7 @@ namespace SourceSDK.Tier1 { - public delegate IntPtr CreateInterfaceFn(string name, IntPtr returnCode); + public delegate IntPtr CreateInterfaceFn(IntPtr name, IntPtr returnCode); public static class interfaceh { public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; From c51d3deda8588a78f61150b52df9ba2f24a60779 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 15:54:36 +0500 Subject: [PATCH 036/235] add result check --- SourceSDK.Test/TestModule.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index df9c181..7a8d756 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -66,7 +66,9 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("Getting factory"); CreateInterfaceFn factory = interfaceh.Sys_GetFactory(handle); Console.WriteLine("Creating"); - IntPtr fsysPtr = factory(Marshal.StringToHGlobalAnsi("VFileSystem022"), IntPtr.Zero); + IntPtr resultPtr = new IntPtr(0); + IntPtr fsysPtr = factory(Marshal.StringToHGlobalAnsi("VFileSystem022"), resultPtr); + Debug.Assert(resultPtr == IntPtr.Zero); Console.WriteLine(fsysPtr); Console.WriteLine("Marshal.PtrToStructure"); IFileSystem fsys = Marshal.PtrToStructure(fsysPtr); From a30531557f3482ebf69201fc5082c24108836605 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 15:55:41 +0500 Subject: [PATCH 037/235] two timeout minutes --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b38d0a5..6360cc9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: - name: Run Garry's Mod run: ./srcds_run_x64 -game garrysmod -systemtest -condebug +sv_hibernate_think 1 || true working-directory: ./gmod/ - timeout-minutes: 1 + timeout-minutes: 2 continue-on-error: true - name: Print log run: cat gmod/garrysmod/console.log @@ -77,7 +77,7 @@ jobs: powershell -Command './gmod/srcds_win64.exe -console -systemtest -condebug -game "garrysmod" +exec "server.cfg" +gamemode sandbox +map gm_construct +maxplayers 16 +sv_hibernate_think 1' powershell -Command 'Wait-Process -Name srcds_win64' continue-on-error: true - timeout-minutes: 1 + timeout-minutes: 2 - name: Print log shell: bash run: cat gmod/garrysmod/console.log From 8fc21c991f09884b8e90cf907465f0c48eba92b2 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 16:33:28 +0500 Subject: [PATCH 038/235] pls work --- SourceSDK.Test/TestModule.cs | 28 ++++++++++++++++++++++------ SourceSDK/tier1/interfaceh.cs | 2 +- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 7a8d756..16efab0 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -28,6 +28,11 @@ internal void Test(Action action) } } + struct CSysModule + { + public IntPtr ptr; + } + public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { Test(() => Dbg.Msg("Msg(string)\n")); @@ -54,24 +59,35 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl string path; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - path = "bin/win64/filesystem_stdio.dll"; + path = "filesystem_stdio.dll"; } else { - path = "bin/linux64/filesystem_stdio.so"; + path = "filesystem_stdio.so"; } + Console.WriteLine("Getting lib handle"); IntPtr handle = NativeLibrary.Load(path); Console.WriteLine(handle); + Console.WriteLine("Getting factory"); - CreateInterfaceFn factory = interfaceh.Sys_GetFactory(handle); + IntPtr createInterfaceFnPtr = NativeLibrary.GetExport(handle, interfaceh.CREATEINTERFACE_PROCNAME); + interfaceh.CreateInterfaceFn factory = interfaceh.Sys_GetFactory(handle); + Console.WriteLine("Creating"); IntPtr resultPtr = new IntPtr(0); - IntPtr fsysPtr = factory(Marshal.StringToHGlobalAnsi("VFileSystem022"), resultPtr); + IntPtr factoryResult = factory(Marshal.StringToHGlobalAnsi("VFileSystem022"), resultPtr); + Console.WriteLine($"factoryResult = {factoryResult}\nresult = {resultPtr}"); Debug.Assert(resultPtr == IntPtr.Zero); - Console.WriteLine(fsysPtr); + + Console.WriteLine("Marshal.PtrToStructure"); + CSysModule cSysModule = Marshal.PtrToStructure(factoryResult); + + Console.WriteLine($"cSysModule = {cSysModule}\ncSysModule.ptr = {cSysModule.ptr}"); + Console.WriteLine("Marshal.PtrToStructure"); - IFileSystem fsys = Marshal.PtrToStructure(fsysPtr); + IFileSystem fsys = Marshal.PtrToStructure(cSysModule.ptr); + Console.WriteLine("fsys.IsSteam()"); Console.WriteLine(fsys.IsSteam()); }); diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index 7b53d04..018f7e4 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -3,10 +3,10 @@ namespace SourceSDK.Tier1 { - public delegate IntPtr CreateInterfaceFn(IntPtr name, IntPtr returnCode); public static class interfaceh { public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; + public delegate IntPtr CreateInterfaceFn(IntPtr name, IntPtr returnCode); public static CreateInterfaceFn Sys_GetFactory(IntPtr module) { IntPtr createInterfaceFnPtr = NativeLibrary.GetExport(module, CREATEINTERFACE_PROCNAME); From f1d99b9bb9de09492e13720fa6307bd8da3b825a Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 6 Feb 2021 16:48:44 +0500 Subject: [PATCH 039/235] use GCHandle --- SourceSDK.Test/TestModule.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 16efab0..4bb65a4 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -75,10 +75,12 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl interfaceh.CreateInterfaceFn factory = interfaceh.Sys_GetFactory(handle); Console.WriteLine("Creating"); - IntPtr resultPtr = new IntPtr(0); + GCHandle resultHandle = GCHandle.Alloc(0, GCHandleType.Pinned); + IntPtr resultPtr = resultHandle.AddrOfPinnedObject(); IntPtr factoryResult = factory(Marshal.StringToHGlobalAnsi("VFileSystem022"), resultPtr); - Console.WriteLine($"factoryResult = {factoryResult}\nresult = {resultPtr}"); + Console.WriteLine($"factoryResult = {factoryResult}\resultPtr.ToInt32() = {resultPtr.ToInt32()}\nresultHandle = {(int)resultHandle.Target}"); Debug.Assert(resultPtr == IntPtr.Zero); + resultHandle.Free(); Console.WriteLine("Marshal.PtrToStructure"); CSysModule cSysModule = Marshal.PtrToStructure(factoryResult); From b712a1c123408f1f4b983277a1ac503ea9b6b1fe Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 11:52:17 +0500 Subject: [PATCH 040/235] something --- SourceSDK.Test/SourceSDK.Test.csproj | 1 + SourceSDK.Test/TestModule.cs | 75 +++++++++++----------------- SourceSDK/SourceSDK.csproj | 1 + SourceSDK/tier1/interfaceh.cs | 16 ++++-- 4 files changed, 42 insertions(+), 51 deletions(-) diff --git a/SourceSDK.Test/SourceSDK.Test.csproj b/SourceSDK.Test/SourceSDK.Test.csproj index 230ba3f..3d100c8 100644 --- a/SourceSDK.Test/SourceSDK.Test.csproj +++ b/SourceSDK.Test/SourceSDK.Test.csproj @@ -2,6 +2,7 @@ net5 SourceSDKTest + true diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 4bb65a4..82bc6db 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -15,6 +15,7 @@ public class TestModule : IModule public string ModuleVersion => "0.0.1"; private bool failed = false; + internal void Test(Action action) { try @@ -28,11 +29,6 @@ internal void Test(Action action) } } - struct CSysModule - { - public IntPtr ptr; - } - public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { Test(() => Dbg.Msg("Msg(string)\n")); @@ -41,57 +37,42 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.Warning_SpewCallStack(100, "Warning_SpewCallStack(int, string)")); - // Error() kills gmod - // Test(() => Dbg.Error("Error(string)\n")); - - Test(() => { Dbg.DevMsg("DevMsg(string)\n"); }); - Test(() => { Dbg.DevWarning("DevWarning(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.ConMsg("ConMsg(string)\n")); + Test(() => Dbg.ConDMsg("ConDMsg(string)\n")); - Test(() => { Dbg.COM_TimestampedLog("%s", "COM_TimestampedLog"); }); + Test(() => Dbg.COM_TimestampedLog("%s", "COM_TimestampedLog")); Test(() => { - string path; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - path = "filesystem_stdio.dll"; - } - else + unsafe { - path = "filesystem_stdio.so"; + string path; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + path = "filesystem_stdio.dll"; + } + else + { + path = "filesystem_stdio.so"; + } + + Console.WriteLine("Getting lib handle"); + IntPtr handle = NativeLibrary.Load(path); + Console.WriteLine(handle); + if (handle == IntPtr.Zero) throw new DllNotFoundException(); + + Console.WriteLine("Getting factory"); + interfaceh.CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); + + Console.WriteLine("Creating"); + void** factoryResult = factory(Marshal.StringToHGlobalAnsi("VFileSystem022"), out int returnCode); + Console.WriteLine($"result is {returnCode}"); } - - Console.WriteLine("Getting lib handle"); - IntPtr handle = NativeLibrary.Load(path); - Console.WriteLine(handle); - - Console.WriteLine("Getting factory"); - IntPtr createInterfaceFnPtr = NativeLibrary.GetExport(handle, interfaceh.CREATEINTERFACE_PROCNAME); - interfaceh.CreateInterfaceFn factory = interfaceh.Sys_GetFactory(handle); - - Console.WriteLine("Creating"); - GCHandle resultHandle = GCHandle.Alloc(0, GCHandleType.Pinned); - IntPtr resultPtr = resultHandle.AddrOfPinnedObject(); - IntPtr factoryResult = factory(Marshal.StringToHGlobalAnsi("VFileSystem022"), resultPtr); - Console.WriteLine($"factoryResult = {factoryResult}\resultPtr.ToInt32() = {resultPtr.ToInt32()}\nresultHandle = {(int)resultHandle.Target}"); - Debug.Assert(resultPtr == IntPtr.Zero); - resultHandle.Free(); - - Console.WriteLine("Marshal.PtrToStructure"); - CSysModule cSysModule = Marshal.PtrToStructure(factoryResult); - - Console.WriteLine($"cSysModule = {cSysModule}\ncSysModule.ptr = {cSysModule.ptr}"); - - Console.WriteLine("Marshal.PtrToStructure"); - IFileSystem fsys = Marshal.PtrToStructure(cSysModule.ptr); - - Console.WriteLine("fsys.IsSteam()"); - Console.WriteLine(fsys.IsSteam()); }); Debug.Assert(!failed); diff --git a/SourceSDK/SourceSDK.csproj b/SourceSDK/SourceSDK.csproj index 99301e6..e87eea7 100644 --- a/SourceSDK/SourceSDK.csproj +++ b/SourceSDK/SourceSDK.csproj @@ -1,5 +1,6 @@ net5 + true diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index 018f7e4..3eecdd3 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -6,19 +6,27 @@ namespace SourceSDK.Tier1 public static class interfaceh { public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; - public delegate IntPtr CreateInterfaceFn(IntPtr name, IntPtr returnCode); + + public unsafe delegate void** CreateInterfaceFn(IntPtr name, out int returnCode); + public static CreateInterfaceFn Sys_GetFactory(IntPtr module) { IntPtr createInterfaceFnPtr = NativeLibrary.GetExport(module, CREATEINTERFACE_PROCNAME); if (createInterfaceFnPtr == IntPtr.Zero) - { throw new EntryPointNotFoundException("CreateInterface was not found"); - } return Marshal.GetDelegateForFunctionPointer(createInterfaceFnPtr); } public static CreateInterfaceFn Sys_GetFactory(string module) { - return Sys_GetFactory(NativeLibrary.Load(module)); + IntPtr handle = NativeLibrary.Load(module); + if (handle == IntPtr.Zero) + throw new DllNotFoundException(module); + return Sys_GetFactory(handle); + } + + public static unsafe void Sys_LoadInterface(string moduleName, string interfaceVersionName, void** outModule, void** outInterface) + { + //todo? } } } From 301d4434fef7e5964d7e4482f068f4848b433dd0 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 11:54:01 +0500 Subject: [PATCH 041/235] free allocated string --- SourceSDK.Test/TestModule.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 82bc6db..21a9f79 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -70,7 +70,9 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl interfaceh.CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); Console.WriteLine("Creating"); - void** factoryResult = factory(Marshal.StringToHGlobalAnsi("VFileSystem022"), out int returnCode); + IntPtr interfaceNamePointer = Marshal.StringToHGlobalAnsi("VFileSystem022"); + void** factoryResult = factory(interfaceNamePointer, out int returnCode); + Marshal.FreeHGlobal(interfaceNamePointer); Console.WriteLine($"result is {returnCode}"); } }); From b7c3294a33adcbb4022ddbaf1675802d0ecef7c2 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 12:02:45 +0500 Subject: [PATCH 042/235] add \n to Warning_SpewCallStack test --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 21a9f79..9955e31 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -35,7 +35,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.Warning("Warning(string)\n")); - Test(() => Dbg.Warning_SpewCallStack(100, "Warning_SpewCallStack(int, string)")); + Test(() => Dbg.Warning_SpewCallStack(100, "Warning_SpewCallStack(int, string)\n")); Test(() => Dbg.DevMsg("DevMsg(string)\n")); Test(() => Dbg.DevWarning("DevWarning(string)\n")); From 71bf1257e4ec8a2c8166de816739e4f531cb8ae8 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 12:26:04 +0500 Subject: [PATCH 043/235] absolute linux path --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 9955e31..60c490f 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -58,7 +58,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl } else { - path = "filesystem_stdio.so"; + path = "bin/linux64/filesystem_stdio.so"; } Console.WriteLine("Getting lib handle"); From 4f2fc13e7ae14934ccbf807f4746efca2ff2c1c1 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 12:29:22 +0500 Subject: [PATCH 044/235] use enums --- SourceSDK.Test/TestModule.cs | 2 +- SourceSDK/tier1/interfaceh.cs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 60c490f..56dc337 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -71,7 +71,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("Creating"); IntPtr interfaceNamePointer = Marshal.StringToHGlobalAnsi("VFileSystem022"); - void** factoryResult = factory(interfaceNamePointer, out int returnCode); + void** factoryResult = factory(interfaceNamePointer, out interfaceh.IFACE returnCode); Marshal.FreeHGlobal(interfaceNamePointer); Console.WriteLine($"result is {returnCode}"); } diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index 3eecdd3..f87cc93 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -5,9 +5,14 @@ namespace SourceSDK.Tier1 { public static class interfaceh { + public enum IFACE + { + OK = 0, + FAILED = 1 + } public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; - public unsafe delegate void** CreateInterfaceFn(IntPtr name, out int returnCode); + public unsafe delegate void** CreateInterfaceFn(IntPtr name, out IFACE returnCode); public static CreateInterfaceFn Sys_GetFactory(IntPtr module) { From 3c6146a98e94c50bee7b2d902180bae3ed940c73 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 13:12:31 +0500 Subject: [PATCH 045/235] ClangSharp test --- SourceSDK.Test/TestModule.cs | 12 ++++++++++++ SourceSDK/public/filesystemh.cs | 15 +++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 56dc337..0a34553 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -70,10 +70,22 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl interfaceh.CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); Console.WriteLine("Creating"); + IntPtr interfaceNamePointer = Marshal.StringToHGlobalAnsi("VFileSystem022"); void** factoryResult = factory(interfaceNamePointer, out interfaceh.IFACE returnCode); Marshal.FreeHGlobal(interfaceNamePointer); + Console.WriteLine($"result is {returnCode}"); + + if (returnCode == interfaceh.IFACE.OK) + { + IFileSystem fileSystem = new IFileSystem() {lpVtbl=factoryResult }; + Console.WriteLine(fileSystem.IsSteam()); + } + else + { + Console.WriteLine("failed getting interface"); + } } }); diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 5130af3..a153bc4 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -1,20 +1,23 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace SourceSDK { - public struct IFileSystem + public unsafe struct IFileSystem { - public static class Delegates + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate byte _IsSteam(IFileSystem* pThis); + + public unsafe void** lpVtbl; + //public extern bool IsSteam(); + public bool IsSteam() { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool rBool(); + return Marshal.GetDelegateForFunctionPointer<_IsSteam>((IntPtr)(lpVtbl[22]))((IFileSystem*)Unsafe.AsPointer(ref this)) != 0; } - - public Delegates.rBool IsSteam; } } From 6d6d25ed9aeea51fe6d4037a430ffab1c610b743 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 13:22:05 +0500 Subject: [PATCH 046/235] more --- SourceSDK.Test/TestModule.cs | 23 ++++++++++++++++++++--- SourceSDK/public/filesystemh.cs | 8 ++++++-- SourceSDK/tier1/interfaceh.cs | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 0a34553..627a8c7 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -72,15 +72,32 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("Creating"); IntPtr interfaceNamePointer = Marshal.StringToHGlobalAnsi("VFileSystem022"); - void** factoryResult = factory(interfaceNamePointer, out interfaceh.IFACE returnCode); + IntPtr* factoryResult = factory(interfaceNamePointer, out interfaceh.IFACE returnCode); Marshal.FreeHGlobal(interfaceNamePointer); Console.WriteLine($"result is {returnCode}"); if (returnCode == interfaceh.IFACE.OK) { - IFileSystem fileSystem = new IFileSystem() {lpVtbl=factoryResult }; - Console.WriteLine(fileSystem.IsSteam()); + try + { + IFileSystem fileSystem = new IFileSystem() { lpVtbl = factoryResult }; + Console.WriteLine(fileSystem.IsSteam()); + } + catch (Exception e) + { + Console.WriteLine(e); + try + { + IFileSystem fileSystem = Marshal.PtrToStructure((IntPtr)factoryResult); + Console.WriteLine(fileSystem.IsSteam()); + } + catch (Exception e2) + { + Console.WriteLine("SECOND EXCEPTION:"); + Console.WriteLine(e2); + } + } } else { diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index a153bc4..793d95a 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -13,11 +13,15 @@ public unsafe struct IFileSystem [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate byte _IsSteam(IFileSystem* pThis); - public unsafe void** lpVtbl; + public unsafe IntPtr* lpVtbl; //public extern bool IsSteam(); public bool IsSteam() { - return Marshal.GetDelegateForFunctionPointer<_IsSteam>((IntPtr)(lpVtbl[22]))((IFileSystem*)Unsafe.AsPointer(ref this)) != 0; + IntPtr isSteamPtr = lpVtbl[22]; + if (isSteamPtr == IntPtr.Zero) throw new KeyNotFoundException("isSteamPtr"); + _IsSteam isSteam = Marshal.GetDelegateForFunctionPointer<_IsSteam>(isSteamPtr); + IFileSystem* fs = (IFileSystem*)Unsafe.AsPointer(ref this); + return isSteam(fs) != 0; } } } diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index f87cc93..ef6563e 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -12,7 +12,7 @@ public enum IFACE } public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; - public unsafe delegate void** CreateInterfaceFn(IntPtr name, out IFACE returnCode); + public unsafe delegate IntPtr* CreateInterfaceFn(IntPtr name, out IFACE returnCode); public static CreateInterfaceFn Sys_GetFactory(IntPtr module) { From bbee39fe1d0b7cb605d4ac7dfc1391c3bd8540eb Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 13:27:32 +0500 Subject: [PATCH 047/235] swap --- SourceSDK.Test/TestModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 627a8c7..8a197b1 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -81,7 +81,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { try { - IFileSystem fileSystem = new IFileSystem() { lpVtbl = factoryResult }; + IFileSystem fileSystem = Marshal.PtrToStructure((IntPtr)factoryResult); Console.WriteLine(fileSystem.IsSteam()); } catch (Exception e) @@ -89,7 +89,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine(e); try { - IFileSystem fileSystem = Marshal.PtrToStructure((IntPtr)factoryResult); + IFileSystem fileSystem = new IFileSystem() { lpVtbl = factoryResult }; Console.WriteLine(fileSystem.IsSteam()); } catch (Exception e2) From bb56082ffd7cf4d29058fd034669610f2f07fb70 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 13:37:07 +0500 Subject: [PATCH 048/235] debug stuff --- SourceSDK.Test/TestModule.cs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 8a197b1..3031b53 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -4,6 +4,7 @@ using SourceSDK.Tier1; using System; using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace SourceSDKTest @@ -29,6 +30,28 @@ internal void Test(Action action) } } + public unsafe struct IFileSystem1 + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate byte _IsSteam(IFileSystem1* pThis); + + public unsafe IntPtr* lpVtbl; + //public extern bool IsSteam(); + public bool IsSteam() + { + IntPtr isSteamPtr = lpVtbl[22]; + if (isSteamPtr == IntPtr.Zero) throw new Exception("isSteamPtr"); + Console.WriteLine("getting delegate"); + _IsSteam isSteam = Marshal.GetDelegateForFunctionPointer<_IsSteam>(isSteamPtr); + Console.WriteLine("fs"); + IFileSystem1* fs = (IFileSystem1*)Unsafe.AsPointer(ref this); + Console.WriteLine("isSteam"); + byte isSteamResult = isSteam(fs); + Console.WriteLine("isSteamResult != 0"); + return isSteamResult != 0; + } + } + public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { Test(() => Dbg.Msg("Msg(string)\n")); @@ -81,15 +104,18 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { try { - IFileSystem fileSystem = Marshal.PtrToStructure((IntPtr)factoryResult); + Console.WriteLine("PtrToStructure"); + IFileSystem1 fileSystem = Marshal.PtrToStructure((IntPtr)factoryResult); + Console.WriteLine("fileSystem.IsSteam"); Console.WriteLine(fileSystem.IsSteam()); + Console.WriteLine("done"); } catch (Exception e) { Console.WriteLine(e); try { - IFileSystem fileSystem = new IFileSystem() { lpVtbl = factoryResult }; + IFileSystem1 fileSystem = new IFileSystem1() { lpVtbl = factoryResult }; Console.WriteLine(fileSystem.IsSteam()); } catch (Exception e2) From facacdee74367d19ca6d1ebe638fcb75065abcd4 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 13:46:12 +0500 Subject: [PATCH 049/235] use bool --- SourceSDK.Test/TestModule.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 3031b53..61d4b46 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -33,7 +33,7 @@ internal void Test(Action action) public unsafe struct IFileSystem1 { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate byte _IsSteam(IFileSystem1* pThis); + public delegate bool _IsSteam(IFileSystem1* pThis); public unsafe IntPtr* lpVtbl; //public extern bool IsSteam(); @@ -46,9 +46,9 @@ public bool IsSteam() Console.WriteLine("fs"); IFileSystem1* fs = (IFileSystem1*)Unsafe.AsPointer(ref this); Console.WriteLine("isSteam"); - byte isSteamResult = isSteam(fs); - Console.WriteLine("isSteamResult != 0"); - return isSteamResult != 0; + bool isSteamResult = isSteam(fs); + Console.WriteLine("return"); + return isSteamResult; } } From aba6646ee6727e14745e0264519cc33d5e6477a0 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 13:50:28 +0500 Subject: [PATCH 050/235] do not pass this --- SourceSDK.Test/TestModule.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 61d4b46..81f861f 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -33,7 +33,7 @@ internal void Test(Action action) public unsafe struct IFileSystem1 { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool _IsSteam(IFileSystem1* pThis); + public delegate bool _IsSteam(); public unsafe IntPtr* lpVtbl; //public extern bool IsSteam(); @@ -43,10 +43,8 @@ public bool IsSteam() if (isSteamPtr == IntPtr.Zero) throw new Exception("isSteamPtr"); Console.WriteLine("getting delegate"); _IsSteam isSteam = Marshal.GetDelegateForFunctionPointer<_IsSteam>(isSteamPtr); - Console.WriteLine("fs"); - IFileSystem1* fs = (IFileSystem1*)Unsafe.AsPointer(ref this); Console.WriteLine("isSteam"); - bool isSteamResult = isSteam(fs); + bool isSteamResult = isSteam(); Console.WriteLine("return"); return isSteamResult; } From 85399684a549b4c08e01b4e6b2f390cf9411bf86 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 13:51:26 +0500 Subject: [PATCH 051/235] use filesystem_stdio instead of path --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 81f861f..bd3a6b1 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -79,7 +79,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl } else { - path = "bin/linux64/filesystem_stdio.so"; + path = "filesystem_stdio"; } Console.WriteLine("Getting lib handle"); From 550490c8ab2e57c727ea7d7929321c7472eef14e Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 13:55:15 +0500 Subject: [PATCH 052/235] swap --- SourceSDK.Test/TestModule.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index bd3a6b1..dcd7382 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -102,8 +102,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { try { - Console.WriteLine("PtrToStructure"); - IFileSystem1 fileSystem = Marshal.PtrToStructure((IntPtr)factoryResult); + IFileSystem1 fileSystem = new IFileSystem1() { lpVtbl = factoryResult }; Console.WriteLine("fileSystem.IsSteam"); Console.WriteLine(fileSystem.IsSteam()); Console.WriteLine("done"); @@ -113,8 +112,11 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine(e); try { - IFileSystem1 fileSystem = new IFileSystem1() { lpVtbl = factoryResult }; + Console.WriteLine("PtrToStructure"); + IFileSystem1 fileSystem = Marshal.PtrToStructure((IntPtr)factoryResult); + Console.WriteLine("fileSystem.IsSteam"); Console.WriteLine(fileSystem.IsSteam()); + Console.WriteLine("done"); } catch (Exception e2) { From b13007e209cdf03751406d56dcd8562353456689 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 14:05:42 +0500 Subject: [PATCH 053/235] again use void** --- SourceSDK.Test/TestModule.cs | 8 ++++---- SourceSDK/tier1/interfaceh.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index dcd7382..0d3b681 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -32,14 +32,14 @@ internal void Test(Action action) public unsafe struct IFileSystem1 { + public void** lpVtbl; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate bool _IsSteam(); - public unsafe IntPtr* lpVtbl; - //public extern bool IsSteam(); public bool IsSteam() { - IntPtr isSteamPtr = lpVtbl[22]; + IntPtr isSteamPtr = new IntPtr(lpVtbl[22]); if (isSteamPtr == IntPtr.Zero) throw new Exception("isSteamPtr"); Console.WriteLine("getting delegate"); _IsSteam isSteam = Marshal.GetDelegateForFunctionPointer<_IsSteam>(isSteamPtr); @@ -93,7 +93,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("Creating"); IntPtr interfaceNamePointer = Marshal.StringToHGlobalAnsi("VFileSystem022"); - IntPtr* factoryResult = factory(interfaceNamePointer, out interfaceh.IFACE returnCode); + void** factoryResult = factory(interfaceNamePointer, out interfaceh.IFACE returnCode); Marshal.FreeHGlobal(interfaceNamePointer); Console.WriteLine($"result is {returnCode}"); diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index ef6563e..f87cc93 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -12,7 +12,7 @@ public enum IFACE } public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; - public unsafe delegate IntPtr* CreateInterfaceFn(IntPtr name, out IFACE returnCode); + public unsafe delegate void** CreateInterfaceFn(IntPtr name, out IFACE returnCode); public static CreateInterfaceFn Sys_GetFactory(IntPtr module) { From 452cc028dfe50b0d5e86971fe948a25601f00bf4 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 18:43:52 +0500 Subject: [PATCH 054/235] SourceSDK.CAPI --- .gitignore | 3 +- .gitmodules | 4 ++ CMakeLists.txt | 9 +++++ SourceSDK.CAPI/CMakeLists.txt | 18 +++++++++ SourceSDK.CAPI/SourceSDK.CAPI.cpp | 14 +++++++ SourceSDK.CAPI/SourceSDK.CAPI.h | 8 ++++ SourceSDK.CAPI/gmod_sdk | 1 + SourceSDK.Test/TestModule.cs | 65 +++++-------------------------- SourceSDK/public/filesystemh.cs | 32 ++++++++------- SourceSDK/tier1/interfaceh.cs | 8 +++- 10 files changed, 88 insertions(+), 74 deletions(-) create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 SourceSDK.CAPI/CMakeLists.txt create mode 100644 SourceSDK.CAPI/SourceSDK.CAPI.cpp create mode 100644 SourceSDK.CAPI/SourceSDK.CAPI.h create mode 160000 SourceSDK.CAPI/gmod_sdk diff --git a/.gitignore b/.gitignore index ac16142..f528826 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -.vs +.vs bin obj +out diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9b2d47a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "SourceSDK.CAPI/gmod_sdk"] + path = SourceSDK.CAPI/gmod_sdk + url = https://github.com/danielga/garrysmod_common.git + branch = x86-64-support-sourcesdk diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1bf6947 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +# CMakeList.txt : Top-level CMake project file, do global configuration +# and include sub-projects here. +# +cmake_minimum_required (VERSION 3.8) + +project ("SourceSDK") + +# Include sub-projects. +add_subdirectory ("SourceSDK.CAPI") diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt new file mode 100644 index 0000000..4da950f --- /dev/null +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -0,0 +1,18 @@ +# CMakeList.txt : CMake project for SourceSDK.CAPI, include source and define +# project specific logic here. +# +link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/x64/tier0.lib") +link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/libz.lib") +#link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/tier1.lib") +link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/tier2.lib") +link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/tier3.lib") +link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/x64/vstdlib.lib") +cmake_minimum_required (VERSION 3.8) +set(arch "x64") +set(CMAKE_SYSTEM_PROCESSOR "x64") +project("sourcesdkc") +add_library (sourcesdkc MODULE "SourceSDK.CAPI.cpp" "SourceSDK.CAPI.h") +include_directories() +target_include_directories(sourcesdkc PUBLIC "gmod_sdk/sourcesdk-minimal/public") + +add_compile_definitions("COMPILER_MSVC" "COMPILER_MSVC64" "__x86_64__") diff --git a/SourceSDK.CAPI/SourceSDK.CAPI.cpp b/SourceSDK.CAPI/SourceSDK.CAPI.cpp new file mode 100644 index 0000000..70c68ed --- /dev/null +++ b/SourceSDK.CAPI/SourceSDK.CAPI.cpp @@ -0,0 +1,14 @@ +#include "SourceSDK.CAPI.h" +#include + + + +DllExport bool IFileSystem_IsSteam(void** fsPtr) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->IsSteam(); +} + +DllExport void IFileSystem_PrintSearchPaths(void** fsPtr) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->PrintSearchPaths(); +} diff --git a/SourceSDK.CAPI/SourceSDK.CAPI.h b/SourceSDK.CAPI/SourceSDK.CAPI.h new file mode 100644 index 0000000..ddfeb24 --- /dev/null +++ b/SourceSDK.CAPI/SourceSDK.CAPI.h @@ -0,0 +1,8 @@ +#pragma once + +#ifdef WIN32 +#define DllExport extern "C" __declspec( dllexport ) +#else +#define DllExport extern "C" __attribute__ ((dllexport)) +#endif + diff --git a/SourceSDK.CAPI/gmod_sdk b/SourceSDK.CAPI/gmod_sdk new file mode 160000 index 0000000..b3f9c35 --- /dev/null +++ b/SourceSDK.CAPI/gmod_sdk @@ -0,0 +1 @@ +Subproject commit b3f9c353af738791d1abf312925a4245294895fe diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 0d3b681..04b444c 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -4,7 +4,6 @@ using SourceSDK.Tier1; using System; using System.Diagnostics; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace SourceSDKTest @@ -30,26 +29,6 @@ internal void Test(Action action) } } - public unsafe struct IFileSystem1 - { - public void** lpVtbl; - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool _IsSteam(); - - public bool IsSteam() - { - IntPtr isSteamPtr = new IntPtr(lpVtbl[22]); - if (isSteamPtr == IntPtr.Zero) throw new Exception("isSteamPtr"); - Console.WriteLine("getting delegate"); - _IsSteam isSteam = Marshal.GetDelegateForFunctionPointer<_IsSteam>(isSteamPtr); - Console.WriteLine("isSteam"); - bool isSteamResult = isSteam(); - Console.WriteLine("return"); - return isSteamResult; - } - } - public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { Test(() => Dbg.Msg("Msg(string)\n")); @@ -82,53 +61,27 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl path = "filesystem_stdio"; } - Console.WriteLine("Getting lib handle"); - IntPtr handle = NativeLibrary.Load(path); - Console.WriteLine(handle); - if (handle == IntPtr.Zero) throw new DllNotFoundException(); - Console.WriteLine("Getting factory"); interfaceh.CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); - Console.WriteLine("Creating"); + Console.WriteLine("factory()"); IntPtr interfaceNamePointer = Marshal.StringToHGlobalAnsi("VFileSystem022"); - void** factoryResult = factory(interfaceNamePointer, out interfaceh.IFACE returnCode); + IntPtr iFileSystemPtr = factory(interfaceNamePointer, out interfaceh.IFACE returnCode); Marshal.FreeHGlobal(interfaceNamePointer); Console.WriteLine($"result is {returnCode}"); if (returnCode == interfaceh.IFACE.OK) { - try - { - IFileSystem1 fileSystem = new IFileSystem1() { lpVtbl = factoryResult }; - Console.WriteLine("fileSystem.IsSteam"); - Console.WriteLine(fileSystem.IsSteam()); - Console.WriteLine("done"); - } - catch (Exception e) - { - Console.WriteLine(e); - try - { - Console.WriteLine("PtrToStructure"); - IFileSystem1 fileSystem = Marshal.PtrToStructure((IntPtr)factoryResult); - Console.WriteLine("fileSystem.IsSteam"); - Console.WriteLine(fileSystem.IsSteam()); - Console.WriteLine("done"); - } - catch (Exception e2) - { - Console.WriteLine("SECOND EXCEPTION:"); - Console.WriteLine(e2); - } - } - } - else - { - Console.WriteLine("failed getting interface"); + IFileSystem fileSystem = new(iFileSystemPtr); + + Console.WriteLine("PrintSearchPaths"); + fileSystem.PrintSearchPaths(); + Console.WriteLine("IsSteam"); + Console.WriteLine(fileSystem.IsSteam()); } + else throw new EntryPointNotFoundException(); } }); diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 793d95a..e686ebd 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -1,27 +1,29 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace SourceSDK { - public unsafe struct IFileSystem + public class IFileSystem { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate byte _IsSteam(IFileSystem* pThis); + private IntPtr ptr; + public IFileSystem(IntPtr ptr) + { + this.ptr = ptr; + } + + [DllImport("sourcesdkc")] + internal static extern bool IFileSystem_IsSteam(IntPtr ptr); - public unsafe IntPtr* lpVtbl; - //public extern bool IsSteam(); public bool IsSteam() { - IntPtr isSteamPtr = lpVtbl[22]; - if (isSteamPtr == IntPtr.Zero) throw new KeyNotFoundException("isSteamPtr"); - _IsSteam isSteam = Marshal.GetDelegateForFunctionPointer<_IsSteam>(isSteamPtr); - IFileSystem* fs = (IFileSystem*)Unsafe.AsPointer(ref this); - return isSteam(fs) != 0; + return IFileSystem_IsSteam(ptr); + } + + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_PrintSearchPaths(IntPtr ptr); + public void PrintSearchPaths() + { + IFileSystem_PrintSearchPaths(ptr); } } } diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index f87cc93..d3d55fb 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -12,24 +12,28 @@ public enum IFACE } public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; - public unsafe delegate void** CreateInterfaceFn(IntPtr name, out IFACE returnCode); + public unsafe delegate IntPtr CreateInterfaceFn(IntPtr name, out IFACE returnCode); public static CreateInterfaceFn Sys_GetFactory(IntPtr module) { IntPtr createInterfaceFnPtr = NativeLibrary.GetExport(module, CREATEINTERFACE_PROCNAME); + if (createInterfaceFnPtr == IntPtr.Zero) throw new EntryPointNotFoundException("CreateInterface was not found"); + return Marshal.GetDelegateForFunctionPointer(createInterfaceFnPtr); } public static CreateInterfaceFn Sys_GetFactory(string module) { IntPtr handle = NativeLibrary.Load(module); + if (handle == IntPtr.Zero) throw new DllNotFoundException(module); + return Sys_GetFactory(handle); } - public static unsafe void Sys_LoadInterface(string moduleName, string interfaceVersionName, void** outModule, void** outInterface) + public static void Sys_LoadInterface(string moduleName, string interfaceVersionName, IntPtr outModule, IntPtr outInterface) { //todo? } From 2652def38d4bed48794856e0e06d0c1971642d6d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 18:49:03 +0500 Subject: [PATCH 055/235] formatting --- SourceSDK/public/filesystemh.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index e686ebd..5b3961e 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -6,6 +6,7 @@ namespace SourceSDK public class IFileSystem { private IntPtr ptr; + public IFileSystem(IntPtr ptr) { this.ptr = ptr; @@ -13,7 +14,6 @@ public IFileSystem(IntPtr ptr) [DllImport("sourcesdkc")] internal static extern bool IFileSystem_IsSteam(IntPtr ptr); - public bool IsSteam() { return IFileSystem_IsSteam(ptr); From d93cf260500593a440381813c1501637e3506eee Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 18:59:20 +0500 Subject: [PATCH 056/235] add cmake ci --- .github/workflows/build.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6360cc9..36301ac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,10 +5,42 @@ on: pull_request: branches: [ main ] jobs: + linux-cmake-build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + - name: 'CMake' + uses: lukka/run-cmake@v2 + with: + cmakeListsOrSettingsJson: CMakeListsTxtBasic + cmakeListsTxtPath: "SourceSDK.CAPI/CMakeLists.txt" + #useVcpkgToolchainFile: true + cmakeBuildType: Release + buildDirectory: '${{ github.workspace }}/out' + - run: tree + windows-cmake-build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + - name: 'CMake' + uses: lukka/run-cmake@v2 + with: + cmakeListsOrSettingsJson: CMakeListsTxtBasic + cmakeListsTxtPath: "SourceSDK.CAPI/CMakeLists.txt" + #useVcpkgToolchainFile: true + cmakeBuildType: Release + buildDirectory: '${{ github.workspace }}/out' + - run: tree linux: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + submodules: recursive - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: From c5e98547ea082ee9df60b21c1137d74150f69760 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 19:32:36 +0500 Subject: [PATCH 057/235] hmm --- .github/workflows/build.yml | 4 +- SourceSDK.CAPI/CMakeLists.txt | 71 +++++++++++++++++++++++++------ SourceSDK.CAPI/SourceSDK.CAPI.cpp | 7 +-- SourceSDK.CAPI/SourceSDK.CAPI.h | 6 +++ 4 files changed, 67 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 36301ac..caffe77 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,7 @@ jobs: uses: lukka/run-cmake@v2 with: cmakeListsOrSettingsJson: CMakeListsTxtBasic - cmakeListsTxtPath: "SourceSDK.CAPI/CMakeLists.txt" + # cmakeListsTxtPath: "SourceSDK.CAPI/CMakeLists.txt" #useVcpkgToolchainFile: true cmakeBuildType: Release buildDirectory: '${{ github.workspace }}/out' @@ -30,7 +30,7 @@ jobs: uses: lukka/run-cmake@v2 with: cmakeListsOrSettingsJson: CMakeListsTxtBasic - cmakeListsTxtPath: "SourceSDK.CAPI/CMakeLists.txt" + # cmakeListsTxtPath: "SourceSDK.CAPI/CMakeLists.txt" #useVcpkgToolchainFile: true cmakeBuildType: Release buildDirectory: '${{ github.workspace }}/out' diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index 4da950f..93e224b 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -1,18 +1,61 @@ -# CMakeList.txt : CMake project for SourceSDK.CAPI, include source and define -# project specific logic here. -# -link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/x64/tier0.lib") -link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/libz.lib") -#link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/tier1.lib") -link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/tier2.lib") -link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/tier3.lib") -link_libraries("C:/Users/Дом/source/repos/SupinePandora43/GmodDotNet.SourceSDK/SourceSDK.CAPI/gmod_sdk/sourcesdk-minimal/lib/public/x64/vstdlib.lib") cmake_minimum_required (VERSION 3.8) -set(arch "x64") -set(CMAKE_SYSTEM_PROCESSOR "x64") + project("sourcesdkc") + +set(SOURCESDK_DEFINES + "PLATFORM_64BITS" + "__x86_64__" +) +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + list(APPEND SOURCESDK_DEFINES "COMPILER_GCC" "GNUC") +elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + list(APPEND SOURCESDK_DEFINES "COMPILER_MSVC") + list(APPEND SOURCESDK_DEFINES "COMPILER_MSVC64") +else() + message(WARNING "Unknown compiler used: ${CMAKE_CXX_COMPILER_ID}") +endif() + +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + list(APPEND SOURCESDK_DEFINES "WIN64" "_WIN64" "_DLL_EXT=.dll" "WIN32") + set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/x64") +endif() + +if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + list(APPEND SOURCESDK_DEFINES + "_DLL_EXT=.so" + "POSIX" + "_POSIX" + "LINUX" + "_LINUX" + "SWDS" + ) + set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/linux64") +endif() + +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + list(APPEND SOURCESDK_DEFINES + "_DLL_EXT=.dylib" + "POSIX" + "_POSIX" + "OSX" + "_OSX" + "_DARWIN_UNLIMITED_SELECT" + "FD_SETSIZE=10240" + "OVERRIDE_V_DEFINES" + "SWDS" + ) + set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/osx64") +endif() + +add_compile_definitions(${SOURCESDK_DEFINES}) + +link_directories("${SOURCESDK_LIBDIRS}") +link_libraries(tier0) add_library (sourcesdkc MODULE "SourceSDK.CAPI.cpp" "SourceSDK.CAPI.h") -include_directories() -target_include_directories(sourcesdkc PUBLIC "gmod_sdk/sourcesdk-minimal/public") -add_compile_definitions("COMPILER_MSVC" "COMPILER_MSVC64" "__x86_64__") +target_include_directories(sourcesdkc PUBLIC#SYSTEM INTERFACE + #"${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/common" + #"${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/game/shared" + "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/public" +) +#target_include_directories(sourcesdkc SYSTEM INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/public/tier0") diff --git a/SourceSDK.CAPI/SourceSDK.CAPI.cpp b/SourceSDK.CAPI/SourceSDK.CAPI.cpp index 70c68ed..bf14c74 100644 --- a/SourceSDK.CAPI/SourceSDK.CAPI.cpp +++ b/SourceSDK.CAPI/SourceSDK.CAPI.cpp @@ -1,14 +1,11 @@ -#include "SourceSDK.CAPI.h" #include - - -DllExport bool IFileSystem_IsSteam(void** fsPtr) { +DLL_EXPORT bool IFileSystem_IsSteam(void** fsPtr) { IFileSystem* fs = (IFileSystem*)fsPtr; return fs->IsSteam(); } -DllExport void IFileSystem_PrintSearchPaths(void** fsPtr) { +DLL_EXPORT void IFileSystem_PrintSearchPaths(void** fsPtr) { IFileSystem* fs = (IFileSystem*)fsPtr; fs->PrintSearchPaths(); } diff --git a/SourceSDK.CAPI/SourceSDK.CAPI.h b/SourceSDK.CAPI/SourceSDK.CAPI.h index ddfeb24..0582251 100644 --- a/SourceSDK.CAPI/SourceSDK.CAPI.h +++ b/SourceSDK.CAPI/SourceSDK.CAPI.h @@ -1,4 +1,9 @@ +#ifndef SourceSDK_CAPI_H +#define SourceSDK_CAPI_H + +#ifdef WIN32 #pragma once +#endif #ifdef WIN32 #define DllExport extern "C" __declspec( dllexport ) @@ -6,3 +11,4 @@ #define DllExport extern "C" __attribute__ ((dllexport)) #endif +#endif From 5a96e5be76b0b26ab7c518d5d75229d70533c36b Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 19:44:34 +0500 Subject: [PATCH 058/235] fix windows ci? --- .github/workflows/build.yml | 3 ++- CMakeSettings.json | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 CMakeSettings.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index caffe77..b37d332 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,10 +26,11 @@ jobs: - uses: actions/checkout@v2 with: submodules: recursive + - uses: ilammy/msvc-dev-cmd@v1 - name: 'CMake' uses: lukka/run-cmake@v2 with: - cmakeListsOrSettingsJson: CMakeListsTxtBasic + cmakeListsOrSettingsJson: CMakeSettingsJson # cmakeListsTxtPath: "SourceSDK.CAPI/CMakeLists.txt" #useVcpkgToolchainFile: true cmakeBuildType: Release diff --git a/CMakeSettings.json b/CMakeSettings.json new file mode 100644 index 0000000..bfa97a6 --- /dev/null +++ b/CMakeSettings.json @@ -0,0 +1,14 @@ +{ + "configurations": [ + { + "name": "x64-Release", + "generator": "Ninja", + "configurationType": "Release", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${projectDir}\\out", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "" + } + ] +} From b06e26a4f7cbaee9b81029eff6b9f49adf699828 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:03:17 +0500 Subject: [PATCH 059/235] improve cmake --- SourceSDK.CAPI/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index 93e224b..5b5c9f6 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -15,12 +15,12 @@ else() message(WARNING "Unknown compiler used: ${CMAKE_CXX_COMPILER_ID}") endif() -if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") +if(CMAKE_SYSTEM_NAME MATCHES "Windows") list(APPEND SOURCESDK_DEFINES "WIN64" "_WIN64" "_DLL_EXT=.dll" "WIN32") set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/x64") endif() -if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") +if(CMAKE_SYSTEM_NAME MATCHES "Linux") list(APPEND SOURCESDK_DEFINES "_DLL_EXT=.so" "POSIX" @@ -32,7 +32,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/linux64") endif() -if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") list(APPEND SOURCESDK_DEFINES "_DLL_EXT=.dylib" "POSIX" From 4a7395f598b5d61ce55853b76896afa40aa528f8 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:04:13 +0500 Subject: [PATCH 060/235] use defines --- SourceSDK.CAPI/CMakeLists.txt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index 5b5c9f6..b0b7075 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -15,12 +15,10 @@ else() message(WARNING "Unknown compiler used: ${CMAKE_CXX_COMPILER_ID}") endif() -if(CMAKE_SYSTEM_NAME MATCHES "Windows") +if(WIN32) list(APPEND SOURCESDK_DEFINES "WIN64" "_WIN64" "_DLL_EXT=.dll" "WIN32") set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/x64") -endif() - -if(CMAKE_SYSTEM_NAME MATCHES "Linux") +elseif(UNIX) list(APPEND SOURCESDK_DEFINES "_DLL_EXT=.so" "POSIX" @@ -30,9 +28,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux") "SWDS" ) set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/linux64") -endif() - -if(CMAKE_SYSTEM_NAME MATCHES "Darwin") +elseif(APPLE) list(APPEND SOURCESDK_DEFINES "_DLL_EXT=.dylib" "POSIX" From 1dd044a41b3acd30675055d514cc2334755e98f3 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:06:37 +0500 Subject: [PATCH 061/235] use ubuntu-latest in linux-cmake-build BRUH MOMENT --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b37d332..451d377 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: branches: [ main ] jobs: linux-cmake-build: - runs-on: windows-latest + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: From f9b7c7bfd610ed9368dd8b0ef2f3b23d037694af Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:12:24 +0500 Subject: [PATCH 062/235] upload artifacts --- .github/workflows/build.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 451d377..7514140 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,6 +20,12 @@ jobs: cmakeBuildType: Release buildDirectory: '${{ github.workspace }}/out' - run: tree + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: linux-x64 + path: "out/SourceSDK.CAPI/libsourcesdkc.so" + retention-days: 10 windows-cmake-build: runs-on: windows-latest steps: @@ -35,7 +41,12 @@ jobs: #useVcpkgToolchainFile: true cmakeBuildType: Release buildDirectory: '${{ github.workspace }}/out' - - run: tree + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: win-x64 + path: "out/SourceSDK.CAPI/sourcesdkc.dll" + retention-days: 10 linux: runs-on: ubuntu-latest steps: From 19121df49f49c5890e834431b15e8c7f25e3ea70 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:17:24 +0500 Subject: [PATCH 063/235] tree /f --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7514140..48ca2e4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,6 +41,7 @@ jobs: #useVcpkgToolchainFile: true cmakeBuildType: Release buildDirectory: '${{ github.workspace }}/out' + - run: tree /f - name: Upload Artifact uses: actions/upload-artifact@v2 with: From 4e12d27951d91ca834a5cd7dd5ec8e3f9792987a Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:21:39 +0500 Subject: [PATCH 064/235] some changes --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 48ca2e4..15bdd49 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: # cmakeListsTxtPath: "SourceSDK.CAPI/CMakeLists.txt" #useVcpkgToolchainFile: true cmakeBuildType: Release - buildDirectory: '${{ github.workspace }}/out' + #buildDirectory: '${{ github.workspace }}/out' - run: tree /f - name: Upload Artifact uses: actions/upload-artifact@v2 From e871780274f4a90456a515e408f8c812b54f9e56 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:22:47 +0500 Subject: [PATCH 065/235] if-no-files-found: error --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 15bdd49..fa57b45 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,6 +26,7 @@ jobs: name: linux-x64 path: "out/SourceSDK.CAPI/libsourcesdkc.so" retention-days: 10 + if-no-files-found: error windows-cmake-build: runs-on: windows-latest steps: @@ -48,6 +49,7 @@ jobs: name: win-x64 path: "out/SourceSDK.CAPI/sourcesdkc.dll" retention-days: 10 + if-no-files-found: error linux: runs-on: ubuntu-latest steps: From f23a21da2bf0ed94b8ab4e10b1c6d7732a57759f Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:23:46 +0500 Subject: [PATCH 066/235] useVcpkgToolchainFile --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa57b45..83b8af5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,9 +39,9 @@ jobs: with: cmakeListsOrSettingsJson: CMakeSettingsJson # cmakeListsTxtPath: "SourceSDK.CAPI/CMakeLists.txt" - #useVcpkgToolchainFile: true + useVcpkgToolchainFile: true cmakeBuildType: Release - #buildDirectory: '${{ github.workspace }}/out' + buildDirectory: '${{ github.workspace }}/out' - run: tree /f - name: Upload Artifact uses: actions/upload-artifact@v2 From 46d436a3c7a3be328e9951de1ea9a4a993999219 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:26:07 +0500 Subject: [PATCH 067/235] ugh, fine --- .github/workflows/build.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 83b8af5..7d3bd0e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,8 +15,6 @@ jobs: uses: lukka/run-cmake@v2 with: cmakeListsOrSettingsJson: CMakeListsTxtBasic - # cmakeListsTxtPath: "SourceSDK.CAPI/CMakeLists.txt" - #useVcpkgToolchainFile: true cmakeBuildType: Release buildDirectory: '${{ github.workspace }}/out' - run: tree @@ -38,8 +36,6 @@ jobs: uses: lukka/run-cmake@v2 with: cmakeListsOrSettingsJson: CMakeSettingsJson - # cmakeListsTxtPath: "SourceSDK.CAPI/CMakeLists.txt" - useVcpkgToolchainFile: true cmakeBuildType: Release buildDirectory: '${{ github.workspace }}/out' - run: tree /f @@ -47,7 +43,7 @@ jobs: uses: actions/upload-artifact@v2 with: name: win-x64 - path: "out/SourceSDK.CAPI/sourcesdkc.dll" + path: "out/x64-Release/SourceSDK.CAPI/sourcesdkc.dll" retention-days: 10 if-no-files-found: error linux: From b2c9b61ca60388097a448f2cb06bc972e8ca87fb Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:28:01 +0500 Subject: [PATCH 068/235] osx --- .github/workflows/build.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7d3bd0e..211f72c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,6 +46,26 @@ jobs: path: "out/x64-Release/SourceSDK.CAPI/sourcesdkc.dll" retention-days: 10 if-no-files-found: error + osx-cmake-build: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + - uses: ilammy/msvc-dev-cmd@v1 + - name: 'CMake' + uses: lukka/run-cmake@v2 + with: + cmakeListsOrSettingsJson: CMakeListsTxtBasic + cmakeBuildType: Release + buildDirectory: '${{ github.workspace }}/out' + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: osx-x64 + path: "out/SourceSDK.CAPI/libsourcesdkc.dylib" + retention-days: 10 + if-no-files-found: error linux: runs-on: ubuntu-latest steps: From c291d0f0a527c5e9ce80ff69973848dba0fed2db Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:31:16 +0500 Subject: [PATCH 069/235] check for APPLE first --- SourceSDK.CAPI/CMakeLists.txt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index b0b7075..6ea3512 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -18,16 +18,6 @@ endif() if(WIN32) list(APPEND SOURCESDK_DEFINES "WIN64" "_WIN64" "_DLL_EXT=.dll" "WIN32") set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/x64") -elseif(UNIX) - list(APPEND SOURCESDK_DEFINES - "_DLL_EXT=.so" - "POSIX" - "_POSIX" - "LINUX" - "_LINUX" - "SWDS" - ) - set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/linux64") elseif(APPLE) list(APPEND SOURCESDK_DEFINES "_DLL_EXT=.dylib" @@ -41,6 +31,16 @@ elseif(APPLE) "SWDS" ) set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/osx64") +elseif(UNIX) + list(APPEND SOURCESDK_DEFINES + "_DLL_EXT=.so" + "POSIX" + "_POSIX" + "LINUX" + "_LINUX" + "SWDS" + ) + set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/linux64") endif() add_compile_definitions(${SOURCESDK_DEFINES}) From e3b21a5a9615d894b1a947d708fc25b1a9619278 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:35:40 +0500 Subject: [PATCH 070/235] CMAKE_CXX_STANDARD 11 --- SourceSDK.CAPI/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index 6ea3512..919c43e 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 3.8) -project("sourcesdkc") - +project("sourcesdkc" CXX) +set (CMAKE_CXX_STANDARD 11) set(SOURCESDK_DEFINES "PLATFORM_64BITS" "__x86_64__" From 6cb02eff926b8c8519878595a3271a1cefd6b1bf Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:45:49 +0500 Subject: [PATCH 071/235] use gcc --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 211f72c..c5d2a29 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,6 +59,7 @@ jobs: cmakeListsOrSettingsJson: CMakeListsTxtBasic cmakeBuildType: Release buildDirectory: '${{ github.workspace }}/out' + buildWithCMakeArgs: "-DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++" - name: Upload Artifact uses: actions/upload-artifact@v2 with: From b27e33b81f3cd8ae6e9e490ca0e14f50321fffd8 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:48:11 +0500 Subject: [PATCH 072/235] exports --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c5d2a29..f718f43 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,13 +53,15 @@ jobs: with: submodules: recursive - uses: ilammy/msvc-dev-cmd@v1 + - run: | + export CMAKE_C_COMPILER=/usr/bin/gcc + export CMAKE_CXX_COMPILER=/usr/bin/g++ - name: 'CMake' uses: lukka/run-cmake@v2 with: cmakeListsOrSettingsJson: CMakeListsTxtBasic cmakeBuildType: Release buildDirectory: '${{ github.workspace }}/out' - buildWithCMakeArgs: "-DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++" - name: Upload Artifact uses: actions/upload-artifact@v2 with: From 03dd360d6c679e003d3b34a48aed37e2c435ca3d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:58:18 +0500 Subject: [PATCH 073/235] disable osx --- .github/workflows/build.yml | 43 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f718f43..e3e38a4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,29 +46,26 @@ jobs: path: "out/x64-Release/SourceSDK.CAPI/sourcesdkc.dll" retention-days: 10 if-no-files-found: error - osx-cmake-build: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - - uses: ilammy/msvc-dev-cmd@v1 - - run: | - export CMAKE_C_COMPILER=/usr/bin/gcc - export CMAKE_CXX_COMPILER=/usr/bin/g++ - - name: 'CMake' - uses: lukka/run-cmake@v2 - with: - cmakeListsOrSettingsJson: CMakeListsTxtBasic - cmakeBuildType: Release - buildDirectory: '${{ github.workspace }}/out' - - name: Upload Artifact - uses: actions/upload-artifact@v2 - with: - name: osx-x64 - path: "out/SourceSDK.CAPI/libsourcesdkc.dylib" - retention-days: 10 - if-no-files-found: error + #osx-cmake-build: + # runs-on: macos-latest + # steps: + # - uses: actions/checkout@v2 + # with: + # submodules: recursive + # - uses: ilammy/msvc-dev-cmd@v1 + # - name: 'CMake' + # uses: lukka/run-cmake@v2 + # with: + # cmakeListsOrSettingsJson: CMakeListsTxtBasic + # cmakeBuildType: Release + # buildDirectory: '${{ github.workspace }}/out' + # - name: Upload Artifact + # uses: actions/upload-artifact@v2 + # with: + # name: osx-x64 + # path: "out/SourceSDK.CAPI/libsourcesdkc.dylib" + # retention-days: 10 + # if-no-files-found: error linux: runs-on: ubuntu-latest steps: From b01a1ef5490830e3007abcebd81d25760a10c936 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 20:58:30 +0500 Subject: [PATCH 074/235] remove tree commands --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e3e38a4..ff070e8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,6 @@ jobs: cmakeListsOrSettingsJson: CMakeListsTxtBasic cmakeBuildType: Release buildDirectory: '${{ github.workspace }}/out' - - run: tree - name: Upload Artifact uses: actions/upload-artifact@v2 with: @@ -38,7 +37,6 @@ jobs: cmakeListsOrSettingsJson: CMakeSettingsJson cmakeBuildType: Release buildDirectory: '${{ github.workspace }}/out' - - run: tree /f - name: Upload Artifact uses: actions/upload-artifact@v2 with: From 1ed6f20cd91bf3dc3943c112a3a734e16ed206af Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 21:15:56 +0500 Subject: [PATCH 075/235] artifacts whoa! --- .github/workflows/build.yml | 71 +++++++++++++++++++++---------------- SourceSDK/SourceSDK.csproj | 4 +++ 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff070e8..8d8c1b9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,18 +64,42 @@ jobs: # path: "out/SourceSDK.CAPI/libsourcesdkc.dylib" # retention-days: 10 # if-no-files-found: error - linux: + Build: + needs: [ linux-cmake-build, windows-cmake-build ] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - with: - submodules: recursive - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: dotnet-version: 5.0.100 - - name: Restore solution - run: dotnet restore SourceSDK.sln + - name: Download linux-x64 + uses: actions/download-artifact@v2 + with: + name: linux-x64 + path: SourceSDK/runtimes/linux-x64/native + - name: Download win-x64 + uses: actions/download-artifact@v2 + with: + name: win-x64 + path: SourceSDK/runtimes/win-x64/native + - name: Build Solution + run: dotnet publish SourceSDK.sln --restore --configuration Release + - name: Upload SourceSDK.dll + uses: actions/upload-artifact@v2 + with: + name: sourcesdk + path: SourceSDK/bin/Release/net5/* + - name: Upload SourceSDKTest.dll + uses: actions/upload-artifact@v2 + with: + name: sourcesdktest + path: SourceSDK.Test/bin/Release/net5/* + Test-linux: + needs: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 - name: Install Steam and Garry's Mod Dedicated Server run: | wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz @@ -88,8 +112,11 @@ jobs: mkdir ./gmod/garrysmod/lua/bin tar -xvzf gmoddotnet.tar.gz -C ./gmod/garrysmod/lua/bin rm -rfv gmoddotnet.tar.gz - - name: Build Module - run: dotnet publish SourceSDK.Test/SourceSDK.Test.csproj --configuration Release --framework net5 -o ./gmod/garrysmod/lua/bin/Modules/SourceSDKTest + - name: Download SourceSDKTest + uses: actions/download-artifact@v2 + with: + name: sourcesdktest + path: ./gmod/garrysmod/lua/bin/SourceSDKTest/ - name: Copy test.lua run: cp .github/workflows/test.lua ./gmod/garrysmod/lua/autorun - name: Run Garry's Mod @@ -104,16 +131,11 @@ jobs: with: files: "gmod/garrysmod/data/success.txt" allow_failure: true - windows-build: + Test-windows: + needs: Build runs-on: windows-latest steps: - uses: actions/checkout@v2 - - name: Setup .NET Core SDK - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 5.0.100 - - name: Restore solution - run: dotnet restore SourceSDK.sln - name: Install Steam and Garry's Mod Dedicated Server shell: bash run: | @@ -126,10 +148,11 @@ jobs: curl -o gmoddotnet.zip https://gleb-krasilich.fra1.digitaloceanspaces.com/GmodNETStorage/storage/gmod-dot-net-windows.0.7.0-beta.2.30293992.master.zip -O -L mkdir ./gmod/garrysmod/lua/bin powershell -Command 'Expand-Archive -LiteralPath ./gmoddotnet.zip -DestinationPath ./gmod/garrysmod/lua/bin' - - name: Build Solution - run: dotnet publish SourceSDK.sln - - name: Build Module - run: dotnet publish SourceSDK.Test/SourceSDK.Test.csproj --configuration Release --framework net5 -o ./gmod/garrysmod/lua/bin/Modules/SourceSDKTest + - name: Download SourceSDKTest + uses: actions/download-artifact@v2 + with: + name: sourcesdktest + path: ./gmod/garrysmod/lua/bin/SourceSDKTest/ - name: Copy test.lua run: cp .github/workflows/test.lua ./gmod/garrysmod/lua/autorun - name: Run Garry's Mod @@ -148,15 +171,3 @@ jobs: with: files: "gmod/garrysmod/data/success.txt" allow_failure: true - macos-build: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 5.0.100 - - name: Restore solution - run: dotnet restore SourceSDK.sln - - name: Build Solution - run: dotnet publish SourceSDK.sln diff --git a/SourceSDK/SourceSDK.csproj b/SourceSDK/SourceSDK.csproj index e87eea7..b12811f 100644 --- a/SourceSDK/SourceSDK.csproj +++ b/SourceSDK/SourceSDK.csproj @@ -3,4 +3,8 @@ net5 true + + + + From e7f612cc807619e9c5c30e51b1f265f6adffb0e3 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 21:17:57 +0500 Subject: [PATCH 076/235] remove --restore --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8d8c1b9..0de6846 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -84,7 +84,7 @@ jobs: name: win-x64 path: SourceSDK/runtimes/win-x64/native - name: Build Solution - run: dotnet publish SourceSDK.sln --restore --configuration Release + run: dotnet publish SourceSDK.sln --configuration Release - name: Upload SourceSDK.dll uses: actions/upload-artifact@v2 with: From 3fb0f02243721e864b781db96166b85f498bc38e Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 21:20:50 +0500 Subject: [PATCH 077/235] use publish folder --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0de6846..6da6c48 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -89,12 +89,12 @@ jobs: uses: actions/upload-artifact@v2 with: name: sourcesdk - path: SourceSDK/bin/Release/net5/* + path: SourceSDK/bin/Release/net5/publish/* - name: Upload SourceSDKTest.dll uses: actions/upload-artifact@v2 with: name: sourcesdktest - path: SourceSDK.Test/bin/Release/net5/* + path: SourceSDK.Test/bin/Release/net5/publish/* Test-linux: needs: Build runs-on: ubuntu-latest From df14233871aeeb58c7745568cd3605e7c808b216 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 21:27:54 +0500 Subject: [PATCH 078/235] SourceSDK -> GmodNET.SourceSDK --- SourceSDK.Test/SourceSDK.Test.csproj | 2 +- SourceSDK.sln | 4 ++-- SourceSDK/{SourceSDK.csproj => GmodNET.SourceSDK.csproj} | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) rename SourceSDK/{SourceSDK.csproj => GmodNET.SourceSDK.csproj} (73%) diff --git a/SourceSDK.Test/SourceSDK.Test.csproj b/SourceSDK.Test/SourceSDK.Test.csproj index 3d100c8..a85bf19 100644 --- a/SourceSDK.Test/SourceSDK.Test.csproj +++ b/SourceSDK.Test/SourceSDK.Test.csproj @@ -8,6 +8,6 @@ - + diff --git a/SourceSDK.sln b/SourceSDK.sln index 31c3631..6471806 100644 --- a/SourceSDK.sln +++ b/SourceSDK.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30914.41 MinimumVisualStudioVersion = 15.0.26124.0 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceSDK", "SourceSDK\SourceSDK.csproj", "{D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GmodNET.SourceSDK", "SourceSDK\GmodNET.SourceSDK.csproj", "{D788BA43-6EAC-4FEF-A999-7B1B8BD17ED3}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B1D17ED4-01E4-43C6-A8B2-EDF2BF351349}" ProjectSection(SolutionItems) = preProject @@ -13,7 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .github\workflows\test.lua = .github\workflows\test.lua EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceSDK.Test", "SourceSDK.Test\SourceSDK.Test.csproj", "{FA6CC35B-83AD-4FA7-9BFD-B77A6DAE735B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceSDK.Test", "SourceSDK.Test\SourceSDK.Test.csproj", "{FA6CC35B-83AD-4FA7-9BFD-B77A6DAE735B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/SourceSDK/SourceSDK.csproj b/SourceSDK/GmodNET.SourceSDK.csproj similarity index 73% rename from SourceSDK/SourceSDK.csproj rename to SourceSDK/GmodNET.SourceSDK.csproj index b12811f..012596d 100644 --- a/SourceSDK/SourceSDK.csproj +++ b/SourceSDK/GmodNET.SourceSDK.csproj @@ -2,6 +2,9 @@ net5 true + GmodNET + GmodNET.SourceSDK + true From a05403f0568b1a7994909723ef1c6bca0039aeda Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 21:33:11 +0500 Subject: [PATCH 079/235] update GmodDotNet --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6da6c48..6f7e7b6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -108,7 +108,7 @@ jobs: ./steamcmd.sh +login anonymous +force_install_dir gmod "+app_update 4020 -beta x86-64 validate" +quit - name: Install GmodDotNet run: | - wget https://gleb-krasilich.fra1.digitaloceanspaces.com/GmodNETStorage/storage/gmod-dot-net-linux.0.7.0-beta.2.30293992.master.tar.gz -O gmoddotnet.tar.gz + wget https://gleb-krasilich.fra1.digitaloceanspaces.com/GmodNETStorage/storage/gmod-dot-net-linux.0.7.0-beta.2.32934270.master.tar.gz -O gmoddotnet.tar.gz mkdir ./gmod/garrysmod/lua/bin tar -xvzf gmoddotnet.tar.gz -C ./gmod/garrysmod/lua/bin rm -rfv gmoddotnet.tar.gz @@ -145,7 +145,7 @@ jobs: - name: Install GmodDotNet shell: bash run: | - curl -o gmoddotnet.zip https://gleb-krasilich.fra1.digitaloceanspaces.com/GmodNETStorage/storage/gmod-dot-net-windows.0.7.0-beta.2.30293992.master.zip -O -L + curl -o gmoddotnet.zip https://gleb-krasilich.fra1.digitaloceanspaces.com/GmodNETStorage/storage/gmod-dot-net-windows.0.7.0-beta.2.32934270.master.zip -O -L mkdir ./gmod/garrysmod/lua/bin powershell -Command 'Expand-Archive -LiteralPath ./gmoddotnet.zip -DestinationPath ./gmod/garrysmod/lua/bin' - name: Download SourceSDKTest From 36077682561c21b001084dadf425e9ebcbcc4426 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 21:38:40 +0500 Subject: [PATCH 080/235] tree --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6f7e7b6..f53a19d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -117,6 +117,7 @@ jobs: with: name: sourcesdktest path: ./gmod/garrysmod/lua/bin/SourceSDKTest/ + - run: tree - name: Copy test.lua run: cp .github/workflows/test.lua ./gmod/garrysmod/lua/autorun - name: Run Garry's Mod From 89d6efcb25d91ac356d15391a1d221568c85f8c1 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 21:42:01 +0500 Subject: [PATCH 081/235] copy to output --- SourceSDK/GmodNET.SourceSDK.csproj | 12 ++++++++++-- SourceSDK/runtimes/win-x64/native/sourcesdkc.dll | Bin 0 -> 9728 bytes 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 SourceSDK/runtimes/win-x64/native/sourcesdkc.dll diff --git a/SourceSDK/GmodNET.SourceSDK.csproj b/SourceSDK/GmodNET.SourceSDK.csproj index 012596d..76cb937 100644 --- a/SourceSDK/GmodNET.SourceSDK.csproj +++ b/SourceSDK/GmodNET.SourceSDK.csproj @@ -7,7 +7,15 @@ true - - + + + + + + PreserveNewest + + + PreserveNewest + diff --git a/SourceSDK/runtimes/win-x64/native/sourcesdkc.dll b/SourceSDK/runtimes/win-x64/native/sourcesdkc.dll new file mode 100644 index 0000000000000000000000000000000000000000..74d09d56ad309636d0f4d76b2100092eca0a564a GIT binary patch literal 9728 zcmeHM4RBl4mAV^TUTGu;_4!%`=7cVwI;4kXkK-K~LP;%-^`5{ImTmL_C( z-+t%)I5s~WI=h`=I^6NS-?`_Ud+xpGp8KQc^>^-P#f-5MWL;-$2uLYll)t~Y0P)=G zkIZFHm7iQRy6ZMqUzZP0rh z1Vk4x<}z59k@bK9C$|28#9N?hHnQP^b(1rABV)VJ^s|4)ScGh%c#1j-FlKg0Or$N0 z2?UE6TL}E9vvZGm?OA8>Ehy5@W1T0Rb3{ z^shjkkpdWXgQ>UXv`4|Lr(zCNCC1Z$x<9V!zbh*vR8*Z zBLxgSF`0&RJpq-O^iNJ;_5)*8g8#k2>w>frhoe!@;heV`WJJ8^<%&(-&zQdVZq zI+S`UuFAgWP%4HfymP3{$BMtIr*w z2CeFgTrCc(RS&~hQ2&|kEQcw>N0UYV0$190IS7Gv8l4)R5wguMf>D(Doc0b){p%2D z{V<$e{4{MiOye6EtN&DB-%qtCK)pM@;MMG}9NKT8t&U6{G6(SjB>VTD;ObGH+bo20 zf!bUI>%+@7-C-NzhZW*%(ZoNPc>Nmy5h|0#hJi#j}0?=RBl4cpf%+3{ALFt z(>GaT>*}79RrVMrUH(@|s*cc7_F^>x!F!_jjM(dD#4|0P(5hZgU*YOo*d!UJMiCoU zkEt(l3Xtg_!1_ned;>$b+6(PmJ!kF%=L0y{`7@1&PA_@rGoV(FWE7qiYZ1xoYjw|; zapH2drIzPfs&!8rYHEQmBRXKx`SpTXr?XsbL7cCz=ED;L_k;GgRCE6@Kdc)GmTo}B zf4M8}4h{31(@8_XXgUAg7^>$Npo$^iJ%SfP&JOxWzIL6=gy#G@^|D@YJ0EQwp4o>C&c76+D6o|b^AHMRQoC_gASuZYJ&r)8L@=}=t0w-Z7U7EzCwl?U7>9?E2Y|(Kun&S(O$a^9BnNM zi+MRdl62lF-dZb2F4BfVoSe~)V(THgugYF>Wab&+%hi)yJ*InZhhw?g=H0A@y%8&V zl5~V9UOEpDLQkTtG1uLO5v3Z=9-mJ!}cdzv|# zGWF%mw(Ld6eP7mI!y;fM>-%5LcrnUGGVDZKOr1u(it4{LbsFGhf2TX`{6`$hJUgnt z0iY@&s#gM@bG~*B?gGQ(7{Xx~W!ifvj5xp%Jv_AjPR2S{Iz4A}J=4qM zRU8B^04G85^Ltm)J1`R+s>I>hxiVOrX$ybmS@(~FH9Y^tT3$Q`(#7+0_Js3up69t5 zZ|mxxDYfcf&Izv`mMYY>WyQnc)di`HXP>Q~JncWlaY$06)MR&h*;k3GKwP?jMMjv` zj+j2$_p){juJxaSUn=`v&6M)5c`7g!)0MU#^;%42-^)r#->J+T?F}@*nSL5zPncpX z@4N{ON3x5{0oY%3$F}qQkGz3PnBv}Z1vo{0`S8^c>Ykf%QKHKd^@Wo+9fl#M9mUSW zxby3$fI*IYg6_GRB(T%OvmM?Qkme^0si72B zM|m#n^@VX_=JOf}P^~AML^DS8X&o;4s5 zeskdZvOF)={@J)o9`TOBS$ywN^4Z-u&&Zd?uI2e_-=Qs;Z$1Z@yaG2q%^yeL<76~D zQpQ)Gmd=XiR@Fu%^xQaS2A6x{oEA|TiQKkUFui`>iI-y4=|LaOsA zv<+rQ9ig1_36PVe;0=Hn!dzG=&o8Z>+I1t16}^X4x;abizTHQDRW4VwR1TwUH<}!C zeiti9)SoTo#zhFI}{i@pL_lp9CsG5qp?? z9nM$1{*JDP)s`N$y^E{sw`es`Crdu;8FXQ^@E_m10s|?y4-Bir;2VSgwD`n%fd9EU zq_5v(;^P(`vGC^>e%sRPweT(r6-&O{s?WF3W#N=1wR_gVVf!f{Lf zoP|Rc{>Z`_OYd!~ZreF;HeD@w}cWq8D|Tn z6?Fdn5mK#h_U9wJi*do^YZlu4Y5XINXWIV9Bqpr!O<8!s!ikTV*T*#b;cECAFo3(+ z_!j2vPLa|8ep}oOw0T~ikNq2Xe>ctRWlS)?tu-X*TbB1PAY$+@qfl({`Qn}1KrCXc zjOyz);5ol82$Ge}=HZ2kPj9n$t%hFhY@VSf%;H51z53ZaL(eyh*JkLgn9Vcv0^k)K z7@zfhk7AQz)U11V?%dh2m8Ma<*qVo=#J#OS!=5mUcc)>mekQNY)bq{anR+Y0>!p5s z&F_HrchCmWtkd_)D`hpXSJPPC{)vapMkI5xb+U z@!Nax7*BL2;?b^Hsv{{%j4cLVRyv}}jvg_ZNOh*89ipsA=^fEzLdHKL z*064|TNXiWTDPJ7_O{mbEz6esjP=5Kj1~z+5v6YSxyy7^WVf)WEOtdZ6G;f8w79h_ z8c(M>6WcP97)`|_DSclwCT-h}ADL#$L@b%uIV}=X+Y?ec)h(vb^YU35>6F-;P@+m~ zYf_|tJw(M`F`iMx=q$li=#TUmi}fUybjwTbOQe>>C1nZz_oXDd#U;sQOO`D$ClV?7 zVn&p9L`11GEp^9IadBN5T5!*GMYoB{x{M@Y91$svV3k`tSltY6TbCrpI>2O8#5KdW z4IKn!3TL8Nog~qw1crWiyi}(;CBz{5ME=^3xOevCj62`-v#^$avSUup0oIb3~vy!L)eNOhE5px z3yU5H_TX*e1)uN$GU*WhlSPjK7hHq4BKQk|n~{4#6XJKHK_3LJ#Ji^t{6XN8$Ol1> z0qOU^0BAybk0}@rA-%6PnyLyxXi}t%thC~_@G-6V&30%h8al4oll2kU=#pKr1_Vm4?R3~H- z!8qN}&2^ozq%790X<9mMdv@b#`!h5?(0kL;Sz~QlIz4GLZ(3^mb4?@|35G(gx8JsT vvqk)0>hw0n9~&Q-7|;f$1}+SYKQ{H)g~tva8aVXBLxYDP`ZWCsd*FWoL&>#i literal 0 HcmV?d00001 From 17a06befa4fd9dc41bccb3566c629aa261ee5c57 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 21:52:31 +0500 Subject: [PATCH 082/235] fix download path --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f53a19d..14188ae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -116,7 +116,7 @@ jobs: uses: actions/download-artifact@v2 with: name: sourcesdktest - path: ./gmod/garrysmod/lua/bin/SourceSDKTest/ + path: ./gmod/garrysmod/lua/bin/Modules/SourceSDKTest/ - run: tree - name: Copy test.lua run: cp .github/workflows/test.lua ./gmod/garrysmod/lua/autorun @@ -153,7 +153,7 @@ jobs: uses: actions/download-artifact@v2 with: name: sourcesdktest - path: ./gmod/garrysmod/lua/bin/SourceSDKTest/ + path: ./gmod/garrysmod/lua/bin/Modules/SourceSDKTest/ - name: Copy test.lua run: cp .github/workflows/test.lua ./gmod/garrysmod/lua/autorun - name: Run Garry's Mod From 851df19e352ae5448392fe27cb3e3c51fd8a9714 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 22:37:43 +0500 Subject: [PATCH 083/235] use GmodNET.SourceSDK namespace NativeLibraryResolver --- SourceSDK.Test/TestModule.cs | 6 ++-- SourceSDK/GmodNET.SourceSDK.csproj | 15 ++++---- SourceSDK/NativeLibraryResolver.cs | 33 ++++++++++++++++++ SourceSDK/public/Color.cs | 2 +- SourceSDK/public/filesystemh.cs | 4 ++- SourceSDK/public/tier0/dbg.cs | 3 +- .../linux-x64/native/libsourcesdkc.so | Bin 0 -> 7680 bytes SourceSDK/tier1/interfaceh.cs | 2 +- 8 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 SourceSDK/NativeLibraryResolver.cs create mode 100644 SourceSDK/runtimes/linux-x64/native/libsourcesdkc.so diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 04b444c..e31bd6c 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -1,10 +1,10 @@ using GmodNET.API; -using SourceSDK; -using SourceSDK.Tier0; -using SourceSDK.Tier1; using System; using System.Diagnostics; using System.Runtime.InteropServices; +using GmodNET.SourceSDK; +using GmodNET.SourceSDK.Tier0; +using GmodNET.SourceSDK.Tier1; namespace SourceSDKTest { diff --git a/SourceSDK/GmodNET.SourceSDK.csproj b/SourceSDK/GmodNET.SourceSDK.csproj index 76cb937..185e610 100644 --- a/SourceSDK/GmodNET.SourceSDK.csproj +++ b/SourceSDK/GmodNET.SourceSDK.csproj @@ -7,15 +7,14 @@ true - - - - - - PreserveNewest - - + + True + runtimes\ + False PreserveNewest + PreserveNewest + %(Identity) + diff --git a/SourceSDK/NativeLibraryResolver.cs b/SourceSDK/NativeLibraryResolver.cs new file mode 100644 index 0000000..4573cdc --- /dev/null +++ b/SourceSDK/NativeLibraryResolver.cs @@ -0,0 +1,33 @@ +using System; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; + +namespace GmodNET.SourceSDK +{ + internal class NativeLibraryResolver + { + internal static Assembly assembly = typeof(NativeLibraryResolver).Assembly; + internal static string platformIdentifier = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win-x64" : (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "linux-x64" : "osx-x64"); + internal static string lib = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "sourcesdkc.dll" : "libsourcesdkc.so"; + internal static void Init() + { + NativeLibrary.SetDllImportResolver(assembly, (libName, asm, searchPath) => + { + if (asm == assembly && libName == "sourcesdkc") + { + string path = Path.Combine(Path.GetDirectoryName(assembly.Location), $"runtimes/{platformIdentifier}/native/{lib}"); + if (File.Exists(path)) + { + return NativeLibrary.Load(path); + } + else + { + return NativeLibrary.Load("sourcesdkc"); + } + } + return IntPtr.Zero; + }); + } + } +} diff --git a/SourceSDK/public/Color.cs b/SourceSDK/public/Color.cs index 00df08a..00e3715 100644 --- a/SourceSDK/public/Color.cs +++ b/SourceSDK/public/Color.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace SourceSDK +namespace GmodNET.SourceSDK { /// /// Color struct diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 5b3961e..7da4c01 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -1,10 +1,12 @@ using System; using System.Runtime.InteropServices; -namespace SourceSDK +namespace GmodNET.SourceSDK { public class IFileSystem { + static IFileSystem() => NativeLibraryResolver.Init(); + private IntPtr ptr; public IFileSystem(IntPtr ptr) diff --git a/SourceSDK/public/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs index aa2d657..a9b28cf 100644 --- a/SourceSDK/public/tier0/dbg.cs +++ b/SourceSDK/public/tier0/dbg.cs @@ -1,8 +1,7 @@ using System; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace SourceSDK.Tier0 +namespace GmodNET.SourceSDK.Tier0 { /// /// "public/tier0/dbg.h" diff --git a/SourceSDK/runtimes/linux-x64/native/libsourcesdkc.so b/SourceSDK/runtimes/linux-x64/native/libsourcesdkc.so new file mode 100644 index 0000000000000000000000000000000000000000..ceb0168430f5e2dae17b61f03a2ed50688ee1d31 GIT binary patch literal 7680 zcmeHMZ)hCH6(8xWO0s3?D%-VUyLgkh)DHEY9LKg4qeik$^2)L0i~fKUYF2x9E8R7B zx7WShMoLN}a9nJJ( z{oM{8Sd=#J^MKz6^7CTjyej110~%)=BK^M3?ZD;`_MZ^)22ixKAn;29{~VWJ%aUS0 z379cmpDJ1{x%nDw$(Ox?uWkwOjPe zw1EbULjGwGd}4S{cmH6%V2;j!m14@MRK{|)yJvsO&X=4~)37tSl;Pwm17AnsM{7zS z7^;jqrcnf$p%q)YK&vp>EYr=b;TSN{bfx0Y6QEL-C305LOxSLzWZH?REc?mC;i8pI zTF$WPsH2u^XUx&$qqV`HS?%vj4JE*ZS-p~dGEw1bP}^Mu4;GC=qL5D~%5J)l&p@^0 zPVaw+yPnP)IwzLIOPdqt3gNE_yhH3S!iisKQ@A}8!*__vVhG1QP32k$$1{z}%@7{m zB1<70-(e~rg>X81uuVJlL6bJuuxYKrw9^-ydT&8H^_!;4%-h!vkoSd+@Y}Y%7izz2 zR@meVWbYrBC)Kv?&v6#pwR1hUL10`v*KiA{*8P!o_J(s0n0_5uFuneycWp)I;xE#~YE@>BUKBCoK(cW2hI>6v#!e9#;q%p|$W_$7=#@vK< zs%JCS#&J9?+FZ{O;BM~rJnyCkKUW(1fUiUKS)2^at8IJI7eD#eNs#b)ZLU$9>(#V_ z4S#4-n5$`X&%#(XYjY!-)_uwC^m$*Vd%@i)wZ}!fH=+6VyuS#FQ-J=s{n-v!V(3E0 zF2(~BFL4-pc{u3BmxPWIQK^m8*F5Tpc}4rf@xyqj&-WW)p-=x1ToAF?cKTZZ9B4q_ z&qO5M3DGy%1*!kpJgWB}Uk_TN{d_WKf>8(SR1U@mYYBtP1yk_XF(tMC7uOjai|-nL zyWqREHFgk|oqrDI|K)iTP=5_5j`;%6CFJjT-c_LSWzYK~&{?4KKvS?Qe+Co_e#^1c zJw3wersH*6TN;~QfCFR)VEE1K0$V(0XpIlHb{uJ2_f*p?dt}SO2lno`5A{$V$Dx2+ z69S^3&R5`BgfUzSVP&Yl4C8n;ggpoKYoJfxG}L_so-cuJ_&fR&z^;Dmd9W+*mb)If z>w&u-2s}XX6va=U7cCzPO0g2f;p+uX@$o%^r#Nk^;OR`;B6y0|@NC3F?f+c%EaaC& z@I~SN84*NbyoRMq9A4tO${ZoT&Todhu3v)KOT>X9y!S6vAVU2v3VDj*NdLCyk0-Dr zr;)#f_16J*DzYYY8+OV7C6)pt8vf6<`{gXmukwxD$>TNveO*oMM5yxsd1m< z_SXgZf@=8|_6lu`P(zHZ5Aq-(80@z)+TYc98{|QhFvROIxT(^8B-|KdpM{{KmV7&- z^{$qW-gmJ*7DOj2(ij`8VYj>$#INCNR1f#yxbP>%2=}iduL^lZ@_(nmCnUUI;B>wK z%gf{NTNk>oi`SXuI3D%qw*kj-(s{*=z|Z%%d~{t_8~%IXTQY$~v3%G)&q;eeaTKSUkRpc$e(Y~BV`OYfx z=K-&kU->2A?KR%7i(EeHA3R^sj+_VjEw>ZR1HC73Ie)VZxFY$0v-;tq#}D-#)%A*- z)`#@!1caI?ms!SkDvmojsb<(p(nfcRdIr-r6-a<&Eq$tBrHz7~bu7E08}2mASjBR| zbj+-JV1IX4Z6Tfx(hb`-W*~Fo*fVU>Hj1X6b&JIrPziB7e^e!^>w_bG#|HF);Uwml zl8+Df9UJNgEyyPksAnsdo-;~W%q;1UN7M&2p{6BA7|s3o;Na-Mm_F8b=;#2L`c#=E zDJ$itxiG<1JBjrlB%(esJr+(j`N=eqg~H5JIE58SSA`oXza=HQu>9({8?y-JQ=e&gG0sj;Yz15@`C=v6*U{1p`5*a(}4hf}>7Z4pSX-8h-h} zRWm0RIF|(#;(Qff?v`n`Xguw>j&|r z=z#V)86Z8P=OulLYdVBJ$;tY}zX27Lq4CrILdq)o!X2c}{CF)oPtxBNNct7h4^!HE zVbPT6|C(?-{_pcecxXQ47u?@8_OO2ECZAg`8K-_p79zWv`aR;{xJ-hA%KHBXTj844 literal 0 HcmV?d00001 diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index d3d55fb..40ac409 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.InteropServices; -namespace SourceSDK.Tier1 +namespace GmodNET.SourceSDK.Tier1 { public static class interfaceh { From 89100f12784fddbd014bffaf6b6e239f3ede51db Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 22:43:32 +0500 Subject: [PATCH 084/235] add .so extension --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index e31bd6c..9636c08 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -58,7 +58,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl } else { - path = "filesystem_stdio"; + path = "filesystem_stdio.so"; } Console.WriteLine("Getting factory"); From 9faecaca456e8e73564d062cda85cd8f3d19a7f6 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 22:48:43 +0500 Subject: [PATCH 085/235] don't check --- SourceSDK.Test/TestModule.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 9636c08..fa01b95 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -72,16 +72,16 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine($"result is {returnCode}"); - if (returnCode == interfaceh.IFACE.OK) - { + //if (returnCode == interfaceh.IFACE.OK) + //{ IFileSystem fileSystem = new(iFileSystemPtr); Console.WriteLine("PrintSearchPaths"); fileSystem.PrintSearchPaths(); Console.WriteLine("IsSteam"); Console.WriteLine(fileSystem.IsSteam()); - } - else throw new EntryPointNotFoundException(); + //} + //else throw new EntryPointNotFoundException(); } }); From bfb6393272f7f346a7cd61ef5b40b6216dbb78d3 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 22:59:48 +0500 Subject: [PATCH 086/235] throw exception on IntPtr.Zero make ptr readonly add check --- SourceSDK.Test/TestModule.cs | 8 ++++---- SourceSDK/public/filesystemh.cs | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index fa01b95..9636c08 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -72,16 +72,16 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine($"result is {returnCode}"); - //if (returnCode == interfaceh.IFACE.OK) - //{ + if (returnCode == interfaceh.IFACE.OK) + { IFileSystem fileSystem = new(iFileSystemPtr); Console.WriteLine("PrintSearchPaths"); fileSystem.PrintSearchPaths(); Console.WriteLine("IsSteam"); Console.WriteLine(fileSystem.IsSteam()); - //} - //else throw new EntryPointNotFoundException(); + } + else throw new EntryPointNotFoundException(); } }); diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 7da4c01..0e010f8 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -7,10 +7,11 @@ public class IFileSystem { static IFileSystem() => NativeLibraryResolver.Init(); - private IntPtr ptr; + private readonly IntPtr ptr; public IFileSystem(IntPtr ptr) { + if (ptr == IntPtr.Zero) throw new ArgumentNullException(nameof(ptr), "Passing invalid pointer will cause crash"); this.ptr = ptr; } From e2149290c91d485069a09f75129ef6c338d3432c Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 7 Feb 2021 23:00:29 +0500 Subject: [PATCH 087/235] use string as argument to CreateInterfaceFn --- SourceSDK.Test/TestModule.cs | 4 +--- SourceSDK/tier1/interfaceh.cs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 9636c08..958e721 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -66,9 +66,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("factory()"); - IntPtr interfaceNamePointer = Marshal.StringToHGlobalAnsi("VFileSystem022"); - IntPtr iFileSystemPtr = factory(interfaceNamePointer, out interfaceh.IFACE returnCode); - Marshal.FreeHGlobal(interfaceNamePointer); + IntPtr iFileSystemPtr = factory("VFileSystem022", out interfaceh.IFACE returnCode); Console.WriteLine($"result is {returnCode}"); diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index 40ac409..d4c646e 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -12,7 +12,7 @@ public enum IFACE } public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; - public unsafe delegate IntPtr CreateInterfaceFn(IntPtr name, out IFACE returnCode); + public unsafe delegate IntPtr CreateInterfaceFn(string name, out IFACE returnCode); public static CreateInterfaceFn Sys_GetFactory(IntPtr module) { From 192980b38a347304928fceb66ed03499cc755efb Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 10:03:27 +0500 Subject: [PATCH 088/235] IAppSystem c --- SourceSDK.CAPI/CMakeLists.txt | 2 +- SourceSDK.CAPI/iappsystem_c.cpp | 46 +++++++++ SourceSDK.Test/TestModule.cs | 6 +- SourceSDK/NativeLibraryResolver.cs | 1 + SourceSDK/public/appframework/iappsystem.cs | 107 ++++++++++++++++++-- SourceSDK/public/filesystemh.cs | 11 +- SourceSDK/tier1/interfaceh.cs | 15 +-- 7 files changed, 162 insertions(+), 26 deletions(-) create mode 100644 SourceSDK.CAPI/iappsystem_c.cpp diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index 919c43e..cb250b3 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -47,7 +47,7 @@ add_compile_definitions(${SOURCESDK_DEFINES}) link_directories("${SOURCESDK_LIBDIRS}") link_libraries(tier0) -add_library (sourcesdkc MODULE "SourceSDK.CAPI.cpp" "SourceSDK.CAPI.h") +add_library (sourcesdkc MODULE "SourceSDK.CAPI.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp") target_include_directories(sourcesdkc PUBLIC#SYSTEM INTERFACE #"${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/common" diff --git a/SourceSDK.CAPI/iappsystem_c.cpp b/SourceSDK.CAPI/iappsystem_c.cpp new file mode 100644 index 0000000..02130be --- /dev/null +++ b/SourceSDK.CAPI/iappsystem_c.cpp @@ -0,0 +1,46 @@ +#include + +DLL_EXPORT bool IAppSystem_Connect(void** ptr, CreateInterfaceFn factory) { + IAppSystem* iAppSystem = (IAppSystem*)ptr; + return iAppSystem->Connect(factory); +} + +DLL_EXPORT void IAppSystem_Disconnect(void** ptr) { + IAppSystem* iAppSystem = (IAppSystem*)ptr; + iAppSystem->Disconnect(); +} + +DLL_EXPORT void* IAppSystem_QueryInterface(void** ptr, const char* pInterfaceName) { + IAppSystem* iAppSystem = (IAppSystem*)ptr; + return iAppSystem->QueryInterface(pInterfaceName); +} + +DLL_EXPORT InitReturnVal_t IAppSystem_Init(void** ptr) { + IAppSystem* iAppSystem = (IAppSystem*)ptr; + return iAppSystem->Init(); +} + +DLL_EXPORT void IAppSystem_Shutdown(void** ptr) { + IAppSystem* iAppSystem = (IAppSystem*)ptr; + iAppSystem->Shutdown(); +} + +DLL_EXPORT const AppSystemInfo_t* IAppSystem_GetDependencies(void** ptr) { + IAppSystem* iAppSystem = (IAppSystem*)ptr; + return iAppSystem->GetDependencies(); +} + +DLL_EXPORT AppSystemTier_t IAppSystem_GetTier(void** ptr) { + IAppSystem* iAppSystem = (IAppSystem*)ptr; + return iAppSystem->GetTier(); +} + +DLL_EXPORT void IAppSystem_Reconnect(void** ptr, CreateInterfaceFn factory, const char* pInterfaceName) { + IAppSystem* iAppSystem = (IAppSystem*)ptr; + return iAppSystem->Reconnect(factory, pInterfaceName); +} + +DLL_EXPORT bool IAppSystem_IsSingleton(void** ptr) { + IAppSystem* iAppSystem = (IAppSystem*)ptr; + return iAppSystem->IsSingleton(); +} diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 958e721..c617d52 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -62,15 +62,15 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl } Console.WriteLine("Getting factory"); - interfaceh.CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); + CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); Console.WriteLine("factory()"); - IntPtr iFileSystemPtr = factory("VFileSystem022", out interfaceh.IFACE returnCode); + IntPtr iFileSystemPtr = factory("VFileSystem022", out IFACE returnCode); Console.WriteLine($"result is {returnCode}"); - if (returnCode == interfaceh.IFACE.OK) + if (returnCode == IFACE.OK) { IFileSystem fileSystem = new(iFileSystemPtr); diff --git a/SourceSDK/NativeLibraryResolver.cs b/SourceSDK/NativeLibraryResolver.cs index 4573cdc..41918ea 100644 --- a/SourceSDK/NativeLibraryResolver.cs +++ b/SourceSDK/NativeLibraryResolver.cs @@ -10,6 +10,7 @@ internal class NativeLibraryResolver internal static Assembly assembly = typeof(NativeLibraryResolver).Assembly; internal static string platformIdentifier = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win-x64" : (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "linux-x64" : "osx-x64"); internal static string lib = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "sourcesdkc.dll" : "libsourcesdkc.so"; + internal static void Init() { NativeLibrary.SetDllImportResolver(assembly, (libName, asm, searchPath) => diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index 7119288..699dfcb 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -1,13 +1,106 @@ +using GmodNET.SourceSDK.Tier1; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.InteropServices; -namespace SourceSDK.appframework +namespace GmodNET.SourceSDK.AppFramework { - public interface IAppSystem + public enum InitReturnVal_t { - //TODO + INIT_FAILED = 0, + INIT_OK = 1, + + INIT_LAST_VAL = 2, + }; + + public struct AppSystemInfo_t + { + public string moduleName; + public string interfaceName; + }; + + public enum AppSystemTier_t + { + APP_SYSTEM_TIER0 = 0, + APP_SYSTEM_TIER1 = 1, + APP_SYSTEM_TIER2 = 2, + APP_SYSTEM_TIER3 = 3, + + APP_SYSTEM_TIER_OTHER = 4, + }; + + public abstract class IAppSystem + { + static IAppSystem() => NativeLibraryResolver.Init(); + + protected readonly IntPtr ptr; + + public IAppSystem(IntPtr ptr) + { + if (ptr == IntPtr.Zero) throw new ArgumentNullException(nameof(ptr), "Passing invalid pointer will cause crash"); + this.ptr = ptr; + } + + [DllImport("sourcesdkc")] + internal static extern bool IAppSystem_Connect(IntPtr ptr, CreateInterfaceFn factory); + public bool Connect(CreateInterfaceFn factory) + { + return IAppSystem_Connect(ptr, factory); + } + + [DllImport("sourcesdkc")] + internal static extern void IAppSystem_Disconnect(IntPtr ptr); + public void Disconnect() + { + IAppSystem_Disconnect(ptr); + } + + [DllImport("sourcesdkc")] + internal static extern IntPtr IAppSystem_QueryInterface(IntPtr ptr, string interfaceName); + public IntPtr QueryInterface(string interfaceName) + { + return IAppSystem_QueryInterface(ptr, interfaceName); + } + + [DllImport("sourcesdkc")] + internal static extern InitReturnVal_t IAppSystem_Init(IntPtr ptr); + public InitReturnVal_t Init() + { + return IAppSystem_Init(ptr); + } + + [DllImport("sourcesdkc")] + internal static extern void IAppSystem_Shutdown(IntPtr ptr); + public void Shutdown() + { + IAppSystem_Shutdown(ptr); + } + + [DllImport("sourcesdkc")] + internal static extern AppSystemInfo_t[] IAppSystem_GetDependencies(IntPtr ptr); + public AppSystemInfo_t[] GetDependencies() + { + return IAppSystem_GetDependencies(ptr); + } + + [DllImport("sourcesdkc")] + internal static extern AppSystemTier_t IAppSystem_GetTier(IntPtr ptr); + public AppSystemTier_t GetTier() + { + return IAppSystem_GetTier(ptr); + } + + [DllImport("sourcesdkc")] + internal static extern void IAppSystem_Reconnect(IntPtr ptr, CreateInterfaceFn factory, string interfaceName); + public void Reconnect(CreateInterfaceFn factory, string interfaceName) + { + IAppSystem_Reconnect(ptr, factory, interfaceName); + } + + [DllImport("sourcesdkc")] + internal static extern bool IAppSystem_IsSingleton(IntPtr ptr); + public bool IsSingleton() + { + return IAppSystem_IsSingleton(ptr); + } } } diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 0e010f8..6d0c84b 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -1,19 +1,14 @@ +using GmodNET.SourceSDK.AppFramework; using System; using System.Runtime.InteropServices; namespace GmodNET.SourceSDK { - public class IFileSystem + public class IFileSystem : IAppSystem { static IFileSystem() => NativeLibraryResolver.Init(); - private readonly IntPtr ptr; - - public IFileSystem(IntPtr ptr) - { - if (ptr == IntPtr.Zero) throw new ArgumentNullException(nameof(ptr), "Passing invalid pointer will cause crash"); - this.ptr = ptr; - } + public IFileSystem(IntPtr ptr) : base(ptr) { } [DllImport("sourcesdkc")] internal static extern bool IFileSystem_IsSteam(IntPtr ptr); diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index d4c646e..af3d238 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -3,17 +3,17 @@ namespace GmodNET.SourceSDK.Tier1 { + public enum IFACE + { + OK = 0, + FAILED = 1 + } + + public delegate IntPtr CreateInterfaceFn(string name, out IFACE returnCode); public static class interfaceh { - public enum IFACE - { - OK = 0, - FAILED = 1 - } public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; - public unsafe delegate IntPtr CreateInterfaceFn(string name, out IFACE returnCode); - public static CreateInterfaceFn Sys_GetFactory(IntPtr module) { IntPtr createInterfaceFnPtr = NativeLibrary.GetExport(module, CREATEINTERFACE_PROCNAME); @@ -23,6 +23,7 @@ public static CreateInterfaceFn Sys_GetFactory(IntPtr module) return Marshal.GetDelegateForFunctionPointer(createInterfaceFnPtr); } + public static CreateInterfaceFn Sys_GetFactory(string module) { IntPtr handle = NativeLibrary.Load(module); From ef6d58f0451adec0b5d003853fd270a28aa40891 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 10:10:03 +0500 Subject: [PATCH 089/235] fix NativeLibraryResolver --- SourceSDK/NativeLibraryResolver.cs | 30 ++++++++++++++++++------------ SourceSDK/public/filesystemh.cs | 2 -- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/SourceSDK/NativeLibraryResolver.cs b/SourceSDK/NativeLibraryResolver.cs index 41918ea..fcaaa39 100644 --- a/SourceSDK/NativeLibraryResolver.cs +++ b/SourceSDK/NativeLibraryResolver.cs @@ -11,24 +11,30 @@ internal class NativeLibraryResolver internal static string platformIdentifier = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win-x64" : (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "linux-x64" : "osx-x64"); internal static string lib = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "sourcesdkc.dll" : "libsourcesdkc.so"; + internal static bool initializated = false; + internal static void Init() { - NativeLibrary.SetDllImportResolver(assembly, (libName, asm, searchPath) => + if (!initializated) { - if (asm == assembly && libName == "sourcesdkc") + NativeLibrary.SetDllImportResolver(assembly, (libName, asm, searchPath) => { - string path = Path.Combine(Path.GetDirectoryName(assembly.Location), $"runtimes/{platformIdentifier}/native/{lib}"); - if (File.Exists(path)) - { - return NativeLibrary.Load(path); - } - else + if (asm == assembly && libName == "sourcesdkc") { - return NativeLibrary.Load("sourcesdkc"); + string path = Path.Combine(Path.GetDirectoryName(assembly.Location), $"runtimes/{platformIdentifier}/native/{lib}"); + if (File.Exists(path)) + { + return NativeLibrary.Load(path); + } + else + { + return NativeLibrary.Load("sourcesdkc"); + } } - } - return IntPtr.Zero; - }); + return IntPtr.Zero; + }); + initializated = true; + } } } } diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 6d0c84b..1a5ca46 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -6,8 +6,6 @@ namespace GmodNET.SourceSDK { public class IFileSystem : IAppSystem { - static IFileSystem() => NativeLibraryResolver.Init(); - public IFileSystem(IntPtr ptr) : base(ptr) { } [DllImport("sourcesdkc")] From 2bdb25f3427d2cb453628645606c635360f1bcca Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 10:16:32 +0500 Subject: [PATCH 090/235] add const FILESYSTEM_INTERFACE_VERSION add MarshalAsAttribute --- SourceSDK.Test/TestModule.cs | 2 +- SourceSDK/public/appframework/iappsystem.cs | 2 ++ SourceSDK/public/filesystemh.cs | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index c617d52..91ca23b 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -66,7 +66,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("factory()"); - IntPtr iFileSystemPtr = factory("VFileSystem022", out IFACE returnCode); + IntPtr iFileSystemPtr = factory(IFileSystem.FILESYSTEM_INTERFACE_VERSION, out IFACE returnCode); Console.WriteLine($"result is {returnCode}"); diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index 699dfcb..323b62b 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -14,7 +14,9 @@ public enum InitReturnVal_t public struct AppSystemInfo_t { + [MarshalAs(UnmanagedType.LPStr)] public string moduleName; + [MarshalAs(UnmanagedType.LPStr)] public string interfaceName; }; diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 1a5ca46..c12f616 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -6,6 +6,8 @@ namespace GmodNET.SourceSDK { public class IFileSystem : IAppSystem { + public const string FILESYSTEM_INTERFACE_VERSION = "VFileSystem022"; + public IFileSystem(IntPtr ptr) : base(ptr) { } [DllImport("sourcesdkc")] From 40444c33a9ab0b0721e3a319be3ef73afa4bbc9b Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 10:36:40 +0500 Subject: [PATCH 091/235] IBaseFileSystem c api rename SourceSDK.CAPI.cpp to filesystem_c.cpp --- SourceSDK.CAPI/CMakeLists.txt | 2 +- SourceSDK.CAPI/SourceSDK.CAPI.cpp | 11 ---- SourceSDK.CAPI/filesystem_c.cpp | 100 ++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 12 deletions(-) delete mode 100644 SourceSDK.CAPI/SourceSDK.CAPI.cpp create mode 100644 SourceSDK.CAPI/filesystem_c.cpp diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index cb250b3..2336711 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -47,7 +47,7 @@ add_compile_definitions(${SOURCESDK_DEFINES}) link_directories("${SOURCESDK_LIBDIRS}") link_libraries(tier0) -add_library (sourcesdkc MODULE "SourceSDK.CAPI.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp") +add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp") target_include_directories(sourcesdkc PUBLIC#SYSTEM INTERFACE #"${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/common" diff --git a/SourceSDK.CAPI/SourceSDK.CAPI.cpp b/SourceSDK.CAPI/SourceSDK.CAPI.cpp deleted file mode 100644 index bf14c74..0000000 --- a/SourceSDK.CAPI/SourceSDK.CAPI.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include - -DLL_EXPORT bool IFileSystem_IsSteam(void** fsPtr) { - IFileSystem* fs = (IFileSystem*)fsPtr; - return fs->IsSteam(); -} - -DLL_EXPORT void IFileSystem_PrintSearchPaths(void** fsPtr) { - IFileSystem* fs = (IFileSystem*)fsPtr; - fs->PrintSearchPaths(); -} diff --git a/SourceSDK.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp new file mode 100644 index 0000000..a90cc7c --- /dev/null +++ b/SourceSDK.CAPI/filesystem_c.cpp @@ -0,0 +1,100 @@ +#include + +#pragma region IBaseFileSystem + +DLL_EXPORT int IBaseFileSystem_Read(void** ptr, void* pOutput, int size, FileHandle_t file) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->Read(pOutput, size, file); +} + +DLL_EXPORT int IBaseFileSystem_Write(void** ptr, void const* pInput, int size, FileHandle_t file) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->Write(pInput, size, file); +} + +DLL_EXPORT FileHandle_t IBaseFileSystem_Open(void** ptr, const char* pFileName, const char* pOptions, const char* pathID = 0) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->Open(pFileName, pOptions, pathID); +} + +DLL_EXPORT void IBaseFileSystem_Close(void** ptr, FileHandle_t file) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + bfs->Close(file); +} + +DLL_EXPORT void IBaseFileSystem_Seek(void** ptr, FileHandle_t file, int pos, FileSystemSeek_t seekType) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + bfs->Seek(file, pos, seekType); +} + +DLL_EXPORT unsigned int IBaseFileSystem_Tell(void** ptr, FileHandle_t file) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->Tell(file); +} + +DLL_EXPORT unsigned int IBaseFileSystem_Size(void** ptr, FileHandle_t file) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->Size(file); +} + +DLL_EXPORT unsigned int IBaseFileSystem_Size_string_string(void** ptr, const char* pFileName, const char* pPathID = 0) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->Size(pFileName, pPathID); +} + +DLL_EXPORT void IBaseFileSystem_Flush(void** ptr, FileHandle_t file) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + bfs->Flush(file); +} + +DLL_EXPORT bool IBaseFileSystem_Precache(void** ptr, const char* pFileName, const char* pPathID = 0) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->Precache(pFileName, pPathID); +} + +DLL_EXPORT bool IBaseFileSystem_FileExists(void** ptr, const char* pFileName, const char* pPathID = 0) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->FileExists(pFileName, pPathID); +} + +DLL_EXPORT bool IBaseFileSystem_IsFileWritable(void** ptr, const char* pFileName, const char* pPathID = 0) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->IsFileWritable(pFileName, pPathID); +} + +DLL_EXPORT bool IBaseFileSystem_SetFileWritable(void** ptr, char const* pFileName, bool writable, const char* pPathID = 0) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->SetFileWritable(pFileName, writable, pPathID); +} + +DLL_EXPORT long IBaseFileSystem_GetFileTime(void** ptr, const char* pFileName, const char* pPathID = 0) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->GetFileTime(pFileName, pPathID); +} + + +DLL_EXPORT bool IBaseFileSystem_ReadFile(void** ptr, const char* pFileName, const char* pPath, CUtlBuffer& buf, int nMaxBytes = 0, int nStartingByte = 0, FSAllocFunc_t pfnAlloc = NULL) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->ReadFile(pFileName, pPath, buf, nMaxBytes, nStartingByte, pfnAlloc); +} + +DLL_EXPORT bool IBaseFileSystem_WriteFile(void** ptr, const char* pFileName, const char* pPath, CUtlBuffer& buf) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->WriteFile(pFileName, pPath, buf); +} + +DLL_EXPORT bool IBaseFileSystem_UnzipFile(void** ptr, const char* pFileName, const char* pPath, const char* pDestination) { + IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; + return bfs->UnzipFile(pFileName, pPath, pDestination); +} +#pragma endregion + +DLL_EXPORT bool IFileSystem_IsSteam(void** fsPtr) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->IsSteam(); +} + +DLL_EXPORT void IFileSystem_PrintSearchPaths(void** fsPtr) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->PrintSearchPaths(); +} From d879f7925c5be76677d168c18e9a78b6c689b936 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 11:11:25 +0500 Subject: [PATCH 092/235] implement some of IBaseFileSystem --- SourceSDK.Test/TestModule.cs | 4 ++-- SourceSDK/public/filesystemh.cs | 42 +++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 91ca23b..96ffc91 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -66,13 +66,13 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("factory()"); - IntPtr iFileSystemPtr = factory(IFileSystem.FILESYSTEM_INTERFACE_VERSION, out IFACE returnCode); + IntPtr iFileSystemPtr = factory(FileSystem.FILESYSTEM_INTERFACE_VERSION, out IFACE returnCode); Console.WriteLine($"result is {returnCode}"); if (returnCode == IFACE.OK) { - IFileSystem fileSystem = new(iFileSystemPtr); + FileSystem fileSystem = new(iFileSystemPtr); Console.WriteLine("PrintSearchPaths"); fileSystem.PrintSearchPaths(); diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index c12f616..301bd20 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -4,11 +4,45 @@ namespace GmodNET.SourceSDK { - public class IFileSystem : IAppSystem + internal static class FileSystemH + { + [DllImport("sourcesdkc")] + internal static extern int IBaseFileSystem_Read(IntPtr ptr, IntPtr output, int size, IntPtr file); + [DllImport("sourcesdkc")] + internal static extern int IBaseFileSystem_Write(IntPtr ptr, IntPtr input, int size, IntPtr file); + [DllImport("sourcesdkc")] + internal static extern IntPtr IBaseFileSystem_Open(IntPtr ptr, string fileName, string options, string pathID); + } + internal interface IBaseFileSystem + { + int Read(IntPtr output, int size, IntPtr file); + int Write(IntPtr input, int size, IntPtr file); + IntPtr Open(string fileName, string options, string pathID); + } + internal interface IFileSystem + { + bool IsSteam(); + void PrintSearchPaths(); + } + + public class BaseFileSystem : IBaseFileSystem + { + public const string BASEFILESYSTEM_INTERFACE_VERSION = "VBaseFileSystem011"; + + protected readonly IntPtr ptr; + + public BaseFileSystem(IntPtr ptr) => this.ptr = ptr; + + public int Read(IntPtr output, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Read(ptr, output, size, file); + public int Write(IntPtr input, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Write(ptr, input, size, file); + public IntPtr Open(string fileName, string options, string pathID) => FileSystemH.IBaseFileSystem_Open(ptr, fileName, options, pathID); + } + + public class FileSystem : IAppSystem, IBaseFileSystem, IFileSystem { public const string FILESYSTEM_INTERFACE_VERSION = "VFileSystem022"; - public IFileSystem(IntPtr ptr) : base(ptr) { } + public FileSystem(IntPtr ptr) : base(ptr) { } [DllImport("sourcesdkc")] internal static extern bool IFileSystem_IsSteam(IntPtr ptr); @@ -23,5 +57,9 @@ public void PrintSearchPaths() { IFileSystem_PrintSearchPaths(ptr); } + + public int Read(IntPtr output, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Read(ptr, output, size, file); + public int Write(IntPtr input, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Write(ptr, input, size, file); + public IntPtr Open(string fileName, string options, string pathID) => FileSystemH.IBaseFileSystem_Open(ptr, fileName, options, pathID); } } From 1bba934500255819933a2387d1256c5f6a719e87 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 11:24:26 +0500 Subject: [PATCH 093/235] try --- SourceSDK.Test/TestModule.cs | 22 ++++++++++++++++++++++ SourceSDK/public/filesystemh.cs | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 96ffc91..812442f 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -5,6 +5,7 @@ using GmodNET.SourceSDK; using GmodNET.SourceSDK.Tier0; using GmodNET.SourceSDK.Tier1; +using System.IO; namespace SourceSDKTest { @@ -78,6 +79,27 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl fileSystem.PrintSearchPaths(); Console.WriteLine("IsSteam"); Console.WriteLine(fileSystem.IsSteam()); + + IntPtr fileHandle = fileSystem.Open("materials/brick/brick_model.vmt", "r", "GAME"); + if (fileHandle != IntPtr.Zero) + { + uint size = fileSystem.Size(fileHandle); + MemoryStream ms = new((int)size); + byte[] buff = ms.GetBuffer(); + + + fixed(byte* buffPtr = buff) + { + IntPtr buffIntPtr = new(buffPtr); + fileSystem.Read(buffIntPtr, (int)size, fileHandle); + //byte* bufferResult = (byte*)buffIntPtr.ToPointer(); + Console.WriteLine(ms.ToArray()); + } + } + else + { + Console.WriteLine("not found vmt"); + } } else throw new EntryPointNotFoundException(); } diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 301bd20..ade89ff 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -12,12 +12,19 @@ internal static class FileSystemH internal static extern int IBaseFileSystem_Write(IntPtr ptr, IntPtr input, int size, IntPtr file); [DllImport("sourcesdkc")] internal static extern IntPtr IBaseFileSystem_Open(IntPtr ptr, string fileName, string options, string pathID); + + + + [DllImport("sourcesdkc")] + internal static extern uint IBaseFileSystem_Size(IntPtr ptr, IntPtr file); } internal interface IBaseFileSystem { int Read(IntPtr output, int size, IntPtr file); int Write(IntPtr input, int size, IntPtr file); IntPtr Open(string fileName, string options, string pathID); + + uint Size(IntPtr file); } internal interface IFileSystem { @@ -36,6 +43,9 @@ public class BaseFileSystem : IBaseFileSystem public int Read(IntPtr output, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Read(ptr, output, size, file); public int Write(IntPtr input, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Write(ptr, input, size, file); public IntPtr Open(string fileName, string options, string pathID) => FileSystemH.IBaseFileSystem_Open(ptr, fileName, options, pathID); + + + public uint Size(IntPtr file) => FileSystemH.IBaseFileSystem_Size(ptr, file); } public class FileSystem : IAppSystem, IBaseFileSystem, IFileSystem @@ -61,5 +71,8 @@ public void PrintSearchPaths() public int Read(IntPtr output, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Read(ptr, output, size, file); public int Write(IntPtr input, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Write(ptr, input, size, file); public IntPtr Open(string fileName, string options, string pathID) => FileSystemH.IBaseFileSystem_Open(ptr, fileName, options, pathID); + + + public uint Size(IntPtr file) => FileSystemH.IBaseFileSystem_Size(ptr, file); } } From f675b5535750cc9e85753254ee7c669c81e967b2 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 11:36:02 +0500 Subject: [PATCH 094/235] use gmod wiki example --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 812442f..9d285b7 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -80,7 +80,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("IsSteam"); Console.WriteLine(fileSystem.IsSteam()); - IntPtr fileHandle = fileSystem.Open("materials/brick/brick_model.vmt", "r", "GAME"); + IntPtr fileHandle = fileSystem.Open("cfg/mapcycle.txt", "r", "MOD"); if (fileHandle != IntPtr.Zero) { uint size = fileSystem.Size(fileHandle); From 6549fc8ebcf21bacbac50bab43b7cf1cb4eb155e Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 11:38:25 +0500 Subject: [PATCH 095/235] use BaseFileSystem --- SourceSDK.Test/TestModule.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 9d285b7..b10ce4f 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -80,10 +80,14 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("IsSteam"); Console.WriteLine(fileSystem.IsSteam()); - IntPtr fileHandle = fileSystem.Open("cfg/mapcycle.txt", "r", "MOD"); + + IntPtr baseFileSystemPtr = factory(BaseFileSystem.BASEFILESYSTEM_INTERFACE_VERSION, out IFACE baseReturnCode); + BaseFileSystem baseFileSystem = new(baseFileSystemPtr); + + IntPtr fileHandle = baseFileSystem.Open("cfg/mapcycle.txt", "r", "MOD"); if (fileHandle != IntPtr.Zero) { - uint size = fileSystem.Size(fileHandle); + uint size = baseFileSystem.Size(fileHandle); MemoryStream ms = new((int)size); byte[] buff = ms.GetBuffer(); @@ -91,7 +95,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl fixed(byte* buffPtr = buff) { IntPtr buffIntPtr = new(buffPtr); - fileSystem.Read(buffIntPtr, (int)size, fileHandle); + baseFileSystem.Read(buffIntPtr, (int)size, fileHandle); //byte* bufferResult = (byte*)buffIntPtr.ToPointer(); Console.WriteLine(ms.ToArray()); } From 0dac4f0ee7ab7fc56543ae48dbbe1fa767105c38 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 11:49:44 +0500 Subject: [PATCH 096/235] run test in OnTick --- .github/workflows/test.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.lua b/.github/workflows/test.lua index f59feb6..d43cc78 100644 --- a/.github/workflows/test.lua +++ b/.github/workflows/test.lua @@ -1,4 +1,3 @@ -hook.Add("Tick", "CloseServer", engine.CloseServer) require("dotnet") local function run_test() @@ -11,7 +10,12 @@ local function run_test() assert(module_unloaded) end -run_test() +local function OnTick() + hook.Remove("Tick", "CloseServer") + run_test() + print("tests are successful!") + file.Write("success.txt", "done") + engine.CloseServer() +end -print("tests are successful!") -file.Write("success.txt", "done") +hook.Add("Tick", "CloseServer", OnTick) From ba18a987acca49aefe07299b4da985b710129d30 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 21:32:41 +0500 Subject: [PATCH 097/235] BaseFileSystem 14/17 implemented --- SourceSDK/public/filesystemh.cs | 84 +++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index ade89ff..ece273f 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -4,31 +4,81 @@ namespace GmodNET.SourceSDK { + public enum FileSystemSeek_t + { + FILESYSTEM_SEEK_HEAD = 0, + FILESYSTEM_SEEK_CURRENT = 1, + FILESYSTEM_SEEK_TAIL = 2, + }; + internal static class FileSystemH { [DllImport("sourcesdkc")] internal static extern int IBaseFileSystem_Read(IntPtr ptr, IntPtr output, int size, IntPtr file); [DllImport("sourcesdkc")] internal static extern int IBaseFileSystem_Write(IntPtr ptr, IntPtr input, int size, IntPtr file); + [DllImport("sourcesdkc")] internal static extern IntPtr IBaseFileSystem_Open(IntPtr ptr, string fileName, string options, string pathID); + [DllImport("sourcesdkc")] + internal static extern void IBaseFileSystem_Close(IntPtr ptr, IntPtr file); + [DllImport("sourcesdkc")] + internal static extern void IBaseFileSystem_Seek(IntPtr ptr, IntPtr file, int pos, in FileSystemSeek_t seekType); + [DllImport("sourcesdkc")] + internal static extern uint IBaseFileSystem_Tell(IntPtr ptr, IntPtr file); + [DllImport("sourcesdkc")] + internal static extern uint IBaseFileSystem_Size(IntPtr ptr, IntPtr file); + [DllImport("sourcesdkc")] + internal static extern uint IBaseFileSystem_Size_string_string(IntPtr ptr, string fileName, string pathID); + [DllImport("sourcesdkc")] + internal static extern void IBaseFileSystem_Flush(IntPtr ptr, IntPtr file); + [DllImport("sourcesdkc")] + internal static extern bool IBaseFileSystem_Precache(IntPtr ptr, string fileName, string pathID); [DllImport("sourcesdkc")] - internal static extern uint IBaseFileSystem_Size(IntPtr ptr, IntPtr file); + internal static extern bool IBaseFileSystem_FileExists(IntPtr ptr, string fileName, string pathID); + [DllImport("sourcesdkc")] + internal static extern bool IBaseFileSystem_IsFileWritable(IntPtr ptr, string fileName, string pathID); + [DllImport("sourcesdkc")] + internal static extern bool IBaseFileSystem_SetFileWritable(IntPtr ptr, string fileName, bool writeable, string pathID); + + [DllImport("sourcesdkc")] + internal static extern long IBaseFileSystem_GetFileTime(IntPtr ptr, string fileName, string pathID); + + //TODO: CUtlBuffer } internal interface IBaseFileSystem { int Read(IntPtr output, int size, IntPtr file); int Write(IntPtr input, int size, IntPtr file); + IntPtr Open(string fileName, string options, string pathID); + void Close(IntPtr file); + void Seek(IntPtr file, int pos, in FileSystemSeek_t seekType); + uint Tell(IntPtr file); uint Size(IntPtr file); + uint Size(string fileName, string pathID); + + void Flush(IntPtr file); + bool Precache(string fileName, string pathID); + + bool FileExists(string fileName, string pathID); + bool IsFileWriteable(string fileName, string pathID); + bool SetFileWriteable(string fileName, bool writeable, string pathID); + + long GetFileTime(string fileName, string pathID); + + } internal interface IFileSystem { bool IsSteam(); + + + void PrintSearchPaths(); } @@ -36,16 +86,31 @@ public class BaseFileSystem : IBaseFileSystem { public const string BASEFILESYSTEM_INTERFACE_VERSION = "VBaseFileSystem011"; + static BaseFileSystem() => NativeLibraryResolver.Init(); + protected readonly IntPtr ptr; public BaseFileSystem(IntPtr ptr) => this.ptr = ptr; public int Read(IntPtr output, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Read(ptr, output, size, file); public int Write(IntPtr input, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Write(ptr, input, size, file); - public IntPtr Open(string fileName, string options, string pathID) => FileSystemH.IBaseFileSystem_Open(ptr, fileName, options, pathID); + public IntPtr Open(string fileName, string options, string pathID) => FileSystemH.IBaseFileSystem_Open(ptr, fileName, options, pathID); + public void Close(IntPtr file) => FileSystemH.IBaseFileSystem_Close(ptr, file); + public void Seek(IntPtr file, int pos, in FileSystemSeek_t seekType) => FileSystemH.IBaseFileSystem_Seek(ptr, file, pos, seekType); + public uint Tell(IntPtr file) => FileSystemH.IBaseFileSystem_Tell(ptr, file); public uint Size(IntPtr file) => FileSystemH.IBaseFileSystem_Size(ptr, file); + public uint Size(string fileName, string pathID) => FileSystemH.IBaseFileSystem_Size_string_string(ptr, fileName, pathID); + + public void Flush(IntPtr file) => FileSystemH.IBaseFileSystem_Flush(ptr, file); + public bool Precache(string fileName, string pathID) => FileSystemH.IBaseFileSystem_Precache(ptr, fileName, pathID); + + public bool FileExists(string fileName, string pathID) => FileSystemH.IBaseFileSystem_FileExists(ptr, fileName, pathID); + public bool IsFileWriteable(string fileName, string pathID) => FileSystemH.IBaseFileSystem_IsFileWritable(ptr, fileName, pathID); + public bool SetFileWriteable(string fileName, bool writeable, string pathID) => FileSystemH.IBaseFileSystem_SetFileWritable(ptr, fileName, writeable, pathID); + + public long GetFileTime(string fileName, string pathID) => FileSystemH.IBaseFileSystem_GetFileTime(ptr, fileName, pathID); } public class FileSystem : IAppSystem, IBaseFileSystem, IFileSystem @@ -70,9 +135,22 @@ public void PrintSearchPaths() public int Read(IntPtr output, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Read(ptr, output, size, file); public int Write(IntPtr input, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Write(ptr, input, size, file); - public IntPtr Open(string fileName, string options, string pathID) => FileSystemH.IBaseFileSystem_Open(ptr, fileName, options, pathID); + public IntPtr Open(string fileName, string options, string pathID) => FileSystemH.IBaseFileSystem_Open(ptr, fileName, options, pathID); + public void Close(IntPtr file) => FileSystemH.IBaseFileSystem_Close(ptr, file); + public void Seek(IntPtr file, int pos, in FileSystemSeek_t seekType) => FileSystemH.IBaseFileSystem_Seek(ptr, file, pos, seekType); + public uint Tell(IntPtr file) => FileSystemH.IBaseFileSystem_Tell(ptr, file); public uint Size(IntPtr file) => FileSystemH.IBaseFileSystem_Size(ptr, file); + public uint Size(string fileName, string pathID) => FileSystemH.IBaseFileSystem_Size_string_string(ptr, fileName, pathID); + + public void Flush(IntPtr file) => FileSystemH.IBaseFileSystem_Flush(ptr, file); + public bool Precache(string fileName, string pathID) => FileSystemH.IBaseFileSystem_Precache(ptr, fileName, pathID); + + public bool FileExists(string fileName, string pathID) => FileSystemH.IBaseFileSystem_FileExists(ptr, fileName, pathID); + public bool IsFileWriteable(string fileName, string pathID) => FileSystemH.IBaseFileSystem_IsFileWritable(ptr, fileName, pathID); + public bool SetFileWriteable(string fileName, bool writeable, string pathID) => FileSystemH.IBaseFileSystem_SetFileWritable(ptr, fileName, writeable, pathID); + + public long GetFileTime(string fileName, string pathID) => FileSystemH.IBaseFileSystem_GetFileTime(ptr, fileName, pathID); } } From 972e79365a3e749f917f008f0d980040ee445aef Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 21:41:30 +0500 Subject: [PATCH 098/235] spam engine.CloseServer --- .github/workflows/test.lua | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.lua b/.github/workflows/test.lua index d43cc78..3844210 100644 --- a/.github/workflows/test.lua +++ b/.github/workflows/test.lua @@ -1,3 +1,4 @@ +hook.Add("Tick", "CloseServer", engine.CloseServer) require("dotnet") local function run_test() @@ -10,12 +11,6 @@ local function run_test() assert(module_unloaded) end -local function OnTick() - hook.Remove("Tick", "CloseServer") - run_test() - print("tests are successful!") - file.Write("success.txt", "done") - engine.CloseServer() -end - -hook.Add("Tick", "CloseServer", OnTick) +run_test() +print("tests are successful!") +file.Write("success.txt", "done") From e4a6162fe8bcca3b99b916b81d887b18784cf176 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 22:02:30 +0500 Subject: [PATCH 099/235] read map --- SourceSDK.Test/TestModule.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index b10ce4f..08e1be4 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -84,14 +84,13 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl IntPtr baseFileSystemPtr = factory(BaseFileSystem.BASEFILESYSTEM_INTERFACE_VERSION, out IFACE baseReturnCode); BaseFileSystem baseFileSystem = new(baseFileSystemPtr); - IntPtr fileHandle = baseFileSystem.Open("cfg/mapcycle.txt", "r", "MOD"); + IntPtr fileHandle = baseFileSystem.Open("maps/gm_construct.bsp", "r", "MOD"); if (fileHandle != IntPtr.Zero) { uint size = baseFileSystem.Size(fileHandle); MemoryStream ms = new((int)size); byte[] buff = ms.GetBuffer(); - fixed(byte* buffPtr = buff) { IntPtr buffIntPtr = new(buffPtr); From b47a9a9c2fdc675f98fb157f32d257aee38e804e Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 22:05:24 +0500 Subject: [PATCH 100/235] don't throw --- SourceSDK.Test/TestModule.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 08e1be4..13dd257 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -104,7 +104,6 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("not found vmt"); } } - else throw new EntryPointNotFoundException(); } }); From 0c0d6bae2c3a991db437b93001c585ce98d40e74 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 22:07:43 +0500 Subject: [PATCH 101/235] test without loading module --- .github/workflows/test.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.lua b/.github/workflows/test.lua index 3844210..c24a4cd 100644 --- a/.github/workflows/test.lua +++ b/.github/workflows/test.lua @@ -11,6 +11,6 @@ local function run_test() assert(module_unloaded) end -run_test() +--run_test() print("tests are successful!") file.Write("success.txt", "done") From 87c649cf77505a35e29de0ce70e0e788e15292e5 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 8 Feb 2021 22:09:40 +0500 Subject: [PATCH 102/235] return test --- .github/workflows/test.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.lua b/.github/workflows/test.lua index c24a4cd..3844210 100644 --- a/.github/workflows/test.lua +++ b/.github/workflows/test.lua @@ -11,6 +11,6 @@ local function run_test() assert(module_unloaded) end ---run_test() +run_test() print("tests are successful!") file.Write("success.txt", "done") From a8ac0709440d2347f22da77659e51e0c60f926dc Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 9 Feb 2021 20:47:42 +0500 Subject: [PATCH 103/235] remove binaries from git --- .gitignore | 2 ++ .../runtimes/linux-x64/native/libsourcesdkc.so | Bin 7680 -> 0 bytes SourceSDK/runtimes/win-x64/native/sourcesdkc.dll | Bin 9728 -> 0 bytes 3 files changed, 2 insertions(+) delete mode 100644 SourceSDK/runtimes/linux-x64/native/libsourcesdkc.so delete mode 100644 SourceSDK/runtimes/win-x64/native/sourcesdkc.dll diff --git a/.gitignore b/.gitignore index f528826..96b8a15 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ bin obj out +.dll +.so diff --git a/SourceSDK/runtimes/linux-x64/native/libsourcesdkc.so b/SourceSDK/runtimes/linux-x64/native/libsourcesdkc.so deleted file mode 100644 index ceb0168430f5e2dae17b61f03a2ed50688ee1d31..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7680 zcmeHMZ)hCH6(8xWO0s3?D%-VUyLgkh)DHEY9LKg4qeik$^2)L0i~fKUYF2x9E8R7B zx7WShMoLN}a9nJJ( z{oM{8Sd=#J^MKz6^7CTjyej110~%)=BK^M3?ZD;`_MZ^)22ixKAn;29{~VWJ%aUS0 z379cmpDJ1{x%nDw$(Ox?uWkwOjPe zw1EbULjGwGd}4S{cmH6%V2;j!m14@MRK{|)yJvsO&X=4~)37tSl;Pwm17AnsM{7zS z7^;jqrcnf$p%q)YK&vp>EYr=b;TSN{bfx0Y6QEL-C305LOxSLzWZH?REc?mC;i8pI zTF$WPsH2u^XUx&$qqV`HS?%vj4JE*ZS-p~dGEw1bP}^Mu4;GC=qL5D~%5J)l&p@^0 zPVaw+yPnP)IwzLIOPdqt3gNE_yhH3S!iisKQ@A}8!*__vVhG1QP32k$$1{z}%@7{m zB1<70-(e~rg>X81uuVJlL6bJuuxYKrw9^-ydT&8H^_!;4%-h!vkoSd+@Y}Y%7izz2 zR@meVWbYrBC)Kv?&v6#pwR1hUL10`v*KiA{*8P!o_J(s0n0_5uFuneycWp)I;xE#~YE@>BUKBCoK(cW2hI>6v#!e9#;q%p|$W_$7=#@vK< zs%JCS#&J9?+FZ{O;BM~rJnyCkKUW(1fUiUKS)2^at8IJI7eD#eNs#b)ZLU$9>(#V_ z4S#4-n5$`X&%#(XYjY!-)_uwC^m$*Vd%@i)wZ}!fH=+6VyuS#FQ-J=s{n-v!V(3E0 zF2(~BFL4-pc{u3BmxPWIQK^m8*F5Tpc}4rf@xyqj&-WW)p-=x1ToAF?cKTZZ9B4q_ z&qO5M3DGy%1*!kpJgWB}Uk_TN{d_WKf>8(SR1U@mYYBtP1yk_XF(tMC7uOjai|-nL zyWqREHFgk|oqrDI|K)iTP=5_5j`;%6CFJjT-c_LSWzYK~&{?4KKvS?Qe+Co_e#^1c zJw3wersH*6TN;~QfCFR)VEE1K0$V(0XpIlHb{uJ2_f*p?dt}SO2lno`5A{$V$Dx2+ z69S^3&R5`BgfUzSVP&Yl4C8n;ggpoKYoJfxG}L_so-cuJ_&fR&z^;Dmd9W+*mb)If z>w&u-2s}XX6va=U7cCzPO0g2f;p+uX@$o%^r#Nk^;OR`;B6y0|@NC3F?f+c%EaaC& z@I~SN84*NbyoRMq9A4tO${ZoT&Todhu3v)KOT>X9y!S6vAVU2v3VDj*NdLCyk0-Dr zr;)#f_16J*DzYYY8+OV7C6)pt8vf6<`{gXmukwxD$>TNveO*oMM5yxsd1m< z_SXgZf@=8|_6lu`P(zHZ5Aq-(80@z)+TYc98{|QhFvROIxT(^8B-|KdpM{{KmV7&- z^{$qW-gmJ*7DOj2(ij`8VYj>$#INCNR1f#yxbP>%2=}iduL^lZ@_(nmCnUUI;B>wK z%gf{NTNk>oi`SXuI3D%qw*kj-(s{*=z|Z%%d~{t_8~%IXTQY$~v3%G)&q;eeaTKSUkRpc$e(Y~BV`OYfx z=K-&kU->2A?KR%7i(EeHA3R^sj+_VjEw>ZR1HC73Ie)VZxFY$0v-;tq#}D-#)%A*- z)`#@!1caI?ms!SkDvmojsb<(p(nfcRdIr-r6-a<&Eq$tBrHz7~bu7E08}2mASjBR| zbj+-JV1IX4Z6Tfx(hb`-W*~Fo*fVU>Hj1X6b&JIrPziB7e^e!^>w_bG#|HF);Uwml zl8+Df9UJNgEyyPksAnsdo-;~W%q;1UN7M&2p{6BA7|s3o;Na-Mm_F8b=;#2L`c#=E zDJ$itxiG<1JBjrlB%(esJr+(j`N=eqg~H5JIE58SSA`oXza=HQu>9({8?y-JQ=e&gG0sj;Yz15@`C=v6*U{1p`5*a(}4hf}>7Z4pSX-8h-h} zRWm0RIF|(#;(Qff?v`n`Xguw>j&|r z=z#V)86Z8P=OulLYdVBJ$;tY}zX27Lq4CrILdq)o!X2c}{CF)oPtxBNNct7h4^!HE zVbPT6|C(?-{_pcecxXQ47u?@8_OO2ECZAg`8K-_p79zWv`aR;{xJ-hA%KHBXTj844 diff --git a/SourceSDK/runtimes/win-x64/native/sourcesdkc.dll b/SourceSDK/runtimes/win-x64/native/sourcesdkc.dll deleted file mode 100644 index 74d09d56ad309636d0f4d76b2100092eca0a564a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9728 zcmeHM4RBl4mAV^TUTGu;_4!%`=7cVwI;4kXkK-K~LP;%-^`5{ImTmL_C( z-+t%)I5s~WI=h`=I^6NS-?`_Ud+xpGp8KQc^>^-P#f-5MWL;-$2uLYll)t~Y0P)=G zkIZFHm7iQRy6ZMqUzZP0rh z1Vk4x<}z59k@bK9C$|28#9N?hHnQP^b(1rABV)VJ^s|4)ScGh%c#1j-FlKg0Or$N0 z2?UE6TL}E9vvZGm?OA8>Ehy5@W1T0Rb3{ z^shjkkpdWXgQ>UXv`4|Lr(zCNCC1Z$x<9V!zbh*vR8*Z zBLxgSF`0&RJpq-O^iNJ;_5)*8g8#k2>w>frhoe!@;heV`WJJ8^<%&(-&zQdVZq zI+S`UuFAgWP%4HfymP3{$BMtIr*w z2CeFgTrCc(RS&~hQ2&|kEQcw>N0UYV0$190IS7Gv8l4)R5wguMf>D(Doc0b){p%2D z{V<$e{4{MiOye6EtN&DB-%qtCK)pM@;MMG}9NKT8t&U6{G6(SjB>VTD;ObGH+bo20 zf!bUI>%+@7-C-NzhZW*%(ZoNPc>Nmy5h|0#hJi#j}0?=RBl4cpf%+3{ALFt z(>GaT>*}79RrVMrUH(@|s*cc7_F^>x!F!_jjM(dD#4|0P(5hZgU*YOo*d!UJMiCoU zkEt(l3Xtg_!1_ned;>$b+6(PmJ!kF%=L0y{`7@1&PA_@rGoV(FWE7qiYZ1xoYjw|; zapH2drIzPfs&!8rYHEQmBRXKx`SpTXr?XsbL7cCz=ED;L_k;GgRCE6@Kdc)GmTo}B zf4M8}4h{31(@8_XXgUAg7^>$Npo$^iJ%SfP&JOxWzIL6=gy#G@^|D@YJ0EQwp4o>C&c76+D6o|b^AHMRQoC_gASuZYJ&r)8L@=}=t0w-Z7U7EzCwl?U7>9?E2Y|(Kun&S(O$a^9BnNM zi+MRdl62lF-dZb2F4BfVoSe~)V(THgugYF>Wab&+%hi)yJ*InZhhw?g=H0A@y%8&V zl5~V9UOEpDLQkTtG1uLO5v3Z=9-mJ!}cdzv|# zGWF%mw(Ld6eP7mI!y;fM>-%5LcrnUGGVDZKOr1u(it4{LbsFGhf2TX`{6`$hJUgnt z0iY@&s#gM@bG~*B?gGQ(7{Xx~W!ifvj5xp%Jv_AjPR2S{Iz4A}J=4qM zRU8B^04G85^Ltm)J1`R+s>I>hxiVOrX$ybmS@(~FH9Y^tT3$Q`(#7+0_Js3up69t5 zZ|mxxDYfcf&Izv`mMYY>WyQnc)di`HXP>Q~JncWlaY$06)MR&h*;k3GKwP?jMMjv` zj+j2$_p){juJxaSUn=`v&6M)5c`7g!)0MU#^;%42-^)r#->J+T?F}@*nSL5zPncpX z@4N{ON3x5{0oY%3$F}qQkGz3PnBv}Z1vo{0`S8^c>Ykf%QKHKd^@Wo+9fl#M9mUSW zxby3$fI*IYg6_GRB(T%OvmM?Qkme^0si72B zM|m#n^@VX_=JOf}P^~AML^DS8X&o;4s5 zeskdZvOF)={@J)o9`TOBS$ywN^4Z-u&&Zd?uI2e_-=Qs;Z$1Z@yaG2q%^yeL<76~D zQpQ)Gmd=XiR@Fu%^xQaS2A6x{oEA|TiQKkUFui`>iI-y4=|LaOsA zv<+rQ9ig1_36PVe;0=Hn!dzG=&o8Z>+I1t16}^X4x;abizTHQDRW4VwR1TwUH<}!C zeiti9)SoTo#zhFI}{i@pL_lp9CsG5qp?? z9nM$1{*JDP)s`N$y^E{sw`es`Crdu;8FXQ^@E_m10s|?y4-Bir;2VSgwD`n%fd9EU zq_5v(;^P(`vGC^>e%sRPweT(r6-&O{s?WF3W#N=1wR_gVVf!f{Lf zoP|Rc{>Z`_OYd!~ZreF;HeD@w}cWq8D|Tn z6?Fdn5mK#h_U9wJi*do^YZlu4Y5XINXWIV9Bqpr!O<8!s!ikTV*T*#b;cECAFo3(+ z_!j2vPLa|8ep}oOw0T~ikNq2Xe>ctRWlS)?tu-X*TbB1PAY$+@qfl({`Qn}1KrCXc zjOyz);5ol82$Ge}=HZ2kPj9n$t%hFhY@VSf%;H51z53ZaL(eyh*JkLgn9Vcv0^k)K z7@zfhk7AQz)U11V?%dh2m8Ma<*qVo=#J#OS!=5mUcc)>mekQNY)bq{anR+Y0>!p5s z&F_HrchCmWtkd_)D`hpXSJPPC{)vapMkI5xb+U z@!Nax7*BL2;?b^Hsv{{%j4cLVRyv}}jvg_ZNOh*89ipsA=^fEzLdHKL z*064|TNXiWTDPJ7_O{mbEz6esjP=5Kj1~z+5v6YSxyy7^WVf)WEOtdZ6G;f8w79h_ z8c(M>6WcP97)`|_DSclwCT-h}ADL#$L@b%uIV}=X+Y?ec)h(vb^YU35>6F-;P@+m~ zYf_|tJw(M`F`iMx=q$li=#TUmi}fUybjwTbOQe>>C1nZz_oXDd#U;sQOO`D$ClV?7 zVn&p9L`11GEp^9IadBN5T5!*GMYoB{x{M@Y91$svV3k`tSltY6TbCrpI>2O8#5KdW z4IKn!3TL8Nog~qw1crWiyi}(;CBz{5ME=^3xOevCj62`-v#^$avSUup0oIb3~vy!L)eNOhE5px z3yU5H_TX*e1)uN$GU*WhlSPjK7hHq4BKQk|n~{4#6XJKHK_3LJ#Ji^t{6XN8$Ol1> z0qOU^0BAybk0}@rA-%6PnyLyxXi}t%thC~_@G-6V&30%h8al4oll2kU=#pKr1_Vm4?R3~H- z!8qN}&2^ozq%790X<9mMdv@b#`!h5?(0kL;Sz~QlIz4GLZ(3^mb4?@|35G(gx8JsT vvqk)0>hw0n9~&Q-7|;f$1}+SYKQ{H)g~tva8aVXBLxYDP`ZWCsd*FWoL&>#i From 1a609abf1937defcc9aca682da8b0283dbe4055a Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 9 Feb 2021 21:04:18 +0500 Subject: [PATCH 104/235] fix git ignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 96b8a15..c2cbdf3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ bin obj out -.dll -.so +*.dll +*.so From da3dcc2874fa17f4765d983bb4701e7ff398107d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 9 Feb 2021 22:16:17 +0500 Subject: [PATCH 105/235] GetSystem --- SourceSDK.Test/TestModule.cs | 77 ++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 13dd257..9852c04 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -6,6 +6,7 @@ using GmodNET.SourceSDK.Tier0; using GmodNET.SourceSDK.Tier1; using System.IO; +using System.Text; namespace SourceSDKTest { @@ -30,6 +31,38 @@ internal void Test(Action action) } } + private static IntPtr GetSystem(string interfaceNoVersionName, string path) + { + Console.WriteLine($"GetSystem(): Searching for {interfaceNoVersionName} in {path}"); + + CreateInterfaceFn createInterfaceFn = interfaceh.Sys_GetFactory(path); + + for (int i = 99; i >= 0; i--) + { + int last = i % 10; + int middle = i / 10; + + string verString = $"0{middle}{last}"; + + if (verString.Length > 3) throw new IndexOutOfRangeException(nameof(verString)); + + Console.WriteLine($"GetSystem(): Trying {verString}"); + + IntPtr systemPtr = createInterfaceFn(interfaceNoVersionName + verString, out IFACE returnCode); + + if (returnCode == IFACE.OK) + { + Console.WriteLine($"GetSystem(): Found {interfaceNoVersionName}{verString}"); + return systemPtr; + } + + } + + Console.WriteLine($"GetSystem(): Not Found {interfaceNoVersionName}"); + + return IntPtr.Zero; + } + public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { Test(() => Dbg.Msg("Msg(string)\n")); @@ -52,56 +85,34 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { unsafe { - string path; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - path = "filesystem_stdio.dll"; - } - else - { - path = "filesystem_stdio.so"; - } - - Console.WriteLine("Getting factory"); - CreateInterfaceFn factory = interfaceh.Sys_GetFactory(path); - - Console.WriteLine("factory()"); + string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "filesystem_stdio.so"; - IntPtr iFileSystemPtr = factory(FileSystem.FILESYSTEM_INTERFACE_VERSION, out IFACE returnCode); + IntPtr fsPtr = GetSystem("VFileSystem", path); - Console.WriteLine($"result is {returnCode}"); - - if (returnCode == IFACE.OK) + if (fsPtr != IntPtr.Zero) { - FileSystem fileSystem = new(iFileSystemPtr); - - Console.WriteLine("PrintSearchPaths"); - fileSystem.PrintSearchPaths(); - Console.WriteLine("IsSteam"); - Console.WriteLine(fileSystem.IsSteam()); - + FileSystem fileSystem = new(fsPtr); - IntPtr baseFileSystemPtr = factory(BaseFileSystem.BASEFILESYSTEM_INTERFACE_VERSION, out IFACE baseReturnCode); - BaseFileSystem baseFileSystem = new(baseFileSystemPtr); + IntPtr fileHandle = fileSystem.Open("lua/autorun/test.lua", "r", "LUA"); - IntPtr fileHandle = baseFileSystem.Open("maps/gm_construct.bsp", "r", "MOD"); if (fileHandle != IntPtr.Zero) { - uint size = baseFileSystem.Size(fileHandle); + uint size = fileSystem.Size(fileHandle); MemoryStream ms = new((int)size); byte[] buff = ms.GetBuffer(); - fixed(byte* buffPtr = buff) + fixed (byte* buffPtr = buff) { IntPtr buffIntPtr = new(buffPtr); - baseFileSystem.Read(buffIntPtr, (int)size, fileHandle); + fileSystem.Read(buffIntPtr, (int)size, fileHandle); //byte* bufferResult = (byte*)buffIntPtr.ToPointer(); - Console.WriteLine(ms.ToArray()); + Console.WriteLine("Printing test.lua"); + Console.WriteLine(Encoding.UTF8.GetChars(ms.ToArray())); } } else { - Console.WriteLine("not found vmt"); + Console.WriteLine("not found file"); } } } From 0c7e887e427647316936a1b0a89ddfdadd326ff4 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 9 Feb 2021 22:24:20 +0500 Subject: [PATCH 106/235] VBaseFileSystem test --- SourceSDK.Test/TestModule.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 9852c04..0259369 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -89,6 +89,8 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl IntPtr fsPtr = GetSystem("VFileSystem", path); + if (fsPtr == IntPtr.Zero) fsPtr = GetSystem("VBaseFileSystem", path); + if (fsPtr != IntPtr.Zero) { FileSystem fileSystem = new(fsPtr); From f308ee5b23396b661fd4e7fa3e7609cf5dd53c4b Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 9 Feb 2021 22:33:39 +0500 Subject: [PATCH 107/235] allocate manually --- SourceSDK.Test/TestModule.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 0259369..e08ef92 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -31,11 +31,12 @@ internal void Test(Action action) } } + private delegate IntPtr CreateInterfaceFn(IntPtr name, out IFACE returnCode); private static IntPtr GetSystem(string interfaceNoVersionName, string path) { Console.WriteLine($"GetSystem(): Searching for {interfaceNoVersionName} in {path}"); - CreateInterfaceFn createInterfaceFn = interfaceh.Sys_GetFactory(path); + CreateInterfaceFn createInterfaceFn = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(NativeLibrary.Load(path), interfaceh.CREATEINTERFACE_PROCNAME)); for (int i = 99; i >= 0; i--) { @@ -48,7 +49,11 @@ private static IntPtr GetSystem(string interfaceNoVersionName, string path) Console.WriteLine($"GetSystem(): Trying {verString}"); - IntPtr systemPtr = createInterfaceFn(interfaceNoVersionName + verString, out IFACE returnCode); + IntPtr namePtr = Marshal.StringToHGlobalAnsi(interfaceNoVersionName + verString); + + IntPtr systemPtr = createInterfaceFn(namePtr, out IFACE returnCode); + + Marshal.FreeHGlobal(namePtr); if (returnCode == IFACE.OK) { From f62ca5663c5ae606e2e2749e0e12a0932d552c16 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Wed, 10 Feb 2021 11:33:45 +0500 Subject: [PATCH 108/235] add filesystem.h enums add FILESYSTEM_MAX_SEARCH_PATHS const refactor filesystem_c.cpp add FileSystem.MountSteamContent rename internal class FileSystemH to BaseFileSystem_c --- SourceSDK.CAPI/filesystem_c.cpp | 23 +-- SourceSDK/public/filesystemh.cs | 245 ++++++++++++++++++++++++++++---- 2 files changed, 219 insertions(+), 49 deletions(-) diff --git a/SourceSDK.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp index a90cc7c..774829d 100644 --- a/SourceSDK.CAPI/filesystem_c.cpp +++ b/SourceSDK.CAPI/filesystem_c.cpp @@ -1,88 +1,70 @@ #include #pragma region IBaseFileSystem - DLL_EXPORT int IBaseFileSystem_Read(void** ptr, void* pOutput, int size, FileHandle_t file) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->Read(pOutput, size, file); } - DLL_EXPORT int IBaseFileSystem_Write(void** ptr, void const* pInput, int size, FileHandle_t file) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->Write(pInput, size, file); } - DLL_EXPORT FileHandle_t IBaseFileSystem_Open(void** ptr, const char* pFileName, const char* pOptions, const char* pathID = 0) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->Open(pFileName, pOptions, pathID); } - DLL_EXPORT void IBaseFileSystem_Close(void** ptr, FileHandle_t file) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; bfs->Close(file); } - DLL_EXPORT void IBaseFileSystem_Seek(void** ptr, FileHandle_t file, int pos, FileSystemSeek_t seekType) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; bfs->Seek(file, pos, seekType); } - DLL_EXPORT unsigned int IBaseFileSystem_Tell(void** ptr, FileHandle_t file) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->Tell(file); } - DLL_EXPORT unsigned int IBaseFileSystem_Size(void** ptr, FileHandle_t file) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->Size(file); } - DLL_EXPORT unsigned int IBaseFileSystem_Size_string_string(void** ptr, const char* pFileName, const char* pPathID = 0) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->Size(pFileName, pPathID); } - DLL_EXPORT void IBaseFileSystem_Flush(void** ptr, FileHandle_t file) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; bfs->Flush(file); } - DLL_EXPORT bool IBaseFileSystem_Precache(void** ptr, const char* pFileName, const char* pPathID = 0) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->Precache(pFileName, pPathID); } - DLL_EXPORT bool IBaseFileSystem_FileExists(void** ptr, const char* pFileName, const char* pPathID = 0) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->FileExists(pFileName, pPathID); } - DLL_EXPORT bool IBaseFileSystem_IsFileWritable(void** ptr, const char* pFileName, const char* pPathID = 0) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->IsFileWritable(pFileName, pPathID); } - DLL_EXPORT bool IBaseFileSystem_SetFileWritable(void** ptr, char const* pFileName, bool writable, const char* pPathID = 0) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->SetFileWritable(pFileName, writable, pPathID); } - DLL_EXPORT long IBaseFileSystem_GetFileTime(void** ptr, const char* pFileName, const char* pPathID = 0) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->GetFileTime(pFileName, pPathID); } - - DLL_EXPORT bool IBaseFileSystem_ReadFile(void** ptr, const char* pFileName, const char* pPath, CUtlBuffer& buf, int nMaxBytes = 0, int nStartingByte = 0, FSAllocFunc_t pfnAlloc = NULL) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->ReadFile(pFileName, pPath, buf, nMaxBytes, nStartingByte, pfnAlloc); } - DLL_EXPORT bool IBaseFileSystem_WriteFile(void** ptr, const char* pFileName, const char* pPath, CUtlBuffer& buf) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->WriteFile(pFileName, pPath, buf); } - DLL_EXPORT bool IBaseFileSystem_UnzipFile(void** ptr, const char* pFileName, const char* pPath, const char* pDestination) { IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; return bfs->UnzipFile(pFileName, pPath, pDestination); @@ -94,6 +76,11 @@ DLL_EXPORT bool IFileSystem_IsSteam(void** fsPtr) { return fs->IsSteam(); } +DLL_EXPORT FilesystemMountRetval_t IFileSystem_MountSteamContent(void** fsPtr, int nExtraAppId = -1) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->MountSteamContent(nExtraAppId); +} + DLL_EXPORT void IFileSystem_PrintSearchPaths(void** fsPtr) { IFileSystem* fs = (IFileSystem*)fsPtr; fs->PrintSearchPaths(); diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index ece273f..c44e5ea 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -4,14 +4,183 @@ namespace GmodNET.SourceSDK { + #region Enums + + public enum EPureServerFileClass + { + /// + /// dummy debugging value + /// + ePureServerFileClass_Unknown = -1, + ePureServerFileClass_Any = 0, + ePureServerFileClass_AnyTrusted = 1, + ePureServerFileClass_CheckHash = 2, + } public enum FileSystemSeek_t { FILESYSTEM_SEEK_HEAD = 0, FILESYSTEM_SEEK_CURRENT = 1, FILESYSTEM_SEEK_TAIL = 2, - }; + } + public enum FileSystem_Handle + { + FILESYSTEM_INVALID_FIND_HANDLE = -1 + } + public enum FileWarningLevel_t + { + /// A problem! + FILESYSTEM_WARNING = -1, + /// Don't print anything + FILESYSTEM_WARNING_QUIET = 0, + ///On shutdown, report names of files left unclosed + FILESYSTEM_WARNING_REPORTUNCLOSED = 1, + /// Report number of times a file was opened, closed + FILESYSTEM_WARNING_REPORTUSAGE = 2, + /// Report all open/close events to console ( !slow! ) + FILESYSTEM_WARNING_REPORTALLACCESSES = 3, + /// Report all open/close/read events to the console ( !slower! ) + FILESYSTEM_WARNING_REPORTALLACCESSES_READ = 4, + /// Report all open/close/read/write events to the console ( !slower! ) + FILESYSTEM_WARNING_REPORTALLACCESSES_READWRITE = 5, + /// Report all open/close/read/write events and all async I/O file events to the console ( !slower(est)! ) + FILESYSTEM_WARNING_REPORTALLACCESSES_ASYNC = 6, + } + /// + /// search path filtering + /// + public enum PathTypeFilter_t + { + /// + /// no filtering, all search path types match + /// + FILTER_NONE = 0, + /// + /// pack based search paths are culled (maps and zips) + /// + FILTER_CULLPACK = 1, + /// + /// non-pack based search paths are culled + /// + FILTER_CULLNONPACK = 2, + } + // search path querying (bit flags) + public enum PATH + { + /// + /// normal path, not pack based + /// + PATH_IS_NORMAL = 0x00, + /// + /// path is a pack file + /// + PATH_IS_PACKFILE = 0x01, + /// + /// path is a map pack file + /// + PATH_IS_MAPPACKFILE = 0x02, + /// + /// path is the remote filesystem + /// + PATH_IS_REMOTE = 0x04, + } + public enum DVDMode_t + { + /// + /// not using dvd + /// + DVDMODE_OFF = 0, + /// + /// dvd device only + /// + DVDMODE_STRICT = 1, + /// + /// dev mode, mutiple devices ok + /// + DVDMODE_DEV = 2 + } + public enum FilesystemMountRetval_t + { + FILESYSTEM_MOUNT_OK = 0, + FILESYSTEM_MOUNT_FAILED = 1 + } + public enum SearchPathAdd_t + { + /// + /// First path searched + /// + PATH_ADD_TO_HEAD = 0, + /// + /// Last path searched + /// + PATH_ADD_TO_TAIL = 1 + } + public enum FilesystemOpenExFlags_t + { + FSOPEN_UNBUFFERED = (1 << 0), + FSOPEN_FORCE_TRACK_CRC = (1 << 1), // This makes it calculate a CRC for the file (if the file came from disk) regardless + // of the IFileList passed to RegisterFileWhitelist. + FSOPEN_NEVERINPACK = (1 << 2), // 360 only, hint to FS that file is not allowed to be in pack file + } + public enum FSAsyncStatus_t + { + FSASYNC_ERR_NOT_MINE = -8, // Filename not part of the specified file system, try a different one. (Used internally to find the right filesystem) + FSASYNC_ERR_RETRY_LATER = -7, // Failure for a reason that might be temporary. You might retry, but not immediately. (E.g. Network problems) + FSASYNC_ERR_ALIGNMENT = -6, // read parameters invalid for unbuffered IO + FSASYNC_ERR_FAILURE = -5, // hard subsystem failure + FSASYNC_ERR_READING = -4, // read error on file + FSASYNC_ERR_NOMEMORY = -3, // out of memory for file read + FSASYNC_ERR_UNKNOWNID = -2, // caller's provided id is not recognized + FSASYNC_ERR_FILEOPEN = -1, // filename could not be opened (bad path, not exist, etc) + FSASYNC_OK = 0, // operation is successful + FSASYNC_STATUS_PENDING = 1, // file is properly queued, waiting for service + FSASYNC_STATUS_INPROGRESS = 2, // file is being accessed + FSASYNC_STATUS_ABORTED = 3, // file was aborted by caller + FSASYNC_STATUS_UNSERVICED = 4, // file is not yet queued + } + public enum FSAsyncFlags_t + { + /// + /// do the allocation for dataPtr, but don't free + /// + FSASYNC_FLAGS_ALLOCNOFREE = (1 << 0), + /// + /// free the memory for the dataPtr post callback + /// + FSASYNC_FLAGS_FREEDATAPTR = (1 << 1), + /// + /// Actually perform the operation synchronously. Used to simplify client code paths + /// + FSASYNC_FLAGS_SYNC = (1 << 2), + /// + /// allocate an extra byte and null terminate the buffer read in + /// + FSASYNC_FLAGS_NULLTERMINATE = (1 << 3) + } + /// + /// Return value for CheckFileCRC. + /// + public enum EFileCRCStatus + { + /// + /// We don't have this file. + /// + k_eFileCRCStatus_CantOpenFile = 0, + k_eFileCRCStatus_GotCRC = 1, + k_eFileCRCStatus_FileInVPK = 2 + } + /// + /// Used in CacheFileCRCs. + /// + public enum ECacheCRCType + { + k_eCacheCRCType_SingleFile = 0, + k_eCacheCRCType_Directory = 1, + k_eCacheCRCType_Directory_Recursive = 2 + } - internal static class FileSystemH + #endregion + + internal static class BaseFileSystem_c { [DllImport("sourcesdkc")] internal static extern int IBaseFileSystem_Read(IntPtr ptr, IntPtr output, int size, IntPtr file); @@ -49,6 +218,13 @@ internal static class FileSystemH //TODO: CUtlBuffer } + + internal static class FileSystem_c + { + [DllImport("sourcesdkc")] + internal static extern FilesystemMountRetval_t IFileSystem_MountSteamContent(IntPtr ptr, int extraAppId = -1); + } + internal interface IBaseFileSystem { int Read(IntPtr output, int size, IntPtr file); @@ -77,7 +253,7 @@ internal interface IFileSystem { bool IsSteam(); - + FilesystemMountRetval_t MountSteamContent(int extraAppId = -1); void PrintSearchPaths(); } @@ -92,29 +268,31 @@ public class BaseFileSystem : IBaseFileSystem public BaseFileSystem(IntPtr ptr) => this.ptr = ptr; - public int Read(IntPtr output, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Read(ptr, output, size, file); - public int Write(IntPtr input, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Write(ptr, input, size, file); + public int Read(IntPtr output, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Read(ptr, output, size, file); + public int Write(IntPtr input, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Write(ptr, input, size, file); - public IntPtr Open(string fileName, string options, string pathID) => FileSystemH.IBaseFileSystem_Open(ptr, fileName, options, pathID); - public void Close(IntPtr file) => FileSystemH.IBaseFileSystem_Close(ptr, file); + public IntPtr Open(string fileName, string options, string pathID) => BaseFileSystem_c.IBaseFileSystem_Open(ptr, fileName, options, pathID); + public void Close(IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Close(ptr, file); - public void Seek(IntPtr file, int pos, in FileSystemSeek_t seekType) => FileSystemH.IBaseFileSystem_Seek(ptr, file, pos, seekType); - public uint Tell(IntPtr file) => FileSystemH.IBaseFileSystem_Tell(ptr, file); - public uint Size(IntPtr file) => FileSystemH.IBaseFileSystem_Size(ptr, file); - public uint Size(string fileName, string pathID) => FileSystemH.IBaseFileSystem_Size_string_string(ptr, fileName, pathID); + public void Seek(IntPtr file, int pos, in FileSystemSeek_t seekType) => BaseFileSystem_c.IBaseFileSystem_Seek(ptr, file, pos, seekType); + public uint Tell(IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Tell(ptr, file); + public uint Size(IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Size(ptr, file); + public uint Size(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_Size_string_string(ptr, fileName, pathID); - public void Flush(IntPtr file) => FileSystemH.IBaseFileSystem_Flush(ptr, file); - public bool Precache(string fileName, string pathID) => FileSystemH.IBaseFileSystem_Precache(ptr, fileName, pathID); + public void Flush(IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Flush(ptr, file); + public bool Precache(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_Precache(ptr, fileName, pathID); - public bool FileExists(string fileName, string pathID) => FileSystemH.IBaseFileSystem_FileExists(ptr, fileName, pathID); - public bool IsFileWriteable(string fileName, string pathID) => FileSystemH.IBaseFileSystem_IsFileWritable(ptr, fileName, pathID); - public bool SetFileWriteable(string fileName, bool writeable, string pathID) => FileSystemH.IBaseFileSystem_SetFileWritable(ptr, fileName, writeable, pathID); + public bool FileExists(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_FileExists(ptr, fileName, pathID); + public bool IsFileWriteable(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_IsFileWritable(ptr, fileName, pathID); + public bool SetFileWriteable(string fileName, bool writeable, string pathID) => BaseFileSystem_c.IBaseFileSystem_SetFileWritable(ptr, fileName, writeable, pathID); - public long GetFileTime(string fileName, string pathID) => FileSystemH.IBaseFileSystem_GetFileTime(ptr, fileName, pathID); + public long GetFileTime(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_GetFileTime(ptr, fileName, pathID); } public class FileSystem : IAppSystem, IBaseFileSystem, IFileSystem { + public const int FILESYSTEM_MAX_SEARCH_PATHS = 128; + public const string FILESYSTEM_INTERFACE_VERSION = "VFileSystem022"; public FileSystem(IntPtr ptr) : base(ptr) { } @@ -126,6 +304,11 @@ public bool IsSteam() return IFileSystem_IsSteam(ptr); } + public FilesystemMountRetval_t MountSteamContent(int extraAppId = -1) + { + return FileSystem_c.IFileSystem_MountSteamContent(ptr, extraAppId); + } + [DllImport("sourcesdkc")] internal static extern void IFileSystem_PrintSearchPaths(IntPtr ptr); public void PrintSearchPaths() @@ -133,24 +316,24 @@ public void PrintSearchPaths() IFileSystem_PrintSearchPaths(ptr); } - public int Read(IntPtr output, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Read(ptr, output, size, file); - public int Write(IntPtr input, int size, IntPtr file) => FileSystemH.IBaseFileSystem_Write(ptr, input, size, file); + public int Read(IntPtr output, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Read(ptr, output, size, file); + public int Write(IntPtr input, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Write(ptr, input, size, file); - public IntPtr Open(string fileName, string options, string pathID) => FileSystemH.IBaseFileSystem_Open(ptr, fileName, options, pathID); - public void Close(IntPtr file) => FileSystemH.IBaseFileSystem_Close(ptr, file); + public IntPtr Open(string fileName, string options, string pathID) => BaseFileSystem_c.IBaseFileSystem_Open(ptr, fileName, options, pathID); + public void Close(IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Close(ptr, file); - public void Seek(IntPtr file, int pos, in FileSystemSeek_t seekType) => FileSystemH.IBaseFileSystem_Seek(ptr, file, pos, seekType); - public uint Tell(IntPtr file) => FileSystemH.IBaseFileSystem_Tell(ptr, file); - public uint Size(IntPtr file) => FileSystemH.IBaseFileSystem_Size(ptr, file); - public uint Size(string fileName, string pathID) => FileSystemH.IBaseFileSystem_Size_string_string(ptr, fileName, pathID); + public void Seek(IntPtr file, int pos, in FileSystemSeek_t seekType) => BaseFileSystem_c.IBaseFileSystem_Seek(ptr, file, pos, seekType); + public uint Tell(IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Tell(ptr, file); + public uint Size(IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Size(ptr, file); + public uint Size(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_Size_string_string(ptr, fileName, pathID); - public void Flush(IntPtr file) => FileSystemH.IBaseFileSystem_Flush(ptr, file); - public bool Precache(string fileName, string pathID) => FileSystemH.IBaseFileSystem_Precache(ptr, fileName, pathID); + public void Flush(IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Flush(ptr, file); + public bool Precache(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_Precache(ptr, fileName, pathID); - public bool FileExists(string fileName, string pathID) => FileSystemH.IBaseFileSystem_FileExists(ptr, fileName, pathID); - public bool IsFileWriteable(string fileName, string pathID) => FileSystemH.IBaseFileSystem_IsFileWritable(ptr, fileName, pathID); - public bool SetFileWriteable(string fileName, bool writeable, string pathID) => FileSystemH.IBaseFileSystem_SetFileWritable(ptr, fileName, writeable, pathID); + public bool FileExists(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_FileExists(ptr, fileName, pathID); + public bool IsFileWriteable(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_IsFileWritable(ptr, fileName, pathID); + public bool SetFileWriteable(string fileName, bool writeable, string pathID) => BaseFileSystem_c.IBaseFileSystem_SetFileWritable(ptr, fileName, writeable, pathID); - public long GetFileTime(string fileName, string pathID) => FileSystemH.IBaseFileSystem_GetFileTime(ptr, fileName, pathID); + public long GetFileTime(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_GetFileTime(ptr, fileName, pathID); } } From b720c53cf3110ba178b243317571b79bc1f5b660 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Wed, 10 Feb 2021 11:53:21 +0500 Subject: [PATCH 109/235] implement FileSystem.AddSearchPath implement FileSystem.RemoveSearchPath --- SourceSDK.CAPI/filesystem_c.cpp | 10 ++++++++++ SourceSDK/public/filesystemh.cs | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/SourceSDK.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp index 774829d..2b07d4a 100644 --- a/SourceSDK.CAPI/filesystem_c.cpp +++ b/SourceSDK.CAPI/filesystem_c.cpp @@ -81,6 +81,16 @@ DLL_EXPORT FilesystemMountRetval_t IFileSystem_MountSteamContent(void** fsPtr, i return fs->MountSteamContent(nExtraAppId); } +DLL_EXPORT void IFileSystem_AddSearchPath(void** fsPtr, const char* pPath, const char* pathID, SearchPathAdd_t addType = PATH_ADD_TO_TAIL) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->AddSearchPath(pPath, pathID, addType); +} + +DLL_EXPORT bool IFileSystem_RemoveSearchPath(void** fsPtr, const char* pPath, const char* pathID = 0) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->RemoveSearchPath(pPath, pathID); +} + DLL_EXPORT void IFileSystem_PrintSearchPaths(void** fsPtr) { IFileSystem* fs = (IFileSystem*)fsPtr; fs->PrintSearchPaths(); diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index c44e5ea..f14ec4c 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -223,6 +223,10 @@ internal static class FileSystem_c { [DllImport("sourcesdkc")] internal static extern FilesystemMountRetval_t IFileSystem_MountSteamContent(IntPtr ptr, int extraAppId = -1); + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_AddSearchPath(IntPtr ptr, string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL); + [DllImport("sourcesdkc")] + internal static extern bool IFileSystem_RemoveSearchPath(IntPtr ptr, string path, string pathID); } internal interface IBaseFileSystem @@ -255,6 +259,9 @@ internal interface IFileSystem FilesystemMountRetval_t MountSteamContent(int extraAppId = -1); + void AddSearchPath(string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL); + bool RemoveSearchPath(string path, string pathID); + void PrintSearchPaths(); } @@ -309,6 +316,16 @@ public FilesystemMountRetval_t MountSteamContent(int extraAppId = -1) return FileSystem_c.IFileSystem_MountSteamContent(ptr, extraAppId); } + public void AddSearchPath(string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL) + { + FileSystem_c.IFileSystem_AddSearchPath(ptr, path, pathID, addType); + } + + public bool RemoveSearchPath(string path, string pathID) + { + return FileSystem_c.IFileSystem_RemoveSearchPath(ptr, path, pathID); + } + [DllImport("sourcesdkc")] internal static extern void IFileSystem_PrintSearchPaths(IntPtr ptr); public void PrintSearchPaths() From e347fba28a3a883fad3840cf2398bd27e570d13c Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 11 Feb 2021 20:25:33 +0500 Subject: [PATCH 110/235] move imports to internal class convert to expressions add IFileSystem_RemoveAllSearchPaths add IFileSystem_RemoveSearchPaths add ISurface_DrawSetTextureRGBAex c definition --- SourceSDK.CAPI/CMakeLists.txt | 2 +- SourceSDK.CAPI/filesystem_c.cpp | 13 ++++++-- SourceSDK.CAPI/vgui/isurface_c.cpp | 6 ++++ SourceSDK/public/filesystemh.cs | 53 +++++++++++++++--------------- 4 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 SourceSDK.CAPI/vgui/isurface_c.cpp diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index 2336711..8c82e42 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -47,7 +47,7 @@ add_compile_definitions(${SOURCESDK_DEFINES}) link_directories("${SOURCESDK_LIBDIRS}") link_libraries(tier0) -add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp") +add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp") target_include_directories(sourcesdkc PUBLIC#SYSTEM INTERFACE #"${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/common" diff --git a/SourceSDK.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp index 2b07d4a..eda95eb 100644 --- a/SourceSDK.CAPI/filesystem_c.cpp +++ b/SourceSDK.CAPI/filesystem_c.cpp @@ -75,21 +75,28 @@ DLL_EXPORT bool IFileSystem_IsSteam(void** fsPtr) { IFileSystem* fs = (IFileSystem*)fsPtr; return fs->IsSteam(); } - DLL_EXPORT FilesystemMountRetval_t IFileSystem_MountSteamContent(void** fsPtr, int nExtraAppId = -1) { IFileSystem* fs = (IFileSystem*)fsPtr; return fs->MountSteamContent(nExtraAppId); } - DLL_EXPORT void IFileSystem_AddSearchPath(void** fsPtr, const char* pPath, const char* pathID, SearchPathAdd_t addType = PATH_ADD_TO_TAIL) { IFileSystem* fs = (IFileSystem*)fsPtr; fs->AddSearchPath(pPath, pathID, addType); } - DLL_EXPORT bool IFileSystem_RemoveSearchPath(void** fsPtr, const char* pPath, const char* pathID = 0) { IFileSystem* fs = (IFileSystem*)fsPtr; return fs->RemoveSearchPath(pPath, pathID); } +DLL_EXPORT void IFileSystem_RemoveAllSearchPaths(void** fsPtr) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->RemoveAllSearchPaths(); +} +DLL_EXPORT void IFileSystem_RemoveSearchPaths(void** fsPtr, const char* szPathID) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->RemoveSearchPaths(szPathID); +} + + DLL_EXPORT void IFileSystem_PrintSearchPaths(void** fsPtr) { IFileSystem* fs = (IFileSystem*)fsPtr; diff --git a/SourceSDK.CAPI/vgui/isurface_c.cpp b/SourceSDK.CAPI/vgui/isurface_c.cpp new file mode 100644 index 0000000..23e1133 --- /dev/null +++ b/SourceSDK.CAPI/vgui/isurface_c.cpp @@ -0,0 +1,6 @@ +#include + +DLL_EXPORT void ISurface_DrawSetTextureRGBAex(void** ptr, int id, const unsigned char* rgba, int wide, int tall, ImageFormat imageFormat) { + vgui::ISurface* surf = (vgui::ISurface*)ptr; + surf->DrawSetTextureRGBAEx(id, rgba, wide, tall, imageFormat); +} diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index f14ec4c..32acb90 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -221,12 +221,22 @@ internal static class BaseFileSystem_c internal static class FileSystem_c { + [DllImport("sourcesdkc")] + internal static extern bool IFileSystem_IsSteam(IntPtr ptr); + [DllImport("sourcesdkc")] internal static extern FilesystemMountRetval_t IFileSystem_MountSteamContent(IntPtr ptr, int extraAppId = -1); [DllImport("sourcesdkc")] internal static extern void IFileSystem_AddSearchPath(IntPtr ptr, string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL); [DllImport("sourcesdkc")] internal static extern bool IFileSystem_RemoveSearchPath(IntPtr ptr, string path, string pathID); + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_RemoveAllSearchPaths(IntPtr ptr); + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_RemoveSearchPaths(IntPtr ptr, string pathID); + + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_PrintSearchPaths(IntPtr ptr); } internal interface IBaseFileSystem @@ -261,6 +271,9 @@ internal interface IFileSystem void AddSearchPath(string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL); bool RemoveSearchPath(string path, string pathID); + void RemoveAllSearchPaths(); + void RemoveSearchPaths(string pathID); + void PrintSearchPaths(); } @@ -304,34 +317,20 @@ public class FileSystem : IAppSystem, IBaseFileSystem, IFileSystem public FileSystem(IntPtr ptr) : base(ptr) { } - [DllImport("sourcesdkc")] - internal static extern bool IFileSystem_IsSteam(IntPtr ptr); - public bool IsSteam() - { - return IFileSystem_IsSteam(ptr); - } - - public FilesystemMountRetval_t MountSteamContent(int extraAppId = -1) - { - return FileSystem_c.IFileSystem_MountSteamContent(ptr, extraAppId); - } - - public void AddSearchPath(string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL) - { - FileSystem_c.IFileSystem_AddSearchPath(ptr, path, pathID, addType); - } - - public bool RemoveSearchPath(string path, string pathID) - { - return FileSystem_c.IFileSystem_RemoveSearchPath(ptr, path, pathID); - } - [DllImport("sourcesdkc")] - internal static extern void IFileSystem_PrintSearchPaths(IntPtr ptr); - public void PrintSearchPaths() - { - IFileSystem_PrintSearchPaths(ptr); - } + public bool IsSteam() => FileSystem_c.IFileSystem_IsSteam(ptr); + + public FilesystemMountRetval_t MountSteamContent(int extraAppId = -1) => FileSystem_c.IFileSystem_MountSteamContent(ptr, extraAppId); + + public void AddSearchPath(string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL) => FileSystem_c.IFileSystem_AddSearchPath(ptr, path, pathID, addType); + public bool RemoveSearchPath(string path, string pathID) => FileSystem_c.IFileSystem_RemoveSearchPath(ptr, path, pathID); + public void RemoveAllSearchPaths() => FileSystem_c.IFileSystem_RemoveAllSearchPaths(ptr); + public void RemoveSearchPaths(string pathID) => FileSystem_c.IFileSystem_RemoveSearchPaths(ptr, pathID); + + + public void PrintSearchPaths() => FileSystem_c.IFileSystem_PrintSearchPaths(ptr); + + /// IBaseFileSystem public int Read(IntPtr output, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Read(ptr, output, size, file); public int Write(IntPtr input, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Write(ptr, input, size, file); From 65e9090869fb99971d55726ddcbfe4848976a773 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 11 Feb 2021 20:35:33 +0500 Subject: [PATCH 111/235] disable isurface_c.cpp --- SourceSDK.CAPI/vgui/isurface_c.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SourceSDK.CAPI/vgui/isurface_c.cpp b/SourceSDK.CAPI/vgui/isurface_c.cpp index 23e1133..955cfc1 100644 --- a/SourceSDK.CAPI/vgui/isurface_c.cpp +++ b/SourceSDK.CAPI/vgui/isurface_c.cpp @@ -1,6 +1,8 @@ -#include +/*#include DLL_EXPORT void ISurface_DrawSetTextureRGBAex(void** ptr, int id, const unsigned char* rgba, int wide, int tall, ImageFormat imageFormat) { vgui::ISurface* surf = (vgui::ISurface*)ptr; surf->DrawSetTextureRGBAEx(id, rgba, wide, tall, imageFormat); } + +*/ From 496a5f65638d046f287afd02d452f028170f8315 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 11 Feb 2021 20:41:52 +0500 Subject: [PATCH 112/235] PrintSearchPaths Init --- SourceSDK.Test/TestModule.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index e08ef92..a3b75c3 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -100,6 +100,10 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { FileSystem fileSystem = new(fsPtr); + fileSystem.PrintSearchPaths(); + fileSystem.Init(); + fileSystem.PrintSearchPaths(); + IntPtr fileHandle = fileSystem.Open("lua/autorun/test.lua", "r", "LUA"); if (fileHandle != IntPtr.Zero) From 37132a7fcf97f33d023bc64341b92ffa86bf0e7e Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 11 Feb 2021 20:50:53 +0500 Subject: [PATCH 113/235] remove useless 2 calls --- SourceSDK.Test/TestModule.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index a3b75c3..416eb30 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -100,8 +100,6 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { FileSystem fileSystem = new(fsPtr); - fileSystem.PrintSearchPaths(); - fileSystem.Init(); fileSystem.PrintSearchPaths(); IntPtr fileHandle = fileSystem.Open("lua/autorun/test.lua", "r", "LUA"); From 71326d83b8fab1f5792210a2470390799a0de8e1 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 09:49:25 +0500 Subject: [PATCH 114/235] disable IFileSystem // for linux test fix, does NativeLibrary.Load causes it? --- SourceSDK.Test/TestModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 416eb30..1c088ed 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -86,7 +86,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.COM_TimestampedLog("%s", "COM_TimestampedLog")); - Test(() => + /*Test(() => { unsafe { @@ -125,7 +125,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl } } } - }); + });*/ Debug.Assert(!failed); } From 9aebff87b5303acce158a46244cac6dbdc35a363 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 09:52:31 +0500 Subject: [PATCH 115/235] COM_TimestampedLog: replace params string[] with string --- SourceSDK.Test/TestModule.cs | 2 +- SourceSDK/public/tier0/dbg.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 1c088ed..7dd21cc 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -84,7 +84,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.ConMsg("ConMsg(string)\n")); Test(() => Dbg.ConDMsg("ConDMsg(string)\n")); - Test(() => Dbg.COM_TimestampedLog("%s", "COM_TimestampedLog")); + Test(() => Dbg.COM_TimestampedLog("COM_TimestampedLog(format = %s)", "COM_TimestampedLog")); /*Test(() => { diff --git a/SourceSDK/public/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs index a9b28cf..939042f 100644 --- a/SourceSDK/public/tier0/dbg.cs +++ b/SourceSDK/public/tier0/dbg.cs @@ -113,6 +113,6 @@ public static class Delegates public static extern void ConDMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void COM_TimestampedLog([MarshalAs(UnmanagedType.LPUTF8Str)] string fmt, params string[] dotdotdot); + public static extern void COM_TimestampedLog([MarshalAs(UnmanagedType.LPUTF8Str)] string fmt, string dotdotdot); } } From 1d229cfbf256f7bb3d3172bf34e4909fc9813aeb Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 11:10:09 +0500 Subject: [PATCH 116/235] use static classes add doc to COM_TimestampedLog add spacing add ArgumentNullException when IntPtr.Zero passed implement Sys_LoadInterface implement Sys_LoadModule implement Sys_UnloadModule improve Sys_GetFactory(string module) // probably NativeLibrary.Free will make errors, but i'll try! edits to TestModule.cs --- SourceSDK.Test/TestModule.cs | 14 ++---- SourceSDK/public/tier0/dbg.cs | 13 ++++-- SourceSDK/tier1/interfaceh.cs | 85 +++++++++++++++++++++++++++++++++-- 3 files changed, 96 insertions(+), 16 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 7dd21cc..ab203a3 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -31,12 +31,11 @@ internal void Test(Action action) } } - private delegate IntPtr CreateInterfaceFn(IntPtr name, out IFACE returnCode); private static IntPtr GetSystem(string interfaceNoVersionName, string path) { Console.WriteLine($"GetSystem(): Searching for {interfaceNoVersionName} in {path}"); - CreateInterfaceFn createInterfaceFn = Marshal.GetDelegateForFunctionPointer(NativeLibrary.GetExport(NativeLibrary.Load(path), interfaceh.CREATEINTERFACE_PROCNAME)); + CreateInterfaceFn createInterfaceFn = interfaceh.Sys_GetFactory(path); for (int i = 99; i >= 0; i--) { @@ -49,18 +48,13 @@ private static IntPtr GetSystem(string interfaceNoVersionName, string path) Console.WriteLine($"GetSystem(): Trying {verString}"); - IntPtr namePtr = Marshal.StringToHGlobalAnsi(interfaceNoVersionName + verString); - - IntPtr systemPtr = createInterfaceFn(namePtr, out IFACE returnCode); - - Marshal.FreeHGlobal(namePtr); + IntPtr systemPtr = createInterfaceFn(interfaceNoVersionName + verString, out IFACE returnCode); if (returnCode == IFACE.OK) { Console.WriteLine($"GetSystem(): Found {interfaceNoVersionName}{verString}"); return systemPtr; } - } Console.WriteLine($"GetSystem(): Not Found {interfaceNoVersionName}"); @@ -86,7 +80,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.COM_TimestampedLog("COM_TimestampedLog(format = %s)", "COM_TimestampedLog")); - /*Test(() => + Test(() => { unsafe { @@ -125,7 +119,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl } } } - });*/ + }); Debug.Assert(!failed); } diff --git a/SourceSDK/public/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs index 939042f..9e42fc5 100644 --- a/SourceSDK/public/tier0/dbg.cs +++ b/SourceSDK/public/tier0/dbg.cs @@ -37,7 +37,7 @@ static Dbg() } } - internal class Windows + internal static class Windows { [DllImport("tier0", EntryPoint = "?DevMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); @@ -52,7 +52,7 @@ internal class Windows [DllImport("tier0", EntryPoint = "?ConMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); } - internal class Linux + internal static class Linux { [DllImport("tier0", EntryPoint = "_Z6DevMsgPKcz", CallingConvention = CallingConvention.Cdecl)] public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); @@ -67,7 +67,7 @@ internal class Linux [DllImport("tier0", EntryPoint = "_Z6ConMsgPKcz", CallingConvention = CallingConvention.Cdecl)] public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); } - internal class OSX + internal static class OSX { [DllImport("tier0", EntryPoint = "__Z6DevMsgPKcz", CallingConvention = CallingConvention.Cdecl)] public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); @@ -112,6 +112,13 @@ public static class Delegates [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void ConDMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); + /// + /// + /// + /// + /// + /// SupinePandora43: doesn't work, i don't know how it supposed to work + /// [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void COM_TimestampedLog([MarshalAs(UnmanagedType.LPUTF8Str)] string fmt, string dotdotdot); } diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index af3d238..cb1087a 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace GmodNET.SourceSDK.Tier1 @@ -10,12 +11,16 @@ public enum IFACE } public delegate IntPtr CreateInterfaceFn(string name, out IFACE returnCode); + public static class interfaceh { public const string CREATEINTERFACE_PROCNAME = "CreateInterface"; public static CreateInterfaceFn Sys_GetFactory(IntPtr module) { + if (module == IntPtr.Zero) + throw new ArgumentNullException(nameof(module)); + IntPtr createInterfaceFnPtr = NativeLibrary.GetExport(module, CREATEINTERFACE_PROCNAME); if (createInterfaceFnPtr == IntPtr.Zero) @@ -31,12 +36,86 @@ public static CreateInterfaceFn Sys_GetFactory(string module) if (handle == IntPtr.Zero) throw new DllNotFoundException(module); - return Sys_GetFactory(handle); + CreateInterfaceFn factory = null; + Exception exception = null; + + try + { + factory = Sys_GetFactory(handle); + } + catch (Exception e) + { + exception = e; + } + finally + { + NativeLibrary.Free(handle); + } + + if (exception is not null) throw exception; + return factory; + } + /// + /// loads module + /// + /// Module name + /// + /// uses NativeLibrary.Load + /// + public static IntPtr Sys_LoadModule(string moduleName) + { + return NativeLibrary.Load(moduleName); } - public static void Sys_LoadInterface(string moduleName, string interfaceVersionName, IntPtr outModule, IntPtr outInterface) + /// + /// unloads module + /// + /// module handle + /// uses NativeLibrary.Free + /// + public static void Sys_UnloadModule(IntPtr module) { - //todo? + NativeLibrary.Free(module); + } + + /// + /// get interface + /// + /// module name + /// interface version + /// loaded module handle + /// loaded module's interface + /// successful + /// + /// + public static bool Sys_LoadInterface(string moduleName, string interfaceVersionName, [NotNullWhen(true)] out IntPtr outModule, [NotNullWhen(true)] out IntPtr outInterface) + { + outModule = Sys_LoadModule(moduleName); + outInterface = IntPtr.Zero; + + if (outModule == IntPtr.Zero) return false; + + CreateInterfaceFn factory; + + try + { + factory = Sys_GetFactory(outModule); + } + catch (EntryPointNotFoundException) + { + Sys_UnloadModule(outModule); + return false; + } + + outInterface = factory(interfaceVersionName, out IFACE returnCode); + + if (returnCode != IFACE.OK || outInterface == IntPtr.Zero) + { + Sys_UnloadModule(outModule); + return false; + } + + return true; } } } From 7a5dace33c199d16c3713bdcfed574e6d635ef2d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 11:11:17 +0500 Subject: [PATCH 117/235] add Version field --- SourceSDK/GmodNET.SourceSDK.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/SourceSDK/GmodNET.SourceSDK.csproj b/SourceSDK/GmodNET.SourceSDK.csproj index 185e610..7c38001 100644 --- a/SourceSDK/GmodNET.SourceSDK.csproj +++ b/SourceSDK/GmodNET.SourceSDK.csproj @@ -4,6 +4,7 @@ true GmodNET GmodNET.SourceSDK + 0.0.1 true From b04cfb3a510c48df1e32c17e786cf3750c2bc00c Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 11:17:33 +0500 Subject: [PATCH 118/235] changes to TestModule.cs --- SourceSDK.Test/TestModule.cs | 50 +++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index ab203a3..1587305 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -86,38 +86,40 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "filesystem_stdio.so"; - IntPtr fsPtr = GetSystem("VFileSystem", path); - if (fsPtr == IntPtr.Zero) fsPtr = GetSystem("VBaseFileSystem", path); + if (!interfaceh.Sys_LoadInterface(path, "VFileSystem022", out IntPtr module, out IntPtr fsPtr)) + if (!interfaceh.Sys_LoadInterface(path, "VBaseFileSystem011", out module, out fsPtr)) + { + Console.WriteLine("failed finding filesystems"); + NativeLibrary.Free(module); + return; + } - if (fsPtr != IntPtr.Zero) - { - FileSystem fileSystem = new(fsPtr); + FileSystem fileSystem = new(fsPtr); - fileSystem.PrintSearchPaths(); + fileSystem.PrintSearchPaths(); - IntPtr fileHandle = fileSystem.Open("lua/autorun/test.lua", "r", "LUA"); + IntPtr fileHandle = fileSystem.Open("lua/autorun/test.lua", "r", "LUA"); - if (fileHandle != IntPtr.Zero) - { - uint size = fileSystem.Size(fileHandle); - MemoryStream ms = new((int)size); - byte[] buff = ms.GetBuffer(); - - fixed (byte* buffPtr = buff) - { - IntPtr buffIntPtr = new(buffPtr); - fileSystem.Read(buffIntPtr, (int)size, fileHandle); - //byte* bufferResult = (byte*)buffIntPtr.ToPointer(); - Console.WriteLine("Printing test.lua"); - Console.WriteLine(Encoding.UTF8.GetChars(ms.ToArray())); - } - } - else + if (fileHandle != IntPtr.Zero) + { + uint size = fileSystem.Size(fileHandle); + MemoryStream ms = new((int)size); + byte[] buff = ms.GetBuffer(); + + fixed (byte* buffPtr = buff) { - Console.WriteLine("not found file"); + IntPtr buffIntPtr = new(buffPtr); + fileSystem.Read(buffIntPtr, (int)size, fileHandle); + //byte* bufferResult = (byte*)buffIntPtr.ToPointer(); + Console.WriteLine("Printing test.lua"); + Console.WriteLine(Encoding.UTF8.GetChars(ms.ToArray())); } } + else + { + Console.WriteLine("not found file"); + } } }); From 19dcc297ddf7b6560c6f59dcf5afd9c464900594 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 11:24:07 +0500 Subject: [PATCH 119/235] full absolute path for linux --- SourceSDK.Test/TestModule.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 1587305..ae45a28 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -84,8 +84,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { unsafe { - string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "filesystem_stdio.so"; - + string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "bin/linux64/filesystem_stdio.so"; if (!interfaceh.Sys_LoadInterface(path, "VFileSystem022", out IntPtr module, out IntPtr fsPtr)) if (!interfaceh.Sys_LoadInterface(path, "VBaseFileSystem011", out module, out fsPtr)) From d388372420de91f37e3243a52a622b4de9a94756 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 11:26:43 +0500 Subject: [PATCH 120/235] disable COM_TimestampedLog --- SourceSDK.Test/TestModule.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index ae45a28..d043c9c 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -78,7 +78,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.ConMsg("ConMsg(string)\n")); Test(() => Dbg.ConDMsg("ConDMsg(string)\n")); - Test(() => Dbg.COM_TimestampedLog("COM_TimestampedLog(format = %s)", "COM_TimestampedLog")); + // Test(() => Dbg.COM_TimestampedLog("COM_TimestampedLog(format = %s)", "COM_TimestampedLog")); Test(() => { @@ -86,6 +86,8 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "bin/linux64/filesystem_stdio.so"; + Console.WriteLine("loading fs"); + if (!interfaceh.Sys_LoadInterface(path, "VFileSystem022", out IntPtr module, out IntPtr fsPtr)) if (!interfaceh.Sys_LoadInterface(path, "VBaseFileSystem011", out module, out fsPtr)) { From f57d7041855a1b744962bb3880043c200d2cb1dc Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 11:32:39 +0500 Subject: [PATCH 121/235] edit build.yml --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 14188ae..a96cc62 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -121,7 +121,7 @@ jobs: - name: Copy test.lua run: cp .github/workflows/test.lua ./gmod/garrysmod/lua/autorun - name: Run Garry's Mod - run: ./srcds_run_x64 -game garrysmod -systemtest -condebug +sv_hibernate_think 1 || true + run: ./srcds_run_x64 -game garrysmod -systemtest -condebug +developer 1 +exec "server.cfg" +gamemode sandbox +map gm_construct +maxplayers 2 +sv_hibernate_think 1 || true working-directory: ./gmod/ timeout-minutes: 2 continue-on-error: true @@ -159,7 +159,7 @@ jobs: - name: Run Garry's Mod shell: bash run: | - powershell -Command './gmod/srcds_win64.exe -console -systemtest -condebug -game "garrysmod" +exec "server.cfg" +gamemode sandbox +map gm_construct +maxplayers 16 +sv_hibernate_think 1' + powershell -Command './gmod/srcds_win64.exe -console -systemtest -condebug -game "garrysmod" +developer 1 +exec "server.cfg" +gamemode sandbox +map gm_construct +maxplayers 2 +sv_hibernate_think 1' powershell -Command 'Wait-Process -Name srcds_win64' continue-on-error: true timeout-minutes: 2 From 7c1ad8bb5c7cfc87803d8e46175c4d5998087e4a Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 11:45:14 +0500 Subject: [PATCH 122/235] do not unload library --- SourceSDK.Test/TestModule.cs | 2 ++ SourceSDK/tier1/interfaceh.cs | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index d043c9c..e27a32f 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -88,6 +88,8 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("loading fs"); + + if (!interfaceh.Sys_LoadInterface(path, "VFileSystem022", out IntPtr module, out IntPtr fsPtr)) if (!interfaceh.Sys_LoadInterface(path, "VBaseFileSystem011", out module, out fsPtr)) { diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index cb1087a..8dc786a 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -47,14 +47,11 @@ public static CreateInterfaceFn Sys_GetFactory(string module) { exception = e; } - finally - { - NativeLibrary.Free(handle); - } if (exception is not null) throw exception; return factory; } + /// /// loads module /// @@ -88,7 +85,7 @@ public static void Sys_UnloadModule(IntPtr module) /// successful /// /// - public static bool Sys_LoadInterface(string moduleName, string interfaceVersionName, [NotNullWhen(true)] out IntPtr outModule, [NotNullWhen(true)] out IntPtr outInterface) + public static bool Sys_LoadInterface(string moduleName, string interfaceVersionName, out IntPtr outModule, out IntPtr outInterface) { outModule = Sys_LoadModule(moduleName); outInterface = IntPtr.Zero; From f823940c223935acb07965ec7d445a99545617b7 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 11:52:35 +0500 Subject: [PATCH 123/235] revert absolute full path --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index e27a32f..0633fe4 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -84,7 +84,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { unsafe { - string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "bin/linux64/filesystem_stdio.so"; + string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "filesystem_stdio.so"; Console.WriteLine("loading fs"); From e70e77ab28d598db6c1977b88ae1ac848e068c65 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 11:55:37 +0500 Subject: [PATCH 124/235] add debug --- SourceSDK/tier1/interfaceh.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index 8dc786a..4a7c11e 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -87,6 +87,7 @@ public static void Sys_UnloadModule(IntPtr module) /// public static bool Sys_LoadInterface(string moduleName, string interfaceVersionName, out IntPtr outModule, out IntPtr outInterface) { + Console.WriteLine("Sys_LoadModule"); outModule = Sys_LoadModule(moduleName); outInterface = IntPtr.Zero; @@ -96,18 +97,22 @@ public static bool Sys_LoadInterface(string moduleName, string interfaceVersionN try { + Console.WriteLine("Sys_GetFactory"); factory = Sys_GetFactory(outModule); } catch (EntryPointNotFoundException) { + Console.WriteLine("Sys_UnloadModule"); Sys_UnloadModule(outModule); return false; } + Console.WriteLine("factory()"); outInterface = factory(interfaceVersionName, out IFACE returnCode); if (returnCode != IFACE.OK || outInterface == IntPtr.Zero) { + Console.WriteLine("Sys_UnloadModule"); Sys_UnloadModule(outModule); return false; } From fe9594d0f9d404147fd6d8cb9f44e53ad3213bd8 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 11:59:39 +0500 Subject: [PATCH 125/235] oof --- SourceSDK.Test/TestModule.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 0633fe4..4ef84a1 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -94,6 +94,8 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl if (!interfaceh.Sys_LoadInterface(path, "VBaseFileSystem011", out module, out fsPtr)) { Console.WriteLine("failed finding filesystems"); + // oof + NativeLibrary.Free(module); NativeLibrary.Free(module); return; } From d88df9c3d7cc7f713bd84543ef3bcedfa123479e Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 12:02:23 +0500 Subject: [PATCH 126/235] upload .nupkg --- .github/workflows/build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a96cc62..e48bf17 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,6 +85,11 @@ jobs: path: SourceSDK/runtimes/win-x64/native - name: Build Solution run: dotnet publish SourceSDK.sln --configuration Release + - name: Upload nuget package + uses: actions/upload-artifact@v2 + with: + name: sourcesdk + path: SourceSDK/bin/Release/*.nupkg - name: Upload SourceSDK.dll uses: actions/upload-artifact@v2 with: From 45507940a80739e164b10a745bbdeb8c7367031d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 12:08:15 +0500 Subject: [PATCH 127/235] do not unload module --- SourceSDK.Test/TestModule.cs | 2 -- SourceSDK/tier1/interfaceh.cs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 4ef84a1..fb014c0 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -88,8 +88,6 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("loading fs"); - - if (!interfaceh.Sys_LoadInterface(path, "VFileSystem022", out IntPtr module, out IntPtr fsPtr)) if (!interfaceh.Sys_LoadInterface(path, "VBaseFileSystem011", out module, out fsPtr)) { diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index 4a7c11e..956d9de 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -72,7 +72,7 @@ public static IntPtr Sys_LoadModule(string moduleName) /// public static void Sys_UnloadModule(IntPtr module) { - NativeLibrary.Free(module); + //NativeLibrary.Free(module); } /// From 364782bb69a5418af320b169d29346c57ac06941 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 12:09:10 +0500 Subject: [PATCH 128/235] add prints xD --- .github/workflows/test.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.lua b/.github/workflows/test.lua index 3844210..e9d0d2e 100644 --- a/.github/workflows/test.lua +++ b/.github/workflows/test.lua @@ -2,11 +2,13 @@ hook.Add("Tick", "CloseServer", engine.CloseServer) require("dotnet") local function run_test() + print("loading") local module_loaded = dotnet.load("SourceSDKTest") assert(module_loaded) -- uhm + print("unloading") local module_unloaded = dotnet.unload("SourceSDKTest") assert(module_unloaded) end From 463efa5279902f9eaa6ff323a3863437bdc0feca Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 12:13:43 +0500 Subject: [PATCH 129/235] add pack script --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e48bf17..afcefe8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,6 +85,8 @@ jobs: path: SourceSDK/runtimes/win-x64/native - name: Build Solution run: dotnet publish SourceSDK.sln --configuration Release + - name: Pack + run: dotnet pack SourceSDK.sln --configuration Release - name: Upload nuget package uses: actions/upload-artifact@v2 with: From 14818aaa4de0b78e6461a5699a754723595efcd9 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 12:19:10 +0500 Subject: [PATCH 130/235] message --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index fb014c0..aabe3e2 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -94,7 +94,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("failed finding filesystems"); // oof NativeLibrary.Free(module); - NativeLibrary.Free(module); + Console.WriteLine("i guess it freed"); return; } From da70c6262edfca0aa92ce6f3a02170205624edd7 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 22:01:58 +0500 Subject: [PATCH 131/235] AddSearchPath --- SourceSDK.Test/TestModule.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index aabe3e2..8874270 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -102,6 +102,13 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl fileSystem.PrintSearchPaths(); + Console.WriteLine("add search path"); + + fileSystem.AddSearchPath("garrysmod", "LUA", SearchPathAdd_t.PATH_ADD_TO_TAIL); + + Console.WriteLine("print paths"); + fileSystem.PrintSearchPaths(); + IntPtr fileHandle = fileSystem.Open("lua/autorun/test.lua", "r", "LUA"); if (fileHandle != IntPtr.Zero) From 3f34378b420f4dc2d6b99de24a31af7a543a24af Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 12 Feb 2021 22:10:20 +0500 Subject: [PATCH 132/235] change things --- SourceSDK.Test/TestModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 8874270..72daa5f 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -104,12 +104,12 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("add search path"); - fileSystem.AddSearchPath("garrysmod", "LUA", SearchPathAdd_t.PATH_ADD_TO_TAIL); + fileSystem.AddSearchPath("garrysmod", "GAME", SearchPathAdd_t.PATH_ADD_TO_HEAD); Console.WriteLine("print paths"); fileSystem.PrintSearchPaths(); - IntPtr fileHandle = fileSystem.Open("lua/autorun/test.lua", "r", "LUA"); + IntPtr fileHandle = fileSystem.Open("resource/GameMenu.res", "r", "GAME"); if (fileHandle != IntPtr.Zero) { From 1c81024f0a450264814cdfc0e1b6cdb9624562eb Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 16:32:09 +0500 Subject: [PATCH 133/235] fix file reading --- SourceSDK.Test/TestModule.cs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 72daa5f..d67cc37 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -88,7 +88,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("loading fs"); - if (!interfaceh.Sys_LoadInterface(path, "VFileSystem022", out IntPtr module, out IntPtr fsPtr)) + if (!interfaceh.Sys_LoadInterface(path, "DISABLED!!!___VFileSystem022", out IntPtr module, out IntPtr fsPtr)) if (!interfaceh.Sys_LoadInterface(path, "VBaseFileSystem011", out module, out fsPtr)) { Console.WriteLine("failed finding filesystems"); @@ -98,33 +98,25 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl return; } - FileSystem fileSystem = new(fsPtr); - - fileSystem.PrintSearchPaths(); - - Console.WriteLine("add search path"); - - fileSystem.AddSearchPath("garrysmod", "GAME", SearchPathAdd_t.PATH_ADD_TO_HEAD); - - Console.WriteLine("print paths"); - fileSystem.PrintSearchPaths(); + BaseFileSystem fileSystem = new(fsPtr); + //fileSystem.PrintSearchPaths(); IntPtr fileHandle = fileSystem.Open("resource/GameMenu.res", "r", "GAME"); if (fileHandle != IntPtr.Zero) { uint size = fileSystem.Size(fileHandle); - MemoryStream ms = new((int)size); - byte[] buff = ms.GetBuffer(); + byte[] buff = new byte[size]; fixed (byte* buffPtr = buff) { IntPtr buffIntPtr = new(buffPtr); fileSystem.Read(buffIntPtr, (int)size, fileHandle); //byte* bufferResult = (byte*)buffIntPtr.ToPointer(); - Console.WriteLine("Printing test.lua"); - Console.WriteLine(Encoding.UTF8.GetChars(ms.ToArray())); + Console.WriteLine("Printing file contents"); + Console.WriteLine(Encoding.UTF8.GetChars(buff)); } + fileSystem.Close(fileHandle); } else { From 06f2042bacfd7154381817016e50c9f281104ac1 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 17:12:52 +0500 Subject: [PATCH 134/235] fix file reading --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index d67cc37..e7eb0b3 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -101,7 +101,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl BaseFileSystem fileSystem = new(fsPtr); //fileSystem.PrintSearchPaths(); - IntPtr fileHandle = fileSystem.Open("resource/GameMenu.res", "r", "GAME"); + IntPtr fileHandle = fileSystem.Open("resource/GameMenu.res", "rb", "GAME"); if (fileHandle != IntPtr.Zero) { From 63cc573a3812ba4b2172631b1c86a9ed73d6fe38 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 17:57:42 +0500 Subject: [PATCH 135/235] rewrite code --- SourceSDK.Test/TestModule.cs | 37 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index e7eb0b3..d63b763 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -86,37 +86,42 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "filesystem_stdio.so"; - Console.WriteLine("loading fs"); + 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 FS"); + } - if (!interfaceh.Sys_LoadInterface(path, "DISABLED!!!___VFileSystem022", out IntPtr module, out IntPtr fsPtr)) - if (!interfaceh.Sys_LoadInterface(path, "VBaseFileSystem011", out module, out fsPtr)) - { - Console.WriteLine("failed finding filesystems"); - // oof - NativeLibrary.Free(module); - Console.WriteLine("i guess it freed"); - return; - } + if (fSPtr == IntPtr.Zero || baseFSPtr == IntPtr.Zero) + { + Console.WriteLine("unloading it"); + NativeLibrary.Free(module); + Console.WriteLine("unloaded ???"); + } + FileSystem fileSystem = new(fSPtr); + BaseFileSystem baseFileSystem = new(baseFSPtr); - BaseFileSystem fileSystem = new(fsPtr); - //fileSystem.PrintSearchPaths(); + fileSystem.PrintSearchPaths(); - IntPtr fileHandle = fileSystem.Open("resource/GameMenu.res", "rb", "GAME"); + IntPtr fileHandle = baseFileSystem.Open("resource/GameMenu.res", "rb", "GAME"); if (fileHandle != IntPtr.Zero) { - uint size = fileSystem.Size(fileHandle); + uint size = baseFileSystem.Size(fileHandle); byte[] buff = new byte[size]; fixed (byte* buffPtr = buff) { IntPtr buffIntPtr = new(buffPtr); - fileSystem.Read(buffIntPtr, (int)size, fileHandle); + baseFileSystem.Read(buffIntPtr, (int)size, fileHandle); //byte* bufferResult = (byte*)buffIntPtr.ToPointer(); Console.WriteLine("Printing file contents"); Console.WriteLine(Encoding.UTF8.GetChars(buff)); } - fileSystem.Close(fileHandle); + baseFileSystem.Close(fileHandle); } else { From 59fa136c4729d0c97f602816d6e90315fd4339f0 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 18:31:09 +0500 Subject: [PATCH 136/235] steam and gmod caching --- .github/workflows/build.yml | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index afcefe8..955092a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -107,11 +107,23 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Install Steam and Garry's Mod Dedicated Server + - name: Cache Steam and Garry's Mod Dedicated Server + id: cache + uses: actions/cache@v2 + with: + path: | + ./gmod + steamcmd.sh + ./linux32 + key: ${{ runner.os }} + - name: Download SteamCMD + if: steps.cache.outputs.cache-hit != 'true' run: | wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz tar -xvzf steamcmd_linux.tar.gz rm -rfv steamcmd_linux.tar.gz + - name: Validate Garry's Mod Dedicated Server + run: | ./steamcmd.sh +login anonymous +force_install_dir gmod "+app_update 4020 -beta x86-64 validate" +quit - name: Install GmodDotNet run: | @@ -144,11 +156,23 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v2 - - name: Install Steam and Garry's Mod Dedicated Server - shell: bash + - name: Cache Steam and Garry's Mod Dedicated Server + id: cache + uses: actions/cache@v2 + with: + path: | + ./gmod + steamcmd.exe + key: ${{ runner.os }} + - name: Download SteamCMD + if: steps.cache.outputs.cache-hit != 'true' run: | curl https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip -O -L powershell -Command 'Expand-Archive -LiteralPath ./steamcmd.zip -DestinationPath ./' + del steamcmd.zip + - name: Validate Garry's Mod Dedicated Server + shell: bash + run: | ./steamcmd.exe +login anonymous +force_install_dir gmod "+app_update 4020 -beta x86-64 validate" +quit || true - name: Install GmodDotNet shell: bash From c0fa40f6df8f235f637052dcdfb6f1fd49750b26 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 18:37:15 +0500 Subject: [PATCH 137/235] increase timeout to 3 --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 955092a..5ea4b69 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -142,7 +142,7 @@ jobs: - name: Run Garry's Mod run: ./srcds_run_x64 -game garrysmod -systemtest -condebug +developer 1 +exec "server.cfg" +gamemode sandbox +map gm_construct +maxplayers 2 +sv_hibernate_think 1 || true working-directory: ./gmod/ - timeout-minutes: 2 + timeout-minutes: 3 continue-on-error: true - name: Print log run: cat gmod/garrysmod/console.log @@ -193,7 +193,7 @@ jobs: powershell -Command './gmod/srcds_win64.exe -console -systemtest -condebug -game "garrysmod" +developer 1 +exec "server.cfg" +gamemode sandbox +map gm_construct +maxplayers 2 +sv_hibernate_think 1' powershell -Command 'Wait-Process -Name srcds_win64' continue-on-error: true - timeout-minutes: 2 + timeout-minutes: 3 - name: Print log shell: bash run: cat gmod/garrysmod/console.log From 9de14db3c2cdcddbe1ad83514c4eba71c4925a7b Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 18:46:17 +0500 Subject: [PATCH 138/235] cleanup step and _new --- .github/workflows/build.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5ea4b69..34f6ecc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -115,7 +115,7 @@ jobs: ./gmod steamcmd.sh ./linux32 - key: ${{ runner.os }} + key: ${{ runner.os }}_new - name: Download SteamCMD if: steps.cache.outputs.cache-hit != 'true' run: | @@ -151,6 +151,9 @@ jobs: with: files: "gmod/garrysmod/data/success.txt" allow_failure: true + - name: Cleanup + run: rm -r ./gmod/garrysmod/lua/bin + Test-windows: needs: Build runs-on: windows-latest @@ -163,7 +166,7 @@ jobs: path: | ./gmod steamcmd.exe - key: ${{ runner.os }} + key: ${{ runner.os }}_new - name: Download SteamCMD if: steps.cache.outputs.cache-hit != 'true' run: | @@ -203,3 +206,5 @@ jobs: with: files: "gmod/garrysmod/data/success.txt" allow_failure: true + - name: Cleanup + run: del ./gmod/garrysmod/lua/bin From b421cf95855473e72252157a2565469f687986e6 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 18:59:55 +0500 Subject: [PATCH 139/235] /S --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 34f6ecc..9eb0b93 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -151,7 +151,7 @@ jobs: with: files: "gmod/garrysmod/data/success.txt" allow_failure: true - - name: Cleanup + - name: Delete ./gmod/garrysmod/lua/bin run: rm -r ./gmod/garrysmod/lua/bin Test-windows: @@ -206,5 +206,5 @@ jobs: with: files: "gmod/garrysmod/data/success.txt" allow_failure: true - - name: Cleanup - run: del ./gmod/garrysmod/lua/bin + - name: Delete ./gmod/garrysmod/lua/bin + run: del /S ./gmod/garrysmod/lua/bin From 62cb18ae3d853e6ec11c2b7e98b22368164ab1b6 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 19:05:46 +0500 Subject: [PATCH 140/235] fix delete --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9eb0b93..ce3bdf3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -207,4 +207,4 @@ jobs: files: "gmod/garrysmod/data/success.txt" allow_failure: true - name: Delete ./gmod/garrysmod/lua/bin - run: del /S ./gmod/garrysmod/lua/bin + run: Remove-Item –path ./gmod/garrysmod/lua/bin –recurse From 4386f753c5d2e9f2b33ef952c7d7af226e95572c Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 19:17:05 +0500 Subject: [PATCH 141/235] fix IntPtr.Zero --- SourceSDK.Test/TestModule.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index d63b763..05d429c 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -100,7 +100,9 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("unloading it"); NativeLibrary.Free(module); Console.WriteLine("unloaded ???"); + return; } + FileSystem fileSystem = new(fSPtr); BaseFileSystem baseFileSystem = new(baseFSPtr); From 5392ecbd1b531a79e54fa3335b0b6a346423c37d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 19:32:00 +0500 Subject: [PATCH 142/235] use SetCustomNativeLibraryResolver --- SourceSDK.Test/TestModule.cs | 6 ++++ SourceSDK/NativeLibraryResolver.cs | 40 --------------------- SourceSDK/public/appframework/iappsystem.cs | 2 -- SourceSDK/public/filesystemh.cs | 2 -- 4 files changed, 6 insertions(+), 44 deletions(-) delete mode 100644 SourceSDK/NativeLibraryResolver.cs diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 05d429c..0fb353a 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -64,6 +64,12 @@ private static IntPtr GetSystem(string interfaceNoVersionName, string path) 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) => + { + return NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc"); + }); + Test(() => Dbg.Msg("Msg(string)\n")); Test(() => Dbg.Warning("Warning(string)\n")); diff --git a/SourceSDK/NativeLibraryResolver.cs b/SourceSDK/NativeLibraryResolver.cs deleted file mode 100644 index fcaaa39..0000000 --- a/SourceSDK/NativeLibraryResolver.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices; - -namespace GmodNET.SourceSDK -{ - internal class NativeLibraryResolver - { - internal static Assembly assembly = typeof(NativeLibraryResolver).Assembly; - internal static string platformIdentifier = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win-x64" : (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "linux-x64" : "osx-x64"); - internal static string lib = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "sourcesdkc.dll" : "libsourcesdkc.so"; - - internal static bool initializated = false; - - internal static void Init() - { - if (!initializated) - { - NativeLibrary.SetDllImportResolver(assembly, (libName, asm, searchPath) => - { - if (asm == assembly && libName == "sourcesdkc") - { - string path = Path.Combine(Path.GetDirectoryName(assembly.Location), $"runtimes/{platformIdentifier}/native/{lib}"); - if (File.Exists(path)) - { - return NativeLibrary.Load(path); - } - else - { - return NativeLibrary.Load("sourcesdkc"); - } - } - return IntPtr.Zero; - }); - initializated = true; - } - } - } -} diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index 323b62b..56c7620 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -32,8 +32,6 @@ public enum AppSystemTier_t public abstract class IAppSystem { - static IAppSystem() => NativeLibraryResolver.Init(); - protected readonly IntPtr ptr; public IAppSystem(IntPtr ptr) diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 32acb90..e833bb6 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -282,8 +282,6 @@ public class BaseFileSystem : IBaseFileSystem { public const string BASEFILESYSTEM_INTERFACE_VERSION = "VBaseFileSystem011"; - static BaseFileSystem() => NativeLibraryResolver.Init(); - protected readonly IntPtr ptr; public BaseFileSystem(IntPtr ptr) => this.ptr = ptr; From 1166f3288924b17a357162d6698f47b81776c636 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 19:41:00 +0500 Subject: [PATCH 143/235] fix --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 0fb353a..d9e7936 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -67,7 +67,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl string platformIdentifier = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win-x64" : "linux-x64"; assembly_context.SetCustomNativeLibraryResolver((ctx, str) => { - return NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc"); + return str.Contains("sourcesdkc") ? NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc") : IntPtr.Zero; }); Test(() => Dbg.Msg("Msg(string)\n")); From b28f200582018641582415fbb39c08ce51b7d44d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 19:47:10 +0500 Subject: [PATCH 144/235] delete stuff --- .github/workflows/build.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce3bdf3..3e11634 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -151,9 +151,10 @@ jobs: with: files: "gmod/garrysmod/data/success.txt" allow_failure: true - - name: Delete ./gmod/garrysmod/lua/bin + - name: Delete stuff 1 run: rm -r ./gmod/garrysmod/lua/bin - + - name: Delete stuff 2 + run: rm ./gmod/garrysmod/console.log Test-windows: needs: Build runs-on: windows-latest @@ -206,5 +207,7 @@ jobs: with: files: "gmod/garrysmod/data/success.txt" allow_failure: true - - name: Delete ./gmod/garrysmod/lua/bin + - name: Delete stuff 1 run: Remove-Item –path ./gmod/garrysmod/lua/bin –recurse + - name: Delete stuff 2 + run: Remove-Item ./gmod/garrysmod/console.log From 44d9355cf3e9652a77d3861875569c5b953c97f0 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 13 Feb 2021 19:52:15 +0500 Subject: [PATCH 145/235] NativeLibrary.Free(sourcesdkc) --- SourceSDK.Test/TestModule.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index d9e7936..795e1e7 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -18,6 +18,8 @@ public class TestModule : IModule private bool failed = false; + private IntPtr sourcesdkc = IntPtr.Zero; + internal void Test(Action action) { try @@ -67,7 +69,12 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl string platformIdentifier = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win-x64" : "linux-x64"; assembly_context.SetCustomNativeLibraryResolver((ctx, str) => { - return str.Contains("sourcesdkc") ? NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc") : IntPtr.Zero; + if (str.Contains("sourcesdkc")) + { + sourcesdkc = NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc"); + return sourcesdkc; + } + return IntPtr.Zero; }); Test(() => Dbg.Msg("Msg(string)\n")); @@ -143,7 +150,10 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl public void Unload(ILua lua) { - + if (sourcesdkc != IntPtr.Zero) + { + NativeLibrary.Free(sourcesdkc); + } } } } From 4a3dd7c6043b1a5a0872253e682a924b12762e9e Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 14 Feb 2021 13:15:24 +0500 Subject: [PATCH 146/235] skip linux --- SourceSDK.Test/TestModule.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 795e1e7..d28bcfb 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -95,6 +95,8 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + return; unsafe { string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "filesystem_stdio.so"; From 193b1a392ecd60e74991716ccf87d4bb93a61c26 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 14 Feb 2021 13:21:23 +0500 Subject: [PATCH 147/235] disable IFileSystem test --- SourceSDK.Test/TestModule.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index d28bcfb..ad329be 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -71,8 +71,8 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { if (str.Contains("sourcesdkc")) { - sourcesdkc = NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc"); - return sourcesdkc; + //sourcesdkc = NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc"); + //return sourcesdkc; } return IntPtr.Zero; }); @@ -95,7 +95,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + //if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return; unsafe { From 447c37101b37302cc4fc2a11295862561e059104 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 14 Feb 2021 13:26:28 +0500 Subject: [PATCH 148/235] remove caching specify retention-days 1 for dlls, 100 for nuget --- .github/workflows/build.yml | 41 +++++++++---------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3e11634..775add0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,7 @@ jobs: with: name: linux-x64 path: "out/SourceSDK.CAPI/libsourcesdkc.so" - retention-days: 10 + retention-days: 1 if-no-files-found: error windows-cmake-build: runs-on: windows-latest @@ -42,7 +42,7 @@ jobs: with: name: win-x64 path: "out/x64-Release/SourceSDK.CAPI/sourcesdkc.dll" - retention-days: 10 + retention-days: 1 if-no-files-found: error #osx-cmake-build: # runs-on: macos-latest @@ -92,37 +92,33 @@ jobs: with: name: sourcesdk path: SourceSDK/bin/Release/*.nupkg + retention-days: 100 + if-no-files-found: error - name: Upload SourceSDK.dll uses: actions/upload-artifact@v2 with: name: sourcesdk path: SourceSDK/bin/Release/net5/publish/* + retention-days: 1 + if-no-files-found: error - name: Upload SourceSDKTest.dll uses: actions/upload-artifact@v2 with: name: sourcesdktest path: SourceSDK.Test/bin/Release/net5/publish/* + retention-days: 1 + if-no-files-found: error Test-linux: needs: Build runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Cache Steam and Garry's Mod Dedicated Server - id: cache - uses: actions/cache@v2 - with: - path: | - ./gmod - steamcmd.sh - ./linux32 - key: ${{ runner.os }}_new - name: Download SteamCMD - if: steps.cache.outputs.cache-hit != 'true' run: | wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz tar -xvzf steamcmd_linux.tar.gz rm -rfv steamcmd_linux.tar.gz - - name: Validate Garry's Mod Dedicated Server + - name: Install Garry's Mod Dedicated Server run: | ./steamcmd.sh +login anonymous +force_install_dir gmod "+app_update 4020 -beta x86-64 validate" +quit - name: Install GmodDotNet @@ -151,30 +147,17 @@ jobs: with: files: "gmod/garrysmod/data/success.txt" allow_failure: true - - name: Delete stuff 1 - run: rm -r ./gmod/garrysmod/lua/bin - - name: Delete stuff 2 - run: rm ./gmod/garrysmod/console.log Test-windows: needs: Build runs-on: windows-latest steps: - uses: actions/checkout@v2 - - name: Cache Steam and Garry's Mod Dedicated Server - id: cache - uses: actions/cache@v2 - with: - path: | - ./gmod - steamcmd.exe - key: ${{ runner.os }}_new - name: Download SteamCMD - if: steps.cache.outputs.cache-hit != 'true' run: | curl https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip -O -L powershell -Command 'Expand-Archive -LiteralPath ./steamcmd.zip -DestinationPath ./' del steamcmd.zip - - name: Validate Garry's Mod Dedicated Server + - name: Install Garry's Mod Dedicated Server shell: bash run: | ./steamcmd.exe +login anonymous +force_install_dir gmod "+app_update 4020 -beta x86-64 validate" +quit || true @@ -207,7 +190,3 @@ jobs: with: files: "gmod/garrysmod/data/success.txt" allow_failure: true - - name: Delete stuff 1 - run: Remove-Item –path ./gmod/garrysmod/lua/bin –recurse - - name: Delete stuff 2 - run: Remove-Item ./gmod/garrysmod/console.log From 3bb3ec936873d627f67f79ac7734fc5d375013f3 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 14 Feb 2021 13:50:10 +0500 Subject: [PATCH 149/235] disable NativeLibraryResolver --- SourceSDK.Test/TestModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index ad329be..636f5ba 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -67,7 +67,7 @@ private static IntPtr GetSystem(string interfaceNoVersionName, string path) 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) => + /*assembly_context.SetCustomNativeLibraryResolver((ctx, str) => { if (str.Contains("sourcesdkc")) { @@ -75,7 +75,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl //return sourcesdkc; } return IntPtr.Zero; - }); + });*/ Test(() => Dbg.Msg("Msg(string)\n")); From 9c1b816ea90c22e6a99e025ab58ce9752fd6a892 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 15 Feb 2021 22:55:05 +0500 Subject: [PATCH 150/235] IFileSystem: + MarkPathIDByRequestOnly + RelativePathToFullPath + GetSearchPath + AddPackFile --- SourceSDK.CAPI/filesystem_c.cpp | 17 +++++++++++++++++ SourceSDK/public/filesystemh.cs | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/SourceSDK.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp index eda95eb..bfaffbe 100644 --- a/SourceSDK.CAPI/filesystem_c.cpp +++ b/SourceSDK.CAPI/filesystem_c.cpp @@ -75,6 +75,7 @@ DLL_EXPORT bool IFileSystem_IsSteam(void** fsPtr) { IFileSystem* fs = (IFileSystem*)fsPtr; return fs->IsSteam(); } + DLL_EXPORT FilesystemMountRetval_t IFileSystem_MountSteamContent(void** fsPtr, int nExtraAppId = -1) { IFileSystem* fs = (IFileSystem*)fsPtr; return fs->MountSteamContent(nExtraAppId); @@ -96,6 +97,22 @@ DLL_EXPORT void IFileSystem_RemoveSearchPaths(void** fsPtr, const char* szPathID fs->RemoveSearchPaths(szPathID); } +DLL_EXPORT void IFileSystem_MarkPathIDByRequestOnly(void** fsPtr, const char* pPathID, bool bRequestOnly) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->MarkPathIDByRequestOnly(pPathID, bRequestOnly); +} +DLL_EXPORT const char* IFileSystem_RelativePathToFullPath(void** fsPtr, const char* pFileName, const char* pPathID, char* pDest, int maxLenInChars, PathTypeFilter_t pathFilter = FILTER_NONE, PathTypeQuery_t* pPathType = NULL) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->RelativePathToFullPath(pFileName, pPathID, pDest, maxLenInChars, pathFilter, pPathType); +} +DLL_EXPORT int IFileSystem_GetSearchPath(void** fsPtr, const char* pathID, bool bGetPackFiles, char* pDest, int maxLenInChars) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->GetSearchPath(pathID, bGetPackFiles, pDest, maxLenInChars); +} +DLL_EXPORT bool IFileSystem_AddPackFile(void** fsPtr, const char* fullpath, const char* pathID) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->AddPackFile(fullpath, pathID); +} DLL_EXPORT void IFileSystem_PrintSearchPaths(void** fsPtr) { diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index e833bb6..ab7bdac 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -235,6 +235,15 @@ internal static class FileSystem_c [DllImport("sourcesdkc")] internal static extern void IFileSystem_RemoveSearchPaths(IntPtr ptr, string pathID); + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_MarkPathIDByRequestOnly(IntPtr ptr, string pathID, bool requestOnly); + [DllImport("sourcesdkc")] + internal static extern string IFileSystem_RelativePathToFullPath(IntPtr ptr, string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeFilter_t pathType = 0); + [DllImport("sourcesdkc")] + internal static extern int IFileSystem_GetSearchPath(IntPtr ptr, string pathID, bool getPackFiles, out string dest, int maxLenInChars); + [DllImport("sourcesdkc")] + internal static extern bool IFileSystem_AddPackFile(IntPtr ptr, string fullpath, string pathID); + [DllImport("sourcesdkc")] internal static extern void IFileSystem_PrintSearchPaths(IntPtr ptr); } @@ -274,6 +283,11 @@ internal interface IFileSystem void RemoveAllSearchPaths(); void RemoveSearchPaths(string pathID); + void MarkPathIDByRequestOnly(string pathID, bool requestOnly); + string RelativePathToFullPath(string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeFilter_t pathType = 0); + int GetSearchPath(string pathID, bool getPackFiles, out string dest, int maxLenInChars); + bool AddPackFile(string fullpath, string pathID); + void PrintSearchPaths(); } @@ -325,6 +339,11 @@ public FileSystem(IntPtr ptr) : base(ptr) { } public void RemoveAllSearchPaths() => FileSystem_c.IFileSystem_RemoveAllSearchPaths(ptr); public void RemoveSearchPaths(string pathID) => FileSystem_c.IFileSystem_RemoveSearchPaths(ptr, pathID); + public void MarkPathIDByRequestOnly(string pathID, bool requestOnly) => FileSystem_c.IFileSystem_MarkPathIDByRequestOnly(ptr, pathID, requestOnly); + public string RelativePathToFullPath(string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeFilter_t pathType = PathTypeFilter_t.FILTER_NONE) => FileSystem_c.IFileSystem_RelativePathToFullPath(ptr, fileName, pathID, out dest, maxLenInChars, pathFilter, pathType); + public int GetSearchPath(string pathID, bool getPackFiles, out string dest, int maxLenInChars) => FileSystem_c.IFileSystem_GetSearchPath(ptr, pathID, getPackFiles, out dest, maxLenInChars); + public bool AddPackFile(string fullpath, string pathID) => FileSystem_c.IFileSystem_AddPackFile(ptr, fullpath, pathID); + public void PrintSearchPaths() => FileSystem_c.IFileSystem_PrintSearchPaths(ptr); From a7b2adbc94ca10a7f67df26aee17e4a5ba6af84f Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 15 Feb 2021 22:58:34 +0500 Subject: [PATCH 151/235] let me guess, it will not work --- SourceSDK.Test/TestModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 636f5ba..ad329be 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -67,7 +67,7 @@ private static IntPtr GetSystem(string interfaceNoVersionName, string path) 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) => + assembly_context.SetCustomNativeLibraryResolver((ctx, str) => { if (str.Contains("sourcesdkc")) { @@ -75,7 +75,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl //return sourcesdkc; } return IntPtr.Zero; - });*/ + }); Test(() => Dbg.Msg("Msg(string)\n")); From 9267840cbd8a4e19b252c0070c74b2eed2abed45 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 15 Feb 2021 22:59:31 +0500 Subject: [PATCH 152/235] return default IntPtr --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index ad329be..0ef9218 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -74,7 +74,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl //sourcesdkc = NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc"); //return sourcesdkc; } - return IntPtr.Zero; + return default; }); Test(() => Dbg.Msg("Msg(string)\n")); From a9e5b7828c0dae40ca62bec41a2248b19ef613da Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 16 Feb 2021 08:56:31 +0500 Subject: [PATCH 153/235] try something else --- SourceSDK.Test/TestModule.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 0ef9218..4df845c 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -71,10 +71,12 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl { if (str.Contains("sourcesdkc")) { - //sourcesdkc = NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc"); - //return 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 default; + return IntPtr.Zero; }); Test(() => Dbg.Msg("Msg(string)\n")); @@ -96,7 +98,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { //if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - return; + return; unsafe { string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "filesystem_stdio.so"; @@ -147,6 +149,8 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl } }); + assembly_context.SetCustomNativeLibraryResolver(null); + Debug.Assert(!failed); } From 420f247783b82baf0163182c49cf32e858287309 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 16 Feb 2021 08:57:31 +0500 Subject: [PATCH 154/235] reduce retention-days to 90 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 775add0..4ebeed9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -92,7 +92,7 @@ jobs: with: name: sourcesdk path: SourceSDK/bin/Release/*.nupkg - retention-days: 100 + retention-days: 90 if-no-files-found: error - name: Upload SourceSDK.dll uses: actions/upload-artifact@v2 From eb0c7028b96cfde8b704fdddc5c42367814e5f91 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 16 Feb 2021 09:02:12 +0500 Subject: [PATCH 155/235] enable test --- SourceSDK.Test/TestModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 4df845c..1189961 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -97,8 +97,8 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { - //if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - return; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + return; unsafe { string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "filesystem_stdio.so"; From a72de6a6f4536a4e7d36ffb356fd863e99ff0dce Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 16 Feb 2021 09:02:44 +0500 Subject: [PATCH 156/235] enable linux test --- SourceSDK.Test/TestModule.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 1189961..fedfa89 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -97,8 +97,6 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - return; unsafe { string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "filesystem_stdio.so"; From 65815a3d239a09ba2cb877f345046abc3da39dfe Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 16 Feb 2021 09:34:23 +0500 Subject: [PATCH 157/235] some documentation add null default values pathType is PathTypeQuery_t rename PATH to PathTypeQuery_t --- SourceSDK/public/filesystemh.cs | 173 +++++++++++++++++--------------- 1 file changed, 94 insertions(+), 79 deletions(-) diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index ab7bdac..74c82ad 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -8,9 +8,7 @@ namespace GmodNET.SourceSDK public enum EPureServerFileClass { - /// - /// dummy debugging value - /// + /// dummy debugging value ePureServerFileClass_Unknown = -1, ePureServerFileClass_Any = 0, ePureServerFileClass_AnyTrusted = 1, @@ -45,57 +43,35 @@ public enum FileWarningLevel_t /// Report all open/close/read/write events and all async I/O file events to the console ( !slower(est)! ) FILESYSTEM_WARNING_REPORTALLACCESSES_ASYNC = 6, } - /// - /// search path filtering - /// + /// search path filtering public enum PathTypeFilter_t { - /// - /// no filtering, all search path types match - /// + /// no filtering, all search path types match FILTER_NONE = 0, - /// - /// pack based search paths are culled (maps and zips) - /// + /// pack based search paths are culled (maps and zips) FILTER_CULLPACK = 1, - /// - /// non-pack based search paths are culled - /// + /// non-pack based search paths are culled FILTER_CULLNONPACK = 2, } - // search path querying (bit flags) - public enum PATH + /// search path querying (bit flags) + public enum PathTypeQuery_t { - /// - /// normal path, not pack based - /// + /// normal path, not pack based PATH_IS_NORMAL = 0x00, - /// - /// path is a pack file - /// + /// path is a pack file PATH_IS_PACKFILE = 0x01, - /// - /// path is a map pack file - /// + /// path is a map pack file PATH_IS_MAPPACKFILE = 0x02, - /// - /// path is the remote filesystem - /// + /// path is the remote filesystem PATH_IS_REMOTE = 0x04, } public enum DVDMode_t { - /// - /// not using dvd - /// + /// not using dvd DVDMODE_OFF = 0, - /// - /// dvd device only - /// + /// dvd device only DVDMODE_STRICT = 1, - /// - /// dev mode, mutiple devices ok - /// + /// dev mode, mutiple devices ok DVDMODE_DEV = 2 } public enum FilesystemMountRetval_t @@ -105,37 +81,47 @@ public enum FilesystemMountRetval_t } public enum SearchPathAdd_t { - /// - /// First path searched - /// + /// First path searched PATH_ADD_TO_HEAD = 0, - /// - /// Last path searched - /// + /// Last path searched PATH_ADD_TO_TAIL = 1 } public enum FilesystemOpenExFlags_t { FSOPEN_UNBUFFERED = (1 << 0), - FSOPEN_FORCE_TRACK_CRC = (1 << 1), // This makes it calculate a CRC for the file (if the file came from disk) regardless - // of the IFileList passed to RegisterFileWhitelist. - FSOPEN_NEVERINPACK = (1 << 2), // 360 only, hint to FS that file is not allowed to be in pack file + /// This makes it calculate a CRC for the file (if the file came from disk) regardless of the IFileList passed to RegisterFileWhitelist. + FSOPEN_FORCE_TRACK_CRC = (1 << 1), + /// 360 only, hint to FS that file is not allowed to be in pack file + FSOPEN_NEVERINPACK = (1 << 2), } public enum FSAsyncStatus_t { - FSASYNC_ERR_NOT_MINE = -8, // Filename not part of the specified file system, try a different one. (Used internally to find the right filesystem) - FSASYNC_ERR_RETRY_LATER = -7, // Failure for a reason that might be temporary. You might retry, but not immediately. (E.g. Network problems) - FSASYNC_ERR_ALIGNMENT = -6, // read parameters invalid for unbuffered IO - FSASYNC_ERR_FAILURE = -5, // hard subsystem failure - FSASYNC_ERR_READING = -4, // read error on file - FSASYNC_ERR_NOMEMORY = -3, // out of memory for file read - FSASYNC_ERR_UNKNOWNID = -2, // caller's provided id is not recognized - FSASYNC_ERR_FILEOPEN = -1, // filename could not be opened (bad path, not exist, etc) - FSASYNC_OK = 0, // operation is successful - FSASYNC_STATUS_PENDING = 1, // file is properly queued, waiting for service - FSASYNC_STATUS_INPROGRESS = 2, // file is being accessed - FSASYNC_STATUS_ABORTED = 3, // file was aborted by caller - FSASYNC_STATUS_UNSERVICED = 4, // file is not yet queued + ///Filename not part of the specified file system, try a different one. (Used internally to find the right filesystem) + FSASYNC_ERR_NOT_MINE = -8, + ///Failure for a reason that might be temporary. You might retry, but not immediately. (E.g. Network problems) + FSASYNC_ERR_RETRY_LATER = -7, + ///read parameters invalid for unbuffered IO + FSASYNC_ERR_ALIGNMENT = -6, + ///hard subsystem failure + FSASYNC_ERR_FAILURE = -5, + ///read error on file + FSASYNC_ERR_READING = -4, + ///out of memory for file read + FSASYNC_ERR_NOMEMORY = -3, + ///caller's provided id is not recognized + FSASYNC_ERR_UNKNOWNID = -2, + ///filename could not be opened (bad path, not exist, etc) + FSASYNC_ERR_FILEOPEN = -1, + ///operation is successful + FSASYNC_OK = 0, + ///file is properly queued, waiting for service + FSASYNC_STATUS_PENDING = 1, + ///file is being accessed + FSASYNC_STATUS_INPROGRESS = 2, + ///file was aborted by caller + FSASYNC_STATUS_ABORTED = 3, + ///file is not yet queued + FSASYNC_STATUS_UNSERVICED = 4, } public enum FSAsyncFlags_t { @@ -156,21 +142,15 @@ public enum FSAsyncFlags_t /// FSASYNC_FLAGS_NULLTERMINATE = (1 << 3) } - /// - /// Return value for CheckFileCRC. - /// + /// Return value for CheckFileCRC. public enum EFileCRCStatus { - /// - /// We don't have this file. - /// + /// We don't have this file. k_eFileCRCStatus_CantOpenFile = 0, k_eFileCRCStatus_GotCRC = 1, k_eFileCRCStatus_FileInVPK = 2 } - /// - /// Used in CacheFileCRCs. - /// + /// Used in CacheFileCRCs. public enum ECacheCRCType { k_eCacheCRCType_SingleFile = 0, @@ -229,7 +209,7 @@ internal static class FileSystem_c [DllImport("sourcesdkc")] internal static extern void IFileSystem_AddSearchPath(IntPtr ptr, string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL); [DllImport("sourcesdkc")] - internal static extern bool IFileSystem_RemoveSearchPath(IntPtr ptr, string path, string pathID); + internal static extern bool IFileSystem_RemoveSearchPath(IntPtr ptr, string path, string pathID = null); [DllImport("sourcesdkc")] internal static extern void IFileSystem_RemoveAllSearchPaths(IntPtr ptr); [DllImport("sourcesdkc")] @@ -238,7 +218,7 @@ internal static class FileSystem_c [DllImport("sourcesdkc")] internal static extern void IFileSystem_MarkPathIDByRequestOnly(IntPtr ptr, string pathID, bool requestOnly); [DllImport("sourcesdkc")] - internal static extern string IFileSystem_RelativePathToFullPath(IntPtr ptr, string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeFilter_t pathType = 0); + internal static extern string IFileSystem_RelativePathToFullPath(IntPtr ptr, string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeQuery_t pathType = PathTypeQuery_t.PATH_IS_NORMAL); [DllImport("sourcesdkc")] internal static extern int IFileSystem_GetSearchPath(IntPtr ptr, string pathID, bool getPackFiles, out string dest, int maxLenInChars); [DllImport("sourcesdkc")] @@ -253,7 +233,11 @@ internal interface IBaseFileSystem int Read(IntPtr output, int size, IntPtr file); int Write(IntPtr input, int size, IntPtr file); - IntPtr Open(string fileName, string options, string pathID); + /// + /// + /// if null, all paths will be searched for the file + /// + IntPtr Open(string fileName, string options, string pathID = null); void Close(IntPtr file); void Seek(IntPtr file, int pos, in FileSystemSeek_t seekType); @@ -274,18 +258,49 @@ internal interface IBaseFileSystem } internal interface IFileSystem { + #region Steam operations bool IsSteam(); FilesystemMountRetval_t MountSteamContent(int extraAppId = -1); - + #endregion + /// + /// Add paths in priority order (mod dir, game dir, ....) + /// If the path is the relative path to a .bsp file, then any previous .bsp file + /// override is cleared and the current .bsp is searched for an embedded PAK file + /// and this file becomes the highest priority search path ( i.e., it's looked at first + /// even before the mod's file system path ). + /// + /// If one or more .pak files are in the specified directory, then they are added after the file system path + /// + /// void AddSearchPath(string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL); - bool RemoveSearchPath(string path, string pathID); + bool RemoveSearchPath(string path, string pathID = null); + /// Remove all search paths (including write path?) void RemoveAllSearchPaths(); + /// Remove search paths associated with a given pathID void RemoveSearchPaths(string pathID); + /// + /// This is for optimization. If you mark a path ID as "by request only", then files inside it + /// will only be accessed if the path ID is specifically requested. Otherwise, it will be ignored. + /// If there are currently no search paths with the specified path ID, then it will still + /// remember it in case you add search paths with this path ID. + /// + /// + /// void MarkPathIDByRequestOnly(string pathID, bool requestOnly); - string RelativePathToFullPath(string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeFilter_t pathType = 0); + /// converts a partial path into a full path + string RelativePathToFullPath(string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeQuery_t pathType = PathTypeQuery_t.PATH_IS_NORMAL); + /// + /// Returns the search path + /// + /// + /// + /// the search path, each path is separated by ;s + /// + /// the length of the string returned int GetSearchPath(string pathID, bool getPackFiles, out string dest, int maxLenInChars); + /// interface for custom pack files > 4Gb bool AddPackFile(string fullpath, string pathID); @@ -303,7 +318,7 @@ public class BaseFileSystem : IBaseFileSystem public int Read(IntPtr output, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Read(ptr, output, size, file); public int Write(IntPtr input, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Write(ptr, input, size, file); - public IntPtr Open(string fileName, string options, string pathID) => BaseFileSystem_c.IBaseFileSystem_Open(ptr, fileName, options, pathID); + public IntPtr Open(string fileName, string options, string pathID = null) => BaseFileSystem_c.IBaseFileSystem_Open(ptr, fileName, options, pathID); public void Close(IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Close(ptr, file); public void Seek(IntPtr file, int pos, in FileSystemSeek_t seekType) => BaseFileSystem_c.IBaseFileSystem_Seek(ptr, file, pos, seekType); @@ -335,12 +350,12 @@ public FileSystem(IntPtr ptr) : base(ptr) { } public FilesystemMountRetval_t MountSteamContent(int extraAppId = -1) => FileSystem_c.IFileSystem_MountSteamContent(ptr, extraAppId); public void AddSearchPath(string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL) => FileSystem_c.IFileSystem_AddSearchPath(ptr, path, pathID, addType); - public bool RemoveSearchPath(string path, string pathID) => FileSystem_c.IFileSystem_RemoveSearchPath(ptr, path, pathID); + public bool RemoveSearchPath(string path, string pathID = null) => FileSystem_c.IFileSystem_RemoveSearchPath(ptr, path, pathID); public void RemoveAllSearchPaths() => FileSystem_c.IFileSystem_RemoveAllSearchPaths(ptr); public void RemoveSearchPaths(string pathID) => FileSystem_c.IFileSystem_RemoveSearchPaths(ptr, pathID); public void MarkPathIDByRequestOnly(string pathID, bool requestOnly) => FileSystem_c.IFileSystem_MarkPathIDByRequestOnly(ptr, pathID, requestOnly); - public string RelativePathToFullPath(string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeFilter_t pathType = PathTypeFilter_t.FILTER_NONE) => FileSystem_c.IFileSystem_RelativePathToFullPath(ptr, fileName, pathID, out dest, maxLenInChars, pathFilter, pathType); + public string RelativePathToFullPath(string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeQuery_t pathType = PathTypeQuery_t.PATH_IS_NORMAL) => FileSystem_c.IFileSystem_RelativePathToFullPath(ptr, fileName, pathID, out dest, maxLenInChars, pathFilter, pathType); public int GetSearchPath(string pathID, bool getPackFiles, out string dest, int maxLenInChars) => FileSystem_c.IFileSystem_GetSearchPath(ptr, pathID, getPackFiles, out dest, maxLenInChars); public bool AddPackFile(string fullpath, string pathID) => FileSystem_c.IFileSystem_AddPackFile(ptr, fullpath, pathID); @@ -352,7 +367,7 @@ public FileSystem(IntPtr ptr) : base(ptr) { } public int Read(IntPtr output, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Read(ptr, output, size, file); public int Write(IntPtr input, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Write(ptr, input, size, file); - public IntPtr Open(string fileName, string options, string pathID) => BaseFileSystem_c.IBaseFileSystem_Open(ptr, fileName, options, pathID); + public IntPtr Open(string fileName, string options, string pathID = null) => BaseFileSystem_c.IBaseFileSystem_Open(ptr, fileName, options, pathID); public void Close(IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Close(ptr, file); public void Seek(IntPtr file, int pos, in FileSystemSeek_t seekType) => BaseFileSystem_c.IBaseFileSystem_Seek(ptr, file, pos, seekType); From ca8323c20bb37f4be9b86dc0314a8ecfa24b0379 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 16 Feb 2021 09:35:39 +0500 Subject: [PATCH 158/235] fix debug message --- SourceSDK.Test/TestModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index fedfa89..55625b4 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -107,7 +107,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl } if (!interfaceh.Sys_LoadInterface(path, BaseFileSystem.BASEFILESYSTEM_INTERFACE_VERSION, out module, out IntPtr baseFSPtr)) { - Console.WriteLine("failed loading FS"); + Console.WriteLine("failed loading BFS"); } if (fSPtr == IntPtr.Zero || baseFSPtr == IntPtr.Zero) From e44f2de4be5b99907dae4b0fd3cc04785356b8e9 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 16 Feb 2021 09:47:43 +0500 Subject: [PATCH 159/235] Free twice --- SourceSDK.Test/TestModule.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 55625b4..afa57ed 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -115,6 +115,12 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("unloading it"); NativeLibrary.Free(module); Console.WriteLine("unloaded ???"); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Console.WriteLine("unload second time"); + NativeLibrary.Free(module); + Console.WriteLine("unloaded !!!"); + } return; } From ec9b83e223fee3dcf2ddba16ea7817e417b49b6c Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 16 Feb 2021 21:09:19 +0500 Subject: [PATCH 160/235] do not unload twice --- SourceSDK.Test/TestModule.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index afa57ed..55625b4 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -115,12 +115,6 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("unloading it"); NativeLibrary.Free(module); Console.WriteLine("unloaded ???"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - Console.WriteLine("unload second time"); - NativeLibrary.Free(module); - Console.WriteLine("unloaded !!!"); - } return; } From c2ca3c9854164db1768a462f876e24ff68c80654 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 16 Feb 2021 21:41:09 +0500 Subject: [PATCH 161/235] IFileSystem + RemoveFile + RenameFile + CreateDirHierarchy + IsDirectory + FileTimeToString add regions --- SourceSDK.CAPI/filesystem_c.cpp | 20 ++++++++++++++++++++ SourceSDK/public/filesystemh.cs | 30 +++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/SourceSDK.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp index bfaffbe..c559812 100644 --- a/SourceSDK.CAPI/filesystem_c.cpp +++ b/SourceSDK.CAPI/filesystem_c.cpp @@ -114,6 +114,26 @@ DLL_EXPORT bool IFileSystem_AddPackFile(void** fsPtr, const char* fullpath, cons return fs->AddPackFile(fullpath, pathID); } +DLL_EXPORT void IFileSystem_RemoveFile(void** fsPtr, char const* pRelativePath, const char* pathID = 0) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->RemoveFile(pRelativePath, pathID); +} +DLL_EXPORT bool IFileSystem_RenameFile(void** fsPtr, char const* pOldPath, char const* pNewPath, const char* pathID = 0) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->RenameFile(pOldPath, pNewPath, pathID); +} +DLL_EXPORT void IFileSystem_CreateDirHierarchy(void** fsPtr, const char* path, const char* pathID = 0) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->CreateDirHierarchy(path, pathID); +} +DLL_EXPORT bool IFileSystem_IsDirectory(void** fsPtr, const char* pFileName, const char* pathID = 0) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->IsDirectory(pFileName, pathID); +} +DLL_EXPORT void IFileSystem_FileTimeToString(void** fsPtr, char* pStrip, int maxCharsIncludingTerminator, long fileTime) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->FileTimeToString(pStrip, maxCharsIncludingTerminator, fileTime); +} DLL_EXPORT void IFileSystem_PrintSearchPaths(void** fsPtr) { IFileSystem* fs = (IFileSystem*)fsPtr; diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 74c82ad..a65ba68 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -224,6 +224,17 @@ internal static class FileSystem_c [DllImport("sourcesdkc")] internal static extern bool IFileSystem_AddPackFile(IntPtr ptr, string fullpath, string pathID); + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_RemoveFile(IntPtr ptr, string relativePath, string pathID = null); + [DllImport("sourcesdkc")] + internal static extern bool IFileSystem_RenameFile(IntPtr ptr, string oldPath, string newPath, string pathID = null); + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_CreateDirHierarchy(IntPtr ptr, string path, string pathID = null); + [DllImport("sourcesdkc")] + internal static extern bool IFileSystem_IsDirectory(IntPtr ptr, string fileName, string pathID = null); + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_FileTimeToString(IntPtr ptr, out string strip, int maxCharsIncludingTerminator, long fileTime); + [DllImport("sourcesdkc")] internal static extern void IFileSystem_PrintSearchPaths(IntPtr ptr); } @@ -263,6 +274,7 @@ internal interface IFileSystem FilesystemMountRetval_t MountSteamContent(int extraAppId = -1); #endregion + #region Search path manipulation /// /// Add paths in priority order (mod dir, game dir, ....) /// If the path is the relative path to a .bsp file, then any previous .bsp file @@ -302,7 +314,17 @@ internal interface IFileSystem int GetSearchPath(string pathID, bool getPackFiles, out string dest, int maxLenInChars); /// interface for custom pack files > 4Gb bool AddPackFile(string fullpath, string pathID); - + #endregion + #region File manipulation operations + ///Deletes a file (on the WritePath) + void RemoveFile(string relativePath, string pathID = null); + ///Renames a file (on the WritePath) + bool RenameFile(string oldPath, string newPath, string pathID = null); + ///create a local directory structure + void CreateDirHierarchy(string path, string pathID = null); + bool IsDirectory(string fileName, string pathID = null); + void FileTimeToString(out string strip, int maxCharsIncludingTerminator, long fileTime); + #endregion void PrintSearchPaths(); } @@ -383,5 +405,11 @@ public FileSystem(IntPtr ptr) : base(ptr) { } public bool SetFileWriteable(string fileName, bool writeable, string pathID) => BaseFileSystem_c.IBaseFileSystem_SetFileWritable(ptr, fileName, writeable, pathID); public long GetFileTime(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_GetFileTime(ptr, fileName, pathID); + + public void RemoveFile(string relativePath, string pathID = null) => FileSystem_c.IFileSystem_RemoveFile(ptr, relativePath, pathID); + public bool RenameFile(string oldPath, string newPath, string pathID = null) => FileSystem_c.IFileSystem_RenameFile(ptr, oldPath, newPath, pathID); + public void CreateDirHierarchy(string path, string pathID = null) => FileSystem_c.IFileSystem_CreateDirHierarchy(ptr, path, pathID); + public bool IsDirectory(string fileName, string pathID = null) => FileSystem_c.IFileSystem_IsDirectory(ptr, fileName, pathID); + public void FileTimeToString(out string strip, int maxCharsIncludingTerminator, long fileTime) => FileSystem_c.IFileSystem_FileTimeToString(ptr, out strip, maxCharsIncludingTerminator, fileTime); } } From cacceb181c143214bffd4280ee4fd9206734c104 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Wed, 17 Feb 2021 21:46:36 +0500 Subject: [PATCH 162/235] IFileSystem + Open file operations: + SetBufferSize + IsOk + EndOfFile + ReadLine + FPrintf --- SourceSDK.CAPI/filesystem_c.cpp | 21 +++++++++ SourceSDK/public/filesystemh.cs | 76 +++++++++++++++++++-------------- 2 files changed, 65 insertions(+), 32 deletions(-) diff --git a/SourceSDK.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp index c559812..6f96468 100644 --- a/SourceSDK.CAPI/filesystem_c.cpp +++ b/SourceSDK.CAPI/filesystem_c.cpp @@ -135,6 +135,27 @@ DLL_EXPORT void IFileSystem_FileTimeToString(void** fsPtr, char* pStrip, int max fs->FileTimeToString(pStrip, maxCharsIncludingTerminator, fileTime); } +DLL_EXPORT void IFileSystem_SetBufferSize(void** fsPtr, FileHandle_t file, unsigned int nBytes) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->SetBufferSize(file, nBytes); +} +DLL_EXPORT bool IFileSystem_IsOk(void** fsPtr, FileHandle_t file) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->IsOk(file); +} +DLL_EXPORT bool IFileSystem_EndOfFile(void** fsPtr, FileHandle_t file) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->EndOfFile(file); +} +DLL_EXPORT char* IFileSystem_ReadLine(void** fsPtr, char* pOutput, int maxChars, FileHandle_t file) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->ReadLine(pOutput, maxChars, file); +} +DLL_EXPORT int IFileSystem_FPrintf(void** fsPtr, FileHandle_t file, const char* pFormat, const char* pMsg = nullptr) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->FPrintf(file, pFormat, pMsg); +} + DLL_EXPORT void IFileSystem_PrintSearchPaths(void** fsPtr) { IFileSystem* fs = (IFileSystem*)fsPtr; fs->PrintSearchPaths(); diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index a65ba68..f166895 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -235,6 +235,17 @@ internal static class FileSystem_c [DllImport("sourcesdkc")] internal static extern void IFileSystem_FileTimeToString(IntPtr ptr, out string strip, int maxCharsIncludingTerminator, long fileTime); + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_SetBufferSize(IntPtr ptr, IntPtr file, uint bytes); + [DllImport("sourcesdkc")] + internal static extern bool IFileSystem_IsOk(IntPtr ptr, IntPtr file); + [DllImport("sourcesdkc")] + internal static extern bool IFileSystem_EndOfFile(IntPtr ptr, IntPtr file); + [DllImport("sourcesdkc")] + internal static extern string IFileSystem_ReadLine(IntPtr ptr, out string output, int maxChars, IntPtr file); + [DllImport("sourcesdkc")] + internal static extern int IFileSystem_FPrintf(IntPtr ptr, IntPtr file, string format, string msg = null); + [DllImport("sourcesdkc")] internal static extern void IFileSystem_PrintSearchPaths(IntPtr ptr); } @@ -264,14 +275,11 @@ internal interface IBaseFileSystem bool SetFileWriteable(string fileName, bool writeable, string pathID); long GetFileTime(string fileName, string pathID); - - } internal interface IFileSystem { #region Steam operations bool IsSteam(); - FilesystemMountRetval_t MountSteamContent(int extraAppId = -1); #endregion #region Search path manipulation @@ -291,25 +299,17 @@ internal interface IFileSystem void RemoveAllSearchPaths(); /// Remove search paths associated with a given pathID void RemoveSearchPaths(string pathID); - /// /// This is for optimization. If you mark a path ID as "by request only", then files inside it /// will only be accessed if the path ID is specifically requested. Otherwise, it will be ignored. /// If there are currently no search paths with the specified path ID, then it will still /// remember it in case you add search paths with this path ID. /// - /// - /// void MarkPathIDByRequestOnly(string pathID, bool requestOnly); /// converts a partial path into a full path string RelativePathToFullPath(string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeQuery_t pathType = PathTypeQuery_t.PATH_IS_NORMAL); - /// - /// Returns the search path - /// - /// - /// + /// Returns the search path /// the search path, each path is separated by ;s - /// /// the length of the string returned int GetSearchPath(string pathID, bool getPackFiles, out string dest, int maxLenInChars); /// interface for custom pack files > 4Gb @@ -325,7 +325,13 @@ internal interface IFileSystem bool IsDirectory(string fileName, string pathID = null); void FileTimeToString(out string strip, int maxCharsIncludingTerminator, long fileTime); #endregion - + #region Open file operations + void SetBufferSize(IntPtr file, uint bytes); + bool IsOk(IntPtr file); + bool EndOfFile(IntPtr file); + string ReadLine(out string output, int maxChars, IntPtr file); + int FPrintf(IntPtr file, string format, string msg = null); + #endregion void PrintSearchPaths(); } @@ -366,25 +372,7 @@ public class FileSystem : IAppSystem, IBaseFileSystem, IFileSystem public FileSystem(IntPtr ptr) : base(ptr) { } - - public bool IsSteam() => FileSystem_c.IFileSystem_IsSteam(ptr); - - public FilesystemMountRetval_t MountSteamContent(int extraAppId = -1) => FileSystem_c.IFileSystem_MountSteamContent(ptr, extraAppId); - - public void AddSearchPath(string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL) => FileSystem_c.IFileSystem_AddSearchPath(ptr, path, pathID, addType); - public bool RemoveSearchPath(string path, string pathID = null) => FileSystem_c.IFileSystem_RemoveSearchPath(ptr, path, pathID); - public void RemoveAllSearchPaths() => FileSystem_c.IFileSystem_RemoveAllSearchPaths(ptr); - public void RemoveSearchPaths(string pathID) => FileSystem_c.IFileSystem_RemoveSearchPaths(ptr, pathID); - - public void MarkPathIDByRequestOnly(string pathID, bool requestOnly) => FileSystem_c.IFileSystem_MarkPathIDByRequestOnly(ptr, pathID, requestOnly); - public string RelativePathToFullPath(string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeQuery_t pathType = PathTypeQuery_t.PATH_IS_NORMAL) => FileSystem_c.IFileSystem_RelativePathToFullPath(ptr, fileName, pathID, out dest, maxLenInChars, pathFilter, pathType); - public int GetSearchPath(string pathID, bool getPackFiles, out string dest, int maxLenInChars) => FileSystem_c.IFileSystem_GetSearchPath(ptr, pathID, getPackFiles, out dest, maxLenInChars); - public bool AddPackFile(string fullpath, string pathID) => FileSystem_c.IFileSystem_AddPackFile(ptr, fullpath, pathID); - - - public void PrintSearchPaths() => FileSystem_c.IFileSystem_PrintSearchPaths(ptr); - - /// IBaseFileSystem + #region IBaseFileSystem public int Read(IntPtr output, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Read(ptr, output, size, file); public int Write(IntPtr input, int size, IntPtr file) => BaseFileSystem_c.IBaseFileSystem_Write(ptr, input, size, file); @@ -406,10 +394,34 @@ public FileSystem(IntPtr ptr) : base(ptr) { } public long GetFileTime(string fileName, string pathID) => BaseFileSystem_c.IBaseFileSystem_GetFileTime(ptr, fileName, pathID); + #endregion + + public bool IsSteam() => FileSystem_c.IFileSystem_IsSteam(ptr); + + public FilesystemMountRetval_t MountSteamContent(int extraAppId = -1) => FileSystem_c.IFileSystem_MountSteamContent(ptr, extraAppId); + + public void AddSearchPath(string path, string pathID, SearchPathAdd_t addType = SearchPathAdd_t.PATH_ADD_TO_TAIL) => FileSystem_c.IFileSystem_AddSearchPath(ptr, path, pathID, addType); + public bool RemoveSearchPath(string path, string pathID = null) => FileSystem_c.IFileSystem_RemoveSearchPath(ptr, path, pathID); + public void RemoveAllSearchPaths() => FileSystem_c.IFileSystem_RemoveAllSearchPaths(ptr); + public void RemoveSearchPaths(string pathID) => FileSystem_c.IFileSystem_RemoveSearchPaths(ptr, pathID); + + public void MarkPathIDByRequestOnly(string pathID, bool requestOnly) => FileSystem_c.IFileSystem_MarkPathIDByRequestOnly(ptr, pathID, requestOnly); + public string RelativePathToFullPath(string fileName, string pathID, out string dest, int maxLenInChars, PathTypeFilter_t pathFilter = PathTypeFilter_t.FILTER_NONE, in PathTypeQuery_t pathType = PathTypeQuery_t.PATH_IS_NORMAL) => FileSystem_c.IFileSystem_RelativePathToFullPath(ptr, fileName, pathID, out dest, maxLenInChars, pathFilter, pathType); + public int GetSearchPath(string pathID, bool getPackFiles, out string dest, int maxLenInChars) => FileSystem_c.IFileSystem_GetSearchPath(ptr, pathID, getPackFiles, out dest, maxLenInChars); + public bool AddPackFile(string fullpath, string pathID) => FileSystem_c.IFileSystem_AddPackFile(ptr, fullpath, pathID); + public void RemoveFile(string relativePath, string pathID = null) => FileSystem_c.IFileSystem_RemoveFile(ptr, relativePath, pathID); public bool RenameFile(string oldPath, string newPath, string pathID = null) => FileSystem_c.IFileSystem_RenameFile(ptr, oldPath, newPath, pathID); public void CreateDirHierarchy(string path, string pathID = null) => FileSystem_c.IFileSystem_CreateDirHierarchy(ptr, path, pathID); public bool IsDirectory(string fileName, string pathID = null) => FileSystem_c.IFileSystem_IsDirectory(ptr, fileName, pathID); public void FileTimeToString(out string strip, int maxCharsIncludingTerminator, long fileTime) => FileSystem_c.IFileSystem_FileTimeToString(ptr, out strip, maxCharsIncludingTerminator, fileTime); + + public void SetBufferSize(IntPtr file, uint bytes) => FileSystem_c.IFileSystem_SetBufferSize(ptr, file, bytes); + public bool IsOk(IntPtr file) => FileSystem_c.IFileSystem_IsOk(ptr, file); + public bool EndOfFile(IntPtr file) => FileSystem_c.IFileSystem_EndOfFile(ptr, file); + public string ReadLine(out string output, int maxChars, IntPtr file) => FileSystem_c.IFileSystem_ReadLine(ptr, out output, maxChars, file); + public int FPrintf(IntPtr file, string format, string msg = null) => FileSystem_c.IFileSystem_FPrintf(ptr, file, format, msg); + + public void PrintSearchPaths() => FileSystem_c.IFileSystem_PrintSearchPaths(ptr); } } From bb60cacda2978cfabb361ae54d30464dd0e58cb0 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 19 Feb 2021 14:07:37 +0500 Subject: [PATCH 163/235] run ci on all branches --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4ebeed9..4e64c01 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: Build & Test on: push: - branches: [ main ] + branches: [ '*' ] pull_request: branches: [ main ] jobs: From 908e1ee24491e294df1396978ec2a025bac15c9d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 19 Feb 2021 21:35:04 +0500 Subject: [PATCH 164/235] add DX_TO_GL_ABSTRACTION define uncomment isurface_c.cpp --- SourceSDK.CAPI/CMakeLists.txt | 2 ++ SourceSDK.CAPI/vgui/isurface_c.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index 8c82e42..6608468 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -29,6 +29,7 @@ elseif(APPLE) "FD_SETSIZE=10240" "OVERRIDE_V_DEFINES" "SWDS" + "DX_TO_GL_ABSTRACTION" ) set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/osx64") elseif(UNIX) @@ -39,6 +40,7 @@ elseif(UNIX) "LINUX" "_LINUX" "SWDS" + "DX_TO_GL_ABSTRACTION" ) set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/linux64") endif() diff --git a/SourceSDK.CAPI/vgui/isurface_c.cpp b/SourceSDK.CAPI/vgui/isurface_c.cpp index 955cfc1..c332eb5 100644 --- a/SourceSDK.CAPI/vgui/isurface_c.cpp +++ b/SourceSDK.CAPI/vgui/isurface_c.cpp @@ -1,8 +1,8 @@ -/*#include +#include DLL_EXPORT void ISurface_DrawSetTextureRGBAex(void** ptr, int id, const unsigned char* rgba, int wide, int tall, ImageFormat imageFormat) { vgui::ISurface* surf = (vgui::ISurface*)ptr; surf->DrawSetTextureRGBAEx(id, rgba, wide, tall, imageFormat); } -*/ + From 0e5c6b248e2ed814695d0ecdcd914306bbc3f613 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 15:52:07 +0500 Subject: [PATCH 165/235] add NormalDecodeMode_t add ImageFormat add ISurface class add ISurface_DrawFilledRect --- SourceSDK.CAPI/vgui/isurface_c.cpp | 5 + .../public/bitmap/imageformat_declarations.cs | 103 ++++++++++++++++++ SourceSDK/public/vgui/isurface.cs | 24 ++++ 3 files changed, 132 insertions(+) create mode 100644 SourceSDK/public/bitmap/imageformat_declarations.cs create mode 100644 SourceSDK/public/vgui/isurface.cs diff --git a/SourceSDK.CAPI/vgui/isurface_c.cpp b/SourceSDK.CAPI/vgui/isurface_c.cpp index c332eb5..e64abac 100644 --- a/SourceSDK.CAPI/vgui/isurface_c.cpp +++ b/SourceSDK.CAPI/vgui/isurface_c.cpp @@ -1,5 +1,10 @@ #include +DLL_EXPORT void ISurface_DrawFilledRect(void** ptr, int x0,int y0, int x1, int y1) { + vgui::ISurface* surf = (vgui::ISurface*)ptr; + surf->DrawFilledRect(x0, y0, x1, y1); +} + DLL_EXPORT void ISurface_DrawSetTextureRGBAex(void** ptr, int id, const unsigned char* rgba, int wide, int tall, ImageFormat imageFormat) { vgui::ISurface* surf = (vgui::ISurface*)ptr; surf->DrawSetTextureRGBAEx(id, rgba, wide, tall, imageFormat); diff --git a/SourceSDK/public/bitmap/imageformat_declarations.cs b/SourceSDK/public/bitmap/imageformat_declarations.cs new file mode 100644 index 0000000..6ba3a76 --- /dev/null +++ b/SourceSDK/public/bitmap/imageformat_declarations.cs @@ -0,0 +1,103 @@ +namespace GmodNET.SourceSDK.bitmap +{ + //TODO omit NORMAL_DECODE_? + public enum NormalDecodeMode_t + { + NORMAL_DECODE_NONE = 0, + NORMAL_DECODE_ATI2N = 1, + NORMAL_DECODE_ATI2N_ALPHA = 2 + }; + public enum ImageFormat + { + /// Use this image format if you want to perform tool operations on the texture + IMAGE_FORMAT_DEFAULT = -2, + IMAGE_FORMAT_UNKNOWN = -1, + IMAGE_FORMAT_RGBA8888 = 0, + IMAGE_FORMAT_ABGR8888, + IMAGE_FORMAT_RGB888, + IMAGE_FORMAT_BGR888, + IMAGE_FORMAT_RGB565, + IMAGE_FORMAT_I8, + IMAGE_FORMAT_IA88, + IMAGE_FORMAT_P8, + IMAGE_FORMAT_A8, + IMAGE_FORMAT_RGB888_BLUESCREEN, + IMAGE_FORMAT_BGR888_BLUESCREEN, + IMAGE_FORMAT_ARGB8888, + IMAGE_FORMAT_BGRA8888, + IMAGE_FORMAT_DXT1, + IMAGE_FORMAT_DXT3, + IMAGE_FORMAT_DXT5, + IMAGE_FORMAT_BGRX8888, + IMAGE_FORMAT_BGR565, + IMAGE_FORMAT_BGRX5551, + IMAGE_FORMAT_BGRA4444, + IMAGE_FORMAT_DXT1_ONEBITALPHA, + IMAGE_FORMAT_BGRA5551, + IMAGE_FORMAT_UV88, + IMAGE_FORMAT_UVWQ8888, + IMAGE_FORMAT_RGBA16161616F, + IMAGE_FORMAT_RGBA16161616, + IMAGE_FORMAT_UVLX8888, + /// Single-channel 32-bit floating point + IMAGE_FORMAT_R32F, + /// NOTE: D3D9 does not have this format + IMAGE_FORMAT_RGB323232F, + IMAGE_FORMAT_RGBA32323232F, + IMAGE_FORMAT_RG1616F, + IMAGE_FORMAT_RG3232F, + IMAGE_FORMAT_RGBX8888, + + /// Dummy format which takes no video memory + IMAGE_FORMAT_NULL, + + // Compressed normal map formats + IMAGE_FORMAT_ATI2N, // One-surface ATI2N / DXN format + IMAGE_FORMAT_ATI1N, // Two-surface ATI1N format + + IMAGE_FORMAT_RGBA1010102, // 10 bit-per component render targets + IMAGE_FORMAT_BGRA1010102, + IMAGE_FORMAT_R16F, // 16 bit FP format + + // Depth-stencil texture formats + IMAGE_FORMAT_D16, + IMAGE_FORMAT_D15S1, + IMAGE_FORMAT_D32, + IMAGE_FORMAT_D24S8, + IMAGE_FORMAT_LINEAR_D24S8, + IMAGE_FORMAT_D24X8, + IMAGE_FORMAT_D24X4S4, + IMAGE_FORMAT_D24FS8, + IMAGE_FORMAT_D16_SHADOW, // Specific formats for shadow mapping + IMAGE_FORMAT_D24X8_SHADOW, // Specific formats for shadow mapping + + // supporting these specific formats as non-tiled for procedural cpu access (360-specific) + IMAGE_FORMAT_LINEAR_BGRX8888, + IMAGE_FORMAT_LINEAR_RGBA8888, + IMAGE_FORMAT_LINEAR_ABGR8888, + IMAGE_FORMAT_LINEAR_ARGB8888, + IMAGE_FORMAT_LINEAR_BGRA8888, + IMAGE_FORMAT_LINEAR_RGB888, + IMAGE_FORMAT_LINEAR_BGR888, + IMAGE_FORMAT_LINEAR_BGRX5551, + IMAGE_FORMAT_LINEAR_I8, + IMAGE_FORMAT_LINEAR_RGBA16161616, + IMAGE_FORMAT_LINEAR_A8, + IMAGE_FORMAT_LINEAR_DXT1, + IMAGE_FORMAT_LINEAR_DXT3, + IMAGE_FORMAT_LINEAR_DXT5, + + IMAGE_FORMAT_LE_BGRX8888, + IMAGE_FORMAT_LE_BGRA8888, + + // these are used for runtime conversion to DXT1/5 + IMAGE_FORMAT_DXT1_RUNTIME, + IMAGE_FORMAT_DXT5_RUNTIME, + + // special depth format + IMAGE_FORMAT_INTZ, + + NUM_IMAGE_FORMATS + } + //TODO: dx image formats +} diff --git a/SourceSDK/public/vgui/isurface.cs b/SourceSDK/public/vgui/isurface.cs new file mode 100644 index 0000000..4e3f685 --- /dev/null +++ b/SourceSDK/public/vgui/isurface.cs @@ -0,0 +1,24 @@ +using GmodNET.SourceSDK.AppFramework; +using GmodNET.SourceSDK.bitmap; +using System; +using System.Runtime.InteropServices; + +namespace GmodNET.SourceSDK.vgui +{ + public class ISurface : IAppSystem + { + public ISurface(IntPtr ptr) : base(ptr) { } + + public void DrawFilledRect(int x0, int y0, int x1, int y1) => Methods.ISurface_DrawFilledRect(ptr, x0, y0, x1, y1); + + internal static class Methods + { + [DllImport("sourcesdkc")] + internal static extern void ISurface_DrawFilledRect(IntPtr ptr, int x0, int y0, int x1, int y1); + + + [DllImport("sourcesdkc")] + internal static extern void ISurface_DrawSetTextureRGBAex(IntPtr ptr, int id, IntPtr rgba, int wide, int tall, ImageFormat imageFormat); + } + } +} From 7728a2969b2de9d239a15b0f32c56f2b1f381aaf Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 15:52:48 +0500 Subject: [PATCH 166/235] sort usings --- SourceSDK.Test/TestModule.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 55625b4..56c53ec 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -1,11 +1,10 @@ using GmodNET.API; -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; using GmodNET.SourceSDK; using GmodNET.SourceSDK.Tier0; using GmodNET.SourceSDK.Tier1; -using System.IO; +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; using System.Text; namespace SourceSDKTest From 49cfe99d066184a308bb4cb75355f0f001a22507 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 15:55:56 +0500 Subject: [PATCH 167/235] GetDependencies test --- SourceSDK.Test/TestModule.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 56c53ec..2b61cec 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -4,6 +4,7 @@ using GmodNET.SourceSDK.Tier1; using System; using System.Diagnostics; +using System.Linq; using System.Runtime.InteropServices; using System.Text; @@ -120,6 +121,12 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl FileSystem fileSystem = new(fSPtr); BaseFileSystem baseFileSystem = new(baseFSPtr); + Console.WriteLine("get dependencies"); + fileSystem.GetDependencies().ToList().ForEach((val) => + { + Console.WriteLine($"{val.moduleName} - {val.interfaceName}"); + }); + fileSystem.PrintSearchPaths(); IntPtr fileHandle = baseFileSystem.Open("resource/GameMenu.res", "rb", "GAME"); From 472ededdf452125e238c1ee156af94318e01d819 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 16:03:55 +0500 Subject: [PATCH 168/235] use ref type --- SourceSDK/public/appframework/iappsystem.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index 56c7620..43c7fcb 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -76,10 +76,10 @@ public void Shutdown() } [DllImport("sourcesdkc")] - internal static extern AppSystemInfo_t[] IAppSystem_GetDependencies(IntPtr ptr); - public AppSystemInfo_t[] GetDependencies() + internal static extern ref AppSystemInfo_t[] IAppSystem_GetDependencies(IntPtr ptr); + public ref AppSystemInfo_t[] GetDependencies() { - return IAppSystem_GetDependencies(ptr); + return ref IAppSystem_GetDependencies(ptr); } [DllImport("sourcesdkc")] From 8a92a65e7feb08508f64bdb74708f750674dd3ff Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 16:18:44 +0500 Subject: [PATCH 169/235] StructLayout(LayoutKind.Sequential) --- SourceSDK/public/appframework/iappsystem.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index 43c7fcb..4443c56 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -12,6 +12,7 @@ public enum InitReturnVal_t INIT_LAST_VAL = 2, }; + [StructLayout(LayoutKind.Sequential)] public struct AppSystemInfo_t { [MarshalAs(UnmanagedType.LPStr)] From 56435f6fdc0b91e54892101b005d8b8043ad0d62 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 16:30:15 +0500 Subject: [PATCH 170/235] match field names use CharSet.Ansi use => --- SourceSDK.Test/TestModule.cs | 2 +- SourceSDK/public/appframework/iappsystem.cs | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 2b61cec..acfae15 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -124,7 +124,7 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine("get dependencies"); fileSystem.GetDependencies().ToList().ForEach((val) => { - Console.WriteLine($"{val.moduleName} - {val.interfaceName}"); + Console.WriteLine($"{val.m_pModuleName} - {val.m_pInterfaceName}"); }); fileSystem.PrintSearchPaths(); diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index 4443c56..5059567 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -12,13 +12,13 @@ public enum InitReturnVal_t INIT_LAST_VAL = 2, }; - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct AppSystemInfo_t { [MarshalAs(UnmanagedType.LPStr)] - public string moduleName; + public string m_pModuleName; [MarshalAs(UnmanagedType.LPStr)] - public string interfaceName; + public string m_pInterfaceName; }; public enum AppSystemTier_t @@ -77,11 +77,8 @@ public void Shutdown() } [DllImport("sourcesdkc")] - internal static extern ref AppSystemInfo_t[] IAppSystem_GetDependencies(IntPtr ptr); - public ref AppSystemInfo_t[] GetDependencies() - { - return ref IAppSystem_GetDependencies(ptr); - } + internal static extern AppSystemInfo_t[] IAppSystem_GetDependencies(IntPtr ptr); + public AppSystemInfo_t[] GetDependencies() => IAppSystem_GetDependencies(ptr); [DllImport("sourcesdkc")] internal static extern AppSystemTier_t IAppSystem_GetTier(IntPtr ptr); From 8c51829ec3edd0eac473b9a3c4f75e7cf34ae582 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 22:29:24 +0500 Subject: [PATCH 171/235] add more attributes to DllImport --- SourceSDK/public/appframework/iappsystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index 5059567..8400bd0 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -76,7 +76,7 @@ public void Shutdown() IAppSystem_Shutdown(ptr); } - [DllImport("sourcesdkc")] + [DllImport("sourcesdkc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] internal static extern AppSystemInfo_t[] IAppSystem_GetDependencies(IntPtr ptr); public AppSystemInfo_t[] GetDependencies() => IAppSystem_GetDependencies(ptr); From 491098d6924491a3e78bdad6527d5c2ffb57f450 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 22:30:34 +0500 Subject: [PATCH 172/235] try using single struct --- SourceSDK.Test/TestModule.cs | 7 ++++--- SourceSDK/public/appframework/iappsystem.cs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index acfae15..7531f6b 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -122,10 +122,11 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl BaseFileSystem baseFileSystem = new(baseFSPtr); Console.WriteLine("get dependencies"); - fileSystem.GetDependencies().ToList().ForEach((val) => - { + //fileSystem.GetDependencies().ToList().ForEach((val) => + //{ + var val = fileSystem.GetDependencies(); Console.WriteLine($"{val.m_pModuleName} - {val.m_pInterfaceName}"); - }); + //}); fileSystem.PrintSearchPaths(); diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index 8400bd0..1bb0771 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -77,8 +77,8 @@ public void Shutdown() } [DllImport("sourcesdkc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern AppSystemInfo_t[] IAppSystem_GetDependencies(IntPtr ptr); - public AppSystemInfo_t[] GetDependencies() => IAppSystem_GetDependencies(ptr); + internal static extern AppSystemInfo_t IAppSystem_GetDependencies(IntPtr ptr); + public AppSystemInfo_t GetDependencies() => IAppSystem_GetDependencies(ptr); [DllImport("sourcesdkc")] internal static extern AppSystemTier_t IAppSystem_GetTier(IntPtr ptr); From 6ff59009461885e469da89b4d5101e6027608808 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 22:38:01 +0500 Subject: [PATCH 173/235] revert the last commit --- SourceSDK/public/appframework/iappsystem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index 1bb0771..8400bd0 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -77,8 +77,8 @@ public void Shutdown() } [DllImport("sourcesdkc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern AppSystemInfo_t IAppSystem_GetDependencies(IntPtr ptr); - public AppSystemInfo_t GetDependencies() => IAppSystem_GetDependencies(ptr); + internal static extern AppSystemInfo_t[] IAppSystem_GetDependencies(IntPtr ptr); + public AppSystemInfo_t[] GetDependencies() => IAppSystem_GetDependencies(ptr); [DllImport("sourcesdkc")] internal static extern AppSystemTier_t IAppSystem_GetTier(IntPtr ptr); From cd2f7bad7c96ffac5e45c958c4085d8a132df03b Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 22:38:22 +0500 Subject: [PATCH 174/235] i said revert --- SourceSDK.Test/TestModule.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 7531f6b..acfae15 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -122,11 +122,10 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl BaseFileSystem baseFileSystem = new(baseFSPtr); Console.WriteLine("get dependencies"); - //fileSystem.GetDependencies().ToList().ForEach((val) => - //{ - var val = fileSystem.GetDependencies(); + fileSystem.GetDependencies().ToList().ForEach((val) => + { Console.WriteLine($"{val.m_pModuleName} - {val.m_pInterfaceName}"); - //}); + }); fileSystem.PrintSearchPaths(); From 593b707ca6171f420982a97150e0bd5a959c43f7 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 22:39:13 +0500 Subject: [PATCH 175/235] try using IntPtr --- SourceSDK/public/appframework/iappsystem.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index 8400bd0..bd41931 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -15,10 +15,14 @@ public enum InitReturnVal_t [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct AppSystemInfo_t { + /* [MarshalAs(UnmanagedType.LPStr)] public string m_pModuleName; [MarshalAs(UnmanagedType.LPStr)] public string m_pInterfaceName; + */ + public IntPtr m_pModuleName; + public IntPtr m_pInterfaceName; }; public enum AppSystemTier_t From 961bb38a1a12a7485f15d7e544f17ba0d25ab378 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 22:46:09 +0500 Subject: [PATCH 176/235] use IntPtr --- SourceSDK.Test/TestModule.cs | 12 ++++++++---- SourceSDK/public/appframework/iappsystem.cs | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index acfae15..9342e63 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -122,10 +122,14 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl BaseFileSystem baseFileSystem = new(baseFSPtr); Console.WriteLine("get dependencies"); - fileSystem.GetDependencies().ToList().ForEach((val) => - { - Console.WriteLine($"{val.m_pModuleName} - {val.m_pInterfaceName}"); - }); + //fileSystem.GetDependencies().ToList().ForEach((val) => + //{ + // Console.WriteLine($"{val.m_pModuleName} - {val.m_pInterfaceName}"); + //}); + + var deps = fileSystem.GetDependencies(); + + Console.WriteLine(deps.ToInt64()); fileSystem.PrintSearchPaths(); diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index bd41931..62a1215 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -81,8 +81,8 @@ public void Shutdown() } [DllImport("sourcesdkc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern AppSystemInfo_t[] IAppSystem_GetDependencies(IntPtr ptr); - public AppSystemInfo_t[] GetDependencies() => IAppSystem_GetDependencies(ptr); + internal static extern IntPtr IAppSystem_GetDependencies(IntPtr ptr); + public IntPtr GetDependencies() => IAppSystem_GetDependencies(ptr); [DllImport("sourcesdkc")] internal static extern AppSystemTier_t IAppSystem_GetTier(IntPtr ptr); From 44e5f057474ea05b075768c92bc42c1d25bbfd1b Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 20 Feb 2021 23:04:11 +0500 Subject: [PATCH 177/235] vguimatsurface test --- SourceSDK.Test/TestModule.cs | 8 ++++++++ SourceSDK/public/vgui/isurface.cs | 2 ++ 2 files changed, 10 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 9342e63..c91af6c 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -2,6 +2,7 @@ using GmodNET.SourceSDK; using GmodNET.SourceSDK.Tier0; using GmodNET.SourceSDK.Tier1; +using GmodNET.SourceSDK.vgui; using System; using System.Diagnostics; using System.Linq; @@ -131,6 +132,13 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Console.WriteLine(deps.ToInt64()); + if(interfaceh.Sys_LoadInterface("vguimatsurface", ISurface.VGUI_SURFACE_INTERFACE_VERSION, out IntPtr isurfaceModule, out IntPtr isurfaceInterface)) + { + ISurface surface = new(isurfaceInterface); + var isurfdeps = surface.GetDependencies(); + Console.WriteLine(isurfdeps.ToInt64()); + } + fileSystem.PrintSearchPaths(); IntPtr fileHandle = baseFileSystem.Open("resource/GameMenu.res", "rb", "GAME"); diff --git a/SourceSDK/public/vgui/isurface.cs b/SourceSDK/public/vgui/isurface.cs index 4e3f685..2c98b75 100644 --- a/SourceSDK/public/vgui/isurface.cs +++ b/SourceSDK/public/vgui/isurface.cs @@ -7,6 +7,8 @@ namespace GmodNET.SourceSDK.vgui { public class ISurface : IAppSystem { + public const string VGUI_SURFACE_INTERFACE_VERSION = "VGUI_Surface030"; + public ISurface(IntPtr ptr) : base(ptr) { } public void DrawFilledRect(int x0, int y0, int x1, int y1) => Methods.ISurface_DrawFilledRect(ptr, x0, y0, x1, y1); From bc3cde50835547f719a1d5303650a0b35f612597 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 21 Feb 2021 18:25:25 +0500 Subject: [PATCH 178/235] get tier testing --- SourceSDK.Test/TestModule.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index c91af6c..6b25abd 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -122,21 +122,14 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl FileSystem fileSystem = new(fSPtr); BaseFileSystem baseFileSystem = new(baseFSPtr); - Console.WriteLine("get dependencies"); - //fileSystem.GetDependencies().ToList().ForEach((val) => - //{ - // Console.WriteLine($"{val.m_pModuleName} - {val.m_pInterfaceName}"); - //}); + Console.WriteLine("get tier"); - var deps = fileSystem.GetDependencies(); + Console.WriteLine(fileSystem.GetTier()); - Console.WriteLine(deps.ToInt64()); - - if(interfaceh.Sys_LoadInterface("vguimatsurface", ISurface.VGUI_SURFACE_INTERFACE_VERSION, out IntPtr isurfaceModule, out IntPtr isurfaceInterface)) + if (interfaceh.Sys_LoadInterface("vguimatsurface", ISurface.VGUI_SURFACE_INTERFACE_VERSION, out IntPtr isurfaceModule, out IntPtr isurfaceInterface)) { ISurface surface = new(isurfaceInterface); - var isurfdeps = surface.GetDependencies(); - Console.WriteLine(isurfdeps.ToInt64()); + Console.WriteLine(surface.GetTier()); } fileSystem.PrintSearchPaths(); From 6aeced114824de48574450512959056a5b5c060b Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 21 Feb 2021 18:26:39 +0500 Subject: [PATCH 179/235] remove unused using --- SourceSDK.Test/TestModule.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 6b25abd..3adf53c 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -5,7 +5,6 @@ using GmodNET.SourceSDK.vgui; using System; using System.Diagnostics; -using System.Linq; using System.Runtime.InteropServices; using System.Text; From 3c77dffb12719dfcfc39c366646cca7f03d138db Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 21 Feb 2021 18:41:46 +0500 Subject: [PATCH 180/235] add new path test --- SourceSDK.Test/TestModule.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 3adf53c..f3fc0dd 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -133,6 +133,12 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl 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) From 591540ea79903faddb9c7e206f5add4699364da3 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 21 Feb 2021 19:56:48 +0500 Subject: [PATCH 181/235] FileSystem: implement Dynamic library operations, File searching operations --- SourceSDK.CAPI/filesystem_c.cpp | 31 +++++++++++++++++++++++++++ SourceSDK/public/filesystemh.cs | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/SourceSDK.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp index 6f96468..522e375 100644 --- a/SourceSDK.CAPI/filesystem_c.cpp +++ b/SourceSDK.CAPI/filesystem_c.cpp @@ -156,6 +156,37 @@ DLL_EXPORT int IFileSystem_FPrintf(void** fsPtr, FileHandle_t file, const char* return fs->FPrintf(file, pFormat, pMsg); } +DLL_EXPORT CSysModule* IFileSystem_LoadModule(void** fsPtr, const char* pFileName, const char* pPathID = 0, bool bValidatedDllOnly = true) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->LoadModule(pFileName, pPathID, bValidatedDllOnly); +} +DLL_EXPORT void IFileSystem_UnloadModule(void** fsPtr, CSysModule* pModule) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->UnloadModule(pModule); +} + +DLL_EXPORT const char* IFileSystem_FindFirst(void** fsPtr, const char* pWildCard, FileFindHandle_t* pHandle) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->FindFirst(pWildCard, pHandle); +} +DLL_EXPORT const char* IFileSystem_FindNext(void** fsPtr, FileFindHandle_t Handle) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->FindNext(Handle); +} +DLL_EXPORT bool IFileSystem_FindIsDirectory(void** fsPtr, FileFindHandle_t Handle) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->FindIsDirectory(Handle); +} +DLL_EXPORT void IFileSystem_FindClose(void** fsPtr, FileFindHandle_t Handle) { + IFileSystem* fs = (IFileSystem*)fsPtr; + fs->FindClose(Handle); +} +DLL_EXPORT const char* IFileSystem_FindFirstEx(void** fsPtr, const char* pWildCard, const char* pPathID, FileFindHandle_t* pHandle) { + IFileSystem* fs = (IFileSystem*)fsPtr; + return fs->FindFirstEx(pWildCard, pPathID, pHandle); +} + + DLL_EXPORT void IFileSystem_PrintSearchPaths(void** fsPtr) { IFileSystem* fs = (IFileSystem*)fsPtr; fs->PrintSearchPaths(); diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index f166895..d871d23 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -246,6 +246,23 @@ internal static class FileSystem_c [DllImport("sourcesdkc")] internal static extern int IFileSystem_FPrintf(IntPtr ptr, IntPtr file, string format, string msg = null); + [DllImport("sourcesdkc")] + internal static extern IntPtr IFileSystem_LoadModule(IntPtr ptr, string fileName, string pathID = null, bool validatedDllOnly = true); + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_UnloadModule(IntPtr ptr, IntPtr module); + + [DllImport("sourcesdkc")] + internal static extern string IFileSystem_FindFirst(IntPtr ptr, string wildCard, out int handle); + [DllImport("sourcesdkc")] + internal static extern string IFileSystem_FindNext(IntPtr ptr, int handle); + [DllImport("sourcesdkc")] + internal static extern bool IFileSystem_FindIsDirectory(IntPtr ptr, int handle); + [DllImport("sourcesdkc")] + internal static extern void IFileSystem_FindClose(IntPtr ptr, int handle); + [DllImport("sourcesdkc")] + internal static extern string IFileSystem_FindFirstEx(IntPtr ptr, string wildCard, string pathID, out int handle); + + [DllImport("sourcesdkc")] internal static extern void IFileSystem_PrintSearchPaths(IntPtr ptr); } @@ -332,6 +349,17 @@ internal interface IFileSystem string ReadLine(out string output, int maxChars, IntPtr file); int FPrintf(IntPtr file, string format, string msg = null); #endregion + #region Dynamic library operations + IntPtr IFileSystem_LoadModule(string fileName, string pathID = null, bool validatedDllOnly = true); + void IFileSystem_UnloadModule(IntPtr module); + #endregion + #region File searching operations + string IFileSystem_FindFirst(string wildCard, out int handle); + string IFileSystem_FindNext(int handle); + bool IFileSystem_FindIsDirectory(int handle); + void IFileSystem_FindClose(int handle); + string IFileSystem_FindFirstEx(string wildCard, string pathID, out int handle); + #endregion void PrintSearchPaths(); } @@ -422,6 +450,15 @@ public FileSystem(IntPtr ptr) : base(ptr) { } public string ReadLine(out string output, int maxChars, IntPtr file) => FileSystem_c.IFileSystem_ReadLine(ptr, out output, maxChars, file); public int FPrintf(IntPtr file, string format, string msg = null) => FileSystem_c.IFileSystem_FPrintf(ptr, file, format, msg); + public IntPtr IFileSystem_LoadModule(string fileName, string pathID = null, bool validatedDllOnly = true) => FileSystem_c.IFileSystem_LoadModule(ptr, fileName, pathID, validatedDllOnly); + public void IFileSystem_UnloadModule(IntPtr module) => FileSystem_c.IFileSystem_UnloadModule(ptr, module); + + public string IFileSystem_FindFirst(string wildCard, out int handle) => FileSystem_c.IFileSystem_FindFirst(ptr, wildCard, out handle); + public string IFileSystem_FindNext(int handle) => FileSystem_c.IFileSystem_FindNext(ptr, handle); + public bool IFileSystem_FindIsDirectory(int handle) => FileSystem_c.IFileSystem_FindIsDirectory(ptr, handle); + public void IFileSystem_FindClose(int handle) => FileSystem_c.IFileSystem_FindClose(ptr, handle); + public string IFileSystem_FindFirstEx(string wildCard, string pathID, out int handle) => FileSystem_c.IFileSystem_FindFirstEx(ptr, wildCard, pathID, out handle); + public void PrintSearchPaths() => FileSystem_c.IFileSystem_PrintSearchPaths(ptr); } } From b5461d213a09767b58a9b1418fe185c1a19ddec3 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 21 Feb 2021 20:01:57 +0500 Subject: [PATCH 182/235] add Obsolete --- SourceSDK/public/appframework/iappsystem.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index 62a1215..f75a78c 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -82,6 +82,7 @@ public void Shutdown() [DllImport("sourcesdkc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] internal static extern IntPtr IAppSystem_GetDependencies(IntPtr ptr); + [Obsolete("it returns IntPtr.Zero, i don't know what IAppSystem will return something")] public IntPtr GetDependencies() => IAppSystem_GetDependencies(ptr); [DllImport("sourcesdkc")] From 66265fb820aee52811fd71a3e935a8ad6501b541 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 21 Feb 2021 21:24:14 +0500 Subject: [PATCH 183/235] CDbgFmtMsg --- SourceSDK.CAPI/CMakeLists.txt | 2 +- SourceSDK.CAPI/dbg_c.cpp | 6 ++ SourceSDK.Test/TestModule.cs | 2 + SourceSDK/VariableArgument.cs | 189 ++++++++++++++++++++++++++++++++++ SourceSDK/public/tier0/dbg.cs | 14 +++ 5 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 SourceSDK.CAPI/dbg_c.cpp create mode 100644 SourceSDK/VariableArgument.cs diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index 6608468..9dc6c47 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -49,7 +49,7 @@ add_compile_definitions(${SOURCESDK_DEFINES}) link_directories("${SOURCESDK_LIBDIRS}") link_libraries(tier0) -add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp") +add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp" "dbg_c.cpp") target_include_directories(sourcesdkc PUBLIC#SYSTEM INTERFACE #"${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/common" diff --git a/SourceSDK.CAPI/dbg_c.cpp b/SourceSDK.CAPI/dbg_c.cpp new file mode 100644 index 0000000..27cee38 --- /dev/null +++ b/SourceSDK.CAPI/dbg_c.cpp @@ -0,0 +1,6 @@ +#include +#include + +DLL_EXPORT const char* CDbgFmtMsg(const char* format, va_list args) { + return CDbgFmtMsg(format, args); +} diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index f3fc0dd..c30c8e9 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -93,6 +93,8 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.ConMsg("ConMsg(string)\n")); Test(() => Dbg.ConDMsg("ConDMsg(string)\n")); + Test(() => Dbg.Msg(CDbgFmtMsg.Format("CDbgFmtMsg%s", "(%s)"))); + // Test(() => Dbg.COM_TimestampedLog("COM_TimestampedLog(format = %s)", "COM_TimestampedLog")); Test(() => diff --git a/SourceSDK/VariableArgument.cs b/SourceSDK/VariableArgument.cs new file mode 100644 index 0000000..4f8ead3 --- /dev/null +++ b/SourceSDK/VariableArgument.cs @@ -0,0 +1,189 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * https://github.com/ChrisEelmaa/StackOverflow/blob/master/VariableArguments.cs * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; + +namespace GmodNET.SourceSDK +{ + class CombinedVariables : IDisposable + { + readonly IntPtr _ptr; + readonly IList _disposables; + + bool _disposed; + + public CombinedVariables(VariableArgument[] args) + { + _disposables = new List(); + + _ptr = Marshal.AllocHGlobal(args.Sum(arg => arg.GetSize())); + var curPtr = _ptr; + + foreach (var arg in args) + { + _disposables.Add(arg.Write(curPtr)); + curPtr += arg.GetSize(); + } + } + + public IntPtr GetPtr() + { + if (_disposed) + throw new InvalidOperationException("Disposed already."); + + return _ptr; + } + + public void Dispose() + { + if (!_disposed) + { + _disposed = true; + + foreach (var disposable in _disposables) + disposable.Dispose(); + + Marshal.FreeHGlobal(_ptr); + } + } + } + + + #region VariableArgument + + public abstract class VariableArgument + { + #region SentinelDispose + + protected static readonly IDisposable SentinelDisposable = + new SentinelDispose(); + + class SentinelDispose : IDisposable + { + public void Dispose() + { + + } + } + + #endregion + + public abstract IDisposable Write(IntPtr buffer); + + public virtual int GetSize() + { + return IntPtr.Size; + } + + public static implicit operator VariableArgument(int input) + { + return new VariableIntegerArgument(input); + } + + public static implicit operator VariableArgument(string input) + { + return new VariableStringArgument(input); + } + + public static implicit operator VariableArgument(double input) + { + return new VariableDoubleArgument(input); + } + } + + #endregion + + #region VariableIntegerArgument + + sealed class VariableIntegerArgument : VariableArgument + { + readonly int _value; + + public VariableIntegerArgument(int value) + { + _value = value; + } + + public override IDisposable Write(IntPtr buffer) + { + Marshal.Copy(new[] { _value }, 0, buffer, 1); + return SentinelDisposable; + } + } + + #endregion + + #region VariableDoubleArgument + + sealed class VariableDoubleArgument : VariableArgument + { + readonly double _value; + + public VariableDoubleArgument(double value) + { + _value = value; + } + + public override int GetSize() + { + return 8; + } + + public override IDisposable Write(IntPtr buffer) + { + Marshal.Copy(new[] { _value }, 0, buffer, 1); + return SentinelDisposable; + } + } + + #endregion + + #region VariableStringArgument + + sealed class VariableStringArgument : VariableArgument + { + readonly string _value; + + public VariableStringArgument(string value) + { + _value = value; + } + + public override IDisposable Write(IntPtr buffer) + { + var ptr = Marshal.StringToHGlobalAnsi(_value); + + Marshal.Copy(new[] { ptr }, 0, buffer, 1); + + return new StringArgumentDisposable(ptr); + } + + #region StringArgumentDisposable + + class StringArgumentDisposable : IDisposable + { + IntPtr _ptr; + + public StringArgumentDisposable(IntPtr ptr) + { + _ptr = ptr; + } + + public void Dispose() + { + if (_ptr != IntPtr.Zero) + { + Marshal.FreeHGlobal(_ptr); + _ptr = IntPtr.Zero; + } + } + } + + #endregion + } + #endregion +} diff --git a/SourceSDK/public/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs index 9e42fc5..d19ced8 100644 --- a/SourceSDK/public/tier0/dbg.cs +++ b/SourceSDK/public/tier0/dbg.cs @@ -122,4 +122,18 @@ public static class Delegates [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void COM_TimestampedLog([MarshalAs(UnmanagedType.LPUTF8Str)] string fmt, string dotdotdot); } + + public static class CDbgFmtMsg + { + internal static class Methods + { + [DllImport("sourcesdkc")] + internal static extern string CDbgFmtMsg(string format, IntPtr args); + } + public static string Format(string format, params VariableArgument[] args) + { + using var va_list = new CombinedVariables(args); + return Methods.CDbgFmtMsg(format, va_list.GetPtr()); + } + } } From 7b90676ad486b743c4732eb9703681f4fb1346b5 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 21 Feb 2021 21:31:14 +0500 Subject: [PATCH 184/235] use different naming --- SourceSDK.CAPI/dbg_c.cpp | 2 +- SourceSDK/public/tier0/dbg.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK.CAPI/dbg_c.cpp b/SourceSDK.CAPI/dbg_c.cpp index 27cee38..7c127b4 100644 --- a/SourceSDK.CAPI/dbg_c.cpp +++ b/SourceSDK.CAPI/dbg_c.cpp @@ -1,6 +1,6 @@ #include #include -DLL_EXPORT const char* CDbgFmtMsg(const char* format, va_list args) { +DLL_EXPORT const char* DBG_CDbgFmtMsg(const char* format, va_list args) { return CDbgFmtMsg(format, args); } diff --git a/SourceSDK/public/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs index d19ced8..b0fdd14 100644 --- a/SourceSDK/public/tier0/dbg.cs +++ b/SourceSDK/public/tier0/dbg.cs @@ -127,7 +127,7 @@ public static class CDbgFmtMsg { internal static class Methods { - [DllImport("sourcesdkc")] + [DllImport("sourcesdkc", EntryPoint = "DBG_CDbgFmtMsg")] internal static extern string CDbgFmtMsg(string format, IntPtr args); } public static string Format(string format, params VariableArgument[] args) From 993f1221eadb26f57e7ca4e2385665253dea8016 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 21 Feb 2021 21:47:52 +0500 Subject: [PATCH 185/235] inline DBG_CDbgFmtMsg implementation --- SourceSDK.CAPI/dbg_c.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SourceSDK.CAPI/dbg_c.cpp b/SourceSDK.CAPI/dbg_c.cpp index 7c127b4..edb4c3e 100644 --- a/SourceSDK.CAPI/dbg_c.cpp +++ b/SourceSDK.CAPI/dbg_c.cpp @@ -2,5 +2,8 @@ #include DLL_EXPORT const char* DBG_CDbgFmtMsg(const char* format, va_list args) { - return CDbgFmtMsg(format, args); + char chars[256]; + Tier0Internal_vsntprintf(chars, sizeof(chars) - 1, format, args); + chars[sizeof(chars) - 1] = 0; + return chars; } From be5259ab0424d8e6a5c3098e9013ee7d0f9094d4 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 21 Feb 2021 22:20:11 +0500 Subject: [PATCH 186/235] scrap CDbgFmtMsg --- SourceSDK.CAPI/CMakeLists.txt | 2 +- SourceSDK.CAPI/dbg_c.cpp | 9 --------- SourceSDK.Test/TestModule.cs | 2 -- SourceSDK/public/tier0/dbg.cs | 23 +++++++++++++++-------- 4 files changed, 16 insertions(+), 20 deletions(-) delete mode 100644 SourceSDK.CAPI/dbg_c.cpp diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index 9dc6c47..03c2b0d 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -49,7 +49,7 @@ add_compile_definitions(${SOURCESDK_DEFINES}) link_directories("${SOURCESDK_LIBDIRS}") link_libraries(tier0) -add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp" "dbg_c.cpp") +add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp" ) target_include_directories(sourcesdkc PUBLIC#SYSTEM INTERFACE #"${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/common" diff --git a/SourceSDK.CAPI/dbg_c.cpp b/SourceSDK.CAPI/dbg_c.cpp deleted file mode 100644 index edb4c3e..0000000 --- a/SourceSDK.CAPI/dbg_c.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -DLL_EXPORT const char* DBG_CDbgFmtMsg(const char* format, va_list args) { - char chars[256]; - Tier0Internal_vsntprintf(chars, sizeof(chars) - 1, format, args); - chars[sizeof(chars) - 1] = 0; - return chars; -} diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index c30c8e9..f3fc0dd 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -93,8 +93,6 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl Test(() => Dbg.ConMsg("ConMsg(string)\n")); Test(() => Dbg.ConDMsg("ConDMsg(string)\n")); - Test(() => Dbg.Msg(CDbgFmtMsg.Format("CDbgFmtMsg%s", "(%s)"))); - // Test(() => Dbg.COM_TimestampedLog("COM_TimestampedLog(format = %s)", "COM_TimestampedLog")); Test(() => diff --git a/SourceSDK/public/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs index b0fdd14..eb412a9 100644 --- a/SourceSDK/public/tier0/dbg.cs +++ b/SourceSDK/public/tier0/dbg.cs @@ -125,15 +125,22 @@ public static class Delegates public static class CDbgFmtMsg { - internal static class Methods +#nullable enable + public static string Format(string format, params object?[]? args) { - [DllImport("sourcesdkc", EntryPoint = "DBG_CDbgFmtMsg")] - internal static extern string CDbgFmtMsg(string format, IntPtr args); - } - public static string Format(string format, params VariableArgument[] args) - { - using var va_list = new CombinedVariables(args); - return Methods.CDbgFmtMsg(format, va_list.GetPtr()); + if (args is null) + { + return format; + } + foreach(var obj in args) + { + if(obj is int) + { + + } + } + throw new NotImplementedException("todo"); } +#nullable restore } } From 82c1fe92dc5f2ae14f8aeceadf02b48d58192b26 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 21 Feb 2021 22:22:18 +0500 Subject: [PATCH 187/235] add readonly to delegates remove unused using --- SourceSDK/public/tier0/dbg.cs | 8 ++++---- SourceSDK/tier1/interfaceh.cs | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/SourceSDK/public/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs index eb412a9..2f4470f 100644 --- a/SourceSDK/public/tier0/dbg.cs +++ b/SourceSDK/public/tier0/dbg.cs @@ -102,12 +102,12 @@ public static class Delegates public static extern void Error([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - public static Delegates.void_string DevMsg; - public static Delegates.void_string DevWarning; + public static readonly Delegates.void_string DevMsg; + public static readonly Delegates.void_string DevWarning; - public static Delegates.void_inColor_string ConColorMsg; - public static Delegates.void_string ConMsg; + public static readonly Delegates.void_inColor_string ConColorMsg; + public static readonly Delegates.void_string ConMsg; [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void ConDMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index 956d9de..0263799 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace GmodNET.SourceSDK.Tier1 From 53e007feba76f187990c05e417ef97032681192f Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 21 Feb 2021 23:22:47 +0500 Subject: [PATCH 188/235] Update filesystem_c.cpp --- SourceSDK.CAPI/filesystem_c.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SourceSDK.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp index 522e375..22b419e 100644 --- a/SourceSDK.CAPI/filesystem_c.cpp +++ b/SourceSDK.CAPI/filesystem_c.cpp @@ -187,7 +187,6 @@ DLL_EXPORT const char* IFileSystem_FindFirstEx(void** fsPtr, const char* pWildCa } -DLL_EXPORT void IFileSystem_PrintSearchPaths(void** fsPtr) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT void IFileSystem_PrintSearchPaths(IFileSystem* fs) { fs->PrintSearchPaths(); } From 83c993389dc25fdf72507e7c1a68a8809a3fdab8 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 22 Feb 2021 10:14:30 +0500 Subject: [PATCH 189/235] remove cast --- SourceSDK.CAPI/filesystem_c.cpp | 132 +++++++++++--------------------- 1 file changed, 44 insertions(+), 88 deletions(-) diff --git a/SourceSDK.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp index 22b419e..09580f8 100644 --- a/SourceSDK.CAPI/filesystem_c.cpp +++ b/SourceSDK.CAPI/filesystem_c.cpp @@ -1,188 +1,144 @@ #include #pragma region IBaseFileSystem -DLL_EXPORT int IBaseFileSystem_Read(void** ptr, void* pOutput, int size, FileHandle_t file) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT int IBaseFileSystem_Read(IBaseFileSystem* bfs, void* pOutput, int size, FileHandle_t file) { return bfs->Read(pOutput, size, file); } -DLL_EXPORT int IBaseFileSystem_Write(void** ptr, void const* pInput, int size, FileHandle_t file) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT int IBaseFileSystem_Write(IBaseFileSystem* bfs, void const* pInput, int size, FileHandle_t file) { return bfs->Write(pInput, size, file); } -DLL_EXPORT FileHandle_t IBaseFileSystem_Open(void** ptr, const char* pFileName, const char* pOptions, const char* pathID = 0) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT FileHandle_t IBaseFileSystem_Open(IBaseFileSystem* bfs, const char* pFileName, const char* pOptions, const char* pathID = 0) { return bfs->Open(pFileName, pOptions, pathID); } -DLL_EXPORT void IBaseFileSystem_Close(void** ptr, FileHandle_t file) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT void IBaseFileSystem_Close(IBaseFileSystem* bfs, FileHandle_t file) { bfs->Close(file); } -DLL_EXPORT void IBaseFileSystem_Seek(void** ptr, FileHandle_t file, int pos, FileSystemSeek_t seekType) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT void IBaseFileSystem_Seek(IBaseFileSystem* bfs, FileHandle_t file, int pos, FileSystemSeek_t seekType) { bfs->Seek(file, pos, seekType); } -DLL_EXPORT unsigned int IBaseFileSystem_Tell(void** ptr, FileHandle_t file) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT unsigned int IBaseFileSystem_Tell(IBaseFileSystem* bfs, FileHandle_t file) { return bfs->Tell(file); } -DLL_EXPORT unsigned int IBaseFileSystem_Size(void** ptr, FileHandle_t file) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT unsigned int IBaseFileSystem_Size(IBaseFileSystem* bfs, FileHandle_t file) { return bfs->Size(file); } -DLL_EXPORT unsigned int IBaseFileSystem_Size_string_string(void** ptr, const char* pFileName, const char* pPathID = 0) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT unsigned int IBaseFileSystem_Size_string_string(IBaseFileSystem* bfs, const char* pFileName, const char* pPathID = 0) { return bfs->Size(pFileName, pPathID); } -DLL_EXPORT void IBaseFileSystem_Flush(void** ptr, FileHandle_t file) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT void IBaseFileSystem_Flush(IBaseFileSystem* bfs, FileHandle_t file) { bfs->Flush(file); } -DLL_EXPORT bool IBaseFileSystem_Precache(void** ptr, const char* pFileName, const char* pPathID = 0) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT bool IBaseFileSystem_Precache(IBaseFileSystem* bfs, const char* pFileName, const char* pPathID = 0) { return bfs->Precache(pFileName, pPathID); } -DLL_EXPORT bool IBaseFileSystem_FileExists(void** ptr, const char* pFileName, const char* pPathID = 0) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT bool IBaseFileSystem_FileExists(IBaseFileSystem* bfs, const char* pFileName, const char* pPathID = 0) { return bfs->FileExists(pFileName, pPathID); } -DLL_EXPORT bool IBaseFileSystem_IsFileWritable(void** ptr, const char* pFileName, const char* pPathID = 0) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT bool IBaseFileSystem_IsFileWritable(IBaseFileSystem* bfs, const char* pFileName, const char* pPathID = 0) { return bfs->IsFileWritable(pFileName, pPathID); } -DLL_EXPORT bool IBaseFileSystem_SetFileWritable(void** ptr, char const* pFileName, bool writable, const char* pPathID = 0) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT bool IBaseFileSystem_SetFileWritable(IBaseFileSystem* bfs, char const* pFileName, bool writable, const char* pPathID = 0) { return bfs->SetFileWritable(pFileName, writable, pPathID); } -DLL_EXPORT long IBaseFileSystem_GetFileTime(void** ptr, const char* pFileName, const char* pPathID = 0) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT long IBaseFileSystem_GetFileTime(IBaseFileSystem* bfs, const char* pFileName, const char* pPathID = 0) { return bfs->GetFileTime(pFileName, pPathID); } -DLL_EXPORT bool IBaseFileSystem_ReadFile(void** ptr, const char* pFileName, const char* pPath, CUtlBuffer& buf, int nMaxBytes = 0, int nStartingByte = 0, FSAllocFunc_t pfnAlloc = NULL) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT bool IBaseFileSystem_ReadFile(IBaseFileSystem* bfs, const char* pFileName, const char* pPath, CUtlBuffer& buf, int nMaxBytes = 0, int nStartingByte = 0, FSAllocFunc_t pfnAlloc = NULL) { return bfs->ReadFile(pFileName, pPath, buf, nMaxBytes, nStartingByte, pfnAlloc); } -DLL_EXPORT bool IBaseFileSystem_WriteFile(void** ptr, const char* pFileName, const char* pPath, CUtlBuffer& buf) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT bool IBaseFileSystem_WriteFile(IBaseFileSystem* bfs, const char* pFileName, const char* pPath, CUtlBuffer& buf) { return bfs->WriteFile(pFileName, pPath, buf); } -DLL_EXPORT bool IBaseFileSystem_UnzipFile(void** ptr, const char* pFileName, const char* pPath, const char* pDestination) { - IBaseFileSystem* bfs = (IBaseFileSystem*)ptr; +DLL_EXPORT bool IBaseFileSystem_UnzipFile(IBaseFileSystem* bfs, const char* pFileName, const char* pPath, const char* pDestination) { return bfs->UnzipFile(pFileName, pPath, pDestination); } #pragma endregion -DLL_EXPORT bool IFileSystem_IsSteam(void** fsPtr) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT bool IFileSystem_IsSteam(IFileSystem* fs) { return fs->IsSteam(); } -DLL_EXPORT FilesystemMountRetval_t IFileSystem_MountSteamContent(void** fsPtr, int nExtraAppId = -1) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT FilesystemMountRetval_t IFileSystem_MountSteamContent(IFileSystem* fs, int nExtraAppId = -1) { return fs->MountSteamContent(nExtraAppId); } -DLL_EXPORT void IFileSystem_AddSearchPath(void** fsPtr, const char* pPath, const char* pathID, SearchPathAdd_t addType = PATH_ADD_TO_TAIL) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT void IFileSystem_AddSearchPath(IFileSystem* fs, const char* pPath, const char* pathID, SearchPathAdd_t addType = PATH_ADD_TO_TAIL) { fs->AddSearchPath(pPath, pathID, addType); } -DLL_EXPORT bool IFileSystem_RemoveSearchPath(void** fsPtr, const char* pPath, const char* pathID = 0) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT bool IFileSystem_RemoveSearchPath(IFileSystem* fs, const char* pPath, const char* pathID = 0) { return fs->RemoveSearchPath(pPath, pathID); } -DLL_EXPORT void IFileSystem_RemoveAllSearchPaths(void** fsPtr) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT void IFileSystem_RemoveAllSearchPaths(IFileSystem* fs) { fs->RemoveAllSearchPaths(); } -DLL_EXPORT void IFileSystem_RemoveSearchPaths(void** fsPtr, const char* szPathID) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT void IFileSystem_RemoveSearchPaths(IFileSystem* fs, const char* szPathID) { fs->RemoveSearchPaths(szPathID); } -DLL_EXPORT void IFileSystem_MarkPathIDByRequestOnly(void** fsPtr, const char* pPathID, bool bRequestOnly) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT void IFileSystem_MarkPathIDByRequestOnly(IFileSystem* fs, const char* pPathID, bool bRequestOnly) { fs->MarkPathIDByRequestOnly(pPathID, bRequestOnly); } -DLL_EXPORT const char* IFileSystem_RelativePathToFullPath(void** fsPtr, const char* pFileName, const char* pPathID, char* pDest, int maxLenInChars, PathTypeFilter_t pathFilter = FILTER_NONE, PathTypeQuery_t* pPathType = NULL) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT const char* IFileSystem_RelativePathToFullPath(IFileSystem* fs, const char* pFileName, const char* pPathID, char* pDest, int maxLenInChars, PathTypeFilter_t pathFilter = FILTER_NONE, PathTypeQuery_t* pPathType = NULL) { return fs->RelativePathToFullPath(pFileName, pPathID, pDest, maxLenInChars, pathFilter, pPathType); } -DLL_EXPORT int IFileSystem_GetSearchPath(void** fsPtr, const char* pathID, bool bGetPackFiles, char* pDest, int maxLenInChars) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT int IFileSystem_GetSearchPath(IFileSystem* fs, const char* pathID, bool bGetPackFiles, char* pDest, int maxLenInChars) { return fs->GetSearchPath(pathID, bGetPackFiles, pDest, maxLenInChars); } -DLL_EXPORT bool IFileSystem_AddPackFile(void** fsPtr, const char* fullpath, const char* pathID) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT bool IFileSystem_AddPackFile(IFileSystem* fs, const char* fullpath, const char* pathID) { return fs->AddPackFile(fullpath, pathID); } -DLL_EXPORT void IFileSystem_RemoveFile(void** fsPtr, char const* pRelativePath, const char* pathID = 0) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT void IFileSystem_RemoveFile(IFileSystem* fs, char const* pRelativePath, const char* pathID = 0) { fs->RemoveFile(pRelativePath, pathID); } -DLL_EXPORT bool IFileSystem_RenameFile(void** fsPtr, char const* pOldPath, char const* pNewPath, const char* pathID = 0) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT bool IFileSystem_RenameFile(IFileSystem* fs, char const* pOldPath, char const* pNewPath, const char* pathID = 0) { return fs->RenameFile(pOldPath, pNewPath, pathID); } -DLL_EXPORT void IFileSystem_CreateDirHierarchy(void** fsPtr, const char* path, const char* pathID = 0) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT void IFileSystem_CreateDirHierarchy(IFileSystem* fs, const char* path, const char* pathID = 0) { fs->CreateDirHierarchy(path, pathID); } -DLL_EXPORT bool IFileSystem_IsDirectory(void** fsPtr, const char* pFileName, const char* pathID = 0) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT bool IFileSystem_IsDirectory(IFileSystem* fs, const char* pFileName, const char* pathID = 0) { return fs->IsDirectory(pFileName, pathID); } -DLL_EXPORT void IFileSystem_FileTimeToString(void** fsPtr, char* pStrip, int maxCharsIncludingTerminator, long fileTime) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT void IFileSystem_FileTimeToString(IFileSystem* fs, char* pStrip, int maxCharsIncludingTerminator, long fileTime) { fs->FileTimeToString(pStrip, maxCharsIncludingTerminator, fileTime); } -DLL_EXPORT void IFileSystem_SetBufferSize(void** fsPtr, FileHandle_t file, unsigned int nBytes) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT void IFileSystem_SetBufferSize(IFileSystem* fs, FileHandle_t file, unsigned int nBytes) { fs->SetBufferSize(file, nBytes); } -DLL_EXPORT bool IFileSystem_IsOk(void** fsPtr, FileHandle_t file) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT bool IFileSystem_IsOk(IFileSystem* fs, FileHandle_t file) { return fs->IsOk(file); } -DLL_EXPORT bool IFileSystem_EndOfFile(void** fsPtr, FileHandle_t file) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT bool IFileSystem_EndOfFile(IFileSystem* fs, FileHandle_t file) { return fs->EndOfFile(file); } -DLL_EXPORT char* IFileSystem_ReadLine(void** fsPtr, char* pOutput, int maxChars, FileHandle_t file) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT char* IFileSystem_ReadLine(IFileSystem* fs, char* pOutput, int maxChars, FileHandle_t file) { return fs->ReadLine(pOutput, maxChars, file); } -DLL_EXPORT int IFileSystem_FPrintf(void** fsPtr, FileHandle_t file, const char* pFormat, const char* pMsg = nullptr) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT int IFileSystem_FPrintf(IFileSystem* fs, FileHandle_t file, const char* pFormat, const char* pMsg = nullptr) { return fs->FPrintf(file, pFormat, pMsg); } -DLL_EXPORT CSysModule* IFileSystem_LoadModule(void** fsPtr, const char* pFileName, const char* pPathID = 0, bool bValidatedDllOnly = true) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT CSysModule* IFileSystem_LoadModule(IFileSystem* fs, const char* pFileName, const char* pPathID = 0, bool bValidatedDllOnly = true) { return fs->LoadModule(pFileName, pPathID, bValidatedDllOnly); } -DLL_EXPORT void IFileSystem_UnloadModule(void** fsPtr, CSysModule* pModule) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT void IFileSystem_UnloadModule(IFileSystem* fs, CSysModule* pModule) { fs->UnloadModule(pModule); } -DLL_EXPORT const char* IFileSystem_FindFirst(void** fsPtr, const char* pWildCard, FileFindHandle_t* pHandle) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT const char* IFileSystem_FindFirst(IFileSystem* fs, const char* pWildCard, FileFindHandle_t* pHandle) { return fs->FindFirst(pWildCard, pHandle); } -DLL_EXPORT const char* IFileSystem_FindNext(void** fsPtr, FileFindHandle_t Handle) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT const char* IFileSystem_FindNext(IFileSystem* fs, FileFindHandle_t Handle) { return fs->FindNext(Handle); } -DLL_EXPORT bool IFileSystem_FindIsDirectory(void** fsPtr, FileFindHandle_t Handle) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT bool IFileSystem_FindIsDirectory(IFileSystem* fs, FileFindHandle_t Handle) { return fs->FindIsDirectory(Handle); } -DLL_EXPORT void IFileSystem_FindClose(void** fsPtr, FileFindHandle_t Handle) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT void IFileSystem_FindClose(IFileSystem* fs, FileFindHandle_t Handle) { fs->FindClose(Handle); } -DLL_EXPORT const char* IFileSystem_FindFirstEx(void** fsPtr, const char* pWildCard, const char* pPathID, FileFindHandle_t* pHandle) { - IFileSystem* fs = (IFileSystem*)fsPtr; +DLL_EXPORT const char* IFileSystem_FindFirstEx(IFileSystem* fs, const char* pWildCard, const char* pPathID, FileFindHandle_t* pHandle) { return fs->FindFirstEx(pWildCard, pPathID, pHandle); } From fe9932d71323674d61a281f1c3f12054147f9a57 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 22 Feb 2021 10:35:20 +0500 Subject: [PATCH 190/235] add length check to CDbgFmtMsg --- SourceSDK/public/tier0/dbg.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SourceSDK/public/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs index 2f4470f..9f0c230 100644 --- a/SourceSDK/public/tier0/dbg.cs +++ b/SourceSDK/public/tier0/dbg.cs @@ -128,15 +128,15 @@ public static class CDbgFmtMsg #nullable enable public static string Format(string format, params object?[]? args) { - if (args is null) + if (args is null || args.Length < 1) { return format; } - foreach(var obj in args) + foreach (var obj in args) { - if(obj is int) + if (obj is int) { - + } } throw new NotImplementedException("todo"); From 2e499dd029bf43421d57aeea3aa955c4204f6220 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 22 Feb 2021 10:37:30 +0500 Subject: [PATCH 191/235] add hint file --- cpp.hint | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 cpp.hint diff --git a/cpp.hint b/cpp.hint new file mode 100644 index 0000000..26c118b --- /dev/null +++ b/cpp.hint @@ -0,0 +1,5 @@ +// Hint files help the Visual Studio IDE interpret Visual C++ identifiers +// such as names of functions and macros. +// For more information see https://go.microsoft.com/fwlink/?linkid=865984 +#define DLL_EXPORT extern "C" __declspec( dllexport ) +#define DLL_EXPORT From b1d8d84f8db6bdbf5bc252547d6bccfed83089f9 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 22 Feb 2021 12:37:15 +0500 Subject: [PATCH 192/235] delegates structs const md5 checksum.cs --- SourceSDK/public/filesystemh.cs | 79 ++++++++++++++++++++++++-- SourceSDK/public/tier1/checksum_md5.cs | 71 +++++++++++++++++++++++ 2 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 SourceSDK/public/tier1/checksum_md5.cs diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index d871d23..6f29432 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -1,11 +1,79 @@ using GmodNET.SourceSDK.AppFramework; +using GmodNET.SourceSDK.tier1; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace GmodNET.SourceSDK { - #region Enums + public delegate void FileSystemLoggingFunc_t(string fileName, string accessType); + /// File system allocation functions. Client must free on failure + public delegate void FSAllocFunc_t(string szFileName, uint bytes); + /// Used to display dirty disk error functions + public delegate void FSDirtyDiskReportFunc_t(); + /// Completion callback for each async file serviced (or failed) + public delegate void FSAsyncCallbackFunc_t(ref FileAsyncRequest_t request, int bytesRead, FSAsyncStatus_t err); + + #region Structs + public struct FileAsyncRequest_t + { + static FileAsyncRequest_t() => throw new NotImplementedException("TODO"); + + //FileAsyncRequest_t() { memset(this, 0, sizeof(*this) ); hSpecificAsyncFile = FS_INVALID_ASYNC_FILE; } + /// file system name + public string szFilename; + /// optional, system will alloc/free if NULL + public IntPtr data; + /// optional initial seek_set, 0=beginning + public int offset; + /// optional read clamp, -1=exist test, 0=full read + public int bytes; + /// optional completion callback + public FSAsyncCallbackFunc_t fnCallback; + /// caller's unique file identifier + public IntPtr context; + /// inter list priority, 0=lowest + public int priority; + /// behavior modifier + public FSAsyncFlags_t flags; + /// path ID (NOTE: this field is here to remain binary compatible with release HL2 filesystem interface) + public string szPathID; + /// Optional hint obtained using AsyncBeginRead() + public IntPtr hSpecificAsyncFile; + /// custom allocator. can be null. not compatible with FSASYNC_FLAGS_FREEDATAPTR + public FSAllocFunc_t fnAlloc; + } + public struct FileHash_t : IEquatable + { + public enum EFileHashType_t + { + k_EFileHashTypeUnknown = 0, + k_EFileHashTypeEntireFile = 1, + k_EFileHashTypeIncompleteFile = 2, + } + + public EFileHashType_t m_eFileHashType; + public uint m_crcIOSequence; + public MD5Value_t m_md5contents; + public int m_cbFileLen; + public int m_PackFileID; + public int m_nPackFileNumber; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator ==(FileHash_t obj1, FileHash_t obj2) => obj1.m_crcIOSequence == obj2.m_crcIOSequence && obj1.m_md5contents == obj2.m_md5contents && obj1.m_eFileHashType == obj2.m_eFileHashType; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator !=(FileHash_t obj1, FileHash_t obj2) => obj1.m_crcIOSequence != obj2.m_crcIOSequence || obj1.m_md5contents != obj2.m_md5contents || obj1.m_eFileHashType != obj2.m_eFileHashType; + + public override bool Equals(object obj) => this == (FileHash_t)obj; + public override int GetHashCode() => base.GetHashCode(); + + public bool Equals(FileHash_t other) => this == other; + } + #endregion + + #region Enums + /// How strict will the pure server be for a particular set of files public enum EPureServerFileClass { /// dummy debugging value @@ -20,10 +88,7 @@ public enum FileSystemSeek_t FILESYSTEM_SEEK_CURRENT = 1, FILESYSTEM_SEEK_TAIL = 2, } - public enum FileSystem_Handle - { - FILESYSTEM_INVALID_FIND_HANDLE = -1 - } + public enum FileWarningLevel_t { /// A problem! @@ -94,6 +159,7 @@ public enum FilesystemOpenExFlags_t /// 360 only, hint to FS that file is not allowed to be in pack file FSOPEN_NEVERINPACK = (1 << 2), } + /// Async file status public enum FSAsyncStatus_t { ///Filename not part of the specified file system, try a different one. (Used internally to find the right filesystem) @@ -395,6 +461,9 @@ public class BaseFileSystem : IBaseFileSystem public class FileSystem : IAppSystem, IBaseFileSystem, IFileSystem { public const int FILESYSTEM_MAX_SEARCH_PATHS = 128; + public const int FILESYSTEM_INVALID_FIND_HANDLE = -1; + public static readonly IntPtr FILESYSTEM_INVALID_HANDLE = IntPtr.Zero; + public const int FS_INVALID_ASYNC_FILE = 0x0000ffff; public const string FILESYSTEM_INTERFACE_VERSION = "VFileSystem022"; diff --git a/SourceSDK/public/tier1/checksum_md5.cs b/SourceSDK/public/tier1/checksum_md5.cs new file mode 100644 index 0000000..696e054 --- /dev/null +++ b/SourceSDK/public/tier1/checksum_md5.cs @@ -0,0 +1,71 @@ +using System; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace GmodNET.SourceSDK.tier1 +{ + public static partial class Global + { + public const int MD5_DIGEST_LENGTH = 16; // 16 bytes == 128 bit digest + } + public struct MD5Value_t : IEquatable + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = Global.MD5_DIGEST_LENGTH)] + public byte[] bits;// MD5_DIGEST_LENGTH + + public void Zero() + { + bits = new byte[Global.MD5_DIGEST_LENGTH]; + } + + public bool IsZero() + { + for (int i = 0; i < bits.Length; ++i) + { + if (bits[i] != 0) + return false; + } + + return true; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator ==(MD5Value_t obj1, MD5Value_t obj2) => obj1.bits.SequenceEqual(obj2.bits); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator !=(MD5Value_t obj1, MD5Value_t obj2) => !(obj1 == obj2); + + public override bool Equals(object obj) => this == (MD5Value_t)obj; + public override int GetHashCode() => base.GetHashCode(); + + public bool Equals(MD5Value_t other) => this == other; + + public void MD5_ProcessSingleBuffer(byte[] buffer) => throw new NotImplementedException("todo"); + } + + // todo + public struct MD5Context_t + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] + public uint[] buf; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public uint[] bits; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] + public byte[] input; + + public void MD5Init() + { + buf[0] = 0x67452301; + buf[1] = 0xefcdab89; + buf[2] = 0x98badcfe; + buf[3] = 0x10325476; + + bits[0] = 0; + bits[1] = 0; + } + public void MD5Update(byte[] buffer) => throw new NotImplementedException("todo"); + public void MD5Final(byte[] buffer) => throw new NotImplementedException("todo"); + public void MD5_Print() => throw new NotImplementedException("todo"); + public void MD5_PseudoRandom() => throw new NotImplementedException("todo"); + } + +} From 5972d1152139bb68e1451e97c87226b46ffbefa2 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 23 Feb 2021 13:45:16 +0500 Subject: [PATCH 193/235] omit entry points --- SourceSDK/public/tier0/dbg.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SourceSDK/public/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs index 9f0c230..e7db65d 100644 --- a/SourceSDK/public/tier0/dbg.cs +++ b/SourceSDK/public/tier0/dbg.cs @@ -46,7 +46,7 @@ internal static class Windows public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", EntryPoint = "?ConColorMsg@@YAXAEBVColor@@PEBDZZ", CallingConvention = CallingConvention.Cdecl)] + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); [DllImport("tier0", EntryPoint = "?ConMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] @@ -61,7 +61,7 @@ internal static class Linux public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", EntryPoint = "_Z11ConColorMsgRK5ColorPKcz", CallingConvention = CallingConvention.Cdecl)] + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); [DllImport("tier0", EntryPoint = "_Z6ConMsgPKcz", CallingConvention = CallingConvention.Cdecl)] @@ -76,7 +76,7 @@ internal static class OSX public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - [DllImport("tier0", EntryPoint = "__Z11ConColorMsgRK5ColorPKcz", CallingConvention = CallingConvention.Cdecl)] + [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); [DllImport("tier0", EntryPoint = "__Z6ConMsgPKcz", CallingConvention = CallingConvention.Cdecl)] From 795d1abd82c910d22ba1097f2f2680c776dbf161 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 23 Feb 2021 14:36:33 +0500 Subject: [PATCH 194/235] SymbolResolver.cs --- SourceSDK/SymbolResolver.cs | 105 ++++++++++++++++++++++++++++++++++ SourceSDK/public/tier0/dbg.cs | 8 +-- 2 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 SourceSDK/SymbolResolver.cs diff --git a/SourceSDK/SymbolResolver.cs b/SourceSDK/SymbolResolver.cs new file mode 100644 index 0000000..43720bb --- /dev/null +++ b/SourceSDK/SymbolResolver.cs @@ -0,0 +1,105 @@ +using System; +using System.IO; +using System.Runtime.InteropServices; + +namespace GmodNET.SourceSDK +{ + internal static class SymbolResolver + { + private static readonly Func getLibPtr; + private static readonly Func getSymbolPtr; + private static readonly string[] libNames; + private static readonly string[] paths; + + private static string getPath(string path) => Path.Combine(Directory.GetCurrentDirectory(), path); + + static SymbolResolver() + { + switch (Environment.OSVersion.Platform) + { + case PlatformID.Win32NT: + getLibPtr = LoadLibrary; + getSymbolPtr = GetProcAddress; + libNames = new[] + { + "{0}.dll" + }; + paths = new[] + { + "bin/win64/{0}", + // "bin/{0}" + }; + break; + case PlatformID.Unix: + getLibPtr = dlopen; + getSymbolPtr = dlsym; + libNames = new[] + { + "{0}.so", + "lib{0}.so" + }; + paths = new[] + { + "bin/linux64/{0}" + }; + break; + case PlatformID.MacOSX: + getLibPtr = dlopen; + getSymbolPtr = dlsym; + libNames = new[] + { + "{0}.dylib", + "lib{0}.dylib" + }; + paths = new[] + { + "bin/osx64/{0}" + }; + break; + default: + throw new PlatformNotSupportedException(); + } + } + + #region native + [DllImport("dl", CharSet = CharSet.Ansi)] + private static extern IntPtr dlopen(string libName, int flags); + private static IntPtr dlopen(string libName) => dlopen(libName, 0x1); + [DllImport("dl", CharSet = CharSet.Ansi)] + private static extern IntPtr dlsym(IntPtr lib, string symbol); + [DllImport("kernel32", SetLastError = true)] + private static extern IntPtr LoadLibrary(string libName); + [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)] + private static extern IntPtr GetProcAddress(IntPtr lib, string name); + #endregion + + internal static TDelegate ResolveSymbol(string libName, string name) + { + foreach (string libNameFormat in libNames) + { + string fullLibName = string.Format(libNameFormat, libName); + + foreach (string path in paths) + { + string relativeLibPath = string.Format(path, fullLibName); + + string absoluteLibPath = getPath(relativeLibPath); + + if (File.Exists(absoluteLibPath)) + { + IntPtr lib = getLibPtr(absoluteLibPath); + if (lib == IntPtr.Zero) continue; + + IntPtr symbolPtr = getSymbolPtr(lib, name); + + if (symbolPtr == IntPtr.Zero) continue; + + return Marshal.GetDelegateForFunctionPointer(symbolPtr); + } + } + } + Console.WriteLine("not found"); + return default; + } + } +} diff --git a/SourceSDK/public/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs index e7db65d..7614bc7 100644 --- a/SourceSDK/public/tier0/dbg.cs +++ b/SourceSDK/public/tier0/dbg.cs @@ -14,21 +14,21 @@ static Dbg() { DevMsg = Windows.DevMsg; DevWarning = Windows.DevWarning; - ConColorMsg = Windows.ConColorMsg; + //ConColorMsg = Windows.ConColorMsg; ConMsg = Windows.ConMsg; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { DevMsg = Linux.DevMsg; DevWarning = Linux.DevWarning; - ConColorMsg = Linux.ConColorMsg; + //ConColorMsg = Linux.ConColorMsg; ConMsg = Linux.ConMsg; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { DevMsg = OSX.DevMsg; DevWarning = OSX.DevWarning; - ConColorMsg = OSX.ConColorMsg; + //ConColorMsg = OSX.ConColorMsg; ConMsg = OSX.ConMsg; } else @@ -106,7 +106,7 @@ public static class Delegates public static readonly Delegates.void_string DevWarning; - public static readonly Delegates.void_inColor_string ConColorMsg; + public static readonly Delegates.void_inColor_string ConColorMsg = SymbolResolver.ResolveSymbol("tier0", "ConColorMsg"); public static readonly Delegates.void_string ConMsg; [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] From 241b7cc81a94c62b52b7f0a06d3a49ed2317f046 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 23 Feb 2021 15:47:38 +0500 Subject: [PATCH 195/235] single line entry points --- SourceSDK/EntryPoints.cs | 17 +++++++ SourceSDK/SymbolResolver.cs | 94 +++++++++++++++++++---------------- SourceSDK/public/tier0/dbg.cs | 84 ++----------------------------- 3 files changed, 71 insertions(+), 124 deletions(-) create mode 100644 SourceSDK/EntryPoints.cs diff --git a/SourceSDK/EntryPoints.cs b/SourceSDK/EntryPoints.cs new file mode 100644 index 0000000..f2496bf --- /dev/null +++ b/SourceSDK/EntryPoints.cs @@ -0,0 +1,17 @@ +namespace GmodNET.SourceSDK +{ + internal static class EntryPoints + { + internal const string DevMsg_win64 = "?DevMsg@@YAXPEBDZZ"; + internal const string DevMsg_linux64 = "_Z6DevMsgPKcz"; + + internal const string DevWarning_win64 = "?DevWarning@@YAXPEBDZZ"; + internal const string DevWarning_linux64 = "_Z10DevWarningPKcz"; + + internal const string ConColorMsg_win64 = "?ConColorMsg@@YAXAEBVColor@@PEBDZZ"; + internal const string ConColorMsg_linux64 = "_Z11ConColorMsgRK5ColorPKcz"; + + internal const string ConMsg_win64 = "?ConMsg@@YAXPEBDZZ"; + internal const string ConMsg_linux64 = "_Z6ConMsgPKcz"; + } +} diff --git a/SourceSDK/SymbolResolver.cs b/SourceSDK/SymbolResolver.cs index 43720bb..de7ea74 100644 --- a/SourceSDK/SymbolResolver.cs +++ b/SourceSDK/SymbolResolver.cs @@ -15,50 +15,49 @@ internal static class SymbolResolver static SymbolResolver() { - switch (Environment.OSVersion.Platform) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - case PlatformID.Win32NT: - getLibPtr = LoadLibrary; - getSymbolPtr = GetProcAddress; - libNames = new[] - { - "{0}.dll" - }; - paths = new[] - { - "bin/win64/{0}", - // "bin/{0}" - }; - break; - case PlatformID.Unix: - getLibPtr = dlopen; - getSymbolPtr = dlsym; - libNames = new[] - { - "{0}.so", - "lib{0}.so" - }; - paths = new[] - { - "bin/linux64/{0}" - }; - break; - case PlatformID.MacOSX: - getLibPtr = dlopen; - getSymbolPtr = dlsym; - libNames = new[] - { - "{0}.dylib", - "lib{0}.dylib" - }; - paths = new[] - { - "bin/osx64/{0}" - }; - break; - default: - throw new PlatformNotSupportedException(); + getLibPtr = LoadLibrary; + getSymbolPtr = GetProcAddress; + libNames = new[] + { + "{0}.dll" + }; + paths = new[] + { + "bin/win64/{0}", + // "bin/{0}" + }; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + getLibPtr = dlopen; + getSymbolPtr = dlsym; + libNames = new[] + { + "{0}.so", + "lib{0}.so" + }; + paths = new[] + { + "bin/linux64/{0}" + }; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + getLibPtr = dlopen; + getSymbolPtr = dlsym; + libNames = new[] + { + "{0}.dylib", + "lib{0}.dylib" + }; + paths = new[] + { + "bin/osx64/{0}" + }; } + else throw new PlatformNotSupportedException(); } #region native @@ -73,7 +72,7 @@ static SymbolResolver() private static extern IntPtr GetProcAddress(IntPtr lib, string name); #endregion - internal static TDelegate ResolveSymbol(string libName, string name) + private static TDelegate ResolveSymbol(string libName, string name) { foreach (string libNameFormat in libNames) { @@ -98,8 +97,15 @@ internal static TDelegate ResolveSymbol(string libName, string name) } } } - Console.WriteLine("not found"); return default; } + + internal static TDelegate GetSymbol(string libName, string windows, string unix, string osx = null) + { + if (osx == null) osx = "_" + unix; + string entryPoint = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? windows : (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? unix : osx); + + return ResolveSymbol(libName, entryPoint); + } } } diff --git a/SourceSDK/public/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs index 7614bc7..238b89a 100644 --- a/SourceSDK/public/tier0/dbg.cs +++ b/SourceSDK/public/tier0/dbg.cs @@ -8,81 +8,6 @@ namespace GmodNET.SourceSDK.Tier0 /// public static class Dbg { - static Dbg() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - DevMsg = Windows.DevMsg; - DevWarning = Windows.DevWarning; - //ConColorMsg = Windows.ConColorMsg; - ConMsg = Windows.ConMsg; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - DevMsg = Linux.DevMsg; - DevWarning = Linux.DevWarning; - //ConColorMsg = Linux.ConColorMsg; - ConMsg = Linux.ConMsg; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - DevMsg = OSX.DevMsg; - DevWarning = OSX.DevWarning; - //ConColorMsg = OSX.ConColorMsg; - ConMsg = OSX.ConMsg; - } - else - { - throw new PlatformNotSupportedException(); - } - } - - internal static class Windows - { - [DllImport("tier0", EntryPoint = "?DevMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", EntryPoint = "?DevWarning@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", EntryPoint = "?ConMsg@@YAXPEBDZZ", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - } - internal static class Linux - { - [DllImport("tier0", EntryPoint = "_Z6DevMsgPKcz", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", EntryPoint = "_Z10DevWarningPKcz", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", EntryPoint = "_Z6ConMsgPKcz", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - } - internal static class OSX - { - [DllImport("tier0", EntryPoint = "__Z6DevMsgPKcz", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", EntryPoint = "__Z10DevWarningPKcz", CallingConvention = CallingConvention.Cdecl)] - public static extern void DevWarning([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - - [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConColorMsg(in Color clr, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - - [DllImport("tier0", EntryPoint = "__Z6ConMsgPKcz", CallingConvention = CallingConvention.Cdecl)] - public static extern void ConMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - } - public static class Delegates { public delegate void void_string(string str); @@ -102,12 +27,11 @@ public static class Delegates public static extern void Error([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); - public static readonly Delegates.void_string DevMsg; - public static readonly Delegates.void_string DevWarning; - + public static readonly Delegates.void_string DevMsg = SymbolResolver.GetSymbol("tier0", EntryPoints.DevMsg_win64, EntryPoints.DevMsg_linux64); + public static readonly Delegates.void_string DevWarning = SymbolResolver.GetSymbol("tier0", EntryPoints.DevWarning_win64, EntryPoints.DevWarning_linux64); - public static readonly Delegates.void_inColor_string ConColorMsg = SymbolResolver.ResolveSymbol("tier0", "ConColorMsg"); - public static readonly Delegates.void_string ConMsg; + public static readonly Delegates.void_inColor_string ConColorMsg = SymbolResolver.GetSymbol("tier0", EntryPoints.ConColorMsg_win64, EntryPoints.ConColorMsg_linux64); + public static readonly Delegates.void_string ConMsg = SymbolResolver.GetSymbol("tier0", EntryPoints.ConMsg_win64, EntryPoints.ConMsg_linux64); [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)] public static extern void ConDMsg([MarshalAs(UnmanagedType.LPUTF8Str)] string msg); From 63ccfcbc86d0db0a1c6e4e4986bcaf0cfd39ee31 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Tue, 23 Feb 2021 15:58:13 +0500 Subject: [PATCH 196/235] fix name violation --- SourceSDK/SymbolResolver.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SourceSDK/SymbolResolver.cs b/SourceSDK/SymbolResolver.cs index de7ea74..e3939e7 100644 --- a/SourceSDK/SymbolResolver.cs +++ b/SourceSDK/SymbolResolver.cs @@ -11,7 +11,7 @@ internal static class SymbolResolver private static readonly string[] libNames; private static readonly string[] paths; - private static string getPath(string path) => Path.Combine(Directory.GetCurrentDirectory(), path); + private static string GetPath(string path) => Path.Combine(Directory.GetCurrentDirectory(), path); static SymbolResolver() { @@ -82,7 +82,7 @@ private static TDelegate ResolveSymbol(string libName, string name) { string relativeLibPath = string.Format(path, fullLibName); - string absoluteLibPath = getPath(relativeLibPath); + string absoluteLibPath = GetPath(relativeLibPath); if (File.Exists(absoluteLibPath)) { From e8e0ecdc2912295d69221a22ed216d2400aee784 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 26 Feb 2021 10:49:09 +0500 Subject: [PATCH 197/235] client side linux/osx library support --- SourceSDK/SymbolResolver.cs | 46 +++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/SourceSDK/SymbolResolver.cs b/SourceSDK/SymbolResolver.cs index e3939e7..f21baf8 100644 --- a/SourceSDK/SymbolResolver.cs +++ b/SourceSDK/SymbolResolver.cs @@ -4,8 +4,10 @@ namespace GmodNET.SourceSDK { - internal static class SymbolResolver + public static class SymbolResolver { + public static bool Server { private get; set; } = true; + private static readonly Func getLibPtr; private static readonly Func getSymbolPtr; private static readonly string[] libNames; @@ -33,11 +35,24 @@ static SymbolResolver() { getLibPtr = dlopen; getSymbolPtr = dlsym; - libNames = new[] + if (Server) { - "{0}.so", - "lib{0}.so" - }; + libNames = new[] + { + "{0}.so", + "lib{0}.so" + }; + } + else + { + libNames = new[] + { + "{0}_client.so", + "lib{0}_client.so", + "{0}.so", + "lib{0}.so" + }; + } paths = new[] { "bin/linux64/{0}" @@ -47,11 +62,24 @@ static SymbolResolver() { getLibPtr = dlopen; getSymbolPtr = dlsym; - libNames = new[] + if (Server) { - "{0}.dylib", - "lib{0}.dylib" - }; + libNames = new[] + { + "{0}.dylib", + "lib{0}.dylib" + }; + } + else + { + libNames = new[] + { + "{0}_client.dylib", + "lib{0}_client.dylib", + "{0}.dylib", + "lib{0}.dylib" + }; + } paths = new[] { "bin/osx64/{0}" From c2eb2a54eb13553905ccb932a3e07193e0e72c9a Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Wed, 5 May 2021 23:04:30 +0500 Subject: [PATCH 198/235] working ISurface --- SourceSDK.CAPI/filesystem_c.cpp | 16 +++++++++++++ SourceSDK.CAPI/vgui/isurface_c.cpp | 9 +++++++- SourceSDK.Test/TestModule.cs | 36 ++++++++++++++++++++++++++++++ SourceSDK/public/filesystemh.cs | 14 ++++++++++++ SourceSDK/public/vgui/isurface.cs | 8 +++++++ SourceSDK/tier1/interfaceh.cs | 2 +- 6 files changed, 83 insertions(+), 2 deletions(-) diff --git a/SourceSDK.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp index 09580f8..5a377f9 100644 --- a/SourceSDK.CAPI/filesystem_c.cpp +++ b/SourceSDK.CAPI/filesystem_c.cpp @@ -142,6 +142,22 @@ DLL_EXPORT const char* IFileSystem_FindFirstEx(IFileSystem* fs, const char* pWil return fs->FindFirstEx(pWildCard, pPathID, pHandle); } +DLL_EXPORT const char* IFileSystem_GetLocalPath(IFileSystem* fs, const char* pFileName, char* pDest, int maxLenInChars) { + return fs->GetLocalPath(pFileName, pDest, maxLenInChars); +} +DLL_EXPORT bool IFileSystem_FullPathToRelativePath(IFileSystem* fs, const char* pFullpath, char* pDest, int maxLenInChars) { + return fs->FullPathToRelativePath(pFullpath, pDest, maxLenInChars); +} +DLL_EXPORT bool IFileSystem_GetCurrentDirectory(IFileSystem* fs, char* pDirectory, int maxlen) { + return fs->GetCurrentDirectory(pDirectory, maxlen); +} + +DLL_EXPORT void* IFileSystem_FindOrAddFileName(IFileSystem* fs, char const* pFileName) { + return fs->FindOrAddFileName(pFileName); +} +DLL_EXPORT bool IFileSystem_String(IFileSystem* fs, void* handle, char* buf, int buflen) { + return fs->String(handle, buf, buflen); +} DLL_EXPORT void IFileSystem_PrintSearchPaths(IFileSystem* fs) { fs->PrintSearchPaths(); diff --git a/SourceSDK.CAPI/vgui/isurface_c.cpp b/SourceSDK.CAPI/vgui/isurface_c.cpp index e64abac..42c1d46 100644 --- a/SourceSDK.CAPI/vgui/isurface_c.cpp +++ b/SourceSDK.CAPI/vgui/isurface_c.cpp @@ -1,6 +1,13 @@ #include -DLL_EXPORT void ISurface_DrawFilledRect(void** ptr, int x0,int y0, int x1, int y1) { +DLL_EXPORT void ISurface_DrawSetColor_RGBA(vgui::ISurface* surf, int r, int g, int b, int a) { + surf->DrawSetColor(r, g, b, a); +} +DLL_EXPORT void ISurface_DrawSetColor_COLOR(vgui::ISurface* surf, Color color) { + surf->DrawSetColor(color); +} + +DLL_EXPORT void ISurface_DrawFilledRect(void** ptr, int x0, int y0, int x1, int y1) { vgui::ISurface* surf = (vgui::ISurface*)ptr; surf->DrawFilledRect(x0, y0, x1, y1); } diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index f3fc0dd..566a01b 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -64,6 +64,8 @@ private static IntPtr GetSystem(string interfaceNoVersionName, string path) return IntPtr.Zero; } + private GCHandle handle; + public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { string platformIdentifier = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win-x64" : "linux-x64"; @@ -166,10 +168,44 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl assembly_context.SetCustomNativeLibraryResolver(null); Debug.Assert(!failed); + + + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + handle = lua.PushManagedFunction(DrawSomething); + lua.SetField(-2, "DrawSomethingPLSWORK"); + lua.Pop(); + } + + private ISurface surface; + + public int DrawSomething(ILua lua) + { + if (surface is null) + { + if (interfaceh.Sys_LoadInterface("vguimatsurface", ISurface.VGUI_SURFACE_INTERFACE_VERSION, out _, out IntPtr isurfacePtr)) + { + surface = new(isurfacePtr); + } + else + { + Console.WriteLine("failed to load"); + } + } + if (surface is not null) + { + Console.WriteLine("drawing"); + surface.DrawSetColor(0, 255, 0, 255); + surface.DrawFilledRect(0, 0, 25, 10); + surface.DrawSetColor(0, 0, 255, 255); + surface.DrawFilledRect(20, 0, 25, 10); + Console.WriteLine("drawn OMG"); + } + return 0; } public void Unload(ILua lua) { + handle.Free(); if (sourcesdkc != IntPtr.Zero) { NativeLibrary.Free(sourcesdkc); diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 6f29432..dbc7a97 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -328,6 +328,20 @@ internal static class FileSystem_c [DllImport("sourcesdkc")] internal static extern string IFileSystem_FindFirstEx(IntPtr ptr, string wildCard, string pathID, out int handle); + [DllImport("sourcesdkc")] + internal static extern string IFileSystem_GetLocalPath(IntPtr ptr, string fileName, ref string dest, int maxlen); + [DllImport("sourcesdkc", CharSet = CharSet.Ansi)] + [return: MarshalAs(UnmanagedType.I1)] + internal static extern bool IFileSystem_FullPathToRelativePath(IntPtr ptr, string fullPath, ref string dest, int maxLenInChars); + + [DllImport("sourcesdkc", CharSet = CharSet.Ansi)] + internal static extern bool IFileSystem_GetCurrentDirectory(IntPtr ptr, ref string pDirectory, int maxlen); + + [DllImport("sourcesdkc", CharSet = CharSet.Ansi)] + internal static extern IntPtr IFileSystem_FindOrAddFileName(IntPtr ptr, string fileName); + + [DllImport("sourcesdkc", CharSet = CharSet.Ansi)] + internal static extern bool IFileSystem_String(IntPtr ptr, IntPtr handle, ref string buffer, int bufMaxLen); [DllImport("sourcesdkc")] internal static extern void IFileSystem_PrintSearchPaths(IntPtr ptr); diff --git a/SourceSDK/public/vgui/isurface.cs b/SourceSDK/public/vgui/isurface.cs index 2c98b75..685a608 100644 --- a/SourceSDK/public/vgui/isurface.cs +++ b/SourceSDK/public/vgui/isurface.cs @@ -11,10 +11,18 @@ public class ISurface : IAppSystem public ISurface(IntPtr ptr) : base(ptr) { } + public void DrawSetColor(int r, int g, int b, int a) => Methods.ISurface_DrawSetColor_RGBA(ptr, r, g, b, a); + public void DrawSetColor(Color color) => Methods.ISurface_DrawSetColor_COLOR(ptr, color); + public void DrawFilledRect(int x0, int y0, int x1, int y1) => Methods.ISurface_DrawFilledRect(ptr, x0, y0, x1, y1); internal static class Methods { + [DllImport("sourcesdkc")] + internal static extern void ISurface_DrawSetColor_RGBA(IntPtr ptr, int r, int g, int b, int a); + [DllImport("sourcesdkc")] + internal static extern void ISurface_DrawSetColor_COLOR(IntPtr ptr, Color color); + [DllImport("sourcesdkc")] internal static extern void ISurface_DrawFilledRect(IntPtr ptr, int x0, int y0, int x1, int y1); diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs index 0263799..cf4db65 100644 --- a/SourceSDK/tier1/interfaceh.cs +++ b/SourceSDK/tier1/interfaceh.cs @@ -109,7 +109,7 @@ public static bool Sys_LoadInterface(string moduleName, string interfaceVersionN Console.WriteLine("factory()"); outInterface = factory(interfaceVersionName, out IFACE returnCode); - if (returnCode != IFACE.OK || outInterface == IntPtr.Zero) + if (returnCode is not IFACE.OK || outInterface == IntPtr.Zero) { Console.WriteLine("Sys_UnloadModule"); Sys_UnloadModule(outModule); From b67474ea96843d3ad8cd9ff46c15db1faa0e470a Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Thu, 6 May 2021 22:53:13 +0500 Subject: [PATCH 199/235] update --- SourceSDK.CAPI/vgui/isurface_c.cpp | 38 +++++++++++++++++- SourceSDK/public/filesystemh.cs | 13 +++++++ SourceSDK/public/vgui/isurface.cs | 62 ++++++++++++++++++++++++++++-- 3 files changed, 107 insertions(+), 6 deletions(-) diff --git a/SourceSDK.CAPI/vgui/isurface_c.cpp b/SourceSDK.CAPI/vgui/isurface_c.cpp index 42c1d46..e7428dc 100644 --- a/SourceSDK.CAPI/vgui/isurface_c.cpp +++ b/SourceSDK.CAPI/vgui/isurface_c.cpp @@ -1,5 +1,27 @@ #include +DLL_EXPORT void ISurface_Shutdown(vgui::ISurface* surf) { + surf->Shutdown(); +} + +DLL_EXPORT void ISurface_RunFrame(vgui::ISurface* surf) { + surf->RunFrame(); +} + +DLL_EXPORT unsigned int ISurface_GetEmbeddedPanel(vgui::ISurface* surf) { + return surf->GetEmbeddedPanel(); +} +DLL_EXPORT void ISurface_SetEmbeddedPanel(vgui::ISurface* surf, unsigned int panel) { + surf->SetEmbeddedPanel(panel); +} + +DLL_EXPORT void ISurface_PushMakeCurrent(vgui::ISurface* surf, unsigned int panel, bool useInsets) { + surf->PushMakeCurrent(panel, useInsets); +} +DLL_EXPORT void ISurface_PopMakeCurrent(vgui::ISurface* surf, unsigned int panel) { + surf->PopMakeCurrent(panel); +} + DLL_EXPORT void ISurface_DrawSetColor_RGBA(vgui::ISurface* surf, int r, int g, int b, int a) { surf->DrawSetColor(r, g, b, a); } @@ -7,10 +29,22 @@ DLL_EXPORT void ISurface_DrawSetColor_COLOR(vgui::ISurface* surf, Color color) { surf->DrawSetColor(color); } -DLL_EXPORT void ISurface_DrawFilledRect(void** ptr, int x0, int y0, int x1, int y1) { - vgui::ISurface* surf = (vgui::ISurface*)ptr; +DLL_EXPORT void ISurface_DrawFilledRect(vgui::ISurface* surf, int x0, int y0, int x1, int y1) { surf->DrawFilledRect(x0, y0, x1, y1); } +DLL_EXPORT void ISurface_DrawFilledRectArray(vgui::ISurface* surf, vgui::IntRect* pRects, int numRects) { + surf->DrawFilledRectArray(pRects, numRects); +} +DLL_EXPORT void ISurface_DrawOutlinedRect(vgui::ISurface* surf, int x0, int y0, int x1, int y1) { + surf->DrawOutlinedRect(x0, y0, x1, y1); +} + +DLL_EXPORT void ISurface_DrawLine(vgui::ISurface* surf, int x0, int y0, int x1, int y1) { + surf->DrawLine(x0, y0, x1, y1); +} +DLL_EXPORT void ISurface_DrawPolyLine(vgui::ISurface* surf, int* px, int* py, int numPoints) { + surf->DrawPolyLine(px, py, numPoints); +} DLL_EXPORT void ISurface_DrawSetTextureRGBAex(void** ptr, int id, const unsigned char* rgba, int wide, int tall, ImageFormat imageFormat) { vgui::ISurface* surf = (vgui::ISurface*)ptr; diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index dbc7a97..9f4eac0 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -440,6 +440,13 @@ internal interface IFileSystem void IFileSystem_FindClose(int handle); string IFileSystem_FindFirstEx(string wildCard, string pathID, out int handle); #endregion + #region Paths + string GetLocalPath(string fileName, ref string dest, int maxLen); + bool FullPathToRelativePath(string fullPath, ref string dest, int maxLen); + bool GetCurrentDirectory(ref string pDirectory, int maxLen); + IntPtr FindOrAddFileName(string fileName); + bool @String(IntPtr handle, ref string buffer, int bufMaxLen); + #endregion void PrintSearchPaths(); } @@ -542,6 +549,12 @@ public FileSystem(IntPtr ptr) : base(ptr) { } public void IFileSystem_FindClose(int handle) => FileSystem_c.IFileSystem_FindClose(ptr, handle); public string IFileSystem_FindFirstEx(string wildCard, string pathID, out int handle) => FileSystem_c.IFileSystem_FindFirstEx(ptr, wildCard, pathID, out handle); + public string GetLocalPath(string fileName, ref string dest, int maxLen) => FileSystem_c.IFileSystem_GetLocalPath(ptr, fileName, ref dest, maxLen); + public bool FullPathToRelativePath(string fullPath, ref string dest, int maxLen) => FileSystem_c.IFileSystem_FullPathToRelativePath(ptr, fullPath, ref dest, maxLen); + public bool GetCurrentDirectory(ref string pDirectory, int maxLen) => FileSystem_c.IFileSystem_GetCurrentDirectory(ptr, ref pDirectory, maxLen); + public IntPtr FindOrAddFileName(string fileName) => FileSystem_c.IFileSystem_FindOrAddFileName(ptr, fileName); + public bool @String(IntPtr handle, ref string buffer, int bufMaxLen) => FileSystem_c.IFileSystem_String(ptr, handle, ref buffer, bufMaxLen); + public void PrintSearchPaths() => FileSystem_c.IFileSystem_PrintSearchPaths(ptr); } } diff --git a/SourceSDK/public/vgui/isurface.cs b/SourceSDK/public/vgui/isurface.cs index 685a608..81f4ca7 100644 --- a/SourceSDK/public/vgui/isurface.cs +++ b/SourceSDK/public/vgui/isurface.cs @@ -5,27 +5,81 @@ namespace GmodNET.SourceSDK.vgui { + [StructLayout(LayoutKind.Sequential)] + public struct IntRect + { + public int x0; + public int y0; + public int x1; + public int y1; + }; public class ISurface : IAppSystem { public const string VGUI_SURFACE_INTERFACE_VERSION = "VGUI_Surface030"; public ISurface(IntPtr ptr) : base(ptr) { } - public void DrawSetColor(int r, int g, int b, int a) => Methods.ISurface_DrawSetColor_RGBA(ptr, r, g, b, a); - public void DrawSetColor(Color color) => Methods.ISurface_DrawSetColor_COLOR(ptr, color); + public new void Shutdown() => Methods.ISurface_Shutdown(ptr); + + public void RunFrame() => Methods.ISurface_RunFrame(ptr); + + public uint GetEmbeddedPanel() => Methods.ISurface_GetEmbeddedPanel(ptr); + public void SetEmbeddedPanel(uint panel) => Methods.ISurface_SetEmbeddedPanel(ptr, panel); + + public void PushMakeCurrent(uint panel, bool useInsets) => Methods.ISurface_PushMakeCurrent(ptr, panel, useInsets); + public void PopMakeCurrent(uint panel) => Methods.ISurface_PopMakeCurrent(ptr, panel); + + public void DrawSetColor(int r, int g, int b, int a) => Methods.ISurface_DrawSetColor(ptr, r, g, b, a); + public void DrawSetColor(Color color) => Methods.ISurface_DrawSetColor(ptr, color); public void DrawFilledRect(int x0, int y0, int x1, int y1) => Methods.ISurface_DrawFilledRect(ptr, x0, y0, x1, y1); + public void DrawFilledRectArray(IntRect[] rects) => Methods.ISurface_DrawFilledRectArray(ptr, rects, rects.Length); + public unsafe void DrawFilledRectArray(IntRect* rects, int numRects) => Methods.ISurface_DrawFilledRectArray(ptr, rects, numRects); + public void DrawOutlinedRect(int x0, int y0, int x1, int y1) => Methods.ISurface_DrawOutlinedRect(ptr, x0, y0, x1, y1); + + public void DrawLine(int x0, int y0, int x1, int y1) => Methods.ISurface_DrawLine(ptr, x0, y0, x1, y1); + public void DrawPolyLine(int[] px, int[] py, int numPoints) => Methods.ISurface_DrawPolyLine(ptr, px, py, numPoints); + public void DrawPolyLine(int[] px, int[] py) => Methods.ISurface_DrawPolyLine(ptr, px, py, Math.Min(px.Length, py.Length)); + public unsafe void DrawPolyLine(int* px, int* py, int numPoints) => Methods.ISurface_DrawPolyLine(ptr, px, py, numPoints); internal static class Methods { [DllImport("sourcesdkc")] - internal static extern void ISurface_DrawSetColor_RGBA(IntPtr ptr, int r, int g, int b, int a); + internal static extern void ISurface_Shutdown(IntPtr ptr); + + [DllImport("sourcesdkc")] + internal static extern void ISurface_RunFrame(IntPtr ptr); + + [DllImport("sourcesdkc")] + internal static extern uint ISurface_GetEmbeddedPanel(IntPtr ptr); [DllImport("sourcesdkc")] - internal static extern void ISurface_DrawSetColor_COLOR(IntPtr ptr, Color color); + internal static extern void ISurface_SetEmbeddedPanel(IntPtr ptr, uint panel); + + [DllImport("sourcesdkc")] + internal static extern void ISurface_PushMakeCurrent(IntPtr ptr, uint panel, [MarshalAs(UnmanagedType.I1)] bool useInsets); + [DllImport("sourcesdkc")] + internal static extern void ISurface_PopMakeCurrent(IntPtr ptr, uint panel); + + [DllImport("sourcesdkc", EntryPoint = "ISurface_DrawSetColor_RGBA")] + internal static extern void ISurface_DrawSetColor(IntPtr ptr, int r, int g, int b, int a); + [DllImport("sourcesdkc", EntryPoint = "ISurface_DrawSetColor_COLOR")] + internal static extern void ISurface_DrawSetColor(IntPtr ptr, Color color); [DllImport("sourcesdkc")] internal static extern void ISurface_DrawFilledRect(IntPtr ptr, int x0, int y0, int x1, int y1); + [DllImport("sourcesdkc")] + internal static extern void ISurface_DrawFilledRectArray(IntPtr ptr, IntRect[] rects, int numRects); + [DllImport("sourcesdkc")] + internal static unsafe extern void ISurface_DrawFilledRectArray(IntPtr ptr, IntRect* rects, int numRects); + [DllImport("sourcesdkc")] + internal static extern void ISurface_DrawOutlinedRect(IntPtr ptr, int x0, int y0, int x1, int y1); + [DllImport("sourcesdkc")] + internal static extern void ISurface_DrawLine(IntPtr ptr, int x0, int y0, int x1, int y1); + [DllImport("sourcesdkc")] + internal static unsafe extern void ISurface_DrawPolyLine(IntPtr ptr, int[] px, int[] py, int numPoints); + [DllImport("sourcesdkc")] + internal static unsafe extern void ISurface_DrawPolyLine(IntPtr ptr, int* px, int* py, int numPoints); [DllImport("sourcesdkc")] internal static extern void ISurface_DrawSetTextureRGBAex(IntPtr ptr, int id, IntPtr rgba, int wide, int tall, ImageFormat imageFormat); From cee7c407d8945cbb3e0b2de54db5a668cb523231 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 11:35:40 +0500 Subject: [PATCH 200/235] DllImportGenerator thing --- SourceSDK/GmodNET.SourceSDK.csproj | 4 ++++ SourceSDK/public/filesystemh.cs | 30 +++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/SourceSDK/GmodNET.SourceSDK.csproj b/SourceSDK/GmodNET.SourceSDK.csproj index 7c38001..f305d9e 100644 --- a/SourceSDK/GmodNET.SourceSDK.csproj +++ b/SourceSDK/GmodNET.SourceSDK.csproj @@ -18,4 +18,8 @@ + + + + diff --git a/SourceSDK/public/filesystemh.cs b/SourceSDK/public/filesystemh.cs index 9f4eac0..eb3d5d6 100644 --- a/SourceSDK/public/filesystemh.cs +++ b/SourceSDK/public/filesystemh.cs @@ -3,6 +3,7 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Text; namespace GmodNET.SourceSDK { @@ -265,10 +266,11 @@ internal static class BaseFileSystem_c //TODO: CUtlBuffer } - internal static class FileSystem_c + internal static partial class FileSystem_c { - [DllImport("sourcesdkc")] - internal static extern bool IFileSystem_IsSteam(IntPtr ptr); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + internal static partial bool IFileSystem_IsSteam(IntPtr ptr); [DllImport("sourcesdkc")] internal static extern FilesystemMountRetval_t IFileSystem_MountSteamContent(IntPtr ptr, int extraAppId = -1); @@ -334,8 +336,9 @@ internal static class FileSystem_c [return: MarshalAs(UnmanagedType.I1)] internal static extern bool IFileSystem_FullPathToRelativePath(IntPtr ptr, string fullPath, ref string dest, int maxLenInChars); - [DllImport("sourcesdkc", CharSet = CharSet.Ansi)] - internal static extern bool IFileSystem_GetCurrentDirectory(IntPtr ptr, ref string pDirectory, int maxlen); + [DllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + internal static extern unsafe bool IFileSystem_GetCurrentDirectory(IntPtr ptr, byte* pDirectory, int maxlen); [DllImport("sourcesdkc", CharSet = CharSet.Ansi)] internal static extern IntPtr IFileSystem_FindOrAddFileName(IntPtr ptr, string fileName); @@ -443,7 +446,7 @@ internal interface IFileSystem #region Paths string GetLocalPath(string fileName, ref string dest, int maxLen); bool FullPathToRelativePath(string fullPath, ref string dest, int maxLen); - bool GetCurrentDirectory(ref string pDirectory, int maxLen); + //bool GetCurrentDirectory(ref string pDirectory, int maxLen); IntPtr FindOrAddFileName(string fileName); bool @String(IntPtr handle, ref string buffer, int bufMaxLen); #endregion @@ -551,7 +554,20 @@ public FileSystem(IntPtr ptr) : base(ptr) { } public string GetLocalPath(string fileName, ref string dest, int maxLen) => FileSystem_c.IFileSystem_GetLocalPath(ptr, fileName, ref dest, maxLen); public bool FullPathToRelativePath(string fullPath, ref string dest, int maxLen) => FileSystem_c.IFileSystem_FullPathToRelativePath(ptr, fullPath, ref dest, maxLen); - public bool GetCurrentDirectory(ref string pDirectory, int maxLen) => FileSystem_c.IFileSystem_GetCurrentDirectory(ptr, ref pDirectory, maxLen); + public unsafe bool GetCurrentDirectory(byte* pDirectory, int maxLen) => FileSystem_c.IFileSystem_GetCurrentDirectory(ptr, pDirectory, maxLen); + public bool GetCurrentDirectory(out string pDirectory, int maxLen = 1024) + { + unsafe + { + byte* bytes = stackalloc byte[maxLen]; + + bool retVal = GetCurrentDirectory(bytes, maxLen); + + pDirectory = Encoding.UTF8.GetString(bytes, maxLen); + + return retVal; + } + } public IntPtr FindOrAddFileName(string fileName) => FileSystem_c.IFileSystem_FindOrAddFileName(ptr, fileName); public bool @String(IntPtr handle, ref string buffer, int bufMaxLen) => FileSystem_c.IFileSystem_String(ptr, handle, ref buffer, bufMaxLen); From 0659da3ae0c9bbf659c83bedf543506f192c23b6 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 11:47:35 +0500 Subject: [PATCH 201/235] update gmod_sdk --- SourceSDK.CAPI/gmod_sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK.CAPI/gmod_sdk b/SourceSDK.CAPI/gmod_sdk index b3f9c35..6ca2122 160000 --- a/SourceSDK.CAPI/gmod_sdk +++ b/SourceSDK.CAPI/gmod_sdk @@ -1 +1 @@ -Subproject commit b3f9c353af738791d1abf312925a4245294895fe +Subproject commit 6ca212226e143d39bdd0c637b7b80adb6cab99b3 From 81b6d7fecaf0f60daddc5f6a20c8e808465dbeff Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 11:59:12 +0500 Subject: [PATCH 202/235] add DotNet Experimental --- nuget.config | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 nuget.config diff --git a/nuget.config b/nuget.config new file mode 100644 index 0000000..be62b1f --- /dev/null +++ b/nuget.config @@ -0,0 +1,8 @@ + + + + + + + + From 1eedbd3826ee7a2efa70213aba4c428f682286ee Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 12:02:50 +0500 Subject: [PATCH 203/235] fix nuget --- nuget.config | 1 + 1 file changed, 1 insertion(+) diff --git a/nuget.config b/nuget.config index be62b1f..5566b7d 100644 --- a/nuget.config +++ b/nuget.config @@ -3,6 +3,7 @@ + From 3f45641344c421f52196d5889237ade01227abf2 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 12:11:15 +0500 Subject: [PATCH 204/235] fix nuget --- SourceSDK.Test/nuget.config | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 SourceSDK.Test/nuget.config diff --git a/SourceSDK.Test/nuget.config b/SourceSDK.Test/nuget.config deleted file mode 100644 index d0286a3..0000000 --- a/SourceSDK.Test/nuget.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - From 80dfeb5e65940c96292a782b56012ab00ab2813d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 12:15:14 +0500 Subject: [PATCH 205/235] PrivateAssets="All" --- SourceSDK/GmodNET.SourceSDK.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SourceSDK/GmodNET.SourceSDK.csproj b/SourceSDK/GmodNET.SourceSDK.csproj index f305d9e..65a9221 100644 --- a/SourceSDK/GmodNET.SourceSDK.csproj +++ b/SourceSDK/GmodNET.SourceSDK.csproj @@ -1,4 +1,4 @@ - + net5 true @@ -19,7 +19,7 @@ - - + + - + \ No newline at end of file From 03dc9f7d4fd1fd545fd69596d08bbea7c23f3ed7 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 12:23:22 +0500 Subject: [PATCH 206/235] fix nuget --- nuget.config | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nuget.config b/nuget.config index 5566b7d..7b42a7e 100644 --- a/nuget.config +++ b/nuget.config @@ -3,7 +3,11 @@ + + + + From 6dfb88a1e57d4cf335f23b497130a4843d550b96 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 12:59:45 +0500 Subject: [PATCH 207/235] fix nuget --- SourceSDK.sln | 1 + nuget.config | 3 +++ 2 files changed, 4 insertions(+) diff --git a/SourceSDK.sln b/SourceSDK.sln index 6471806..bae1298 100644 --- a/SourceSDK.sln +++ b/SourceSDK.sln @@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .editorconfig = .editorconfig .gitignore = .gitignore .github\workflows\build.yml = .github\workflows\build.yml + nuget.config = nuget.config .github\workflows\test.lua = .github\workflows\test.lua EndProjectSection EndProject diff --git a/nuget.config b/nuget.config index 7b42a7e..9f2e200 100644 --- a/nuget.config +++ b/nuget.config @@ -8,6 +8,9 @@ + + + From 30ec049a58cc625780b25e3da94bed3755adeb9b Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 13:16:09 +0500 Subject: [PATCH 208/235] fix --- SourceSDK/GmodNET.SourceSDK.csproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SourceSDK/GmodNET.SourceSDK.csproj b/SourceSDK/GmodNET.SourceSDK.csproj index 65a9221..2d2c433 100644 --- a/SourceSDK/GmodNET.SourceSDK.csproj +++ b/SourceSDK/GmodNET.SourceSDK.csproj @@ -1,4 +1,4 @@ - + net5 true @@ -6,6 +6,10 @@ GmodNET.SourceSDK 0.0.1 true + true + preview + true + true From e18cc87ca42c4be3c79aecf7b9acf136390568f8 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 13:23:58 +0500 Subject: [PATCH 209/235] install net6 --- .github/workflows/build.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4e64c01..85c313b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -69,10 +69,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 + - name: Setup .NET Core SDK + uses: actions/setup-dotnet@v1.7.2 with: dotnet-version: 5.0.100 + - name: Setup .NET Core SDK + uses: actions/setup-dotnet@v1.7.2 + with: + dotnet-version: 6.0.100-preview.3.21202.5 - name: Download linux-x64 uses: actions/download-artifact@v2 with: From 8042e2f821613b68296119b9221bb9a17fbcd388 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 13:30:24 +0500 Subject: [PATCH 210/235] remove unused things --- SourceSDK/GmodNET.SourceSDK.csproj | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/SourceSDK/GmodNET.SourceSDK.csproj b/SourceSDK/GmodNET.SourceSDK.csproj index 2d2c433..4cad751 100644 --- a/SourceSDK/GmodNET.SourceSDK.csproj +++ b/SourceSDK/GmodNET.SourceSDK.csproj @@ -7,9 +7,7 @@ 0.0.1 true true - preview - true - true + 9.0 From 2092895035739d6f6adf8813ccce222414754a3f Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 13:32:14 +0500 Subject: [PATCH 211/235] higher timeout --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 85c313b..4c76c7f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -142,7 +142,7 @@ jobs: - name: Run Garry's Mod run: ./srcds_run_x64 -game garrysmod -systemtest -condebug +developer 1 +exec "server.cfg" +gamemode sandbox +map gm_construct +maxplayers 2 +sv_hibernate_think 1 || true working-directory: ./gmod/ - timeout-minutes: 3 + timeout-minutes: 5 continue-on-error: true - name: Print log run: cat gmod/garrysmod/console.log From ba04343fc5542aed2d675ab98a380496f3d63e0a Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 14:03:18 +0500 Subject: [PATCH 212/235] stackalloc --- SourceSDK.Test/TestModule.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs index 566a01b..05c8e2a 100644 --- a/SourceSDK.Test/TestModule.cs +++ b/SourceSDK.Test/TestModule.cs @@ -146,16 +146,13 @@ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembl if (fileHandle != IntPtr.Zero) { uint size = baseFileSystem.Size(fileHandle); - byte[] buff = new byte[size]; - - fixed (byte* buffPtr = buff) - { - IntPtr buffIntPtr = new(buffPtr); - baseFileSystem.Read(buffIntPtr, (int)size, fileHandle); - //byte* bufferResult = (byte*)buffIntPtr.ToPointer(); - Console.WriteLine("Printing file contents"); - Console.WriteLine(Encoding.UTF8.GetChars(buff)); - } + + 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 From 797d1cde9a6742a0570837c045e1ea9600954c8f Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 18:43:58 +0500 Subject: [PATCH 213/235] IMatSystemSurface --- SourceSDK.CAPI/CMakeLists.txt | 2 +- .../VGuiMatSurface/IMatSystemSurface_c.cpp | 92 +++++++++++++++++++ .../VGuiMatSurface/IMatSystemSurface_h.cs | 63 +++++++++++++ 3 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 SourceSDK.CAPI/VGuiMatSurface/IMatSystemSurface_c.cpp create mode 100644 SourceSDK/public/VGuiMatSurface/IMatSystemSurface_h.cs diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index 03c2b0d..70ab49c 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -49,7 +49,7 @@ add_compile_definitions(${SOURCESDK_DEFINES}) link_directories("${SOURCESDK_LIBDIRS}") link_libraries(tier0) -add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp" ) +add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp" "VGuiMatSurface/IMatSystemSurface_c.cpp") target_include_directories(sourcesdkc PUBLIC#SYSTEM INTERFACE #"${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/common" diff --git a/SourceSDK.CAPI/VGuiMatSurface/IMatSystemSurface_c.cpp b/SourceSDK.CAPI/VGuiMatSurface/IMatSystemSurface_c.cpp new file mode 100644 index 0000000..ffa9eeb --- /dev/null +++ b/SourceSDK.CAPI/VGuiMatSurface/IMatSystemSurface_c.cpp @@ -0,0 +1,92 @@ +#include + +DLL_EXPORT void IMatSystemSurface_AttachToWindow(IMatSystemSurface* s, void* hwnd, bool bLetAppDriveInput) { + s->AttachToWindow(hwnd, bLetAppDriveInput); +} +DLL_EXPORT void IMatSystemSurface_EnableWindowsMessages(IMatSystemSurface* s, bool enable) { + s->EnableWindowsMessages(enable); +} + + +DLL_EXPORT void IMatSystemSurface_Begin3DPaint(IMatSystemSurface* s, int iLeft, int iTop, int iRight, int iBottom, bool bRenderToTexture) { + s->Begin3DPaint(iLeft, iTop, iRight, iBottom, bRenderToTexture); +} +DLL_EXPORT void IMatSystemSurface_End3DPaint(IMatSystemSurface* s) { + s->End3DPaint(); +} + +DLL_EXPORT void IMatSystemSurface_DisableClipping(IMatSystemSurface* s, bool disable) { + s->DisableClipping(disable); +} +DLL_EXPORT void IMatSystemSurface_GetClippingRect(IMatSystemSurface* s, int& left, int& top, int& right, int& bottom, bool& bClippingDisabled) { + s->GetClippingRect(left, top, right, bottom, bClippingDisabled); +} +DLL_EXPORT void IMatSystemSurface_SetClippingRect(IMatSystemSurface* s, int left, int top, int right, int bottom) { + s->SetClippingRect(left, top, right, bottom); +} + +DLL_EXPORT bool IMatSystemSurface_IsCursorLocked(IMatSystemSurface* s) { + return s->IsCursorLocked(); +} + +DLL_EXPORT void IMatSystemSurface_SetMouseCallbacks(IMatSystemSurface* s, GetMouseCallback_t get, SetMouseCallback_t set) { + s->SetMouseCallbacks(get, set); +} +DLL_EXPORT void IMatSystemSurface_InstallPlaySoundFunc(IMatSystemSurface* s, PlaySoundFunc_t f) { + s->InstallPlaySoundFunc(f); +} +// aaaaaaaaaaaaaaaaaaaaaaaaaaa +DLL_EXPORT void IMatSystemSurface_DrawColoredCircle(IMatSystemSurface* s, int centerx, int centery, float radius, int r, int g, int b, int a) { + s->DrawColoredCircle(centerx, centery, radius, r, g, b, a); +} +DLL_EXPORT int IMatSystemSurface_DrawColoredText(IMatSystemSurface* s, vgui::HFont font, int x, int y, int r, int g, int b, int a, const char* fmt) { + return s->DrawColoredText(font, x, y, r, g, b, a, fmt); +} + +DLL_EXPORT void IMatSystemSurface_DrawColoredTextRect(IMatSystemSurface* s, vgui::HFont font, int x, int y, int w, int h, int r, int g, int b, int a, const char* fmt) { + s->DrawColoredTextRect(font, x, y, w, h, r, g, b, a, fmt); +} +DLL_EXPORT void IMatSystemSurface_DrawTextHeight(IMatSystemSurface* s, vgui::HFont font, int w, int& h, const char* fmt) { + s->DrawTextHeight(font, w, h, fmt); +} + +DLL_EXPORT int IMatSystemSurface_DrawTextLen(IMatSystemSurface* s, vgui::HFont font, const char* fmt) { + return s->DrawTextLen(font, fmt); +} + +DLL_EXPORT void IMatSystemSurface_DrawPanelIn3DSpace(IMatSystemSurface* s, vgui::VPANEL pRootPanel, const VMatrix& panelCenterToWorld, int nPixelWidth, int nPixelHeight, float flWorldWidth, float flWorldHeight) { + s->DrawPanelIn3DSpace(pRootPanel, panelCenterToWorld, nPixelWidth, nPixelHeight, flWorldWidth, flWorldHeight); +} + +DLL_EXPORT void IMatSystemSurface_DrawSetTextureMaterial(IMatSystemSurface* s, int id, IMaterial* pMaterial) { + s->DrawSetTextureMaterial(id, pMaterial); +} + +DLL_EXPORT void IMatSystemSurface_Set3DPaintTempRenderTarget(IMatSystemSurface* s, const char* renderTargetName) { + s->Set3DPaintTempRenderTarget(renderTargetName); +} +DLL_EXPORT void IMatSystemSurface_Reset3DPaintTempRenderTarget(IMatSystemSurface* s) { + s->Reset3DPaintTempRenderTarget(); +} + +DLL_EXPORT IMaterial* IMatSystemSurface_DrawGetTextureMaterial(IMatSystemSurface* s, int id) { + return s->DrawGetTextureMaterial(id); +} + +DLL_EXPORT void IMatSystemSurface_GetFullscreenViewportAndRenderTarget(IMatSystemSurface* s, int& x, int& y, int& w, int& h, ITexture** ppRenderTarget) { + s->GetFullscreenViewportAndRenderTarget(x, y, w, h, ppRenderTarget); +} +DLL_EXPORT void IMatSystemSurface_SetFullscreenViewportAndRenderTarget(IMatSystemSurface* s, int x, int y, int w, int h, ITexture* pRenderTarget) { + s->SetFullscreenViewportAndRenderTarget(x, y, w, h, pRenderTarget); +} + +DLL_EXPORT int IMatSystemSurface_DrawGetTextureId(IMatSystemSurface* s, ITexture* t) { + return s->DrawGetTextureId(t); +} + +DLL_EXPORT void IMatSystemSurface_BeginSkinCompositionPainting(IMatSystemSurface* s) { + s->BeginSkinCompositionPainting(); +} +DLL_EXPORT void IMatSystemSurface_EndSkinCompositionPainting(IMatSystemSurface* s) { + s->EndSkinCompositionPainting(); +} diff --git a/SourceSDK/public/VGuiMatSurface/IMatSystemSurface_h.cs b/SourceSDK/public/VGuiMatSurface/IMatSystemSurface_h.cs new file mode 100644 index 0000000..da8408f --- /dev/null +++ b/SourceSDK/public/VGuiMatSurface/IMatSystemSurface_h.cs @@ -0,0 +1,63 @@ +using System; +using System.Runtime.InteropServices; + +namespace GmodNET.SourceSDK.VGuiMatSurface +{ + public unsafe delegate void GetMouseCallback_t(int* x, int* y); + public delegate void SetMouseCallback_t(int x, int y); + public delegate void PlaySoundFunc_t([MarshalAs(UnmanagedType.LPUTF8Str)] string fileName); + + public partial class IMatSystemSurface : vgui.ISurface + { + public const string MAT_SYSTEM_SURFACE_INTERFACE_VERSION = "MatSystemSurface008"; + public IMatSystemSurface(IntPtr ptr) : base(ptr) + { } + + public void AttachToWindow(IntPtr hwnd, bool bLetAppDriveInput = false) => Methods.IMatSystemSurface_AttachToWindow(ptr, hwnd, bLetAppDriveInput); + public void EnableWindowsMessages(bool enable) => Methods.IMatSystemSurface_EnableWindowsMessages(ptr, enable); + + public void Begin3DPaint(int left, int top, int right, int bottom, bool renderToTexture) => Methods.IMatSystemSurface_Begin3DPaint(ptr, left, top, right, bottom, renderToTexture); + public void End3DPaint() => Methods.IMatSystemSurface_End3DPaint(ptr); + + public void DisableClipping(bool disable) => Methods.IMatSystemSurface_DisableClipping(ptr, disable); + + public void GetClippingRect(ref int left, ref int top, ref int right, ref int bottom, ref bool clippingDisabled) => Methods.IMatSystemSurface_GetClippingRect(ptr, ref left, ref top, ref right, ref bottom, ref clippingDisabled); + public void SetClippingRect(int left, int top, int right, int bottom) => Methods.IMatSystemSurface_SetClippingRect(ptr, left, top, right, bottom); + + public bool IsCursorLocked => Methods.IMatSystemSurface_IsCursorLocked(ptr); + + public void SetMouseCallbacks(GetMouseCallback_t get, SetMouseCallback_t set) => Methods.IMatSystemSurface_SetMouseCallbacks(ptr, get, set); + public void InstallPlaySoundFunc(PlaySoundFunc_t func) => Methods.IMatSystemSurface_InstallPlaySoundFunc(ptr, func); + + new internal static partial class Methods + { + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMatSystemSurface_AttachToWindow(IntPtr s, IntPtr hwnd, [MarshalAs(UnmanagedType.I1)] bool bLetAppDriveInput); + + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMatSystemSurface_EnableWindowsMessages(IntPtr s, [MarshalAs(UnmanagedType.I1)] bool enable); + + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMatSystemSurface_Begin3DPaint(IntPtr s, int iLeft, int iTop, int iRight, int iBottom, [MarshalAs(UnmanagedType.I1)] bool bRenderToTexture); + [DllImport("sourcesdkc")] + internal static extern void IMatSystemSurface_End3DPaint(IntPtr s); + + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMatSystemSurface_DisableClipping(IntPtr s, [MarshalAs(UnmanagedType.I1)] bool disable); + + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMatSystemSurface_GetClippingRect(IntPtr s, ref int left, ref int top, ref int right, ref int bottom, [MarshalAs(UnmanagedType.I1)] ref bool clippingDisabled); + [DllImport("sourcesdkc")] + internal static extern void IMatSystemSurface_SetClippingRect(IntPtr s, int left, int top, int right, int bottom); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + internal static partial bool IMatSystemSurface_IsCursorLocked(IntPtr s); + + [DllImport("sourcesdkc")] + internal static extern void IMatSystemSurface_SetMouseCallbacks(IntPtr s, GetMouseCallback_t get, SetMouseCallback_t set); + [DllImport("sourcesdkc")] + internal static extern void IMatSystemSurface_InstallPlaySoundFunc(IntPtr s, PlaySoundFunc_t func); + } + } +} From 236d953444b297ffb4b831adfa674b64521ebd43 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 20:40:14 +0500 Subject: [PATCH 214/235] IMatSystemSurface --- .../VGuiMatSurface/IMatSystemSurface_c.cpp | 2 +- .../VGuiMatSurface/IMatSystemSurface_h.cs | 68 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/SourceSDK.CAPI/VGuiMatSurface/IMatSystemSurface_c.cpp b/SourceSDK.CAPI/VGuiMatSurface/IMatSystemSurface_c.cpp index ffa9eeb..5ad1c27 100644 --- a/SourceSDK.CAPI/VGuiMatSurface/IMatSystemSurface_c.cpp +++ b/SourceSDK.CAPI/VGuiMatSurface/IMatSystemSurface_c.cpp @@ -35,7 +35,7 @@ DLL_EXPORT void IMatSystemSurface_SetMouseCallbacks(IMatSystemSurface* s, GetMou DLL_EXPORT void IMatSystemSurface_InstallPlaySoundFunc(IMatSystemSurface* s, PlaySoundFunc_t f) { s->InstallPlaySoundFunc(f); } -// aaaaaaaaaaaaaaaaaaaaaaaaaaa + DLL_EXPORT void IMatSystemSurface_DrawColoredCircle(IMatSystemSurface* s, int centerx, int centery, float radius, int r, int g, int b, int a) { s->DrawColoredCircle(centerx, centery, radius, r, g, b, a); } diff --git a/SourceSDK/public/VGuiMatSurface/IMatSystemSurface_h.cs b/SourceSDK/public/VGuiMatSurface/IMatSystemSurface_h.cs index da8408f..a72f184 100644 --- a/SourceSDK/public/VGuiMatSurface/IMatSystemSurface_h.cs +++ b/SourceSDK/public/VGuiMatSurface/IMatSystemSurface_h.cs @@ -1,4 +1,5 @@ using System; +using System.Numerics; using System.Runtime.InteropServices; namespace GmodNET.SourceSDK.VGuiMatSurface @@ -29,6 +30,33 @@ public IMatSystemSurface(IntPtr ptr) : base(ptr) public void SetMouseCallbacks(GetMouseCallback_t get, SetMouseCallback_t set) => Methods.IMatSystemSurface_SetMouseCallbacks(ptr, get, set); public void InstallPlaySoundFunc(PlaySoundFunc_t func) => Methods.IMatSystemSurface_InstallPlaySoundFunc(ptr, func); + public void DrawColoredCircle(int centerx, int centery, float radius, int r, int g, int b, int a) => Methods.IMatSystemSurface_DrawColoredCircle(ptr, centerx, centery, radius, r, g, b, a); + public int DrawColoredText(ulong font, int x, int y, int r, int g, int b, int a, string fmt) => Methods.IMatSystemSurface_DrawColoredText(ptr, font, x, y, r, g, b, a, fmt); + + public void DrawColoredTextRect(ulong font, int x, int y, int w, int h, int r, int g, int b, int a, string fmt) => Methods.IMatSystemSurface_DrawColoredTextRect(ptr, font, x, y, w, h, r, g, b, a, fmt); + public void DrawTextHeight(ulong font, int w, ref int h, string fmt) => Methods.IMatSystemSurface_DrawTextHeight(ptr, font, w, ref h, fmt); + + public int DrawTextLen(ulong font, string fmt) => Methods.IMatSystemSurface_DrawTextLen(ptr, font, fmt); + public void DrawPanelIn3DSpace(uint pRootPanel, ref Matrix4x4 panelCenterToWorld, int nPixelWidth, int nPixelHeight, float flWorldWidth, float flWorldHeight) => Methods.IMatSystemSurface_DrawPanelIn3DSpace(ptr, pRootPanel, ref panelCenterToWorld, nPixelWidth, nPixelHeight, flWorldWidth, flWorldHeight); + + // todo: ITexture bindings + public void DrawSetTextureMaterial(int id, IntPtr texture) => Methods.IMatSystemSurface_DrawSetTextureMaterial(ptr, id, texture); + + public void Set3DPaintTempRenderTarget(string name) => Methods.IMatSystemSurface_Set3DPaintTempRenderTarget(ptr, name); + public void Reset3DPaintTempRenderTarget() => Methods.IMatSystemSurface_Reset3DPaintTempRenderTarget(ptr); + + // todo: ITexture bindings + public IntPtr DrawGetTextureMaterial(int id) => Methods.IMatSystemSurface_DrawGetTextureMaterial(ptr, id); + + public void GetFullscreenViewportAndRenderTarget(ref int x, ref int y, ref int w, ref int h, out IntPtr texture) => Methods.IMatSystemSurface_GetFullscreenViewportAndRenderTarget(ptr, ref x, ref y, ref w, ref h, out texture); + public void SetFullscreenViewportAndRenderTarget(int x, int y, int w, int h, IntPtr texture) => Methods.IMatSystemSurface_SetFullscreenViewportAndRenderTarget(ptr, x, y, w, h, texture); + + public int DrawGetTextureId(IntPtr texture) => Methods.IMatSystemSurface_DrawGetTextureId(ptr, texture); + + public void BeginSkinCompositionPainting() => Methods.IMatSystemSurface_BeginSkinCompositionPainting(ptr); + public void EndSkinCompositionPainting() => Methods.IMatSystemSurface_EndSkinCompositionPainting(ptr); + + new internal static partial class Methods { [GeneratedDllImport("sourcesdkc")] @@ -58,6 +86,46 @@ public IMatSystemSurface(IntPtr ptr) : base(ptr) internal static extern void IMatSystemSurface_SetMouseCallbacks(IntPtr s, GetMouseCallback_t get, SetMouseCallback_t set); [DllImport("sourcesdkc")] internal static extern void IMatSystemSurface_InstallPlaySoundFunc(IntPtr s, PlaySoundFunc_t func); + + [DllImport("sourcesdkc")] + internal static extern void IMatSystemSurface_DrawColoredCircle(IntPtr s, int centerx, int centery, float radius, int r, int g, int b, int a); + [GeneratedDllImport("sourcesdkc")] + internal static partial int IMatSystemSurface_DrawColoredText(IntPtr s, ulong font, int x, int y, int r, int g, int b, int a, [MarshalAs(UnmanagedType.LPUTF8Str)] string fmt); + + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMatSystemSurface_DrawColoredTextRect(IntPtr s, ulong font, int x, int y, int w, int h, int r, int g, int b, int a, [MarshalAs(UnmanagedType.LPUTF8Str)] string fmt); + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMatSystemSurface_DrawTextHeight(IntPtr s, ulong font, int w, ref int h, [MarshalAs(UnmanagedType.LPUTF8Str)] string fmt); + + [GeneratedDllImport("sourcesdkc")] + internal static partial int IMatSystemSurface_DrawTextLen(IntPtr s, ulong font, [MarshalAs(UnmanagedType.LPUTF8Str)] string fmt); + + [DllImport("sourcesdkc")] + internal static extern void IMatSystemSurface_DrawPanelIn3DSpace(IntPtr s, uint pRootPanel, ref Matrix4x4 panelCenterToWorld, int nPixelWidth, int nPixelHeight, float flWorldWidth, float flWorldHeight); + + [DllImport("sourcesdkc")] + internal static extern void IMatSystemSurface_DrawSetTextureMaterial(IntPtr s, int id, IntPtr material); + + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMatSystemSurface_Set3DPaintTempRenderTarget(IntPtr s, [MarshalAs(UnmanagedType.LPUTF8Str)] string renderTargetName); + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMatSystemSurface_Reset3DPaintTempRenderTarget(IntPtr s); + + [DllImport("sourcesdkc")] + internal static extern IntPtr IMatSystemSurface_DrawGetTextureMaterial(IntPtr s, int id); + + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMatSystemSurface_GetFullscreenViewportAndRenderTarget(IntPtr s, ref int x, ref int y, ref int w, ref int h, out IntPtr texture); + [DllImport("sourcesdkc")] + internal static extern void IMatSystemSurface_SetFullscreenViewportAndRenderTarget(IntPtr s, int x, int y, int w, int h, IntPtr texture); + + [DllImport("sourcesdkc")] + internal static extern int IMatSystemSurface_DrawGetTextureId(IntPtr s, IntPtr texture); + + [DllImport("sourcesdkc")] + internal static extern void IMatSystemSurface_BeginSkinCompositionPainting(IntPtr s); + [DllImport("sourcesdkc")] + internal static extern void IMatSystemSurface_EndSkinCompositionPainting(IntPtr s); } } } From 77293df7d1e4ed5b2366b6adfb31ecc6d05c4dd8 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Fri, 7 May 2021 23:06:22 +0500 Subject: [PATCH 215/235] IMaterialSystem --- SourceSDK.CAPI/CMakeLists.txt | 2 +- .../materialsystem/imaterialsystem_c.cpp | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index 70ab49c..ebb9c7f 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -49,7 +49,7 @@ add_compile_definitions(${SOURCESDK_DEFINES}) link_directories("${SOURCESDK_LIBDIRS}") link_libraries(tier0) -add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp" "VGuiMatSurface/IMatSystemSurface_c.cpp") +add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp" "VGuiMatSurface/IMatSystemSurface_c.cpp" "materialsystem/imaterialsystem_c.cpp") target_include_directories(sourcesdkc PUBLIC#SYSTEM INTERFACE #"${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/common" diff --git a/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp b/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp new file mode 100644 index 0000000..03bf299 --- /dev/null +++ b/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp @@ -0,0 +1,53 @@ +#include + + +DLL_EXPORT CreateInterfaceFn IMaterialSystem_Init(IMaterialSystem* m, char const* pShaderAPIDLL, IMaterialProxyFactory* pMaterialProxyFactory, CreateInterfaceFn fileSystemFactory, CreateInterfaceFn cvarFactory = NULL) { + return m->Init(pShaderAPIDLL, pMaterialProxyFactory, fileSystemFactory, cvarFactory); +} + +DLL_EXPORT void IMaterialSystem_SetShaderAPI(IMaterialSystem* m, char const* pShaderAPIDLL) { + m->SetShaderAPI(pShaderAPIDLL); +} +DLL_EXPORT void IMaterialSystem_SetAdapter(IMaterialSystem* m, int nAdapter, int nFlags) { + m->SetAdapter(nAdapter, nFlags); +} + +DLL_EXPORT void IMaterialSystem_ModInit(IMaterialSystem* m) { + m->ModInit(); +} +DLL_EXPORT void IMaterialSystem_ModShutdown(IMaterialSystem* m) { + m->ModShutdown(); +} + +DLL_EXPORT void IMaterialSystem_SetThreadMode(IMaterialSystem* m, MaterialThreadMode_t mode, int nServiceThread = -1) { + m->SetThreadMode(mode, nServiceThread); +} +DLL_EXPORT MaterialThreadMode_t IMaterialSystem_GetThreadMode(IMaterialSystem* m) { + return m->GetThreadMode(); +} +DLL_EXPORT bool IMaterialSystem_IsRenderThreadSafe(IMaterialSystem* m) { + return m->IsRenderThreadSafe(); +} +DLL_EXPORT void IMaterialSystem_ExecuteQueued(IMaterialSystem* m) { + m->ExecuteQueued(); +} +DLL_EXPORT void IMaterialSystem_OnDebugEvent(IMaterialSystem* m, const char* pEvent = "") { + m->OnDebugEvent(pEvent); +} + +DLL_EXPORT IMaterialSystemHardwareConfig* IMaterialSystem_GetHardwareConfig(IMaterialSystem* m, const char* pVersion, int* returnCode) { + return m->GetHardwareConfig(pVersion, returnCode); +} + +DLL_EXPORT bool IMaterialSystem_UpdateConfig(IMaterialSystem* m, bool bForceUpdate) { + return m->UpdateConfig(bForceUpdate); +} +DLL_EXPORT bool IMaterialSystem_OverrideConfig(IMaterialSystem* m, const MaterialSystem_Config_t& config, bool bForceUpdate) { + return m->OverrideConfig(config, bForceUpdate); +} +DLL_EXPORT const MaterialSystem_Config_t& IMaterialSystem_GetCurrentConfigForVideoCard(IMaterialSystem* m) { + return m->GetCurrentConfigForVideoCard(); +} +DLL_EXPORT bool GetRecommendedConfigurationInfo(IMaterialSystem* m, int nDXLevel, KeyValues* pKeyValues) { + return m->GetRecommendedConfigurationInfo(nDXLevel, pKeyValues); +} From 7d504fed580266caaaf4dd169c630acbe8bbcffe Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 8 May 2021 13:32:13 +0500 Subject: [PATCH 216/235] IMaterialSystem --- .../materialsystem/imaterialsystem_c.cpp | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp b/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp index 03bf299..e7962d8 100644 --- a/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp +++ b/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp @@ -48,6 +48,52 @@ DLL_EXPORT bool IMaterialSystem_OverrideConfig(IMaterialSystem* m, const Materia DLL_EXPORT const MaterialSystem_Config_t& IMaterialSystem_GetCurrentConfigForVideoCard(IMaterialSystem* m) { return m->GetCurrentConfigForVideoCard(); } -DLL_EXPORT bool GetRecommendedConfigurationInfo(IMaterialSystem* m, int nDXLevel, KeyValues* pKeyValues) { +DLL_EXPORT bool IMaterialSystem_GetRecommendedConfigurationInfo(IMaterialSystem* m, int nDXLevel, KeyValues* pKeyValues) { return m->GetRecommendedConfigurationInfo(nDXLevel, pKeyValues); } + +DLL_EXPORT int IMaterialSystem_GetDisplayAdapterCount(IMaterialSystem* m) { + return m->GetDisplayAdapterCount(); +} +DLL_EXPORT int IMaterialSystem_GetCurrentAdapter(IMaterialSystem* m) { + return m->GetCurrentAdapter(); +} +DLL_EXPORT void IMaterialSystem_GetDisplayAdapterInfo(IMaterialSystem* m, int adapter, MaterialAdapterInfo_t& info) { + m->GetDisplayAdapterInfo(adapter, info); +} +DLL_EXPORT int IMaterialSystem_GetModeCount(IMaterialSystem* m, int adapter) { + return m->GetModeCount(adapter); +} +DLL_EXPORT void IMaterialSystem_GetModeInfo(IMaterialSystem* m, int adapter, int mode, MaterialVideoMode_t& info) { + m->GetModeInfo(adapter, mode, info); +} +DLL_EXPORT void IMaterialSystem_AddModeChangeCallBack(IMaterialSystem* m, ModeChangeCallbackFunc_t func) { + m->AddModeChangeCallBack(func); +} +DLL_EXPORT void IMaterialSystem_GetDisplayMode(IMaterialSystem* m, MaterialVideoMode_t& mode) { + m->GetDisplayMode(mode); +} +DLL_EXPORT bool IMaterialSystem_SetMode(IMaterialSystem* m, void* hwnd, const MaterialSystem_Config_t& config) { + return m->SetMode(hwnd, config); +} +DLL_EXPORT bool IMaterialSystem_SupportsMSAAMode(IMaterialSystem* m, int nMSAAMode) { + return m->SupportsMSAAMode(nMSAAMode); +} +DLL_EXPORT const MaterialSystemHardwareIdentifier_t& IMaterialSystem_GetVideoCardIdentifier(IMaterialSystem* m) { + return m->GetVideoCardIdentifier(); +} +DLL_EXPORT void IMaterialSystem_SpewDriverInfo(IMaterialSystem* m) { + m->SpewDriverInfo(); +} +DLL_EXPORT void IMaterialSystem_GetBackBufferDimensions(IMaterialSystem* m, int& width, int& height){ + m->GetBackBufferDimensions(width, height); +} +DLL_EXPORT ImageFormat IMaterialSystem_GetBackBufferFormat(IMaterialSystem* m) { + return m->GetBackBufferFormat(); +} +DLL_EXPORT const AspectRatioInfo_t& IMaterialSystem_GetAspectRatioInfo(IMaterialSystem* m) { + return m->GetAspectRatioInfo(); +} +DLL_EXPORT bool IMaterialSystem_SupportsHDRMode(IMaterialSystem* m, HDRType_t nHDRModede) { + return m->SupportsHDRMode(nHDRModede); +} From 843013698e07641d827a95d7b463ee585ccea65d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 8 May 2021 13:53:39 +0500 Subject: [PATCH 217/235] inline improvements --- SourceSDK/public/vgui/isurface.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/SourceSDK/public/vgui/isurface.cs b/SourceSDK/public/vgui/isurface.cs index 81f4ca7..751cbcf 100644 --- a/SourceSDK/public/vgui/isurface.cs +++ b/SourceSDK/public/vgui/isurface.cs @@ -1,11 +1,13 @@ using GmodNET.SourceSDK.AppFramework; using GmodNET.SourceSDK.bitmap; using System; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace GmodNET.SourceSDK.vgui { [StructLayout(LayoutKind.Sequential)] + [BlittableType] public struct IntRect { public int x0; @@ -13,7 +15,7 @@ public struct IntRect public int x1; public int y1; }; - public class ISurface : IAppSystem + public partial class ISurface : IAppSystem { public const string VGUI_SURFACE_INTERFACE_VERSION = "VGUI_Surface030"; @@ -29,11 +31,14 @@ public ISurface(IntPtr ptr) : base(ptr) { } public void PushMakeCurrent(uint panel, bool useInsets) => Methods.ISurface_PushMakeCurrent(ptr, panel, useInsets); public void PopMakeCurrent(uint panel) => Methods.ISurface_PopMakeCurrent(ptr, panel); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void DrawSetColor(int r, int g, int b, int a) => Methods.ISurface_DrawSetColor(ptr, r, g, b, a); public void DrawSetColor(Color color) => Methods.ISurface_DrawSetColor(ptr, color); + [MethodImpl(MethodImplOptions.AggressiveInlining)] // guess why ;D public void DrawFilledRect(int x0, int y0, int x1, int y1) => Methods.ISurface_DrawFilledRect(ptr, x0, y0, x1, y1); public void DrawFilledRectArray(IntRect[] rects) => Methods.ISurface_DrawFilledRectArray(ptr, rects, rects.Length); + public void DrawFilledRectArray(IntRect[] rects, int numRects) => Methods.ISurface_DrawFilledRectArray(ptr, rects, numRects); public unsafe void DrawFilledRectArray(IntRect* rects, int numRects) => Methods.ISurface_DrawFilledRectArray(ptr, rects, numRects); public void DrawOutlinedRect(int x0, int y0, int x1, int y1) => Methods.ISurface_DrawOutlinedRect(ptr, x0, y0, x1, y1); @@ -42,7 +47,7 @@ public ISurface(IntPtr ptr) : base(ptr) { } public void DrawPolyLine(int[] px, int[] py) => Methods.ISurface_DrawPolyLine(ptr, px, py, Math.Min(px.Length, py.Length)); public unsafe void DrawPolyLine(int* px, int* py, int numPoints) => Methods.ISurface_DrawPolyLine(ptr, px, py, numPoints); - internal static class Methods + internal static partial class Methods { [DllImport("sourcesdkc")] internal static extern void ISurface_Shutdown(IntPtr ptr); @@ -55,8 +60,8 @@ internal static class Methods [DllImport("sourcesdkc")] internal static extern void ISurface_SetEmbeddedPanel(IntPtr ptr, uint panel); - [DllImport("sourcesdkc")] - internal static extern void ISurface_PushMakeCurrent(IntPtr ptr, uint panel, [MarshalAs(UnmanagedType.I1)] bool useInsets); + [GeneratedDllImport("sourcesdkc")] + internal static partial void ISurface_PushMakeCurrent(IntPtr ptr, uint panel, [MarshalAs(UnmanagedType.I1)] bool useInsets); [DllImport("sourcesdkc")] internal static extern void ISurface_PopMakeCurrent(IntPtr ptr, uint panel); @@ -67,8 +72,8 @@ internal static class Methods [DllImport("sourcesdkc")] internal static extern void ISurface_DrawFilledRect(IntPtr ptr, int x0, int y0, int x1, int y1); - [DllImport("sourcesdkc")] - internal static extern void ISurface_DrawFilledRectArray(IntPtr ptr, IntRect[] rects, int numRects); + [GeneratedDllImport("sourcesdkc")] + internal static partial void ISurface_DrawFilledRectArray(IntPtr ptr, IntRect[] rects, int numRects); [DllImport("sourcesdkc")] internal static unsafe extern void ISurface_DrawFilledRectArray(IntPtr ptr, IntRect* rects, int numRects); [DllImport("sourcesdkc")] @@ -76,8 +81,8 @@ internal static class Methods [DllImport("sourcesdkc")] internal static extern void ISurface_DrawLine(IntPtr ptr, int x0, int y0, int x1, int y1); - [DllImport("sourcesdkc")] - internal static unsafe extern void ISurface_DrawPolyLine(IntPtr ptr, int[] px, int[] py, int numPoints); + [GeneratedDllImport("sourcesdkc")] + internal static unsafe partial void ISurface_DrawPolyLine(IntPtr ptr, int[] px, int[] py, int numPoints); [DllImport("sourcesdkc")] internal static unsafe extern void ISurface_DrawPolyLine(IntPtr ptr, int* px, int* py, int numPoints); From fba4e22bbfeeebfb5c73c0ded3762a621bb3f290 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 8 May 2021 13:53:51 +0500 Subject: [PATCH 218/235] mark as BlittableType --- SourceSDK/public/Color.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SourceSDK/public/Color.cs b/SourceSDK/public/Color.cs index 00e3715..215797c 100644 --- a/SourceSDK/public/Color.cs +++ b/SourceSDK/public/Color.cs @@ -11,6 +11,7 @@ namespace GmodNET.SourceSDK /// /// "public/Color.h" /// + [BlittableType] public struct Color { /// From 24788059ef8d59883625de5642d6bb92f551ea8f Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 8 May 2021 14:09:02 +0500 Subject: [PATCH 219/235] IMaterialSystem --- .../public/materialsystem/imaterialsystemh.cs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 SourceSDK/public/materialsystem/imaterialsystemh.cs diff --git a/SourceSDK/public/materialsystem/imaterialsystemh.cs b/SourceSDK/public/materialsystem/imaterialsystemh.cs new file mode 100644 index 0000000..b3bd35a --- /dev/null +++ b/SourceSDK/public/materialsystem/imaterialsystemh.cs @@ -0,0 +1,48 @@ +using GmodNET.SourceSDK.Tier1; +using GmodNET.SourceSDK.vgui; +using System; +using System.Runtime.InteropServices; + +namespace GmodNET.SourceSDK.materialsystem +{ + public enum MaterialThreadMode_t + { + MATERIAL_SINGLE_THREADED, + MATERIAL_QUEUED_SINGLE_THREADED, + MATERIAL_QUEUED_THREADED + } + + public partial class IMaterialSystem : ISurface + { + public IMaterialSystem(IntPtr ptr) : base(ptr) { } + + new internal static partial class Methods + { + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMaterialSystem_Init(IntPtr m, [MarshalAs(UnmanagedType.LPUTF8Str)] string shaderAPIDLL, IntPtr materialProxyFactory, CreateInterfaceFn fileSystemFactory, CreateInterfaceFn cvarFactory = null); + + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMaterialSystem_SetShaderAPI(IntPtr m, [MarshalAs(UnmanagedType.LPUTF8Str)] string shaderAPIDLL); + + [DllImport("sourcesdkc")] + internal static extern void IMaterialSystem_SetAdapter(IntPtr m, int adapter, int flags); + + [DllImport("sourcesdkc")] + internal static extern void IMaterialSystem_ModInit(IntPtr m); + [DllImport("sourcesdkc")] + internal static extern void IMaterialSystem_ModShutdown(IntPtr m); + + [DllImport("sourcesdkc")] + internal static extern void IMaterialSystem_SetThreadMode(IntPtr m, MaterialThreadMode_t mode, int nServiceThread = -1); + [DllImport("sourcesdkc")] + internal static extern MaterialThreadMode_t IMaterialSystem_GetThreadMode(IntPtr m); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + internal static partial bool IMaterialSystem_IsRenderThreadSafe(IntPtr m); + [DllImport("sourcesdkc")] + internal static extern void IMaterialSystem_ExecuteQueued(IntPtr m); + [GeneratedDllImport("sourcesdkc")] + internal static partial void IMaterialSystem_OnDebugEvent(IntPtr m, [MarshalAs(UnmanagedType.LPUTF8Str)] string pEvent = ""); + } + } +} From 20a7d411347aa0c81e2eee370171e7ffd97386a6 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 8 May 2021 15:26:25 +0500 Subject: [PATCH 220/235] IMaterialSystem_GetHardwareConfig --- SourceSDK/public/materialsystem/imaterialsystemh.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SourceSDK/public/materialsystem/imaterialsystemh.cs b/SourceSDK/public/materialsystem/imaterialsystemh.cs index b3bd35a..4e1b6e1 100644 --- a/SourceSDK/public/materialsystem/imaterialsystemh.cs +++ b/SourceSDK/public/materialsystem/imaterialsystemh.cs @@ -43,6 +43,9 @@ public IMaterialSystem(IntPtr ptr) : base(ptr) { } internal static extern void IMaterialSystem_ExecuteQueued(IntPtr m); [GeneratedDllImport("sourcesdkc")] internal static partial void IMaterialSystem_OnDebugEvent(IntPtr m, [MarshalAs(UnmanagedType.LPUTF8Str)] string pEvent = ""); + + [GeneratedDllImport("sourcesdkc")] + internal static partial IntPtr IMaterialSystem_GetHardwareConfig(IntPtr m, [MarshalAs(UnmanagedType.LPUTF8Str)] string version, out int returnCode); } } } From df0fc4bc3d00f5903a1afaf691564bab66dd287d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 8 May 2021 22:40:53 +0500 Subject: [PATCH 221/235] IMaterialSystemHardwareConfig --- SourceSDK.CAPI/CMakeLists.txt | 2 +- .../imaterialsystemhardwareconfig_c.cpp | 242 +++++++++++++++ .../IMaterialSystemHardwareConfig.cs | 286 ++++++++++++++++++ 3 files changed, 529 insertions(+), 1 deletion(-) create mode 100644 SourceSDK.CAPI/materialsystem/imaterialsystemhardwareconfig_c.cpp create mode 100644 SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index ebb9c7f..b81c72d 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -49,7 +49,7 @@ add_compile_definitions(${SOURCESDK_DEFINES}) link_directories("${SOURCESDK_LIBDIRS}") link_libraries(tier0) -add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp" "VGuiMatSurface/IMatSystemSurface_c.cpp" "materialsystem/imaterialsystem_c.cpp") +add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp" "VGuiMatSurface/IMatSystemSurface_c.cpp" "materialsystem/imaterialsystem_c.cpp" "materialsystem/imaterialsystemhardwareconfig_c.cpp") target_include_directories(sourcesdkc PUBLIC#SYSTEM INTERFACE #"${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/common" diff --git a/SourceSDK.CAPI/materialsystem/imaterialsystemhardwareconfig_c.cpp b/SourceSDK.CAPI/materialsystem/imaterialsystemhardwareconfig_c.cpp new file mode 100644 index 0000000..106c905 --- /dev/null +++ b/SourceSDK.CAPI/materialsystem/imaterialsystemhardwareconfig_c.cpp @@ -0,0 +1,242 @@ +#include + +DLL_EXPORT int IMaterialSystemHardwareConfig_GetFrameBufferColorDepth(IMaterialSystemHardwareConfig* c) { + return c->GetFrameBufferColorDepth(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_GetSamplerCount(IMaterialSystemHardwareConfig* c) { + return c->GetSamplerCount(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsStaticControlFlow(IMaterialSystemHardwareConfig* c) { + return c->SupportsStaticControlFlow(); +} +DLL_EXPORT VertexCompressionType_t IMaterialSystemHardwareConfig_SupportsCompressedVertices(IMaterialSystemHardwareConfig* c) { + return c->SupportsCompressedVertices(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_MaximumAnisotropicLevel(IMaterialSystemHardwareConfig* c) { + return c->MaximumAnisotropicLevel(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_MaxTextureWidth(IMaterialSystemHardwareConfig* c) { + return c->MaxTextureWidth(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_MaxTextureHeight(IMaterialSystemHardwareConfig* c) { + return c->MaxTextureHeight(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_TextureMemorySize(IMaterialSystemHardwareConfig* c) { + return c->TextureMemorySize(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsMipmappedCubemaps(IMaterialSystemHardwareConfig* c) { + return c->SupportsMipmappedCubemaps(); +} + +DLL_EXPORT int IMaterialSystemHardwareConfig_NumVertexShaderConstants(IMaterialSystemHardwareConfig* c) { + return c->NumVertexShaderConstants(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_NumPixelShaderConstants(IMaterialSystemHardwareConfig* c) { + return c->NumPixelShaderConstants(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_MaxNumLights(IMaterialSystemHardwareConfig* c) { + return c->MaxNumLights(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_MaxTextureAspectRatio(IMaterialSystemHardwareConfig* c) { + return c->MaxTextureAspectRatio(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_MaxVertexShaderBlendMatrices(IMaterialSystemHardwareConfig* c) { + return c->MaxVertexShaderBlendMatrices(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_MaxUserClipPlanes(IMaterialSystemHardwareConfig* c) { + return c->MaxUserClipPlanes(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_UseFastClipping(IMaterialSystemHardwareConfig* c) { + return c->UseFastClipping(); +} + +DLL_EXPORT int IMaterialSystemHardwareConfig_GetDXSupportLevel(IMaterialSystemHardwareConfig* c) { + return c->GetDXSupportLevel(); +} +DLL_EXPORT const char* IMaterialSystemHardwareConfig_GetShaderDLLName(IMaterialSystemHardwareConfig* c) { + return c->GetShaderDLLName(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_ReadPixelsFromFrontBuffer(IMaterialSystemHardwareConfig* c) { + return c->ReadPixelsFromFrontBuffer(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_PreferDynamicTextures(IMaterialSystemHardwareConfig* c) { + return c->PreferDynamicTextures(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsHDR(IMaterialSystemHardwareConfig* c) { + return c->SupportsHDR(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_NeedsAAClamp(IMaterialSystemHardwareConfig* c) { + return c->NeedsAAClamp(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_NeedsATICentroidHack(IMaterialSystemHardwareConfig* c) { + return c->NeedsATICentroidHack(); +} + +DLL_EXPORT int IMaterialSystemHardwareConfig_GetMaxDXSupportLevel(IMaterialSystemHardwareConfig* c) { + return c->GetMaxDXSupportLevel(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_SpecifiesFogColorInLinearSpace(IMaterialSystemHardwareConfig* c) { + return c->SpecifiesFogColorInLinearSpace(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsSRGB(IMaterialSystemHardwareConfig* c) { + return c->SupportsSRGB(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_FakeSRGBWrite(IMaterialSystemHardwareConfig* c) { + return c->FakeSRGBWrite(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_CanDoSRGBReadFromRTs(IMaterialSystemHardwareConfig* c) { + return c->CanDoSRGBReadFromRTs(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsGLMixedSizeTargets(IMaterialSystemHardwareConfig* c) { + return c->SupportsGLMixedSizeTargets(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_IsAAEnabled(IMaterialSystemHardwareConfig* c) { + return c->IsAAEnabled(); +} + +DLL_EXPORT int IMaterialSystemHardwareConfig_GetVertexSamplerCount(IMaterialSystemHardwareConfig* c) { + return c->GetVertexSamplerCount(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_GetMaxVertexTextureDimension(IMaterialSystemHardwareConfig* c) { + return c->GetMaxVertexTextureDimension(); +} + +DLL_EXPORT int IMaterialSystemHardwareConfig_MaxTextureDepth(IMaterialSystemHardwareConfig* c) { + return c->MaxTextureDepth(); +} + +DLL_EXPORT HDRType_t IMaterialSystemHardwareConfig_GetHDRType(IMaterialSystemHardwareConfig* c) { + return c->GetHDRType(); +} +DLL_EXPORT HDRType_t IMaterialSystemHardwareConfig_GetHardwareHDRType(IMaterialSystemHardwareConfig* c) { + return c->GetHardwareHDRType(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsStreamOffset(IMaterialSystemHardwareConfig* c) { + return c->SupportsStreamOffset(); +} + +DLL_EXPORT int IMaterialSystemHardwareConfig_StencilBufferBits(IMaterialSystemHardwareConfig* c) { + return c->StencilBufferBits(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_MaxViewports(IMaterialSystemHardwareConfig* c) { + return c->MaxViewports(); +} + +DLL_EXPORT void IMaterialSystemHardwareConfig_OverrideStreamOffsetSupport(IMaterialSystemHardwareConfig* c, bool bOverrideEnabled, bool bEnableSupport) { + c->OverrideStreamOffsetSupport(bOverrideEnabled, bEnableSupport); +} + +DLL_EXPORT ShadowFilterMode_t IMaterialSystemHardwareConfig_GetShadowFilterMode(IMaterialSystemHardwareConfig* c, bool bForceLowQualityShadows, bool bPS30) { + return c->GetShadowFilterMode(bForceLowQualityShadows, bPS30); +} + +DLL_EXPORT int IMaterialSystemHardwareConfig_NeedsShaderSRGBConversion(IMaterialSystemHardwareConfig* c) { + return c->NeedsShaderSRGBConversion(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_UsesSRGBCorrectBlending(IMaterialSystemHardwareConfig* c) { + return c->UsesSRGBCorrectBlending(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_HasFastVertexTextures(IMaterialSystemHardwareConfig* c) { + return c->HasFastVertexTextures(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_MaxHWMorphBatchCount(IMaterialSystemHardwareConfig* c) { + return c->MaxHWMorphBatchCount(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_GetHDREnabled(IMaterialSystemHardwareConfig* c) { + return c->GetHDREnabled(); +} +DLL_EXPORT void IMaterialSystemHardwareConfig_SetHDREnabled(IMaterialSystemHardwareConfig* c, bool bEnable) { + c->SetHDREnabled(bEnable); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsBorderColor(IMaterialSystemHardwareConfig* c) { + return c->SupportsBorderColor(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsFetch4(IMaterialSystemHardwareConfig* c) { + return c->SupportsFetch4(); +} + +DLL_EXPORT float IMaterialSystemHardwareConfig_GetShadowDepthBias(IMaterialSystemHardwareConfig* c) { + return c->GetShadowDepthBias(); +} +DLL_EXPORT float IMaterialSystemHardwareConfig_GetShadowSlopeScaleDepthBias(IMaterialSystemHardwareConfig* c) { + return c->GetShadowSlopeScaleDepthBias(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_PreferZPrepass(IMaterialSystemHardwareConfig* c) { + return c->PreferZPrepass(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_SuppressPixelShaderCentroidHackFixup(IMaterialSystemHardwareConfig* c) { + return c->SuppressPixelShaderCentroidHackFixup(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_PreferTexturesInHWMemory(IMaterialSystemHardwareConfig* c) { + return c->PreferTexturesInHWMemory(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_PreferHardwareSync(IMaterialSystemHardwareConfig* c) { + return c->PreferHardwareSync(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_ActualHasFastVertexTextures(IMaterialSystemHardwareConfig* c) { + return c->ActualHasFastVertexTextures(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsShadowDepthTextures(IMaterialSystemHardwareConfig* c) { + return c->SupportsShadowDepthTextures(); +} +DLL_EXPORT ImageFormat IMaterialSystemHardwareConfig_GetShadowDepthTextureFormat(IMaterialSystemHardwareConfig* c) { + return c->GetShadowDepthTextureFormat(); +} +DLL_EXPORT ImageFormat IMaterialSystemHardwareConfig_GetHighPrecisionShadowDepthTextureFormat(IMaterialSystemHardwareConfig* c) { + return c->GetHighPrecisionShadowDepthTextureFormat(); +} +DLL_EXPORT ImageFormat IMaterialSystemHardwareConfig_GetNullTextureFormat(IMaterialSystemHardwareConfig* c) { + return c->GetNullTextureFormat(); +} +DLL_EXPORT int IMaterialSystemHardwareConfig_GetMinDXSupportLevel(IMaterialSystemHardwareConfig* c) { + return c->GetMinDXSupportLevel(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_IsUnsupported(IMaterialSystemHardwareConfig* c) { + return c->IsUnsupported(); +} + +DLL_EXPORT float IMaterialSystemHardwareConfig_GetLightMapScaleFactor(IMaterialSystemHardwareConfig* c) { + return c->GetLightMapScaleFactor(); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsCascadedShadowMapping(IMaterialSystemHardwareConfig* c) { + return c->SupportsCascadedShadowMapping(); +} +DLL_EXPORT CSMQualityMode_t IMaterialSystemHardwareConfig_GetCSMQuality(IMaterialSystemHardwareConfig* c) { + return c->GetCSMQuality(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsBilinearPCFSampling(IMaterialSystemHardwareConfig* c) { + return c->SupportsBilinearPCFSampling(); +} +DLL_EXPORT CSMShaderMode_t IMaterialSystemHardwareConfig_GetCSMShaderMode(IMaterialSystemHardwareConfig* c, CSMQualityMode_t nQualityLevel) { + return c->GetCSMShaderMode(nQualityLevel); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_GetCSMAccurateBlending(IMaterialSystemHardwareConfig* c) { + return c->GetCSMAccurateBlending(); +} +DLL_EXPORT void IMaterialSystemHardwareConfig_SetCSMAccurateBlending(IMaterialSystemHardwareConfig* c, bool bEnable) { + c->SetCSMAccurateBlending(bEnable); +} + +DLL_EXPORT bool IMaterialSystemHardwareConfig_SupportsResolveDepth(IMaterialSystemHardwareConfig* c) { + return c->SupportsResolveDepth(); +} +DLL_EXPORT bool IMaterialSystemHardwareConfig_HasFullResolutionDepthTexture(IMaterialSystemHardwareConfig* c) { + return c->HasFullResolutionDepthTexture(); +} diff --git a/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs new file mode 100644 index 0000000..d23d38d --- /dev/null +++ b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs @@ -0,0 +1,286 @@ +using GmodNET.SourceSDK.bitmap; +using System; +using System.Runtime.InteropServices; + +namespace GmodNET.SourceSDK.materialsystem +{ + public enum VertexCompressionType_t + { + // This indicates an uninitialized VertexCompressionType_t value + VERTEX_COMPRESSION_INVALID = unchecked((int)0xFFFFFFFF), + + // 'VERTEX_COMPRESSION_NONE' means that no elements of a vertex are compressed + VERTEX_COMPRESSION_NONE = 0, + + // Currently (more stuff may be added as needed), 'VERTEX_COMPRESSION_ON' means: + // - if a vertex contains VERTEX_ELEMENT_NORMAL, this is compressed + // (see CVertexBuilder::CompressedNormal3f) + // - if a vertex contains VERTEX_ELEMENT_USERDATA4 (and a normal - together defining a tangent + // frame, with the binormal reconstructed in the vertex shader), this is compressed + // (see CVertexBuilder::CompressedUserData) + // - if a vertex contains VERTEX_ELEMENT_BONEWEIGHTSx, this is compressed + // (see CVertexBuilder::CompressedBoneWeight3fv) + VERTEX_COMPRESSION_ON = 1 + } + public enum ShadowFilterMode_t + { + SHADOWFILTERMODE_DEFAULT = 0, + + NVIDIA_PCF = 0, + ATI_NO_PCF_FETCH4 = 1, + NVIDIA_PCF_CHEAP = 2, + ATI_NOPCF = 3, + + // Game consoles use a different set of combo indices to control shadow filtering. + GAMECONSOLE_NINE_TAP_PCF = 0, + GAMECONSOLE_SINGLE_TAP_PCF = 1, + + SHADOWFILTERMODE_FIRST_CHEAP_MODE = NVIDIA_PCF_CHEAP, + }; + public enum CSMQualityMode_t + { + CSMQUALITY_VERY_LOW, + CSMQUALITY_LOW, + CSMQUALITY_MEDIUM, + CSMQUALITY_HIGH, + + CSMQUALITY_TOTAL_MODES + }; + public enum CSMShaderMode_t + { + CSMSHADERMODE_LOW_OR_VERY_LOW = 0, + CSMSHADERMODE_MEDIUM = 1, + CSMSHADERMODE_HIGH = 2, + CSMSHADERMODE_ATIFETCH4 = 3, + + CSMSHADERMODE_TOTAL_MODES + }; + public enum HDRType_t + { + HDR_TYPE_NONE, + HDR_TYPE_INTEGER, + HDR_TYPE_FLOAT, + }; + public partial class IMaterialSystemHardwareConfig + { + private IntPtr c; + + public IMaterialSystemHardwareConfig(IntPtr ptr) + { + this.c = ptr; + } + + public int FrameBufferColorDepth => Methods.IMaterialSystemHardwareConfig_GetFrameBufferColorDepth(c); + public int SamplerCount => Methods.IMaterialSystemHardwareConfig_GetSamplerCount(c); + public bool SupportsStaticControlFlow => Methods.IMaterialSystemHardwareConfig_SupportsStaticControlFlow(c); + public VertexCompressionType_t SupportsCompressedVertices => Methods.IMaterialSystemHardwareConfig_SupportsCompressedVertices(c); + + private static partial class Methods + { + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_GetFrameBufferColorDepth(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_GetSamplerCount(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsStaticControlFlow(IntPtr c); + [DllImport("sourcesdkc")] + public static extern VertexCompressionType_t IMaterialSystemHardwareConfig_SupportsCompressedVertices(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_MaximumAnisotropicLevel(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_MaxTextureWidth(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_MaxTextureHeight(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_TextureMemorySize(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsMipmappedCubemaps(IntPtr c); + + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_NumVertexShaderConstants(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_NumPixelShaderConstants(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_MaxNumLights(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_MaxTextureAspectRatio(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_MaxVertexShaderBlendMatrices(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_MaxUserClipPlanes(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_UseFastClipping(IntPtr c); + + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_GetDXSupportLevel(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.LPUTF8Str)] + public static partial string IMaterialSystemHardwareConfig_GetShaderDLLName(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_ReadPixelsFromFrontBuffer(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_PreferDynamicTextures(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsHDR(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_NeedsAAClamp(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_NeedsATICentroidHack(IntPtr c); + + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_GetMaxDXSupportLevel(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SpecifiesFogColorInLinearSpace(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsSRGB(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_FakeSRGBWrite(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_CanDoSRGBReadFromRTs(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsGLMixedSizeTargets(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_IsAAEnabled(IntPtr c); + + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_GetVertexSamplerCount(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_GetMaxVertexTextureDimension(IntPtr c); + + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_MaxTextureDepth(IntPtr c); + + [DllImport("sourcesdkc")] + public static extern HDRType_t IMaterialSystemHardwareConfig_GetHDRType(IntPtr c); + [DllImport("sourcesdkc")] + public static extern HDRType_t IMaterialSystemHardwareConfig_GetHardwareHDRType(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsStreamOffset(IntPtr c); + + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_StencilBufferBits(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_MaxViewports(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + public static partial void IMaterialSystemHardwareConfig_OverrideStreamOffsetSupport(IntPtr c, [MarshalAs(UnmanagedType.I1)] bool overrideEnabled, [MarshalAs(UnmanagedType.I1)] bool enableSupport); + + [GeneratedDllImport("sourcesdkc")] + public static partial ShadowFilterMode_t IMaterialSystemHardwareConfig_GetShadowFilterMode(IntPtr c, [MarshalAs(UnmanagedType.I1)] bool forceLowQualityShadows, [MarshalAs(UnmanagedType.I1)] bool PS30); + + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_NeedsShaderSRGBConversion(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_UsesSRGBCorrectBlending(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_HasFastVertexTextures(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_MaxHWMorphBatchCount(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_GetHDREnabled(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + public static partial void IMaterialSystemHardwareConfig_SetHDREnabled(IntPtr c, [MarshalAs(UnmanagedType.I1)] bool enable); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsBorderColor(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsFetch4(IntPtr c); + + [DllImport("sourcesdkc")] + public static extern float IMaterialSystemHardwareConfig_GetShadowDepthBias(IntPtr c); + [DllImport("sourcesdkc")] + public static extern float IMaterialSystemHardwareConfig_GetShadowSlopeScaleDepthBias(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_PreferZPrepass(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SuppressPixelShaderCentroidHackFixup(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_PreferTexturesInHWMemory(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_PreferHardwareSync(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_ActualHasFastVertexTextures(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsShadowDepthTextures(IntPtr c); + + [DllImport("sourcesdkc")] + public static extern ImageFormat IMaterialSystemHardwareConfig_GetShadowDepthTextureFormat(IntPtr c); + [DllImport("sourcesdkc")] + public static extern ImageFormat IMaterialSystemHardwareConfig_GetHighPrecisionShadowDepthTextureFormat(IntPtr c); + [DllImport("sourcesdkc")] + public static extern ImageFormat IMaterialSystemHardwareConfig_GetNullTextureFormat(IntPtr c); + [DllImport("sourcesdkc")] + public static extern int IMaterialSystemHardwareConfig_GetMinDXSupportLevel(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_IsUnsupported(IntPtr c); + + [DllImport("sourcesdkc")] + public static extern float IMaterialSystemHardwareConfig_GetLightMapScaleFactor(IntPtr c); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsCascadedShadowMapping(IntPtr c); + [DllImport("sourcesdkc")] + public static extern CSMQualityMode_t IMaterialSystemHardwareConfig_GetCSMQuality(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsBilinearPCFSampling(IntPtr c); + [DllImport("sourcesdkc")] + public static extern CSMShaderMode_t IMaterialSystemHardwareConfig_GetCSMShaderMode(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_GetCSMAccurateBlending(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + public static partial void IMaterialSystemHardwareConfig_SetCSMAccurateBlending(IntPtr c, [MarshalAs(UnmanagedType.I1)] bool enable); + + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_SupportsResolveDepth(IntPtr c); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool IMaterialSystemHardwareConfig_HasFullResolutionDepthTexture(IntPtr c); + } + } +} From b966106377c032c2d79eb2809f6b51f1859255f5 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sat, 8 May 2021 22:43:14 +0500 Subject: [PATCH 222/235] simplify --- .../public/materialsystem/IMaterialSystemHardwareConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs index d23d38d..e299358 100644 --- a/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs +++ b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs @@ -67,7 +67,7 @@ public partial class IMaterialSystemHardwareConfig public IMaterialSystemHardwareConfig(IntPtr ptr) { - this.c = ptr; + c = ptr; } public int FrameBufferColorDepth => Methods.IMaterialSystemHardwareConfig_GetFrameBufferColorDepth(c); From 3b8ea7624af9beabfbb926968f3405840e750873 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 9 May 2021 12:50:26 +0500 Subject: [PATCH 223/235] IMaterialSystemHardwareConfig --- .../IMaterialSystemHardwareConfig.cs | 52 +++++++++++++++++++ .../public/materialsystem/imaterialsystemh.cs | 7 +++ 2 files changed, 59 insertions(+) diff --git a/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs index e299358..b0692fb 100644 --- a/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs +++ b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs @@ -74,6 +74,58 @@ public IMaterialSystemHardwareConfig(IntPtr ptr) public int SamplerCount => Methods.IMaterialSystemHardwareConfig_GetSamplerCount(c); public bool SupportsStaticControlFlow => Methods.IMaterialSystemHardwareConfig_SupportsStaticControlFlow(c); public VertexCompressionType_t SupportsCompressedVertices => Methods.IMaterialSystemHardwareConfig_SupportsCompressedVertices(c); + public int MaximumAnisotropicLevel => Methods.IMaterialSystemHardwareConfig_MaximumAnisotropicLevel(c); + public int MaxTextureWidth => Methods.IMaterialSystemHardwareConfig_MaxTextureWidth(c); + public int MaxTextureHeight => Methods.IMaterialSystemHardwareConfig_MaxTextureHeight(c); + public int TextureMemorySize => Methods.IMaterialSystemHardwareConfig_TextureMemorySize(c); + public bool SupportsMipmappedCubemaps => Methods.IMaterialSystemHardwareConfig_SupportsMipmappedCubemaps(c); + + public int NumVertexShaderConstants => Methods.IMaterialSystemHardwareConfig_NumVertexShaderConstants(c); + public int NumPixelShaderConstants => Methods.IMaterialSystemHardwareConfig_NumPixelShaderConstants(c); + public int MaxNumLights => Methods.IMaterialSystemHardwareConfig_MaxNumLights(c); + public int MaxTextureAspectRatio => Methods.IMaterialSystemHardwareConfig_MaxTextureAspectRatio(c); + public int MaxVertexShaderBlendMatrices => Methods.IMaterialSystemHardwareConfig_MaxVertexShaderBlendMatrices(c); + public int MaxUserClipPlanes => Methods.IMaterialSystemHardwareConfig_MaxUserClipPlanes(c); + public bool UseFastClipping => Methods.IMaterialSystemHardwareConfig_UseFastClipping(c); + + public int DXSupportLevel => Methods.IMaterialSystemHardwareConfig_GetDXSupportLevel(c); + public string ShaderDLLName => Methods.IMaterialSystemHardwareConfig_GetShaderDLLName(c); + + public bool ReadPixelsFromFrontBuffer => Methods.IMaterialSystemHardwareConfig_ReadPixelsFromFrontBuffer(c); + + public bool PreferDynamicTextures => Methods.IMaterialSystemHardwareConfig_PreferDynamicTextures(c); + + public bool SupportsHDR => Methods.IMaterialSystemHardwareConfig_SupportsHDR(c); + + public bool NeedsAAClamp => Methods.IMaterialSystemHardwareConfig_NeedsAAClamp(c); + public bool NeedsATICentroidHack => Methods.IMaterialSystemHardwareConfig_NeedsATICentroidHack(c); + + public int MaxDXSupportLevel => Methods.IMaterialSystemHardwareConfig_GetMaxDXSupportLevel(c); + + public bool SpecifiesFogColorInLinearSpace => Methods.IMaterialSystemHardwareConfig_SpecifiesFogColorInLinearSpace(c); + + public bool SupportsSRGB => Methods.IMaterialSystemHardwareConfig_SupportsSRGB(c); + public bool FakeSRGBWrite => Methods.IMaterialSystemHardwareConfig_FakeSRGBWrite(c); + public bool CanDoSRGBReadFromRTs => Methods.IMaterialSystemHardwareConfig_CanDoSRGBReadFromRTs(c); + + public bool SupportsGLMixedSizeTargets => Methods.IMaterialSystemHardwareConfig_SupportsGLMixedSizeTargets(c); + + public bool IsAAEnabled => Methods.IMaterialSystemHardwareConfig_IsAAEnabled(c); + + public int VertexSamplerCount => Methods.IMaterialSystemHardwareConfig_GetVertexSamplerCount(c); + public int MaxVertexTextureDimension => Methods.IMaterialSystemHardwareConfig_GetMaxVertexTextureDimension(c); + + public int MaxTextureDepth => Methods.IMaterialSystemHardwareConfig_MaxTextureDepth(c); + + public HDRType_t HDRType => Methods.IMaterialSystemHardwareConfig_GetHDRType(c); + public HDRType_t HardwareHDRType => Methods.IMaterialSystemHardwareConfig_GetHardwareHDRType(c); + + public bool SupportsStreamOffset => Methods.IMaterialSystemHardwareConfig_SupportsStreamOffset(c); + + public int StencilBufferBits => Methods.IMaterialSystemHardwareConfig_StencilBufferBits(c); + public int MaxViewports => Methods.IMaterialSystemHardwareConfig_MaxViewports(c); + + public void OverrideStreamOffsetSupport(bool overrideEnabled, bool enableSupport) => Methods.IMaterialSystemHardwareConfig_OverrideStreamOffsetSupport(c, overrideEnabled, enableSupport); private static partial class Methods { diff --git a/SourceSDK/public/materialsystem/imaterialsystemh.cs b/SourceSDK/public/materialsystem/imaterialsystemh.cs index 4e1b6e1..8e3f072 100644 --- a/SourceSDK/public/materialsystem/imaterialsystemh.cs +++ b/SourceSDK/public/materialsystem/imaterialsystemh.cs @@ -16,6 +16,13 @@ public partial class IMaterialSystem : ISurface { public IMaterialSystem(IntPtr ptr) : base(ptr) { } + + + + + public IMaterialSystemHardwareConfig GetHardwareConfig(string version, out int returnCode) => new(Methods.IMaterialSystem_GetHardwareConfig(ptr, version, out returnCode)); + + new internal static partial class Methods { [GeneratedDllImport("sourcesdkc")] From 5cbc83785b5736d85ae5ad0ccafc6f38b1cbb13d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 9 May 2021 13:13:49 +0500 Subject: [PATCH 224/235] IMaterialSystemHardwareConfig --- .../IMaterialSystemHardwareConfig.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs index b0692fb..df40c0f 100644 --- a/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs +++ b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs @@ -127,6 +127,57 @@ public IMaterialSystemHardwareConfig(IntPtr ptr) public void OverrideStreamOffsetSupport(bool overrideEnabled, bool enableSupport) => Methods.IMaterialSystemHardwareConfig_OverrideStreamOffsetSupport(c, overrideEnabled, enableSupport); + public ShadowFilterMode_t GetShadowFilterMode(bool forceLowQualityShadows, bool PS30) => Methods.IMaterialSystemHardwareConfig_GetShadowFilterMode(c, forceLowQualityShadows, PS30); + + public int NeedsShaderSRGBConversion => Methods.IMaterialSystemHardwareConfig_NeedsShaderSRGBConversion(c); + + public bool UsesSRGBCorrectBlending => Methods.IMaterialSystemHardwareConfig_UsesSRGBCorrectBlending(c); + + public bool HasFastVertexTextures => Methods.IMaterialSystemHardwareConfig_HasFastVertexTextures(c); + public int MaxHWMorphBatchCount => Methods.IMaterialSystemHardwareConfig_MaxHWMorphBatchCount(c); + + public bool HDREnabled + { + get => Methods.IMaterialSystemHardwareConfig_GetHDREnabled(c); + set => Methods.IMaterialSystemHardwareConfig_SetHDREnabled(c, value); + } + + public bool SupportsBorderColor => Methods.IMaterialSystemHardwareConfig_SupportsBorderColor(c); + public bool SupportsFetch4 => Methods.IMaterialSystemHardwareConfig_SupportsFetch4(c); + + public float ShadowDepthBias => Methods.IMaterialSystemHardwareConfig_GetShadowDepthBias(c); + public float ShadowSlopeScaleDepthBias => Methods.IMaterialSystemHardwareConfig_GetShadowSlopeScaleDepthBias(c); + + public bool PreferZPrepass => Methods.IMaterialSystemHardwareConfig_PreferZPrepass(c); + + public bool SuppressPixelShaderCentroidHackFixup => Methods.IMaterialSystemHardwareConfig_SuppressPixelShaderCentroidHackFixup(c); + public bool PreferTexturesInHWMemory => Methods.IMaterialSystemHardwareConfig_PreferTexturesInHWMemory(c); + public bool PreferHardwareSync => Methods.IMaterialSystemHardwareConfig_PreferHardwareSync(c); + public bool ActualHasFastVertexTextures => Methods.IMaterialSystemHardwareConfig_ActualHasFastVertexTextures(c); + + public bool SupportsShadowDepthTextures => Methods.IMaterialSystemHardwareConfig_SupportsShadowDepthTextures(c); + + public ImageFormat ShadowDepthTextureFormat => Methods.IMaterialSystemHardwareConfig_GetShadowDepthTextureFormat(c); + public ImageFormat HighPrecisionShadowDepthTextureFormat => Methods.IMaterialSystemHardwareConfig_GetHighPrecisionShadowDepthTextureFormat(c); + public ImageFormat NullTextureFormat => Methods.IMaterialSystemHardwareConfig_GetNullTextureFormat(c); + public int MinDXSupportLevel => Methods.IMaterialSystemHardwareConfig_GetMinDXSupportLevel(c); + public bool IsUnsupported => Methods.IMaterialSystemHardwareConfig_IsUnsupported(c); + + public float LightMapScaleFactor => Methods.IMaterialSystemHardwareConfig_GetLightMapScaleFactor(c); + + public bool SupportsCascadedShadowMapping => Methods.IMaterialSystemHardwareConfig_SupportsCascadedShadowMapping(c); + public CSMQualityMode_t CSMQuality => Methods.IMaterialSystemHardwareConfig_GetCSMQuality(c); + public bool SupportsBilinearPCFSampling => Methods.IMaterialSystemHardwareConfig_SupportsBilinearPCFSampling(c); + public CSMShaderMode_t CSMShaderMode => Methods.IMaterialSystemHardwareConfig_GetCSMShaderMode(c); + public bool CSMAccurateBlending + { + get => Methods.IMaterialSystemHardwareConfig_GetCSMAccurateBlending(c); + set => Methods.IMaterialSystemHardwareConfig_SetCSMAccurateBlending(c, value); + } + + public bool SupportsResolveDepth => Methods.IMaterialSystemHardwareConfig_SupportsResolveDepth(c); + public bool HasFullResolutionDepthTexture => Methods.IMaterialSystemHardwareConfig_HasFullResolutionDepthTexture(c); + private static partial class Methods { [DllImport("sourcesdkc")] From 3d9d986e255ada01a1fcd14de4ccd0c7cd629274 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 9 May 2021 13:24:48 +0500 Subject: [PATCH 225/235] IMaterialSystem --- SourceSDK/public/materialsystem/imaterialsystemh.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/SourceSDK/public/materialsystem/imaterialsystemh.cs b/SourceSDK/public/materialsystem/imaterialsystemh.cs index 8e3f072..1aa096b 100644 --- a/SourceSDK/public/materialsystem/imaterialsystemh.cs +++ b/SourceSDK/public/materialsystem/imaterialsystemh.cs @@ -16,12 +16,23 @@ public partial class IMaterialSystem : ISurface { public IMaterialSystem(IntPtr ptr) : base(ptr) { } + public void Init(string shaderAPIDLL, IntPtr materialProxyFactory, CreateInterfaceFn fileSystemFactory, CreateInterfaceFn cvarFactory = null) => Methods.IMaterialSystem_Init(ptr, shaderAPIDLL, materialProxyFactory, fileSystemFactory, cvarFactory); + public void SetShaderApi(string shaderApiDll) => Methods.IMaterialSystem_SetShaderAPI(ptr, shaderApiDll); + public void SetAdapter(int adapter, int flags) => Methods.IMaterialSystem_SetAdapter(ptr, adapter, flags); + public void ModInit() => Methods.IMaterialSystem_ModInit(ptr); + public void ModShutdown() => Methods.IMaterialSystem_ModShutdown(ptr); - public IMaterialSystemHardwareConfig GetHardwareConfig(string version, out int returnCode) => new(Methods.IMaterialSystem_GetHardwareConfig(ptr, version, out returnCode)); + public void SetThreadMode(MaterialThreadMode_t mode, int nServiceThread = -1) => Methods.IMaterialSystem_SetThreadMode(ptr, mode, nServiceThread); + public MaterialThreadMode_t GetThreadMode() => Methods.IMaterialSystem_GetThreadMode(ptr); + + public bool IsRenderThreadSafe => Methods.IMaterialSystem_IsRenderThreadSafe(ptr); + public void ExecuteQueued() => Methods.IMaterialSystem_ExecuteQueued(ptr); + public void OnDebugEvent(string pEvent = "") => Methods.IMaterialSystem_OnDebugEvent(ptr, pEvent); + public IMaterialSystemHardwareConfig GetHardwareConfig(string version, out int returnCode) => new(Methods.IMaterialSystem_GetHardwareConfig(ptr, version, out returnCode)); new internal static partial class Methods { From ec8565b0e7ccbc2ddbe6c0aba456adbf001c4887 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 9 May 2021 20:20:00 +0500 Subject: [PATCH 226/235] readonly, nullcheck --- .../public/materialsystem/IMaterialSystemHardwareConfig.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs index df40c0f..55ba48c 100644 --- a/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs +++ b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs @@ -63,10 +63,11 @@ public enum HDRType_t }; public partial class IMaterialSystemHardwareConfig { - private IntPtr c; + private readonly IntPtr c; public IMaterialSystemHardwareConfig(IntPtr ptr) { + if (ptr == IntPtr.Zero) throw new ArgumentNullException(nameof(ptr), "Passing invalid pointer will cause crash"); c = ptr; } From 03c519de1f09aff46b74bb6086ce0006e7382698 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Sun, 9 May 2021 22:14:55 +0500 Subject: [PATCH 227/235] ITexture & RenderTargets --- SourceSDK.CAPI/CMakeLists.txt | 2 +- .../materialsystem/imaterialsystem_c.cpp | 32 +++++++- SourceSDK.CAPI/materialsystem/itexture_c.cpp | 26 +++++++ SourceSDK/public/materialsystem/ITexture.cs | 49 ++++++++++++ .../public/materialsystem/imaterialsystemh.cs | 78 +++++++++++++++++++ SourceSDK/public/vtf/vtf_declarations_H.cs | 60 ++++++++++++++ 6 files changed, 245 insertions(+), 2 deletions(-) create mode 100644 SourceSDK.CAPI/materialsystem/itexture_c.cpp create mode 100644 SourceSDK/public/materialsystem/ITexture.cs create mode 100644 SourceSDK/public/vtf/vtf_declarations_H.cs diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt index b81c72d..120ca20 100644 --- a/SourceSDK.CAPI/CMakeLists.txt +++ b/SourceSDK.CAPI/CMakeLists.txt @@ -49,7 +49,7 @@ add_compile_definitions(${SOURCESDK_DEFINES}) link_directories("${SOURCESDK_LIBDIRS}") link_libraries(tier0) -add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp" "VGuiMatSurface/IMatSystemSurface_c.cpp" "materialsystem/imaterialsystem_c.cpp" "materialsystem/imaterialsystemhardwareconfig_c.cpp") +add_library (sourcesdkc MODULE "filesystem_c.cpp" "SourceSDK.CAPI.h" "iappsystem_c.cpp" "vgui/isurface_c.cpp" "VGuiMatSurface/IMatSystemSurface_c.cpp" "materialsystem/imaterialsystem_c.cpp" "materialsystem/imaterialsystemhardwareconfig_c.cpp" "materialsystem/itexture_c.cpp") target_include_directories(sourcesdkc PUBLIC#SYSTEM INTERFACE #"${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/common" diff --git a/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp b/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp index e7962d8..3af71d3 100644 --- a/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp +++ b/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp @@ -85,7 +85,7 @@ DLL_EXPORT const MaterialSystemHardwareIdentifier_t& IMaterialSystem_GetVideoCar DLL_EXPORT void IMaterialSystem_SpewDriverInfo(IMaterialSystem* m) { m->SpewDriverInfo(); } -DLL_EXPORT void IMaterialSystem_GetBackBufferDimensions(IMaterialSystem* m, int& width, int& height){ +DLL_EXPORT void IMaterialSystem_GetBackBufferDimensions(IMaterialSystem* m, int& width, int& height) { m->GetBackBufferDimensions(width, height); } DLL_EXPORT ImageFormat IMaterialSystem_GetBackBufferFormat(IMaterialSystem* m) { @@ -97,3 +97,33 @@ DLL_EXPORT const AspectRatioInfo_t& IMaterialSystem_GetAspectRatioInfo(IMaterial DLL_EXPORT bool IMaterialSystem_SupportsHDRMode(IMaterialSystem* m, HDRType_t nHDRModede) { return m->SupportsHDRMode(nHDRModede); } + + + + + + + + + + + +DLL_EXPORT void IMaterialSystem_BeginRenderTargetAllocation(IMaterialSystem* m) { + m->BeginRenderTargetAllocation(); +} +DLL_EXPORT void IMaterialSystem_EndRenderTargetAllocation(IMaterialSystem* m) { + m->EndRenderTargetAllocation(); +} + +DLL_EXPORT ITexture* IMaterialSystem_CreateRenderTargetTexture(IMaterialSystem* m, int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth) { + return m->CreateRenderTargetTexture(w, h, sizeMode, format, depth); +} +DLL_EXPORT ITexture* IMaterialSystem_CreateNamedRenderTargetTextureEx(IMaterialSystem* m, const char* pRTName, int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth, unsigned int textureFlags, unsigned int renderTargetFlags) { + return m->CreateNamedRenderTargetTextureEx(pRTName, w, h, sizeMode, format, depth, textureFlags, renderTargetFlags); +} +DLL_EXPORT ITexture* IMaterialSystem_CreateNamedRenderTargetTexture(IMaterialSystem* m, const char* pRTName, int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth, bool bClampTexCoords, bool bAutoMipMap) { + return m->CreateNamedRenderTargetTexture(pRTName, w, h, sizeMode, format, depth, bClampTexCoords, bAutoMipMap); +} +DLL_EXPORT ITexture* IMaterialSystem_CreateNamedRenderTargetTextureEx2(IMaterialSystem* m, const char* pRTName, int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth, unsigned int textureFlags, unsigned int renderTargetFlags) { + return m->CreateNamedRenderTargetTextureEx2(pRTName, w, h, sizeMode, format, depth, textureFlags, renderTargetFlags); +} diff --git a/SourceSDK.CAPI/materialsystem/itexture_c.cpp b/SourceSDK.CAPI/materialsystem/itexture_c.cpp new file mode 100644 index 0000000..763b4d7 --- /dev/null +++ b/SourceSDK.CAPI/materialsystem/itexture_c.cpp @@ -0,0 +1,26 @@ +#include + +DLL_EXPORT const char* ITexture_GetName(ITexture* t) { + return t->GetName(); +} +DLL_EXPORT int ITexture_GetMappingWidth(ITexture* t) { + return t->GetMappingWidth(); +} +DLL_EXPORT int ITexture_GetMappingHeight(ITexture* t) { + return t->GetMappingHeight(); +} +DLL_EXPORT int ITexture_GetActualWidth(ITexture* t) { + return t->GetActualWidth(); +} +DLL_EXPORT int ITexture_GetActualHeight(ITexture* t) { + return t->GetActualHeight(); +} +DLL_EXPORT int ITexture_GetNumAnimationFrames(ITexture* t) { + return t->GetNumAnimationFrames(); +} +DLL_EXPORT bool ITexture_IsTranslucent(ITexture* t) { + return t->IsTranslucent(); +} +DLL_EXPORT bool ITexture_IsMipmapped(ITexture* t) { + return t->IsMipmapped(); +} diff --git a/SourceSDK/public/materialsystem/ITexture.cs b/SourceSDK/public/materialsystem/ITexture.cs new file mode 100644 index 0000000..45ac902 --- /dev/null +++ b/SourceSDK/public/materialsystem/ITexture.cs @@ -0,0 +1,49 @@ +using System; +using System.Runtime.InteropServices; + +namespace GmodNET.SourceSDK.materialsystem +{ + public partial class ITexture + { + private readonly IntPtr t; + + public ITexture(IntPtr ptr) + { + if (ptr == IntPtr.Zero) throw new ArgumentNullException(nameof(ptr), "Passing invalid pointer will cause crash"); + + t = ptr; + } + + public string Name => Methods.ITexture_GetName(t); + public int MappingWidth => Methods.ITexture_GetMappingWidth(t); + public int MappingHeight => Methods.ITexture_GetMappingHeight(t); + public int ActualWidth => Methods.ITexture_GetActualWidth(t); + public int ActualHeight => Methods.ITexture_GetActualHeight(t); + public int NumAnimationFrames => Methods.ITexture_GetNumAnimationFrames(t); + public bool IsTranslucent => Methods.ITexture_IsTranslucent(t); + public bool IsMipmapped => Methods.ITexture_IsMipmapped(t); + + private static partial class Methods + { + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.LPUTF8Str)] + public static partial string ITexture_GetName(IntPtr t); + [DllImport("sourcesdkc")] + public static extern int ITexture_GetMappingWidth(IntPtr t); + [DllImport("sourcesdkc")] + public static extern int ITexture_GetMappingHeight(IntPtr t); + [DllImport("sourcesdkc")] + public static extern int ITexture_GetActualWidth(IntPtr t); + [DllImport("sourcesdkc")] + public static extern int ITexture_GetActualHeight(IntPtr t); + [DllImport("sourcesdkc")] + public static extern int ITexture_GetNumAnimationFrames(IntPtr t); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool ITexture_IsTranslucent(IntPtr t); + [GeneratedDllImport("sourcesdkc")] + [return: MarshalAs(UnmanagedType.I1)] + public static partial bool ITexture_IsMipmapped(IntPtr t); + } + } +} diff --git a/SourceSDK/public/materialsystem/imaterialsystemh.cs b/SourceSDK/public/materialsystem/imaterialsystemh.cs index 1aa096b..f616746 100644 --- a/SourceSDK/public/materialsystem/imaterialsystemh.cs +++ b/SourceSDK/public/materialsystem/imaterialsystemh.cs @@ -1,5 +1,7 @@ +using GmodNET.SourceSDK.bitmap; using GmodNET.SourceSDK.Tier1; using GmodNET.SourceSDK.vgui; +using GmodNET.SourceSDK.vtf; using System; using System.Runtime.InteropServices; @@ -11,6 +13,38 @@ public enum MaterialThreadMode_t MATERIAL_QUEUED_SINGLE_THREADED, MATERIAL_QUEUED_THREADED } + public enum MaterialRenderTargetDepth_t + { + MATERIAL_RT_DEPTH_SHARED = 0x0, + MATERIAL_RT_DEPTH_SEPARATE = 0x1, + MATERIAL_RT_DEPTH_NONE = 0x2, + MATERIAL_RT_DEPTH_ONLY = 0x3, + } + public enum RenderTargetSizeMode_t + { + RT_SIZE_NO_CHANGE = 0, // Only allowed for render targets that don't want a depth buffer + // (because if they have a depth buffer, the render target must be less than or equal to the size of the framebuffer). + RT_SIZE_DEFAULT = 1, // Don't play with the specified width and height other than making sure it fits in the framebuffer. + RT_SIZE_PICMIP = 2, // Apply picmip to the render target's width and height. + RT_SIZE_HDR = 3, // frame_buffer_width / 4 + RT_SIZE_FULL_FRAME_BUFFER = 4, // Same size as frame buffer, or next lower power of 2 if we can't do that. + RT_SIZE_OFFSCREEN = 5, // Target of specified size, don't mess with dimensions + RT_SIZE_FULL_FRAME_BUFFER_ROUNDED_UP = 6 // Same size as the frame buffer, rounded up if necessary for systems that can't do non-power of two textures. + } + /// + /// CREATERENDERTARGETFLAGS_ defines + /// + public enum CREATERENDERTARGETFLAGS: uint + { + HDR = 0x00000001, + AUTOMIPMAP = 0x00000002, + UNFILTERABLE_OK = 0x00000004, + + // XBOX ONLY + // NOEDRAM = 0x00000008, + // TEMP = 0x00000010, + // ALIASCOLORANDDEPTHSURFACES = 0x00000020 + } public partial class IMaterialSystem : ISurface { @@ -34,6 +68,26 @@ public IMaterialSystem(IntPtr ptr) : base(ptr) { } public IMaterialSystemHardwareConfig GetHardwareConfig(string version, out int returnCode) => new(Methods.IMaterialSystem_GetHardwareConfig(ptr, version, out returnCode)); + + + + + + + + + + + public void BeginRenderTargetAllocation() => Methods.IMaterialSystem_BeginRenderTargetAllocation(ptr); + public void EndRenderTargetAllocation() => Methods.IMaterialSystem_EndRenderTargetAllocation(ptr); + + public ITexture CreateRenderTargetTexture(int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth = MaterialRenderTargetDepth_t.MATERIAL_RT_DEPTH_SHARED) => new(Methods.IMaterialSystem_CreateRenderTargetTexture(ptr, w, h, sizeMode, format, depth)); + public ITexture CreateNamedRenderTargetTextureEx(string RTName, int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth = MaterialRenderTargetDepth_t.MATERIAL_RT_DEPTH_SHARED, CompiledVtfFlags textureFlags = CompiledVtfFlags.TEXTUREFLAGS_CLAMPS | CompiledVtfFlags.TEXTUREFLAGS_CLAMPT, CREATERENDERTARGETFLAGS renderTargetFlags = 0) => new(Methods.IMaterialSystem_CreateNamedRenderTargetTextureEx(ptr, RTName, w, h, sizeMode, format, depth, textureFlags, renderTargetFlags)); + public ITexture CreateNamedRenderTargetTexture(string RTName, int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth = MaterialRenderTargetDepth_t.MATERIAL_RT_DEPTH_SHARED, bool clampTexCoords = true, bool autoMipmap = false) => new(Methods.IMaterialSystem_CreateNamedRenderTargetTexture(ptr, RTName, w, h, sizeMode, format, depth, clampTexCoords, autoMipmap)); + public ITexture CreateNamedRenderTargetTextureEx2(string RTName, int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth = MaterialRenderTargetDepth_t.MATERIAL_RT_DEPTH_SHARED, CompiledVtfFlags textureFlags = CompiledVtfFlags.TEXTUREFLAGS_CLAMPS | CompiledVtfFlags.TEXTUREFLAGS_CLAMPT, CREATERENDERTARGETFLAGS renderTargetFlags = 0) => new(Methods.IMaterialSystem_CreateNamedRenderTargetTextureEx2(ptr, RTName, w, h, sizeMode, format, depth, textureFlags, renderTargetFlags)); + + + new internal static partial class Methods { [GeneratedDllImport("sourcesdkc")] @@ -64,6 +118,30 @@ public IMaterialSystem(IntPtr ptr) : base(ptr) { } [GeneratedDllImport("sourcesdkc")] internal static partial IntPtr IMaterialSystem_GetHardwareConfig(IntPtr m, [MarshalAs(UnmanagedType.LPUTF8Str)] string version, out int returnCode); + + + + + + + + + + + + [DllImport("sourcesdkc")] + internal static extern void IMaterialSystem_BeginRenderTargetAllocation(IntPtr m); + [DllImport("sourcesdkc")] + internal static extern void IMaterialSystem_EndRenderTargetAllocation(IntPtr m); + + [DllImport("sourcesdkc")] + internal static extern IntPtr IMaterialSystem_CreateRenderTargetTexture(IntPtr m, int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth = MaterialRenderTargetDepth_t.MATERIAL_RT_DEPTH_SHARED); + [GeneratedDllImport("sourcesdkc")] + internal static partial IntPtr IMaterialSystem_CreateNamedRenderTargetTextureEx(IntPtr m, [MarshalAs(UnmanagedType.LPUTF8Str)] string pRTName, int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth, CompiledVtfFlags textureFlags = CompiledVtfFlags.TEXTUREFLAGS_CLAMPS | CompiledVtfFlags.TEXTUREFLAGS_CLAMPT, CREATERENDERTARGETFLAGS renderTargetFlags = 0); + [GeneratedDllImport("sourcesdkc")] + internal static partial IntPtr IMaterialSystem_CreateNamedRenderTargetTexture(IntPtr m, [MarshalAs(UnmanagedType.LPUTF8Str)] string pRTName, int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth, [MarshalAs(UnmanagedType.I1)] bool bClampTexCoords, [MarshalAs(UnmanagedType.I1)] bool bAutoMipMap); + [GeneratedDllImport("sourcesdkc")] + internal static partial IntPtr IMaterialSystem_CreateNamedRenderTargetTextureEx2(IntPtr m, [MarshalAs(UnmanagedType.LPUTF8Str)] string pRTName, int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat format, MaterialRenderTargetDepth_t depth, CompiledVtfFlags textureFlags, CREATERENDERTARGETFLAGS renderTargetFlags); } } } diff --git a/SourceSDK/public/vtf/vtf_declarations_H.cs b/SourceSDK/public/vtf/vtf_declarations_H.cs new file mode 100644 index 0000000..22821fe --- /dev/null +++ b/SourceSDK/public/vtf/vtf_declarations_H.cs @@ -0,0 +1,60 @@ +namespace GmodNET.SourceSDK.vtf +{ + public enum CompiledVtfFlags: uint + { + // Flags from the *.txt config file + TEXTUREFLAGS_POINTSAMPLE = 0x00000001, + TEXTUREFLAGS_TRILINEAR = 0x00000002, + TEXTUREFLAGS_CLAMPS = 0x00000004, + TEXTUREFLAGS_CLAMPT = 0x00000008, + TEXTUREFLAGS_ANISOTROPIC = 0x00000010, + TEXTUREFLAGS_HINT_DXT5 = 0x00000020, + TEXTUREFLAGS_PWL_CORRECTED = 0x00000040, + TEXTUREFLAGS_NORMAL = 0x00000080, + TEXTUREFLAGS_NOMIP = 0x00000100, + TEXTUREFLAGS_NOLOD = 0x00000200, + TEXTUREFLAGS_ALL_MIPS = 0x00000400, + TEXTUREFLAGS_PROCEDURAL = 0x00000800, + + // These are automatically generated by vtex from the texture data. + TEXTUREFLAGS_ONEBITALPHA = 0x00001000, + TEXTUREFLAGS_EIGHTBITALPHA = 0x00002000, + + // Newer flags from the *.txt config file + TEXTUREFLAGS_ENVMAP = 0x00004000, + TEXTUREFLAGS_RENDERTARGET = 0x00008000, + TEXTUREFLAGS_DEPTHRENDERTARGET = 0x00010000, + TEXTUREFLAGS_NODEBUGOVERRIDE = 0x00020000, + TEXTUREFLAGS_SINGLECOPY = 0x00040000, + + TEXTUREFLAGS_SRGB = 0x00080000, //SRGB correction has already been applied to this texture. + + TEXTUREFLAGS_DEFAULT_POOL = 0x00100000, // Nvidia Stereo Change: Water (Force a texture to the default pool) + + TEXTUREFLAGS_COMBINED = 0x00200000, + + TEXTUREFLAGS_ASYNC_DOWNLOAD = 0x00400000, + + TEXTUREFLAGS_NODEPTHBUFFER = 0x00800000, + + TEXTUREFLAGS_SKIP_INITIAL_DOWNLOAD = 0x01000000, // Skip initial download when creating a procedural texture + + TEXTUREFLAGS_CLAMPU = 0x02000000, + TEXTUREFLAGS_VERTEXTEXTURE = 0x04000000, // Usable as a vertex texture + TEXTUREFLAGS_SSBUMP = 0x08000000, + + TEXTUREFLAGS_MOST_MIPS = 0x10000000, // Don't load the bottom few mips at runtime + + TEXTUREFLAGS_BORDER = 0x20000000, // Clamp to border color on all texture coordinates + + // PS3 extensions + TEXTUREFLAGS_QUINCUNX = 0x40000000, + TEXTUREFLAGS_QUINCUNX_ALT = 0x80000000, + // XBOX 360 + TEXTUREFLAGS_ALIAS_COLOR_AND_DEPTH_SURFACES = 0x40000000, + TEXTUREFLAGS_UNUSED_80000000 = 0x80000000, + // PC + TEXTUREFLAGS_UNUSED_40000000 = 0x40000000, + // TEXTUREFLAGS_UNUSED_80000000 = unchecked((int)0x80000000), + } +} From 37430299255511bf98a3ef1cc81773fefd8b710d Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 10 May 2021 10:56:45 +0500 Subject: [PATCH 228/235] GetRenderTargetExampleModule --- .../GetRenderTargetExample.csproj | 12 + .../GetRenderTargetExampleModule.cs | 210 ++++++++++++++++++ SourceSDK.Test/SourceSDK.Test.csproj | 4 +- SourceSDK.sln | 6 + .../public/materialsystem/imaterialsystemh.cs | 2 + SourceSDK/public/vgui/isurface.cs | 2 +- 6 files changed, 233 insertions(+), 3 deletions(-) create mode 100644 GetRenderTargetExample/GetRenderTargetExample.csproj create mode 100644 GetRenderTargetExample/GetRenderTargetExampleModule.cs diff --git a/GetRenderTargetExample/GetRenderTargetExample.csproj b/GetRenderTargetExample/GetRenderTargetExample.csproj new file mode 100644 index 0000000..00c7493 --- /dev/null +++ b/GetRenderTargetExample/GetRenderTargetExample.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + + + + + + + + diff --git a/GetRenderTargetExample/GetRenderTargetExampleModule.cs b/GetRenderTargetExample/GetRenderTargetExampleModule.cs new file mode 100644 index 0000000..3796e92 --- /dev/null +++ b/GetRenderTargetExample/GetRenderTargetExampleModule.cs @@ -0,0 +1,210 @@ +using GmodNET.API; +using GmodNET.SourceSDK.materialsystem; +using GmodNET.SourceSDK.Tier1; +using GmodNET.SourceSDK.vgui; +using System; +using System.Runtime.InteropServices; + +namespace GetRenderTargetExample +{ + public class GetRenderTargetExampleModule : IModule + { + string IModule.ModuleName => "GetRenderTargetExample"; + + string IModule.ModuleVersion => "1.0.0"; + + private ISurface surface; + private IMaterialSystem materialSystem; + + private IntPtr sourcesdkc = IntPtr.Zero; + + private IntPtr rt; + + void IModule.Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) + { + if (is_serverside) throw new Exception("Must be loaded from client"); + + string platformIdentifier = OperatingSystem.IsWindows() ? "win-x64" : "linux-x64"; + assembly_context.SetCustomNativeLibraryResolver((ctx, str) => + { + if (str.Contains("sourcesdkc")) + { + if (sourcesdkc == IntPtr.Zero) + { + 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; + }); + + if (interfaceh.Sys_LoadInterface("vguimatsurface", ISurface.VGUI_SURFACE_INTERFACE_VERSION, out _, out IntPtr isurfacePtr)) + surface = new(isurfacePtr); + else + throw new Exception("failed loading vguimatsurface"); + + if (interfaceh.Sys_LoadInterface("materialsystem", IMaterialSystem.MATERIAL_SYSTEM_INTERFACE_VERSION, out _, out IntPtr materialSystemPtr)) + materialSystem = new(materialSystemPtr); + else + Console.WriteLine("failed loading materialsystem"); + + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "GetRenderTarget"); + lua.PushString("ExampleRTwithAlpha"); + lua.PushNumber(512); + lua.PushNumber(512); + lua.MCall(3, 1); + rt = lua.GetUserType(-1, (int)TYPES.TEXTURE); + lua.Pop(); + + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "hook"); + lua.GetField(-1, "Add"); + lua.PushString("HUDPaint"); + lua.PushString("ExampleRTwithAlpha_Render"); + lua.PushManagedFunction(Render); + lua.MCall(3, 0); + lua.Pop(); + } + + public int Render(ILua lua) + { + //render.PushRenderTarget(textureRT) + //cam.Start2D() + // render.Clear(0, 0, 0, 0) + + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "CurTime"); + lua.MCall(0, 1); + int CurTime = (int)lua.GetNumber(1); + lua.Pop(); + + // PushRenderTarget + { + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "render"); + lua.GetField(-1, "PushRenderTarget"); + lua.PushUserType(rt, (int)TYPES.TEXTURE); + lua.MCall(1, 0); + lua.Pop(); + } + + // Start 2D + { + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "cam"); + lua.GetField(-1, "Start2D"); + lua.MCall(0, 0); + lua.Pop(); + } + + // Clear + { + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "render"); + lua.GetField(-1, "Clear"); + lua.PushNumber(0); + lua.PushNumber(0); + lua.PushNumber(0); + lua.PushNumber(0); + lua.MCall(4, 0); + lua.Pop(); + } + // Draw Rects + { + if (surface is not null) + { + surface.DrawSetColor(255, 255, 255, 255); + surface.DrawFilledRect(20, (100 + (((int)Math.Sin(CurTime)) * 50)), 50, 50); + surface.DrawSetColor(255, 0, 0, 100); + surface.DrawFilledRect(120, (100 + (((int)Math.Sin(CurTime)) * 50)), 50, 50); + } + else + { + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "surface"); + lua.GetField(-1, "SetDrawColor"); + lua.PushNumber(255); + lua.PushNumber(255); + lua.PushNumber(255); + lua.PushNumber(255); + lua.MCall(4, 0); + lua.Pop(2); + + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "surface"); + lua.GetField(-1, "DrawRect"); + lua.PushNumber(20); + lua.PushNumber((100 + (((int)Math.Sin(CurTime)) * 50))); + lua.PushNumber(50); + lua.PushNumber(50); + lua.MCall(4, 0); + lua.Pop(2); + + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "surface"); + lua.GetField(-1, "SetDrawColor"); + lua.PushNumber(255); + lua.PushNumber(0); + lua.PushNumber(0); + lua.PushNumber(100); + lua.MCall(4, 0); + lua.Pop(2); + + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "surface"); + lua.GetField(-1, "DrawRect"); + lua.PushNumber(120); + lua.PushNumber((100 + (((int)Math.Sin(CurTime)) * 50))); + lua.PushNumber(50); + lua.PushNumber(50); + lua.MCall(4, 0); + lua.Pop(2); + } + } + + // End2D + { + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "cam"); + lua.GetField(-1, "End2D"); + lua.MCall(0, 0); + lua.Pop(); + } + + // Pop + { + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "render"); + lua.GetField(-1, "PopRenderTarget"); + lua.MCall(0, 0); + lua.Pop(); + } + + // Draw it on screen + { + if(surface is not null) + { + surface.DrawSetColor(255, 255, 255, 255); + } + else + { + + } + } + + return 0; + } + + void IModule.Unload(ILua lua) + { + surface = null; + materialSystem = null; + + if (sourcesdkc != IntPtr.Zero) + NativeLibrary.Free(sourcesdkc); + } + } +} diff --git a/SourceSDK.Test/SourceSDK.Test.csproj b/SourceSDK.Test/SourceSDK.Test.csproj index a85bf19..1877d8d 100644 --- a/SourceSDK.Test/SourceSDK.Test.csproj +++ b/SourceSDK.Test/SourceSDK.Test.csproj @@ -5,9 +5,9 @@ true - + - + diff --git a/SourceSDK.sln b/SourceSDK.sln index bae1298..586f60d 100644 --- a/SourceSDK.sln +++ b/SourceSDK.sln @@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceSDK.Test", "SourceSDK.Test\SourceSDK.Test.csproj", "{FA6CC35B-83AD-4FA7-9BFD-B77A6DAE735B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetRenderTargetExample", "GetRenderTargetExample\GetRenderTargetExample.csproj", "{CD6A20A3-6DFC-4F3B-B6CF-F4DD31B6F802}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -30,6 +32,10 @@ Global {FA6CC35B-83AD-4FA7-9BFD-B77A6DAE735B}.Debug|Any CPU.Build.0 = Debug|Any CPU {FA6CC35B-83AD-4FA7-9BFD-B77A6DAE735B}.Release|Any CPU.ActiveCfg = Release|Any CPU {FA6CC35B-83AD-4FA7-9BFD-B77A6DAE735B}.Release|Any CPU.Build.0 = Release|Any CPU + {CD6A20A3-6DFC-4F3B-B6CF-F4DD31B6F802}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD6A20A3-6DFC-4F3B-B6CF-F4DD31B6F802}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD6A20A3-6DFC-4F3B-B6CF-F4DD31B6F802}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD6A20A3-6DFC-4F3B-B6CF-F4DD31B6F802}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SourceSDK/public/materialsystem/imaterialsystemh.cs b/SourceSDK/public/materialsystem/imaterialsystemh.cs index f616746..9e8c0a3 100644 --- a/SourceSDK/public/materialsystem/imaterialsystemh.cs +++ b/SourceSDK/public/materialsystem/imaterialsystemh.cs @@ -48,6 +48,8 @@ public enum CREATERENDERTARGETFLAGS: uint public partial class IMaterialSystem : ISurface { + public const string MATERIAL_SYSTEM_INTERFACE_VERSION = "VMaterialSystem080"; + public IMaterialSystem(IntPtr ptr) : base(ptr) { } public void Init(string shaderAPIDLL, IntPtr materialProxyFactory, CreateInterfaceFn fileSystemFactory, CreateInterfaceFn cvarFactory = null) => Methods.IMaterialSystem_Init(ptr, shaderAPIDLL, materialProxyFactory, fileSystemFactory, cvarFactory); diff --git a/SourceSDK/public/vgui/isurface.cs b/SourceSDK/public/vgui/isurface.cs index 751cbcf..a8172d9 100644 --- a/SourceSDK/public/vgui/isurface.cs +++ b/SourceSDK/public/vgui/isurface.cs @@ -32,7 +32,7 @@ public ISurface(IntPtr ptr) : base(ptr) { } public void PopMakeCurrent(uint panel) => Methods.ISurface_PopMakeCurrent(ptr, panel); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void DrawSetColor(int r, int g, int b, int a) => Methods.ISurface_DrawSetColor(ptr, r, g, b, a); + public void DrawSetColor(int r, int g, int b, int a = 255) => Methods.ISurface_DrawSetColor(ptr, r, g, b, a); public void DrawSetColor(Color color) => Methods.ISurface_DrawSetColor(ptr, color); [MethodImpl(MethodImplOptions.AggressiveInlining)] // guess why ;D From a69ac8bbc2a8505629e52b92317ea68ff809d26e Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 10 May 2021 11:21:23 +0500 Subject: [PATCH 229/235] update --- .../GetRenderTargetExampleModule.cs | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/GetRenderTargetExample/GetRenderTargetExampleModule.cs b/GetRenderTargetExample/GetRenderTargetExampleModule.cs index 3796e92..b6e95b7 100644 --- a/GetRenderTargetExample/GetRenderTargetExampleModule.cs +++ b/GetRenderTargetExample/GetRenderTargetExampleModule.cs @@ -19,6 +19,7 @@ public class GetRenderTargetExampleModule : IModule private IntPtr sourcesdkc = IntPtr.Zero; private IntPtr rt; + private IntPtr mat; void IModule.Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context) { @@ -59,6 +60,24 @@ void IModule.Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assemb rt = lua.GetUserType(-1, (int)TYPES.TEXTURE); lua.Pop(); + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "CreateMaterial"); + lua.PushString("ExampleRTwithAlpha_Mat"); + lua.PushString("UnlitGeneric"); + lua.CreateTable(); + { + lua.PushString("$basetexture"); + lua.PushString("ExampleRTwithAlpha"); + lua.SetTable(-4); + + lua.PushString("$translucent"); + lua.PushString("1"); + lua.SetTable(-4); + } + lua.MCall(3, 1); + mat = lua.GetUserType(-1, (int)TYPES.MATERIAL); + lua.Pop(); + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); lua.GetField(-1, "hook"); lua.GetField(-1, "Add"); @@ -191,8 +210,33 @@ public int Render(ILua lua) } else { - + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "surface"); + lua.GetField(-1, "SetDrawColor"); + lua.PushNumber(255); + lua.PushNumber(255); + lua.PushNumber(255); + lua.PushNumber(255); + lua.MCall(4, 0); + lua.Pop(); } + + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "surface"); + lua.GetField(-1, "SetMaterial"); + lua.PushUserType(mat, (int)TYPES.MATERIAL); + lua.MCall(1, 0); + lua.Pop(); + + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "surface"); + lua.GetField(-1, "DrawTexturedRect"); + lua.PushNumber(50); + lua.PushNumber(50); + lua.PushNumber(512); + lua.PushNumber(512); + lua.MCall(4, 0); + lua.Pop(); } return 0; From e610d24ee4ec487962296ba5d7925bc1d1b1bb9e Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 10 May 2021 11:30:16 +0500 Subject: [PATCH 230/235] Public Internal pointer --- SourceSDK/public/appframework/iappsystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs index f75a78c..1f8898d 100644 --- a/SourceSDK/public/appframework/iappsystem.cs +++ b/SourceSDK/public/appframework/iappsystem.cs @@ -37,7 +37,7 @@ public enum AppSystemTier_t public abstract class IAppSystem { - protected readonly IntPtr ptr; + public readonly IntPtr ptr; public IAppSystem(IntPtr ptr) { From 2d13c1e1e6caf1313646b662914ec530c75e6372 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 10 May 2021 11:31:00 +0500 Subject: [PATCH 231/235] ISurface.DrawTexturedRect --- SourceSDK.CAPI/vgui/isurface_c.cpp | 3 +++ SourceSDK/public/vgui/isurface.cs | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/SourceSDK.CAPI/vgui/isurface_c.cpp b/SourceSDK.CAPI/vgui/isurface_c.cpp index e7428dc..beda512 100644 --- a/SourceSDK.CAPI/vgui/isurface_c.cpp +++ b/SourceSDK.CAPI/vgui/isurface_c.cpp @@ -51,4 +51,7 @@ DLL_EXPORT void ISurface_DrawSetTextureRGBAex(void** ptr, int id, const unsigned surf->DrawSetTextureRGBAEx(id, rgba, wide, tall, imageFormat); } +DLL_EXPORT void ISurface_DrawTexturedRect(vgui::ISurface* s, int x0, int y0, int x1, int y1) { + s->DrawTexturedRect(x0, y0, x1, y1); +} diff --git a/SourceSDK/public/vgui/isurface.cs b/SourceSDK/public/vgui/isurface.cs index a8172d9..277451b 100644 --- a/SourceSDK/public/vgui/isurface.cs +++ b/SourceSDK/public/vgui/isurface.cs @@ -47,6 +47,12 @@ public ISurface(IntPtr ptr) : base(ptr) { } public void DrawPolyLine(int[] px, int[] py) => Methods.ISurface_DrawPolyLine(ptr, px, py, Math.Min(px.Length, py.Length)); public unsafe void DrawPolyLine(int* px, int* py, int numPoints) => Methods.ISurface_DrawPolyLine(ptr, px, py, numPoints); + + + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void DrawTexturedRect(int x0, int y0, int x1, int y1) => Methods.ISurface_DrawTexturedRect(ptr, x0, y0, x1, y1); + internal static partial class Methods { [DllImport("sourcesdkc")] @@ -88,6 +94,9 @@ internal static partial class Methods [DllImport("sourcesdkc")] internal static extern void ISurface_DrawSetTextureRGBAex(IntPtr ptr, int id, IntPtr rgba, int wide, int tall, ImageFormat imageFormat); + + [DllImport("sourcesdkc")] + internal static extern void ISurface_DrawTexturedRect(IntPtr s, int x0, int y0, int x1, int y1); } } } From 79e2ceee296fc8a8d978c8afdb03e5af24373ec5 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 10 May 2021 11:32:35 +0500 Subject: [PATCH 232/235] use sourcesdk's DrawTexturedRect --- .../GetRenderTargetExampleModule.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/GetRenderTargetExample/GetRenderTargetExampleModule.cs b/GetRenderTargetExample/GetRenderTargetExampleModule.cs index b6e95b7..a46fec7 100644 --- a/GetRenderTargetExample/GetRenderTargetExampleModule.cs +++ b/GetRenderTargetExample/GetRenderTargetExampleModule.cs @@ -204,7 +204,7 @@ public int Render(ILua lua) // Draw it on screen { - if(surface is not null) + if (surface is not null) { surface.DrawSetColor(255, 255, 255, 255); } @@ -228,15 +228,22 @@ public int Render(ILua lua) lua.MCall(1, 0); lua.Pop(); - lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); - lua.GetField(-1, "surface"); - lua.GetField(-1, "DrawTexturedRect"); - lua.PushNumber(50); - lua.PushNumber(50); - lua.PushNumber(512); - lua.PushNumber(512); - lua.MCall(4, 0); - lua.Pop(); + if (surface is not null) + { + surface.DrawTexturedRect(50, 50, 512, 512); + } + else + { + lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); + lua.GetField(-1, "surface"); + lua.GetField(-1, "DrawTexturedRect"); + lua.PushNumber(50); + lua.PushNumber(50); + lua.PushNumber(512); + lua.PushNumber(512); + lua.MCall(4, 0); + lua.Pop(); + } } return 0; From 945d7d6cdf39e8848dd52db0a8ceb73ee5c9d1c9 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 10 May 2021 12:21:06 +0500 Subject: [PATCH 233/235] fix table --- GetRenderTargetExample/GetRenderTargetExampleModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GetRenderTargetExample/GetRenderTargetExampleModule.cs b/GetRenderTargetExample/GetRenderTargetExampleModule.cs index a46fec7..c794da8 100644 --- a/GetRenderTargetExample/GetRenderTargetExampleModule.cs +++ b/GetRenderTargetExample/GetRenderTargetExampleModule.cs @@ -68,11 +68,11 @@ void IModule.Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assemb { lua.PushString("$basetexture"); lua.PushString("ExampleRTwithAlpha"); - lua.SetTable(-4); + lua.SetTable(-3); lua.PushString("$translucent"); lua.PushString("1"); - lua.SetTable(-4); + lua.SetTable(-3); } lua.MCall(3, 1); mat = lua.GetUserType(-1, (int)TYPES.MATERIAL); From 55ea4c51f4ed297850f7f2e8a06f56868c05989c Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 10 May 2021 12:30:10 +0500 Subject: [PATCH 234/235] fix sourcesdkc resolver --- GetRenderTargetExample/GetRenderTargetExampleModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GetRenderTargetExample/GetRenderTargetExampleModule.cs b/GetRenderTargetExample/GetRenderTargetExampleModule.cs index c794da8..61ef031 100644 --- a/GetRenderTargetExample/GetRenderTargetExampleModule.cs +++ b/GetRenderTargetExample/GetRenderTargetExampleModule.cs @@ -33,7 +33,7 @@ void IModule.Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assemb if (sourcesdkc == IntPtr.Zero) { Console.WriteLine("loading sourcesdkc"); - sourcesdkc = NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc"); + sourcesdkc = NativeLibrary.Load($"./garrysmod/lua/bin/Modules/GetRenderTargetExample/runtimes/{platformIdentifier}/native/sourcesdkc"); Console.WriteLine($"loaded sourcesdkc: {sourcesdkc != IntPtr.Zero}"); } return sourcesdkc; From 497408a3e2448c9cf279eea70f18b8fd7110e5f5 Mon Sep 17 00:00:00 2001 From: SupinePandora43 Date: Mon, 10 May 2021 13:20:54 +0500 Subject: [PATCH 235/235] fix CurTime --- GetRenderTargetExample/GetRenderTargetExampleModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GetRenderTargetExample/GetRenderTargetExampleModule.cs b/GetRenderTargetExample/GetRenderTargetExampleModule.cs index 61ef031..545f7c2 100644 --- a/GetRenderTargetExample/GetRenderTargetExampleModule.cs +++ b/GetRenderTargetExample/GetRenderTargetExampleModule.cs @@ -97,7 +97,7 @@ public int Render(ILua lua) lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB); lua.GetField(-1, "CurTime"); lua.MCall(0, 1); - int CurTime = (int)lua.GetNumber(1); + int CurTime = (int)lua.GetNumber(-1); lua.Pop(); // PushRenderTarget