Skip to content

Commit

Permalink
Job scanner fixes (#206)
Browse files Browse the repository at this point in the history
* Fixes for roof building and HasJob method in all scanners

* Cleaning

Co-authored-by: Hazzer <[email protected]>
  • Loading branch information
Hazzer and Hazzer authored Aug 2, 2020
1 parent 1465bdd commit f2522c5
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 22 deletions.
Binary file modified Assemblies/PrisonLabor.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace PrisonLabor.HarmonyPatches.Patches_Construction
{
[HarmonyPatch()]
[HarmonyPatch(typeof(WorkGiver_BuildRoof), "HasJobOnCell")]
class Patch_RoofReservation
{
public static bool Postfix(bool __result, WorkGiver_BuildRoof __instance, Pawn pawn, IntVec3 c, bool forced)
{
if (__result && pawn.IsPrisonerOfColony)
{
try
{
System.Reflection.MethodInfo methodInfo = AccessTools.Method(typeof(WorkGiver_BuildRoof), "BuildingToTouchToBeAbleToBuildRoof");
Building building = methodInfo.Invoke(__instance, new object[] { c, pawn }) as Building;
if (building != null)
{
return pawn.CanReach(building, Verse.AI.PathEndMode.Touch, pawn.NormalMaxDanger());
}
} catch(Exception e)
{
Verse.Log.Message($"Exception in roof patch{e}");
}
}
return __result;
}
}
}
36 changes: 36 additions & 0 deletions Source/HarmonyPatches/Patches_LaborArea/Patch_Scanner_HasJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using HarmonyLib;
using PrisonLabor.Core;
using PrisonLabor.Core.AI.WorkGivers;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace PrisonLabor.HarmonyPatches.Patches_LaborArea
{
[HarmonyPatch]
class Patch_Scanner_HasJob
{
static IEnumerable<MethodBase> TargetMethods()
{
return Assembly.GetAssembly(typeof(WorkGiver_Scanner)).GetTypes()
.Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(WorkGiver_Scanner)) && myType != typeof(WorkGiver_Supervise) && myType != typeof(WorkGiver_Warden))
.SelectMany(type => type.GetMethods())
.Where(method => method.Name.Equals("HasJobOnThing"))
.Cast<MethodBase>();
}

static bool Postfix(bool __result, WorkGiver_Scanner __instance, Pawn pawn, Thing t, bool forced = false)
{
if (__result && t != null )
{
return PrisonLaborUtility.canWorkHere(t.Position, pawn, __instance.def.workType);
}
return __result;
}
}
}
2 changes: 1 addition & 1 deletion Source/Initialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static Initialization()
}
catch (Exception e)
{
Log.Error($"Prison Labor v{VersionUtility.versionString} caught error during start up:\n{e.Message}");
Log.Error($"Prison Labor v{VersionUtility.versionString} caught error during start up:\n{e}");
}

}
Expand Down
48 changes: 27 additions & 21 deletions Source/PrisonLabor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,30 @@
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>packages\Rimworld\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\Gry\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>packages\Rimworld\UnityEngine.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\Gry\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>packages\Rimworld\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\Gry\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>packages\Rimworld\UnityEngine.IMGUIModule.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\Gry\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>packages\Rimworld\UnityEngine.TextRenderingModule.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\Gry\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CompatibilityPatches\Quarry.cs" />
<Compile Include="Core\Alerts\Alert_EscapingPrisoners.cs" />
<Compile Include="Core\Alerts\Alert_LazyPrisoners.cs" />
<Compile Include="Core\Alerts\Alert_StarvingPrisoners.cs" />
Expand All @@ -79,13 +75,11 @@
<Compile Include="CompatibilityPatches\NoWaterNoLife.cs" />
<Compile Include="CompatibilityPatches\OlderVersions.cs" />
<Compile Include="CompatibilityPatches\WorkTab.cs" />
<Compile Include="CompatibilityPatches\SeedsPlease.cs" />
<Compile Include="CompatibilityPatches\SeedsPlease_WorkDriver_Patch.cs" />
<Compile Include="CompatibilityPatches\SeedsPlease_WorkGiver.cs" />
<Compile Include="Core\LaborArea\Designator_AreaLaborClear.cs" />
<Compile Include="Core\LaborArea\Designator_AreaLabor.cs" />
<Compile Include="Core\LaborArea\Designator_AreaLaborExpand.cs" />
<Compile Include="Core\Meta\Version.cs" />
<Compile Include="Core\Other\ModSearcher.cs" />
<Compile Include="Core\Other\NewsProvider.cs" />
<Compile Include="Core\Other\TutorialProvider.cs" />
<Compile Include="Core\Settings\CleanSaveDialog.cs" />
Expand All @@ -96,6 +90,9 @@
<Compile Include="HarmonyPatches\DevTools.cs" />
<Compile Include="HarmonyPatches\Patches_AssignBed\Patch_AssignPrisonersToBed.cs" />
<Compile Include="HarmonyPatches\Patches_Construction\EnableConstructionFinishFrames.cs" />
<Compile Include="HarmonyPatches\Patches_Construction\Patch_BlueprintsForPlayerFaction.cs" />
<Compile Include="HarmonyPatches\Patches_Construction\Patch_RoofReservation.cs" />
<Compile Include="HarmonyPatches\Patches_Construction\Patch_Smoothing.cs" />
<Compile Include="HarmonyPatches\Patches_DeepDrill\EnableDeepDrillsToPrisoners.cs" />
<Compile Include="HarmonyPatches\Patches_Escaping\Patch_EscapeTracker.cs" />
<Compile Include="HarmonyPatches\Patches_Food\AddCustomFoodReservation.cs" />
Expand All @@ -105,6 +102,12 @@
<Compile Include="HarmonyPatches\Patches_Food\ReservedByPrisonerPatch.cs" />
<Compile Include="HarmonyPatches\Patches_Food\StopIfPrisonerCanGetFoodByHimself.cs" />
<Compile Include="HarmonyPatches\Patches_LaborArea\Patch_AddLaborArea.cs" />
<Compile Include="HarmonyPatches\Patches_LaborArea\Patch_Labor_Thing.cs" />
<Compile Include="HarmonyPatches\Patches_LaborArea\Patch_Labor_Position.cs" />
<Compile Include="HarmonyPatches\Patches_Construction\WorkGiver_ConstructDeliverResourcesToBlueprints.cs" />
<Compile Include="HarmonyPatches\Patches_Construction\Patch_WorkGiver_ConstructDeliverResourcesToFrames.cs" />
<Compile Include="HarmonyPatches\Patches_Construction\Patch_WorkGiver_Repair.cs" />
<Compile Include="HarmonyPatches\Patches_LaborArea\Patch_Scanner_HasJob.cs" />
<Compile Include="HarmonyPatches\Patches_PermissionFix\Patch_ForibiddenDrop2.cs" />
<Compile Include="HarmonyPatches\Patches_Version\Patch_AddModVersionToFile.cs" />
<Compile Include="HarmonyPatches\Patches_GUI\GUI_PrisonerTab\Patch_AddScrollToPrisonerTab.cs" />
Expand All @@ -120,7 +123,6 @@
<Compile Include="HarmonyPatches\Patches_PermissionFix\Patch_ItemIsForbidden.cs" />
<Compile Include="HarmonyPatches\HPatcher.cs" />
<Compile Include="HarmonyPatches\Patches_SaveCompatibility\Patch_JailorTypeSaveCompatibility.cs" />
<Compile Include="HarmonyPatches\Patches_LaborArea\Patch_LaborForbid.cs" />
<Compile Include="HarmonyPatches\Patches_Needs\Patch_NeedOnlyByPrisoners.cs" />
<Compile Include="HarmonyPatches\Patches_GUI\GUI_PrisonerTab\Patch_PrisonerTab.cs" />
<Compile Include="HarmonyPatches\Patches_InteractionMode\Patch_PrisonInteractionLabel.cs" />
Expand All @@ -135,6 +137,9 @@
<Compile Include="HarmonyPatches\Patches_GUI\GUI_WorkTab\Patch_WorkDisabled.cs" />
<Compile Include="HarmonyPatches\Patches_GUI\GUI_WorkTab\Patch_WorkDisabled2.cs" />
<Compile Include="HarmonyPatches\Patches_GUI\GUI_WorkTab\Patch_PawnTableSetDirtyFix.cs" />
<Compile Include="HarmonyPatches\Patches_Work\Patch_JobDriver_Mine.cs" />
<Compile Include="HarmonyPatches\Patches_Work\Patch_PlantWork.cs" />
<Compile Include="HarmonyPatches\Patches_Work\Patch_WorkGiver_CleanFilth.cs" />
<Compile Include="HarmonyPatches\Triggers.cs" />
<Compile Include="Core\Hediffs\HediffGiver_PrisonersChains.cs" />
<Compile Include="Core\Hediffs\HediffManager.cs" />
Expand Down Expand Up @@ -191,6 +196,7 @@
<Compile Include="Core\Other\ArrestUtility.cs" />
<Compile Include="Core\AI\WorkGivers\WorkGiver_Supervise.cs" />
<Compile Include="Core\LaborWorkSettings\WorkSettings.cs" />
<Compile Include="WorkUtils\ConstructionUtils.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\About\About.xml">
Expand Down

0 comments on commit f2522c5

Please sign in to comment.