Exemple #1
0
        protected static void UpdateDescription(OWCloneSettings cs, SimPe.PackedFiles.Wrapper.Str str)
        {
            str.ClearNonDefault();
            while (str.Items.Length < 2)
            {
                str.Add(new SimPe.PackedFiles.Wrapper.StrToken(str.Items.Length, 1, "", ""));
            }

            str.Items[0].Title = cs.Title;
            str.Items[1].Title = cs.Description;

            str.SynchronizeUserData();
        }
Exemple #2
0
        /// <summary>
        /// Runs the Fix Operation
        /// </summary>
        /// <param name="map">the map we have to use for name Replacements</param>
        /// <param name="uniquefamily">change the family values in the MMAT Files</param>
        public void Fix(Hashtable map, bool uniquefamily)
        {
            string grouphash = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!";        //"#0x"+Helper.HexString(package.FileGroupHash)+"!";


            Hashtable refmap         = new Hashtable();
            Hashtable completerefmap = new Hashtable();

            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Fixing Names");
            }
            FixNames(map);

            foreach (uint type in Data.MetaData.RcolList)
            {
                Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(type);

                //build a List of RefItems
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    SimPe.Plugin.Rcol rcol = new GenericRcol(null, false);
                    rcol.ProcessData(pfd, package);

                    //rcol.FileName = Hashes.StripHashFromName(rcol.);

                    /*if (types.Contains(pfd.Type)) rcol. = Hashes.StripHashFromName(rcol.);
                     * else rcol.FileName = grouphash + Hashes.StripHashFromName(rcol.FileName);*/

                    foreach (Interfaces.Files.IPackedFileDescriptor rpfd in rcol.ReferencedFiles)
                    {
                        string refstr = BuildRefString(rpfd);
                        if (!refmap.Contains(refstr))
                        {
                            refmap.Add(refstr, null);
                        }
                    }
                    //rcol.SynchronizeUserData();
                }
            }

            //Updated TGI Values and update the refmap
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Updating TGI Values");
            }
            foreach (uint type in Data.MetaData.RcolList)
            {
                Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(type);

                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    string            refstr = BuildRefString(pfd);
                    SimPe.Plugin.Rcol rcol   = new GenericRcol(null, false);
                    rcol.ProcessData(pfd, package);

                    //rcol.FileName = grouphash + Hashes.StripHashFromName(rcol.);
                    rcol.FileDescriptor.Instance = Hashes.InstanceHash(Hashes.StripHashFromName(rcol.FileName));
                    rcol.FileDescriptor.SubType  = Hashes.SubTypeHash(Hashes.StripHashFromName(rcol.FileName));

                    if (refmap.Contains(refstr))
                    {
                        refmap[refstr] = rcol.FileDescriptor;
                    }
                    completerefmap[refstr] = rcol.FileDescriptor;
                }
            }

            //Update the References
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Updating TGI References");
            }
            foreach (uint type in Data.MetaData.RcolList)
            {
                Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(type);

                foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    SimPe.Plugin.Rcol rcol = new GenericRcol(null, false);
                    rcol.ProcessData(pfd, package);

                    foreach (Interfaces.Files.IPackedFileDescriptor rpfd in rcol.ReferencedFiles)
                    {
                        string refstr = Helper.HexString(rpfd.Group) + Helper.HexString(rpfd.Type) + Helper.HexString(rpfd.Instance) + Helper.HexString(rpfd.SubType);

                        if (ver == FixVersion.UniversityReady2)
                        {
                            if (types.Contains(rpfd.Type))
                            {
                                rpfd.Group = Data.MetaData.CUSTOM_GROUP;
                            }
                            else
                            {
                                rpfd.Group = Data.MetaData.LOCAL_GROUP;
                            }
                        }
                        else
                        {
                            if (rpfd.Type != Data.MetaData.ANIM)
                            {
                                rpfd.Group = Data.MetaData.CUSTOM_GROUP;
                            }
                            else
                            {
                                rpfd.Group = Data.MetaData.GLOBAL_GROUP;
                            }
                        }

                        if (refmap.Contains(refstr))
                        {
                            Interfaces.Files.IPackedFileDescriptor npfd = (Interfaces.Files.IPackedFileDescriptor)refmap[refstr];
                            if (npfd != null)
                            {
                                rpfd.Instance = npfd.Instance;
                                rpfd.SubType  = npfd.SubType;
                            }
                        }
                    }                     //foreach

                    rcol.SynchronizeUserData();
                }
            }

            //Make sure XObjects and Skins get Fixed Too
            FixXObject(map, completerefmap, grouphash);
            FixSkin(map, completerefmap, grouphash);

            //Make sure MMATs get fixed
            FixMMAT(map, uniquefamily, grouphash);

            //Make sure OBJd's get fixed too
            FixOBJd();

            //And finally the Root String
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Updating Root");
            }
            SimPe.Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.STRING_FILE);
            string modelname = null;

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds)
            {
                SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
                str.ProcessData(pfd, package);

                foreach (SimPe.PackedFiles.Wrapper.StrToken i in str.Items)
                {
                    string name = Hashes.StripHashFromName(i.Title.Trim().ToLower());

                    if (name == "")
                    {
                        continue;
                    }
                    if (pfd.Instance == 0x88)
                    {
                        if (!name.EndsWith("_txmt"))
                        {
                            name += "_txmt";
                        }
                    }
                    else if (pfd.Instance == 0x85)
                    {
                        if (!name.EndsWith("_cres"))
                        {
                            name += "_cres";
                        }
                    }
                    else if ((pfd.Instance == 0x81) || (pfd.Instance == 0x82) || (pfd.Instance == 0x86) || (pfd.Instance == 0x192))
                    {
                        if (!name.EndsWith("_anim"))
                        {
                            name += "_anim";
                        }
                    }
                    else
                    {
                        continue;
                    }


                    string newref = (string)map[name];
                    if (newref != null)
                    {
                        i.Title = Hashes.StripHashFromName(newref.Substring(0, newref.Length - 5));
                    }
                    else
                    {
                        i.Title = Hashes.StripHashFromName(i.Title);
                    }

                    if (((ver == FixVersion.UniversityReady) || (pfd.Instance == 0x88)) && (newref != null))
                    {
                        i.Title = Hashes.StripHashFromName(i.Title);

                        if (!((pfd.Instance == 0x81) || (pfd.Instance == 0x82) || (pfd.Instance == 0x86) || (pfd.Instance == 0x192)))
                        {
                            i.Title = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + i.Title;
                        }
                    }
                    else
                    {
                        uint tp = Data.MetaData.ANIM;
                        if (pfd.Instance == 0x88)
                        {
                            tp = Data.MetaData.TXMT;
                        }
                        else if (pfd.Instance == 0x85)
                        {
                            tp = Data.MetaData.CRES;
                        }

                        SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem fii = FileTable.FileIndex.FindFileByName(i.Title, tp, Data.MetaData.LOCAL_GROUP, true);
                        if (fii != null)
                        {
                            if (fii.FileDescriptor.Group == Data.MetaData.CUSTOM_GROUP)
                            {
                                i.Title = "##0x" + Helper.HexString(Data.MetaData.CUSTOM_GROUP) + "!" + Hashes.StripHashFromName(i.Title);
                            }
                        }
                    }

                    if ((modelname == null) && (i.Language.Id == 1) && (pfd.Instance == 0x85))
                    {
                        modelname = name.ToUpper().Replace("-", "_");
                    }
                }

                if (RemoveNonDefaultTextReferences)
                {
                    if (pfd.Instance == 0x88 || pfd.Instance == 0x85 || (pfd.Instance == 0x81) || (pfd.Instance == 0x82) || (pfd.Instance == 0x86) || (pfd.Instance == 0x192))
                    {
                        str.ClearNonDefault();
                    }
                }


                str.SynchronizeUserData();
            }

            //Now change the NREF

            if (modelname != null)
            {
                mpfds = package.FindFiles(0x4E524546);
                foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds)
                {
                    SimPe.PackedFiles.Wrapper.Nref nref = new SimPe.PackedFiles.Wrapper.Nref();
                    nref.ProcessData(pfd, package);
                    if (ver == FixVersion.UniversityReady)
                    {
                        nref.FileName = "SIMPE_" + modelname;
                    }
                    else
                    {
                        nref.FileName = "SIMPE_v2_" + modelname;
                    }

                    nref.SynchronizeUserData();
                }
            }
        }