Beispiel #1
0
        public static ArrayByte GetResource(string resName)
        {
            if (resName == null)
            {
                return(null);
            }
            InputStream resource = OpenStream(resName);

            if (resource != null)
            {
                ArrayByte result = new ArrayByte();
                try
                {
                    result.Write(resource);
                    resource.Close();
                    result.Reset();
                }
                catch (IOException)
                {
                    result = null;
                }
                return(result);
            }
            return(null);
        }
Beispiel #2
0
        public void In(byte[] o)
        {
            ArrayByte touchByte = new ArrayByte(o);

            type    = touchByte.ReadInt();
            keyCode = touchByte.ReadInt();
            keyChar = (char)touchByte.ReadInt();
            type    = touchByte.ReadInt();
        }
Beispiel #3
0
        public byte[] Out()
        {
            ArrayByte touchByte = new ArrayByte();

            touchByte.WriteInt(type);
            touchByte.WriteInt(keyCode);
            touchByte.WriteInt(keyChar);
            return(touchByte.GetData());
        }
Beispiel #4
0
        public void In(byte[] o)
        {
            ArrayByte touchByte = new ArrayByte(o);

            x0      = touchByte.ReadInt();
            y0      = touchByte.ReadInt();
            button  = touchByte.ReadInt();
            pointer = touchByte.ReadInt();
            type    = touchByte.ReadInt();
        }
Beispiel #5
0
        public byte[] Out()
        {
            ArrayByte touchByte = new ArrayByte();

            touchByte.WriteInt(X());
            touchByte.WriteInt(Y());
            touchByte.WriteInt(GetButton());
            touchByte.WriteInt(GetPointer());
            touchByte.WriteInt(GetCode());
            return(touchByte.GetData());
        }
Beispiel #6
0
        public static LPKHeader ReadHeader(ArrayByte dis)
        {
            LPKHeader header = new LPKHeader();

            header.SetPAKIdentity(dis.ReadInt());
            byte[] pass = dis.ReadByteArray(LPKHeader.LF_PASSWORD_LENGTH);
            header.SetPassword(pass);
            header.SetVersion(dis.ReadFloat());
            header.SetTables(dis.ReadLong());
            return(header);
        }
Beispiel #7
0
 public static LPKTable[] ReadLPKTable(ArrayByte dis, int fileTableNumber)
 {
     LPKTable[] fileTable = new LPKTable[fileTableNumber];
     for (int i = 0; i < fileTableNumber; i++)
     {
         LPKTable ft = new LPKTable();
         ft.SetFileName(dis.ReadByteArray(LPKHeader.LF_FILE_LENGTH));
         ft.SetFileSize(dis.ReadLong());
         ft.SetOffSet(dis.ReadLong());
         fileTable[i] = ft;
     }
     return(fileTable);
 }
Beispiel #8
0
        public static SpriteFont Read(string resName)
        {
            try
            {
                List <RectBox> xGlyphs = new List <RectBox>(), xCropping = new List <RectBox>();
                List <Char>    xChars = new List <Char>();
                int            xSpacingV;
                float          xSpacingH;
                List <float[]> xKerning = new List <float[]>();

                ArrayByte arrays = new ArrayByte(Resources.OpenResource(resName),
                                                 ArrayByte.BIG_ENDIAN);

                int size = arrays.ReadInt();

                LImage image = LImage.CreateImage(arrays.ReadByteArray(size));

                int count = arrays.ReadInt();
                while (count-- > 0)
                {
                    xGlyphs.Add(new RectBox(arrays.ReadInt(), arrays.ReadInt(),
                                            arrays.ReadInt(), arrays.ReadInt()));
                    xCropping.Add(new RectBox(arrays.ReadInt(), arrays.ReadInt(),
                                              arrays.ReadInt(), arrays.ReadInt()));
                    xChars.Add((char)arrays.ReadInt());
                }

                xSpacingV = arrays.ReadInt();
                xSpacingH = arrays.ReadFloat();

                count = arrays.ReadInt();
                while (count-- > 0)
                {
                    xKerning.Add(new float[] { arrays.ReadFloat(),
                                               arrays.ReadFloat(), arrays.ReadFloat() });
                }
                arrays.Dispose();
                return(new SpriteFont(new LTexture(GLLoader.GetTextureData(image),
                                                   Loon.Core.Graphics.Opengl.LTexture.Format.LINEAR), xGlyphs, xCropping, xChars, xSpacingV,
                                      xSpacingH, xKerning, 'A'));
            }
            catch (Exception e)
            {
                Loon.Utils.Debugging.Log.Exception(e);
            }
            return(null);
        }
Beispiel #9
0
        public static byte[] ReadFileFromPak(ArrayByte dis, int size,
                                             LPKTable fileTable)
        {
            dis.Skip(fileTable.GetOffSet() - size);
            int fileLength = (int)fileTable.GetFileSize();

            byte[] fileBuff   = new byte[fileLength];
            int    readLength = dis.Read(fileBuff, 0, fileLength);

            if (readLength < fileLength)
            {
                return(null);
            }
            else
            {
                NativeSupport.MakeBuffer(fileBuff, readLength, 0xF7);
                return(fileBuff);
            }
        }
Beispiel #10
0
        static void LoadResToMemory()
        {
            Stream    stream    = null;
            ArrayByte resStream = null;

            try
            {
                stream    = XNAConfig.LoadStream(LSystem.FRAMEWORK_IMG_NAME + "font.zip");
                resStream = new ArrayByte(new GZipInputStream(stream), ArrayByte.BIG_ENDIAN);
                realsize  = resStream.ReadByte();
                offy      = resStream.ReadByte();
                fontSpace = (realsize + offy) * 2;
                if (realsize > 0x10)
                {
                    fontSpace *= 2;
                }
                int    num        = resStream.ReadInt();
                int    num2       = resStream.ReadByte();
                byte[] bufferData = new byte[resStream.Available()];
                resStream.Read(bufferData);
                fontData = bufferData;
            }
            catch (Exception)
            {
                fontData = null;
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                    stream.Close();
                    stream = null;
                }
                if (resStream != null)
                {
                    resStream = null;
                }
            }
        }
Beispiel #11
0
        public static byte[] OpenResource(string fileName, string resName)
        {
            try {
                PAK    pak = (PAK)CollectionUtils.Get(pakRes, fileName);
                Stream ins = Resources.OpenStream(fileName);

                ArrayByte result = null;

                if (CACHE)
                {
                    if (cacheRes == null)
                    {
                        cacheRes = new System.Collections.Generic.Dictionary <string, ArrayByte>(
                            CollectionUtils.INITIAL_CAPACITY);
                    }
                    result = (ArrayByte)CollectionUtils.Get(cacheRes, fileName);
                    if (result == null)
                    {
                        result = new ArrayByte(ins, ArrayByte.LITTLE_ENDIAN);
                        CollectionUtils.Put(cacheRes, fileName, result);
                    }
                    else
                    {
                        result.Reset(ArrayByte.LITTLE_ENDIAN);
                    }
                }
                else
                {
                    result = new ArrayByte(ins, ArrayByte.LITTLE_ENDIAN);
                }

                if (pak == null)
                {
                    pak = new PAK();
                    LPKHeader header = ReadHeader(result);
                    pak.tables    = ReadLPKTable(result, (int)header.GetTables());
                    pak.head_size = (int)(LPKHeader.Size() + header.GetTables()
                                          * LPKTable.Size());
                    pak.skip   = result.Position();
                    pak.length = result.Length();
                    CollectionUtils.Put(pakRes, fileName, pak);
                }
                else
                {
                    result.SetPosition(pak.skip);
                }

                bool       find      = false;
                int        fileIndex = 0;
                string     innerName = null;
                LPKTable[] tables_0  = pak.tables;
                int        size      = tables_0.Length;

                for (int i = 0; i < size; i++)
                {
                    innerName = tables_0[i].GetFileName();
                    if (resName.Equals(innerName, System.StringComparison.InvariantCultureIgnoreCase))
                    {
                        find      = true;
                        fileIndex = i;
                        break;
                    }
                }

                if (!find)
                {
                    throw new Exception("File not found. ( " + fileName
                                        + " )");
                }
                else
                {
                    return(ReadFileFromPak(result, pak.head_size, tables_0[fileIndex]));
                }
            } catch (Exception) {
                throw new Exception("File not found. ( " + fileName + " )");
            }
        }
Beispiel #12
0
 public ArrayByteReader(ArrayByte stream)
 {
     ins = stream;
 }