Esempio n. 1
0
        public void ApplyTextures()
        {
            foreach (MultiplayerRemoteTexture mpTex in multiplayerTextures)
            {
                if (mpTex.saved && !mpTex.loaded && !(mpTex.infoType == GearInfoType.Body))
                {
                    mpTex.LoadFromFileMainThread(this);
                }
                else if (mpTex.saved && !mpTex.loaded && mpTex.textureType.Equals("head", StringComparison.InvariantCultureIgnoreCase))
                {
                    MultiplayerRemoteTexture bodyTex = multiplayerTextures.Find((t) => t.textureType.Equals("body", StringComparison.InvariantCultureIgnoreCase));
                    if (bodyTex != null)
                    {
                        UnityModManagerNet.UnityModManager.Logger.Log($"Updating body textures for {this.bodyType} id: {this.playerID}");

                        bodyTex.loaded = true;
                        mpTex.loaded   = true;

                        TextureChange[] headChange = { new TextureChange("albedo", mpTex.fileLocation) };
                        TextureChange[] bodyChange = { new TextureChange("albedo", bodyTex.fileLocation) };

                        List <MaterialChange> materialChanges = new List <MaterialChange>();
                        materialChanges.Add(new MaterialChange("body", bodyChange));
                        materialChanges.Add(new MaterialChange("head", headChange));

                        CharacterBodyInfo bodyInfo = new CharacterBodyInfo("MP Temp body", this.bodyType, true, materialChanges, new string[0]);

                        characterCustomizer.EquipGear(bodyInfo);
                    }
                }
            }
        }
Esempio n. 2
0
        public void ParseTextureStream(byte[] inTextureStream)
        {
            ushort currentMessage = BitConverter.ToUInt16(inTextureStream, 0);
            ushort totalMessages  = BitConverter.ToUInt16(inTextureStream, 2);

            for (int i = 4; i < inTextureStream.Length; i++)
            {
                gearStream.Add(inTextureStream[i]);
            }

            this.debugWriter.WriteLine($"Texture {currentMessage}/{totalMessages}");

            if (currentMessage != totalMessages)
            {
                return;
            }
            this.debugWriter.WriteLine($"Finished Texture loading");

            byte[] textureStream = gearStream.ToArray();

            ushort bodyTypeLen = BitConverter.ToUInt16(textureStream, 0);

            this.bodyType = Encoding.UTF8.GetString(textureStream, 2, bodyTypeLen);

            UnityModManagerNet.UnityModManager.Logger.Log($"Attempting to equip body with name length {bodyTypeLen} and name: {bodyType}!");

            CharacterBodyInfo bodyInfo = new CharacterBodyInfo("MP Temp body", this.bodyType, false, null, new string[0]);

            characterCustomizer.EquipGear(bodyInfo);

            int readBytes = 2 + bodyTypeLen;

            while (readBytes < textureStream.Length - 1)
            {
                UnityModManagerNet.UnityModManager.Logger.Log($"Read {readBytes} bytes of {textureStream.Length}");
                bool         customTex   = textureStream[readBytes] == 1 ? true : false;
                GearInfoType texInfotype = (GearInfoType)textureStream[readBytes + 1];

                readBytes += 2;
                if (customTex)
                {
                    ushort typeLen = BitConverter.ToUInt16(textureStream, readBytes);
                    int    dataLen = BitConverter.ToInt32(textureStream, readBytes + 2);

                    string texType = Encoding.UTF8.GetString(textureStream, readBytes + 6, typeLen);
                    readBytes += 6 + typeLen;

                    byte[] texData = new byte[dataLen];
                    Array.Copy(textureStream, readBytes, texData, 0, dataLen);
                    readBytes += dataLen;

                    MultiplayerRemoteTexture newTexture = new MultiplayerRemoteTexture(customTex, "", texType, texInfotype, this.debugWriter);
                    multiplayerTextures.Add(newTexture);
                    newTexture.SaveTexture(this.playerID, texData);
                }
            }
        }
        public void ApplyTextures()
        {
            if (this.receivedTextures && !this.loadedTextures && GameManagement.GameStateMachine.Instance.CurrentState.GetType() != typeof(GameManagement.ReplayState))
            {
                characterCustomizer.RemoveAllGear();
                characterCustomizer.RemoveAllGear(true);

                Transform[] ignoredObjects = characterCustomizer.WheelParents.Union(characterCustomizer.TruckHangerParents).Union(characterCustomizer.TruckBaseParents).Append(characterCustomizer.DeckParent).Append(characterCustomizer.ClothingParent).ToArray();
                foreach (Transform t in ignoredObjects)
                {
                    Transform[] childrenTransforms = t.GetComponentsInChildren <Transform>();
                    if (childrenTransforms == null || childrenTransforms.Length == 0)
                    {
                        continue;
                    }
                    foreach (Transform t2 in childrenTransforms)
                    {
                        if (t2 == null || t2.gameObject == null)
                        {
                            continue;
                        }
                        if (t2.gameObject.layer == LayerMask.NameToLayer("Character") || t2.gameObject.layer == LayerMask.NameToLayer("Skateboard"))
                        {
                            if (!ignoredObjects.Contains(t2))
                            {
                                GameObject.Destroy(t2.gameObject);
                            }
                        }
                    }
                }

                bool loadedBodyInfo = false;

                foreach (MultiplayerRemoteTexture mpTex in multiplayerTextures)
                {
                    if (mpTex.saved && !mpTex.loaded && !(mpTex.infoType == GearInfoType.Body))
                    {
                        mpTex.LoadFromFileMainThread(this);
                    }
                    else if (mpTex.saved && !mpTex.loaded && mpTex.textureType.Equals("head", StringComparison.InvariantCultureIgnoreCase))
                    {
                        MultiplayerRemoteTexture bodyTex = multiplayerTextures.Find((t) => t.textureType.Equals("body", StringComparison.InvariantCultureIgnoreCase));
                        if (bodyTex != null)
                        {
                            UnityModManagerNet.UnityModManager.Logger.Log($"Updating body textures for {this.bodyType} id: {this.playerID}");

                            bodyTex.loaded = true;
                            mpTex.loaded   = true;

                            TextureChange[] headChange = { new TextureChange("albedo", mpTex.fileLocation) };
                            TextureChange[] bodyChange = { new TextureChange("albedo", bodyTex.fileLocation) };

                            List <MaterialChange> materialChanges = new List <MaterialChange>();
                            materialChanges.Add(new MaterialChange("body", bodyChange));
                            materialChanges.Add(new MaterialChange("head", headChange));

                            CharacterBodyInfo bodyInfo = new CharacterBodyInfo("MP Temp body", this.bodyType, true, materialChanges, new string[0]);

                            characterCustomizer.EquipGear(bodyInfo);

                            loadedBodyInfo = true;
                        }
                    }
                }

                if (!loadedBodyInfo)
                {
                    CharacterBodyInfo baseBodyInfo = new CharacterBodyInfo("MP Temp body", this.bodyType, false, null, new string[0]);
                    characterCustomizer.EquipGear(baseBodyInfo);
                }

                loadedTextures = true;
            }
        }
        public void ApplyTextures()
        {
            if (!loadedAllTextures)
            {
                if (shirtMPTex != null && shirtMPTex.saved && !shirtMPTex.loaded)
                {
                    shirtMPTex.LoadFromFileMainThread(this);
                }
                if (pantsMPTex != null && pantsMPTex.saved && !pantsMPTex.loaded)
                {
                    pantsMPTex.LoadFromFileMainThread(this);
                }
                if (hatMPTex != null && hatMPTex.saved && !hatMPTex.loaded)
                {
                    hatMPTex.LoadFromFileMainThread(this);
                }
                if (shoesMPTex != null && shoesMPTex.saved && !shoesMPTex.loaded)
                {
                    shoesMPTex.LoadFromFileMainThread(this);
                    characterCustomizer.SetShoesVisible(true);
                }

                if (deckMPTex != null && deckMPTex.saved && !deckMPTex.loaded)
                {
                    deckMPTex.LoadFromFileMainThread(this);
                }
                if (gripMPTex != null && gripMPTex.saved && !gripMPTex.loaded)
                {
                    gripMPTex.LoadFromFileMainThread(this);
                }
                if (wheelMPTex != null && wheelMPTex.saved && !wheelMPTex.loaded)
                {
                    wheelMPTex.LoadFromFileMainThread(this);
                }
                if (truckMPTex != null && truckMPTex.saved && !truckMPTex.loaded)
                {
                    truckMPTex.LoadFromFileMainThread(this);
                }

                if (headMPTex != null && headMPTex.saved && bodyMPTex != null && bodyMPTex.saved && !headMPTex.loaded && !bodyMPTex.loaded)
                {
                    headMPTex.loaded = true;
                    bodyMPTex.loaded = true;

                    if (headMPTex.useTexture && bodyMPTex.useTexture)
                    {
                        TextureChange[] headChange = { new TextureChange("albedo", headMPTex.fileLocation) };
                        TextureChange[] bodyChange = { new TextureChange("albedo", bodyMPTex.fileLocation) };

                        List <MaterialChange> materialChanges = new List <MaterialChange>();
                        materialChanges.Add(new MaterialChange("body", bodyChange));
                        materialChanges.Add(new MaterialChange("head", headChange));

                        CharacterBodyInfo bodyInfo = new CharacterBodyInfo("MP Temp body", "male", true, materialChanges, new string[0]);

                        characterCustomizer.EquipGear(bodyInfo);
                    }
                }

                loadedAllTextures = shirtMPTex.loaded && pantsMPTex.loaded && hatMPTex.loaded && shoesMPTex.loaded && deckMPTex.loaded && gripMPTex.loaded && wheelMPTex.loaded && truckMPTex.loaded && headMPTex.loaded && bodyMPTex.loaded;
            }
        }