|
2 | 2 | using HarmonyLib; |
3 | 3 | using Newtonsoft.Json.Linq; |
4 | 4 | using Polytopia.Data; |
| 5 | +using PolytopiaBackendBase.Game; |
5 | 6 | using System.Diagnostics; |
6 | 7 | using System.Text; |
7 | 8 | using System.Text.Json; |
@@ -70,13 +71,71 @@ private static bool IL2CPPUnityLogSource_UnityLogCallback(string logLine, string |
70 | 71 | return true; |
71 | 72 | } |
72 | 73 |
|
| 74 | + [HarmonyPrefix] |
| 75 | + [HarmonyPatch(typeof(GameModeScreen), nameof(GameModeScreen.Init))] |
| 76 | + private static void GameModeScreen_Init(GameModeScreen __instance) |
| 77 | + { |
| 78 | + List<GamemodeButton> list = __instance.buttons.ToList(); |
| 79 | + for (int i = 0; i < Loader.gamemodes.Count; i++) |
| 80 | + { |
| 81 | + var item = Loader.gamemodes[i]; |
| 82 | + var button = GameObject.Instantiate(__instance.buttons[2]); |
| 83 | + list.Add(button); |
| 84 | + Loader.gamemodes[i] = new Loader.GameModeButtonsInformation(item.gameModeIndex, item.action, __instance.buttons.Length, item.sprite); |
| 85 | + } |
| 86 | + |
| 87 | + var newArray = list.ToArray(); |
| 88 | + for (int i = 0; i < __instance.buttons.Length; i++) |
| 89 | + { |
| 90 | + if (newArray[i] != null) newArray[i].OnClicked = __instance.buttons[i].OnClicked; |
| 91 | + } |
| 92 | + |
| 93 | + for (int i = 0; i < Loader.gamemodes.Count; i++) |
| 94 | + { |
| 95 | + if (Loader.gamemodes[i].buttonIndex != null) |
| 96 | + newArray[Loader.gamemodes[i].buttonIndex!.Value].OnClicked = Loader.gamemodes[i].action; |
| 97 | + } |
| 98 | + |
| 99 | + __instance.buttons = newArray; |
| 100 | + |
| 101 | + for (int i = 0; i < __instance.buttons.Length; i++) |
| 102 | + { |
| 103 | + GamemodeButton button = __instance.buttons[i]; |
| 104 | + var newData = button.gamemodeData.ToList(); |
| 105 | + foreach (var info in Loader.gamemodes) |
| 106 | + { |
| 107 | + string id = EnumCache<GameMode>.GetName((GameMode)info.gameModeIndex).ToLower(); |
| 108 | + newData.Add(new GamemodeButton.GamemodeButtonData() |
| 109 | + { |
| 110 | + gameMode = (GameMode)info.gameModeIndex, |
| 111 | + id = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(id), |
| 112 | + descriptionKey = "gamemode." + id + ".description.button", |
| 113 | + headerKey = "gamemode." + id + ".caps", |
| 114 | + icon = info.sprite |
| 115 | + }); |
| 116 | + } |
| 117 | + button.gamemodeData = newData.ToArray(); |
| 118 | + |
| 119 | + for (int j = 0; j < Loader.gamemodes.Count; j++) |
| 120 | + { |
| 121 | + Loader.GameModeButtonsInformation info = Loader.gamemodes[j]; |
| 122 | + |
| 123 | + if(info.buttonIndex == i) |
| 124 | + { |
| 125 | + button.SetGamemode(info.buttonIndex.Value); |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + |
73 | 131 | internal static void Init() |
74 | 132 | { |
75 | 133 | stopwatch.Start(); |
76 | 134 | Harmony.CreateAndPatchAll(typeof(Main)); |
77 | 135 | Mod.Manifest polytopia = new( |
78 | 136 | "polytopia", |
79 | 137 | "The Battle of Polytopia", |
| 138 | + null, |
80 | 139 | new(Application.version.ToString()), |
81 | 140 | new string[] { "Midjiwan AB" }, |
82 | 141 | Array.Empty<Mod.Dependency>() |
@@ -131,21 +190,31 @@ internal static void Load(JObject gameLogicdata) |
131 | 190 | if (mod.status != Mod.Status.Success) continue; |
132 | 191 | foreach (var file in mod.files) |
133 | 192 | { |
134 | | - if (Path.GetFileName(file.name) == "patch.json") |
135 | | - { |
136 | | - Loader.LoadGameLogicDataPatch(mod, gameLogicdata, JObject.Parse(new StreamReader(new MemoryStream(file.bytes)).ReadToEnd())); |
137 | | - } |
138 | | - if (Path.GetFileName(file.name) == "localization.json") |
| 193 | + switch (Path.GetFileName(file.name)) |
139 | 194 | { |
140 | | - Loader.LoadLocalizationFile(mod, file); |
| 195 | + case "patch.json": |
| 196 | + Loader.LoadGameLogicDataPatch( |
| 197 | + mod, |
| 198 | + gameLogicdata, |
| 199 | + JObject.Parse(new StreamReader(new MemoryStream(file.bytes)).ReadToEnd()) |
| 200 | + ); |
| 201 | + break; |
| 202 | + case "localization.json": |
| 203 | + Loader.LoadLocalizationFile(mod, file); |
| 204 | + break; |
141 | 205 | } |
142 | | - if (Path.GetExtension(file.name) == ".png") |
143 | | - { |
144 | | - Loader.LoadSpriteFile(mod, file); |
145 | | - } |
146 | | - if (Path.GetExtension(file.name) == ".wav") |
| 206 | + |
| 207 | + switch (Path.GetExtension(file.name)) |
147 | 208 | { |
148 | | - Loader.LoadAudioFile(mod, file); |
| 209 | + case ".png": |
| 210 | + Loader.LoadSpriteFile(mod, file); |
| 211 | + break; |
| 212 | + case ".wav": |
| 213 | + Loader.LoadAudioFile(mod, file); |
| 214 | + break; |
| 215 | + case ".bundle": |
| 216 | + Loader.LoadAssetBundle(mod, file); |
| 217 | + break; |
149 | 218 | } |
150 | 219 | } |
151 | 220 | } |
|
0 commit comments