diff --git a/RW_NodeTree/Patch/CombatExtended/CombatExtended_CompFireModes_Patcher.cs b/RW_NodeTree/Patch/CombatExtended/CombatExtended_CompFireModes_Patcher.cs index b755479..3925bf7 100644 --- a/RW_NodeTree/Patch/CombatExtended/CombatExtended_CompFireModes_Patcher.cs +++ b/RW_NodeTree/Patch/CombatExtended/CombatExtended_CompFireModes_Patcher.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using Mono.Unix.Native; using RimWorld; using RW_NodeTree.Tools; using System; @@ -17,40 +18,59 @@ namespace RW_NodeTree.Patch.CombatExtended internal static class CombatExtended_CompFireModes_Patcher { private static MethodInfo _PostCompFireModes_Verb = typeof(CombatExtended_CompFireModes_Patcher).GetMethod("PostCompFireModes_Verb", BindingFlags.Static | BindingFlags.NonPublic); - private static MethodInfo _PostCompFireModes_Verb_Transpiler = typeof(CombatExtended_CompFireModes_Patcher).GetMethod("CompFireModes_Verb_Transpiler", BindingFlags.Static | BindingFlags.NonPublic); - private static MethodInfo _CompFireModes_TryGetComp = typeof(CombatExtended_CompFireModes_Patcher).GetMethod("CompFireModes_TryGetComp", BindingFlags.Static | BindingFlags.NonPublic); + //private static MethodInfo _CompFireModes_Verb_Transpiler = typeof(CombatExtended_CompFireModes_Patcher).GetMethod("CompFireModes_Verb_Transpiler", BindingFlags.Static | BindingFlags.NonPublic); + //private static MethodInfo _CompFireModes_TryGetComp = typeof(CombatExtended_CompFireModes_Patcher).GetMethod("CompFireModes_TryGetComp", BindingFlags.Static | BindingFlags.NonPublic); private static Type CombatExtended_CompFireModes = GenTypes.GetTypeInAnyAssembly("CombatExtended.CompFireModes"); - private static MethodInfo ThingCompUtility_TryGetComp = typeof(ThingCompUtility).GetMethod("TryGetComp", BindingFlags.Static | BindingFlags.Public).MakeGenericMethod(new Type[] { typeof(CompEquippable) }); + //private static MethodInfo ThingCompUtility_TryGetComp = typeof(ThingCompUtility).GetMethod("TryGetComp", BindingFlags.Static | BindingFlags.Public).MakeGenericMethod(new Type[] { typeof(CompEquippable) }); private static AccessTools.FieldRef CompFireModes_verbInt = null; - private static void PostCompFireModes_Verb(ThingComp __instance) + private static void PostCompFireModes_Verb(ThingComp __instance, ref Verb __result) { - CompChildNodeProccesser comp = ((CompChildNodeProccesser)__instance.parent) ?? (__instance.ParentHolder as CompChildNodeProccesser); - if (comp != null) + if(__result == null) { - CompFireModes_verbInt(__instance) = null; + CompChildNodeProccesser comp = ((CompChildNodeProccesser)__instance.parent) ?? (__instance.ParentHolder as CompChildNodeProccesser); + if (comp != null) + { + CompFireModes_verbInt(__instance) = null; + while(__result == null && comp != null) + { + List verbs = comp.parent.TryGetComp()?.AllVerbs; + if (verbs != null) + { + foreach (Verb verb in verbs) + { + if (comp.GetBeforeConvertVerbCorrespondingThing(typeof(CompEquippable), verb).Item1 == __instance.parent && verb.verbProps.isPrimary) + { + __result = verb; + break; + } + } + } + comp = comp.ParentProccesser; + } + } } } - private static IEnumerable CompFireModes_Verb_Transpiler(IEnumerable instructions) - { - foreach (CodeInstruction instruction in instructions) - { - if (instruction.Calls(ThingCompUtility_TryGetComp)) yield return new CodeInstruction(OpCodes.Call, _CompFireModes_TryGetComp); - else yield return instruction; - } - } + //private static IEnumerable CompFireModes_Verb_Transpiler(IEnumerable instructions) + //{ + // foreach (CodeInstruction instruction in instructions) + // { + // if (instruction.Calls(ThingCompUtility_TryGetComp)) yield return new CodeInstruction(OpCodes.Call, _CompFireModes_TryGetComp); + // else yield return instruction; + // } + //} - private static CompEquippable CompFireModes_TryGetComp(Thing thing) - { - return thing.TryGetComp() - ?? ((CompChildNodeProccesser)thing)?.parent.TryGetComp() - ?? (thing?.ParentHolder as CompChildNodeProccesser)?.parent.TryGetComp(); - } + //private static CompEquippable CompFireModes_TryGetComp(Thing thing) + //{ + // return thing.TryGetComp() + // ?? ((CompChildNodeProccesser)thing)?.parent.TryGetComp() + // ?? (thing?.ParentHolder as CompChildNodeProccesser)?.parent.TryGetComp(); + //} public static void PatchVerb(Harmony patcher) { @@ -60,8 +80,9 @@ public static void PatchVerb(Harmony patcher) MethodInfo target = CombatExtended_CompFireModes.GetMethod("get_Verb", BindingFlags.Instance | BindingFlags.NonPublic); patcher.Patch( target, - postfix: new HarmonyMethod(_PostCompFireModes_Verb), - transpiler: new HarmonyMethod(_PostCompFireModes_Verb_Transpiler) + postfix: new HarmonyMethod(_PostCompFireModes_Verb) + //, + //transpiler: new HarmonyMethod(_CompFireModes_Verb_Transpiler) ); } } diff --git a/RW_NodeTree/Patch/GenRecipe_Patcher.cs b/RW_NodeTree/Patch/GenRecipe_Patcher.cs index e776074..cf2457a 100644 --- a/RW_NodeTree/Patch/GenRecipe_Patcher.cs +++ b/RW_NodeTree/Patch/GenRecipe_Patcher.cs @@ -43,7 +43,7 @@ namespace RW_NodeTree /// public partial class CompChildNodeProccesser : ThingComp, IThingHolder { - internal IEnumerable PostGenRecipe_MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List ingredients, Thing dominantIngredient1, IBillGiver billGiver, Precept_ThingStyle precept, RecipeInvokeSource InvokeSource, IEnumerable result) + public IEnumerable PostGenRecipe_MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List ingredients, Thing dominantIngredient1, IBillGiver billGiver, Precept_ThingStyle precept, RecipeInvokeSource InvokeSource, IEnumerable result) { foreach (CompBasicNodeComp comp in AllNodeComp) { diff --git a/RW_NodeTree/Patch/IVerbOwner_Patcher.cs b/RW_NodeTree/Patch/IVerbOwner_Patcher.cs index 58d3de1..ea5cff7 100644 --- a/RW_NodeTree/Patch/IVerbOwner_Patcher.cs +++ b/RW_NodeTree/Patch/IVerbOwner_Patcher.cs @@ -140,7 +140,7 @@ public partial class CompChildNodeProccesser : ThingComp, IThingHolder /// /// IVerbOwner source /// result of IVerbOwner.VerbProperties - internal void PreIVerbOwner_GetVerbProperties(Type ownerType, Dictionary forPostRead) + public void PreIVerbOwner_GetVerbProperties(Type ownerType, Dictionary forPostRead) { if (ownerType != null && typeof(IVerbOwner).IsAssignableFrom(ownerType)) { @@ -165,7 +165,7 @@ internal void PreIVerbOwner_GetVerbProperties(Type ownerType, Dictionary /// IVerbOwner source /// result of IVerbOwner.Tools - internal void PreIVerbOwner_GetTools(Type ownerType, Dictionary forPostRead) + public void PreIVerbOwner_GetTools(Type ownerType, Dictionary forPostRead) { if (ownerType != null && typeof(IVerbOwner).IsAssignableFrom(ownerType)) { @@ -188,7 +188,7 @@ internal void PreIVerbOwner_GetTools(Type ownerType, Dictionary /// /// IVerbOwner source /// result of IVerbOwner.VerbProperties - internal List PostIVerbOwner_GetVerbProperties(Type ownerType, List verbProperties, Dictionary forPostRead) + public List PostIVerbOwner_GetVerbProperties(Type ownerType, List verbProperties, Dictionary forPostRead) { if (ownerType != null && typeof(IVerbOwner).IsAssignableFrom(ownerType)) { @@ -235,7 +235,7 @@ internal List PostIVerbOwner_GetVerbProperties(Type ownerType, L /// /// IVerbOwner source /// result of IVerbOwner.Tools - internal List PostIVerbOwner_GetTools(Type ownerType, List tools, Dictionary forPostRead) + public List PostIVerbOwner_GetTools(Type ownerType, List tools, Dictionary forPostRead) { if (ownerType != null && typeof(IVerbOwner).IsAssignableFrom(ownerType)) { diff --git a/RW_NodeTree/Patch/StatWorker_GetInfoCardHyperlinks_Patcher.cs b/RW_NodeTree/Patch/StatWorker_GetInfoCardHyperlinks_Patcher.cs index 247299c..f75d19d 100644 --- a/RW_NodeTree/Patch/StatWorker_GetInfoCardHyperlinks_Patcher.cs +++ b/RW_NodeTree/Patch/StatWorker_GetInfoCardHyperlinks_Patcher.cs @@ -77,7 +77,7 @@ public partial class CompChildNodeProccesser : ThingComp, IThingHolder /// result of StatWorker.GetInfoCardHyperlinks(), modifiable /// StatWorker /// parm 'reqstatRequest' of StatWorker.GetInfoCardHyperlinks() - internal IEnumerable PostStatWorker_GetInfoCardHyperlinks(StatWorker statWorker, StatRequest statRequest, IEnumerable result) + public IEnumerable PostStatWorker_GetInfoCardHyperlinks(StatWorker statWorker, StatRequest statRequest, IEnumerable result) { foreach (CompBasicNodeComp comp in AllNodeComp) {