-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguage.cs
94 lines (88 loc) · 3.26 KB
/
Language.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
using HarmonyLib;
using Newtonsoft.Json.Linq;
namespace DarkwoodCustomizer;
internal class LanguagePatch
{
[HarmonyPatch(typeof(Language), nameof(Language.Get), [typeof(string), typeof(string)])]
[HarmonyPostfix]
public static void LanguageGet(string key, string sheetTitle, ref string __result)
{
var cleankey = key.Replace("_name", "").Replace("_desc", "");
if (Plugin.CustomItemsUseDefaults.Value && Plugin.DefaultCustomItems[cleankey] != null)
{
var data = (JObject)Plugin.DefaultCustomItems[cleankey];
var name = data["name"]?.Value<string>() ?? null;
var desc = data["description"]?.Value<string>() ?? null;
if (key.EndsWith("_name") && name != null && name != key) __result = name;
if (key.EndsWith("_desc") && desc != null && desc != key) __result = desc;
}
if (Plugin.CustomItems[cleankey] != null)
{
var data = (JObject)Plugin.CustomItems[cleankey];
var name = data["name"]?.Value<string>() ?? null;
var desc = data["description"]?.Value<string>() ?? null;
if (key.EndsWith("_name"))
{
if (name == null)
{
if (__result == key) data["name"] = "";
else data["name"] = __result;
Plugin.SaveItems = true;
}
name = data["name"]?.Value<string>() ?? null;
if (name != null && name != key) __result = name;
};
if (key.EndsWith("_desc"))
{
if (desc == null)
{
if (__result == key) data["description"] = "";
else data["description"] = __result;
Plugin.SaveItems = true;
}
desc = data["description"]?.Value<string>() ?? null;
if (desc != null && desc != key) __result = desc;
};
}
__result ??= "Unset Name Property";
}
[HarmonyPatch(typeof(Language), nameof(Language.Get), [typeof(string)])]
[HarmonyPostfix]
public static void LanguageGet(string key, ref string __result)
{
var cleankey = key.Replace("_name", "").Replace("_desc", "");
if (Plugin.CustomItems[cleankey] != null)
{
var data = (JObject)Plugin.CustomItems[cleankey];
if (key.EndsWith("_name"))
{
var name = data["name"]?.Value<string>();
if (name == null | name == $"{key}_name")
{
data["name"] = __result;
Plugin.SaveJsonFile(Plugin.CustomItemsPath, Plugin.CustomItems);
}
};
if (key.EndsWith("_desc"))
{
var description = data["description"]?.Value<string>();
if (description == null | description == $"{key}_desc")
{
data["description"] = __result;
Plugin.SaveJsonFile(Plugin.CustomItemsPath, Plugin.CustomItems);
}
};
}
__result ??= "Unset Name Property";
}
[HarmonyPatch(typeof(Language), nameof(Language.HasKey), typeof(string), typeof(string))]
[HarmonyPostfix]
public static void LanguageHasKey(string key, string sheetTitle, ref bool __result)
{
var cleankey = key.Replace("_name", "").Replace("_desc", "");
if (Plugin.CustomItems.TryGetValue(cleankey, out var data) && (data["name"] != null || data["description"] != null))
__result = true;
else if (Plugin.DefaultCustomItems.TryGetValue(cleankey, out data) && (data["name"] != null || data["description"] != null))
__result = true;
}
}