Skip to content

Commit

Permalink
feat: supress the "Shuttle is loaded with required cargo and can laun…
Browse files Browse the repository at this point in the history
…ch when ready" message
  • Loading branch information
ilyvion committed May 12, 2024
1 parent 95cf105 commit 45a5cf7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The way grace time was calculated was not very intuitive. Instead of adding the grace time to the existing time, the time was directly set to the grace time value. This meant that you could end up in a situation where when you were supposed to have grace time added, it would actually give you _less_ time instead of more! For instance if the trader was leaving in 6 hours and you had set your grace time setting to 4 hours, the new trader leave time would be in 4 hours, not the expected 10! The logic is now that the grace time is added on top of the existing time, not replacing it.
- Trade ships will now leave an hour after the last trade if their comms were closed; there's no reason to keep them around any longer than that.
- When you get blacklisted, all active trade quests will be cancelled, not just the one whose shuttle you destroyed.
- Supress the "Shuttle is loaded with required cargo and can launch when ready" message that would appear after a trade shuttle was fully loaded; an artefact of vanilla-inherited behavior.

### Fixed

Expand Down
42 changes: 42 additions & 0 deletions Source/RealisticOrbitalTrade/Comps/CompTradeShuttle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,45 @@ private static void Postfix(CompShuttle __instance, ref bool __result)
}
}
}


[HarmonyPatch(typeof(CompTransporter), nameof(CompTransporter.SubtractFromToLoadList))]
internal static class Rimworld_CompTransporter_SubtractFromToLoadList
{
private static bool HideFinishedMessageForTradeShuttle(CompTransporter compTransporter)
{
return compTransporter?.parent.TryGetComp<CompTradeShuttle>() != null;
}

#pragma warning disable CS8625
private static readonly MethodInfo _methodHideFinishedMessageForTradeShuttle = SymbolExtensions.GetMethodInfo(() => HideFinishedMessageForTradeShuttle(default));
#pragma warning restore CS8625

private static readonly MethodInfo _methodCompTransporterAnyInGroupHasAnythingLeftToLoad_get = AccessTools.PropertyGetter(typeof(CompTransporter), nameof(CompTransporter.AnyInGroupHasAnythingLeftToLoad));

private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var codeMatcher = new CodeMatcher(instructions);

codeMatcher.SearchForward(i => i.opcode == OpCodes.Call && i.operand is MethodInfo m && m == _methodCompTransporterAnyInGroupHasAnythingLeftToLoad_get);
if (!codeMatcher.IsValid)
{
RealisticOrbitalTradeMod.Error("Could not patch CompTransporter.SubtractFromToLoadList, IL does not match expectations: call to get value of CompTransporter::AnyInGroupHasAnythingLeftToLoad not found.");
return codeMatcher.Instructions();
}
codeMatcher.Advance(1);
var endLabel = codeMatcher.Operand;
codeMatcher.Advance(1);

codeMatcher.Insert(new CodeInstruction[] {
// == this
new(OpCodes.Ldarg_0),
// call patch method (HideFinishedMessageForTradeShuttle)
new(OpCodes.Call, _methodHideFinishedMessageForTradeShuttle),
// if HideFinishedMessageForTradeShuttle returns true, skip showing message
new(OpCodes.Brtrue_S, endLabel)
});

return codeMatcher.Instructions();
}
}

0 comments on commit 45a5cf7

Please sign in to comment.