Skip to content

Commit

Permalink
germ thing initial
Browse files Browse the repository at this point in the history
  • Loading branch information
asquared31415 committed Feb 21, 2023
1 parent f5a6369 commit 2decf8e
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ONI-Mods.sln
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StartWithResearch", "src\St
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpicedFoodFilter", "src\SpicedFoodFilter\SpicedFoodFilter.csproj", "{B995D37C-FF7F-411E-8287-C6753F8AFC9B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GermThing", "src\GermThing\GermThing.csproj", "{1FA0693A-7615-4ED6-AEB1-8222F830CCCC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Mergedown|Any CPU = Mergedown|Any CPU
Expand Down Expand Up @@ -116,5 +118,7 @@ Global
{FC2F1647-8BCF-4705-B011-61D2175C8A2B}.Mergedown|Any CPU.Build.0 = Mergedown|Any CPU
{B995D37C-FF7F-411E-8287-C6753F8AFC9B}.Mergedown|Any CPU.ActiveCfg = Mergedown|Any CPU
{B995D37C-FF7F-411E-8287-C6753F8AFC9B}.Mergedown|Any CPU.Build.0 = Mergedown|Any CPU
{1FA0693A-7615-4ED6-AEB1-8222F830CCCC}.Mergedown|Any CPU.ActiveCfg = Mergedown|Any CPU
{1FA0693A-7615-4ED6-AEB1-8222F830CCCC}.Mergedown|Any CPU.Build.0 = Mergedown|Any CPU
EndGlobalSection
EndGlobal
111 changes: 111 additions & 0 deletions src/GermThing/GermThing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using HarmonyLib;
using JetBrains.Annotations;
using KMod;
using UnityEngine;

namespace GermThing;

[UsedImplicitly]
public class GermThing : UserMod2
{
}

public class GermOverlayMode : OverlayModes.Mode
{
public static HashedString Id = "asquared31415_" + nameof(GermOverlayMode);

public override HashedString ViewMode()
{
return Id;
}

public override string GetSoundName()
{
return "Decor";
}
}

// The overlay code
[HarmonyPatch(typeof(SimDebugView), "OnPrefabInit")]
public static class SimDebugView_OnPrefabInit_Patch
{
[UsedImplicitly]
public static void Postfix(Dictionary<HashedString, Func<SimDebugView, int, Color>> ___getColourFuncs)
{
___getColourFuncs.Add(
GermOverlayMode.Id,
(view, cell) =>
{
var color = (Color) AccessTools.Method(typeof(SimDebugView), "GetDiseaseColour")
.Invoke(null, new object[] { view, cell });
color.a = (Grid.DiseaseCount[cell] <= 0) || (Grid.DiseaseIdx[cell] == byte.MaxValue) ? 0 : 1;
return color;
}
);
}
}

// Register in the overlay
[HarmonyPatch(typeof(OverlayMenu), "InitializeToggles")]
public static class OverlayMenu_InitializeToggles_Patch
{
[UsedImplicitly]
public static void Postfix(List<KIconToggleMenu.ToggleInfo> ___overlayToggleInfos)
{
var constructor = AccessTools.Constructor(
AccessTools.Inner(typeof(OverlayMenu), "OverlayToggleInfo"),
new[]
{
typeof(string),
typeof(string),
typeof(HashedString),
typeof(string),
typeof(Action),
typeof(string),
typeof(string),
}
);
var _ = Action.NumActions.ToString();

var obj = constructor.Invoke(
new object[]
{
"Germ Overlay",
"overlay_disease",
GermOverlayMode.Id,
"",
Action.NumActions,
"Displays germs betterer",
"Germ Overlay",
}
);

___overlayToggleInfos.Add((KIconToggleMenu.ToggleInfo) obj);
}
}

[HarmonyPatch(typeof(OverlayScreen), "RegisterModes")]
public static class OverlayScreen_RegisterModes_Patch
{
[UsedImplicitly]
public static void Postfix()
{
var overlayScreen = Traverse.Create(OverlayScreen.Instance);
overlayScreen.Method("RegisterMode", new GermOverlayMode()).GetValue();
}
}

[HarmonyPatch(typeof(StatusItem), "GetStatusItemOverlayBySimViewMode")]
public static class StatusItem_GetStatusItemOverlayBySimViewMode_Patch
{
[UsedImplicitly]
public static void Prefix(Dictionary<HashedString, StatusItem.StatusItemOverlays> ___overlayBitfieldMap)
{
if (!___overlayBitfieldMap.ContainsKey(GermOverlayMode.Id))
{
___overlayBitfieldMap.Add(GermOverlayMode.Id, StatusItem.StatusItemOverlays.None);
}
}
}
10 changes: 10 additions & 0 deletions src/GermThing/GermThing.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configurations>Mergedown</Configurations>
<RootNamespace>GermThing</RootNamespace>
<AssemblyName>GermThing</AssemblyName>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Mergedown'" />
</Project>
2 changes: 2 additions & 0 deletions src/GermThing/mod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: "Brighter Germ Overlay"
staticID: "asquared31415.GermThing"
4 changes: 4 additions & 0 deletions src/GermThing/mod_info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
supportedContent: ALL
minimumSupportedBuild: 535842
version: "0.0.1"
APIVersion: 2

0 comments on commit 2decf8e

Please sign in to comment.