Repository navigation
Expand file tree
/
Copy pathMain.cs
More file actions
93 lines (85 loc) · 3.21 KB
/
Copy pathMain.cs
File metadata and controls
93 lines (85 loc) · 3.21 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
using Kingmaker.Blueprints;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityModManagerNet;
namespace Derring_Do
{
public class Main
{
internal class Settings
{
internal bool thrown_weapons_and_flying_blade { get; }
internal Settings()
{
using (StreamReader settings_file = File.OpenText(UnityModManager.modsPath + @"/Derring-Do/settings.json"))
using (JsonTextReader reader = new JsonTextReader(settings_file))
{
JObject jo = (JObject)JToken.ReadFrom(reader);
thrown_weapons_and_flying_blade = (bool)jo["thrown_weapons_and_flying_blade"];
}
}
}
static internal Settings settings = new Settings();
internal static UnityModManagerNet.UnityModManager.ModEntry.ModLogger logger;
internal static Harmony12.HarmonyInstance harmony;
public static LibraryScriptableObject library;
static readonly Dictionary<Type, bool> typesPatched = new Dictionary<Type, bool>();
static readonly List<String> failedPatches = new List<String>();
static readonly List<String> failedLoading = new List<String>();
[System.Diagnostics.Conditional("DEBUG")]
internal static void DebugLog(string msg)
{
if (logger != null) logger.Log(msg);
}
internal static void DebugError(Exception ex)
{
if (logger != null) logger.Log(ex.ToString() + "\n" + ex.StackTrace);
}
//internal static bool enabled;
static bool Load(UnityModManager.ModEntry modEntry)
{
try
{
logger = modEntry.Logger;
harmony = Harmony12.HarmonyInstance.Create(modEntry.Info.Id);
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
catch (Exception ex)
{
DebugError(ex);
throw ex;
}
return true;
}
[Harmony12.HarmonyPatch(typeof(LibraryScriptableObject), "LoadDictionary")]
[Harmony12.HarmonyPatch(typeof(LibraryScriptableObject), "LoadDictionary", new Type[0])]
[Harmony12.HarmonyAfter("CallOfTheWild", "ProperFlanking2")]
static class LibraryScriptableObject_LoadDictionary_Patch
{
static void Postfix(LibraryScriptableObject __instance)
{
var self = __instance;
if (Main.library != null) return;
Main.library = self;
try
{
Main.DebugLog("Loading Derring-Do");
if (settings.thrown_weapons_and_flying_blade)
{
Main.DebugLog("Adding Thrown Daggers and Starknives");
ThrowAnything.create();
}
Swashbuckler.createSwashbucklerClass(settings.thrown_weapons_and_flying_blade);
}
catch (Exception ex)
{
Main.DebugError(ex);
}
}
}
}
}