解决任务昼夜mode问题

This commit is contained in:
sin365 2023-04-06 08:55:15 +08:00
parent 15a8da3216
commit fa3a08da0f
16 changed files with 170 additions and 58 deletions

Binary file not shown.

View File

@ -162,14 +162,6 @@ namespace MHFQuestToMH2Dos
for (int i = 0; i < targetVal.Length && i < targetVal.Length; i++) for (int i = 0; i < targetVal.Length && i < targetVal.Length; i++)
temp[i] = srcdata[startoffset + i]; temp[i] = srcdata[startoffset + i];
if (!Array.Equals(targetVal, temp))
{
for (int i = 0; i < targetVal.Length; i++)
{
Console.WriteLine($"{(targetVal[i] != temp[i] ? "" : "")} target{targetVal[i]} src{temp[i]}");
}
}
return Array.Equals(targetVal, temp); return Array.Equals(targetVal, temp);
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -46,22 +47,22 @@ namespace MHFQuestToMH2Dos
//从前4字节取出指针 定位任务信息位置 //从前4字节取出指针 定位任务信息位置
int _QuestInfoPtr = HexHelper.bytesToInt(target, 4, 0x00); int _QuestInfoPtr = HexHelper.bytesToInt(target, 4, 0x00);
Log.HexTips(0x00, "开始读取任务头部信息,指针->{0}", _QuestInfoPtr); //Log.HexTips(0x00, "开始读取任务头部信息,指针->{0}", _QuestInfoPtr);
//任务目的地MapID //任务目的地MapID
_QuestTargetMapID = HexHelper.bytesToInt(target, ModifyQuest.cQuestInfo_TargetMapID_Lenght, _QuestInfoPtr + ModifyQuest.cQuestInfo_TargetMap_Offset); _QuestTargetMapID = HexHelper.bytesToInt(target, ModifyQuest.cQuestInfo_TargetMapID_Lenght, _QuestInfoPtr + ModifyQuest.cQuestInfo_TargetMap_Offset);
Log.HexColor(ConsoleColor.Green, _QuestInfoPtr + ModifyQuest.cQuestInfo_TargetMap_Offset, "目的地地图,指针->{0} 【" + MHHelper.Get2MapName(_QuestTargetMapID) + "】", _QuestTargetMapID); //Log.HexColor(ConsoleColor.Green, _QuestInfoPtr + ModifyQuest.cQuestInfo_TargetMap_Offset, "目的地地图,指针->{0} 【" + MHHelper.Get2MapName(_QuestTargetMapID) + "】", _QuestTargetMapID);
//区域数量 //区域数量
int _AreaCount = MHHelper.GetMapAreaCount(_QuestTargetMapID); int _AreaCount = MHHelper.GetMapAreaCount(_QuestTargetMapID);
Log.Info(MHHelper.Get2MapName(_QuestTargetMapID) + "的地图数量" + _AreaCount); //Log.Info(MHHelper.Get2MapName(_QuestTargetMapID) + "的地图数量" + _AreaCount);
mapAreaData = new MapAreaData(_AreaCount); mapAreaData = new MapAreaData(_AreaCount);
#region #region
//换区设置指针 //换区设置指针
int _CAreaSetTopPtr = HexHelper.bytesToInt(target, 4, 0x1C); int _CAreaSetTopPtr = HexHelper.bytesToInt(target, 4, 0x1C);
Log.HexInfo(0x1C, "换区设置指针->{0}", _CAreaSetTopPtr); //Log.HexInfo(0x1C, "换区设置指针->{0}", _CAreaSetTopPtr);
//读取换区单个区域游标 //读取换区单个区域游标
int _CAreaSetTop_CurrPtr = _CAreaSetTopPtr; int _CAreaSetTop_CurrPtr = _CAreaSetTopPtr;
@ -72,7 +73,7 @@ namespace MHFQuestToMH2Dos
if (_One_CurrPtr == 0x0) if (_One_CurrPtr == 0x0)
{ {
Log.HexInfo(_CAreaSetTop_CurrPtr, "区域设置"+i+"指针为0跳过"); //Log.HexInfo(_CAreaSetTop_CurrPtr, "区域设置"+i+"指针为0跳过");
break; break;
} }
@ -84,11 +85,11 @@ namespace MHFQuestToMH2Dos
|| ||
HexHelper.bytesToInt(target, 1, _One_CurrPtr) == 0) HexHelper.bytesToInt(target, 1, _One_CurrPtr) == 0)
{ {
Log.HexInfo(_One_CurrPtr, "区域设置结束符"); //Log.HexInfo(_One_CurrPtr, "区域设置结束符");
break; break;
} }
Log.HexInfo(_CAreaSetTop_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标,换区设置指针->{0}", _One_CurrPtr); //Log.HexInfo(_CAreaSetTop_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标,换区设置指针->{0}", _One_CurrPtr);
Log.HexTips(_One_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标,读取数据,长度{0}", 0x34); //Log.HexTips(_One_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标,读取数据,长度{0}", 0x34);
datas.Add(HexHelper.ReadBytes(target, 0x34, _One_CurrPtr)); datas.Add(HexHelper.ReadBytes(target, 0x34, _One_CurrPtr));
Set_TargetIndex++; Set_TargetIndex++;
_One_CurrPtr += 0x34; _One_CurrPtr += 0x34;
@ -102,12 +103,12 @@ namespace MHFQuestToMH2Dos
#region #region
//区域映射指针 //区域映射指针
int _CAreaPosTopPtr = HexHelper.bytesToInt(target, 4, 0x20); int _CAreaPosTopPtr = HexHelper.bytesToInt(target, 4, 0x20);
Log.HexInfo(0x20, "换区映射指针->{0}", _CAreaPosTopPtr); //Log.HexInfo(0x20, "换区映射指针->{0}", _CAreaPosTopPtr);
//读取单个区域映射游标 //读取单个区域映射游标
int _CAreaPosTop_CurrPtr = _CAreaPosTopPtr; int _CAreaPosTop_CurrPtr = _CAreaPosTopPtr;
for (int i = 0; i < _AreaCount; i++) for (int i = 0; i < _AreaCount; i++)
{ {
Log.HexTips(_CAreaPosTop_CurrPtr, "第" + i + "区的区域映射,读取数据,长度{0}", 0x20); //Log.HexTips(_CAreaPosTop_CurrPtr, "第" + i + "区的区域映射,读取数据,长度{0}", 0x20);
mapAreaData.areaPosDatas.Add(HexHelper.ReadBytes(target, 0x20, _CAreaPosTop_CurrPtr)); mapAreaData.areaPosDatas.Add(HexHelper.ReadBytes(target, 0x20, _CAreaPosTop_CurrPtr));
_CAreaPosTop_CurrPtr += 0x20; _CAreaPosTop_CurrPtr += 0x20;
} }
@ -128,8 +129,35 @@ namespace MHFQuestToMH2Dos
File.Delete(DictMapIDFullFileName[_QuestTargetMapID]); File.Delete(DictMapIDFullFileName[_QuestTargetMapID]);
} }
DictMapIDFullFileName[_QuestTargetMapID] = FullFileName; DictMapIDFullFileName[_QuestTargetMapID] = FullFileName;
Log.HexColor(ConsoleColor.Green, _QuestTargetMapID, "成功,缓存地图 编号{0}" + MHHelper.Get2MapName(_QuestTargetMapID) + "的数据", _QuestTargetMapID); //Log.HexColor(ConsoleColor.Green, _QuestTargetMapID, "成功,缓存地图 编号{0}" + MHHelper.Get2MapName(_QuestTargetMapID) + "的数据", _QuestTargetMapID);
return true; return true;
} }
public static Dictionary<string, int> DictTimeTypeCount = new Dictionary<string, int>();
public static void GetModeType(byte[] src,string FileName)
{
try
{
byte[] target = HexHelper.CopyByteArr(src);//加载数据
//从前4字节取出指针 定位任务信息位置
int _QuestInfoPtr = HexHelper.bytesToInt(target, 4, 0x00);
int _TimeType = HexHelper.bytesToInt(target, 1, _QuestInfoPtr + 2);
string key = FileName.Substring(FileName.Length - 1 - 5) + "_" + "(0x" + _TimeType.ToString("X") + ")";
if(!DictTimeTypeCount.ContainsKey(key))
{
DictTimeTypeCount[key] = 0;
}
DictTimeTypeCount[key]++;
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
} }
} }

View File

@ -54,33 +54,93 @@ namespace MHFQuestToMH2Dos
return "未定义"; return "未定义";
} }
public static bool CheckIsXunLianMode(int mode)
{
return XunLianMode.Contains(mode);
}
public static bool CheckIsDayMode(int mode)
{
return DayMode.Contains(mode);
}
public static bool CheckIsNightMode(int mode)
{
return NightMode.Contains(mode);
}
static List<int> NightMode = new List<int>() { 0x11,0x12,0x14};
static List<int> XunLianMode = new List<int>() { 0x3F, 0xBF};
static List<int> DayMode = new List<int>() { 0x19,0x1A,0x1C,0x9,0xA,0xC};
public static bool CheckIsDayMapID(int mapid)
{
return Dict2DosMap_Day.ContainsKey(mapid);
}
public static bool CheckIsNightMapID(int mapid)
{
return Dict2DosMap_Night.ContainsKey(mapid);
}
static Dictionary<int, string> Dict2DosMap_Day = new Dictionary<int, string>()
{
{0x1,"砦(昼)"},
{0x2,"森丘(昼)"},
{0x3,"砂漠(昼)"},
{0x4,"沼地(昼)"},
{0x5,"火山(昼)"},
{0x6,"密林(昼)"},
{0x9,"大闘技場(昼)"},
{0xA,"闘技場(昼)"},
{0xB,"雪山(昼)"},
{0xC,"戦闘街(昼)"},
};
static Dictionary<int, string> Dict2DosMap_Night = new Dictionary<int, string>()
{
{0x10,"森丘(夜)"},
{0x11,"砂漠(夜)"},
{0x12,"沼地(夜)"},
{0x13,"火山(夜)"},
{0x14,"密林(夜)"},
{0x15,"雪山(夜)"},
{0x16,"戦闘街(夜)"},
{0x17,"砦(夜)"},
{0x18,"大闘技場(夜)"},
{0x19,"闘技場(夜)"},
};
static Dictionary<int, string> Dict2DosMap = new Dictionary<int, string>() static Dictionary<int, string> Dict2DosMap = new Dictionary<int, string>()
{ {
{0x1,"砦"}, {0x1,"砦(昼)"},
{0x2,"森丘"}, {0x2,"森丘(昼)"},
{0x3,"砂漠"}, {0x3,"砂漠(昼)"},
{0x4,"沼地"}, {0x4,"沼地(昼)"},
{0x5,"火山"}, {0x5,"火山(昼)"},
{0x6,"密林"}, {0x6,"密林(昼)"},
{0x7,"城"}, {0x7,"修雷特城"},
{0x8,"決戦場紅"}, {0x8,"决战场"},
{0x9,"大闘技場"}, {0x9,"大闘技場(昼)"},
{0xA,"闘技場"}, {0xA,"闘技場(昼)"},
{0xB,"雪山"}, {0xB,"雪山(昼)"},
{0xC,"戦闘街"}, {0xC,"戦闘街(昼)"},
{0xD,"塔A"}, {0xD,"塔A"},
{0xE,"塔B"}, {0xE,"塔B"},
{0xF,"塔C"}, {0xF,"塔C"},
{0x10,"森丘"}, {0x10,"森丘(夜)"},
{0x11,"砂漠"}, {0x11,"砂漠(夜)"},
{0x12,"沼地"}, {0x12,"沼地(夜)"},
{0x13,"火山"}, {0x13,"火山(夜)"},
{0x14,"密林"}, {0x14,"密林(夜)"},
{0x15,"雪山"}, {0x15,"雪山(夜)"},
{0x16,"戦闘街"}, {0x16,"戦闘街(夜)"},
{0x17,"砦"}, {0x17,"砦(夜)"},
{0x18,"大闘技場"}, {0x18,"大闘技場(夜)"},
{0x19,"闘技場"}, {0x19,"闘技場(夜)"},
}; };
static Dictionary<int, string> Dict2DosBoss = new Dictionary<int, string>() static Dictionary<int, string> Dict2DosBoss = new Dictionary<int, string>()
{ {

View File

@ -181,7 +181,6 @@ namespace MHFQuestToMH2Dos
} }
} }
/// <summary> /// <summary>
/// 迁移任务信息 /// 迁移任务信息
/// </summary> /// </summary>
@ -374,6 +373,8 @@ namespace MHFQuestToMH2Dos
int _QuestType = HexHelper.bytesToInt(target, cQuestInfo_Type_Lenght, _QuestInfoPtr + cQuestInfo_Type_Offset); int _QuestType = HexHelper.bytesToInt(target, cQuestInfo_Type_Lenght, _QuestInfoPtr + cQuestInfo_Type_Offset);
Log.HexInfo(_QuestInfoPtr + cQuestInfo_Type_Offset, "任务类型->{0}", _QuestType); Log.HexInfo(_QuestInfoPtr + cQuestInfo_Type_Offset, "任务类型->{0}", _QuestType);
//任务星 //任务星
//int _QuestStart = HexHelper.bytesToInt(target, cQuestInfo_Star_Lenght, _QuestInfoPtr + cQuestInfo_Star_Offset); //int _QuestStart = HexHelper.bytesToInt(target, cQuestInfo_Star_Lenght, _QuestInfoPtr + cQuestInfo_Star_Offset);
//if (_QuestStart > cMax_QuestStar) //if (_QuestStart > cMax_QuestStar)
@ -410,6 +411,36 @@ namespace MHFQuestToMH2Dos
Log.HexColor(ConsoleColor.Green, _QuestInfoPtr + cQuestInfo_TargetMap_Offset, "目的地地图,指针->{0} 【"+MHHelper.Get2MapName(_QuestTargetMapID)+ "】", _QuestTargetMapID); Log.HexColor(ConsoleColor.Green, _QuestInfoPtr + cQuestInfo_TargetMap_Offset, "目的地地图,指针->{0} 【"+MHHelper.Get2MapName(_QuestTargetMapID)+ "】", _QuestTargetMapID);
} }
int _ModeType = HexHelper.bytesToInt(target, 1, _QuestInfoPtr + 2);
//非训练任务
if (!MHHelper.CheckIsXunLianMode(_ModeType))
{
Log.HexTips(_QuestInfoPtr + 2, "任务模式->原始数据{0}", _ModeType);
//如果是昼地图 但不是昼模式
if (MHHelper.CheckIsDayMapID(_QuestTargetMapID)
&&
!MHHelper.CheckIsDayMode(_ModeType)
)
{
HexHelper.ModifyIntHexToBytes(target, 0x1C, _QuestInfoPtr + 2, 1);
Log.HexWar(_QuestInfoPtr + 2, "任务模式->修改白天 为{0}", 0x1C);
}
//如果是夜地图 但不是夜模式
else if (MHHelper.CheckIsNightMapID(_QuestTargetMapID)
&&
!MHHelper.CheckIsNightMode(_ModeType)
)
{
HexHelper.ModifyIntHexToBytes(target, 0x12, _QuestInfoPtr + 2, 1);
Log.HexWar(_QuestInfoPtr + 2, "任务模式->修改黑夜 为{0}", 0x12);
}
}
else
{
Log.HexTips(_QuestInfoPtr + 2, "任务模式 原始数据 是训练模式 ->{0}", _ModeType);
}
uint _QuestID = HexHelper.bytesToUInt(target, cQuestInfo_QuestID_Lenght, _QuestInfoPtr + cQuestInfo_QuestID_Offset); uint _QuestID = HexHelper.bytesToUInt(target, cQuestInfo_QuestID_Lenght, _QuestInfoPtr + cQuestInfo_QuestID_Offset);
Log.HexTips(_QuestInfoPtr + cQuestInfo_QuestID_Offset, "任务编号【{0}】", _QuestID); Log.HexTips(_QuestInfoPtr + cQuestInfo_QuestID_Offset, "任务编号【{0}】", _QuestID);
if (_QuestID < 60000) if (_QuestID < 60000)
@ -610,8 +641,6 @@ namespace MHFQuestToMH2Dos
} }
} }
public static bool FixMapAreaData(byte[] src,out byte[] target) public static bool FixMapAreaData(byte[] src,out byte[] target)
{ {
int _QuestTargetMapID; int _QuestTargetMapID;
@ -670,7 +699,7 @@ namespace MHFQuestToMH2Dos
break; break;
} }
if (srcData2Dos.targetDatas.Length <= i) if (srcData2Dos.targetDatas[i].targetData.Count <= Set_TargetIndex)
{ {
Log.HexWar(_One_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标,比2Dos目标数超限。"); Log.HexWar(_One_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标,比2Dos目标数超限。");
break; break;
@ -678,11 +707,6 @@ namespace MHFQuestToMH2Dos
byte[] srcOneData = srcData2Dos.targetDatas[i].targetData[Set_TargetIndex]; byte[] srcOneData = srcData2Dos.targetDatas[i].targetData[Set_TargetIndex];
if (!HexHelper.CheckDataEquals(target, srcOneData, _One_CurrPtr))
{
Log.HexWar(_One_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标数据和2Dos差异长度{0}", srcOneData.Length);
}
HexHelper.ModifyDataToBytes(target, srcOneData, _One_CurrPtr); HexHelper.ModifyDataToBytes(target, srcOneData, _One_CurrPtr);
Log.HexTips(_One_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标更换为2Dos数据长度{0}", srcOneData.Length); Log.HexTips(_One_CurrPtr, "第" + i + "区,第" + Set_TargetIndex + "个目标更换为2Dos数据长度{0}", srcOneData.Length);
@ -709,11 +733,6 @@ namespace MHFQuestToMH2Dos
} }
byte[] srcOneData = srcData2Dos.areaPosDatas[i]; byte[] srcOneData = srcData2Dos.areaPosDatas[i];
if (!HexHelper.CheckDataEquals(target, srcOneData, _CAreaPosTop_CurrPtr))
{
Log.HexWar(_CAreaPosTop_CurrPtr, "第" + i + "区的区域映射数据和2Dos差异读取数据,长度{0}", srcOneData.Length);
}
HexHelper.ModifyDataToBytes(target, srcOneData, _CAreaPosTop_CurrPtr); HexHelper.ModifyDataToBytes(target, srcOneData, _CAreaPosTop_CurrPtr);
Log.HexTips(_CAreaPosTop_CurrPtr, "第" + i + "区的区域映射更换为2Dos数据读取数据,长度{0}", srcOneData.Length); Log.HexTips(_CAreaPosTop_CurrPtr, "第" + i + "区的区域映射更换为2Dos数据读取数据,长度{0}", srcOneData.Length);
_CAreaPosTop_CurrPtr += 0x20; _CAreaPosTop_CurrPtr += 0x20;

View File

@ -17,6 +17,7 @@ namespace MHFQuestToMH2Dos
Console.Title = title; Console.Title = title;
Console.WriteLine(title); Console.WriteLine(title);
if (!Directory.Exists(loc + InDir)) if (!Directory.Exists(loc + InDir))
{ {
Console.WriteLine("Input文件不存在"); Console.WriteLine("Input文件不存在");
@ -53,16 +54,16 @@ namespace MHFQuestToMH2Dos
} }
index_temp++; index_temp++;
Console.WriteLine($">>>>>>>>>>>>>>读取 第{index_temp}个模板文件 {FileName}<<<<<<<<<<<<<<<<<<<"); //Console.WriteLine($">>>>>>>>>>>>>>读取 第{index_temp}个模板文件 {FileName}<<<<<<<<<<<<<<<<<<<");
FileHelper.LoadFile(tempfiles[i], out byte[] data); FileHelper.LoadFile(tempfiles[i], out byte[] data);
if (LoadToSaveTemplate.LoadMapTemplateAreaData(data, FileName, tempfiles[i])) if (LoadToSaveTemplate.LoadMapTemplateAreaData(data, FileName, tempfiles[i]))
{ {
Console.WriteLine($">>>>>>>>>>>>>>成功读取 第{index_temp}个,"+ FileName); //Console.WriteLine($">>>>>>>>>>>>>>成功读取 第{index_temp}个,"+ FileName);
} }
else else
{ {
errcount_temp++; errcount_temp++;
Console.WriteLine($">>>>>>>>>>>>>>成功失败 第{index_temp}个"); //Console.WriteLine($">>>>>>>>>>>>>>成功失败 第{index_temp}个");
} }
} }
@ -93,6 +94,9 @@ namespace MHFQuestToMH2Dos
{ {
string newfileName = FileName + "_fix"; string newfileName = FileName + "_fix";
string outstring = loc + OutDir + "\\" + newfileName; string outstring = loc + OutDir + "\\" + newfileName;
//LoadToSaveTemplate.GetModeType(targetdata, FileName);
FileHelper.SaveFile(outstring, targetdata); FileHelper.SaveFile(outstring, targetdata);
Console.WriteLine($">>>>>>>>>>>>>>成功处理 第{index}个:{outstring}"); Console.WriteLine($">>>>>>>>>>>>>>成功处理 第{index}个:{outstring}");
} }
@ -104,6 +108,15 @@ namespace MHFQuestToMH2Dos
} }
Console.WriteLine($"已处理{files.Length}个文件,其中{errcount}个失败"); Console.WriteLine($"已处理{files.Length}个文件,其中{errcount}个失败");
string[] tempkeys = LoadToSaveTemplate.DictTimeTypeCount.Keys.OrderBy(w => w).ToArray();
foreach (var r in tempkeys)
{
Console.WriteLine(r + ":" + LoadToSaveTemplate.DictTimeTypeCount[r]);
}
Console.ReadLine(); Console.ReadLine();
} }
} }