public Server() { this.timeKeeper = new TimeKeeper(); this.tcpServer = new TcpServer(); this.simulationOwnership = new SimulationOwnership(); this.packetHandler = new PacketHandler(tcpServer, timeKeeper, simulationOwnership); }
public static bool Prefix(DockedVehicleHandTarget __instance, GUIHand hand) { Vehicle vehicle = __instance.dockingBay.GetDockedVehicle(); if (skipPrefix || vehicle == null) { return(true); } SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); NitroxId id = NitroxEntity.GetId(vehicle.gameObject); if (simulationOwnership.HasExclusiveLock(id)) { Log.Debug($"Already have an exclusive lock on this vehicle: {id}"); return(true); } HandInteraction <DockedVehicleHandTarget> context = new HandInteraction <DockedVehicleHandTarget>(__instance, hand); LockRequest <HandInteraction <DockedVehicleHandTarget> > lockRequest = new LockRequest <HandInteraction <DockedVehicleHandTarget> >(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse, context); simulationOwnership.RequestSimulationLock(lockRequest); return(false); }
public static bool Prefix(PilotingChair __instance, GUIHand hand) { if (skipPrefix) { return(true); } pilotingChair = __instance; guiHand = hand; SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); SubRoot subRoot = __instance.GetComponentInParent <SubRoot>(); Validate.NotNull(subRoot, "PilotingChair cannot find it's corresponding SubRoot!"); string guid = GuidHelper.GetGuid(subRoot.gameObject); if (simulationOwnership.HasExclusiveLock(guid)) { Log.Debug($"Already have an exclusive lock on the piloting chair: {guid}"); return(true); } simulationOwnership.RequestSimulationLock(guid, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse); return(false); }
public static bool Prefix(DockedVehicleHandTarget __instance, GUIHand hand) { vehicleDockingBay = __instance.dockingBay; Vehicle vehicle = vehicleDockingBay.GetDockedVehicle(); if (skipPrefix || vehicle == null) { return(true); } dockedVehicle = __instance; guiHand = hand; SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); NitroxId id = NitroxEntity.GetId(vehicle.gameObject); if (simulationOwnership.HasExclusiveLock(id)) { Log.Debug($"Already have an exclusive lock on this vehicle: {id}"); return(true); } simulationOwnership.RequestSimulationLock(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse); return(false); }
public static bool Prefix(PilotingChair __instance, GUIHand hand) { if (skipPrefix) { return(true); } SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); SubRoot subRoot = __instance.GetComponentInParent <SubRoot>(); Validate.NotNull(subRoot, "PilotingChair cannot find it's corresponding SubRoot!"); NitroxId id = NitroxEntity.GetId(subRoot.gameObject); if (simulationOwnership.HasExclusiveLock(id)) { Log.Debug($"Already have an exclusive lock on the piloting chair: {id}"); return(true); } HandInteraction <PilotingChair> context = new HandInteraction <PilotingChair>(__instance, hand); LockRequest <HandInteraction <PilotingChair> > lockRequest = new LockRequest <HandInteraction <PilotingChair> >(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse, context); simulationOwnership.RequestSimulationLock(lockRequest); return(false); }
public VehicleDockingProcessor(IPacketSender packetSender, Vehicles vehicles, SimulationOwnership simulationOwnership, PlayerManager remotePlayerManager) { this.packetSender = packetSender; this.vehicles = vehicles; this.simulationOwnership = simulationOwnership; this.remotePlayerManager = remotePlayerManager; }
public static void Postfix(Bench __instance) { NitroxId id = NitroxEntity.GetId(__instance.gameObject); SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); // Request to be downgraded to a transient lock so we can still simulate the positioning. simulationOwnership.RequestSimulationLock(id, SimulationLockType.TRANSIENT); }
public static void Prefix(Vehicle __instance) { NitroxServiceLocator.LocateService <Vehicles>().BroadcastOnPilotModeChanged(__instance, false); NitroxId id = NitroxIdentifier.GetId(__instance.gameObject); SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); simulationOwnership.RequestSimulationLock(id, SimulationLockType.TRANSIENT, null); }
public SimulationOwnershipInitialSyncProcessor(IPacketSender packetSender, SimulationOwnership simulationOwnership) { this.packetSender = packetSender; this.simulationOwnership = simulationOwnership; DependentProcessors.Add(typeof(BuildingInitialSyncProcessor)); DependentProcessors.Add(typeof(CyclopsInitialAsyncProcessor)); DependentProcessors.Add(typeof(VehicleInitialSyncProcessor)); }
public Server() { TimeKeeper timeKeeper = new TimeKeeper(); SimulationOwnership simulationOwnership = new SimulationOwnership(); PlayerManager playerManager = new PlayerManager(); PacketHandler packetHandler = new PacketHandler(playerManager, timeKeeper, simulationOwnership); tcpServer = new TcpServer(packetHandler, playerManager); }
public static void Postfix(PilotingChair __instance) { SubRoot subRoot = __instance.GetComponentInParent <SubRoot>(); Validate.NotNull(subRoot, "PilotingChair cannot find it's corresponding SubRoot!"); NitroxId id = NitroxEntity.GetId(subRoot.gameObject); SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); // Request to be downgraded to a transient lock so we can still simulate the positioning. simulationOwnership.RequestSimulationLock(id, SimulationLockType.TRANSIENT); }
public PacketHandler(TcpServer tcpServer, TimeKeeper timeKeeper, SimulationOwnership simulationOwnership) { this.defaultPacketProcessor = new DefaultServerPacketProcessor(tcpServer); var ProcessorArguments = new Dictionary <Type, object> { { typeof(TcpServer), tcpServer }, { typeof(TimeKeeper), timeKeeper }, { typeof(SimulationOwnership), simulationOwnership } }; authenticatedPacketProcessorsByType = PacketProcessor.GetProcessors(ProcessorArguments, p => p.BaseType.IsGenericType && p.BaseType.GetGenericTypeDefinition() == typeof(AuthenticatedPacketProcessor <>)); unauthenticatedPacketProcessorsByType = PacketProcessor.GetProcessors(ProcessorArguments, p => p.BaseType.IsGenericType && p.BaseType.GetGenericTypeDefinition() == typeof(UnauthenticatedPacketProcessor <>)); }
public static bool Prefix(PropulsionCannon __instance) { GameObject grabbed = __instance.grabbedObject; if (!grabbed) { return(false); } NitroxId id = NitroxEntity.GetId(grabbed); SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); // Request to be downgraded to a transient lock so we can still simulate the positioning. simulationOwnership.RequestSimulationLock(id, SimulationLockType.TRANSIENT); return(true); }
public PacketHandler(PlayerManager playerManager, TimeKeeper timeKeeper, SimulationOwnership simulationOwnership) { this.playerManager = playerManager; defaultPacketProcessor = new DefaultServerPacketProcessor(playerManager); Dictionary <Type, object> ProcessorArguments = new Dictionary <Type, object> { { typeof(PlayerManager), playerManager }, { typeof(TimeKeeper), timeKeeper }, { typeof(SimulationOwnership), simulationOwnership }, { typeof(EscapePodManager), new EscapePodManager() }, { typeof(EntityManager), new EntityManager(new EntitySpawner(), simulationOwnership) } }; authenticatedPacketProcessorsByType = PacketProcessor.GetProcessors(ProcessorArguments, p => p.BaseType.IsGenericType && p.BaseType.GetGenericTypeDefinition() == typeof(AuthenticatedPacketProcessor <>)); unauthenticatedPacketProcessorsByType = PacketProcessor.GetProcessors(ProcessorArguments, p => p.BaseType.IsGenericType && p.BaseType.GetGenericTypeDefinition() == typeof(UnauthenticatedPacketProcessor <>)); }
private static void SpawnBabiesIfSimulating(IncubatorEgg egg) { SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); NitroxEntity serverKnownParent = egg.GetComponentInParent <NitroxEntity>(); Validate.NotNull(serverKnownParent, "Could not find a server known parent for incubator egg"); // Only spawn the babies if we are simulating the main incubator platform. if (simulationOwnership.HasAnyLockType(serverKnownParent.Id)) { GameObject baby = UnityEngine.Object.Instantiate <GameObject>(egg.seaEmperorBabyPrefab); baby.transform.position = egg.attachPoint.transform.position; baby.transform.localRotation = Quaternion.identity; NitroxId babyId = NitroxEntity.GetId(baby); Entity entity = new(baby.transform.position.ToDto(), baby.transform.rotation.ToDto(), baby.transform.localScale.ToDto(), TechType.SeaEmperorBaby.ToDto(), 3, "09883a6c-9e78-4bbf-9561-9fa6e49ce766", true, babyId, null); NitroxServiceLocator.LocateService <Entities>().BroadcastEntitySpawnedByClient(entity); } }
public static bool Prefix(Vehicle __instance, GUIHand hand) { if (skipPrefix) { return(true); } vehicle = __instance; guiHand = hand; SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); string guid = GuidHelper.GetGuid(__instance.gameObject); if (simulationOwnership.HasExclusiveLock(guid)) { Log.Debug($"Already have an exclusive lock on the vehicle: {guid}"); return(true); } simulationOwnership.RequestSimulationLock(guid, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse); return(false); }
public static bool Prefix(Vehicle __instance, GUIHand hand) { if (skipPrefix) { return(true); } SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); NitroxId id = NitroxEntity.GetId(__instance.gameObject); if (simulationOwnership.HasExclusiveLock(id)) { Log.Debug($"Already have an exclusive lock on the vehicle: {id}"); return(true); } HandInteraction <Vehicle> context = new(__instance, hand); LockRequest <HandInteraction <Vehicle> > lockRequest = new(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse, context); simulationOwnership.RequestSimulationLock(lockRequest); return(false); }
public static float AddHealthOverride(LiveMixin live, float addHealth, Welder welder) { float result = 0f; if ((live.IsAlive() || live.canResurrect) && live.health < live.maxHealth) { float num = live.health; float newHealth = Math.Min(live.health + addHealth, live.maxHealth); result = newHealth - num; SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); NitroxId id = NitroxEntity.GetId(live.gameObject); // For now, we only control the LiveMixin for vehicles (not even repair nodes at a cyclops) // If we change that, this if should be removed! Vehicle vehicle = live.GetComponent <Vehicle>(); if (vehicle) { if (simulationOwnership.HasAnyLockType(id)) { result = live.AddHealth(addHealth); } else { // Another player simulates this entity. Send the weld info Log.Debug($"Broadcast weld action for {id}"); NitroxServiceLocator.LocateService <LocalPlayer>().BroadcastWeld(id, addHealth); } } else { result = live.AddHealth(addHealth); } } return(result); }
public static bool Prefix(Incubator __instance, GUIHand hand) { if (skipPrefix) { return(true); } // Request a simulation lock on the incubator so that we can authoritatively spawn the resulting creatures if (__instance.powered && !__instance.hatched && Inventory.main.container.Contains(TechType.HatchingEnzymes)) { SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); // the server only knows about the the main incubator platform which is the direct parent GameObject platform = __instance.gameObject.transform.parent.gameObject; NitroxId id = NitroxEntity.GetId(platform); HandInteraction <Incubator> context = new HandInteraction <Incubator>(__instance, hand); LockRequest <HandInteraction <Incubator> > lockRequest = new LockRequest <HandInteraction <Incubator> >(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse, context); simulationOwnership.RequestSimulationLock(lockRequest); } return(false); }
public static bool Prefix(PropulsionCannon __instance, GameObject target) { if (skipPrefixPatch) { return(true); } SimulationOwnership simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); NitroxId id = NitroxEntity.GetId(target); if (simulationOwnership.HasExclusiveLock(id)) { Log.Debug($"Already have an exclusive lock on the grabbed propulsion cannon object: {id}"); return(true); } PropulsionGrab context = new(__instance, target); LockRequest <PropulsionGrab> lockRequest = new(id, SimulationLockType.EXCLUSIVE, ReceivedSimulationLockResponse, context); simulationOwnership.RequestSimulationLock(lockRequest); return(false); }
public SimulationOwnershipRequestProcessor(TcpServer tcpServer, SimulationOwnership simulationOwnership) { this.tcpServer = tcpServer; this.simulationOwnership = simulationOwnership; }
public override void Patch(Harmony harmony) { localPlayer = NitroxServiceLocator.LocateService <LocalPlayer>(); simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); PatchPostfix(harmony, TARGET_METHOD); }
public EntitySimulation(EntityData entityData, SimulationOwnership simulationOwnership) { this.entityData = entityData; this.simulationOwnership = simulationOwnership; }
public SimulationOwnershipChangeProcessor(IMultiplayerSession multiplayerSession, SimulationOwnership simulationOwnershipManager) { this.multiplayerSession = multiplayerSession; this.simulationOwnershipManager = simulationOwnershipManager; }
public override void Patch(Harmony harmony) { localPlayer = NitroxServiceLocator.LocateService <LocalPlayer>(); simulationOwnership = NitroxServiceLocator.LocateService <SimulationOwnership>(); PatchPrefix(harmony, targetMethod); }
public SimulationOwnershipRequestProcessor(PlayerManager playerManager, SimulationOwnership simulationOwnership) { this.playerManager = playerManager; this.simulationOwnership = simulationOwnership; }
public WeldActionProcessor(IMultiplayerSession multiplayerSession, SimulationOwnership simulationOwnership) { this.multiplayerSession = multiplayerSession; this.simulationOwnership = simulationOwnership; }