-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.cs
More file actions
414 lines (374 loc) · 15.4 KB
/
Main.cs
File metadata and controls
414 lines (374 loc) · 15.4 KB
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
using Epic.OnlineServices;
using HarmonyLib;
using NewHorizons.Components.Orbital;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using NewHorizons.Utility.OWML;
using OWML.Common;
using OWML.ModHelper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
namespace Axiom
{
public class Main : ModBehaviour
{
private static Main instance;
private INewHorizons _newHorizons;
public static IModConsole ConsoleInstance => instance.ModHelper.Console;
public static INewHorizons NewHorizonsInstance => instance._newHorizons;
private void Awake()
{
instance = this;
}
public static Dictionary<AudioType, string> AudiosToReplace = new Dictionary<AudioType, string>
{
{
AudioType.EndOfTime,
"audio/End Times (Short) 041013 AP.wav"
},
{
AudioType.Travel_Theme,
"audio/OW 110912 AP.wav"
},
{
AudioType.ShipCockpitAutopilotActivate,
"audio/Computer_Interface_Retro.wav"
},
{
AudioType.PlayerSuitJetpackBoost,
"audio/JetPack.wav"
},
{
AudioType.PlayerSuitCriticalWarning,
"audio/JetPack_NotificationBeep.wav"
},
{
AudioType.PlayerSuitOxygenRefill,
"audio/OxygenRefill_Breath.wav"
},
{
AudioType.ShipCockpitProbeLaunch,
"audio/ProbeLaunch_HighPower.wav"
},
{
AudioType.ShipCockpitProbeLaunchUnderwater,
"audio/ProbeLaunch_LowPower.wav"
},
{
AudioType.ShipCabinAmbience,
"audio/SpaceshipAmbience_louder.wav"
},
{
AudioType.PlayerBreathing_LP,
"audio/SpacesuitAmbience.wav"
},
{
AudioType.PlayerSuitRemoveSuit,
"audio/SuitOff.wav"
},
{
AudioType.PlayerSuitWearSuit,
"audio/SuitUp_Faster.wav"
},
{
AudioType.Sun_Ambience_LP,
"audio/Sun_Surface.wav"
},
{
AudioType.Sun_Explosion,
"audio/Supernova_Explosion3.wav"
},
{
AudioType.Sun_Collapse,
"audio/Supernova_Start2_Longer.wav"
},
{
AudioType.Sun_SupernovaWall_LP,
"audio/Supernova_Wave4.wav"
},
{
AudioType.TH_ZeroGTrainingAllRepaired,
"audio/SystemBackOnline.wav"
},
{
AudioType.ShipThrustIgnition,
"audio/ThrusterIgnition_crossfade.wav"
},
{
AudioType.ShipThrustTranslational_LP,
"audio/Thrusters_HighPower_New.wav"
},
{
AudioType.ShipThrustTranslationalUnderwater_LP,
"audio/Thrusters_LowPower_New.wav"
},
{
AudioType.Flashback_End,
"audio/TimeLoop_End_LOUD.wav"
},
{
AudioType.Flashback_Overlay_1_LP,
"audio/TimeLoop_Middle_LOUD.wav"
},
{
AudioType.Flashback_Overlay_2_LP,
"audio/TimeLoop_Middle_LOUD.wav"
},
{
AudioType.Flashback_Base_LP,
"audio/TimeLoop_Middle_LOUD.wav"
},
{
AudioType.GD_UnderwaterAmbient_LP,
"audio/UnderWaterAmbience.wav"
},
{
AudioType.TH_Observatory,
"audio/Observatory 062913 AP.wav"
},
};
public const int EndOfTime = (int)AudioType.EndOfTime;
public static bool AlphaSFX = true;
private void Start()
{
_newHorizons = ModHelper.Interaction.TryGetModApi<INewHorizons>("xen.NewHorizons");
_newHorizons.LoadConfigs(this);
LoadAllClips(); //load audio
new HarmonyLib.Harmony("MegaPiggy.Axiom").PatchAll(Assembly.GetExecutingAssembly());
ModHelper.HarmonyHelper.AddPostfix<AudioManager>(nameof(AudioManager.Awake), typeof(Main), nameof(Main.ReplaceInAudioManager));
ModHelper.HarmonyHelper.AddPostfix<AudioLibrary>(nameof(AudioLibrary.BuildAudioEntryDictionary), typeof(Main), nameof(Main.ReplaceInAudioLibrary));
_newHorizons.GetBodyLoadedEvent().AddListener((string name) =>
{
if (_newHorizons.GetCurrentStarSystem() == "Jam3")
{
if (name == "Axiom") OnAxiomLoaded(_newHorizons.GetPlanet("Axiom"));
else if (name == "Aicale") OnAicaleLoaded(_newHorizons.GetPlanet("Aicale"));
else if (name == "Broken Satellite") OnBrokenSatelliteLoaded(_newHorizons.GetPlanet("Broken Satellite"));
}
});
}
public override void Configure(IModConfig config)
{
AlphaSFX = config.GetSettingsValue<bool>("alphaSFX");
}
private void OnAxiomLoaded(GameObject axiom)
{
ModHelper.Console.WriteLine("Axiom has loaded", MessageType.Info);
axiom.transform.Find("Sector/IcePlanet/Interior/Details/TreeHouseIsland").gameObject.SetActive(false); // Disable for now until I can make it less laggy
HandleMaterials(axiom);
}
private void OnAicaleLoaded(GameObject aicale)
{
ModHelper.Console.WriteLine("Aicale has loaded", MessageType.Info);
var astroObject = aicale.GetComponent<NHAstroObject>();
astroObject._primaryBody._moon = astroObject;
HandleMaterials(aicale);
}
private void OnBrokenSatelliteLoaded(GameObject brokenSatellite)
{
ModHelper.Console.WriteLine("Broken Satellite has loaded", MessageType.Info);
//brokenSatellite.AddComponent<AlignWithJamSun>();
brokenSatellite.GetComponent<Rigidbody>().mass = 10;
var astroObject = brokenSatellite.GetComponent<NHAstroObject>();
astroObject._primaryBody._satellite = astroObject;
astroObject._type = AstroObject.Type.Satellite;
brokenSatellite.GetComponentInChildren<Camera>().fieldOfView = 40;
brokenSatellite.GetComponentInChildren<NoiseImageEffect>()._strength = 0.25f;
var satelliteSnapshot = astroObject._primaryBody.GetComponentInChildren<SatelliteSnapshotController>(true);
satelliteSnapshot._satelliteCamera = brokenSatellite.GetComponentInChildren<OWCamera>();
satelliteSnapshot._probeMesh = brokenSatellite.GetComponentInChildren<BrokenSatelliteManager>().transform.Find("BrokenSatellite/center").GetComponent<MeshRenderer>();
satelliteSnapshot.gameObject.SetActive(true);
HandleMaterials(brokenSatellite);
}
public static void HandleMaterials(GameObject gameObject)
{
instance.ModHelper.Events.Unity.FireOnNextUpdate(() =>
{
SurfaceManager surfaceManager = GameObject.FindObjectOfType<SurfaceManager>();
var handled = new List<string>();
var rndrs = gameObject.GetComponentsInChildren<MeshRenderer>(true);
foreach (var rndr in rndrs)
{
foreach (var mat in rndr.sharedMaterials)
{
if (mat == null) continue;
if (handled.Contains(mat.name)) continue;
handled.Add(mat.name);
SurfaceType type = GetSurfaceType(mat);
if (type != SurfaceType.None)
{
surfaceManager._lookupTable.SafeAdd(mat, type);
}
}
}
});
}
public static SurfaceType GetSurfaceType(Material mat)
{
instance.ModHelper.Console.WriteLine("Surface material: \"" + mat.name + "\"", MessageType.Warning);
switch (mat.name)
{
case "Planet1Mtl":
case "SnowBrick1Mtl":
return SurfaceType.Snow;
case "Ice1Mtl":
return SurfaceType.Ice;
case "ElevatorShaft_Color_0":
case "SatelliteDish_Winch_Color":
case "Wood1Mtl":
case "Wood2Mtl":
case "WoodBeamMat":
case "DarkWood":
case "DoorFrameAndWindow":
case "RoofFoundation":
case "Railing":
return SurfaceType.Wood;
case "shack_mat":
case "cabin_mat":
case "porchCabin_mat":
case "Cabin1Mtl":
case "FloorPlanks":
case "RoofPlanks":
case "SidePlanks":
case "observatoryFloorMat":
return SurfaceType.Planks;
case "Skull_Color":
return SurfaceType.Bone;
case "observatoryCeilingMat":
return SurfaceType.Ceramic;
case "TreeLeaves":
case "OuterLeaves":
case "InnerLeaves":
return SurfaceType.Grass;
case "RadioSpeakerMat":
case "OuterRug":
case "InnerRug":
return SurfaceType.Fabric;
case "At1Base1Mtl":
case "Cube0141Mtl":
case "Pic1Mtl":
return SurfaceType.GrittyRock;
case "Icosphere0031Mtl":
return SurfaceType.QuantumRock;
case "Part1Mtl":
return SurfaceType.Obsidian;
case "CrystalMat":
case "CrystalSconceMat":
case "crystalSpireMat":
case "AncientCrystalMat":
return SurfaceType.Crystal;
case "HoloProjectorMat":
return SurfaceType.MetalNomai;
case "Glass":
case "Glass_0":
case "displayCase":
case "FishTankGlass":
case "telescopeLensMat":
return SurfaceType.Glass;
case "FishTankMat":
case "Plaque_Color":
case "plaqueMat":
case "Metal1Mtl":
case "SatelliteDish_Color":
case "RadioMat":
case "RadioAntennaMat":
case "CairnLamp_Color":
case "StreetlampMat":
case "telescopeBodyMat":
case "telescopeArmsMat":
return SurfaceType.Metal;
case "LandingPlatform_Color":
case "observatoryWallsMat":
case "Well":
return SurfaceType.Stone;
case "FakeWater":
case "WellWater":
return SurfaceType.Water;
default: return SurfaceType.None;
}
}
public static void ReplaceInAudioManager(AudioManager __instance)
{
if (!AlphaSFX) return;
//The audio dictionary is a dictionary containing all of the sounds, matched to the int value of the AudioType enum
foreach (var pair in AudiosToReplace)
{
var type = pair.Key;
var path = pair.Value;
if (__instance._audioLibraryDict.ContainsKey((int)type))
__instance._audioLibraryDict[(int)type] = new AudioLibrary.AudioEntry(type, GetClips(path), 1f);
else
__instance._audioLibraryDict.Add((int)type, new AudioLibrary.AudioEntry(type, GetClips(path), 1f));
}
}
public static void ReplaceInAudioLibrary(ref Dictionary<int, AudioLibrary.AudioEntry> __result)
{
if (!AlphaSFX) return;
//The audio dictionary is a dictionary containing all of the sounds, matched to the int value of the AudioType enum
foreach (var pair in AudiosToReplace)
{
var type = pair.Key;
var path = pair.Value;
if (__result.ContainsKey((int)type))
__result[(int)type] = new AudioLibrary.AudioEntry(type, GetClips(path), 1f);
else
__result.Add((int)type, new AudioLibrary.AudioEntry(type, GetClips(path), 1f));
}
}
public static Dictionary<string, AudioClip> LoadedClips = new Dictionary<string, AudioClip>();
private static AudioClip[] LoadAllClips() => AudiosToReplace.Values.Select(path => GetClip(path)).ToArray();
private static AudioClip[] GetClips(string path) => new AudioClip[1] { GetClip(path) };
private static AudioClip GetClip(string path)
{
if (LoadedClips.ContainsKey(path)) return LoadedClips[path]; //If it's already loaded, give the one in memory
AudioClip audioClip = instance.ModHelper.Assets.GetAudio(path); //Else load it
LoadedClips[path] = audioClip;
return audioClip;
}
}
[HarmonyPatch(typeof(OWExtensions), nameof(OWExtensions.Assert), new Type[] { typeof(Collider), typeof(LayerMask), typeof(bool) })]
public static class AssertPatch
{
public static void Prefix(Collider collider, LayerMask layerMask, bool isTrigger)
{
if (!OWLayerMask.IsLayerInMask(collider.gameObject.layer, layerMask))
{
Main.ConsoleInstance.WriteLine("\"" + collider.transform.GetPath() + "\" collider is not in the \"" + LayerMask.LayerToName(layerMask.value) + "\" | #" + layerMask.value + " LayerMask!", MessageType.Error);
}
if (collider.isTrigger != isTrigger)
{
Main.ConsoleInstance.WriteLine("\"" + collider.transform.GetPath() + "\" isTrigger should be set to " + isTrigger, MessageType.Error);
}
}
}
[HarmonyPatch(typeof(Sector), nameof(Sector.Awake))]
public static class SectorPatch
{
public static void Prefix(Sector __instance)
{
var triggerRoot = __instance._triggerRoot;
if (triggerRoot == null)
{
Main.ConsoleInstance.WriteLine(__instance.transform.GetPath() + " does not have a trigger root. Defaulting to self.", MessageType.Debug);
triggerRoot = __instance.gameObject;
}
var proximityTrigger = triggerRoot.GetComponent<ProximityTrigger>();
if (proximityTrigger != null)
{
return;
}
var owTriggerVolume = triggerRoot.GetComponent<OWTriggerVolume>();
if (owTriggerVolume != null)
{
return;
}
Main.ConsoleInstance.WriteLine("Could not find any triggers for Sector " + __instance.transform.GetPath(), MessageType.Error);
}
}
}