Skip to content

Commit

Permalink
Merge pull request #427 from hubastard/fix-single-player
Browse files Browse the repository at this point in the history
Fix single player
  • Loading branch information
hubastard authored Aug 28, 2021
2 parents 061aecb + 06e847c commit 1c6987a
Show file tree
Hide file tree
Showing 24 changed files with 100 additions and 66 deletions.
7 changes: 0 additions & 7 deletions NebulaPatcher/MainMenuManager.cs

This file was deleted.

11 changes: 6 additions & 5 deletions NebulaPatcher/Patches/Dynamic/ArriveLeavePlanet_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,21 @@ public static bool ArrivePlanet_Prefix(GameData __instance, PlanetData planet)
}
}

public static bool RefreshMissingMeshes = false;

[HarmonyPostfix]
[HarmonyPatch(nameof(GameData.ArrivePlanet))]
public static void ArrivePlanet_Postfix(GameData __instance, PlanetData planet)
{
RefreshMissingMeshes = true;
if (Multiplayer.IsActive)
{
Multiplayer.Session.PlanetRefreshMissingMeshes = true;
}
}

[HarmonyPostfix]
[HarmonyPatch(nameof(GameData.GameTick))]
public static void GameTick_Postfix(GameData __instance)
{
if (Multiplayer.IsActive && RefreshMissingMeshes && __instance.localPlanet != null)
if (Multiplayer.IsActive && Multiplayer.Session.PlanetRefreshMissingMeshes && __instance.localPlanet != null)
{
PlanetData planetData = __instance.localPlanet;

Expand All @@ -84,7 +85,7 @@ public static void GameTick_Postfix(GameData __instance)
planetData.meshColliders[i].sharedMesh = planetData.meshes[i];
}
}
RefreshMissingMeshes = false;
Multiplayer.Session.PlanetRefreshMissingMeshes = false;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions NebulaPatcher/Patches/Dynamic/BuildTool_Common_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public static bool CreatePrebuilds_Prefix(BuildTool __instance)
if (!Multiplayer.IsActive)
return true;


List<BuildPreview> previews = __instance.buildPreviews;
if (__instance is BuildTool_BlueprintPaste)
{
Expand Down Expand Up @@ -51,11 +50,12 @@ public static bool CreatePrebuilds_Prefix(BuildTool __instance)
[HarmonyPatch(typeof(BuildTool_BlueprintPaste), nameof(BuildTool_BlueprintPaste.CheckBuildConditions))]
public static bool CheckBuildConditions(ref bool __result)
{
if (Multiplayer.Session.Factories.IsIncomingRequest)
if (Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest)
{
__result = true;
return false;
}

return true;
}
}
Expand Down
1 change: 0 additions & 1 deletion NebulaPatcher/Patches/Dynamic/DysonSphere_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using HarmonyLib;
using NebulaModel.Packets.Universe;
using NebulaWorld;
using NebulaWorld.Universe;
using System;
using UnityEngine;

Expand Down
5 changes: 2 additions & 3 deletions NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ public static bool OnActivePlanetLoaded_Prefix(GameData __instance, PlanetData p
[HarmonyPatch(nameof(GameData.OnActivePlanetFactoryLoaded))]
public static bool OnActivePlanetFactoryLoaded_Prefix(GameData __instance, PlanetData planet)
{
// NOTE: this is part of the weird planet movement fix, see ArrivePlanet() patch for more information

if (Multiplayer.Session.LocalPlayer.IsHost)
if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost)
{
return true;
}

if (planet != null)
{
if (GameMain.gameTick == 0L && DSPGame.SkipPrologue)
Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/GameLoader_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GameLoader_Patch
[HarmonyPatch(nameof(GameLoader.FixedUpdate))]
public static void FixedUpdate_Postfix(int ___frame)
{
if (___frame >= 11 && Multiplayer.IsActive)
if (Multiplayer.IsActive && ___frame >= 11)
{
Multiplayer.Session.OnGameLoadCompleted();
}
Expand Down
10 changes: 8 additions & 2 deletions NebulaPatcher/Patches/Dynamic/PlanetFactory_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,21 @@ public static bool UpgradeFinally_Prefix(PlanetFactory __instance, Player player
[HarmonyPatch(nameof(PlanetFactory.GameTick))]
public static bool InternalUpdate_Prefix()
{
Multiplayer.Session.Storage.IsHumanInput = false;
if (Multiplayer.IsActive)
{
Multiplayer.Session.Storage.IsHumanInput = false;
}
return true;
}

[HarmonyPostfix]
[HarmonyPatch(nameof(PlanetFactory.GameTick))]
public static void InternalUpdate_Postfix()
{
Multiplayer.Session.Storage.IsHumanInput = true;
if (Multiplayer.IsActive)
{
Multiplayer.Session.Storage.IsHumanInput = true;
}
}

[HarmonyPrefix]
Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/UIGalaxySelect_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UIGalaxySelect_Patch
[HarmonyPatch(nameof(UIGalaxySelect.EnterGame))]
public static bool EnterGame_Prefix(UIGalaxySelect __instance)
{
if (MainMenuManager.IsInMultiplayerMenu)
if (Multiplayer.IsInMultiplayerMenu)
{
Log.Info($"Listening server on port {Config.Options.HostPort}");
Multiplayer.HostGame(new Server(Config.Options.HostPort));
Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/UILoadGameWindow_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UILoadGameWindow_Patch
[HarmonyPatch(nameof(UILoadGameWindow.DoLoadSelectedGame))]
public static void DoLoadSelectedGame_Postfix()
{
if (MainMenuManager.IsInMultiplayerMenu)
if (Multiplayer.IsInMultiplayerMenu)
{
Log.Info($"Listening server on port {Config.Options.HostPort}");
Multiplayer.HostGame(new Server(Config.Options.HostPort, true));
Expand Down
4 changes: 2 additions & 2 deletions NebulaPatcher/Patches/Dynamic/UIMainMenu_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static void AddMultiplayerButton()

private static void OnMultiplayerButtonClick()
{
MainMenuManager.IsInMultiplayerMenu = true;
Multiplayer.IsInMultiplayerMenu = true;
mainMenuButtonGroup.gameObject.SetActive(false);
multiplayerSubMenu.gameObject.SetActive(true);
}
Expand Down Expand Up @@ -113,7 +113,7 @@ private static void OnMultiplayerJoinGameButtonClick()

private static void OnMultiplayerBackButtonClick()
{
MainMenuManager.IsInMultiplayerMenu = false;
Multiplayer.IsInMultiplayerMenu = false;
multiplayerSubMenu.gameObject.SetActive(false);
mainMenuButtonGroup.gameObject.SetActive(true);
}
Expand Down
13 changes: 10 additions & 3 deletions NebulaPatcher/Patches/Dynamic/UIStorageWindow_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public static bool OnStorageIdChange_Prefix(UIStorageWindow __instance)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")]
public static bool _OnOpen_Prefix()
{
Multiplayer.Session.Storage.WindowOpened = true;
if (Multiplayer.IsActive)
{
Multiplayer.Session.Storage.WindowOpened = true;
}

return true;
}

Expand All @@ -46,8 +50,11 @@ public static bool _OnOpen_Prefix()
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")]
public static void _OnClose_Prefix()
{
Multiplayer.Session.Storage.WindowOpened = false;
Multiplayer.Session.Storage.ActiveStorageComponent = null;
if (Multiplayer.IsActive)
{
Multiplayer.Session.Storage.WindowOpened = false;
Multiplayer.Session.Storage.ActiveStorageComponent = null;
}
}
}
}
21 changes: 14 additions & 7 deletions NebulaPatcher/Patches/Dynamic/UITankWindow_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,36 @@ namespace NebulaPatcher.Patches.Dynamic
[HarmonyPatch(typeof(UITankWindow))]
class UITankWindow_Patch
{
public static bool PointerPress = false;

[HarmonyPostfix]
[HarmonyPatch(nameof(UITankWindow.OnTakeBackPointerDown))]
public static void OnTakeBackPointerDown_Postfix(UITankWindow __instance)
{
PointerPress = __instance.pointerPress;
if (Multiplayer.IsActive)
{
Multiplayer.Session.IsTankWindowPointerPress = __instance.pointerPress;
}
}

[HarmonyPostfix]
[HarmonyPatch(nameof(UITankWindow.OnTakeBackPointerUp))]
public static void OnTakeBackPointerUp_Postfix()
{
PointerPress = false;
if (Multiplayer.IsActive)
{
Multiplayer.Session.IsTankWindowPointerPress = false;
}
}

[HarmonyPostfix]
[HarmonyPatch(nameof(UITankWindow.OnApplicationFocus))]
public static void OnApplicationFocus_Postfix(bool focus)
{
if (!focus)
if (Multiplayer.IsActive)
{
PointerPress = false;
if (!focus)
{
Multiplayer.Session.IsTankWindowPointerPress = false;
}
}
}

Expand Down Expand Up @@ -58,7 +65,7 @@ public static void OnInputSwitchClick_Postfix(UITankWindow __instance)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")]
public static void _OnUpdate_Postfix(UITankWindow __instance)
{
if (PointerPress && Multiplayer.IsActive)
if (Multiplayer.IsActive && Multiplayer.Session.IsTankWindowPointerPress)
{
//Send update for inserting or withdrawing
TankComponent thisTank = __instance.storage.tankPool[__instance.tankId];
Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/VFInput_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class VFInput_Patch
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")]
public static bool _buildConfirm_Prefix(ref VFInput.InputValue __result)
{
if (Multiplayer.Session.Factories.IsIncomingRequest)
if (Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest)
{
__result = default;
__result.onDown = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using HarmonyLib;
using NebulaWorld;
using NebulaWorld.Factory;
using System;
using System.Collections.Generic;
using System.Reflection;
Expand Down
19 changes: 15 additions & 4 deletions NebulaPatcher/Patches/Transpilers/MechaDroneLogic_Transpiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static IEnumerable<CodeInstruction> UpdateTargets_Transpiler(IEnumerable<CodeIns
.InsertAndAdvance(num4Instruction)
.InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate<Func<int, bool>>((num4) =>
{
return Multiplayer.Session.Drones.IsPendingBuildRequest(num4);
return Multiplayer.IsActive && Multiplayer.Session.Drones.IsPendingBuildRequest(num4);
}))
.InsertAndAdvance(jumpInstruction);

Expand Down Expand Up @@ -79,6 +79,11 @@ static IEnumerable<CodeInstruction> UpdateTargets_Transpiler(IEnumerable<CodeIns
.InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, aOperand))
.InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate<Func<Vector3, bool>>((aVar) =>
{
if (!Multiplayer.IsActive)
{
return true;
}

return Multiplayer.Session.Drones.AmIClosestPlayer(ref aVar);
}))
.InsertAndAdvance(new CodeInstruction(OpCodes.Brfalse, jumpOperand));
Expand Down Expand Up @@ -120,7 +125,10 @@ static IEnumerable<CodeInstruction> UpdateTargets_Transpiler(IEnumerable<CodeIns
.InsertAndAdvance(stageInstruction)
.InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate<Action<int, int, int>>((droneId, entityId, stage) =>
{
Multiplayer.Session.Drones.BroadcastDroneOrder(droneId, entityId, stage);
if (Multiplayer.IsActive)
{
Multiplayer.Session.Drones.BroadcastDroneOrder(droneId, entityId, stage);
}
}))
.InstructionEnumeration();
}
Expand Down Expand Up @@ -162,7 +170,10 @@ static IEnumerable<CodeInstruction> UpdateDrones_Transpiler(IEnumerable<CodeInst
.InsertAndAdvance(stageInst)
.InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate<Action<int, int, int>>((droneId, entityId, stage) =>
{
Multiplayer.Session.Drones.BroadcastDroneOrder(droneId, entityId, stage);
if (Multiplayer.IsActive)
{
Multiplayer.Session.Drones.BroadcastDroneOrder(droneId, entityId, stage);
}
}))
.Advance(1);
})
Expand Down Expand Up @@ -201,7 +212,7 @@ static IEnumerable<CodeInstruction> FindNext_Transpiler(IEnumerable<CodeInstruct
.InsertAndAdvance(target)
.InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate<Func<int, bool>>((targetId) =>
{
return Multiplayer.Session.Drones.IsPendingBuildRequest(targetId);
return Multiplayer.IsActive && Multiplayer.Session.Drones.IsPendingBuildRequest(targetId);
}))
.Insert(new CodeInstruction(OpCodes.Brtrue, jump))
.InstructionEnumeration();
Expand Down
10 changes: 8 additions & 2 deletions NebulaPatcher/Patches/Transpilers/PlanetFactory_Transpiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ static IEnumerable<CodeInstruction> OnBeltBuilt_Transpiler(IEnumerable<CodeInstr
.InsertAndAdvance(pointPosInsts.ToArray())
.InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate<Action<int, int, int, int, UnityEngine.Vector3>>((inserterId, pickTarget, offset, objId, pointPos) =>
{
Multiplayer.Session.Factories.OnNewSetInserterPickTarget(objId, pickTarget, inserterId, offset, pointPos);
if (Multiplayer.IsActive)
{
Multiplayer.Session.Factories.OnNewSetInserterPickTarget(objId, pickTarget, inserterId, offset, pointPos);
}
}));

/*
Expand Down Expand Up @@ -77,7 +80,10 @@ static IEnumerable<CodeInstruction> OnBeltBuilt_Transpiler(IEnumerable<CodeInstr
.InsertAndAdvance(pointPosInsts.ToArray())
.InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate<Action<int, int, int, int, UnityEngine.Vector3>>((inserterId, pickTarget, offset, objId, pointPos) =>
{
Multiplayer.Session.Factories.OnNewSetInserterInsertTarget(objId, pickTarget, inserterId, offset, pointPos);
if (Multiplayer.IsActive)
{
Multiplayer.Session.Factories.OnNewSetInserterInsertTarget(objId, pickTarget, inserterId, offset, pointPos);
}
}));

return codeMatcher.InstructionEnumeration();
Expand Down
29 changes: 12 additions & 17 deletions NebulaPatcher/Patches/Transpilers/PlayerMove_Sail_Transpiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,21 @@ public static IEnumerable<CodeInstruction> GameTick_Transpiler(IEnumerable<CodeI
.Advance(1)
.InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate<Action>(() =>
{
// send to host / clients
if (!Multiplayer.IsActive)
if (Multiplayer.IsActive)
{
return;
}

if (Multiplayer.Session.LocalPlayer.IsHost)
{
PlayerUseWarper packet = new PlayerUseWarper(warpCommand)
if (Multiplayer.Session.LocalPlayer.IsHost)
{
PlayerId = Multiplayer.Session.LocalPlayer.Id
};
Multiplayer.Session.Network.SendPacket(packet);
}
else
{
Multiplayer.Session.Network.SendPacket(new PlayerUseWarper(warpCommand));
PlayerUseWarper packet = new PlayerUseWarper(warpCommand)
{
PlayerId = Multiplayer.Session.LocalPlayer.Id
};
Multiplayer.Session.Network.SendPacket(packet);
}
else
{
Multiplayer.Session.Network.SendPacket(new PlayerUseWarper(warpCommand));
}
}

return;
}));
})
.InstructionEnumeration();
Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Transpilers/Player_Transpiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static IEnumerable<CodeInstruction> Get_nearestFactory_Transpiler(IEnumer
.Advance(-1)
.InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate<Func<bool>>(() =>
{
return Multiplayer.Session.LocalPlayer.IsHost || !Multiplayer.IsActive;
return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost;
}))
.Insert(new CodeInstruction(OpCodes.Brfalse, op))
.InstructionEnumeration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static IEnumerable<CodeInstruction> SetFilterToEntity_Transpiler(IEnumera
{
return 0;
}

if (Multiplayer.Session.Ships.ItemSlotStationId == stationComponent.id &&
Multiplayer.Session.Ships.ItemSlotStationGId == stationComponent.gid &&
Multiplayer.Session.Ships.ItemSlotLastSlotId == outputSlotId &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static IEnumerable<CodeInstruction> SetFilterToEntity_Transpiler(IEnumera
{
return 0;
}

Multiplayer.Session.Network.SendPacketToLocalStar(new ILSUpdateSlotData(stationComponent.planetId, stationComponent.id, stationComponent.gid, outputSlotId, selectedIndex));
return 0;
}))
Expand Down
Loading

0 comments on commit 1c6987a

Please sign in to comment.