예제 #1
0
        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);
        }
예제 #2
0
        /// <summary>
        /// Loads Slave TXMTs by name Replacement
        /// </summary>
        /// <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(SimPe.Interfaces.Files.IPackageFile pkg, Hashtable slaves)
        {
            ArrayList files = new ArrayList();
            ArrayList items = new ArrayList();

            SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFiles(Data.MetaData.TXMT);
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                GenericRcol rcol = new GenericRcol(null, false);
                rcol.ProcessData(pfd, pkg);

                if (rcol.FileDescriptor.Type == Data.MetaData.TXMT)
                {
                    AddSlaveTxmts(new ArrayList(), new ArrayList(), files, items, rcol, slaves);
                }
            }

            foreach (GenericRcol rcol in files)
            {
                if (pkg.FindFile(rcol.FileDescriptor) == null)
                {
                    rcol.FileDescriptor = rcol.FileDescriptor.Clone();
                    rcol.SynchronizeUserData();
                    pkg.Add(rcol.FileDescriptor);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Return all Modelnames that can be found in this package
        /// </summary>
        /// <param name="pkg">The Package you want to scan</param>
        /// <returns>a list of Modelnames</returns>
        public static string[] FindModelNames(SimPe.Interfaces.Files.IPackageFile pkg)
        {
            ArrayList names = new ArrayList();

            Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFile(Data.MetaData.STRING_FILE, 0, 0x85);
            if (pfds.Length > 0)
            {
                foreach (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 item in str.Items)
                    {
                        string mname = Hashes.StripHashFromName(item.Title.Trim().ToLower());
                        if (!mname.EndsWith("_cres"))
                        {
                            mname += "_cres";
                        }
                        if ((mname != "") && (!names.Contains(mname)))
                        {
                            names.Add(mname);
                        }
                    }
                }
            }

            pfds = pkg.FindFiles(Data.MetaData.MMAT);
            if (pfds.Length > 0)
            {
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf();
                    cpf.ProcessData(pfd, pkg);

                    string mname = Hashes.StripHashFromName(cpf.GetSaveItem("modelName").StringValue.Trim().ToLower());
                    if (!mname.EndsWith("_cres"))
                    {
                        mname += "_cres";
                    }
                    if ((mname != "") && (!names.Contains(mname)))
                    {
                        names.Add(mname);
                    }
                }
            }

            string[] ret = new string[names.Count];
            names.CopyTo(ret);

            return(ret);
        }
예제 #4
0
        /// <summary>
        /// Create a package based on the collected Files
        /// </summary>
        /// <returns></returns>
        public static void BuildPackage(ArrayList files, SimPe.Interfaces.Files.IPackageFile pkg)
        {
            foreach (SimPe.Plugin.GenericRcol rcol in files)
            {
                rcol.FileDescriptor = Clone(rcol.FileDescriptor);
                rcol.SynchronizeUserData();

                if (pkg.FindFile(rcol.FileDescriptor) == null)
                {
                    pkg.Add(rcol.FileDescriptor);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Load the IdNo stored in the passed package
        /// </summary>
        /// <param name="pkg"></param>
        /// <returns></returns>
        public static Idno FromPackage(SimPe.Interfaces.Files.IPackageFile pkg)
        {
            if (pkg == null)
            {
                return(null);
            }
            Interfaces.Files.IPackedFileDescriptor idno = pkg.FindFile(Data.MetaData.IDNO, 0, Data.MetaData.LOCAL_GROUP, 1);
            if (idno != null)
            {
                SimPe.Plugin.Idno wrp = new Idno();
                wrp.ProcessData(idno, pkg);

                return(wrp);
            }

            return(null);
        }
예제 #6
0
        /// <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);
        }
예제 #7
0
        /// <summary>
        /// Find the TXTRs that are referenced by the passed TXMTs
        /// </summary>
        /// <param name="txmts"></param>
        /// <param name="flname">null, or the Filename of a package to search in</param>
        /// <returns>null or the first found shpe</returns>
        public Hashtable FindReferencedTXTR(Hashtable txmts, string flname)
        {
            Hashtable ht = new Hashtable();

            if (txmts == null)
            {
                return(ht);
            }

            SimPe.Interfaces.Files.IPackageFile lpackage = package;
            if (flname != null)
            {
                lpackage = SimPe.Packages.File.LoadFromFile(flname);
            }

            foreach (string subset in txmts.Keys)
            {
                Rcol rcol = (Rcol)txmts[subset];
                MaterialDefinition txmt     = (MaterialDefinition)rcol.Blocks[0];
                string             txtrname = Hashes.StripHashFromName(txmt.GetProperty("stdMatBaseTextureName").Value) + "_txtr";
                txtrname = txtrname.Trim().ToLower();

                Interfaces.Files.IPackedFileDescriptor[] pfds = lpackage.FindFile(txtrname, 0x1C4A276C);
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    Rcol txtr = new GenericRcol(null, false);
                    txtr.ProcessData(pfd, lpackage);

                    if (Hashes.StripHashFromName(txtr.FileName).Trim().ToLower() == txtrname)
                    {
                        if (!ht.Contains(subset))
                        {
                            ht.Add(subset, txtr);
                        }
                    }
                }
            }


            return(ht);
        }
예제 #8
0
        protected override void SetImage(SimPe.Interfaces.Files.IPackageFile pkg)
        {
            SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pkg.FindFile(0x856DDBAC, 0, Data.MetaData.LOCAL_GROUP, 0x35CA0002);
            if (pfd == null)
            {
                SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFiles(0x856DDBAC);
                if (pfds.Length > 0)
                {
                    pfd = pfds[0];
                }
            }

            if (pfd != null)
            {
                SimPe.PackedFiles.Wrapper.Picture pic = new SimPe.PackedFiles.Wrapper.Picture();
                pic.ProcessData(pfd, pkg);
                nfo.Image = pic.Image;
            }

            nfo.KnockoutThumbnail = false;
        }
예제 #9
0
        /// <summary>
        /// Find the TXMTs that are referenced by the passed Shape
        /// </summary>
        /// <param name="shpe"></param>
        /// <param name="flname">null, or the Filename of a package to search in</param>
        /// <returns>null or the first found shpe</returns>
        public Hashtable FindReferencedTXMT(Rcol shpe, string flname)
        {
            Hashtable ht = new Hashtable();

            if (shpe == null)
            {
                return(ht);
            }

            SimPe.Interfaces.Files.IPackageFile lpackage = package;
            if (flname != null)
            {
                lpackage = SimPe.Packages.File.LoadFromFile(flname);
            }

            Shape shp = (Shape)shpe.Blocks[0];

            foreach (ShapePart p in shp.Parts)
            {
                string txmtflname = Hashes.StripHashFromName(p.FileName).Trim().ToLower() + "_txmt";
                string subset     = p.Subset.Trim().ToLower();

                Interfaces.Files.IPackedFileDescriptor[] pfds = lpackage.FindFile(txmtflname, 0x49596978);
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    Rcol rcol = new GenericRcol(null, false);
                    rcol.ProcessData(pfd, lpackage);

                    if (Hashes.StripHashFromName(rcol.FileName).Trim().ToLower() == txmtflname)
                    {
                        if (!ht.Contains(subset))
                        {
                            ht.Add(subset, rcol);
                        }
                    }
                }
            }

            return(ht);
        }
예제 #10
0
        public virtual void SetFromPackage(SimPe.Interfaces.Files.IPackageFile pkg)
        {
            if (pkg == null)
            {
                objd = null;
                ClearScreen();
                return;
            }

            SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFile(Data.MetaData.OBJD_FILE, 0, 0x41A7);
            if (pfds.Length > 0)
            {
                objd = new SimPe.PackedFiles.Wrapper.ExtObjd();
                objd.ProcessData(pfds[0], pkg);
            }
            int fct = 0; int vct = 0;

            pfds = pkg.FindFiles(Data.MetaData.GMDC);
            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                SimPe.Plugin.Rcol rcol = new GenericRcol();
                rcol.ProcessData(pfd, pkg, true);

                SimPe.Plugin.GeometryDataContainer gmdc = rcol.Blocks[0] as SimPe.Plugin.GeometryDataContainer;
                foreach (SimPe.Plugin.Gmdc.GmdcGroup g in gmdc.Groups)
                {
                    fct += g.FaceCount;
                    vct += g.UsedVertexCount;
                }

                rcol.Dispose();
            }
            lbVert.Text = vct.ToString() + " (" + fct.ToString() + " Faces)";


            UpdateScreen();
        }
예제 #11
0
        void AddItem(SimPe.Interfaces.Files.IPackedFileDescriptor pfd, SimPe.Interfaces.Files.IPackageFile pkg, GraphItem parent, SimPe.Interfaces.Scenegraph.IScenegraphFileIndex fileindex)
        {
            #region Default Setup
            int top  = -128;
            int left = 0;

            if (parent != null)
            {
                top = parent.Location.Y;
            }
            do
            {
                top += 128;
                if (coords.ContainsKey(top))
                {
                    left = (int)coords[top];
                }
                //if (parent!=null) if (left<parent.Location.X) left = parent.Location.X;
            } while (left > gc.Parent.Width && false);

            GraphItem gi = new GraphItem(new Ambertation.Collections.PropertyItems());
            gi.Text = Hashes.StripHashFromName(pfd.Filename);
            //gi.BeginUpdate();
            //gi.Location = new Point(left, top);
            gi.SetBounds(left, top, 200, 64);
            gi.GotFocus += new EventHandler(gi_GotFocus);
            gi.Tag       = Hashes.StripHashFromName(pfd.Filename);
            gi.Fade      = 0.7f;
            //gi.LinkColor = Color.FromArgb(35, Color.Black);
            //gi.SelectedLinkColor = Color.FromArgb(0xff, Color.DarkBlue);

            SimPe.Data.TypeAlias ta = Data.MetaData.FindTypeAlias(pfd.Type);
            gi.Properties["Type"].Value      = ta.shortname;
            gi.Properties["Available"].Value = "false";
            //gi.Parent = gc;
            #endregion

            //check if we already have a reource of that kind
            string name = gi.Text.Trim().ToLower();
            if (names.ContainsKey(name))
            {
                //gi.EndUpdate();
                gi = (GraphItem)names[name];

                if (parent != null)
                {
                    parent.ChildItems.Add(gi);
                }
            }
            else
            {
                #region find File
                SimPe.Interfaces.Scenegraph.IScenegraphItem  item   = null;
                SimPe.Interfaces.Files.IPackedFileDescriptor pkgpfd = pkg.FindFile(pfd);

                //not found in the passed package, look for a global File with that Name
                if (pkgpfd == null)
                {
                    SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem items = FileTable.FileIndex.FindFileByName(pfd.Filename, pfd.Type, pfd.Group, true);
                    if (items != null)
                    {
                        gi.Properties["Available"].Value = "extern";
                        gi.Properties["File"].Value      = items.Package.FileName;
                        gi.Size       = new Size(gi.Size.Width, 70);
                        gi.PanelColor = Color.Black;
                    }
                }
                #endregion

                //the file is available, so add it
                if (pkgpfd != null)
                {
                    gi.Properties["Available"].Value = "true";
                    if (colors.ContainsKey(ta.shortname))
                    {
                        gi.PanelColor = (Color)colors[ta.shortname];
                    }

                    if (Data.MetaData.RcolList.Contains(pfd.Type))
                    {
                        item = BuildRcol(pkgpfd, pkg, gi);
                    }
                    else if (pfd.Type == Data.MetaData.MMAT)
                    {
                        item = BuildMmat(pkgpfd, pkg, gi);
                    }

                    /*}
                     * else
                     * {
                     *      if (Data.MetaData.RcolList.Contains(pfd.Type)) item = BuildRcol(pkgpfd, altpkg, gi);
                     *      else if (pfd.Type==Data.MetaData.MMAT) item = BuildMmat(pkgpfd, altpkg, gi);
                     * }*/

                    //check again if we still don't have that file
                    name = gi.Text.Trim().ToLower();
                    if (names.ContainsKey(name))
                    {
                        //gi.EndUpdate();
                        gi = (GraphItem)names[name];
                    }
                    else
                    {
                        //now process the Reference Files
                        if (item != null)
                        {
                            Hashtable ht = item.ReferenceChains;
                            foreach (ArrayList list in ht.Values)
                            {
                                foreach (SimPe.Interfaces.Files.IPackedFileDescriptor spfd in list)
                                {
                                    AddItem(spfd, pkg, gi, fileindex);
                                }
                            }
                        }
                    }
                }

                gi.Invalidate();

                if (!names.ContainsKey(name))
                {
                    names.Add(name, gi);
                    gi.Parent   = gc;
                    coords[top] = left + 8 + gi.Size.Width;

                    if (pkgpfd == null)
                    {
                        gi.PanelColor  = Color.DarkRed;
                        gi.ForeColor   = Color.White;
                        gi.BorderColor = gi.ForeColor;

                        if ((string)gi.Properties["Available"].Value == "extern")
                        {
                            gi.PanelColor = Color.Black;
                        }
                    }
                }


                if (parent != null)
                {
                    parent.ChildItems.Add(gi);
                }
            }

            //gi.EndUpdate();
        }
예제 #12
0
        /// <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
            }
        }