Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Cn-mjt44 committed Nov 26, 2022
1 parent 2b352a0 commit f764ebc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using Mono.Unix.Native;
using RimWorld;
using RW_NodeTree.Tools;
using System;
Expand All @@ -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<object, Verb> 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<Verb> verbs = comp.parent.TryGetComp<CompEquippable>()?.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<CodeInstruction> CompFireModes_Verb_Transpiler(IEnumerable<CodeInstruction> 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<CodeInstruction> CompFireModes_Verb_Transpiler(IEnumerable<CodeInstruction> 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<CompEquippable>()
?? ((CompChildNodeProccesser)thing)?.parent.TryGetComp<CompEquippable>()
?? (thing?.ParentHolder as CompChildNodeProccesser)?.parent.TryGetComp<CompEquippable>();
}
//private static CompEquippable CompFireModes_TryGetComp(Thing thing)
//{
// return thing.TryGetComp<CompEquippable>()
// ?? ((CompChildNodeProccesser)thing)?.parent.TryGetComp<CompEquippable>()
// ?? (thing?.ParentHolder as CompChildNodeProccesser)?.parent.TryGetComp<CompEquippable>();
//}

public static void PatchVerb(Harmony patcher)
{
Expand All @@ -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)
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion RW_NodeTree/Patch/GenRecipe_Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace RW_NodeTree
/// </summary>
public partial class CompChildNodeProccesser : ThingComp, IThingHolder
{
internal IEnumerable<Thing> PostGenRecipe_MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List<Thing> ingredients, Thing dominantIngredient1, IBillGiver billGiver, Precept_ThingStyle precept, RecipeInvokeSource InvokeSource, IEnumerable<Thing> result)
public IEnumerable<Thing> PostGenRecipe_MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List<Thing> ingredients, Thing dominantIngredient1, IBillGiver billGiver, Precept_ThingStyle precept, RecipeInvokeSource InvokeSource, IEnumerable<Thing> result)
{
foreach (CompBasicNodeComp comp in AllNodeComp)
{
Expand Down
8 changes: 4 additions & 4 deletions RW_NodeTree/Patch/IVerbOwner_Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public partial class CompChildNodeProccesser : ThingComp, IThingHolder
/// </summary>
/// <param name="owner">IVerbOwner source</param>
/// <param name="verbProperties">result of IVerbOwner.VerbProperties</param>
internal void PreIVerbOwner_GetVerbProperties(Type ownerType, Dictionary<string, object> forPostRead)
public void PreIVerbOwner_GetVerbProperties(Type ownerType, Dictionary<string, object> forPostRead)
{
if (ownerType != null && typeof(IVerbOwner).IsAssignableFrom(ownerType))
{
Expand All @@ -165,7 +165,7 @@ internal void PreIVerbOwner_GetVerbProperties(Type ownerType, Dictionary<string,
/// </summary>
/// <param name="owner">IVerbOwner source</param>
/// <param name="verbProperties">result of IVerbOwner.Tools</param>
internal void PreIVerbOwner_GetTools(Type ownerType, Dictionary<string, object> forPostRead)
public void PreIVerbOwner_GetTools(Type ownerType, Dictionary<string, object> forPostRead)
{
if (ownerType != null && typeof(IVerbOwner).IsAssignableFrom(ownerType))
{
Expand All @@ -188,7 +188,7 @@ internal void PreIVerbOwner_GetTools(Type ownerType, Dictionary<string, object>
/// </summary>
/// <param name="owner">IVerbOwner source</param>
/// <param name="verbProperties">result of IVerbOwner.VerbProperties</param>
internal List<VerbProperties> PostIVerbOwner_GetVerbProperties(Type ownerType, List<VerbProperties> verbProperties, Dictionary<string, object> forPostRead)
public List<VerbProperties> PostIVerbOwner_GetVerbProperties(Type ownerType, List<VerbProperties> verbProperties, Dictionary<string, object> forPostRead)
{
if (ownerType != null && typeof(IVerbOwner).IsAssignableFrom(ownerType))
{
Expand Down Expand Up @@ -235,7 +235,7 @@ internal List<VerbProperties> PostIVerbOwner_GetVerbProperties(Type ownerType, L
/// </summary>
/// <param name="owner">IVerbOwner source</param>
/// <param name="verbProperties">result of IVerbOwner.Tools</param>
internal List<Tool> PostIVerbOwner_GetTools(Type ownerType, List<Tool> tools, Dictionary<string, object> forPostRead)
public List<Tool> PostIVerbOwner_GetTools(Type ownerType, List<Tool> tools, Dictionary<string, object> forPostRead)
{
if (ownerType != null && typeof(IVerbOwner).IsAssignableFrom(ownerType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public partial class CompChildNodeProccesser : ThingComp, IThingHolder
/// <param name="result">result of StatWorker.GetInfoCardHyperlinks(), modifiable</param>
/// <param name="statWorker">StatWorker</param>
/// <param name="reqstatRequest">parm 'reqstatRequest' of StatWorker.GetInfoCardHyperlinks()</param>
internal IEnumerable<Dialog_InfoCard.Hyperlink> PostStatWorker_GetInfoCardHyperlinks(StatWorker statWorker, StatRequest statRequest, IEnumerable<Dialog_InfoCard.Hyperlink> result)
public IEnumerable<Dialog_InfoCard.Hyperlink> PostStatWorker_GetInfoCardHyperlinks(StatWorker statWorker, StatRequest statRequest, IEnumerable<Dialog_InfoCard.Hyperlink> result)
{
foreach (CompBasicNodeComp comp in AllNodeComp)
{
Expand Down

0 comments on commit f764ebc

Please sign in to comment.