Skip to content

Commit

Permalink
Silence a base game warning when any building is registered about a m…
Browse files Browse the repository at this point in the history
…issing subcategory for all PLib buildings.

Update Smart Pumps, Thermal Interface Plate, Thermo Sensor Tile, and Airlock Door to no longer emit this warning.
  • Loading branch information
peterhaneve committed Apr 30, 2023
1 parent 99379b9 commit 2af635a
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 25 deletions.
2 changes: 1 addition & 1 deletion AirlockDoor/AirlockDoor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Airlock Door</AssemblyTitle>
<FileVersion>3.8.0.0</FileVersion>
<FileVersion>3.9.0.0</FileVersion>
<RootNamespace>PeterHan.AirlockDoor</RootNamespace>
<Description>A powered airlock door that allows passage without ever exchanging liquid or gas.</Description>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
Expand Down
26 changes: 25 additions & 1 deletion DebugNotIncluded/DebugNotIncludedPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using KMod;
using PeterHan.PLib.Core;
using PeterHan.PLib.Database;
using PeterHan.PLib.Detours;
using PeterHan.PLib.Options;
using PeterHan.PLib.PatchManager;
using PeterHan.PLib.UI;
Expand Down Expand Up @@ -629,6 +630,18 @@ internal static void Postfix(ScheduleManager __instance) {
}
}

#if DEBUG
/// <summary>
/// Applied to StationaryChoreRangeVisualizer to silence a warning.
/// </summary>
[HarmonyPatch(typeof(StationaryChoreRangeVisualizer), "OnCleanUp")]
public static class StationaryChoreRangeVisualizer_OnCleanUp_Patch {
internal static TranspiledMethod Transpiler(TranspiledMethod method) {
return PPatchTools.ReplaceConstant(method, 0, 1, true);
}
}
#endif

#if DEBUG
/// <summary>
/// Applied to SelectToolHoverTextCard to show the cell coordinates, number, and other
Expand All @@ -651,7 +664,6 @@ private static HoverTextDrawer DrawCoordinates(HoverTextDrawer drawer,
cell, x, y), instance.Styles_BodyText.Standard);
drawer.EndShadowBar();
}

return drawer;
}

Expand All @@ -677,4 +689,16 @@ internal static TranspiledMethod Transpiler(TranspiledMethod method) {
}
}
#endif

#if DEBUG
/// <summary>
/// Applied to UtilityNetworkLink to silence a warning.
/// </summary>
[HarmonyPatch(typeof(UtilityNetworkLink), "OnCleanUp")]
public static class UtilityNetworkLink_OnCleanUp_Patch {
internal static TranspiledMethod Transpiler(TranspiledMethod method) {
return PPatchTools.ReplaceConstant(method, 0, 1, true);
}
}
#endif
}
33 changes: 20 additions & 13 deletions DebugNotIncluded/DebugUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,25 @@ internal static ModDebugInfo GetFirstModOnCallStack(this StackTrace stackTrace)
internal static Mod.PackagedModInfo GetModInfoForFolder(Mod modInfo,
string archivedPath) {
var items = new List<FileSystemItem>(32);
modInfo.file_source.GetTopLevelItems(items, archivedPath);
Mod.PackagedModInfo result = null;
foreach (var item in items)
if (item.type == FileSystemItem.ItemType.File && item.name ==
MOD_INFO_FILENAME) {
// No option but to read into memory, Klei API has no stream version
string contents = modInfo.file_source.Read(Path.Combine(archivedPath,
MOD_INFO_FILENAME));
if (!string.IsNullOrEmpty(contents))
result = Klei.YamlIO.Parse<Mod.PackagedModInfo>(contents, default);
break;
}
try {
modInfo.file_source.GetTopLevelItems(items, archivedPath);
foreach (var item in items)
if (item.type == FileSystemItem.ItemType.File && item.name ==
MOD_INFO_FILENAME) {
// No option but to read into memory, Klei API has no stream version
string contents = modInfo.file_source.Read(Path.Combine(archivedPath,
MOD_INFO_FILENAME));
if (!string.IsNullOrEmpty(contents))
result = Klei.YamlIO.Parse<Mod.PackagedModInfo>(contents, default);
break;
}
} catch (ObjectDisposedException) {
// Mod Updater properly closes resource handles. Ignore them
PUtil.LogWarning("Mod zip file for {0} was closed due to update".F(modInfo.
title));
result = null;
}
return result;
}

Expand Down Expand Up @@ -234,10 +241,10 @@ internal static bool IsBaseGameType(this Type type) {
return isBase;
}

#if false
/// <summary>
/// Opens the output log file.
/// </summary>
#if false
internal static void OpenOutputLog() {
// Ugly but true!
var platform = Application.platform;
Expand Down Expand Up @@ -266,7 +273,7 @@ internal static void OpenOutputLog() {
if (!string.IsNullOrEmpty(path))
Application.OpenURL(Path.GetFullPath(path));
}
#endif
#endif

/// <summary>
/// Profiles a method, outputting how many milliseconds it took to run on each use.
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
<DistributeMod>true</DistributeMod>
<ArchivedVersionPath></ArchivedVersionPath>
<UsePublicized>false</UsePublicized>
<PLibVersion>4.12.2.0</PLibVersion>
<PLibVersion>4.13.0.0</PLibVersion>
</PropertyGroup>
</Project>
4 changes: 3 additions & 1 deletion PLib/PLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<Description>PLib - Peter Han's library used for creating mods for Oxygen Not Included, a simulation game by Klei Entertainment.

Contains methods aimed at improving cross-mod compatibility, in-game user interfaces, and game-wide functions such as Actions and Lighting. An easy-to-use Mod Options menu is also included.</Description>
<PackageReleaseNotes>Fix a potential crash when running PLib AVC on the Epic Game Store or WeGame editions.</PackageReleaseNotes>
<PackageReleaseNotes>Fix a potential crash when running PLib AVC on the Epic Game Store or WeGame editions.

Silence a warning emitted when buildings are registered with PLib.</PackageReleaseNotes>
<RootNamespace>PeterHan.PLib</RootNamespace>
<AssemblyVersion>$(PLibVersion)</AssemblyVersion>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
Expand Down
6 changes: 4 additions & 2 deletions PLibBuildings/PBuilding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ public BuildingDef CreateDef() {
Noise);
// Solid tile?
if (IsSolidTile) {
//def.isSolidTile = true;
def.BaseTimeUntilRepair = -1.0f;
def.UseStructureTemperature = false;
BuildingTemplates.CreateFoundationTileDef(def);
Expand Down Expand Up @@ -407,6 +406,9 @@ public BuildingDef CreateDef() {
def.UtilityOutputOffset = conduit.Location;
def.OutputConduitType = conduit.Type;
}
// Add to the massive sub category dictionary to silence a warning
var subcategory = TUNING.BUILDINGS.PLANSUBCATEGORYSORTING;
subcategory[ID] = SubCategory;
return def;
}

Expand Down Expand Up @@ -459,7 +461,7 @@ public void DoPostConfigureComplete(GameObject go) {
}
}
if (IndustrialMachine && go.TryGetComponent(out KPrefabID id))
id.AddTag(RoomConstraints.ConstraintTags.IndustrialMachinery, false);
id.AddTag(RoomConstraints.ConstraintTags.IndustrialMachinery);
if (PowerInput != null)
go.AddOrGet<EnergyConsumer>();
if (PowerOutput != null)
Expand Down
29 changes: 28 additions & 1 deletion PLibCore/PPatchTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,34 @@ public static TranspiledMethod ReplaceMethodCallSafe(TranspiledMethod method,
}

/// <summary>
/// Attempts to read a field value from an object of a type not in this assembly.
/// Attempts to read a static field value from an object of a type not in this assembly.
///
/// If this operation is expected to be performed more than once on the same object,
/// use a delegate. If the type of the object is known, use Detours.
/// </summary>
/// <typeparam name="T">The type of the value to read.</typeparam>
/// <param name="type">The type whose static field should be read.</param>
/// <param name="name">The field name.</param>
/// <param name="value">The location where the field value will be stored.</param>
/// <returns>true if the field was read, or false if the field was not found or
/// has the wrong type.</returns>
public static bool TryGetFieldValue<T>(Type type, string name, out T value) {
bool ok = false;
if (type != null && !string.IsNullOrEmpty(name)) {
var field = type.GetFieldSafe(name, true);
if (field != null && field.GetValue(null) is T newValue) {
ok = true;
value = newValue;
} else
value = default;
} else
value = default;
return ok;
}

/// <summary>
/// Attempts to read a non-static field value from an object of a type not in this
/// assembly.
///
/// If this operation is expected to be performed more than once on the same object,
/// use a delegate. If the type of the object is known, use Detours.
Expand Down
4 changes: 2 additions & 2 deletions SmartPumps/SmartPumps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Smart Pumps</AssemblyTitle>
<FileVersion>4.7.0.0</FileVersion>
<FileVersion>4.8.0.0</FileVersion>
<RootNamespace>PeterHan.SmartPumps</RootNamespace>
<Description>Adds advanced liquid and gas pumps with configurable options.</Description>
<AssemblyVersion>4.1.0.0</AssemblyVersion>
<LastWorkingBuild>525812</LastWorkingBuild>
<LastWorkingBuild>546664</LastWorkingBuild>
<Platforms>Vanilla;Mergedown</Platforms>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion ThermalPlate/ThermalPlate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RootNamespace>PeterHan.ThermalPlate</RootNamespace>
<Description>Exchanges heat between buildings in its tile, even in Vacuum.</Description>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<LastWorkingBuild>498381</LastWorkingBuild>
<LastWorkingBuild>546664</LastWorkingBuild>
<Platforms>Vanilla;Mergedown</Platforms>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions TileTempSensor/TileTempSensor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Thermo Sensor Tile</AssemblyTitle>
<FileVersion>3.6.0.0</FileVersion>
<FileVersion>3.7.0.0</FileVersion>
<RootNamespace>PeterHan.TileTempSensor</RootNamespace>
<Description>A Thermo Sensor in tile form, allowing heat transfer to it even in Vacuum.</Description>
<AssemblyVersion>3.1.0.0</AssemblyVersion>
<LastWorkingBuild>496912</LastWorkingBuild>
<LastWorkingBuild>546664</LastWorkingBuild>
<Platforms>Vanilla;Mergedown</Platforms>
</PropertyGroup>
</Project>

0 comments on commit 2af635a

Please sign in to comment.