public void Update() { if (SceneLoader.loading) { return; } //ui.SetPlayerCount(players.Count); #region Unused Code //if (localHead != null && !enableFullRig) //{ // OtherPlayerPositionMessage oppm = new OtherPlayerPositionMessage // { // playerId = 0, // headPos = localHead.transform.position, // lHandPos = localHandL.transform.position, // rHandPos = localHandR.transform.position, // pelvisPos = localPelvis.transform.position, // lFootPos = localFootL.transform.position, // rFootPos = localFootR.transform.position, // headRot = localHead.transform.rotation, // lHandRot = localHandL.transform.rotation, // rHandRot = localHandR.transform.rotation, // pelvisRot = localPelvis.transform.rotation, // lFootRot = localFootL.transform.rotation, // rFootRot = localFootR.transform.rotation // }; // ServerSendToAll(oppm, P2PSend.Unreliable); //} //else if(enableFullRig && localHead != null) #endregion if (localRigTransforms.main == null) { localRigTransforms = BWUtil.GetLocalRigTransforms(); } if (localRigTransforms.main != null) { OtherFullRigTransformMessage ofrtm = new OtherFullRigTransformMessage { playerId = 0, posMain = localRigTransforms.main.position, posRoot = localRigTransforms.root.position, posLHip = localRigTransforms.lHip.position, posRHip = localRigTransforms.rHip.position, posLKnee = localRigTransforms.lKnee.position, posRKnee = localRigTransforms.rKnee.position, posLAnkle = localRigTransforms.lAnkle.position, posRAnkle = localRigTransforms.rAnkle.position, posSpine1 = localRigTransforms.spine1.position, posSpine2 = localRigTransforms.spine2.position, posSpineTop = localRigTransforms.spineTop.position, posLClavicle = localRigTransforms.lClavicle.position, posRClavicle = localRigTransforms.rClavicle.position, posNeck = localRigTransforms.neck.position, posLShoulder = localRigTransforms.lShoulder.position, posRShoulder = localRigTransforms.rShoulder.position, posLElbow = localRigTransforms.lElbow.position, posRElbow = localRigTransforms.rElbow.position, posLWrist = localRigTransforms.lWrist.position, posRWrist = localRigTransforms.rWrist.position, rotMain = localRigTransforms.main.rotation, rotRoot = localRigTransforms.root.rotation, rotLHip = localRigTransforms.lHip.rotation, rotRHip = localRigTransforms.rHip.rotation, rotLKnee = localRigTransforms.lKnee.rotation, rotRKnee = localRigTransforms.rKnee.rotation, rotLAnkle = localRigTransforms.lAnkle.rotation, rotRAnkle = localRigTransforms.rAnkle.rotation, rotSpine1 = localRigTransforms.spine1.rotation, rotSpine2 = localRigTransforms.spine2.rotation, rotSpineTop = localRigTransforms.spineTop.rotation, rotLClavicle = localRigTransforms.lClavicle.rotation, rotRClavicle = localRigTransforms.rClavicle.rotation, rotNeck = localRigTransforms.neck.rotation, rotLShoulder = localRigTransforms.lShoulder.rotation, rotRShoulder = localRigTransforms.rShoulder.rotation, rotLElbow = localRigTransforms.lElbow.rotation, rotRElbow = localRigTransforms.rElbow.rotation, rotLWrist = localRigTransforms.lWrist.rotation, rotRWrist = localRigTransforms.rWrist.rotation }; ServerSendToAll(ofrtm, MessageSendType.Unreliable); } foreach (PlayerRep pr in playerObjects.Values) { pr.UpdateNameplateFacing(Camera.current.transform); } // Disabled temporarily #if false { enemyPoolManager.FindMissingPools(); Pool pool = enemyPoolManager.GetPool(EnemyType.NullBody); for (int i = 0; i < pool.transform.childCount; i++) { GameObject childEnemy = pool.transform.GetChild(i).gameObject; BoneworksRigTransforms brt = BWUtil.GetHumanoidRigTransforms(childEnemy.transform.Find("brettEnemy@neutral").gameObject); EnemyRigTransformMessage ertf = new EnemyRigTransformMessage() { poolChildIdx = (byte)i, enemyType = EnemyType.NullBody, posMain = localRigTransforms.main.position, posRoot = localRigTransforms.root.position, posLHip = localRigTransforms.lHip.position, posRHip = localRigTransforms.rHip.position, posLKnee = localRigTransforms.lKnee.position, posRKnee = localRigTransforms.rKnee.position, posLAnkle = localRigTransforms.lAnkle.position, posRAnkle = localRigTransforms.rAnkle.position, posSpine1 = localRigTransforms.spine1.position, posSpine2 = localRigTransforms.spine2.position, posSpineTop = localRigTransforms.spineTop.position, posLClavicle = localRigTransforms.lClavicle.position, posRClavicle = localRigTransforms.rClavicle.position, posNeck = localRigTransforms.neck.position, posLShoulder = localRigTransforms.lShoulder.position, posRShoulder = localRigTransforms.rShoulder.position, posLElbow = localRigTransforms.lElbow.position, posRElbow = localRigTransforms.rElbow.position, posLWrist = localRigTransforms.lWrist.position, posRWrist = localRigTransforms.rWrist.position, rotMain = localRigTransforms.main.rotation, rotRoot = localRigTransforms.root.rotation, rotLHip = localRigTransforms.lHip.rotation, rotRHip = localRigTransforms.rHip.rotation, rotLKnee = localRigTransforms.lKnee.rotation, rotRKnee = localRigTransforms.rKnee.rotation, rotLAnkle = localRigTransforms.lAnkle.rotation, rotRAnkle = localRigTransforms.rAnkle.rotation, rotSpine1 = localRigTransforms.spine1.rotation, rotSpine2 = localRigTransforms.spine2.rotation, rotSpineTop = localRigTransforms.spineTop.rotation, rotLClavicle = localRigTransforms.lClavicle.rotation, rotRClavicle = localRigTransforms.rClavicle.rotation, rotNeck = localRigTransforms.neck.rotation, rotLShoulder = localRigTransforms.lShoulder.rotation, rotRShoulder = localRigTransforms.rShoulder.rotation, rotLElbow = localRigTransforms.lElbow.rotation, rotRElbow = localRigTransforms.rElbow.rotation, rotLWrist = localRigTransforms.lWrist.rotation, rotRWrist = localRigTransforms.rWrist.rotation }; ServerSendToAll(ertf, P2PSend.UnreliableNoDelay); } } #endif }
private void TransportLayer_OnMessageReceived(ITransportConnection arg1, P2PMessage msg) { MessageType type = (MessageType)msg.ReadByte(); try { switch (type) { case MessageType.GunFire: { GunFireMessageOther gfmo = new GunFireMessageOther(msg); PlayerRep pr = GetPlayerRep(gfmo.playerId); AmmoVariables ammoVariables = new AmmoVariables() { AttackDamage = gfmo.ammoDamage, AttackType = AttackType.Piercing, cartridgeType = Cart.Cal_9mm, ExitVelocity = gfmo.exitVelocity, ProjectileMass = gfmo.projectileMass, Tracer = false }; if ((StressLevelZero.Handedness)gfmo.handedness == StressLevelZero.Handedness.RIGHT) { pr.rightGunScript.firePointTransform.position = gfmo.firepointPos; pr.rightGunScript.firePointTransform.rotation = gfmo.firepointRotation; pr.rightGunScript.muzzleVelocity = gfmo.muzzleVelocity; pr.rightBulletObject.ammoVariables = ammoVariables; pr.rightGunScript.PullCartridge(); pr.rightGunScript.Fire(); } if ((StressLevelZero.Handedness)gfmo.handedness == StressLevelZero.Handedness.LEFT) { pr.leftGunScript.firePointTransform.position = gfmo.firepointPos; pr.leftGunScript.firePointTransform.rotation = gfmo.firepointRotation; pr.leftGunScript.muzzleVelocity = gfmo.muzzleVelocity; pr.leftBulletObject.ammoVariables = ammoVariables; pr.leftGunScript.PullCartridge(); pr.leftGunScript.Fire(); } pr.faceAnimator.faceState = Source.Representations.FaceAnimator.FaceState.Angry; pr.faceAnimator.faceTime = 5; break; } case MessageType.OtherPlayerPosition: { OtherPlayerPositionMessage oppm = new OtherPlayerPositionMessage(msg); if (playerObjects.ContainsKey(oppm.playerId)) { PlayerRep pr = GetPlayerRep(oppm.playerId); pr.head.transform.position = oppm.headPos; pr.handL.transform.position = oppm.lHandPos; pr.handR.transform.position = oppm.rHandPos; pr.pelvis.transform.position = oppm.pelvisPos; pr.ford.transform.position = oppm.pelvisPos - new Vector3(0.0f, 0.3f, 0.0f); pr.footL.transform.position = oppm.lFootPos; pr.footR.transform.position = oppm.rFootPos; pr.head.transform.rotation = oppm.headRot; pr.handL.transform.rotation = oppm.lHandRot; pr.handR.transform.rotation = oppm.rHandRot; pr.pelvis.transform.rotation = oppm.pelvisRot; pr.footL.transform.rotation = oppm.lFootRot; pr.footR.transform.rotation = oppm.rFootRot; } break; } case MessageType.OtherFullRig: { OtherFullRigTransformMessage ofrtm = new OtherFullRigTransformMessage(msg); byte playerId = ofrtm.playerId; if (playerObjects.ContainsKey(ofrtm.playerId)) { PlayerRep pr = GetPlayerRep(playerId); pr.ApplyTransformMessage(ofrtm); } break; } case MessageType.ServerShutdown: { foreach (PlayerRep pr in playerObjects.Values) { pr.Delete(); } break; } case MessageType.Disconnect: { byte pid = msg.ReadByte(); playerObjects[pid].Delete(); playerObjects.Remove(pid); largePlayerIds.Remove(pid); playerNames.Remove(pid); foreach (PlayerRep pr in playerObjects.Values) { pr.faceAnimator.faceState = Source.Representations.FaceAnimator.FaceState.Sad; pr.faceAnimator.faceTime = 10; } break; } case MessageType.JoinRejected: { MelonLogger.LogError("Join rejected - you are using an incompatible version of the mod!"); Disconnect(); break; } case MessageType.SceneTransition: { SceneTransitionMessage stm = new SceneTransitionMessage(msg); if (BoneworksSceneManager.GetCurrentSceneName() != stm.sceneName) { BoneworksSceneManager.LoadScene(stm.sceneName); } break; } case MessageType.Join: { ClientJoinMessage cjm = new ClientJoinMessage(msg); largePlayerIds.Add(cjm.playerId, cjm.steamId); playerNames.Add(cjm.playerId, cjm.name); playerObjects.Add(cjm.playerId, new PlayerRep(cjm.name, cjm.steamId)); foreach (PlayerRep pr in playerObjects.Values) { pr.faceAnimator.faceState = Source.Representations.FaceAnimator.FaceState.Happy; pr.faceAnimator.faceTime = 15; } break; } case MessageType.SetPartyId: { SetPartyIdMessage spid = new SetPartyIdMessage(msg); RichPresence.SetActivity( new Activity() { Details = "Connected to a server", Secrets = new ActivitySecrets() { Join = ServerId.ToString() }, Party = new ActivityParty() { Id = spid.partyId, Size = new PartySize() { CurrentSize = 1, MaxSize = MultiplayerMod.MAX_PLAYERS } } }); break; } case MessageType.EnemyRigTransform: { enemyPoolManager.FindMissingPools(); EnemyRigTransformMessage ertm = new EnemyRigTransformMessage(msg); Pool pool = enemyPoolManager.GetPool(ertm.enemyType); // HORRID PERFORMANCE Transform enemyTf = pool.transform.GetChild(ertm.poolChildIdx); GameObject rootObj = enemyTf.Find("enemyBrett@neutral").gameObject; BoneworksRigTransforms brt = BWUtil.GetHumanoidRigTransforms(rootObj); BWUtil.ApplyRigTransform(brt, ertm); break; } case MessageType.IdAllocation: { IDAllocationMessage iam = new IDAllocationMessage(msg); GameObject obj = BWUtil.GetObjectFromFullPath(iam.namePath); if (!obj) { MelonLogger.LogWarning("Got IdAllocation for nonexistent object???"); } ObjectIDManager.AddObject(iam.allocatedId, obj); var so = obj.AddComponent <SyncedObject>(); so.ID = iam.allocatedId; so.owner = iam.initialOwner; so.rb = obj.GetComponent <Rigidbody>(); syncedObjects.Add(so); if (so.owner != localSmallId) { so.rb.isKinematic = true; } MelonLogger.Log($"ID Allocation: {iam.namePath}, {so.ID}"); break; } case MessageType.ObjectSync: { ObjectSyncMessage osm = new ObjectSyncMessage(msg); GameObject obj = ObjectIDManager.GetObject(osm.id); if (!obj) { MelonLogger.LogError($"Couldn't find object with ID {osm.id}"); } else { obj.transform.position = osm.position; obj.transform.rotation = osm.rotation; } break; } case MessageType.ChangeObjectOwnership: { var coom = new ChangeObjectOwnershipMessage(msg); var obj = ObjectIDManager.GetObject(coom.objectId); var so = obj.GetComponent <SyncedObject>(); so.owner = coom.ownerId; if (so.owner == localSmallId) { so.rb.isKinematic = false; so.rb.velocity = coom.linVelocity; so.rb.angularVelocity = coom.angVelocity; } else { so.rb.isKinematic = true; } MelonLogger.Log($"Object {coom.objectId} is now owned by {coom.ownerId} (kinematic: {so.rb.isKinematic})"); break; } case MessageType.SetLocalSmallId: { var slsi = new SetLocalSmallIdMessage(msg); localSmallId = slsi.smallId; break; } } } catch (Exception e) { MelonLogger.LogError($"Caught exception in message handler for message {type}: {e}"); } }
private void TransportLayer_OnMessageReceived(ITransportConnection arg1, P2PMessage msg) { MessageType type = (MessageType)msg.ReadByte(); switch (type) { case MessageType.OtherPlayerPosition: { OtherPlayerPositionMessage oppm = new OtherPlayerPositionMessage(msg); if (playerObjects.ContainsKey(oppm.playerId)) { PlayerRep pr = GetPlayerRep(oppm.playerId); pr.head.transform.position = oppm.headPos; pr.handL.transform.position = oppm.lHandPos; pr.handR.transform.position = oppm.rHandPos; pr.pelvis.transform.position = oppm.pelvisPos; pr.ford.transform.position = oppm.pelvisPos - new Vector3(0.0f, 0.3f, 0.0f); pr.footL.transform.position = oppm.lFootPos; pr.footR.transform.position = oppm.rFootPos; pr.head.transform.rotation = oppm.headRot; pr.handL.transform.rotation = oppm.lHandRot; pr.handR.transform.rotation = oppm.rHandRot; pr.pelvis.transform.rotation = oppm.pelvisRot; pr.footL.transform.rotation = oppm.lFootRot; pr.footR.transform.rotation = oppm.rFootRot; } break; } case MessageType.OtherFullRig: { OtherFullRigTransformMessage ofrtm = new OtherFullRigTransformMessage(msg); byte playerId = ofrtm.playerId; if (playerObjects.ContainsKey(ofrtm.playerId)) { PlayerRep pr = GetPlayerRep(playerId); pr.ApplyTransformMessage(ofrtm); } break; } case MessageType.ServerShutdown: { foreach (PlayerRep pr in playerObjects.Values) { pr.Destroy(); } break; } case MessageType.Disconnect: { byte pid = msg.ReadByte(); playerObjects[pid].Destroy(); playerObjects.Remove(pid); largePlayerIds.Remove(pid); playerNames.Remove(pid); break; } case MessageType.JoinRejected: { MelonModLogger.LogError("Join rejected - you are using an incompatible version of the mod!"); Disconnect(); break; } case MessageType.SceneTransition: { SceneTransitionMessage stm = new SceneTransitionMessage(msg); if (BoneworksSceneManager.GetCurrentSceneName() != stm.sceneName) { BoneworksSceneManager.LoadScene(stm.sceneName); } break; } case MessageType.Join: { ClientJoinMessage cjm = new ClientJoinMessage(msg); largePlayerIds.Add(cjm.playerId, cjm.steamId); playerNames.Add(cjm.playerId, cjm.name); playerObjects.Add(cjm.playerId, new PlayerRep(cjm.name, cjm.steamId)); break; } case MessageType.OtherHandGunChange: { HandGunChangeMessage hgcm = new HandGunChangeMessage(msg, true); if (hgcm.destroy) { Destroy(playerObjects[hgcm.playerId].currentGun); } else { PlayerRep pr = playerObjects[hgcm.playerId]; pr.currentGun = BWUtil.SpawnGun(hgcm.type); pr.currentGun.transform.parent = pr.gunParent.transform; pr.currentGun.transform.localPosition = Vector3.zero; pr.currentGun.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 90.0f); pr.currentGun.GetComponent <Rigidbody>().isKinematic = true; } break; } case MessageType.SetPartyId: { SetPartyIdMessage spid = new SetPartyIdMessage(msg); RichPresence.SetActivity( new Activity() { Details = "Connected to a server", Secrets = new ActivitySecrets() { Join = ServerId.ToString() }, Party = new ActivityParty() { Id = spid.partyId, Size = new PartySize() { CurrentSize = 1, MaxSize = MultiplayerMod.MAX_PLAYERS } } }); break; } case MessageType.EnemyRigTransform: { enemyPoolManager.FindMissingPools(); EnemyRigTransformMessage ertm = new EnemyRigTransformMessage(msg); Pool pool = enemyPoolManager.GetPool(ertm.enemyType); // HORRID PERFORMANCE Transform enemyTf = pool.transform.GetChild(ertm.poolChildIdx); GameObject rootObj = enemyTf.Find("enemyBrett@neutral").gameObject; BoneworksRigTransforms brt = BWUtil.GetHumanoidRigTransforms(rootObj); BWUtil.ApplyRigTransform(brt, ertm); break; } } }