示例#1
0
        /// <summary>
        /// Create a 1:1 Clone based on the CRES Name
        /// </summary>
        /// <param name="cres"></param>
        /// <returns></returns>
        public static SimPe.Packages.GeneratableFile CreatCloneByCres(string cres)
        {
            SimPe.Packages.GeneratableFile         package = SimPe.Packages.GeneratableFile.CreateNew();
            SimPe.Interfaces.IAlias                a;
            Interfaces.Files.IPackedFileDescriptor pfd;
            uint            localgroup;
            OWCloneSettings cs;

            ObjectWorkshopHelper.PrepareForClone(package, out a, out localgroup, out pfd, out cs);

            SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
            str.FileDescriptor              = new SimPe.Packages.PackedFileDescriptor();
            str.FileDescriptor.Type         = Data.MetaData.STRING_FILE;
            str.FileDescriptor.LongInstance = 0x85;
            str.FileDescriptor.Group        = 0x7F000000;
            package.Add(str.FileDescriptor);

            string name = cres.ToLower().Trim();

            if (!name.EndsWith("_cres"))
            {
                name += "_cres";
            }

            str.FileName = "Model - Names";
            str.Add(new SimPe.PackedFiles.Wrapper.StrToken(0, (byte)Data.MetaData.Languages.English, "", ""));
            str.Add(new SimPe.PackedFiles.Wrapper.StrToken(1, (byte)Data.MetaData.Languages.English, name, ""));
            str.SynchronizeUserData();

            str.FileDescriptor.MarkForDelete = true;

            return(ObjectWorkshopHelper.Start(package, a, ref pfd, localgroup, cs, true));
        }
示例#2
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();
        }
示例#3
0
        /// <summary>
        /// Updates the S2CP ID File with the cuurrent settings
        /// </summary>
        /// <param name="p">The Package to change/read from</param>
        /// <param name="guid">The packages GUID</param>
        /// <param name="name">The Name for the Package (used if the File is created)</param>
        /// <param name="author">Author of this package</param>
        /// <param name="contact">How to contact the Author</param>
        /// <param name="gameguid">The List of original Game Guids</param>
        /// <returns>the stored or the new GlobalGUID</returns>
        public static void UpdateGlobalGuid(File p, string guid, string name, string author, string contact, string gameguid)
        {
            Interfaces.Files.IPackedFileDescriptor pfd = p.FindFile(Data.MetaData.STRING_FILE, 0xffffffff, 0x00000000, 0xffffffff);
            SimPe.PackedFiles.Wrapper.Str          str = null;
            if (pfd == null)
            {
                str = new SimPe.PackedFiles.Wrapper.Str();

                str.FileDescriptor          = new SimPe.Packages.PackedFileDescriptor();
                str.FileDescriptor.Type     = Data.MetaData.STRING_FILE;
                str.FileDescriptor.Group    = 0;
                str.FileDescriptor.SubType  = 0xffffffff;
                str.FileDescriptor.Instance = 0xffffffff;
                str.SynchronizeUserData();
                str.Package = p;

                p.Add(str.FileDescriptor);
            }
            else
            {
                str = new SimPe.PackedFiles.Wrapper.Str();
                str.ProcessData(pfd, p);
            }

            SimPe.PackedFiles.Wrapper.StrLanguageList lng = new SimPe.PackedFiles.Wrapper.StrLanguageList();
            lng.Add(new SimPe.PackedFiles.Wrapper.StrLanguage(1));
            str.Languages = lng;

            if (guid == null)
            {
                guid = System.Guid.NewGuid().ToString();
            }
            str.Items = new SimPe.PackedFiles.Wrapper.StrItemList();
            str.Items.Add(new SimPe.PackedFiles.Wrapper.StrToken(0, lng[0], guid, gameguid));
            str.Items.Add(new SimPe.PackedFiles.Wrapper.StrToken(1, lng[0], author, contact));
            str.Items.Add(new SimPe.PackedFiles.Wrapper.StrToken(2, lng[0], name, ""));

            str.SynchronizeUserData();
        }
示例#4
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();
                }
            }
        }