Skip to content

Commit 26162cf

Browse files
committed
Fixed crash and some visuals
1 parent b3348ec commit 26162cf

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

PolyMod.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
https://polymod.dev/nuget/v3/index.json;
1111
</RestoreAdditionalProjectSources>
1212
<Configurations>IL2CPP</Configurations>
13-
<Version>1.2.6-104</Version>
13+
<Version>1.2.6</Version>
1414
<PolytopiaVersion>2.9.1.12223</PolytopiaVersion>
1515
<Authors>PolyModdingTeam</Authors>
1616
<Description>The Battle of Polytopia's mod loader.</Description>

src/Managers/Compatibility.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private static bool GameInfoPopup_OnMainButtonClicked(GameInfoPopup __instance,
151151
[HarmonyPatch(typeof(StartScreen), nameof(StartScreen.OnResumeButtonClick))]
152152
private static bool StartScreen_OnResumeButtonClick(StartScreen __instance, int id, BaseEventData eventData)
153153
{
154-
return CheckSignatures(__instance.OnResumeButtonClick, id, eventData, ClientBase.GetSinglePlayerSessions(GameManager.LocalPlayer.Id)[0]);
154+
return CheckSignatures(__instance.OnResumeButtonClick, id, eventData, ClientBase.GetSinglePlayerSessions(0)[0]);
155155
}
156156

157157
/// <summary>
@@ -198,11 +198,11 @@ private static void GameManager_MatchEnded(bool localPlayerIsWinner, ScoreDetail
198198
/// Creates a signature file when a new game session is created.
199199
/// </summary>
200200
[HarmonyPostfix]
201-
[HarmonyPatch(typeof(ClientBase), nameof(ClientBase.CreateSession), typeof(GameSettings), typeof(Il2CppSystem.Guid))]
202-
private static void ClientBase_CreateSession(GameSettings settings, Il2CppSystem.Guid gameId)
201+
[HarmonyPatch(typeof(ClientBase), nameof(ClientBase.CreateSession), typeof(GameSettings), typeof(Il2CppSystem.Collections.Generic.List<PlayerState>))]
202+
private static void ClientBase_CreateSession(ClientBase __instance, GameSettings settings, Il2CppSystem.Collections.Generic.List<PlayerState> players)
203203
{
204204
File.WriteAllTextAsync(
205-
Path.Combine(Application.persistentDataPath, $"{gameId}.signatures"),
205+
Path.Combine(Application.persistentDataPath, $"{__instance.gameId}.signatures"),
206206
checksum
207207
);
208208
}

src/Managers/Visual.cs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using PolyMod.Json;
99
using System.Text.Json.Serialization;
1010
using UnityEngine.EventSystems;
11+
using PolytopiaBackendBase.Auth;
1112

1213
namespace PolyMod.Managers;
1314

@@ -428,27 +429,28 @@ private static void CityRenderer_GetHouse(ref PolytopiaSpriteRenderer __result,
428429
/// <summary>Provides custom sprites for houses in the UI city renderer.</summary>
429430
[HarmonyPostfix]
430431
[HarmonyPatch(typeof(UICityRenderer), nameof(UICityRenderer.GetResource))]
431-
private static void UICityRenderer_GetResource(ref GameObject __result, string baseName, TribeData.Type tribe, SkinType skin)
432+
private static void UICityRenderer_GetResource(ref GameObject __result, Il2CppInterop.Runtime.InteropTypes.Arrays.Il2CppReferenceArray<SpriteAddress> spriteAddresses)
432433
{
433-
Image imageComponent = __result.GetComponent<Image>();
434-
string[] tokens = baseName.Split('_');
435-
if (tokens.Length > 0)
434+
foreach (var address in spriteAddresses)
436435
{
437-
if (tokens[0] == "House")
436+
Image imageComponent = __result.GetComponent<Image>();
437+
string[] tokens = address.sprite.Split('_');
438+
if (tokens.Length == 3 && tokens[0] == "House")
438439
{
439-
int level = 0;
440-
if (tokens.Length > 1)
440+
if (tokens[0] == "House")
441441
{
442-
_ = int.TryParse(tokens[1], out level);
443-
}
444-
445-
Sprite? sprite = Registry.GetSprite("house", Util.GetStyle(tribe, skin), level);
446-
if (sprite == null)
447-
{
448-
return;
442+
string style = tokens[1];
443+
if(int.TryParse(tokens[2], out int level) && !string.IsNullOrEmpty(style))
444+
{
445+
Sprite? sprite = Registry.GetSprite("house", style, level);
446+
if (sprite == null)
447+
{
448+
return;
449+
}
450+
imageComponent.sprite = sprite;
451+
imageComponent.SetNativeSize();
452+
}
449453
}
450-
imageComponent.sprite = sprite;
451-
imageComponent.SetNativeSize();
452454
}
453455
}
454456
}
@@ -514,12 +516,17 @@ private static void GameInfoRow_LoadFaceIcon(GameInfoRow __instance, TribeData.T
514516

515517
/// <summary>Provides custom sprites for player info icons.</summary>
516518
[HarmonyPostfix]
517-
[HarmonyPatch(typeof(PlayerInfoIcon), nameof(PlayerInfoIcon.SetData), typeof(TribeData.Type), typeof(SkinType), typeof(SpriteData.SpecialFaceIcon), typeof(Color), typeof(DiplomacyRelationState), typeof(PlayerInfoIcon.Mood))]
518-
private static void PlayerInfoIcon_SetData(PlayerInfoIcon __instance, TribeData.Type tribe, SkinType skin, SpriteData.SpecialFaceIcon face, Color color, DiplomacyRelationState diplomacyState, PlayerInfoIcon.Mood mood)
519+
[HarmonyPatch(typeof(PlayerInfoIcon), nameof(PlayerInfoIcon.SetData))]
520+
private static void PlayerInfoIcon_SetData(PlayerInfoIcon __instance, PlayerState player, PlayerState otherPlayer, PlayerInfoIcon.Mood mood, bool shouldShowDiplomaticState, bool forceKnownPlayer)
519521
{
520-
if (face == SpriteData.SpecialFaceIcon.neutral)
522+
GameState gameState = GameManager.GameState;
523+
bool flag = player.IsAlive(gameState);
524+
PlayerState localPlayer = GameManager.LocalPlayer;
525+
bool flag2 = localPlayer.KnowsPlayer(player.Id) || forceKnownPlayer;
526+
527+
if (flag && !(localPlayer.Id != player.Id && !flag2))
521528
{
522-
Sprite? sprite = Registry.GetSprite("head", Util.GetStyle(tribe, skin));
529+
Sprite? sprite = Registry.GetSprite("head", Util.GetStyle(player.tribe, player.skinType));
523530
if (sprite != null)
524531
{
525532
__instance.HeadImage.sprite = sprite;

src/Plugin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ internal static readonly string CHECKSUM_PATH
7979
"Couldn't find prefab for type",
8080
"MARKET: id:",
8181
"Missing name for value",
82+
"Can't find atlas for raw name",
8283
};
8384

8485

0 commit comments

Comments
 (0)