Skip to content

Commit

Permalink
Merge pull request #595 from starfi5h/pr-bugfix0.8.12
Browse files Browse the repository at this point in the history
Bugfix for nebula 0.8.12 (DSP 0.9.27.15466)
  • Loading branch information
starfi5h authored Mar 11, 2023
2 parents ee63b66 + 439d302 commit 8edc691
Show file tree
Hide file tree
Showing 34 changed files with 527 additions and 171 deletions.
15 changes: 15 additions & 0 deletions NebulaModel/Packets/Factory/Belt/BeltReversePacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace NebulaModel.Packets.Factory.Belt
{
public class BeltReversePacket
{
public int BeltId { get; set; }
public int PlanetId { get; set; }

public BeltReversePacket() { }
public BeltReversePacket(int beltId, int planetId)
{
BeltId = beltId;
PlanetId = planetId;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace NebulaModel.Packets.Factory.Inserter
{
public class InserterOffsetCorrectionPacket
{
public int InserterId { get; set; }
public short PickOffset { get; set; }
public short InsertOffset { get; set; }
public int PlanetId { get; set; }

public InserterOffsetCorrectionPacket() { }
public InserterOffsetCorrectionPacket(int inserterId, short pickOffset, short insertOffset, int planetId)
{
InserterId = inserterId;
PickOffset = pickOffset;
InsertOffset = insertOffset;
PlanetId = planetId;
}
}
}
4 changes: 3 additions & 1 deletion NebulaModel/Packets/GameHistory/GameHistoryDataResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
public class GameHistoryDataResponse
{
public byte[] HistoryBinaryData { get; set; }
public bool SandboxToolsEnabled { get; set; }

public GameHistoryDataResponse() { }
public GameHistoryDataResponse(byte[] historyBinaryData)
public GameHistoryDataResponse(byte[] historyBinaryData, bool sandboxToolsEnabled)
{
HistoryBinaryData = historyBinaryData;
SandboxToolsEnabled = sandboxToolsEnabled;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ public class GameHistoryResearchUpdatePacket
public int TechId { get; set; }
public long HashUploaded { get; set; }
public long HashNeeded { get; set; }
public int TechHashedFor10Frames { get; set; }

public GameHistoryResearchUpdatePacket() { }

public GameHistoryResearchUpdatePacket(int techId, long hashUploaded, long hashNeeded)
public GameHistoryResearchUpdatePacket(int techId, long hashUploaded, long hashNeeded, int techHashedFor10Frames)
{
TechId = techId;
HashUploaded = hashUploaded;
HashNeeded = hashNeeded;
TechHashedFor10Frames = techHashedFor10Frames;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
public class GameHistoryUnlockTechPacket
{
public int TechId { get; set; }
public int Level { get; set; }

public GameHistoryUnlockTechPacket() { }
public GameHistoryUnlockTechPacket(int techId)
public GameHistoryUnlockTechPacket(int techId, int level)
{
TechId = techId;
Level = level;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using NebulaAPI;
using NebulaModel.Packets.Factory.Belt;

namespace NebulaNetwork.PacketProcessors.Factory.Belt
{
[RegisterPacketProcessor]
internal class BeltReverseProcessor : BasePacketProcessor<BeltReversePacket>
{
public override void ProcessPacket(BeltReversePacket packet, INebulaConnection conn)
{
PlanetFactory factory = GameMain.galaxy.PlanetById(packet.PlanetId).factory;
if (factory == null)
return;

using (NebulaModAPI.MultiplayerSession.Factories.IsIncomingRequest.On())
{
NebulaModAPI.MultiplayerSession.Factories.EventFactory = factory;
NebulaModAPI.MultiplayerSession.Factories.TargetPlanet = packet.PlanetId;
if (NebulaModAPI.MultiplayerSession.LocalPlayer.IsHost)
{
// Load planet model
NebulaModAPI.MultiplayerSession.Factories.AddPlanetTimer(packet.PlanetId);
}

UIBeltWindow beltWindow = UIRoot.instance.uiGame.beltWindow;
beltWindow._Close(); // close the window first to avoid changing unwant variable when setting beltId
PlanetFactory tmpFactory = beltWindow.factory;
int tmpBeltId = beltWindow.beltId;
beltWindow.factory = factory;
beltWindow.beltId = packet.BeltId;
beltWindow.OnReverseButtonClick(0);
beltWindow.factory = tmpFactory;
beltWindow.beltId = tmpBeltId;

NebulaModAPI.MultiplayerSession.Factories.EventFactory = null;
NebulaModAPI.MultiplayerSession.Factories.TargetPlanet = NebulaModAPI.PLANET_NONE;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,9 @@ internal class BeltUpdatePutItemOnProcessor : PacketProcessor<BeltUpdatePutItemO
{
public override void ProcessPacket(BeltUpdatePutItemOnPacket packet, NebulaConnection conn)
{
using (Multiplayer.Session.Factories.IsIncomingRequest.On())
if (!Multiplayer.Session.Belts.TryPutItemOnBelt(packet))
{
CargoTraffic cargoTraffic = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.cargoTraffic;
if (cargoTraffic == null)
{
return;
}
if(packet.ItemCount == 1)
{
if (!cargoTraffic.PutItemOnBelt(packet.BeltId, packet.ItemId, packet.ItemInc))
{
Log.Warn($"BeltUpdatePutItemOn: Cannot put item{packet.ItemId} on belt{packet.BeltId}, planet{packet.PlanetId}");
}
}
else
{
bool ret = false;
if (cargoTraffic.beltPool[packet.BeltId].id != 0 && cargoTraffic.beltPool[packet.BeltId].id == packet.BeltId)
{
int index = cargoTraffic.beltPool[packet.BeltId].segIndex + cargoTraffic.beltPool[packet.BeltId].segPivotOffset;
ret = cargoTraffic.GetCargoPath(cargoTraffic.beltPool[packet.BeltId].segPathId).TryInsertItem(index, packet.ItemId, packet.ItemCount, packet.ItemInc);
}
if (!ret)
{
Log.Warn($"BeltUpdatePutItemOn: Cannot put item{packet.ItemId} on belt{packet.BeltId}, planet{packet.PlanetId}");
}
}
Multiplayer.Session.Belts.RegiserbeltPutdownPacket(packet);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NebulaAPI;
using NebulaModel.Packets.Factory.Inserter;

namespace NebulaNetwork.PacketProcessors.Factory.Inserter
{
[RegisterPacketProcessor]
internal class InserterOffsetCorrectionProcessor : BasePacketProcessor<InserterOffsetCorrectionPacket>
{
public override void ProcessPacket(InserterOffsetCorrectionPacket packet, INebulaConnection conn)
{
InserterComponent[] pool = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.factorySystem?.inserterPool;
if (pool != null)
{
NebulaModel.Logger.Log.Warn($"{packet.PlanetId} Fix inserter{packet.InserterId} pickOffset->{packet.PickOffset} insertOffset->{packet.InsertOffset}");
pool[packet.InserterId].pickOffset = packet.PickOffset;
pool[packet.InserterId].insertOffset = packet.InsertOffset;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using NebulaModel.Networking;
using NebulaModel.Packets;
using NebulaModel.Packets.Factory.Splitter;
using NebulaWorld;

namespace NebulaNetwork.PacketProcessors.Factory.Splitter
{
Expand All @@ -11,13 +10,11 @@ internal class SplitterPriorityChangeProcessor : PacketProcessor<SplitterPriorit
{
public override void ProcessPacket(SplitterPriorityChangePacket packet, NebulaConnection conn)
{
SplitterComponent[] pool = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.cargoTraffic?.splitterPool;
SplitterComponent[] pool = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.cargoTraffic.splitterPool;
if (pool != null && packet.SplitterIndex != -1 && packet.SplitterIndex < pool.Length && pool[packet.SplitterIndex].id != -1)
{
Multiplayer.Session.Storage.IsHumanInput = false;
pool[packet.SplitterIndex].SetPriority(packet.Slot, packet.IsPriority, packet.Filter);
Multiplayer.Session.Storage.IsHumanInput = true;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public override void ProcessPacket(GameHistoryDataResponse packet, NebulaConnect
{
GameMain.data.history.Import(reader.BinaryReader);
}
GameMain.sandboxToolsEnabled = packet.SandboxToolsEnabled;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using NebulaModel.Networking;
using NebulaModel.Packets;
using NebulaModel.Packets.GameHistory;
using NebulaWorld;

namespace NebulaNetwork.PacketProcessors.GameHistory
{
Expand All @@ -22,6 +23,7 @@ public override void ProcessPacket(GameHistoryResearchUpdatePacket packet, Nebul
state.hashUploaded = packet.HashUploaded;
state.hashNeeded = packet.HashNeeded;
data.techStates[data.currentTech] = state;
Multiplayer.Session.Statistics.TechHashedFor10Frames = packet.TechHashedFor10Frames;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,18 @@ internal class GameHistoryUnlockTechProcessor : PacketProcessor<GameHistoryUnloc
{
public override void ProcessPacket(GameHistoryUnlockTechPacket packet, NebulaConnection conn)
{
Log.Info($"Unlocking tech (ID: {packet.TechId})");
using (Multiplayer.Session.History.IsIncomingRequest.On())
{
// Let the default method give back the items
GameMain.mainPlayer.mecha.lab.ManageTakeback();

// Update techState
TechProto techProto = LDB.techs.Select(packet.TechId);
// Update techState
TechState techState = GameMain.history.techStates[packet.TechId];
if (techState.curLevel >= techState.maxLevel)
{
techState.curLevel = techState.maxLevel;
techState.hashUploaded = techState.hashNeeded;
techState.unlocked = true;
}
else
{
techState.curLevel++;
techState.hashUploaded = 0L;
techState.hashNeeded = techProto.GetHashNeeded(techState.curLevel);
}
// UnlockTech() unlocks tech to techState.maxLevel, so change it to curLevel temporarily
int maxLevl = techState.maxLevel;
techState.maxLevel = techState.curLevel;
GameMain.history.techStates[packet.TechId] = techState;
GameMain.history.UnlockTech(packet.TechId);
techState.maxLevel = maxLevl;
Log.Info($"Unlocking tech={packet.TechId} local:{techState.curLevel} remote:{packet.Level}");
techState.curLevel = packet.Level;
GameMain.history.techStates[packet.TechId] = techState;

GameMain.history.UnlockTechUnlimited(packet.TechId, false);
GameMain.history.DequeueTech();
}
}
Expand Down
11 changes: 6 additions & 5 deletions NebulaNetwork/PacketProcessors/Planet/VegeMinedProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ internal class VegeMinedProcessor : PacketProcessor<VegeMinedPacket>
{
public override void ProcessPacket(VegeMinedPacket packet, NebulaConnection conn)
{
if (GameMain.galaxy.PlanetById(packet.PlanetId)?.factory != null && GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.vegePool != null)
PlanetData planetData = GameMain.galaxy.PlanetById(packet.PlanetId);
PlanetFactory factory = planetData?.factory;
if (factory != null && factory?.vegePool != null)
{
using (Multiplayer.Session.Planets.IsIncomingRequest.On())
{
PlanetFactory factory = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory;
if (packet.Amount == 0 && factory != null)
{
if (packet.IsVein)
Expand All @@ -26,8 +27,8 @@ public override void ProcessPacket(VegeMinedPacket packet, NebulaConnection conn
VeinProto veinProto = LDB.veins.Select((int)veinData.type);

factory.RemoveVeinWithComponents(packet.VegeId);

if (veinProto != null)
if (veinProto != null && GameMain.localPlanet == planetData)
{
VFEffectEmitter.Emit(veinProto.MiningEffect, veinData.pos, Maths.SphericalRotation(veinData.pos, 0f));
VFAudio.Create(veinProto.MiningAudio, null, veinData.pos, true, 0, -1, -1L);
Expand All @@ -40,7 +41,7 @@ public override void ProcessPacket(VegeMinedPacket packet, NebulaConnection conn

factory.RemoveVegeWithComponents(packet.VegeId);

if (vegeProto != null)
if (vegeProto != null && GameMain.localPlanet == planetData)
{
VFEffectEmitter.Emit(vegeProto.MiningEffect, vegeData.pos, Maths.SphericalRotation(vegeData.pos, 0f));
VFAudio.Create(vegeProto.MiningAudio, null, vegeData.pos, true, 0, -1, -1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override void ProcessPacket(GlobalGameDataRequest packet, NebulaConnectio
using (BinaryUtils.Writer writer = new BinaryUtils.Writer())
{
GameMain.history.Export(writer.BinaryWriter);
conn.SendPacket(new GameHistoryDataResponse(writer.CloseAndGetBytes()));
conn.SendPacket(new GameHistoryDataResponse(writer.CloseAndGetBytes(), GameMain.sandboxToolsEnabled));
}

using (BinaryUtils.Writer writer = new BinaryUtils.Writer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public override void ProcessPacket(TrashSystemResponseDataPacket packet, NebulaC
{
GameMain.data.trashSystem.Import(reader.BinaryReader);
}
// Wait until WarningDataPacket to assign warningId
TrashContainer container = GameMain.data.trashSystem.container;
for (int i = 0; i < container.trashCursor; i++)
{
container.trashDataPool[i].warningId = -1;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,15 @@ namespace NebulaNetwork.PacketProcessors.Trash
[RegisterPacketProcessor]
internal class TrashSystemTrashRemovedProcessor : PacketProcessor<TrashSystemTrashRemovedPacket>
{
private readonly IPlayerManager playerManager;

public TrashSystemTrashRemovedProcessor()
{
playerManager = Multiplayer.Session.Network.PlayerManager;
}

public override void ProcessPacket(TrashSystemTrashRemovedPacket packet, NebulaConnection conn)
{
bool valid = true;

if (IsHost)
{
INebulaPlayer player = playerManager.GetPlayer(conn);
if (player != null)
{
playerManager.SendPacketToOtherPlayers(packet, player);
}
else
{
valid = false;
}
Multiplayer.Session.Network.PlayerManager.SendPacketToOtherPlayers(packet, conn);
}

if (valid)
using (Multiplayer.Session.Trashes.RemoveTrashFromOtherPlayers.On())
{
using (Multiplayer.Session.Trashes.RemoveTrashFromOtherPlayers.On())
{
GameMain.data.trashSystem.container.RemoveTrash(packet.TrashId);
}
GameMain.data.trashSystem.RemoveTrash(packet.TrashId);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion NebulaNetwork/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public override void Update()
if (GameMain.data.history.currentTech != 0)
{
TechState state = GameMain.data.history.techStates[GameMain.data.history.currentTech];
SendPacket(new GameHistoryResearchUpdatePacket(GameMain.data.history.currentTech, state.hashUploaded, state.hashNeeded));
SendPacket(new GameHistoryResearchUpdatePacket(GameMain.data.history.currentTech, state.hashUploaded, state.hashNeeded, GameMain.statistics.techHashedFor10Frames));
}
}

Expand Down
1 change: 1 addition & 0 deletions NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public static void GameTick_Postfix(GameData __instance, long time)
}

Multiplayer.Session.Couriers.GameTick();
Multiplayer.Session.Belts.GameTick();

if (Multiplayer.Session.LocalPlayer.IsHost)
{
Expand Down
Loading

0 comments on commit 8edc691

Please sign in to comment.