-
Notifications
You must be signed in to change notification settings - Fork 1
/
CyclopsDoorSaver.cs
105 lines (88 loc) · 4.27 KB
/
CyclopsDoorSaver.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
using FMOD;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using static ErrorMessage;
namespace Tweaks_Fixes
{
internal class CyclopsDoorSaver
{
static Dictionary<string, float> closedDoorsYangles = new Dictionary<string, float>() { { "submarine_hatch_01", 270f }, { "submarine_hatch_02 1", 180f }, { "submarine_hatch_02", 180f }, { "submarine_hatch_02 7", 0 }, { "submarine_hatch_02 3", 180f }, { "submarine_hatch_02 4", 0 } };
static bool IsDoorClosed(Openable openable)
{
if (!closedDoorsYangles.ContainsKey(openable.name) || !Main.configMain.cyclopsDoors.ContainsKey(SaveLoadManager.main.currentSlot))
return false;
//GameObject cyclopsRoot = Util.GetEntityRoot(openable.gameObject);
//if (cyclopsRoot == null)
// return false;
PrefabIdentifier prefabIdentifier = openable.GetComponentInParent<PrefabIdentifier>();
if (prefabIdentifier == null || prefabIdentifier.name == "__LIGHTMAPPED_PREFAB__")
return false;
//AddDebug("IsDoorClosed prefabIdentifier " + prefabIdentifier.name);
//Main.logger.LogMessage("IsDoorClosed prefabIdentifier " + prefabIdentifier.name);
var saved = Main.configMain.cyclopsDoors[SaveLoadManager.main.currentSlot];
return saved.ContainsKey(prefabIdentifier.id) && saved[prefabIdentifier.id].Contains(openable.name);
}
[HarmonyPatch(typeof(Openable), "Start")]
class Openable_Start_Patch
{
static void Prefix(Openable __instance)
{
//Main.logger.LogMessage("Openable Start " + __instance.name);
if (closedDoorsYangles.ContainsKey(__instance.name) && IsDoorClosed(__instance))
{
CloseDoor(__instance);
}
}
private static void CloseDoor(Openable openable)
{
openable.isOpen = false;
Vector3 rot = openable.transform.localEulerAngles;
float y = closedDoorsYangles[openable.name];
openable.transform.localEulerAngles = new Vector3(rot.x, y, rot.z);
}
}
static void SaveClosedDoor(Openable openable)
{
PrefabIdentifier prefabIdentifier = openable.GetComponentInParent<PrefabIdentifier>();
if (prefabIdentifier == null)
return;
//AddDebug(openable.name + " SaveClosedDoor prefabIdentifier.id " + prefabIdentifier.id);
string slot = SaveLoadManager.main.currentSlot;
if (!Main.configMain.cyclopsDoors.ContainsKey(slot))
Main.configMain.cyclopsDoors[slot] = new Dictionary<string, HashSet<string>>();
if (Main.configMain.cyclopsDoors[slot].ContainsKey(prefabIdentifier.id))
Main.configMain.cyclopsDoors[slot][prefabIdentifier.id].Add(openable.name);
else
Main.configMain.cyclopsDoors[slot][prefabIdentifier.id] = new HashSet<string>() { openable.name };
}
static void DeleteSavedDoor(Openable openable)
{
PrefabIdentifier prefabIdentifier = openable.GetComponentInParent<PrefabIdentifier>();
if (prefabIdentifier == null)
return;
//AddDebug(openable.name + " DeleteSavedDoor prefabIdentifier.id " + prefabIdentifier.id);
string slot = SaveLoadManager.main.currentSlot;
if (!Main.configMain.cyclopsDoors.ContainsKey(slot))
return;
if (Main.configMain.cyclopsDoors[slot].ContainsKey(prefabIdentifier.id))
Main.configMain.cyclopsDoors[slot][prefabIdentifier.id].Remove(openable.name);
}
[HarmonyPatch(typeof(Openable), "PlayOpenAnimation")]
class Openable_PlayOpenAnimation_Patch
{
static void Postfix(Openable __instance, bool openState, float duration)
{
if (!closedDoorsYangles.ContainsKey(__instance.name))
return;
if (openState == false)
SaveClosedDoor(__instance);
else
DeleteSavedDoor(__instance);
}
}
}
}