mirror of
https://github.com/vegapnk/RJW-Genes.git
synced 2024-08-15 00:23:31 +00:00
Adopted Breeding Genes by Shabalox
This commit is contained in:
parent
95fc9b89a0
commit
21fc56fe2b
14 changed files with 264 additions and 3 deletions
9
Source/Genes/Breeding/Gene_MechBreeder.cs
Normal file
9
Source/Genes/Breeding/Gene_MechBreeder.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
using Verse;
|
||||
|
||||
namespace Genes.Breeding
|
||||
{
|
||||
internal class Gene_MechBreeder : Gene
|
||||
{
|
||||
// This one does not do anything, the patch is some where else checking for the pawn to have this Gene!
|
||||
}
|
||||
}
|
64
Source/Genes/Breeding/PatchMechBirth.cs
Normal file
64
Source/Genes/Breeding/PatchMechBirth.cs
Normal file
|
@ -0,0 +1,64 @@
|
|||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HarmonyLib;
|
||||
using rjw;
|
||||
|
||||
namespace RJW_Genes
|
||||
{
|
||||
/// <summary>
|
||||
/// This Class patches the RJW-Mechbirth to not deal damage when the pawn has the MechBreeder Gene.
|
||||
/// This harmony patch was kindly provided by 'shabalox' https://github.com/Shabalox/RJW_Genes_Addons/
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(Hediff_MechanoidPregnancy), "GiveBirth")]
|
||||
public static class PatchMechBirth
|
||||
{
|
||||
[HarmonyTranspiler]
|
||||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
|
||||
{
|
||||
bool found_call = false;
|
||||
bool found_skip = false;
|
||||
Label skip_label = il.DefineLabel();
|
||||
MethodInfo ismechbreeder = AccessTools.Method(typeof(GeneUtility), "IsMechbreeder");
|
||||
foreach (CodeInstruction codeInstruction in instructions)
|
||||
{
|
||||
//Check if the first opcode after endfinally ldloc_0 is and in that case add the label to skip the code
|
||||
if (found_skip && codeInstruction.opcode == OpCodes.Ldloc_0)
|
||||
{
|
||||
codeInstruction.labels.Add(skip_label);
|
||||
}
|
||||
found_skip = false;
|
||||
if (codeInstruction.opcode == OpCodes.Endfinally)
|
||||
{
|
||||
found_skip = true;
|
||||
}
|
||||
|
||||
yield return codeInstruction;
|
||||
|
||||
if (codeInstruction.opcode == OpCodes.Call)
|
||||
{
|
||||
if (codeInstruction.operand.ToString() == "Boolean TryMakeFilth(Verse.IntVec3, Verse.Map, Verse.ThingDef, System.String, Int32, RimWorld.FilthSourceFlags)")
|
||||
{
|
||||
found_call = true;
|
||||
}
|
||||
}
|
||||
//Triggers after the pop opcode (after generating filth in c#).
|
||||
else if (found_call)
|
||||
{
|
||||
//Load pawn, call function to check if a mechbreeder, and skip past the part which does damage
|
||||
yield return new CodeInstruction(OpCodes.Ldloc_0, null);
|
||||
yield return new CodeInstruction(OpCodes.Call, ismechbreeder);
|
||||
yield return new CodeInstruction(OpCodes.Brtrue_S, skip_label);
|
||||
found_call = false;
|
||||
}
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
22
Source/Genes/Breeding/PatchPawnExtensions.cs
Normal file
22
Source/Genes/Breeding/PatchPawnExtensions.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using HarmonyLib;
|
||||
using rjw;
|
||||
using Verse;
|
||||
|
||||
namespace RJW_Genes
|
||||
{
|
||||
/// <summary>
|
||||
/// Kindly provided by 'shabalox' https://github.com/Shabalox/RJW_Genes_Addons/
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(PawnExtensions), "RaceImplantEggs")]
|
||||
public static class PatchPawnExtensions
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
public static void Postfix(Pawn pawn, ref bool __result)
|
||||
{
|
||||
if (!__result)
|
||||
{
|
||||
__result = GeneUtility.isInsectBreeder(pawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
54
Source/Genes/Breeding/PatchPregnancyHelper.cs
Normal file
54
Source/Genes/Breeding/PatchPregnancyHelper.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HarmonyLib;
|
||||
using Verse;
|
||||
using RimWorld;
|
||||
using rjw;
|
||||
|
||||
namespace RJW_Genes
|
||||
{
|
||||
/// <summary>
|
||||
/// This Class patches the RJW-DoEgg to allow up to MaxEggSizeMul times the original amount of eggs.
|
||||
/// This harmony patch was kindly provided by 'shabalox' https://github.com/Shabalox/RJW_Genes_Addons/
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(PregnancyHelper), "DoEgg")]
|
||||
static class PatchPregnancyHelper
|
||||
{
|
||||
[HarmonyTranspiler]
|
||||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il)
|
||||
{
|
||||
//MethodInfo isinsectincubator = AccessTools.Method(typeof(GeneUtility), "IsInsectIncubator");
|
||||
MethodInfo maxeggsizemul = AccessTools.Method(typeof(GeneUtility), "MaxEggSizeMul");
|
||||
FieldInfo partner = AccessTools.Field(typeof(SexProps), "partner");
|
||||
|
||||
Label skiplabel = il.DefineLabel();
|
||||
bool finished = false;
|
||||
foreach (CodeInstruction codeInstruction in instructions)
|
||||
{
|
||||
if (!finished)
|
||||
{
|
||||
if (codeInstruction.opcode == OpCodes.Ldc_R4 && codeInstruction.operand.ToString() == "0")
|
||||
{
|
||||
yield return new CodeInstruction(OpCodes.Ldarg_0, null);
|
||||
yield return new CodeInstruction(OpCodes.Ldfld, partner);
|
||||
//yield return new CodeInstruction(OpCodes.Call, isinsectincubator);
|
||||
yield return new CodeInstruction(OpCodes.Callvirt, maxeggsizemul);
|
||||
//yield return new CodeInstruction(OpCodes.Brfalse_S, skiplabel);
|
||||
yield return new CodeInstruction(OpCodes.Ldloc_0, null);
|
||||
//yield return new CodeInstruction(OpCodes.Ldc_R4, 2f);
|
||||
yield return new CodeInstruction(OpCodes.Mul, null);
|
||||
yield return new CodeInstruction(OpCodes.Stloc_0, null);
|
||||
//codeInstruction.labels.Add(skiplabel);
|
||||
finished = true;
|
||||
}
|
||||
}
|
||||
yield return codeInstruction;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue