diff --git a/ModifyQuest.cs b/ModifyQuest.cs index 684bc5b..b870f82 100644 --- a/ModifyQuest.cs +++ b/ModifyQuest.cs @@ -29,7 +29,7 @@ namespace MHFQuestToMH2Dos target[i] = src[i]; } - //清除无意义数据 + //清除对于2Dos来说 无意义的数据 target[fixindex_1] = 0x00; string IntPtrHex = ""; @@ -46,24 +46,33 @@ namespace MHFQuestToMH2Dos IntPtrHex += target[i].ToString("X"); } + + //从前4字节取出指针 定位任务信息位置 long PtrIndex = HexHelper.HexaToDecimal(IntPtrHex); + //MHF偏移12的位置 long MoveStarPtr = PtrIndex + Offset; + //目标2Dos偏移8的位置 + long targetStarPtr = PtrIndex + Offset_2nd; + + //取出原始数据 byte[] temp = new byte[moveLenght]; for (int i = 0; i < moveLenght; i++) { temp[i] = target[MoveStarPtr + i]; - target[MoveStarPtr + i] = 0x00; } - long targetStarPtr = PtrIndex + Offset_2nd; - + //清理原始数据 + for (int i = 0; i < moveLenght; i++) + { + target[MoveStarPtr + i] = 0x00; + } + //将temp数据往前位移4字节 for (int i = 0; i < moveLenght; i++) { target[targetStarPtr + i] = temp[i]; } - return true; } catch (Exception ex) diff --git a/Program.cs b/Program.cs index cada1cb..683e97c 100644 --- a/Program.cs +++ b/Program.cs @@ -26,23 +26,31 @@ string[] files = FileHelper.GetDirFile(loc + InDir); int index= 0; + int errcount = 0; for(int i = 0;i < files.Length;i++) { - string FileName = files[0].Substring(files[0].LastIndexOf("\\")); + string FileName = files[i].Substring(files[i].LastIndexOf("\\")); if (!FileName.ToLower().Contains(".mib") && !FileName.ToLower().Contains(".bin")) { return; } index++; FileHelper.LoadFile(files[i], out byte[] data); - ModifyQuest.ModifyFile(data, out byte[] targetdata); - string newfileName = FileName + "_unpack"; - string outstring = loc + OutDir + "\\" + newfileName; - FileHelper.SaveFile(outstring, targetdata); - Console.WriteLine($"已处理第{index}个:{outstring}"); + if (ModifyQuest.ModifyFile(data, out byte[] targetdata)) + { + string newfileName = FileName + "_unpack"; + string outstring = loc + OutDir + "\\" + newfileName; + FileHelper.SaveFile(outstring, targetdata); + Console.WriteLine($"成功已处理 第{index}个:{outstring}"); + } + else + { + errcount++; + Console.WriteLine($"处理失败 第{index}个:{files[i]}"); + } } - Console.WriteLine($"需处理{files.Length}个文件"); + Console.WriteLine($"需处理{files.Length}个文件,其中{errcount}个失败"); Console.ReadLine(); } }