-
Notifications
You must be signed in to change notification settings - Fork 2
/
ModTemplate.cs
83 lines (68 loc) · 2.02 KB
/
ModTemplate.cs
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
// I use this for copy/paste it in my next mod and save me time. You can use it too.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using HarmonyLib;
using UnityEngine;
using UnityModManagerNet;
namespace ModTemplate
{
static class Main
{
public static UnityModManager.ModEntry mod;
public static bool enabled;
public static Settings settings;
static bool Load(UnityModManager.ModEntry modEntry)
{
modEntry.OnGUI = OnGUI;
modEntry.OnSaveGUI = OnSaveGUI;
modEntry.OnToggle = OnToggle;
modEntry.OnUpdate = OnUpdate;
settings = Settings.Load<Settings>(modEntry);
mod = modEntry;
var harmony = new Harmony(modEntry.Info.Id);
try
{
var assembly = Assembly.GetExecutingAssembly();
harmony.PatchAll(assembly);
}
catch(Exception ex)
{
mod.Logger.Log("Failed to Patch Harmony !\n"+ex.ToString());
}
return true;
}
static void OnGUI(UnityModManager.ModEntry modEntry)
{
}
static void OnUpdate(UnityModManager.ModEntry modEntry, float dt)
{
}
static void OnSaveGUI(UnityModManager.ModEntry modEntry)
{
settings.Save(modEntry);
}
static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
{
enabled = value;
return true;
}
public static void Log(object str)
{
mod.Logger.Log(str.ToString());
}
public static void Log(IEnumerable<object> str)
{
mod.Logger.Log(str.ToString());
}
}
public class Settings : UnityModManager.ModSettings
{
public override void Save(UnityModManager.ModEntry modEntry)
{
Save(this, modEntry);
}
}
}