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/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..4c76c7f
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,196 @@
+name: Build & Test
+on:
+ push:
+ branches: [ '*' ]
+ pull_request:
+ branches: [ main ]
+jobs:
+ linux-cmake-build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ with:
+ submodules: recursive
+ - 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: linux-x64
+ path: "out/SourceSDK.CAPI/libsourcesdkc.so"
+ retention-days: 1
+ if-no-files-found: error
+ windows-cmake-build:
+ runs-on: windows-latest
+ steps:
+ - uses: actions/checkout@v2
+ with:
+ submodules: recursive
+ - uses: ilammy/msvc-dev-cmd@v1
+ - name: 'CMake'
+ uses: lukka/run-cmake@v2
+ with:
+ cmakeListsOrSettingsJson: CMakeSettingsJson
+ cmakeBuildType: Release
+ buildDirectory: '${{ github.workspace }}/out'
+ - name: Upload Artifact
+ uses: actions/upload-artifact@v2
+ with:
+ name: win-x64
+ path: "out/x64-Release/SourceSDK.CAPI/sourcesdkc.dll"
+ retention-days: 1
+ 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
+ Build:
+ needs: [ linux-cmake-build, windows-cmake-build ]
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - 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:
+ 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 --configuration Release
+ - name: Pack
+ run: dotnet pack SourceSDK.sln --configuration Release
+ - name: Upload nuget package
+ uses: actions/upload-artifact@v2
+ with:
+ name: sourcesdk
+ path: SourceSDK/bin/Release/*.nupkg
+ retention-days: 90
+ 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: Download SteamCMD
+ 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: 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
+ run: |
+ 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
+ - name: Download SourceSDKTest
+ uses: actions/download-artifact@v2
+ with:
+ name: sourcesdktest
+ path: ./gmod/garrysmod/lua/bin/Modules/SourceSDKTest/
+ - run: tree
+ - 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 +developer 1 +exec "server.cfg" +gamemode sandbox +map gm_construct +maxplayers 2 +sv_hibernate_think 1 || true
+ working-directory: ./gmod/
+ timeout-minutes: 5
+ 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
+ Test-windows:
+ needs: Build
+ runs-on: windows-latest
+ steps:
+ - uses: actions/checkout@v2
+ - name: Download SteamCMD
+ 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: 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
+ - 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.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
+ uses: actions/download-artifact@v2
+ with:
+ name: 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
+ shell: bash
+ run: |
+ 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: 3
+ - 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
diff --git a/.github/workflows/test.lua b/.github/workflows/test.lua
new file mode 100644
index 0000000..e9d0d2e
--- /dev/null
+++ b/.github/workflows/test.lua
@@ -0,0 +1,18 @@
+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
+
+run_test()
+print("tests are successful!")
+file.Write("success.txt", "done")
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c2cbdf3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+.vs
+bin
+obj
+out
+*.dll
+*.so
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/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": ""
+ }
+ ]
+}
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..545f7c2
--- /dev/null
+++ b/GetRenderTargetExample/GetRenderTargetExampleModule.cs
@@ -0,0 +1,261 @@
+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;
+ private IntPtr mat;
+
+ 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/GetRenderTargetExample/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, "CreateMaterial");
+ lua.PushString("ExampleRTwithAlpha_Mat");
+ lua.PushString("UnlitGeneric");
+ lua.CreateTable();
+ {
+ lua.PushString("$basetexture");
+ lua.PushString("ExampleRTwithAlpha");
+ lua.SetTable(-3);
+
+ lua.PushString("$translucent");
+ lua.PushString("1");
+ lua.SetTable(-3);
+ }
+ 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");
+ 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
+ {
+ 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();
+
+ 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;
+ }
+
+ void IModule.Unload(ILua lua)
+ {
+ surface = null;
+ materialSystem = null;
+
+ if (sourcesdkc != IntPtr.Zero)
+ NativeLibrary.Free(sourcesdkc);
+ }
+ }
+}
diff --git a/SourceSDK.CAPI/CMakeLists.txt b/SourceSDK.CAPI/CMakeLists.txt
new file mode 100644
index 0000000..120ca20
--- /dev/null
+++ b/SourceSDK.CAPI/CMakeLists.txt
@@ -0,0 +1,59 @@
+cmake_minimum_required (VERSION 3.8)
+
+project("sourcesdkc" CXX)
+set (CMAKE_CXX_STANDARD 11)
+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(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(APPLE)
+ list(APPEND SOURCESDK_DEFINES
+ "_DLL_EXT=.dylib"
+ "POSIX"
+ "_POSIX"
+ "OSX"
+ "_OSX"
+ "_DARWIN_UNLIMITED_SELECT"
+ "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)
+ list(APPEND SOURCESDK_DEFINES
+ "_DLL_EXT=.so"
+ "POSIX"
+ "_POSIX"
+ "LINUX"
+ "_LINUX"
+ "SWDS"
+ "DX_TO_GL_ABSTRACTION"
+ )
+ set(SOURCESDK_LIBDIRS "${CMAKE_CURRENT_SOURCE_DIR}/gmod_sdk/sourcesdk-minimal/lib/public/linux64")
+endif()
+
+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" "materialsystem/itexture_c.cpp")
+
+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.h b/SourceSDK.CAPI/SourceSDK.CAPI.h
new file mode 100644
index 0000000..0582251
--- /dev/null
+++ b/SourceSDK.CAPI/SourceSDK.CAPI.h
@@ -0,0 +1,14 @@
+#ifndef SourceSDK_CAPI_H
+#define SourceSDK_CAPI_H
+
+#ifdef WIN32
+#pragma once
+#endif
+
+#ifdef WIN32
+#define DllExport extern "C" __declspec( dllexport )
+#else
+#define DllExport extern "C" __attribute__ ((dllexport))
+#endif
+
+#endif
diff --git a/SourceSDK.CAPI/VGuiMatSurface/IMatSystemSurface_c.cpp b/SourceSDK.CAPI/VGuiMatSurface/IMatSystemSurface_c.cpp
new file mode 100644
index 0000000..5ad1c27
--- /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);
+}
+
+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.CAPI/filesystem_c.cpp b/SourceSDK.CAPI/filesystem_c.cpp
new file mode 100644
index 0000000..5a377f9
--- /dev/null
+++ b/SourceSDK.CAPI/filesystem_c.cpp
@@ -0,0 +1,164 @@
+#include
+
+#pragma region IBaseFileSystem
+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(IBaseFileSystem* bfs, void const* pInput, int size, FileHandle_t file) {
+ return bfs->Write(pInput, size, file);
+}
+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(IBaseFileSystem* bfs, FileHandle_t file) {
+ bfs->Close(file);
+}
+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(IBaseFileSystem* bfs, FileHandle_t file) {
+ return bfs->Tell(file);
+}
+DLL_EXPORT unsigned int IBaseFileSystem_Size(IBaseFileSystem* bfs, FileHandle_t file) {
+ return bfs->Size(file);
+}
+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(IBaseFileSystem* bfs, FileHandle_t file) {
+ bfs->Flush(file);
+}
+DLL_EXPORT bool IBaseFileSystem_Precache(IBaseFileSystem* bfs, const char* pFileName, const char* pPathID = 0) {
+ return bfs->Precache(pFileName, pPathID);
+}
+DLL_EXPORT bool IBaseFileSystem_FileExists(IBaseFileSystem* bfs, const char* pFileName, const char* pPathID = 0) {
+ return bfs->FileExists(pFileName, pPathID);
+}
+DLL_EXPORT bool IBaseFileSystem_IsFileWritable(IBaseFileSystem* bfs, const char* pFileName, const char* pPathID = 0) {
+ return bfs->IsFileWritable(pFileName, pPathID);
+}
+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(IBaseFileSystem* bfs, const char* pFileName, const char* pPathID = 0) {
+ return bfs->GetFileTime(pFileName, pPathID);
+}
+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(IBaseFileSystem* bfs, const char* pFileName, const char* pPath, CUtlBuffer& buf) {
+ return bfs->WriteFile(pFileName, pPath, buf);
+}
+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(IFileSystem* fs) {
+ return fs->IsSteam();
+}
+
+DLL_EXPORT FilesystemMountRetval_t IFileSystem_MountSteamContent(IFileSystem* fs, int nExtraAppId = -1) {
+ return fs->MountSteamContent(nExtraAppId);
+}
+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(IFileSystem* fs, const char* pPath, const char* pathID = 0) {
+ return fs->RemoveSearchPath(pPath, pathID);
+}
+DLL_EXPORT void IFileSystem_RemoveAllSearchPaths(IFileSystem* fs) {
+ fs->RemoveAllSearchPaths();
+}
+DLL_EXPORT void IFileSystem_RemoveSearchPaths(IFileSystem* fs, const char* szPathID) {
+ fs->RemoveSearchPaths(szPathID);
+}
+
+DLL_EXPORT void IFileSystem_MarkPathIDByRequestOnly(IFileSystem* fs, const char* pPathID, bool bRequestOnly) {
+ fs->MarkPathIDByRequestOnly(pPathID, bRequestOnly);
+}
+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(IFileSystem* fs, const char* pathID, bool bGetPackFiles, char* pDest, int maxLenInChars) {
+ return fs->GetSearchPath(pathID, bGetPackFiles, pDest, maxLenInChars);
+}
+DLL_EXPORT bool IFileSystem_AddPackFile(IFileSystem* fs, const char* fullpath, const char* pathID) {
+ return fs->AddPackFile(fullpath, pathID);
+}
+
+DLL_EXPORT void IFileSystem_RemoveFile(IFileSystem* fs, char const* pRelativePath, const char* pathID = 0) {
+ fs->RemoveFile(pRelativePath, pathID);
+}
+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(IFileSystem* fs, const char* path, const char* pathID = 0) {
+ fs->CreateDirHierarchy(path, pathID);
+}
+DLL_EXPORT bool IFileSystem_IsDirectory(IFileSystem* fs, const char* pFileName, const char* pathID = 0) {
+ return fs->IsDirectory(pFileName, pathID);
+}
+DLL_EXPORT void IFileSystem_FileTimeToString(IFileSystem* fs, char* pStrip, int maxCharsIncludingTerminator, long fileTime) {
+ fs->FileTimeToString(pStrip, maxCharsIncludingTerminator, fileTime);
+}
+
+DLL_EXPORT void IFileSystem_SetBufferSize(IFileSystem* fs, FileHandle_t file, unsigned int nBytes) {
+ fs->SetBufferSize(file, nBytes);
+}
+DLL_EXPORT bool IFileSystem_IsOk(IFileSystem* fs, FileHandle_t file) {
+ return fs->IsOk(file);
+}
+DLL_EXPORT bool IFileSystem_EndOfFile(IFileSystem* fs, FileHandle_t file) {
+ return fs->EndOfFile(file);
+}
+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(IFileSystem* fs, FileHandle_t file, const char* pFormat, const char* pMsg = nullptr) {
+ return fs->FPrintf(file, pFormat, pMsg);
+}
+
+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(IFileSystem* fs, CSysModule* pModule) {
+ fs->UnloadModule(pModule);
+}
+
+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(IFileSystem* fs, FileFindHandle_t Handle) {
+ return fs->FindNext(Handle);
+}
+DLL_EXPORT bool IFileSystem_FindIsDirectory(IFileSystem* fs, FileFindHandle_t Handle) {
+ return fs->FindIsDirectory(Handle);
+}
+DLL_EXPORT void IFileSystem_FindClose(IFileSystem* fs, FileFindHandle_t Handle) {
+ fs->FindClose(Handle);
+}
+DLL_EXPORT const char* IFileSystem_FindFirstEx(IFileSystem* fs, const char* pWildCard, const char* pPathID, FileFindHandle_t* pHandle) {
+ 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/gmod_sdk b/SourceSDK.CAPI/gmod_sdk
new file mode 160000
index 0000000..6ca2122
--- /dev/null
+++ b/SourceSDK.CAPI/gmod_sdk
@@ -0,0 +1 @@
+Subproject commit 6ca212226e143d39bdd0c637b7b80adb6cab99b3
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.CAPI/materialsystem/imaterialsystem_c.cpp b/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp
new file mode 100644
index 0000000..3af71d3
--- /dev/null
+++ b/SourceSDK.CAPI/materialsystem/imaterialsystem_c.cpp
@@ -0,0 +1,129 @@
+#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 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);
+}
+
+
+
+
+
+
+
+
+
+
+
+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/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.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.CAPI/vgui/isurface_c.cpp b/SourceSDK.CAPI/vgui/isurface_c.cpp
new file mode 100644
index 0000000..beda512
--- /dev/null
+++ b/SourceSDK.CAPI/vgui/isurface_c.cpp
@@ -0,0 +1,57 @@
+#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);
+}
+DLL_EXPORT void ISurface_DrawSetColor_COLOR(vgui::ISurface* surf, Color color) {
+ surf->DrawSetColor(color);
+}
+
+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;
+ 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.Test/SourceSDK.Test.csproj b/SourceSDK.Test/SourceSDK.Test.csproj
new file mode 100644
index 0000000..1877d8d
--- /dev/null
+++ b/SourceSDK.Test/SourceSDK.Test.csproj
@@ -0,0 +1,13 @@
+
+
+ net5
+ SourceSDKTest
+ true
+
+
+
+
+
+
+
+
diff --git a/SourceSDK.Test/TestModule.cs b/SourceSDK.Test/TestModule.cs
new file mode 100644
index 0000000..05c8e2a
--- /dev/null
+++ b/SourceSDK.Test/TestModule.cs
@@ -0,0 +1,212 @@
+using GmodNET.API;
+using GmodNET.SourceSDK;
+using GmodNET.SourceSDK.Tier0;
+using GmodNET.SourceSDK.Tier1;
+using GmodNET.SourceSDK.vgui;
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace SourceSDKTest
+{
+ public class TestModule : IModule
+ {
+ public string ModuleName => "SourceSDKTest";
+
+ public string ModuleVersion => "0.0.1";
+
+ private bool failed = false;
+
+ private IntPtr sourcesdkc = IntPtr.Zero;
+
+ internal void Test(Action action)
+ {
+ try
+ {
+ action();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+ failed = true;
+ }
+ }
+
+ 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;
+ }
+
+ private GCHandle handle;
+
+ public void Load(ILua lua, bool is_serverside, ModuleAssemblyLoadContext assembly_context)
+ {
+ string platformIdentifier = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "win-x64" : "linux-x64";
+ assembly_context.SetCustomNativeLibraryResolver((ctx, str) =>
+ {
+ if (str.Contains("sourcesdkc"))
+ {
+ Console.WriteLine("loading sourcesdkc");
+ sourcesdkc = NativeLibrary.Load($"./garrysmod/lua/bin/Modules/SourceSDKTest/runtimes/{platformIdentifier}/native/sourcesdkc");
+ Console.WriteLine($"loaded sourcesdkc: {sourcesdkc != IntPtr.Zero}");
+ return sourcesdkc;
+ }
+ return IntPtr.Zero;
+ });
+
+ Test(() => Dbg.Msg("Msg(string)\n"));
+
+ Test(() => Dbg.Warning("Warning(string)\n"));
+
+ Test(() => Dbg.Warning_SpewCallStack(100, "Warning_SpewCallStack(int, string)\n"));
+
+ Test(() => Dbg.DevMsg("DevMsg(string)\n"));
+ Test(() => Dbg.DevWarning("DevWarning(string)\n"));
+
+ Test(() => Dbg.ConColorMsg(new Color(255, 255, 0), "ConColorMsg(in Color, string)\n"));
+
+ Test(() => Dbg.ConMsg("ConMsg(string)\n"));
+ Test(() => Dbg.ConDMsg("ConDMsg(string)\n"));
+
+ // Test(() => Dbg.COM_TimestampedLog("COM_TimestampedLog(format = %s)", "COM_TimestampedLog"));
+
+ Test(() =>
+ {
+ unsafe
+ {
+ string path = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "filesystem_stdio.dll" : "filesystem_stdio.so";
+
+ if (!interfaceh.Sys_LoadInterface(path, FileSystem.FILESYSTEM_INTERFACE_VERSION, out IntPtr module, out IntPtr fSPtr))
+ {
+ Console.WriteLine("failed loading FS");
+ }
+ if (!interfaceh.Sys_LoadInterface(path, BaseFileSystem.BASEFILESYSTEM_INTERFACE_VERSION, out module, out IntPtr baseFSPtr))
+ {
+ Console.WriteLine("failed loading BFS");
+ }
+
+ if (fSPtr == IntPtr.Zero || baseFSPtr == IntPtr.Zero)
+ {
+ Console.WriteLine("unloading it");
+ NativeLibrary.Free(module);
+ Console.WriteLine("unloaded ???");
+ return;
+ }
+
+ FileSystem fileSystem = new(fSPtr);
+ BaseFileSystem baseFileSystem = new(baseFSPtr);
+
+ Console.WriteLine("get tier");
+
+ Console.WriteLine(fileSystem.GetTier());
+
+ if (interfaceh.Sys_LoadInterface("vguimatsurface", ISurface.VGUI_SURFACE_INTERFACE_VERSION, out IntPtr isurfaceModule, out IntPtr isurfaceInterface))
+ {
+ ISurface surface = new(isurfaceInterface);
+ Console.WriteLine(surface.GetTier());
+ }
+
+ fileSystem.PrintSearchPaths();
+
+ Console.WriteLine("add new path");
+
+ fileSystem.AddSearchPath("garrysmod", "GAME", SearchPathAdd_t.PATH_ADD_TO_HEAD);
+
+ fileSystem.PrintSearchPaths();
+
+ IntPtr fileHandle = baseFileSystem.Open("resource/GameMenu.res", "rb", "GAME");
+
+ if (fileHandle != IntPtr.Zero)
+ {
+ uint size = baseFileSystem.Size(fileHandle);
+
+ byte* buffPtr = stackalloc byte[(int)size];
+
+ IntPtr buffIntPtr = new(buffPtr);
+ baseFileSystem.Read(buffIntPtr, (int)size, fileHandle);
+ Console.WriteLine("Printing file contents");
+ Console.WriteLine(Encoding.UTF8.GetString(buffPtr, (int)size));
+ baseFileSystem.Close(fileHandle);
+ }
+ else
+ {
+ Console.WriteLine("not found file");
+ }
+ }
+ });
+
+ assembly_context.SetCustomNativeLibraryResolver(null);
+
+ Debug.Assert(!failed);
+
+
+ lua.PushSpecial(SPECIAL_TABLES.SPECIAL_GLOB);
+ handle = lua.PushManagedFunction(DrawSomething);
+ lua.SetField(-2, "DrawSomethingPLSWORK");
+ lua.Pop();
+ }
+
+ 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.sln b/SourceSDK.sln
new file mode 100644
index 0000000..586f60d
--- /dev/null
+++ b/SourceSDK.sln
@@ -0,0 +1,46 @@
+
+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}") = "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
+ .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
+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
+ Release|Any CPU = Release|Any CPU
+ 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}.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
+ {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
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {BF1CCF79-0F81-4BF5-AB82-F21D369099C3}
+ EndGlobalSection
+EndGlobal
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/GmodNET.SourceSDK.csproj b/SourceSDK/GmodNET.SourceSDK.csproj
new file mode 100644
index 0000000..4cad751
--- /dev/null
+++ b/SourceSDK/GmodNET.SourceSDK.csproj
@@ -0,0 +1,27 @@
+
+
+ net5
+ true
+ GmodNET
+ GmodNET.SourceSDK
+ 0.0.1
+ true
+ true
+ 9.0
+
+
+
+ True
+ runtimes\
+ False
+ PreserveNewest
+ PreserveNewest
+ %(Identity)
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/SourceSDK/SymbolResolver.cs b/SourceSDK/SymbolResolver.cs
new file mode 100644
index 0000000..f21baf8
--- /dev/null
+++ b/SourceSDK/SymbolResolver.cs
@@ -0,0 +1,139 @@
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+
+namespace GmodNET.SourceSDK
+{
+ 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;
+ private static readonly string[] paths;
+
+ private static string GetPath(string path) => Path.Combine(Directory.GetCurrentDirectory(), path);
+
+ static SymbolResolver()
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ 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;
+ if (Server)
+ {
+ 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}"
+ };
+ }
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ {
+ getLibPtr = dlopen;
+ getSymbolPtr = dlsym;
+ if (Server)
+ {
+ 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}"
+ };
+ }
+ else 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
+
+ private 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);
+ }
+ }
+ }
+ 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/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/Color.cs b/SourceSDK/public/Color.cs
new file mode 100644
index 0000000..215797c
--- /dev/null
+++ b/SourceSDK/public/Color.cs
@@ -0,0 +1,50 @@
+using System.Runtime.InteropServices;
+
+namespace GmodNET.SourceSDK
+{
+ ///
+ /// Color struct
+ ///
+ ///
+ /// Tier0.Dbg.ConColorMsg(new Color(255, 0, 255), "message\n");
+ ///
+ ///
+ /// "public/Color.h"
+ ///
+ [BlittableType]
+ 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/public/VGuiMatSurface/IMatSystemSurface_h.cs b/SourceSDK/public/VGuiMatSurface/IMatSystemSurface_h.cs
new file mode 100644
index 0000000..a72f184
--- /dev/null
+++ b/SourceSDK/public/VGuiMatSurface/IMatSystemSurface_h.cs
@@ -0,0 +1,131 @@
+using System;
+using System.Numerics;
+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);
+
+ 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")]
+ 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);
+
+ [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);
+ }
+ }
+}
diff --git a/SourceSDK/public/appframework/iappsystem.cs b/SourceSDK/public/appframework/iappsystem.cs
new file mode 100644
index 0000000..1f8898d
--- /dev/null
+++ b/SourceSDK/public/appframework/iappsystem.cs
@@ -0,0 +1,109 @@
+using GmodNET.SourceSDK.Tier1;
+using System;
+using System.Runtime.InteropServices;
+
+namespace GmodNET.SourceSDK.AppFramework
+{
+ public enum InitReturnVal_t
+ {
+ INIT_FAILED = 0,
+ INIT_OK = 1,
+
+ INIT_LAST_VAL = 2,
+ };
+
+ [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
+ {
+ 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
+ {
+ public 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", 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")]
+ 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/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/filesystemh.cs b/SourceSDK/public/filesystemh.cs
new file mode 100644
index 0000000..eb3d5d6
--- /dev/null
+++ b/SourceSDK/public/filesystemh.cs
@@ -0,0 +1,576 @@
+using GmodNET.SourceSDK.AppFramework;
+using GmodNET.SourceSDK.tier1;
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace GmodNET.SourceSDK
+{
+ 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
+ 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 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 PathTypeQuery_t
+ {
+ /// 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),
+ /// 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),
+ }
+ /// 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)
+ 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
+ {
+ ///
+ /// 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
+ }
+
+ #endregion
+
+ internal static class BaseFileSystem_c
+ {
+ [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 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 static partial class FileSystem_c
+ {
+ [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);
+ [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 = null);
+ [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_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 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")]
+ 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_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 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 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")]
+ [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);
+
+ [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);
+ }
+
+ internal interface IBaseFileSystem
+ {
+ int Read(IntPtr output, int size, IntPtr file);
+ int Write(IntPtr input, int size, IntPtr file);
+
+ ///
+ ///
+ /// 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);
+ 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
+ {
+ #region Steam operations
+ bool IsSteam();
+ 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
+ /// 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 = 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);
+ /// 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);
+ #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
+ #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
+ #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
+ #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();
+ }
+
+ 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) => 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 = 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);
+ 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) => 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) => 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) => BaseFileSystem_c.IBaseFileSystem_GetFileTime(ptr, fileName, pathID);
+ }
+
+ 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";
+
+ public FileSystem(IntPtr ptr) : base(ptr) { }
+
+ #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);
+
+ 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);
+ 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) => 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) => 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) => 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 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 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 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);
+
+ public void PrintSearchPaths() => FileSystem_c.IFileSystem_PrintSearchPaths(ptr);
+ }
+}
diff --git a/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs
new file mode 100644
index 0000000..55ba48c
--- /dev/null
+++ b/SourceSDK/public/materialsystem/IMaterialSystemHardwareConfig.cs
@@ -0,0 +1,390 @@
+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 readonly IntPtr c;
+
+ public IMaterialSystemHardwareConfig(IntPtr ptr)
+ {
+ if (ptr == IntPtr.Zero) throw new ArgumentNullException(nameof(ptr), "Passing invalid pointer will cause crash");
+ 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);
+ 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);
+
+ 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")]
+ 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);
+ }
+ }
+}
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
new file mode 100644
index 0000000..9e8c0a3
--- /dev/null
+++ b/SourceSDK/public/materialsystem/imaterialsystemh.cs
@@ -0,0 +1,149 @@
+using GmodNET.SourceSDK.bitmap;
+using GmodNET.SourceSDK.Tier1;
+using GmodNET.SourceSDK.vgui;
+using GmodNET.SourceSDK.vtf;
+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 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
+ {
+ 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);
+
+ 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 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));
+
+
+
+
+
+
+
+
+
+
+
+ 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")]
+ 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 = "");
+
+ [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/tier0/dbg.cs b/SourceSDK/public/tier0/dbg.cs
new file mode 100644
index 0000000..238b89a
--- /dev/null
+++ b/SourceSDK/public/tier0/dbg.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Runtime.InteropServices;
+
+namespace GmodNET.SourceSDK.Tier0
+{
+ ///
+ /// "public/tier0/dbg.h"
+ ///
+ public static class Dbg
+ {
+ public static class Delegates
+ {
+ public delegate void void_string(string str);
+ 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 Warning_SpewCallStack(int maxCallStackLength, [MarshalAs(UnmanagedType.LPUTF8Str)] string msg);
+
+ [DllImport("tier0", CallingConvention = CallingConvention.Cdecl)]
+ public static extern void Error([MarshalAs(UnmanagedType.LPUTF8Str)] string msg);
+
+
+ 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.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);
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// 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);
+ }
+
+ public static class CDbgFmtMsg
+ {
+#nullable enable
+ public static string Format(string format, params object?[]? args)
+ {
+ if (args is null || args.Length < 1)
+ {
+ return format;
+ }
+ foreach (var obj in args)
+ {
+ if (obj is int)
+ {
+
+ }
+ }
+ throw new NotImplementedException("todo");
+ }
+#nullable restore
+ }
+}
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");
+ }
+
+}
diff --git a/SourceSDK/public/vgui/isurface.cs b/SourceSDK/public/vgui/isurface.cs
new file mode 100644
index 0000000..277451b
--- /dev/null
+++ b/SourceSDK/public/vgui/isurface.cs
@@ -0,0 +1,102 @@
+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;
+ public int y0;
+ public int x1;
+ public int y1;
+ };
+ public partial class ISurface : IAppSystem
+ {
+ public const string VGUI_SURFACE_INTERFACE_VERSION = "VGUI_Surface030";
+
+ public ISurface(IntPtr ptr) : base(ptr) { }
+
+ 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);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ 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
+ 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);
+
+ 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);
+
+
+
+
+ [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")]
+ 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_SetEmbeddedPanel(IntPtr ptr, uint panel);
+
+ [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);
+
+ [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);
+ [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")]
+ 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);
+ [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);
+
+ [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);
+ }
+ }
+}
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),
+ }
+}
diff --git a/SourceSDK/tier1/interfaceh.cs b/SourceSDK/tier1/interfaceh.cs
new file mode 100644
index 0000000..cf4db65
--- /dev/null
+++ b/SourceSDK/tier1/interfaceh.cs
@@ -0,0 +1,122 @@
+using System;
+using System.Runtime.InteropServices;
+
+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 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)
+ 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);
+
+ CreateInterfaceFn factory = null;
+ Exception exception = null;
+
+ try
+ {
+ factory = Sys_GetFactory(handle);
+ }
+ catch (Exception e)
+ {
+ exception = e;
+ }
+
+ 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);
+ }
+
+ ///
+ /// unloads module
+ ///
+ /// module handle
+ /// uses NativeLibrary.Free
+ ///
+ public static void Sys_UnloadModule(IntPtr module)
+ {
+ //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, out IntPtr outModule, out IntPtr outInterface)
+ {
+ Console.WriteLine("Sys_LoadModule");
+ outModule = Sys_LoadModule(moduleName);
+ outInterface = IntPtr.Zero;
+
+ if (outModule == IntPtr.Zero) return false;
+
+ CreateInterfaceFn factory;
+
+ 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 is not IFACE.OK || outInterface == IntPtr.Zero)
+ {
+ Console.WriteLine("Sys_UnloadModule");
+ Sys_UnloadModule(outModule);
+ return false;
+ }
+
+ return true;
+ }
+ }
+}
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
diff --git a/nuget.config b/nuget.config
new file mode 100644
index 0000000..9f2e200
--- /dev/null
+++ b/nuget.config
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+