Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions PolyMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
https://polymod.dev/nuget/v3/index.json;
</RestoreAdditionalProjectSources>
<Configurations>IL2CPP</Configurations>
<Version>1.1.6</Version>
<PolytopiaVersion>2.12.2.13970</PolytopiaVersion>
<Version>1.1.7-pre</Version>
<PolytopiaVersion>2.12.3.14031</PolytopiaVersion>
<Authors>PolyModdingTeam</Authors>
<Description>The Battle of Polytopia's mod loader.</Description>
<NoWarn>IDE0130</NoWarn>
<NoWarn>NU5104</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.725" />
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.733" />
<PackageReference Include="TheBattleOfPolytopia" Version="$(PolytopiaVersion)" />
<EmbeddedResource Include="resources\*.*" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
9 changes: 5 additions & 4 deletions src/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AudioSource>();
GameObject.DontDestroyOnLoad(audioSource);
audioSource.clip = Managers.Audio.BuildAudioClip(file.bytes);
Registry.audioClips.Add(Path.GetFileNameWithoutExtension(file.name), audioSource);
// AudioSource audioSource = new GameObject().AddComponent<AudioSource>();
// 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)
Expand Down
9 changes: 2 additions & 7 deletions src/Managers/Audio.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HarmonyLib;
using Polytopia.Data;
using UnityEngine;
using UnityEngine.Networking;

namespace PolyMod.Managers;
public static class Audio
Expand Down Expand Up @@ -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()
Expand Down
93 changes: 62 additions & 31 deletions src/Managers/Hub.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Cpp2IL.Core.Extensions;
using HarmonyLib;
using Il2CppInterop.Runtime;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
Expand Down Expand Up @@ -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<RectTransform>();
rect.anchoredPosition = new(265, 40);
rect.sizeDelta = new(500, rect.sizeDelta.y);
rect.anchorMax = new(0, 0);
rect.anchorMin = new(0, 0);
text.GetComponent<TextMeshProUGUI>().fontSize = 18;
text.GetComponent<TextMeshProUGUI>().alignment = TextAlignmentOptions.BottomLeft;
text.GetComponent<TMPLocalizer>().Text = $"PolyMod {Plugin.VERSION}";
text.AddComponent<LayoutElement>().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<TMPLocalizer>().Key = "polymod.hub";

UIRoundButton buttonObject = button.GetComponent<UIRoundButton>();
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<UnityEngine.Object> allLocalizers = GameObject.FindObjectsOfTypeAll(Il2CppType.From(typeof(TMPLocalizer)));

foreach (UnityEngine.Object item in allLocalizers)
{
TMPLocalizer? localizer = item.TryCast<TMPLocalizer>();
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<RectTransform>();
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<TextMeshProUGUI>();
textComponent.fontSize = 18;
textComponent.alignment = TextAlignmentOptions.BottomLeft;

text.GetComponent<TMPLocalizer>().Text = $"PolyMod {Plugin.VERSION}";
text.AddComponent<LayoutElement>().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<UIRoundButton>();
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)
{
Expand Down
23 changes: 23 additions & 0 deletions src/NullableFix.cs
Original file line number Diff line number Diff line change
@@ -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) { }
}
}