private static void WriteRecord(BinaryWriter bw, Record r) { /*if(r.Size>4096) { MemoryStream ms=new MemoryStream(); BinaryWriter bw2=new BinaryWriter(ms); foreach(SubRecord sr in r.SubRecords) sr.SaveData(bw2); int len=(int)ms.Length; deflater.Reset(); deflater.SetInput(ms.GetBuffer(), 0, len); deflater.Finish(); int i=deflater.Deflate(outputbuffer); bw2.Close(); if(i==ushort.MaxValue) { throw new Exception("Don't handle this yet!"); } if(i<len*0.75) { WriteString(bw, r.Name); bw.Write(i+4); bw.Write(r.Flags1|0x00040000); bw.Write(r.FormID); bw.Write(r.Flags2); bw.Write(r.Flags3); return; } }*/ r.SaveData(bw); }
private HeaderEditor(Record r) { InitializeComponent(); Icon = Resources.fomm02; R = r; tbName.Text = r.Name; Flags1 = r.Flags1; Flags2 = r.Flags2; Flags3 = r.Flags3; FormID = r.FormID; tbFormID.Text = FormID.ToString("x8"); tbFlags2.Text = Flags2.ToString("x8"); tbFlags3.Text = Flags3.ToString("x8"); foreach (Control c in Controls) { if (c is CheckBox) { c.Tag = int.Parse((string) c.Tag); if ((Flags1 & GetInt(c.Tag)) > 0) { ((CheckBox) c).Checked = true; } } } cb18.Enabled = false; }
/// <summary> /// Compiles a script. /// </summary> /// <seealso cref="ModScript.CompileScript(Fomm.TESsnip.Record r2, out string msg)"/> public static void CompileScript(Record r2, out string msg) { try { Script.CompileScript(r2, out msg); r2.SubRecords.Clear(); for (int i = 0; i < r2.SubRecords.Count; i++) r2.SubRecords.Add((SubRecord)r2.SubRecords[i].Clone()); } catch (Exception e) { LastError = e.Message; msg = null; } }
/// <summary> /// Compiles the result script. /// </summary> /// <seealso cref="ModScript.CompileResultScript(Fomm.TESsnip.SubRecord sr, out Fomm.TESsnip.Record r2, out string msg)"/> public static void CompileResultScript(SubRecord sr, out Record r2, out string msg) { Record r; try { Script.CompileResultScript(sr, out r, out msg); } catch (Exception e) { LastError = e.Message; r = null; msg = null; } if (r != null) r2 = (Record)r.Clone(); else r2 = null; }
private Record(Record r) { SubRecords = new List<SubRecord>(r.SubRecords.Count); for (var i = 0; i < r.SubRecords.Count; i++) { SubRecords.Add((SubRecord) r.SubRecords[i].Clone()); } Flags1 = r.Flags1; Flags2 = r.Flags2; Flags3 = r.Flags3; FormID = r.FormID; Name = r.Name; descriptiveName = r.descriptiveName; }
internal GroupRecord(uint Size, BinaryReader br, bool Oblivion) { Name = "GRUP"; data = br.ReadBytes(4); groupType = br.ReadUInt32(); dateStamp = br.ReadUInt32(); if (!Oblivion) { flags = br.ReadUInt32(); } uint AmountRead = 0; while (AmountRead < Size - (Oblivion ? 20 : 24)) { var s = ReadRecName(br); var recsize = br.ReadUInt32(); if (s == "GRUP") { var gr = new GroupRecord(recsize, br, Oblivion); AmountRead += recsize; Records.Add(gr); } else { var r = new Record(s, recsize, br, Oblivion); AmountRead += (uint) (recsize + (Oblivion ? 20 : 24)); Records.Add(r); } } if (AmountRead > (Size - (Oblivion ? 20 : 24))) { throw new TESParserException("Record block did not match the size specified in the group header"); } if (groupType == 0) { descriptiveName = " (" + (char) data[0] + (char) data[1] + (char) data[2] + (char) data[3] + ")"; } }
public static void Display(Record r) { HeaderEditor hr=new HeaderEditor(r); hr.ShowDialog(); }
/// <summary> /// Gets the well-known MESG record's subrecord data containg the critical record info. /// </summary> /// <remarks> /// If the required record is not found, it is created. /// </remarks> /// <returns>The well-known MESG record's subrecord data containg the critical record info.</returns> protected SubRecord getCriticalRecordData() { GroupRecord grcGroup = null; Record recCriticalRecords = null; SubRecord srcCriticalData = null; foreach (var rec in Records) { grcGroup = rec as GroupRecord; if (grcGroup == null) { continue; } if (grcGroup.ContentsType == "MESG") { foreach (Record recRecord in grcGroup.Records) { foreach (var srcSubRecord in recRecord.SubRecords) { switch (srcSubRecord.Name) { case "EDID": if (srcSubRecord.GetStrData().Equals(CRITICAL_DATA_RECORD_EDID)) { recCriticalRecords = recRecord; } break; case "DESC": srcCriticalData = srcSubRecord; break; } } if (recCriticalRecords != null) { return srcCriticalData; } } } } //if there is no MESG group, create one if (grcGroup == null) { grcGroup = new GroupRecord("MESG"); AddRecord(grcGroup); } //if there is no fommCriticalRecords record, create one, we returned otherwise. recCriticalRecords = new Record(); recCriticalRecords.Name = "MESG"; var uintMastersCount = (UInt32) Masters.Count << 24; var uintFormId = uintMastersCount + 1; while (ContainsFormId(uintFormId)) { uintFormId++; } if ((uintFormId & 0xff000000) != uintMastersCount) { throw new PluginFullException("No available Form Id for new MESG record"); } recCriticalRecords.FormID = uintFormId; recCriticalRecords.Flags2 = 0x00044210; recCriticalRecords.Flags3 = 0x0002000f; var srcSub = new SubRecord(); srcSub.Name = "EDID"; srcSub.SetStrData(CRITICAL_DATA_RECORD_EDID, true); recCriticalRecords.SubRecords.Add(srcSub); srcCriticalData = new SubRecord(); srcCriticalData.Name = "DESC"; recCriticalRecords.SubRecords.Add(srcCriticalData); srcSub = new SubRecord(); srcSub.Name = "INAM"; srcSub.SetData(new byte[] { 0, 0, 0, 0 }); recCriticalRecords.SubRecords.Add(srcSub); srcSub = new SubRecord(); srcSub.Name = "DNAM"; srcSub.SetData(new byte[] { 0, 0, 0, 0 }); recCriticalRecords.SubRecords.Add(srcSub); srcSub = new SubRecord(); srcSub.Name = "TNAM"; srcSub.SetData(new byte[] { 0, 0, 0, 1 }); recCriticalRecords.SubRecords.Add(srcSub); grcGroup.AddRecord(recCriticalRecords); return srcCriticalData; }
/// <summary> /// Compiles a script. /// </summary> public void CompileScript(Record r2, out string msg) { Fomm.Games.Fallout3.Tools.TESsnip.ScriptCompiler.ScriptCompiler.Compile(r2, out msg); }
private static bool ReturnError(string msg, out string error) { error=ts.Line.ToString()+": "+msg; ts=null; r=null; return false; }
private static bool OutputErrors(out string msg) { msg=""; foreach(string s in errors) msg+=s+Environment.NewLine; ts=null; r=null; return false; }
private void TESsnip_FormClosing(object sender, FormClosingEventArgs e) { if (searchForm != null) { searchForm.Close(); } PluginTree.Nodes.Clear(); Clipboard = null; ClipboardNode = null; parentRecord = null; Properties.Settings.Default.windowPositions.SetWindowPosition("TESsnip", this); Properties.Settings.Default.Save(); }
private void insertRecordToolStripMenuItem_Click(object sender, EventArgs e) { if (searchForm != null && searchForm.InSearch) { MessageBox.Show("Cannot modify contents while searching", "Error"); return; } var node = (BaseRecord) PluginTree.SelectedNode.Tag; var p = new Record(); node.AddRecord(p); var tn = new TreeNode(p.Name); tn.Tag = p; PluginTree.SelectedNode.Nodes.Add(tn); }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (searchForm != null && searchForm.InSearch) { MessageBox.Show("Cannot modify contents while searching", "Error"); return; } var p = new Plugin(); var r = new Record(); r.Name = "TES4"; var sr = new SubRecord(); sr.Name = "HEDR"; sr.SetData(new byte[] { 0xD7, 0xA3, 0x70, 0x3F, 0xFA, 0x56, 0x0C, 0x00, 0x19, 0xEA, 0x07, 0xFF }); r.AddRecord(sr); sr = new SubRecord(); sr.Name = "CNAM"; sr.SetData(Encoding.ASCII.GetBytes("Default\0")); r.AddRecord(sr); p.AddRecord(r); var tn = new TreeNode(p.Name); tn.Tag = p; var tn2 = new TreeNode(r.DescriptiveName); tn2.Tag = r; tn.Nodes.Add(tn2); PluginTree.Nodes.Add(tn); }
private void PluginTree_AfterSelect(object sender, EventArgs e) { if (PluginTree.SelectedNode == null) { return; } //Enable and disable relevent menu items listView1.Items.Clear(); SelectedSubrecord = false; parentRecord = null; SubrecordStructs = null; FindMasters(); addMasterToolStripMenuItem.Enabled = (PluginTree.Nodes.Count > 0); if (PluginTree.SelectedNode.Tag is Plugin) { tbInfo.Text = ((BaseRecord) PluginTree.SelectedNode.Tag).GetDesc(); cutToolStripMenuItem.Enabled = false; copyToolStripMenuItem.Enabled = false; deleteToolStripMenuItem.Enabled = false; pasteToolStripMenuItem.Enabled = true; insertRecordToolStripMenuItem.Enabled = true; insertSubrecordToolStripMenuItem.Enabled = false; } else if (PluginTree.SelectedNode.Tag is Record) { cutToolStripMenuItem.Enabled = true; copyToolStripMenuItem.Enabled = true; deleteToolStripMenuItem.Enabled = true; pasteToolStripMenuItem.Enabled = true; insertRecordToolStripMenuItem.Enabled = false; insertSubrecordToolStripMenuItem.Enabled = true; var r = (Record) PluginTree.SelectedNode.Tag; foreach (var sr in r.SubRecords) { var lvi = new ListViewItem(new[] { sr.Name, sr.Size.ToString() }); lvi.Tag = sr; listView1.Items.Add(lvi); } parentRecord = r; MatchRecordStructureToRecord(); if (SubrecordStructs != null) { tbInfo.Text = ((Record) PluginTree.SelectedNode.Tag).GetDesc(SubrecordStructs, lookupFormidsToolStripMenuItem.Checked ? new dFormIDLookupI(LookupFormIDI) : null); } else { tbInfo.Text = ((BaseRecord) PluginTree.SelectedNode.Tag).GetDesc(); } } else { tbInfo.Text = ((BaseRecord) PluginTree.SelectedNode.Tag).GetDesc(); cutToolStripMenuItem.Enabled = true; copyToolStripMenuItem.Enabled = true; deleteToolStripMenuItem.Enabled = true; pasteToolStripMenuItem.Enabled = true; insertRecordToolStripMenuItem.Enabled = true; insertSubrecordToolStripMenuItem.Enabled = false; } }
/// <summary> /// Compiles the result script. /// </summary> public void CompileResultScript(SubRecord sr, out Record r2, out string msg) { ScriptCompiler.CompileResultScript(sr, out r2, out msg); }
/// <summary> /// Compiles a script. /// </summary> public void CompileScript(Record r2, out string msg) { ScriptCompiler.Compile(r2, out msg); }
public static bool CompileResultScript(SubRecord sr, out Record r2, out string msg) { msg=null; r2=null; r=new Record(); string script=sr.GetStrData(); locals.Clear(); localList.Clear(); edidRefs.Clear(); refcount=0; errors.Clear(); ts=new TokenStream(script, errors); if(errors.Count>0) return OutputErrors(out msg); schr=new SubRecord(); schr.Name="SCHR"; r.AddRecord(schr); scda=new SubRecord(); scda.Name="SCDA"; r.AddRecord(scda); sr=(SubRecord)sr.Clone(); r.AddRecord(sr); bw=new BinaryWriter(new MemoryStream()); while(ts.PeekNextStatement().Length>0) { try { HandleResultsBlock(); } catch(Exception ex) { return ReturnError(ex.Message, out msg); } } if(errors.Count>0) { return OutputErrors(out msg); } byte[] header=new byte[20]; TypeConverter.si2h(refcount, header, 4); TypeConverter.i2h((uint)bw.BaseStream.Length, header, 8); TypeConverter.si2h(localList.Count, header, 12); TypeConverter.si2h(0x10000, header, 16); schr.SetData(header); byte[] compileddata=((MemoryStream)bw.BaseStream).GetBuffer(); if(compileddata.Length!=bw.BaseStream.Length) Array.Resize<byte>(ref compileddata, (int)bw.BaseStream.Length); scda.SetData(compileddata); bw.Close(); r2=r; return true; }
public static bool Compile(Record r2, out string msg) { msg=null; r=new Record(); string script=null; int scptype=0; foreach(SubRecord sr2 in r2.SubRecords) { if(sr2.Name=="SCTX") script=sr2.GetStrData(); if(sr2.Name=="SCHR") { byte[] tmp=sr2.GetReadonlyData(); scptype=TypeConverter.h2si(tmp[16], tmp[17], tmp[18], tmp[19]); } } if(script==null) { msg="Script had no SCTX record to compile"; return false; } locals.Clear(); localList.Clear(); edidRefs.Clear(); refcount=0; errors.Clear(); ts=new TokenStream(script, errors); if(errors.Count>0) return OutputErrors( out msg); Token[] smt=ts.PopNextStatement(); if(smt.Length!=2||!smt[0].IsKeyword(Keywords.ScriptName)||smt[1].token==null) return ReturnError("Expected 'ScriptName <edid>'", out msg); SubRecord sr=new SubRecord(); sr.Name="EDID"; sr.SetStrData(smt[1].utoken, true); r.AddRecord(sr); r.descriptiveName=" ("+smt[1].token+")"; schr=new SubRecord(); schr.Name="SCHR"; r.AddRecord(schr); scda=new SubRecord(); scda.Name="SCDA"; r.AddRecord(scda); sr=new SubRecord(); sr.Name="SCTX"; sr.SetStrData(script, false); r.AddRecord(sr); bw=new BinaryWriter(new MemoryStream()); Emit(0x001d); Emit(0x0000); try { HandleVariables(); } catch(Exception ex) { return ReturnError(ex.Message, out msg); } for(int i=0;i<localList.Count;i++) { if(localList[i].type==VarType.Ref) { sr=new SubRecord(); sr.Name="SCRV"; sr.SetData(TypeConverter.si2h(i+1)); r.AddRecord(sr); refcount++; localList[i].refid=refcount; } } while(ts.PeekNextStatement().Length>0) { try { HandleBlock(); } catch(Exception ex) { return ReturnError(ex.Message, out msg); } } if(errors.Count>0) { return OutputErrors(out msg); } byte[] header=new byte[20]; TypeConverter.si2h(refcount, header, 4); TypeConverter.i2h((uint)bw.BaseStream.Length, header, 8); TypeConverter.si2h(localList.Count, header, 12); TypeConverter.si2h(scptype, header, 16); schr.SetData(header); byte[] compileddata=((MemoryStream)bw.BaseStream).GetBuffer(); if(compileddata.Length!=bw.BaseStream.Length) Array.Resize<byte>(ref compileddata, (int)bw.BaseStream.Length); scda.SetData(compileddata); r2.SubRecords.Clear(); r2.SubRecords.AddRange(r.SubRecords); bw.Close(); return true; }
/// <summary> /// Compiles the result script. /// </summary> public void CompileResultScript(SubRecord sr, out Record r2, out string msg) { Fomm.Games.Fallout3.Tools.TESsnip.ScriptCompiler.ScriptCompiler.CompileResultScript(sr, out r2, out msg); }