Example #1
0
        /// <summary>
        /// 写入CSV文件
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="csvFile"></param>
        /// <param name="mode"></param>
        /// <param name="seq"></param>
        private void writeToCsv(ItemEntity entity, string csvFile, FileMode mode, int seq)
        {
            if (entity != null)
            {
                FileStream csvFos = new FileStream(csvFile, mode, FileAccess.Write);
                using (StreamWriter fileWriter = new StreamWriter(csvFos))
                {
                    StringBuilder builder = new StringBuilder();

                    builder.Append(seq);
                    builder.Append(",");
                    builder.Append(entity.ItemNo);
                    builder.Append(",");
                    builder.Append(entity.UnknowFragment1);
                    builder.Append(",");
                    builder.Append(entity.ItemNameLen);
                    builder.Append(",");
                    builder.Append(entity.ItemName);
                    builder.Append(",");
                    builder.Append(entity.UnknowFragment2);
                    builder.Append(",");
                    builder.Append(entity.ItemX);
                    builder.Append(",");
                    builder.Append(entity.ItemY);
                    builder.Append(",");
                    builder.Append(entity.UnknowFragment3);
                    builder.Append(",");
                    builder.Append(entity.UnknowFragment4);
                    builder.Append(",");
                    builder.Append(entity.UnknowFragment5);
                    builder.Append(",");
                    builder.Append(entity.UnknowFragment6);
                    builder.Append(",");
                    builder.Append(entity.UnknowFragment7);
                    builder.Append(",");
                    builder.Append(entity.UnknowFragment8);
                    builder.Append(",");
                    builder.Append(entity.UnknowFragment9);
                    builder.Append(",");
                    builder.Append(entity.UnknowFragment10);
                    builder.Append(",");
                    builder.Append(entity.ItemHex);

                    fileWriter.WriteLine(builder.ToString());
                    fileWriter.Flush();
                }

                csvFos.Close();
            }
        }
Example #2
0
        /// <summary>
        /// 分段信息转为元素实体
        /// </summary>
        /// <param name="itemName"></param>
        /// <param name="fragment"></param>
        /// <param name="items"></param>
        /// <returns></returns>
        private ItemEntity convertFromFragment(string itemName, List<string> fragment, List<ItemEntity> items)
        {
            if (fragment != null && fragment.Count > 0)
            {
                ItemEntity entity = new ItemEntity();

                // 最后两位为元素编号
                entity.ItemNo = getDecFromFragmentSlice(fragment.Count - 2, 2, fragment, true).ToString();

                // 未知位信息1 - 偏移位? 第三字节位
                entity.UnknowFragment1 = getDecFromFragmentSlice(2, 2, fragment, true).ToString();

                // 元素名称
                entity.ItemName = itemName;

                // 元素长度
                entity.ItemNameLen = itemName.Length.ToString();

                // 除去头信息和文件名之后的起始索引点
                int offset = ITEM_HEADER_LEN + itemName.Length;

                // 未知位信息2 - 1个字节
                entity.UnknowFragment2 = HexHelper.hexToDec(fragment[offset]).ToString();

                // 移动偏移位, 中间过滤7个字节的占位符 + 位字节
                offset = offset + 7 + 1;

                // X坐标
                entity.ItemX = getDecFromFragmentSlice(offset, 4, fragment, true).ToString();

                // 移动偏移位 - 4个字节占位符 + X坐标位字节位
                offset = offset + 4 + 4;

                // Y坐标
                entity.ItemY = getDecFromFragmentSlice(offset, 4, fragment, true).ToString();

                // 移动偏移位 - 4个字节占位符 + X坐标位字节位
                offset = offset + 4;

                // 未知位信息3 - 4个字节
                entity.UnknowFragment3 = getDecFromFragmentSlice(offset, 4, fragment, true).ToString();

                // 移动偏移位 - 4个字节占位符 + 未知位信息3字节位
                offset = offset + 4 + 4;

                // 未知位信息4 - 4个字节
                entity.UnknowFragment4 = getDecFromFragmentSlice(offset, 4, fragment, true).ToString();

                // 移动偏移位 - 未知位信息4字节位
                offset = offset + 4;

                // 未知位信息5 - 4个字节
                entity.UnknowFragment5 = getDecFromFragmentSlice(offset, 4, fragment, true).ToString();

                // 移动偏移位 - 未知位信息5字节位
                offset = offset + 4;

                // 未知位信息6 - 4个字节
                entity.UnknowFragment6 = getDecFromFragmentSlice(offset, 4, fragment, true).ToString();

                // 移动偏移位 - 4个字节占位符 + 未知位信息6字节位
                offset = offset + 4 + 4;

                // 未知位信息7 - 4个字节
                entity.UnknowFragment7 = getDecFromFragmentSlice(offset, 4, fragment, true).ToString();

                // 移动偏移位 - 未知位信息7字节位
                offset = offset + 4;

                // 未知位信息8 - 4个字节
                entity.UnknowFragment8 = getDecFromFragmentSlice(offset, 4, fragment, true).ToString();

                // 移动偏移位 - 未知位信息8字节位
                offset = offset + 4;

                if (fragment.Count - offset > 15)
                {
                    // 超出预期的数据格式
                    // 00 00 CB 4B 00 00 0F 73 74 61 67 65 30 30 35 5F 30 30 32 61 5F 67 00 00 00 00 00 00 00 00
                    // 28 00 00 00 00 00 00 00 EC FF FF FF 35 00 00 00 00 00 00 00 ,91 1F 00 00, 00 00 00 00 ,00 00 00 00, 02 00 00 00,
                    // 0F 00 00 00, 0F 00 00 00, 00 00 00 00, 01 00 00 00,
                    // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 B8 D5 CC CC CC C9 C6 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
                    // 01, FF FF FF FF, 48 07
                    offset = fragment.Count - 7;
                }

                entity.UnknowFragment9 = getDecFromFragmentSlice(offset, 1, fragment, false).ToString();

                // 移动偏移位 - 未知位信息9字节位
                offset = offset + 1;

                // 未知位信息10 - 不固定长度, 可能0个字节, 可能多个字节
                if (fragment.Count - 2 - offset > 0)
                {
                    entity.UnknowFragment10 = getDecFromFragmentSlice(offset, fragment.Count - 2 - offset, fragment, true).ToString();
                }
                else
                {
                    entity.UnknowFragment10 = entity.ItemNo;
                }

                // 地图元素编号修正, 确保`mogu_mogu_a001`, `mogu_mogu_a0011`元素编号一致
                bool revised = false;
                string entityName = entity.ItemName;

                if (entityName.StartsWith("shuicao_qun_b"))
                {
                    Console.Write("Debug");
                }

                while (!revised)
                {
                    foreach (ItemEntity item in items)
                    {
                        if (entityName.StartsWith(item.ItemName) || item.ItemName.StartsWith(entityName))
                        {
                            entity.ItemNo = item.ItemNo;
                            log("修正元素编号: `" + entity.ItemName + " `to " + entity.ItemNo);
                            revised = true;
                            break;
                        }
                    }

                    int num = -1;
                    if (int.TryParse(entityName[entityName.Length - 1].ToString(), out num))
                    {
                        entityName = entityName.Substring(0, entityName.Length - 1);
                    }
                    else
                    {
                        break;
                    }

                }

                entity.ItemHex = String.Join(" ", fragment.ToArray());

                return entity;
            }

            return null;
        }