Source SDK 2013 With C# Scripting support via .NET 9.0.0.
If you have any questions or need any help feel free to contact me via email ([email protected]
) or on discord (tweety333
).
- Networked Entity Support
- Interaction with Source's File System
- Cleaned up API
- Input Support
- Bindable Game Events (OnDeath, OnMapChange, etc)
C# Support adds a lot of new folders and files, each with their own conventions. Some of them are as follows:
Stored in Client OR Server/Source Files/CSharp/Bridge/
. This is where all the C++ Code that gets called by C# is stored. Files made in here should be appended with "Exports" to make their function clear.
The C# solution src/CSharp/SourceEngine/SourceEngine.sln
provides all the abstractions for interacting with Engine code from C#. Inside of the solution the imports are stored in Bridge/
and often mirror the folder structure of the C++ bindings its importing. Bridge classes should ALWAYS be marked as internal
to prevent users accessing the low level engine imports.
- Add the
src/CSharp
andsrc/game/shared/csharp
folders to your SDK. - In your
client_game.vpc
andserver_game.vpc
files add the following line:$Include "$SRCDIR\game\shared\csharp\csharp.vpc"
- Open your game's
gameinterface.cpp
file and add the following code to the end ofCServerGameDLL::GameInit
:
// If we haven't already, initialize the C# scripting system
if (!CSharpScripting::IsInitialized)
{
// Initialize C# with .NET
CSharpScripting::Initialize<DotNetHostBackend>();
// Run the C# Engine load method
CSharpScripting::RunCSharpMethod("SourceEngine.SourceEngine:Load");
// Register C# Entity factories (DO THIS LAST)
// This allows entities defined in C# to be spawned from their name
CSharpScripting::RegisterCSharpEntityFactories();
}
- Add the lines
#include "scripting/CSharpScripting.h"
and#include "scripting/dotnet/DotNetScriptingBackend.h"
near the top ofgameinterface.cpp
- Follow the steps in Build Instructions
- Enjoy!
- Source SDK 2013 Multiplayer installed via Steam
- Visual Studio 2022 (Windows) or compatible build tools (Linux)
- Python 3.13 or later (Windows only)
- .NET 9.0 for C# compilation
- podman (Linux only)
-
Clone the repository:
git clone https://github.com/YourUsername/source-cs
-
Navigate to the
src
folder and run:createallprojects.bat
-
Open
everything.sln
in Visual Studio 2022. -
Build the solution via
Build > Build Solution
. -
Copy
nethost.dll
fromsrc/thirdparty/dotnet
to thebin/x64
folder of the mod. -
Build both the
SourceEngine
and optionallyGame
C# Projects insrc/CSharp
and copy the outputs to thebin/x64
folder of the mod. -
Set your mod project (e.g.,
Client (HL2MP)
) as the startup project. -
Run with the debugger (
Local Windows Debugger
).
C# Has not been tested on Linux.
Requirements:
- Source SDK 2013 Multiplayer installed via Steam
- podman
Inside the cloned directory, navigate to src
, run:
./buildallprojects
This will build all the projects related to the SDK and your mods automatically against the Steam Runtime.
You can then, in the root of the cloned directory, you can navigate to game
and run your mod by launching the build launcher for your mod project, eg:
./mod_tf
Mods that are distributed on Steam MUST be built against the Steam Runtime, which the above steps will automatically do for you.
There is guidance on distributing your mod both on and off Steam available at the following link:
https://partner.steamgames.com/doc/sdk/uploading/distributing_source_engine
The SDK is licensed to users on a non-commercial basis under the SOURCE 1 SDK LICENSE, which is contained in the LICENSE file in the root of the repository.
For more information, see Distributing your Mod.