Skip to content

Commit

Permalink
Dependency update
Browse files Browse the repository at this point in the history
  • Loading branch information
XeoNovaDan committed Mar 2, 2020
1 parent 8902905 commit 5f511eb
Show file tree
Hide file tree
Showing 27 changed files with 168 additions and 89 deletions.
Binary file modified 1.1/Assemblies/TurretExtensions.dll
Binary file not shown.
12 changes: 6 additions & 6 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
<li>1.0</li>
<li>1.1</li>
</supportedVersions>
<description>Current Version: v1.3.0 (29th February 2020)\n\nA resource which allows modders to create turret mods with more flair, as well as various bugfixes and quality-of-life improvements.</description>
<description>Current Version: v1.3.1 (2nd March 2020)\n\nA resource which allows modders to create turret mods with more flair, as well as various bugfixes and quality-of-life improvements.</description>
<modDependencies>
<li>
<packageId>UnlimitedHugs.HugsLib</packageId>
<displayName>HugsLib</displayName>
<downloadUrl>https://github.com/UnlimitedHugs/RimworldHugsLib/releases/latest</downloadUrl>
<steamWorkshopUrl>https://steamcommunity.com/sharedfiles/filedetails/?id=818773962</steamWorkshopUrl>
<packageId>brrainz.harmony</packageId>
<displayName>Harmony</displayName>
<downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl>
<steamWorkshopUrl>https://steamcommunity.com/workshop/filedetails/?id=2009463077</steamWorkshopUrl>
</li>
</modDependencies>
<loadAfter>
<li>Ludeon.RimWorld</li>
<li>Ludeon.RimWorld.Royalty</li>
<li>UnlimitedHugs.HugsLib</li>
<li>brrainz.harmony</li>
</loadAfter>
</ModMetaData>
Binary file modified Source/TurretExtensions/.vs/TurretExtensions/v16/.suo
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,7 @@ private void RefundResources(float yield)
t.stackCount = c;
else
t.Destroy();
});
//List<ThingDefCountClass> ingredientCount = UpgradableComp.finalCostList;
//foreach (ThingDefCountClass thing in ingredientCount)
//{
// int yieldCount = GenMath.RoundRandom(thing.count * yield);
// Thing yieldItem = ThingMaker.MakeThing(thing.thingDef);
// yieldItem.stackCount = yieldCount;
// if (yieldCount > 0) { GenPlace.TryPlaceThing(yieldItem, TargetThingA.Position, TargetThingA.Map, ThingPlaceMode.Near); }
//}
}
}); }

private CompUpgradable UpgradableComp
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ public override Danger MaxPathDanger(Pawn pawn)

public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn)
{
foreach (Designation des in pawn.Map.designationManager.SpawnedDesignationsOfDef(DesignationDefOf.UpgradeTurret))
var upgradeDesignations = pawn.Map.designationManager.SpawnedDesignationsOfDef(DesignationDefOf.UpgradeTurret).ToList();
for (int i = 0; i < upgradeDesignations.Count; i++)
{
var des = upgradeDesignations[i];
yield return des.target.Thing;
}
}

public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
Expand Down
18 changes: 12 additions & 6 deletions Source/TurretExtensions/TurretExtensions/Comps/CompUpgradable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ private void ResolveCostList()
{
if (parent.def.MadeFromStuff && Props.costStuffCount > 0)
finalCostList.Add(new ThingDefCountClass(parent.Stuff, Props.costStuffCount));
if (Props.costList != null)
var costList = Props.costList;
if (costList != null)
{
foreach (ThingDefCountClass thing in Props.costList)
for (int i = 0; i < costList.Count; i++)
{
var thing = costList[i];
var duplicate = finalCostList.FirstOrDefault(t => t.thingDef == thing.thingDef);
if (duplicate != null)
duplicate.count += thing.count;
Expand Down Expand Up @@ -77,8 +79,9 @@ public override void PostDestroy(DestroyMode mode, Map previousMap)
{
float resourceDropFraction = (mode == DestroyMode.KillFinalize) ? Props.destroyedResourceDropPct : Props.baseResourceDropPct;

foreach (Thing thing in innerContainer)
for (int i = 0; i < innerContainer.Count; i++)
{
var thing = innerContainer[i];
thing.stackCount = GenMath.RoundRandom(thing.stackCount * resourceDropFraction);
if (thing.stackCount == 0)
thing.Destroy();
Expand All @@ -102,8 +105,9 @@ public override string CompInspectStringExtra()
if (!finalCostList.NullOrEmpty())
{
inspectBuilder.AppendLine($"{"ContainedResources".Translate()}:");
foreach (var cost in finalCostList)
for (int i = 0; i < finalCostList.Count; i++)
{
var cost = finalCostList[i];
var costDef = cost.thingDef;
inspectBuilder.AppendLine($"{costDef.LabelCap}: {innerContainer.TotalStackCountOfDef(costDef)} / {cost.count}");
}
Expand All @@ -122,8 +126,9 @@ public bool SufficientMatsToUpgrade
{
get
{
foreach (var cost in finalCostList)
for (int i = 0; i < finalCostList.Count; i++)
{
var cost = finalCostList[i];
int thingCount = innerContainer.TotalStackCountOfDef(cost.thingDef);
if (thingCount < cost.count)
return false;
Expand Down Expand Up @@ -186,8 +191,9 @@ public List<ThingDefCountClass> MaterialsNeeded()
cachedMaterialsNeeded.Clear();

// Determine needed materials
foreach (var cost in finalCostList)
for (int i = 0; i < finalCostList.Count; i++)
{
var cost = finalCostList[i];
int resourceCount = innerContainer.TotalStackCountOfDef(cost.thingDef);
int amountNeeded = cost.count - resourceCount;
if (amountNeeded > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ public override AcceptanceReport CanDesignateThing(Thing t) =>

public override void DesignateSingleCell(IntVec3 c)
{
foreach (Thing t in UpgradableTurretsInSelection(c))
var upgradableTurrets = UpgradableTurretsInSelection(c).ToList();
for (int i = 0; i < upgradableTurrets.Count; i++)
{
var turret = upgradableTurrets[i];
if (DebugSettings.godMode)
t.TryGetComp<CompUpgradable>().upgraded = true;
turret.TryGetComp<CompUpgradable>().upgraded = true;
else
DesignateThing(t);;
DesignateThing(turret);;
}
}

Expand All @@ -62,9 +64,16 @@ public override void DesignateThing(Thing t)
CompUpgradable upgradableComp = t.TryGetComp<CompUpgradable>();
upgradableComp.Upgrade();
if (upgradableComp.finalCostList != null)
foreach (ThingDefCountClass thing in upgradableComp.finalCostList)
for (int i = 0; i < thing.count; i++)
{
for (int i = 0; i < upgradableComp.finalCostList.Count; i++)
{
var thing = upgradableComp.finalCostList[i];
var initThingCount = upgradableComp.innerContainer.TotalStackCountOfDef(thing.thingDef);
for (int j = initThingCount; j < thing.count; j++)
upgradableComp.innerContainer.TryAdd(ThingMaker.MakeThing(thing.thingDef));

}
}
}

else
Expand All @@ -77,11 +86,14 @@ public override void DesignateThing(Thing t)
protected override void FinalizeDesignationSucceeded()
{
if (!DebugSettings.godMode)
foreach (Building_Turret turret in designatedTurrets)
{
for (int i = 0; i < designatedTurrets.Count; i++)
{
var turret = designatedTurrets[i];
NotifyPlayerOfInsufficientSkill(turret);
NotifyPlayerOfInsufficientResearch(turret);
}
}
designatedTurrets.Clear();
}

Expand All @@ -91,8 +103,10 @@ private void NotifyPlayerOfInsufficientSkill(Thing t)
{
bool meetsMinSkill = false;
int minimumSkill = t.TryGetComp<CompUpgradable>().Props.constructionSkillPrerequisite;
foreach (Pawn pawn in Find.CurrentMap.mapPawns.FreeColonists)
var freeColonists = Find.CurrentMap.mapPawns.FreeColonists;
for (int i = 0; i < freeColonists.Count; i++)
{
var pawn = freeColonists[i];
if (pawn.skills.GetSkill(SkillDefOf.Construction).Level >= minimumSkill)
{
meetsMinSkill = true;
Expand All @@ -112,8 +126,9 @@ private void NotifyPlayerOfInsufficientResearch(Thing t)
List<string> researchProjectsUnfinished = new List<string>();
if (researchRequirements != null)
{
foreach (ResearchProjectDef research in researchRequirements)
for (int i = 0; i < researchRequirements.Count; i++)
{
var research = researchRequirements[i];
if (!research.IsFinished)
{
researchRequirementsMet = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public static class HarmonyPatches

static HarmonyPatches()
{
//Harmony.DEBUG = true;
#if DEBUG
Harmony.DEBUG = true;
#endif

TurretExtensions.harmonyInstance.PatchAll();

// Gizmo_RefuelableFuelStatus delegate
Expand All @@ -33,6 +36,10 @@ static HarmonyPatches()
Patch_ThingDef.manual_SpecialDisplayStats.enumeratorType = thingDefEnumeratorType;
TurretExtensions.harmonyInstance.Patch(thingDefEnumeratorType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).First(m => m.Name == "MoveNext"),
transpiler: new HarmonyMethod(typeof(Patch_ThingDef.manual_SpecialDisplayStats), "Transpiler"));

// Fully refuel devmode gizmo
TurretExtensions.harmonyInstance.Patch(typeof(CompRefuelable).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Last(m => m.Name.Contains("CompGetGizmosExtra")),
transpiler: new HarmonyMethod(typeof(Patch_CompRefuelable), nameof(Patch_CompRefuelable.FuelCapacityTranspiler)));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public static class PreApplyDamage

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
#if DEBUG
Log.Message("Transpiler start: Building_Turret.PreApplyDamage (1 match)");
#endif

var instructionList = instructions.ToList();

for (int i = 0; i < instructionList.Count; i++)
Expand All @@ -49,8 +53,12 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
if (instruction.opcode == OpCodes.Ldc_I4_1)
{
var nextInstruction = instructionList[i + 1];
if (nextInstruction.opcode == OpCodes.Callvirt && nextInstruction.operand == notifyDamageAppliedInfo)
if (nextInstruction.opcode == OpCodes.Callvirt && nextInstruction.OperandIs(notifyDamageAppliedInfo))
{
#if DEBUG
Log.Message("Building_Turret.PreApplyDamage match 1 of 1");
#endif

yield return new CodeInstruction(OpCodes.Ldarg_0); // this
yield return instruction.Clone(); // true
instruction = new CodeInstruction(OpCodes.Call, affectedByEMPInfo); // AffectedByEMP(this, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public static class DrawExtraSelectionOverlays

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator ilGen)
{
#if DEBUG
Log.Message("Transpiler start: Building_TurretGun.DrawExtraSelectionOverlays (1 match)");
#endif

var instructionList = instructions.ToList();

var drawRadiusRingInfo = AccessTools.Method(typeof(GenDraw), nameof(GenDraw.DrawRadiusRing), new Type[] { typeof(IntVec3), typeof(float) });
Expand All @@ -48,8 +52,12 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
break;

// Look for a call to drawRadiusRing
if (HarmonyPatchesUtility.CallingInstruction(xInstructionAhead) && (MethodInfo)xInstructionAhead.operand == drawRadiusRingInfo)
if (HarmonyPatchesUtility.CallingInstruction(xInstructionAhead) && xInstructionAhead.OperandIs(drawRadiusRingInfo))
{
#if DEBUG
Log.Message("Building_TurretGun.DrawExtraSelectionOverlays match 1 of 1");
#endif

yield return instruction; // num < x or num > x
yield return new CodeInstruction(OpCodes.Ldarg_0); // this
yield return instructionList[i - 2].Clone(); // num
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public static class Patch_CompRefuelable
// As of 25th July 2019, still haven't been able to top this one in terms of copypasta potential
public static IEnumerable<CodeInstruction> FuelCapacityTranspiler(IEnumerable<CodeInstruction> instructions)
{
#if DEBUG
Log.Message("Transpiler start: CompRefuelable.FuelCapacityTranspiler (1 match)");
#endif

var instructionList = instructions.ToList();

var adjustedFuelCapacity = AccessTools.Method(typeof(TurretExtensionsUtility), nameof(TurretExtensionsUtility.AdjustedFuelCapacity));
Expand All @@ -32,10 +36,15 @@ public static IEnumerable<CodeInstruction> FuelCapacityTranspiler(IEnumerable<Co

if (instruction.IsFuelCapacityInstruction())
{
#if DEBUG
Log.Message("Patch_CompRefuelable.FuelCapacityTranspiler match 1 of 1");
#endif


yield return instruction;
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(CompRefuelable), nameof(CompRefuelable.parent)));
instruction = new CodeInstruction(OpCodes.Call, adjustedFuelCapacity);
yield return new CodeInstruction(OpCodes.Ldarg_0); // this
yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(CompRefuelable), nameof(CompRefuelable.parent))); // this.parent
instruction = new CodeInstruction(OpCodes.Call, adjustedFuelCapacity); // TurretExtensionsUtility.AdjustedFuelCapacity(this.parent)
}

yield return instruction;
Expand Down Expand Up @@ -95,40 +104,9 @@ public static class GetFuelCountToFullyRefuel

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var instructionList = instructions.ToList();

var adjustedFuelCapacity = AccessTools.Method(typeof(TurretExtensionsUtility), nameof(TurretExtensionsUtility.AdjustedFuelCapacity));
var adjustedFuelCount = AccessTools.Method(typeof(GetFuelCountToFullyRefuel), nameof(AdjustedFuelCount));

for (int i = 0; i < instructionList.Count; i++)
{
CodeInstruction instruction = instructionList[i];

if (instruction.IsFuelCapacityInstruction())
{
yield return instruction;
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(CompRefuelable), nameof(CompRefuelable.parent)));
instruction = new CodeInstruction(OpCodes.Call, adjustedFuelCapacity);
}

if (instruction.opcode == OpCodes.Stloc_0)
{
yield return instruction;
yield return new CodeInstruction(OpCodes.Ldloc_0);
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(CompRefuelable), nameof(CompRefuelable.parent)));
yield return new CodeInstruction(OpCodes.Call, adjustedFuelCount);
instruction = new CodeInstruction(OpCodes.Stloc_0);
}

yield return instruction;
}
return FuelCapacityTranspiler(instructions);
}

private static float AdjustedFuelCount(float currentFuelCount, Thing thing) =>
currentFuelCount / (thing.IsUpgraded(out CompUpgradable uC) ? uC.Props.fuelMultiplierFactor : 1f);

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public static class manual_GizmoOnGUI_Delegate

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase method, ILGenerator ilGen)
{
#if DEBUG
Log.Message("Transpiler start: Gizmo_RefuelableFuelStatus.manual_GizmoOnGUI_Delegate (1 match)");
#endif

var instructionList = instructions.ToList();

// Add local
Expand All @@ -40,8 +44,12 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
var instruction = instructionList[i];

// Adjust all calls to fuel capacity to factor in upgraded status
if (instruction.operand == fuelCapacityInfo)
if (instruction.OperandIs(fuelCapacityInfo))
{
#if DEBUG
Log.Message("Gizmo_RefuelableFuelStatus.manual_GizmoOnGUI_Delegate match 1 of 1");
#endif

bool addr = false;
if (instruction.opcode == OpCodes.Ldflda)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public static class FindAmmoForTurret

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
#if DEBUG
Log.Message("Transpiler start: JobDriver_ManTurret.FindAmmoForTurret (1 match)");
#endif


var instructionList = instructions.ToList();

var pawnInfo = typeof(JobDriver_ManTurret).GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Instance).
Expand All @@ -39,6 +44,10 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
// Update the validator
if (instruction == originalValidatorStore)
{
#if DEBUG
Log.Message("JobDriver_ManTurret.FindAmmoForTurret match 1 of 1");
#endif

yield return instruction;
yield return new CodeInstruction(OpCodes.Ldloc_1); // validator
yield return new CodeInstruction(OpCodes.Ldloc_0);
Expand Down
Loading

0 comments on commit 5f511eb

Please sign in to comment.