Beispiel #1
0
        private void _LoadWav(byte[] _bytes)
        {
            int channels      = (int)Beth.FromEndian(_bytes.SubArray(22, 2));
            int samplerate    = (int)Beth.FromEndian(_bytes.SubArray(24, 4));
            int bitspersample = (int)Beth.FromEndian(_bytes.SubArray(34, 2));

            byte[] data = _bytes.SubArray(44);

            this._LoadData(channels, samplerate, bitspersample, data);
        }
Beispiel #2
0
        //public static SoundSource[] SplitStereo(string _path)
        //{
        //	Tuple<int, int, int, byte[]> info = SoundSource._GetInfo(File.ReadBytes(_path));

        //	byte[][] bs = new byte[2][];
        //	bs[0] = new byte[info.Item4.Length / 2];
        //	bs[1] = new byte[info.Item4.Length / 2];

        //	int bytes = (info.Item3 / 8);
        //	for (int i = 0; i < info.Item4.Length; i += bytes * 2)
        //	{
        //		for (int x = 0; x < bytes; x++)
        //		{
        //			bs[0][i / 2 + x] = info.Item4[i + x];
        //			bs[1][i / 2 + x] = info.Item4[i + bytes + x];
        //		}
        //	}

        //	throw new Exception();
        //	return new SoundSource[] { new SoundSource(1, info.Item2, info.Item3, bs[0]), new SoundSource(1, info.Item2, info.Item3, bs[1]) };
        //}

        private static Tuple <int, int, int, byte[]> _GetInfo(byte[] _bytes)
        {
            int channels      = (int)Beth.FromEndian(_bytes.SubArray(22, 2));
            int samplerate    = (int)Beth.FromEndian(_bytes.SubArray(24, 4));
            int bitspersample = (int)Beth.FromEndian(_bytes.SubArray(34, 2));

            byte[] data = _bytes.SubArray(44, (int)Beth.FromEndian(_bytes.SubArray(40, 4)));

            //throw new Exception();

            return(new Tuple <int, int, int, byte[]>(channels, samplerate, bitspersample, data));
        }
Beispiel #3
0
        public void LoadFromImage(ImageSource _source, Bunch <string> _areasets)
        {
            this.Size = _source.Size;

            for (int x = 0; x < _source.Size.X; x++)
            {
                for (int y = 0; y < _source.Size.Y; y++)
                {
                    this[x, y] = new Tuple <string, int>(_areasets[(int)Beth.FromEndian(_source[x, y].Bytes.Sub(0, 2))], (int)Beth.FromEndian(_source[x, y].Bytes.Sub(2, 2)));
                }
            }
        }
Beispiel #4
0
        private void _LoadOggPages(string _path)
        {
            FileStream stream = new FileStream(_path, FileMode.Open);

            long pos = 0;
            long end = stream.Length;

            Bunch <OggPage> ps = new Bunch <OggPage>();

            while (pos < end)
            {
                byte[] header = new byte[27];
                stream.Read(header, 0, 27);

                OggPage p = new OggPage();
                p.Granule        = Beth.FromEndian(header.SubArray(6, 8));
                p.StreamId       = (int)Beth.FromEndian(header.SubArray(14, 4));
                p.StreamPosition = (int)Beth.FromEndian(header.SubArray(18, 4));

                int ss = header[26];
                p.Segments = new byte[ss];
                pos       += 27;

                int si = 0;
                while (ss > 0)
                {
                    ss--;
                    p.Segments[si] = ((byte)stream.ReadByte());
                    si++;
                    pos++;
                }

                p.SegmentsPositionInFile = pos;

                foreach (byte s in p.Segments)
                {
                    pos             += s;
                    stream.Position += s;
                }

                ps.Add(p);
            }

            stream.Close();

            byte[][] bs1 = ps[0].ReadSegments(_path);
            byte[][] bs2 = ps[1].ReadSegments(_path);

            throw new Exception();
        }
Beispiel #5
0
        internal MekaItem _Export(Bunch <string> _areasets)
        {
            MekaItem @out = new MekaItem("Layer", new List <MekaItem>());

            ImageSource src = new ImageSource(this.Tiles.GetLength(0), this.Tiles.GetLength(1));

            for (int x = 0; x < this.Tiles.GetLength(0); x++)
            {
                for (int y = 0; y < this.Tiles.GetLength(1); y++)
                {
                    Bunch <byte> bs = Beth.ToEndian(_areasets.IndexOf(this.Tiles[x, y].Item1), 2);
                    bs.Add(Beth.ToEndian(this.Tiles[x, y].Item2, 2));
                    src[x, y] = new Color(bs);
                }
            }
            @out.Children.Add(new MekaItem("Tiles", src.Bytes));

            @out.Children.Add(new MekaItem("Entities", this.Entities.Select(item => item._Export()).ToList()));

            return(@out);
        }
Beispiel #6
0
        public LayerSource(MekaItem _item, Bunch <string> _areasets)
        {
            this.Main = _item.Contains("Main");

            ImageSource img = GameBase.LoadImageSource(_item["Tiles"].Data);

            Color[,] px = img.Pixels;
            this.Tiles  = new Tuple <string, int> [img.Width, img.Height];
            for (int x = 0; x < img.Width; x++)
            {
                for (int y = 0; y < img.Height; y++)
                {
                    this.Tiles[x, y] = new Tuple <string, int>(_areasets[(int)Beth.FromEndian(px[x, y].Bytes.Sub(0, 2))], (int)Beth.FromEndian(px[x, y].Bytes.Sub(2, 2)));
                }
            }

            foreach (MekaItem entity in _item["Entities"].Children)
            {
                this.Entities.Add(new EntityInstance(entity));
            }
        }