Skip to content

Commit

Permalink
v1.1.8
Browse files Browse the repository at this point in the history
Significant optimisations made to loading times
  • Loading branch information
XeoNovaDan committed Jul 4, 2019
1 parent 935ab33 commit e611141
Show file tree
Hide file tree
Showing 27 changed files with 621 additions and 344 deletions.
Binary file modified 1.0/Assemblies/SurvivalTools.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<name>[XND] Survival Tools</name>
<author>XeoNovaDan</author>
<url>https://ludeon.com/forums/index.php?topic=29503.0</url>
<description>Current version: v1.1.7 (27th June 2019)\n\nAdds tools and the need to manage tools to RimWorld.\n* Colonists work much less efficiently in certain tasks without the relevant tools\n* Colonists can use tools from their inventory as well as their main hand\n* Acquire tools through production, purchase and plunder\n* Different materials affect tools in different ways\n* Tools will degrade over use</description>
<description>Current version: v1.1.8 (4th July 2019)\n\nAdds tools and the need to manage tools to RimWorld.\n* Colonists work much less efficiently in certain tasks without the relevant tools\n* Colonists can use tools from their inventory as well as their main hand\n* Acquire tools through production, purchase and plunder\n* Different materials affect tools in different ways\n* Tools will degrade over use</description>
<supportedVersions>
<li>1.0</li>
</supportedVersions>
Expand Down
Binary file modified Source/SurvivalTools/.vs/SurvivalTools/v16/.suo
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using UnityEngine;
using Verse;
using RimWorld;
using RimWorld.BaseGen;
using Harmony;
using System.Reflection;
using System.Reflection.Emit;
Expand All @@ -14,7 +15,7 @@ namespace SurvivalTools.Harmony

[HarmonyPatch(typeof(ITab_Pawn_Gear))]
[HarmonyPatch("DrawThingRow")]
public static class Patch_ITab_Pawn_Gear
public static class Patch_ITab_Pawn_Gear_DrawThingRow
{

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
Expand All @@ -27,18 +28,19 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
{
var instruction = instructionList[i];

yield return instruction;

// If equipment is a tool, adjust its label in a similar fashion to how apparel labels are adjusted (though using a helper method)
if (!done && instruction.opcode == OpCodes.Stloc_S && instruction.operand.ToString() == "5")
if (!done && instruction.opcode == OpCodes.Stloc_S && ((LocalBuilder)instruction.operand).LocalIndex == 5)
{
yield return instruction;
yield return new CodeInstruction(OpCodes.Ldloca_S, 5); // text
yield return new CodeInstruction(OpCodes.Ldarg_3); // thing
yield return new CodeInstruction(OpCodes.Ldarg_0); // this
yield return new CodeInstruction(OpCodes.Call, AccessTools.Property(typeof(ITab_Pawn_Gear), "SelPawnForGear").GetGetMethod(true)); // this.SelPawnForGear
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Patch_ITab_Pawn_Gear), "AdjustDisplayedLabel")); // AdjustDisplayedLabel(ref text, thing, this.SelPawnForGear)
instruction = new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(Patch_ITab_Pawn_Gear_DrawThingRow), "AdjustDisplayedLabel")); // AdjustDisplayedLabel(ref text, thing, this.SelPawnForGear)
done = true;
}

yield return instruction;
}
}

Expand All @@ -55,6 +57,7 @@ public static void AdjustDisplayedLabel(ref string originalLabel, Thing thing, P
originalLabel += $", {"ToolInUse".Translate()}";
}
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using RimWorld;
using RimWorld.BaseGen;
using Harmony;
using System.Reflection;
using System.Reflection.Emit;

namespace SurvivalTools.Harmony
{

[HarmonyPatch(typeof(Mineable))]
[HarmonyPatch(nameof(Mineable.Notify_TookMiningDamage))]
public static class Patch_Mineable_Notify_TookMiningDamage
{

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> instructionList = instructions.ToList();

for (int i = 0; i < instructionList.Count; i++)
{
CodeInstruction instruction = instructionList[i];

if (instruction.opcode == OpCodes.Ldsfld && instruction.operand == AccessTools.Field(typeof(StatDefOf), nameof(StatDefOf.MiningYield)))
{
instruction.operand = AccessTools.Field(typeof(ST_StatDefOf), nameof(ST_StatDefOf.MiningYieldDigging));
}

yield return instruction;
}
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using RimWorld;
using RimWorld.BaseGen;
using Harmony;
using System.Reflection;
using System.Reflection.Emit;

namespace SurvivalTools.Harmony
{

[HarmonyPatch(typeof(JobDriver_Mine))]
[HarmonyPatch("ResetTicksToPickHit")]
public static class Patch_JobDriver_Mine_ResetTicksToPickHit
{

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> instructionList = instructions.ToList();

for (int i = 0; i < instructionList.Count; i++)
{
CodeInstruction instruction = instructionList[i];

if (instruction.opcode == OpCodes.Ldsfld && instruction.operand == AccessTools.Field(typeof(StatDefOf), nameof(StatDefOf.MiningSpeed)))
{
instruction.operand = AccessTools.Field(typeof(ST_StatDefOf), nameof(ST_StatDefOf.DiggingSpeed));
}

yield return instruction;
}
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using RimWorld;
using RimWorld.BaseGen;
using Harmony;
using System.Reflection;
using System.Reflection.Emit;

namespace SurvivalTools.Harmony
{

[HarmonyPatch(typeof(MassUtility))]
[HarmonyPatch(nameof(MassUtility.CountToPickUpUntilOverEncumbered))]
public static class Patch_MassUtility_CountToPickUpUntilOverEncumbered
{

public static void Postfix(ref int __result, Pawn pawn, Thing thing)
{
if (__result > 0 && pawn.RaceProps.Humanlike && thing as SurvivalTool != null && !pawn.CanCarryAnyMoreSurvivalTools())
__result = 0;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using RimWorld;
using RimWorld.BaseGen;
using Harmony;
using System.Reflection;
using System.Reflection.Emit;

namespace SurvivalTools.Harmony
{

[HarmonyPatch(typeof(MassUtility))]
[HarmonyPatch(nameof(MassUtility.WillBeOverEncumberedAfterPickingUp))]
public static class Patch_MassUtility_WillBeOverEncumberedAfterPickingUp
{

// Another janky hack
public static void Postfix(ref bool __result, Pawn pawn, Thing thing)
{
if (pawn.RaceProps.Humanlike && thing as SurvivalTool != null && !pawn.CanCarryAnyMoreSurvivalTools())
__result = true;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using RimWorld;
using RimWorld.BaseGen;
using Harmony;
using System.Reflection;
using System.Reflection.Emit;

namespace SurvivalTools.Harmony
{

[HarmonyPatch(typeof(Pawn_InventoryTracker))]
[HarmonyPatch(nameof(Pawn_InventoryTracker.FirstUnloadableThing), MethodType.Getter)]
public static class Patch_Pawn_InventoryTracker_FirstUnloadableThing
{

public static void Postfix(Pawn_InventoryTracker __instance, ref ThingCount __result)
{
if (__result.Thing is SurvivalTool tool && tool.InUse)
{
bool foundNewThing = false;
// Had to iterate through because a lambda expression in this case isn't possible
for (int i = 0; i < __instance.innerContainer.Count; i++)
{
Thing newThing = __instance.innerContainer[i];
if (newThing as SurvivalTool == null || !((SurvivalTool)newThing).InUse)
{
__result = new ThingCount(newThing, newThing.stackCount);
foundNewThing = true;
break;
}
}
if (!foundNewThing)
__result = default;
}
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using Verse.AI;
using RimWorld;
using RimWorld.BaseGen;
using Harmony;
using System.Reflection;
using System.Reflection.Emit;

namespace SurvivalTools.Harmony
{

[HarmonyPatch(typeof(Pawn_InventoryTracker))]
[HarmonyPatch(nameof(Pawn_InventoryTracker.InventoryTrackerTickRare))]
public static class Patch_Pawn_InventoryTracker_InventoryTrackerTickRare
{

public static void Postfix(Pawn_InventoryTracker __instance)
{
if (SurvivalToolsSettings.toolLimit)
{
Pawn pawn = __instance.pawn;
if (pawn.CanUseSurvivalTools() && pawn.GetHeldSurvivalTools().Count() > pawn.GetStatValue(ST_StatDefOf.SurvivalToolCarryCapacity) && pawn.CanRemoveExcessSurvivalTools())
{
Thing tool = pawn.GetHeldSurvivalTools().Last();
Job job = pawn.DequipAndTryStoreSurvivalTool(tool);
pawn.jobs.StartJob(job, JobCondition.InterruptForced, cancelBusyStances: false);
}
}
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using RimWorld;
using RimWorld.BaseGen;
using Harmony;
using System.Reflection;
using System.Reflection.Emit;

namespace SurvivalTools.Harmony
{

[HarmonyPatch(typeof(Pawn_InventoryTracker))]
[HarmonyPatch(nameof(Pawn_InventoryTracker.Notify_ItemRemoved))]
public static class Patch_Pawn_InventoryTracker_Notify_ItemRemoved
{

public static void Postfix(Pawn_InventoryTracker __instance, Thing item)
{
if (item is SurvivalTool && __instance.pawn.TryGetComp<Pawn_SurvivalToolAssignmentTracker>() is Pawn_SurvivalToolAssignmentTracker assignmentTracker)
{
assignmentTracker.forcedHandler.SetForced(item, false);
}

}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;
using RimWorld;
using RimWorld.BaseGen;
using Harmony;
using System.Reflection;
using System.Reflection.Emit;

namespace SurvivalTools.Harmony
{

[HarmonyPatch(typeof(RoofUtility))]
[HarmonyPatch(nameof(RoofUtility.CanHandleBlockingThing))]
public static class Patch_RoofUtility_CanHandleBlockingThing
{

public static void Postfix(ref bool __result, Thing blocker, Pawn worker)
{
if (blocker?.def.plant?.IsTree == true && !worker.MeetsWorkGiverStatRequirements(ST_WorkGiverDefOf.FellTrees.GetModExtension<WorkGiverExtension>().requiredStats))
__result = false;
}

}

}
Loading

0 comments on commit e611141

Please sign in to comment.