Skip to content

Commit

Permalink
Decrease cyclone spin by adjusting CycloneSpinupStartingStep
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasksu committed Apr 25, 2023
1 parent c14ef8b commit d3ad875
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions GameMod/MPWeaponBehavior.cs
@@ -1,6 +1,7 @@
using HarmonyLib;
using Overload;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;

Expand Down Expand Up @@ -166,4 +167,49 @@ static void Postfix(PlayerShip __instance)
}
}
}

/// <summary>
/// Cyclone Tweaks
/// </summary>
internal static class Cyclone
{
private static FieldInfo _PlayerShip_flak_fire_count_Field = typeof(PlayerShip).GetField("flak_fire_count", BindingFlags.NonPublic | BindingFlags.Instance);
public static int CycloneSpinupStartingStep = 6;

/// <summary>
/// Simply adjust flak_fire_count input which would normally start at 0 in existing formula:
/// 1f - Mathf.Min((float)flak_fire_count * 0.05f, (c_player.m_weapon_level[(int)c_player.m_weapon_type] != WeaponUnlock.LEVEL_2B) ? 0.4f : 0.25f)
/// </summary>
/// <param name="player_ship"></param>
/// <returns></returns>
static float GetCycloneSpinupAdjustment(PlayerShip player_ship)
{
int flak_fire_count = (int)_PlayerShip_flak_fire_count_Field.GetValue(player_ship);
if (flak_fire_count == 0)
{
_PlayerShip_flak_fire_count_Field.SetValue(player_ship, CycloneSpinupStartingStep);
}
return 1f - Mathf.Min(flak_fire_count * 0.05f, (player_ship.c_player.m_weapon_level[(int)player_ship.c_player.m_weapon_type] != WeaponUnlock.LEVEL_2B) ? 0.4f : 0.25f);
}

[HarmonyPatch(typeof(PlayerShip), "MaybeFireWeapon")]
internal class MPWeaponBehavior_Cyclone_PlayerShip_MaybeFireWeapon
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codes)
{
foreach (var code in codes)
{
if (code.opcode == OpCodes.Stloc_S && ((LocalBuilder)code.operand).LocalIndex == 19)
{
yield return code;
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Cyclone), "GetCycloneSpinupAdjustment"));
yield return new CodeInstruction(OpCodes.Stloc_S, 19);
continue;
}
yield return code;
}
}
}
}
}

0 comments on commit d3ad875

Please sign in to comment.