-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharmHelper_Example.cs
197 lines (182 loc) · 6.84 KB
/
CharmHelper_Example.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using Modding;
using ModCommon;
using UnityEngine;
using System.Security.Cryptography;
using SFCore;
using SFCore.Generics;
namespace InvalidNamespaceLol
{
public class CHESaveSettings : ModSettings
{
// Better charms, insert default values here
public List<bool> gotCharms = new List<bool>() { true, true, true, true };
public List<bool> newCharms = new List<bool>() { false, false, false, false };
public List<bool> equippedCharms = new List<bool>() { false, false, false, false };
public List<int> charmCosts = new List<int>() { 1, 1, 1, 1 };
}
public class CHEGlobalSettings : ModSettings
{
}
public class CharmHelperExample : FullSettingsMod<CHESaveSettings, CHEGlobalSettings>
{
public CharmHelper charmHelper { get; private set; }
public override string GetVersion() => SFCore.Utils.GetVersion(Assembly.GetExecutingAssembly());
public override void Initialize()
{
Log("Initializing");
charmHelper = new CharmHelper();
charmHelper.customCharms = 4;
charmHelper.customSprites = new Sprite[] { new Sprite(), new Sprite(), new Sprite(), new Sprite() };
initCallbacks();
Log("Initialized");
}
private void initCallbacks()
{
// Hooks
ModHooks.Instance.GetPlayerBoolHook += OnGetPlayerBoolHook;
ModHooks.Instance.SetPlayerBoolHook += OnSetPlayerBoolHook;
ModHooks.Instance.GetPlayerIntHook += OnGetPlayerIntHook;
ModHooks.Instance.SetPlayerIntHook += OnSetPlayerIntHook;
ModHooks.Instance.ApplicationQuitHook += SaveCHEGlobalSettings;
ModHooks.Instance.LanguageGetHook += OnLanguageGetHook;
}
private void SaveCHEGlobalSettings()
{
SaveGlobalSettings();
}
#region Charm Names and Descriptions
private string[] charmNames = { "Charm Name 1", "Charm Name 2", "Charm Name 3", "Charm Name 4" };
private string[] charmDescriptions = { "Charm Description 1", "Charm Description 2", "Charm Description 3", "Charm Description 4" };
#endregion
#region Get/Set Hooks
private string OnLanguageGetHook(string key, string sheet)
{
// There probably is a better way to do this, but for now take this
#region Custom Charms
if (key.StartsWith("CHARM_NAME_"))
{
int charmNum = int.Parse(key.Split('_')[2]);
if (charmHelper.charmIDs.Contains(charmNum))
{
return charmNames[charmHelper.charmIDs.IndexOf(charmNum)];
}
}
if (key.StartsWith("CHARM_DESC_"))
{
int charmNum = int.Parse(key.Split('_')[2]);
if (charmHelper.charmIDs.Contains(charmNum))
{
return charmDescriptions[charmHelper.charmIDs.IndexOf(charmNum)];
}
}
#endregion
return Language.Language.GetInternal(key, sheet);
}
private bool OnGetPlayerBoolHook(string target)
{
if (Settings.BoolValues.ContainsKey(target))
{
return Settings.BoolValues[target];
}
#region Custom Charms
if (target.StartsWith("gotCharm_"))
{
int charmNum = int.Parse(target.Split('_')[1]);
if (charmHelper.charmIDs.Contains(charmNum))
{
return Settings.gotCharms[charmHelper.charmIDs.IndexOf(charmNum)];
}
}
if (target.StartsWith("newCharm_"))
{
int charmNum = int.Parse(target.Split('_')[1]);
if (charmHelper.charmIDs.Contains(charmNum))
{
return Settings.newCharms[charmHelper.charmIDs.IndexOf(charmNum)];
}
}
if (target.StartsWith("equippedCharm_"))
{
int charmNum = int.Parse(target.Split('_')[1]);
if (charmHelper.charmIDs.Contains(charmNum))
{
return Settings.equippedCharms[charmHelper.charmIDs.IndexOf(charmNum)];
}
}
#endregion
return PlayerData.instance.GetBoolInternal(target);
}
private void OnSetPlayerBoolHook(string target, bool val)
{
if (Settings.BoolValues.ContainsKey(target))
{
Settings.BoolValues[target] = val;
return;
}
#region Custom Charms
if (target.StartsWith("gotCharm_"))
{
int charmNum = int.Parse(target.Split('_')[1]);
if (charmHelper.charmIDs.Contains(charmNum))
{
Settings.gotCharms[charmHelper.charmIDs.IndexOf(charmNum)] = val;
return;
}
}
if (target.StartsWith("newCharm_"))
{
int charmNum = int.Parse(target.Split('_')[1]);
if (charmHelper.charmIDs.Contains(charmNum))
{
Settings.newCharms[charmHelper.charmIDs.IndexOf(charmNum)] = val;
return;
}
}
if (target.StartsWith("equippedCharm_"))
{
int charmNum = int.Parse(target.Split('_')[1]);
if (charmHelper.charmIDs.Contains(charmNum))
{
Settings.equippedCharms[charmHelper.charmIDs.IndexOf(charmNum)] = val;
return;
}
}
#endregion
PlayerData.instance.SetBoolInternal(target, val);
}
private int OnGetPlayerIntHook(string target)
{
if (Settings.IntValues.ContainsKey(target))
{
return Settings.IntValues[target];
}
#region Custom Charms
if (target.StartsWith("charmCost_"))
{
int charmNum = int.Parse(target.Split('_')[1]);
if (charmHelper.charmIDs.Contains(charmNum))
{
return Settings.charmCosts[charmHelper.charmIDs.IndexOf(charmNum)];
}
}
#endregion
return PlayerData.instance.GetIntInternal(target);
}
private void OnSetPlayerIntHook(string target, int val)
{
if (Settings.IntValues.ContainsKey(target))
{
Settings.IntValues[target] = val;
}
else
{
PlayerData.instance.SetIntInternal(target, val);
}
}
#endregion
}
}