Skip to content

Commit 887ea25

Browse files
committed
Sync cyclops destruction beacon, removed virtual cyclops logs, shut virtual cyclops lights, removed debug logs
1 parent 02b91c3 commit 887ea25

10 files changed

+97
-37
lines changed

Nitrox.Test/Patcher/Patches/PatchesTranspilerTest.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class PatchesTranspilerTest
1414
// Add "true" to any of those elements to have its transformed IL printed.
1515
public static IEnumerable<object[]> TranspilerPatchClasses =>
1616
[
17+
[typeof(AggressiveWhenSeeTarget_ScanForAggressionTarget_Patch), 3],
18+
[typeof(AttackCyclops_OnCollisionEnter_Patch), -17],
19+
[typeof(AttackCyclops_UpdateAggression_Patch), -23],
20+
[typeof(Bullet_Update_Patch), 3],
1721
[typeof(BaseDeconstructable_Deconstruct_Patch), BaseDeconstructable_Deconstruct_Patch.InstructionsToAdd(true).Count() * 2],
1822
[typeof(BaseHullStrength_CrushDamageUpdate_Patch), 3],
1923
[typeof(BreakableResource_SpawnResourceFromPrefab_Patch), 2],
@@ -28,13 +32,15 @@ public class PatchesTranspilerTest
2832
[typeof(CrashHome_Update_Patch), -5],
2933
[typeof(CreatureDeath_OnKillAsync_Patch), 9],
3034
[typeof(CreatureDeath_SpawnRespawner_Patch), 2],
35+
[typeof(CyclopsDestructionEvent_DestroyCyclops_Patch), 3],
3136
[typeof(CyclopsDestructionEvent_SpawnLootAsync_Patch), 7],
3237
[typeof(CyclopsShieldButton_OnClick_Patch), -6],
3338
[typeof(CyclopsSonarButton_Update_Patch), 3],
3439
[typeof(CyclopsSonarDisplay_NewEntityOnSonar_Patch), 3],
3540
[typeof(DevConsole_Update_Patch), 0],
3641
[typeof(Eatable_IterateDespawn_Patch), 2],
3742
[typeof(EnergyMixin_SpawnDefaultAsync_Patch), -64],
43+
[typeof(EntityCell_AwakeAsync_Patch), 2],
3844
[typeof(EntityCell_SleepAsync_Patch), 2],
3945
[typeof(Equipment_RemoveItem_Patch), 7],
4046
[typeof(EscapePod_Start_Patch), 43],
@@ -48,9 +54,11 @@ public class PatchesTranspilerTest
4854
[typeof(IngameMenu_QuitSubscreen_Patch), -24],
4955
[typeof(Inventory_LoseItems_Patch), -2],
5056
[typeof(ItemsContainer_DestroyItem_Patch), 2],
57+
[typeof(LargeWorldEntity_UpdateCell_Patch), 1],
5158
[typeof(LaunchRocket_OnHandClick_Patch), -9],
5259
[typeof(LeakingRadiation_Update_Patch), 0],
5360
[typeof(MainGameController_StartGame_Patch), 1],
61+
[typeof(MeleeAttack_CanDealDamageTo_Patch), 4],
5462
[typeof(PDAScanner_Scan_Patch), 3],
5563
[typeof(Player_OnKill_Patch), 0],
5664
[typeof(Respawn_Start_Patch), 3],
@@ -66,10 +74,6 @@ public class PatchesTranspilerTest
6674
[typeof(uGUI_SceneIntro_IntroSequence_Patch), 8],
6775
[typeof(uSkyManager_SetVaryingMaterialProperties_Patch), 0],
6876
[typeof(Welder_Weld_Patch), 1],
69-
[typeof(AggressiveWhenSeeTarget_ScanForAggressionTarget_Patch), 3],
70-
[typeof(AttackCyclops_OnCollisionEnter_Patch), -17],
71-
[typeof(AttackCyclops_UpdateAggression_Patch), -23],
72-
[typeof(Bullet_Update_Patch), 3],
7377
[typeof(Poop_Perform_Patch), 1],
7478
[typeof(SeaDragonMeleeAttack_OnTouchFront_Patch), 9],
7579
[typeof(SeaDragonMeleeAttack_SwatAttack_Patch), 4],
@@ -79,10 +83,7 @@ public class PatchesTranspilerTest
7983
[typeof(SeaTreader_UpdatePath_Patch), 0],
8084
[typeof(SeaTreader_UpdateTurning_Patch), 0],
8185
[typeof(SeaTreader_Update_Patch), 0],
82-
[typeof(EntityCell_AwakeAsync_Patch), 2],
8386
[typeof(StasisSphere_LateUpdate_Patch), 0],
84-
[typeof(MeleeAttack_CanDealDamageTo_Patch), 4],
85-
[typeof(LargeWorldEntity_UpdateCell_Patch), 1],
8687
];
8788

8889
[TestMethod]

NitroxClient/GameLogic/AI.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public void BroadcastNewAction(NitroxId creatureId, Creature creature, CreatureA
5151
return;
5252
}
5353

54-
ErrorMessage.AddMessage($"[SEND] synced action: {newAction.GetType().FullName}");
5554
packetSender.Send(new CreatureActionChanged(creatureId, newAction.GetType().FullName));
5655
}
5756

@@ -63,7 +62,6 @@ public void CreatureActionChanged(NitroxId id, string creatureActionTypeName)
6362
}
6463
if (cachedCreatureActionTypeByFullName.TryGetValue(creatureActionTypeName, out Type creatureActionType))
6564
{
66-
ErrorMessage.AddMessage($"[GET] {creatureActionType}");
6765
if (creature.TryGetComponent(creatureActionType, out Component component) && component is CreatureAction creatureAction)
6866
{
6967
actions[creature] = creatureAction;
@@ -79,8 +77,6 @@ public static void AggressiveWhenSeeTargetChanged(NitroxId creatureId, NitroxId
7977
return;
8078
}
8179

82-
ErrorMessage.AddMessage($"[GET] {aggressiveWhenSeeTarget.gameObject.name} chases {targetObject.name}");
83-
8480
Creature creature = aggressiveWhenSeeTarget.creature;
8581

8682
// Code from AggressiveWhenSeeTarget.ScanForAggressionTarget
@@ -109,8 +105,6 @@ public static void AttackCyclopsTargetChanged(NitroxId creatureId, NitroxId targ
109105
return;
110106
}
111107

112-
ErrorMessage.AddMessage($"[GET] {attackCyclops.gameObject.name} attacks {targetObject.name}");
113-
114108
// Kinda stuff from AttackCyclops.UpdateAggression
115109
attackCyclops.aggressiveToNoise.Value = aggressiveToNoiseAmount;
116110
// Force currentTarget to null to ensure SetCurrentTarget detects a change
@@ -134,11 +128,9 @@ public static void RangedAttackLastTargetUpdate(NitroxId creatureId, NitroxId ta
134128
{
135129
case ActionState.CHARGING:
136130
rangedAttackLastTarget.StartCharging(attackType);
137-
ErrorMessage.AddMessage($"[GET] {rangedAttackLastTarget.name} charges against {targetObject.name}");
138131
break;
139132
case ActionState.CASTING:
140133
rangedAttackLastTarget.StartCasting(attackType);
141-
ErrorMessage.AddMessage($"[GET] {rangedAttackLastTarget.name} casts against {targetObject.name}");
142134
break;
143135
}
144136
}

NitroxClient/MonoBehaviours/Cyclops/VirtualCyclops.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public static void CreateVirtualCyclops()
5656
SubConsoleCommand.main.OnSubPrefabLoaded(cyclopsPrefab);
5757
GameObject model = SubConsoleCommand.main.GetLastCreatedSub();
5858
model.name = NAME;
59-
LargeWorldEntity.Register(model);
6059
Vector3 position = Vector3.up * 500;
6160
Quaternion rotation = Quaternion.identity;
6261
model.transform.position = position;
@@ -69,6 +68,7 @@ public static void CreateVirtualCyclops()
6968
GameObject.Destroy(model.GetComponent<EcoTarget>());
7069
GameObject.Destroy(model.GetComponent<PingInstance>());
7170
GameObject.Destroy(model.GetComponent<CyclopsDestructionEvent>());
71+
GameObject.Destroy(model.GetComponent<VFXConstructing>());
7272

7373
Instance.InitialPosition = position;
7474
Instance.InitialRotation = rotation;
@@ -83,6 +83,8 @@ public static void CreateVirtualCyclops()
8383

8484
Instance.RegisterVirtualOpenables();
8585
Instance.ToggleRenderers(false);
86+
Instance.DisableBadComponents();
87+
8688
model.SetActive(true);
8789
});
8890
}
@@ -165,14 +167,35 @@ public void ToggleRenderers(bool toggled)
165167
}
166168
}
167169

168-
public void RegisterVirtualOpenables()
170+
private void RegisterVirtualOpenables()
169171
{
170172
foreach (Openable openable in transform.GetComponentsInChildren<Openable>(true))
171173
{
172174
virtualOpenableByName.Add(openable.name, openable);
173175
}
174176
}
175177

178+
private void DisableBadComponents()
179+
{
180+
CyclopsLightingPanel cyclopsLightingPanel = GetComponentInChildren<CyclopsLightingPanel>(true);
181+
cyclopsLightingPanel.floodlightsOn = false;
182+
cyclopsLightingPanel.lightingOn = false;
183+
cyclopsLightingPanel.SetExternalLighting(false);
184+
cyclopsLightingPanel.cyclopsRoot.ForceLightingState(false);
185+
cyclopsLightingPanel.enabled = false;
186+
Destroy(cyclopsLightingPanel);
187+
188+
// Disable a source of useless logs
189+
foreach (FMOD_CustomEmitter customEmitter in GetComponentsInChildren<FMOD_CustomEmitter>(true))
190+
{
191+
customEmitter.enabled = false;
192+
}
193+
foreach (PlayerCinematicController cinematicController in GetComponentsInChildren<PlayerCinematicController>(true))
194+
{
195+
cinematicController.enabled = false;
196+
}
197+
}
198+
176199
public void ReplicateOpening(Openable openable, bool openState)
177200
{
178201
if (virtualOpenableByName.TryGetValue(openable.name, out Openable virtualOpenable))

NitroxClient/MonoBehaviours/PlayerDeathBroadcaster.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using NitroxClient.GameLogic;
2-
using NitroxModel.Core;
32
using UnityEngine;
43

54
namespace NitroxClient.MonoBehaviours;
@@ -10,7 +9,7 @@ public class PlayerDeathBroadcaster : MonoBehaviour
109

1110
public void Awake()
1211
{
13-
localPlayer = NitroxServiceLocator.LocateService<LocalPlayer>();
12+
localPlayer = this.Resolve<LocalPlayer>();
1413

1514
Player.main.playerDeathEvent.AddHandler(this, PlayerDeath);
1615
}

NitroxPatcher/Patches/Dynamic/AggressiveWhenSeeTarget_ScanForAggressionTarget_Patch.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public static void BroadcastTargetChange(AggressiveWhenSeeTarget aggressiveWhenS
6262
float aggressionAmount = aggressiveWhenSeeTarget.creature.Aggression.Value;
6363

6464
Resolve<IPacketSender>().Send(new AggressiveWhenSeeTargetChanged(creatureId, targetId, lastTarget.targetLocked, aggressionAmount));
65-
ErrorMessage.AddMessage($"[SEND] {aggressiveWhenSeeTarget.gameObject.name} chases {realTarget.name}");
6665
}
6766
}
6867
}

NitroxPatcher/Patches/Dynamic/AttackCyclops_UpdateAggression_Patch.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public static void Postfix(AttackCyclops __instance)
6464
float aggressiveToNoise = __instance.aggressiveToNoise.Value;
6565

6666
Resolve<IPacketSender>().Send(new AttackCyclopsTargetChanged(creatureId, targetId, aggressiveToNoise));
67-
ErrorMessage.AddMessage($"[SEND] {__instance.gameObject.name} attacks {__instance.currentTarget.name}");
6867
}
6968
}
7069

NitroxPatcher/Patches/Dynamic/CyclopsDestructionEvent_DestroyCyclops_Patch.cs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1+
using System.Collections.Generic;
12
using System.Reflection;
3+
using System.Reflection.Emit;
4+
using HarmonyLib;
25
using NitroxClient.GameLogic;
3-
using NitroxClient.MonoBehaviours;
46
using NitroxClient.MonoBehaviours.Cyclops;
57
using NitroxModel.DataStructures;
68
using NitroxModel.Helper;
9+
using UnityEngine;
710

811
namespace NitroxPatcher.Patches.Dynamic;
912

1013
/// <summary>
11-
/// Broadcasts the cyclops destruction, and safely removes every player from it.
14+
/// Broadcasts the cyclops destruction, and safely removes every player from it. Also broadcasts the creation of the beacon.
1215
/// </summary>
1316
public sealed partial class CyclopsDestructionEvent_DestroyCyclops_Patch : NitroxPatch, IDynamicPatch
1417
{
1518
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((CyclopsDestructionEvent t) => t.DestroyCyclops());
1619

1720
public static void Prefix(CyclopsDestructionEvent __instance)
1821
{
19-
if (__instance.TryGetNitroxId(out NitroxId nitroxId))
20-
{
21-
Resolve<SimulationOwnership>().StopSimulatingEntity(nitroxId);
22-
EntityPositionBroadcaster.StopWatchingEntity(nitroxId);
23-
}
24-
2522
bool wasInCyclops = Player.main.currentSub == __instance.subRoot;
2623

2724
// Before the cyclops destruction, we move out the remote players so that they aren't stuck in its hierarchy
@@ -46,4 +43,37 @@ public static void Postfix(CyclopsDestructionEvent __instance)
4643
Resolve<Vehicles>().BroadcastDestroyedCyclops(__instance.gameObject, nitroxId);
4744
}
4845
}
46+
47+
/*
48+
* ADD at the end of the method:
49+
* CyclopsDestructionEvent_DestroyCyclops_Patch.ManageBeacon(component, this);
50+
*/
51+
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
52+
{
53+
return new CodeMatcher(instructions).End() // Move before Ret
54+
.InsertAndAdvance([
55+
new CodeInstruction(OpCodes.Ldloc_2),
56+
new CodeInstruction(OpCodes.Ldarg_0),
57+
new CodeInstruction(OpCodes.Call, Reflect.Method(() => ManageBeacon(default, default)))
58+
]).InstructionEnumeration();
59+
}
60+
61+
public static void ManageBeacon(Beacon beacon, CyclopsDestructionEvent cyclopsDestructionEvent)
62+
{
63+
if (!cyclopsDestructionEvent.TryGetNitroxId(out NitroxId nitroxId))
64+
{
65+
return;
66+
}
67+
68+
// We let the simulating player spawn it for everyone
69+
if (!Resolve<SimulationOwnership>().HasAnyLockType(nitroxId))
70+
{
71+
Object.Destroy(beacon.gameObject);
72+
return;
73+
}
74+
75+
// We need to force this state for beaconLabel to wear the correct tag
76+
beacon.Start();
77+
Resolve<Items>().Dropped(beacon.gameObject, TechType.Beacon);
78+
}
4979
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Reflection;
2+
using NitroxClient.GameLogic;
3+
using NitroxModel.DataStructures;
4+
using NitroxModel.Helper;
5+
6+
namespace NitroxPatcher.Patches.Dynamic;
7+
8+
public sealed partial class Floater_FixedUpdate_Patch : NitroxPatch, IDynamicPatch
9+
{
10+
private static readonly MethodInfo TARGET_METHOD = Reflect.Method((Floater t) => t.FixedUpdate());
11+
12+
public static bool Prefix(Floater __instance)
13+
{
14+
if (!__instance.fixedJoint || !__instance.fixedJoint.connectedBody ||
15+
!__instance.fixedJoint.connectedBody.TryGetNitroxId(out NitroxId jointId))
16+
{
17+
return true;
18+
}
19+
20+
// If target has an id, we only apply the FixedUpdate when we have a lock type on it (true)
21+
return Resolve<SimulationOwnership>().HasAnyLockType(jointId);
22+
}
23+
}

NitroxPatcher/Patches/Dynamic/RangedAttackLastTarget_StartCasting_Patch.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ public sealed partial class RangedAttackLastTarget_StartCasting_Patch : NitroxPa
1414

1515
public static void Prefix(RangedAttackLastTarget __instance)
1616
{
17-
if (RangedAttackLastTarget_StartCharging_Patch.BroadcastRangedAttack(__instance, RangedAttackLastTargetUpdate.ActionState.CASTING))
18-
{
19-
ErrorMessage.AddMessage($"[SEND] {__instance.name} casts against {__instance.currentTarget.name}");
20-
}
17+
RangedAttackLastTarget_StartCharging_Patch.BroadcastRangedAttack(__instance, RangedAttackLastTargetUpdate.ActionState.CASTING);
2118
}
2219
}
2320

NitroxPatcher/Patches/Dynamic/RangedAttackLastTarget_StartCharging_Patch.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ public sealed partial class RangedAttackLastTarget_StartCharging_Patch : NitroxP
1717

1818
public static void Prefix(RangedAttackLastTarget __instance)
1919
{
20-
if (BroadcastRangedAttack(__instance, RangedAttackLastTargetUpdate.ActionState.CHARGING))
21-
{
22-
ErrorMessage.AddMessage($"[SEND] {__instance.name} charges against {__instance.currentTarget.name}");
23-
}
20+
BroadcastRangedAttack(__instance, RangedAttackLastTargetUpdate.ActionState.CHARGING);
2421
}
2522

2623
/// <summary>

0 commit comments

Comments
 (0)