-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPatch.cs
205 lines (180 loc) · 5.97 KB
/
Patch.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
198
199
200
201
202
203
204
205
using System.IO;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;
using Utage;
using UtageExtensions;
namespace TSKHook;
public class Patch
{
private static string currentAdvId;
public static string fontName = "notosanscjktc";
public static AssetBundle fontBundle;
public static Font TranslateFont;
public static TMP_FontAsset TMPTranslateFont;
public static void Initialize()
{
Harmony.CreateAndPatchAll(typeof(Patch));
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameConfig), "set_FixedFrameRate")]
public static void set_FixedFrameRate(ref int value)
{
if (TSKConfig.FPS > 60)
{
value = TSKConfig.FPS;
Plugin.Global.Log.LogInfo("FPS setting was overridden: " + value);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AdvDataManager), "DownloadChaperKeyFileUsed")]
public static void DownloadChaperKeyFileUsed(ref string scenarioLabel)
{
if (!TSKConfig.TranslationEnabled)
{
return;
}
if (scenarioLabel != null)
{
if ((TranslateFont == null || TMPTranslateFont == null) && File.Exists($"{Paths.PluginPath}/font/{fontName}"))
{
if (fontBundle == null)
{
fontBundle = AssetBundle.LoadFromFile($"{Paths.PluginPath}/font/{fontName}");
}
TranslateFont = fontBundle.LoadAsset(fontName).Cast<Font>();
TMPTranslateFont = fontBundle.LoadAsset(fontName + " SDF").TryCast<TMP_FontAsset>();
fontBundle.Unload(false);
if (TranslateFont != null && TMPTranslateFont != null)
{
Plugin.Global.Log.LogInfo("Font loaded.");
}
}
currentAdvId = scenarioLabel.ToLower();
if (!Translation.chapterDicts.ContainsKey(currentAdvId))
{
Translation.FetchChapterTranslationAsync(currentAdvId).Wait();
}
Plugin.Global.Log.LogInfo(scenarioLabel);
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AdventureTitleBandView), "Initialize")]
public static void AdvIniPre(AdventureTitleBandView __instance)
{
if (!TSKConfig.TranslationEnabled)
{
return;
}
string value;
if (Translation.chapterDicts.ContainsKey(currentAdvId) && Translation.chapterDicts[currentAdvId].TryGetValue(__instance.TitleText, out value))
{
__instance.TitleText = value.IsNullOrEmpty() ? __instance.TitleText : value;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(AdventureTitleBandView), "Initialize")]
public static void AdvInitPost(AdventureTitleBandView __instance)
{
if (!TSKConfig.TranslationEnabled)
{
return;
}
if (TMPTranslateFont != null)
{
__instance.upTextComp.text.font = TMPTranslateFont;
__instance.donwTextComp.text.font = TMPTranslateFont;
for (int i = 0; i < __instance.titleText.Length; i++)
{
__instance.titleText[i].font = TMPTranslateFont;
}
for (int i = 0; i < __instance.donwTextObject.Length; i++)
{
TKSTextTMPGUI component = __instance.donwTextObject[i].GetComponent<TKSTextTMPGUI>();
component.text.font = TMPTranslateFont;
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UguiNovelText), "OnEnable")]
public static void FontPatch(ref UguiNovelText __instance)
{
if (!TSKConfig.TranslationEnabled)
{
return;
}
if (TranslateFont != null)
{
__instance.font = TranslateFont;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(AdvPage), "get_NameText")]
public static void get_NameText(ref string __result)
{
if (!TSKConfig.TranslationEnabled)
{
return;
}
string value;
if (Translation.nameDicts.TryGetValue(__result, out value))
{
__result = value.IsNullOrEmpty() ? __result : value;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(AdvBacklog), "get_MainCharacterNameText")]
public static void get_MainCharacterNameText(ref string __result)
{
if (!TSKConfig.TranslationEnabled)
{
return;
}
string value;
if (Translation.nameDicts.TryGetValue(__result, out value))
{
__result = value.IsNullOrEmpty() ? __result : value;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(LanguageManagerBase), "ParseCellLocalizedTextBySwapDefaultLanguage")]
public static void ParseCellLocalizedTextBySwapDefaultLanguage(ref StringGridRow row, ref string defaultColumnName,
ref string __result)
{
if (!TSKConfig.TranslationEnabled)
{
return;
}
string value;
if (Translation.chapterDicts.ContainsKey(currentAdvId) && Translation.chapterDicts[currentAdvId].TryGetValue(__result, out value))
{
__result = value.IsNullOrEmpty() ? __result : value;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Screen), "SetResolution", new[] { typeof(int), typeof(int), typeof(bool) })]
public static bool SetWindowSize(ref int width, ref int height, ref bool fullscreen)
{
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(MaximizeCharaView), "SetCharaRoot_Scale")]
public static void SetCharaRoot_Scale(ref MaximizeZoomEventData _zoomData)
{
if (_zoomData.PinchData > 0)
{
_zoomData.PinchData = TSKConfig.zoom;
}
else
{
_zoomData.PinchData = -TSKConfig.zoom;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(MaximizeCharaView), "initialize")]
public static void CharaViewInit(ref MaximizeCharaView __instance)
{
__instance.maximizeMinSize = 0.1f;
}
}