Skip to content

Commit efc45ad

Browse files
authored
Unity6
1 parent 2b914f6 commit efc45ad

File tree

6 files changed

+96
-46
lines changed

6 files changed

+96
-46
lines changed

PolyMod.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
https://polymod.dev/nuget/v3/index.json;
1111
</RestoreAdditionalProjectSources>
1212
<Configurations>IL2CPP</Configurations>
13-
<Version>1.1.6</Version>
14-
<PolytopiaVersion>2.12.2.13970</PolytopiaVersion>
13+
<Version>1.1.7-pre</Version>
14+
<PolytopiaVersion>2.12.3.14031</PolytopiaVersion>
1515
<Authors>PolyModdingTeam</Authors>
1616
<Description>The Battle of Polytopia's mod loader.</Description>
1717
<NoWarn>IDE0130</NoWarn>
1818
<NoWarn>NU5104</NoWarn>
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.725" />
22+
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.733" />
2323
<PackageReference Include="TheBattleOfPolytopia" Version="$(PolytopiaVersion)" />
2424
<EmbeddedResource Include="resources\*.*" />
2525
</ItemGroup>

installer/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"win32": "win",
1515
"darwin": "macos",
1616
}[sys.platform]
17-
BEPINEX = f"725/BepInEx-Unity.IL2CPP-{OS}-x64-6.0.0-be.725%2Be1974e2"
17+
BEPINEX = f"733/BepInEx-Unity.IL2CPP-{OS}-x64-6.0.0-be.733%2B995f049"
1818
POLYMOD = "https://github.com/PolyModdingTeam/PolyMod/releases/latest/download/PolyMod.dll"
1919

2020

src/Loader.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,11 @@ public static void LoadSpriteInfoFile(Mod mod, Mod.File file)
303303

304304
public static void LoadAudioFile(Mod mod, Mod.File file)
305305
{
306-
AudioSource audioSource = new GameObject().AddComponent<AudioSource>();
307-
GameObject.DontDestroyOnLoad(audioSource);
308-
audioSource.clip = Managers.Audio.BuildAudioClip(file.bytes);
309-
Registry.audioClips.Add(Path.GetFileNameWithoutExtension(file.name), audioSource);
306+
// AudioSource audioSource = new GameObject().AddComponent<AudioSource>();
307+
// GameObject.DontDestroyOnLoad(audioSource);
308+
// audioSource.clip = Managers.Audio.BuildAudioClip(file.bytes);
309+
// Registry.audioClips.Add(Path.GetFileNameWithoutExtension(file.name), audioSource);
310+
// TODO: issue #71
310311
}
311312

312313
public static void LoadGameLogicDataPatch(Mod mod, JObject gld, JObject patch)

src/Managers/Audio.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using HarmonyLib;
22
using Polytopia.Data;
33
using UnityEngine;
4+
using UnityEngine.Networking;
45

56
namespace PolyMod.Managers;
67
public static class Audio
@@ -62,13 +63,7 @@ private static bool AudioSFXData_GetClip(ref AudioClip __result, SFXTypes id, Sk
6263

6364
public static AudioClip BuildAudioClip(byte[] data)
6465
{
65-
string path = Path.Combine(Application.persistentDataPath, "temp.wav");
66-
File.WriteAllBytes(path, data);
67-
WWW www = new("file://" + path);
68-
while (!www.isDone) { }
69-
AudioClip audioClip = www.GetAudioClip(false);
70-
File.Delete(path);
71-
return audioClip;
66+
return new AudioClip(new());
7267
}
7368

7469
internal static void Init()

src/Managers/Hub.cs

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Cpp2IL.Core.Extensions;
22
using HarmonyLib;
3+
using Il2CppInterop.Runtime;
34
using TMPro;
45
using UnityEngine;
56
using UnityEngine.EventSystems;
@@ -43,37 +44,67 @@ private static void PopupButtonContainer_SetButtonData(PopupButtonContainer __in
4344
[HarmonyPatch(typeof(StartScreen), nameof(StartScreen.Start))]
4445
private static void StartScreen_Start()
4546
{
46-
GameObject originalText = GameObject.Find("SettingsButton/DescriptionText");
47-
GameObject text = GameObject.Instantiate(originalText, originalText.transform.parent.parent.parent);
48-
text.name = "PolyModVersion";
49-
RectTransform rect = text.GetComponent<RectTransform>();
50-
rect.anchoredPosition = new(265, 40);
51-
rect.sizeDelta = new(500, rect.sizeDelta.y);
52-
rect.anchorMax = new(0, 0);
53-
rect.anchorMin = new(0, 0);
54-
text.GetComponent<TextMeshProUGUI>().fontSize = 18;
55-
text.GetComponent<TextMeshProUGUI>().alignment = TextAlignmentOptions.BottomLeft;
56-
text.GetComponent<TMPLocalizer>().Text = $"PolyMod {Plugin.VERSION}";
57-
text.AddComponent<LayoutElement>().ignoreLayout = true;
58-
59-
GameObject originalButton = GameObject.Find("StartScreen/NewsButton");
60-
GameObject button = GameObject.Instantiate(originalButton, originalButton.transform.parent);
61-
button.gameObject.name = "PolyModHubButton";
62-
button.transform.position = originalButton.transform.position - new Vector3(90, 0, 0);
63-
button.active = true;
64-
65-
Transform descriptionText = button.transform.Find("DescriptionText");
66-
descriptionText.gameObject.SetActive(true);
67-
descriptionText.GetComponentInChildren<TMPLocalizer>().Key = "polymod.hub";
68-
69-
UIRoundButton buttonObject = button.GetComponent<UIRoundButton>();
70-
buttonObject.bg.sprite = Visual.BuildSprite(Plugin.GetResource("polymod_icon.png").ReadBytes());
71-
buttonObject.bg.transform.localScale = new Vector3(1.2f, 1.2f, 0);
72-
buttonObject.bg.color = Color.white;
73-
74-
buttonObject.outline.gameObject.SetActive(false);
75-
buttonObject.iconContainer.gameObject.SetActive(false);
76-
buttonObject.OnClicked += (UIButtonBase.ButtonAction)PolyModHubButtonClicked;
47+
Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppReferenceArray<UnityEngine.Object> allLocalizers = GameObject.FindObjectsOfTypeAll(Il2CppType.From(typeof(TMPLocalizer)));
48+
49+
foreach (UnityEngine.Object item in allLocalizers)
50+
{
51+
TMPLocalizer? localizer = item.TryCast<TMPLocalizer>();
52+
if (localizer == null)
53+
{
54+
continue;
55+
}
56+
57+
Transform? parent = localizer?.gameObject?.transform?.parent;
58+
if (parent == null)
59+
{
60+
continue;
61+
}
62+
63+
string parentName = parent.name;
64+
65+
if (parentName == "SettingsButton")
66+
{
67+
Transform? textTransform = parent.FindChild("DescriptionText");
68+
if (textTransform == null)
69+
{
70+
return;
71+
}
72+
73+
GameObject originalText = textTransform.gameObject;
74+
GameObject text = GameObject.Instantiate(originalText, originalText.transform.parent.parent.parent);
75+
text.name = "PolyModVersion";
76+
77+
RectTransform rect = text.GetComponent<RectTransform>();
78+
rect.anchoredPosition = new Vector2(265, 40);
79+
rect.sizeDelta = new Vector2(500, rect.sizeDelta.y);
80+
rect.anchorMax = Vector2.zero;
81+
rect.anchorMin = Vector2.zero;
82+
83+
TextMeshProUGUI textComponent = text.GetComponent<TextMeshProUGUI>();
84+
textComponent.fontSize = 18;
85+
textComponent.alignment = TextAlignmentOptions.BottomLeft;
86+
87+
text.GetComponent<TMPLocalizer>().Text = $"PolyMod {Plugin.VERSION}";
88+
text.AddComponent<LayoutElement>().ignoreLayout = true;
89+
}
90+
else if (parentName == "NewsButton")
91+
{
92+
GameObject originalButton = parent.gameObject;
93+
GameObject button = GameObject.Instantiate(originalButton, originalButton.transform.parent);
94+
button.name = "PolyModHubButton";
95+
button.transform.position = originalButton.transform.position - new Vector3(90, 0, 0);
96+
97+
UIRoundButton buttonComponent = button.GetComponent<UIRoundButton>();
98+
buttonComponent.bg.sprite = Visual.BuildSprite(Plugin.GetResource("polymod_icon.png").ReadBytes());
99+
buttonComponent.bg.transform.localScale = new Vector3(1.2f, 1.2f, 0);
100+
buttonComponent.bg.color = Color.white;
101+
102+
GameObject.Destroy(buttonComponent.icon.gameObject);
103+
GameObject.Destroy(buttonComponent.outline.gameObject);
104+
105+
buttonComponent.OnClicked += (UIButtonBase.ButtonAction)PolyModHubButtonClicked;
106+
}
107+
}
77108

78109
static void PolyModHubButtonClicked(int buttonId, BaseEventData eventData)
79110
{

src/NullableFix.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#nullable disable
2+
3+
namespace System.Runtime.CompilerServices
4+
{
5+
[System.AttributeUsage(System.AttributeTargets.All, AllowMultiple = true)]
6+
internal sealed class NullableAttribute : System.Attribute
7+
{
8+
public NullableAttribute(byte b) { }
9+
public NullableAttribute(byte[] b) { }
10+
}
11+
12+
[System.AttributeUsage(System.AttributeTargets.All, AllowMultiple = false)]
13+
internal sealed class NullableContextAttribute : System.Attribute
14+
{
15+
public NullableContextAttribute(byte b) { }
16+
}
17+
18+
[System.AttributeUsage(System.AttributeTargets.Module)]
19+
internal sealed class NullablePublicOnlyAttribute : System.Attribute
20+
{
21+
public NullablePublicOnlyAttribute(bool b) { }
22+
}
23+
}

0 commit comments

Comments
 (0)