diff --git a/.vs/MHFQuestToMH2Dos/DesignTimeBuild/.dtbcache.v2 b/.vs/MHFQuestToMH2Dos/DesignTimeBuild/.dtbcache.v2 index 0a96450..0ffdf44 100644 Binary files a/.vs/MHFQuestToMH2Dos/DesignTimeBuild/.dtbcache.v2 and b/.vs/MHFQuestToMH2Dos/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/0b196810-a5ff-4285-929f-62a5d46db840.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/0b196810-a5ff-4285-929f-62a5d46db840.vsidx new file mode 100644 index 0000000..12819f5 Binary files /dev/null and b/.vs/MHFQuestToMH2Dos/FileContentIndex/0b196810-a5ff-4285-929f-62a5d46db840.vsidx differ diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/3065ff7b-d888-4a62-8ddb-4c590d937f45.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/3065ff7b-d888-4a62-8ddb-4c590d937f45.vsidx deleted file mode 100644 index 3c604d6..0000000 Binary files a/.vs/MHFQuestToMH2Dos/FileContentIndex/3065ff7b-d888-4a62-8ddb-4c590d937f45.vsidx and /dev/null differ diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/5fa92854-8543-48ed-8731-70281b87afa8.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/5fa92854-8543-48ed-8731-70281b87afa8.vsidx deleted file mode 100644 index 489a852..0000000 Binary files a/.vs/MHFQuestToMH2Dos/FileContentIndex/5fa92854-8543-48ed-8731-70281b87afa8.vsidx and /dev/null differ diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/be97255e-e451-4a1f-a323-64333d70356f.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/be97255e-e451-4a1f-a323-64333d70356f.vsidx new file mode 100644 index 0000000..9be0556 Binary files /dev/null and b/.vs/MHFQuestToMH2Dos/FileContentIndex/be97255e-e451-4a1f-a323-64333d70356f.vsidx differ diff --git a/.vs/MHFQuestToMH2Dos/v17/.suo b/.vs/MHFQuestToMH2Dos/v17/.suo index 20ef170..2567625 100644 Binary files a/.vs/MHFQuestToMH2Dos/v17/.suo and b/.vs/MHFQuestToMH2Dos/v17/.suo differ diff --git a/HexHelper.cs b/HexHelper.cs index 6940c3f..1a03936 100644 --- a/HexHelper.cs +++ b/HexHelper.cs @@ -137,6 +137,42 @@ namespace MHFQuestToMH2Dos srcdata[startoffset + i] = targetVal[i]; } + + /** + * 写入byte[]到byte[] byte高位在前 + */ + public static void ModifyDataToBytes(byte[] srcdata, byte[] targetVal, int startoffset) + { + //抹去数据 + for (int i = 0; i < targetVal.Length; i++) + srcdata[startoffset + i] = 0x00; + + for (int i = 0; i < targetVal.Length && i < targetVal.Length; i++) + srcdata[startoffset + i] = targetVal[i]; + } + + + + /** + * 对比数据 + */ + public static bool CheckDataEquals(byte[] srcdata, byte[] targetVal, int startoffset) + { + byte[] temp = new byte[targetVal.Length]; + for (int i = 0; i < targetVal.Length && i < targetVal.Length; i++) + temp[i] = srcdata[startoffset + i]; + + if (!Array.Equals(targetVal, temp)) + { + for (int i = 0; i < targetVal.Length; i++) + { + Console.WriteLine($"{(targetVal[i] != temp[i] ? "不等" : "相等")} target:{targetVal[i]} src:{temp[i]}"); + } + } + + return Array.Equals(targetVal, temp); + } + /// /// 另一种16进制转10进制的处理方式,Multiplier参与*16的循环很巧妙,对Multiplier的处理很推荐,逻辑统一 /// diff --git a/LoadToSaveTemplate.cs b/LoadToSaveTemplate.cs index 87a058d..ec03a9a 100644 --- a/LoadToSaveTemplate.cs +++ b/LoadToSaveTemplate.cs @@ -70,6 +70,12 @@ namespace MHFQuestToMH2Dos { int _One_CurrPtr = HexHelper.bytesToInt(target, 4, _CAreaSetTop_CurrPtr); + if (_One_CurrPtr == 0x0) + { + Log.HexInfo(_CAreaSetTop_CurrPtr, "区域设置"+i+"指针为0,跳过"); + break; + } + List datas = new List(); int Set_TargetIndex = 0; while (true) diff --git a/ModifyQuest.cs b/ModifyQuest.cs index eaa5024..2e3dcad 100644 --- a/ModifyQuest.cs +++ b/ModifyQuest.cs @@ -125,6 +125,9 @@ namespace MHFQuestToMH2Dos if (ModifyQuestRewardItem(target, out byte[] out_ModifyQuestRewardItem)) target = out_ModifyQuestRewardItem; + if (FixMapAreaData(target, out byte[] out_FixMapAreaData)) + target = out_FixMapAreaData; + return true; } @@ -606,5 +609,126 @@ namespace MHFQuestToMH2Dos Console.WriteLine(ex); target = null; return false; } } + + + + public static bool FixMapAreaData(byte[] src,out byte[] target) + { + int _QuestTargetMapID; + try + { + target = HexHelper.CopyByteArr(src);//加载数据 + + //从前4字节取出指针 定位任务信息位置 + int _QuestInfoPtr = HexHelper.bytesToInt(target, 4, 0x00); + Log.HexTips(0x00, "开始读取任务头部信息,指针->{0}", _QuestInfoPtr); + + //任务目的地MapID + _QuestTargetMapID = HexHelper.bytesToInt(target, ModifyQuest.cQuestInfo_TargetMapID_Lenght, _QuestInfoPtr + ModifyQuest.cQuestInfo_TargetMap_Offset); + Log.HexColor(ConsoleColor.Green, _QuestInfoPtr + ModifyQuest.cQuestInfo_TargetMap_Offset, "目的地地图,指针->{0} 【" + MHHelper.Get2MapName(_QuestTargetMapID) + "】", _QuestTargetMapID); + + //区域数量 + int _AreaCount = MHHelper.GetMapAreaCount(_QuestTargetMapID); + Log.Info(MHHelper.Get2MapName(_QuestTargetMapID) + "的地图数量" + _AreaCount); + + MapAreaData srcData2Dos = LoadToSaveTemplate.DictMapAreaData[_QuestTargetMapID]; + + #region 换区设置 + + //换区设置指针 + int _CAreaSetTopPtr = HexHelper.bytesToInt(target, 4, 0x1C); + 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); + + if (_One_CurrPtr == 0x0) + { + Log.HexInfo(_CAreaSetTop_CurrPtr, "区域设置" + i + "指针为0,跳过"); + break; + } + + if (srcData2Dos.targetDatas.Length <= i) + { + Log.HexWar(_One_CurrPtr, "第" + i + "区 区域设置,比2Dos区数超限。"); + break; + } + + + int Set_TargetIndex = 0; + while (true) + { + if (MHHelper.CheckEnd(target, _One_CurrPtr) + || + HexHelper.bytesToInt(target, 1, _One_CurrPtr) == 0) + { + Log.HexInfo(_One_CurrPtr, "区域设置结束符"); + break; + } + + if (srcData2Dos.targetDatas.Length <= i) + { + Log.HexWar(_One_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标,比2Dos目标数超限。"); + break; + } + + byte[] srcOneData = srcData2Dos.targetDatas[i].targetData[Set_TargetIndex]; + + if (!HexHelper.CheckDataEquals(target, srcOneData, _One_CurrPtr)) + { + Log.HexWar(_One_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标,数据和2Dos差异,长度{0}", srcOneData.Length); + } + + HexHelper.ModifyDataToBytes(target, srcOneData, _One_CurrPtr); + Log.HexTips(_One_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标,更换为2Dos数据,长度{0}", srcOneData.Length); + + Set_TargetIndex++; + _One_CurrPtr += 0x34; + } + + _CAreaSetTop_CurrPtr += 0x4; + } + #endregion + + #region 区域映射 + //区域映射指针 + int _CAreaPosTopPtr = HexHelper.bytesToInt(target, 4, 0x20); + Log.HexInfo(0x20, "换区映射指针->{0}", _CAreaPosTopPtr); + //读取单个区域映射游标 + int _CAreaPosTop_CurrPtr = _CAreaPosTopPtr; + for (int i = 0; i < _AreaCount; i++) + { + if (srcData2Dos.targetDatas.Length <= i) + { + Log.HexWar(_CAreaPosTop_CurrPtr, "第" + i + "区 换区映射,比2Dos区数超限。"); + break; + } + byte[] srcOneData = srcData2Dos.areaPosDatas[i]; + + if (!HexHelper.CheckDataEquals(target, srcOneData, _CAreaPosTop_CurrPtr)) + { + Log.HexWar(_CAreaPosTop_CurrPtr, "第" + i + "区的区域映射,数据和2Dos差异,读取数据,长度{0}", srcOneData.Length); + } + + HexHelper.ModifyDataToBytes(target, srcOneData, _CAreaPosTop_CurrPtr); + Log.HexTips(_CAreaPosTop_CurrPtr, "第" + i + "区的区域映射,更换为2Dos数据,读取数据,长度{0}", srcOneData.Length); + _CAreaPosTop_CurrPtr += 0x20; + } + #endregion + + } + catch (Exception ex) + { + Console.WriteLine(ex); + target = null; + return false; + } + + return true; + } } } diff --git a/Program.cs b/Program.cs index 7d96260..8d8b6c0 100644 --- a/Program.cs +++ b/Program.cs @@ -66,12 +66,11 @@ namespace MHFQuestToMH2Dos } } - Console.WriteLine($"原数据读取完毕"); + Console.WriteLine($"-----------原数据读取完毕-----------"); string[] files = FileHelper.GetDirFile(loc + InDir); Console.WriteLine($"共{files.Length}个文件,是否处理? (y/n)"); - string yn = Console.ReadLine(); if (yn.ToLower() != "y") return;