Skip to content

feat: MobSync#80

Open
Liparakis wants to merge 36 commits into
Extremelyd1:mainfrom
Liparakis:MobSyncOnly
Open

feat: MobSync#80
Liparakis wants to merge 36 commits into
Extremelyd1:mainfrom
Liparakis:MobSyncOnly

Conversation

@Liparakis

@Liparakis Liparakis commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Meaningful Changes

Animation & Visual Hits (DamageAnimationEffect.cs)

  • Changed:

    • Caches delegate subscriptions for visual damage effects (WillDamageEnemyOptionsDelegate and DamagedEnemyHealthManagerDelegate) to avoid repeated delegate allocations on hit processing paths.
    • Subscribes to UnityEngine.SceneManagement.SceneManager.activeSceneChanged to clear the static RemoteVisualHitHpBefore tracking dictionary between scenes.
    • Reworks FixDamageEnemies so remote attack replicas can trigger visual hit feedback while disabling lethal triggers, non-lethal side effects, and death events. The enemy HP is recorded before the remote hit and restored after the hit event completes.
  • Why it matters:

    • Reduces allocation pressure during repeated hit processing.
    • Avoids stale static hit-state leaking across scene transitions.
    • Allows remote player attacks to produce visible hit reactions without applying unauthorized local damage, double damage, or client-side kills.

Pause & Input Management (PauseManager.cs)

  • Changed:

    • Replaces previously commented-out placeholders with active MonoMod.RuntimeDetour.Hook instances targeting UIManager.TogglePauseGame, HeroController.Pause, TransitionPoint.OnTriggerEnter2D, and HeroController.DieFromHazard.
    • Forces Time.timeScale back to 1f while multiplayer pause handling is active so world simulation can continue for other players.
    • Disables input and clears selected button state during forced unpause flows.
    • Forces immediate unpausing on death, hazard death, and scene transitions to reduce the risk of pause-menu softlocks.
  • Why it matters:

    • Prevents one player’s pause state from freezing shared world simulation.
    • Reduces softlock risk when pause state overlaps with death, hazard respawn, or scene transition flows.
    • Keeps multiplayer world state moving even when local UI pause behavior is active.

Player-Player Collisions (PlayerManager.cs)

  • Changed:

    • Disables collisions between the local player and remote players inside CreateNewPlayerContainer by calling Physics2D.IgnoreCollision across local and remote colliders.
    • Registers and unregisters remote player root objects through PlayerTargetRegistry.
  • Why it matters:

    • Prevents remote player replicas from physically pushing, blocking, or displacing the local player.
    • Centralizes remote player target/collider tracking for systems that need to query valid player targets.

FSM Performance & Garbage Collection (Entity.cs, EntityFsmActions.cs)

  • Changed:

    • Replaces generic delegates and closure-heavy FSM synchronization helpers, such as CondAddData and CondUpdateVars, with direct type-specific loops for floats, ints, bools, strings, Vector2, and Vector3.
    • Replaces PlayMaker/Animator hook setup with explicit MonoMod.RuntimeDetour.Hook fields.
    • Replaces Dictionary<FsmStateAction, Queue<object>> RandomActionValues with ConditionalWeakTable<FsmStateAction, Queue<object>>.
  • Why it matters:

    • Reduces frame-by-frame GC allocations in hot FSM synchronization paths.
    • Makes hook lifetime easier to reason about by storing explicit hook references.
    • Allows randomized action data associated with FsmStateAction instances to be collected once the action is no longer strongly referenced elsewhere.

Registry Generalization & Silksong Port (EntityRegistry.cs, EntityType.cs)

  • Changed:

    • Replaces hardcoded type-check structures with generalized metadata-driven registry matching using fields such as FsmNames and parent_name.
    • Uses a deserialized HashSet<string> cache (_fsmNameSet) for faster FSM name lookups in registry entry matching.
    • Ports the entity type enum and registry lookup structure from the Hollow Knight version toward the Silksong Entity V1 system.
  • Why it matters:

    • Reduces one-off hardcoded entity handling.
    • Makes new entity support easier to add through registry metadata instead of source-level conditionals.
    • Improves lookup cost for repeated FSM-name matching.

Component Updates & Centralization (EntityComponent.cs and Components)

  • Changed:

    • Replaces decentralized component update subscriptions through MonoBehaviourUtil.Instance.OnUpdateEvent with a centralized update path where Entity.OnUpdate() drives EntityComponent.OnUpdate().
    • Passes sceneHostEpoch into InitializeHost and InitializeClient during component setup.
  • Why it matters:

    • Reduces the number of individual update-event subscriptions.
    • Makes component update order and lifecycle easier to reason about from the owning entity.
    • Propagates scene-host epoch context into component initialization.

Entity Update Lifetime & Buffer Lifecycles (EntityManager.cs, ClientManager.cs)

  • Changed:

    • Renames _receivedUpdates to _pendingUpdates.
    • Implements DrainPendingUpdates() and returns processed updates to the object pool with ObjectPool<EntityUpdate>.Return.
    • Retains ownership of queued updates until they are successfully applied or discarded during entity destruction.
    • Hooks FindGameObject.OnEnter so FSM queries can locate entities that the system has deactivated.
    • Replaces full scene traversal inside FindEntitiesInScene with targeted component candidate gathering.
  • Why it matters:

    • Fixes a critical lifetime issue where buffered network updates could be returned to the pool before the entity finished consuming them.
    • Reduces the risk of pooled update data being overwritten while still logically active.
    • Helps host-transfer and FSM restoration paths find inactive controller assets.
    • Reduces expensive full-scene traversal during entity discovery.

Health Synchronization (HealthManagerComponent.cs)

  • Changed:

    • Implements epoch/update-id tracking for health synchronization using _currentHealthEpoch and _nextHealthUpdateId.
    • Tracks health update sequencing per sender.
    • Pools EntityNetworkData objects used for HP and invincibility updates.
    • Delays client-side HP increases by 0.4 seconds to verify whether the increase is backed by host authority, rolling back unauthorized local increases when needed.
  • Why it matters:

    • Improves protection against duplicate, stale, and out-of-order health packets.
    • Reduces allocation pressure during combat-heavy synchronization.
    • Reduces the risk of unauthorized client-side healing or stale HP restoration.

Packet Serialization (IPacket.cs, Packet.cs, UpdatePacket.cs, EntityUpdate.cs, PlayerUpdate.cs)

  • Changed:

    • Adds ReadPacketView(length) to return a sub-packet view over an existing packet buffer without copying the byte array.
    • Replaces Enum.GetNames(typeof(T)) with EnumCache<T>.Count for enum-size lookup.
    • Reuses the existing AckField array in UpdatePacket when it already has the correct size.
  • Why it matters:

    • Reduces allocation pressure in network serialization/deserialization paths.
    • Avoids repeated enum reflection in packet parsing.
    • Avoids allocating a new acknowledgement array for every compatible received update packet.

Deferred / New Files

These files are intentionally listed separately because they are new or mostly self-contained. They should be reviewed after existing behavior changes.

  • SSMP/Game/Client/GamePatcher.EnemyTargeting.cs

    • New enemy target allocation and redirection logic.
    • Uses distance hysteresis and approved target selection for enemy FSM actions.
    • Review after existing synchronization, lifecycle, and hook changes.
  • SSMP/Game/Client/GamePatcher.PlayerDetection.cs

    • New player detection/range detour logic.
    • Uses frame-cached bounds and detection helpers.
    • Review after existing synchronization, lifecycle, and hook changes.
  • SSMP/Game/Client/PlayerTargetRegistry.cs

    • New static tracking helper for remote player instances and collider components.
    • Review for lifecycle cleanup, scene-change behavior, and disconnect handling.
  • SSMP/Util/EnumCache.cs

    • New generic enum-size cache used to avoid repeated enum reflection.
    • Low complexity, but verify it behaves correctly for all enum types used in packet serialization.

@Liparakis Liparakis changed the title feat: Stripped MobSync Version feat: MobSync Jun 9, 2026
@Liparakis Liparakis marked this pull request as ready for review June 9, 2026 01:46
@Liparakis Liparakis marked this pull request as draft June 10, 2026 12:16
Liparakis added 20 commits June 10, 2026 19:33
- Track approved targets per enemy owner
- Allow target takeover with distance hysteresis
- Retarget FSM actions to approved targets instead of nearest players
- Prevent self/source references from being rewritten
- Keep attack/chomp range validation scoped to approved targets
…Ds for out-of-order and duplicate protection
… fix warning comment format in ActionRegistry
@Liparakis Liparakis marked this pull request as ready for review June 12, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant