기타 1 하모니 패치 예제 - solaris0115/RimWorldModGuide GitHub Wiki

//패치의 예시
    public static class AdditionalVerbPatch
    {
        private static readonly Type patchType = typeof(AdditionalVerbPatch);
        static AdditionalVerbPatch()
        {
            HarmonyInstance harmonyInstance = HarmonyInstance.Create("com.AdditionalVerb.rimworld.mod");
            //매서드
            harmonyInstance.Patch(AccessTools.Method(typeof(VerbTracker), "CreateVerbTargetCommand", null, null), new HarmonyMethod(patchType, "CreateVerbTargetCommandPrefix", null));
            //프로퍼티
            harmonyInstance.Patch(AccessTools.Property(typeof(VerbTracker), "PrimaryVerb").GetGetMethod(), new HarmonyMethod(patchType, "PrimaryVerbPrefix", null));
        }
    }

//------------------------------------------------------------------------------------
        //리턴값에 대한 패치
        public static bool CreateVerbTargetCommandPrefix(ref Command_VerbTarget __result, Thing ownerThing, Verb verb)
        {
            Command_VerbTarget command_VerbTarget = new Command_VerbTarget();
            VerbProperties_Custom verbProps = verb.verbProps as VerbProperties_Custom;
            if (verbProps != null)
            {
                command_VerbTarget.defaultDesc = verbProps.desc;
                command_VerbTarget.defaultLabel = verbProps.label;
                Comp_VerbSaveable comp_VerbSaveable = ownerThing.TryGetComp<Comp_VerbSaveable>();
                if (comp_VerbSaveable != null && comp_VerbSaveable.currentVerb == verb)
                {
                    command_VerbTarget.icon = currentCommandTexture;
                }
                else
                {
                    command_VerbTarget.icon = verbProps.texture;
                }
            }
            else
            {
                command_VerbTarget.icon = ownerThing.def.uiIcon;
                command_VerbTarget.defaultDesc = ownerThing.LabelCap + ": " + ownerThing.def.description.CapitalizeFirst();
            }
            command_VerbTarget.iconAngle = ownerThing.def.uiIconAngle;
            command_VerbTarget.iconOffset = ownerThing.def.uiIconOffset;
            command_VerbTarget.tutorTag = "VerbTarget";
            command_VerbTarget.verb = verb;
            if (verb.caster.Faction != Faction.OfPlayer)
            {
                command_VerbTarget.Disable("CannotOrderNonControlled".Translate());
            }
            else if (verb.CasterIsPawn)
            {
                if (verb.CasterPawn.story.WorkTagIsDisabled(WorkTags.Violent))
                {
                    command_VerbTarget.Disable("IsIncapableOfViolence".Translate(verb.CasterPawn.LabelShort, verb.CasterPawn));
                }
                else if (!verb.CasterPawn.drafter.Drafted)
                {
                    command_VerbTarget.Disable("IsNotDrafted".Translate(verb.CasterPawn.LabelShort, verb.CasterPawn));
                }
            }
            __result = command_VerbTarget;
            return false;
        }

        //인스턴스와 결과값 패치
        public static bool PrimaryVerbPrefix(VerbTracker __instance, ref Verb __result)
        {
            Comp_VerbSaveable comp = ((CompEquippable)__instance.directOwner).parent.GetComp<Comp_VerbSaveable>();
            if (comp != null)
            {
                __result = comp.currentVerb;
                if (__result != null)
                {
                    return false;
                }
            }
            return true;
        }
        
        //private 변수를 사용한 패치
        public static bool GetTargetingVerbPrefix(ref Verb __result, Pawn pawn,Verb ___targetingVerb)
        {
            //do something with ___targetingVerb   <-__instance.targetingVerb는 private이기 때문에 언더바 3개로 접근
            return true;
        }