Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="textureDictionary">all the different textures the ship uses, most used are Default, Left and Right</param>
 /// <param name="position">position of the ship</param>
 /// <param name="turrets">turrets on the ship</param>
 /// <param name="healthMax">max health</param>
 /// <param name="energyMax">max energy</param>
 /// <param name="energyRegen">energy regen per frame</param>
 /// <param name="turnRate">how fast the ship turns</param>
 public Ship(IReadOnlyDictionary <string, Texture2D> textureDictionary, Vector2 position, Dictionary <string, List <ITurret> > turrets, float healthMax, float energyMax, float energyRegen, float turnRate, float speed, TractorBeam tractorBeam, int upgradeCount) : base(textureDictionary["Default"], position)
 {
     foreach (var t in turrets)
     {
         Turrets.Add(t.Key, t.Value);
     }
     foreach (var entry in textureDictionary)
     {
         TextureDictionary.Add(entry.Key, entry.Value);
     }
     Upgrades        = new Upgrade[upgradeCount];
     TractorBeam     = tractorBeam;
     HealthMax       = healthMax;
     BaseHealth      = healthMax;
     Health          = healthMax;
     BaseEnergy      = energyMax;
     EnergyMax       = energyMax;
     Energy          = energyMax;
     BaseEnergyRegen = energyRegen;
     EnergyRegen     = energyRegen;
     TurnRate        = turnRate;
     Speed           = speed;
     BackwardsSpeed  = 1 / 5f * speed;
     StrafeSpeed     = 3 / 5f * speed;
 }
Пример #2
0
        public static Dictionary <string, string> ExportTextures(TextureDictionary textureDictionary, string dirPath)
        {
            Directory.CreateDirectory(dirPath);
            var texPaths = new Dictionary <string, string>();

            foreach (var tex in textureDictionary.Textures)
            {
                string texPath;

                switch (tex.Format)
                {
                case TextureFormat.DDS:
                    texPath = Path.Combine(dirPath, Path.ChangeExtension(tex.Name, ".dds"));
                    File.WriteAllBytes(texPath, tex.Data);
                    break;

                default:
                    texPath = Path.Combine(dirPath, Path.ChangeExtension(tex.Name, ".png"));
                    TextureDecoder.Decode(tex).Save(texPath);
                    break;
                }

                texPaths[tex.Name] = texPath;
            }

            return(texPaths);
        }
Пример #3
0
        /// <summary>
        /// Reads the data-block from a stream.
        /// </summary>
        public override void Read(ResourceDataReader reader, params object[] parameters)
        {
            // read structure data
            this.VFT        = reader.ReadUInt32();
            this.Unknown_4h = reader.ReadUInt32();
            this.TextureDictionaryPointer = reader.ReadUInt64();
            this.ShadersPointer           = reader.ReadUInt64();
            this.ShadersCount1            = reader.ReadUInt16();
            this.ShadersCount2            = reader.ReadUInt16();
            this.Unknown_1Ch = reader.ReadUInt32();
            this.Unknown_20h = reader.ReadUInt32();
            this.Unknown_24h = reader.ReadUInt32();
            this.Unknown_28h = reader.ReadUInt32();
            this.Unknown_2Ch = reader.ReadUInt32();
            this.Unknown_30h = reader.ReadUInt32();
            this.Unknown_34h = reader.ReadUInt32();
            this.Unknown_38h = reader.ReadUInt32();
            this.Unknown_3Ch = reader.ReadUInt32();

            // read reference data
            this.TextureDictionary = reader.ReadBlockAt <TextureDictionary>(
                this.TextureDictionaryPointer // offset
                );
            this.Shaders = reader.ReadBlockAt <ResourcePointerArray64 <ShaderFX> >(
                this.ShadersPointer, // offset
                this.ShadersCount1
                );
        }
Пример #4
0
        private static void StepLoadSpecialTextures()
        {
            // Load mouse cursor texture
            Texture2D mouse    = TextureDictionary.Load("fronten_pc").GetDiffuse("mouse").Texture;
            Texture2D mouseFix = new Texture2D(mouse.width, mouse.height);

            for (int x = 0; x < mouse.width; x++)
            {
                for (int y = 0; y < mouse.height; y++)
                {
                    mouseFix.SetPixel(x, mouse.height - y - 1, mouse.GetPixel(x, y));
                }
            }

            mouseFix.Apply();
            Cursor.SetCursor(mouseFix, Vector2.zero, CursorMode.Auto);

            // load crosshair texture
            Weapon.CrosshairTexture = TextureDictionary.Load("hud").GetDiffuse("siteM16").Texture;

            // fist texture
            Weapon.FistTexture = TextureDictionary.Load("hud").GetDiffuse("fist").Texture;

            // arrow textures
            var pcbtnsTxd = TextureDictionary.Load("pcbtns");

            UI.HUD.LeftArrowTexture  = pcbtnsTxd.GetDiffuse("left").Texture;
            UI.HUD.RightArrowTexture = pcbtnsTxd.GetDiffuse("right").Texture;
            UI.HUD.UpArrowTexture    = pcbtnsTxd.GetDiffuse("up").Texture;
            UI.HUD.DownArrowTexture  = pcbtnsTxd.GetDiffuse("down").Texture;
        }
Пример #5
0
    //! Sets up the material for mod block meshes.
    public void SetMaterial(GameObject obj, string blockType)
    {
        TextureDictionary textureDictionary = gameManager.GetComponent <TextureDictionary>();

        if (textureDictionary.dictionary.ContainsKey(blockType))
        {
            if (blockType.ToUpper().Contains("GLASS"))
            {
                obj.GetComponent <Renderer>().material = gameManager.glassMaterial;
            }
            else
            {
                Material mat = new Material(Shader.Find("Standard"));
                mat.mainTexture = textureDictionary.dictionary[blockType];
                if (textureDictionary.dictionary.ContainsKey(blockType + "_Normal"))
                {
                    mat.shaderKeywords = new string[] { "_NORMALMAP" };
                    mat.SetTexture("_BumpMap", textureDictionary.dictionary[blockType + "_Normal"]);
                    if (blockType != "Door" && blockType != "Iron Block" && blockType != "Brick")
                    {
                        mat.SetFloat("_BumpScale", 2);
                    }
                }
                obj.GetComponent <Renderer>().material = mat;
            }
        }
    }
Пример #6
0
        /// <summary>
        /// Initialize predefined textures<para/>
        /// Инициализация предзаданных текстур
        /// </summary>
        public static void Init()
        {
            // Checking for extensions
            // Проверка расширений
            CompressionSupported = GLExtensions.Supported("GL_EXT_Texture_Compression_S3TC");
            FrameBufferSupported = GLExtensions.Supported("GL_ARB_Framebuffer_Object");

            // Load DAT-defined texture dictionaries
            // Загрузка предопределенных архивов текстур
            foreach (string TXD in FileManager.TextureFiles)
            {
                string      name = Path.GetFileNameWithoutExtension(TXD).ToLower();
                string      path = PathManager.GetAbsolute(TXD);
                TextureFile f    = new TextureFile(path, true);
                CachedFiles.TryAdd(name, f);
                TextureDictionary td = new TextureDictionary(f, true, true);
                Cached.TryAdd(name, td);
            }

            // Starting TextureFile thread
            // Запуск потока чтения TextureFile
            fileReaderThread = new Thread(FileLoaderProcess);
            fileReaderThread.IsBackground = true;
            fileReaderThread.Priority     = ThreadPriority.BelowNormal;
            fileReaderThread.Start();

            // Starting model builder thread
            // Запуск потока постройки Model
            textureBuilderThread = new Thread(TextureBuilderProcess);
            textureBuilderThread.IsBackground = true;
            textureBuilderThread.Priority     = ThreadPriority.BelowNormal;
            textureBuilderThread.Start();
        }
Пример #7
0
 public void LoadTextures(TextureDictionary txd)
 {
     if (TextureName.Length > 0)
     {
         if (txd.Contains(TextureName, TextureType.Diffuse))
         {
             Texture = txd[TextureName, TextureType.Diffuse];
         }
         else
         {
             Texture = Texture2D.Missing;
         }
     }
     if (MaskName.Length > 0)
     {
         if (txd.Contains(MaskName, TextureType.Mask))
         {
             Mask = txd[MaskName, TextureType.Mask];
         }
         else
         {
             Mask = null;
         }
     }
 }
Пример #8
0
 public static Geometry.GeometryParts LoadGeometryParts(VehicleDef vehicleDef)
 {
     return(Geometry.Load(vehicleDef.ModelName,
                          TextureDictionary.Load(vehicleDef.TextureDictionaryName),
                          TextureDictionary.Load("vehicle"),
                          TextureDictionary.Load("misc")));
 }
Пример #9
0
        private static void StepLoadSpecialTextures()
        {
            // Load mouse cursor texture
            F.RunExceptionSafe(() =>
            {
                Texture2D mouse = TextureDictionary.Load("fronten_pc").GetDiffuse("mouse",
                                                                                  new TextureLoadParams()
                {
                    makeNoLongerReadable = false
                }).Texture;
                Texture2D mouseFix = new Texture2D(mouse.width, mouse.height);

                for (int x = 0; x < mouse.width; x++)
                {
                    for (int y = 0; y < mouse.height; y++)
                    {
                        mouseFix.SetPixel(x, mouse.height - y - 1, mouse.GetPixel(x, y));
                    }
                }

                mouseFix.Apply();

                Cursor.SetCursor(mouseFix, Vector2.zero, CursorMode.Auto);
            });

            // fist texture
            Weapon.FistTexture = TextureDictionary.Load("hud").GetDiffuse("fist").Texture;


            onLoadSpecialTextures();
        }
Пример #10
0
 //! Called once per frame by unity engine.
 public void Update()
 {
     if (!stateManager.Busy())
     {
         if (type != "nothing")
         {
             TextureDictionary td = gameManager.GetComponent <TextureDictionary>();
             if (td != null)
             {
                 if (td.dictionary != null)
                 {
                     if (td.dictionary.ContainsKey(type + "_Icon"))
                     {
                         billboard.GetComponent <Renderer>().material.mainTexture = td.dictionary[type + "_Icon"];
                         billboard.GetComponent <Renderer>().enabled = true;
                     }
                     else if (td.dictionary.ContainsKey(type))
                     {
                         billboard.GetComponent <Renderer>().material.mainTexture = td.dictionary[type];
                         billboard.GetComponent <Renderer>().enabled = true;
                     }
                 }
             }
         }
         transform.Rotate(transform.up * 100 * Time.deltaTime);
     }
 }
Пример #11
0
 public void LoadTextures(TextureDictionary txd)
 {
     foreach (TextureSectionData tex in Textures)
     {
         tex.LoadTextures(txd);
     }
 }
Пример #12
0
        private void ShowTextures(TextureDictionary td)
        {
            SelTexturesListView.Items.Clear();
            SelTexturePictureBox.Image     = null;
            SelTextureNameTextBox.Text     = string.Empty;
            SelTextureDimensionsLabel.Text = "-";
            SelTextureMipLabel.Text        = "0";
            SelTextureMipTrackBar.Value    = 0;
            SelTextureMipTrackBar.Maximum  = 0;

            if (td == null)
            {
                HideTexturesTab();
                return;
            }
            if (!SelectionTabControl.TabPages.Contains(TexturesTabPage))
            {
                SelectionTabControl.TabPages.Add(TexturesTabPage);
            }


            if ((td.Textures == null) || (td.Textures.data_items == null))
            {
                return;
            }
            var texs = td.Textures.data_items;

            for (int i = 0; i < texs.Length; i++)
            {
                var          tex = texs[i];
                ListViewItem lvi = SelTexturesListView.Items.Add(tex.Name);
                lvi.Tag = tex;
            }
        }
Пример #13
0
 public void LoadTextures(TextureDictionary txd)
 {
     foreach (MaterialSectionData mat in Materials)
     {
         mat.LoadTextures(txd);
     }
 }
Пример #14
0
        // Texture
        private void WriteTextureDictionaryChunk(TextureDictionary textureDictionary)
        {
            StartWritingChunk(textureDictionary.Version, ResourceChunkType.TextureDictionary);

            WriteTextureDictionary(textureDictionary);

            FinishWritingChunk();
        }
Пример #15
0
 private void WriteTextureDictionary(TextureDictionary textureDictionary)
 {
     WriteInt(textureDictionary.Count);
     foreach (var texture in textureDictionary.Textures)
     {
         WriteTexture(texture);
     }
 }
Пример #16
0
        /// <summary>
        /// Loads the texture dictionary from a file.
        /// </summary>
        public void Load(string fileName)
        {
            var resource = new ResourceFile_GTA5_pc <TextureDictionary>();

            resource.Load(fileName);

            textureDictionary = resource.ResourceData;
        }
Пример #17
0
    //! Called by unity engine on start up to initialize variables.
    public void Start()
    {
        playerController = GetComponent <PlayerController>();
        GameManager gameManager = GameObject.Find("GameManager").GetComponent <GameManager>();

        textureDictionary = gameManager.GetComponent <TextureDictionary>();
        guiCoordinates    = new GuiCoordinates();
    }
Пример #18
0
        void LoadCrosshairTexture()
        {
            Texture2D originalTex = TextureDictionary.Load("hud")
                                    .GetDiffuse("siteM16", new TextureLoadParams {
                makeNoLongerReadable = false
            })
                                    .Texture;

            // construct crosshair texture

            int originalWidth  = originalTex.width;
            int originalHeight = originalTex.height;

            Texture2D tex = new Texture2D(originalWidth * 2, originalHeight * 2, TextureFormat.ARGB32, false, true);

            // bottom left
            for (int i = 0; i < originalWidth; i++)
            {
                for (int j = 0; j < originalHeight; j++)
                {
                    tex.SetPixel(i, j, originalTex.GetPixel(i, j));
                }
            }

            // bottom right - flip around X axis
            for (int i = 0; i < originalWidth; i++)
            {
                for (int j = 0; j < originalHeight; j++)
                {
                    tex.SetPixel(originalWidth - i - 1 + originalWidth, j, originalTex.GetPixel(i, j));
                }
            }

            // top left - flip Y axis
            for (int i = 0; i < originalWidth; i++)
            {
                for (int j = 0; j < originalHeight; j++)
                {
                    tex.SetPixel(i, originalHeight - j - 1 + originalHeight, originalTex.GetPixel(i, j));
                }
            }

            // top right - flip both X and Y axes
            for (int i = 0; i < originalWidth; i++)
            {
                for (int j = 0; j < originalHeight; j++)
                {
                    tex.SetPixel(originalWidth - i - 1 + originalWidth, originalHeight - j - 1 + originalHeight, originalTex.GetPixel(i, j));
                }
            }

            tex.Apply(false, true);

            Weapon.CrosshairTexture     = tex;
            this.crosshairImage.enabled = true;
            this.crosshairImage.texture = tex;
        }
Пример #19
0
        static Texture2D ConstructCrosshairTexture(string textureName, float sizeMultiplier)
        {
            Texture2D originalTex = TextureDictionary.Load("hud")
                                    .GetDiffuse(textureName, new TextureLoadParams {
                makeNoLongerReadable = false
            })
                                    .Texture;

            return(ConstructCrosshairTexture(originalTex, sizeMultiplier));
        }
Пример #20
0
 //! Network functions for multiplayer games.
 public NetworkController(PlayerController playerController)
 {
     this.playerController = playerController;
     textureDictionary     = playerController.gameManager.GetComponent <TextureDictionary>();
     networkPlayers        = new Dictionary <string, GameObject>();
     playerPositions       = new Dictionary <string, Vector3>();
     playerNames           = new List <string>();
     networkSend           = new NetworkSend(this);
     networkReceive        = new NetworkReceive(this);
 }
Пример #21
0
        private static void StepLoadSplashScreen()
        {
            var txd = TextureDictionary.Load("LOADSCS");

            int index1 = Random.Range(1, 15);
            int index2 = Random.Range(1, 15);

            SplashTex1 = txd.GetDiffuse("loadsc" + index1).Texture;
            SplashTex2 = txd.GetDiffuse("loadsc" + index2).Texture;
        }
Пример #22
0
 //! Called by unity engine on start up to initialize variables.
 public void Start()
 {
     playerController      = GetComponent <PlayerController>();
     playerInventory       = GetComponent <InventoryManager>();
     stateManager          = GameObject.Find("GameManager").GetComponent <StateManager>();
     gameManager           = GameObject.Find("GameManager").GetComponent <GameManager>();
     textureDictionary     = gameManager.GetComponent <TextureDictionary>();
     descriptions          = new Descriptions();
     guiCoordinates        = new GuiCoordinates();
     paintSelectionTexture = new Texture2D(512, 128);
 }
Пример #23
0
    //! Called by unity engine on start up to initialize variables.
    public void Start()
    {
        playerController = GameObject.Find("Player").GetComponent <PlayerController>();
        guiCoordinates   = new GuiCoordinates();
        slots            = new Dictionary <int, string>();
        GameManager gameManager = GameObject.Find("GameManager").GetComponent <GameManager>();

        textureDictionary = gameManager.GetComponent <TextureDictionary>();
        boxTexture        = Resources.Load("ShadedSelectionBox") as Texture2D;
        toggled           = true;
    }
Пример #24
0
        private void ConvertTextures(TextureDictionary textureDictionary)
        {
            Directory.CreateDirectory(mTextureBaseDirectoryPath);

            foreach (var texture in textureDictionary.Textures)
            {
                var texturePath = Path.Combine(mTextureBaseDirectoryPath, AssimpConverterCommon.EscapeName(texture.Name));

                File.WriteAllBytes(texturePath, texture.Data);
            }
        }
Пример #25
0
        public static void loadTextures()
        {
            for (int i = 0; i < tileCount; i++)
            {
                tiles [i] = TextureDictionary.Load("radar" + ((i < 10) ? "0" : "") + i);
            }

            huds       = TextureDictionary.Load("hud");
            northBlip  = huds.GetDiffuse("radar_north").Texture;
            playerBlip = huds.GetDiffuse("radar_centre").Texture;
        }
Пример #26
0
        public static Weapon Load(int modelId)
        {
            WeaponDef def = Item.GetDefinition <WeaponDef> (modelId);

            if (null == def)
            {
                return(null);
            }

            WeaponData weaponData = WeaponData.LoadedWeaponsData.FirstOrDefault(wd => wd.modelId1 == def.Id);

            if (null == weaponData)
            {
                return(null);
            }

            var geoms = Geometry.Load(def.ModelName, def.TextureDictionaryName);

            if (null == geoms)
            {
                return(null);
            }

            if (null == s_weaponsContainer)
            {
                s_weaponsContainer = new GameObject("Weapons");
                //	weaponsContainer.SetActive (false);
            }

            GameObject go = new GameObject(def.ModelName);

            go.transform.SetParent(s_weaponsContainer.transform);

            geoms.AttachFrames(go.transform, MaterialFlags.Default);

            Weapon weapon = AddWeaponComponent(go, weaponData);

            weapon.definition = def;
            weapon.data       = weaponData;
            // cache gun aiming offset
            if (weapon.data.gunData != null)
            {
                weapon.gunAimingOffset = weapon.data.gunData.aimingOffset;
            }

            // load hud texture
            try {
                weapon.HudTexture = TextureDictionary.Load(def.TextureDictionaryName).GetDiffuse(def.TextureDictionaryName + "icon").Texture;
            } catch {
                Debug.LogErrorFormat("Failed to load hud icon for weapon: model {0}, txd {1}", def.ModelName, def.TextureDictionaryName);
            }

            return(weapon);
        }
Пример #27
0
        void LoadTextures()
        {
            // load arrow textures
            var pcbtnsTxd = TextureDictionary.Load("pcbtns");

            LeftArrowTexture  = pcbtnsTxd.GetDiffuse("left").Texture;
            RightArrowTexture = pcbtnsTxd.GetDiffuse("right").Texture;
            UpArrowTexture    = pcbtnsTxd.GetDiffuse("up").Texture;
            DownArrowTexture  = pcbtnsTxd.GetDiffuse("down").Texture;

            LoadCrosshairTexture();
        }
Пример #28
0
    public string GetVersion()
    {
        TextureDictionary gett = textComp.GetComponent <TextureDictionary>();

        string txt = textComp.text;

        char[] chs = txt.ToCharArray();
        int    x;
        int    j;
        int    k;



        for (x = 0; x <= chs.Length - 1; x++)
        {
            for (j = 0; j < gett.textureList.Capacity; j++)
            {
                string symbol   = gett.textureList[j].key;
                char[] chs_symb = symbol.ToCharArray();

                if ((chs [x].ToString() == chs_symb[0].ToString()) && (x + 1 < chs.Length))
                {
                    if (chs [(x + 1)].ToString() == chs_symb [1].ToString())
                    {
                        Count = Count + 1;
                        if (chs [(x - 1)].ToString() != " ")
                        {
                            Negative [Count] = "" + x;
                        }

                        if (chs [(x + 2)].ToString() != " ")
                        {
                            Positive [Count] = "" + (x + 2);
                        }


                        for (k = 0; k < gett.textureList.Capacity; k++)
                        {
                            string symbol2   = gett.textureList[k].key;
                            char[] chs_symb2 = symbol2.ToCharArray();
                            if (chs [(x + 2)].ToString() == " " && chs [(x + 3)].ToString() == chs_symb2 [0].ToString() && chs [(x + 4)].ToString() == chs_symb2 [1].ToString())
                            {
                                Successive [Count] = "" + (x + 2);
                            }
                        }
                    }
                }
            }
        }

        BSP_Add();
        return(txt);
    }
Пример #29
0
        private Geometry(RenderWareStream.Geometry geom, Mesh mesh, TextureDictionary[] textureDictionaries)
        {
            Mesh = mesh;

            if (geom.Skinning != null) {
                Mesh.boneWeights = Types.Convert(geom.Skinning.VertexBoneIndices, geom.Skinning.VertexBoneWeights);
                SkinToBoneMatrices = Types.Convert(geom.Skinning.SkinToBoneMatrices);
            }

            _geom = geom;
            _textureDictionaries = textureDictionaries;
            _materials = new Dictionary<MaterialFlags, UnityEngine.Material[]>();
        }
Пример #30
0
        public void Load(Stream stream)
        {
            var resource = new ResourceFile_GTA5_pc <TextureDictionary>();

            resource.Load(stream);

            if (resource.Version != 13)
            {
                throw new Exception("version error");
            }

            textureDictionary = resource.ResourceData;
        }
Пример #31
0
    private void OnTerrainEntity(EntityAddedEvent evt)
    {
        TerrainEntity terEnt  = (TerrainEntity)evt.AddedXmasEntity;
        TilePosition  posinfo = (TilePosition)evt.AddedPosition;
        Point         pos     = posinfo.Point;

        var transform = Factory.CreateTile(terEnt, posinfo);

        transform.gameObject.AddComponent <TerrainInformation>();
        var terinfo = transform.gameObject.GetComponent <TerrainInformation>();

        terinfo.SetTerrain(terEnt);
        this.termap[terEnt] = transform;
        transform.renderer.sharedMaterial.SetTexture("_MainTex", TextureDictionary.GetTexture(terEnt.TextureType));
    }
Пример #32
0
            public GeometryParts(string name, Clump clump, TextureDictionary[] txds)
            {
                Name = name;

                Geometry = clump.GeometryList.Geometry
                    .Select(x => new Geometry(x, Convert(x), txds))
                    .ToArray();

                Frames = clump.FrameList.Frames
                    .Select(x => Convert(x, clump.Atomics))
                    .ToArray();

                _collisions = clump.Collision;
            }
        public static TextureDictionary Load(string name)
        {
            name = name.ToLower();
            if (_sLoaded.ContainsKey(name)) return _sLoaded[name];

            var txd = new TextureDictionary(ArchiveManager.ReadFile<RenderWareStream.TextureDictionary>(name + ".txd"));
            _sLoaded.Add(name, txd);

            return txd;
        }
Пример #34
0
        private static UnityEngine.Material Convert(RenderWareStream.Material src, TextureDictionary[] txds, MaterialFlags flags)
        {
            LoadedTexture diffuse;
            LoadedTexture mask = null;

            var overrideAlpha = (flags & MaterialFlags.OverrideAlpha) == MaterialFlags.OverrideAlpha;
            var vehicle = (flags & MaterialFlags.Vehicle) == MaterialFlags.Vehicle;

            if (!overrideAlpha && src.Colour.A != 255) {
                flags |= MaterialFlags.Alpha;
            }

            if (src.TextureCount > 0) {
                var tex = src.Textures[0];
                diffuse = txds.GetDiffuse(tex.TextureName);

                if (src.TextureCount > 1) {
                    Debug.LogFormat("Something has {0} textures!", src.TextureCount);
                }

                if (diffuse == null) {
                    Debug.LogWarningFormat("Unable to find texture {0}", tex.TextureName);
                }

                if (!string.IsNullOrEmpty(tex.MaskName)) {
                    mask = txds.GetAlpha(tex.MaskName) ?? diffuse;
                } else if (vehicle) {
                    mask = diffuse;
                }

                if (!overrideAlpha && mask != null && mask.HasAlpha) {
                    flags |= MaterialFlags.Alpha;
                }
            } else {
                diffuse = WhiteTex;
            }

            var shader = GetShader(flags);
            var mat = new UnityEngine.Material(shader);

            var clr = Types.Convert(src.Colour);

            if (vehicle) {
                var found = false;
                for (var i = 1; i < _sKeyColors.Length; ++i) {
                    var key = _sKeyColors[i];
                    if (key.r != clr.r || key.g != clr.g || key.b != clr.b) continue;
                    mat.SetInt(CarColorIndexId, i);
                    found = true;
                    break;
                }

                if (found) {
                    mat.color = Color.white;
                } else {
                    mat.color = clr;
                }
            } else {
                mat.color = clr;
            }

            if (diffuse != null) mat.SetTexture(MainTexId, diffuse.Texture);
            if (mask != null) mat.SetTexture(MaskTexId, mask.Texture);

            mat.SetFloat(MetallicId, src.Specular);
            mat.SetFloat(SmoothnessId, src.Smoothness);

            return mat;
        }