private static void UpdateAnimalRelease(Pawn pawn, Pawn_PlayerSettings __instance)
 {
     __instance.animalsReleased = !__instance.animalsReleased;
     if (__instance.animalsReleased)
     {
         foreach (Pawn current in PawnUtility.SpawnedMasteredPawns(pawn))
         {
             if (current.caller != null)
             {
                 current.caller.Notify_Released();
             }
             if (current.CurJob.def != GUC_JobDefOf.Mounted)
             {
                 current.jobs.EndCurrentJob(JobCondition.InterruptForced, true);
             }
         }
     }
 }
        //Almost literal copy of vanilla code. Only added a check around the EndCurrentJob call
        static IEnumerable <Gizmo> helpIterator(Pawn_PlayerSettings __instance)
        {
            Pawn pawn = __instance.pawn;

            if (pawn.Drafted)
            {
                if (PawnUtility.SpawnedMasteredPawns(pawn).Any((Pawn p) => p.training.HasLearned(TrainableDefOf.Release)))
                {
                    yield return(new Command_Toggle
                    {
                        defaultLabel = "CommandReleaseAnimalsLabel".Translate(),
                        defaultDesc = "CommandReleaseAnimalsDesc".Translate(),
                        icon = TexCommand.ReleaseAnimals,
                        hotKey = KeyBindingDefOf.Misc7,
                        isActive = (() => __instance.animalsReleased),
                        toggleAction = () => UpdateAnimalRelease(pawn, __instance)
                    });
                }
            }
        }
        //Almost literal copy of vanilla code. Only added a check around the EndCurrentJob call
        static IEnumerable <Gizmo> helpIterator(Pawn_PlayerSettings __instance)
        {
            Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>();

            if (pawn.Drafted)
            {
                if (PawnUtility.SpawnedMasteredPawns(pawn).Any((Pawn p) => p.training.IsCompleted(TrainableDefOf.Release)))
                {
                    yield return(new Command_Toggle
                    {
                        defaultLabel = "CommandReleaseAnimalsLabel".Translate(),
                        defaultDesc = "CommandReleaseAnimalsDesc".Translate(),
                        icon = TexCommand.ReleaseAnimals,
                        hotKey = KeyBindingDefOf.Misc7,
                        isActive = (() => __instance.animalsReleased),
                        toggleAction = delegate
                        {
                            __instance.animalsReleased = !__instance.animalsReleased;
                            if (__instance.animalsReleased)
                            {
                                foreach (Pawn current in PawnUtility.SpawnedMasteredPawns(pawn))
                                {
                                    if (current.caller != null)
                                    {
                                        current.caller.Notify_Released();
                                    }
                                    if (current.CurJob.def != GUC_JobDefOf.Mounted)
                                    {
                                        current.jobs.EndCurrentJob(JobCondition.InterruptForced, true);
                                    }
                                }
                            }
                        }
                    });
                }
            }
        }