Esempio n. 1
0
        public static List <AccAttr> LoadPlayerInfos(string file, bool reload = false)
        {
            if (!reload && m_playersAttrList.Count != 0)
            {
                return(m_playersAttrList);
            }

            List <AccAttr> AccAttrList = new List <AccAttr>();

            AccAttrList.Clear();

            string dbfile = file;

            if (!File.Exists(dbfile))
            {
                AccAttrList.Clear();
                return(AccAttrList);
            }

            if (File.Exists(@".\\Temp\\players.dat"))
            {
                File.SetAttributes(@".\\Temp\\players.dat", FileAttributes.Normal);
                File.Copy(dbfile, @".\\Temp\\players.dat", true);
            }
            else
            {
                File.Copy(dbfile, @".\\Temp\\players.dat", false);
            }


            FileStream  fs   = new FileStream(".\\Temp\\players.dat", FileMode.Open, FileAccess.ReadWrite);
            AccAttrHead head = new AccAttrHead();

            int ret = 0;

            byte[] bytData = new byte[Marshal.SizeOf(head)];
            ret = fs.Read(bytData, 0, Marshal.SizeOf(head));
            while (ret > 0)
            {
                AccAttr aa             = new AccAttr();
                byte[]  bytAccAttrData = new byte[Marshal.SizeOf(aa)];
                ret = fs.Read(bytAccAttrData, 0, Marshal.SizeOf(aa));
                if (ret <= 0)
                {
                    break;
                }
                AccAttr acc_attr = CStructBytesFormat.BytesToStruct <AccAttr>(bytAccAttrData);

                AccAttrList.Add(acc_attr);
            }

            fs.Close();

            //更新本地list
            m_playersAttrList.Clear();
            m_playersAttrList = AccAttrList;

            return(AccAttrList);
        }
Esempio n. 2
0
        public static Tran_Head GetDataHead(byte[] data)
        {
            Tran_Head head = new Tran_Head();

            byte[] rcv_head = new byte[Marshal.SizeOf(head)];
            Array.ConstrainedCopy(data, 0, rcv_head, 0, Marshal.SizeOf(head));
            head = (Tran_Head)CStructBytesFormat.BytesToStruct <Tran_Head>(rcv_head);

            return(head);
        }
Esempio n. 3
0
        public static byte[] BuildBytes <T>(Tran_Head hd, T obj)
        {
            byte[] head = CStructBytesFormat.StructToBytes(hd);
            byte[] data = CStructBytesFormat.StructToBytes(obj);

            byte[] rbyte = new byte[data.Length + head.Length];

            Array.ConstrainedCopy(head, 0, rbyte, 0, head.Length);
            Array.ConstrainedCopy(data, 0, rbyte, head.Length, data.Length);

            return(rbyte);
        }
Esempio n. 4
0
        public static List <Skill_Str> LoadSkillsData(string file)
        {
            List <Skill_Str> skillList = new List <Skill_Str>();

            skillList.Clear();

            if (!File.Exists(file))
            {
                skillList.Clear();
                return(skillList);
            }

            if (File.Exists(@".\\Temp\\skill.dat"))
            {
                File.SetAttributes(@".\\Temp\\skill.dat", FileAttributes.Normal);
                File.Copy(file, @".\\Temp\\skill.dat", true);
            }
            else
            {
                File.Copy(file, @".\\Temp\\skill.dat", false);
            }

            FileStream fs = new FileStream(".\\Temp\\skill.dat", FileMode.Open, FileAccess.ReadWrite);

            int ret = 0;

            ret = fs.Read(skillHd, 0, SkillData_HeadOffset);
            while (ret > 0)
            {
                Skill_Str aa             = new Skill_Str();
                byte[]    bytAccAttrData = new byte[Marshal.SizeOf(aa)];
                ret = fs.Read(bytAccAttrData, 0, Marshal.SizeOf(aa));
                if (ret <= 0)
                {
                    break;
                }
                Skill_Str acc_attr = CStructBytesFormat.BytesToStruct <Skill_Str>(bytAccAttrData);

                skillList.Add(acc_attr);
            }

            fs.Close();

            skillData.Clear();
            skillData = skillList;

            return(skillList);
        }
Esempio n. 5
0
        public static T GetDataObj <T>(byte[] data, Tran_Head head)
        {
            if (data == null)
            {
                return(default(T));
            }
            if (data.Length <= 0)
            {
                return(default(T));
            }
            int objLength = Marshal.SizeOf(typeof(T));

            byte[] rcv_data = new byte[head.length];
            T      obj;

            Array.ConstrainedCopy(data, Marshal.SizeOf(head), rcv_data, 0, rcv_data.Length);
            obj = (T)CStructBytesFormat.BytesToStruct <T>(rcv_data);

            return(obj);
        }