This commit is contained in:
sin365 2023-03-23 18:32:30 +08:00
commit c34789da45
13 changed files with 296 additions and 0 deletions

Binary file not shown.

Binary file not shown.

60
FileHelper.cs Normal file
View File

@ -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;
}
}
}
}

75
HexHelper.cs Normal file
View File

@ -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
{
/// <summary>
/// 另一种16进制转10进制的处理方式Multiplier参与*16的循环很巧妙对Multiplier的处理很推荐逻辑统一
/// </summary>
/// <param name="HexaDecimalString"></param>
/// <returns></returns>
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;
}
}
}

10
MHFQuestToMH2Dos.csproj Normal file
View File

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

25
MHFQuestToMH2Dos.sln Normal file
View File

@ -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

77
ModifyQuest.cs Normal file
View File

@ -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
{
/// <summary>
/// Dos中无意义数据
/// </summary>
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;
}
}
}
}

49
Program.cs Normal file
View File

@ -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();
}
}
}