Advertisement
Guest User

sfsvs

a guest
Nov 12th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Reflection;
  3. using System.Linq;
  4. using System.Text;
  5. using RimWorld;
  6. using Harmony;
  7. using System;
  8. using Verse;
  9.  
  10. namespace RustyWorld
  11. {
  12. [StaticConstructorOnStartup]
  13. public class HarmonyBoot
  14. {
  15. static HarmonyBoot()
  16. {
  17. var harmony = HarmonyInstance.Create("com.Cenbes.patches");
  18. harmony.PatchAll();
  19.  
  20. var harmony = HarmonyInstance.Create("rimworld.Cenbes.patches");
  21. harmony.Patch(
  22. typeof(SymbolResolver_RandomMechanoidGroup).GetMethods(BindingFlags.NonPublic | BindingFlags.Static)
  23. .First(mi =>
  24. mi.HasAttribute<CompilerGeneratedAttribute>() && mi.ReturnType == typeof(bool) &&
  25. mi.GetParameters().Count() == 1 && mi.GetParameters()[0].ParameterType == typeof(PawnKindDef)),
  26. null, new HarmonyMethod(typeof(YourType),
  27. nameof(MechanoidsFixerAncient)));
  28. harmony.Patch(
  29. typeof(CompSpawnerMechanoidsOnDamaged).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).First(
  30. mi => mi.HasAttribute<CompilerGeneratedAttribute>() && mi.ReturnType == typeof(bool) &&
  31. mi.GetParameters().Count() == 1 &&
  32. mi.GetParameters()[0].ParameterType == typeof(PawnKindDef)), null, new HarmonyMethod(
  33. typeof(YourType),
  34. nameof(MechanoidsFixer)));
  35. }
  36.  
  37. public static void MechanoidsFixerAncient(ref bool __result, PawnKindDef kind)
  38. {
  39. if (kind == Defs.ScientistMechPawn_BunkerBuster ||
  40. kind == Defs.ScientistMechPawn_TankTypeA ||
  41. kind == Defs.ScientistMechPawn_TankTypeB)
  42. __result = false;
  43. }
  44. public static void MechanoidsFixer(ref bool __result, PawnKindDef kind)
  45. {
  46. if (kind == Defs.ScientistMechPawn_BunkerBuster ||
  47. kind == Defs.ScientistMechPawn_TankTypeA ||
  48. kind == Defs.ScientistMechPawn_TankTypeB)
  49. __result = false;
  50. }
  51. }
  52.  
  53. [DefOf]
  54. public static class Defs
  55. {
  56. public static PawnKindDef ScientistMechPawn_BunkerBuster;
  57. public static PawnKindDef ScientistMechPawn_TankTypeA;
  58. public static PawnKindDef ScientistMechPawn_TankTypeB;
  59. }
  60.  
  61. private static FieldInfo fleshTypeField = AccessTools.Field(typeof(RaceProperties), "fleshType");
  62.  
  63. [HarmonyPatch(typeof(CompSpawnerMechanoidsOnDamaged))]
  64. [HarmonyPatch(nameof(CompSpawnerMechanoidsOnDamaged.TrySpawnMechanoids))]
  65. public static class Harmony_TrySpawnMechanoids
  66. {
  67. public static void Prefix()
  68. {
  69. fleshTypeField.SetValue(Defs.ScientistMechPawn_BunkerBuster.RaceProps, FleshTypeDefOf.Normal);
  70. fleshTypeField.SetValue(Defs.ScientistMechPawn_TankTypeA.RaceProps, FleshTypeDefOf.Normal);
  71. fleshTypeField.SetValue(Defs.ScientistMechPawn_TankTypeB.RaceProps, FleshTypeDefOf.Normal);
  72. }
  73. public static void Postfix()
  74. {
  75. fleshTypeField.SetValue(Defs.ScientistMechPawn_BunkerBuster.RaceProps, FleshTypeDefOf.Mechanoid);
  76. fleshTypeField.SetValue(Defs.ScientistMechPawn_TankTypeA.RaceProps, FleshTypeDefOf.Mechanoid);
  77. fleshTypeField.SetValue(Defs.ScientistMechPawn_TankTypeB.RaceProps, FleshTypeDefOf.Mechanoid);
  78. }
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement