-
Notifications
You must be signed in to change notification settings - Fork 11
/
BetterContinents.FejdStartupPatch.cs
134 lines (126 loc) · 6.22 KB
/
BetterContinents.FejdStartupPatch.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
using System;
using System.ComponentModel;
using System.IO;
using HarmonyLib;
using UnityEngine.UI;
namespace BetterContinents
{
public partial class BetterContinents
{
[HarmonyPatch(typeof(FejdStartup))]
private class FejdStartupPatch
{
[HarmonyPostfix, HarmonyPatch("ShowConnectError")]
private static void ShowConnectErrorPrefix(Text ___m_connectionFailedError)
{
if (LastConnectionError != null)
{
___m_connectionFailedError.text = LastConnectionError;
LastConnectionError = null;
}
}
private static Presets presets = new Presets();
[HarmonyPostfix, HarmonyPatch("Start")]
private static void StartPostfix(FejdStartup __instance)
{
//if (ZNet.instance.IsDedicated())
// return;
Log("Start postfix");
presets.InitUI(__instance);
// Code from before I used an assetbundle instead...
// var newLabel = Instantiate(panel.Find("seed").gameObject, panel);
// ((RectTransform) newLabel.transform).anchoredPosition = new Vector2(-194.6217f, -160.95f);
// newLabel.GetComponent<Text>().text = "Preset";
//
// var templateInputField = panel.GetComponentInChildren<InputField>();
// var dropdownObject = DefaultControls.CreateDropdown(new DefaultControls.Resources
// {
// inputField = templateInputField.image.sprite,
// background = templateInputField.image.sprite,
// dropdown = templateInputField.image.sprite,
// standard = templateInputField.image.sprite,
// });
//
// var dropdown = dropdownObject.GetComponent<Dropdown>();
// dropdown.captionText.font = templateInputField.textComponent.font;
// dropdown.captionText.fontSize = templateInputField.textComponent.fontSize;
// dropdown.itemText.font = templateInputField.textComponent.font;
// dropdown.itemText.fontSize = templateInputField.textComponent.fontSize;
// dropdown.
//
// var dropdownTransform = (RectTransform) dropdownObject.transform;
// dropdownTransform.SetParent(panel);
// dropdownTransform.anchoredPosition = new Vector2(51.447f, -33f);
// dropdownTransform.sizeDelta = new Vector2(364.075f, 30f);
//
}
// [HarmonyPrefix, HarmonyPatch("MoveWorld")]
// private static void MoveWorldPrefix(FejdStartup __instance, World ___m_world, BackgroundWorker ___m_moveFileWorker)
// {
// // Same early out conditions as MoveWorld
// if (___m_world == null || ___m_moveFileWorker != null)
// {
// return;
// }
//
// // Move the .BetterContinents file if it exists. Not doing this async, unlike the rest of the copy, and it
// // might be by far the slowest bit.
// var moveTarget = __instance.GetMoveTarget(___m_world.m_fileSource);
// string sourcePath = ___m_world.GetMetaPath() + BetterContinents.ConfigFileExtension;
// string targetPath = ___m_world.GetMetaPath(moveTarget) + BetterContinents.ConfigFileExtension;
// if (moveTarget == FileHelpers.FileSource.Cloud)
// {
// if (File.Exists(sourcePath))
// {
// Log( $"Copying BetterContinents config file from {sourcePath} to {targetPath}");
// FileHelpers.FileCopyIntoCloud(sourcePath, targetPath);
// }
// }
// else if (___m_world.m_fileSource == FileHelpers.FileSource.Cloud)
// {
// if (FileHelpers.FileExistsCloud(sourcePath))
// {
// Log( $"Copying BetterContinents config file from {sourcePath} to {targetPath}");
// FileHelpers.FileCopyOutFromCloud(sourcePath, targetPath, true);
// }
// }
// else
// {
// string directoryName = Path.GetDirectoryName(targetPath);
// if (!Directory.Exists(directoryName))
// {
// Directory.CreateDirectory(directoryName);
// }
// if (File.Exists(sourcePath))
// {
// Log( $"Copying BetterContinents config file from {sourcePath} to {targetPath}");
// File.Copy(sourcePath, targetPath);
// }
// }
// if (___m_world.m_fileSource != FileHelpers.FileSource.Cloud)
// {
// if (File.Exists(sourcePath))
// {
// Log( $"Moving old BetterContinents config file from {sourcePath} to backup");
// FileHelpers.MoveToBackup(sourcePath, DateTime.Now);
// }
// }
// }
[HarmonyPrefix, HarmonyPatch("OnNewWorldDone")]
private static void OnNewWorldDonePrefix()
{
// Indicator to SaveWorldMetaDataPostfix that it should save a new BC config file using the
// selected preset, rather than saving the active worlds settings.
WorldPatch.bWorldBeingCreated = true;
Log($"[Saving] Setting the bWorldBeingCreated flag");
}
[HarmonyPostfix, HarmonyPatch("OnNewWorldDone")]
private static void OnNewWorldDonePostfix()
{
// Clear the flag again, ready for normal save operations
WorldPatch.bWorldBeingCreated = false;
Log($"[Saving] Clearing the bWorldBeingCreated flag again");
}
}
}
}