commit c34789da454f5b3484cb6fed43061abe02254008
Author: sin365 <353374337@qq.com>
Date: Thu Mar 23 18:32:30 2023 +0800
归档
diff --git a/.vs/MHFQuestToMH2Dos/DesignTimeBuild/.dtbcache.v2 b/.vs/MHFQuestToMH2Dos/DesignTimeBuild/.dtbcache.v2
new file mode 100644
index 0000000..29ea1fe
Binary files /dev/null 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
new file mode 100644
index 0000000..e5fe1e6
Binary files /dev/null and b/.vs/MHFQuestToMH2Dos/FileContentIndex/22a22e0a-378a-4162-9029-df857dd8a9b7.vsidx differ
diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/7d2f5524-f7b5-49f7-b6d7-33f1ebc58b92.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/7d2f5524-f7b5-49f7-b6d7-33f1ebc58b92.vsidx
new file mode 100644
index 0000000..ef1b08b
Binary files /dev/null and b/.vs/MHFQuestToMH2Dos/FileContentIndex/7d2f5524-f7b5-49f7-b6d7-33f1ebc58b92.vsidx differ
diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/c0664012-1feb-404d-a35b-78294170492b.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/c0664012-1feb-404d-a35b-78294170492b.vsidx
new file mode 100644
index 0000000..e206e9b
Binary files /dev/null and b/.vs/MHFQuestToMH2Dos/FileContentIndex/c0664012-1feb-404d-a35b-78294170492b.vsidx differ
diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/e774d260-8760-453e-b362-96d9289ea8fe.vsidx b/.vs/MHFQuestToMH2Dos/FileContentIndex/e774d260-8760-453e-b362-96d9289ea8fe.vsidx
new file mode 100644
index 0000000..9315c06
Binary files /dev/null and b/.vs/MHFQuestToMH2Dos/FileContentIndex/e774d260-8760-453e-b362-96d9289ea8fe.vsidx differ
diff --git a/.vs/MHFQuestToMH2Dos/FileContentIndex/read.lock b/.vs/MHFQuestToMH2Dos/FileContentIndex/read.lock
new file mode 100644
index 0000000..e69de29
diff --git a/.vs/MHFQuestToMH2Dos/v17/.suo b/.vs/MHFQuestToMH2Dos/v17/.suo
new file mode 100644
index 0000000..a80ac1f
Binary files /dev/null and b/.vs/MHFQuestToMH2Dos/v17/.suo differ
diff --git a/FileHelper.cs b/FileHelper.cs
new file mode 100644
index 0000000..8a8841f
--- /dev/null
+++ b/FileHelper.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MHFQuestToMH2Dos
+{
+ public class FileHelper
+ {
+ public static bool LoadFile(string FilePath, out byte[] data)
+ {
+ using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
+ {
+ try
+ {
+ byte[] buffur = new byte[fs.Length];
+ fs.Read(buffur, 0, (int)fs.Length);
+ fs.Close();
+ data = buffur;
+ return true;
+ }
+ catch (Exception ex)
+ {
+ data = null;
+ return false;
+ }
+ }
+ }
+
+ public static string[] GetDirFile(string Path)
+ {
+ return Directory.GetFiles(Path);
+ }
+
+ public static byte[] String2Byte(string value)
+ {
+ return Encoding.Default.GetBytes(value);
+ }
+ public static bool SaveFile(string FilePath, byte[] buffer)
+ {
+ try
+ {
+ //创建一个文件流
+ using (FileStream wfs = new FileStream(FilePath, FileMode.Create))
+ {
+ //将byte数组写入文件中
+ wfs.Write(buffer, 0, buffer.Length);
+ //所有流类型都要关闭流,否则会出现内存泄露问题
+ wfs.Close();
+ return true;
+ }
+ }
+ catch
+ {
+ return false;
+ }
+ }
+ }
+}
diff --git a/HexHelper.cs b/HexHelper.cs
new file mode 100644
index 0000000..9a8754e
--- /dev/null
+++ b/HexHelper.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MHFQuestToMH2Dos
+{
+ public class HexHelper
+ {
+ ///
+ /// 另一种16进制转10进制的处理方式,Multiplier参与*16的循环很巧妙,对Multiplier的处理很推荐,逻辑统一
+ ///
+ ///
+ ///
+ public static int HexaToDecimal(string HexaDecimalString)
+ {
+ int Decimal = 0;
+ int Multiplier = 1;
+
+ for (int i = HexaDecimalString.Length - 1; i >= 0; i--)
+ {
+ Decimal += HexaToDecimal(HexaDecimalString[i]) * Multiplier;
+ Multiplier *= 16;
+ }
+ return Decimal;
+ }
+
+ static int HexaToDecimal(char c)
+ {
+ switch (c)
+ {
+ case '0':
+ return 0;
+ case '1':
+ return 1;
+ case '2':
+ return 2;
+ case '3':
+ return 3;
+ case '4':
+ return 4;
+ case '5':
+ return 5;
+ case '6':
+ return 6;
+ case '7':
+ return 7;
+ case '8':
+ return 8;
+ case '9':
+ return 9;
+ case 'A':
+ case 'a':
+ return 10;
+ case 'B':
+ case 'b':
+ return 11;
+ case 'C':
+ case 'c':
+ return 12;
+ case 'D':
+ case 'd':
+ return 13;
+ case 'E':
+ case 'e':
+ return 14;
+ case 'F':
+ case 'f':
+ return 15;
+ }
+ return -1;
+ }
+ }
+}
diff --git a/MHFQuestToMH2Dos.csproj b/MHFQuestToMH2Dos.csproj
new file mode 100644
index 0000000..f02677b
--- /dev/null
+++ b/MHFQuestToMH2Dos.csproj
@@ -0,0 +1,10 @@
+
+
+
+ Exe
+ net7.0
+ enable
+ enable
+
+
+
diff --git a/MHFQuestToMH2Dos.sln b/MHFQuestToMH2Dos.sln
new file mode 100644
index 0000000..bcd4fb0
--- /dev/null
+++ b/MHFQuestToMH2Dos.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.4.33403.182
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MHFQuestToMH2Dos", "MHFQuestToMH2Dos.csproj", "{EE88C3AA-67C2-47C8-8326-AA4537A31F74}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {EE88C3AA-67C2-47C8-8326-AA4537A31F74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EE88C3AA-67C2-47C8-8326-AA4537A31F74}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EE88C3AA-67C2-47C8-8326-AA4537A31F74}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EE88C3AA-67C2-47C8-8326-AA4537A31F74}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {78C4E67B-A482-4AE4-BD41-93A15B6FF133}
+ EndGlobalSection
+EndGlobal
diff --git a/ModifyQuest.cs b/ModifyQuest.cs
new file mode 100644
index 0000000..684bc5b
--- /dev/null
+++ b/ModifyQuest.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MHFQuestToMH2Dos
+{
+ public static class ModifyQuest
+ {
+ ///
+ /// Dos中无意义数据
+ ///
+ const int fixindex_1 = 19;
+
+ const int Offset = 12;
+ const int Offset_2nd = 8;
+
+ const int moveLenght = 64;
+
+ public static bool ModifyFile(byte[] src,out byte[] target)
+ {
+ try
+ {
+ target = new byte[src.Length];
+
+ for (int i = 0; i < src.Length; i++)
+ {
+ target[i] = src[i];
+ }
+
+ //清除无意义数据
+ 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");
+ }
+
+ long PtrIndex = HexHelper.HexaToDecimal(IntPtrHex);
+
+ long MoveStarPtr = PtrIndex + Offset;
+
+ 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[targetStarPtr + i] = temp[i];
+ }
+
+ return true;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex);
+ target = null;
+ return false;
+ }
+ }
+ }
+}
diff --git a/Program.cs b/Program.cs
new file mode 100644
index 0000000..cada1cb
--- /dev/null
+++ b/Program.cs
@@ -0,0 +1,49 @@
+namespace MHFQuestToMH2Dos
+{
+ internal class Program
+ {
+ static string loc = Path.GetDirectoryName(AppContext.BaseDirectory) + "\\";
+
+ const string InDir = "Input";
+ const string OutDir = "Out";
+
+ static void Main(string[] args)
+ {
+ if (!Directory.Exists(loc + InDir))
+ {
+ Console.WriteLine("Input文件不存在");
+ Console.ReadLine();
+ return;
+ }
+
+ if (!Directory.Exists(loc + OutDir))
+ {
+ Console.WriteLine("Out文件不存在");
+ Console.ReadLine();
+ return;
+ }
+
+ string[] files = FileHelper.GetDirFile(loc + InDir);
+
+ int index= 0;
+ for(int i = 0;i < files.Length;i++)
+ {
+ string FileName = files[0].Substring(files[0].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}");
+ }
+
+ Console.WriteLine($"需处理{files.Length}个文件");
+ Console.ReadLine();
+ }
+ }
+}
\ No newline at end of file