Restructuring, some sorting into folders

This commit is contained in:
Vegapnk 2023-01-22 09:06:28 +01:00
parent ac1fdc99be
commit 31e96bd5e3
36 changed files with 80 additions and 65 deletions

View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HarmonyLib;
using RimWorld;
using Verse;
using rjw;
namespace RJW_BGS
{
[HarmonyPatch(typeof(Hediff_BasePregnancy), "Initialize")]
public static class Patch_RJW_BestialityPregnancyUtility
{
[HarmonyPostfix]
public static void AddGenes(Pawn mother, Pawn dad, ref Hediff_BasePregnancy __instance)
{
if (!RJW_BGSSettings.rjw_bgs_enabled)
{
return;
}
foreach (Pawn baby in __instance.babies)
{
if (baby.RaceProps.Humanlike)
{
if (baby.genes == null)
{
baby.genes = new Pawn_GeneTracker(baby);
}
//Remove the hair and skin genes pawns always start with, should get correct ones from human parent anyway.
for (int i = baby.genes.Endogenes.Count - 1; i >= 0; i--)
{
baby.genes.RemoveGene(baby.genes.Endogenes[i]);
}
List<GeneDef> humangenes = PregnancyUtility.GetInheritedGenes(dad, mother);
List<GeneDef> beastgenes = InheritanceUtility.AnimalInheritedGenes(dad, mother);
InheritanceUtility.AddGenes(baby, beastgenes);
InheritanceUtility.AddGenes(baby, humangenes);
// The mix-breed babies should be labelled hybrids
baby.genes.hybrid = true;
baby.genes.xenotypeName = "Hybrid";
}
}
}
}
}

View file

@ -0,0 +1,35 @@
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using HarmonyLib;
using rjw;
namespace RJW_BGS
{
[HarmonyPatch(typeof(Hediff_InsectEgg), "GiveBirth")]
public static class Patch_RJW_HediffInsect_Egg
{
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
MethodInfo newgenes = AccessTools.Method(typeof(InheritanceUtility), "NewGenes", null, null);
FieldInfo implanter = AccessTools.Field(typeof(Hediff_InsectEgg), "implanter");
FieldInfo father = AccessTools.Field(typeof(Hediff_InsectEgg), "father");
foreach (CodeInstruction instruction in instructions)
{
yield return instruction;
if (instruction.opcode == OpCodes.Call && instruction.operand.ToString() == "Void BabyPostBirth(Verse.Pawn, Verse.Pawn, Verse.Pawn)")
{
yield return new CodeInstruction(OpCodes.Ldloc_0, null);
yield return new CodeInstruction(OpCodes.Ldfld, implanter);
yield return new CodeInstruction(OpCodes.Ldarg_0, null);
yield return new CodeInstruction(OpCodes.Ldfld, father);
yield return new CodeInstruction(OpCodes.Ldloc_1, null);
yield return new CodeInstruction(OpCodes.Call, newgenes);
}
}
}
}
}

View file

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using RimWorld;
using Verse;
namespace RJW_BGS
{
/// <summary>
/// This Patch is applied to change the normal pregnancy to add animal-inheritance.
/// If the settings allow animal gene inheritance,
/// the genes are determined and "simply added".
/// </summary>
[HarmonyPatch(typeof(PregnancyUtility), "GetInheritedGeneSet", new Type[]
{
typeof(Pawn),
typeof(Pawn),
//typeof(bool)
}
)]
public static class Patch_Vanilla_PregnancyUtility
{
[HarmonyPostfix]
public static void AnimalInheritedGenes(Pawn father, Pawn mother, ref GeneSet __result)
{
if (!RJW_BGSSettings.rjw_bgs_enabled)
{
return;
}
List<GeneDef> genes = InheritanceUtility.AnimalInheritedGenes(father, mother);
if (genes.Any())
{
foreach (GeneDef gene in genes)
{
__result.AddGene(gene);
}
}
}
}
}