Made a patch for insectegg pregnancy

This commit is contained in:
Shabakur 2022-11-30 13:48:23 +01:00
parent ddd55d1400
commit 3d6c84f66f
13 changed files with 121 additions and 19 deletions

BIN
About/Preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 568 KiB

Binary file not shown.

Binary file not shown.

View File

@ -14,17 +14,17 @@ namespace RJW_BGS
static Class1()
{
RJWcopy.Racegroupdictbuilder();
foreach (RaceGroupDef raceGroupDef2 in DefDatabase<RaceGroupDef>.AllDefs)
{
//foreach (RaceGroupDef raceGroupDef2 in DefDatabase<RaceGroupDef>.AllDefs)
//{
//Log.Message("defName = " + raceGroupDef2.defName);
if (raceGroupDef2.raceNames != null)
{
foreach (string race in raceGroupDef2.raceNames)
{
// if (raceGroupDef2.raceNames != null)
// {
// foreach (string race in raceGroupDef2.raceNames)
// {
//Log.Message(race);
}
}
}
// }
// }
//}
}
}
}

View File

@ -85,5 +85,65 @@ namespace RJW_BGS
}
return genelist;
}
public static void AddGenes(Pawn pawn, List<GeneDef> genes)
{
foreach (GeneDef gene in genes)
{
pawn.genes.AddGene(gene, false);
}
}
public static void NewGenes(Pawn mother, Pawn dad, Pawn baby)
{
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> genes = PregnancyUtility.GetInheritedGenes(dad, mother);
List<GeneDef> beastgenes = InheritanceUtility.AnimalInheritedGenes(dad, mother);
InheritanceUtility.AddGenes(baby, beastgenes);
InheritanceUtility.AddGenes(baby, genes);
if(baby.genes.GetFirstEndogeneByCategory(EndogeneCategory.Melanin) == null)
{
AddSkinColor(mother, dad, baby);
}
}
}
public static void AddSkinColor(Pawn mother, Pawn father, Pawn baby)
{
if (mother != null && mother.genes != null)
{
GeneDef gene = mother.genes.GetFirstEndogeneByCategory(EndogeneCategory.Melanin);
if (gene != null)
{
baby.genes.AddGene(gene, false);
}
}
else if (father != null && father.genes != null)
{
GeneDef gene = father.genes.GetFirstEndogeneByCategory(EndogeneCategory.Melanin);
if (gene != null)
{
baby.genes.AddGene(gene, false);
}
}
else
{
Log.Message("Could not find skincolor of " + baby.Name + "'s parents, giving random skincolor.");
baby.genes.AddGene(PawnSkinColors.RandomSkinColorGene(baby), false);
}
}
}
}

View File

@ -33,15 +33,16 @@ namespace RJW_BGS
List<GeneDef> genes = PregnancyUtility.GetInheritedGenes(dad, mother);
List<GeneDef> beastgenes = InheritanceUtility.AnimalInheritedGenes(dad, mother);
foreach (GeneDef gene in beastgenes)
{
baby.genes.AddGene(gene, false);
}
foreach (GeneDef gene in genes)
{
baby.genes.AddGene(gene, false);
}
InheritanceUtility.AddGenes(baby, beastgenes);
InheritanceUtility.AddGenes(baby, genes);
//foreach (GeneDef gene in beastgenes)
//{
// baby.genes.AddGene(gene, false);
//}
//foreach (GeneDef gene in genes)
//{
// baby.genes.AddGene(gene, false);
//}
}
}
}

View File

@ -0,0 +1,40 @@
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;
using RimWorld;
using Verse;
namespace RJW_BGS
{
[HarmonyPatch(typeof(Hediff_InsectEgg), "GiveBirth")]
public static class PatchRJWHediffInsect_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)
{
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);
}
yield return instruction;
}
}
}
}

View File

@ -61,6 +61,7 @@
<Compile Include="Harmony_Init.cs" />
<Compile Include="InheritanceUtility.cs" />
<Compile Include="PatchRJWBestialityPregnancyUtility.cs" />
<Compile Include="PatchRJWHediffInsect_Egg.cs" />
<Compile Include="PatchVanillaPregnancyUtility.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RaceGeneDef.cs" />

View File

@ -1 +1 @@
a5d60a90fbe0915a4fbdad7293220b682c74b0b1
bbcef32adb57331bca8d9d64ae20e770e4ed1e71

Binary file not shown.