修正hexhelper,加载任务目的地

This commit is contained in:
sin365 2023-03-24 18:21:24 +08:00
parent b737122a64
commit a85fa6fcb4
15 changed files with 129 additions and 40 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http.Headers;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -8,6 +9,46 @@ namespace MHFQuestToMH2Dos
{ {
public class HexHelper 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];
}
/// <summary> /// <summary>
/// 另一种16进制转10进制的处理方式Multiplier参与*16的循环很巧妙对Multiplier的处理很推荐逻辑统一 /// 另一种16进制转10进制的处理方式Multiplier参与*16的循环很巧妙对Multiplier的处理很推荐逻辑统一
/// </summary> /// </summary>

View File

@ -11,68 +11,116 @@ namespace MHFQuestToMH2Dos
/// <summary> /// <summary>
/// Dos中无意义数据 /// Dos中无意义数据
/// </summary> /// </summary>
const int fixindex_1 = 19; const int cNon0x00For2DosPtr = 19;
/// <summary>
/// MHF任务信息偏移
/// </summary>
const int cQuestMHFOffset = 12;
/// <summary>
/// 2Dos任务信息偏移
/// </summary>
const int cQuest2DosOffset = 8;
/// <summary>
/// 任务信息长度
/// </summary>
const int cQuestInfoLenght = 64;
/// <summary>
/// 任务_类型 偏移
/// </summary>
const int cQuestInfo_Type_Offset = 0;
/// <summary>
/// 任务_类型 长度
/// </summary>
const int cQuestInfo_Type_Lenght = 1;
/// <summary>
/// 任务_类型 偏移
/// </summary>
const int cQuestInfo_TargetMap_Offset = 32;
/// <summary>
/// 任务_类型 长度
/// </summary>
const int cQuestInfo_TargetMapID_Lenght = 1;
const int Offset = 12; public static bool ModifyQuset(byte[] src, out byte[] target)
const int Offset_2nd = 8; {
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 try
{ {
//加载数据
target = new byte[src.Length]; target = new byte[src.Length];
for (int i = 0; i < src.Length; i++) for (int i = 0; i < src.Length; i++)
{
target[i] = src[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字节取出指针 定位任务信息位置 //从前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的位置 //MHF偏移12的位置
long MoveStarPtr = PtrIndex + Offset; long QuestInfoPtr_MHFTarget = _QuestInfoPtr + cQuestMHFOffset;
//目标2Dos偏移8的位置 //目标2Dos偏移8的位置
long targetStarPtr = PtrIndex + Offset_2nd; long QuestInfoPtr_2DosTarget = _QuestInfoPtr + cQuest2DosOffset;
//取出原始数据 //取出原始数据
byte[] temp = new byte[moveLenght]; byte[] temp = new byte[cQuestInfoLenght];
for (int i = 0; i < moveLenght; i++) 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字节 //将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; return true;
} }
catch (Exception ex) catch (Exception ex)

View File

@ -36,7 +36,7 @@
} }
index++; index++;
FileHelper.LoadFile(files[i], out byte[] data); 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 newfileName = FileName + "_fix";
string outstring = loc + OutDir + "\\" + newfileName; string outstring = loc + OutDir + "\\" + newfileName;