forked from Skullywag/ExtendedStorage
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
137 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ModMetaData> | ||
<name>Extended Storage</name> | ||
<author>Skullywag, Fluffy, spdskatr, DoctorVanGogh</author> | ||
<targetVersion>1.0.1950</targetVersion> | ||
<description>Adds additional storage buildings that multi stack items. Auto sort by Fluffy, Harmony by spdskatr</description> | ||
<name>Extended Storage</name> | ||
<targetVersion>0.19.2009</targetVersion> | ||
<author>(see description)</author> | ||
<description xml:whitespace="preserve">Adds additional storage buildings that multi stack items. Auto sort by Fluffy, Harmony by spdskatr | ||
|
||
Authors: Skullywag, Fluffy, spdskatr, DoctorVanGogh | ||
</description> | ||
</ModMetaData> |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using Harmony; | ||
using Verse; | ||
|
||
namespace ExtendedStorage.Patches | ||
{ | ||
|
||
/// <summary> | ||
/// infrastructure to suppress item splurge during load | ||
/// </summary> | ||
[HarmonyPatch(typeof(GenSpawn), "Spawn", new Type[] {typeof(Thing), typeof(IntVec3), typeof(Map), typeof(Rot4), typeof(WipeMode), typeof(bool)})] | ||
public static class GenSpawn_Spawn | ||
{ | ||
public static FieldInfo LoadedFullThingsField = typeof(Map).GetField("loadedFullThings", BindingFlags.NonPublic | BindingFlags.Static); | ||
|
||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il) | ||
{ | ||
bool ldargsSeen = false; | ||
Label l = il.DefineLabel(); | ||
List<CodeInstruction> instrList = instructions.ToList(); | ||
for (int i = 0; i < instrList.Count; i++) | ||
{ | ||
if (!ldargsSeen && instrList[i].opcode == OpCodes.Ldarg_S && instrList[i].operand.Equals((byte) 4)) | ||
{ | ||
Label jmpLabel = instrList[i].labels[0]; | ||
instrList[i].labels.Clear(); | ||
CodeInstruction ins = new CodeInstruction(OpCodes.Ldarg_1) | ||
{ | ||
labels = new List<Label>() {jmpLabel} | ||
}; | ||
yield return ins; | ||
yield return new CodeInstruction(OpCodes.Ldarg_2); | ||
yield return new CodeInstruction(OpCodes.Ldarg_S, (byte) 5); | ||
yield return new CodeInstruction(OpCodes.Call, typeof(GenSpawn_Spawn).GetMethod("ShouldDisplaceOtherItems")); | ||
yield return new CodeInstruction(OpCodes.Brfalse, l); | ||
ldargsSeen = true; | ||
} | ||
|
||
if (i + 2 < instrList.Count && instrList[i + 2].opcode == OpCodes.Callvirt && instrList[i + 2].operand == typeof(Thing).GetProperty("Rotation").GetSetMethod()) | ||
{ | ||
instrList[i].labels.Add(l); | ||
} | ||
|
||
yield return instrList[i]; | ||
} | ||
} | ||
|
||
public static bool ShouldDisplaceOtherItems(IntVec3 cell, Map map, bool respawningAfterLoad) | ||
{ | ||
return !respawningAfterLoad || map?.thingGrid.ThingsListAtFast(cell).OfType<Building_ExtendedStorage>().Any() != true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using System.Text; | ||
using Harmony; | ||
using Verse; | ||
|
||
namespace ExtendedStorage.Patches { | ||
/// <summary> | ||
/// prioritize ES building spawn so genspawn.spawn splurge suppression patch can return a valid discriminator | ||
/// </summary> | ||
/// <seealso cref="GenSpawn_Spawn.ShouldDisplaceOtherItems"/> | ||
[HarmonyPatch(typeof(Map), nameof(Map.FinalizeLoading))] | ||
class Map_FinalizeLoading | ||
{ | ||
private static MethodInfo mi = typeof(BackCompatibility).GetMethod(nameof(BackCompatibility.PreCheckSpawnBackCompatibleThingAfterLoading)); | ||
|
||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instr) { | ||
List<CodeInstruction> instructions = new List<CodeInstruction>(instr); | ||
|
||
var idxAnchor = instructions.FindIndex(ci => ci.opcode == OpCodes.Call && ci.operand == mi); | ||
if (idxAnchor == -1) { | ||
Log.Warning("Could not find Map_FinalizeLoading transpiler anchor - not patching."); | ||
return instructions; | ||
} | ||
|
||
instructions.InsertRange(idxAnchor +1, | ||
new [] | ||
{ | ||
new CodeInstruction(OpCodes.Ldloc_1), | ||
new CodeInstruction(OpCodes.Ldarg_0), | ||
new CodeInstruction(OpCodes.Call, typeof(Map_FinalizeLoading).GetMethod(nameof(PrioritySpawnStorageBuildings))) | ||
}); | ||
|
||
return instructions; | ||
|
||
} | ||
|
||
public static void PrioritySpawnStorageBuildings(List<Thing> things, Map map) | ||
{ | ||
var candidates = things.OfType<Building_ExtendedStorage>().ToArray(); | ||
|
||
foreach (Building_ExtendedStorage current in candidates) | ||
{ | ||
try | ||
{ | ||
GenSpawn.SpawnBuildingAsPossible(current, map, true); | ||
} | ||
catch (Exception ex2) | ||
{ | ||
Log.Error(string.Concat(new object[] | ||
{ | ||
"Exception spawning loaded thing ", | ||
current.ToStringSafe<Building>(), | ||
": ", | ||
ex2 | ||
}), false); | ||
} | ||
|
||
things.Remove(current); | ||
} | ||
} | ||
} | ||
} |