Skip to content

Commit

Permalink
Merge pull request #442 from hubastard/upgrade-0.8.21
Browse files Browse the repository at this point in the history
Support for DSP 0.8.21
  • Loading branch information
hubastard authored Sep 19, 2021
2 parents b636bdf + d327d56 commit 5fac1c1
Show file tree
Hide file tree
Showing 27 changed files with 430 additions and 251 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/thunderstore_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function generateManifest() {
function generateApiManifest() {
const manifest = {
name: apiPluginInfo.name,
description: "API for other mods to work with the Nebula Multiplayer Mod",
description: "API for other mods to work with the Nebula Multiplayer Mod. (Does NOT require Nebula)",
version_number: apiPluginInfo.version,
dependencies: [
BEPINEX_DEPENDENCY
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## Changelog

0.6.0:

- Fixed cases where a multiplayer session could hang on the player joining screen.
- Fixed issue where foundations built by clients would not sync to other clients.
- Fixed issue where the user would not be informed if they were kicked due to a mod mismatch.
- Enabled pausing in Multiplayer when no clients are connected. (thanks to @starfi5h)
- Now supports DSP version 0.8.21.8562+ (also thanks to @starfi5h!)
- Mecha color configuration has been removed from the options in favor of the new option in the Mecha panel

0.5.0:

- Added API that enables other mods to sync over multiplayer! (Big thanks to @kremnev8!)
Expand Down
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
</ItemGroup>

<ItemGroup Label="BepInEx">
<PackageReference Include="BepInEx.Core" Version="5.4.11" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.4.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.Analyzers" Version="1.0.*" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Label="Dyson Sphere Program">
<Reference Include="$(PropsheetPath)\Libs\Assembly-CSharp.dll" Private="false" SpecificVersion="true" />

<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-*" PrivateAssets="all" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.AnimationModule.dll" Private="false" SpecificVersion="true" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.CoreModule.dll" Private="false" SpecificVersion="true" />
Expand Down
Binary file removed Libs/Assembly-CSharp.dll
Binary file not shown.
5 changes: 5 additions & 0 deletions NebulaAPI/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

1.1.0:

- Float3 IPlayerData.MechaColor has been changed to Float4[] IPlayerData.MechaColors in line with changes introduced in DSP version 0.8.21.8562.
- Edited description.

1.0.0:

- initial release on thunderstore
34 changes: 34 additions & 0 deletions NebulaAPI/DataStructures/Float4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,40 @@ public Float4(Quaternion value)
w = value.w;
}

public Color ToColor()
{
return new Color(x, y, z, w);
}

public Color32 ToColor32()
{
return new Color32((byte)x, (byte)y, (byte)z, (byte)w);
}

public static Color32[] ToColor32(Float4[] float4s)
{
Color32[] color32s = new Color32[float4s.Length];
for (int i = 0; i < float4s.Length; i++)
{
color32s[i] = float4s[i].ToColor32();
}
return color32s;
}
public static Float4 ToFloat4(Color32 color32)
{
return new Float4(color32.r, color32.g, color32.b, color32.a);
}

public static Float4[] ToFloat4(Color32[] color32s)
{
Float4[] float4s = new Float4[color32s.Length];
for (int i = 0; i < color32s.Length; i++)
{
float4s[i] = new Float4(color32s[i].r, color32s[i].g, color32s[i].b, color32s[i].a);
}
return float4s;
}

public void Serialize(INetDataWriter writer)
{
writer.Put(x);
Expand Down
2 changes: 1 addition & 1 deletion NebulaAPI/GameState/IPlayerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public interface IPlayerData : INetSerializable
string Username { get; set; }
ushort PlayerId { get; set; }
int LocalPlanetId { get; set; }
Float3 MechaColor { get; set; }
Float4[] MechaColors { get; set; }
Float3 LocalPlanetPosition { get; set; }
Double3 UPosition { get; set; }
Float3 Rotation { get; set; }
Expand Down
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.0.0",
"version": "1.1.0",
"assemblyVersion": {
"precision": "build"
},
Expand Down
20 changes: 14 additions & 6 deletions NebulaModel/DataStructures/PlayerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class PlayerData : IPlayerData
public string Username { get; set; }
public ushort PlayerId { get; set; }
public int LocalPlanetId { get; set; }
public Float3 MechaColor { get; set; }
public Float4[] MechaColors { get; set; }
public Float3 LocalPlanetPosition { get; set; }
public Double3 UPosition { get; set; }
public Float3 Rotation { get; set; }
Expand All @@ -17,13 +17,13 @@ public class PlayerData : IPlayerData
public int LocalStarId { get; set; }

public PlayerData() { }
public PlayerData(ushort playerId, int localPlanetId, Float3 mechaColor, string username = null, Float3 localPlanetPosition = new Float3(), Double3 position = new Double3(), Float3 rotation = new Float3(), Float3 bodyRotation = new Float3())
public PlayerData(ushort playerId, int localPlanetId, Float4[] mechaColors, string username = null, Float3 localPlanetPosition = new Float3(), Double3 position = new Double3(), Float3 rotation = new Float3(), Float3 bodyRotation = new Float3())
{
PlayerId = playerId;
LocalPlanetId = localPlanetId;
MechaColors = mechaColors;
Username = !string.IsNullOrWhiteSpace(username) ? username : $"Player {playerId}";
LocalPlanetPosition = localPlanetPosition;
MechaColor = mechaColor;
UPosition = position;
Rotation = rotation;
BodyRotation = bodyRotation;
Expand All @@ -35,7 +35,11 @@ public void Serialize(INetDataWriter writer)
writer.Put(Username);
writer.Put(PlayerId);
writer.Put(LocalPlanetId);
MechaColor.Serialize(writer);
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 All @@ -48,7 +52,11 @@ public void Deserialize(INetDataReader reader)
Username = reader.GetString();
PlayerId = reader.GetUShort();
LocalPlanetId = reader.GetInt();
MechaColor = reader.GetFloat3();
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 All @@ -59,7 +67,7 @@ public void Deserialize(INetDataReader reader)

public IPlayerData CreateCopyWithoutMechaData()
{
return new PlayerData(PlayerId, LocalPlanetId, MechaColor, Username, LocalPlanetPosition, UPosition, Rotation, BodyRotation);
return new PlayerData(PlayerId, LocalPlanetId, MechaColors, Username, LocalPlanetPosition, UPosition, Rotation, BodyRotation);
}
}
}
49 changes: 35 additions & 14 deletions NebulaModel/MultiplayerOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NebulaModel.Attributes;
using NebulaAPI;
using NebulaModel.Attributes;
using System;
using System.ComponentModel;

Expand All @@ -10,18 +11,6 @@ public class MultiplayerOptions : ICloneable
[DisplayName("Nickname")]
public string Nickname { get; set; } = string.Empty;

[DisplayName("Mecha Color Red")]
[UIRange(0, 255, true)]
public float MechaColorR { get; set; } = 255;

[DisplayName("Mecha Color Green")]
[UIRange(0, 255, true)]
public float MechaColorG { get; set; } = 174;

[DisplayName("Mecha Color Blue")]
[UIRange(0, 255, true)]
public float MechaColorB { get; set; } = 61;

[DisplayName("Host Port")]
[UIRange(1, ushort.MaxValue)]
public ushort HostPort { get; set; } = 8469;
Expand All @@ -31,6 +20,38 @@ public class MultiplayerOptions : ICloneable

public string LastIP { get; set; } = string.Empty;

public string MechaColors { get; set; } = "209 151 76 255;184 90 72 255;94 92 92 255;123 234 255 255;229 155 94 255;255 243 235 255;255 248 245 255;255 255 255 255;";

public Float4[] GetMechaColors()
{
string[] colors = MechaColors.Split(';');
Float4[] mechaColors = new Float4[colors.Length - 1];
for (int i = 0; i < colors.Length - 1; i++)
{
string[] color = colors[i].Split(' ');
if (!float.TryParse(color[0], out mechaColors[i].x) ||
!float.TryParse(color[1], out mechaColors[i].y) ||
!float.TryParse(color[2], out mechaColors[i].z) ||
!float.TryParse(color[3], out mechaColors[i].w))
{
Logger.Log.Error($"Color {i} is invalid.");
}
}
return mechaColors;
}

public void SetMechaColors()
{
UnityEngine.Color32[] mainColors = GameMain.mainPlayer.mecha.mainColors;
string mechaColors = string.Empty;
for (int i = 0; i < mainColors.Length; i++)
{
mechaColors += $"{(int)mainColors[i].r} {(int)mainColors[i].g} {(int)mainColors[i].b} {(int)mainColors[i].a};";
}
MechaColors = mechaColors;
Config.SaveOptions();
}

// Detail function group buttons
public bool PowerGridEnabled { get; set; } = false;
public bool VeinDistributionEnabled { get; set; } = false;
Expand All @@ -41,7 +62,7 @@ public class MultiplayerOptions : ICloneable

public object Clone()
{
return this.MemberwiseClone();
return MemberwiseClone();
}
}
}
54 changes: 37 additions & 17 deletions NebulaModel/Packets/Players/PlayerAnimationUpdate.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
using NebulaAPI;
using NebulaModel.DataStructures;
using Unity;
using UnityEngine;

namespace NebulaModel.Packets.Players
{
[HidePacketInDebugLogs]
public class PlayerAnimationUpdate
{
public ushort PlayerId { get; set; }
public float JumpWeight { get; set; }
public float JumpNormalizedTime { get; set; }
public int IdleAnimIndex { get; set; }
public int SailAnimIndex { get; set; }
public float MiningWeight { get; set; }
public int MiningAnimIndex { get; set; }

// TODO: They don't use a finite state machine for there animation. But we need to find a way to optimized this packet.
// maybe we could only send the variables that are used to changed the animation state.
// See: (Game: PlayerAnimator class)
public NebulaAnimationState Idle { get; set; }
public NebulaAnimationState RunSlow { get; set; }
public NebulaAnimationState RunFast { get; set; }
public NebulaAnimationState Drift { get; set; }
public NebulaAnimationState DriftF { get; set; }
public NebulaAnimationState DriftL { get; set; }
public NebulaAnimationState DriftR { get; set; }
public NebulaAnimationState Fly { get; set; }
public NebulaAnimationState Sail { get; set; }
public NebulaAnimationState Mining0 { get; set; }
// some extra values to compute backpack flame size
// i put them here because i update the player fx together with the animation update
public float vertSpeed { get; set; }
public float horzSpeed { get; set; }
public EMovementState MovementState { get; set; }
public float HorzSpeed { get; set; }
public float VertSpeed { get; set; }
public float Turning { get; set; }
public float Altitude { get; set; }

public PlayerAnimationUpdate() { }

public PlayerAnimationUpdate(ushort playerId, PlayerAnimator animator)
{
PlayerId = playerId;

JumpWeight = animator.jumpWeight;
JumpNormalizedTime = animator.jumpNormalizedTime;
IdleAnimIndex = animator.idleAnimIndex;
SailAnimIndex = animator.sailAnimIndex;
MiningWeight = animator.miningWeight;
MiningAnimIndex = animator.miningAnimIndex;

MovementState = animator.movementState;
HorzSpeed = animator.controller.horzSpeed;
VertSpeed = animator.controller.vertSpeed;
Turning = animator.turning;
Altitude = 1f;
if (GameMain.localPlanet != null)
{
Altitude = Mathf.Clamp01((animator.player.position.magnitude - GameMain.localPlanet.realRadius - 7f) * 0.15f);
}
}
}
}
6 changes: 3 additions & 3 deletions NebulaModel/Packets/Players/PlayerColorChanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace NebulaModel.Packets.Players
public class PlayerColorChanged
{
public ushort PlayerId { get; set; }
public Float3 Color { get; set; }
public Float4[] Colors { get; set; }

public PlayerColorChanged() { }
public PlayerColorChanged(ushort playerID, Float3 color)
public PlayerColorChanged(ushort playerID, Float4[] colors)
{
PlayerId = playerID;
Color = color;
Colors = colors;
}
}
}
8 changes: 4 additions & 4 deletions NebulaModel/Packets/Session/HandshakeRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ namespace NebulaModel.Packets.Session
public class HandshakeRequest
{
public string Username { get; set; }
public Float3 MechaColor { get; set; }
public Float4[] MechaColors { get; set; }
public byte[] ModsVersion { get; set; }
public int ModsCount { get; set; }
public int GameVersionSig { get; set; }
public byte[] ClientCert { get; set; }

public HandshakeRequest() { }

public HandshakeRequest(byte[] clientCert, string username, Float3 mechaColor)
public HandshakeRequest(byte[] clientCert, string username, Float4[] mechaColors)
{
Username = username;
MechaColor = mechaColor;
MechaColors = mechaColors;

using (BinaryUtils.Writer writer = new BinaryUtils.Writer())
{
int count = 0;
foreach (var pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos)
foreach (System.Collections.Generic.KeyValuePair<string, BepInEx.PluginInfo> pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos)
{
if (pluginInfo.Value.Instance is IMultiplayerMod mod)
{
Expand Down
2 changes: 1 addition & 1 deletion NebulaNetwork/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void ClientSocket_OnOpen(object sender, System.EventArgs e)
SendPacket(new HandshakeRequest(
CryptoUtils.GetPublicKey(CryptoUtils.GetOrCreateUserCert()),
!string.IsNullOrWhiteSpace(Config.Options.Nickname) ? Config.Options.Nickname : GameMain.data.account.userName,
new Float3(Config.Options.MechaColorR / 255, Config.Options.MechaColorG / 255, Config.Options.MechaColorB / 255)));
Config.Options.GetMechaColors()));
}

private void ClientSocket_OnClose(object sender, CloseEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NebulaNetwork.PacketProcessors.Players
[RegisterPacketProcessor]
public class PlayerColorChangedProcessor : PacketProcessor<PlayerColorChanged>
{
private IPlayerManager playerManager;
private readonly IPlayerManager playerManager;

public PlayerColorChangedProcessor()
{
Expand All @@ -25,7 +25,7 @@ public override void ProcessPacket(PlayerColorChanged packet, NebulaConnection c
INebulaPlayer player = playerManager.GetPlayer(conn);
if (player != null)
{
player.Data.MechaColor = packet.Color;
player.Data.MechaColors = packet.Colors;
playerManager.SendPacketToOtherPlayers(packet, player);
}
else
Expand All @@ -36,7 +36,7 @@ public override void ProcessPacket(PlayerColorChanged packet, NebulaConnection c

if (valid)
{
Multiplayer.Session.World.UpdatePlayerColor(packet.PlayerId, packet.Color);
Multiplayer.Session.World.UpdatePlayerColor(packet.PlayerId, packet.Colors);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public override void ProcessPacket(HandshakeRequest packet, NebulaConnection con
player.Data.Username = !string.IsNullOrWhiteSpace(packet.Username) ? packet.Username : $"Player {player.Id}";

// Add the Mecha Color to the player data
player.Data.MechaColor = packet.MechaColor;
player.Data.MechaColors = packet.MechaColors;

// Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter
PlayerJoining pdata = new PlayerJoining((PlayerData)player.Data.CreateCopyWithoutMechaData()); // Remove inventory from mecha data
Expand Down
Loading

0 comments on commit 5fac1c1

Please sign in to comment.