Skip to content

Commit

Permalink
harmonyx, new csproj
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkroeg committed Apr 17, 2023
1 parent d3d1814 commit f443b04
Show file tree
Hide file tree
Showing 27 changed files with 114 additions and 509 deletions.
1 change: 1 addition & 0 deletions GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using HarmonyLib;
8 changes: 3 additions & 5 deletions ModInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using Harmony;
using System.Reflection;
using BattleTech;
using IRBTModUtils.Logging;
Expand Down Expand Up @@ -45,11 +44,10 @@ public static void Init(string directory, string settingsJSON)
ModInit.modLog?.Info?.Write($"Initializing TisButAScratch - Version {typeof(Settings).Assembly.GetName().Version}");
PilotInjuryManager.ManagerInstance.Initialize();
PilotInjuryHolder.HolderInstance.Initialize();
var harmony = HarmonyInstance.Create(HarmonyPackage);
harmony.PatchAll(Assembly.GetExecutingAssembly());

//var harmony = HarmonyInstance.Create(HarmonyPackage);
//harmony.PatchAll(Assembly.GetExecutingAssembly());
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), HarmonyPackage);
}

}

class Settings
Expand Down
1 change: 0 additions & 1 deletion Patches/BleedingOut.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel;
using BattleTech;
using Harmony;
using System.Linq;
using BattleTech.UI;
using Localize;
Expand Down
1 change: 0 additions & 1 deletion Patches/DescriptionPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using BattleTech.UI.TMProWrapper;
using BattleTech.UI.Tooltips;
using TisButAScratch.Framework;
using Harmony;
using UnityEngine;

namespace TisButAScratch.Patches
Expand Down
1 change: 0 additions & 1 deletion Patches/FloatyPatches.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BattleTech;
using Harmony;
using Localize;
using System;
using System.Collections.Generic;
Expand Down
66 changes: 35 additions & 31 deletions Patches/InjuryPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using Harmony;
using BattleTech;
using TisButAScratch.Framework;
using static TisButAScratch.Framework.GlobalVars;
Expand Down Expand Up @@ -269,25 +268,29 @@ public static bool Prepare()
public static class Mech_ApplyHeadStructureEffects
{
[HarmonyPriority(Priority.First)]
public static bool Prefix(Mech __instance, ChassisLocations location, LocationDamageLevel oldDamageLevel,
public static void Prefix(ref bool __runOriginal, Mech __instance, ChassisLocations location, LocationDamageLevel oldDamageLevel,
LocationDamageLevel newDamageLevel, WeaponHitInfo hitInfo)
{
if (!__runOriginal) return;
if (__instance.StatCollection.GetValue<bool>(ModInit.modSettings.isTorsoMountStatName))
{
var currentReason = __instance.GetPilot().InjuryReason;
if (currentReason != InjuryReason.HeadHit && currentReason != InjuryReason.NotSet)
{
ModInit.modLog?.Info?.Write($" [Mech_ApplyHeadStructureEffects Prefix] Head hit, cockpit not located in head BUT existing reason == {currentReason}, not processing set needs Injury here!");
return false;
__runOriginal = false;
return;
}

if (newDamageLevel == LocationDamageLevel.Destroyed)
{
ModInit.modLog?.Info?.Write($"[Mech_ApplyHeadStructureEffects Prefix] Head destroyed, but cockpit not located in head! Not injuring pilot here!");
return false;
__runOriginal = false;
return;
}
}
return true;
__runOriginal = true;
return;
}

public static void Postfix(Mech __instance, ChassisLocations location, LocationDamageLevel oldDamageLevel,
Expand Down Expand Up @@ -315,33 +318,32 @@ public static class Mech_ApplyHeadStructureEffects
public static class Pilot_InjurePilot_Patch
{
[HarmonyPriority(Priority.First)]

public static bool Prefix(Pilot __instance, string sourceID, int stackItemUID, int dmg, DamageType damageType, Weapon sourceWeapon, AbstractActor sourceActor)
[HarmonyWrapSafe]
public static void Prefix(ref bool __runOriginal, Pilot __instance, string sourceID, int stackItemUID, int dmg, DamageType damageType, Weapon sourceWeapon, AbstractActor sourceActor)
{
try
if (!__runOriginal)return;
if (__instance == null)
{
if (__instance == null) return true;
ModInit.modLog?.Info?.Write(
$"{__instance.Callsign} has {__instance.StatCollection.GetValue<int>("Injuries")} injuries before InjurePilot; proceeding.");
PilotInjuryHolder.HolderInstance.injuryStat = __instance.StatCollection.GetValue<int>("Injuries");
ModInit.modLog?.Info?.Write($"{__instance.Callsign} injuryStat set to {PilotInjuryHolder.HolderInstance.injuryStat}.");

if (__instance.pilotDef.PilotTags.Contains(ModInit.modSettings.pilotPainShunt) &&
(damageType == DamageType.Overheat || damageType == DamageType.OverheatSelf ||
damageType == DamageType.AmmoExplosion || damageType == DamageType.ComponentExplosion || (int)__instance.injuryReason == 101 || (int)__instance.injuryReason == 666 || (int)__instance.injuryReason == 667
|| "OVERHEATED".Equals(__instance.InjuryReasonDescription, StringComparison.InvariantCultureIgnoreCase))) //add head-only injury herre?
{
ModInit.modLog?.Info?.Write(
$"Pilot {__instance.Callsign} has {ModInit.modSettings.pilotPainShunt}, ignoring injury from {damageType}.");
return false;
}
}
catch (Exception ex)
{
ModInit.modLog?.Error?.Write(ex);
return true;
__runOriginal = true;
return;
}
return true;
ModInit.modLog?.Info?.Write(
$"{__instance.Callsign} has {__instance.StatCollection.GetValue<int>("Injuries")} injuries before InjurePilot; proceeding.");
PilotInjuryHolder.HolderInstance.injuryStat = __instance.StatCollection.GetValue<int>("Injuries");
ModInit.modLog?.Info?.Write($"{__instance.Callsign} injuryStat set to {PilotInjuryHolder.HolderInstance.injuryStat}.");

if (__instance.pilotDef.PilotTags.Contains(ModInit.modSettings.pilotPainShunt) &&
(damageType == DamageType.Overheat || damageType == DamageType.OverheatSelf ||
damageType == DamageType.AmmoExplosion || damageType == DamageType.ComponentExplosion || (int)__instance.injuryReason == 101 || (int)__instance.injuryReason == 666 || (int)__instance.injuryReason == 667
|| "OVERHEATED".Equals(__instance.InjuryReasonDescription, StringComparison.InvariantCultureIgnoreCase))) //add head-only injury herre?
{
ModInit.modLog?.Info?.Write(
$"Pilot {__instance.Callsign} has {ModInit.modSettings.pilotPainShunt}, ignoring injury from {damageType}.");
__runOriginal = false;
return;
}
__runOriginal = true;
return;
}

public static void Postfix(Pilot __instance, string sourceID, int stackItemUID, int dmg,
Expand Down Expand Up @@ -473,8 +475,9 @@ public class ContractFinalizeKilledMechwarriorsPatch
//private static MethodInfo popReport = AccessTools.Method(typeof(Contract), "PopReport");
//private static MethodInfo reportLog = AccessTools.Method(typeof(Contract), "ReportLog");
[HarmonyAfter(new string[] { "co.uk.cwolf.MissionControl" })]
public static bool Prefix(Contract __instance)
public static void Prefix(ref bool __runOriginal, Contract __instance)
{
if (!__runOriginal) return;
__instance.PushReport("MechWarriorFinalizeKill");
//pushReport.Invoke(__instance, new object[] {"MechWarriorFinalizeKill"});
foreach (UnitResult unitResult in __instance.PlayerUnitResults)
Expand Down Expand Up @@ -536,7 +539,8 @@ public static bool Prefix(Contract __instance)
}
__instance.PopReport();
//popReport.Invoke(__instance, new object[] { });
return false;
__runOriginal = false;
return;
}
}

Expand Down
7 changes: 4 additions & 3 deletions Patches/SaveAndStatePatches.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Harmony;
using BattleTech;
using TisButAScratch.Framework;
using static TisButAScratch.Framework.GlobalVars;
Expand Down Expand Up @@ -835,8 +834,9 @@ public static class SG_HiringHall_Screen_CheckMaxBerthsWarning
{
public static bool Prepare() => ModInit.modSettings.CanIntentionallyHotBunk;

public static bool Prefix(SG_HiringHall_Screen __instance, ref bool __result, bool JustTest = false)
public static void Prefix(ref bool __runOriginal, SG_HiringHall_Screen __instance, ref bool __result, bool JustTest = false)
{
if (!__runOriginal) return;
if (__instance.simState.PilotRoster.Count >= __instance.simState.GetMaxMechWarriors())
{
if (!JustTest)
Expand All @@ -846,7 +846,8 @@ public static bool Prefix(SG_HiringHall_Screen __instance, ref bool __result, bo
}
}
__result = false;
return false;
__runOriginal = false;
return;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion Patches/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Text;
using System.Threading.Tasks;
using BattleTech;
using Harmony;
using HBS.Collections;

namespace TisButAScratch.Patches
Expand Down
35 changes: 0 additions & 35 deletions Properties/AssemblyInfo.cs

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TisButAScratch

#### Requires CustomComponents and CustomAmmoCategories
#### v1.1.0.0 and higher requires modtek v3 or higher

This mod overhauls the Battletech injury system, and lets modders apply different stat effects based on injuries a pilot receives. When a pilot receives an injury, a roll is made to determine both the location of the injury and the injury itself. Injuries are specific to a location; Valid `injuryLoc`s are `Head`, `ArmL`, `ArmR`, `Torso`, `LegL` and `LegR`. This mod is fully save-game compatible, and pilots with existing injuries will roll random injury effects on the first time the mod is loaded.

Expand Down
Loading

0 comments on commit f443b04

Please sign in to comment.