/// <summary> /// Adds theGlobalGUID Data to the package if it is missing and generates a new GUID for it. /// </summary> /// <param name="p">The Package to change/read from</param> /// <param name="name">The Name for the Package (used if the File is created)</param> /// <param name="title">Title of this Object</param> /// <param name="author">Author of this package</param> /// <param name="contact">How to contact the Author</param> /// <param name="description">Description of this Package</param> /// <param name="gameguid">The List of original Game Guids</param> /// <returns>the stored or the new GlobalGUID</returns> /// <remarks>If the GlobalGUID File does exist, the Data from this File will be returned and no new /// GlobalGUID will be returned</remarks> public static string GetSetGlobalGuid(File p, ref string name, ref string title, ref string author, ref string contact, ref string description, ref string gameguid) { string guid = null; Interfaces.Files.IPackedFileDescriptor pfd = p.FindFile(Data.MetaData.STRING_FILE, 0xffffffff, 0x00000000, 0xffffffff); if (pfd == null) { guid = System.Guid.NewGuid().ToString(); UpdateGlobalGuid(p, guid, name, author, contact, gameguid); } else { guid = GetGlobalGuid(p, ref name, ref title, ref author, ref contact, ref description, ref gameguid); } Interfaces.Files.IPackedFileDescriptor[] pfds = p.FindFiles(Data.MetaData.OBJD_FILE); uint ctssid = 1; uint group = 0xffffffff; if (pfds.Length > 0) { SimPe.PackedFiles.Wrapper.Objd objd = new SimPe.PackedFiles.Wrapper.Objd(null); objd.ProcessData(pfds[0], p); ctssid = objd.CTSSId; group = objd.FileDescriptor.Group; } pfd = p.FindFile(Data.MetaData.CTSS_FILE, 0, group, ctssid); if (pfd == null) { UpdateGlobalGuid(p, title, description); } else { guid = GetGlobalGuid(p, ref name, ref title, ref author, ref contact, ref description, ref gameguid); } return(guid); }
/// <summary> /// Add a MMAT to the package /// </summary> protected SimPe.PackedFiles.Wrapper.Cpf AddMMAT(SimPe.Plugin.Rcol matd, string subset, string cresname, uint instance, bool substate) { //now add the default MMAT System.IO.BinaryReader br = new System.IO.BinaryReader(this.GetType().Assembly.GetManifestResourceStream("SimPe.Plugin.mmat.simpe")); SimPe.Packages.PackedFileDescriptor pfd1 = new SimPe.Packages.PackedFileDescriptor(); pfd1.Group = 0xffffffff; pfd1.SubType = 0x00000000; pfd1.Instance = instance; pfd1.Type = 0x4C697E5A; //MMAT pfd1.UserData = br.ReadBytes((int)br.BaseStream.Length); package.Add(pfd1); SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf(); mmat.ProcessData(pfd1, package); if (!substate) { mmat.GetSaveItem("family").StringValue = System.Guid.NewGuid().ToString(); } mmat.GetSaveItem("name").StringValue = matd.FileName.Substring(0, matd.FileName.Length - 5); mmat.GetSaveItem("subsetName").StringValue = subset; mmat.GetSaveItem("modelName").StringValue = cresname; //Get the GUID Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(Data.MetaData.OBJD_FILE); mmat.GetSaveItem("objectGUID").UIntegerValue = 0x00000000; foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds) { SimPe.PackedFiles.Wrapper.Objd objd = new SimPe.PackedFiles.Wrapper.Objd(null); objd.ProcessData(pfds[0], package); mmat.GetSaveItem("objectGUID").UIntegerValue = objd.SimId; if (pfd.Instance == 0x000041A7) { break; } } ObjectRecolor.FixMMAT(mmat); mmat.SynchronizeUserData(); gm_pkg.Add(mmat.FileDescriptor); //alternate states if (!substate) { string name = mmat.GetSaveItem("name").StringValue; pfds = ObjectCloner.FindStateMatchingMatd(name, package); if (pfds != null) { if (pfds.Length > 0) { SimPe.Plugin.Rcol submatd = new GenericRcol(null, false); submatd.ProcessData(pfds[0], package); SimPe.PackedFiles.Wrapper.Cpf mmat2 = AddMMAT(submatd, subset, cresname, instance, true); mmat2.GetSaveItem("family").StringValue = mmat.GetSaveItem("family").StringValue; } } } return(mmat); }
/// <summary> /// Reads the Guid from the Package /// </summary> /// <param name="p">The Package to load the Guid From</param> /// <param name="name">Returns the name stored in te package</param> /// <param name="title">The Title of this package</param> /// <param name="author">Author of this package</param> /// <param name="contact">How to contact the Author</param> /// <param name="description">Description of this Package</param> /// <param name="gameguid">The List of original Game Guids</param> /// <returns>null if no GUID Data was found, otherwise null</returns> public static string GetGlobalGuid(File p, ref string name, ref string title, ref string author, ref string contact, ref string description, ref string gameguid) { string guid = null; Interfaces.Files.IPackedFileDescriptor pfd = p.FindFile(Data.MetaData.STRING_FILE, 0xffffffff, 0x00000000, 0xffffffff); if (pfd != null) { SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str(); str.ProcessData(pfd, p); SimPe.PackedFiles.Wrapper.StrItemList sitems = str.LanguageItems(1); if (sitems.Length > 0) { guid = sitems[0].Title; gameguid = sitems[0].Description; } else { guid = System.Guid.NewGuid().ToString(); } if (sitems.Length > 1) { author = sitems[1].Title; contact = sitems[1].Description; } if (sitems.Length > 2) { name = sitems[1].Title; } } //Title and Description is stored in the CatalogString Interfaces.Files.IPackedFileDescriptor[] pfds = p.FindFiles(Data.MetaData.OBJD_FILE); uint ctssid = 1; uint group = 0xffffffff; if (pfds.Length > 0) { SimPe.PackedFiles.Wrapper.Objd objd = new SimPe.PackedFiles.Wrapper.Objd(null); objd.ProcessData(pfds[0], p); ctssid = objd.CTSSId; group = objd.FileDescriptor.Group; } pfd = p.FindFile(Data.MetaData.CTSS_FILE, 0, group, ctssid); if (pfd != null) { SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str(); str.ProcessData(pfd, p); SimPe.PackedFiles.Wrapper.StrItemList sitems = str.LanguageItems(1); if (sitems.Length > 0) { title = sitems[0].Title; } if (sitems.Length > 1) { description = sitems[1].Title; } } return(guid); }
/// <summary> /// Updates the S2CP ID File with the cuurrent settings /// </summary> /// <param name="p">The Package to change/read from</param> /// <param name="title">Title of this Object</param> /// <param name="description">Description of this Package</param> /// <returns>the stored or the new GlobalGUID</returns> public static void UpdateGlobalGuid(File p, string title, string description) { Interfaces.Files.IPackedFileDescriptor pfd = null; SimPe.PackedFiles.Wrapper.Str str = null; SimPe.PackedFiles.Wrapper.StrLanguage[] lng = new SimPe.PackedFiles.Wrapper.StrLanguage[1]; lng[0] = new SimPe.PackedFiles.Wrapper.StrLanguage(1); //Title and Description is stored in the CatalogString Interfaces.Files.IPackedFileDescriptor[] pfds = p.FindFiles(Data.MetaData.OBJD_FILE); uint ctssid = 1; uint group = 0xffffffff; if (pfds.Length > 0) { SimPe.PackedFiles.Wrapper.Objd objd = new SimPe.PackedFiles.Wrapper.Objd(null); objd.ProcessData(pfds[0], p); ctssid = objd.CTSSId; group = objd.FileDescriptor.Group; } pfd = p.FindFile(Data.MetaData.CTSS_FILE, 0, group, ctssid); if (pfd == null) { str = new SimPe.PackedFiles.Wrapper.Str(); str.FileDescriptor = new SimPe.Packages.PackedFileDescriptor(); str.FileDescriptor.Type = Data.MetaData.CTSS_FILE; str.FileDescriptor.Group = 0xffffffff; str.FileDescriptor.SubType = 0x00000000; str.FileDescriptor.Instance = 0x1; str.Languages.Add(lng[0]); p.Add(str.FileDescriptor); } else { str = new SimPe.PackedFiles.Wrapper.Str(); str.ProcessData(pfd, p); } SimPe.PackedFiles.Wrapper.StrItemList items = str.LanguageItems(1); if (str.Items.Length > 0) { str.Items[0].Title = title; } else { str.Add(new SimPe.PackedFiles.Wrapper.StrToken(0, lng[0], title, "")); } if (str.Items.Length > 1) { str.Items[1].Title = description; } else { str.Add(new SimPe.PackedFiles.Wrapper.StrToken(1, lng[0], description, "")); } str.SynchronizeUserData(); }
/// <summary> /// Show the Relink Screen /// </summary> /// <param name="path">The Path where to look for character Files</param> /// <param name="wrp">The Sim Description Wrapper</param> /// <returns>The new SimID</returns> public static uint Execute(SimPe.PackedFiles.Wrapper.SDesc wrp) { Hashtable ht = wrp.nameprovider.StoredData; SimRelinkForm srf = new SimRelinkForm(); WaitingScreen.Wait(); try { foreach (SimPe.Data.Alias a in ht.Values) { ListViewItem lvi = new ListViewItem(a.Name + " " + (string)a.Tag[2]); lvi.Tag = a; if (a.Tag[1] != null) { lvi.ImageIndex = srf.ilist.Images.Count; Image img = SimPe.Plugin.ImageLoader.Preview((Image)a.Tag[1], srf.ilist.ImageSize); if (wrp.sdescprovider.FindSim(a.Id) != null) { Graphics gr = Graphics.FromImage(img); gr.FillRectangle(new Pen(Color.FromArgb(0x60, Color.Red), 1).Brush, 0, 0, img.Width, img.Height); } srf.ilist.Images.Add(img); } srf.lv.Items.Add(lvi); } srf.lv.Sort(); srf.btlink.Enabled = false; srf.ok = false; } finally { WaitingScreen.Stop(srf); } srf.ShowDialog(); if (srf.ok) { SimPe.Data.Alias a = (SimPe.Data.Alias)srf.lv.SelectedItems[0].Tag; SimPe.Packages.GeneratableFile pkg = SimPe.Packages.GeneratableFile.LoadFromFile((string)a.Tag[0]); Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFiles(Data.MetaData.OBJD_FILE); if (pfds.Length == 1) { SimPe.PackedFiles.Wrapper.Objd objd = new SimPe.PackedFiles.Wrapper.Objd(null); objd.ProcessData(pfds[0], pkg); if (srf.cbfile.Checked) { objd.Guid = wrp.SimId; objd.SynchronizeUserData(); pkg.Save(); } else { wrp.SimId = objd.Guid; } } } return(wrp.SimId); }