예제 #1
0
    public static GameLevel_EnterProto GetProto(byte[] buffer)
    {
        GameLevel_EnterProto proto = new GameLevel_EnterProto();

        using (MMoMemorySteam ms = new MMoMemorySteam(buffer))
        {
            ms.ReadUShort();
            proto.GameLevelId = ms.ReadInt();
            proto.Grade       = (byte)ms.ReadByte();
        }
        return(proto);
    }
예제 #2
0
    private byte[] xorScale = new byte[] { 45, 66, 38, 55, 23, 251, 9, 166, 90, 19, 41, 45, 201, 58, 55, 37, 254, 185, 165, 169, 19, 171 };    //.data文件的xor加解密因子
    #endregion

    #region GameDataTableParser 构造函数
    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="path"></param>
    public ReadExcelAndParss(string path)
    {
        m_FieldNameDic = new Dictionary <string, int>();
        byte[] buffer = null;

        //------------------
        //第1步:读取文件
        //------------------
        using (FileStream fs = new FileStream(path, FileMode.Open))
        {
            buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
        }

        //------------------
        //第2步:解压缩
        //------------------
        buffer = ZlibHelper.DeCompressBytes(buffer);

        //------------------
        //第3步:xor解密
        //------------------
        int iScaleLen = xorScale.Length;

        for (int i = 0; i < buffer.Length; i++)
        {
            buffer[i] = (byte)(buffer[i] ^ xorScale[i % iScaleLen]);
        }

        //------------------
        //第4步:解析数据到数组
        //------------------
        using (MMoMemorySteam ms = new MMoMemorySteam(buffer))
        {
            m_Row    = ms.ReadInt();
            m_Column = ms.ReadInt();

            m_GameData  = new String[m_Row, m_Column];
            m_FieldName = new string[m_Column];

            for (int i = 0; i < m_Row; i++)
            {
                for (int j = 0; j < m_Column; j++)
                {
                    string str = ms.ReadString();

                    if (i == 0)
                    {
                        //表示读取的是字段
                        m_FieldName[j]      = str;
                        m_FieldNameDic[str] = j;
                    }
                    else if (i > 2)
                    {
                        //表示读取的是内容
                        m_GameData[i, j] = str;
                    }
                }
            }
        }
    }