Пример #1
0
    public static void Load()
    {
        if (TexturesLoaded)
        {
            return;
        }

        TexturesLoaded = true;

        // load palette1. we only have palette1 for now.
        Palettes.Add(LoadPalette("Palette[1]"));

        Resource.Entry ent = ResourceManager.FindEntry("WallBitmaps");
        using (MemoryStream ms = ResourceManager.OpenRead(ent))
            using (BinaryReader br = new BinaryReader(ms))
            {
                uint count   = br.ReadUInt16();
                uint roffset = br.ReadUInt32();
                // now, Radix is so stupid that "roffset" is actually an absolute offset in radix.dat
                // so we need to know the offset of the original entry
                uint foffs = roffset - ent.Offset;
                for (uint i = 0; i < count; i++)
                {
                    ms.Position = foffs + i * 40;

                    string imgnb    = Utils.GetNullTermString(br.ReadBytes(32));
                    uint   r_offset = br.ReadUInt32();
                    uint   r_width  = br.ReadUInt16();
                    uint   r_height = br.ReadUInt16();

                    //Debug.LogFormat("found texture {0} ({1}x{2})", imgnb, r_width, r_height);

                    // r_offset is an absolute offset in radix.dat as well
                    ms.Position = r_offset - ent.Offset;
                    // read in the pixels
                    RadixBitmap bmp = new RadixBitmap();
                    bmp.Width  = (int)r_width;
                    bmp.Height = (int)r_height;
                    bmp.Name   = imgnb;
                    bmp.Pixels = new byte[bmp.Width, bmp.Height];

                    for (int y = 0; y < bmp.Height; y++)
                    {
                        for (int x = 0; x < bmp.Width; x++)
                        {
                            bmp.Pixels[x, y] = br.ReadByte(); // palette index here
                        }
                    }

                    Textures.Add(bmp);
                }
            }
    }
Пример #2
0
    public static MemoryStream OpenRead(Resource.Entry ent)
    {
        byte[] buf = new byte[ent.Size];

        RadixDat.ResStream.Position = ent.Offset;
        if (RadixDat.ResStream.Read(buf, 0, (int)ent.Size) != (int)ent.Size)
        {
            return(null);
        }

        MemoryStream ms = new MemoryStream(buf);

        return(ms);
    }
Пример #3
0
    public static Resource.Entry FindEntry(string filename)
    {
        InitResources();

        filename = filename.ToLower();
        for (int i = 0; i < RadixDat.Entries.Count; i++)
        {
            Resource.Entry ent = RadixDat.Entries[i];
            if (ent.Name.ToLower().Equals(filename))
            {
                return(ent);
            }
        }

        return(null);
    }
Пример #4
0
    public static MemoryStream OpenRead(string filename)
    {
        InitResources();

        filename = filename.ToLower();
        for (int i = 0; i < RadixDat.Entries.Count; i++)
        {
            Resource.Entry ent = RadixDat.Entries[i];
            if (ent.Name.ToLower().Equals(filename))
            {
                return(OpenRead(ent));
            }
        }

        return(null);
    }