Exemplo n.º 1
0
        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}");
            }
        }
Exemplo n.º 2
0
        // Constructor
        public PlayerRep(string name, SteamId steamId)
        {
            this.steamId = steamId;

            // Create this player's "Ford" to represent them, known as their rep
            GameObject ford = Instantiate(fordBundle.LoadAsset("Assets/Ford.prefab").Cast <GameObject>());

            // Makes sure that the rep isn't destroyed per level change.
            DontDestroyOnLoad(ford);


            GameObject root     = ford.transform.Find("Ford/Brett@neutral").gameObject; // Get the rep's head
            Transform  realRoot = root.transform.Find("SHJntGrp/MAINSHJnt/ROOTSHJnt");  // Then get the head's root joint

            #region Unused Code
            // Networked IK code?

            //var ik = root.AddComponent<VRIK>();

            //VRIK.References bipedReferences = new VRIK.References
            //{
            //    root = root.transform.Find("SHJntGrp"),

            //    spine = realRoot.Find("Spine_01SHJnt"),
            //    pelvis = realRoot,

            //    leftThigh = realRoot.Find("l_Leg_HipSHJnt"),
            //    leftCalf = realRoot.Find("l_Leg_HipSHJnt/l_Leg_KneeSHJnt"),
            //    leftFoot = realRoot.Find("l_Leg_HipSHJnt/l_Leg_KneeSHJnt/l_Leg_AnkleSHJnt"),
            //    leftToes = realRoot.Find("l_Leg_HipSHJnt/l_Leg_KneeSHJnt/l_Leg_AnkleSHJnt/l_Leg_BallSHJnt"),

            //    rightThigh = realRoot.Find("r_Leg_HipSHJnt"),
            //    rightCalf = realRoot.Find("r_Leg_HipSHJnt/r_Leg_KneeSHJnt"),
            //    rightFoot = realRoot.Find("r_Leg_HipSHJnt/r_Leg_KneeSHJnt/r_Leg_AnkleSHJnt"),
            //    rightToes = realRoot.Find("r_Leg_HipSHJnt/r_Leg_KneeSHJnt/r_Leg_AnkleSHJnt/r_Leg_BallSHJnt"),

            //    leftUpperArm = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/l_Arm_ClavicleSHJnt/l_AC_AuxSHJnt/l_Arm_ShoulderSHJnt"),
            //    leftForearm = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/l_Arm_ClavicleSHJnt/l_AC_AuxSHJnt/l_Arm_ShoulderSHJnt/l_Arm_Elbow_CurveSHJnt"),
            //    leftHand = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/l_Arm_ClavicleSHJnt/l_AC_AuxSHJnt/l_Arm_ShoulderSHJnt/l_Arm_Elbow_CurveSHJnt/l_WristSHJnt/l_Hand_1SHJnt"),
            //    //leftShoulder = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/l_Arm_ClavicleSHJnt/l_AC_AuxSHJnt/l_Arm_ShoulderSHJnt"),

            //    rightUpperArm = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/r_Arm_ClavicleSHJnt/r_AC_AuxSHJnt/r_Arm_ShoulderSHJnt"),
            //    rightForearm = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/r_Arm_ClavicleSHJnt/r_AC_AuxSHJnt/r_Arm_ShoulderSHJnt/r_Arm_Elbow_CurveSHJnt"),
            //    rightHand = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/r_Arm_ClavicleSHJnt/r_AC_AuxSHJnt/r_Arm_ShoulderSHJnt/r_Arm_Elbow_CurveSHJnt/r_WristSHJnt/r_Hand_1SHJnt"),
            //    //rightShoulder = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/r_Arm_ClavicleSHJnt/r_AC_AuxSHJnt/r_Arm_ShoulderSHJnt"),

            //    head = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/Neck_01SHJnt")
            //};

            ////ik.AutoDetectReferences();
            //ik.enabled = false;
            //ik.references = bipedReferences;
            ////ik.solver.plantFeet = false;
            //ik.fixTransforms = false;

            //ik.solver.leftLeg.positionWeight = 1.0f;
            //ik.solver.leftLeg.swivelOffset = 0.0f;
            //ik.solver.leftLeg.bendToTargetWeight = 0.0f;
            //ik.solver.leftLeg.legLengthMlp = 1.0f;

            //ik.solver.rightLeg.positionWeight = 1.0f;
            //ik.solver.rightLeg.swivelOffset = 0.0f;
            //ik.solver.rightLeg.bendToTargetWeight = 0.0f;
            //ik.solver.rightLeg.legLengthMlp = 1.0f;

            //ik.solver.hasChest = false;
            //ik.solver.spine.chestGoalWeight = 0.0f;
            //ik.solver.spine.pelvisPositionWeight = 0.0f;
            //ik.solver.spine.pelvisRotationWeight = 0.0f;
            //ik.solver.spine.positionWeight = 1.0f;
            //ik.solver.spine.rotationWeight = 1.0f;
            //ik.solver.spine.minHeadHeight = 0.8f;
            //ik.solver.spine.bodyPosStiffness = 0.55f;
            //ik.solver.spine.bodyRotStiffness = 0.1f;
            //ik.solver.spine.neckStiffness = 0.3f;
            //ik.solver.spine.rotateChestByHands = 1.0f;
            //ik.solver.spine.chestClampWeight = 0.5f;
            //ik.solver.spine.headClampWeight = 0.6f;
            //ik.solver.spine.moveBodyBackWhenCrouching = 0.5f;
            //ik.solver.spine.maintainPelvisPosition = 0.2f;
            //ik.solver.spine.maxRootAngle = 25.0f;

            //ik.solver.leftArm.positionWeight = 1.0f;
            //ik.solver.leftArm.rotationWeight = 1.0f;
            //ik.solver.leftArm.shoulderRotationMode = IKSolverVR.Arm.ShoulderRotationMode.YawPitch;
            //ik.solver.leftArm.shoulderRotationWeight = 0.5f;
            //ik.solver.leftArm.shoulderTwistWeight = 1.0f;
            //ik.solver.leftArm.bendGoalWeight = 0.0f;
            //ik.solver.leftArm.swivelOffset = 20.0f;
            //ik.solver.leftArm.armLengthMlp = 1.0f;

            //ik.solver.rightArm.positionWeight = 1.0f;
            //ik.solver.rightArm.rotationWeight = 1.0f;
            //ik.solver.rightArm.shoulderRotationMode = IKSolverVR.Arm.ShoulderRotationMode.YawPitch;
            //ik.solver.rightArm.shoulderRotationWeight = 0.5f;
            //ik.solver.rightArm.shoulderTwistWeight = 1.0f;
            //ik.solver.rightArm.bendGoalWeight = 0.0f;
            //ik.solver.rightArm.swivelOffset = 20.0f;
            //ik.solver.rightArm.armLengthMlp = 1.0f;

            //IKSolverVR.Locomotion l = ik.solver.locomotion;
            //l.weight = 0.0f;
            //l.blockingEnabled = false;
            //l.blockingLayers = LayerMask.NameToLayer("Default");
            //l.footDistance = 0.3f;
            //l.stepThreshold = 0.35f;
            //l.angleThreshold = 60.0f;
            //l.comAngleMlp = 0.5f;
            //l.maxVelocity = 0.3f;
            //l.velocityFactor = 0.3f;
            //l.maxLegStretch = 0.98f;
            //l.rootSpeed = 20.0f;
            //l.stepSpeed = 2.8f;
            //l.relaxLegTwistMinAngle = 20.0f;
            //l.relaxLegTwistSpeed = 400.0f;
            //l.stepInterpolation = InterpolationMode.InOutSine;
            //l.offset = Vector3.zero;
            #endregion

            // Assign targets for the IK system
            //GameObject lHandTarget = new GameObject("LHand");
            //GameObject rHandTarget = new GameObject("RHand");
            GameObject pelvisTarget = new GameObject("Pelvis");
            //GameObject headTarget = new GameObject("HeadTarget");
            //GameObject lFootTarget = new GameObject("LFoot");
            //GameObject rFootTarget = new GameObject("RFoot");

            // Create an anchor object to hold the rep's gun
            gunParent = new GameObject("gunParent");
            gunParent.transform.parent        = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/r_Arm_ClavicleSHJnt/r_AC_AuxSHJnt/r_Arm_ShoulderSHJnt/r_Arm_Elbow_CurveSHJnt/r_WristSHJnt/r_Hand_1SHJnt");
            gunParent.transform.localPosition = Vector3.zero;
            gunParent.transform.localRotation = Quaternion.identity;

            // If for whatever reason this is needed, show or hide the rep's body and hair
            root.transform.Find("geoGrp/brett_body").GetComponent <SkinnedMeshRenderer>().enabled = showBody;
            root.transform.Find("geoGrp/brett_hairCards").gameObject.SetActive(showHair);

            #region Unused Code
            // IK code?

            //ik.solver.leftArm.target = lHandTarget.transform;
            //ik.solver.rightArm.target = rHandTarget.transform;
            //ik.solver.spine.pelvisTarget = pelvisTarget.transform;
            //ik.solver.spine.headTarget = headTarget.transform;
            //ik.solver.leftLeg.target = lFootTarget.transform;
            //ik.solver.rightLeg.target = rFootTarget.transform;

            //footL = ik.solver.leftLeg.target.gameObject;
            //footR = ik.solver.rightLeg.target.gameObject;

            //head = headTarget;
            //handL = lHandTarget;
            //handR = rHandTarget;
            //pelvis = pelvisTarget;
            #endregion

            // Assign the transforms for the rep
            rigTransforms = BWUtil.GetHumanoidRigTransforms(root);

            // Grab these body parts from the rigTransforms
            head   = rigTransforms.neck.gameObject;
            handL  = rigTransforms.lWrist.gameObject;
            handR  = rigTransforms.rWrist.gameObject;
            pelvis = rigTransforms.spine1.gameObject;

            // Create the nameplate and assign values to the TMP's vars
            namePlate = new GameObject("Nameplate");
            TextMeshPro tm = namePlate.AddComponent <TextMeshPro>();
            tm.text      = name;
            tm.color     = UnityEngine.Color.green;
            tm.alignment = TextAlignmentOptions.Center;
            tm.fontSize  = 1.0f;

            // Prevents the nameplate from being destroyed during a level change
            DontDestroyOnLoad(namePlate);

            MelonCoroutines.Start(AsyncAvatarRoutine(steamId));

            // Gives certain users special appearances
            Extras.SpecialUsers.GiveUniqueAppearances(steamId, realRoot, tm);

            // Change the shader to the one that's already used in the game
            // Without this, the player model will only show in one eye
            foreach (SkinnedMeshRenderer smr in ford.GetComponentsInChildren <SkinnedMeshRenderer>())
            {
                foreach (Material m in smr.sharedMaterials)
                {
                    m.shader = Shader.Find("Valve/vr_standard");
                }
            }
            foreach (MeshRenderer smr in ford.GetComponentsInChildren <MeshRenderer>())
            {
                foreach (Material m in smr.sharedMaterials)
                {
                    m.shader = Shader.Find("Valve/vr_standard");
                }
            }

#if DEBUG
            zCubed.Accessories.Accessory.CreateDummies(realRoot.parent);
#endif

            this.ford = ford;

            #region Unused Code
            // More IK stuff?

            //lArm = ik.solver.leftArm;
            //rArm = ik.solver.rightArm;
            //spine = ik.solver.spine;
            #endregion
        }
Exemplo n.º 3
0
        // Constructor
        public PlayerRep(string name, SteamId steamId)
        {
            this.steamId = steamId;

            // Create this player's "Ford" to represent them, known as their rep
            GameObject ford = Instantiate(fordBundle.LoadAsset("Assets/Ford.prefab").Cast <GameObject>());

            // Makes sure that the rep isn't destroyed per level change.
            DontDestroyOnLoad(ford);

            ImpactPropertiesManager bloodManager = ford.AddComponent <ImpactPropertiesManager>();

            bloodManager.material              = ImpactPropertiesVariables.Material.Blood;
            bloodManager.modelType             = ImpactPropertiesVariables.ModelType.Skinned;
            bloodManager.MainColor             = UnityEngine.Color.red;
            bloodManager.SecondaryColor        = UnityEngine.Color.red;
            bloodManager.PenetrationResistance = 0.8f;
            bloodManager.megaPascalModifier    = 1;
            bloodManager.FireResistance        = 100;
            Collider[] colliders = ford.GetComponentsInChildren <Collider>();
            foreach (Collider c in colliders)
            {
                ImpactProperties blood = c.gameObject.AddComponent <ImpactProperties>();
                blood.material              = ImpactPropertiesVariables.Material.Blood;
                blood.modelType             = ImpactPropertiesVariables.ModelType.Skinned;
                blood.MainColor             = UnityEngine.Color.red;
                blood.SecondaryColor        = UnityEngine.Color.red;
                blood.PenetrationResistance = 0.8f;
                blood.megaPascalModifier    = 1;
                blood.FireResistance        = 100;
                blood.MyCollider            = c;
                blood.hasManager            = true;
                blood.Manager = bloodManager;
            }

            GameObject root = ford.transform.Find("Ford/Brett@neutral").gameObject; // Get the rep's head

            faceAnimator          = new FaceAnimator();
            faceAnimator.animator = root.GetComponent <Animator>();
            faceAnimator.faceTime = 10;

            Transform realRoot = root.transform.Find("SHJntGrp/MAINSHJnt/ROOTSHJnt"); // Then get the head's root joint


            // Assign targets for the IK system
            GameObject pelvisTarget = new GameObject("Pelvis");

            // Create an anchor object to hold the rep's gun
            gunRParent = new GameObject("gunRParent");
            gunRParent.transform.parent           = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/r_Arm_ClavicleSHJnt/r_AC_AuxSHJnt/r_Arm_ShoulderSHJnt/r_Arm_Elbow_CurveSHJnt/r_WristSHJnt/r_Hand_1SHJnt");
            gunRParent.transform.localPosition    = new Vector3(0.0758f, -0.0459f, -0.0837f);
            gunRParent.transform.localEulerAngles = new Vector3(2.545f, -251.689f, 149.121f);

            GameObject              rig        = Player.FindRigManager();
            PopUpMenuView           menu       = rig.GetComponentInChildren <PopUpMenuView>();
            GameObject              spawnGun   = menu.utilityGunSpawnable.prefab;
            SpawnableMasterListData masterList = spawnGun.GetComponent <SpawnGun>().masterList;

            rightGun = Instantiate(masterList.objects[BWUtil.gunOffset].prefab.transform.Find("Physics/Root/Gun").gameObject);
            rightGun.GetComponent <Rigidbody>().isKinematic = true;
            rightGun.transform.parent        = gunRParent.transform;
            rightGun.transform.localPosition = Vector3.zero;
            rightGun.transform.localRotation = Quaternion.identity;
            rightGunScript = rightGun.GetComponent <Gun>();
            rightGunScript.proxyOverride   = null;
            rightBulletObject              = rightGunScript.overrideMagazine.AmmoSlots[0];
            rightGunScript.roundsPerMinute = 20000;
            rightGunScript.roundsPerSecond = 333;
            GameObject.Destroy(rightGun.GetComponent <ConfigurableJoint>());
            GameObject.Destroy(rightGun.GetComponent <ImpactProperties>());
            GameObject.Destroy(rightGun.transform.Find("attachment_Lazer_Omni").gameObject);

            // Create an anchor object to hold the rep's gun
            gunLParent = new GameObject("gunLParent");
            gunLParent.transform.parent           = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/l_Arm_ClavicleSHJnt/l_AC_AuxSHJnt/l_Arm_ShoulderSHJnt/l_Arm_Elbow_CurveSHJnt/l_WristSHJnt/l_Hand_1SHJnt");
            gunLParent.transform.localPosition    = new Vector3(-0.0941f, 0.0452f, 0.0945f);
            gunLParent.transform.localEulerAngles = new Vector3(3.711f, -81.86301f, -157.739f);

            leftGun = Instantiate(masterList.objects[BWUtil.gunOffset].prefab.transform.Find("Physics/Root/Gun").gameObject);
            leftGun.GetComponent <Rigidbody>().isKinematic = true;
            leftGun.transform.parent        = gunLParent.transform;
            leftGun.transform.localPosition = Vector3.zero;
            leftGun.transform.localRotation = Quaternion.identity;
            leftGunScript = leftGun.GetComponent <Gun>();
            leftGunScript.proxyOverride = null;
            leftBulletObject            = leftGunScript.overrideMagazine.AmmoSlots[0];
            GameObject.Destroy(leftGun.GetComponent <ConfigurableJoint>());
            GameObject.Destroy(leftGun.transform.Find("attachment_Lazer_Omni").gameObject);
            GameObject.Destroy(leftGun.GetComponent <ImpactProperties>());

            foreach (var renderer in gunLParent.GetComponentsInChildren <Renderer>())
            {
                renderer.enabled = false;
            }

            foreach (var renderer in gunRParent.GetComponentsInChildren <Renderer>())
            {
                renderer.enabled = false;
            }

            foreach (var col in gunLParent.GetComponentsInChildren <Collider>())
            {
                Destroy(col);
            }

            foreach (var col in gunRParent.GetComponentsInChildren <Collider>())
            {
                Destroy(col);
            }

            // If for whatever reason this is needed, show or hide the rep's body and hair
            root.transform.Find("geoGrp/brett_body").GetComponent <SkinnedMeshRenderer>().enabled = showBody;
            //root.transform.Find("geoGrp/brett_hairCards").gameObject.SetActive(showHair);

            // Assign the transforms for the rep
            rigTransforms = BWUtil.GetHumanoidRigTransforms(root);

            // Grab these body parts from the rigTransforms
            head   = rigTransforms.neck.gameObject;
            handL  = rigTransforms.lWrist.gameObject;
            handR  = rigTransforms.rWrist.gameObject;
            pelvis = rigTransforms.spine1.gameObject;

            // Create the nameplate and assign values to the TMP's vars
            namePlate = new GameObject("Nameplate");
            TextMeshPro tm = namePlate.AddComponent <TextMeshPro>();

            tm.text      = name;
            tm.color     = UnityEngine.Color.green;
            tm.alignment = TextAlignmentOptions.Center;
            tm.fontSize  = 1.0f;

            // Prevents the nameplate from being destroyed during a level change
            DontDestroyOnLoad(namePlate);

            MelonCoroutines.Start(AsyncAvatarRoutine(steamId));

            // Gives certain users special appearances
            Extras.SpecialUsers.GiveUniqueAppearances(steamId, realRoot, tm);

            this.ford = ford;
        }
Exemplo n.º 4
0
        // Constructor
        public PlayerRep(string name, SteamId steamId)
        {
            this.steamId = steamId;

            // Create this player's "Ford" to represent them, known as their rep
            GameObject ford = Instantiate(fordBundle.LoadAsset("Assets/Ford.prefab").Cast <GameObject>());

            // Makes sure that the rep isn't destroyed per level change.
            DontDestroyOnLoad(ford);


            GameObject root     = ford.transform.Find("Ford/Brett@neutral").gameObject; // Get the rep's head
            Transform  realRoot = root.transform.Find("SHJntGrp/MAINSHJnt/ROOTSHJnt");  // Then get the head's root joint


            // Assign targets for the IK system
            GameObject pelvisTarget = new GameObject("Pelvis");

            // Create an anchor object to hold the rep's gun
            gunParent = new GameObject("gunParent");
            gunParent.transform.parent        = realRoot.Find("Spine_01SHJnt/Spine_02SHJnt/Spine_TopSHJnt/r_Arm_ClavicleSHJnt/r_AC_AuxSHJnt/r_Arm_ShoulderSHJnt/r_Arm_Elbow_CurveSHJnt/r_WristSHJnt/r_Hand_1SHJnt");
            gunParent.transform.localPosition = Vector3.zero;
            gunParent.transform.localRotation = Quaternion.identity;

            // If for whatever reason this is needed, show or hide the rep's body and hair
            root.transform.Find("geoGrp/brett_body").GetComponent <SkinnedMeshRenderer>().enabled = showBody;
            root.transform.Find("geoGrp/brett_hairCards").gameObject.SetActive(showHair);

            // Assign the transforms for the rep
            rigTransforms = BWUtil.GetHumanoidRigTransforms(root);

            // Grab these body parts from the rigTransforms
            head   = rigTransforms.neck.gameObject;
            handL  = rigTransforms.lWrist.gameObject;
            handR  = rigTransforms.rWrist.gameObject;
            pelvis = rigTransforms.spine1.gameObject;

            // Create the nameplate and assign values to the TMP's vars
            namePlate = new GameObject("Nameplate");
            TextMeshPro tm = namePlate.AddComponent <TextMeshPro>();

            tm.text      = name;
            tm.color     = UnityEngine.Color.green;
            tm.alignment = TextAlignmentOptions.Center;
            tm.fontSize  = 1.0f;

            // Prevents the nameplate from being destroyed during a level change
            DontDestroyOnLoad(namePlate);

            MelonCoroutines.Start(AsyncAvatarRoutine(steamId));

            // Gives certain users special appearances
            Extras.SpecialUsers.GiveUniqueAppearances(steamId, realRoot, tm);

            // Change the shader to the one that's already used in the game
            // Without this, the player model will only show in one eye
            foreach (SkinnedMeshRenderer smr in ford.GetComponentsInChildren <SkinnedMeshRenderer>())
            {
                foreach (Material m in smr.sharedMaterials)
                {
                    m.shader = Shader.Find("Valve/vr_standard");
                }
            }
            foreach (MeshRenderer smr in ford.GetComponentsInChildren <MeshRenderer>())
            {
                foreach (Material m in smr.sharedMaterials)
                {
                    m.shader = Shader.Find("Valve/vr_standard");
                }
            }

#if DEBUG
            zCubed.Accessories.Accessory.CreateDummies(realRoot.parent);
#endif

            this.ford = ford;
        }
Exemplo n.º 5
0
        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
        }
Exemplo n.º 6
0
        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;
            }
            }
        }