From b8525529042e98ae13846eebd69aa5e007607f29 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 17 Apr 2025 12:52:21 +0200 Subject: [PATCH 1/4] Update to 2.12.3 --- PolyMod.csproj | 6 +-- src/Loader.cs | 8 ++-- src/Managers/Hub.cs | 93 ++++++++++++++++++++++++++++++--------------- src/NullableFix.cs | 23 +++++++++++ 4 files changed, 92 insertions(+), 38 deletions(-) create mode 100644 src/NullableFix.cs diff --git a/PolyMod.csproj b/PolyMod.csproj index 16f3018..f860b50 100644 --- a/PolyMod.csproj +++ b/PolyMod.csproj @@ -10,8 +10,8 @@ https://polymod.dev/nuget/v3/index.json; IL2CPP - 1.1.6 - 2.12.2.13970 + 1.1.7 + 2.12.3.14031 PolyModdingTeam The Battle of Polytopia's mod loader. IDE0130 @@ -19,7 +19,7 @@ - + diff --git a/src/Loader.cs b/src/Loader.cs index ea28e85..8ffc363 100644 --- a/src/Loader.cs +++ b/src/Loader.cs @@ -303,10 +303,10 @@ public static void LoadSpriteInfoFile(Mod mod, Mod.File file) public static void LoadAudioFile(Mod mod, Mod.File file) { - AudioSource audioSource = new GameObject().AddComponent(); - GameObject.DontDestroyOnLoad(audioSource); - audioSource.clip = Managers.Audio.BuildAudioClip(file.bytes); - Registry.audioClips.Add(Path.GetFileNameWithoutExtension(file.name), audioSource); + //AudioSource audioSource = new GameObject().AddComponent(); + //GameObject.DontDestroyOnLoad(audioSource); + //audioSource.clip = Managers.Audio.BuildAudioClip(file.bytes); + //Registry.audioClips.Add(Path.GetFileNameWithoutExtension(file.name), audioSource); } public static void LoadGameLogicDataPatch(Mod mod, JObject gld, JObject patch) diff --git a/src/Managers/Hub.cs b/src/Managers/Hub.cs index ae5cbd2..9bee0fc 100644 --- a/src/Managers/Hub.cs +++ b/src/Managers/Hub.cs @@ -1,5 +1,6 @@ using Cpp2IL.Core.Extensions; using HarmonyLib; +using Il2CppInterop.Runtime; using TMPro; using UnityEngine; using UnityEngine.EventSystems; @@ -43,37 +44,67 @@ private static void PopupButtonContainer_SetButtonData(PopupButtonContainer __in [HarmonyPatch(typeof(StartScreen), nameof(StartScreen.Start))] private static void StartScreen_Start() { - GameObject originalText = GameObject.Find("SettingsButton/DescriptionText"); - GameObject text = GameObject.Instantiate(originalText, originalText.transform.parent.parent.parent); - text.name = "PolyModVersion"; - RectTransform rect = text.GetComponent(); - rect.anchoredPosition = new(265, 40); - rect.sizeDelta = new(500, rect.sizeDelta.y); - rect.anchorMax = new(0, 0); - rect.anchorMin = new(0, 0); - text.GetComponent().fontSize = 18; - text.GetComponent().alignment = TextAlignmentOptions.BottomLeft; - text.GetComponent().Text = $"PolyMod {Plugin.VERSION}"; - text.AddComponent().ignoreLayout = true; - - GameObject originalButton = GameObject.Find("StartScreen/NewsButton"); - GameObject button = GameObject.Instantiate(originalButton, originalButton.transform.parent); - button.gameObject.name = "PolyModHubButton"; - button.transform.position = originalButton.transform.position - new Vector3(90, 0, 0); - button.active = true; - - Transform descriptionText = button.transform.Find("DescriptionText"); - descriptionText.gameObject.SetActive(true); - descriptionText.GetComponentInChildren().Key = "polymod.hub"; - - UIRoundButton buttonObject = button.GetComponent(); - buttonObject.bg.sprite = Visual.BuildSprite(Plugin.GetResource("polymod_icon.png").ReadBytes()); - buttonObject.bg.transform.localScale = new Vector3(1.2f, 1.2f, 0); - buttonObject.bg.color = Color.white; - - buttonObject.outline.gameObject.SetActive(false); - buttonObject.iconContainer.gameObject.SetActive(false); - buttonObject.OnClicked += (UIButtonBase.ButtonAction)PolyModHubButtonClicked; + Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppReferenceArray allLocalizers = GameObject.FindObjectsOfTypeAll(Il2CppType.From(typeof(TMPLocalizer))); + + foreach (UnityEngine.Object item in allLocalizers) + { + TMPLocalizer? localizer = item.TryCast(); + if (localizer == null) + { + continue; + } + + Transform? parent = localizer?.gameObject?.transform?.parent; + if (parent == null) + { + continue; + } + + string parentName = parent.name; + + if (parentName == "SettingsButton") + { + Transform? textTransform = parent.FindChild("DescriptionText"); + if (textTransform == null) + { + return; + } + + GameObject originalText = textTransform.gameObject; + GameObject text = GameObject.Instantiate(originalText, originalText.transform.parent.parent.parent); + text.name = "PolyModVersion"; + + RectTransform rect = text.GetComponent(); + rect.anchoredPosition = new Vector2(265, 40); + rect.sizeDelta = new Vector2(500, rect.sizeDelta.y); + rect.anchorMax = Vector2.zero; + rect.anchorMin = Vector2.zero; + + TextMeshProUGUI textComponent = text.GetComponent(); + textComponent.fontSize = 18; + textComponent.alignment = TextAlignmentOptions.BottomLeft; + + text.GetComponent().Text = $"PolyMod {Plugin.VERSION}"; + text.AddComponent().ignoreLayout = true; + } + else if (parentName == "NewsButton") + { + GameObject originalButton = parent.gameObject; + GameObject button = GameObject.Instantiate(originalButton, originalButton.transform.parent); + button.name = "PolyModHubButton"; + button.transform.position = originalButton.transform.position - new Vector3(90, 0, 0); + + UIRoundButton buttonComponent = button.GetComponent(); + buttonComponent.bg.sprite = Visual.BuildSprite(Plugin.GetResource("polymod_icon.png").ReadBytes()); + buttonComponent.bg.transform.localScale = new Vector3(1.2f, 1.2f, 0); + buttonComponent.bg.color = Color.white; + + GameObject.Destroy(buttonComponent.icon.gameObject); + GameObject.Destroy(buttonComponent.outline.gameObject); + + buttonComponent.OnClicked += (UIButtonBase.ButtonAction)PolyModHubButtonClicked; + } + } static void PolyModHubButtonClicked(int buttonId, BaseEventData eventData) { diff --git a/src/NullableFix.cs b/src/NullableFix.cs new file mode 100644 index 0000000..3d05f54 --- /dev/null +++ b/src/NullableFix.cs @@ -0,0 +1,23 @@ +#nullable disable + +namespace System.Runtime.CompilerServices +{ + [System.AttributeUsage(System.AttributeTargets.All, AllowMultiple = true)] + internal sealed class NullableAttribute : System.Attribute + { + public NullableAttribute(byte b) { } + public NullableAttribute(byte[] b) { } + } + + [System.AttributeUsage(System.AttributeTargets.All, AllowMultiple = false)] + internal sealed class NullableContextAttribute : System.Attribute + { + public NullableContextAttribute(byte b) { } + } + + [System.AttributeUsage(System.AttributeTargets.Module)] + internal sealed class NullablePublicOnlyAttribute : System.Attribute + { + public NullablePublicOnlyAttribute(bool b) { } + } +} From 7009b0855292964bbc35ada127014775aa197e49 Mon Sep 17 00:00:00 2001 From: IExploitableMan Date: Fri, 18 Apr 2025 18:34:08 +0300 Subject: [PATCH 2/4] Bump BepInEx --- PolyMod.csproj | 2 +- src/Loader.cs | 9 +++++---- src/Managers/Audio.cs | 9 ++------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/PolyMod.csproj b/PolyMod.csproj index f860b50..3be93eb 100644 --- a/PolyMod.csproj +++ b/PolyMod.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/Loader.cs b/src/Loader.cs index 8ffc363..8b3662f 100644 --- a/src/Loader.cs +++ b/src/Loader.cs @@ -303,10 +303,11 @@ public static void LoadSpriteInfoFile(Mod mod, Mod.File file) public static void LoadAudioFile(Mod mod, Mod.File file) { - //AudioSource audioSource = new GameObject().AddComponent(); - //GameObject.DontDestroyOnLoad(audioSource); - //audioSource.clip = Managers.Audio.BuildAudioClip(file.bytes); - //Registry.audioClips.Add(Path.GetFileNameWithoutExtension(file.name), audioSource); + // AudioSource audioSource = new GameObject().AddComponent(); + // GameObject.DontDestroyOnLoad(audioSource); + // audioSource.clip = Managers.Audio.BuildAudioClip(file.bytes); + // Registry.audioClips.Add(Path.GetFileNameWithoutExtension(file.name), audioSource); + // TODO: issue #71 } public static void LoadGameLogicDataPatch(Mod mod, JObject gld, JObject patch) diff --git a/src/Managers/Audio.cs b/src/Managers/Audio.cs index 4fffff9..7eecf93 100644 --- a/src/Managers/Audio.cs +++ b/src/Managers/Audio.cs @@ -1,6 +1,7 @@ using HarmonyLib; using Polytopia.Data; using UnityEngine; +using UnityEngine.Networking; namespace PolyMod.Managers; public static class Audio @@ -62,13 +63,7 @@ private static bool AudioSFXData_GetClip(ref AudioClip __result, SFXTypes id, Sk public static AudioClip BuildAudioClip(byte[] data) { - string path = Path.Combine(Application.persistentDataPath, "temp.wav"); - File.WriteAllBytes(path, data); - WWW www = new("file://" + path); - while (!www.isDone) { } - AudioClip audioClip = www.GetAudioClip(false); - File.Delete(path); - return audioClip; + return new AudioClip(new()); } internal static void Init() From 33744db1cffa1c97e5fce5753c31bb3bfa9fc668 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 21 Apr 2025 11:05:41 +0200 Subject: [PATCH 3/4] Added pre to version --- PolyMod.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PolyMod.csproj b/PolyMod.csproj index 3be93eb..0796727 100644 --- a/PolyMod.csproj +++ b/PolyMod.csproj @@ -10,7 +10,7 @@ https://polymod.dev/nuget/v3/index.json; IL2CPP - 1.1.7 + 1.1.7-pre 2.12.3.14031 PolyModdingTeam The Battle of Polytopia's mod loader. From 7118153ca8ac023f5228bd84d3baaf659ad76bda Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 21 Apr 2025 12:02:24 +0200 Subject: [PATCH 4/4] Updated bepinex ver --- installer/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/main.py b/installer/main.py index 5d7828c..5474049 100644 --- a/installer/main.py +++ b/installer/main.py @@ -14,7 +14,7 @@ "win32": "win", "darwin": "macos", }[sys.platform] -BEPINEX = f"725/BepInEx-Unity.IL2CPP-{OS}-x64-6.0.0-be.725%2Be1974e2" +BEPINEX = f"733/BepInEx-Unity.IL2CPP-{OS}-x64-6.0.0-be.733%2B995f049" POLYMOD = "https://github.com/PolyModdingTeam/PolyMod/releases/latest/download/PolyMod.dll"