MRF/XML conversion

This commit is contained in:
alexguirre 2022-08-24 12:39:23 +02:00
parent f0567d315b
commit ddf689ae81
6 changed files with 1621 additions and 203 deletions

File diff suppressed because it is too large Load Diff

View File

@ -4543,6 +4543,39 @@ namespace CodeWalker.GameFiles
}
else
{ }
var xml = MrfXml.GetXml(mrffile);
var mrf2 = XmlMrf.GetMrf(xml);
var ndata2 = mrf2.Save();
if (ndata2.Length == odata.Length)
{
for (int i = 0; i < ndata2.Length; i++)
{
if (ndata2[i] != odata[i] && !mrfDiffCanBeIgnored(i, mrffile))
{ break; }
}
}
else
{ }
bool mrfDiffCanBeIgnored(int fileOffset, MrfFile originalMrf)
{
foreach (var n in originalMrf.AllNodes)
{
if (n is MrfNodeStateBase state)
{
// If TransitionCount is 0, the TransitionsOffset value can be ignored.
// TransitionsOffset in original MRFs isn't always set to 0 in this case,
// XML-imported MRFs always set it to 0
if (state.TransitionCount == 0 && fileOffset == (state.FileOffset + 0x1C))
{
return true;
}
}
}
return false;
}
}
else
{ }

View File

@ -147,6 +147,11 @@ namespace CodeWalker.GameFiles
HeightmapFile hmf = RpfFile.GetFile<HeightmapFile>(e, data);
return GetXml(hmf, out filename, outputfolder);
}
else if (fnl.EndsWith(".mrf"))
{
MrfFile mrf = RpfFile.GetFile<MrfFile>(e, data);
return GetXml(mrf, out filename, outputfolder);
}
filename = fn;
return string.Empty;
}
@ -314,6 +319,12 @@ namespace CodeWalker.GameFiles
filename = fn + ".xml";
return HmapXml.GetXml(hmf);
}
public static string GetXml(MrfFile mrf, out string filename, string outputfolder)
{
var fn = (mrf?.Name) ?? "";
filename = fn + ".xml";
return MrfXml.GetXml(mrf);
}
@ -2231,6 +2242,7 @@ namespace CodeWalker.GameFiles
Fxc = 20,
Heightmap = 21,
Ypdb = 22,
Mrf = 23,
}
}

View File

@ -59,6 +59,8 @@ namespace CodeWalker.GameFiles
return GetHeightmapData(doc);
case MetaFormat.Ypdb:
return GetYpdbData(doc);
case MetaFormat.Mrf:
return GetMrfData(doc);
}
return null;
}
@ -194,6 +196,12 @@ namespace CodeWalker.GameFiles
if (ypdb.WeightSet == null) return null;
return ypdb.Save();
}
public static byte[] GetMrfData(XmlDocument doc)
{
var mrf = XmlMrf.GetMrf(doc);
if (mrf == null) return null;
return mrf.Save();
}
public static string GetXMLFormatName(MetaFormat mformat)
@ -222,6 +230,7 @@ namespace CodeWalker.GameFiles
case MetaFormat.CacheFile: return "CacheFile XML";
case MetaFormat.Heightmap: return "Heightmap XML";
case MetaFormat.Ypdb: return "YPDB XML";
case MetaFormat.Mrf: return "MRF XML";
default: return "XML";
}
}
@ -320,6 +329,10 @@ namespace CodeWalker.GameFiles
{
mformat = MetaFormat.Ypdb;
}
if (fnamel.EndsWith(".mrf.xml"))
{
mformat = MetaFormat.Mrf;
}
return mformat;
}

View File

@ -298,7 +298,7 @@ namespace CodeWalker
InitFileType(".png", "Portable Network Graphics", 16);
InitFileType(".dds", "DirectDraw Surface", 16);
InitFileType(".ytd", "Texture Dictionary", 16, FileTypeAction.ViewYtd, true);
InitFileType(".mrf", "Move Network File", 18, FileTypeAction.ViewMrf);
InitFileType(".mrf", "Move Network File", 18, FileTypeAction.ViewMrf, true);
InitFileType(".ycd", "Clip Dictionary", 18, FileTypeAction.ViewYcd, true);
InitFileType(".ypt", "Particle Effect", 18, FileTypeAction.ViewModel, true);
InitFileType(".ybn", "Static Collisions", 19, FileTypeAction.ViewModel, true);
@ -1793,9 +1793,9 @@ namespace CodeWalker
private void ViewMrf(string name, string path, byte[] data, RpfFileEntry e)
{
var mrf = RpfFile.GetFile<MrfFile>(e, data);
GenericForm f = new GenericForm(this);
MetaForm f = new MetaForm(this);
f.Show();
f.LoadFile(mrf, mrf.RpfFileEntry);
f.LoadMeta(mrf);
}
private void ViewNametable(string name, string path, byte[] data, RpfFileEntry e)
{

View File

@ -388,6 +388,20 @@ namespace CodeWalker.Forms
metaFormat = MetaFormat.Ypdb;
}
}
public void LoadMeta(MrfFile mrf)
{
var fn = ((mrf?.RpfFileEntry?.Name) ?? "") + ".xml";
Xml = MrfXml.GetXml(mrf);
FileName = fn;
RawPropertyGrid.SelectedObject = mrf;
rpfFileEntry = mrf?.RpfFileEntry;
modified = false;
metaFormat = MetaFormat.XML;
if (mrf?.RpfFileEntry != null)
{
metaFormat = MetaFormat.Mrf;
}
}