Skip to content

Commit

Permalink
update patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Cn-mjt44 committed Nov 27, 2022
1 parent f764ebc commit b23b908
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,39 @@ 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");


//private static MethodInfo ThingCompUtility_TryGetComp = typeof(ThingCompUtility).GetMethod("TryGetComp", BindingFlags.Static | BindingFlags.Public).MakeGenericMethod(new Type[] { typeof(CompEquippable) });

private static AccessTools.FieldRef<object, Verb> CompFireModes_verbInt = null;
//private static AccessTools.FieldRef<object, Verb> 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<Verb> verbs = comp.parent.TryGetComp<CompEquippable>()?.AllVerbs;
if (verbs != null)
{
List<Verb> verbs = comp.parent.TryGetComp<CompEquippable>()?.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;
}


Expand All @@ -76,11 +73,11 @@ public static void PatchVerb(Harmony patcher)
{
if (CombatExtended_CompFireModes != null)
{
CompFireModes_verbInt = AccessTools.FieldRefAccess<Verb>(CombatExtended_CompFireModes, "verbInt");
//CompFireModes_verbInt = AccessTools.FieldRefAccess<Verb>(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)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CodeInstruction> JobDriver_Reload_compReloader_Transpiler(IEnumerable<CodeInstruction> 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<ThingComp> 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;
Expand All @@ -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)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ private static ThingComp LoadoutPropertiesExtension_TryGetComp(Thing thing)
CompEquippable equippable = thing.TryGetComp<CompEquippable>();
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ internal static class CombatExtended_PawnRenderer_Patcher
private static AccessTools.FieldRef<object, Vector2> GunDrawExtension_DrawSize = null;

private static void PerHarmony_PawnRenderer_Harmony_PawnRenderer_DrawEquipmentAiming_DrawMesh(
#if !V13
Matrix4x4 matrix,
#endif
Thing eq,
ref (DefModExtension, Vector2) __state)
{
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit b23b908

Please sign in to comment.