Beispiel #1
0
        //Get a resource given an id
        // the id is coming from	TILEART -> TEXTURES
        //					or		TERRAINDEF -> TEXTURES
        public static UOResource getResource(Tileart tileart)
        {
            UOResource resource = null;

            //WorldArt Texture
            if (tileart.textures[0].texturePresent == 1)
            {
                resource = getResource(tileart.textures[0].texturesArray[0], ShaderTypes.Sprite);
            }
            //LegacyTexture
            if (resource == null && tileart.textures[1].texturePresent == 1)
            {
                resource = getLegacyResource(tileart.textures[1].texturesArray[0]);
            }
            //EnhancedTexture
            //Is this really necessary?
            //Light Texture
            if (resource != null && tileart.textures[3].texturePresent == 1)
            {
                //TODO: light texture load
            }
            //
            if (resource == null)
            {
                UOConsole.Fatal("texture is not present {0}", tileart.id);
                tileart  = UOResourceManager.getTileart(1);
                resource = getResource(tileart.textures[0].texturesArray[0], ShaderTypes.Sprite);
            }

            return(resource);
        }
Beispiel #2
0
        public UOSprite(uint spriteID)
        {
            tileart  = UOResourceManager.getTileart(spriteID);
            resource = UOResourceManager.getResource(tileart);

            if (resource.isLegacy)
            {
                _imageOffset = tileart.offset2D;
            }
            else
            {
                _imageOffset = tileart.offsetEC;
            }

            _drawOffsetX = tileart.offsetEC.offX / UOEC_SIZE;
            _drawOffsetY = tileart.offsetEC.offY / UOEC_SIZE;
        }
Beispiel #3
0
        //Get a tileart given a graphic id
        public static Tileart getTileart(uint graphic)
        {
            //Fast search
            if (tileartCollection.ContainsKey(graphic))
            {
                return(tileartCollection[graphic]);
            }

            //Get the file from tileart using the id
            ulong hash = HashDictionary.HashFileName(string.Format("build/tileart/{0:D8}.bin", graphic));

            if (!uopHashes.tileartHashes.ContainsKey(hash))
            {
                UOConsole.Fatal("Cannot find {0} in tileartHashes", graphic);
                return(null);
            }
            uopMapping_t pos = uopHashes.tileartHashes[hash];

            MythicPackage _uop = new MythicPackage(fileDirectory + "tileart.uop");

            byte[] raw = _uop.Blocks[pos.block].Files[pos.file].Unpack(_uop.FileInfo.FullName);

            //Read the loaded tileart file.
            Tileart t;

            using (MemoryStream ms = new MemoryStream(raw)) {
                using (BinaryReader r = new BinaryReader(ms)) {
                    t = Tileart.readTileart(r);
                }
            }
            if (t == null)
            {
                UOConsole.Fatal("Cannot read tileart file");
                return(t);
            }

            tileartCollection[graphic] = t;

            //Returns the texture according to subtype
            return(t);
        }
Beispiel #4
0
        private unsafe void ReadStaticTexture(int index, out Texture2D texture, out Tileart tileart)
        {
            uint resource = 0xFFFFFFFF;
            string resPath = "ERROR";
            bool resize;

            int x;
            int y;
            int width;
            int height;

            using (FileStream fs = new FileStream(string.Format(FileManager.GetPath("EC/build/tileart/{0:d8}.bin"), index), FileMode.Open))
            using (BinaryReader r = new BinaryReader(fs))
                tileart = Tileart.readTileart(r);

            x = 0;
            y = 0;
            width = 44;
            height = 44;
            resize = false;

            //WorldArt Texture
            if (tileart.textures[0].texturePresent == -1)
            {
                resource = tileart.textures[0].texturesArray[0].textureIDX;
                resPath = string.Format(FileManager.GetPath("EC/build/worldart/{0:d8}.dds"), index);

                if (!File.Exists(resPath))
                {
                    resource = 0xFFFFFFFF;
                }
                else
                {
                    x = tileart.offsetEC.Xstart;
                    y = 0;
                    width = tileart.offsetEC.Width;
                    height = tileart.offsetEC.Height;

                    if (width == 0)
                    {
                        width = height = 64;
                    }
                    resize = true;
                }
            }
            //LegacyTexture
            if (resource == 0xFFFFFFFF && tileart.textures[1].texturePresent == 1)
            {
                //resource = tileart.textures[1].texturesArray[0].textureIDX;
                resource = 0;
                resPath = string.Format(FileManager.GetPath("EC/build/tileartlegacy/{0:d8}.dds"), index);
                if (!File.Exists(resPath))
                {
                    resource = 0xFFFFFFFF;
                }
                else
                {
                    x = tileart.offset2D.Xstart;
                    y = tileart.offset2D.Ystart;
                    width = tileart.offset2D.Width;
                    height = tileart.offset2D.Height;

                    if (width == 0)
                    {
                        width = height = 44;
                    }
                }
            }
            //EnhancedTexture
            //Is this really necessary?
            //Light Texture
            if (resource != 0xFFFFFFFF && tileart.textures[3].texturePresent == 1)
            {
                //TODO: light texture load
            }

            if (resource == 0xFFFFFFFF)
                throw new System.Exception("Missing IMAGE!");

            DDSImage img = new DDSImage(File.ReadAllBytes(resPath));

            //Metrics.ReportDataRead((int)filestream.Length);
            using (MemoryStream ms = new MemoryStream())
            {
                img.images[0].Save(ms, ImageFormat.Png);
                Texture2D temp;

                if (resize)//HERE WE SCALE THE IMAGE
                {
                    temp = Texture2D.FromStream(m_Graphics, ms, (int)(img.images[0].Width * 0.6875), (int)(img.images[0].Height * 0.6875), true);
                    x = (int)(x * 0.6875);
                    y = (int)(y * 0.6875);
                    width = (int)(width * 0.6875);
                    height = (int)(height * 0.6875);
                }
                else
                    temp = Texture2D.FromStream(m_Graphics, ms);

                if ((width + x) > temp.Width)
                    width = temp.Width - x;
                if ((height + y) > temp.Height)
                    height = temp.Height - y;

                uint[] texData = new uint[width * height];
                temp.GetData<uint>(
                    0,
                    new Rectangle(
                        x,
                        y,
                        width,
                        height),
                    texData,
                    0,
                    width * height);

                texture = new Texture2D(m_Graphics, width, height, false, SurfaceFormat.Color);
                texture.SetData(texData);

            }
            return;
        }