forked from Pinkstink-Rust/Rust-Server-Metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e835b1
commit df3aed5
Showing
5 changed files
with
97 additions
and
48 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,67 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using API.Assembly; | ||
using API.Events; | ||
using HarmonyLib; | ||
using UnityEngine; | ||
using Logger = Carbon.Logger; | ||
using Object = UnityEngine.Object; | ||
|
||
namespace RustServerMetrics; | ||
|
||
public class RustServerMetricsLoader : IHarmonyModHooks | ||
public class RustServerMetricsLoader : IModulePackage | ||
{ | ||
public static bool __serverStarted = false; | ||
|
||
public static Harmony __harmonyInstance; | ||
public static List<Harmony> __modTimeWarningsHarmonyInstances = new (); | ||
|
||
public void OnLoaded(OnHarmonyModLoadedArgs args) | ||
{ | ||
if (!Bootstrap.bootstrapInitRun) | ||
return; | ||
|
||
MetricsLogger.Initialize(); | ||
|
||
if (MetricsLogger.Instance != null) | ||
MetricsLogger.Instance.OnServerStarted(); | ||
} | ||
|
||
public void OnUnloaded(OnHarmonyModUnloadedArgs args) | ||
{ | ||
__harmonyInstance?.UnpatchAll(); | ||
foreach (var instance in __modTimeWarningsHarmonyInstances) | ||
{ | ||
instance?.UnpatchAll(); | ||
} | ||
|
||
if (MetricsLogger.Instance != null) | ||
Object.DestroyImmediate(MetricsLogger.Instance); | ||
} | ||
|
||
public void AddModTimeWarnings(List<MethodInfo> methods) | ||
{ | ||
{ | ||
var instance = new Harmony($"RustServerMetrics.ModTimeWarnings.{__modTimeWarningsHarmonyInstances.Count}"); | ||
__modTimeWarningsHarmonyInstances.Add(instance); | ||
|
||
ModTimeWarnings.Methods.Clear(); | ||
ModTimeWarnings.Methods.AddRange(methods); | ||
|
||
var patchProcessor = new PatchClassProcessor(instance, typeof(ModTimeWarnings)); | ||
patchProcessor.Patch(); | ||
|
||
foreach (var method in methods) | ||
{ | ||
Debug.Log($"{method.DeclaringType?.Name}.{method.Name}"); | ||
Logger.Log($"{method.DeclaringType?.Name}.{method.Name}"); | ||
} | ||
|
||
Debug.Log($"[ServerMetrics]: Added {methods.Count} ModTimeWarnings"); | ||
Logger.Log($"[ServerMetrics]: Added {methods.Count} ModTimeWarnings"); | ||
} | ||
|
||
public void Awake(EventArgs args) | ||
{ | ||
Logger.Log($"[ServerMetrics]: Carbon Community version {typeof(RustServerMetricsLoader).Assembly.GetName().Version} [module]"); | ||
} | ||
|
||
public void OnLoaded(EventArgs args) | ||
{ | ||
if (!Bootstrap.bootstrapInitRun) | ||
return; | ||
|
||
Carbon.Community.Runtime.Events.Subscribe(CarbonEvent.HookValidatorRefreshed, _ => | ||
{ | ||
Carbon.Components.Harmony.PatchAll(Assembly.GetExecutingAssembly()); | ||
|
||
MetricsLogger.Initialize(); | ||
}); | ||
} | ||
|
||
public void OnUnloaded(EventArgs args) | ||
{ | ||
__harmonyInstance?.UnpatchAll(); | ||
foreach (var instance in __modTimeWarningsHarmonyInstances) | ||
{ | ||
instance?.UnpatchAll(); | ||
} | ||
|
||
if (MetricsLogger.Instance != null) | ||
Object.DestroyImmediate(MetricsLogger.Instance); | ||
} | ||
} | ||
} |