Skip to content

Commit

Permalink
Cleanup code and changing Harmony patch to Postfix
Browse files Browse the repository at this point in the history
  • Loading branch information
MadSkunky committed Jul 23, 2022
1 parent 0651dde commit 0e156e7
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 206 deletions.
Binary file modified Dist/GrenadeThrowRangeFix.dll
Binary file not shown.
Binary file modified GTRF_Thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions GrenadeThrowRangeFix/GrenadeThrowRangeFix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="GrenadeThrowRangeFixGeoscape.cs" />
<Compile Include="GrenadeThrowRangeFixConfig.cs" />
<Compile Include="GrenadeThrowRangeFixMain.cs" />
<Compile Include="GrenadeThrowRangeFixTactical.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
40 changes: 20 additions & 20 deletions GrenadeThrowRangeFix/GrenadeThrowRangeFixConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

namespace GrenadeThrowRangeFix
{
/// <summary>
/// ModConfig is mod settings that players can change from within the game.
/// Config is only editable from players in main menu.
/// Only one config can exist per mod assembly.
/// Config is serialized on disk as json.
/// </summary>
public class GrenadeThrowRangeFixConfig : ModConfig
{
/// <summary>
/// ModConfig is mod settings that players can change from within the game.
/// Config is only editable from players in main menu.
/// Only one config can exist per mod assembly.
/// Config is serialized on disk as json.
/// </summary>
public class GrenadeThrowRangeFixConfig : ModConfig
{
/// Only public fields are serialized.
[ConfigField(text: "Throwing range multiplier",
description: "Multiplier (in %) to adjust the throwing range.\nDefault 100 = with 20 strength the throwing range is equal to the defind range of the grenade (see Info screen of the grenade).\nLower numbers will decrease the range of all grenades, higher numbers do the opposite.")]
public int ThrowRangeMultiplier = 100;
public int ThrowRangeMultiplier = 100;

/// Supported types for in-game UI are:
//public int IntegerValue;
//public float FloatValue;
//public bool BoolValue;
//
//public enum CustomEnum
//{
// A, B ,C
//}
//public CustomEnum CustomEnumValue;
}
/// Supported types for in-game UI are:
//public int IntegerValue;
//public float FloatValue;
//public bool BoolValue;
//
//public enum CustomEnum
//{
// A, B ,C
//}
//public CustomEnum CustomEnumValue;
}
}
72 changes: 0 additions & 72 deletions GrenadeThrowRangeFix/GrenadeThrowRangeFixGeoscape.cs

This file was deleted.

68 changes: 14 additions & 54 deletions GrenadeThrowRangeFix/GrenadeThrowRangeFixMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class GrenadeThrowRangeFixMain : ModMain
public new GrenadeThrowRangeFixConfig Config => (GrenadeThrowRangeFixConfig)base.Config;

/// This property indicates if mod can be Safely Disabled from the game.
/// Safely sisabled mods can be reenabled again. Unsafely disabled mods will need game restart ot take effect.
/// Safely disabled mods can be reenabled again. Unsafely disabled mods will need game restart ot take effect.
/// Unsafely disabled mods usually cannot revert thier changes in OnModDisabled
public override bool CanSafelyDisable => true;

Expand All @@ -25,7 +25,7 @@ public class GrenadeThrowRangeFixMain : ModMain
public new Harmony HarmonyInstance => (Harmony)base.HarmonyInstance;

/// <summary>
/// Callback for when mod is enabled. Called even on game starup.
/// Callback for when mod is enabled. Called even on game startup.
/// </summary>
public override void OnModEnabled()
{
Expand All @@ -46,69 +46,29 @@ public override void OnModDisabled()
}

/// <summary>
/// Callback for when any property from mod's config is changed.
/// Harmony patch that fixes the vanilla throw range calculation.
/// The attenuation tag allows Harmony to find the targeted class/object method and apply the patch from the following class.
/// </summary>
public override void OnConfigChanged()
{
/// Config is accessible at any time.
}


/// <summary>
/// In Phoenix Point there can be only one active level at a time.
/// Levels go through different states (loading, unloaded, start, etc.).
/// General puprose level state change callback.
/// </summary>
/// <param name="level">Level being changed.</param>
/// <param name="prevState">Old state of the level.</param>
/// <param name="state">New state of the level.</param>
public override void OnLevelStateChanged(Level level, Level.State prevState, Level.State state)
{
/// Alternative way to access current level at any time.
//Level l = GetLevel();
}

/// <summary>
/// Useful callback for when level is loaded, ready, and starts.
/// Usually game setup is executed.
/// </summary>
/// <param name="level">Level that starts.</param>
public override void OnLevelStart(Level level)
{
}

/// <summary>
/// Useful callback for when level is ending, before unloading.
/// Usually game cleanup is executed.
/// </summary>
/// <param name="level">Level that ends.</param>
public override void OnLevelEnd(Level level)
{
}

// This "tag" allows Harmony to find this class and apply it as a patch.
[HarmonyPatch(typeof(Weapon), "GetThrowingRange")]
// Class can be any name, but must be static.
internal static class GetThrowingRange_fix
/// Class can be any name, but must be static.
internal static class Weapon_GetThrowingRange_Patch
{
// Overwrite original fuction to calculate throwing range for grenades.
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0051")]
private static bool Prefix(ref float __result, Weapon __instance, float rangeMultiplier)
/// Using Postfix patch to be guaranteed to get executed.
public static void Postfix(ref float __result, Weapon __instance, float rangeMultiplier)
{
try
{
float num = __instance.TacticalActor.CharacterStats.Endurance * __instance.TacticalActor.TacticalActorDef.EnduranceToThrowMultiplier;
float num2 = __instance.TacticalActor.CharacterStats.BonusAttackRange.CalcModValueBasedOn(num);
// MadSkunky: adding range multiplier and divisor
// MadSkunky: Extension of calculation with range multiplier divided by 12 for normalization and multiplier from configuration.
num *= __instance.GetDamagePayload().Range / 12f;
float multiplierPerc = (Main.Config as GrenadeThrowRangeFixConfig).ThrowRangeMultiplier / 100f;
__result = ((num / __instance.Weight * rangeMultiplier) + num2) * multiplierPerc;
// End of changes, the rest is vanilla code
return false;
float multiplier = (Main.Config as GrenadeThrowRangeFixConfig).ThrowRangeMultiplier / 100f;
__result = ((num / __instance.Weight * rangeMultiplier) + num2) * multiplier;
// End of changes
}
catch (Exception)
catch (Exception e)
{
return true;
Main.Logger.LogError("GrenadeThrowRangeFix mod ERROR:\n", e);
}
}
}
Expand Down
58 changes: 0 additions & 58 deletions GrenadeThrowRangeFix/GrenadeThrowRangeFixTactical.cs

This file was deleted.

Binary file added Screenshot_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshot_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0e156e7

Please sign in to comment.