Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,4 @@ __pycache__/

libs/
libs.fixed/
*/*.swp
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
- Make all simgame room transitions instant.
- RemovedContractsFix
- This fix removes invalid contracts allowing saves to load if a user created contract was removed from the mods in use.
- NavigationMapFilterLagFix
- This fix removes some unnecessary code in the navigation map's difficulty filter selection.
- The performance gain is negligible in vanilla, but in modpacks using the entire IS map such as RT or BTA, this saves a few seconds.

# Experimental patches
- MDDB_TagsetQueryInChunks
Expand Down
5 changes: 3 additions & 2 deletions source/BattletechPerformanceFix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="LocalizationPatches.cs" />
<Compile Include="HarmonyPatches.cs" />
<Compile Include="ContractLagFix.cs" />
<Compile Include="NavigationMapFilterLagFix.cs" />
<Compile Include="DisableSensitiveDataLogDump.cs" />
<Compile Include="DisableDeployAudio.cs" />
<Compile Include="DisableSimAnimations.cs" />
Expand All @@ -67,7 +68,7 @@
<Compile Include="LoadFixes.cs" />
<Compile Include="ShaderDependencyOverride.cs" />
<Compile Include="ShopTabLagFix.cs" />
<Compile Include="PatchMechLabLimitItems.cs" />
<Compile Include="PatchMechlabLimitItems.cs" />
<Compile Include="EnableLoggingDuringLoads.cs" />
<Compile Include="RemovedFlashpointFix.cs" />
<Compile Include="RemovedContractsFix.cs" />
Expand Down Expand Up @@ -120,4 +121,4 @@
<PostBuildEvent Condition="$(IsLinux) == true">yes | cp "$(TargetDir)$(TargetName).dll" "$(SolutionDir)../../Mods/BattletechPerformanceFix/$(TargetName).dll"</PostBuildEvent>
<PostBuildEvent Condition="$(IsOSX) == true">yes | cp "$(TargetDir)$(TargetName).dll" "$(SolutionDir)../../Mods/BattletechPerformanceFix/$(TargetName).dll"</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public static void Start(string modDirectory, string json)
{ typeof(DataLoaderGetEntryCheck), true },
{ typeof(ShopTabLagFix), true },
{ typeof(ContractLagFix), true },
{ typeof(NavigationMapFilterLagFix), true },
{ typeof(EnableLoggingDuringLoads), true },
{ typeof(ExtraLogging), true },
{ typeof(ShaderDependencyOverride), true },
Expand Down
60 changes: 60 additions & 0 deletions source/NavigationMapFilterLagFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Collections.Generic;
using System.Linq;
using BattleTech.UI;
using Harmony;
using System.Reflection;
using System.Reflection.Emit;
using static BattletechPerformanceFix.Extensions;

namespace BattletechPerformanceFix
{
/* Removes a redundant call for creating difficulty callouts, saves a few seconds per filter selection */
class NavigationMapFilterLagFix : Feature
{
public void Activate()
{
var method = AccessTools.Method(typeof(SGNavigationScreen), "OnDifficultySelectionChanged");
var transpiler = new HarmonyMethod(typeof(NavigationMapFilterLagFix), nameof(Transpiler));
Main.harmony.Patch(method, null, null, transpiler);
}

// cuts out the if/else block in OnDifficultySelectionChanged() because CreateDifficultyCallouts()
// is called later by RefreshSystemIndicators() anyways just after the block
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
int startIndex = -1;
int endIndex = -1;

// searches for the if block start & end points, in case some other mod is modifying this function
// (which is why we don't hardcode the indices)
var code = instructions.ToList();
for (int i = 0; i < code.Count-1; i++) {
if (startIndex == -1) {
if (code[i].opcode == OpCodes.Ldarg_1 && code[i+1].opcode == OpCodes.Brtrue) {
startIndex = i;
}
} else {
if (code[i].opcode == OpCodes.Ldarg_1 && code[i+1].opcode == OpCodes.Call &&
(code[i+1].operand as MethodInfo).Name == "CreateDifficultyCallouts") {
endIndex = i+1;
break;
}
}
}

if (startIndex != -1 && endIndex != -1) {
LogDebug("Overwriting instructions in SGNavigationScreen.OnDifficultySelectionChanged()" +
" at indices " + startIndex + "-" + endIndex + " with nops");
for (int i = startIndex; i <= endIndex; i++) {
code[i].opcode = OpCodes.Nop;
}
} else {
LogError("Failed to find the code to overwrite in " +
"SGNavigationScreen.OnDifficultySelectionChanged(); no changes were made.");
LogError("NavigationMapFilterLagFix has not been applied, report this as a bug");
}

return code.AsEnumerable();
}
}
}