protected ArrayList LoadStrLinked(SimPe.Interfaces.Files.IPackageFile pkg, CloneSettings.StrIntsanceAlias instance) { ArrayList list = new ArrayList(); SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFile(Data.MetaData.STRING_FILE, 0, instance.Instance); foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds) { SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str(); str.ProcessData(pfd, pkg); foreach (SimPe.PackedFiles.Wrapper.StrToken si in str.Items) { string name = Hashes.StripHashFromName(si.Title).Trim(); if (name == "") { continue; } name += instance.Extension; //Console.WriteLine("Str Linked: "+name); SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem fii = FileTable.FileIndex.FindFileByName(name, instance.Type, Hashes.GetHashGroupFromName(si.Title, Data.MetaData.GLOBAL_GROUP), true); if (fii != null) { //Console.WriteLine(" --> found"); list.Add(fii); } } } return(list); }
/// <summary> /// Add Resources referenced from XML Files /// </summary> protected void AddFromXml(SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item) { if (item == null) { return; } SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = new SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[1]; items[0] = item; AddFromXml(items); }
public SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem FindReferencedType(uint type) { foreach (ArrayList list in ReferenceChains.Values) { foreach (object o in list) { SimPe.Interfaces.Files.IPackedFileDescriptor opfd = (SimPe.Interfaces.Files.IPackedFileDescriptor)o; if (opfd.Type == type) { SimPe.Interfaces.Files.IPackedFileDescriptor pfd = Package.FindFile(opfd); if (pfd == null) { opfd.Group = this.FileDescriptor.Group; pfd = Package.FindFile(opfd); } if (pfd == null) { opfd.Group = Data.MetaData.LOCAL_GROUP; pfd = Package.FindFile(opfd); } SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item = null; if (pfd == null) { FileTable.FileIndex.Load(); SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = FileTable.FileIndex.FindFile((SimPe.Interfaces.Files.IPackedFileDescriptor)o, null); if (items.Length > 0) { item = items[0]; } } else { item = FileTable.FileIndex.CreateFileIndexItem(pfd, Package); } if (item != null) { return(item); } } } } return(null); }
/// <summary> /// If this MipMap is a LifoReference, then this Method will try to load the Lifo Data /// </summary> protected bool GetReferencedLifo_NoLoad() { if (datatype == MipMapType.LifoReference) { SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item = FileTable.FileIndex.FindFileByName(this.lifofile, SimPe.Data.MetaData.LIFO, SimPe.Data.MetaData.LOCAL_GROUP, true); GenericRcol rcol = null; if (item != null) //we have a global LIFO (loads faster) { rcol = new GenericRcol(null, false); rcol.ProcessData(item.FileDescriptor, item.Package); } else //the lifo wasn't found globaly, so we look for it in the local package { SimPe.Interfaces.Files.IPackageFile pkg = parent.Parent.Package; SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFile(this.lifofile, SimPe.Data.MetaData.LIFO); if (pfds.Length > 0) { rcol = new GenericRcol(null, false); rcol.ProcessData(pfds[0], pkg); } } //process the Lifo File if found if (rcol != null) { LevelInfo li = (LevelInfo)rcol.Blocks[0]; this.img = null; this.Data = li.Data; return(true); } } else { return(true); } return(false); }
/// <summary> /// Loads Slave TXMTs by name Replacement /// </summary> /// <param name="rcol">a TXMT File</param> /// <param name="pkg">the package File with the base TXMTs</param> /// <param name="slaves">The Hashtable holding als Slave Subsets</param> public static void AddSlaveTxmts(ArrayList modelnames, ArrayList ex, ArrayList list, ArrayList itemlist, Rcol rcol, Hashtable slaves) { string name = rcol.FileName.Trim().ToLower(); foreach (string k in slaves.Keys) { foreach (string sub in (ArrayList)slaves[k]) { string slavename = name.Replace("_" + k + "_", "_" + sub + "_"); if (slavename != name) { SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item = FileTable.FileIndex.FindFileByName(slavename, Data.MetaData.TXMT, Data.MetaData.LOCAL_GROUP, true); if (item != null) { GenericRcol txmt = new GenericRcol(null, false); txmt.ProcessData(item); txmt.FileDescriptor = (Interfaces.Files.IPackedFileDescriptor)item.FileDescriptor.Clone(); LoadReferenced(modelnames, ex, list, itemlist, txmt, item, true, null); } } } } }
/// <summary> /// Adds all know MMATs that reference one of the models; /// </summary> /// <param name="pkg"></param> /// <param name="onlydefault">true, if you only want to read default MMATS</param> /// <param name="subitems">true, if you also want to load MMAT Files that reference Files ouside the passed package</param> /// <param name="exception">true if you want to throw an exception when something goes wrong</param> /// <returns>List of all referenced GUIDs</returns> public void AddMaterialOverrides(SimPe.Interfaces.Files.IPackageFile pkg, bool onlydefault, bool subitems, bool exception) { LoadCache(); SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = FileTable.FileIndex.FindFile(Data.MetaData.MMAT, true); ArrayList itemlist = new ArrayList(); ArrayList contentlist = new ArrayList(); ArrayList defaultfam = new ArrayList(); ArrayList guids = new ArrayList(); //create an UpTo Date Cache bool chgcache = false; foreach (SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item in items) { string pname = item.Package.FileName.Trim().ToLower(); SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] citems = cachefile.FileIndex.FindFile(item.FileDescriptor, item.Package); bool have = false; foreach (SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem citem in citems) { if (citem.FileDescriptor.Filename == pname) { have = true; break; } } //Not in cache, so add that File if (!have) { SimPe.Plugin.MmatWrapper mmat = new MmatWrapper(); mmat.ProcessData(item.FileDescriptor, item.Package); cachefile.AddItem(mmat); chgcache = true; } } if (chgcache) { SaveCache(); } //collect a list of Default Material Override family values first if (onlydefault) { foreach (SimPe.Cache.MMATCacheItem mci in (SimPe.Cache.CacheItems)cachefile.DefaultMap[true]) { defaultfam.Add(mci.Family); } } //now do the real collect foreach (string k in modelnames) { SimPe.Cache.CacheItems list = (SimPe.Cache.CacheItems)cachefile.ModelMap[k.Trim().ToLower()]; if (list != null) { foreach (SimPe.Cache.MMATCacheItem mci in list) { if (onlydefault && !defaultfam.Contains(mci.Family)) { continue; } string name = k; items = FileTable.FileIndex.FindFile(mci.FileDescriptor, null); foreach (Interfaces.Scenegraph.IScenegraphFileIndexItem item in items) { if (itemlist.Contains(item)) { continue; } itemlist.Add(item); SimPe.Plugin.MmatWrapper mmat = new MmatWrapper(); mmat.ProcessData(item); string content = Scenegraph.MmatContent(mmat); content = content.Trim().ToLower(); if (!contentlist.Contains(content)) { mmat.FileDescriptor = Clone(mmat.FileDescriptor); mmat.SynchronizeUserData(); if (subitems) { if (pkg.FindFile(mmat.FileDescriptor) == null) { pkg.Add(mmat.FileDescriptor); } SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem txmtitem = SimPe.FileTable.FileIndex.FindFileByName(mmat.GetSaveItem("name").StringValue + "_txmt", Data.MetaData.TXMT, Data.MetaData.LOCAL_GROUP, true); if (txmtitem != null) { try { SimPe.Plugin.GenericRcol sub = new GenericRcol(null, false); sub.ProcessData(txmtitem.FileDescriptor, txmtitem.Package, false); ArrayList newfiles = new ArrayList(); LoadReferenced(this.modelnames, this.exclude, newfiles, itemlist, sub, txmtitem, true, setup); BuildPackage(newfiles, pkg); } catch (Exception ex) { Helper.ExceptionMessage("", new CorruptedFileException(txmtitem, ex)); } } else { continue; //if (exception) throw new ScenegraphException("Invalid Scenegraph Link", new ScenegraphException("Unable to find Referenced File "+name+"_txmt.", mmat.FileDescriptor), mmat.FileDescriptor); } } else { if (pkg.FindFile(mmat.FileDescriptor) == null) { string txmtname = mmat.GetSaveItem("name").StringValue.Trim(); if (!txmtname.EndsWith("_txmt")) { txmtname += "_txmt"; } if (pkg.FindFile(txmtname, Data.MetaData.TXMT).Length > 0) { pkg.Add(mmat.FileDescriptor); } } } contentlist.Add(content); } //if contentlist } //foreach item } //foreach MMATCacheItem } // if list !=null } }
/// <summary> /// Load all File referenced by the passed rcol File /// </summary> /// <param name="modelnames">The Modulenames</param> /// <param name="exclude">The Exclude List</param> /// <param name="list">A List containing all Rcol Files</param> /// <param name="itemlist">A List of all FileIndexItems already added</param> /// <param name="rcol">The Rcol File (Scenegraph Resource)</param> /// <param name="item">The Item that was used to load the rcol</param> /// <param name="recursive">true if you want to add all sub Rcols</param> protected static void LoadReferenced(ArrayList modelnames, ArrayList exclude, ArrayList list, ArrayList itemlist, SimPe.Plugin.GenericRcol rcol, SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item, bool recursive, CloneSettings setup) { //if we load a CRES, we also have to add the Modelname! if (rcol.FileDescriptor.Type == Data.MetaData.CRES) { modelnames.Add(rcol.FileName.Trim().ToLower()); } list.Add(rcol); itemlist.Add(item); Hashtable map = rcol.ReferenceChains; foreach (string s in map.Keys) { if (exclude.Contains(s)) { continue; } ArrayList descs = (ArrayList)map[s]; foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in descs) { if (setup != null) { if (setup.KeepOriginalMesh) { if (pfd.Type == Data.MetaData.GMND) { continue; } if (pfd.Type == Data.MetaData.GMDC) { continue; } } } SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem subitem = FileTable.FileIndex.FindSingleFile(pfd, null, true); if (subitem != null) { if (!itemlist.Contains(subitem)) { try { SimPe.Plugin.GenericRcol sub = new GenericRcol(null, false); sub.ProcessData(subitem.FileDescriptor, subitem.Package, false); if (Scenegraph.excludefiles.Contains(sub.FileName.Trim().ToLower())) { continue; } if (recursive) { LoadReferenced(modelnames, exclude, list, itemlist, sub, subitem, true, setup); } } catch (Exception ex) { Helper.ExceptionMessage("", new CorruptedFileException(subitem, ex)); } } } } } }
/// <summary> /// Add Resources referenced from XML Files /// </summary> protected void AddFromXml(string name, uint type) { SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item = FileTable.FileIndex.FindFileByName(name, type, Data.MetaData.LOCAL_GROUP, true); AddFromXml(item); }