-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathModBehaviour.cs
More file actions
100 lines (81 loc) · 2.71 KB
/
ModBehaviour.cs
File metadata and controls
100 lines (81 loc) · 2.71 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
using System;
using System.Collections.Generic;
using System.Linq;
using EfDEnhanced.Features;
using EfDEnhanced.Utils;
using EfDEnhanced.Utils.Settings;
using HarmonyLib;
using Unity.VisualScripting;
using UnityEngine;
namespace EfDEnhanced;
public class ModBehaviour : Duckov.Modding.ModBehaviour
{
private const string HARMONY_ID = "com.efdenhanced.mod";
private static Harmony? _harmonyInstance;
public static ModBehaviour? Instance { get; private set; }
void Awake()
{
// Set singleton instance
if (Instance != null)
{
ModLogger.LogWarning("Multiple ModBehaviour instances detected!");
Destroy(gameObject);
return;
}
Instance = this;
// Persist across scene changes
DontDestroyOnLoad(gameObject);
ModLogger.Log("=== EfDEnhanced Mod Loading ===");
ModLogger.Log("Version: 2510202100");
// Initialize localization system
LocalizationHelper.Initialize();
// Initialize settings system first (required by other components)
ModSettings.Initialize();
// Initialize quest tracking manager
QuestTrackingManager.Initialize();
// Initialize patches that need early setup
Patches.FastBuySell.Initialize();
_harmonyInstance = new Harmony(HARMONY_ID);
_harmonyInstance.PatchAll();
// Log all patched methods
var patchedMethods = _harmonyInstance.GetPatchedMethods();
ModLogger.Log("Harmony", $"Applied {patchedMethods.Count()} patches:");
foreach (var method in patchedMethods)
{
ModLogger.Log("Harmony", $" - {method.DeclaringType?.Name}.{method.Name}");
}
transform.AddComponent<ActiveQuestTracker>();
transform.AddComponent<DuckShitFeature>();
}
void OnDisable()
{
CleanupResources();
}
void OnDestroy()
{
CleanupResources();
}
/// <summary>
/// Clean up all resources and subscriptions
/// </summary>
private void CleanupResources()
{
try
{
var questTracker = transform.GetComponent<ActiveQuestTracker>();
if (questTracker != null)
{
Destroy(questTracker);
}
// Clean up localization
LocalizationHelper.Cleanup();
// Remove Harmony patches
_harmonyInstance?.UnpatchAll(HARMONY_ID);
ModLogger.Log("ModBehaviour", "All resources cleaned up");
}
catch (Exception ex)
{
ModLogger.LogError($"CleanupResources failed: {ex}");
}
}
}