dv_CR-style_smoke_deflectors/CR-style_smoke_deflectors/Main.cs

65 lines
1.5 KiB
C#
Raw Permalink Normal View History

using System;
using System.IO;
using System.Reflection;
using HarmonyLib;
using UnityModManagerNet;
using UnityEngine;
2023-12-09 15:33:48 +00:00
namespace CR_style_smoke_deflectors
2023-11-25 14:38:56 +00:00
{
[EnableReloading]
public static class Main
{
2023-12-09 15:33:48 +00:00
private static UnityModManager.ModEntry MyModEntry;
2023-11-25 14:38:56 +00:00
public static Settings MySettings { get; private set; }
2023-12-09 15:33:48 +00:00
public static GameObject CRSmokeDeflectorsPrefab;
2023-11-25 14:38:56 +00:00
private static bool Load(UnityModManager.ModEntry modEntry)
{
Harmony harmony = null;
try
{
MyModEntry = modEntry;
MySettings = UnityModManager.ModSettings.Load<Settings>(MyModEntry);
MyModEntry.OnGUI = entry => MySettings.Draw(entry);
MyModEntry.OnSaveGUI = entry => MySettings.Save(entry);
string assetPath = Path.Combine(MyModEntry.Path, "assetbundles\\");
2023-12-09 15:33:48 +00:00
CRSmokeDeflectorsPrefab = AssetBundle.LoadFromFile(Path.Combine(assetPath, "CRSmokeDeflectors"))
2023-11-25 14:38:56 +00:00
.LoadAsset<GameObject>("Assets/Prefab/LocoS282A_Smokebox.prefab");
harmony = new Harmony(MyModEntry.Info.Id);
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
catch (Exception ex)
{
MyModEntry.Logger.LogException($"Failed to load {MyModEntry.Info.DisplayName}:", ex);
harmony?.UnpatchAll(MyModEntry.Info.Id);
return false;
}
return true;
}
2023-11-25 14:38:56 +00:00
// Logger Commands
public static void Log(string message)
{
MyModEntry.Logger.Log(message);
}
2023-11-25 14:38:56 +00:00
public static void Warning(string message)
{
MyModEntry.Logger.Warning(message);
}
2023-11-25 14:38:56 +00:00
public static void Error(string message)
{
MyModEntry.Logger.Error(message);
}
2023-08-17 01:19:48 +00:00
}
}