Heightmap/XML conversion

This commit is contained in:
dexy
2021-04-18 00:30:32 +10:00
Unverified
parent ac14e716d8
commit ab4a34cc53
6 changed files with 468 additions and 3 deletions
+43 -3
View File
@@ -308,19 +308,21 @@ namespace CodeWalker
InitFileType(".awc", "Audio Wave Container", 22, FileTypeAction.ViewAwc, true);
InitFileType(".rel", "Audio Data (REL)", 23, FileTypeAction.ViewRel, true);
InitSubFileType(".dat", "cache_y.dat", "Cache File", 6, FileTypeAction.ViewCacheDat);
InitSubFileType(".dat", "cache_y.dat", "Cache File", 6, FileTypeAction.ViewCacheDat, true);
InitSubFileType(".dat", "heightmap.dat", "Heightmap", 6, FileTypeAction.ViewHeightmap, true);
InitSubFileType(".dat", "heightmapheistisland.dat", "Heightmap", 6, FileTypeAction.ViewHeightmap, true);
}
private void InitFileType(string ext, string name, int imgidx, FileTypeAction defaultAction = FileTypeAction.ViewHex, bool xmlConvertible = false)
{
var ft = new FileTypeInfo(ext, name, imgidx, defaultAction, xmlConvertible);
FileTypes[ext] = ft;
}
private void InitSubFileType(string ext, string subext, string name, int imgidx, FileTypeAction defaultAction = FileTypeAction.ViewHex)
private void InitSubFileType(string ext, string subext, string name, int imgidx, FileTypeAction defaultAction = FileTypeAction.ViewHex, bool xmlConvertible = false)
{
FileTypeInfo pti = null;
if (FileTypes.TryGetValue(ext, out pti))
{
var ft = new FileTypeInfo(subext, name, imgidx, defaultAction, pti.XmlConvertible);
var ft = new FileTypeInfo(subext, name, imgidx, defaultAction, xmlConvertible);
pti.AddSubType(ft);
}
}
@@ -1398,6 +1400,7 @@ namespace CodeWalker
case FileTypeAction.ViewYed:
case FileTypeAction.ViewYld:
case FileTypeAction.ViewYfd:
case FileTypeAction.ViewHeightmap:
return true;
case FileTypeAction.ViewHex:
default:
@@ -1524,6 +1527,9 @@ namespace CodeWalker
case FileTypeAction.ViewYfd:
ViewYfd(name, path, data, fe);
break;
case FileTypeAction.ViewHeightmap:
ViewHeightmap(name, path, data, fe);
break;
case FileTypeAction.ViewHex:
default:
ViewHex(name, path, data);
@@ -1758,6 +1764,13 @@ namespace CodeWalker
f.Show();
f.LoadMeta(cachedat);
}
private void ViewHeightmap(string name, string path, byte[] data, RpfFileEntry e)
{
var heightmap = RpfFile.GetFile<HeightmapFile>(e, data);
MetaForm f = new MetaForm(this);
f.Show();
f.LoadMeta(heightmap);
}
private RpfFileEntry CreateFileEntry(string name, string path, ref byte[] data)
{
@@ -2643,6 +2656,14 @@ namespace CodeWalker
{
mformat = MetaFormat.Awc;
}
if (fnamel.EndsWith("cache_y.dat.xml"))
{
mformat = MetaFormat.CacheFile;
}
if (fnamel.EndsWith(".dat.xml") && fnamel.StartsWith("heightmap"))
{
mformat = MetaFormat.Heightmap;
}
fname = fname.Substring(0, fname.Length - trimlength);
fnamel = fnamel.Substring(0, fnamel.Length - trimlength);
@@ -2825,6 +2846,24 @@ namespace CodeWalker
data = awc.Save();
break;
}
case MetaFormat.CacheFile:
{
var cdf = new CacheDatFile();
//cdf.LoadXml() //TODO!!!
MessageBox.Show(fname + ": CacheFile XML import still TODO!!!", "Cannot import CacheFile XML");
break;
}
case MetaFormat.Heightmap:
{
var hmf = XmlHmap.GetHeightmap(doc);
if (hmf.MaxHeights == null)
{
MessageBox.Show(fname + ": Schema not supported.", "Cannot import Heightmap XML");
continue;
}
data = hmf.Save();
break;
}
}
@@ -4653,6 +4692,7 @@ namespace CodeWalker
ViewYed = 20,
ViewYld = 21,
ViewYfd = 22,
ViewHeightmap = 23,
}
+23
View File
@@ -332,6 +332,20 @@ namespace CodeWalker.Forms
metaFormat = MetaFormat.CacheFile;
}
}
public void LoadMeta(HeightmapFile heightmap)
{
var fn = ((heightmap?.RpfFileEntry?.Name) ?? "") + ".xml";
Xml = HmapXml.GetXml(heightmap);
FileName = fn;
RawPropertyGrid.SelectedObject = heightmap;
rpfFileEntry = heightmap?.RpfFileEntry;
modified = false;
metaFormat = MetaFormat.XML;
if (heightmap?.RpfFileEntry != null)
{
metaFormat = MetaFormat.Heightmap;
}
}
@@ -393,6 +407,15 @@ namespace CodeWalker.Forms
case MetaFormat.CacheFile:
MessageBox.Show("Sorry, CacheFile import is not supported.", "Cannot import CacheFile XML");
return false;
case MetaFormat.Heightmap:
var hmap = XmlHmap.GetHeightmap(doc);
if (hmap.MaxHeights == null)
{
MessageBox.Show("Schema not supported.", "Cannot import Heightmap XML");
return false;
}
data = hmap.Save();
break;
}
}
#if !DEBUG