mirror of
https://github.com/Jacobwasbeast/LegacyWeaveLoader.git
synced 2026-05-24 06:34:34 +00:00
- Replace dbghelp with raw_pdb library for cross-platform PDB symbol resolution - Add main menu branding overlay via C4JRender::Present hook - Add creative inventory item injection from mods - Add file-based logging (LogUtil) alongside console output - Fix mod discovery with custom AssemblyLoadContext for proper type identity - Add file dialog for game path selection in launcher - Add CreativeTab enum and block/item creative tab assignment - Unify build output to single ModLoader/build directory
96 lines
2.4 KiB
C#
96 lines
2.4 KiB
C#
using System.Runtime.InteropServices;
|
|
using LegacyForge.API;
|
|
|
|
namespace LegacyForge.Core;
|
|
|
|
public static class LegacyForgeCore
|
|
{
|
|
private static ModManager? _modManager;
|
|
private static bool _initialized;
|
|
|
|
public static int Initialize(IntPtr args, int sizeBytes)
|
|
{
|
|
if (_initialized) return 0;
|
|
_initialized = true;
|
|
|
|
Logger.SetLogHandler((message, level) =>
|
|
{
|
|
string formatted = $"[LegacyForge/{level}] {message}";
|
|
try
|
|
{
|
|
NativeInterop.native_log(formatted, (int)level);
|
|
}
|
|
catch
|
|
{
|
|
Console.WriteLine(formatted);
|
|
}
|
|
});
|
|
|
|
Logger.Info("LegacyForge Core initialized");
|
|
_modManager = new ModManager();
|
|
return 0;
|
|
}
|
|
|
|
public static int DiscoverMods(IntPtr args, int sizeBytes)
|
|
{
|
|
try
|
|
{
|
|
string modsPath;
|
|
if (args != IntPtr.Zero && sizeBytes > 0)
|
|
modsPath = Marshal.PtrToStringUTF8(args, sizeBytes) ?? "mods";
|
|
else
|
|
modsPath = "mods";
|
|
|
|
Logger.Info($"Discovering mods in: {modsPath}");
|
|
Logger.Info($"Directory exists: {Directory.Exists(modsPath)}");
|
|
|
|
if (Directory.Exists(modsPath))
|
|
{
|
|
var files = Directory.GetFiles(modsPath, "*.dll");
|
|
Logger.Info($"DLL files found: {string.Join(", ", files.Select(Path.GetFileName))}");
|
|
}
|
|
|
|
var discovered = ModDiscovery.DiscoverMods(modsPath);
|
|
_modManager?.AddMods(discovered);
|
|
Logger.Info($"Loaded {discovered.Count} mod(s)");
|
|
return discovered.Count;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Error($"DiscoverMods EXCEPTION: {ex}");
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public static int PreInit(IntPtr args, int sizeBytes)
|
|
{
|
|
_modManager?.PreInit();
|
|
return 0;
|
|
}
|
|
|
|
public static int Init(IntPtr args, int sizeBytes)
|
|
{
|
|
_modManager?.Init();
|
|
return 0;
|
|
}
|
|
|
|
public static int PostInit(IntPtr args, int sizeBytes)
|
|
{
|
|
_modManager?.PostInit();
|
|
return 0;
|
|
}
|
|
|
|
public static int Tick(IntPtr args, int sizeBytes)
|
|
{
|
|
_modManager?.Tick();
|
|
return 0;
|
|
}
|
|
|
|
public static int Shutdown(IntPtr args, int sizeBytes)
|
|
{
|
|
_modManager?.Shutdown();
|
|
Logger.Info("LegacyForge shut down.");
|
|
return 0;
|
|
}
|
|
}
|