diff --git a/1.3/Assemblies/Locks.dll b/1.3/Assemblies/Locks.dll index 2872f0d..5d2b5aa 100644 Binary files a/1.3/Assemblies/Locks.dll and b/1.3/Assemblies/Locks.dll differ diff --git a/1.3/Patches/AddCompLockSoS2.xml b/1.3/Patches/AddCompLockSoS2.xml new file mode 100644 index 0000000..00137ba --- /dev/null +++ b/1.3/Patches/AddCompLockSoS2.xml @@ -0,0 +1,26 @@ + + + + +
  • Save Our Ship 2
  • +
    + + /Defs/ThingDef[thingClass = "Building_ShipAirlock"]/comps + + /Defs/ThingDef[thingClass = "Building_ShipAirlock"] + + +
  • + + + + + /Defs/ThingDef[thingClass = "Building_ShipAirlock"]/comps + +
  • + + + + + + \ No newline at end of file diff --git a/1.3/Patches/AddInspectTabSoS2.xml b/1.3/Patches/AddInspectTabSoS2.xml new file mode 100644 index 0000000..45e6870 --- /dev/null +++ b/1.3/Patches/AddInspectTabSoS2.xml @@ -0,0 +1,26 @@ + + + + +
  • Save Our Ship 2
  • + + + /Defs/ThingDef[thingClass = "Building_ShipAirlock"]/inspectorTabs + + /Defs/ThingDef[thingClass = "Building_ShipAirlock"] + + +
  • Locks.ITab_Lock
  • +
    +
    +
    + + /Defs/ThingDef[thingClass = "Building_ShipAirlock"]/inspectorTabs + +
  • Locks.ITab_Lock
  • +
    +
    +
    +
    + +
    \ No newline at end of file diff --git a/About/About.xml b/About/About.xml index 0000f77..b620dcd 100644 --- a/About/About.xml +++ b/About/About.xml @@ -11,6 +11,10 @@ avius.locks
  • brrainz.harmony
  • +
  • haplo.miscellaneous.robots
  • +
  • kentington.saveourship2
  • +
  • linkolas.linkabledoors
  • +
  • jecrell.doorsexpanded
  • @@ -20,5 +24,5 @@ https://github.com/pardeike/HarmonyRimWorld/releases/latest
  • - Version 2.7.2\nThis addon adds Lock command on every door.\n - Left-click to lock toggle.\n - Right click for more options\n - Alternatively you can use "Lock" inspector tab\n\nNote: Door lock must be flicked by colonist. + Version 2.7.3\nThis addon adds Lock command on every door.\n - Left-click to lock toggle.\n - Right click for more options\n - Alternatively you can use "Lock" inspector tab\n\nNote: Door lock must be flicked by colonist. diff --git a/Languages/English/Keyed/Keys.xml b/Languages/English/Keyed/Keys.xml index 3d79e37..fdf2faa 100644 --- a/Languages/English/Keyed/Keys.xml +++ b/Languages/English/Keyed/Keys.xml @@ -1,42 +1,47 @@ - Lock - When unlocked all pawn will be allowed to use this door.\n[Right click for more options] + Lock + When unlocked all pawn will be allowed to use this door.\n[Right click for more options] - Door - locked - unlocked - changing... + Door + locked + unlocked + changing... - Locked - When unlocked door settings do not apply, therefore all humanoids capable of opening doors can pass. - Visitors allowed - When disabled, allies and traders will not be allowed to pass through this door. This setting do not apply when owners are set. - Pet door - When enabled small animals, like dogs can pass through door. This setting is not required for doors without owners. - Pens door - When enabled, pens animals can't pass through the door. Some doors may not block animals (e.g. Animal Flap). Check "roamerCanOpen" in defs. - Owners - Change lock in order to apply settings! - - Lock - Unlock - Allow visitors to use - Forbid visitors from using - Add pet door - Remove pet door - Set as pens door - Remove pens door - Set owners - Clear owners - - Lock does not belong to {0} + Locked + When unlocked door settings do not apply, therefore all humanoids capable of opening doors can pass. + Visitors allowed + When disabled, allies and traders will not be allowed to pass through this door. This setting do not apply when owners are set. + Pet door + When enabled small animals, like dogs can pass through door. This setting is not required for doors without owners. + Pens door + When enabled, pens animals can't pass through the door. Some doors may not block animals (e.g. Animal Flap). Check "roamerCanOpen" in defs. + Slaves allowed + When disabled slaves are not allowed to pass through this door. This setting do not apply when owners are set. + Animals allowed + When disabled all animals will not be allowed to pass through this door. This setting is checked after pens and pet door settings. - Locks can't be changed - Some locks can't be changed, because owners of those locks do not perform flick jobs:\n\n{0} - Some locks can't be changed, because owners of those locks do not perform flick jobs. + Owners + Change lock in order to apply settings! - Cancel - Copy - Paste + Lock + Unlock + Allow visitors to use + Forbid visitors from using + Add pet door + Remove pet door + Set as pens door + Remove pens door + Set owners + Clear owners + + Lock does not belong to {0} + + Locks can't be changed + Some locks can't be changed, because owners of those locks do not perform flick jobs:\n\n{0} + Some locks can't be changed, because owners of those locks do not perform flick jobs. + + Cancel + Copy + Paste \ No newline at end of file diff --git a/README.md b/README.md index 9eaf120..8badf8e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

    - v2.7.2 + v2.7.3

    diff --git a/Source/CompatibilityPatches/SoS2.cs b/Source/CompatibilityPatches/SoS2.cs new file mode 100644 index 0000000..406d1a7 --- /dev/null +++ b/Source/CompatibilityPatches/SoS2.cs @@ -0,0 +1,71 @@ +using HarmonyLib; +using Locks.HarmonyPatches; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Reflection.Emit; +using System.Text; +using System.Threading.Tasks; +using Verse; + +namespace Locks.CompatibilityPatches +{ + class SoS2 + { + public static void Init() + { + var mod = LoadedModManager.RunningMods.FirstOrDefault(m => m.Name == "Save Our Ship 2"); + if (mod != null) + { + var doorDef = AccessTools.Method("Building_ShipAirlock:PawnCanOpen"); + if (doorDef != null) + { + var harmony = new Harmony("Harmony_Locks_SoS2"); + harmony.Patch(doorDef, transpiler: new HarmonyMethod(typeof(SoS2).GetMethod("AirLockTranspiler"))); + Log.Message("Locks: SoS2 patched"); + } + else + { + Log.Error("Locks: mod SoS2 found but cant find airlock to patch"); + } + } + else + { + Log.Message("Locks: SoS2 not found "); + } + } + + public static IEnumerable AirLockTranspiler(ILGenerator gen, MethodBase mBase, IEnumerable instr) + { + OpCode[] codeToFind = + { + OpCodes.Ldarg_1, + OpCodes.Call, + OpCodes.Stloc_0 + + }; + + string[] labelToFind = + { + "", + "Verse.AI.Group.Lord GetLord(Verse.Pawn)", + "" + }; + int step = 0; + foreach (CodeInstruction codeInst in instr) + { + yield return codeInst; + if (HPatcher.IsFragment(codeToFind, labelToFind, codeInst, ref step)) + { + yield return new CodeInstruction(OpCodes.Ldarg_0); + yield return new CodeInstruction(OpCodes.Ldarg_1); + yield return new CodeInstruction(OpCodes.Call, typeof(LockUtility).GetMethod("PawnCanOpen")); + yield return new CodeInstruction(OpCodes.Ret); + } + } + + } + + } +} diff --git a/Source/ITab_Lock.cs b/Source/ITab_Lock.cs index 61509b9..8ac2500 100644 --- a/Source/ITab_Lock.cs +++ b/Source/ITab_Lock.cs @@ -17,7 +17,7 @@ public class ITab_Lock : ITab private static readonly Vector2 WinSize = new Vector2(310f + WindowGap, ButtonsHeight + OwnersWindowHeight + OwnersTitleHeight + MainSettingsHeight + WindowGap + 2 * Spacing + WarningHeight); private const float ButtonsHeight = 25f; private const float WindowGap = 15f; - private const float MainSettingsHeight = 4 * 32f; + private const float MainSettingsHeight = 6 * 32f; private const float OwnersTitleHeight = 24f; private const float OwnersWindowHeight = 200f; private const float WarningHeight = 24f; @@ -28,6 +28,8 @@ public class ITab_Lock : ITab private bool vistitorsAllowed; private bool petDoor; private bool pensDoor; + private bool slaveDoor; + private bool animalsAllowed; private Thing lastSelectedThing; @@ -75,12 +77,20 @@ protected override void FillTab() listing.Begin(upperSettingsRect); if (Data.WantedState.IsVisible(nameof(LockState.locked))) listing.CheckboxLabeled("Locks_ITabLocked".Translate(), ref locked, "Locks_ITabLockedDesc".Translate()); + if (Data.WantedState.IsVisible(nameof(LockState.allowSlave))) + { + listing.CheckboxLabeled("Locks_ITabSlaveDoors".Translate(), ref slaveDoor, "Locks_ITabSlaveDoorsDesc".Translate()); + } if (Data.WantedState.IsVisible(nameof(LockState.mode))) listing.CheckboxLabeled("Locks_ITabVisitorsAllowed".Translate(), ref vistitorsAllowed, "Locks_ITabVisitorsAllowedDesc".Translate()); if (Data.WantedState.IsVisible(nameof(LockState.petDoor))) listing.CheckboxLabeled("Locks_ITabPetDoor".Translate(), ref petDoor, "Locks_ITabPetDoorDesc".Translate()); if (Data.WantedState.IsVisible(nameof(LockState.pensDoor))) listing.CheckboxLabeled("Locks_ITabPensDoor".Translate(), ref pensDoor, "Locks_ITabPensDoorDesc".Translate()); + if (Data.WantedState.IsVisible(nameof(LockState.allowAnimals))) + { + listing.CheckboxLabeled("Locks_ITabAnimalAllowed".Translate(), ref animalsAllowed, "Locks_ITabAnimalAllowedDesc".Translate()); + } listing.End(); if (Data.WantedState.IsVisible(nameof(LockState.owners))) @@ -145,6 +155,8 @@ private void UpdateSettings() Data.WantedState.mode = vistitorsAllowed ? LockMode.Allies : LockMode.Colony; Data.WantedState.petDoor = petDoor; Data.WantedState.pensDoor = pensDoor; + Data.WantedState.allowSlave = slaveDoor; + Data.WantedState.allowAnimals = animalsAllowed; if (Data.NeedChange) LockUtility.UpdateLockDesignation(SelDoor); } @@ -158,9 +170,11 @@ private void UpdateSettings() public override void OnOpen() { locked = Data.WantedState.locked; - vistitorsAllowed = Data.WantedState.mode == LockMode.Allies ? true : false; + vistitorsAllowed = Data.WantedState.mode == LockMode.Allies; petDoor = Data.WantedState.petDoor; pensDoor = Data.WantedState.pensDoor; + slaveDoor = Data.WantedState.allowSlave; + animalsAllowed = Data.WantedState.allowAnimals; } private void OwnerCheckbox(Rect rect, Pawn pawn) diff --git a/Source/Initialization.cs b/Source/Initialization.cs index ed897b6..a46d158 100644 --- a/Source/Initialization.cs +++ b/Source/Initialization.cs @@ -13,6 +13,7 @@ static Initialization() HarmonyPatches.HPatcher.Init(); CompatibilityPatches.ClutterStructure.Init(); CompatibilityPatches.DoorsExpanded.Init(); + CompatibilityPatches.SoS2.Init(); } } } diff --git a/Source/LockState.cs b/Source/LockState.cs index 0ccb830..91569cc 100644 --- a/Source/LockState.cs +++ b/Source/LockState.cs @@ -16,17 +16,23 @@ public struct LockState { public LockMode mode; public bool locked; + public bool allowSlave; public bool petDoor; public bool pensDoor; + public bool allowAnimals; public List owners; - public LockState(LockMode mode, bool locked, bool petDoor, bool pensDoor, List owners) + public LockState(LockMode mode, bool locked, bool petDoor, bool pensDoor, List owners, + bool allowSlave = true, bool allowAnimals = true) { this.mode = mode; this.locked = locked; this.petDoor = petDoor; this.pensDoor = pensDoor; this.owners = owners; + + this.allowSlave = allowSlave; + this.allowAnimals = allowAnimals; } public void CopyFrom(LockState copy) @@ -37,60 +43,57 @@ public void CopyFrom(LockState copy) pensDoor = copy.pensDoor; owners.Clear(); owners.AddRange(copy.owners); + + allowSlave = copy.allowSlave; + allowAnimals = copy.allowAnimals; } public static bool operator ==(LockState a, LockState b) { if (a.mode != b.mode) + { return false; + } if (a.locked != b.locked) + { return false; + } if (a.petDoor != b.petDoor) - return false; - if (a.pensDoor != b.pensDoor) - return false; - foreach (var p in a.owners) - if (!b.owners.Contains(p)) - return false; - foreach (var p in b.owners) - if (!a.owners.Contains(p)) - return false; - return true; - } - - public static bool operator !=(LockState a, LockState b) - { - if (a.mode != b.mode) { - return true; + return false; } - if (a.locked != b.locked) + if (a.pensDoor != b.pensDoor) { - return true; + return false; } - if (a.petDoor != b.petDoor) + if (a.allowSlave != b.allowSlave) { - return true; + return false; } - if (a.pensDoor != b.pensDoor) + if (a.allowAnimals != b.allowAnimals) { - return true; + return false; } foreach (var p in a.owners) { if (!b.owners.Contains(p)) { - return true; + return false; } } foreach (var p in b.owners) { if (!a.owners.Contains(p)) { - return true; + return false; } } - return false; + return true; + } + + public static bool operator !=(LockState a, LockState b) + { + return !(a == b); } public bool Private @@ -107,6 +110,10 @@ public void ExposeData(String postfix) Scribe_Values.Look(ref locked, $"Locks_LockData_Locked_{postfix}", true, false); Scribe_Values.Look(ref petDoor, $"Locks_LockData_PetDoor_{postfix}", false, false); Scribe_Values.Look(ref pensDoor, $"Locks_LockData_PensDoor_{postfix}", false, false); + + Scribe_Values.Look(ref allowSlave, $"Locks_LockData_SlaveDoor_{postfix}", true, false); + Scribe_Values.Look(ref allowAnimals, $"Locks_LockData_NonAnimalDoor_{postfix}", true, false); + Scribe_Collections.Look(ref owners, $"Locks_LockData_Owners_{postfix}", LookMode.Reference); } } diff --git a/Source/LockUtility.cs b/Source/LockUtility.cs index e2c49ea..4063173 100644 --- a/Source/LockUtility.cs +++ b/Source/LockUtility.cs @@ -1,4 +1,5 @@ -using RimWorld; +using Locks.CompatibilityPatches; +using RimWorld; using System; using System.Collections.Generic; using System.Linq; @@ -78,14 +79,23 @@ public static bool PawnCanOpen(ThingWithComps door, Pawn p) { return true; } - + if (!respectedState.allowAnimals && p.RaceProps != null && p.RaceProps.Animal) + { + return false; + } if (respectedState.Private && !respectedState.owners.Contains(p)) - { return false; } + { + return false; + } - if (p.Faction == door.Faction && !p.IsPrisoner) + if (p.Faction == door.Faction && !p.IsPrisoner && !p.IsSlave) { return true; } + if (!respectedState.allowSlave && p.Faction == door.Faction && p.IsSlave) + { + return false; + } bool guestCondition = !p.IsPrisoner || p.HostFaction != door.Faction; if (respectedState.mode == LockMode.Allies && guestCondition) { @@ -146,6 +156,10 @@ public static bool IsVisible(this LockState state, string propertyName) return true; case nameof(LockState.owners): return state.locked; + case nameof(LockState.allowAnimals): + return state.locked; + case nameof(LockState.allowSlave): + return state.locked; default: return true; } diff --git a/Source/Locks.csproj b/Source/Locks.csproj index 368f10d..833a55e 100644 --- a/Source/Locks.csproj +++ b/Source/Locks.csproj @@ -73,6 +73,7 @@ + @@ -107,6 +108,9 @@ Patches\AddCompLockLinkableDoors.xml + + Patches\AddCompLockSoS2.xml + Patches\AddInspectTab.xml @@ -116,6 +120,9 @@ Patches\AddInspectTabLockLinkableDoors.xml + + Patches\AddInspectTabSoS2.xml + Organizer\About.xml diff --git a/changelog.txt b/changelog.txt index 8b9cbb9..ebead9d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,10 @@ Changelog: +2.7.3 +- Add German translation (https://github.com/thephluxer) +- Add Italian transaltion - not complete (https://github.com/StoneNimRod) +- New option "Slaves allowed" for doors +- New option "Animals allowed" for doors +- Compatibility patches for SoS2 (I dont use this mod so any feedback welcome) 2.7.2 - Add compatibility with Linkable Doors 2.7.1