|
| 1 | +using Harmony; |
| 2 | +using RimWorld; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Linq; |
| 6 | +using System.Reflection; |
| 7 | +using System.Text; |
| 8 | +using UnityEngine; |
| 9 | +using Verse; |
| 10 | +using Verse.Sound; |
| 11 | + |
| 12 | +namespace TechAdvancing |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// Class storing all the detours and the detour call. |
| 16 | + /// </summary> |
| 17 | + class HarmonyDetours |
| 18 | + { |
| 19 | + /// <summary> |
| 20 | + /// Method for performing all the detours via Harmony. |
| 21 | + /// </summary> |
| 22 | + public static void Setup() |
| 23 | + { |
| 24 | + var harmony = HarmonyInstance.Create("com.ghxx.rimworld.techadvancing"); |
| 25 | + harmony.PatchAll(Assembly.GetExecutingAssembly()); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + /// <summary> |
| 30 | + /// Prefix for adding the button below the progressbar of the research window. The button is used for opening the config screen. |
| 31 | + /// </summary> |
| 32 | + [HarmonyPatch(typeof(RimWorld.MainTabWindow_Research))] |
| 33 | + [HarmonyPatch("DrawLeftRect")] |
| 34 | + [HarmonyPatch(new Type[] { typeof(Rect) })] |
| 35 | + class TA_Research_Menu_Patch |
| 36 | + { |
| 37 | + static void Prefix(Rect leftOutRect) |
| 38 | + { |
| 39 | + Rect TA_Cfgrect = new Rect(0f, 0f, 180f, 20f); |
| 40 | + TA_Cfgrect.x = (leftOutRect.width - TA_Cfgrect.width) / 2f; |
| 41 | + TA_Cfgrect.y = leftOutRect.height - 20f; |
| 42 | + |
| 43 | + if (Widgets.ButtonText(TA_Cfgrect, "TAcfgmenulabel".Translate(), true, false, true)) |
| 44 | + { |
| 45 | + SoundDef.Named("ResearchStart").PlayOneShotOnCamera(); |
| 46 | + Find.WindowStack.Add((Window)new TechAdvancing_Config_Tab()); |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + /// <summary> |
| 52 | + /// Patch for having a method called when a pawn dies. |
| 53 | + /// </summary> |
| 54 | + [HarmonyPatch(typeof(Verse.Pawn))] |
| 55 | + [HarmonyPatch("Kill")] |
| 56 | + [HarmonyPatch(new Type[] { typeof(DamageInfo?) })] |
| 57 | + class TA_OnKill_Event |
| 58 | + { |
| 59 | + static void Postfix(Pawn __instance, DamageInfo? dinfo) |
| 60 | + { |
| 61 | + TechAdvancing.Event.OnKill(__instance); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Patch for getting notified about faction changes. E.g.: when a pawn joins the colony. |
| 67 | + /// </summary> |
| 68 | + [HarmonyPatch(typeof(Verse.Pawn))] |
| 69 | + [HarmonyPatch("SetFaction")] |
| 70 | + [HarmonyPatch(new Type[] { typeof(Faction), typeof(Pawn) })] |
| 71 | + class TA_OnNewPawn_Event |
| 72 | + { |
| 73 | + static void Prefix(Pawn __instance, Faction newFaction, Pawn recruiter = null) |
| 74 | + { |
| 75 | + TechAdvancing.Event.OnNewPawn(__instance); |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + /// <summary> |
| 80 | + /// Postfix Patch for getting to know the new faction. |
| 81 | + /// </summary> |
| 82 | + [HarmonyPatch(typeof(Verse.Pawn))] |
| 83 | + [HarmonyPatch("SetFaction")] |
| 84 | + [HarmonyPatch(new Type[] { typeof(Faction), typeof(Pawn) })] |
| 85 | + class TA_PostOnNewPawn_Event |
| 86 | + { |
| 87 | + static void Postfix(Faction newFaction, Pawn recruiter = null) |
| 88 | + { |
| 89 | + TechAdvancing.Event.PostOnNewPawn(); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | +} |
0 commit comments