Skip to content

Commit

Permalink
git commit from PowerShell in C#JecsTools Adds new BuildingExtension …
Browse files Browse the repository at this point in the history
…class to allow for bypasses to SpawningWipes. Perfect for adding furniture on top of existing tables.
  • Loading branch information
jecrell committed Sep 30, 2018
1 parent 1e78c82 commit becd995
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 12 deletions.
12 changes: 10 additions & 2 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<author>jecrell</author>
<url>https://discord.gg/AaVFA7V</url>
<targetVersion>0.19.0</targetVersion>
<description>1.1.0.5
<description>1.1.0.6 (09-30-2018)

Adds modding components to RimWorld: vehicles, spell casting, weapon slots, oversized weapons, and more!

Expand Down Expand Up @@ -53,5 +53,13 @@ Additions by Swenzi
Additions and transpilers by Erdelf
Extensive hours of testing, debugging, and fixes by Xen.
"Hey, should we make this into a public toolset for people to take advantage of all this cool stuff?" - Jecrell
"Hell yes - this is awesome stuff - people will love it!" - Xen</description>
"Hell yes - this is awesome stuff - people will love it!" - Xen
===================
Changelog
===================
1.1.0.6 (09-30-2018)
===================
Adds new BuildingExtension class to allow for bypasses to SpawningWipes. Perfect for adding furniture on top of existing tables.

</description>
</ModMetaData>
4 changes: 4 additions & 0 deletions About/Changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1.1.0.6 (09-30-2018)
===================
Adds new BuildingExtension class to allow for bypasses to SpawningWipes. Perfect for adding furniture on top of existing tables.

2 changes: 1 addition & 1 deletion About/Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0.5
1.1.0.6
Binary file modified Assemblies/0JecsTools.dll
Binary file not shown.
Binary file modified Assemblies/AbilityUserAI.dll
Binary file not shown.
Binary file modified Assemblies/CompInstalledPart.dll
Binary file not shown.
Binary file modified Assemblies/CompSlotLoadable.dll
Binary file not shown.
1 change: 1 addition & 0 deletions Source/.idea/.idea.JecsTools/.idea/contentModel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Source/AllModdingComponents/JecsTools/BuildingExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using Verse;
using Verse.AI;

namespace JecsTools
{

public class BuildingExtension : DefModExtension
{
public List<string> wipeCategories = new List<string>();
}
}
118 changes: 115 additions & 3 deletions Source/AllModdingComponents/JecsTools/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using RimWorld;
using UnityEngine;
using Verse;
using Verse.AI;
using Verse.Sound;

namespace JecsTools
Expand Down Expand Up @@ -36,30 +37,141 @@ static HarmonyPatches()
// nameof(PawnGroupKindWorker_Normal.MinPointsToGenerateAnything)),
// new HarmonyMethod(type, nameof(MinPointsTest)), null);
//------------

//Adds HediffCompProperties_DamageSoak checks to damage
harmony.Patch(AccessTools.Method(typeof(Pawn_HealthTracker), nameof(Pawn_HealthTracker.PreApplyDamage)),
new HarmonyMethod(type, nameof(PreApplyDamage_PrePatch)), null);

//Applies cached armor damage and absorption
harmony.Patch(AccessTools.Method(typeof(ArmorUtility), "ApplyArmor"),
new HarmonyMethod(type, nameof(ApplyProperDamage)), null);

//Applies damage soak motes
harmony.Patch(AccessTools.Method(typeof(ArmorUtility), nameof(ArmorUtility.GetPostArmorDamage)), null,
new HarmonyMethod(type, nameof(Post_GetPostArmorDamage)));

//Allows for adding additional HediffSets when characters spawn using the StartWithHediff class.
harmony.Patch(
AccessTools.Method(typeof(PawnGenerator), "GeneratePawn", new[] {typeof(PawnGenerationRequest)}), null,
new HarmonyMethod(type, nameof(Post_GeneratePawn)));

//Checks apparel that uses the ApparelExtension
harmony.Patch(AccessTools.Method(typeof(ApparelUtility), nameof(ApparelUtility.CanWearTogether)), null,
new HarmonyMethod(type, nameof(Post_CanWearTogether)));

//Handles special cases of faction disturbances
harmony.Patch(AccessTools.Method(typeof(Faction), nameof(Faction.Notify_MemberDied)),
new HarmonyMethod(type, nameof(Notify_MemberDied)), null);

//Handles FactionSettings extension to allow for fun effects when factions arrive.
harmony.Patch(
AccessTools.Method(typeof(PawnGroupMakerUtility), nameof(PawnGroupMakerUtility.GeneratePawns)), null,
new HarmonyMethod(type, nameof(GeneratePawns)), null);
//harmony.Patch(AccessTools.Method(AccessTools.TypeByName("PossibleApparelSet"), "IsNaked"), null,
// new HarmonyMethod(type, nameof(IsNaked)), null);

//Handles cases where gendered apparel swaps out for individual genders.
harmony.Patch(
AccessTools.Method(typeof(PawnApparelGenerator),
nameof(PawnApparelGenerator.GenerateStartingApparelFor)), null,
new HarmonyMethod(type, nameof(GenerateStartingApparelFor_PostFix)), null);

//GUIPatches(harmony);
//BuildingExtension prevents some things from wiping other things when spawned.
harmony.Patch(
AccessTools.Method(typeof(GenSpawn),
nameof(GenSpawn.SpawningWipes)), null,
new HarmonyMethod(type, nameof(SpawningWipes_PostFix)), null);
// harmony.Patch(
// AccessTools.Method(typeof(GenConstruct),
// nameof(GenConstruct.HandleBlockingThingJob)), null,
// new HarmonyMethod(type, nameof(HandleBlockingThingJob_PostFix)), null);
harmony.Patch(
AccessTools.Method(typeof(GenConstruct),
nameof(GenConstruct.BlocksConstruction)), null,
new HarmonyMethod(type, nameof(BlocksConstruction_PostFix)), null);
}

public static void BlocksConstruction_PostFix(Thing constructible, Thing t, ref bool __result)
{
ThingDef thingDef = constructible.def;
ThingDef thingDef2 = t.def;
if (thingDef == null || thingDef2 == null)
return;
if (thingDef.HasModExtension<BuildingExtension>() || thingDef2.HasModExtension<BuildingExtension>())
{
BuildableDef buildableDef = GenConstruct.BuiltDefOf(thingDef);
BuildableDef buildableDef2 = GenConstruct.BuiltDefOf(thingDef2);
__result = ShouldWipe(buildableDef, buildableDef2, t.PositionHeld, t.MapHeld);
}
}

public static void SpawningWipes_PostFix(BuildableDef newEntDef, BuildableDef oldEntDef, ref bool __result)
{
ThingDef thingDef = newEntDef as ThingDef;
ThingDef thingDef2 = oldEntDef as ThingDef;
if (thingDef == null || thingDef2 == null)
return;
if (thingDef.HasModExtension<BuildingExtension>() || thingDef2.HasModExtension<BuildingExtension>())
{
BuildableDef buildableDef = GenConstruct.BuiltDefOf(thingDef);
BuildableDef buildableDef2 = GenConstruct.BuiltDefOf(thingDef2);
__result = ShouldWipe(buildableDef, buildableDef2, IntVec3.Invalid, null);
}
}

private static bool ShouldWipe(BuildableDef newEntDef, BuildableDef oldEntDef, IntVec3 loc, Map map)
{
if (map == null || loc == null || !loc.IsValid)
{
var buildingExtensionA = newEntDef?.GetModExtension<BuildingExtension>();
var buildingExtensionB = oldEntDef?.GetModExtension<BuildingExtension>();
if (buildingExtensionB == null && buildingExtensionA == null)
{
//Log.Message("Both null");
return true;
}

//Log.Message("A: " + newEntDef.label);
//Log.Message("B: " + oldEntDef.label);
if (buildingExtensionA != null && buildingExtensionB == null &&
buildingExtensionA.wipeCategories?.Count > 0)
{
//Log.Message("B null");

return false;
}

if (buildingExtensionB != null && buildingExtensionA == null &&
buildingExtensionB.wipeCategories?.Count > 0)
{
//Log.Message("A null");

return false;
}

if (buildingExtensionA != null && buildingExtensionB != null &&
buildingExtensionA.wipeCategories?.Count > 0 &&
buildingExtensionB.wipeCategories?.Count > 0)
{
var hashes = new HashSet<string>();
foreach (var str in buildingExtensionA.wipeCategories)
hashes.Add(str);
foreach (var strB in buildingExtensionB.wipeCategories)
{
if (!hashes.Contains(strB)) continue;
//Log.Message("ShouldWipe");
return true;
}
}
return true;
}
var locThings = loc.GetThingList(map);
for (var index = 0; index < locThings.Count; index++)
{
var thing = locThings[index];
if (thing.def is ThingDef thingDef && ShouldWipe(newEntDef, GenConstruct.BuiltDefOf(thingDef), IntVec3.Invalid, null))
return true;
}

return true;
}

public static void MinPointsTest(PawnGroupKindWorker_Normal __instance, PawnGroupMaker groupMaker)
Expand Down
1 change: 1 addition & 0 deletions Source/AllModdingComponents/JecsTools/JecsTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ApparelExtension.cs" />
<Compile Include="BuildingExtension.cs" />
<Compile Include="CaravanJobs\CaravanJob.cs" />
<Compile Include="CaravanJobs\CaravanJobDef.cs" />
<Compile Include="CaravanJobs\CaravanJobDriver.cs" />
Expand Down
12 changes: 6 additions & 6 deletions updateinfo
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

JecsTools Update
====================
Version: 1.1.0.3
Updated: 09-17-2018
Description: Neglected to include latest compiled fix.
Version: 1.1.0.5
Updated: 09-22-2018
Description: Added a max range check to make GetInRangeToil fire for pawns who target enemies outside of max range.
====================

Download now on...
Expand All @@ -25,9 +25,9 @@ Discuss the mod on...
[img width=260]https://raw.githubusercontent.com/jecrell/JecsTools/master/About/Preview.png[/img]
[hr]
[b]JecsTools
Version: 1.1.0.3
Updated: 09-17-2018
Description: [color=orange]Neglected to include latest compiled fix. [/color]
Version: 1.1.0.5
Updated: 09-22-2018
Description: [color=orange]Added a max range check to make GetInRangeToil fire for pawns who target enemies outside of max range.[/color]
[hr]
[b]Download now on...[/b]
[url=https://www.patreon.com/posts/jecstools-for-0-21059900]Patreon[/url]
Expand Down

0 comments on commit becd995

Please sign in to comment.