Allow opening ydr,ydd,yft,ytd files in project window

This commit is contained in:
dexy 2022-01-10 04:03:57 +11:00
parent edabc852a9
commit eb12b5ddcd
9 changed files with 1168 additions and 41 deletions

View File

@ -23,6 +23,14 @@ namespace CodeWalker.GameFiles
{ {
} }
public void Load(byte[] data)
{
//direct load from a raw, compressed ydd file
RpfFile.LoadResourceFile(this, data, 165);
Loaded = true;
}
public void Load(byte[] data, RpfFileEntry entry) public void Load(byte[] data, RpfFileEntry entry)
{ {
Name = entry.Name; Name = entry.Name;

View File

@ -19,6 +19,14 @@ namespace CodeWalker.GameFiles
{ {
} }
public void Load(byte[] data)
{
//direct load from a raw, compressed ydr file
RpfFile.LoadResourceFile(this, data, 165);
Loaded = true;
}
public void Load(byte[] data, RpfFileEntry entry) public void Load(byte[] data, RpfFileEntry entry)
{ {
Name = entry.Name; Name = entry.Name;

View File

@ -21,6 +21,14 @@ namespace CodeWalker.GameFiles
{ {
} }
public void Load(byte[] data)
{
//direct load from a raw, compressed yft file
RpfFile.LoadResourceFile(this, data, 162);
Loaded = true;
}
public void Load(byte[] data, RpfFileEntry entry) public void Load(byte[] data, RpfFileEntry entry)
{ {
Name = entry.Name; Name = entry.Name;

View File

@ -23,6 +23,14 @@ namespace CodeWalker.GameFiles
} }
public void Load(byte[] data)
{
//direct load from a raw, compressed ytd file
RpfFile.LoadResourceFile(this, data, 13);
Loaded = true;
}
public void Load(byte[] data, RpfFileEntry entry) public void Load(byte[] data, RpfFileEntry entry)
{ {
Name = entry.Name; Name = entry.Name;

View File

@ -35,6 +35,8 @@ namespace CodeWalker.GameFiles
private object textureSyncRoot = new object(); //for the texture lookup. private object textureSyncRoot = new object(); //for the texture lookup.
private Dictionary<GameFileCacheKey, GameFile> projectFiles = new Dictionary<GameFileCacheKey, GameFile>(); //for cache files loaded in project window: ydr,ydd,ytd,yft
private Dictionary<uint, Archetype> projectArchetypes = new Dictionary<uint, Archetype>(); //used to override archetypes in world view with project ones
@ -1890,6 +1892,69 @@ namespace CodeWalker.GameFiles
public void AddProjectFile(GameFile f)
{
if (f == null) return;
if (f.RpfFileEntry == null) return;
if (f.RpfFileEntry.ShortNameHash == 0)
{
f.RpfFileEntry.ShortNameHash = JenkHash.GenHash(f.RpfFileEntry.GetShortNameLower());
}
var key = new GameFileCacheKey(f.RpfFileEntry.ShortNameHash, f.Type);
lock (requestSyncRoot)
{
projectFiles[key] = f;
}
}
public void RemoveProjectFile(GameFile f)
{
if (f == null) return;
if (f.RpfFileEntry == null) return;
if (f.RpfFileEntry.ShortNameHash == 0) return;
var key = new GameFileCacheKey(f.RpfFileEntry.ShortNameHash, f.Type);
lock (requestSyncRoot)
{
projectFiles.Remove(key);
}
}
public void ClearProjectFiles()
{
lock (requestSyncRoot)
{
projectFiles.Clear();
}
}
public void AddProjectArchetype(Archetype a)
{
if ((a?.Hash ?? 0) == 0) return;
lock (requestSyncRoot)
{
projectArchetypes[a.Hash] = a;
}
}
public void RemoveProjectArchetype(Archetype a)
{
if ((a?.Hash ?? 0) == 0) return;
Archetype tarch = null;
lock (requestSyncRoot)
{
projectArchetypes.TryGetValue(a.Hash, out tarch);
if (tarch == a)
{
projectArchetypes.Remove(a.Hash);
}
}
}
public void ClearProjectArchetypes()
{
lock (requestSyncRoot)
{
projectArchetypes.Clear();
}
}
public void TryLoadEnqueue(GameFile gf) public void TryLoadEnqueue(GameFile gf)
{ {
if (((!gf.Loaded)) && (requestQueue.Count < 10))// && (!gf.LoadQueued) if (((!gf.Loaded)) && (requestQueue.Count < 10))// && (!gf.LoadQueued)
@ -1904,6 +1969,8 @@ namespace CodeWalker.GameFiles
{ {
if (!archetypesLoaded) return null; if (!archetypesLoaded) return null;
Archetype arch = null; Archetype arch = null;
projectArchetypes.TryGetValue(hash, out arch);
if (arch != null) return arch;
archetypeDict.TryGetValue(hash, out arch); archetypeDict.TryGetValue(hash, out arch);
return arch; return arch;
} }
@ -1921,6 +1988,10 @@ namespace CodeWalker.GameFiles
lock (requestSyncRoot) lock (requestSyncRoot)
{ {
var key = new GameFileCacheKey(hash, GameFileType.Ydr); var key = new GameFileCacheKey(hash, GameFileType.Ydr);
if (projectFiles.TryGetValue(key, out GameFile pgf))
{
return pgf as YdrFile;
}
YdrFile ydr = mainCache.TryGet(key) as YdrFile; YdrFile ydr = mainCache.TryGet(key) as YdrFile;
if (ydr == null) if (ydr == null)
{ {
@ -1956,6 +2027,10 @@ namespace CodeWalker.GameFiles
lock (requestSyncRoot) lock (requestSyncRoot)
{ {
var key = new GameFileCacheKey(hash, GameFileType.Ydd); var key = new GameFileCacheKey(hash, GameFileType.Ydd);
if (projectFiles.TryGetValue(key, out GameFile pgf))
{
return pgf as YddFile;
}
YddFile ydd = mainCache.TryGet(key) as YddFile; YddFile ydd = mainCache.TryGet(key) as YddFile;
if (ydd == null) if (ydd == null)
{ {
@ -1991,6 +2066,10 @@ namespace CodeWalker.GameFiles
lock (requestSyncRoot) lock (requestSyncRoot)
{ {
var key = new GameFileCacheKey(hash, GameFileType.Ytd); var key = new GameFileCacheKey(hash, GameFileType.Ytd);
if (projectFiles.TryGetValue(key, out GameFile pgf))
{
return pgf as YtdFile;
}
YtdFile ytd = mainCache.TryGet(key) as YtdFile; YtdFile ytd = mainCache.TryGet(key) as YtdFile;
if (ytd == null) if (ytd == null)
{ {
@ -2062,6 +2141,10 @@ namespace CodeWalker.GameFiles
{ {
var key = new GameFileCacheKey(hash, GameFileType.Yft); var key = new GameFileCacheKey(hash, GameFileType.Yft);
YftFile yft = mainCache.TryGet(key) as YftFile; YftFile yft = mainCache.TryGet(key) as YftFile;
if (projectFiles.TryGetValue(key, out GameFile pgf))
{
return pgf as YftFile;
}
if (yft == null) if (yft == null)
{ {
var e = GetYftEntry(hash); var e = GetYftEntry(hash);

View File

@ -216,6 +216,90 @@ namespace CodeWalker.Project.Panels
audiorelsnode.Expand(); audiorelsnode.Expand();
} }
if (CurrentProjectFile.YdrFiles.Count > 0)
{
var ydrsnode = projnode.Nodes.Add("Ydr Files");
ydrsnode.Name = "Ydr";
foreach (var ydrfile in CurrentProjectFile.YdrFiles)
{
var ycstr = "";// ydrfile.HasChanged ? "*" : "";
string name = ydrfile.Name;
if (ydrfile.RpfFileEntry != null)
{
name = ydrfile.RpfFileEntry.Name;
}
var ydrnode = ydrsnode.Nodes.Add(ycstr + name);
ydrnode.Tag = ydrfile;
//LoadYdrTreeNodes(ydrfile, ydrnode);
}
ydrsnode.Expand();
}
if (CurrentProjectFile.YddFiles.Count > 0)
{
var yddsnode = projnode.Nodes.Add("Ydd Files");
yddsnode.Name = "Ydd";
foreach (var yddfile in CurrentProjectFile.YddFiles)
{
var ycstr = "";// yddfile.HasChanged ? "*" : "";
string name = yddfile.Name;
if (yddfile.RpfFileEntry != null)
{
name = yddfile.RpfFileEntry.Name;
}
var yddnode = yddsnode.Nodes.Add(ycstr + name);
yddnode.Tag = yddfile;
//LoadYddTreeNodes(yddfile, yddnode);
}
yddsnode.Expand();
}
if (CurrentProjectFile.YftFiles.Count > 0)
{
var yftsnode = projnode.Nodes.Add("Yft Files");
yftsnode.Name = "Yft";
foreach (var yftfile in CurrentProjectFile.YftFiles)
{
var ycstr = "";// yftfile.HasChanged ? "*" : "";
string name = yftfile.Name;
if (yftfile.RpfFileEntry != null)
{
name = yftfile.RpfFileEntry.Name;
}
var yftnode = yftsnode.Nodes.Add(ycstr + name);
yftnode.Tag = yftfile;
//LoadYftTreeNodes(yftfile, yftnode);
}
yftsnode.Expand();
}
if (CurrentProjectFile.YtdFiles.Count > 0)
{
var ytdsnode = projnode.Nodes.Add("Ytd Files");
ytdsnode.Name = "Ytd";
foreach (var ytdfile in CurrentProjectFile.YtdFiles)
{
var ycstr = "";// ytdfile.HasChanged ? "*" : "";
string name = ytdfile.Name;
if (ytdfile.RpfFileEntry != null)
{
name = ytdfile.RpfFileEntry.Name;
}
var ytdnode = ytdsnode.Nodes.Add(ycstr + name);
ytdnode.Tag = ytdfile;
//LoadYtdTreeNodes(ytdfile, ytdnode);
}
ytdsnode.Expand();
}
projnode.Expand(); projnode.Expand();
} }

View File

@ -23,6 +23,10 @@ namespace CodeWalker.Project
public List<string> TrainsFilenames { get; set; } = new List<string>(); public List<string> TrainsFilenames { get; set; } = new List<string>();
public List<string> ScenarioFilenames { get; set; } = new List<string>(); public List<string> ScenarioFilenames { get; set; } = new List<string>();
public List<string> AudioRelFilenames { get; set; } = new List<string>(); public List<string> AudioRelFilenames { get; set; } = new List<string>();
public List<string> YdrFilenames { get; set; } = new List<string>();
public List<string> YddFilenames { get; set; } = new List<string>();
public List<string> YftFilenames { get; set; } = new List<string>();
public List<string> YtdFilenames { get; set; } = new List<string>();
//fields not stored //fields not stored
public string Filename { get; set; } //filename without path public string Filename { get; set; } //filename without path
@ -37,6 +41,10 @@ namespace CodeWalker.Project
public List<TrainTrack> TrainsFiles { get; set; } = new List<TrainTrack>(); public List<TrainTrack> TrainsFiles { get; set; } = new List<TrainTrack>();
public List<YmtFile> ScenarioFiles { get; set; } = new List<YmtFile>(); public List<YmtFile> ScenarioFiles { get; set; } = new List<YmtFile>();
public List<RelFile> AudioRelFiles { get; set; } = new List<RelFile>(); public List<RelFile> AudioRelFiles { get; set; } = new List<RelFile>();
public List<YdrFile> YdrFiles { get; set; } = new List<YdrFile>();
public List<YddFile> YddFiles { get; set; } = new List<YddFile>();
public List<YftFile> YftFiles { get; set; } = new List<YftFile>();
public List<YtdFile> YtdFiles { get; set; } = new List<YtdFile>();
@ -97,6 +105,30 @@ namespace CodeWalker.Project
Xml.AddChildWithInnerText(doc, audiorelselem, "Item", audiorelfilename); Xml.AddChildWithInnerText(doc, audiorelselem, "Item", audiorelfilename);
} }
var ydrselem = Xml.AddChild(doc, projelem, "YdrFilenames");
foreach (string ydrfilename in YdrFilenames)
{
Xml.AddChildWithInnerText(doc, ydrselem, "Item", ydrfilename);
}
var yddselem = Xml.AddChild(doc, projelem, "YddFilenames");
foreach (string yddfilename in YddFilenames)
{
Xml.AddChildWithInnerText(doc, yddselem, "Item", yddfilename);
}
var yftselem = Xml.AddChild(doc, projelem, "YftFilenames");
foreach (string yftfilename in YftFilenames)
{
Xml.AddChildWithInnerText(doc, yftselem, "Item", yftfilename);
}
var ytdselem = Xml.AddChild(doc, projelem, "YtdFilenames");
foreach (string ytdfilename in YtdFilenames)
{
Xml.AddChildWithInnerText(doc, ytdselem, "Item", ytdfilename);
}
doc.Save(Filepath); doc.Save(Filepath);
} }
@ -244,6 +276,70 @@ namespace CodeWalker.Project
} }
} }
YdrFilenames.Clear();
YdrFiles.Clear();
var ydrselem = Xml.GetChild(projelem, "YdrFilenames");
if (ydrselem != null)
{
foreach (var node in ydrselem.SelectNodes("Item"))
{
XmlElement ydrel = node as XmlElement;
if (ydrel != null)
{
AddYdrFile(ydrel.InnerText);
}
}
}
YddFilenames.Clear();
YddFiles.Clear();
var yddselem = Xml.GetChild(projelem, "YddFilenames");
if (yddselem != null)
{
foreach (var node in yddselem.SelectNodes("Item"))
{
XmlElement yddel = node as XmlElement;
if (yddel != null)
{
AddYddFile(yddel.InnerText);
}
}
}
YftFilenames.Clear();
YftFiles.Clear();
var yftselem = Xml.GetChild(projelem, "YftFilenames");
if (yftselem != null)
{
foreach (var node in yftselem.SelectNodes("Item"))
{
XmlElement yftel = node as XmlElement;
if (yftel != null)
{
AddYftFile(yftel.InnerText);
}
}
}
YtdFilenames.Clear();
YtdFiles.Clear();
var ytdselem = Xml.GetChild(projelem, "YtdFilenames");
if (ytdselem != null)
{
foreach (var node in ytdselem.SelectNodes("Item"))
{
XmlElement ytdel = node as XmlElement;
if (ytdel != null)
{
AddYtdFile(ytdel.InnerText);
}
}
}
} }
@ -281,6 +377,22 @@ namespace CodeWalker.Project
{ {
AudioRelFilenames[i] = GetUpdatedFilePath(AudioRelFilenames[i], oldprojpath); AudioRelFilenames[i] = GetUpdatedFilePath(AudioRelFilenames[i], oldprojpath);
} }
for (int i = 0; i < YdrFilenames.Count; i++)
{
YdrFilenames[i] = GetUpdatedFilePath(YdrFilenames[i], oldprojpath);
}
for (int i = 0; i < YddFilenames.Count; i++)
{
YddFilenames[i] = GetUpdatedFilePath(YddFilenames[i], oldprojpath);
}
for (int i = 0; i < YftFilenames.Count; i++)
{
YftFilenames[i] = GetUpdatedFilePath(YftFilenames[i], oldprojpath);
}
for (int i = 0; i < YtdFilenames.Count; i++)
{
YtdFilenames[i] = GetUpdatedFilePath(YtdFilenames[i], oldprojpath);
}
} }
public string GetUpdatedFilePath(string oldpath, string oldprojpath) public string GetUpdatedFilePath(string oldpath, string oldprojpath)
@ -888,5 +1000,272 @@ namespace CodeWalker.Project
} }
public YdrFile AddYdrFile(string filename)
{
YdrFile ydr = new YdrFile();
ydr.RpfFileEntry = new RpfResourceFileEntry();
ydr.RpfFileEntry.Name = Path.GetFileName(filename);
ydr.FilePath = GetFullFilePath(filename);
ydr.Name = ydr.RpfFileEntry.Name;
if (!AddYdrFile(ydr)) return null;
return ydr;
}
public bool AddYdrFile(YdrFile ydr)
{
string relpath = GetRelativePath(ydr.FilePath);
if (string.IsNullOrEmpty(relpath)) relpath = ydr.Name;
if (YdrFilenames.Contains(relpath)) return false;
YdrFilenames.Add(relpath);
YdrFiles.Add(ydr);
return true;
}
public void RemoveYdrFile(YdrFile ydr)
{
if (ydr == null) return;
var relpath = GetRelativePath(ydr.FilePath);
if (string.IsNullOrEmpty(relpath)) relpath = ydr.Name;
YdrFiles.Remove(ydr);
YdrFilenames.Remove(relpath);
HasChanged = true;
}
public bool ContainsYdr(string filename)
{
bool found = false;
filename = filename.ToLowerInvariant();
foreach (var ydrfn in YdrFilenames)
{
if (ydrfn == filename)
{
found = true;
break;
}
}
return found;
}
public bool ContainsYdr(YdrFile ydr)
{
foreach (var f in YdrFiles)
{
if (f == ydr) return true;
}
return false;
}
public bool RenameYdr(string oldfilename, string newfilename)
{
oldfilename = oldfilename.ToLowerInvariant();
newfilename = newfilename.ToLowerInvariant();
for (int i = 0; i < YdrFilenames.Count; i++)
{
if (YdrFilenames[i]?.ToLowerInvariant() == oldfilename)
{
YdrFilenames[i] = newfilename;
HasChanged = true;
return true;
}
}
return false;
}
public YddFile AddYddFile(string filename)
{
YddFile ydd = new YddFile();
ydd.RpfFileEntry = new RpfResourceFileEntry();
ydd.RpfFileEntry.Name = Path.GetFileName(filename);
ydd.FilePath = GetFullFilePath(filename);
ydd.Name = ydd.RpfFileEntry.Name;
if (!AddYddFile(ydd)) return null;
return ydd;
}
public bool AddYddFile(YddFile ydd)
{
string relpath = GetRelativePath(ydd.FilePath);
if (string.IsNullOrEmpty(relpath)) relpath = ydd.Name;
if (YddFilenames.Contains(relpath)) return false;
YddFilenames.Add(relpath);
YddFiles.Add(ydd);
return true;
}
public void RemoveYddFile(YddFile ydd)
{
if (ydd == null) return;
var relpath = GetRelativePath(ydd.FilePath);
if (string.IsNullOrEmpty(relpath)) relpath = ydd.Name;
YddFiles.Remove(ydd);
YddFilenames.Remove(relpath);
HasChanged = true;
}
public bool ContainsYdd(string filename)
{
bool found = false;
filename = filename.ToLowerInvariant();
foreach (var yddfn in YddFilenames)
{
if (yddfn == filename)
{
found = true;
break;
}
}
return found;
}
public bool ContainsYdd(YddFile ydd)
{
foreach (var f in YddFiles)
{
if (f == ydd) return true;
}
return false;
}
public bool RenameYdd(string oldfilename, string newfilename)
{
oldfilename = oldfilename.ToLowerInvariant();
newfilename = newfilename.ToLowerInvariant();
for (int i = 0; i < YddFilenames.Count; i++)
{
if (YddFilenames[i]?.ToLowerInvariant() == oldfilename)
{
YddFilenames[i] = newfilename;
HasChanged = true;
return true;
}
}
return false;
}
public YftFile AddYftFile(string filename)
{
YftFile yft = new YftFile();
yft.RpfFileEntry = new RpfResourceFileEntry();
yft.RpfFileEntry.Name = Path.GetFileName(filename);
yft.FilePath = GetFullFilePath(filename);
yft.Name = yft.RpfFileEntry.Name;
if (!AddYftFile(yft)) return null;
return yft;
}
public bool AddYftFile(YftFile yft)
{
string relpath = GetRelativePath(yft.FilePath);
if (string.IsNullOrEmpty(relpath)) relpath = yft.Name;
if (YftFilenames.Contains(relpath)) return false;
YftFilenames.Add(relpath);
YftFiles.Add(yft);
return true;
}
public void RemoveYftFile(YftFile yft)
{
if (yft == null) return;
var relpath = GetRelativePath(yft.FilePath);
if (string.IsNullOrEmpty(relpath)) relpath = yft.Name;
YftFiles.Remove(yft);
YftFilenames.Remove(relpath);
HasChanged = true;
}
public bool ContainsYft(string filename)
{
bool found = false;
filename = filename.ToLowerInvariant();
foreach (var yftfn in YftFilenames)
{
if (yftfn == filename)
{
found = true;
break;
}
}
return found;
}
public bool ContainsYft(YftFile yft)
{
foreach (var f in YftFiles)
{
if (f == yft) return true;
}
return false;
}
public bool RenameYft(string oldfilename, string newfilename)
{
oldfilename = oldfilename.ToLowerInvariant();
newfilename = newfilename.ToLowerInvariant();
for (int i = 0; i < YftFilenames.Count; i++)
{
if (YftFilenames[i]?.ToLowerInvariant() == oldfilename)
{
YftFilenames[i] = newfilename;
HasChanged = true;
return true;
}
}
return false;
}
public YtdFile AddYtdFile(string filename)
{
YtdFile ytd = new YtdFile();
ytd.RpfFileEntry = new RpfResourceFileEntry();
ytd.RpfFileEntry.Name = Path.GetFileName(filename);
ytd.FilePath = GetFullFilePath(filename);
ytd.Name = ytd.RpfFileEntry.Name;
if (!AddYtdFile(ytd)) return null;
return ytd;
}
public bool AddYtdFile(YtdFile ytd)
{
string relpath = GetRelativePath(ytd.FilePath);
if (string.IsNullOrEmpty(relpath)) relpath = ytd.Name;
if (YtdFilenames.Contains(relpath)) return false;
YtdFilenames.Add(relpath);
YtdFiles.Add(ytd);
return true;
}
public void RemoveYtdFile(YtdFile ytd)
{
if (ytd == null) return;
var relpath = GetRelativePath(ytd.FilePath);
if (string.IsNullOrEmpty(relpath)) relpath = ytd.Name;
YtdFiles.Remove(ytd);
YtdFilenames.Remove(relpath);
HasChanged = true;
}
public bool ContainsYtd(string filename)
{
bool found = false;
filename = filename.ToLowerInvariant();
foreach (var ytdfn in YtdFilenames)
{
if (ytdfn == filename)
{
found = true;
break;
}
}
return found;
}
public bool ContainsYtd(YtdFile ytd)
{
foreach (var f in YtdFiles)
{
if (f == ytd) return true;
}
return false;
}
public bool RenameYtd(string oldfilename, string newfilename)
{
oldfilename = oldfilename.ToLowerInvariant();
newfilename = newfilename.ToLowerInvariant();
for (int i = 0; i < YtdFilenames.Count; i++)
{
if (YtdFilenames[i]?.ToLowerInvariant() == oldfilename)
{
YtdFilenames[i] = newfilename;
HasChanged = true;
return true;
}
}
return false;
}
} }
} }

View File

@ -195,6 +195,22 @@
this.ToolbarSaveAllButton = new System.Windows.Forms.ToolStripButton(); this.ToolbarSaveAllButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
this.FolderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); this.FolderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
this.YdrMenu = new System.Windows.Forms.ToolStripMenuItem();
this.YddMenu = new System.Windows.Forms.ToolStripMenuItem();
this.YftMenu = new System.Windows.Forms.ToolStripMenuItem();
this.YtdMenu = new System.Windows.Forms.ToolStripMenuItem();
this.YdrNameMenu = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
this.YddNameMenu = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator9 = new System.Windows.Forms.ToolStripSeparator();
this.YftNameMenu = new System.Windows.Forms.ToolStripMenuItem();
this.YtdNameMenu = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator29 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripSeparator30 = new System.Windows.Forms.ToolStripSeparator();
this.YdrRemoveFromProjectMenu = new System.Windows.Forms.ToolStripMenuItem();
this.YddRemoveFromProjectMenu = new System.Windows.Forms.ToolStripMenuItem();
this.YftRemoveFromProjectMenu = new System.Windows.Forms.ToolStripMenuItem();
this.YtdRemoveFromProjectMenu = new System.Windows.Forms.ToolStripMenuItem();
this.MainMenu.SuspendLayout(); this.MainMenu.SuspendLayout();
this.MainToolbar.SuspendLayout(); this.MainToolbar.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -208,6 +224,10 @@
this.YmapMenu, this.YmapMenu,
this.YtypMenu, this.YtypMenu,
this.YbnMenu, this.YbnMenu,
this.YdrMenu,
this.YddMenu,
this.YftMenu,
this.YtdMenu,
this.YndMenu, this.YndMenu,
this.YnvMenu, this.YnvMenu,
this.TrainsMenu, this.TrainsMenu,
@ -253,7 +273,7 @@
this.FileNewScenarioMenu, this.FileNewScenarioMenu,
this.FileNewAudioDatMenu}); this.FileNewAudioDatMenu});
this.FileNewMenu.Name = "FileNewMenu"; this.FileNewMenu.Name = "FileNewMenu";
this.FileNewMenu.Size = new System.Drawing.Size(180, 22); this.FileNewMenu.Size = new System.Drawing.Size(163, 22);
this.FileNewMenu.Text = "New"; this.FileNewMenu.Text = "New";
// //
// FileNewProjectMenu // FileNewProjectMenu
@ -327,47 +347,47 @@
// FileOpenProjectMenu // FileOpenProjectMenu
// //
this.FileOpenProjectMenu.Name = "FileOpenProjectMenu"; this.FileOpenProjectMenu.Name = "FileOpenProjectMenu";
this.FileOpenProjectMenu.Size = new System.Drawing.Size(180, 22); this.FileOpenProjectMenu.Size = new System.Drawing.Size(163, 22);
this.FileOpenProjectMenu.Text = "Open Project..."; this.FileOpenProjectMenu.Text = "Open Project...";
this.FileOpenProjectMenu.Click += new System.EventHandler(this.FileOpenProjectMenu_Click); this.FileOpenProjectMenu.Click += new System.EventHandler(this.FileOpenProjectMenu_Click);
// //
// FileOpenFilesMenu // FileOpenFilesMenu
// //
this.FileOpenFilesMenu.Name = "FileOpenFilesMenu"; this.FileOpenFilesMenu.Name = "FileOpenFilesMenu";
this.FileOpenFilesMenu.Size = new System.Drawing.Size(180, 22); this.FileOpenFilesMenu.Size = new System.Drawing.Size(163, 22);
this.FileOpenFilesMenu.Text = "Open Files..."; this.FileOpenFilesMenu.Text = "Open Files...";
this.FileOpenFilesMenu.Click += new System.EventHandler(this.FileOpenFilesMenu_Click); this.FileOpenFilesMenu.Click += new System.EventHandler(this.FileOpenFilesMenu_Click);
// //
// FileOpenFolderMenu // FileOpenFolderMenu
// //
this.FileOpenFolderMenu.Name = "FileOpenFolderMenu"; this.FileOpenFolderMenu.Name = "FileOpenFolderMenu";
this.FileOpenFolderMenu.Size = new System.Drawing.Size(180, 22); this.FileOpenFolderMenu.Size = new System.Drawing.Size(163, 22);
this.FileOpenFolderMenu.Text = "Open Folder..."; this.FileOpenFolderMenu.Text = "Open Folder...";
this.FileOpenFolderMenu.Click += new System.EventHandler(this.FileOpenFolderMenu_Click); this.FileOpenFolderMenu.Click += new System.EventHandler(this.FileOpenFolderMenu_Click);
// //
// toolStripSeparator3 // toolStripSeparator3
// //
this.toolStripSeparator3.Name = "toolStripSeparator3"; this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(177, 6); this.toolStripSeparator3.Size = new System.Drawing.Size(160, 6);
// //
// FileCloseProjectMenu // FileCloseProjectMenu
// //
this.FileCloseProjectMenu.Enabled = false; this.FileCloseProjectMenu.Enabled = false;
this.FileCloseProjectMenu.Name = "FileCloseProjectMenu"; this.FileCloseProjectMenu.Name = "FileCloseProjectMenu";
this.FileCloseProjectMenu.Size = new System.Drawing.Size(180, 22); this.FileCloseProjectMenu.Size = new System.Drawing.Size(163, 22);
this.FileCloseProjectMenu.Text = "Close Project"; this.FileCloseProjectMenu.Text = "Close Project";
this.FileCloseProjectMenu.Click += new System.EventHandler(this.FileCloseProjectMenu_Click); this.FileCloseProjectMenu.Click += new System.EventHandler(this.FileCloseProjectMenu_Click);
// //
// toolStripSeparator4 // toolStripSeparator4
// //
this.toolStripSeparator4.Name = "toolStripSeparator4"; this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(177, 6); this.toolStripSeparator4.Size = new System.Drawing.Size(160, 6);
// //
// FileSaveProjectMenu // FileSaveProjectMenu
// //
this.FileSaveProjectMenu.Enabled = false; this.FileSaveProjectMenu.Enabled = false;
this.FileSaveProjectMenu.Name = "FileSaveProjectMenu"; this.FileSaveProjectMenu.Name = "FileSaveProjectMenu";
this.FileSaveProjectMenu.Size = new System.Drawing.Size(180, 22); this.FileSaveProjectMenu.Size = new System.Drawing.Size(163, 22);
this.FileSaveProjectMenu.Text = "Save Project"; this.FileSaveProjectMenu.Text = "Save Project";
this.FileSaveProjectMenu.Click += new System.EventHandler(this.FileSaveProjectMenu_Click); this.FileSaveProjectMenu.Click += new System.EventHandler(this.FileSaveProjectMenu_Click);
// //
@ -375,7 +395,7 @@
// //
this.FileSaveProjectAsMenu.Enabled = false; this.FileSaveProjectAsMenu.Enabled = false;
this.FileSaveProjectAsMenu.Name = "FileSaveProjectAsMenu"; this.FileSaveProjectAsMenu.Name = "FileSaveProjectAsMenu";
this.FileSaveProjectAsMenu.Size = new System.Drawing.Size(180, 22); this.FileSaveProjectAsMenu.Size = new System.Drawing.Size(163, 22);
this.FileSaveProjectAsMenu.Text = "Save Project As..."; this.FileSaveProjectAsMenu.Text = "Save Project As...";
this.FileSaveProjectAsMenu.Click += new System.EventHandler(this.FileSaveProjectAsMenu_Click); this.FileSaveProjectAsMenu.Click += new System.EventHandler(this.FileSaveProjectAsMenu_Click);
// //
@ -383,7 +403,7 @@
// //
this.FileSaveItemMenu.Enabled = false; this.FileSaveItemMenu.Enabled = false;
this.FileSaveItemMenu.Name = "FileSaveItemMenu"; this.FileSaveItemMenu.Name = "FileSaveItemMenu";
this.FileSaveItemMenu.Size = new System.Drawing.Size(180, 22); this.FileSaveItemMenu.Size = new System.Drawing.Size(163, 22);
this.FileSaveItemMenu.Text = "Save Item"; this.FileSaveItemMenu.Text = "Save Item";
this.FileSaveItemMenu.Visible = false; this.FileSaveItemMenu.Visible = false;
this.FileSaveItemMenu.Click += new System.EventHandler(this.FileSaveItemMenu_Click); this.FileSaveItemMenu.Click += new System.EventHandler(this.FileSaveItemMenu_Click);
@ -392,7 +412,7 @@
// //
this.FileSaveItemAsMenu.Enabled = false; this.FileSaveItemAsMenu.Enabled = false;
this.FileSaveItemAsMenu.Name = "FileSaveItemAsMenu"; this.FileSaveItemAsMenu.Name = "FileSaveItemAsMenu";
this.FileSaveItemAsMenu.Size = new System.Drawing.Size(180, 22); this.FileSaveItemAsMenu.Size = new System.Drawing.Size(163, 22);
this.FileSaveItemAsMenu.Text = "Save Item As..."; this.FileSaveItemAsMenu.Text = "Save Item As...";
this.FileSaveItemAsMenu.Visible = false; this.FileSaveItemAsMenu.Visible = false;
this.FileSaveItemAsMenu.Click += new System.EventHandler(this.FileSaveItemAsMenu_Click); this.FileSaveItemAsMenu.Click += new System.EventHandler(this.FileSaveItemAsMenu_Click);
@ -1538,6 +1558,130 @@
this.toolStripSeparator5.Name = "toolStripSeparator5"; this.toolStripSeparator5.Name = "toolStripSeparator5";
this.toolStripSeparator5.Size = new System.Drawing.Size(6, 25); this.toolStripSeparator5.Size = new System.Drawing.Size(6, 25);
// //
// YdrMenu
//
this.YdrMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.YdrNameMenu,
this.toolStripSeparator6,
this.YdrRemoveFromProjectMenu});
this.YdrMenu.Name = "YdrMenu";
this.YdrMenu.Size = new System.Drawing.Size(36, 20);
this.YdrMenu.Text = "Ydr";
this.YdrMenu.Visible = false;
//
// YddMenu
//
this.YddMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.YddNameMenu,
this.toolStripSeparator9,
this.YddRemoveFromProjectMenu});
this.YddMenu.Name = "YddMenu";
this.YddMenu.Size = new System.Drawing.Size(39, 20);
this.YddMenu.Text = "Ydd";
this.YddMenu.Visible = false;
//
// YftMenu
//
this.YftMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.YftNameMenu,
this.toolStripSeparator30,
this.YftRemoveFromProjectMenu});
this.YftMenu.Name = "YftMenu";
this.YftMenu.Size = new System.Drawing.Size(34, 20);
this.YftMenu.Text = "Yft";
this.YftMenu.Visible = false;
//
// YtdMenu
//
this.YtdMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.YtdNameMenu,
this.toolStripSeparator29,
this.YtdRemoveFromProjectMenu});
this.YtdMenu.Name = "YtdMenu";
this.YtdMenu.Size = new System.Drawing.Size(37, 20);
this.YtdMenu.Text = "Ytd";
this.YtdMenu.Visible = false;
//
// YdrNameMenu
//
this.YdrNameMenu.Enabled = false;
this.YdrNameMenu.Name = "YdrNameMenu";
this.YdrNameMenu.Size = new System.Drawing.Size(186, 22);
this.YdrNameMenu.Text = "(No .ydr file selected)";
//
// toolStripSeparator6
//
this.toolStripSeparator6.Name = "toolStripSeparator6";
this.toolStripSeparator6.Size = new System.Drawing.Size(183, 6);
//
// YddNameMenu
//
this.YddNameMenu.Enabled = false;
this.YddNameMenu.Name = "YddNameMenu";
this.YddNameMenu.Size = new System.Drawing.Size(189, 22);
this.YddNameMenu.Text = "(No .ydd file selected)";
//
// toolStripSeparator9
//
this.toolStripSeparator9.Name = "toolStripSeparator9";
this.toolStripSeparator9.Size = new System.Drawing.Size(186, 6);
//
// YftNameMenu
//
this.YftNameMenu.Enabled = false;
this.YftNameMenu.Name = "YftNameMenu";
this.YftNameMenu.Size = new System.Drawing.Size(186, 22);
this.YftNameMenu.Text = "(No .yft file selected)";
//
// YtdNameMenu
//
this.YtdNameMenu.Enabled = false;
this.YtdNameMenu.Name = "YtdNameMenu";
this.YtdNameMenu.Size = new System.Drawing.Size(186, 22);
this.YtdNameMenu.Text = "(No .ytd file selected)";
//
// toolStripSeparator29
//
this.toolStripSeparator29.Name = "toolStripSeparator29";
this.toolStripSeparator29.Size = new System.Drawing.Size(183, 6);
//
// toolStripSeparator30
//
this.toolStripSeparator30.Name = "toolStripSeparator30";
this.toolStripSeparator30.Size = new System.Drawing.Size(183, 6);
//
// YdrRemoveFromProjectMenu
//
this.YdrRemoveFromProjectMenu.Enabled = false;
this.YdrRemoveFromProjectMenu.Name = "YdrRemoveFromProjectMenu";
this.YdrRemoveFromProjectMenu.Size = new System.Drawing.Size(186, 22);
this.YdrRemoveFromProjectMenu.Text = "Remove from Project";
this.YdrRemoveFromProjectMenu.Click += new System.EventHandler(this.YdrRemoveFromProjectMenu_Click);
//
// YddRemoveFromProjectMenu
//
this.YddRemoveFromProjectMenu.Enabled = false;
this.YddRemoveFromProjectMenu.Name = "YddRemoveFromProjectMenu";
this.YddRemoveFromProjectMenu.Size = new System.Drawing.Size(189, 22);
this.YddRemoveFromProjectMenu.Text = "Remove from Project";
this.YddRemoveFromProjectMenu.Click += new System.EventHandler(this.YddRemoveFromProjectMenu_Click);
//
// YftRemoveFromProjectMenu
//
this.YftRemoveFromProjectMenu.Enabled = false;
this.YftRemoveFromProjectMenu.Name = "YftRemoveFromProjectMenu";
this.YftRemoveFromProjectMenu.Size = new System.Drawing.Size(186, 22);
this.YftRemoveFromProjectMenu.Text = "Remove from Project";
this.YftRemoveFromProjectMenu.Click += new System.EventHandler(this.YftRemoveFromProjectMenu_Click);
//
// YtdRemoveFromProjectMenu
//
this.YtdRemoveFromProjectMenu.Enabled = false;
this.YtdRemoveFromProjectMenu.Name = "YtdRemoveFromProjectMenu";
this.YtdRemoveFromProjectMenu.Size = new System.Drawing.Size(186, 22);
this.YtdRemoveFromProjectMenu.Text = "Remove from Project";
this.YtdRemoveFromProjectMenu.Click += new System.EventHandler(this.YtdRemoveFromProjectMenu_Click);
//
// ProjectForm // ProjectForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -1729,5 +1873,21 @@
private System.Windows.Forms.FolderBrowserDialog FolderBrowserDialog; private System.Windows.Forms.FolderBrowserDialog FolderBrowserDialog;
private System.Windows.Forms.ToolStripMenuItem ToolbarOpenFilesMenu; private System.Windows.Forms.ToolStripMenuItem ToolbarOpenFilesMenu;
private System.Windows.Forms.ToolStripMenuItem ToolbarOpenFolderMenu; private System.Windows.Forms.ToolStripMenuItem ToolbarOpenFolderMenu;
private System.Windows.Forms.ToolStripMenuItem YdrMenu;
private System.Windows.Forms.ToolStripMenuItem YdrNameMenu;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator6;
private System.Windows.Forms.ToolStripMenuItem YdrRemoveFromProjectMenu;
private System.Windows.Forms.ToolStripMenuItem YddMenu;
private System.Windows.Forms.ToolStripMenuItem YddNameMenu;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator9;
private System.Windows.Forms.ToolStripMenuItem YddRemoveFromProjectMenu;
private System.Windows.Forms.ToolStripMenuItem YftMenu;
private System.Windows.Forms.ToolStripMenuItem YftNameMenu;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator30;
private System.Windows.Forms.ToolStripMenuItem YftRemoveFromProjectMenu;
private System.Windows.Forms.ToolStripMenuItem YtdMenu;
private System.Windows.Forms.ToolStripMenuItem YtdNameMenu;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator29;
private System.Windows.Forms.ToolStripMenuItem YtdRemoveFromProjectMenu;
} }
} }

View File

@ -84,6 +84,13 @@ namespace CodeWalker.Project
private BoundPolygon CurrentCollisionPoly; private BoundPolygon CurrentCollisionPoly;
private BoundVertex CurrentCollisionVertex; private BoundVertex CurrentCollisionVertex;
private YdrFile CurrentYdrFile;
private YddFile CurrentYddFile;
private YftFile CurrentYftFile;
private YtdFile CurrentYtdFile;
private bool renderitems = true; private bool renderitems = true;
private bool hidegtavmap = false; private bool hidegtavmap = false;
private bool autoymapflags = true; private bool autoymapflags = true;
@ -101,7 +108,6 @@ namespace CodeWalker.Project
private Dictionary<uint, YmapEntityDef> visiblemloentities = new Dictionary<uint, YmapEntityDef>(); private Dictionary<uint, YmapEntityDef> visiblemloentities = new Dictionary<uint, YmapEntityDef>();
private Dictionary<uint, RelFile> visibleaudiofiles = new Dictionary<uint, RelFile>(); private Dictionary<uint, RelFile> visibleaudiofiles = new Dictionary<uint, RelFile>();
private Dictionary<uint, Archetype> projectarchetypes = new Dictionary<uint, Archetype>();//used to override archetypes in world view
private Dictionary<uint, YbnFile> projectybns = new Dictionary<uint, YbnFile>();//used for handling interior ybns private Dictionary<uint, YbnFile> projectybns = new Dictionary<uint, YbnFile>();//used for handling interior ybns
private List<YmapEntityDef> interiorslist = new List<YmapEntityDef>(); //used for handling interiors ybns private List<YmapEntityDef> interiorslist = new List<YmapEntityDef>(); //used for handling interiors ybns
@ -127,7 +133,8 @@ namespace CodeWalker.Project
else else
{ {
GameFileCache = GameFileCacheFactory.Create(); GameFileCache = GameFileCacheFactory.Create();
new Thread(new ThreadStart(() => { new Thread(new ThreadStart(() =>
{
GTA5Keys.LoadFromPath(GTAFolder.CurrentGTAFolder, Settings.Default.Key); GTA5Keys.LoadFromPath(GTAFolder.CurrentGTAFolder, Settings.Default.Key);
GameFileCache.Init(UpdateStatus, UpdateError); GameFileCache.Init(UpdateStatus, UpdateError);
RpfMan = GameFileCache.RpfMan; RpfMan = GameFileCache.RpfMan;
@ -302,7 +309,7 @@ namespace CodeWalker.Project
PreviewPanel = panel; PreviewPanel = panel;
} }
} }
public void ShowPanel<T>(bool promote, Func<T> createFunc, Action<T> updateAction, Func<T,bool> findFunc) where T : ProjectPanel public void ShowPanel<T>(bool promote, Func<T> createFunc, Action<T> updateAction, Func<T, bool> findFunc) where T : ProjectPanel
{ {
T found = FindPanel(findFunc); T found = FindPanel(findFunc);
if ((found != null) && (found != PreviewPanel)) if ((found != null) && (found != PreviewPanel))
@ -850,6 +857,10 @@ namespace CodeWalker.Project
CurrentMloRoom = item as MCMloRoomDef; CurrentMloRoom = item as MCMloRoomDef;
CurrentMloPortal = item as MCMloPortalDef; CurrentMloPortal = item as MCMloPortalDef;
CurrentMloEntitySet = item as MCMloEntitySet; CurrentMloEntitySet = item as MCMloEntitySet;
CurrentYdrFile = item as YdrFile;
CurrentYddFile = item as YddFile;
CurrentYftFile = item as YftFile;
CurrentYtdFile = item as YtdFile;
if (CurrentAudioZone?.AudioZone == null) CurrentAudioZone = null; if (CurrentAudioZone?.AudioZone == null) CurrentAudioZone = null;
if (CurrentAudioEmitter?.AudioEmitter == null) CurrentAudioEmitter = null; if (CurrentAudioEmitter?.AudioEmitter == null) CurrentAudioEmitter = null;
@ -1010,7 +1021,7 @@ namespace CodeWalker.Project
} }
} }
private void ClosePanel<T>(Func<T,bool> findFunc) where T : ProjectPanel private void ClosePanel<T>(Func<T, bool> findFunc) where T : ProjectPanel
{ {
var panel = FindPanel(findFunc); var panel = FindPanel(findFunc);
if (PreviewPanel == panel) if (PreviewPanel == panel)
@ -1270,6 +1281,74 @@ namespace CodeWalker.Project
} }
} }
foreach (var ydr in CurrentProjectFile.YdrFiles)
{
string filename = ydr.FilePath;
if (!File.Exists(filename))
{
filename = cpath + "\\" + filename;
}
if (File.Exists(filename))
{
LoadYdrFromFile(ydr, filename);
}
else
{
MessageBox.Show("Couldn't find file: " + filename);
}
}
foreach (var ydd in CurrentProjectFile.YddFiles)
{
string filename = ydd.FilePath;
if (!File.Exists(filename))
{
filename = cpath + "\\" + filename;
}
if (File.Exists(filename))
{
LoadYddFromFile(ydd, filename);
}
else
{
MessageBox.Show("Couldn't find file: " + filename);
}
}
foreach (var yft in CurrentProjectFile.YftFiles)
{
string filename = yft.FilePath;
if (!File.Exists(filename))
{
filename = cpath + "\\" + filename;
}
if (File.Exists(filename))
{
LoadYftFromFile(yft, filename);
}
else
{
MessageBox.Show("Couldn't find file: " + filename);
}
}
foreach (var ytd in CurrentProjectFile.YtdFiles)
{
string filename = ytd.FilePath;
if (!File.Exists(filename))
{
filename = cpath + "\\" + filename;
}
if (File.Exists(filename))
{
LoadYtdFromFile(ytd, filename);
}
else
{
MessageBox.Show("Couldn't find file: " + filename);
}
}
LoadProjectUI(); LoadProjectUI();
} }
@ -1404,6 +1483,10 @@ namespace CodeWalker.Project
CurrentYnvFile = null; CurrentYnvFile = null;
CurrentTrainTrack = null; CurrentTrainTrack = null;
CurrentScenario = null; CurrentScenario = null;
CurrentYdrFile = null;
CurrentYddFile = null;
CurrentYftFile = null;
CurrentYtdFile = null;
LoadProjectUI(); LoadProjectUI();
@ -1414,6 +1497,13 @@ namespace CodeWalker.Project
{ {
WorldForm.SelectItem(null);//make sure current selected item isn't still selected... WorldForm.SelectItem(null);//make sure current selected item isn't still selected...
} }
if (GameFileCache != null)
{
GameFileCache.ClearProjectFiles();
GameFileCache.ClearProjectArchetypes();
}
} }
public void SaveProject(bool saveas = false) public void SaveProject(bool saveas = false)
{ {
@ -1458,10 +1548,14 @@ namespace CodeWalker.Project
if (files == null) if (files == null)
{ {
string[] filetypes = { string[] filetypes = {
"All supported|*.ymap;*.ytyp;*.ybn;*.ynd;*.ynv;*.dat;*.ymt;*.rel", "All supported|*.ymap;*.ytyp;*.ybn;*.ydr;*.ydd;*.yft;*.ytd;*.ynd;*.ynv;*.dat;*.ymt;*.rel",
"Ymap files|*.ymap", "Ymap files|*.ymap",
"Ytyp files|*.ytyp", "Ytyp files|*.ytyp",
"Ybn files|*.ybn", "Ybn files|*.ybn",
"Ydr files|*.ydr",
"Ydd files|*.ydd",
"Yft files|*.yft",
"Ytd files|*.ytd",
"Ynd files|*.ynd", "Ynd files|*.ynd",
"Ynv files|*.ynv", "Ynv files|*.ynv",
"Dat files|*.dat", "Dat files|*.dat",
@ -1503,6 +1597,22 @@ namespace CodeWalker.Project
var ybn = CurrentProjectFile.AddYbnFile(file); var ybn = CurrentProjectFile.AddYbnFile(file);
if (ybn != null) LoadYbnFromFile(ybn, file); if (ybn != null) LoadYbnFromFile(ybn, file);
break; break;
case ".ydr":
var ydr = CurrentProjectFile.AddYdrFile(file);
if (ydr != null) LoadYdrFromFile(ydr, file);
break;
case ".ydd":
var ydd = CurrentProjectFile.AddYddFile(file);
if (ydd != null) LoadYddFromFile(ydd, file);
break;
case ".yft":
var yft = CurrentProjectFile.AddYftFile(file);
if (yft != null) LoadYftFromFile(yft, file);
break;
case ".ytd":
var ytd = CurrentProjectFile.AddYtdFile(file);
if (ytd != null) LoadYtdFromFile(ytd, file);
break;
case ".ynd": case ".ynd":
var ynd = CurrentProjectFile.AddYndFile(file); var ynd = CurrentProjectFile.AddYndFile(file);
if (ynd != null) LoadYndFromFile(ynd, file); if (ynd != null) LoadYndFromFile(ynd, file);
@ -3028,7 +3138,7 @@ namespace CodeWalker.Project
cent.priorityLevel = rage__ePriorityLevel.PRI_REQUIRED; cent.priorityLevel = rage__ePriorityLevel.PRI_REQUIRED;
cent.ambientOcclusionMultiplier = 255; cent.ambientOcclusionMultiplier = 255;
cent.artificialAmbientOcclusion = 255; cent.artificialAmbientOcclusion = 255;
if(uint.TryParse(placement.ObjectProperties.FirstOrDefault(p => p.Name == "TextureVariation")?.Value, out uint tint)) if (uint.TryParse(placement.ObjectProperties.FirstOrDefault(p => p.Name == "TextureVariation")?.Value, out uint tint))
{ {
cent.tintValue = tint; cent.tintValue = tint;
} }
@ -3311,7 +3421,7 @@ namespace CodeWalker.Project
} }
else else
{ {
if ((mloArch.rooms?.Length??0) <= 0) if ((mloArch.rooms?.Length ?? 0) <= 0)
{ {
MessageBox.Show($@"Mlo {mloArch.Name} has no rooms! Cannot create entity."); MessageBox.Show($@"Mlo {mloArch.Name} has no rooms! Cannot create entity.");
return null; return null;
@ -3401,7 +3511,7 @@ namespace CodeWalker.Project
outEnt.SetArchetype(GameFileCache.GetArchetype(cent.archetypeName)); outEnt.SetArchetype(GameFileCache.GetArchetype(cent.archetypeName));
} }
} }
catch(Exception e) catch (Exception e)
{ {
MessageBox.Show(this, e.Message, "Create MLO Entity Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(this, e.Message, "Create MLO Entity Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null; return null;
@ -3746,10 +3856,9 @@ namespace CodeWalker.Project
} }
private void AddProjectArchetype(Archetype arch) private void AddProjectArchetype(Archetype arch)
{ {
if ((arch?.Hash ?? 0) == 0) return;
lock (projectsyncroot) lock (projectsyncroot)
{ {
projectarchetypes[arch.Hash] = arch; GameFileCache.AddProjectArchetype(arch);
} }
} }
private void RemoveProjectArchetypes(YtypFile ytyp) private void RemoveProjectArchetypes(YtypFile ytyp)
@ -3762,15 +3871,9 @@ namespace CodeWalker.Project
} }
private void RemoveProjectArchetype(Archetype arch) private void RemoveProjectArchetype(Archetype arch)
{ {
if ((arch?.Hash ?? 0) == 0) return;
Archetype tarch = null;
lock (projectsyncroot) lock (projectsyncroot)
{ {
projectarchetypes.TryGetValue(arch.Hash, out tarch); GameFileCache.RemoveProjectArchetype(arch);
if (tarch == arch)
{
projectarchetypes.Remove(arch.Hash);
}
} }
} }
@ -4447,10 +4550,10 @@ namespace CodeWalker.Project
if (CurrentYndFile == null) return; if (CurrentYndFile == null) return;
// Check that vehicle nodes and ped nodes add up to total nodes // Check that vehicle nodes and ped nodes add up to total nodes
if(CurrentYndFile.NodeDictionary != null && (CurrentYndFile.NodeDictionary.NodesCountPed + CurrentYndFile.NodeDictionary.NodesCountVehicle != CurrentYndFile.NodeDictionary.NodesCount)) if (CurrentYndFile.NodeDictionary != null && (CurrentYndFile.NodeDictionary.NodesCountPed + CurrentYndFile.NodeDictionary.NodesCountVehicle != CurrentYndFile.NodeDictionary.NodesCount))
{ {
var result = MessageBox.Show($"YND Area {CurrentYndFile.AreaID}: The total number of nodes ({CurrentYndFile.NodeDictionary.NodesCount}) does not match the total number of ped ({CurrentYndFile.NodeDictionary.NodesCountPed}) and vehicle ({CurrentYndFile.NodeDictionary.NodesCountVehicle}) nodes. You should manually adjust the number of nodes on the YND screen.\n\nDo you want to continue saving the YND file? Some of your nodes may not work in game.", $"Node count mismatch in Area {CurrentYndFile.AreaID}", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); var result = MessageBox.Show($"YND Area {CurrentYndFile.AreaID}: The total number of nodes ({CurrentYndFile.NodeDictionary.NodesCount}) does not match the total number of ped ({CurrentYndFile.NodeDictionary.NodesCountPed}) and vehicle ({CurrentYndFile.NodeDictionary.NodesCountVehicle}) nodes. You should manually adjust the number of nodes on the YND screen.\n\nDo you want to continue saving the YND file? Some of your nodes may not work in game.", $"Node count mismatch in Area {CurrentYndFile.AreaID}", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
if(result == DialogResult.Cancel) if (result == DialogResult.Cancel)
{ {
return; return;
} }
@ -6257,7 +6360,7 @@ namespace CodeWalker.Project
zone.Unk14 = cp ? copy.AudioZone.Unk14 : (byte)4; zone.Unk14 = cp ? copy.AudioZone.Unk14 : (byte)4;
zone.Unk15 = cp ? copy.AudioZone.Unk15 : (byte)1; zone.Unk15 = cp ? copy.AudioZone.Unk15 : (byte)1;
zone.Unk16 = cp ? copy.AudioZone.Unk16 : (byte)0; zone.Unk16 = cp ? copy.AudioZone.Unk16 : (byte)0;
zone.RulesCount = cp ? copy.AudioZone.RulesCount: (byte)0; zone.RulesCount = cp ? copy.AudioZone.RulesCount : (byte)0;
zone.Rules = cp ? copy.AudioZone.Rules : null; zone.Rules = cp ? copy.AudioZone.Rules : null;
zone.ExtParamsCount = cp ? copy.AudioZone.ExtParamsCount : 0; zone.ExtParamsCount = cp ? copy.AudioZone.ExtParamsCount : 0;
zone.ExtParams = cp ? copy.AudioZone.ExtParams : null; zone.ExtParams = cp ? copy.AudioZone.ExtParams : null;
@ -6742,6 +6845,154 @@ namespace CodeWalker.Project
public void AddYdrToProject(YdrFile ydr)
{
if (ydr == null) return;
if (CurrentProjectFile == null)
{
NewProject();
}
if (YdrExistsInProject(ydr)) return;
if (CurrentProjectFile.AddYdrFile(ydr))
{
//ydr.HasChanged = true;
CurrentProjectFile.HasChanged = true;
LoadProjectTree();
}
CurrentYdrFile = ydr;
RefreshUI();
GameFileCache?.AddProjectFile(ydr);
}
public void RemoveYdrFromProject()
{
if (CurrentYdrFile == null) return;
if (CurrentProjectFile == null) return;
GameFileCache?.RemoveProjectFile(CurrentYdrFile);
CurrentProjectFile.RemoveYdrFile(CurrentYdrFile);
CurrentYdrFile = null;
LoadProjectTree();
RefreshUI();
}
public bool YdrExistsInProject(YdrFile ydr)
{
if (ydr == null) return false;
if (CurrentProjectFile == null) return false;
return CurrentProjectFile.ContainsYdr(ydr);
}
public void AddYddToProject(YddFile ydd)
{
if (ydd == null) return;
if (CurrentProjectFile == null)
{
NewProject();
}
if (YddExistsInProject(ydd)) return;
if (CurrentProjectFile.AddYddFile(ydd))
{
//ydd.HasChanged = true;
CurrentProjectFile.HasChanged = true;
LoadProjectTree();
}
CurrentYddFile = ydd;
RefreshUI();
GameFileCache?.AddProjectFile(ydd);
}
public void RemoveYddFromProject()
{
if (CurrentYddFile == null) return;
if (CurrentProjectFile == null) return;
GameFileCache?.RemoveProjectFile(CurrentYddFile);
CurrentProjectFile.RemoveYddFile(CurrentYddFile);
CurrentYddFile = null;
LoadProjectTree();
RefreshUI();
}
public bool YddExistsInProject(YddFile ydd)
{
if (ydd == null) return false;
if (CurrentProjectFile == null) return false;
return CurrentProjectFile.ContainsYdd(ydd);
}
public void AddYftToProject(YftFile yft)
{
if (yft == null) return;
if (CurrentProjectFile == null)
{
NewProject();
}
if (YftExistsInProject(yft)) return;
if (CurrentProjectFile.AddYftFile(yft))
{
//yft.HasChanged = true;
CurrentProjectFile.HasChanged = true;
LoadProjectTree();
}
CurrentYftFile = yft;
RefreshUI();
GameFileCache?.AddProjectFile(yft);
}
public void RemoveYftFromProject()
{
if (CurrentYftFile == null) return;
if (CurrentProjectFile == null) return;
GameFileCache?.RemoveProjectFile(CurrentYftFile);
CurrentProjectFile.RemoveYftFile(CurrentYftFile);
CurrentYftFile = null;
LoadProjectTree();
RefreshUI();
}
public bool YftExistsInProject(YftFile yft)
{
if (yft == null) return false;
if (CurrentProjectFile == null) return false;
return CurrentProjectFile.ContainsYft(yft);
}
public void AddYtdToProject(YtdFile ytd)
{
if (ytd == null) return;
if (CurrentProjectFile == null)
{
NewProject();
}
if (YtdExistsInProject(ytd)) return;
if (CurrentProjectFile.AddYtdFile(ytd))
{
//ytd.HasChanged = true;
CurrentProjectFile.HasChanged = true;
LoadProjectTree();
}
CurrentYtdFile = ytd;
RefreshUI();
GameFileCache?.AddProjectFile(ytd);
}
public void RemoveYtdFromProject()
{
if (CurrentYtdFile == null) return;
if (CurrentProjectFile == null) return;
GameFileCache?.RemoveProjectFile(CurrentYtdFile);
CurrentProjectFile.RemoveYtdFile(CurrentYtdFile);
CurrentYtdFile = null;
LoadProjectTree();
RefreshUI();
}
public bool YtdExistsInProject(YtdFile ytd)
{
if (ytd == null) return false;
if (CurrentProjectFile == null) return false;
return CurrentProjectFile.ContainsYtd(ytd);
}
@ -6782,13 +7033,10 @@ namespace CodeWalker.Project
{ {
foreach (var ent in ymap.AllEntities) foreach (var ent in ymap.AllEntities)
{ {
if (ent.Archetype == null) continue; Archetype arch = GameFileCache.GetArchetype(ent._CEntityDef.archetypeName);
if ((arch != null) && (ent.Archetype != arch))
Archetype parch = null;
projectarchetypes.TryGetValue(ent.Archetype.Hash, out parch);
if ((parch != null) && (ent.Archetype != parch))
{ {
ent.SetArchetype(parch); //swap archetype to project one... ent.SetArchetype(arch); //swap archetype to project one...
if (ent.IsMlo) if (ent.IsMlo)
{ {
ent.MloInstance.InitYmapEntityArchetypes(GameFileCache); ent.MloInstance.InitYmapEntityArchetypes(GameFileCache);
@ -7354,6 +7602,10 @@ namespace CodeWalker.Project
CurrentAudioEmitter = (audiopl?.AudioEmitter != null) ? audiopl : null; CurrentAudioEmitter = (audiopl?.AudioEmitter != null) ? audiopl : null;
CurrentAudioZoneList = null; CurrentAudioZoneList = null;
CurrentAudioEmitterList = null; CurrentAudioEmitterList = null;
CurrentYdrFile = null;
CurrentYddFile = null;
CurrentYftFile = null;
CurrentYtdFile = null;
RefreshUI(); RefreshUI();
if (showcurrent) if (showcurrent)
{ {
@ -8330,6 +8582,50 @@ namespace CodeWalker.Project
rel.Load(data, rel?.RpfFileEntry); rel.Load(data, rel?.RpfFileEntry);
} }
private void LoadYdrFromFile(YdrFile ydr, string filename)
{
byte[] data = File.ReadAllBytes(filename);
ydr.Load(data);
if (GameFileCache != null)
{
GameFileCache.AddProjectFile(ydr);
}
}
private void LoadYddFromFile(YddFile ydd, string filename)
{
byte[] data = File.ReadAllBytes(filename);
ydd.Load(data);
if (GameFileCache != null)
{
GameFileCache.AddProjectFile(ydd);
}
}
private void LoadYftFromFile(YftFile yft, string filename)
{
byte[] data = File.ReadAllBytes(filename);
yft.Load(data);
if (GameFileCache != null)
{
GameFileCache.AddProjectFile(yft);
}
}
private void LoadYtdFromFile(YtdFile ytd, string filename)
{
byte[] data = File.ReadAllBytes(filename);
ytd.Load(data);
if (GameFileCache != null)
{
GameFileCache.AddProjectFile(ytd);
}
}
@ -8377,6 +8673,10 @@ namespace CodeWalker.Project
RefreshTrainTrackUI(); RefreshTrainTrackUI();
RefreshScenarioUI(); RefreshScenarioUI();
RefreshAudioUI(); RefreshAudioUI();
RefreshYdrUI();
RefreshYddUI();
RefreshYftUI();
RefreshYtdUI();
SetCurrentSaveItem(); SetCurrentSaveItem();
//ShowEditYmapPanel(false); //ShowEditYmapPanel(false);
//ShowEditYmapEntityPanel(false); //ShowEditYmapEntityPanel(false);
@ -8633,6 +8933,78 @@ namespace CodeWalker.Project
WorldForm.EnableAudioUI(enable, CurrentAudioFile?.Name ?? ""); WorldForm.EnableAudioUI(enable, CurrentAudioFile?.Name ?? "");
} }
} }
private void RefreshYdrUI()
{
bool enable = (CurrentYdrFile != null);
bool inproj = YdrExistsInProject(CurrentYdrFile);
if (CurrentYdrFile != null)
{
YdrNameMenu.Text = "(" + CurrentYdrFile.Name + ")";
}
else
{
YdrNameMenu.Text = "(No .ydr file selected)";
}
//YdrAddToProjectMenu.Enabled = enable && !inproj;
YdrRemoveFromProjectMenu.Enabled = inproj;
YdrMenu.Visible = enable;
}
private void RefreshYddUI()
{
bool enable = (CurrentYddFile != null);
bool inproj = YddExistsInProject(CurrentYddFile);
if (CurrentYddFile != null)
{
YddNameMenu.Text = "(" + CurrentYddFile.Name + ")";
}
else
{
YddNameMenu.Text = "(No .ydd file selected)";
}
//YddAddToProjectMenu.Enabled = enable && !inproj;
YddRemoveFromProjectMenu.Enabled = inproj;
YddMenu.Visible = enable;
}
private void RefreshYftUI()
{
bool enable = (CurrentYftFile != null);
bool inproj = YftExistsInProject(CurrentYftFile);
if (CurrentYftFile != null)
{
YftNameMenu.Text = "(" + CurrentYftFile.Name + ")";
}
else
{
YftNameMenu.Text = "(No .yft file selected)";
}
//YftAddToProjectMenu.Enabled = enable && !inproj;
YftRemoveFromProjectMenu.Enabled = inproj;
YftMenu.Visible = enable;
}
private void RefreshYtdUI()
{
bool enable = (CurrentYtdFile != null);
bool inproj = YtdExistsInProject(CurrentYtdFile);
if (CurrentYtdFile != null)
{
YtdNameMenu.Text = "(" + CurrentYtdFile.Name + ")";
}
else
{
YtdNameMenu.Text = "(No .ytd file selected)";
}
//YtdAddToProjectMenu.Enabled = enable && !inproj;
YtdRemoveFromProjectMenu.Enabled = inproj;
YtdMenu.Visible = enable;
}
private void SetCurrentSaveItem() private void SetCurrentSaveItem()
@ -9012,6 +9384,23 @@ namespace CodeWalker.Project
RemoveYbnFromProject(); RemoveYbnFromProject();
} }
private void YdrRemoveFromProjectMenu_Click(object sender, EventArgs e)
{
RemoveYdrFromProject();
}
private void YddRemoveFromProjectMenu_Click(object sender, EventArgs e)
{
RemoveYddFromProject();
}
private void YftRemoveFromProjectMenu_Click(object sender, EventArgs e)
{
RemoveYftFromProject();
}
private void YtdRemoveFromProjectMenu_Click(object sender, EventArgs e)
{
RemoveYtdFromProject();
}
private void YndNewNodeMenu_Click(object sender, EventArgs e) private void YndNewNodeMenu_Click(object sender, EventArgs e)
{ {
NewPathNode(); NewPathNode();