From b23b9086b546874842acce46a930adc5ca5796ed Mon Sep 17 00:00:00 2001 From: Future <1609605489@qq.com> Date: Sun, 27 Nov 2022 18:31:38 +0800 Subject: [PATCH] update patch --- .../CombatExtended_CompFireModes_Patcher.cs | 35 +++++++++---------- ...CombatExtended_JobDriver_Reload_Patcher.cs | 27 +++++++++----- ...nded_LoadoutPropertiesExtension_Patcher.cs | 4 +-- .../CombatExtended_PawnRenderer_Patcher.cs | 9 ----- 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/RW_NodeTree/Patch/CombatExtended/CombatExtended_CompFireModes_Patcher.cs b/RW_NodeTree/Patch/CombatExtended/CombatExtended_CompFireModes_Patcher.cs index 3925bf7..bf59e90 100644 --- a/RW_NodeTree/Patch/CombatExtended/CombatExtended_CompFireModes_Patcher.cs +++ b/RW_NodeTree/Patch/CombatExtended/CombatExtended_CompFireModes_Patcher.cs @@ -17,7 +17,7 @@ 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 _PreCompFireModes_Verb = typeof(CombatExtended_CompFireModes_Patcher).GetMethod("PreCompFireModes_Verb", 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"); @@ -25,34 +25,31 @@ internal static class CombatExtended_CompFireModes_Patcher //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 AccessTools.FieldRef CompFireModes_verbInt = null; - private static void PostCompFireModes_Verb(ThingComp __instance, ref Verb __result) + private static bool PreCompFireModes_Verb(ThingComp __instance, ref Verb __result) { - if(__result == null) + CompChildNodeProccesser comp = ((CompChildNodeProccesser)__instance.parent) ?? (__instance.ParentHolder as CompChildNodeProccesser); + if (comp != null) { - CompChildNodeProccesser comp = ((CompChildNodeProccesser)__instance.parent) ?? (__instance.ParentHolder as CompChildNodeProccesser); - if (comp != null) + while (comp != null) { - CompFireModes_verbInt(__instance) = null; - while(__result == null && comp != null) + List verbs = comp.parent.TryGetComp()?.AllVerbs; + if (verbs != null) { - List verbs = comp.parent.TryGetComp()?.AllVerbs; - if (verbs != null) + foreach (Verb verb in verbs) { - foreach (Verb verb in verbs) + if (verb.EquipmentSource == __instance.parent && verb.verbProps.isPrimary) { - if (comp.GetBeforeConvertVerbCorrespondingThing(typeof(CompEquippable), verb).Item1 == __instance.parent && verb.verbProps.isPrimary) - { - __result = verb; - break; - } + __result = verb; + return false; } } - comp = comp.ParentProccesser; } + comp = comp.ParentProccesser; } } + return true; } @@ -76,11 +73,11 @@ public static void PatchVerb(Harmony patcher) { if (CombatExtended_CompFireModes != null) { - CompFireModes_verbInt = AccessTools.FieldRefAccess(CombatExtended_CompFireModes, "verbInt"); + //CompFireModes_verbInt = AccessTools.FieldRefAccess(CombatExtended_CompFireModes, "verbInt"); MethodInfo target = CombatExtended_CompFireModes.GetMethod("get_Verb", BindingFlags.Instance | BindingFlags.NonPublic); patcher.Patch( target, - postfix: new HarmonyMethod(_PostCompFireModes_Verb) + prefix: new HarmonyMethod(_PreCompFireModes_Verb) //, //transpiler: new HarmonyMethod(_CompFireModes_Verb_Transpiler) ); diff --git a/RW_NodeTree/Patch/CombatExtended/CombatExtended_JobDriver_Reload_Patcher.cs b/RW_NodeTree/Patch/CombatExtended/CombatExtended_JobDriver_Reload_Patcher.cs index 13bedf3..e02bf63 100644 --- a/RW_NodeTree/Patch/CombatExtended/CombatExtended_JobDriver_Reload_Patcher.cs +++ b/RW_NodeTree/Patch/CombatExtended/CombatExtended_JobDriver_Reload_Patcher.cs @@ -17,29 +17,40 @@ namespace RW_NodeTree.Patch.CombatExtended internal static class CombatExtended_JobDriver_Reload_Patcher { private static MethodInfo _PostJobDriver_Reload_weapon = typeof(CombatExtended_JobDriver_Reload_Patcher).GetMethod("PostJobDriver_Reload_weapon", BindingFlags.Static | BindingFlags.NonPublic); - private static MethodInfo _JobDriver_Reload_compReloader_Transpiler = typeof(CombatExtended_JobDriver_Reload_Patcher).GetMethod("JobDriver_Reload_compReloader_Transpiler", BindingFlags.Static | BindingFlags.NonPublic); + private static MethodInfo _PostJobDriver_Reload_compReloader = typeof(CombatExtended_JobDriver_Reload_Patcher).GetMethod("PostJobDriver_Reload_compReloader", BindingFlags.Static | BindingFlags.NonPublic); private static Type CombatExtended_JobDriver_Reload = GenTypes.GetTypeInAnyAssembly("CombatExtended.JobDriver_Reload"); + private static Type CombatExtended_CompAmmoUser = GenTypes.GetTypeInAnyAssembly("CombatExtended.CompAmmoUser"); private static MethodInfo JobDriver_Reload_weapon = null; - private static MethodInfo JobDriver_TargetThingB = typeof(JobDriver).GetMethod("get_TargetThingB", BindingFlags.Instance | BindingFlags.NonPublic); private static void PostJobDriver_Reload_weapon(ref ThingWithComps __result) { __result = __result.RootNode()?.parent ?? __result; } - private static IEnumerable JobDriver_Reload_compReloader_Transpiler(IEnumerable instructions) + private static void PostJobDriver_Reload_compReloader(JobDriver __instance, ref ThingComp __result) { - foreach(CodeInstruction instruction in instructions) + CompChildNodeProccesser Proccesser = ((CompChildNodeProccesser)__instance.job.targetB.Thing) ?? (__instance.job.targetB.Thing?.ParentHolder as CompChildNodeProccesser); + if(Proccesser != null) { - if(instruction.Calls(JobDriver_Reload_weapon)) yield return new CodeInstruction(OpCodes.Call, JobDriver_TargetThingB); - else yield return instruction; + List comps = (__instance.job.targetB.Thing as ThingWithComps)?.AllComps; + if (comps != null) + { + foreach (ThingComp comp in comps) + { + if (CombatExtended_CompAmmoUser.IsAssignableFrom(comp.GetType())) + { + __result = comp; + return; + } + } + } } } public static void PatchJobDriver_Reload(Harmony patcher) { - if (CombatExtended_JobDriver_Reload != null) + if (CombatExtended_JobDriver_Reload != null && CombatExtended_CompAmmoUser != null) { JobDriver_Reload_weapon = CombatExtended_JobDriver_Reload.GetMethod("get_weapon", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo target = JobDriver_Reload_weapon; @@ -50,7 +61,7 @@ public static void PatchJobDriver_Reload(Harmony patcher) target = CombatExtended_JobDriver_Reload.GetMethod("get_compReloader", BindingFlags.Instance | BindingFlags.NonPublic); patcher.Patch( target, - transpiler: new HarmonyMethod(_JobDriver_Reload_compReloader_Transpiler) + postfix: new HarmonyMethod(_PostJobDriver_Reload_compReloader) ); } } diff --git a/RW_NodeTree/Patch/CombatExtended/CombatExtended_LoadoutPropertiesExtension_Patcher.cs b/RW_NodeTree/Patch/CombatExtended/CombatExtended_LoadoutPropertiesExtension_Patcher.cs index cbc888f..00bb66f 100644 --- a/RW_NodeTree/Patch/CombatExtended/CombatExtended_LoadoutPropertiesExtension_Patcher.cs +++ b/RW_NodeTree/Patch/CombatExtended/CombatExtended_LoadoutPropertiesExtension_Patcher.cs @@ -50,13 +50,13 @@ private static ThingComp LoadoutPropertiesExtension_TryGetComp(Thing thing) CompEquippable equippable = thing.TryGetComp(); if (equippable != null) { - thing = comp.GetBeforeConvertVerbCorrespondingThing(equippable.GetType(), equippable.PrimaryVerb, true).Item1 as ThingWithComps; + thing = comp.GetBeforeConvertVerbCorrespondingThing(typeof(CompEquippable), equippable.PrimaryVerb, true).Item1 as ThingWithComps; ThingComp result = (ThingComp)TryGetComp.Invoke(null, new object[] { thing }); if (result != null) return result; - thing = comp.GetBeforeConvertVerbCorrespondingThing(equippable.GetType(), equippable.PrimaryVerb).Item1 as ThingWithComps; + thing = comp.GetBeforeConvertVerbCorrespondingThing(typeof(CompEquippable), equippable.PrimaryVerb).Item1 as ThingWithComps; result = (ThingComp)TryGetComp.Invoke(null, new object[] { thing }); if (result != null) return result; diff --git a/RW_NodeTree/Patch/CombatExtended/CombatExtended_PawnRenderer_Patcher.cs b/RW_NodeTree/Patch/CombatExtended/CombatExtended_PawnRenderer_Patcher.cs index 1f7a771..51b7ea9 100644 --- a/RW_NodeTree/Patch/CombatExtended/CombatExtended_PawnRenderer_Patcher.cs +++ b/RW_NodeTree/Patch/CombatExtended/CombatExtended_PawnRenderer_Patcher.cs @@ -21,9 +21,6 @@ internal static class CombatExtended_PawnRenderer_Patcher private static AccessTools.FieldRef GunDrawExtension_DrawSize = null; private static void PerHarmony_PawnRenderer_Harmony_PawnRenderer_DrawEquipmentAiming_DrawMesh( -#if !V13 - Matrix4x4 matrix, -#endif Thing eq, ref (DefModExtension, Vector2) __state) { @@ -51,13 +48,7 @@ private static void PerHarmony_PawnRenderer_Harmony_PawnRenderer_DrawEquipmentAi } ref Vector2 DrawSize = ref GunDrawExtension_DrawSize(targetExtension); __state = (targetExtension, DrawSize); -#if V13 - //Log.Message(eq.Graphic.drawSize.ToString()); DrawSize = eq.Graphic.drawSize; -#else - Vector3 scale = matrix.lossyScale; - DrawSize = new Vector2(scale.x, scale.z); -#endif } }