Skip to content

Commit

Permalink
Merge pull request NebulaModTeam#686 from starfi5h/pr-bugfix
Browse files Browse the repository at this point in the history
Bugfixes (Game version 0.10.30.22292)
  • Loading branch information
starfi5h authored Jul 5, 2024
2 parents 6f3e674 + 4f31bf2 commit 9200136
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 103 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## Changelog

0.9.6:
- @AlienXAXS: Fix headless server throwing a small error during boot sequence due to the UI being disabled
- @PhantomGamers: Add additional error description to ngrokmanager
- @starfi5h: Enable Log.Debug messages
- @starfi5h: Fix DF relay landed on planet message in client
- @starfi5h: Fix client's attacks won't increase DF threat when host player is dead
- @starfi5h: Fix ACH_BroadcastStar.OnGameTick error on client
- @starfi5h: Prevent server from sending out construction drones in headless mode

0.9.5:
- @starfi5h: Sync Dark Fog communicator (aggressiveness and truce)
- @starfi5h: Show server last save time in client esc menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DFGKillEnemyProcessor : PacketProcessor<DFGKillEnemyPacket>
protected override void ProcessPacket(DFGKillEnemyPacket packet, NebulaConnection conn)
{
var factory = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory;
if (factory == null) return;
if (factory == null || packet.EnemyId >= factory.enemyPool.Length) return;

if (IsHost)
{
Expand Down
25 changes: 25 additions & 0 deletions NebulaPatcher/Patches/Dynamic/ACH_BroadcastStar_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#region

using HarmonyLib;
using NebulaWorld;

#endregion

namespace NebulaPatcher.Patches.Dynamic;

[HarmonyPatch(typeof(ACH_BroadcastStar))]
internal class ACH_BroadcastStar_Patch
{
[HarmonyPrefix]
[HarmonyPatch(nameof(ACH_BroadcastStar.OnGameTick))]
[HarmonyPatch(nameof(ACH_BroadcastStar.TryAlterEntity))]
public static bool Block_On_Client_Prefix()
{
// ACH_BroadcastStar is for the achievement "Let there be light!"
// which needs to light up Artificial Star (2210) on certain planets
// Clients only have partial factories loaded so they won't get the correct stats.
// Therefore it's disabled to prevent errors.
// TODO: Try to handle global achievements syncing?
return !Multiplayer.IsActive || Multiplayer.Session.IsServer;
}
}
4 changes: 3 additions & 1 deletion NebulaPatcher/Patches/Dynamic/Dedicated_Server_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public static void GameMainBegin_Postfix()
{
// Don't let the player of dedicated server to interact with enemies
GameMain.mainPlayer.isAlive = false;
// Don't let the player of dedicated server send out construction drones
GameMain.mainPlayer.mecha.constructionModule.droneEnabled = false;
}
}

Expand All @@ -64,7 +66,7 @@ public static bool OnLateUpdate()
return false;
}

// Destory gameObject so Update() won't execute
// Destroy gameObject so Update() won't execute
[HarmonyPrefix]
[HarmonyPatch(typeof(PlanetAtmoBlur), nameof(PlanetAtmoBlur.Start))]
public static bool PlanetAtmoBlur_Start(PlanetAtmoBlur __instance)
Expand Down
40 changes: 21 additions & 19 deletions NebulaPatcher/Patches/Dynamic/SkillSystem_Common_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ public static bool GeneralShieldBurst_Prefix(ref GeneralShieldBurst __instance,
return false;
}

static void SwtichPlayerState(int playerId)
static void SwitchPlayerState(int playerId)
{
if (!Multiplayer.Session.Combat.IndexByPlayerId.TryGetValue(playerId, out var index)) return;

ref var playerData = ref Multiplayer.Session.Combat.Players[index];
var skillSystem = GameMain.data.spaceSector.skillSystem;
skillSystem.mecha = playerData.mecha;
skillSystem.playerAlive = playerData.isAlive;
skillSystem.playerSkillTargetL = playerData.skillTargetL;
skillSystem.playerSkillTargetULast = playerData.skillTargetULast;
skillSystem.playerSkillTargetU = playerData.skillTargetU;
Expand All @@ -49,13 +50,14 @@ static void SwtichPlayerState(int playerId)
skillSystem.playerSkillCastRightU = playerData.skillTargetU;
}

static void SwtichTargetPlayerWithCollider(int playerId)
static void SwitchTargetPlayerWithCollider(int playerId)
{
if (!Multiplayer.Session.Combat.IndexByPlayerId.TryGetValue(playerId, out var index)) return;

ref var playerData = ref Multiplayer.Session.Combat.Players[index];
var skillSystem = GameMain.data.spaceSector.skillSystem;
skillSystem.mecha = playerData.mecha;
skillSystem.playerAlive = playerData.isAlive;
skillSystem.playerSkillTargetL = playerData.skillTargetL;
skillSystem.playerSkillTargetULast = playerData.skillTargetULast;
skillSystem.playerSkillTargetU = playerData.skillTargetU;
Expand All @@ -66,78 +68,78 @@ static void SwtichTargetPlayerWithCollider(int playerId)
public static void GeneralExpImpProjectile_Prefix(ref GeneralExpImpProjectile __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichTargetPlayerWithCollider(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchTargetPlayerWithCollider(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(GeneralMissile), nameof(GeneralMissile.TickSkillLogic))]
public static void GeneralProjectile_Prefix(ref GeneralMissile __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichTargetPlayerWithCollider(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchTargetPlayerWithCollider(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(GeneralProjectile), nameof(GeneralProjectile.TickSkillLogic))]
public static void GeneralProjectile_Prefix(ref GeneralProjectile __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichTargetPlayerWithCollider(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchTargetPlayerWithCollider(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(LocalGeneralProjectile), nameof(LocalGeneralProjectile.TickSkillLogic))]
public static void LocalGeneralProjectile_Prefix(ref LocalGeneralProjectile __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichTargetPlayerWithCollider(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchTargetPlayerWithCollider(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(LocalLaserContinuous), nameof(LocalLaserContinuous.TickSkillLogic))]
public static void LocalLaserContinuous_Prefix(ref LocalLaserContinuous __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichPlayerState(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchPlayerState(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(LocalLaserOneShot), nameof(LocalLaserOneShot.TickSkillLogic))]
public static void LocalLaserOneShot_Prefix(ref LocalLaserOneShot __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichPlayerState(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchPlayerState(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(LocalCannonade), nameof(LocalCannonade.TickSkillLogic))]
public static void LocalCannonade_Prefix(ref LocalCannonade __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(SpaceLaserOneShot), nameof(SpaceLaserOneShot.TickSkillLogic))]
public static void SpaceLaserOneShot_Prefix(ref SpaceLaserOneShot __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwtichPlayerState(__instance.target.id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if (__instance.target.type == ETargetType.Player) SwitchPlayerState(__instance.target.id);
}

[HarmonyPrefix]
[HarmonyPatch(typeof(SpaceLaserSweep), nameof(SpaceLaserSweep.TickSkillLogic))]
public static void SpaceLaserSweep_Prefix(ref SpaceLaserSweep __instance)
{
if (!Multiplayer.IsActive) return;
if (__instance.caster.type == ETargetType.Player) SwtichPlayerState(__instance.caster.id);
if ((__instance.mask & ETargetTypeMask.Player) != 0) SwtichTargetPlayerWithCollider(Multiplayer.Session.LocalPlayer.Id);
if (__instance.caster.type == ETargetType.Player) SwitchPlayerState(__instance.caster.id);
if ((__instance.mask & ETargetTypeMask.Player) != 0) SwitchTargetPlayerWithCollider(Multiplayer.Session.LocalPlayer.Id);
}
}
11 changes: 11 additions & 0 deletions NebulaPatcher/Patches/Dynamic/SkillSystem_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public static bool Import_Prefix(SkillSystem __instance, BinaryReader r)
return false;
}

[HarmonyPostfix]
[HarmonyPatch(nameof(SkillSystem.CollectPlayerStates))]
public static void CollectPlayerStates_Postfix(SkillSystem __instance)
{
if (!Multiplayer.IsActive) return;

// Set those flags to false so AddSpaceEnemyHatred can add threat correctly for client's skill in host
__instance.playerIsSailing = false;
__instance.playerIsWarping = false;
}

[HarmonyPostfix]
[HarmonyPatch(nameof(SkillSystem.AfterTick))]
public static void AfterTick_Postfix(SkillSystem __instance)
Expand Down
69 changes: 0 additions & 69 deletions NebulaPatcher/Patches/Transpilers/ACH_BroadcastStar_Transpiler.cs

This file was deleted.

37 changes: 37 additions & 0 deletions NebulaPatcher/Patches/Transpilers/EnemyDFHiveSystem_Transpiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,43 @@ public static IEnumerable<CodeInstruction> GameTickLogic_Transpiler(IEnumerable<
.MatchForward(true, new CodeMatch(OpCodes.Callvirt, AccessTools.Method(typeof(DFRelayComponent), nameof(DFRelayComponent.RealizePlanetBase))))
.Set(OpCodes.Call, AccessTools.Method(typeof(EnemyDFHiveSystem_Transpiler), nameof(RealizePlanetBase)));


// Insert null guard in EnemyUnitComponent loop
// if (ptr10.id == k)
// {
// ref EnemyData ptr11 = ref enemyPool[ptr10.enemyId];
// PrefabDesc prefabDesc = SpaceSector.PrefabDescByModelIndex[(int)ptr11.modelIndex];
// if (prefabDesc == null) continue; // null guard

codeMatcher.MatchForward(true,
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(EnemyUnitComponent), nameof(EnemyUnitComponent.id))),
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(OpCodes.Bne_Un));
if (codeMatcher.IsInvalid)
{
Log.Warn("EnemyDFHiveSystem.GameTickLogic: Can't find operand_continue");
return codeMatcher.InstructionEnumeration();
}
var operand_continue = codeMatcher.Operand;

codeMatcher.MatchForward(true,
new CodeMatch(OpCodes.Ldsfld, AccessTools.Field(typeof(SpaceSector), nameof(SpaceSector.PrefabDescByModelIndex))),
new CodeMatch(OpCodes.Ldloc_S),
new CodeMatch(OpCodes.Ldfld),
new CodeMatch(OpCodes.Ldelem_Ref),
new CodeMatch(OpCodes.Stloc_S));
if (codeMatcher.IsInvalid)
{
Log.Warn("EnemyDFHiveSystem.GameTickLogic: Can't find operand_prefabDesc");
return codeMatcher.InstructionEnumeration();
}
var operand_prefabDesc = codeMatcher.Operand;

codeMatcher.Advance(1).Insert(
new CodeInstruction(OpCodes.Ldloc_S, operand_prefabDesc),
new CodeInstruction(OpCodes.Brfalse_S, operand_continue));

return codeMatcher.InstructionEnumeration();
}
catch (System.Exception e)
Expand Down
13 changes: 6 additions & 7 deletions NebulaWorld/SimulatedWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NebulaAPI;
using NebulaAPI.DataStructures;
Expand All @@ -24,7 +23,6 @@
using UnityEngine;
using UnityEngine.UI;
using Object = UnityEngine.Object;
using Random = UnityEngine.Random;

#endregion

Expand Down Expand Up @@ -127,6 +125,7 @@ public void SetupInitialPlayerState()
GameMain.mainPlayer.mecha.coreEnergy = GameMain.mainPlayer.mecha.coreEnergyCap;
GameMain.mainPlayer.mecha.energyShieldEnergy = GameMain.mainPlayer.mecha.energyShieldCapacity;
GameMain.mainPlayer.mecha.hp = GameMain.mainPlayer.mecha.hpMaxApplied;
GameMain.mainPlayer.mecha.constructionModule.droneEnabled = true;
if (GameMain.history.logisticShipWarpDrive)
{
// If warp has unlocked, give new client few warpers
Expand Down Expand Up @@ -188,7 +187,7 @@ public void SetupInitialPlayerState()
}
// Finally we need add the local player components to the player character
localPlayerMovement = GameMain.mainPlayer.gameObject.AddComponentIfMissing<LocalPlayerMovement>();
// ChatManager should continuous exsit until the game is closed
// ChatManager should exist continuously until the game is closed
GameMain.mainPlayer.gameObject.AddComponentIfMissing<ChatManager>();
}

Expand Down Expand Up @@ -234,7 +233,7 @@ public static void OnPlayerJoinedGame(INebulaPlayer player)
{
Multiplayer.Session.World.SpawnRemotePlayerModel(player.Data);

// Load overriden Planet and Star names
// Sync overrideName of planets and stars
player.SendPacket(new NameInputPacket(GameMain.galaxy));

// add together player sand count and tell others if we are syncing soil
Expand Down Expand Up @@ -316,10 +315,10 @@ public void SpawnRemotePlayerModel(IPlayerData playerData)
model.Movement.localPlanetId = playerData.LocalPlanetId;
remotePlayersModels.Add(playerData.PlayerId, model);

// Show conneted message
var planetname = GameMain.galaxy.PlanetById(playerData.LocalPlanetId)?.displayName ?? "In space";
// Show connected message
var planetName = GameMain.galaxy.PlanetById(playerData.LocalPlanetId)?.displayName ?? "In space";
var message = string.Format("[{0:HH:mm}] {1} connected ({2})".Translate(), DateTime.Now, playerData.Username,
planetname);
planetName);
ChatManager.Instance.SendChatMessage(message, ChatMessageType.SystemInfoMessage);
}
}
Expand Down
Loading

0 comments on commit 9200136

Please sign in to comment.