Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
- Fix issue in RoofMaintenance
- Clean-up Transpilers
- Bump ModSync Version
  • Loading branch information
AaronCRobinson committed Sep 12, 2018
1 parent 7e3c57d commit 623de25
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 28 deletions.
12 changes: 5 additions & 7 deletions About/ModSync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
<ModSyncNinjaData>
<ID>da411a34-76ea-42c8-b350-b8ddc07dccc1</ID>
<ModName>Expanded Roofing</ModName>
<Version>0.19.0</Version>
<Version>0.19.1</Version>
<SaveBreaking>False</SaveBreaking>
<Host name="Github">
<Owner>AaronCRobinson</Owner>
<Project>ExpandedRoofing</Project>
<AboutDir>About</AboutDir>
<DownloadFrom>ModSyncMainPage</DownloadFrom>
<Branch>master</Branch>
<Host name="Direct">
<AboutUri>https://raw.githubusercontent.com/AaronCRobinson/ExpandedRoofing/master/About/About.xml</AboutUri>
<ModSyncUri>https://raw.githubusercontent.com/AaronCRobinson/ExpandedRoofing/master/About/ModSync.xml</ModSyncUri>
<DownloadUri>https://github.com/AaronCRobinson/ExpandedRoofing/releases/tag/v0.19.1</DownloadUri>
</Host>
</ModSyncNinjaData>
Binary file modified Assemblies/1SettingsHelper.dll
Binary file not shown.
Binary file modified Assemblies/ExpandedRoofing.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions Source/ExpandedRoofing/ExpandedRoofing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<HintPath>..\..\..\SettingsHelper\Assemblies\1SettingsHelper.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -52,7 +52,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
Expand Down
27 changes: 12 additions & 15 deletions Source/ExpandedRoofing/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ internal class HarmonyPatches
{
public static FieldInfo FI_RoofGrid_map = AccessTools.Field(typeof(RoofGrid), "map");

private static int SectionLayer_LightingOverlay__Regenerate__RoofDef__LocalIndex = AccessTools.Method(typeof(SectionLayer_LightingOverlay), nameof(SectionLayer_LightingOverlay.Regenerate)).GetMethodBody().LocalVariables.First(lvi => lvi.LocalType == typeof(RoofDef)).LocalIndex;

static HarmonyPatches()
{
#if DEBUG
Expand All @@ -98,7 +100,6 @@ static HarmonyPatches()

// fix lighting inside rooms with transparent roof
harmony.Patch(AccessTools.Method(typeof(SectionLayer_LightingOverlay), nameof(SectionLayer_LightingOverlay.Regenerate)), null, null, new HarmonyMethod(typeof(HarmonyPatches), nameof(TransparentRoofLightingOverlayFix)));
//harmony.Patch(AccessTools.Method(typeof(RoofGrid), nameof(RoofGrid.RoofAt), new Type[] { typeof(int) }), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(TransparentRoofLightingOverlayPostfix)));

// Fix infestation under buildable thick roofs
harmony.Patch(AccessTools.Method(typeof(InfestationCellFinder), "GetScoreAt"), null, null, new HarmonyMethod(typeof(HarmonyPatches), nameof(ThickRoofInfestationFix)));
Expand All @@ -107,7 +108,7 @@ static HarmonyPatches()
harmony.Patch(AccessTools.Method(typeof(ListerBuildingsRepairable), nameof(ListerBuildingsRepairable.Notify_BuildingRepaired)), null, new HarmonyMethod(typeof(HarmonyPatches), nameof(BuildingRepairedPostfix)));

// Set clearBuildingArea flag in BlocksConstruction to be respected before large plant check (trees mostly)
//harmony.Patch(AccessTools.Method(typeof(GenConstruct), nameof(GenConstruct.BlocksConstruction)), null, null, new HarmonyMethod(typeof(HarmonyPatches), nameof(FixClearBuildingArea)));
harmony.Patch(AccessTools.Method(typeof(GenConstruct), nameof(GenConstruct.BlocksConstruction)), null, null, new HarmonyMethod(typeof(HarmonyPatches), nameof(FixClearBuildingArea)));

harmony.Patch(AccessTools.Property(typeof(CompPowerPlantSolar), "RoofedPowerOutputFactor").GetGetMethod(true), null, null, new HarmonyMethod(typeof(HarmonyPatches), nameof(TransparentRoofOutputFactorFix)));

Expand Down Expand Up @@ -175,13 +176,12 @@ public static IEnumerable<CodeInstruction> TransparentRoofLightingOverlayFix(IEn
for (int i = 0; i < instructionList.Count; i++)
{
yield return instructionList[i];
if (instructionList[i].opcode == OpCodes.Callvirt && instructionList[i].operand == MI_RoofAt)
if (instructionList[i].opcode == OpCodes.Stloc_S && instructionList[i].operand is LocalBuilder lb && lb.LocalIndex == SectionLayer_LightingOverlay__Regenerate__RoofDef__LocalIndex)
{
// NOTE: consider finding a better way to locate this...
#if DEBUG
Log.Message("Patching TransparentRoof");
#endif
// make sure state by checking ops a few times
yield return instructionList[++i];
if (instructionList[i].opcode != OpCodes.Stloc_S) break;

yield return instructionList[++i];
if (instructionList[i].opcode != OpCodes.Ldloc_S) break;

Expand All @@ -202,13 +202,6 @@ public static IEnumerable<CodeInstruction> TransparentRoofLightingOverlayFix(IEn
}
}

// WARNING: this may have side-effects at some point...
/*public static void TransparentRoofLightingOverlayPostfix(ref RoofDef __result)
{
if (__result == RoofDefOf.RoofTransparent)
__result = null;
}*/

public static IEnumerable<CodeInstruction> ThickRoofInfestationFix(IEnumerable<CodeInstruction> instructions, ILGenerator il)
{
MethodInfo MI_IsBuildableThickroof = AccessTools.Method(typeof(TraspileHelper), nameof(TraspileHelper.IsBuildableThickRoof));
Expand Down Expand Up @@ -241,6 +234,7 @@ public static void BuildingRepairedPostfix(Building b)
comp.ticksSinceMaintain = 0;
}

// NOTE: this method is getting mighty ugly...
public static IEnumerable<CodeInstruction> FixClearBuildingArea(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> instructionList = instructions.ToList();
Expand All @@ -265,7 +259,10 @@ public static IEnumerable<CodeInstruction> FixClearBuildingArea(IEnumerable<Code
#endif
j = i;
while (instructionList[j++].opcode != OpCodes.Ble_Un) continue;
endIndex = j+4; // values and returns
j = j+4; // values and returns
// keep going...
while (instructionList[j++].opcode != OpCodes.Ldloc_0) continue;
endIndex = j-1; // values and returns
#if DEBUG
Log.Message($"endIndex: {endIndex}");
#endif
Expand Down
5 changes: 3 additions & 2 deletions Source/ExpandedRoofing/RoofMaintenance .cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,13 @@ public void Add(IntVec3 c)
public void Tick()
{
// bucketing? kind of?
this.grid.Where(kp => Find.TickManager.TicksGame + kp.Key.HashOffset() % long_TickInterval == 0).Do( kp =>
List<KeyValuePair<int,int>> items = this.grid.Where(kp => Find.TickManager.TicksGame + kp.Key.HashOffset() % long_TickInterval == 0).ToList();
foreach(KeyValuePair<int,int> kp in items)
{
this.grid[kp.Key] += 1;
if (this.grid[kp.Key] > minTicksBeforeMTBCollapses && Rand.MTBEventOccurs(3.5f, 60000f, long_TickInterval))
this.map.roofCollapseBuffer.MarkToCollapse(this.GetIntVec3(kp.Key));
});
}
}

public IEnumerable<IntVec3> CurrentlyRequiresMaintenance
Expand Down
3 changes: 1 addition & 2 deletions Source/ExpandedRoofing/SolarRoofingTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Reflection;
using Verse;

using static ExpandedRoofing.SolarRoofingTracker;

namespace ExpandedRoofing
Expand Down Expand Up @@ -86,7 +85,7 @@ public void AddSolarCell(IntVec3 cell)

int idx = 0;
#if DEBUG
Log.Message($"{idx} -> case {found.Count()}");
Log.Message($"SolarRoofingTracker.AddSolarCell: {idx} -> case {found.Count()}");
#endif
switch (found.Count)
{
Expand Down

0 comments on commit 623de25

Please sign in to comment.