コード例 #1
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);
                }
            }
        }
コード例 #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;
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
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
            }
        }
コード例 #5
0
        private void ImportFiles(object sender, System.EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            //first find the highest Instance of a BHAV, BCON in the package
            Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(Data.MetaData.BHAV_FILE);
            uint maxbhavinst = 0x1000;

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                if ((pfd.Instance < 0x2000) && (pfd.Instance > maxbhavinst))
                {
                    maxbhavinst = pfd.Instance;
                }
            }
            Hashtable bhavalias = new Hashtable();

            maxbhavinst++;

            //her is the BCOn part
            pfds = package.FindFiles(0x42434F4E);
            uint maxbconinst = 0x1000;

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                if ((pfd.Instance < 0x2000) && (pfd.Instance > maxbconinst))
                {
                    maxbconinst = pfd.Instance;
                }
            }
            Hashtable bconalias = new Hashtable();

            maxbconinst++;


            ArrayList bhavs = new ArrayList();
            ArrayList ttabs = new ArrayList();

            package.BeginUpdate();
            try
            {
                for (int i = 0; i < lbfiles.Items.Count; i++)
                {
                    if (!lbfiles.GetItemChecked(i))
                    {
                        continue;
                    }
                    Interfaces.Scenegraph.IScenegraphFileIndexItem item = (Interfaces.Scenegraph.IScenegraphFileIndexItem)lbfiles.Items[i];
                    SimPe.Packages.PackedFileDescriptor            npfd = new SimPe.Packages.PackedFileDescriptor();
                    npfd.Type     = item.FileDescriptor.Type;
                    npfd.Group    = item.FileDescriptor.Group;
                    npfd.Instance = item.FileDescriptor.Instance;
                    npfd.SubType  = item.FileDescriptor.SubType;
                    npfd.UserData = item.Package.Read(item.FileDescriptor).UncompressedData;
                    package.Add(npfd);

                    if (npfd.Type == Data.MetaData.BHAV_FILE)
                    {
                        maxbhavinst++;
                        npfd.Group = 0xffffffff;
                        bhavalias[(ushort)npfd.Instance] = (ushort)maxbhavinst;
                        npfd.Instance = maxbhavinst;

                        SimPe.Plugin.Bhav bhav = new SimPe.Plugin.Bhav(prov.OpcodeProvider);
                        bhav.ProcessData(npfd, package);
                        if (cbname.Checked)
                        {
                            bhav.FileName = "[" + cbsemi.Text + "] " + bhav.FileName;
                        }
                        bhav.SynchronizeUserData();

                        bhavs.Add(bhav);
                    }
                    else if (npfd.Type == 0x42434F4E)                     //BCON
                    {
                        npfd.Instance = maxbconinst++;
                        npfd.Group    = 0xffffffff;
                        bconalias[(ushort)npfd.Instance] = (ushort)npfd.Instance;

                        SimPe.Plugin.Bcon bcon = new SimPe.Plugin.Bcon();
                        bcon.ProcessData(npfd, package);
                        if (cbname.Checked)
                        {
                            bcon.FileName = "[" + cbsemi.Text + "] " + bcon.FileName;
                        }
                        bcon.SynchronizeUserData();
                    }
                    else if (npfd.Type == 0x54544142)                      //TTAB
                    {
                        SimPe.Plugin.Ttab ttab = new SimPe.Plugin.Ttab(prov.OpcodeProvider);
                        ttab.ProcessData(npfd, package);

                        ttabs.Add(ttab);
                    }
                }

                if (cbfix.Checked)
                {
                    pfds = package.FindFiles(Data.MetaData.BHAV_FILE);
                    foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                    {
                        SimPe.Plugin.Bhav bhav = new SimPe.Plugin.Bhav(prov.OpcodeProvider);
                        bhav.ProcessData(pfd, package);

                        bhavs.Add(bhav);
                    }

                    pfds = package.FindFiles(0x54544142);
                    foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                    {
                        SimPe.Plugin.Ttab ttab = new SimPe.Plugin.Ttab(prov.OpcodeProvider);
                        ttab.ProcessData(pfd, package);

                        ttabs.Add(ttab);
                    }
                }

                //Relink all SemiGlobals in imported BHAV's
                foreach (SimPe.Plugin.Bhav bhav in bhavs)
                {
                    foreach (SimPe.PackedFiles.Wrapper.Instruction i in bhav)
                    {
                        if (bhavalias.Contains(i.OpCode))
                        {
                            i.OpCode = (ushort)bhavalias[i.OpCode];
                        }
                    }
                    bhav.SynchronizeUserData();
                }

                //Relink all TTAbs
                foreach (SimPe.Plugin.Ttab ttab in ttabs)
                {
                    foreach (SimPe.PackedFiles.Wrapper.TtabItem item in ttab)
                    {
                        if (bhavalias.Contains(item.Guardian))
                        {
                            item.Guardian = (ushort)bhavalias[item.Guardian];
                        }
                        if (bhavalias.Contains(item.Action))
                        {
                            item.Action = (ushort)bhavalias[item.Action];
                        }
                    }
                    ttab.SynchronizeUserData();
                }
            }
            finally
            {
                package.EndUpdate();
            }
            this.Cursor = Cursors.Default;
            Close();
        }