Skip to content

Commit

Permalink
ModManager. detour fully works
Browse files Browse the repository at this point in the history
  • Loading branch information
XeoNovaDan committed Sep 28, 2018
1 parent 9b90946 commit 7d7be9c
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<name>[XND] Visible Pants</name>
<author>XeoNovaDan</author>
<url>https://ludeon.com/forums/index.php?topic=29503.0</url>
<targetVersion>0.19.0</targetVersion>
<targetVersion>0.19.2009</targetVersion>
<description>A mod that allows you to see everybody's trousers - for that complete feel. Taken from Vindar's Medieval Times mod with permission.</description>
</ModMetaData>
6 changes: 6 additions & 0 deletions About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Manifest>
<identifier>VisiblePants</identifier>
<version>2.1</version>
<manifestUri>https://rawgit.com/XeoNovaDan/VisiblePants/master/About/Manifest.xml</manifestUri>
<downloadUri>https://github.com/XeoNovaDan/VisiblePants/releases</downloadUri>
</Manifest>
Binary file modified Assemblies/VisiblePants.dll
Binary file not shown.
Binary file modified Source/VisiblePants/.vs/VisiblePants/v15/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 11 additions & 4 deletions Source/VisiblePants/HarmonyPatches.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using UnityEngine;
using Verse;
Expand All @@ -20,16 +23,20 @@ static HarmonyPatches()
HarmonyInstance h = HarmonyInstance.Create("XeoNovaDan.VisiblePants");

h.Patch(AccessTools.Method(typeof(Pawn_ApparelTracker), "SortWornApparelIntoDrawOrder"),
new HarmonyMethod(patchType, nameof(Prefix_SortWornApparelIntoDrawOrder)));
new HarmonyMethod(patchType, nameof(Detour_SortWornApparelIntoDrawOrder)));
}

public static bool Prefix_SortWornApparelIntoDrawOrder(Pawn_ApparelTracker __instance, ref ThingOwner<Apparel> ___wornApparel)
public static bool Detour_SortWornApparelIntoDrawOrder(Pawn_ApparelTracker __instance, ref ThingOwner<Apparel> ___wornApparel)
{
___wornApparel.InnerListForReading.Sort((Apparel a, Apparel b) => (a.IsPants() ? 99 : a.def.apparel.LastLayer.drawOrder).CompareTo(b.def.apparel.LastLayer.drawOrder));
___wornApparel.InnerListForReading.Sort((Apparel a, Apparel b) => AdjustedDrawOrder(a.def).CompareTo(AdjustedDrawOrder(b.def)));
return false;
}

private static bool IsPants(this Apparel a) => a.def == VP_ThingDefOf.Apparel_Pants || a.def == VP_ThingDefOf.Apparel_FlakPants;
private static int AdjustedDrawOrder(ThingDef apparel) =>
apparel.apparel.LastLayer.drawOrder + ((apparel.IsPants()) ? 99 : 0);

private static bool IsPants(this ThingDef apparel) =>
apparel == VP_ThingDefOf.Apparel_Pants || apparel == VP_ThingDefOf.Apparel_FlakPants;

}
}
2 changes: 1 addition & 1 deletion Source/VisiblePants/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file not shown.
Binary file modified Source/VisiblePants/obj/Debug/VisiblePants.dll
Binary file not shown.

0 comments on commit 7d7be9c

Please sign in to comment.