Skip to content

Commit

Permalink
Merge pull request #665 from starfi5h/pr-fix22010
Browse files Browse the repository at this point in the history
Bugfixes (Game version 0.10.29.22010)
  • Loading branch information
starfi5h authored Mar 23, 2024
2 parents a108ac0 + 28441bf commit 4d6bfcb
Show file tree
Hide file tree
Showing 15 changed files with 299 additions and 15 deletions.
17 changes: 17 additions & 0 deletions NebulaModel/Packets/Combat/CombatStatFullHpPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace NebulaModel.Packets.Combat;

public class CombatStatFullHpPacket
{
public CombatStatFullHpPacket() { }

public CombatStatFullHpPacket(int originAstroId, int objectType, int objectId)
{
OriginAstroId = originAstroId;
ObjectType = objectType;
ObjectId = objectId;
}

public int OriginAstroId { get; set; }
public int ObjectType { get; set; }
public int ObjectId { get; set; }
}
7 changes: 7 additions & 0 deletions NebulaModel/Packets/Combat/DFRelay/DFRelayArriveBasePacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ public DFRelayArriveBasePacket(in DFRelayComponent dFRelay)
HiveAstroId = dFRelay.hiveAstroId;
RelayId = dFRelay.id;
HiveRtseed = dFRelay.hive.rtseed;

var factory = dFRelay.hive.galaxy.astrosFactory[dFRelay.targetAstroId];
if (factory != null)
{
NextGroundEnemyId = factory.enemyRecycleCursor > 0 ? factory.enemyRecycle[factory.enemyRecycleCursor - 1] : factory.enemyCursor;
}
}

public int HiveAstroId { get; set; }
public int RelayId { get; set; }
public int HiveRtseed { get; set; }
public int NextGroundEnemyId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using NebulaAPI.DataStructures;

namespace NebulaModel.Packets.Combat.DFRelay;

public class DFRelayRealizePlanetBasePacket
{
public DFRelayRealizePlanetBasePacket() { }

public DFRelayRealizePlanetBasePacket(in DFRelayComponent dFRelay)
{
HiveAstroId = dFRelay.hiveAstroId;
RelayId = dFRelay.id;
RelayNeutralizedCounter = dFRelay.hive.relayNeutralizedCounter;
HiveSeed = dFRelay.hive.seed;
HiveRtseed = dFRelay.hive.rtseed;
TargetAstroId = dFRelay.targetAstroId;
TargetLPos = dFRelay.targetLPos.ToFloat3();
TargetYaw = dFRelay.targetYaw;
BaseTicks = dFRelay.baseTicks;

var factory = dFRelay.hive.galaxy.astrosFactory[dFRelay.targetAstroId];
if (factory != null)
{
EnemyCursor = factory.enemyCursor;
EnemyRecyle = new int[factory.enemyRecycleCursor];
Array.Copy(factory.enemyRecycle, EnemyRecyle, EnemyRecyle.Length);
}
else
{
EnemyCursor = -1;
EnemyRecyle = [];
}
}

public int HiveAstroId { get; set; }
public int RelayId { get; set; }
public int RelayNeutralizedCounter { get; set; }
public int HiveSeed { get; set; }
public int HiveRtseed { get; set; }
public int TargetAstroId { get; set; }
public Float3 TargetLPos { get; set; }
public float TargetYaw { get; set; }
public int BaseTicks { get; set; }
public int EnemyCursor { get; set; }
public int[] EnemyRecyle { get; set; }
}
62 changes: 62 additions & 0 deletions NebulaNetwork/PacketProcessors/Combat/CombatStatFullHpProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#region

using NebulaAPI.Packets;
using NebulaModel.Networking;
using NebulaModel.Packets;
using NebulaModel.Packets.Combat;
using NebulaWorld;

#endregion

namespace NebulaNetwork.PacketProcessors.Combat;

[RegisterPacketProcessor]
public class CombatStatFullHpProcessor : PacketProcessor<CombatStatFullHpPacket>
{
protected override void ProcessPacket(CombatStatFullHpPacket packet, NebulaConnection conn)
{
var combatStatId = 0;
var starId = 0;
if (packet.OriginAstroId > 100 && packet.OriginAstroId <= 204899 && packet.OriginAstroId % 100 > 0)
{
var planetFactory = GameMain.spaceSector.skillSystem.astroFactories[packet.OriginAstroId];
if (planetFactory != null)
{
starId = packet.OriginAstroId / 100;

if (packet.ObjectType == 0 && packet.ObjectId < planetFactory.entityPool.Length)
{
combatStatId = planetFactory.entityPool[packet.ObjectId].combatStatId;
planetFactory.entityPool[packet.ObjectId].combatStatId = 0;
}
}
}

var skillSystem = GameMain.spaceSector.skillSystem;
if (combatStatId > 0 && combatStatId < skillSystem.combatStats.cursor)
{
ref var combatStatRef = ref skillSystem.combatStats.buffer[combatStatId];
if (combatStatRef.id == combatStatId)
{
if (IsHost && combatStatRef.warningId > 0)
{
GameMain.data.warningSystem.RemoveWarningData(combatStatRef.warningId);
}
skillSystem.OnRemovingSkillTarget(combatStatRef.id, combatStatRef.originAstroId, ETargetType.CombatStat);
skillSystem.combatStats.Remove(combatStatRef.id);
}
}

if (IsHost)
{
if (starId > 0)
{
Multiplayer.Session.Server.SendPacketToStarExclude(packet, starId, conn);
}
else
{
Multiplayer.Session.Server.SendPacketExclude(packet, conn);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NebulaModel.Packets;
using NebulaModel.Packets.Combat.DFRelay;
using NebulaWorld;
using NebulaWorld.Combat;

#endregion

Expand Down Expand Up @@ -33,7 +34,16 @@ protected override void ProcessPacket(DFRelayArriveBasePacket packet, NebulaConn
{
hiveSystem.rtseed = packet.HiveRtseed;
dfrelayComponent.stage = 2;
dfrelayComponent.ArriveBase();
using (Multiplayer.Session.Combat.IsIncomingRequest.On())
{
var factory = dfrelayComponent.hive.galaxy.astrosFactory[dfrelayComponent.targetAstroId];
if (factory != null)
{
// Prepare enemyId in CreateEnemyPlanetBase
EnemyManager.SetPlanetFactoryNextEnemyId(factory, packet.NextGroundEnemyId);
}
dfrelayComponent.ArriveBase();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#region

using NebulaAPI.DataStructures;
using NebulaAPI.Packets;
using NebulaModel.Networking;
using NebulaModel.Packets;
using NebulaModel.Packets.Combat.DFRelay;
using NebulaWorld;
using NebulaWorld.Combat;

#endregion

namespace NebulaNetwork.PacketProcessors.Combat.DFRelay;

[RegisterPacketProcessor]
public class DFRelayRealizePlanetBaseProcessor : PacketProcessor<DFRelayRealizePlanetBasePacket>
{
protected override void ProcessPacket(DFRelayRealizePlanetBasePacket packet, NebulaConnection conn)
{
var hiveSystem = GameMain.spaceSector.GetHiveByAstroId(packet.HiveAstroId);
if (hiveSystem == null) return;

var dfrelayComponent = hiveSystem.relays.buffer[packet.RelayId];
if (dfrelayComponent?.id != packet.RelayId) return;

dfrelayComponent.hive.relayNeutralizedCounter = packet.RelayNeutralizedCounter;
dfrelayComponent.hive.seed = packet.HiveSeed;
dfrelayComponent.hive.rtseed = packet.HiveRtseed;
dfrelayComponent.targetAstroId = packet.TargetAstroId;
dfrelayComponent.targetLPos = packet.TargetLPos.ToVector3();
dfrelayComponent.targetYaw = packet.TargetYaw;
dfrelayComponent.baseTicks = packet.BaseTicks;

using (Multiplayer.Session.Enemies.IsIncomingRelayRequest.On())
{
using (Multiplayer.Session.Combat.IsIncomingRequest.On())
{
var factory = dfrelayComponent.hive.galaxy.astrosFactory[dfrelayComponent.targetAstroId];
if (factory != null && packet.EnemyCursor != -1)
{
// Prepare enemyIds in CreateEnemyPlanetBase
EnemyManager.SetPlanetFactoryRecycle(factory, packet.EnemyCursor, packet.EnemyRecyle);
}
dfrelayComponent.RealizePlanetBase(GameMain.spaceSector);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ protected override void ProcessPacket(TurretSuperNovaPacket packet, NebulaConnec
{
return;
}
uiTurret.supernovaWait = packet.SetSuperNova;
if (refTurret.inSupernova)
{
GameMain.gameScenario.NotifyOnSupernovaUITriggered();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,19 @@ static void OnPlanetFactoryLoad(PlanetData planet)
}
enemyDFHiveSystem = enemyDFHiveSystem.nextSibling;
}

// Set entities (building) on the planet to full health
// Note: Try to sync the current value in the future
var astroId = planet.astroId;
var combatStatCursor = spaceSector.skillSystem.combatStats.cursor;
var buffer = spaceSector.skillSystem.combatStats.buffer;
for (var id = 1; id < combatStatCursor; id++)
{
if (buffer[id].id == id && buffer[id].astroId == astroId && buffer[id].objectType == 0)
{
buffer[id].HandleFullHp(GameMain.data, spaceSector.skillSystem);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ protected override void ProcessPacket(DysonSphereStatusPacket packet, NebulaConn
{
return;
}
// Replace some values set in DysonSphere.BeforeGameTick
dysonSphere.grossRadius = packet.GrossRadius;
dysonSphere.energyReqCurrentTick = packet.EnergyReqCurrentTick;
dysonSphere.energyGenCurrentTick = packet.EnergyGenCurrentTick;
dysonSphere.energyGenOriginalCurrentTick = (long)(dysonSphere.energyGenCurrentTick / dysonSphere.energyDFHivesDebuffCoef);
}
}
23 changes: 23 additions & 0 deletions NebulaPatcher/Patches/Dynamic/CombatStat_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#region

using HarmonyLib;
using NebulaModel.Packets.Combat;
using NebulaWorld;

#endregion
Expand All @@ -27,4 +28,26 @@ public static void TickSkillLogic_Prefix(ref CombatStat __instance)
}
}
}

[HarmonyPrefix]
[HarmonyPatch(nameof(CombatStat.HandleFullHp))]
public static void HandleFullHp_Prefix(ref CombatStat __instance)
{
if (!Multiplayer.IsActive) return;

// objectType 0:entity
if (__instance.objectType == 0 && __instance.originAstroId > 100 && __instance.originAstroId <= 204899 && __instance.originAstroId % 100 > 0)
{
var packet = new CombatStatFullHpPacket(__instance.originAstroId, __instance.objectType, __instance.objectId);
if (Multiplayer.Session.IsServer)
{
var starId = __instance.originAstroId / 100;
Multiplayer.Session.Server.SendPacketToStar(packet, starId);
}
else
{
Multiplayer.Session.Client.SendPacket(packet);
}
}
}
}
11 changes: 11 additions & 0 deletions NebulaPatcher/Patches/Dynamic/DFRelayComponent_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ public static bool SearchTargetPlaceProcess_Prefix()
return false;
}

[HarmonyPrefix]
[HarmonyPatch(nameof(DFRelayComponent.RealizePlanetBase))]
public static bool RealizePlanetBase_Prefix(DFRelayComponent __instance)
{
if (!Multiplayer.IsActive) return true;
if (Multiplayer.Session.IsClient) return Multiplayer.Session.Enemies.IsIncomingRelayRequest;

Multiplayer.Session.Network.SendPacket(new DFRelayRealizePlanetBasePacket(__instance));
return true;
}

[HarmonyPrefix]
[HarmonyPatch(nameof(DFRelayComponent.ArriveBase))]
public static bool ArriveBase_Prefix(DFRelayComponent __instance)
Expand Down
13 changes: 1 addition & 12 deletions NebulaPatcher/Patches/Dynamic/EnemyDFHiveSystem_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,7 @@ public static bool NotifyRelayKilled(EnemyDFHiveSystem __instance, ref EnemyData
if (dfrelayComponent?.id == enemy.dfRelayId)
{
__instance.relayNeutralizedCounter++;
if (dfrelayComponent.baseState == 1 && dfrelayComponent.stage == 2)
{
var planetData = __instance.sector.galaxy.PlanetById(dfrelayComponent.targetAstroId);
if (planetData != null)
{
//Don't call GetOrCreateFactory in client. Only realize if the factory is already load from server
if (planetData.factory != null)
{
dfrelayComponent.RealizePlanetBase(__instance.sector);
}
}
}
// Client will wait for server to send RealizePlanetBase packet
}
return false;
}
Expand Down
34 changes: 34 additions & 0 deletions NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,38 @@ private static void RefreshMissingMeshes()
Log.Debug("RefreshMissingMeshes");
}
}

[HarmonyPrefix]
[HarmonyPatch(nameof(GameData.CreateDysonSphere))]
public static bool CreateDysonSphere_Prefix(GameData __instance, int starIndex, ref DysonSphere __result)
{
if (!Multiplayer.IsActive || Multiplayer.Session.IsServer) return true;


if ((ulong)starIndex >= (ulong)((long)__instance.galaxy.starCount))
{
__result = null;
return false;
}
if (__instance.dysonSpheres[starIndex] != null)
{
__result = __instance.dysonSpheres[starIndex];
return false;
}

// Create a dummy dyson sphere and prevent sending packets
Multiplayer.Session.DysonSpheres.InBlueprint = true;
__instance.dysonSpheres[starIndex] = new DysonSphere();
__instance.dysonSpheres[starIndex].Init(__instance, __instance.galaxy.stars[starIndex]);
__instance.dysonSpheres[starIndex].ResetNew();
Multiplayer.Session.DysonSpheres.InBlueprint = false;

if (Multiplayer.Session.DysonSpheres.RequestingIndex == -1)
{
// If client is not requesting yet, request the target sphere from server
Multiplayer.Session.DysonSpheres.RequestDysonSphere(starIndex, false);
}
__result = __instance.dysonSpheres[starIndex];
return false;
}
}
1 change: 0 additions & 1 deletion NebulaPatcher/Patches/Dynamic/UITurretWindow_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public static bool OnSetSuperNova_Prefix(UITurretWindow __instance)
{
// Client will wait for server to authorize
Multiplayer.Session.Network.SendPacket(packet);
__instance.supernovaWait &= !turret.inSupernova;
return false;
}
else
Expand Down
Loading

0 comments on commit 4d6bfcb

Please sign in to comment.