-
Notifications
You must be signed in to change notification settings - Fork 4
/
NewGameUI.cs
366 lines (336 loc) · 18.2 KB
/
NewGameUI.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
using System.Collections.Generic;
using System.Reflection;
using BepInEx.Logging;
using HarmonyLib;
using LunacidAP.Data;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
namespace LunacidAP
{
public class NewGameUI
{
private static ManualLogSource _log;
private static GameObject HostEntry;
private static GameObject PortEntry;
private static GameObject PasswordEntry;
private static int _currentSave;
public static NewGameUI UI;
public static readonly Dictionary<Goal, string> GoalToString = new(){
{Goal.AnyEnding, "Any"},
{Goal.EndingA, "A"},
{Goal.EndingB, "B"},
{Goal.EndingCD, "CD"},
{Goal.EndingE, "E"},
};
public static readonly Dictionary<Dropsanity, string> DropsanityToString = new(){
{Dropsanity.Off, "OFF"},
{Dropsanity.Unique, "UNQ"},
{Dropsanity.Randomized, "RAN"}
};
public NewGameUI(ManualLogSource log)
{
_log = log;
Harmony.CreateAndPatchAll(typeof(NewGameUI));
}
public void ModifyCharCreateForArchipelago()
{
var create = GameObject.Find("PLAYER").transform.GetChild(1).GetChild(0).GetChild(4).GetChild(2);
var textField = create.GetChild(6).gameObject;
HostEntry = GameObject.Instantiate(textField);
HostEntry.name = "Host";
var hostInputComponent = HostEntry.GetComponent<TMP_InputField>();
hostInputComponent.placeholder.GetComponent<TMP_Text>().text = "input hostname";
hostInputComponent.characterLimit = 30;
HostEntry.transform.position = new Vector3(62.0523f, 14.18f, -66.08f);
HostEntry.transform.SetParent(create);
HostEntry.transform.localScale = new Vector3(1f, 0.8f, 1f);
PortEntry = GameObject.Instantiate(textField);
PortEntry.name = "Port";
var portInputComponent = PortEntry.GetComponent<TMP_InputField>();
portInputComponent.placeholder.GetComponent<TMP_Text>().text = "input port";
portInputComponent.characterLimit = 30;
PortEntry.transform.position = new Vector3(62.0523f, 14.081f, -66.08f);
PortEntry.transform.SetParent(create);
PortEntry.transform.localScale = new Vector3(1f, 0.8f, 1f);
PasswordEntry = GameObject.Instantiate(textField);
PasswordEntry.name = "Password";
var passwordInputComponent = PasswordEntry.GetComponent<TMP_InputField>();
passwordInputComponent.placeholder.GetComponent<TMP_Text>().text = "input password";
passwordInputComponent.characterLimit = 30;
PasswordEntry.transform.position = new Vector3(62.0523f, 13.9689f, -66.08f);
PasswordEntry.transform.SetParent(create);
PasswordEntry.transform.localScale = new Vector3(1f, 0.8f, 1f);
}
[HarmonyPatch(typeof(Menus), "Click")]
[HarmonyPrefix]
private static bool Click_GatherData(int which, Menus __instance)
{
var eqSlot2Field = __instance.GetType().GetField("EQ_SLOT2", BindingFlags.Instance | BindingFlags.NonPublic);
var EQ_SLOT2 = (int)eqSlot2Field.GetValue(__instance);
var eqselField = __instance.GetType().GetField("EQ_SEL", BindingFlags.Instance | BindingFlags.NonPublic);
var EQ_SEL = (int)eqselField.GetValue(__instance);
var loadTextMethod = __instance.GetType().GetMethod("LoadText", BindingFlags.Instance | BindingFlags.NonPublic);
if (which == 51 && (__instance.current_query == 6 || __instance.current_query == 0)) // Loading a save from main menu
{
var eqSlotField = __instance.GetType().GetField("EQ_SLOT", BindingFlags.Instance | BindingFlags.NonPublic);
var EQ_SLOT = (int)eqSlotField.GetValue(__instance);
PlayerPrefs.SetInt("CURRENT_SAVE", EQ_SLOT);
var saveSlot = PlayerPrefs.GetInt("CURRENT_SAVE", EQ_SLOT);
_currentSave = saveSlot;
if (EQ_SLOT2 != 10 && !StaticFuncs.IS_NULL(OfferSaveInfo(__instance.CON, saveSlot))) // Some menu instances are similar but not quite
{
SaveHandler.ReadSave(saveSlot);
__instance.StartCoroutine(ArchipelagoClient.AP.Connect(ConnectionData.SlotName, ConnectionData.HostName, ConnectionData.Port, ConnectionData.Password, false, slotID: saveSlot));
}
return true;
}
else if (which == 55 && __instance.current_query == 0) // Player has died but wants to resume. Need some feedback.
{
if (ArchipelagoClient.AP.IsConnecting)
{
return false;
}
if (ArchipelagoClient.AP.Authenticated)
{
return true;
}
else
{
_log.LogInfo($"Reloading {_currentSave}");
SaveHandler.ReadSave(_currentSave);
ArchipelagoClient.AP.AttemptConnectFromDeath(_currentSave);
return false; // don't let the player play.
}
}
else if (which == 28) // Query for deleting save data
{
if (__instance.current_query == 0) // saving in-game
{
SaveHandler.SaveData(_currentSave);
}
else if (__instance.current_query == 5) // deleting a save
{
var eqSlotField = __instance.GetType().GetField("EQ_SLOT", BindingFlags.Instance | BindingFlags.NonPublic);
var EQ_SLOT = (int)eqSlotField.GetValue(__instance);
PlayerPrefs.SetInt("CURRENT_SAVE", EQ_SLOT);
var saveSlot = PlayerPrefs.GetInt("CURRENT_SAVE", EQ_SLOT);
_currentSave = saveSlot;
ConnectionData.WriteConnectionData();
SaveHandler.SaveData(saveSlot);
}
}
else if (which == 28 && __instance.current_query == 6) // Trying to load save fully but connection isn't made yet
{
if (!ArchipelagoClient.AP.Authenticated)
{
return false;
}
}
else if (which == 29 && __instance.current_query == 6) // Say no to a load at menu
{
ArchipelagoClient.AP.Disconnect();
}
else if (which == 37)
{
var audioMethod = __instance.GetType().GetMethod("Audio", BindingFlags.Instance | BindingFlags.NonPublic);
var slotName = __instance.ITEMS[20].GetComponent<TMP_InputField>().text;
var hostName = GameObject.Find("PLAYER").transform.GetChild(1).GetChild(0).GetChild(4).GetChild(2).GetChild(27).gameObject.GetComponent<TMP_InputField>().text;
var portName = GameObject.Find("PLAYER").transform.GetChild(1).GetChild(0).GetChild(4).GetChild(2).GetChild(28).gameObject.GetComponent<TMP_InputField>().text;
var port = int.Parse(portName);
var password = GameObject.Find("PLAYER").transform.GetChild(1).GetChild(0).GetChild(4).GetChild(2).GetChild(29).gameObject.GetComponent<TMP_InputField>().text;
if (StaticFuncs.IS_NULL(slotName) || StaticFuncs.IS_NULL(hostName) || StaticFuncs.IS_NULL(portName))
{
audioMethod.Invoke(__instance, new object[] { 5 });
return false;
}
if (!ArchipelagoClient.AP.Authenticated)
{
_log.LogInfo($"Telling the game to save AP data at {_currentSave}");
__instance.StartCoroutine(ArchipelagoClient.AP.Connect(slotName, hostName, port, password, false, _currentSave));
return false;
}
__instance.sub_menu = 9;
__instance.LoadSub();
__instance.TXT[31].text = "Finalize Creation?";
__instance.current_query = 1;
EventSystem.current.SetSelectedGameObject(__instance.ITEMS[10]);
audioMethod.Invoke(__instance, new object[] { 8 });
_log.LogInfo($"Saving to {_currentSave}");
SaveHandler.SaveData(_currentSave);
}
else if (which == 41)
{
ShopHandler.EnsureEnchantedKey();
}
return true;
}
[HarmonyPatch(typeof(Menus), "Click")]
[HarmonyPostfix]
private static void Click_FixDueToPronouns_Postfix(int which, Menus __instance)
{
if (which == 83 || which == 84)
{
FixConnectionInfoDisplay();
}
}
private static string OfferSaveInfo(CONTROL control, int saveSlot)
{
switch (saveSlot)
{
case 0:
return control.CURRENT_SYS_DATA.SAVE0_INFO;
case 1:
return control.CURRENT_SYS_DATA.SAVE1_INFO;
case 2:
return control.CURRENT_SYS_DATA.SAVE2_INFO;
}
return control.CURRENT_SYS_DATA.SAVE0_INFO;
}
[HarmonyPatch(typeof(Menus), "Update")]
[HarmonyPostfix]
private static void Update_ChangeMenuStateToNormalIfOnline(Menus __instance)
{
var sceneName = __instance.gameObject.scene.name;
switch (sceneName)
{
case "CHAR_CREATE":
{
var create = GameObject.Find("PLAYER").transform.GetChild(1).GetChild(0).GetChild(4).GetChild(2);
if (!ArchipelagoClient.AP.Authenticated && GameObject.Find("PLAYER").transform.GetChild(1).GetChild(0).GetChild(4).GetChild(2).GetChild(18).gameObject.activeSelf)
{
create.GetChild(12).GetComponent<TextMeshProUGUI>().GetComponent<TMP_Text>().text = "SLOT NAME\nHOST\nPORT\nPASSWORD";
HostEntry.SetActive(value: true);
PortEntry.SetActive(value: true);
PasswordEntry.SetActive(value: true);
create.GetChild(13).GetComponent<TextMeshProUGUI>().text = "Archipelago\nsettings";
create.GetChild(14).gameObject.SetActive(value: false);
create.GetChild(15).gameObject.SetActive(value: false);
create.GetChild(16).gameObject.SetActive(value: false);
create.GetChild(19).gameObject.SetActive(value: false);
create.GetChild(20).gameObject.SetActive(value: false);
create.GetChild(21).gameObject.SetActive(value: false);
create.GetChild(22).gameObject.SetActive(value: false);
create.GetChild(23).gameObject.SetActive(value: false);
create.GetChild(17).gameObject.SetActive(value: false);
create.GetChild(18).gameObject.SetActive(value: false);
create.GetChild(26).gameObject.SetActive(value: false);
create.GetChild(10).gameObject.SetActive(value: false);
create.GetChild(11).gameObject.SetActive(value: false);
create.GetChild(7).GetChild(0).GetComponent<TextMeshProUGUI>().text = "Connect";
create.GetChild(8).gameObject.SetActive(value: false);
create.GetChild(9).gameObject.SetActive(value: false);
return;
}
else if (ArchipelagoClient.AP.Authenticated && PortEntry.activeSelf)
{
create.GetChild(12).GetComponent<TextMeshProUGUI>().GetComponent<TMP_Text>().text = "NAME\nBEAUTY\nCLASS\nPRONOUNS";
HostEntry.SetActive(value: false);
PortEntry.SetActive(value: false);
PasswordEntry.SetActive(value: false);
create.GetChild(18).gameObject.SetActive(value: true);
create.GetChild(11).gameObject.SetActive(value: true);
var count = 0;
var button = create.GetChild(11).GetComponent<UnityEngine.UI.Button>();
_log.LogInfo($"We were given {ArchipelagoClient.AP.SlotData.StartingClass}");
while (count < ArchipelagoClient.AP.SlotData.StartingClass)
{
button.onClick.Invoke();
count += 1;
}
create.GetChild(11).gameObject.SetActive(value: false);
create.GetChild(14).gameObject.SetActive(value: true);
create.GetChild(14).GetComponent<TextMeshProUGUI>().text = "ENDING\nSHOPS\nDROPS\nSWITCH\nDOOR";
create.GetChild(15).gameObject.SetActive(value: true);
create.GetChild(15).GetComponent<TextMeshProUGUI>().text = "SECRET\nER\nELEMENT\nREQ COIN\nFILLER";
create.GetChild(16).gameObject.SetActive(value: true);
create.GetChild(16).GetComponent<TextMeshProUGUI>().text = "NORMDROP\nDEATH";
create.GetChild(19).gameObject.SetActive(value: true);
create.GetChild(19).GetComponent<TextMeshProUGUI>().text = $"{Ending()}\n{Shopsanity()}\n{Drops()}\n{Switchlock()}\n{Doorlock()}";
create.GetChild(20).gameObject.SetActive(value: true);
create.GetChild(20).GetComponent<TextMeshProUGUI>().text = $"{Secretdoor()}\n{(ER())}\n{Elements()}\n{RequiredCoins()}\n{Filler()}";
create.GetChild(21).gameObject.SetActive(value: true);
create.GetChild(21).GetComponent<TextMeshProUGUI>().text = $"{NormalizedDrops()}\n{Death()}";
create.GetChild(8).gameObject.SetActive(value: true);
create.GetChild(9).gameObject.SetActive(value: true);
create.GetChild(17).gameObject.SetActive(value: true);
create.GetChild(26).gameObject.SetActive(value: true);
create.GetChild(7).GetChild(0).GetComponent<TextMeshProUGUI>().text = "Confirm";
}
return;
}
case "Gameover":
{
var load = GameObject.Find("PLAYER").transform.GetChild(1).GetChild(0).GetChild(2).GetChild(0);
if (!ArchipelagoClient.AP.Authenticated)
{
load.GetChild(0).GetComponent<TextMeshProUGUI>().text = "connect";
}
else
{
load.GetChild(0).GetComponent<TextMeshProUGUI>().text = "load";
}
return;
}
}
}
private static void FixConnectionInfoDisplay()
{
var create = GameObject.Find("PLAYER").transform.GetChild(1).GetChild(0).GetChild(4).GetChild(2);
create.GetChild(14).GetComponent<TextMeshProUGUI>().text = "ENDING\nSHOPS\nDROPS\nSWITCH\nDOOR";
create.GetChild(15).GetComponent<TextMeshProUGUI>().text = "SECRET\nER\nELEMENT\nREQ COIN\nFILLER";
create.GetChild(16).GetComponent<TextMeshProUGUI>().text = "NORMDROP\nDEATH";
create.GetChild(19).GetComponent<TextMeshProUGUI>().text = $"{Ending()}\n{Shopsanity()}\n{Drops()}\n{Switchlock()}\n{Doorlock()}";
create.GetChild(20).GetComponent<TextMeshProUGUI>().text = $"{Secretdoor()}\n{(ER())}\n{Elements()}\n{RequiredCoins()}\n{Filler()}";
create.GetChild(21).GetComponent<TextMeshProUGUI>().text = $"{NormalizedDrops()}\n{Death()}";
}
private static string Ending()
{
return GoalToString[ArchipelagoClient.AP.SlotData.Ending];
}
private static string Shopsanity()
{
return ArchipelagoClient.AP.SlotData.Shopsanity ? "Y" : "N";
}
private static string Drops()
{
return DropsanityToString[ArchipelagoClient.AP.SlotData.Dropsanity];
}
private static string Switchlock()
{
return ArchipelagoClient.AP.SlotData.Switchlock ? "Y" : "N";
}
private static string Doorlock()
{
return ArchipelagoClient.AP.SlotData.Doorlock ? "Y" : "N";
}
private static string Secretdoor()
{
return ArchipelagoClient.AP.SlotData.FalseWalls ? "Y" : "N";
}
private static string ER()
{
return ArchipelagoClient.AP.SlotData.EntranceRandomizer ? "Y" : "N";
}
private static string Elements()
{
return ArchipelagoClient.AP.SlotData.RandomElements ? "Y" : "N";
}
private static string RequiredCoins()
{
return ArchipelagoClient.AP.SlotData.RequiredCoins.ToString();
}
private static string Filler()
{
return ArchipelagoClient.AP.SlotData.Fillerbundle.ToString();
}
private static string NormalizedDrops()
{
return ArchipelagoClient.AP.SlotData.NormalizedDrops ? "Y": "N";
}
private static string Death()
{
return ArchipelagoClient.AP.SlotData.DeathLink ? "Y" : "N";
}
}
}