Files
sbox-public/engine/Sandbox.NetCore/NetCore.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

41 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
/*
*
* This dll is only called in instances where we want to initialize .net from c++.
*
* We purposefully don't reference any dlls here because it's loaded in its own isolated
* context, so if we load sandbox.engine, it technically won't be loaded in the main context
* and stuff will be weird.
*
* Eventually we might not need this. We might make all the exe's dotnet exes - in which case
* we'll make the exe call Interop.InitializeAll directly to set everything up.
*
* */
internal static class NetCore
{
[UnmanagedCallersOnly]
public static int InitializeEngine( IntPtr gameFolderPtr )
{
//
// This should contain the minimal amount of logic needed to call InitializeInterop
//
var gameFolder = Marshal.PtrToStringUTF8( gameFolderPtr );
var managedFolder = $"{gameFolder}\\bin\\managed\\";
var assembly = Assembly.LoadFrom( $"{managedFolder}Sandbox.Engine.dll" );
var type = assembly.GetTypes().Where( x => x.Name == "NetCore" ).FirstOrDefault();
var method = type.GetMethod( "InitializeInterop", BindingFlags.Static | BindingFlags.NonPublic );
method.Invoke( null, new object[] { gameFolder } );
return 0;
}
}