Skip to content

Commit

Permalink
1.4 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehni committed Oct 21, 2022
1 parent 38510a4 commit 1972f60
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 112 deletions.
Binary file added 1.4/Assemblies/IHoldMultipleThings.dll
Binary file not shown.
Binary file added 1.4/Assemblies/PickUpAndHaul.dll
Binary file not shown.
9 changes: 9 additions & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<li>1.1</li>
<li>1.2</li>
<li>1.3</li>
<li>1.4</li>
</supportedVersions>
<packageId>Mehni.PickUpAndHaul</packageId>
<modDependenciesByVersion>
Expand Down Expand Up @@ -34,6 +35,14 @@
<downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl>
</li>
</v1.3>
<v1.4>
<li>
<packageId>brrainz.harmony</packageId>
<displayName>Harmony</displayName>
<steamWorkshopUrl>steam://url/CommunityFilePage/2009463077</steamWorkshopUrl>
<downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl>
</li>
</v1.4>
</modDependenciesByVersion>
<loadAfter>
<li>brrainz.harmony</li>
Expand Down
72 changes: 18 additions & 54 deletions Source/IHoldMultipleThings/IHoldMultipleThings.csproj
Original file line number Diff line number Diff line change
@@ -1,56 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E1536A54-D289-41FA-9D0B-8A2F6812C7FA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IHoldMultipleThings</RootNamespace>
<AssemblyName>IHoldMultipleThings</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\1.2\Assemblies\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\1.3\Assemblies\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IHoldMultipleThings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>IHoldMultipleThings</RootNamespace>
<AssemblyName>IHoldMultipleThings</AssemblyName>
<TargetFramework>net48</TargetFramework>
<LangVersion>10.0</LangVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
<Optimize>true</Optimize>
<DebugType>none</DebugType>
<ErrorReport>prompt</ErrorReport>
<OutputPath>..\..\1.4\Assemblies\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<PublicizeAsReferenceAssemblies>false</PublicizeAsReferenceAssemblies>
<WarningLevel>5</WarningLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.4.3522-beta" />
</ItemGroup>
</Project>
36 changes: 0 additions & 36 deletions Source/IHoldMultipleThings/Properties/AssemblyInfo.cs

This file was deleted.

15 changes: 10 additions & 5 deletions Source/PickUpAndHaul/CompatHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ internal class CompatHelper
{
public static bool CeOverweight(Pawn pawn)
{
var ceCompInventory = pawn.GetComp<CombatExtended.CompInventory>();
return (ceCompInventory.currentWeight / ceCompInventory.capacityWeight) >= Settings.MaximumOccupiedCapacityToConsiderHauling;
return false;
//var ceCompInventory = pawn.GetComp<CombatExtended.CompInventory>();
//return (ceCompInventory.currentWeight / ceCompInventory.capacityWeight) >= Settings.MaximumOccupiedCapacityToConsiderHauling;
}

public static int CanFitInInventory(Pawn pawn, Thing thing)
{
pawn.GetComp<CombatExtended.CompInventory>().CanFitInInventory(thing, out var countToPickUp);
return countToPickUp;
return thing.stackCount;
//pawn.GetComp<CombatExtended.CompInventory>().CanFitInInventory(thing, out var countToPickUp);
//return countToPickUp;
}

internal static void UpdateInventory(Pawn pawn) => pawn.GetComp<CombatExtended.CompInventory>().UpdateInventory();
internal static void UpdateInventory(Pawn pawn)
{
//pawn.GetComp<CombatExtended.CompInventory>().UpdateInventory();
}
}
8 changes: 8 additions & 0 deletions Source/PickUpAndHaul/FishTranspiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public int GetIndex() => Operand is LocalBuilder builder ? builder.LocalIndex
public static IEnumerable<Container> FindLoadLocals(MethodBase method, Predicate<LocalVariableInfo> predicate)
{
foreach (var index in GetLocalIndices(method, predicate))
{
yield return new() { OpCode = GetLoadLocalOpCode(index), Operand = GetOperandFromIndex(index) };
}
}
public static Container FindLoadLocal(IEnumerable<CodeInstruction> codes, Type localType) => LoadLocal(GetLocalOperandsOrIndices(codes, c => c.Returns(localType)).First());
public static Container LoadLocal(object operand) => operand is LocalBuilder builder ? LoadLocal(builder) : LoadLocal((int)operand);
Expand All @@ -70,7 +72,9 @@ public static IEnumerable<Container> FindLoadLocals(MethodBase method, Predicate
public static IEnumerable<Container> FindStoreLocals(MethodBase method, Predicate<LocalVariableInfo> predicate)
{
foreach (var index in GetLocalIndices(method, predicate))
{
yield return new() { OpCode = GetStoreLocalOpCode(index), Operand = GetOperandFromIndex(index) };
}
}
public static Container FindStoreLocal(IEnumerable<CodeInstruction> codes, Type localType) => StoreLocal(GetLocalOperandsOrIndices(codes, c => c.Returns(localType)).First());
public static Container StoreLocal(object operand) => operand is LocalBuilder builder ? StoreLocal(builder) : StoreLocal((int)operand);
Expand Down Expand Up @@ -167,15 +171,19 @@ public static IEnumerable<object> GetLocalOperandsOrIndices(IEnumerable<CodeInst
public static IEnumerable<int> GetLocalIndices(IEnumerable<CodeInstruction> codes, Predicate<CodeInstruction> predicate)
{
foreach (var operand in GetLocalOperandsOrIndices(codes, predicate))
{
yield return operand is LocalBuilder builder ? builder.LocalIndex : (int)operand;
}
}
public static IEnumerable<int> GetLocalIndices(MethodBase method, Predicate<LocalVariableInfo> predicate)
{
var variables = method.GetMethodBody().LocalVariables;
for (var i = 0; i < variables.Count; i++)
{
if (predicate(variables[i]))
{
yield return variables[i].LocalIndex;
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion Source/PickUpAndHaul/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static HarmonyPatches()

if (!ModCompatibilityCheck.CombatExtendedIsActive)
{
harmony.Patch(original: AccessTools.Method(typeof(PawnUtility), nameof(PawnUtility.GetMaxAllowedToPickUp)),
harmony.Patch(original: AccessTools.Method(typeof(PawnUtility), nameof(PawnUtility.GetMaxAllowedToPickUp), new[] { typeof(Pawn), typeof(ThingDef) }),
prefix: new HarmonyMethod(typeof(HarmonyPatches), nameof(MaxAllowedToPickUpPrefix)));

harmony.Patch(original: AccessTools.Method(typeof(PawnUtility), nameof(PawnUtility.CanPickUp)),
Expand Down Expand Up @@ -52,7 +52,9 @@ private static bool Drop_Prefix(Pawn pawn, Thing thing)
{
var takenToInventory = pawn.GetComp<CompHauledToInventory>();
if (takenToInventory == null)
{
return true;
}

var carriedThing = takenToInventory.GetHashSet();
return !carriedThing.Contains(thing);
Expand All @@ -62,19 +64,25 @@ private static void Pawn_InventoryTracker_PostFix(Pawn_InventoryTracker __instan
{
var takenToInventory = __instance.pawn?.GetComp<CompHauledToInventory>();
if (takenToInventory == null)
{
return;
}

var carriedThing = takenToInventory.GetHashSet();
if (carriedThing?.Count > 0)
{
carriedThing.Remove(item);
}
}

private static void JobDriver_HaulToCell_PostFix(JobDriver_HaulToCell __instance)
{
var pawn = __instance.pawn;
var takenToInventory = pawn?.GetComp<CompHauledToInventory>();
if (takenToInventory == null)
{
return;
}

var carriedThing = takenToInventory.GetHashSet();

Expand Down Expand Up @@ -108,7 +116,9 @@ public static bool CanBeMadeToDropStuff(Pawn pawn, ref bool __result)
public static bool SkipCorpses_Prefix(WorkGiver_Haul __instance, ref bool __result, Pawn pawn)
{
if (__instance is not WorkGiver_HaulCorpses)
{
return true;
}

if (Settings.AllowCorpses //Don't use the vanilla HaulCorpses WorkGiver if PUAH is allowed to haul those
|| pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Corpse).Count < 1) //...or if there are no corpses to begin with. Indeed Tynan did not foresee this situation
Expand Down Expand Up @@ -155,7 +165,9 @@ public static IEnumerable<CodeInstruction> GearTabHighlightTranspiler(IEnumerabl
}

if (!done)
{
Verse.Log.Warning("Pick Up And Haul failed to patch ITab_Pawn_Gear.DrawThingRow. This is only used for coloring and totally harmless, but you might wanna know anyway");
}
}

private static Color GetColorForHauled(Pawn pawn, Thing thing)
Expand Down
4 changes: 4 additions & 0 deletions Source/PickUpAndHaul/IHoldMultipleThings_Support.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public static bool CapacityAt(Thing thing, IntVec3 storeCell, Map map, out int c
foreach (var t in storeCell.GetThingList(map))
{
if (t is IHoldMultipleThings.IHoldMultipleThings holderOfMultipleThings)
{
return holderOfMultipleThings.CapacityAt(thing, storeCell, map, out capacity);
}
}

return false;
Expand All @@ -36,7 +38,9 @@ public static bool StackableAt(Thing thing, IntVec3 storeCell, Map map)
foreach (var t in storeCell.GetThingList(map))
{
if (t is IHoldMultipleThings.IHoldMultipleThings holderOfMultipleThings)
{
return holderOfMultipleThings.StackableAt(thing, storeCell, map);
}
}

return false;
Expand Down
6 changes: 6 additions & 0 deletions Source/PickUpAndHaul/JobDriver_HaulToInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public override IEnumerable<Toil> MakeNewToils()
Log.Message($"{actor} is hauling to inventory {thing}:{countToPickUp}");

if (ModCompatibilityCheck.CombatExtendedIsActive)
{
countToPickUp = CompatHelper.CanFitInInventory(pawn, thing);
}

if (countToPickUp > 0)
{
Expand All @@ -54,7 +56,9 @@ public override IEnumerable<Toil> MakeNewToils()
takenToInventory.RegisterHauledItem(splitThing);

if (ModCompatibilityCheck.CombatExtendedIsActive)
{
CompatHelper.UpdateInventory(pawn);
}
}

//thing still remains, so queue up hauling if we can + end the current job (smooth/instant transition)
Expand Down Expand Up @@ -136,7 +140,9 @@ public Toil CheckForOverencumberedForCombatExtended()
var toil = new Toil();

if (!ModCompatibilityCheck.CombatExtendedIsActive)
{
return toil;
}

toil.initAction = () =>
{
Expand Down
8 changes: 7 additions & 1 deletion Source/PickUpAndHaul/JobDriver_UnloadYourHauledInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public override IEnumerable<Toil> MakeNewToils()
var carriedThing = takenToInventory.GetHashSet();

if (ModCompatibilityCheck.ExtendedStorageIsActive)
{
_unloadDuration = 20;
}

var wait = Toils_General.Wait(_unloadDuration);
var celebrate = Toils_General.Wait(_unloadDuration);
Expand Down Expand Up @@ -87,7 +89,9 @@ public override IEnumerable<Toil> MakeNewToils()
}

if (ModCompatibilityCheck.CombatExtendedIsActive)
CompatHelper.UpdateInventory(pawn);
{
CompatHelper.UpdateInventory(pawn);
}

thing.SetForbidden(false, false);
}
Expand Down Expand Up @@ -146,7 +150,9 @@ private static ThingCount FirstUnloadableThing(Pawn pawn)
{
var dirtyStraggler = innerPawnContainer[i];
if (dirtyStraggler.def == stragglerDef)
{
return new ThingCount(dirtyStraggler, dirtyStraggler.stackCount);
}
}
}
return new ThingCount(thing, thing.stackCount);
Expand Down
2 changes: 2 additions & 0 deletions Source/PickUpAndHaul/PawnUnloadChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public static void CheckIfPawnShouldUnloadInventory(Pawn pawn, bool forced = fal
var itemsTakenToInventory = pawn?.GetComp<CompHauledToInventory>();

if (itemsTakenToInventory == null)
{
return;
}

var carriedThing = itemsTakenToInventory.GetHashSet();

Expand Down
Loading

0 comments on commit 1972f60

Please sign in to comment.