Skip to content

Commit

Permalink
Fixed compatibility with EnemySkinRegistry that made the mod not work…
Browse files Browse the repository at this point in the history
…ing for players that didn't have the mod
  • Loading branch information
Feiryn committed Sep 25, 2024
1 parent f097d95 commit a343871
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion LethalMon/Behaviours/TamedEnemyBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ public virtual void MoveTowards(Vector3 position)
pokeballItem.scrapPersistedThroughRounds = scrapPersistedThroughRounds || alreadyCollectedThisRound;
pokeballItem.SetScrapValue(ballValue);
ball.GetComponent<NetworkObject>().Spawn(false);
pokeballItem.enemySkinRegistryId = EnemySkinRegistryId;
if (EnemySkinRegistryCompatibility.Instance.Enabled)
pokeballItem.enemySkinRegistryId = EnemySkinRegistryId;
pokeballItem.SetCaughtEnemyServerRpc(Enemy.enemyType.name, pokeballItem.enemySkinRegistryId);
pokeballItem.isDnaComplete = isDnaComplete;
pokeballItem.FallToGround();
Expand Down
25 changes: 22 additions & 3 deletions LethalMon/Compatibility/EnemySkinRegistryCompatibility.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using AntlerShed.SkinRegistry;
using BepInEx;
using HarmonyLib;
using LethalMon.Behaviours;

Expand All @@ -9,9 +10,27 @@ public class EnemySkinRegistryCompatibility() : ModCompatibility("antlershed.let
{
public static EnemySkinRegistryCompatibility Instance { get; } = new();

private static EnemySkinRegistry? _pluginInstance;
private BaseUnityPlugin? _pluginInstance;

internal static EnemySkinRegistry PluginInstance => _pluginInstance ??= BepInEx.Bootstrap.Chainloader.PluginInfos["antlershed.lethalcompany.enemyskinregistry"].Instance as EnemySkinRegistry;
internal BaseUnityPlugin? PluginInstance
{
get
{
if (_pluginInstance == null)
{
if (Instance.Enabled)
{
_pluginInstance = BepInEx.Bootstrap.Chainloader.PluginInfos["antlershed.lethalcompany.enemyskinregistry"].Instance as EnemySkinRegistry;
}
else
{
return null;
}
}

return _pluginInstance;
}
}

public static string GetEnemySkinId(EnemyAI enemy)
{
Expand All @@ -25,7 +44,7 @@ public static string GetSkinName(string skinId)

try
{
var skinData = PluginInstance.GetSkinData(skinId);
var skinData = ((EnemySkinRegistry) Instance.PluginInstance!).GetSkinData(skinId);
return skinData != null ? skinData.Label : string.Empty;
}
catch (Exception e)
Expand Down
5 changes: 4 additions & 1 deletion LethalMon/Items/PokeballItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,10 @@ private void CaptureEnemy(EnemyAI enemyAI, CatchableEnemy.CatchableEnemy catchab
this.catchableEnemy = catchable;
this.enemyAI = enemyAI;
this.enemyType = enemyAI.enemyType;
this.enemySkinRegistryId = EnemySkinRegistryCompatibility.GetEnemySkinId(enemyAI);
if (EnemySkinRegistryCompatibility.Instance.Enabled)
{
this.enemySkinRegistryId = EnemySkinRegistryCompatibility.GetEnemySkinId(enemyAI);
}

float captureProbability = catchable.GetCaptureProbability(this.captureStrength, this.enemyAI);
float shakeProbability = Mathf.Pow(captureProbability, 1f / 3f); // Cube root
Expand Down

0 comments on commit a343871

Please sign in to comment.