Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion CodeWalker/ExploreForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CodeWalker.Properties;
using CodeWalker.Tools;
using CodeWalker.World;
using SharpDX.DirectWrite;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down Expand Up @@ -2350,6 +2351,42 @@ private void ViewSelectedHex()
}
}
}

private void ExportYmapModels(MainListItem ymapItem, string exportPath)
{
byte[] data = ymapItem.File.File.ExtractFile(ymapItem.File);
YmapFile ymap = RpfFile.GetFile<YmapFile>(ymapItem.File, data);

HashSet<YmapEntityDef> uniqueEntities = new HashSet<YmapEntityDef>();

foreach (YmapEntityDef entity in ymap.AllEntities)
{
uniqueEntities.Add(entity);
}

foreach (YmapEntityDef entity in uniqueEntities)
{
uint hash = JenkHash.GenHash(entity.Name);

YdrFile ydr = GetFileCache().GetYdr(hash);
if (ydr != null)
{
GetFileCache().LoadFile(ydr);
File.WriteAllBytes(Path.Combine(exportPath, ydr.Name), ydr.Save());
continue;
}

YftFile yft = GetFileCache().GetYft(hash);
if (yft != null)
{
GetFileCache().LoadFile(yft);
File.WriteAllBytes(Path.Combine(exportPath, yft.Name), yft.Save());
continue;
}
// Find a way to retreive YDDs from a ymap entity
}
}

private void ExportXml()
{
var needfolder = false;//need a folder to output ytd XML to, for the texture .dds files
Expand All @@ -2365,6 +2402,24 @@ private void ExportXml()
}
}


bool hasYmap = false;
foreach (MainListItem file in CurrentFiles)
{
if (file.Name.EndsWith(".ymap")) { hasYmap = true; break; }
}

bool exportModels = false;
if (hasYmap)
{
var result = MessageBox.Show(
".ymap files found, do you want to export the used models?",
"Export Ymap Models",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
exportModels = (result == DialogResult.Yes);
}

if ((MainListView.SelectedIndices.Count == 1) && (!needfolder))
{
var errorAction = new Action<string>((msg) => MessageBox.Show(msg));
Expand All @@ -2375,7 +2430,7 @@ private void ExportXml()
if (file.Folder == null)
{
var xml = GetFileXml(file, out var newfn, null, errorAction);

if (string.IsNullOrEmpty(xml) == false)
{
SaveFileDialog.FileName = newfn;
Expand All @@ -2385,6 +2440,12 @@ private void ExportXml()
try
{
File.WriteAllText(path, xml);
if (file.Name.EndsWith(".ymap") && exportModels)
{
var modelsFolder = Path.Combine(Path.GetDirectoryName(path), file.Name + "_models");
Directory.CreateDirectory(modelsFolder);
ExportYmapModels(file, modelsFolder);
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -2416,6 +2477,12 @@ private void ExportXml()
try
{
File.WriteAllText(path, xml);
if (file.Name.EndsWith(".ymap") && exportModels)
{
var modelsFolder = Path.Combine(Path.GetDirectoryName(path), file.Name + "_models");
Directory.CreateDirectory(modelsFolder);
ExportYmapModels(file, modelsFolder);
}
}
catch (Exception ex)
{
Expand Down