Skip to content

Commit

Permalink
SAr compat
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkroeg committed Dec 15, 2022
1 parent 506b111 commit 205a62b
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 140 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,6 @@ ModelManifest.xml
*.pdb
*.dll
.vs/TisButAScratch/v16/.suo

# Ignore the VS Directory.build.props file
Directory.Build.props
162 changes: 39 additions & 123 deletions Patches/SaveAndStatePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ public static void Prefix(SimGameState __instance)
}
}

var rm = PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Keys.Where(x => !curPilots.Contains(x));
foreach (var key in new List<string>(rm))
if (false)
{
PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Remove(key);
ModInit.modLog?.Info?.Write(
$"Pilot with pilotID {key} not in roster, removing from pilotInjuriesMap");
var rm = PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Keys.Where(x => !curPilots.Contains(x));
foreach (var key in new List<string>(rm))
{
PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Remove(key);
ModInit.modLog?.Info?.Write(
$"Pilot with pilotID {key} not in roster, removing from pilotInjuriesMap");
}
}

var rm2 = new List<string>(
Expand Down Expand Up @@ -167,65 +170,8 @@ public static void Postfix(SimGameState __instance)
}
}

if (false)
{


// this bigass clusterfuck is just for if you have existing injuries when first loading up TBAS
if (PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].Count <
sim.Commander.StatCollection.GetValue<int>("Injuries"))
{
var dmg = sim.Commander.StatCollection.GetValue<int>("Injuries") -
PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].Count;
ModInit.modLog?.Info?.Write($"Commander is missing {dmg} TBAS injuries. Rerolling.");
PilotInjuryManager.ManagerInstance.rollInjurySG(sim.Commander, dmg, DamageType.Unknown);
if (ModInit.modSettings.debilSeverityThreshold > 0
) //now trying to add up "severity" threshold for crippled injury
{

var injuryList = new List<Injury>();
foreach (var id in PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey])
{
injuryList.AddRange(
PilotInjuryManager.ManagerInstance.InjuryEffectsList.Where(x => x.injuryID == id));
}

var groupedLocs = injuryList.GroupBy(x => x.injuryLoc);

foreach (var injuryLoc in groupedLocs)
{
var t = 0;
foreach (var injury in injuryLoc)
{
t += injury.severity;
}

if (t >= ModInit.modSettings.debilSeverityThreshold)
{
sim.Commander.pilotDef.PilotTags.Add(DEBILITATEDTAG);
if (ModInit.modSettings.enableLethalTorsoHead && (injuryLoc.Key == InjuryLoc.Head ||
injuryLoc.Key == InjuryLoc.Torso))
{
sim.Commander.StatCollection.ModifyStat<bool>("TBAS_Injuries", 0,
"LethalInjury",
StatCollection.StatOperation.Set, true);
}
}
}
}

var rm2 = new List<string>(
PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Keys.Where(x => x.EndsWith(aiPilotFlag)));
foreach (var key in rm2)
{
PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Remove(key);
ModInit.modLog?.Info?.Write(
$"Pilot with pilotID {key} was AI Pilot, removing from pilotInjuriesMap");
}
}
}
if (PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].Count >
sim.Commander.StatCollection.GetValue<int>("Injuries"))
sim.Commander.StatCollection.GetValue<int>("Injuries"))
{
if (sim.Commander.StatCollection.GetValue<int>("Injuries") < 1)
{
Expand All @@ -234,14 +180,16 @@ public static void Postfix(SimGameState __instance)
}
else
{
var dmg = PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].Count - sim.Commander.StatCollection.GetValue<int>("Injuries");
var dmg = PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].Count -
sim.Commander.StatCollection.GetValue<int>("Injuries");
for (int i = 0; i < dmg; i++)
{
PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].RemoveAt(i);
ModInit.modLog?.Info?.Write($"Commander has {dmg} more TBAS injuries than vanilla injuries, removing TBAS injury at {i}.");
ModInit.modLog?.Info?.Write(
$"Commander has {dmg} more TBAS injuries than vanilla injuries, removing TBAS injury at {i}.");
}
}

}

foreach (Pilot p in sim.PilotRoster)
Expand All @@ -260,7 +208,8 @@ public static void Postfix(SimGameState __instance)
if (!PilotInjuryHolder.HolderInstance.pilotInjuriesMap.ContainsKey(pKey))
{
PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Add(pKey, new List<string>());
ModInit.modLog?.Info?.Write($"{p.Callsign} missing, added to pilotInjuriesMap with iGUID {pKey}");
ModInit.modLog?.Info?.Write(
$"{p.Callsign} missing, added to pilotInjuriesMap with iGUID {pKey}");
}

foreach (var id in new List<string>(PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey]))
Expand All @@ -272,81 +221,48 @@ public static void Postfix(SimGameState __instance)
ModInit.modLog?.Info?.Write($"Removed deprecated injury from {p.Callsign} with id {id}");
}
}

// this bigass clusterfuck is just for if you have existing injuries when first loading up TBAS.
if (false)
{
if (PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].Count <
p.StatCollection.GetValue<int>("Injuries"))
{
var dmg = p.StatCollection.GetValue<int>("Injuries") -
PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].Count;
ModInit.modLog?.Info?.Write($"{p.Callsign} is missing {dmg} TBAS injuries. Rerolling.");
PilotInjuryManager.ManagerInstance.rollInjurySG(p, dmg, DamageType.Unknown);
if (ModInit.modSettings.debilSeverityThreshold > 0
) //now trying to add up "severity" threshold for crippled injury
{

var injuryList = new List<Injury>();
foreach (var id in PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey])
{
injuryList.AddRange(
PilotInjuryManager.ManagerInstance.InjuryEffectsList.Where(
x => x.injuryID == id));
}

var groupedLocs = injuryList.GroupBy(x => x.injuryLoc);

foreach (var injuryLoc in groupedLocs)
{
var t = 0;
foreach (var injury in injuryLoc)
{
t += injury.severity;
}

if (t > ModInit.modSettings.debilSeverityThreshold)
{
p.pilotDef.PilotTags.Add(DEBILITATEDTAG);
if (ModInit.modSettings.enableLethalTorsoHead &&
(injuryLoc.Key == InjuryLoc.Head ||
injuryLoc.Key == InjuryLoc.Torso))
{
p.StatCollection.ModifyStat<bool>("TBAS_Injuries", 0,
"LethalInjury",
StatCollection.StatOperation.Set, true);
}
}
}
}
}
}

if (PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].Count >
p.StatCollection.GetValue<int>("Injuries"))
p.StatCollection.GetValue<int>("Injuries"))
{
if (p.StatCollection.GetValue<int>("Injuries") < 1)
{
PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey] = new List<string>();
ModInit.modLog?.Info?.Write($"Pilot {p.Callsign} had no vanilla injuries, clearing TBAS injuries.");
ModInit.modLog?.Info?.Write(
$"Pilot {p.Callsign} had no vanilla injuries, clearing TBAS injuries.");
}
else
{
var dmg = PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].Count - p.StatCollection.GetValue<int>("Injuries");
var dmg = PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].Count -
p.StatCollection.GetValue<int>("Injuries");
for (int i = 0; i < dmg; i++)
{
PilotInjuryHolder.HolderInstance.pilotInjuriesMap[pKey].RemoveAt(i);
ModInit.modLog?.Info?.Write($"Pilot {p.Callsign} has {dmg} more TBAS injuries than vanilla injuries, removing TBAS injury at {i}.");
ModInit.modLog?.Info?.Write(
$"Pilot {p.Callsign} has {dmg} more TBAS injuries than vanilla injuries, removing TBAS injury at {i}.");
}
}
}
}

var rm = PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Keys.Where(x => !curPilots.Contains(x));
foreach (var key in new List<string>(rm))
var rm2 = new List<string>(
PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Keys.Where(x => x.EndsWith(aiPilotFlag)));
foreach (var key in rm2)
{
PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Remove(key);
ModInit.modLog?.Info?.Write(
$"Pilot with pilotID {key} not in roster, removing from pilotInjuriesMap");
$"Pilot with pilotID {key} was AI Pilot, removing from pilotInjuriesMap");
}

if (false)
{
var rm = PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Keys.Where(x => !curPilots.Contains(x));
foreach (var key in new List<string>(rm))
{
PilotInjuryHolder.HolderInstance.pilotInjuriesMap.Remove(key);
ModInit.modLog?.Info?.Write(
$"Pilot with pilotID {key} not in roster, removing from pilotInjuriesMap");
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Patches/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static void Postfix(MechDef __instance, ref TagSet __result)
//ModInit.modLog?.Info?.Write($"[UtilityPatches_MechTag] .");
return;
}
if (!Utility.CachedTagSets.ContainsKey(__instance?.Description?.Id))
if (!Utility.CachedTagSets.ContainsKey(__instance.Description.Id))
{
Utility.CachedTagSets.Add(__instance?.Description?.Id, __result);
Utility.CachedTagSets.Add(__instance.Description.Id, __result);
var values = $"\n";
foreach (var tag in __result)
{
Expand All @@ -65,7 +65,7 @@ public static void Postfix(MechDef __instance, ref TagSet __result)
{
values += $"\n{tag}";
}
ModInit.modLog?.Info?.Write($"[UtilityPatches_MechTag] Equality check failure, Tagset changed since init. Dumping stack trace and tagset: {Environment.StackTrace} TagSet Values: {values}");
ModInit.modLog?.Info?.Write($"[UtilityPatches_MechTag] Equality check failure for {__instance.Description.Id}, Tagset changed since init. Dumping stack trace and tagset: {Environment.StackTrace} TagSet Values: {values}");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.4.7")]
[assembly: AssemblyFileVersion("1.0.4.7")]
[assembly: AssemblyVersion("1.0.4.8")]
[assembly: AssemblyFileVersion("1.0.4.8")]
22 changes: 11 additions & 11 deletions TisButAScratch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,43 @@
<ItemGroup>
<Reference Include="0Harmony, Version=1.2.0.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>D:\SteamLibrary\steamapps\common\BATTLETECH\BattleTech_Data\Managed\0Harmony.dll</HintPath>
<HintPath>$(BattleTechGameDir)\BattleTech_Data\Managed\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>D:\SteamLibrary\steamapps\common\BATTLETECH\BattleTech_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>$(BattleTechGameDir)\BattleTech_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>F:\Steam Library\steamapps\common\BATTLETECH\BattleTech_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath>$(BattleTechGameDir)\BattleTech_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="CustomComponents, Version=8.5.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\BATTLETECH\Mods\CustomComponents\CustomComponents.dll</HintPath>
<HintPath>$(BattleTechGameDir)\Mods\CustomComponents\CustomComponents.dll</HintPath>
</Reference>
<Reference Include="InControl">
<HintPath>F:\Steam Library\steamapps\common\BATTLETECH\BattleTech_Data\Managed\InControl.dll</HintPath>
<HintPath>$(BattleTechGameDir)\BattleTech_Data\Managed\InControl.dll</HintPath>
</Reference>
<Reference Include="IRBTModUtils">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\BATTLETECH\Mods\IRBTModUtils\IRBTModUtils.dll</HintPath>
<HintPath>$(BattleTechGameDir)\Mods\IRBTModUtils\IRBTModUtils.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>F:\Steam Library\steamapps\common\BATTLETECH\BattleTech_Data\Managed\Newtonsoft.Json.dll</HintPath>
<HintPath>$(BattleTechGameDir)\BattleTech_Data\Managed\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Unity.TextMeshPro">
<HintPath>F:\Steam Library\steamapps\common\BATTLETECH\BattleTech_Data\Managed\Unity.TextMeshPro.dll</HintPath>
<HintPath>$(BattleTechGameDir)\BattleTech_Data\Managed\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>F:\Steam Library\steamapps\common\BATTLETECH\BattleTech_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>$(BattleTechGameDir)\BattleTech_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>F:\Steam Library\steamapps\common\BATTLETECH\BattleTech_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<HintPath>$(BattleTechGameDir)\BattleTech_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>F:\Steam Library\steamapps\common\BATTLETECH\BattleTech_Data\Managed\UnityEngine.UI.dll</HintPath>
<HintPath>$(BattleTechGameDir)\BattleTech_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
Binary file modified bin/Debug/Assembly-CSharp.dll
Binary file not shown.
Binary file modified bin/Debug/TisButAScratch.dll
Binary file not shown.
Binary file modified bin/Debug/TisButAScratch.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion obj/Debug/TisButAScratch.csproj.CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
598ff3b8e57ee2a9a7d802e0326eb5357d0974c1
c64154fd8186abd14df9d1ae87f90f8f0f1e760b
Loading

0 comments on commit 205a62b

Please sign in to comment.