-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoader.cs
More file actions
129 lines (117 loc) · 3.62 KB
/
Loader.cs
File metadata and controls
129 lines (117 loc) · 3.62 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Threading;
using UnityEngine;
using System.IO;
namespace Trinity
{
/// <summary>
/// Entry point for Unity Doorstop/mono injection
/// Minimal, no threads, just attach TrinityMenu once Unity is ready.
/// </summary>
public static class Loader
{
private static GameObject _menuObject;
private static bool _isLoaded = false;
/// <summary>
/// Initialize the menu - must be called from Unity's main thread
/// </summary>
public static void Init()
{
if (_isLoaded) return;
try
{
TryWriteMarker();
_menuObject = new GameObject("TrinityMenu");
_menuObject.AddComponent<TrinityMenu>();
UnityEngine.Object.DontDestroyOnLoad(_menuObject);
_isLoaded = true;
Debug.Log("[Trinity] ========================================");
Debug.Log("[Trinity] Trinity Menu v1.0 Loaded Successfully!");
Debug.Log("[Trinity] Press INSERT or F1 to open the menu");
Debug.Log("[Trinity] ========================================");
}
catch (Exception ex)
{
Debug.LogError("[Trinity] Failed to initialize: " + ex.Message);
Debug.LogError("[Trinity] Stack trace: " + ex.StackTrace);
}
}
private static void TryWriteMarker()
{
try
{
string dataPath = Application.dataPath; // .../Infinite Lives_Data
string root = Directory.GetParent(dataPath).FullName;
string marker = Path.Combine(root, "Trinity_loaded.txt");
File.WriteAllText(marker, DateTime.Now.ToString("u") + " - TrinityMenu loaded");
}
catch { /* ignore */ }
}
/// <summary>
/// Unload the menu
/// </summary>
public static void Unload()
{
if (!_isLoaded) return;
try
{
if (_menuObject != null)
{
UnityEngine.Object.Destroy(_menuObject);
_menuObject = null;
}
_isLoaded = false;
Debug.Log("[Trinity] Menu unloaded.");
}
catch (Exception ex)
{
Debug.LogError("[Trinity] Failed to unload: " + ex.Message);
}
}
/// <summary>
/// Check if menu is loaded
/// </summary>
public static bool IsLoaded => _isLoaded;
}
/// <summary>
/// Unity runtime hook to attach the menu after scene load
/// </summary>
public static class TrinityEntrypoint
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
public static void OnAfterSceneLoad()
{
Loader.Init();
}
}
/// <summary>
/// Startup class that Unity Doorstop uses (calls Main on load)
/// </summary>
public static class Startup
{
public static void Main()
{
Loader.Init();
}
}
/// <summary>
/// Generic entrypoint signature some loaders expect: Main(string[] args)
/// </summary>
public static class Entrypoint
{
public static void Main(string[] args)
{
Loader.Init();
}
}
/// <summary>
/// Doorstop entry point for older versions
/// </summary>
public static class Doorstop
{
public static void Start()
{
Loader.Init();
}
}
}