public static void Patch(HarmonyObj obj) { if (obj.GetPatchedMethods().Any(x => x == coreGame)) { obj.Unpatch(coreGame, transpiler); } obj.Patch(coreGame, null, null, new HarmonyMethod(transpiler)); }
public static void Patch(HarmonyObj obj, CanvasUtility canvas, HUDConfigModel hud, MenuUIInstaller menuUIInstaller) { if (obj.GetPatchedMethods().Any(x => x == menuTransitions)) { obj.Unpatch(menuTransitions, transpiler); } canvasUtility = canvas; hudConfig = hud; menuInstaller = menuUIInstaller; obj.Patch(menuTransitions, null, null, new HarmonyMethod(transpiler)); }
static HarmonyPatchesFS() { HarmonyLib.Harmony harmony = new HarmonyLib.Harmony("rimworld.facialstuff.mod"); // HarmonyLib.Harmony.DEBUG = true; harmony.PatchAll(Assembly.GetExecutingAssembly()); harmony.Patch( AccessTools.Method(typeof(Page_ConfigureStartingPawns), "DrawPortraitArea"), null, new HarmonyMethod(typeof(HarmonyPatchesFS), nameof(AddFaceEditButton))); harmony.Patch( AccessTools.Method(typeof(PawnGraphicSet), nameof(PawnGraphicSet.ResolveAllGraphics)), null, new HarmonyMethod(typeof(HarmonyPatchesFS), nameof(ResolveAllGraphics_Postfix))); harmony.Patch( AccessTools.Method(typeof(PawnGraphicSet), nameof(PawnGraphicSet.ResolveApparelGraphics)), null, new HarmonyMethod(typeof(HarmonyPatchesFS), nameof(ResolveApparelGraphics_Postfix))); harmony.Patch( AccessTools.Method(typeof(PawnRenderer), nameof(PawnRenderer.DrawEquipmentAiming)), new HarmonyMethod(typeof(HarmonyPatchesFS), nameof(DrawEquipmentAiming_Prefix)), null, new HarmonyMethod(typeof(HarmonyPatchesFS), nameof(DrawEquipmentAiming_Transpiler))); harmony.Patch( AccessTools.Method(typeof(PawnRenderer), nameof(PawnRenderer.RenderPawnAt), new[] { typeof(Vector3), typeof(RotDrawMode), typeof(bool), typeof(bool) }), // new HarmonyMethod(typeof(HarmonyPatchesFS), nameof(HarmonyPatchesFS.RenderPawnAt)), null, null, new HarmonyMethod(typeof(HarmonyPatchesFS), nameof(RenderPawnAt_Transpiler)) ); harmony.Patch( AccessTools.Method(typeof(HediffSet), nameof(HediffSet.DirtyCache)), null, new HarmonyMethod(typeof(HarmonyPatchesFS), nameof(DirtyCache_Postfix))); harmony.Patch( AccessTools.Method(typeof(GraphicDatabaseHeadRecords), nameof(GraphicDatabaseHeadRecords.Reset)), null, new HarmonyMethod( typeof(GraphicDatabaseHeadRecordsModded), nameof(GraphicDatabaseHeadRecordsModded.Reset))); harmony.Patch( AccessTools.Method(typeof(PawnHairChooser), nameof(PawnHairChooser.RandomHairDefFor)), new HarmonyMethod(typeof(HarmonyPatchesFS), nameof(RandomHairDefFor_PreFix)), null); harmony.Patch( AccessTools.Method(typeof(PawnSkinColors), "GetSkinDataIndexOfMelanin"), new HarmonyMethod( typeof(PawnSkinColors_FS), nameof(PawnSkinColors_FS.GetSkinDataIndexOfMelanin_Prefix)), null); harmony.Patch( AccessTools.Method(typeof(PawnSkinColors), nameof(PawnSkinColors.GetSkinColor)), new HarmonyMethod(typeof(PawnSkinColors_FS), nameof(PawnSkinColors_FS.GetSkinColor_Prefix)), null); harmony.Patch( AccessTools.Method(typeof(PawnSkinColors), nameof(PawnSkinColors.RandomMelanin)), new HarmonyMethod(typeof(PawnSkinColors_FS), nameof(PawnSkinColors_FS.RandomMelanin_Prefix)), null); harmony.Patch( AccessTools.Method(typeof(PawnSkinColors), nameof(PawnSkinColors.GetMelaninCommonalityFactor)), new HarmonyMethod( typeof(PawnSkinColors_FS), nameof(PawnSkinColors_FS.GetMelaninCommonalityFactor_Prefix)), null); harmony.Patch( AccessTools.Method(typeof(Pawn_InteractionsTracker), nameof(Pawn_InteractionsTracker.TryInteractWith)), null, new HarmonyMethod(typeof(HarmonyPatchesFS), nameof(TryInteractWith_Postfix))); Log.Message( "Facial Stuff successfully completed " + harmony.GetPatchedMethods().Count() + " patches with harmony."); foreach (ThingDef def in DefDatabase <ThingDef> .AllDefsListForReading.Where( td => td.category == ThingCategory.Pawn && td.race.Humanlike)) { if (def.inspectorTabs == null || def.inspectorTabs.Count == 0) { def.inspectorTabs = new List <Type>(); def.inspectorTabsResolved = new List <InspectTabBase>(); } if (def.inspectorTabs.Contains(typeof(ITab_Pawn_Weapons))) { return; } def.inspectorTabs.Add(typeof(ITab_Pawn_Weapons)); def.inspectorTabsResolved.Add(InspectTabManager.GetSharedInstance(typeof(ITab_Pawn_Weapons))); def.inspectorTabs.Add(typeof(ITab_Pawn_Face)); def.inspectorTabsResolved.Add(InspectTabManager.GetSharedInstance(typeof(ITab_Pawn_Face))); } List <HairDef> beardyHairList = DefDatabase <HairDef> .AllDefsListForReading.Where(x => x.IsBeardNotHair()).ToList(); for (int i = 0; i < beardyHairList.Count(); i++) { HairDef beardy = beardyHairList[i]; if (beardy.label.Contains("shaven")) { continue; } BeardDef beardDef = new BeardDef { defName = beardy.defName, label = "_VHE_" + beardy.label, hairGender = beardy.hairGender, texPath = beardy.texPath.Replace("Things/Pawn/Humanlike/Beards/", ""), hairTags = beardy.hairTags, beardType = BeardType.FullBeard }; if (beardDef.label.Contains("stubble") || beardDef.label.Contains("goatee") || beardDef.label.Contains("lincoln")) { beardDef.drawMouth = true; } DefDatabase <BeardDef> .Add(beardDef); } Dialog_FaceStyling.FullBeardDefs = DefDatabase <BeardDef> .AllDefsListForReading.Where(x => x.beardType == BeardType.FullBeard) .ToList(); Dialog_FaceStyling.LowerBeardDefs = DefDatabase <BeardDef> .AllDefsListForReading.Where(x => x.beardType != BeardType.FullBeard) .ToList(); Dialog_FaceStyling.MoustacheDefs = DefDatabase <MoustacheDef> .AllDefsListForReading; CheckAllInjected(); }
static HarmonyPatches() { bool injected = false; string patchLog = "Start injecting PSI to pawns ..."; foreach (ThingDef def in DefDatabase <ThingDef> .AllDefs.Where( x => x.race != null && x.race.Humanlike && x.race.IsFlesh)) { patchLog += "\nPSI check: " + def; if (def?.comps != null) { def.comps.Add(new CompProperties(typeof(CompPSI))); patchLog += " - PSI injected."; injected = true; } } patchLog += injected ? string.Empty : "\nNo pawns found for PSI :("; Log.Message(patchLog); var harmony = new HarmonyLib.Harmony("com.colonistbarkf.rimworld.mod"); harmony.Patch( AccessTools.Method(typeof(ColonistBar), nameof(ColonistBar.ColonistBarOnGUI)), new HarmonyMethod(typeof(ColonistBar_KF), nameof(ColonistBar_KF.ColonistBarOnGUI_Prefix)), null); harmony.Patch( AccessTools.Method(typeof(ColonistBar), nameof(ColonistBar.MapColonistsOrCorpsesInScreenRect)), new HarmonyMethod(typeof(HarmonyPatches), nameof(MapColonistsOrCorpsesInScreenRect_Prefix)), null); harmony.Patch( AccessTools.Method(typeof(ColonistBar), nameof(ColonistBar.CaravanMembersCaravansInScreenRect)), new HarmonyMethod(typeof(HarmonyPatches), nameof(CaravanMembersCaravansInScreenRect_Prefix)), null); harmony.Patch( AccessTools.Method(typeof(ColonistBar), nameof(ColonistBar.ColonistOrCorpseAt)), new HarmonyMethod(typeof(HarmonyPatches), nameof(ColonistOrCorpseAt_Prefix)), null); harmony.Patch( AccessTools.Method(typeof(ColonistBar), nameof(ColonistBar.CaravanMemberCaravanAt)), new HarmonyMethod(typeof(HarmonyPatches), nameof(CaravanMemberCaravanAt_Prefix)), null); harmony.Patch( AccessTools.Method(typeof(ColonistBar), nameof(ColonistBar.GetColonistsInOrder)), new HarmonyMethod(typeof(HarmonyPatches), nameof(GetColonistsInOrder_Prefix)), null); harmony.Patch( AccessTools.Method(typeof(ColonistBar), nameof(ColonistBar.MarkColonistsDirty)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(MarkColonistsDirty_Postfix))); harmony.Patch( AccessTools.Method(typeof(Caravan), nameof(Caravan.Notify_PawnAdded)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(EntriesDirty_Postfix))); harmony.Patch( AccessTools.Method(typeof(Caravan), nameof(Caravan.Notify_PawnRemoved)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(EntriesDirty_Postfix))); harmony.Patch( AccessTools.Method(typeof(Caravan), nameof(Caravan.PostAdd)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(EntriesDirty_Postfix))); harmony.Patch( AccessTools.Method(typeof(Caravan), nameof(Caravan.PostRemove)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(EntriesDirty_Postfix))); harmony.Patch( AccessTools.Method(typeof(Game), nameof(Game.AddMap)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(EntriesDirty_Postfix))); harmony.Patch( AccessTools.Method(typeof(Window), nameof(Window.Notify_ResolutionChanged)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(IsPlayingDirty_Postfix))); harmony.Patch( AccessTools.Method(typeof(Game), nameof(Game.DeinitAndRemoveMap)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(IsPlayingDirty_Postfix))); harmony.Patch( AccessTools.Method(typeof(Pawn), nameof(Pawn.SetFaction)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(EntriesDirty_Postfix))); harmony.Patch( AccessTools.Method(typeof(Pawn), nameof(Pawn.SpawnSetup)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(Pawn_SpawnSetup_Postfix))); harmony.Patch( AccessTools.Method(typeof(Pawn), nameof(Pawn.Kill)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(Pawn_Kill_Postfix))); harmony.Patch( AccessTools.Method(typeof(Pawn_HealthTracker), nameof(Pawn_HealthTracker.Notify_Resurrected)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(Pawn_Resurrected_Postfix))); // NOT WORKING, FollowMe immediatly cancels if this is active // harmony.Patch( // AccessTools.Method(typeof(CameraDriver), nameof(CameraDriver.JumpToCurrentMapLoc), new[] { typeof(Vector3) }), // new HarmonyMethod(typeof(HarmonyPatches), nameof(StopFollow_Prefix)), // null); harmony.Patch( AccessTools.Method( typeof(WorldCameraDriver), nameof(WorldCameraDriver.JumpTo), new[] { typeof(Vector3) }), new HarmonyMethod(typeof(HarmonyPatches), nameof(StopFollow_Prefix)), null); harmony.Patch( AccessTools.Method( typeof(ThingSelectionUtility), nameof(ThingSelectionUtility.SelectNextColonist)), new HarmonyMethod(typeof(HarmonyPatches), nameof(StartFollowSelectedColonist1)), new HarmonyMethod(typeof(HarmonyPatches), nameof(StartFollowSelectedColonist2)), null); harmony.Patch( AccessTools.Method( typeof(ThingSelectionUtility), nameof(ThingSelectionUtility.SelectPreviousColonist)), new HarmonyMethod(typeof(HarmonyPatches), nameof(StartFollowSelectedColonist1)), new HarmonyMethod(typeof(HarmonyPatches), nameof(StartFollowSelectedColonist2)), null); harmony.Patch( AccessTools.Method( typeof(CameraDriver), nameof(CameraDriver.JumpToCurrentMapLoc), new[] { typeof(Vector3) }), new HarmonyMethod(typeof(HarmonyPatches), nameof(StopFollow_Prefix_Vector3)), null); harmony.Patch( AccessTools.Method(typeof(Pawn), nameof(Pawn.PostApplyDamage)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(Pawn_PostApplyDamage_Postfix))); harmony.Patch( AccessTools.Method(typeof(Corpse), "NotifyColonistBar"), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(NotifyColonistBar_Postfix))); harmony.Patch( AccessTools.Method(typeof(MapPawns), "DoListChangedNotifications"), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(IsColonistBarNull_Postfix))); harmony.Patch( AccessTools.Method(typeof(ThingOwner), "NotifyColonistBarIfColonistCorpse"), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(NotifyColonistBarIfColonistCorpse_Postfix))); harmony.Patch( AccessTools.Method(typeof(Thing), nameof(Thing.DeSpawn)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(DeSpawn_Postfix))); harmony.Patch( AccessTools.Method(typeof(PlaySettings), nameof(PlaySettings.DoPlaySettingsGlobalControls)), new HarmonyMethod(typeof(HarmonyPatches), nameof(PlaySettingsDirty_Prefix)), new HarmonyMethod(typeof(HarmonyPatches), nameof(PlaySettingsDirty_Postfix))); Log.Message( "Colonistbar KF successfully completed " + harmony.GetPatchedMethods().Count() + " patches with harmony."); }