/// <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> /// adds the subsets to the tsDesignMode.. Block and returns a List of all added Subsets /// </summary> /// <param name="shpes"></param> /// <param name="gmnd"></param> /// <param name="subsets"></param> protected void GetSubsets(SimPe.Plugin.Rcol[] shpes, SimPe.Plugin.Rcol gmnd, ArrayList subsets) { ArrayList list = new ArrayList(); ArrayList localsubsets = new ArrayList(); DataListExtension dle = new DataListExtension(gmnd); uint index = (uint)(gm_pkg.FindFiles(0x4C697E5A).Length + 1); foreach (SimPe.Plugin.Rcol shpe in shpes) { SimPe.Plugin.Shape sh = (SimPe.Plugin.Shape)shpe.Blocks[0]; SimPe.Plugin.Rcol cres = FindResourceNode(shpe); foreach (SimPe.Plugin.ShapePart part in sh.Parts) { if (subsets.Contains(part.Subset)) { continue; } if (localsubsets.Contains(part.Subset)) { continue; } //Read the MATD Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFile(part.FileName + "_txmt", 0x49596978); foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds) { SimPe.Plugin.Rcol matd = new GenericRcol(null, false); matd.ProcessData(pfd, package); SimPe.Plugin.MaterialDefinition md = (SimPe.Plugin.MaterialDefinition)matd.Blocks[0]; //check that the Material is not transparent if (md.GetProperty("stdMatAlphaBlendMode").Value == "none") { //check that the Material references a texture if (package.FindFile(md.GetProperty("stdMatBaseTextureName").Value + "_txtr", 0x1C4A276C).Length > 0) { localsubsets.Add(part.Subset); SimPe.Plugin.ExtensionItem ei = new ExtensionItem(); ei.Name = part.Subset; ei.Typecode = ExtensionItem.ItemTypes.Array; WorkshopMMAT i = new WorkshopMMAT(part.Subset); object[] tag = new object[3]; tag[0] = matd; tag[1] = cres.FileName; tag[2] = ei; i.Tag = tag; //if (md.GetProperty("stdMatAlphaBlendMode").Value!="none") i.AddObjectStateIndex(1); list.Add(i); //dle.Extension.Items = (ExtensionItem[])Helper.Add(dle.Extension.Items, ei); //AddMMAT(matd, part.Type, cres.FileName, index++); } } } } } WorkshopMMAT[] mmats = new WorkshopMMAT[list.Count]; list.CopyTo(mmats); Listing li = new Listing(); if (mmats.Length > 0) { mmats = li.Execute(mmats); } foreach (WorkshopMMAT mmat in mmats) { subsets.Add(mmat.Subset); dle.Extension.Items = (ExtensionItem[])Helper.Add(dle.Extension.Items, (ExtensionItem)mmat.Tag[2]); AddMMAT((SimPe.Plugin.Rcol)mmat.Tag[0], mmat.Subset, (string)mmat.Tag[1], index++, false); } if (dle.Extension.Items.Length > 0) { AddDesignModeBlock(gmnd, dle); gmnd.SynchronizeUserData(); dn_pkg.Add(gmnd.FileDescriptor); } }