-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathBaseLibMain.cs
More file actions
75 lines (59 loc) · 1.99 KB
/
BaseLibMain.cs
File metadata and controls
75 lines (59 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System.Reflection;
using System.Runtime.InteropServices;
using BaseLib.Config;
using BaseLib.Extensions;
using BaseLib.Patches.Content;
using BaseLib.Patches.Utils;
using BaseLib.Utils.NodeFactories;
using HarmonyLib;
using MegaCrit.Sts2.Core.Modding;
namespace BaseLib;
[ModInitializer(nameof(Initialize))]
public static class BaseLibMain
{
[ThreadStatic]
public static bool IsMainThread;
public const string ModId = "BaseLib";
public static MegaCrit.Sts2.Core.Logging.Logger Logger { get; } = new(ModId, MegaCrit.Sts2.Core.Logging.LogType.Generic);
private static Harmony? _mainHarmony = null;
public static void Initialize()
{
Libgcc();
IsMainThread = true;
Godot.OS.AddLogger(new LogListener());
try
{
NodeFactory.Init();
}
catch (Exception e)
{
Logger.Error(e.ToString());
}
var assembly = Assembly.GetExecutingAssembly();
Godot.Bridge.ScriptManagerBridge.LookupScriptsInAssembly(assembly);
ModConfigRegistry.Register(ModId, new BaseLibConfig());
_mainHarmony ??= new(ModId);
TheBigPatchToCardPileCmdAdd.Patch(_mainHarmony);
_mainHarmony.TryPatchAll(assembly);
}
//Hopefully temporary fix for linux
[DllImport("libdl.so.2")]
static extern IntPtr dlopen(string filename, int flags);
[DllImport("libdl.so.2")]
static extern IntPtr dlerror();
[DllImport("libdl.so.2")]
static extern IntPtr dlsym(IntPtr handle, string symbol);
private static IntPtr _holder;
private static void Libgcc()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Logger.Info("Running on Linux, manually dlopen libgcc for Harmony");
_holder = dlopen("libgcc_s.so.1", 2 | 256);
if (_holder == IntPtr.Zero)
{
Logger.Info("Or Nor: "+Marshal.PtrToStringAnsi(dlerror()));
}
}
}
}