Skip to content

Commit

Permalink
Merge pull request #581 from hubastard/upgrade-0.9.27
Browse files Browse the repository at this point in the history
fix compatibility with dsp 0.9.27.14659
  • Loading branch information
starfi5h authored Oct 6, 2022
2 parents fbc41a2 + f4fa42f commit 4cbbfd3
Show file tree
Hide file tree
Showing 44 changed files with 1,489 additions and 290 deletions.
4 changes: 2 additions & 2 deletions .github/scripts/thunderstore_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ function generateManifest() {
BEPINEX_DEPENDENCY,
`nebula-${apiPluginInfo.name}-${apiPluginInfo.version}`,
"PhantomGamers-IlLine-1.0.0",
"CommonAPI-CommonAPI-1.5.4",
"starfi5h-BulletTime-1.2.6",
"CommonAPI-CommonAPI-1.5.5",
"starfi5h-BulletTime-1.2.9",
],
website_url: "https://github.com/hubastard/nebula"
};
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Changelog

0.8.11:

- @starfi5h: Added support for DSP 0.9.27 along with syncing for the new logistics distribution system
- @starfi5h: Optimized network traffic
- @starfi5h: Dedicated servers will now save when gracefully exited (ctrl+c on the console window)
- @starfi5h: Fix error when sail capacity increases in dedicated server

0.8.10:

- @starfi5h: Fix compilation with 0.9.26.13034
Expand Down
5 changes: 5 additions & 0 deletions NebulaAPI/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## Changelog

1.3.1:

- Added DeliveryPackage to IMechaData and IPlayerTechBonuses

1.3.0:

- Add a new event OnDysonSphereLoadFinished to NebulaModAPI
Expand Down
1 change: 1 addition & 0 deletions NebulaAPI/DataStructures/IMechaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface IMechaData : INetSerializable
double CoreEnergy { get; set; }
double ReactorEnergy { get; set; }
StorageComponent Inventory { get; set; }
DeliveryPackage DeliveryPackage { get; set; }
StorageComponent ReactorStorage { get; set; }
StorageComponent WarpStorage { get; set; }
MechaForge Forge { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions NebulaAPI/DataStructures/IPlayerTechBonuses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ public interface IPlayerTechBonuses : INetSerializable
float droneSpeed { get; }
int droneMovement { get; }
int inventorySize { get; }
bool deliveryPackageUnlocked { get; }
int deliveryPackageColCount { get; set; }
int deliveryPackageStackSizeMultiplier { get; }
}
}
2 changes: 1 addition & 1 deletion NebulaAPI/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.3.0",
"version": "1.3.1",
"assemblyVersion": {
"precision": "build"
},
Expand Down
66 changes: 54 additions & 12 deletions NebulaModel/DataStructures/MechaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class MechaData : IMechaData
public double CoreEnergy { get; set; }
public double ReactorEnergy { get; set; }
public StorageComponent Inventory { get; set; }
public DeliveryPackage DeliveryPackage { get; set; }
public StorageComponent ReactorStorage { get; set; }
public StorageComponent WarpStorage { get; set; }
public MechaForge Forge { get; set; }
Expand All @@ -27,7 +28,7 @@ public MechaData()
TechBonuses = new PlayerTechBonuses();
}

public MechaData(int sandCount, double coreEnergy, double reactorEnergy, StorageComponent inventory, StorageComponent reactorStorage, StorageComponent warpStorage, MechaForge forge)
public MechaData(int sandCount, double coreEnergy, double reactorEnergy, StorageComponent inventory, DeliveryPackage deliveryPackage, StorageComponent reactorStorage, StorageComponent warpStorage, MechaForge forge)
{
SandCount = sandCount;
CoreEnergy = coreEnergy;
Expand All @@ -36,6 +37,7 @@ public MechaData(int sandCount, double coreEnergy, double reactorEnergy, Storage
WarpStorage = warpStorage;
Forge = forge;
Inventory = inventory;
DeliveryPackage = deliveryPackage;
TechBonuses = new PlayerTechBonuses();
}

Expand All @@ -48,26 +50,27 @@ public void Serialize(INetDataWriter writer)
writer.Put(ReactorStorage != null);
if (ReactorStorage != null)
{
using (MemoryStream ms = new MemoryStream())
using MemoryStream ms = new MemoryStream();
using (BinaryWriter wr = new BinaryWriter(ms))
{
using (BinaryWriter wr = new BinaryWriter(ms))
{
Inventory.Export(wr);
ReactorStorage.Export(wr);
WarpStorage.Export(wr);
Forge.Export(wr);
}
byte[] export = ms.ToArray();
writer.Put(export.Length);
writer.Put(export);
Inventory.Export(wr);
DeliveryPackage.Export(wr);
ReactorStorage.Export(wr);
WarpStorage.Export(wr);
Forge.Export(wr);
}
byte[] export = ms.ToArray();
writer.Put(export.Length);
writer.Put(export);
}
}

public void Deserialize(INetDataReader reader)
{
TechBonuses = new PlayerTechBonuses();
Inventory = new StorageComponent(4);
DeliveryPackage = new DeliveryPackage();
DeliveryPackage.Init();
ReactorStorage = new StorageComponent(4);
WarpStorage = new StorageComponent(1);
Forge = new MechaForge
Expand All @@ -89,6 +92,45 @@ public void Deserialize(INetDataReader reader)
using (BinaryReader br = new BinaryReader(ms))
{
Inventory.Import(br);
DeliveryPackage.Import(br);
ReactorStorage.Import(br);
WarpStorage.Import(br);
Forge.Import(br);
}
}
}

public void Import(INetDataReader reader, int revision)
{
TechBonuses = new PlayerTechBonuses();
Inventory = new StorageComponent(4);
DeliveryPackage = new DeliveryPackage();
DeliveryPackage.Init();
ReactorStorage = new StorageComponent(4);
WarpStorage = new StorageComponent(1);
Forge = new MechaForge
{
tasks = new List<ForgeTask>(),
extraItems = new ItemBundle()
};
TechBonuses.Import(reader, revision);
SandCount = reader.GetInt();
CoreEnergy = reader.GetDouble();
ReactorEnergy = reader.GetDouble();
bool isPayloadPresent = reader.GetBool();
if (isPayloadPresent)
{
int mechaLength = reader.GetInt();
byte[] mechaBytes = new byte[mechaLength];
reader.GetBytes(mechaBytes, mechaLength);
using (MemoryStream ms = new MemoryStream(mechaBytes))
using (BinaryReader br = new BinaryReader(ms))
{
Inventory.Import(br);
if (revision >= 7)
{
DeliveryPackage.Import(br);
}
ReactorStorage.Import(br);
WarpStorage.Import(br);
Forge.Import(br);
Expand Down
100 changes: 52 additions & 48 deletions NebulaModel/DataStructures/PlayerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ public class PlayerData : IPlayerData
public int[] DIYItemId { get; set; }
public int[] DIYItemValue { get; set; }

private Float4[] MechaColors { get; set; } //Obsoleted by MechaAppearance

public PlayerData()
{
Appearance = null;
DIYAppearance = null;
DIYItemId = new int[0];
DIYItemValue = new int[0];
DIYItemId = System.Array.Empty<int>();
DIYItemValue = System.Array.Empty<int>();
}
public PlayerData(ushort playerId, int localPlanetId, string username = null, Float3 localPlanetPosition = new Float3(), Double3 position = new Double3(), Float3 rotation = new Float3(), Float3 bodyRotation = new Float3())
{
Expand All @@ -41,20 +39,15 @@ public PlayerData()
Mecha = new MechaData();
Appearance = null;
DIYAppearance = null;
DIYItemId = new int[0];
DIYItemValue = new int[0];
DIYItemId = System.Array.Empty<int>();
DIYItemValue = System.Array.Empty<int>();
}

public void Serialize(INetDataWriter writer)
{
writer.Put(Username);
writer.Put(PlayerId);
writer.Put(LocalPlanetId);
writer.Put(MechaColors?.Length ?? 0);
for (int i = 0; i < (MechaColors?.Length ?? 0); i++)
{
MechaColors[i].Serialize(writer);
}
LocalPlanetPosition.Serialize(writer);
UPosition.Serialize(writer);
Rotation.Serialize(writer);
Expand Down Expand Up @@ -101,11 +94,6 @@ public void Deserialize(INetDataReader reader)
Username = reader.GetString();
PlayerId = reader.GetUShort();
LocalPlanetId = reader.GetInt();
MechaColors = new Float4[reader.GetInt()];
for (int i = 0; i < MechaColors.Length; i++)
{
MechaColors[i] = reader.GetFloat4();
}
LocalPlanetPosition = reader.GetFloat3();
UPosition = reader.GetDouble3();
Rotation = reader.GetFloat3();
Expand Down Expand Up @@ -150,54 +138,70 @@ public void Deserialize(INetDataReader reader)
}
}

public void Deserialize_5(INetDataReader reader)
// Backward compatiblity for older versions
public void Import(INetDataReader reader, int revision)
{
Username = reader.GetString();
PlayerId = reader.GetUShort();
LocalPlanetId = reader.GetInt();
MechaColors = new Float4[reader.GetInt()];
for (int i = 0; i < MechaColors.Length; i++)
if (revision < 7)
{
MechaColors[i] = reader.GetFloat4();
// MechaColors is obsoleted by MechaAppearance
Float4[] mechaColors = new Float4[reader.GetInt()];
for (int i = 0; i < mechaColors.Length; i++)
{
mechaColors[i] = reader.GetFloat4();
}
}
LocalPlanetPosition = reader.GetFloat3();
UPosition = reader.GetDouble3();
Rotation = reader.GetFloat3();
BodyRotation = reader.GetFloat3();
Mecha = new MechaData();
Mecha.Deserialize(reader);
bool isAppearancePresent = reader.GetBool();
if (isAppearancePresent)
MechaData mechaData = new();
mechaData.Import(reader, revision);
Mecha = mechaData;
if (revision >= 5)
{
int len = reader.GetInt();
byte[] data = new byte[len];
reader.GetBytes(data, len);
using (MemoryStream ms = new MemoryStream(data))
using (BinaryReader br = new BinaryReader(ms))
bool isAppearancePresent = reader.GetBool();
if (isAppearancePresent)
{
Appearance = new MechaAppearance();
Appearance.Init();
Appearance.Import(br);
int len = reader.GetInt();
byte[] data = new byte[len];
reader.GetBytes(data, len);
using (MemoryStream ms = new MemoryStream(data))
using (BinaryReader br = new BinaryReader(ms))
{
Appearance = new MechaAppearance();
Appearance.Init();
Appearance.Import(br);
}
}
}
}

public void Deserialize_4(INetDataReader reader)
{
Username = reader.GetString();
PlayerId = reader.GetUShort();
LocalPlanetId = reader.GetInt();
MechaColors = new Float4[reader.GetInt()];
for (int i = 0; i < MechaColors.Length; i++)
if (revision >= 6)
{
MechaColors[i] = reader.GetFloat4();
bool isDIYAppearancePresent = reader.GetBool();
if (isDIYAppearancePresent)
{
int len = reader.GetInt();
byte[] data = new byte[len];
reader.GetBytes(data, len);
using (MemoryStream ms = new MemoryStream(data))
using (BinaryReader br = new BinaryReader(ms))
{
DIYAppearance = new MechaAppearance();
DIYAppearance.Init();
DIYAppearance.Import(br);
}
}
int DIYItemLen = reader.GetInt();
DIYItemId = new int[DIYItemLen];
DIYItemValue = new int[DIYItemLen];
for (int i = 0; i < DIYItemLen; i++)
{
DIYItemId[i] = reader.GetInt();
DIYItemValue[i] = reader.GetInt();
}
}
LocalPlanetPosition = reader.GetFloat3();
UPosition = reader.GetDouble3();
Rotation = reader.GetFloat3();
BodyRotation = reader.GetFloat3();
Mecha = new MechaData();
Mecha.Deserialize(reader);
}

public IPlayerData CreateCopyWithoutMechaData()
Expand Down
4 changes: 4 additions & 0 deletions NebulaModel/Packets/Factory/CreatePrebuildsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private static void DeserializeBuildPreview(BuildPreview buildPreview, List<Buil
isAssembler = br.ReadBoolean(),
isBelt = br.ReadBoolean(),
isCollectStation = br.ReadBoolean(),
isDispenser = br.ReadBoolean(),
isEjector = br.ReadBoolean(),
isFractionator = br.ReadBoolean(),
isInserter = br.ReadBoolean(),
Expand All @@ -103,6 +104,7 @@ private static void DeserializeBuildPreview(BuildPreview buildPreview, List<Buil
isStellarStation = br.ReadBoolean(),
isStorage = br.ReadBoolean(),
isTank = br.ReadBoolean(),
isVeinCollector = br.ReadBoolean(),
minerType = (EMinerType)br.ReadInt32(),
modelIndex = br.ReadInt32(),
multiLevel = br.ReadBoolean(),
Expand Down Expand Up @@ -200,6 +202,7 @@ private static void SerializeBuildPreview(BuildPreview buildPreview, List<BuildP
bw.Write(buildPreview.desc.isAssembler);
bw.Write(buildPreview.desc.isBelt);
bw.Write(buildPreview.desc.isCollectStation);
bw.Write(buildPreview.desc.isDispenser);
bw.Write(buildPreview.desc.isEjector);
bw.Write(buildPreview.desc.isFractionator);
bw.Write(buildPreview.desc.isInserter);
Expand All @@ -210,6 +213,7 @@ private static void SerializeBuildPreview(BuildPreview buildPreview, List<BuildP
bw.Write(buildPreview.desc.isStellarStation);
bw.Write(buildPreview.desc.isStorage);
bw.Write(buildPreview.desc.isTank);
bw.Write(buildPreview.desc.isVeinCollector);
bw.Write((int)buildPreview.desc.minerType);
bw.Write(buildPreview.desc.modelIndex);
bw.Write(buildPreview.desc.multiLevel);
Expand Down
32 changes: 32 additions & 0 deletions NebulaModel/Packets/Logistics/DispenserAddTakePacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace NebulaModel.Packets.Logistics
{
public class DispenserAddTakePacket
{
public int PlanetId { get; set; }
public int EntityId { get; set; }
public EDispenserAddTakeEvent AddTakeEvent { get; set; }
public int ItemId { get; set; }
public int ItemCount { get; set; }
public int ItemInc { get; set; }

public DispenserAddTakePacket() { }
public DispenserAddTakePacket(int planetId, int entityId, EDispenserAddTakeEvent addTakeEvent, int itemId, int itemCount, int itemInc)
{
PlanetId = planetId;
EntityId = entityId;
AddTakeEvent = addTakeEvent;
ItemId = itemId;
ItemCount = itemCount;
ItemInc = itemInc;
}
}

public enum EDispenserAddTakeEvent
{
None,
ManualAdd,
ManualTake,
CourierAdd,
CourierTake
}
}
Loading

0 comments on commit 4cbbfd3

Please sign in to comment.