Exemple #1
0
        /// <summary>
        /// Add all Files that could be borrowed from the current package by the passed one, to the passed package
        /// </summary>
        /// <param name="orgmodelnames">List of available modelnames in this package</param>
        /// <param name="pkg">The package that should receive the Files</param>
        /// <remarks>Simply Copies MMAT, LIFO, TXTR and TXMT Files</remarks>
        public void AddParentFiles(string[] orgmodelnames, SimPe.Interfaces.Files.IPackageFile pkg)
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Loading Parent Files");
            }
            ArrayList names = new ArrayList();

            foreach (string s in orgmodelnames)
            {
                names.Add(s);
            }

            ArrayList types = new ArrayList();

            types.Add(Data.MetaData.MMAT);
            types.Add(Data.MetaData.TXMT);
            types.Add(Data.MetaData.TXTR);
            types.Add(Data.MetaData.LIFO);

            foreach (uint type in types)
            {
                SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(type);
                foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    if (pkg.FindFile(pfd) != null)
                    {
                        continue;
                    }

                    SimPe.Interfaces.Files.IPackedFile file = package.Read(pfd);
                    pfd.UserData = file.UncompressedData;

                    //Update the modeName in the MMAT
                    if ((pfd.Type == Data.MetaData.MMAT) && (names.Count > 0))
                    {
                        SimPe.Plugin.MmatWrapper mmat = new MmatWrapper();
                        mmat.ProcessData(pfd, package);

                        string n = mmat.ModelName.Trim().ToLower();
                        if (!n.EndsWith("_cres"))
                        {
                            n += "_cres";
                        }

                        if (!names.Contains(n))
                        {
                            n = names[0].ToString();
                            //n = n.Substring(0, n.Length-5);
                            mmat.ModelName = n;
                            mmat.SynchronizeUserData();
                        }
                    }

                    pkg.Add(pfd);
                }
            }             //foreach type
        }
Exemple #2
0
        public static Ambertation.Scenes.Scene BuildScene(SimPe.Interfaces.Scenegraph.IScenegraphFileIndex fii, MmatWrapper mmat, SimPe.Interfaces.Files.IPackageFile package, out SimPe.Interfaces.Files.IPackageFile npkg)
        {
            npkg = null;
            try
            {
                FileTable.FileIndex.Load();
                if (System.IO.File.Exists(package.SaveFileName))
                {
                    fii.AddIndexFromFolder(System.IO.Path.GetDirectoryName(package.SaveFileName));
                }

                npkg = SimPe.Plugin.Tool.Dockable.ObjectWorkshopHelper.CreatCloneByCres(mmat.ModelName);
                try
                {
                    foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in package.Index)
                    {
                        SimPe.Interfaces.Files.IPackedFileDescriptor npfd = pfd.Clone();
                        npfd.UserData = package.Read(pfd).UncompressedData;
                        if (pfd == mmat.FileDescriptor)
                        {
                            mmat.ProcessData(npfd, npkg);
                        }

                        npkg.Add(npfd, true);
                    }

                    fii.AddIndexFromPackage(npkg, true);
                    //fii.WriteContentToConsole();

                    return(RenderScene(mmat));
                }
                finally
                {
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                Wait.Stop();
                if (MessageBox.Show("The Microsoft Managed DirectX Extensions were not found on your System. Without them, the Preview is not available.\n\nYou can install them manually, by extracting the content of the DirectX\\ManagedDX.CAB on your Sims 2 Installation CD #1. If you double click on the extracted msi File, all needed Files will be installed.\n\nYou can also let SimPE install it automatically. SimPE will download the needed Files (3.5MB) from the SimPE Homepage and install them. Do you want SimPE to download and install the Files?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    if (WebUpdate.InstallMDX())
                    {
                        MessageBox.Show("Managed DirectX Extension were installed succesfully!");
                    }
                }

                return(null);
            }


            //return null;
        }
Exemple #3
0
        SimPe.Interfaces.Scenegraph.IScenegraphItem BuildMmat(SimPe.Interfaces.Files.IPackedFileDescriptor pfd, SimPe.Interfaces.Files.IPackageFile pkg, GraphItem gi)
        {
            SimPe.Plugin.MmatWrapper mmat = new MmatWrapper();
            mmat.ProcessData(pfd, pkg);

            gi.Text = mmat.GetSaveItem("subsetName").StringValue + " (family=" + mmat.GetSaveItem("family").StringValue + ", objectStateIndex=" + Helper.HexString(mmat.GetSaveItem("objectStateIndex").UIntegerValue) + ", materialStateFlags=" + Helper.HexString(mmat.GetSaveItem("materialStateFlags").UIntegerValue) + ", objectGuid=" + Helper.HexString(mmat.GetSaveItem("objectGUID").UIntegerValue) + ")";
            gi.Properties["Default"].Value = mmat.GetSaveItem("defaultMaterial").BooleanValue.ToString();
            gi.Properties["cres"].Value    = mmat.GetSaveItem("modelName").StringValue.ToString();
            gi.Properties["txmt"].Value    = mmat.GetSaveItem("name").StringValue.ToString();

            gi.Size = new Size(gi.Size.Width, 96);
            gi.Tag  = mmat;
            return(mmat);
        }
Exemple #4
0
        /// <summary>
        /// Return al Hashtable (subset) of Hashtable (family) of ArrayLists (mmat Files) specifiying all available Material Overrides
        /// </summary>
        /// <param name="pkg">The package you want to scan</param>
        /// <returns>The Hashtable</returns>
        public static Hashtable GetMMATMap(SimPe.Interfaces.Files.IPackageFile pkg)
        {
            if (pkg == null)
            {
                return(new Hashtable());
            }

            SimPe.Interfaces.Files.IPackedFileDescriptor[] mmats = pkg.FindFiles(Data.MetaData.MMAT);
            Hashtable ht = new Hashtable();

            foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in mmats)
            {
                SimPe.Plugin.MmatWrapper mmat = new MmatWrapper();
                mmat.ProcessData(pfd, pkg);

                string subset = mmat.GetSaveItem("subsetName").StringValue.Trim().ToLower();
                string family = mmat.GetSaveItem("family").StringValue;

                //get the available families
                Hashtable families = null;
                if (!ht.ContainsKey(subset))
                {
                    families   = new Hashtable();
                    ht[subset] = families;
                }
                else
                {
                    families = (Hashtable)ht[subset];
                }

                //get listing of the current Family
                ArrayList list = null;
                if (!families.ContainsKey(family))
                {
                    list             = new ArrayList();
                    families[family] = list;
                }
                else
                {
                    list = (ArrayList)families[family];
                }

                //add the MMAT File
                list.Add(mmat);
            }

            return(ht);
        }
Exemple #5
0
        /// <summary>
        /// Updates the MMATGuids
        /// </summary>
        /// <param name="guids">list of allowed GUIDS</param>
        /// <param name="primary">the guid you want to use if the guid was not allowed</param>
        public void UpdateMMATGuids(ArrayList guids, uint primary)
        {
            if (primary == 0)
            {
                return;
            }

            SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(Data.MetaData.MMAT);

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                SimPe.Plugin.MmatWrapper mmat = new MmatWrapper();
                mmat.ProcessData(pfd, package);


                //this seems to cause problems with slave Objects

                /*if (!guids.Contains(mmat.ObjectGUID))
                 * {
                 *      mmat.ObjectGUID = primary;
                 *      mmat.SynchronizeUserData();
                 * }*/
            }
        }
Exemple #6
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
            }
        }