Skip to content

Commit

Permalink
Prevent AutoSave failed message from showing up on clients
Browse files Browse the repository at this point in the history
  • Loading branch information
hubastard committed Apr 16, 2021
1 parent 46bd04f commit da76cad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions NebulaPatcher/NebulaPatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Compile Include="Patches\Dynamic\TrashSystem_Patch.cs" />
<Compile Include="Patches\Dynamic\StorageComponent_Patch.cs" />
<Compile Include="Patches\Dynamic\UIAssemblerWindow_Patch.cs" />
<Compile Include="Patches\Dynamic\UIAutoSave_Patch.cs" />
<Compile Include="Patches\Dynamic\UIEjectorWindow_Patch.cs" />
<Compile Include="Patches\Dynamic\UIInserterWindow_Patch.cs" />
<Compile Include="Patches\Dynamic\UILabWindow_Patch.cs" />
Expand Down
28 changes: 28 additions & 0 deletions NebulaPatcher/Patches/Dynamic/UIAutoSave_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using HarmonyLib;
using NebulaModel.Logger;
using NebulaWorld;
using UnityEngine;

namespace NebulaPatcher.Patches.Dynamic
{
[HarmonyPatch(typeof(UIAutoSave))]
class UIAutoSave_Patch
{
[HarmonyPostfix]
[HarmonyPatch("_OnOpen")]
public static void _OnOpen_Postfix(UIAutoSave __instance)
{
// Hide AutoSave failed message on clients, since client cannot save in multiplayer
CanvasGroup contentCanvas = AccessTools.Field(__instance.GetType(), "contentCanvas").GetValue(__instance) as CanvasGroup;
contentCanvas?.gameObject.SetActive(!SimulatedWorld.Initialized || LocalPlayer.IsMasterClient);
Log.Warn($"UIAutoSave active: {contentCanvas?.gameObject.activeSelf}");
}

[HarmonyPrefix]
[HarmonyPatch("_OnLateUpdate")]
public static bool _OnLateUpdate_Prefix()
{
return !SimulatedWorld.Initialized || LocalPlayer.IsMasterClient;
}
}
}

0 comments on commit da76cad

Please sign in to comment.