Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
- Fixed default rules not applying to prisoners and guests
- Arresting own colonists now keep their original rules
  • Loading branch information
Jaxe-Dev committed Sep 10, 2018
1 parent 0a85b5a commit 5fda731
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 78 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<name>Pawn Rules</name>
<author>Jaxe</author>
<targetVersion>0.19.0</targetVersion>
<description>Mod Version: 1.0.9\n\n\nPawn Rules is a mod that allows custom rules to be assigned individually to your colonists, animals, guests and prisoners.\n\nCurrently the following rules can be applied:\n\n- Disallow certain foods\n- Disallow bonding with certain animals\n- Disallow new romances\n- Disallow constructing items that have a quality level\n\nAny of these rules can be disabled and hidden from the rules window.</description>
<description>Mod Version: 1.1.0\n\n\nPawn Rules is a mod that allows custom rules to be assigned individually to your colonists, animals, guests and prisoners.\n\nCurrently the following rules can be applied:\n\n- Disallow certain foods\n- Disallow bonding with certain animals\n- Disallow new romances\n- Disallow constructing items that have a quality level\n\nAny of these rules can be disabled and hidden from the rules window.</description>
<url>https://ludeon.com/forums/index.php?topic=43086.0</url>
</ModMetaData>
2 changes: 1 addition & 1 deletion About/ModSync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ModSyncNinjaData>
<ID>59f538ed-f86d-4506-a4a5-7e9faaa37508</ID>
<ModName>Pawn Rules</ModName>
<Version>v1.0.9</Version>
<Version>v1.1.0</Version>
<SaveBreaking>False</SaveBreaking>
<Host name="Github">
<Owner>Jaxe-Dev</Owner>
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Pawn Rules
![](https://img.shields.io/badge/Version-1.0.9-brightgreen.svg)
![](https://img.shields.io/badge/Version-1.1.0-brightgreen.svg)

Built for **RimWorld B19**\
Powered by **Harmony**\
Expand Down Expand Up @@ -42,22 +42,22 @@ Supports addons created by other modders by allowing easy creation of new rule o
------------

The following original methods are patched using Harmony:
The following base methods are patched with Harmony:
```C#
RimWorld.FoodUtility.BestFoodSourceOnMap : Prefix
RimWorld.FoodUtility.BestFoodInInventory : Prefix
RimWorld.FoodUtility.TryFindBestFoodSourceFor : Prefix
RimWorld.GenConstruct.CanConstruct : Postfix
RimWorld.InteractionWorker_RomanceAttempt.RandomSelectionWeight : Prefix
RimWorld.InteractionWorker_RomanceAttempt.SuccessChance : Prefix
RimWorld.JobGiver_PackFood.IsGoodPackableFoodFor : Postfix
RimWorld.JoyGiver_Ingest.CanIngestForJoy : Prefix
RimWorld.Pawn_GuestTracker.SetGuestStatus : Prefix
RimWorld.PawnUtility.TrySpawnHatchedOrBornPawn : Postfix
RimWorld.RelationsUtility.TryDevelopBondRelation : Prefix
Verse.Game.FinalizeInit : Postfix
Verse.Pawn.GetGizmos : Postfix
Verse.Pawn.Kill : Postfix
Verse.Pawn.SetFaction : Prefix
Verse.PawnGenerator.GeneratePawn : Postfix
Prefix : RimWorld.FoodUtility.BestFoodSourceOnMap
Prefix : RimWorld.FoodUtility.BestFoodInInventory
Prefix : RimWorld.FoodUtility.TryFindBestFoodSourceFor
Postfix : RimWorld.GenConstruct.CanConstruct
Prefix : RimWorld.InteractionWorker_RomanceAttempt.RandomSelectionWeight
Prefix : RimWorld.InteractionWorker_RomanceAttempt.SuccessChance
Postfix : RimWorld.JobGiver_PackFood.IsGoodPackableFoodFor
Prefix : RimWorld.JoyGiver_Ingest.CanIngestForJoy
Prefix : RimWorld.Pawn_GuestTracker.SetGuestStatus
Postfix : RimWorld.PawnUtility.TrySpawnHatchedOrBornPawn
Prefix : RimWorld.RelationsUtility.TryDevelopBondRelation
Postfix : Verse.Game.FinalizeInit
Postfix : Verse.Pawn.GetGizmos
Postfix : Verse.Pawn.Kill
Prefix : Verse.Pawn.SetFaction
Postfix : Verse.PawnGenerator.GeneratePawn
```
15 changes: 10 additions & 5 deletions Source/Data/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ public static Rules GetOrDefaultRules(Pawn pawn)
public static void ReplaceRules(Pawn pawn, Rules rules) => Instance._rules[pawn] = rules;
public static void ReplaceDefaultRules(PawnType type, Rules rules) => Instance._defaults[type] = rules;

private static void ChangeTypeOrCreateRules(Pawn pawn, PawnType type) => Instance._rules[pawn] = GetDefaultRules(type);
private static void ChangeTypeOrCreateRules(Pawn pawn, PawnType type)
{
if (type == pawn.GetTargetType()) { return; }
Instance._rules[pawn] = GetDefaultRules(type);
}

public static Rules CloneRules(Pawn original, Pawn cloner)
{
Expand All @@ -187,16 +191,17 @@ public static void DeleteRules(Pawn pawn)

public static void FactionUpdate(Thing thing, Faction newFaction, bool? guest = null)
{
if (!(thing is Pawn pawn) || !pawn.Spawned || pawn.Dead) { return; }
if (!(thing is Pawn pawn) || pawn.Dead) { return; }

var oldFaction = guest == null ? pawn.Faction : pawn.HostFaction;
PawnType type;

if (newFaction == Faction.OfPlayer)
{
if ((guest == null) || pawn.IsColonistPlayerControlled) { type = pawn.RaceProps.Animal ? PawnType.Animal : PawnType.Colonist; }
if ((guest == null) || (pawn.Faction == Faction.OfPlayer)) { type = pawn.RaceProps.Animal ? PawnType.Animal : PawnType.Colonist; }
else { type = guest.Value ? PawnType.Guest : PawnType.Prisoner; }
}
else if ((guest == null ? pawn.Faction : pawn.HostFaction) == Faction.OfPlayer)
else if ((oldFaction == Faction.OfPlayer) && (newFaction != null))
{
DeleteRules(pawn);
return;
Expand All @@ -212,7 +217,7 @@ public static void DeactivateMod()

ModsConfig.SetActive(Mod.ContentPack.Identifier, false);

var runningMods = PrivateAccess.Verse_LoadedModManager_RunningMods();
var runningMods = Access.Field_Verse_LoadedModManager_RunningMods_Get();
runningMods.Remove(Mod.ContentPack);

var addonMods = new StringBuilder();
Expand Down
5 changes: 3 additions & 2 deletions Source/Data/RestrictionTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using PawnRules.Patch;
using Verse;

namespace PawnRules.Data
Expand All @@ -28,7 +27,7 @@ private static RestrictionTemplate GetFoodsCategorized(Restriction restriction)

foreach (var food in FoodCache)
{
var category = food.GetCategoryLabel();
var category = GetCategoryLabel(food);

if (!list.ContainsKey(category)) { list[category] = new Category(category); }
list[category].Members.Add(new Toggle(food, restriction.Allows(food)));
Expand Down Expand Up @@ -75,6 +74,8 @@ public static RestrictionTemplate Build(RestrictionType type, Restriction restri
return type == RestrictionType.Bonding ? GetAnimalsCategorized(restriction) : null;
}

private static string GetCategoryLabel(ThingDef self) => self.category == ThingCategory.Item ? self.FirstThingCategory.LabelCap : self.category.ToString();

public class Category
{
public string Label { get; }
Expand Down
2 changes: 1 addition & 1 deletion Source/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class Mod : Verse.Mod
public const string Id = "PawnRules";
public const string Name = "Pawn Rules";
public const string Author = "Jaxe";
public const string Version = "1.0.9";
public const string Version = "1.1.0";

public static ModContentPack ContentPack { get; private set; }

Expand Down
29 changes: 29 additions & 0 deletions Source/Patch/Access.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Harmony;
using RimWorld;
using Verse;
using Verse.AI;

namespace PawnRules.Patch
{
internal static class Access
{
private static readonly MethodInfo Method_RimWorld_FoodUtility_BestPawnToHuntForPredator = AccessTools.Method(typeof(FoodUtility), "BestPawnToHuntForPredator");
private static readonly MethodInfo Method_RimWorld_FoodUtility_GetMaxRegionsToScan = AccessTools.Method(typeof(FoodUtility), "GetMaxRegionsToScan");
private static readonly MethodInfo Method_RimWorld_FoodUtility_IsFoodSourceOnMapSociallyProper = AccessTools.Method(typeof(FoodUtility), "IsFoodSourceOnMapSociallyProper");
private static readonly MethodInfo Method_RimWorld_FoodUtility_SpawnedFoodSearchInnerScan = AccessTools.Method(typeof(FoodUtility), "SpawnedFoodSearchInnerScan");
private static readonly FieldInfo Field_RimWorld_FoodUtility_Filtered = AccessTools.Field(typeof(FoodUtility), "filtered");
private static readonly FieldInfo Field_RimWorld_Pawn_GuestTracker_Pawn = AccessTools.Field(typeof(Pawn_GuestTracker), "pawn");
private static readonly FieldInfo Field_Verse_LoadedModManager_RunningMods = AccessTools.Field(typeof(LoadedModManager), "runningMods");

public static Pawn Method_RimWorld_FoodUtility_BestPawnToHuntForPredator_Call(Pawn predator, bool forceScanWholeMap) => (Pawn) Method_RimWorld_FoodUtility_BestPawnToHuntForPredator.Invoke(null, new object[] { predator, forceScanWholeMap });
public static int Method_RimWorld_FoodUtility_GetMaxRegionsToScan_Call(Pawn getter, bool forceScanWholeMap) => (int) Method_RimWorld_FoodUtility_GetMaxRegionsToScan.Invoke(null, new object[] { getter, forceScanWholeMap });
public static bool Method_RimWorld_FoodUtility_IsFoodSourceOnMapSociallyProper_Call(Thing thing, Pawn getter, Pawn eater, bool allowSociallyImproper) => (bool) Method_RimWorld_FoodUtility_IsFoodSourceOnMapSociallyProper.Invoke(null, new object[] { thing, getter, eater, allowSociallyImproper });
public static Thing Method_RimWorld_FoodUtility_SpawnedFoodSearchInnerScan_Call(Pawn eater, IntVec3 root, List<Thing> searchSet, PathEndMode peMode, TraverseParms traverseParams, float maxDistance = 9999f, Predicate<Thing> validator = null) => (Thing) Method_RimWorld_FoodUtility_SpawnedFoodSearchInnerScan.Invoke(null, new object[] { eater, root, searchSet, peMode, traverseParams, maxDistance, validator });
public static HashSet<Thing> Field_RimWorld_FoodUtility_Filtered_Get() => (HashSet<Thing>) Field_RimWorld_FoodUtility_Filtered.GetValue(null);
public static Pawn Field_RimWorld_Pawn_GuestTracker_Pawn_Get(Pawn_GuestTracker instance) => (Pawn) Field_RimWorld_Pawn_GuestTracker_Pawn.GetValue(instance);
public static List<ModContentPack> Field_Verse_LoadedModManager_RunningMods_Get() => (List<ModContentPack>) Field_Verse_LoadedModManager_RunningMods.GetValue(null);
}
}
7 changes: 2 additions & 5 deletions Source/Patch/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ internal static class Extensions
public static string Italic(this string self) => "<i>" + self + "</i>";
public static string Bold(this string self) => "<b>" + self + "</b>";

public static string GetCategoryLabel(this ThingDef self) => self.category == ThingCategory.Item ? self.FirstThingCategory.LabelCap : self.category.ToString();
public static Rect AdjustedBy(this Rect self, float x, float y, float width, float height) => new Rect(self.x + x, self.y + y, self.width + width, self.height + height);

public static int LastIndex(this Array self) => self.Length - 1;

public static int ToInt(this string self, int defaultValue = 0) => int.TryParse(self, out var result) ? result : defaultValue;
public static float ToFloat(this string self, float defaultValue = 0f) => float.TryParse(self, out var result) ? result : defaultValue;

public static bool CanHaveRules(this Pawn self) => (self != null) && !self.Dead && (self.GetTargetType() != null);

public static PawnType GetTargetType(this Pawn self)
{
if (self == null) { return null; }
Expand All @@ -30,6 +25,8 @@ public static PawnType GetTargetType(this Pawn self)
return null;
}

public static Rect AdjustedBy(this Rect self, float x, float y, float width, float height) => new Rect(self.x + x, self.y + y, self.width + width, self.height + height);

public static Rect[] GetHGrid(this Rect self, float spacing, params float[] widths)
{
var unfixedCount = 0;
Expand Down
27 changes: 0 additions & 27 deletions Source/Patch/PrivateAccess.cs

This file was deleted.

Loading

0 comments on commit 5fda731

Please sign in to comment.