Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,8 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# git merge
*.orig
*.bak
10 changes: 10 additions & 0 deletions ColorCycler/About/About.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<ModMetadata xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Name>Color Cycler</Name>
<Author>Elmotrix</Author>
<Version>1.200000.00</Version>
<Description>Cycles colors on spray cans with mouse wheel</Description>
<Tags>
<Tag>paint</Tag>
</Tags>
</ModMetadata>
Binary file added ColorCycler/About/Preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added ColorCycler/About/bepinex
Empty file.
Binary file added ColorCycler/About/thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 25 additions & 10 deletions ColorCycler/BepInEx.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HarmonyLib;
using BepInEx.Logging;
using HarmonyLib;
using System;
using UnityEngine;

namespace ColorCycler
{
Expand All @@ -10,24 +10,39 @@ public class ColorCyclerBep : BepInEx.BaseUnityPlugin
{
public const string pluginGuid = "net.elmo.stationeers.ColorCycler";
public const string pluginName = "ColorCycler";
public const string pluginVersion = "1.1.0";
public static void Log(string line)
public const string pluginVersion = "1.2.0";

private Harmony _harmony;

internal static new ManualLogSource Logger;
internal static ColorCyclerConfig Settings;

public ColorCyclerBep()
{
Debug.Log("[" + pluginName + "]: " + line);
Settings ??= new ColorCyclerConfig(Config);
}

void Awake()
{
Logger = base.Logger;
try
{
var harmony = new Harmony(pluginGuid);
harmony.PatchAll();
Log("Patch succeeded");
_harmony = new Harmony(pluginGuid);
_harmony.PatchAll();
Logger.LogInfo("Patch succeeded");
}
catch (Exception e)
{
Log("Patch Failed");
Log(e.ToString());
Logger.LogFatal("Patch Failed");
Logger.LogFatal(e);
}
Logger.LogMessage($"{nameof(Settings.ShouldCreatePollution)}: {Settings.ShouldCreatePollution}");
Logger.LogMessage($"{nameof(Settings.InfinitePaint)}: {Settings.InfinitePaint}");
}

private void OnDestroy()
{
_harmony.UnpatchSelf();
}
}
#endregion
Expand Down
53 changes: 36 additions & 17 deletions ColorCycler/ColorCycler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,51 @@
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>bin\Debug\ColorCycler</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<DebugType>embedded</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>bin\Release\ColorCycler</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<Reference Include="0Harmony" Private="False">
<HintPath>D:\SteamLibrary\steamapps\common\Stationeers\BepInEx\core\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<Reference Include="Assembly-CSharp" Private="False">
<HintPath>D:\SteamLibrary\steamapps\common\Stationeers\rocketstation_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<Reference Include="BepInEx" Private="False">
<HintPath>D:\SteamLibrary\steamapps\common\Stationeers\BepInEx\core\BepInEx.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<Reference Include="System" Private="False" />
<Reference Include="System.Core" Private="False" />
<Reference Include="System.Xml.Linq" Private="False" />
<Reference Include="System.Data.DataSetExtensions" Private="False" />
<Reference Include="Microsoft.CSharp" Private="False" />
<Reference Include="System.Data" Private="False" />
<Reference Include="System.Net.Http" Private="False" />
<Reference Include="System.Xml" Private="False" />
<Reference Include="UnityEngine" Private="False">
<HintPath>D:\SteamLibrary\steamapps\common\Stationeers\rocketstation_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<Reference Include="UnityEngine.CoreModule" Private="False">
<HintPath>D:\SteamLibrary\steamapps\common\Stationeers\rocketstation_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL" Private="False">
<SpecificVersion>False</SpecificVersion>
<HintPath>D:\SteamLibrary\steamapps\common\Stationeers\rocketstation_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
Expand All @@ -63,7 +65,24 @@
<Compile Include="BepInEx.cs" />
<Compile Include="ColorCyclerMod.cs" />
<Compile Include="ColorCyclerModHelpers.cs" />
<Compile Include="ColorCyclerConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="About\About.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="About\Preview.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="About\thumb.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="About\bepinex">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
39 changes: 39 additions & 0 deletions ColorCycler/ColorCyclerConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using BepInEx.Configuration;
using System;

namespace ColorCycler
{
internal class ColorCyclerConfig
{
private ConfigEntry<bool> _shouldCreatePollutionEntry;
private ConfigEntry<bool> _infinitePaint;

public bool ShouldCreatePollution => _shouldCreatePollutionEntry.Value;
public bool InfinitePaint => _infinitePaint.Value;

public ColorCyclerConfig(ConfigFile config)
{
_shouldCreatePollutionEntry = config.Bind(
"ColorCycler",
nameof(ShouldCreatePollution),
false,
"Should spray cans create pollution?"
);
_infinitePaint = config.Bind(
"ColorCycler",
nameof(InfinitePaint),
true,
"Should spray cans have infinite uses?"
);

config.ConfigReloaded += OnConfigReloaded;
}

private void OnConfigReloaded(object sender, EventArgs e)
{
ColorCyclerBep.Logger.LogWarning("Config Reloaded");
ColorCyclerBep.Logger.LogWarning($"{nameof(ShouldCreatePollution)}: {ShouldCreatePollution}");
ColorCyclerBep.Logger.LogWarning($"{nameof(InfinitePaint)}: {InfinitePaint}");
}
}
}
43 changes: 39 additions & 4 deletions ColorCycler/ColorCyclerMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static void Prefix(InventoryManager __instance)

if (NetworkManager.IsClient)
{
ColorCyclerBep.Logger.LogDebug($"Sending {nameof(ThingColorMessage)} to Server. ColorIndex = {current}, ThingId = {sprayCan.ReferenceId}");
NetworkClient.SendToServer(new ThingColorMessage
{
ThingId = sprayCan.ReferenceId,
Expand All @@ -59,12 +60,45 @@ public static void Prefix(InventoryManager __instance)
public class SprayCanOnUseItemPatch
{
[UsedImplicitly]
public static bool Prefix(ref bool __result)
public static bool Prefix(SprayCan __instance, ref bool __result, ref float quantity)
{
// Modify __result and return false, so that pollution does not occur.
__result = true;

// Make Paint infinite.
if (ColorCyclerBep.Settings.InfinitePaint)
{
ColorCyclerBep.Logger.LogDebug($"Setting Quantity to 0 from {quantity}");
quantity = 0.0f;
}
ColorCyclerBep.Logger.LogDebug($"Using Quantity {quantity}");

// Return true, so that original code is executed, if pollution should occur.
if (ColorCyclerBep.Settings.ShouldCreatePollution)
{
return true;
}

// No pollution, skip original, but apply Quantity in case of non-infinite paint
__instance.Quantity -= quantity;
return false;
}
}

// We have to patch Consumable because SprayCan does not implement the method
[HarmonyPatch(typeof(Consumable), nameof(Consumable.GetQuantityText))]
public class ConsumableGetQuantityTextPatch
{
[UsedImplicitly]
public static bool Prefix(Consumable __instance, ref string __result)
{
if (__instance is not SprayCan sprayCan || !ColorCyclerBep.Settings.InfinitePaint)
{
return true;
}
__result = "Infinite";
return false;
}

}

// We have to patch Consumable because SprayCan does not implement the method
Expand All @@ -76,7 +110,7 @@ public static void Postfix(Consumable __instance, RocketBinaryWriter writer, ush
{
if (__instance is SprayCan sprayCan)
{
if (Thing.IsNetworkUpdateRequired(4096U, networkUpdateType))
if (Thing.IsNetworkUpdateRequired(ColorCyclerModHelpers.PaintableMaterialNetworkFlag, networkUpdateType))
{
writer.WriteInt32(ColorCyclerModHelpers.GetPaintColorIndex(sprayCan.PaintMaterial));
}
Expand All @@ -93,7 +127,7 @@ public static void Postfix(Consumable __instance, RocketBinaryReader reader, ush
{
if (__instance is SprayCan sprayCan)
{
if (Thing.IsNetworkUpdateRequired(4096U, networkUpdateType))
if (Thing.IsNetworkUpdateRequired(ColorCyclerModHelpers.PaintableMaterialNetworkFlag, networkUpdateType))
{
int index = reader.ReadInt32();
var paintMaterial = ColorCyclerModHelpers.GetPaintColor(index);
Expand All @@ -109,6 +143,7 @@ public class ThingColorMessageProcessPatch
[UsedImplicitly]
public static void Postfix(ThingColorMessage __instance, long hostId)
{
ColorCyclerBep.Logger.LogDebug($"Received {nameof(ThingColorMessage)}. ColorIndex = {__instance.ColorIndex}, ThingId = {__instance.ThingId}");
if (Thing.Find(__instance.ThingId) is SprayCan sprayCan)
{
var paintMaterial = ColorCyclerModHelpers.GetPaintColor(__instance.ColorIndex);
Expand Down
Loading