private void openPCCToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.u;*.upk;*sfm|*.u;*.upk;*sfm"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { pcc = new PCCObject(d.FileName); manageTLKSetToolStripMenuItem.Enabled = true; InitBioTlkFileSet(); Objs = new List <int>(); for (int i = 0; i < pcc.Exports.Count; i++) { if (pcc.Exports[i].ClassName == "BioConversation") { Objs.Add(i); } } RefreshCombo(); } catch (Exception ex) { MessageBox.Show("Error:\n" + ex.Message); } } }
public void InitTlkManager(PCCObject pcc, BioTlkFileSet tlkSet, TalkFiles tlks = null) { packages = new List <PCCObject>(); tlkFileSets = new List <BioTlkFileSet>(); selectedTlks = tlks ?? new TalkFiles(); packages.Add(pcc); refreshFileBox(); fileBox.SelectedIndex = 0; Application.DoEvents(); for (int i = 0; i < tlkFileSets.Count; i++) { if (tlkFileSets[i].index == tlkSet.index) { bioTlkSetBox.SelectedIndex = i; Application.DoEvents(); tlkFileBox.SelectedIndex = tlkSet.selectedTLK; break; } } TalkFile tlk = tlkSet.talkFiles[tlkSet.selectedTLK]; if (!selectedTlks.tlkList.Contains(tlk)) { selectedTlks.tlkList.Add(tlk); } foreach (TalkFile tlkFile in selectedTlks.tlkList) { selectedTlkFilesBox.Items.Add(Path.GetFileName(pcc.fullname) + " -> " + tlkFile.BioTlkSetName + tlkFile.Name); } }
private void openPccToolStripMenuItem_Click_1(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.u;*.upk;*sfm|*.u;*.upk;*sfm"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { pcc = new PCCObject(d.FileName); CurrList = 0; classes = new List<int>(); foreach (PCCObject.ExportEntry ent in pcc.Exports) { int f = -1; for (int i = 0; i < classes.Count(); i++) if (classes[i] == ent.ClassNameID) f = i; if (f == -1) classes.Add(ent.ClassNameID); } bool run = true; while (run) { run = false; for (int i = 0; i < classes.Count() - 1; i++) if (pcc.GetName(classes[i]).CompareTo(pcc.GetName(classes[i + 1])) > 0) { int t = classes[i]; classes[i] = classes[i + 1]; classes[i + 1] = t; run = true; } } RefreshLists(); } }
public TreeNode FindSequences(PCCObject pcc, int index, bool wantFullName = false, bool refSeq = false) { string objectName = ""; if (refSeq) { List <SaltPropertyReader.Property> p = SaltPropertyReader.getPropList(pcc, pcc.Exports[index].Data); for (int i = 0; i < p.Count(); i++) { if (p[i].Name == "ObjName") { objectName = p[i].Value.StringValue; break; } } } else { objectName = pcc.Exports[index].ObjectName; } TreeNode ret = new TreeNode("#" + index.ToString() + ": " + (wantFullName ? pcc.Exports[index].GetFullPath : objectName)); ret.Name = index.ToString(); Sequence seq = new Sequence(pcc, index); if (seq.SequenceObjects != null) { for (int i = 0; i < seq.SequenceObjects.Count(); i++) { if (pcc.Exports[seq.SequenceObjects[i] - 1].ClassName == "Sequence" || pcc.Exports[seq.SequenceObjects[i] - 1].ClassName.StartsWith("PrefabSequence")) { TreeNode t = FindSequences(pcc, seq.SequenceObjects[i] - 1, wantFullName); ret.Nodes.Add(t); } else if (pcc.Exports[seq.SequenceObjects[i] - 1].ClassName == "SequenceReference") { var props = SaltPropertyReader.getPropList(pcc, pcc.Exports[seq.SequenceObjects[i] - 1].Data); var propSequenceReference = props.FirstOrDefault(p => p.Name.Equals("oSequenceReference")); if (propSequenceReference != null) { int n = propSequenceReference.Value.IntValue; if (propSequenceReference.Value.IntValue < 0) { n += 1; TreeNode t = new TreeNode("#" + n.ToString() + ": " + pcc.Imports[-n].Name + "(Import)"); t.Name = n.ToString(); ret.Nodes.Add(t); } else { TreeNode t = FindSequences(pcc, propSequenceReference.Value.IntValue - 1, wantFullName, true); ret.Nodes.Add(t); } } } } } return(ret); }
public SAction(int idx, float x, float y, PCCObject p) : base(idx, x, y, p) { GetVarLinks(); GetOutputLinks(); originalX = x; originalY = y; }
public SAction(int idx, float x, float y, PCCObject p, GraphEditor grapheditor) : base(idx, x, y, p, grapheditor) { GetVarLinks(); GetOutputLinks(); originalX = x; originalY = y; }
private void openPccToolStripMenuItem_Click_1(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.u;*.upk;*sfm|*.u;*.upk;*sfm"; if (d.ShowDialog() == DialogResult.OK) { AddRecent(d.FileName); SaveRecentList(); pcc = new PCCObject(d.FileName); loadPCC(); } }
public void LoadGlobalTlk() { string path = ME1Directory.cookedPath + @"Packages\Dialog\GlobalTlk.upk"; try { PCCObject pcc = new PCCObject(path); tlkList.Add(new TalkFile(pcc, 0)); } catch (Exception) { return; } }
public PCCEditor() { InitializeComponent(); LoadRecentList(); RefreshRecent(); if (RFiles != null && RFiles.Count != 0) { int index = RFiles.Count - 1; if (File.Exists(RFiles[index])) { pcc = new PCCObject(RFiles[index]); loadPCC(); } } }
private void RecentFile_click(object sender, EventArgs e) { //just load a file string s = sender.ToString(); try { pcc = new PCCObject(s); loadPCC(); } catch (Exception ex) { MessageBox.Show("Error:\n" + ex.Message); } }
private void openPccToolStripMenuItem_Click_1(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.u;*.upk;*sfm|*.u;*.upk;*sfm"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { pcc = new PCCObject(d.FileName); CurrentView = 2; classes = new List <int>(); foreach (PCCObject.ExportEntry ent in pcc.Exports) { int f = -1; for (int i = 0; i < classes.Count(); i++) { if (classes[i] == ent.ClassNameID) { f = i; } } if (f == -1) { classes.Add(ent.ClassNameID); } } bool run = true; while (run) { run = false; for (int i = 0; i < classes.Count() - 1; i++) { if (pcc.GetName(classes[i]).CompareTo(pcc.GetName(classes[i + 1])) > 0) { int t = classes[i]; classes[i] = classes[i + 1]; classes[i + 1] = t; run = true; } } } RefreshView(); } }
private void fileBox_SelectedIndexChanged(object sender, EventArgs e) { bioTlkSetBox.Items.Clear(); tlkFileBox.Items.Clear(); int n = fileBox.SelectedIndex; if (n == -1) { return; } PCCObject pcc = packages[n]; tlkFileSets.Clear(); for (int i = 0; i < pcc.ExportCount; i++) { if (pcc.Exports[i].ClassName == "BioTlkFileSet") { BioTlkFileSet b = new BioTlkFileSet(pcc, i); tlkFileSets.Add(b); bioTlkSetBox.Items.Add(b.Name); } } //No BioTlkSets, look for loose BioTlkFiles if (tlkFileSets.Count == 0) { BioTlkFileSet tlkSet = new BioTlkFileSet(pcc); for (int i = 0; i < pcc.ExportCount; i++) { if (pcc.Exports[i].ClassName == "BioTlkFile") { TalkFile tlk = new TalkFile(pcc, i); tlkSet.talkFiles.Add(tlk); } } if (tlkSet.talkFiles.Count != 0) { tlkFileSets.Add(tlkSet); bioTlkSetBox.Items.Add("Misc TlkFiles"); } } }
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { if (autoSaveViewToolStripMenuItem.Checked) { saveView(); } OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.u;*.upk;*sfm|*.u;*.upk;*sfm"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { pcc = new PCCObject(d.FileName); CurrentFile = d.FileName; toolStripStatusLabel1.Text = CurrentFile.Substring(CurrentFile.LastIndexOf(@"\") + 1); LoadSequences(); graphEditor.nodeLayer.RemoveAllChildren(); graphEditor.edgeLayer.RemoveAllChildren(); if (CurrentObjects != null) { CurrentObjects.Clear(); } } }
public void CopyImgList(Texture2D inTex, PCCObject pcc, bool norender = false) { List<ImageInfo> tempList = new List<ImageInfo>(); MemoryStream tempData = new MemoryStream(); SaltLZOHelper lzo = new SaltLZOHelper(); numMipMaps = inTex.numMipMaps; // forced norenderfix // norender = true; int type = -1; if (!norender) { if (imgList.Exists(img => img.storageType == storage.arcCpr) && imgList.Count > 1) type = 1; else if (imgList.Exists(img => img.storageType == storage.pccCpr)) type = 2; else if (imgList.Exists(img => img.storageType == storage.pccSto) || imgList.Count == 1) type = 3; } else type = 3; switch (type) { case 1: for (int i = 0; i < inTex.imgList.Count; i++) { try { ImageInfo newImg = new ImageInfo(); ImageInfo replaceImg = inTex.imgList[i]; Texture2D.storage replaceType = imgList.Find(img => img.imgSize == replaceImg.imgSize).storageType; int j = 0; while (replaceType == storage.empty) { j++; replaceType = imgList[imgList.FindIndex(img => img.imgSize == replaceImg.imgSize) + j].storageType; } if (replaceType == storage.arcCpr || !imgList.Exists(img => img.imgSize == replaceImg.imgSize)) { newImg.storageType = storage.arcCpr; newImg.uncSize = replaceImg.uncSize; newImg.cprSize = replaceImg.cprSize; newImg.imgSize = replaceImg.imgSize; newImg.offset = (int)(replaceImg.offset + inTex.pccOffset + inTex.dataOffset); } else { newImg.storageType = storage.pccSto; newImg.uncSize = replaceImg.uncSize; newImg.cprSize = replaceImg.uncSize; newImg.imgSize = replaceImg.imgSize; newImg.offset = (int)(tempData.Position); using (MemoryStream tempStream = new MemoryStream(inTex.imageData)) { tempData.WriteBytes(lzo.DecompressTex(tempStream, replaceImg.offset, replaceImg.uncSize, replaceImg.cprSize)); } } tempList.Add(newImg); } catch { ImageInfo replaceImg = inTex.imgList[i]; if (!imgList.Exists(img => img.imgSize == replaceImg.imgSize)) throw new Exception("An error occurred during imglist copying and no suitable replacement was found"); ImageInfo newImg = imgList.Find(img => img.imgSize == replaceImg.imgSize); if (newImg.storageType != storage.pccCpr && newImg.storageType != storage.pccSto) throw new Exception("An error occurred during imglist copying and no suitable replacement was found"); int temppos = newImg.offset; newImg.offset = (int)tempData.Position; tempData.Write(imageData, temppos, newImg.cprSize); tempList.Add(newImg); } } break; case 2: for (int i = 0; i < inTex.imgList.Count; i++) { ImageInfo newImg = new ImageInfo(); ImageInfo replaceImg = inTex.imgList[i]; newImg.storageType = storage.pccCpr; newImg.uncSize = replaceImg.uncSize; newImg.cprSize = replaceImg.cprSize; newImg.imgSize = replaceImg.imgSize; newImg.offset = (int)(tempData.Position); byte[] buffer = new byte[newImg.cprSize]; Buffer.BlockCopy(inTex.imageData, replaceImg.offset, buffer, 0, buffer.Length); tempData.WriteBytes(buffer); tempList.Add(newImg); } break; case 3: for (int i = 0; i < inTex.imgList.Count; i++) { ImageInfo newImg = new ImageInfo(); ImageInfo replaceImg = inTex.imgList[i]; newImg.storageType = storage.pccSto; newImg.uncSize = replaceImg.uncSize; newImg.cprSize = replaceImg.uncSize; newImg.imgSize = replaceImg.imgSize; newImg.offset = (int)(tempData.Position); if (replaceImg.storageType == storage.pccCpr) { using (MemoryStream tempStream = new MemoryStream(inTex.imageData)) { tempData.WriteBytes(lzo.DecompressTex(tempStream, replaceImg.offset, replaceImg.uncSize, replaceImg.cprSize)); } } else if (replaceImg.storageType == storage.pccSto) { byte[] buffer = new byte[newImg.cprSize]; Buffer.BlockCopy(inTex.imageData, replaceImg.offset, buffer, 0, buffer.Length); tempData.WriteBytes(buffer); } else throw new NotImplementedException("Copying from non package stored texture no available"); tempList.Add(newImg); } break; default: throw new NotImplementedException(); } for (int i = 0; i < tempList.Count; i++) { ImageInfo tempinfo = tempList[i]; if (inTex.imgList[i].storageType == storage.empty) tempinfo.storageType = storage.empty; tempList[i] = tempinfo; } imgList = tempList; imageData = tempData.ToArray(); tempData.Close(); byte[] buff; //Copy properties using (MemoryStream tempMem = new MemoryStream()) { tempMem.WriteBytes(headerData); for (int i = 0; i < inTex.properties.Count; i++) { SaltPropertyReader.Property prop = inTex.properties.ElementAt(i).Value; if (prop.Name == "UnpackMin") { for (int j = 0; j < inTex.UnpackNum; j++) { tempMem.WriteValueS64(pcc.AddName(prop.Name)); tempMem.WriteValueS64(pcc.AddName(prop.TypeVal.ToString())); tempMem.WriteValueS32(prop.Size); tempMem.WriteValueS32(j); tempMem.WriteValueF32(prop.Value.FloatValue, Endian.Little); } continue; } tempMem.WriteValueS64(pcc.AddName(prop.Name)); if (prop.Name == "None") { for (int j = 0; j < 12; j++) tempMem.WriteByte(0); } else { tempMem.WriteValueS64(pcc.AddName(prop.TypeVal.ToString())); tempMem.WriteValueS64(prop.Size); switch (prop.TypeVal) { case SaltPropertyReader.Type.IntProperty: tempMem.WriteValueS32(prop.Value.IntValue); break; case SaltPropertyReader.Type.BoolProperty: tempMem.Seek(-4, SeekOrigin.Current); tempMem.WriteValueS32(prop.Value.IntValue); tempMem.Seek(4, SeekOrigin.Current); break; case SaltPropertyReader.Type.NameProperty: tempMem.WriteValueS64(pcc.AddName(prop.Value.StringValue)); break; case SaltPropertyReader.Type.StrProperty: tempMem.WriteValueS32(prop.Value.StringValue.Length + 1); foreach (char c in prop.Value.StringValue) tempMem.WriteByte((byte)c); tempMem.WriteByte(0); break; case SaltPropertyReader.Type.StructProperty: tempMem.WriteValueS64(pcc.AddName(prop.Value.StringValue)); foreach (SaltPropertyReader.PropertyValue value in prop.Value.Array) tempMem.WriteValueS32(value.IntValue); break; case SaltPropertyReader.Type.ByteProperty: tempMem.WriteValueS32(pcc.AddName(prop.Value.StringValue)); tempMem.WriteValueS32(prop.Value.IntValue); break; case SaltPropertyReader.Type.FloatProperty: tempMem.WriteValueF32(prop.Value.FloatValue, Endian.Little); break; default: throw new FormatException("unknown property"); } } } buff = tempMem.ToArray(); } int propertiesOffset = SaltPropertyReader.detectStart(pcc, buff); headerData = new byte[propertiesOffset]; Buffer.BlockCopy(buff, 0, headerData, 0, propertiesOffset); properties = new Dictionary<string, SaltPropertyReader.Property>(); List<SaltPropertyReader.Property> tempProperties = SaltPropertyReader.getPropList(pcc, buff); UnpackNum = 0; for (int i = 0; i < tempProperties.Count; i++) { SaltPropertyReader.Property property = tempProperties[i]; if (property.Name == "UnpackMin") UnpackNum++; if (!properties.ContainsKey(property.Name)) properties.Add(property.Name, property); switch (property.Name) { case "Format": texFormat = property.Value.StringValue; break; case "LODGroup": LODGroup = property.Value.StringValue; break; case "CompressionSettings": Compression = property.Value.StringValue; break; case "None": dataOffset = (uint)(property.offsetval + property.Size); break; } } // if "None" property isn't found throws an exception if (dataOffset == 0) throw new Exception("\"None\" property not found"); }
public void ChangeCompression(string newComp, PCCObject pcc) { if (!properties.ContainsKey("CompressionSettings")) throw new KeyNotFoundException("Texture doesn't have a compression property"); SaltPropertyReader.Property prop = properties["CompressionSettings"]; Int64 comp = (Int64)pcc.AddName(newComp); byte[] buff = BitConverter.GetBytes(comp); Buffer.BlockCopy(buff, 0, prop.raw, 24, sizeof(Int64)); prop.Value.StringValue = pcc.Names[(int)comp]; properties["CompressionSettings"] = prop; Compression = properties["CompressionSettings"].Value.StringValue; }
public void ChangeTexFormat(string newFormat, PCCObject pcc) { SaltPropertyReader.Property prop = properties["Format"]; Int64 formatID = (Int64)pcc.AddName(newFormat); byte[] buff = BitConverter.GetBytes(formatID); Buffer.BlockCopy(buff, 0, prop.raw, 24, sizeof(Int64)); prop.Value.StringValue = pcc.Names[(int)formatID]; properties["Format"] = prop; texFormat = properties["Format"].Value.StringValue; }
public Texture2D(PCCObject pcc, int pccExpID) { PCCObject.ExportEntry exp = pcc.Exports[pccExpID]; ; if (String.Compare(exp.ClassName, className) != 0 && String.Compare(exp.ClassName, class2) != 0 && String.Compare(exp.ClassName, class3) != 0) { throw new FormatException("Export is not a texture"); } Class = exp.ClassName; exportOffset = exp.DataOffset; FullPackage = exp.PackageFullName; texName = exp.ObjectName; allPccs = new List<string>(); allPccs.Add(pcc.pccFileName); properties = new Dictionary<string, SaltPropertyReader.Property>(); byte[] rawData = (byte[])exp.Data.Clone(); Compression = "No Compression"; int propertiesOffset = SaltPropertyReader.detectStart(pcc, rawData); headerData = new byte[propertiesOffset]; Buffer.BlockCopy(rawData, 0, headerData, 0, propertiesOffset); pccOffset = (uint)exp.DataOffset; UnpackNum = 0; List<SaltPropertyReader.Property> tempProperties = SaltPropertyReader.getPropList(pcc, rawData); for (int i = 0; i < tempProperties.Count; i++) { SaltPropertyReader.Property property = tempProperties[i]; if (property.Name == "UnpackMin") UnpackNum++; if (!properties.ContainsKey(property.Name)) properties.Add(property.Name, property); switch (property.Name) { case "Format": texFormat = property.Value.StringValue; break; case "LODGroup": LODGroup = property.Value.StringValue; break; case "CompressionSettings": Compression = property.Value.StringValue; break; case "None": dataOffset = (uint)(property.offsetval + property.Size); break; } } // if "None" property isn't found throws an exception if (dataOffset == 0) throw new Exception("\"None\" property not found"); else { imageData = new byte[rawData.Length - dataOffset]; Buffer.BlockCopy(rawData, (int)dataOffset, imageData, 0, (int)(rawData.Length - dataOffset)); } //DebugOutput.PrintLn("ImageData size = " + imageData.Length); pccExpIdx = pccExpID; MemoryStream dataStream = new MemoryStream(imageData); imgList = new List<ImageInfo>(); dataStream.ReadValueU32(); //Current position in pcc numMipMaps = dataStream.ReadValueU32(); uint count = numMipMaps; //DebugOutput.PrintLn(numMipMaps + " derp"); while (dataStream.Position < dataStream.Length && count > 0) { ImageInfo imgInfo = new ImageInfo(); imgInfo.storageType = (storage)dataStream.ReadValueS32(); imgInfo.uncSize = dataStream.ReadValueS32(); imgInfo.cprSize = dataStream.ReadValueS32(); imgInfo.offset = dataStream.ReadValueS32(); if (imgInfo.storageType == storage.pccSto) { imgInfo.offset = (int)dataStream.Position; dataStream.Seek(imgInfo.uncSize, SeekOrigin.Current); } else if (imgInfo.storageType == storage.pccCpr) { imgInfo.offset = (int)dataStream.Position; dataStream.Seek(imgInfo.cprSize, SeekOrigin.Current); } imgInfo.imgSize = new ImageSize(dataStream.ReadValueU32(), dataStream.ReadValueU32()); if (imgList.Exists(img => img.imgSize == imgInfo.imgSize)) { uint width = imgInfo.imgSize.width; uint height = imgInfo.imgSize.height; if (width == 4 && imgList.Exists(img=> img.imgSize.width == width)) width = imgList.Last().imgSize.width / 2; if (width == 0) width = 1; if (height == 4 && imgList.Exists(img => img.imgSize.height == height)) height = imgList.Last().imgSize.height / 2; if (height == 0) height = 1; imgInfo.imgSize = new ImageSize(width, height); if (imgList.Exists(img => img.imgSize == imgInfo.imgSize)) throw new Exception("Duplicate image size found"); } imgList.Add(imgInfo); count--; //DebugOutput.PrintLn("ImgInfo no: " + count + ", Storage Type = " + imgInfo.storageType + ", offset = " + imgInfo.offset); } dataStream.Seek(-4, SeekOrigin.End); footerData = dataStream.ReadBytes(4); dataStream.Dispose(); }
public SBox(int idx, float x, float y, PCCObject p, GraphEditor grapheditor) : base(idx, x, y, p, grapheditor) { }
public SEvent(int idx, float x, float y, PCCObject p, GraphEditor grapheditor) : base(idx, x, y, p, grapheditor) { outlinePen = new Pen(Color.FromArgb(214, 30, 28)); string s = pcc.Exports[index].ObjectName; s = s.Replace("BioSeqEvt_", ""); s = s.Replace("SFXSeqEvt_", ""); s = s.Replace("SeqEvt_", ""); s = s.Replace("SeqEvent_", ""); float starty = 0; float w = 15; float midW = 0; varLinkBox = new PPath(); GetVarLinks(); for (int i = 0; i < Varlinks.Count; i++) { string d = ""; foreach (int l in Varlinks[i].Links) d = d + "#" + l + ","; d = d.Remove(d.Length - 1); SText t2 = new SText( d + "\n" + Varlinks[i].Desc); t2.X = w; t2.Y = 0; w += t2.Width + 20; t2.Pickable = false; Varlinks[i].node.TranslateBy(t2.X + t2.Width / 2, t2.Y + t2.Height); t2.AddChild(Varlinks[i].node); varLinkBox.AddChild(t2); } if(Varlinks.Count != 0) varLinkBox.AddRectangle(0, 0, w, varLinkBox[0].Height); varLinkBox.Pickable = false; varLinkBox.Pen = outlinePen; varLinkBox.Brush = nodeBrush; GetOutputLinks(); outLinkBox = new PPath(); for (int i = 0; i < Outlinks.Count(); i++) { SText t2 = new SText(Outlinks[i].Desc); if(t2.Width + 10 > midW) midW = t2.Width + 10; //t2.TextAlignment = StringAlignment.Far; //t2.ConstrainWidthToTextWidth = false; t2.X = 0 - t2.Width; t2.Y = starty + 3; starty += t2.Height + 6; t2.Pickable = false; Outlinks[i].node.TranslateBy(0, t2.Y + t2.Height / 2); t2.AddChild(Outlinks[i].node); outLinkBox.AddChild(t2); } outLinkBox.AddPolygon(new PointF[] { new PointF(0, 0), new PointF(0, starty), new PointF(-0.5f*midW, starty+30), new PointF(0 - midW, starty), new PointF(0 - midW, 0), new PointF(midW/-2, -30) }); outLinkBox.Pickable = false; outLinkBox.Pen = outlinePen; outLinkBox.Brush = nodeBrush; List<SaltPropertyReader.Property> props = SaltPropertyReader.getPropList(pcc, pcc.Exports[index].Data); foreach (SaltPropertyReader.Property prop in props) { if (prop.Name.Contains("EventName") || prop.Name == "sScriptName") s += "\n\"" + prop.Value.IntValue + "\""; else if (prop.Name == "InputLabel" || prop.Name == "sEvent") s += "\n\"" + prop.Value.StringValue + "\""; } float tW = GetTitleBox(s, w); if (tW > w) { if (midW > tW) { w = midW; titleBox.Width = w; } else { w = tW; } varLinkBox.Width = w; } float h = titleBox.Height + 1; outLinkBox.TranslateBy(titleBox.Width/2 + midW/2, h + 30); h += outLinkBox.Height + 1; varLinkBox.TranslateBy(0, h); h += varLinkBox.Height; this.bounds = new RectangleF(0, 0, w, h); this.AddChild(titleBox); this.AddChild(varLinkBox); this.AddChild(outLinkBox); this.TranslateBy(x, y); }
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { if (autoSaveViewToolStripMenuItem.Checked) saveView(); OpenFileDialog d = new OpenFileDialog(); d.Filter = "*.u;*.upk;*sfm|*.u;*.upk;*sfm"; if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK) { pcc = new PCCObject(d.FileName); CurrentFile = d.FileName; toolStripStatusLabel1.Text = CurrentFile.Substring(CurrentFile.LastIndexOf(@"\") + 1); LoadSequences(); graphEditor.nodeLayer.RemoveAllChildren(); graphEditor.edgeLayer.RemoveAllChildren(); if(CurrentObjects != null) CurrentObjects.Clear(); } }
public SObj(int idx, float x, float y, PCCObject p) : base() { pcc = p; index = idx; comment = new SText(GetComment(index), commentColor, false); comment.X = 0; comment.Y = 0 - comment.Height; comment.Pickable = false; this.AddChild(comment); this.Pickable = true; }
public SVar(int idx, float x, float y, PCCObject p, GraphEditor grapheditor) : base(idx, x, y, p, grapheditor) { string s = pcc.Exports[index].ObjectName; s = s.Replace("BioSeqVar_", ""); s = s.Replace("SFXSeqVar_", ""); s = s.Replace("SeqVar_", ""); type = getType(s); float w = 60; float h = 60; shape = PPath.CreateEllipse(0, 0, w, h); outlinePen = new Pen(getColor(type)); shape.Pen = outlinePen; shape.Brush = nodeBrush; shape.Pickable = false; this.AddChild(shape); this.Bounds = new RectangleF(0, 0, w, h); val = new SText(GetValue()); val.Pickable = false; val.TextAlignment = StringAlignment.Center; val.X = w / 2 - val.Width / 2; val.Y = h / 2 - val.Height / 2; this.AddChild(val); List<SaltPropertyReader.Property> props = SaltPropertyReader.getPropList(pcc, pcc.Exports[index].Data); foreach (SaltPropertyReader.Property prop in props) { if (prop.Name == "VarName" || prop.Name == "varName") { SText VarName = new SText(prop.Value.StringValue, Color.Red, false); VarName.Pickable = false; VarName.TextAlignment = StringAlignment.Center; VarName.X = w / 2 - VarName.Width / 2; VarName.Y = h; this.AddChild(VarName); break; } } this.TranslateBy(x, y); this.MouseEnter += new PInputEventHandler(OnMouseEnter); this.MouseLeave += new PInputEventHandler(OnMouseLeave); }
public SFrame(int idx, float x, float y, PCCObject p, GraphEditor grapheditor) : base(idx, x, y, p, grapheditor) { string s = pcc.Exports[index].ObjectName; float w = 0; float h = 0; List<SaltPropertyReader.Property> props = SaltPropertyReader.getPropList(pcc, pcc.Exports[index].Data); foreach (SaltPropertyReader.Property prop in props) { if (prop.Name == "SizeX") { w = prop.Value.IntValue; } if (prop.Name == "SizeY") { h = prop.Value.IntValue; } } MakeTitleBox(s); shape = PPath.CreateRectangle(0, -titleBox.Height, w, h + titleBox.Height); outlinePen = new Pen(Color.Black); shape.Pen = outlinePen; shape.Brush = new SolidBrush(Color.Transparent); shape.Pickable = false; this.AddChild(shape); titleBox.TranslateBy(0, -titleBox.Height); this.AddChild(titleBox); comment.Y -= titleBox.Height; this.Bounds = new RectangleF(0, -titleBox.Height, titleBox.Width, titleBox.Height); this.TranslateBy(x, y); }
public void extractImage(ImageInfo imgInfo, string archiveDir = null, string fileName = null) { ImageFile imgFile; if (fileName == null) fileName = texName + "_" + imgInfo.imgSize + getFileFormat(); byte[] imgBuffer = null; switch (imgInfo.storageType) { case storage.pccSto: imgBuffer = new byte[imgInfo.uncSize]; Buffer.BlockCopy(imageData, imgInfo.offset, imgBuffer, 0, imgInfo.uncSize); break; case storage.arcCpr: case storage.arcUnc: string archivePath = FindFile(); if (String.IsNullOrEmpty(archivePath)) throw new FileNotFoundException(); PCCObject temp = new PCCObject(archivePath); for (int i = 0; i < temp.ExportCount; i++) { if (String.Compare(texName, temp.Exports[i].ObjectName, true) == 0 && temp.Exports[i].ClassName == "Texture2D") { Texture2D temptex = new Texture2D(temp, i); temptex.extractImage(imgInfo.imgSize.ToString(), temp, null, fileName); } } break; case storage.pccCpr: using (MemoryStream ms = new MemoryStream(imageData)) { SaltLZOHelper lzohelp = new SaltLZOHelper(); imgBuffer = lzohelp.DecompressTex(ms, imgInfo.offset, imgInfo.uncSize, imgInfo.cprSize); } break; default: throw new FormatException("Unsupported texture storage type"); } if (imgInfo.storageType == storage.pccSto || imgInfo.storageType == storage.pccCpr) { if (getFileFormat() == ".dds") imgFile = new DDS(fileName, imgInfo.imgSize, texFormat, imgBuffer); else imgFile = new TGA(fileName, imgInfo.imgSize, texFormat, imgBuffer); byte[] saveImg = imgFile.ToArray(); using (FileStream outputImg = new FileStream(imgFile.fileName, FileMode.Create, FileAccess.Write)) outputImg.Write(saveImg, 0, saveImg.Length); } }
public void extractImage(string strImgSize, PCCObject pcc, string archiveDir = null, string fileName = null) { ImageSize imgSize = ImageSize.stringToSize(strImgSize); if (imgList.Exists(img => img.imgSize == imgSize)) extractImage(imgList.Find(img => img.imgSize == imgSize), archiveDir, fileName); else throw new FileNotFoundException("Image with resolution " + imgSize + " not found"); }
public void replaceTlkwithFile(PCCObject pcc, int Index) { BitConverter.IsLittleEndian = true; /* converts Huffmann Tree to binary form */ byte[] treeBuffer = ConvertHuffmanTreeToBuffer(); List <EncodedString> encodedStrings = new List <EncodedString>(); int i = 0; foreach (var entry in _inputData) { if (entry.Flags == 0) { if (entry.StringID > 0) { entry.index = -1; } else { entry.index = 0; } } else { entry.index = i; i++; List <BitArray> binaryData = new List <BitArray>(); int binaryLength = 0; /* for every character in a string, put it's binary code into data array */ foreach (char c in entry.data) { binaryData.Add(_huffmanCodes[c]); binaryLength += _huffmanCodes[c].Count; } byte[] buffer = BitArrayListToByteArray(binaryData, binaryLength); encodedStrings.Add(new EncodedString(entry.data.Length, buffer.Length, buffer)); } } /* get properties from object we're replacing*/ byte[] properties = pcc.Exports[Index].Data.Take(40).ToArray(); MemoryStream m = new MemoryStream(); /* writing properties */ m.Write(properties, 0, 40); m.Seek(0x1C, SeekOrigin.Begin); m.Write(BitConverter.GetBytes(_inputData.Count), 0, 4); m.Seek(0, SeekOrigin.End); /* writing entries */ m.Write(BitConverter.GetBytes(_inputData.Count), 0, 4); foreach (TLKEntry entry in _inputData) { m.Write(BitConverter.GetBytes(entry.StringID), 0, 4); m.Write(BitConverter.GetBytes(entry.Flags), 0, 4); m.Write(BitConverter.GetBytes(entry.index), 0, 4); } /* writing HuffmanTree */ m.Write(treeBuffer, 0, treeBuffer.Length); /* writing data */ m.Write(BitConverter.GetBytes(encodedStrings.Count), 0, 4); foreach (EncodedString enc in encodedStrings) { m.Write(BitConverter.GetBytes(enc.stringLength), 0, 4); m.Write(BitConverter.GetBytes(enc.encodedLength), 0, 4); m.Write(enc.binaryData, 0, enc.encodedLength); } byte[] buff = m.ToArray(); pcc.Exports[Index].Data = buff; pcc.SaveToFile(pcc.pccFileName); }
public byte[] ToArray(int pccExportDataOffset, PCCObject pcc) { MemoryStream buffer = new MemoryStream(); buffer.Write(headerData, 0, headerData.Length); if (properties.ContainsKey("LODGroup")) { properties["LODGroup"].Value.StringValue = "TEXTUREGROUP_LightAndShadowMap"; //properties["LODGroup"].Value.IntValue = 1025; } else { buffer.WriteValueS64(pcc.AddName("LODGroup")); buffer.WriteValueS64(pcc.AddName("ByteProperty")); buffer.WriteValueS64(8); buffer.WriteValueS32(pcc.AddName("TEXTUREGROUP_LightAndShadowMap")); buffer.WriteValueS32(1025); } foreach (KeyValuePair<string, SaltPropertyReader.Property> kvp in properties) { SaltPropertyReader.Property prop = kvp.Value; if (prop.Name == "UnpackMin") { for (int j = 0; j < UnpackNum; j++) { buffer.WriteValueS64(pcc.AddName(prop.Name)); buffer.WriteValueS64(pcc.AddName(prop.TypeVal.ToString())); buffer.WriteValueS32(prop.Size); buffer.WriteValueS32(j); buffer.WriteValueF32(prop.Value.FloatValue, Endian.Little); } continue; } buffer.WriteValueS64(pcc.AddName(prop.Name)); if (prop.Name == "None") { for (int j = 0; j < 12; j++) buffer.WriteByte(0); } else { buffer.WriteValueS64(pcc.AddName(prop.TypeVal.ToString())); buffer.WriteValueS64(prop.Size); switch (prop.TypeVal) { case SaltPropertyReader.Type.IntProperty: buffer.WriteValueS32(prop.Value.IntValue); break; case SaltPropertyReader.Type.BoolProperty: buffer.Seek(-4, SeekOrigin.Current); buffer.WriteValueS32(prop.Value.IntValue); buffer.Seek(4, SeekOrigin.Current); break; case SaltPropertyReader.Type.NameProperty: buffer.WriteValueS64(pcc.AddName(prop.Value.StringValue)); break; case SaltPropertyReader.Type.StrProperty: buffer.WriteValueS32(prop.Value.StringValue.Length + 1); foreach (char c in prop.Value.StringValue) buffer.WriteByte((byte)c); buffer.WriteByte(0); break; case SaltPropertyReader.Type.StructProperty: buffer.WriteValueS64(pcc.AddName(prop.Value.StringValue)); foreach (SaltPropertyReader.PropertyValue value in prop.Value.Array) buffer.WriteValueS32(value.IntValue); break; case SaltPropertyReader.Type.ByteProperty: buffer.WriteValueS32(pcc.AddName(prop.Value.StringValue)); buffer.WriteValueS32(prop.Value.IntValue); break; case SaltPropertyReader.Type.FloatProperty: buffer.WriteValueF32(prop.Value.FloatValue, Endian.Little); break; default: throw new FormatException("unknown property"); } } } buffer.WriteValueS32((int)(pccOffset + buffer.Position + 4)); //Remove empty textures List<ImageInfo> tempList = new List<ImageInfo>(); foreach (ImageInfo imgInfo in imgList) { if (imgInfo.storageType != storage.empty) tempList.Add(imgInfo); } imgList = tempList; numMipMaps = (uint)imgList.Count; buffer.WriteValueU32(numMipMaps); foreach (ImageInfo imgInfo in imgList) { buffer.WriteValueS32((int)imgInfo.storageType); buffer.WriteValueS32(imgInfo.uncSize); buffer.WriteValueS32(imgInfo.cprSize); if (imgInfo.storageType == storage.pccSto) { buffer.WriteValueS32((int)(imgInfo.offset + pccExportDataOffset + dataOffset)); buffer.Write(imageData, imgInfo.offset, imgInfo.uncSize); } else if (imgInfo.storageType == storage.pccCpr) { buffer.WriteValueS32((int)(imgInfo.offset + pccExportDataOffset + dataOffset)); buffer.Write(imageData, imgInfo.offset, imgInfo.cprSize); } else buffer.WriteValueS32(imgInfo.offset); if (imgInfo.imgSize.width < 4) buffer.WriteValueU32(4); else buffer.WriteValueU32(imgInfo.imgSize.width); if (imgInfo.imgSize.height < 4) buffer.WriteValueU32(4); else buffer.WriteValueU32(imgInfo.imgSize.height); } buffer.WriteBytes(footerData); return buffer.ToArray(); }
/// <summary> /// This function will first guess and then do a thorough search to find the original location of the texture /// </summary> private string FindFile() { if (!String.IsNullOrEmpty(oriPackage)) return oriPackage; // KFreon: All files should have been added elsewhere rather than searched for here if (allFiles == null) { allFiles = new List<string>(); //List<string> allFiles = Directory.GetFiles(ME1Directory.cookedPath, "*.u", SearchOption.AllDirectories).ToList(); allFiles.AddRange(Directory.GetFiles(ME1Directory.cookedPath, "*.upk", SearchOption.AllDirectories)); allFiles.AddRange(Directory.GetFiles(ME1Directory.cookedPath, "*.upk", SearchOption.AllDirectories)); allFiles.AddRange(Directory.GetFiles(ME1Directory.cookedPath, "*.sfm", SearchOption.AllDirectories)); //List<string> allFiles = Directory.GetFiles(ME1Directory.DLCPath, "*.u", SearchOption.AllDirectories).ToList(); allFiles.AddRange(Directory.GetFiles(ME1Directory.DLCPath, "*.u", SearchOption.AllDirectories)); allFiles.AddRange(Directory.GetFiles(ME1Directory.DLCPath, "*.upk", SearchOption.AllDirectories)); allFiles.AddRange(Directory.GetFiles(ME1Directory.DLCPath, "*.sfm", SearchOption.AllDirectories)); } string package = FullPackage.Split('.')[0]; for (int i = 0; i < allFiles.Count; i++) { string tempFile = allFiles[i].Split('\\')[allFiles[i].Split('\\').Length - 1]; tempFile = tempFile.Split('.')[0]; if (String.Compare(package, tempFile, true) == 0) return allFiles[i]; } if (DialogResult.No == MessageBox.Show("Package guessing failed. Would you like to do the thorough check? (LONG)", "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) return null; for (int i = 0; i < allFiles.Count; i++) { PCCObject temp = new PCCObject(allFiles[i]); for (int j = 0; j < temp.ExportCount; j++) { PCCObject.ExportEntry exp = temp.Exports[j]; if (String.Compare(texName, exp.ObjectName, true) == 0 && exp.ClassName == "Texture2D") { Texture2D temptex = new Texture2D(temp, j); if (temptex.imgList[0].storageType == storage.pccCpr || temptex.imgList[0].storageType == storage.pccSto) { return allFiles[i]; } } } } return null; }
public SBox(int idx, float x, float y, PCCObject p) : base(idx, x, y, p) { }
public byte[] DumpImage(ImageSize imgSize) { byte[] imgBuffer = null; ImageInfo imgInfo; if (imgList.Exists(img => (img.imgSize == imgSize && img.cprSize != -1))) imgInfo = imgList.Find(img => img.imgSize == imgSize); else //throw new FileNotFoundException("Image with resolution " + imgSize + " not found"); return null; switch (imgInfo.storageType) { case storage.pccSto: imgBuffer = new byte[imgInfo.uncSize]; Buffer.BlockCopy(imageData, imgInfo.offset, imgBuffer, 0, imgInfo.uncSize); break; case storage.arcCpr: case storage.arcUnc: string archivePath = FindFile(); if (String.IsNullOrEmpty(archivePath)) throw new FileNotFoundException(); PCCObject temp = new PCCObject(archivePath); for (int i = 0; i < temp.ExportCount; i++) { if (String.Compare(texName, temp.Exports[i].ObjectName, true) == 0 && (temp.Exports[i].ClassName == "Texture2D"))// || temp.Exports[i].ClassName == "TextureFlipBook")) { Texture2D temptex = new Texture2D(temp, i); /*if (imgSize.width > dims) { dims = (int) imgSize.width;*/ byte[] temp1 = temptex.DumpImage(imgSize); if (temp1 != null) imgBuffer = temp1; //} } } break; case storage.pccCpr: using (MemoryStream ms = new MemoryStream(imageData)) { SaltLZOHelper lzohelp = new SaltLZOHelper(); imgBuffer = lzohelp.DecompressTex(ms, imgInfo.offset, imgInfo.uncSize, imgInfo.cprSize); } break; default: throw new FormatException("Unsupported texture storage type"); imgBuffer = null; break; } return imgBuffer; }
public TreeNode FindSequences(PCCObject pcc, int index, bool wantFullName = false, bool refSeq = false) { string objectName = ""; if (refSeq) { List<SaltPropertyReader.Property> p = SaltPropertyReader.getPropList(pcc, pcc.Exports[index].Data); for (int i = 0; i < p.Count(); i++) if (p[i].Name == "ObjName") { objectName = p[i].Value.StringValue; break; } } else { objectName = pcc.Exports[index].ObjectName; } TreeNode ret = new TreeNode("#" + index.ToString() + ": " + (wantFullName ? pcc.Exports[index].GetFullPath : objectName)); ret.Name = index.ToString(); Sequence seq = new Sequence(pcc, index); if (seq.SequenceObjects != null) for (int i = 0; i < seq.SequenceObjects.Count(); i++) if (pcc.Exports[seq.SequenceObjects[i] - 1].ClassName == "Sequence" || pcc.Exports[seq.SequenceObjects[i] - 1].ClassName.StartsWith("PrefabSequence")) { TreeNode t = FindSequences(pcc, seq.SequenceObjects[i] - 1, wantFullName); ret.Nodes.Add(t); } else if (pcc.Exports[seq.SequenceObjects[i] - 1].ClassName == "SequenceReference") { var props = SaltPropertyReader.getPropList(pcc, pcc.Exports[seq.SequenceObjects[i] - 1].Data); var propSequenceReference = props.FirstOrDefault(p => p.Name.Equals("oSequenceReference")); if (propSequenceReference != null) { int n = propSequenceReference.Value.IntValue; if (propSequenceReference.Value.IntValue < 0) { n += 1; TreeNode t = new TreeNode("#" + n.ToString() + ": " + pcc.Imports[-n].Name + "(Import)"); t.Name = n.ToString(); ret.Nodes.Add(t); } else { TreeNode t = FindSequences(pcc, propSequenceReference.Value.IntValue - 1, wantFullName, true); ret.Nodes.Add(t); } } } return ret; }