Skip to content

Commit b1e2225

Browse files
Merge pull request #489 from starfi5h/pr-dysonSphereStatus
2 parents 200d1cb + 48420dd commit b1e2225

File tree

11 files changed

+142
-58
lines changed

11 files changed

+142
-58
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Changelog
22

3+
0.7.6:
4+
5+
- @starfi5h: Added syncing of ray receiver output
6+
- @starfi5h: Fixed lighting of remote players
7+
- @starfi5h: Fixed clients receiving duplicate items when cancelling manual research
8+
39
0.7.5:
410

511
- @sp00ktober: Fixed error caused by warning system introduced in previous update

NebulaModel/DataStructures/DataStructureExtensions.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

NebulaModel/DataStructures/NebulaAnimationState.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace NebulaModel.Packets.Universe
2+
{
3+
public class DysonSphereStatusPacket
4+
{
5+
public int StarIndex { get; set; }
6+
public float GrossRadius { get; set; }
7+
public long EnergyReqCurrentTick { get; set; }
8+
public long EnergyGenCurrentTick { get; set; }
9+
10+
public DysonSphereStatusPacket() {}
11+
public DysonSphereStatusPacket(DysonSphere dysonSphere)
12+
{
13+
StarIndex = dysonSphere.starData.index;
14+
GrossRadius = dysonSphere.grossRadius;
15+
EnergyReqCurrentTick = dysonSphere.energyReqCurrentTick;
16+
EnergyGenCurrentTick = dysonSphere.energyGenCurrentTick;
17+
}
18+
}
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NebulaAPI;
2+
using NebulaModel.Networking;
3+
using NebulaModel.Packets;
4+
using NebulaModel.Packets.Universe;
5+
6+
namespace NebulaNetwork.PacketProcessors.Universe
7+
{
8+
[RegisterPacketProcessor]
9+
internal class DysonSphereStatusProcessor : PacketProcessor<DysonSphereStatusPacket>
10+
{
11+
public override void ProcessPacket(DysonSphereStatusPacket packet, NebulaConnection conn)
12+
{
13+
DysonSphere dysonSphere = GameMain.data.dysonSpheres[packet.StarIndex];
14+
if (IsHost || dysonSphere == null)
15+
{
16+
return;
17+
}
18+
dysonSphere.grossRadius = packet.GrossRadius;
19+
dysonSphere.energyReqCurrentTick = packet.EnergyReqCurrentTick;
20+
dysonSphere.energyGenCurrentTick = packet.EnergyGenCurrentTick;
21+
}
22+
}
23+
}

NebulaNetwork/Server.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using NebulaModel.Networking.Serialization;
77
using NebulaModel.Packets.GameHistory;
88
using NebulaModel.Packets.GameStates;
9+
using NebulaModel.Packets.Universe;
910
using NebulaModel.Utils;
1011
using NebulaWorld;
1112
using System.Net.Sockets;
@@ -22,11 +23,13 @@ public class Server : NetworkProvider
2223
private const float GAME_RESEARCH_UPDATE_INTERVAL = 2;
2324
private const float STATISTICS_UPDATE_INTERVAL = 1;
2425
private const float LAUNCH_UPDATE_INTERVAL = 2;
26+
private const float DYSONSPHERE_UPDATE_INTERVAL = 5;
2527

2628
private float gameStateUpdateTimer = 0;
2729
private float gameResearchHashUpdateTimer = 0;
2830
private float productionStatisticsUpdateTimer = 0;
29-
private float dysonLaunchUpateTimer = 0;
31+
private float dysonLaunchUpateTimer = 1;
32+
private float dysonSphereUpdateTimer = 0;
3033

3134
private WebSocketServer socket;
3235

@@ -125,6 +128,7 @@ public override void Update()
125128
gameResearchHashUpdateTimer += Time.deltaTime;
126129
productionStatisticsUpdateTimer += Time.deltaTime;
127130
dysonLaunchUpateTimer += Time.deltaTime;
131+
dysonSphereUpdateTimer += Time.deltaTime;
128132

129133
if (gameStateUpdateTimer > GAME_STATE_UPDATE_INTERVAL)
130134
{
@@ -154,6 +158,19 @@ public override void Update()
154158
Multiplayer.Session.Launch.SendBroadcastIfNeeded();
155159
}
156160

161+
if (dysonSphereUpdateTimer > DYSONSPHERE_UPDATE_INTERVAL)
162+
{
163+
dysonSphereUpdateTimer = 0;
164+
DysonSphere[] dysonSpheres = GameMain.data.dysonSpheres;
165+
for (int i = 0; i < dysonSpheres.Length; i++)
166+
{
167+
if (dysonSpheres[i] != null)
168+
{
169+
SendPacketToStar(new DysonSphereStatusPacket(dysonSpheres[i]), dysonSpheres[i].starData.id);
170+
}
171+
}
172+
}
173+
157174
PacketProcessor.ProcessPacketQueue();
158175
}
159176

NebulaPatcher/Patches/Dynamic/DysonSphere_Patch.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,47 @@ namespace NebulaPatcher.Patches.Dynamic
99
[HarmonyPatch(typeof(DysonSphere))]
1010
internal class DysonSphere_Patch
1111
{
12+
[HarmonyPrefix]
13+
[HarmonyPatch(nameof(DysonSphere.BeforeGameTick))]
14+
public static bool BeforeGameTick_Prefix(DysonSphere __instance, long times)
15+
{
16+
if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost)
17+
{
18+
return true;
19+
}
20+
//Update swarm and layer energy generation stats every 120 frames
21+
if (times % 120 == 0)
22+
{
23+
__instance.swarm.energyGenCurrentTick = __instance.swarm.sailCount * __instance.energyGenPerSail;
24+
for (int i = 0; i < 10; i++)
25+
{
26+
DysonSphereLayer dysonSphereLayer = __instance.layersSorted[i];
27+
if (dysonSphereLayer != null)
28+
{
29+
dysonSphereLayer.energyGenCurrentTick = 0L;
30+
DysonNode[] nodePool = dysonSphereLayer.nodePool;
31+
DysonShell[] shellPool = dysonSphereLayer.shellPool;
32+
for (int j = 1; j < dysonSphereLayer.nodeCursor; j++)
33+
{
34+
if (nodePool[j] != null && nodePool[j].id == j)
35+
{
36+
dysonSphereLayer.energyGenCurrentTick += nodePool[j].EnergyGenCurrentTick(__instance.energyGenPerNode, __instance.energyGenPerFrame, 0L);
37+
}
38+
}
39+
for (int k = 1; k < dysonSphereLayer.shellCursor; k++)
40+
{
41+
if (shellPool[k] != null && shellPool[k].id == k)
42+
{
43+
dysonSphereLayer.energyGenCurrentTick += shellPool[k].cellPoint * __instance.energyGenPerShell;
44+
}
45+
}
46+
}
47+
}
48+
}
49+
//Sync other Dyson sphere status related to ray receivers on client side by DysonSphereStatusPacket
50+
return false;
51+
}
52+
1253
[HarmonyPrefix]
1354
[HarmonyPatch(nameof(DysonSphere.AddLayer))]
1455
public static bool AddLayer_Prefix(DysonSphere __instance, float orbitRadius, Quaternion orbitRotation, float orbitAngularSpeed)

NebulaPatcher/Patches/Dynamic/GameHistoryData_Patch.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,5 @@ public static bool UnlockTech_Prefix()
148148
//Wait for the authoritative packet for unlocking tech features in multiplayer for clients
149149
return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost || Multiplayer.Session.History.IsIncomingRequest;
150150
}
151-
152-
[HarmonyPrefix]
153-
[HarmonyPatch(nameof(GameHistoryData.RemoveTechInQueue))]
154-
public static void RemoveTechInQueue_Prefix(int index, out int __state)
155-
{
156-
__state = GameMain.history.techQueue[index];
157-
if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost)
158-
{
159-
//we need to know which itemtypes are currently needed for refunds, so trigger refund before cancelling own research
160-
Multiplayer.Session.Network.PlayerManager.SendTechRefundPackagesToClients(__state);
161-
}
162-
Log.Info($"RemoveTechInQueue: remove tech at index {index} with techId { __state}");
163-
}
164151
}
165152
}

NebulaPatcher/Patches/Transpilers/PowerSystem_Transpiler.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using HarmonyLib;
22
using NebulaModel.Packets.Factory.PowerTower;
33
using NebulaWorld;
4+
using System;
45
using System.Collections.Generic;
56
using System.Reflection.Emit;
67

@@ -126,5 +127,36 @@ public static IEnumerable<CodeInstruction> PowerSystem_GameTick_Transpiler(IEnum
126127
})
127128
.InstructionEnumeration();
128129
}
130+
131+
[HarmonyTranspiler]
132+
[HarmonyPatch(nameof(PowerSystem.RequestDysonSpherePower))]
133+
public static IEnumerable<CodeInstruction> PowerSystem_RequestDysonSpherePower_Transpiler(IEnumerable<CodeInstruction> instructions)
134+
{
135+
//Prevent dysonSphere.energyReqCurrentTick from changing on the client side
136+
//Change: if (this.dysonSphere != null)
137+
//To: if (this.dysonSphere != null && (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost))
138+
try
139+
{
140+
CodeMatcher codeMatcher = new CodeMatcher(instructions)
141+
.MatchForward(true,
142+
new CodeMatch(OpCodes.Ldarg_0),
143+
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PowerSystem), "dysonSphere")),
144+
new CodeMatch(OpCodes.Brfalse) //IL #93
145+
);
146+
object label = codeMatcher.Instruction.operand;
147+
codeMatcher.Advance(1)
148+
.InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate<Func<bool>>(() =>
149+
{
150+
return !Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost;
151+
}))
152+
.InsertAndAdvance(new CodeInstruction(OpCodes.Brfalse_S, label));
153+
return codeMatcher.InstructionEnumeration();
154+
}
155+
catch
156+
{
157+
NebulaModel.Logger.Log.Error("PowerSystem.RequestDysonSpherePower_Transpiler failed. Mod version not compatible with game version.");
158+
return instructions;
159+
}
160+
}
129161
}
130162
}

NebulaWorld/MonoBehaviours/Remote/RemotePlayerAnimation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public void AnimateSailState(PlayerAnimator animator)
128128
public void AnimateRenderers(PlayerAnimator animator)
129129
{
130130
animator.player.mechaArmorModel.inst_armor_mat.SetVector("_InitPositionSet", transform.position);
131+
animator.player.mechaArmorModel.inst_part_ar_mat.SetVector("_InitPositionSet", transform.position);
132+
animator.player.mechaArmorModel.inst_part_sk_mat.SetVector("_InitPositionSet", transform.position);
131133
}
132134
}
133135
}

0 commit comments

Comments
 (0)