@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace BSO
|
||||
{
|
||||
/// <summary>Was der Loader (dinput8.dll) mitgibt - Gegenstueck zu HostApi in BSO.Loader\dinput8.cpp.</summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct HostApi
|
||||
{
|
||||
public delegate* unmanaged<byte*, void> Log;
|
||||
public char* GameDir;
|
||||
public char* BsoDir;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Einstieg: der Loader startet .NET beim ersten DirectInput8Create und ruft Start auf, danach OnFrame einmal pro
|
||||
/// Bild im Hauptthread des Spiels. Protokoll: <Spiel>\BSO\BSO_Loader.txt.
|
||||
/// </summary>
|
||||
public static unsafe class Bootstrap
|
||||
{
|
||||
public const string ModVersion = "0.2.0";
|
||||
|
||||
static HostApi* host;
|
||||
static int frameErrors;
|
||||
|
||||
/// <summary>Ordner von BSO.dll (<Spiel>\BSO).</summary>
|
||||
public static string Folder { get; private set; }
|
||||
/// <summary>Ordner der Spiel-EXE (Bin_High_Win64).</summary>
|
||||
public static string GameFolder { get; private set; }
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
public static void Start(HostApi* api)
|
||||
{
|
||||
try
|
||||
{
|
||||
host = api;
|
||||
Folder = new string(api->BsoDir);
|
||||
GameFolder = new string(api->GameDir);
|
||||
Log("BSO " + ModVersion + " gestartet (.NET " + Environment.Version + ")");
|
||||
Log("Kommandozeile: " + Environment.CommandLine);
|
||||
Config.Load();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log("Start fehlgeschlagen: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
public static void OnFrame()
|
||||
{
|
||||
try
|
||||
{
|
||||
Mem.NewFrame();
|
||||
if (!Vision.Init()) return;
|
||||
if (Vision.TimerAdvanced())
|
||||
{
|
||||
Input.Update();
|
||||
BorderlessWindow.Update();
|
||||
LocalPlayer.Update();
|
||||
Multiplayer.Update();
|
||||
PositionHud.Update();
|
||||
}
|
||||
PositionHud.Draw();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Nicht jedes Bild ins Protokoll schreiben
|
||||
if (frameErrors++ < 5) Log("Fehler im Bild-Takt: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Log(string line)
|
||||
{
|
||||
if (host == null) return;
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(line + "\0");
|
||||
fixed (byte* p = bytes) host->Log(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user