public static bool Replace_DoBirthSpawn(Pawn mother, Pawn father)
    {
        if (father is null || mother.kindDef == father.kindDef)
        {
            return(true);
        }

        var litterCount = Math.Min(GetLitterCount(mother), GetLitterCount(father));

        List <(PawnKindDef p, List <HybridDef> h)> hybridKinds = null;

        if (
            DogsMateMod.TryGetCompatibleFemales(father.kindDef, out var dict) &&
            dict.TryGetValue(mother.kindDef, out var hybridDefs) &&
            hybridDefs.Count > 0
            )
        {
            hybridKinds = hybridDefs.Select(h => h.children.Where(c => c.IsUsable).Select(a => (a, h)))
                          .SelectMany(x => x).Select(ah => ah.a.pawnKinds.Where(p => p != null).Select(p => (p, ah.h)))
                          .SelectMany(x => x).GroupBy(ph => ph.p)
                          .Select(g => (g.Key, g.Select(ph => ph.h).Where(h => h.IsUsable).ToList())).ToList();
            DogsMateMod.Debug(
                $"father=<{father.kindDef.ToStringSafe()}> " +
                $"mother=<{mother.kindDef.ToStringSafe()}> " +
                $"hybrids=<{hybridKinds.Select(ph => ph.p.label).ToCommaList()}>"
                );
        }

        Pawn child = null;

        for (var childIndex = 0; childIndex < litterCount; ++childIndex)
        {
            PawnKindDef childKind;
            HybridDef   hybridDef = null;
            if (hybridKinds != null)
            {
                hybridKinds.TryGetRandomElement(out var ph);
                ph.h.TryGetRandomElement(out hybridDef);
                childKind = ph.p;
            }
            else if (Rand.Value > 0.5f)
            {
                childKind = mother.kindDef;
            }
            else
            {
                childKind = father.kindDef;
            }

            bool newChildIsGood;
            var  newChild = PawnGenerator.GeneratePawn(new PawnGenerationRequest(
                                                           childKind,
                                                           mother.Faction,
                                                           forceGenerateNewPawn: false,
                                                           newborn: true
                                                           ));
            if (PawnUtility.TrySpawnHatchedOrBornPawn(newChild, mother))
            {
                if (newChild.playerSettings != null && mother.playerSettings != null)
                {
                    newChild.playerSettings.AreaRestriction = mother.playerSettings.AreaRestriction;
                }

                if (newChild.RaceProps.IsFlesh)
                {
                    newChild.relations.AddDirectRelation(PawnRelationDefOf.Parent, mother);
                    newChild.relations.AddDirectRelation(PawnRelationDefOf.Parent, father);
                }

                if (hybridDef != null)
                {
                    AddHediffs(newChild, hybridDef.childrenHediffs);
                    switch (newChild.gender)
                    {
                    case Gender.Male:
                        AddHediffs(newChild, hybridDef.maleChildrenHediffs);
                        break;

                    case Gender.Female:
                        AddHediffs(newChild, hybridDef.femaleChildrenHediffs);
                        break;
                    }
                }

                newChildIsGood = true;
            }
            else
            {
                Find.WorldPawns.PassToWorld(newChild, PawnDiscardDecideMode.Discard);
                newChildIsGood = false;
            }

            TaleRecorder.RecordTale(TaleDefOf.GaveBirth, mother, newChild);

            if (newChildIsGood)
            {
                child = newChild;
            }
        }

        if (!mother.Spawned)
        {
            return(false);
        }

        FilthMaker.TryMakeFilth(mother.Position, mother.Map, ThingDefOf.Filth_AmnioticFluid,
                                mother.LabelIndefinite(), 5);
        mother.caller?.DoCall();
        child?.caller?.DoCall();

        return(false);
    }
    public static bool Replace_TryGiveJob(ref Job __result, Pawn pawn)
    {
        var malePawn = pawn;

        if (malePawn.GetComp <CompEggLayer>()?.props != null)
        {
            DogsMateMod.Debug(
                $"male=<{malePawn.ToStringSafe()}={malePawn.kindDef.ToStringSafe()}> is egg layer -> using default implementation");
            return(true);
        }

        if (!DogsMateMod.TryGetCompatibleFemales(malePawn.kindDef, out var specialDict))
        {
            DogsMateMod.Debug(
                $"male=<{malePawn.ToStringSafe()}={malePawn.kindDef.ToStringSafe()}> is not special -> using default implementation");
            return(true);
        }

        if (malePawn.gender != Gender.Male)
        {
            DogsMateMod.Debug(
                $"male=<{malePawn.ToStringSafe()}={malePawn.kindDef.ToStringSafe()}> is male -> fail");
            __result = null;
            return(false);
        }

        if (!malePawn.ageTracker.CurLifeStage.reproductive)
        {
            DogsMateMod.Debug(
                $"male=<{malePawn.ToStringSafe()}={malePawn.kindDef.ToStringSafe()}> cannot reproduce in this life stage -> fail");
            __result = null;
            return(false);
        }

        if (GenClosest.ClosestThingReachable(
                malePawn.Position,
                malePawn.Map,
                ThingRequest.ForGroup(ThingRequestGroup
                                      .Pawn),             // original implementation tests for "ThingRequest.ForDef(malePawn.def)"
                PathEndMode.Touch,
                TraverseParms.For(malePawn, Danger.Some), // original implementation allows "Danger.Deadly"
                30f,
                femaleThing => IsValidFemale(femaleThing, malePawn, specialDict)
                ) is Pawn validFemalePawn)
        {
            DogsMateMod.Debug(
                $"male=<{malePawn.ToStringSafe()}={malePawn.kindDef.ToStringSafe()}> " +
                $"female=<{validFemalePawn.ToStringSafe()}={validFemalePawn.kindDef.ToStringSafe()}> " +
                "will mate -> success"
                );
            __result = JobMaker.MakeJob(JobDefOf.Mate, validFemalePawn);
        }
        else
        {
            DogsMateMod.Debug(
                $"male=<{malePawn.ToStringSafe()}={malePawn.kindDef.ToStringSafe()}> " +
                "no valid female found -> fail"
                );
            __result = null;
        }

        return(false);
    }