Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
(feature): animals always well fed
Browse files Browse the repository at this point in the history
  • Loading branch information
mzonski committed Jul 2, 2023
1 parent c45e1e7 commit 8ccb7ca
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
1 change: 1 addition & 0 deletions CheatMod.Core/CheatMod.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<Compile Include="PachaItemDb.cs" />
<Compile Include="PachaManager.cs" />
<Compile Include="PachaUtils.cs" />
<Compile Include="Patches\EasyAnimals.cs" />
<Compile Include="Patches\EasyFishing.cs" />
<Compile Include="Patches\FreezeTime.cs" />
<Compile Include="Patches\InfiniteFlute.cs" />
Expand Down
2 changes: 1 addition & 1 deletion CheatMod.Core/CheatOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class CheatOptions
#region Game options
public static bool IsEasyFishingEnabled { get; set; } = true;
public static bool IsInfiniteFluteEnabled { get; set; } = true;
public static bool IsSkipAttuneMinigameEnabled { get; set; } = true;
public static bool IsEasyAnimalsEnabled { get; set; } = true;
public static bool IsInfiniteSeedsEnabled { get; set; } = true;
public static bool IsInfiniteStaminaEnabled { get; set; } = true;
public static bool IsInfiniteWaterToolEnabled { get; set; } = true;
Expand Down
4 changes: 2 additions & 2 deletions CheatMod.Core/PachaCheats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void DestroyHittableResources(float range = 3f)
{
if (!caveRoom.Stage.GetComponent<Collider2D>().OverlapPoint(psc.transform.position)) continue;

foreach (var hittableEntity in caveRoom.CurrentHittables.ToList())
foreach (var hittableEntity in caveRoom.CurrentHittables.Where(ch => ch is not null).ToList())
{
if (Vector2.Distance(hittableEntity.transform.position, psc.transform.position) < range)
{
Expand All @@ -318,7 +318,7 @@ public void DestroyHittableResources(float range = 3f)
}
}

foreach (var shim in caveRoom.CurrentCaveOresShams.ToList())
foreach (var shim in caveRoom.CurrentCaveOresShams.Where(sh => sh is not null).ToList())
{
if (Vector2.Distance(shim.transform.position, psc.transform.position) < range &&
shim.Health.CurrentHealth > 0f)
Expand Down
43 changes: 43 additions & 0 deletions CheatMod.Core/Patches/EasyAnimals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Reflection;
using System.Threading;
using Cysharp.Threading.Tasks;
using HarmonyLib;
using SodaDen.Pacha;

namespace CheatMod.Core.Patches;

public partial class CheatModPatches
{
[HarmonyPatch(typeof(AnimalAttuneMinigame), "StartMinigame", typeof(Animal), typeof(AnimalVariant), typeof(bool), typeof(CancellationToken))]
[HarmonyPrefix]
private static bool SkipAttuneMinigamePatch(ref UniTask<int> __result)
{
if (!CheatOptions.IsEasyAnimalsEnabled)
return true;

__result = UniTask.FromResult(4);
return false;
}

[HarmonyPatch(typeof(AnimalEntity), "OnNextDayLocal")]
[HarmonyPostfix]
private static void AnimalEntityAutoFeed(AnimalEntity __instance)
{
if (!CheatOptions.IsEasyAnimalsEnabled) return;

if (__instance.IsTamed || __instance.IsPet)
{
var feedMethodInfo = __instance.GetType().GetMethod("Feed", BindingFlags.Instance | BindingFlags.NonPublic);
feedMethodInfo?.Invoke(__instance, new object[] { __instance.CurrentDay });

if (__instance.Hunger != AnimalHunger.WellFed)
{
feedMethodInfo?.Invoke(__instance, new object[] { __instance.CurrentDay - 1 });
feedMethodInfo?.Invoke(__instance, new object[] { __instance.CurrentDay - 2 });
feedMethodInfo?.Invoke(__instance, new object[] { __instance.CurrentDay - 3 });
}

__instance.CureAllSickness();
}
}
}
15 changes: 1 addition & 14 deletions CheatMod.Core/Patches/InfiniteFlute.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Threading;
using Cysharp.Threading.Tasks;
using HarmonyLib;
using HarmonyLib;
using SodaDen.Pacha;

namespace CheatMod.Core.Patches;
Expand All @@ -17,15 +15,4 @@ private static bool InfiniteFlutePatch(FluteToolItem __instance, PlayerEntity pl

return true;
}

[HarmonyPatch(typeof(AnimalAttuneMinigame), "StartMinigame", typeof(Animal), typeof(AnimalVariant), typeof(bool), typeof(CancellationToken))]
[HarmonyPrefix]
private static bool SkipAttuneMinigamePatch(ref UniTask<int> __result)
{
if (!CheatOptions.IsSkipAttuneMinigameEnabled)
return true;

__result = UniTask.FromResult(4);
return false;
}
}
4 changes: 2 additions & 2 deletions CheatMod.Core/UI/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ protected override void DrawInternal(int windowId)
GUILayout.Toggle(CheatOptions.IsEasyFishingEnabled, "Easy fishing", CheatUIStyles.Toggle);
CheatOptions.IsInfiniteFluteEnabled =
GUILayout.Toggle(CheatOptions.IsInfiniteFluteEnabled, "Infinite flute", CheatUIStyles.Toggle);
CheatOptions.IsSkipAttuneMinigameEnabled =
GUILayout.Toggle(CheatOptions.IsSkipAttuneMinigameEnabled, "Skip attune game", CheatUIStyles.Toggle);
CheatOptions.IsEasyAnimalsEnabled =
GUILayout.Toggle(CheatOptions.IsEasyAnimalsEnabled, "Easy animals", CheatUIStyles.Toggle);
CheatOptions.IsInfiniteSeedsEnabled =
GUILayout.Toggle(CheatOptions.IsInfiniteSeedsEnabled, "Infinite seeds", CheatUIStyles.Toggle);
CheatOptions.IsInfiniteStaminaEnabled =
Expand Down

0 comments on commit 8ccb7ca

Please sign in to comment.