lost_RD

BeepBoop

Mar 26th, 2017
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1. using Verse;
  2. using Harmony;
  3. using RimWorld;
  4. using System.Linq;
  5. using System;
  6. using System.Reflection;
  7. using System.Collections.Generic;
  8.  
  9. namespace BeepBoop
  10. {
  11.     [StaticConstructorOnStartup]
  12.     class Main
  13.     {
  14.         static Main()
  15.         {
  16.             var harmony = HarmonyInstance.Create("org.rd.beepboop");
  17.             harmony.PatchAll(Assembly.GetExecutingAssembly());
  18.         }
  19.     }
  20.  
  21.     [HarmonyPatch]
  22.     static class Patcher
  23.     {
  24.         /* SameSpot's code
  25.          * static bool DestinationIsReserved(this PawnDestinationManager instance, IntVec3 c, Pawn searcher)
  26.         {
  27.             if (Find.Selector.SelectedObjects.Count() == 1) return false;
  28.             if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) return false;
  29.             return instance.DestinationIsReserved(c, searcher);
  30.         }*/
  31.  
  32.         static MethodBase TargetMethod()
  33.         {
  34.             /* SameSpot's code
  35.              * var predicateClass = typeof(RCellFinder).GetNestedTypes(AccessTools.all)
  36.                 .FirstOrDefault(t => t.FullName.Contains("BestOrderedGotoDestNear"));
  37.             return predicateClass.GetMethods(AccessTools.all).FirstOrDefault(m => m.ReturnType == typeof(bool));*/
  38.  
  39.             /* need to redirect an invokation of
  40.                 private static void Verse.Messages.Message(Messages.LiveMessage msg, MessageSound sound)
  41.             from within
  42.                 public void Verse.Pawn_HealthTracker.Kill(DamageInfo? dinfo, Hediff hediff)
  43.             to a method of my own
  44.             */
  45.  
  46.             var predicateClass = typeof(Pawn_HealthTracker).GetNestedTypes(AccessTools.all)
  47.                 .FirstOrDefault(t => t.FullName.Contains("Kill"));
  48.             return predicateClass.GetMethods(AccessTools.all).FirstOrDefault( /* what to put here? */ );
  49.         }
  50.  
  51.         static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
  52.         {
  53.             return instructions
  54.  
  55.                 /* SameSpot code
  56.                  * .MethodReplacer(
  57.                     AccessTools.Method(typeof(PawnDestinationManager), "DestinationIsReserved", new Type[] { typeof(IntVec3), typeof(Pawn) }),
  58.                     AccessTools.Method(typeof(Patcher), "DestinationIsReserved")
  59.                 );*/
  60.  
  61.                 .MethodReplacer( // CodeInstruction does not contain a definition for MethodReplacer
  62.                     AccessTools.Method(typeof(Verse.Messages), "Message", new Type[] { AccessTools.TypeByName("LiveMessage"), typeof(MessageSound) }),
  63.                     AccessTools.Method(typeof(BeepBoop.Messages), "Message", new Type[] { typeof(string), typeof(SoundDef) })
  64.                 );
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment