-
Notifications
You must be signed in to change notification settings - Fork 1
/
DumpostorPlugin.cs
172 lines (138 loc) · 5.14 KB
/
DumpostorPlugin.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
global using static Reactor.Utilities.Logger<Dumpostor.DumpostorPlugin>;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using AmongUs.GameOptions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using Dumpostor.Dumpers;
using Dumpostor.Dumpers.Map;
using HarmonyLib;
using InnerNet;
using Reactor;
using Reactor.Utilities;
using Reactor.Utilities.Extensions;
using UnityEngine;
namespace Dumpostor;
[BepInAutoPlugin]
[BepInProcess("Among Us.exe")]
[BepInDependency(ReactorPlugin.Id)]
public sealed partial class DumpostorPlugin : BasePlugin
{
internal static JsonSerializerOptions JsonSerializerOptions { get; } = new()
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters =
{
new JsonStringEnumConverter(),
new Vector2Converter(),
},
};
internal static LanguageUnit EnglishLanguageUnit { get; set; }
public Harmony Harmony { get; } = new(Id);
public ConfigEntry<string> DumpPath { get; private set; }
public override void Load()
{
DumpPath = Config.Bind("Settings", "DumpPath", "dump");
if (Environment.GetEnvironmentVariable("DUMPOSTOR_DISABLE") != null)
{
Warning("Dumpostor is disabled with an environment variable");
return;
}
Harmony.PatchAll();
var dumpPath = DumpPath.Value;
if (string.IsNullOrEmpty(dumpPath) || !Directory.Exists(dumpPath))
{
Error("DumpedPath is empty or is not a directory");
Application.Quit();
return;
}
EntrypointPatch.Initialized += () =>
{
Coroutines.Start(Dump(dumpPath));
};
}
private IEnumerator Dump(string dumpPath)
{
Debug("Dumping to " + dumpPath);
DummyMapLoadHacks.Initialize();
var spawnableObjects = new Dictionary<uint, InnerNetObject>();
yield return LoadSpawnableObjects(spawnableObjects);
var dumpers = new IDumper[]
{
new InfoDumper(),
new SpawnableObjectsDumper(spawnableObjects),
// new TranslationsDumper(),
new ColorDumper(),
new EnumDumper<DisconnectReasons>(),
new EnumDumper<SanctionReasons>(),
new EnumDumper<GameKeywords>(),
new EnumDumper<GameOverReason>(),
new EnumDumper<Platforms>(),
new EnumDumper<RoleTypes>(),
new EnumDumper<StringNames>(),
new EnumDumper<SystemTypes>(),
new EnumDumper<SupportedLangs>(),
new EnumDumper<TaskTypes>(),
new EnumDumper<RpcCalls>(),
};
foreach (var dumper in dumpers)
{
Info("Dumping " + dumper);
var outputPath = Path.Combine(dumpPath, dumper.FileName);
Directory.CreateDirectory(Path.GetDirectoryName(outputPath)!);
File.WriteAllText(outputPath, dumper.Dump());
}
var mapsDirectory = Path.Combine(dumpPath, "maps");
Directory.CreateDirectory(mapsDirectory);
var mapDumpers = new IMapDumper[]
{
new SpawnDumper(),
new SystemsDumper(),
new TaskDumper(),
new VentDumper(),
new DoorsDumper(),
};
foreach (var spawnableObject in spawnableObjects.Values)
{
var shipStatusPrefab = spawnableObject.GetComponent<ShipStatus>();
if (shipStatusPrefab == null) continue;
var name = shipStatusPrefab.name.RemoveSuffix("Ship");
var mapDirectory = Path.Combine(mapsDirectory, name);
Directory.CreateDirectory(mapDirectory);
Info("Dumping map " + name);
var shipStatus = UnityEngine.Object.Instantiate(shipStatusPrefab);
foreach (var dumper in mapDumpers)
{
Info("Dumping " + dumper);
var outputPath = Path.Combine(mapDirectory, dumper.FileName);
Directory.CreateDirectory(Path.GetDirectoryName(outputPath)!);
File.WriteAllText(outputPath, dumper.Dump(shipStatus));
}
shipStatus.DestroyImmediate();
}
Info("Dumped");
Application.Quit();
}
private static IEnumerator LoadSpawnableObjects(Dictionary<uint, InnerNetObject> spawnableObjects)
{
foreach (var spawnableObject in AmongUsClient.Instance.NonAddressableSpawnableObjects)
{
spawnableObjects.Add(spawnableObject.SpawnId, spawnableObject);
}
for (var spawnId = 0; spawnId < AmongUsClient.Instance.SpawnableObjects.Count; spawnId++)
{
var assetReference = AmongUsClient.Instance.SpawnableObjects[spawnId];
if (assetReference == null) continue;
var handle = assetReference.LoadAssetAsync<GameObject>();
while (!handle.IsDone) yield return null;
if (handle.Result == null) continue;
spawnableObjects.Add((uint)spawnId, handle.Result.GetComponent<InnerNetObject>());
}
}
}