MHFQuestToMH2Dos/LoadToSaveTemplate.cs

164 lines
6.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2023-04-06 08:55:15 +08:00
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MHFQuestToMH2Dos
{
public class MapAreaData
{
public MapAreaData(int Count)
{
targetDatas = new TargetData[Count];
areaPosDatas = new List<byte[]>();
}
public TargetData[] targetDatas;
public List<byte[]> areaPosDatas;
}
public class TargetData
{
public TargetData(List<byte[]> data)
{
targetData = data;
}
public List<byte[]> targetData;
}
public static class LoadToSaveTemplate
{
public static Dictionary<int, MapAreaData> DictMapAreaData = new Dictionary<int, MapAreaData>();
public static Dictionary<int, string> DictMapIDFileName = new Dictionary<int, string>();
public static Dictionary<int, string> DictMapIDFullFileName = new Dictionary<int, string>();
public static bool LoadMapTemplateAreaData(byte[] src,string FileName,string FullFileName)
{
byte[] target;
int _QuestTargetMapID;
//地图数据
MapAreaData mapAreaData;
try
{
target = HexHelper.CopyByteArr(src);//加载数据
//从前4字节取出指针 定位任务信息位置
int _QuestInfoPtr = HexHelper.bytesToInt(target, 4, 0x00);
2023-04-06 08:55:15 +08:00
//Log.HexTips(0x00, "开始读取任务头部信息,指针->{0}", _QuestInfoPtr);
//任务目的地MapID
_QuestTargetMapID = HexHelper.bytesToInt(target, ModifyQuest.cQuestInfo_TargetMapID_Lenght, _QuestInfoPtr + ModifyQuest.cQuestInfo_TargetMap_Offset);
2023-04-06 08:55:15 +08:00
//Log.HexColor(ConsoleColor.Green, _QuestInfoPtr + ModifyQuest.cQuestInfo_TargetMap_Offset, "目的地地图,指针->{0} 【" + MHHelper.Get2MapName(_QuestTargetMapID) + "】", _QuestTargetMapID);
//区域数量
int _AreaCount = MHHelper.GetMapAreaCount(_QuestTargetMapID);
2023-04-06 08:55:15 +08:00
//Log.Info(MHHelper.Get2MapName(_QuestTargetMapID) + "的地图数量" + _AreaCount);
mapAreaData = new MapAreaData(_AreaCount);
#region
//换区设置指针
int _CAreaSetTopPtr = HexHelper.bytesToInt(target, 4, 0x1C);
2023-04-06 08:55:15 +08:00
//Log.HexInfo(0x1C, "换区设置指针->{0}", _CAreaSetTopPtr);
//读取换区单个区域游标
int _CAreaSetTop_CurrPtr = _CAreaSetTopPtr;
for (int i = 0; i < _AreaCount; i++)
{
int _One_CurrPtr = HexHelper.bytesToInt(target, 4, _CAreaSetTop_CurrPtr);
2023-04-04 18:28:24 +08:00
if (_One_CurrPtr == 0x0)
{
2023-04-06 08:55:15 +08:00
//Log.HexInfo(_CAreaSetTop_CurrPtr, "区域设置"+i+"指针为0跳过");
2023-04-04 18:28:24 +08:00
break;
}
List<byte[]> datas = new List<byte[]>();
int Set_TargetIndex = 0;
while (true)
{
if (MHHelper.CheckEnd(target, _One_CurrPtr)
||
HexHelper.bytesToInt(target, 1, _One_CurrPtr) == 0)
{
2023-04-06 08:55:15 +08:00
//Log.HexInfo(_One_CurrPtr, "区域设置结束符");
break;
}
2023-04-06 08:55:15 +08:00
//Log.HexInfo(_CAreaSetTop_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标,换区设置指针->{0}", _One_CurrPtr);
//Log.HexTips(_One_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标,读取数据,长度{0}", 0x34);
datas.Add(HexHelper.ReadBytes(target, 0x34, _One_CurrPtr));
Set_TargetIndex++;
_One_CurrPtr += 0x34;
}
mapAreaData.targetDatas[i] = new TargetData(datas);
_CAreaSetTop_CurrPtr += 0x4;
}
#endregion
#region
//区域映射指针
int _CAreaPosTopPtr = HexHelper.bytesToInt(target, 4, 0x20);
2023-04-06 08:55:15 +08:00
//Log.HexInfo(0x20, "换区映射指针->{0}", _CAreaPosTopPtr);
//读取单个区域映射游标
int _CAreaPosTop_CurrPtr = _CAreaPosTopPtr;
for (int i = 0; i < _AreaCount; i++)
{
2023-04-06 08:55:15 +08:00
//Log.HexTips(_CAreaPosTop_CurrPtr, "第" + i + "区的区域映射,读取数据,长度{0}", 0x20);
mapAreaData.areaPosDatas.Add(HexHelper.ReadBytes(target, 0x20, _CAreaPosTop_CurrPtr));
_CAreaPosTop_CurrPtr += 0x20;
}
#endregion
}
catch (Exception ex)
{
Console.WriteLine(ex);
target = null;
return false;
}
DictMapAreaData[_QuestTargetMapID] = mapAreaData;
DictMapIDFileName[_QuestTargetMapID] = MHHelper.Get2MapName(_QuestTargetMapID) + FileName;
if (DictMapIDFullFileName.ContainsKey(_QuestTargetMapID))
{
File.Delete(DictMapIDFullFileName[_QuestTargetMapID]);
}
DictMapIDFullFileName[_QuestTargetMapID] = FullFileName;
2023-04-06 08:55:15 +08:00
//Log.HexColor(ConsoleColor.Green, _QuestTargetMapID, "成功,缓存地图 编号{0}" + MHHelper.Get2MapName(_QuestTargetMapID) + "的数据", _QuestTargetMapID);
return true;
}
2023-04-06 08:55:15 +08:00
public static Dictionary<string, int> DictTimeTypeCount = new Dictionary<string, int>();
public static void GetModeType(byte[] src,string FileName)
{
try
{
byte[] target = HexHelper.CopyByteArr(src);//加载数据
//从前4字节取出指针 定位任务信息位置
int _QuestInfoPtr = HexHelper.bytesToInt(target, 4, 0x00);
int _TimeType = HexHelper.bytesToInt(target, 1, _QuestInfoPtr + 2);
string key = FileName.Substring(FileName.Length - 1 - 5) + "_" + "(0x" + _TimeType.ToString("X") + ")";
if(!DictTimeTypeCount.ContainsKey(key))
{
DictTimeTypeCount[key] = 0;
}
DictTimeTypeCount[key]++;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}