Skip to content

Commit

Permalink
Fixed preloading of components so AutoFixer works again.
Browse files Browse the repository at this point in the history
  • Loading branch information
CptMoore committed Jan 18, 2020
1 parent 0b0853b commit 4009b62
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 43 deletions.
12 changes: 5 additions & 7 deletions source/Fixes/BTLoadUtils.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
using BattleTech;
using BattleTech;
using BattleTech.Data;
using System;

namespace CustomComponents
{
class BTLoadUtils
{
internal static void PreloadComponents(DataManager manager)
internal static LoadRequest CreateLoadRequest(DataManager dataManager, Action<LoadRequest> loadCompleteCallback, bool filterByOwnership)
{
var loadRequest = manager.CreateLoadRequest();
var loadRequest = dataManager.CreateLoadRequest(loadCompleteCallback, filterByOwnership);
loadRequest.AddAllOfTypeLoadRequest<HeatSinkDef>(BattleTechResourceType.HeatSinkDef, null);
loadRequest.AddAllOfTypeLoadRequest<UpgradeDef>(BattleTechResourceType.UpgradeDef, null);
loadRequest.AddAllOfTypeLoadRequest<WeaponDef>(BattleTechResourceType.WeaponDef, null);
loadRequest.AddAllOfTypeLoadRequest<AmmunitionBoxDef>(BattleTechResourceType.AmmunitionBoxDef, null);
loadRequest.AddAllOfTypeLoadRequest<JumpJetDef>(BattleTechResourceType.AmmunitionBoxDef, null);
loadRequest.ProcessRequests();
return loadRequest;
}
}
}
25 changes: 9 additions & 16 deletions source/Fixes/SimGameState_RequestDataManagerResources_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BattleTech;
using BattleTech;
using BattleTech.Data;
using Harmony;
using System.Collections.Generic;

namespace CustomComponents.Fixes
{
[HarmonyPatch(typeof(SimGameState), "RequestDataManagerResources")]
public static class SimGameState_RequestDataManagerResources_Patch
{
[HarmonyPrefix]
public static void Preload(SimGameState __instance)
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
try
{
BTLoadUtils.PreloadComponents(__instance.DataManager);
}
catch (Exception e)
{
Control.LogError(e);
}

return instructions
.MethodReplacer(
AccessTools.Method(typeof(DataManager), nameof(DataManager.CreateLoadRequest)),
AccessTools.Method(typeof(BTLoadUtils), nameof(BTLoadUtils.CreateLoadRequest))
);
}
}
}
18 changes: 8 additions & 10 deletions source/Fixes/SkirmishMechBayPanel_RequestResources_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
using System;
using BattleTech.Data;
using BattleTech.UI;
using Harmony;
using System.Collections.Generic;

namespace CustomComponents
{
[HarmonyPatch(typeof(SkirmishMechBayPanel), "RequestResources")]
public static class SkirmishMechBayPanel_RequestResources_Patch
{
public static void Prefix(SkirmishMechBayPanel __instance)
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
try
{
BTLoadUtils.PreloadComponents(__instance.dataManager);
}
catch (Exception e)
{
Control.LogError(e);
}
return instructions
.MethodReplacer(
AccessTools.Method(typeof(DataManager), nameof(DataManager.CreateLoadRequest)),
AccessTools.Method(typeof(BTLoadUtils), nameof(BTLoadUtils.CreateLoadRequest))
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
using System;
using BattleTech.Data;
using BattleTech.UI;
using Harmony;
using System.Collections.Generic;

namespace CustomComponents
{
[HarmonyPatch(typeof(SkirmishSettings_Beta), "LoadLanceConfiguratorData")]
public static class SkirmishSettings_Beta_LoadLanceConfiguratorData_Patch
{
public static void Prefix(SkirmishSettings_Beta __instance, UIManager ___uiManager)
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
try
{
BTLoadUtils.PreloadComponents(___uiManager.dataManager);
}
catch (Exception e)
{
Control.LogError(e);
}
return instructions
.MethodReplacer(
AccessTools.Method(typeof(DataManager), nameof(DataManager.CreateLoadRequest)),
AccessTools.Method(typeof(BTLoadUtils), nameof(BTLoadUtils.CreateLoadRequest))
);
}
}
}

0 comments on commit 4009b62

Please sign in to comment.