Skip to content

Commit 705e447

Browse files
authored
Merge pull request #875 from zymex22/issue869
fixed biotech messing with drone skills
2 parents a389e45 + a21d28c commit 705e447

File tree

4 files changed

+67
-7
lines changed

4 files changed

+67
-7
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System.Collections.Generic;
2+
using System.Reflection.Emit;
3+
using HarmonyLib;
4+
using ProjectRimFactory.Drones;
5+
using Verse;
6+
7+
namespace ProjectRimFactory.Common.HarmonyPatches;
8+
9+
[HarmonyPatch (typeof(Pawn), "get_IsColonyMech")]
10+
// ReSharper disable once InconsistentNaming
11+
// Required for Drone Skills to function property
12+
// get_IsColonyMech checks if a Pawn is Mechanoid and controlled by the Play but NOT if it is a Biotech Mech
13+
// BUT it is used as IF that where the case. requiring this patch
14+
public class Patch_Pawn_get_IsColonyMech
15+
{
16+
17+
private static bool foundReturnFalsePointer;
18+
private static object returnFalsePointer;
19+
private static int referencePointCnt;
20+
private static bool foundReferencePoint;
21+
22+
// ReSharper disable once UnusedMember.Local
23+
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
24+
{
25+
26+
foreach (var instruction in instructions)
27+
{
28+
// Get the Return False Pointer
29+
if (!foundReturnFalsePointer && instruction.opcode == OpCodes.Brfalse_S)
30+
{
31+
foundReturnFalsePointer = true;
32+
returnFalsePointer = instruction.operand;
33+
}
34+
35+
// Find the get_MentalStateDef() Check (we want to be inserted right after that)
36+
if (!foundReferencePoint && foundReturnFalsePointer &&
37+
instruction.operand?.ToString() == "Verse.MentalStateDef get_MentalStateDef()")
38+
{
39+
foundReferencePoint = true;
40+
}
41+
42+
if (foundReferencePoint) referencePointCnt++;
43+
44+
if (foundReferencePoint && referencePointCnt == 3)
45+
{
46+
// now we want to insert a check if the pawn is Pawn_Drone
47+
// For maximum performance fully inlined IL
48+
// 5 additional instructions
49+
yield return new CodeInstruction(OpCodes.Ldarg_0);
50+
yield return new CodeInstruction(OpCodes.Isinst, typeof(Pawn_Drone));
51+
yield return new CodeInstruction(OpCodes.Ldnull);
52+
yield return new CodeInstruction(OpCodes.Cgt_Un);
53+
54+
yield return new CodeInstruction(OpCodes.Brtrue_S, returnFalsePointer);
55+
56+
}
57+
58+
59+
60+
yield return instruction;
61+
}
62+
}
63+
}

Source/ProjectRimFactory/Drones/Building_WorkGiverDroneStation.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ namespace ProjectRimFactory.Drones
99
{
1010
public abstract class Building_WorkGiverDroneStation : Building_DroneStation
1111
{
12-
public virtual IEnumerable<WorkTypeDef> WorkTypes => DefModExtensionDroneStation.workTypes;
12+
public Dictionary<WorkTypeDef, bool> WorkSettingsDict => WorkSettings;
1313

14-
public virtual Dictionary<WorkTypeDef, bool> WorkSettingsDict => WorkSettings;
1514

16-
17-
private Pawn_WorkSettings workSettings = null;
15+
private Pawn_WorkSettings workSettings;
1816

1917

2018
//Try give Job to Spawned drone

Source/ProjectRimFactory/Drones/DroneSkills.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace ProjectRimFactory.Drones
77
{
8-
class DroneSkills
8+
internal static class DroneSkills
99
{
1010
/// <summary>
1111
///
@@ -53,7 +53,7 @@ public static List<SkillRecord> UpdateSkills(Pawn_SkillTracker skill, List<Skill
5353
continue;
5454
}
5555

56-
record.levelInt = ReserchSkillModifier.GetResearchSkillLevel(); //No Settings Found use the Reserch Directly
56+
record.levelInt = ReserchSkillModifier.GetResearchSkillLevel(); //No Settings Found use the Research Directly
5757

5858
}
5959

Source/ProjectRimFactory/Drones/Pawn_Drone.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using ProjectRimFactory.Common;
2-
using ProjectRimFactory.SAL3;
32
using ProjectRimFactory.SAL3.Tools;
43
using RimWorld;
54
using Verse;

0 commit comments

Comments
 (0)