Skip to content

Commit

Permalink
fishing aberrated fishes increases (in)sanity
Browse files Browse the repository at this point in the history
  • Loading branch information
sp00ktober committed May 2, 2023
1 parent 78ae566 commit 815a8f5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
5 changes: 5 additions & 0 deletions BeyondAbyss/BeyondAbyss.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\GOG Games\DREDGE\DREDGE_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Cinemachine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\GOG Games\DREDGE\DREDGE_Data\Managed\Cinemachine.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil, Version=0.11.5.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.5\lib\net40\Mono.Cecil.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -119,6 +123,7 @@
<Compile Include="Patches\Dynamic\BoatActionsDestinationUI_Patch.cs" />
<Compile Include="Patches\Dynamic\HarvestMinigameView_Patch.cs" />
<Compile Include="Patches\Dynamic\PlayerSanity_Patch.cs" />
<Compile Include="Patches\Transpiler\HarvestMinigameView_Transpiler.cs" />
<Compile Include="Patches\Transpiler\TimeController_Transpiler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Singletons\ConfigManager.cs" />
Expand Down
58 changes: 58 additions & 0 deletions BeyondAbyss/Patches/Transpiler/HarvestMinigameView_Transpiler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Cinemachine;
using HarmonyLib;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading;
using UnityEngine;
using Winch.Core;

namespace BeyondAbyss.Patches.Transpiler
{
[HarmonyPatch(typeof(HarvestMinigameView))]
internal class HarvestMinigameView_Transpiler
{
[HarmonyTranspiler]
[HarmonyPatch(typeof(HarvestMinigameView), "SpawnItem")]
public static IEnumerable<CodeInstruction> SpawnItem_Transpiler(IEnumerable<CodeInstruction> instructions)
{
CodeMatcher matcher = new CodeMatcher(instructions)
.MatchEndForward(
new CodeMatch(OpCodes.Ldarg_0),
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(HarvestMinigameView), "currentPOI")),
new CodeMatch(OpCodes.Ldc_I4_0),
new CodeMatch(i => i.opcode == OpCodes.Callvirt && ((MethodInfo)i.operand).Name == "SetIsCurrentlySpecial"));

if (matcher.IsInvalid)
{
WinchCore.Log.Error("Could not find IL code in HarvestMinigameView, skipping patch (no sanity effect on aberration catch).");
return instructions;
}

matcher
.Advance(1)
.Insert(Helper.Transpiler.EmitDelegate<System.Action>(() =>
{
AccessTools.Field(typeof(PlayerSanity), "_sanity").SetValue(GameManager.Instance.Player.Sanity, GameManager.Instance.Player.Sanity.CurrentSanity + 0.15f);
new Thread(new ThreadStart(() =>
{
float defaultFOV = (float)AccessTools.Field(typeof(PlayerCamera), "defaultFOV").GetValue(GameManager.Instance.PlayerCamera);
float hasteFOV = (float)AccessTools.Field(typeof(PlayerCamera), "hasteFOV").GetValue(GameManager.Instance.PlayerCamera);
CinemachineFreeLook cmfl = (CinemachineFreeLook)AccessTools.Field(typeof(PlayerCamera), "cinemachineCamera").GetValue(GameManager.Instance.PlayerCamera);

float value = 1f;
while(value >= 0f)
{
cmfl.m_Lens.FieldOfView = Mathf.Lerp(defaultFOV, hasteFOV, value);
value -= 0.01f;

Thread.Sleep(50);
}
})).Start();
}));

return matcher.InstructionEnumeration();
}
}
}
2 changes: 1 addition & 1 deletion BeyondAbyss/mod_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Author": "sp00ktober",
"ModAssembly": "BeyondAbyss.dll",
"Entrypoint": "BeyondAbyss.BeyondAbyss/Init",
"Version": "0.3.0",
"Version": "0.1.0",
"MinWinchVersion": "alpha-1.3",
"DefaultConfig": {}
}

0 comments on commit 815a8f5

Please sign in to comment.