Exemple #1
0
        protected void FixXObject(Hashtable namemap, Hashtable refmap, string grphash)
        {
            //set list of critical types
            uint[] types = new uint[] { Data.MetaData.REF_FILE };

            SimPe.Plugin.RefFile fl = new RefFile();

            //now fix the texture References in those Resources
            foreach (uint t in types)
            {
                SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(t);
                foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                {
                    fl.ProcessData(pfd, package);

                    foreach (SimPe.Packages.PackedFileDescriptor rfi in fl.Items)
                    {
                        string name = this.BuildRefString(rfi);
                        SimPe.Interfaces.Files.IPackedFileDescriptor npfd = (SimPe.Interfaces.Files.IPackedFileDescriptor)refmap[name];
                        if (npfd != null)
                        {
                            rfi.Group        = npfd.Group;
                            rfi.LongInstance = npfd.LongInstance;
                        }
                    }

                    fl.SynchronizeUserData();
                }
            }
        }
Exemple #2
0
        void LoadTurnOns()
        {
            if (turnons != null)
            {
                return;
            }
            turnons = new System.Collections.Generic.Dictionary <int, string>();

            if (SimPe.PathProvider.Global.EPInstalled < 2)
            {
                return;
            }

            SimPe.Packages.File           pkg = SimPe.Packages.File.LoadFromFile(System.IO.Path.Combine(PathProvider.Global.Latest.InstallFolder, @"TSData\Res\Text\UIText.package"));
            SimPe.PackedFiles.Wrapper.Str str = new Str();
            SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pkg.FindFile(Data.MetaData.STRING_FILE, 0, Data.MetaData.LOCAL_GROUP, 0xe1);

            if (pfd != null)
            {
                str.ProcessData(pfd, pkg);
                SimPe.PackedFiles.Wrapper.StrItemList strs = str.FallbackedLanguageItems(Helper.WindowsRegistry.LanguageCode);

                for (int i = 0; i < strs.Count; i++)
                {
                    turnons[i] = strs[i].Title;
                }
            }
        }
Exemple #3
0
 public SimPe.Interfaces.Plugin.IToolResult ShowDialog(ref SimPe.Interfaces.Files.IPackedFileDescriptor pfd, ref SimPe.Interfaces.Files.IPackageFile package)
 {
     if (!IsReallyEnabled(pfd, package))
     {
         System.Windows.Forms.MessageBox.Show(SimPe.Localization.GetString("This is not an appropriate context in which to use this tool"),
                                              L.Get("pjSML"));
         return(new SimPe.Plugin.ToolResult(false, false));
     }
     Main();
     return(new SimPe.Plugin.ToolResult(false, false));
 }
Exemple #4
0
        SimPe.Interfaces.Plugin.IToolResult ITool.ShowDialog(ref SimPe.Interfaces.Files.IPackedFileDescriptor pfd, ref SimPe.Interfaces.Files.IPackageFile package)
        {
            if (!System.IO.Directory.Exists(PathProvider.Global.NeighborhoodFolder))
            {
                System.Windows.Forms.MessageBox.Show("The Folder " + PathProvider.Global.NeighborhoodFolder + " was not found.\n" +
                                                     "Please specify the correct SaveGame Folder in the Options Dialog.");
                return(new ToolResult(false, false));
            }

            System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
            fbd.Description         = L.Get("ChooseFolder");
            fbd.SelectedPath        = SimPe.PathProvider.SimSavegameFolder;
            fbd.ShowNewFolderButton = true;
            System.Windows.Forms.DialogResult dr = fbd.ShowDialog();
            if (dr != System.Windows.Forms.DialogResult.OK)
            {
                return(new ToolResult(false, false));
            }


            NeighborhoodForm nfm = new NeighborhoodForm();

            nfm.LoadNgbh          = false;
            nfm.ShowBackupManager = false;
            nfm.Text = L.Get("nfmTitle");
            SimPe.Interfaces.Plugin.IToolResult ret = nfm.Execute(ref package, null);

            string hood = "";

            if (nfm.DialogResult == System.Windows.Forms.DialogResult.OK && nfm.SelectedNgbh != null)
            {
                hood = Path.GetFileName(Path.GetDirectoryName(nfm.SelectedNgbh));
            }

            try
            {
                SimPe.WaitingScreen.Wait();
                splash = delegate(string message) { SimPe.WaitingScreen.UpdateMessage(message); };
                Rufio(fbd.SelectedPath, hood, 0);
                return(new SimPe.Plugin.ToolResult(false, false));
            }
            finally
            {
                SimPe.WaitingScreen.Stop();
            }
        }
Exemple #5
0
 public SimPe.Interfaces.Plugin.IToolResult ShowDialog(ref SimPe.Interfaces.Files.IPackedFileDescriptor pfd, ref SimPe.Interfaces.Files.IPackageFile package)
 {
     currentPackage = package;
     if (package == null)
     {
         System.Windows.Forms.MessageBox.Show(SimPe.Localization.GetString("This is not an appropriate context in which to use this tool"),
                                              L.Get("pjSME"));
         return(new SimPe.Plugin.ToolResult(false, false));
     }
     if (packs == null)
     {
         packs = new List <string>();
         SetPacks();
         SimPe.FileTable.FileIndex.FILoad += new EventHandler(FileIndex_FILoad);
     }
     Main();
     return(new SimPe.Plugin.ToolResult(false, false));
 }
Exemple #6
0
        /// <summary>
        /// This adds all second Leve Textures to the Recolor (like normal Maps)
        /// </summary>
        /// <param name="newpkg"></param>
        /// <param name="md"></param>
        protected void AddReferencedTxtr(IPackageFile newpkg, GenericRcol txmt, MaterialDefinition md, string unique)
        {
            foreach (string k in txmt.ReferenceChains.Keys)
            {
                if (k.ToLower() == "stdmatnormalmaptexturename")               //at the moment i only know of NormalMaps that need to be added
                {
                    MaterialDefinitionProperty mdp = md.GetProperty(k);
                    if (mdp != null)
                    {
                        string name = Hashes.StripHashFromName(mdp.Value).Trim();
                        if (!name.EndsWith("_txtr"))
                        {
                            name += "_txtr";
                        }

                        //Console.Write("loading second txtr "+mdp.Name+" = "+mdp.Value);
                        IPackageFile pkg = txmt.Package;
                        SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFile(name, Data.MetaData.TXTR);
                        if (pfds.Length > 0)
                        {
                            SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pfds[0];
                            //Console.Write(" [found in local Package]");

                            GenericRcol txtr = new GenericRcol();
                            txtr.ProcessData(pfd, pkg);

                            AddTxtr(newpkg, txtr, unique, txmt, md);
                        }

                        /*else  //we don't pull from the Filetable, as we expect, that all needed Files are already cloned!
                         * {
                         *      SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item = FileTable.FileIndex.FindFileByName(name, Data.MetaData.TXTR, Hashes.GetHashGroupFromName(mdp.Value, Data.MetaData.GLOBAL_GROUP), true);
                         *      if (item!=null)
                         *      {
                         *              Console.Write(" [found in FileTable]");
                         *      }
                         * }*/


                        //Console.WriteLine();
                    }
                }
            }
        }
Exemple #7
0
        protected override void StartThread()
        {
            lotfi.Load();
            SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = lotfi.FindFile(0x856DDBAC, Data.MetaData.LOCAL_GROUP, 0x35CA0002, null);
            bool run = Wait.Running;

            if (!run)
            {
                Wait.Start();
            }
            Wait.SubStart(items.Length);
            try
            {
                int ct   = 0;
                int step = Math.Max(2, Wait.MaxProgress / 100);
                foreach (SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item in items)
                {
                    if (this.HaveToStop)
                    {
                        break;
                    }


                    SimPe.Interfaces.Files.IPackageFile pkg = item.Package;

                    SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pkg.FindFile(Data.MetaData.STRING_FILE, 0, Data.MetaData.LOCAL_GROUP, 0x00000A46);
                    string name = SimPe.Localization.GetString("Unknown");
                    if (pfd != null)
                    {
                        SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
                        str.ProcessData(pfd, pkg);

                        SimPe.PackedFiles.Wrapper.StrItemList list = str.FallbackedLanguageItems(Helper.WindowsRegistry.LanguageCode);
                        if (list.Count > 0)
                        {
                            name = list[0].Title;
                        }
                    }

                    SimPe.PackedFiles.Wrapper.Picture pic = new SimPe.PackedFiles.Wrapper.Picture();
                    pic.ProcessData(item);

                    uint inst = GetInstanceFromFilename(pkg.SaveFileName);

                    SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] ltxtitems = ngbhfi.FindFile(0x0BF999E7, Data.MetaData.LOCAL_GROUP, inst, null);
                    SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem   ltxt      = null;
                    if (ltxtitems.Length > 0)
                    {
                        ltxt = ltxtitems[0];
                    }

                    LotItem li = new LotItem(inst, name, pic.Image, ltxt);
                    if (LoadingLot != null)
                    {
                        LoadingLot(this, li);
                    }
                    content[li.Instance] = li;
                    ct++;
                    if (ct % step == 0)
                    {
                        Wait.Message  = name;
                        Wait.Progress = ct;
                    }
                }                //foreach
            }
#if !DEBUG
            catch (Exception ex)
            {
                Helper.ExceptionMessage(ex);
            }
#endif
            finally
            {
                Wait.SubStop();
                if (!run)
                {
                    Wait.Stop();
                }
            }

            ended.Set();
        }
Exemple #8
0
        void LoadCollectibles()
        {
            if (collectibles != null)
            {
                return;
            }
            collectibles = new System.Collections.Generic.Dictionary <int, CollectibleAlias>();
            if (SimPe.PathProvider.Global.EPInstalled < 11)
            {
                return;
            }

            SimPe.Packages.File           pkg = SimPe.Packages.File.LoadFromFile(System.IO.Path.Combine(PathProvider.Global.Latest.InstallFolder, @"TSData\Res\Text\UIText.package"));
            SimPe.PackedFiles.Wrapper.Str str = new Str();
            SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pkg.FindFile(Data.MetaData.STRING_FILE, 0, Data.MetaData.LOCAL_GROUP, 0xb7);
            if (pfd != null)
            {
                str.ProcessData(pfd, pkg);
                SimPe.PackedFiles.Wrapper.StrItemList strs = str.FallbackedLanguageItems(Helper.WindowsRegistry.LanguageCode);



                pkg = SimPe.Packages.File.LoadFromFile(System.IO.Path.Combine(PathProvider.Global.Latest.InstallFolder, @"TSData\Res\UI\ui.package"));
                pfd = pkg.FindFile(0, 0, 0xA99D8A11, 0xACDC6300);
                if (pfd != null)
                {
                    try
                    {
                        SimPe.PackedFiles.Wrapper.Xml xml = new SimPe.PackedFiles.Wrapper.Xml();
                        xml.ProcessData(pfd, pkg);


                        string[] lines = xml.Text.Split(new char[] { '\r' });
                        SimPe.PackedFiles.Wrapper.Picture pic = new Picture();
                        SimPe.FileTable.FileIndex.Load();
                        foreach (string fulline in lines)
                        {
                            string line = fulline.ToLower().Trim();
                            if (line.StartsWith("<legacy") && line.IndexOf("enabled\"") > 0 && line.IndexOf("tipres=") >= 0)
                            {
                                line = line.Replace("<legacy", "").Replace(">", "").Trim();
                                string tipres = GetUIListAttribute(line, "tipres");
                                int    index  = Helper.StringToInt32(tipres.Split(new char[] { ',' })[1], 0, 16) & 0xFFFF;
                                int    testnr = (int)((Helper.StringToInt32(tipres.Split(new char[] { ',' })[1], 0, 16) & 0xFFFF0000) >> 16);

                                if (index > 0 && testnr == 0xb7)
                                {
                                    index = CreateCollectibleAlias(strs, pic, line, index);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("ERROR during Voyage Collectible Image Parsing:\n" + e.ToString());
                        if (Helper.DebugMode)
                        {
                            Helper.ExceptionMessage(e);
                        }
                    }
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Compiles a new Package File from the currently stored Information
        /// </summary>
        /// <returns>The MemoryStream representing the new Package File</returns>
        public MemoryStream Build()
        {
            this.LockStream();
            OpenReader();
            System.IO.MemoryStream ms     = new MemoryStream(10000);
            System.IO.BinaryWriter writer = new BinaryWriter(ms);


            //make sure we write the correct Version!
            if ((header.majorversion == 1) && (header.minorversion == 0))
            {
                header.minorversion = 1;
                header.majorversion = 1;
                filelist            = null;
            }

            int oldcount = 0;

            if (this.Index != null)
            {
                oldcount = this.Index.Length;
            }

            //now save the stuff
            header.Save(writer);

            //now save the files
            PackedFileDescriptors tmpindex = new PackedFileDescriptors();
            ArrayList             tmpcmp   = new ArrayList();

            if (this.fileindex == null)
            {
                fileindex = new SimPe.Interfaces.Files.IPackedFileDescriptor[0];
            }

            PrepareCompression();

            foreach (PackedFileDescriptor pfd in this.fileindex)
            {
                pfd.Changed = false;

                //we write the filelist as last File
                if (pfd == this.filelist)
                {
                    continue;
                }
                if (pfd.Type == Data.MetaData.DIRECTORY_FILE)
                {
                    continue;
                }
                if (pfd.MarkForDelete)
                {
                    continue;
                }

                //PackedFileDescriptor newpfd = (PackedFileDescriptor)pfd.Clone();
                PackedFileDescriptor newpfd = (PackedFileDescriptor)pfd;


                PackedFile pf = null;
                if (pfd.MarkForReCompress)
                {
                    try
                    {
                        if (pfd.HasUserdata)
                        {
                            pf         = new PackedFile(PackedFile.Compress(pfd.UserData));
                            pf.uncsize = (uint)pfd.UserData.Length;
                        }
                        else
                        {
                            byte[] data = ((PackedFile)this.Read(pfd)).UncompressedData;
                            pf         = new PackedFile(PackedFile.Compress(data));
                            pf.uncsize = (uint)data.Length;
                        }

                        pf.size       = pf.data.Length;
                        pf.signature  = Data.MetaData.COMPRESS_SIGNATURE;
                        pf.headersize = 9;
                        newpfd.size   = pf.data.Length;
                        newpfd.SetUserData(null, false);

                        //recreate the FileList
                        filelist = null;
                    }
                    catch (Exception ex)
                    {
                        pf          = (PackedFile)this.Read(pfd);
                        newpfd.size = pf.data.Length;
                        newpfd.SetUserData(pfd.UserData, false);

                        if (Helper.DebugMode)
                        {
                            Helper.ExceptionMessage(ex);
                        }
                    }
                }
                else
                {
                    pf          = (PackedFile)this.Read(pfd);
                    newpfd.size = pf.data.Length;
                    newpfd.SetUserData(pfd.UserData, false);
                }

                newpfd.offset            = (uint)writer.BaseStream.Position;
                newpfd.Changed           = false;
                newpfd.MarkForReCompress = false;
                newpfd.fldata            = pf;
                newpfd.WasCompressed     = pf.IsCompressed;



                tmpcmp.Add(pf.IsCompressed);
                tmpindex.Add(newpfd);

                writer.Write(pf.data);
            }

            //Last Entry should be the Filelist
            WriteFileList(writer, ref tmpindex, tmpcmp);

            //create a new Index
            IPackedFileDescriptor[] myindex = new PackedFileDescriptor[tmpindex.Count];
            tmpindex.CopyTo(myindex);

            //write the hole index
            header.HoleIndex.Offset = 0;
            header.HoleIndex.Size   = (int)(header.HoleIndex.ItemSize * 0);
            header.HoleIndex.Count  = 0;
            holeindex = new HoleIndexItem[0];

            //write the packed Fileindex
            header.Index.Offset = (uint)writer.BaseStream.Position;
            header.Index.Size   = (int)(header.Index.ItemSize * myindex.Length);
            header.Index.Count  = myindex.Length;
            SaveIndex(writer, myindex);
            Index = myindex;


            //rewrite Header
            ms.Seek(0, SeekOrigin.Begin);
            header.Save(writer);

            ms.Seek(0, SeekOrigin.Begin);
            this.UnLockStream();
            CloseReader();

            FireIndexEvent();
            if (Index.Length < oldcount)
            {
                this.FireRemoveEvent();
            }
            else if (Index.Length > oldcount)
            {
                this.FireAddEvent();
            }
            return(ms);
        }
Exemple #10
0
        /// <summary>
        /// Loads all package Files in the directory and scans them for Name Informations
        /// </summary>
        public void LoadSimsFromFolder()
        {
            names = new Hashtable();
            if (BasePackage == null)
            {
                return;
            }

            SimPe.PackedFiles.Wrapper.Fami fami = new SimPe.PackedFiles.Wrapper.Fami(null);
            Hashtable al = new Hashtable();

            foreach (uint type in fami.AssignableTypes)
            {
                IPackedFileDescriptor[] list = BasePackage.FindFiles(type);

                foreach (IPackedFileDescriptor pfd in list)
                {
                    fami.ProcessData(pfd, BasePackage);
                    al[(ushort)pfd.Instance] = fami.Name;

                    foreach (uint simid in fami.Members)
                    {
                        Alias a = new Alias(simid, fami.Name);
                        if (!names.Contains(simid))
                        {
                            names.Add(simid, a);
                        }
                    }
                }
            }            //foreach

            ///add unlisted Sims
            foreach (SimPe.PackedFiles.Wrapper.SDesc sdesc in FileTable.ProviderRegistry.SimDescriptionProvider.SimInstance.Values)
            {
                //load extern Fami Name
                if (!names.Contains(sdesc.SimId))
                {
                    if (sdesc.Package.SaveFileName.Trim().ToLower() != BasePackage.SaveFileName.Trim().ToLower())
                    {
                        SimPe.Interfaces.Files.IPackageFile pkg = sdesc.Package;
                        if (pkg != null)
                        {
                            SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pkg.FindFile(fami.AssignableTypes[0], 0, Data.MetaData.LOCAL_GROUP, sdesc.FamilyInstance);
                            if (pfd != null)
                            {
                                fami.ProcessData(pfd, pkg);
                                Alias a = new Alias(sdesc.SimId, fami.Name);
                                names.Add(sdesc.SimId, a);
                            }
                        }
                    }
                    else
                    {
                        object o = al[sdesc.FamilyInstance];
                        if (o != null)
                        {
                            Alias a = new Alias(sdesc.SimId, o.ToString());
                            names.Add(sdesc.SimId, a);
                        }
                    }
                }
            }

            al.Clear();

            /*names = new Alias[al.Count];
             * al.CopyTo(names);*/
        }
Exemple #11
0
 bool ITool.IsEnabled(SimPe.Interfaces.Files.IPackedFileDescriptor pfd, SimPe.Interfaces.Files.IPackageFile package)
 {
     return(true);
 }