Skip to content

Commit

Permalink
Merge pull request #607 from starfi5h/pr-bugfix0.8.13
Browse files Browse the repository at this point in the history
Bugfix for nebula 0.8.13
  • Loading branch information
starfi5h authored Jul 9, 2023
2 parents 8e6748a + 0c4d446 commit 525ffac
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 14 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
## Changelog

0.8.14:
- @starfi5h: Fix mecha animation when player count > 2
- @starfi5h: Fix UIPerformance save test in multiplayer
- @starfi5h: Disable build/dismantle sounds when too far away
- @starfi5h: Convert strings to string.Translate() to enable translation

<details>
<summary>All changes</summary>

0.8.13:

- @starfi5h: Fix compilation with 0.9.27.15466
- @starfi5h: Add -newgame launch option for dedicated server

<details>
<summary>All changes</summary>

0.8.12:

- @PhantomGamers: Remove exe targeting to support game pass version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ namespace NebulaNetwork.PacketProcessors.Factory.Foundation
[RegisterPacketProcessor]
internal class FoundationBuildUpdateProcessor : PacketProcessor<FoundationBuildUpdatePacket>
{
private readonly Vector3[] reformPoints = new Vector3[100];
private Vector3[] reformPoints = new Vector3[100];

public override void ProcessPacket(FoundationBuildUpdatePacket packet, NebulaConnection conn)
{
PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId);
PlanetFactory factory = IsHost ? GameMain.data.GetOrCreateFactory(planet) : planet?.factory;
if (factory != null)
{
// Increase reformPoints for mods that increase brush size over 10
if (packet.ReformSize * packet.ReformSize > reformPoints.Length)
{
reformPoints = new Vector3[packet.ReformSize * packet.ReformSize];
}
Array.Clear(reformPoints, 0, reformPoints.Length);

//Check if some mandatory variables are missing
Expand Down
50 changes: 50 additions & 0 deletions NebulaPatcher/Patches/Dynamic/FactoryAudio_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using HarmonyLib;
using NebulaWorld;
using UnityEngine;

namespace NebulaPatcher.Patches.Dynamic
{
[HarmonyPatch(typeof(FactoryAudio))]
class FactoryAudio_Patch
{
[HarmonyPrefix]
[HarmonyPatch(nameof(FactoryAudio.OnEntityBuild))]
public static bool OnEntityBuild_Prefix(FactoryAudio __instance, int objId)
{
if (Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest.Value && objId > 0)
{
Vector3 pos = __instance.planet.factory.entityPool[objId].pos;
if ((pos - GameMain.mainPlayer.position).sqrMagnitude > (__instance.planet.radius * __instance.planet.radius / 4))
{
// Don't make sounds if distance is over half of the planet radius
return false;
}
}
return true;
}

[HarmonyPrefix]
[HarmonyPatch(nameof(FactoryAudio.OnEntityDismantle))]
public static bool OnEntityDismantle_Prefix(FactoryAudio __instance, int objId)
{
if (Multiplayer.IsActive && Multiplayer.Session.Factories.IsIncomingRequest.Value)
{
Vector3 pos;
if (objId > 0)
{
pos = __instance.planet.factory.entityPool[objId].pos;
}
else
{
pos = __instance.planet.factory.prebuildPool[-objId].pos;
}
if ((pos - GameMain.mainPlayer.position).sqrMagnitude > (__instance.planet.radius * __instance.planet.radius / 4))
{
// Don't make sounds if distance is over half of the planet radius
return false;
}
}
return true;
}
}
}
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/GameSave_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static bool SaveCurrentGame_Prefix(string saveName)
}

// Only save if in single player or if you are the host
return (!Multiplayer.IsActive && !Multiplayer.IsLeavingGame) || Multiplayer.Session.LocalPlayer.IsHost;
return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost;
}

[HarmonyPostfix]
Expand Down
23 changes: 23 additions & 0 deletions NebulaPatcher/Patches/Dynamic/UIPerformancePanel_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using HarmonyLib;
using NebulaWorld;

namespace NebulaPatcher.Patches.Dynamic
{
[HarmonyPatch(typeof(UIPerformancePanel))]
internal class UIPerformancePanel_Patch
{
[HarmonyPrefix]
[HarmonyPatch(nameof(UIPerformancePanel.OnDataActiveButtonClick))]
public static bool OnDataActiveButtonClick_Prefix(UIPerformancePanel __instance)
{
if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost)
{
// Replace SaveAsLastExit() because it only triggers on UI exit in multiplayer mode
GameSave.SaveCurrentGame(GameSave.LastExit);
__instance.RefreshDataStatTexts();
return false;
}
return true;
}
}
}
36 changes: 31 additions & 5 deletions NebulaWorld/MonoBehaviours/Remote/RemotePlayerAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ namespace NebulaWorld.MonoBehaviours.Remote
// TODO: Missing client side interpolation
public class RemotePlayerAnimation : MonoBehaviour
{
public struct Snapshot
{
public EMovementState MovementState { get; set; }
public float HorzSpeed { get; set; }
public float VertSpeed { get; set; }
public float Turning { get; set; }
public float JumpWeight { get; set; }
public float JumpNormalizedTime { get; set; }
public byte IdleAnimIndex { get; set; }
public byte MiningAnimIndex { get; set; }
public float MiningWeight { get; set; }
public PlayerMovement.EFlags Flags { get; set; }
}

public PlayerAnimator PlayerAnimator;
private RemotePlayerMovement rootMovement;
private RemotePlayerEffects remotePlayerEffects;
private float altitudeFactor;
private readonly PlayerMovement[] packetBuffer = new PlayerMovement[3];
private readonly Snapshot[] packetBuffer = new Snapshot[3];

private void Awake()
{
Expand All @@ -26,13 +40,25 @@ public void UpdateState(PlayerMovement packet)
{
packetBuffer[i] = packetBuffer[i + 1];
}
packetBuffer[packetBuffer.Length - 1] = packet;
packetBuffer[packetBuffer.Length - 1] = new Snapshot()
{
MovementState = packet.MovementState,
HorzSpeed = packet.HorzSpeed,
VertSpeed = packet.VertSpeed,
Turning = packet.Turning,
JumpWeight = packet.JumpWeight,
JumpNormalizedTime = packet.JumpNormalizedTime,
IdleAnimIndex = packet.IdleAnimIndex,
MiningAnimIndex = packet.MiningAnimIndex,
MiningWeight = packet.MiningWeight,
Flags = packet.Flags
};
}

private void Update()
{
PlayerMovement packet = packetBuffer[0];
if (packet == null || PlayerAnimator == null)
ref Snapshot packet = ref packetBuffer[0];
if (PlayerAnimator == null)
{
return;
}
Expand Down Expand Up @@ -72,7 +98,7 @@ private void Update()
PlayerAnimator.AnimateSkills(deltaTime);
AnimateRenderers(PlayerAnimator);

remotePlayerEffects.UpdateState(packet);
remotePlayerEffects.UpdateState(ref packet);
}

private void CalculateMovementStateWeights(PlayerAnimator animator, float dt)
Expand Down
6 changes: 3 additions & 3 deletions NebulaWorld/MonoBehaviours/Remote/RemotePlayerEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ private bool CheckPlayerInReform()
}

// collision with vegetation, landing sound effect
private void UpdateExtraSoundEffects(PlayerMovement packet)
private void UpdateExtraSoundEffects(ref RemotePlayerAnimation.Snapshot packet)
{
if (rootMovement.localPlanetId < 0)
{
Expand Down Expand Up @@ -550,7 +550,7 @@ private void UpdateExtraSoundEffects(PlayerMovement packet)
vegeCollideColdTime = (vegeCollideColdTime > 0) ? vegeCollideColdTime - Time.deltaTime * 2 : 0;
}

public void UpdateState(PlayerMovement packet)
public void UpdateState(ref RemotePlayerAnimation.Snapshot packet)
{
bool runActive = rootAnimation.runWeight > 0.001f;
bool driftActive = rootAnimation.driftWeight > 0.001f;
Expand All @@ -562,7 +562,7 @@ public void UpdateState(PlayerMovement packet)

if (runActive || !isGrounded || maxAltitude > 0)
{
UpdateExtraSoundEffects(packet);
UpdateExtraSoundEffects(ref packet);
}
if (runActive && isGrounded)
{
Expand Down
2 changes: 1 addition & 1 deletion 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": "0.8.13",
"version": "0.8.14",
"assemblyVersion": {
"precision": "build"
},
Expand Down

0 comments on commit 525ffac

Please sign in to comment.