Skip to content

Commit

Permalink
#647 added support for Quality Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Sn1p3rr3c0n committed Feb 24, 2023
1 parent bbd8551 commit b2f2fe0
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using ProjectRimFactory.Drones;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace ProjectRimFactory.Common.HarmonyPatches
{
internal class Patch_QualityBuilder_getPawnConstructionSkill
{
static public bool Prefix(out int __result, Pawn pawn)
{
__result = 0;
if (pawn is Pawn_Drone)
{
__result = pawn.skills.GetSkill(SkillDefOf.Construction).Level;
return false;
}
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using ProjectRimFactory.Drones;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace ProjectRimFactory.Common.HarmonyPatches
{
class Patch_QualityBuilder_pawnCanConstruct
{
public static void Postfix(Pawn pawn, ref bool __result)
{
if (!__result && pawn is Pawn_Drone && (pawn.workSettings?.WorkIsActive(WorkTypeDefOf.Construction) ?? false))
{
__result = true;
}
}
}
}
21 changes: 21 additions & 0 deletions Source/ProjectRimFactory/Common/ProjectRimFactory_ModComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using ProjectRimFactory.Common.HarmonyPatches;
using ProjectRimFactory.Storage;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -220,6 +221,26 @@ private void LoadModSupport()
{
ModSupport_VEF_DualCropExtension = true;
}
if (ModLister.HasActiveModWithName("QualityBuilder"))
{
MethodBase QualityBuilder_pawnCanConstruct = AccessTools.Method("QualityBuilder.QualityBuilder:pawnCanConstruct");
MethodBase QualityBuilder_getPawnConstructionSkill = AccessTools.Method("QualityBuilder.QualityBuilder:getPawnConstructionSkill");

if (QualityBuilder_pawnCanConstruct != null && QualityBuilder_getPawnConstructionSkill != null)
{
var postfix_pawnCanConstruct = typeof(HarmonyPatches.Patch_QualityBuilder_pawnCanConstruct).GetMethod("Postfix");
var prefix_getPawnConstructionSkill = typeof(HarmonyPatches.Patch_QualityBuilder_getPawnConstructionSkill).GetMethod("Prefix");
this.HarmonyInstance.Patch(QualityBuilder_pawnCanConstruct, null, new HarmonyMethod(postfix_pawnCanConstruct));
this.HarmonyInstance.Patch(QualityBuilder_getPawnConstructionSkill, new HarmonyMethod(prefix_getPawnConstructionSkill));
Log.Message("Project Rimfactory - Added Support for QualityBuilder");
}
else
{
Log.Warning("Project Rimfactory - Failed to add Support for QualityBuilder");
}

}


}

Expand Down

0 comments on commit b2f2fe0

Please sign in to comment.