diff --git a/.vs/MHFQuestToMH2Dos/DesignTimeBuild/.dtbcache.v2 b/.vs/MHFQuestToMH2Dos/DesignTimeBuild/.dtbcache.v2 index 29ea1fe..8b3e2ff 100644 Binary files a/.vs/MHFQuestToMH2Dos/DesignTimeBuild/.dtbcache.v2 and b/.vs/MHFQuestToMH2Dos/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/22a22e0a-378a-4162-9029-df857dd8a9b7.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/22a22e0a-378a-4162-9029-df857dd8a9b7.vsidx deleted file mode 100644 index e5fe1e6..0000000 Binary files a/.vs/MHFQuestToMH2Dos/FileContentIndex/22a22e0a-378a-4162-9029-df857dd8a9b7.vsidx and /dev/null differ diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/84346fa7-44ef-4e25-b949-4db4fce71946.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/84346fa7-44ef-4e25-b949-4db4fce71946.vsidx new file mode 100644 index 0000000..287adc9 Binary files /dev/null and b/.vs/MHFQuestToMH2Dos/FileContentIndex/84346fa7-44ef-4e25-b949-4db4fce71946.vsidx differ diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/94264fbb-8443-4cdf-a0bd-37b258fbba7c.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/94264fbb-8443-4cdf-a0bd-37b258fbba7c.vsidx new file mode 100644 index 0000000..4fa2c92 Binary files /dev/null and b/.vs/MHFQuestToMH2Dos/FileContentIndex/94264fbb-8443-4cdf-a0bd-37b258fbba7c.vsidx differ diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/c0664012-1feb-404d-a35b-78294170492b.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/c0664012-1feb-404d-a35b-78294170492b.vsidx deleted file mode 100644 index e206e9b..0000000 Binary files a/.vs/MHFQuestToMH2Dos/FileContentIndex/c0664012-1feb-404d-a35b-78294170492b.vsidx and /dev/null differ diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/c466fafe-3689-4c5b-a77b-c54847288655.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/c466fafe-3689-4c5b-a77b-c54847288655.vsidx new file mode 100644 index 0000000..0c00f61 Binary files /dev/null and b/.vs/MHFQuestToMH2Dos/FileContentIndex/c466fafe-3689-4c5b-a77b-c54847288655.vsidx differ diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/7d2f5524-f7b5-49f7-b6d7-33f1ebc58b92.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/dac73615-8854-481f-819e-dce5a960ad20.vsidx similarity index 100% rename from .vs/MHFQuestToMH2Dos/FileContentIndex/7d2f5524-f7b5-49f7-b6d7-33f1ebc58b92.vsidx rename to .vs/MHFQuestToMH2Dos/FileContentIndex/dac73615-8854-481f-819e-dce5a960ad20.vsidx diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/e774d260-8760-453e-b362-96d9289ea8fe.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/e774d260-8760-453e-b362-96d9289ea8fe.vsidx deleted file mode 100644 index 9315c06..0000000 Binary files a/.vs/MHFQuestToMH2Dos/FileContentIndex/e774d260-8760-453e-b362-96d9289ea8fe.vsidx and /dev/null differ diff --git a/.vs/MHFQuestToMH2Dos/v17/.futdcache.v2 b/.vs/MHFQuestToMH2Dos/v17/.futdcache.v2 new file mode 100644 index 0000000..41ce14a Binary files /dev/null and b/.vs/MHFQuestToMH2Dos/v17/.futdcache.v2 differ diff --git a/.vs/MHFQuestToMH2Dos/v17/.suo b/.vs/MHFQuestToMH2Dos/v17/.suo index a80ac1f..f34f67d 100644 Binary files a/.vs/MHFQuestToMH2Dos/v17/.suo and b/.vs/MHFQuestToMH2Dos/v17/.suo differ diff --git a/.vs/ProjectEvaluation/mhfquesttomh2dos.metadata.v5.2 b/.vs/ProjectEvaluation/mhfquesttomh2dos.metadata.v5.2 new file mode 100644 index 0000000..9bb3cfe Binary files /dev/null and b/.vs/ProjectEvaluation/mhfquesttomh2dos.metadata.v5.2 differ diff --git a/.vs/ProjectEvaluation/mhfquesttomh2dos.projects.v5.2 b/.vs/ProjectEvaluation/mhfquesttomh2dos.projects.v5.2 new file mode 100644 index 0000000..1e91772 Binary files /dev/null and b/.vs/ProjectEvaluation/mhfquesttomh2dos.projects.v5.2 differ diff --git a/HexHelper.cs b/HexHelper.cs index 9a8754e..3f3f7ef 100644 --- a/HexHelper.cs +++ b/HexHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; @@ -8,6 +9,46 @@ namespace MHFQuestToMH2Dos { public class HexHelper { + + /** + * byte[]转换int byte高位在前 + */ + public static int bytesToInt(byte[] src,int lenght, int offset = 0) + { + if (lenght == 1) + return src[offset + 0]; + + byte[] data = new byte[lenght]; + for (int i = 0; i < lenght; i++) + { + data[i] = src[offset + i]; + } + return BitConverter.ToInt32(data, 0); + } + + /** + * int 转 byte[] byte高位在前 + */ + public static byte[] intToBytes(int value) + { + return BitConverter.GetBytes(value); + } + + /** + * 写入int到byte[] byte高位在前 + */ + public static void ModifyIntHexToBytes(byte[] srcdata, int targetvalue,int startoffset, int srclenght) + { + byte[] targetVal = intToBytes(targetvalue); + + //抹去数据 + for (int i = 0; i < srclenght; i++) + srcdata[startoffset + i] = 0x00; + + for (int i = 0; i < targetVal.Length && i < srclenght; i++) + srcdata[startoffset + i] = targetVal[i]; + } + /// /// 另一种16进制转10进制的处理方式,Multiplier参与*16的循环很巧妙,对Multiplier的处理很推荐,逻辑统一 /// diff --git a/ModifyQuest.cs b/ModifyQuest.cs index b870f82..b6e9cec 100644 --- a/ModifyQuest.cs +++ b/ModifyQuest.cs @@ -11,68 +11,116 @@ namespace MHFQuestToMH2Dos /// /// Dos中无意义数据 /// - const int fixindex_1 = 19; + const int cNon0x00For2DosPtr = 19; + /// + /// MHF任务信息偏移 + /// + const int cQuestMHFOffset = 12; + /// + /// 2Dos任务信息偏移 + /// + const int cQuest2DosOffset = 8; + /// + /// 任务信息长度 + /// + const int cQuestInfoLenght = 64; + /// + /// 任务_类型 偏移 + /// + const int cQuestInfo_Type_Offset = 0; + /// + /// 任务_类型 长度 + /// + const int cQuestInfo_Type_Lenght = 1; + /// + /// 任务_类型 偏移 + /// + const int cQuestInfo_TargetMap_Offset = 32; + /// + /// 任务_类型 长度 + /// + const int cQuestInfo_TargetMapID_Lenght = 1; - const int Offset = 12; - const int Offset_2nd = 8; + public static bool ModifyQuset(byte[] src, out byte[] target) + { + target = null; - const int moveLenght = 64; + if (!ModifyFileOffset(src, out byte[] Setp1out)) + return false; - public static bool ModifyFile(byte[] src,out byte[] target) + if (!ModifyQuestMap(Setp1out, out byte[] Setp2out)) + return false; + + target = Setp2out; + return true; + } + + + public static bool ModifyFileOffset(byte[] src, out byte[] target) { try { + //加载数据 target = new byte[src.Length]; - for (int i = 0; i < src.Length; i++) - { target[i] = src[i]; - } - - //清除对于2Dos来说 无意义的数据 - target[fixindex_1] = 0x00; - - string IntPtrHex = ""; - bool flag = false; - - for (int i = 3; i >= 0; i--) - { - if (target[i] != 0x00) - flag = true; - - if (flag) - IntPtrHex += target[i].ToString("X"); - else if (target[i] != 0x00) - IntPtrHex += target[i].ToString("X"); - } - //从前4字节取出指针 定位任务信息位置 - long PtrIndex = HexHelper.HexaToDecimal(IntPtrHex); + int _QuestInfoPtr = HexHelper.bytesToInt(target, 4, 0x00); + //----Step---- 清除对于2Dos来说 无意义的数据 + target[cNon0x00For2DosPtr] = 0x00; + + //----Step---- 前移任务数据4字节 (MHF比2Dos后移了4字节,MHF:+12 2Dos: +8) //MHF偏移12的位置 - long MoveStarPtr = PtrIndex + Offset; + long QuestInfoPtr_MHFTarget = _QuestInfoPtr + cQuestMHFOffset; //目标2Dos偏移8的位置 - long targetStarPtr = PtrIndex + Offset_2nd; - - + long QuestInfoPtr_2DosTarget = _QuestInfoPtr + cQuest2DosOffset; //取出原始数据 - byte[] temp = new byte[moveLenght]; - for (int i = 0; i < moveLenght; i++) + byte[] temp = new byte[cQuestInfoLenght]; + for (int i = 0; i < cQuestInfoLenght; i++) { - temp[i] = target[MoveStarPtr + i]; + temp[i] = target[QuestInfoPtr_MHFTarget + i]; } - //清理原始数据 - for (int i = 0; i < moveLenght; i++) + for (int i = 0; i < cQuestInfoLenght; i++) { - target[MoveStarPtr + i] = 0x00; + target[QuestInfoPtr_MHFTarget + i] = 0x00; } //将temp数据往前位移4字节 - for (int i = 0; i < moveLenght; i++) + for (int i = 0; i < cQuestInfoLenght; i++) { - target[targetStarPtr + i] = temp[i]; + target[QuestInfoPtr_2DosTarget + i] = temp[i]; } + + return true; + } + catch (Exception ex) + { + Console.WriteLine(ex); + target = null; + return false; + } + } + + + public static bool ModifyQuestMap(byte[] src, out byte[] target) + { + try + { + //加载数据 + target = new byte[src.Length]; + for (int i = 0; i < src.Length; i++) + target[i] = src[i]; + + //从前4字节取出指针 定位任务信息位置 + int _QuestInfoPtr = HexHelper.bytesToInt(target, 4, 0x00); + + //----Step---- 读取任务数据 + //任务类型 + int _QuestType = HexHelper.bytesToInt(target, cQuestInfo_Type_Lenght, _QuestInfoPtr + cQuestInfo_Type_Offset); + int _QuestTargetMapID = HexHelper.bytesToInt(target, cQuestInfo_TargetMapID_Lenght, _QuestInfoPtr + cQuestInfo_TargetMap_Offset); + return true; } catch (Exception ex) diff --git a/Program.cs b/Program.cs index 51836e0..d341e58 100644 --- a/Program.cs +++ b/Program.cs @@ -36,7 +36,7 @@ } index++; FileHelper.LoadFile(files[i], out byte[] data); - if (ModifyQuest.ModifyFile(data, out byte[] targetdata)) + if (ModifyQuest.ModifyQuset(data, out byte[] targetdata)) { string newfileName = FileName + "_fix"; string outstring = loc + OutDir + "\\" + newfileName;