Skip to content

Commit

Permalink
Add a bug fix for generator minimum output temperatures to Stock Bug …
Browse files Browse the repository at this point in the history
…Fix.

Update core documentation.

Update the CI build assemblies to U52-626616. Skip building the reference assemblies if Refasmer cannot be found, as they are not critical to the build.
  • Loading branch information
peterhaneve committed Aug 25, 2024
1 parent 7263d94 commit 643de45
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 31 deletions.
4 changes: 3 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
$(GameFolderActive)/UnityEngine.InputLegacyModule.dll $(GameFolderActive)/Unity.TextMeshPro.dll ^
$(GameFolderActive)/UnityEngine.TextRenderingModule.dll $(GameFolderActive)/UnityEngine.UI.dll ^
$(GameFolderActive)/UnityEngine.UIModule.dll $(GameFolderActive)/UnityEngine.UnityWebRequestModule.dll ^
$(GameFolderActive)/Ionic.Zip.dll $(GameFolderActive)/Newtonsoft.Json.dll $(GameFolderActive)/com.rlabrecque.steamworks.net.dll" />
$(GameFolderActive)/Ionic.Zip.dll $(GameFolderActive)/Newtonsoft.Json.dll $(GameFolderActive)/com.rlabrecque.steamworks.net.dll"
IgnoreExitCode="true"/>
</Target>

<Target Name="PLibTranslationEmbeddedResources" BeforeTargets="ResolveReferences" Condition=" '$(AssemblyName)' == 'PLibCore' ">
Expand Down Expand Up @@ -68,6 +69,7 @@ staticID: PeterHan.$(AssemblyName)
<Internalize>true</Internalize>
</PropertyGroup>
<ItemGroup Condition=" '$(UsesPLib)' != 'false' Or '$(AssemblyName)' == 'PLib' ">
<InputAssemblies Include="$(TargetPath)" />
<InputAssemblies Include="$(TargetDir)PLib*.dll" />
</ItemGroup>
<ItemGroup Condition=" '$(UsesPLib)' == 'false' ">
Expand Down
Binary file modified Lib/Assembly-CSharp-firstpass.dll
Binary file not shown.
Binary file modified Lib/Assembly-CSharp-firstpass_public.dll
Binary file not shown.
Binary file modified Lib/Assembly-CSharp.dll
Binary file not shown.
Binary file modified Lib/Assembly-CSharp_public.dll
Binary file not shown.
1 change: 1 addition & 0 deletions Lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The libraries in this folder are automatically generated Reference Assemblies. They do not contain the actual game code, only stubs of it with the implementations removed. This usage has been allowed by Klei for the game DLLs; other dependency DLLs are used under their license.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Peter Han&#39;s Mods for Oxygen Not Included

Last tested on game version: **U51-596100**
Last tested on game version: **U52-623711**

**No support** for Public Testing branches, including the rolled back Legacy Vanilla (CS-469300).

Expand Down Expand Up @@ -42,7 +42,6 @@ Mods should remain in their own subfolder.
| [Food Supply Tooltips](https://steamcommunity.com/sharedfiles/filedetails/?id=1914501780) | Adds tooltips to food sources indicating their calorie production per cycle | Yes | Yes |
| [Mismatched Wire Finder](https://steamcommunity.com/sharedfiles/filedetails/?id=2607620648) | Finds wires and pipes that do not match the rest of their network | Yes | Yes |
| [Mod Updater](https://steamcommunity.com/sharedfiles/filedetails/?id=2018291283) | Updates mods that Steam leaves at old versions | Yes | Yes |
| [No Splash Screen](https://steamcommunity.com/sharedfiles/filedetails/?id=2361698345) | Hides the Early Access splash screen | Yes | Yes |
| [Not Enough Tags](https://steamcommunity.com/sharedfiles/filedetails/?id=2230218796) | Deprecated! No longer supported. | No | No |
| [Pip Plant Overlay](https://steamcommunity.com/sharedfiles/filedetails/?id=2493100777) | Adds an overlay showing where Pips can plant seeds | Yes | Yes |
| [Popup Control](https://steamcommunity.com/sharedfiles/filedetails/?id=2032187035) | Shows or hides text info popups for each source | Yes | Yes |
Expand Down Expand Up @@ -80,21 +79,24 @@ Mods should remain in their own subfolder.
| **Name** | **Description** | **Vanilla** | **Spaced Out! DLC** |
| :--------: | :---------------: | :-----------: | :-------------------: |
| [Decor Reimagined](https://steamcommunity.com/sharedfiles/filedetails/?id=1892161928) | Reimagines decor, rewarding bases with consistent, unique decor items | Yes | Yes |
| [Diseases Restored](https://steamcommunity.com/sharedfiles/filedetails/?id=1911357229) | Restores diseases making germs more dangerous again, and adds methods to deal with germ spread | Yes | No |
| [Traits Reworked](https://steamcommunity.com/sharedfiles/filedetails/?id=1905214098) | Reworks Duplicant traits to make all traits meaningful and the most extreme traits more sensible | Yes | No |
| [Diseases Restored](https://steamcommunity.com/sharedfiles/filedetails/?id=1911357229) | Restores diseases making germs more dangerous again, and adds methods to deal with germ spread | Yes | Yes |
| [Traits Reworked](https://steamcommunity.com/sharedfiles/filedetails/?id=1905214098) | Deprecated! No longer supported. | No | No |

# Compiling this repository

This repository requires an installed copy of Oxygen Not Included to compile. The project is currently built against Visual Studio 2022, the .NET Framework 4.7.1 (as required by the game), and [Refasmer](https://github.com/JetBrains/Refasmer). Make sure that the correct targeting packs, as well as MSBuild support, are installed to build.
This repository requires an installed copy of Oxygen Not Included to compile.
The project is currently built against Visual Studio 2022, the .NET Framework 4.7.1 (as required by the game), and optionally [Refasmer](https://github.com/JetBrains/Refasmer) to regenerate the CI assemblies.
Make sure that the correct targeting packs, as well as MSBuild support, are installed to build.

To install the .NET runtime, targeting pack, and external build tools, run the following commands in a terminal.

```sh
> winget install Microsoft.DotNet.Framework.DeveloperPack_4 -v 4.7.1
> winget install Microsoft.DotNet.SDK.8
> dotnet tool install -g JetBrains.Refasmer.CliTool
```

The build scripts will automatically detect most Steam installations of Oxygen Not Included. To customize paths for other distribution platforms or operating systems, create a copy of `Directory.Build.props.default` named `Directory.Build.props.user`. Modify the values in it to match the correct folder locations. The "legacy" game folder is only used for pre-Mergedown versions of the game and can usually be safely ignored.
The build scripts will automatically detect most Steam installations of Oxygen Not Included.
To customize paths for other distribution platforms or operating systems, create a copy of `Directory.Build.props.default` named `Directory.Build.props.user`.
Modify the values in it to match the correct folder locations. The "legacy" game folder is only used for pre-Mergedown versions of the game and can usually be safely ignored.

*Note that ReSharper may have issues with the Steam build auto-detection; users of this plugin will need to manually specify paths to any custom Steam installations*
2 changes: 1 addition & 1 deletion StockBugFix/StockBugFix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyTitle>Stock Bug Fix</AssemblyTitle>
<FileVersion>4.2.0.0</FileVersion>
<FileVersion>4.3.0.0</FileVersion>
<RootNamespace>PeterHan.StockBugFix</RootNamespace>
<Description>Fixes bugs and annoyances in the stock game.</Description>
<AssemblyVersion>3.2.0.0</AssemblyVersion>
Expand Down
14 changes: 11 additions & 3 deletions StockBugFix/StockBugFixOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public sealed class StockBugFixOptions : SingletonOptions<StockBugFixOptions> {
[JsonProperty]
public bool FixTraits { get; set; }

/// <summary>
/// If true, fixes a bug where generator minimum output temperatures are ignored.
/// </summary>
[Option("Minimum Output Temperatures", "Corrects the minimum output exhaust temperatures of many generators.")]
[JsonProperty]
public bool MinOutputTemperature { get; set; }

/// <summary>
/// If true, locks out the Mods button until the race condition which reinstalls all
/// mods clears out, or until the timeout passes.
Expand All @@ -75,17 +82,18 @@ public sealed class StockBugFixOptions : SingletonOptions<StockBugFixOptions> {

public StockBugFixOptions() {
AllowTepidizerPulsing = false;
DelayModsMenu = false;
DelayModsMenu = true;
FixMultipleAttributes = true;
FixOverheat = true;
FixTraits = true;
MinOutputTemperature = false;
StoreFoodChoreType = StoreFoodCategory.Store;
}

public override string ToString() {
return "StockBugFixOptions[allowTepidizer={1},fixOverheat={0},foodChoreType={2},fixAttributes={3},fixTraits={4},delayModsMenu={5}]".F(
return "StockBugFixOptions[allowTepidizer={1},fixOverheat={0},foodChoreType={2},fixAttributes={3},fixTraits={4},delayModsMenu={5},minOutput={6}]".F(
FixOverheat, AllowTepidizerPulsing, StoreFoodChoreType, FixMultipleAttributes,
FixTraits, DelayModsMenu);
FixTraits, DelayModsMenu, MinOutputTemperature);
}
}

Expand Down
52 changes: 52 additions & 0 deletions StockBugFix/StockBugsPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,58 @@ internal static bool Prefix(Diggable __instance, Worker worker, ref bool __resul
}
}

/// <summary>
/// Applied to EnergyGenerator to use the correct building output temperature.
/// </summary>
[HarmonyPatch(typeof(EnergyGenerator), "Emit")]
public static class EnergyGenerator_Emit_Patch {
/// <summary>
/// Allow this patch to be turned off in the config.
/// </summary>
internal static bool Prepare() {
return StockBugFixOptions.Instance.MinOutputTemperature;
}

/// <summary>
/// Transpiles Emit to add a call to Mathf.Max on each attempt to access the building
/// temperature with the output minimum temperature.
/// </summary>
internal static TranspiledMethod Transpiler(TranspiledMethod method,
ILGenerator generator) {
var targetMethod = typeof(PrimaryElement).GetPropertySafe<float>(nameof(
PrimaryElement.Temperature), false)?.GetGetMethod();
var maxMethod = typeof(Mathf).GetMethodSafe(nameof(Mathf.Max), true, typeof(float),
typeof(float));
var emitOffset = typeof(EnergyGenerator.OutputItem).GetFieldSafe(nameof(
EnergyGenerator.OutputItem.emitOffset), false);
var minTempField = typeof(EnergyGenerator.OutputItem).GetFieldSafe(
nameof(EnergyGenerator.OutputItem.minTemperature), false);
if (maxMethod != null && targetMethod != null) {
var local = generator.DeclareLocal(typeof(float));
bool emitCase = false;
// Store the min temperature into local
yield return new CodeInstruction(OpCodes.Ldarg_1);
yield return new CodeInstruction(OpCodes.Ldfld, minTempField);
yield return new CodeInstruction(OpCodes.Stloc_S, local.LocalIndex);
foreach (var instr in method) {
yield return instr;
if (!emitCase && instr.opcode == OpCodes.Callvirt && instr.operand is
MethodBase getter && getter == targetMethod) {
// Patch all cases until the emit offset is used
yield return new CodeInstruction(OpCodes.Ldloc_S, local.LocalIndex);
yield return new CodeInstruction(OpCodes.Call, maxMethod);
}
if (instr.operand is FieldInfo info && info == emitOffset)
emitCase = true;
}
} else {
PUtil.LogWarning("Target PrimaryElement method not found.");
foreach (var instr in method)
yield return instr;
}
}
}

/// <summary>
/// Applied to ExobaseHeadquartersConfig to ban them from being built in rockets. They
/// already cannot be built there in the base game, but this greatly improves the
Expand Down
19 changes: 0 additions & 19 deletions StockBugFix/StockQOLPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,6 @@ internal static void Postfix(BuildingDef __result) {
}
}

/// <summary>
/// Applied to IceMachineConfig to give it a sensible overheat temperature.
/// </summary>
[HarmonyPatch(typeof(IceMachineConfig), "CreateBuildingDef")]
public static class IceMachineConfig_CreateBuildingDef_Patch {
internal static bool Prepare() {
return StockBugFixOptions.Instance.FixOverheat;
}

/// <summary>
/// Applied after CreateBuildingDef runs.
/// </summary>
internal static void Postfix(BuildingDef __result) {
// Overheat at 125 C
__result.Overheatable = true;
__result.OverheatTemperature = TUNING.BUILDINGS.OVERHEAT_TEMPERATURES.HIGH_2;
}
}

/// <summary>
/// Applied to KilnConfig to give it a sensible overheat temperature.
/// </summary>
Expand Down

0 comments on commit 643de45

Please sign in to comment.