-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
380 lines (321 loc) · 14.6 KB
/
Plugin.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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
using System;
using System.IO;
using System.Collections.Generic;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements.Collections;
namespace DDSTerminalExtensions
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
[BepInProcess("DeadeyeDeepfakeSimulacrum.exe")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private void Awake()
{
Log = Logger;
Log.LogInfo($"Loading plugin...");
Harmony.CreateAndPatchAll(typeof(TerminalPatches), $"{PluginInfo.PLUGIN_GUID}.TerminalPatches");
Log.LogInfo($"Harmony patches are loaded!");
}
private void OnDestroy()
{
Log.LogInfo($"Unloading plugin...");
Harmony.UnpatchID($"{PluginInfo.PLUGIN_GUID}.TerminalPatches");
Log.LogInfo($"Plugin has been destroyed, goodbye!");
}
}
[HarmonyPatch(typeof(Terminal))]
class TerminalPatches
{
public static void HelpGeneral(Terminal __instance, string[] args)
{
__instance.helpBasic = "\n";
__instance.helpBasic += "Type HELPLOCAL for a list of localhost commands.\n";
__instance.helpBasic += "Type HELPREMOTE for a list of commands unique to your remotehost.\n";
__instance.helpBasic += "Type HELPSECRET for a list of secret commands.\n";
__instance.helpBasic += "Type HELPEXT for a list of commands added by DDSTerminalExtensions.\n";
}
public static void HelpSecret(Terminal __instance, string[] args)
{
string helpSecret = "\n";
helpSecret += "SECRET COMMANDS\n";
helpSecret += "--------------------\n";
helpSecret += "Hidden commands built into the game.\n";
helpSecret += "--------------------\n";
helpSecret += "RENAME_ME [NEW_NAME] -- renames the save/player\n";
helpSecret += "CHIPS_ -- gain 100 chips\n";
helpSecret += "DATUM_ -- gain 10 data\n";
helpSecret += "GODD_ -- enables godmode (until new scene)\n";
helpSecret += "GO_TO_SCENE_ [SCENE_NAME] -- loads given unity scene\n";
helpSecret += "HAVE_SEX_ -- uh\n";
helpSecret += "LOCKTOBER_ -- force unequip necklace\n";
helpSecret += "MIDAS_ -- gain $100,000\n";
helpSecret += "MOB_ -- gain 100 ego\n";
helpSecret += "SKIPP_ -- skips current mission\n";
helpSecret += "SPEND_ -- set spending level to 8 (WILL override level 9)\n";
__instance.WriteToTerminal(helpSecret);
}
public static void HelpExt(Terminal __instance, string[] args)
{
string helpExt = "\n";
helpExt += "TERMINALEXTENSIONS COMMANDS\n";
helpExt += "--------------------\n";
helpExt += "Commands added by the DDSTerminalExtensions mod.\n";
helpExt += "--------------------\n";
helpExt += "DUMP_MAP_ <FILENAME> -- dumps current scene's map\n";
helpExt += "UNGODD_ -- disables godmode\n";
helpExt += "COORDS_COMPUTER_ [COMPUTER_ID] -- gets coordinates of computer\n";
helpExt += "COORDS_PLAYER_ -- gets coordinates of the player\n";
helpExt += "TELEPORT_ [X] [Y] -- teleports player to x, y\n";
__instance.WriteToTerminal(helpExt);
}
public static readonly Dictionary<string, string> textureLookup = new()
{
{"Vidya", "obj/gamer_station"},
{"fridge", "obj/fridge"},
{"Keyboard", "obj/desktop"},
{"AmmoStation", "obj/ammo_station"},
{"RepairStation", "obj/repair_station"},
{"toilet", "obj/toilet"},
{"SlowRefill", "obj/slug_needle"},
{"CommunicationsArray", "obj/com_hub"},
};
public static void DumpMap(Terminal __instance, string[] args)
{
string filename;
if (args.Length > 1)
filename = args[1];
else
filename = "extracted.map";
__instance.WriteToTerminal("Starting map dump...");
var sr = File.CreateText(filename);
sr.NewLine = "\n";
sr.WriteLine($"MAP");
sr.WriteLine($"name: {SceneManager.GetActiveScene().name}");
sr.WriteLine($"cam_start: 0, 0");
sr.WriteLine($"");
GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType<GameObject>();
foreach (GameObject obj in allObjects)
{
Computer computer = obj.GetComponent<Computer>();
if (computer != null)
{
if (computer is Terminal || computer is GrenadeComputer)
continue;
sr.WriteLine($"OBJ");
sr.WriteLine($"name: {computer.computerID}");
sr.WriteLine($"position: {Math.Round(obj.transform.position.x, 4)}, {Math.Round(obj.transform.position.y, 4)}");
sr.WriteLine($"texture_name: {textureLookup.Get(computer.displaySprite.name, computer.displaySprite.name)}");
sr.WriteLine($"color: #{ColorUtility.ToHtmlStringRGB(computer.displayColor)}");
sr.WriteLine($"");
}
bool isDoor = obj.GetComponent<Door>() != null;
if (obj.tag == "Wall" || isDoor)
{
sr.WriteLine($"WALL");
if (isDoor)
sr.WriteLine($"type: door");
sr.WriteLine($"position: {Math.Round(obj.transform.position.x, 4)}, {Math.Round(obj.transform.position.y, 4)}");
Vector3 scale = obj.transform.lossyScale;
if (isDoor)
{
for (int i = 0; i < obj.transform.childCount; i++)
{
Transform child = obj.transform.GetChild(i);
if (child.tag != "Door")
continue;
scale.x = child.lossyScale.x * 2;
scale.y = child.lossyScale.y;
break;
}
if (obj.transform.rotation.z != 0)
{
scale.z = scale.y;
scale.y = scale.x;
scale.x = scale.z;
}
}
else
{
if (obj.transform.parent.transform.rotation.z != 0)
{
scale.z = scale.y;
scale.y = scale.x;
scale.x = scale.z;
}
}
sr.WriteLine($"scale: {Math.Round(scale.x, 2)}, {Math.Round(scale.y, 2)}");
sr.WriteLine($"");
}
}
sr.Close();
__instance.WriteToTerminal($"Map dumped to {filename}!");
}
public static void GetCoordsComputer(Terminal __instance, string[] args)
{
string computerID;
if (args.Length > 1)
computerID = args[1];
else
{
__instance.WriteToTerminal("Please specify target computer name.");
return;
}
GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType<GameObject>();
foreach (GameObject obj in allObjects)
{
Computer computer = obj.GetComponent<Computer>();
if (computer != null)
{
if (computer.computerID == computerID)
__instance.WriteToTerminal($"{computer.computerID} -- {obj.transform.position.x}, {obj.transform.position.y}");
}
}
}
public static void GetCoordsPlayer(Terminal __instance, string[] args)
{
GameObject player = __instance.playerCyborg.gameObject;
__instance.WriteToTerminal($"player -- {player.transform.position.x}, {player.transform.position.y}");
}
public static void UnGod(Terminal __instance, string[] args)
{
__instance.playerCyborg.godMode = 0;
}
public static void Teleport(Terminal __instance, string[] args)
{
float x, y;
if (args.Length > 2) {
if (!float.TryParse(args[1], out x))
{
__instance.WriteToTerminal("x coordinate is not a number.");
return;
}
if (!float.TryParse(args[2], out y))
{
__instance.WriteToTerminal("y coordinate is not a number.");
return;
}
}
else
{
__instance.WriteToTerminal("Please specify x and y coordinates.");
return;
}
GameObject player = __instance.playerCyborg.gameObject;
player.transform.position = new Vector3(x, y, player.transform.position.z);
}
public delegate void Command(Terminal __instance, string[] args);
public static readonly Dictionary<string, Command> commandLookup = new()
{
{"hs", HelpSecret},
{"helpsecret", HelpSecret},
{"he", HelpExt},
{"helpext", HelpExt},
{"dump_map_", DumpMap},
{"coords_computer_", GetCoordsComputer},
{"coords_player_", GetCoordsPlayer},
{"ungodd_", UnGod},
{"teleport_", Teleport},
// COMMAND OVERRIDES
{"help", HelpGeneral},
};
[HarmonyPrefix]
[HarmonyPatch("ProcessInput")]
public static bool ProcessInputPatch(Terminal __instance, string input)
{
string[] cmdArray = input.ToLower().Split(' ');
commandLookup.Get(cmdArray[0])?.Invoke(__instance, cmdArray);
return true;
}
[HarmonyPostfix]
[HarmonyPatch("Start")]
public static void StartPost(Terminal __instance)
{
int fontSize = __instance.inputField.textComponent.fontSize;
FontStyle fontStyle = __instance.inputField.textComponent.fontStyle;
__instance.inputField.textComponent.font.RequestCharactersInTexture("x", fontSize, fontStyle);
__instance.inputField.textComponent.font.GetCharacterInfo('x', out CharacterInfo characterInfo, fontSize);
__instance.inputField.caretWidth = characterInfo.advance;
__instance.inputField.customCaretColor = true;
__instance.inputField.caretColor = new Color(1, 1, 1, 0.4f);
}
[HarmonyPrefix]
[HarmonyPatch("GoBackInHistory")]
public static bool GoBackInHistoryPatch(Terminal __instance)
{
var traverse = Traverse.Create(__instance);
int inputHistoryIndex = traverse.Field("inputHistoryIndex").GetValue() as int? ?? 0;
List<string> inputHistory = traverse.Field("inputHistory").GetValue() as List<string>;
if (inputHistoryIndex > 0)
{
inputHistoryIndex--;
if (inputHistoryIndex < inputHistory.Count)
__instance.inputField.text = inputHistory[inputHistoryIndex];
}
else
{
inputHistoryIndex = -1;
__instance.inputField.text = "";
}
__instance.inputField.caretPosition = __instance.inputField.text.Length;
traverse.Field("inputHistoryIndex").SetValue(inputHistoryIndex);
return false;
}
[HarmonyPrefix]
[HarmonyPatch("GoForwardInHistory")]
public static bool GoForwardInHistoryPatch(Terminal __instance)
{
var traverse = Traverse.Create(__instance);
int inputHistoryIndex = traverse.Field("inputHistoryIndex").GetValue() as int? ?? 0;
List<string> inputHistory = traverse.Field("inputHistory").GetValue() as List<string>;
if (inputHistoryIndex < inputHistory.Count - 1)
{
inputHistoryIndex++;
if (inputHistoryIndex < inputHistory.Count)
__instance.inputField.text = inputHistory[inputHistoryIndex];
}
else
{
inputHistoryIndex = inputHistory.Count;
__instance.inputField.text = "";
}
__instance.inputField.caretPosition = __instance.inputField.text.Length;
traverse.Field("inputHistoryIndex").SetValue(inputHistoryIndex);
return false;
}
[HarmonyPostfix]
[HarmonyPatch("Update")]
public static void UpdatePost(Terminal __instance)
{
var traverse = Traverse.Create(__instance);
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.C))
{
__instance.inputField.text = "";
List<string> inputHistory = traverse.Field("inputHistory").GetValue() as List<string>;
traverse.Field("inputHistoryIndex").SetValue(inputHistory.Count);
}
}
[HarmonyPrefix]
[HarmonyPatch("LateUpdate")]
public static bool LateUpdatePatch(Terminal __instance)
{
var traverse = Traverse.Create(__instance);
bool inputFieldActive = traverse.Field("inputFieldActive").GetValue() as bool? ?? false;
bool hackingOpen = (traverse.Field("hackManager").GetValue() as HackManager).hackingOpen;
if (inputFieldActive && hackingOpen)
{
traverse.Field("savedInput").SetValue(__instance.inputField.text);
__instance.inputField.enabled = true;
__instance.inputField.Select();
__instance.inputField.ActivateInputField();
}
else
__instance.inputField.DeactivateInputField();
return false;
}
}
}