-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGODump.cs
73 lines (64 loc) · 2.07 KB
/
GODump.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
using Modding;
using Modding.Patches;
using MonoMod.Utils;
using Newtonsoft.Json;
using System;
using System.IO;
using UnityEngine;
using ReflectionHelper = Modding.ReflectionHelper;
using UObject = UnityEngine.Object;
namespace GODump
{
public class GODump : Mod, IGlobalSettings<Settings>
{
public static GODump Instance;
private static Settings _settings = new Settings();
public static Settings Settings => _settings;
public override string GetVersion() => "1.0.0.1";
public GODump() : base("Game Object Dump") {}
public override void Initialize()
{
Instance = this;
GameObject dumpObj = new GameObject("GODump");
dumpObj.AddComponent<Dump>();
UObject.DontDestroyOnLoad(dumpObj);
}
public void OnLoadGlobal(Settings settings) => _settings = settings;
public Settings OnSaveGlobal() => _settings;
public void LoadSettings()
{
try
{
Type type = ReflectionHelper.GetField<Mod, Type>(this, "globalSettingsType");
if (type != null)
{
string globalSettingsPath = ReflectionHelper.GetField<Mod, string>(this, "_globalSettingsPath");
if (File.Exists(globalSettingsPath))
{
using (FileStream fileStream = File.OpenRead(globalSettingsPath))
using (StreamReader streamReader = new StreamReader(fileStream))
{
object obj = JsonConvert.DeserializeObject(streamReader.ReadToEnd(), type, new JsonSerializerSettings
{
ContractResolver = ShouldSerializeContractResolver.Instance,
TypeNameHandling = TypeNameHandling.Auto,
ObjectCreationHandling = ObjectCreationHandling.Replace,
Converters = JsonConverterTypes.ConverterTypes
});
var onLoadGlobalSettings = ReflectionHelper.GetField<Mod, FastReflectionDelegate>(this, "onLoadGlobalSettings");
onLoadGlobalSettings(this, new object[]
{
obj
});
}
}
}
}
catch (Exception message)
{
LogError(message);
}
}
public void SaveSettings() => SaveGlobalSettings();
}
}