public static Image GetXThumbnail(SimPe.PackedFiles.Wrapper.Cpf cpf) { if (xthumbs == null) { xthumbs = SimPe.Packages.File.LoadFromFile(System.IO.Path.Combine(PathProvider.SimSavegameFolder, "Thumbnails\\BuildModeThumbnails.package")); } SimPe.Packages.File tmbs = xthumbs; Data.XObjFunctionSubSort fss = GetFunctionSort(cpf); uint inst = cpf.GetSaveItem("guid").UIntegerValue; uint grp = cpf.FileDescriptor.Group; if (cpf.GetItem("thumbnailinstanceid") != null) { inst = cpf.GetSaveItem("thumbnailinstanceid").UIntegerValue; grp = cpf.GetSaveItem("thumbnailgroupid").UIntegerValue; } //get Thumbnail Type uint[] types = new uint[] { 0x8C311262, 0x8C31125E }; //floors, walls if (fss == Data.XObjFunctionSubSort.Roof) { types = new uint[] { 0xCC489E46 } } ; else if (fss == Data.XObjFunctionSubSort.Fence_Rail || fss == Data.XObjFunctionSubSort.Fence_Halfwall) { types = new uint[] { 0xCC30CDF8 } } ; else if (fss == Data.XObjFunctionSubSort.Roof) { types = new uint[] { 0xCC489E46 } } ; else if (fss == Data.XObjFunctionSubSort.Terrain) { types = new uint[] { 0xEC3126C4 }; if (cpf.GetItem("texturetname") != null) { inst = Hashes.GetCrc32(Hashes.StripHashFromName(cpf.GetItem("texturetname").StringValue.Trim().ToLower())); } } else if (cpf.FileDescriptor.Type == Data.MetaData.XNGB) { types = new uint[] { 0x4D533EDD }; if (nthumbs == null) { nthumbs = SimPe.Packages.File.LoadFromFile(System.IO.Path.Combine(PathProvider.SimSavegameFolder, "Thumbnails\\CANHObjectsThumbnails.package")); } tmbs = nthumbs; } return(GetThumbnail(cpf.GetSaveItem("name").StringValue, types, grp, inst, tmbs)); //tmbs = null; }
public ColorOptionsItem(SimPe.PackedFiles.Wrapper.Cpf mmat) { this.MMAT = mmat; Subset = mmat.GetSaveItem("subsetName").StringValue.Trim().ToLower(); Family = mmat.GetSaveItem("family").StringValue.Trim().ToLower(); Guid = mmat.GetSaveItem("objectGUID").UIntegerValue; Default = mmat.GetSaveItem("defaultMaterial").BooleanValue; matd = null; }
/// <summary> /// /// </summary> /// <param name="cs"></param> /// <param name="cpf"></param> /// <returns>ResourceDescriptor for the references String</returns> protected static SimPe.Interfaces.Files.IPackedFileDescriptor UpdateDescription(OWCloneSettings cs, SimPe.Packages.GeneratableFile package, SimPe.PackedFiles.Wrapper.Cpf cpf) { cpf.GetSaveItem("cost").UIntegerValue = (uint)cs.Price; cpf.GetSaveItem("name").StringValue = cs.Title.Replace("\n", " ").Replace("\t", " ").Replace("\r", " "); cpf.GetSaveItem("description").StringValue = cs.Description.Replace("\n", " ").Replace("\t", " ").Replace("\r", " "); cpf.SynchronizeUserData(); SimPe.Interfaces.Files.IPackedFileDescriptor pfd = package.FindFile(cpf.GetSaveItem("stringsetrestypeid").UIntegerValue, 0, cpf.GetSaveItem("stringsetgroupid").UIntegerValue, cpf.GetSaveItem("stringsetid").UIntegerValue); return(pfd); }
/// <summary> /// Add Resources referenced from XML Files /// </summary> /// <param name="names"></param> public void AddFromXml(SimPe.Interfaces.Files.IPackageFile pkg) { SimPe.Interfaces.Files.IPackedFileDescriptor[] index = (SimPe.Interfaces.Files.IPackedFileDescriptor[])pkg.Index.Clone(); foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in index) { SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf(); if (!cpf.CanHandleType(pfd.Type)) { continue; } cpf.ProcessData(pfd, pkg); //xobj AddFromXml(cpf.GetItem("material"), "_txmt", Data.MetaData.TXMT); //hood object if (pfd.Type == Data.MetaData.XNGB) { AddFromXml(cpf.GetItem("modelname"), "_cres", Data.MetaData.CRES); } //fences AddFromXml(cpf.GetItem("diagrail"), "_cres", Data.MetaData.CRES); AddFromXml(cpf.GetItem("post"), "_cres", Data.MetaData.CRES); AddFromXml(cpf.GetItem("rail"), "_cres", Data.MetaData.CRES); AddFromXml(cpf.GetItem("diagrail"), "_txmt", Data.MetaData.TXMT); AddFromXml(cpf.GetItem("post"), "_txmt", Data.MetaData.TXMT); AddFromXml(cpf.GetItem("rail"), "_txmt", Data.MetaData.TXMT); //terrain AddFromXml(cpf.GetItem("texturetname"), "_txtr", Data.MetaData.TXTR); AddFromXml(cpf.GetItem("texturetname"), "_detail_txtr", Data.MetaData.TXTR); AddFromXml(cpf.GetItem("texturetname"), "-bump_txtr", Data.MetaData.TXTR); //roof AddFromXml(cpf.GetItem("textureedges"), "_txtr", Data.MetaData.TXTR); AddFromXml(cpf.GetItem("texturetop"), "_txtr", Data.MetaData.TXTR); AddFromXml(cpf.GetItem("texturetopbump"), "_txtr", Data.MetaData.TXTR); AddFromXml(cpf.GetItem("texturetrim"), "_txtr", Data.MetaData.TXTR); AddFromXml(cpf.GetItem("textureunder"), "_txtr", Data.MetaData.TXTR); SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = FileTable.FileIndex.FindFile( cpf.GetSaveItem("stringsetrestypeid").UIntegerValue, cpf.GetSaveItem("stringsetgroupid").UIntegerValue, cpf.GetSaveItem("stringsetid").UIntegerValue, null ); AddFromXml(items); } }
/// <summary> /// Add the MATD referenced by the passed MMAT /// </summary> /// <param name="mmat">A valid MMAT file</param> protected void AddMATD(SimPe.PackedFiles.Wrapper.Cpf mmat) { SimPe.Packages.File pkg = SimPe.Packages.File.LoadFromFile(System.IO.Path.Combine(PathProvider.Global.GetExpansion(Expansions.BaseGame).InstallFolder, "TSData\\Res\\Sims3D\\Objects02.package")); ArrayList list = new ArrayList(); string flname = Hashes.StripHashFromName(mmat.GetSaveItem("name").StringValue) + "_txmt"; Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFile(flname, 0x49596978); foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds) { SimPe.Plugin.Rcol matd = new GenericRcol(null, false); matd.ProcessData(pfd, pkg); if (matd.FileName.Trim().ToLower() == flname.Trim().ToLower()) { matd.SynchronizeUserData(); if (package.FindFile(matd.FileDescriptor) == null) { package.Add(matd.FileDescriptor); } } } //pkg.Reader.Close(); }
private bool FindInField(SimPe.PackedFiles.Wrapper.Cpf cpf, bool found, string fldname) { string n = cpf.GetSaveItem(fldname).StringValue.ToLower(); if (compareType == CompareType.Equal) { found = n == name; } else if (compareType == CompareType.Start) { found = n.StartsWith(name); } else if (compareType == CompareType.End) { found = n.EndsWith(name); } else if (compareType == CompareType.Contain) { found = n.IndexOf(name) > -1; } else if (compareType == CompareType.RegExp && reg != null) { found = reg.IsMatch(n); } return(found); }
public void ExecuteEventHandler(object sender, SimPe.Events.ResourceEventArgs e) { if (!RealChangeEnabledStateEventHandler(null, e)) { System.Windows.Forms.MessageBox.Show(Localization.GetString("This is not an appropriate context in which to use this tool"), Localization.GetString(this.ToString())); return; } if (Message.Show(SimPe.Localization.GetString("Fix_Fence_Warning"), SimPe.Localization.GetString("Warning"), System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) { return; } try { SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = e.LoadedPackage.Package.FindFiles(Data.MetaData.XFNC); foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds) { SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf(); cpf.ProcessData(pfd, e.LoadedPackage.Package); uint guid = cpf.GetSaveItem("guid").UIntegerValue; //load the Descriptor for the String Resource SimPe.Interfaces.Files.IPackedFileDescriptor p = e.LoadedPackage.Package.FindFile( cpf.GetSaveItem("stringsetrestypeid").UIntegerValue, 0, cpf.GetSaveItem("stringsetgroupid").UIntegerValue, cpf.GetSaveItem("stringsetid").UIntegerValue ); //change the Properties cpf.GetSaveItem("resourcegroupid").UIntegerValue = 0x4c8cc5c0; cpf.GetSaveItem("resourceid").UIntegerValue = guid; cpf.GetSaveItem("stringsetgroupid").UIntegerValue = guid; cpf.SynchronizeUserData(true, true); //change the Descriptor for the XML cpf.FileDescriptor.Instance = guid; cpf.FileDescriptor.Group = 0x4c8cc5c0; //change the descriptor for the CTSS if (p != null) { p.Group = guid; } } } catch (Exception ex) { Helper.ExceptionMessage(ex); } }
/// <summary> /// Remove some unreferenced and useless Files /// </summary> public void CleanUp() { if (WaitingScreen.Running) { WaitingScreen.UpdateMessage("Cleaning up"); } Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.MMAT); //MMAT ArrayList mmats = new ArrayList(); foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds) { SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf(); mmat.ProcessData(pfd, package); string content = Scenegraph.MmatContent(mmat); if (!mmats.Contains(content)) { string txmtname = (string)Hashes.StripHashFromName(mmat.GetSaveItem("name").StringValue.Trim().ToLower()) + "_txmt"; string cresname = (string)Hashes.StripHashFromName(mmat.GetSaveItem("modelName").StringValue.Trim().ToLower()); if (package.FindFile(Hashes.StripHashFromName(txmtname), 0x49596978).Length < 0) { pfd.MarkForDelete = true; } if (package.FindFile(Hashes.StripHashFromName(cresname), 0xE519C933).Length < 0) { pfd.MarkForDelete = true; } if (!pfd.MarkForDelete) { mmats.Add(content); } } else { pfd.MarkForDelete = true; } } }
/// <summary> /// Return all Modelnames that can be found in this package /// </summary> /// <param name="pkg">The Package you want to scan</param> /// <returns>a list of Modelnames</returns> public static string[] FindModelNames(SimPe.Interfaces.Files.IPackageFile pkg) { ArrayList names = new ArrayList(); Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFile(Data.MetaData.STRING_FILE, 0, 0x85); if (pfds.Length > 0) { foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds) { SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str(); str.ProcessData(pfd, pkg); foreach (SimPe.PackedFiles.Wrapper.StrToken item in str.Items) { string mname = Hashes.StripHashFromName(item.Title.Trim().ToLower()); if (!mname.EndsWith("_cres")) { mname += "_cres"; } if ((mname != "") && (!names.Contains(mname))) { names.Add(mname); } } } } pfds = pkg.FindFiles(Data.MetaData.MMAT); if (pfds.Length > 0) { foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds) { SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf(); cpf.ProcessData(pfd, pkg); string mname = Hashes.StripHashFromName(cpf.GetSaveItem("modelName").StringValue.Trim().ToLower()); if (!mname.EndsWith("_cres")) { mname += "_cres"; } if ((mname != "") && (!names.Contains(mname))) { names.Add(mname); } } } string[] ret = new string[names.Count]; names.CopyTo(ret); return(ret); }
/// <summary> /// Changes all guids (ignore the current GUID) /// </summary> /// <param name="newguid">The new GUID</param> public void FixGuids(uint newguid) { Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.MMAT); foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds) { SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf(); mmat.ProcessData(pfd, package); mmat.GetSaveItem("objectGUID").UIntegerValue = newguid; mmat.SynchronizeUserData(); } }
/// <summary> /// Changes all guids (Depends on the passed Replacement Map) /// </summary> /// <param name="guids">List of GuidSet Objects</param> public void FixGuids(ArrayList guids) { Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.MMAT); foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds) { SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf(); mmat.ProcessData(pfd, package); if (guids != null) { foreach (GuidSet sget in guids) { if (mmat.GetSaveItem("objectGUID").UIntegerValue == sget.oldguid) { mmat.GetSaveItem("objectGUID").UIntegerValue = sget.guid; mmat.SynchronizeUserData(); } } } } }
/// <summary> /// Find the Modelname of the Original Object /// </summary> /// <param name="package">The Package containing the Data</param> /// <returns>The Modelname</returns> public static string FindMainOldName(SimPe.Interfaces.Files.IPackageFile package) { Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(Data.MetaData.STRING_FILE); foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds) { if (pfd.Instance == 0x85) { SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str(); str.ProcessData(pfd, package); SimPe.PackedFiles.Wrapper.StrItemList sil = str.LanguageItems(1); if (sil.Length > 1) { return(sil[1].Title); } else if (str.Items.Length > 1) { return(str.Items[1].Title); } } } pfds = package.FindFiles(0x4C697E5A); foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds) { SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf(); cpf.ProcessData(pfd, package); if (cpf.GetSaveItem("modelName").StringValue.Trim() != "") { return(cpf.GetSaveItem("modelName").StringValue.Trim()); } } return("SimPE"); }
/// <summary> /// /// </summary> /// <param name="ocpf">The MMAT or Property Set describing the Model</param> /// <returns>The Texture or null</returns> public object FindTxtrName(object ocpf) { SimPe.PackedFiles.Wrapper.Cpf cpf = (SimPe.PackedFiles.Wrapper.Cpf)ocpf; SimPe.PackedFiles.Wrapper.CpfItem item = cpf.GetSaveItem("name"); if (cpf.Package != BasePackage) { string name = FindTxtrName(cpf.FileDescriptor); return(FindUserTxtr(name)); } else { string name = FindTxtrName(item.StringValue + "_txmt"); return(FindTxtr(name)); } }
protected void UpdateXObjScreen(SimPe.Interfaces.Files.IPackageFile pkg, bool clear) { if (clear) { ClearScreen(); } if (cpf == null) { return; } nfo.FirstExpansion = PackageInfo.FileFrom(cpf.FileDescriptor); SetupCategories(SimPe.Cache.ObjectCacheItem.GetCategory(SimPe.Cache.ObjectCacheItemVersions.DockableOW, (SimPe.Data.ObjFunctionSubSort)GetFunctionSort(cpf), Data.ObjectTypes.Normal, SimPe.Cache.ObjectClass.XObject)); nfo.Image = GetXThumbnail(cpf); if (pkg != null) { RenderGmdcPreview(pkg); } SimPe.PackedFiles.Wrapper.StrItemList strs = GetCtssItems(); if (strs != null) { if (strs.Count > 0) { nfo.Name = strs[0].Title; } if (strs.Count > 1) { nfo.Description = strs[1].Title; } } else { nfo.Name = cpf.GetSaveItem("name").StringValue; nfo.Description = cpf.GetSaveItem("description").StringValue; } nfo.Price = (int)cpf.GetSaveItem("cost").UIntegerValue; UpdateScreen(); }
protected void UpdateXObjScreen() { ClearScreen(); if (cpf == null) { return; } this.lbEPs.Visible = this.lbEPList.Visible = false; SetupCategories(SimPe.Cache.ObjectCacheItem.GetCategory(SimPe.Cache.ObjectCacheItemVersions.DockableOW, (SimPe.Data.ObjFunctionSubSort)GetFunctionSort(cpf), Data.ObjectTypes.Normal, SimPe.Cache.ObjectClass.XObject)); pb.Image = null; pb.Image = GenerateImage(pb.Size, GetXThumbnail(cpf), true); SimPe.PackedFiles.Wrapper.StrItemList strs = GetCtssItems(); if (strs != null) { if (strs.Count > 0) { this.lbName.Text = strs[0].Title; } if (strs.Count > 1) { this.lbAbout.Text = strs[1].Title; } } else { this.lbName.Text = cpf.GetSaveItem("name").StringValue; this.lbAbout.Text = cpf.GetSaveItem("description").StringValue; } this.lbPrice.Text = cpf.GetSaveItem("cost").UIntegerValue.ToString() + " $"; if (pb.Image == null) { pb.Image = defimg; } }
void FillCategoryNodes(Hashtable mmap) { WaitingScreen.Wait(); try { FileTable.FileIndex.Load(); Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = FileTable.FileIndex.FindFile(Data.MetaData.GZPS, true); foreach (Interfaces.Scenegraph.IScenegraphFileIndexItem item in items) { SimPe.PackedFiles.Wrapper.Cpf skin = new SimPe.PackedFiles.Wrapper.Cpf(); skin.ProcessData(item); if (skin.GetSaveItem("type").StringValue == "skin") { bool added = false; uint skinage = skin.GetSaveItem("age").UIntegerValue; uint skincat = skin.GetSaveItem("category").UIntegerValue; if ((skincat & (uint)Data.SkinCategories.Skin) == (uint)Data.SkinCategories.Skin) { skincat = (uint)Data.SkinCategories.Skin; } if (skin.GetSaveItem("override0subset").StringValue.Trim().ToLower().StartsWith("hair")) { skincat = (uint)Data.SkinCategories.Skin; } if (skin.GetSaveItem("override0subset").StringValue.Trim().ToLower().StartsWith("bang")) { skincat = (uint)Data.SkinCategories.Skin; } uint skinsex = skin.GetSaveItem("gender").UIntegerValue; string name = skin.GetSaveItem("name").StringValue; foreach (uint age in mmap.Keys) { if ((age & skinage) == age) { Hashtable cats = (Hashtable)mmap[age]; foreach (uint cat in cats.Keys) { if ((cat & skincat) == cat) { Hashtable sex = (Hashtable)cats[cat]; foreach (uint g in sex.Keys) { if ((g & skinsex) == g) { TreeNode parent = (TreeNode)sex[g]; TreeNode node = new TreeNode(name); node.Tag = skin; parent.Nodes.Add(node); added = true; } } } } } } //foreach age if (!added) { TreeNode tn = new TreeNode(name); tn.Tag = skin; tvmale.Nodes.Add(tn); tvfemale.Nodes.Add((TreeNode)tn.Clone()); } } } } finally { WaitingScreen.Stop(); } }
/// <summary> /// Fix all links /// </summary> public string Fix(string family, uint group, ref int ct, Hashtable matdrep, Hashtable txtrrep, ArrayList guids) { //make sure the references are loaded txtr = TXTR; string groups = "#0x" + Helper.HexString(group) + "!"; groups = "##0x1c050000!"; MMAT.GetSaveItem("family").StringValue = family; string matdname = Hashes.StripHashFromName(MMAT.GetSaveItem("name").StringValue) + "_" + family; if (matdrep[MMAT.GetSaveItem("name").StringValue] == null) { matdrep.Add(MMAT.GetSaveItem("name").StringValue, groups + matdname); MMAT.GetSaveItem("name").StringValue = groups + matdname; } else { MMAT.GetSaveItem("name").StringValue = (string)matdrep[MMAT.GetSaveItem("name").StringValue]; } //make sure we use a supported GUID if (guids.Count > 0) { if (!guids.Contains(MMAT.GetSaveItem("objectGUID").UIntegerValue)) { MMAT.GetSaveItem("objectGUID").UIntegerValue = (uint)guids[0]; } } MMAT.GetSaveItem("defaultMaterial").BooleanValue = false; MMAT.FileDescriptor.Instance = (uint)(0x4000 + ct++); MMAT.FileDescriptor.Group = 0xffffffff; string txtrname = groups + "_" + family; string org = ""; if (MATD != null) { MaterialDefinition md = (MaterialDefinition)MATD.Blocks[0]; md.FileDescription = matdname; MATD.FileName = groups + matdname + "_txmt"; SimPe.Packages.PackedFileDescriptor matdpfd = new PackedFileDescriptor(); matdpfd.Type = MATD.FileDescriptor.Type; MATD.FileDescriptor = matdpfd; MATD.FileDescriptor.Group = 0x1c050000; //group; //0x1C0532FA; MATD.FileDescriptor.Instance = Hashes.InstanceHash(Hashes.StripHashFromName(MATD.FileName)); MATD.FileDescriptor.SubType = Hashes.SubTypeHash(Hashes.StripHashFromName(MATD.FileName)); org = TxtrRef; string realtxtrname = ""; //Hashes.StripHashFromName(md.GetProperty("stdMatBaseTextureName").Value); if (TXTR != null) { realtxtrname = Hashes.StripHashFromName(TXTR.FileName); if (realtxtrname.Length > 5) { realtxtrname = realtxtrname.Substring(0, realtxtrname.Length - 5); } } //we foudn a texture if (realtxtrname.Trim() != "") { txtrname = realtxtrname + "_" + family; if (txtrrep[realtxtrname] == null) { txtrrep.Add(realtxtrname, txtrname); txtrrep.Add(txtrname, txtrname); } else { txtrname = (string)txtrrep[realtxtrname]; } md.GetProperty("stdMatBaseTextureName").Value = /*groups +*/ Hashes.StripHashFromName(txtrname); string[] files = new string[1]; files[0] = /*groups +*/ Hashes.StripHashFromName(txtrname); md.Listing = files; } } if (TXTR != null) { TXTR.FileName = groups + txtrname + "_txtr"; SimPe.Packages.PackedFileDescriptor txtrpfd = new PackedFileDescriptor(); txtrpfd.Type = TXTR.FileDescriptor.Type; TXTR.FileDescriptor = txtrpfd; TXTR.FileDescriptor.Group = 0x1c050000; //group; //0x1C0532FA; TXTR.FileDescriptor.Instance = Hashes.InstanceHash(Hashes.StripHashFromName(TXTR.FileName)); TXTR.FileDescriptor.SubType = Hashes.SubTypeHash(Hashes.StripHashFromName(TXTR.FileName)); } return(org); }
/// <summary> /// Create a new Instance and load the main Template Files /// </summary> /// <param name="package"></param> public PhotoStudioTemplate(Interfaces.Files.IPackageFile package) { this.package = package; Interfaces.Files.IPackedFileDescriptor pfd = package.FindFile(0xEBCF3E27, 0xffffffff, 0xffffffff, 0xffffffff); pset = new SimPe.PackedFiles.Wrapper.Cpf(); ctss = null; if (pfd != null) { pset.ProcessData(pfd, package); pfd = package.FindFile(Data.MetaData.CTSS_FILE, 0xffffffff, 0xffffffff, pset.GetSaveItem("description").UIntegerValue); if (pfd != null) { ctss = new SimPe.PackedFiles.Wrapper.Str(); ctss.ProcessData(pfd, package); } } }
/// <summary> /// returns a unique identifier for the MMAT Files /// </summary> /// <param name="mmat"></param> /// <returns></returns> public static string MmatContent(SimPe.PackedFiles.Wrapper.Cpf mmat) { return(mmat.GetSaveItem("modelName").StringValue /*+mmat.GetSaveItem("family").StringValue*/ + mmat.GetSaveItem("subsetName").StringValue + mmat.GetSaveItem("name").StringValue + Helper.HexString(mmat.GetSaveItem("objectStateIndex").UIntegerValue) + Helper.HexString(mmat.GetSaveItem("materialStateFlags").UIntegerValue) + Helper.HexString(mmat.GetSaveItem("objectGUID").UIntegerValue)); }
public static Data.XObjFunctionSubSort GetFunctionSort(SimPe.PackedFiles.Wrapper.Cpf cpf) { string type = cpf.GetSaveItem("type").StringValue.Trim().ToLower(); switch (type) { case "": case "canh": { string stype = cpf.GetSaveItem("sort").StringValue.Trim().ToLower(); if (stype == "landmark") { return(Data.XObjFunctionSubSort.Hood_Landmark); } else if (stype == "flora") { return(Data.XObjFunctionSubSort.Hood_Flora); } else if (stype == "effects") { return(Data.XObjFunctionSubSort.Hood_Effects); } else if (stype == "misc") { return(Data.XObjFunctionSubSort.Hood_Misc); } else if (stype == "stone") { return(Data.XObjFunctionSubSort.Hood_Stone); } else { return(Data.XObjFunctionSubSort.Hood_Other); } } case "wall": { string stype = cpf.GetSaveItem("subsort").StringValue.Trim().ToLower(); if (stype == "brick") { return(Data.XObjFunctionSubSort.Wall_Brick); } else if (stype == "masonry") { return(Data.XObjFunctionSubSort.Wall_Masonry); } else if (stype == "paint") { return(Data.XObjFunctionSubSort.Wall_Paint); } else if (stype == "paneling") { return(Data.XObjFunctionSubSort.Wall_Paneling); } else if (stype == "poured") { return(Data.XObjFunctionSubSort.Wall_Poured); } else if (stype == "siding") { return(Data.XObjFunctionSubSort.Wall_Siding); } else if (stype == "tile") { return(Data.XObjFunctionSubSort.Wall_Tile); } else if (stype == "wallpaper") { return(Data.XObjFunctionSubSort.Wall_Wallpaper); } else { return(Data.XObjFunctionSubSort.Wall_Other); } } case "terrainpaint": { return(Data.XObjFunctionSubSort.Terrain); } case "floor": { string stype = cpf.GetSaveItem("subsort").StringValue.Trim().ToLower(); if (stype == "brick") { return(Data.XObjFunctionSubSort.Floor_Brick); } else if (stype == "carpet") { return(Data.XObjFunctionSubSort.Floor_Carpet); } else if (stype == "lino") { return(Data.XObjFunctionSubSort.Floor_Lino); } else if (stype == "poured") { return(Data.XObjFunctionSubSort.Floor_Poured); } else if (stype == "stone") { return(Data.XObjFunctionSubSort.Floor_Stone); } else if (stype == "tile") { return(Data.XObjFunctionSubSort.Floor_Tile); } else if (stype == "wood") { return(Data.XObjFunctionSubSort.Floor_Wood); } else { return(Data.XObjFunctionSubSort.Floor_Other); } } case "roof": { return(Data.XObjFunctionSubSort.Roof); } case "fence": { if (cpf.GetSaveItem("ishalfwall").UIntegerValue == 1) { return(Data.XObjFunctionSubSort.Fence_Halfwall); } return(Data.XObjFunctionSubSort.Fence_Rail); } default: { return((Data.XObjFunctionSubSort) 0); } } }
static void ConsumeFromXobj(SimPe.Cache.ObjectCacheItem oci, Interfaces.Scenegraph.IScenegraphFileIndexItem nrefitem, SimPe.Data.MetaData.Languages deflang) { SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf(); nrefitem.FileDescriptor.UserData = nrefitem.Package.Read(nrefitem.FileDescriptor).UncompressedData; cpf.ProcessData(nrefitem); oci.FileDescriptor = nrefitem.FileDescriptor; oci.LocalGroup = nrefitem.LocalGroup; oci.ObjectType = SimPe.Data.ObjectTypes.Normal; SetFunctionSortForXObj(cpf, oci); oci.ObjectFileName = cpf.GetSaveItem("filename").StringValue; if (oci.ObjectFileName == "") { oci.ObjectFileName = cpf.GetSaveItem("name").StringValue; } oci.Useable = true; oci.Class = SimPe.Cache.ObjectClass.XObject; Interfaces.Scenegraph.IScenegraphFileIndexItem[] ctssitems = FileTable.FileIndex.FindFile(cpf.GetSaveItem("stringsetrestypeid").UIntegerValue, cpf.GetSaveItem("stringsetgroupid").UIntegerValue, cpf.GetSaveItem("stringsetid").UIntegerValue, null); //Data.MetaData.STRING_FILE if (ctssitems.Length > 0) { SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str(); str.ProcessData(ctssitems[0]); SimPe.PackedFiles.Wrapper.StrItemList items = str.LanguageItems(deflang); if (items.Length > 0) { oci.Name = items[0].Title; } else { items = str.LanguageItems(1); if (items.Length > 0) { oci.Name = items[0].Title; } else { oci.Name = ""; } } } else { oci.Name = ""; } if (oci.Name == "") { oci.Name = oci.ObjectFileName; } //now the ModeName File if (cpf.GetItem("texturetname") != null) { oci.ModelName = cpf.GetItem("texturetname").StringValue; } else if (cpf.GetItem("filename") != null) { oci.ModelName = cpf.GetItem("filename").StringValue; } else { oci.ModelName = cpf.GetSaveItem("material").StringValue; } //oci.Name = cpf.GetSaveItem("type").StringValue + " - "+ cpf.GetSaveItem("subsort").StringValue; if (oci.Thumbnail == null) { oci.Thumbnail = ObjectPreview.GetXThumbnail(cpf); } ObjectReader.changedcache = true; }
/// <summary> /// Chnages materialStateFlags and objectStateIndex according to the MaTD Reference Name /// </summary> /// <param name="mmat">The MMAT File to change the values in</param> public static void FixMMAT(SimPe.PackedFiles.Wrapper.Cpf mmat) { string name = mmat.GetSaveItem("name").StringValue; if (name.EndsWith("_clean")) { mmat.GetSaveItem("materialStateFlags").UIntegerValue = 0; mmat.GetSaveItem("objectStateIndex").IntegerValue = 0; } else if (name.EndsWith("_dirty")) { mmat.GetSaveItem("materialStateFlags").UIntegerValue = 2; mmat.GetSaveItem("objectStateIndex").IntegerValue = 1; } else if (name.EndsWith("_lit")) { mmat.GetSaveItem("materialStateFlags").UIntegerValue = 1; mmat.GetSaveItem("objectStateIndex").IntegerValue = 3; } else if (name.EndsWith("_unlit")) { mmat.GetSaveItem("materialStateFlags").UIntegerValue = 0; mmat.GetSaveItem("objectStateIndex").IntegerValue = 4; } else if (name.EndsWith("_on")) { mmat.GetSaveItem("materialStateFlags").UIntegerValue = 2; mmat.GetSaveItem("objectStateIndex").IntegerValue = 6; } else if (name.EndsWith("_off")) { mmat.GetSaveItem("materialStateFlags").UIntegerValue = 0; mmat.GetSaveItem("objectStateIndex").IntegerValue = 5; } }
public SimPe.Cache.PackageType GetType(SimPe.Interfaces.Files.IPackageFile pkg) { SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFiles(Data.MetaData.GZPS); if (pfds.Length == 0) { pfds = pkg.FindFiles(Data.MetaData.XOBJ); //Object XML } if (pfds.Length == 0) { pfds = pkg.FindFiles(0x2C1FD8A1); //TextureOverlay XML } if (pfds.Length == 0) { pfds = pkg.FindFiles(0x8C1580B5); //Hairtone XML } if (pfds.Length == 0) { pfds = pkg.FindFiles(0x0C1FE246); //Mesh Overlay XML } if (pfds.Length == 0) { pfds = pkg.FindFiles(Data.MetaData.XROF); //Object XML } if (pfds.Length == 0) { pfds = pkg.FindFiles(Data.MetaData.XFLR); //Object XML } if (pfds.Length == 0) { pfds = pkg.FindFiles(Data.MetaData.XFNC); //Object XML } if (pfds.Length > 0) { SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf(); cpf.ProcessData(pfds[0], pkg, false); string type = cpf.GetSaveItem("type").StringValue.Trim().ToLower(); switch (type) { case "wall": { return(SimPe.Cache.PackageType.Wallpaper); } case "terrainpaint": { return(SimPe.Cache.PackageType.Terrain); } case "floor": { return(SimPe.Cache.PackageType.Floor); } case "roof": { return(SimPe.Cache.PackageType.Roof); } case "fence": { return(SimPe.Cache.PackageType.Fence); } case "skin": { uint cat = cpf.GetSaveItem("category").UIntegerValue; if ((cat & (uint)Data.SkinCategories.Skin) != 0) { return(SimPe.Cache.PackageType.Skin); } else { return(SimPe.Cache.PackageType.Cloth); } } case "meshoverlay": case "textureoverlay": { if (cpf.GetSaveItem("subtype").UIntegerValue == (uint)Data.TextureOverlayTypes.Blush) { return(SimPe.Cache.PackageType.Blush); } if (cpf.GetSaveItem("subtype").UIntegerValue == (uint)Data.TextureOverlayTypes.Eye) { return(SimPe.Cache.PackageType.Eye); } if (cpf.GetSaveItem("subtype").UIntegerValue == (uint)Data.TextureOverlayTypes.EyeBrow) { return(SimPe.Cache.PackageType.EyeBrow); } if (cpf.GetSaveItem("subtype").UIntegerValue == (uint)Data.TextureOverlayTypes.EyeShadow) { return(SimPe.Cache.PackageType.EyeShadow); } if (cpf.GetSaveItem("subtype").UIntegerValue == (uint)Data.TextureOverlayTypes.Glasses) { return(SimPe.Cache.PackageType.Glasses); } if (cpf.GetSaveItem("subtype").UIntegerValue == (uint)Data.TextureOverlayTypes.Lipstick) { return(SimPe.Cache.PackageType.Lipstick); } if (cpf.GetSaveItem("subtype").UIntegerValue == (uint)Data.TextureOverlayTypes.Mask) { return(SimPe.Cache.PackageType.Mask); } if (cpf.GetSaveItem("subtype").UIntegerValue == (uint)Data.TextureOverlayTypes.Beard) { return(SimPe.Cache.PackageType.Beard); } if (type == "meshoverlay") { return(SimPe.Cache.PackageType.Accessory); } return(SimPe.Cache.PackageType.Makeup); } case "hairtone": { return(SimPe.Cache.PackageType.Hair); } } } return(SimPe.Cache.PackageType.Unknown); }
/// <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); }