Skip to content

Commit

Permalink
fixes allow forbidden with unhaulable items
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Sep 24, 2020
1 parent ef02f1b commit c194ff7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Binary file modified 1.2/Assemblies/AchtungMod.dll
Binary file not shown.
7 changes: 5 additions & 2 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,9 @@ public static int GetPriority(Pawn pawn, WorkTypeDef w)
return pawn.workSettings.GetPriority(w);
}

static bool IgnoreForbiddenHauling(WorkGiver_Scanner workgiver)
static bool IgnoreForbiddenHauling(WorkGiver_Scanner workgiver, Thing thing)
{
if (workgiver is WorkGiver_Haul && thing.def.alwaysHaulable == false && thing.def.EverHaulable == false) return false;
if (Achtung.Settings.ignoreForbidden == false) return false;
return workgiver.Ignorable();
}
Expand All @@ -436,7 +437,7 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
var c_FloatMenuOption = AccessTools.FirstConstructor(typeof(FloatMenuOption), c => c.GetParameters().Count() > 1);
var m_ForcedFloatMenuOption = AccessTools.Method(typeof(ForcedFloatMenuOption), createForcedMenuItemName);
var m_Accepts = SymbolExtensions.GetMethodInfo(() => new ThingRequest().Accepts(default));
var m_IgnoreForbiddenHauling = SymbolExtensions.GetMethodInfo(() => IgnoreForbiddenHauling(default));
var m_IgnoreForbiddenHauling = SymbolExtensions.GetMethodInfo(() => IgnoreForbiddenHauling(default, default));

var list = instructions.ToList();

Expand All @@ -445,13 +446,15 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
Log.Error("Cannot find ThingRequest.Accepts in RimWorld.FloatMenuMakerMap::AddJobGiverWorkOrders");
else
{
var loadThingVar = list[idx - 1];
var jump = list[idx + 1];
if (jump.Branches(out var label) == false)
Log.Error("Cannot find branch after ThingRequest.Accepts in RimWorld.FloatMenuMakerMap::AddJobGiverWorkOrders");
else
list.InsertRange(idx + 2, new[]
{
list[idx + 2], // local variable 'WorkGiver_Scanner'
loadThingVar.Clone(), // clicked thing
new CodeInstruction(OpCodes.Call, m_IgnoreForbiddenHauling),
new CodeInstruction(OpCodes.Brtrue, label)
});
Expand Down

0 comments on commit c194ff7

Please sign in to comment.