当前位置: 首页>>代码示例>>C#>>正文


C# SubRecord.SetData方法代码示例

本文整理汇总了C#中SubRecord.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# SubRecord.SetData方法的具体用法?C# SubRecord.SetData怎么用?C# SubRecord.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SubRecord的用法示例。


在下文中一共展示了SubRecord.SetData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compile

        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;
        }
开发者ID:robjer,项目名称:tesvsnip,代码行数:86,代码来源:ScriptCompiler.cs

示例2: AddMaster

        public bool AddMaster(string masterName)
        {
            Record brcTES4 = Records.OfType<Record>().FirstOrDefault(x => x.Name == "TES4");
            if (brcTES4 == null)
                throw new ApplicationException("Plugin lacks a valid TES4 record. Cannot continue.");
            // find existing if already present
            foreach (var mast in brcTES4.SubRecords.Where(x => x.Name == "MAST"))
            {
                var path = mast.GetStrData();
                if (string.Compare(path, masterName, true) == 0)
                    return false;
            }
            int idx = brcTES4.SubRecords.IndexOf(brcTES4.SubRecords.FirstOrDefault(x => x.Name == "INTV"));
            if (idx < 0) idx = brcTES4.SubRecords.Count;

            var sbrMaster = new SubRecord();
            sbrMaster = new SubRecord();
            sbrMaster.Name = "DATA";
            sbrMaster.SetData(new byte[] {0, 0, 0, 0, 0, 0, 0, 0});
            brcTES4.InsertRecord(idx, sbrMaster);

            sbrMaster = new SubRecord();
            sbrMaster.Name = "MAST";
            Int32 intCount = Encoding.CP1252.GetByteCount(masterName);
            var bteData = new byte[intCount + 1];
            Array.Copy(Encoding.CP1252.GetBytes(masterName), bteData, intCount);
            sbrMaster.SetData(bteData);
            brcTES4.InsertRecord(idx, sbrMaster);

            // Fix Masters
            //  Update IDs for current record to be +1
            return true;
        }
开发者ID:rxantos,项目名称:tesv-snip,代码行数:33,代码来源:Plugin.cs

示例3: EmitRefLabel

 private static void EmitRefLabel(Token t, RefType type)
 {
     if(t.type==TokenType.Global) {
         EmitByte(0x47);
     } else {
         switch(type) {
         case RefType.Standard: Emit(0x1c); break;
         case RefType.Expression: EmitByte(0x72); break;
         case RefType.Standalone: EmitByte(0x5a); break;
         }
     }
     if(t.type==TokenType.Local) {
         LocalVar var=locals[t.token];
         if(var.refid==0) AddError("Variable was not of type ref");
         else Emit((ushort)var.refid);
     } else if(t.type==TokenType.edid||t.type==TokenType.Global) {
         if(!edidRefs.ContainsKey(t.token)) {
             SubRecord sr=new SubRecord();
             sr.Name="SCRO";
             if(t.type==TokenType.edid) sr.SetData(TypeConverter.i2h(edidList[t.token].Key));
             else sr.SetData(TypeConverter.i2h(globals[t.token]));
             r.AddRecord(sr);
             refcount++;
             edidRefs[t.token]=(ushort)refcount;
         }
         Emit(edidRefs[t.token]);
     } else {
         AddError("Expected ref variable or edid");
     }
 }
开发者ID:robjer,项目名称:tesvsnip,代码行数:30,代码来源:ScriptCompiler.cs

示例4: CompileResultScript

        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;
        }
开发者ID:robjer,项目名称:tesvsnip,代码行数:50,代码来源:ScriptCompiler.cs

示例5: HandleVariables

        private static void HandleVariables()
        {
            Token[] smt=ts.PeekNextStatement();
            SubRecord slsd;
            SubRecord scvr;
            while(smt.Length>0&&smt[0].IsType()) {
                ts.PopNextStatement();
                if(smt.Length!=2||smt[1].type!=TokenType.Unknown) {
                    AddError("Expected <type> <variable name>");
                    smt=ts.PeekNextStatement();
                    continue;
                }
                slsd=new SubRecord();
                slsd.Name="SLSD";
                byte[] data=new byte[24];
                TypeConverter.si2h(locals.Count+1, data, 0);
                if(smt[0].IsKeyword(Keywords.Int)) data[16]=1;
                slsd.SetData(data);
                r.AddRecord(slsd);
                scvr=new SubRecord();
                scvr.Name="SCVR";
                scvr.SetStrData(smt[1].utoken, true);
                r.AddRecord(scvr);

                LocalVar lv=new LocalVar(locals.Count+1, smt[0]);
                locals.Add(smt[1].token, lv);
                localList.Add(lv);
                ts.AddLocal(smt[1].token);

                smt=ts.PeekNextStatement();
            }
        }
开发者ID:robjer,项目名称:tesvsnip,代码行数:32,代码来源:ScriptCompiler.cs

示例6: AddMaster

        public bool AddMaster(string masterName)
        {
            Record brcTES4 = this.Records.OfType<Record>().FirstOrDefault(x => x.Name.StartsWith("TES"));
            if (brcTES4 == null)
            {
                throw new ApplicationException("Plugin lacks a valid TES4 record. Cannot continue.");
            }

            // find existing if already present
            foreach (var mast in brcTES4.SubRecords.Where(x => x.Name == "MAST"))
            {
                var path = mast.GetStrData();
                if (string.Compare(path, masterName, true) == 0)
                {
                    return false;
                }
            }

            int idx = brcTES4.SubRecords.IndexOf(brcTES4.SubRecords.FirstOrDefault(x => x.Name == "INTV"));
            if (idx < 0)
            {
                idx = brcTES4.SubRecords.Count;
            }

            var sbrMaster = new SubRecord();
            sbrMaster.Name = "DATA";
            sbrMaster.SetData(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 });
            brcTES4.InsertRecord(idx, sbrMaster);

            sbrMaster = new SubRecord();
            sbrMaster.Name = "MAST";
            int intCount = Encoding.Instance.GetByteCount(masterName);
            var bteData = new byte[intCount + 1];
            Array.Copy(Encoding.Instance.GetBytes(masterName), bteData, intCount);
            sbrMaster.SetData(bteData);
            brcTES4.InsertRecord(idx, sbrMaster);

            int masterIdx = brcTES4.SubRecords.Count(x => x.Name == "MAST") - 1;
            // Update IDs for current record to be +1
            // Fix FormID and references now
            foreach (var rec in EnumerateRecords(null).Select(x => x.Value)
                .SkipWhile(x=>RecordLayout.NoNewCopyTypes.Contains(x.Name)))
            {
                if ((rec.FormID >> 24) >= masterIdx)
                    rec.FormID = (rec.FormID & 0x00FFFFFF) | (((rec.FormID >> 24) + 1) << 24);

                // now handle child references
                rec.MatchRecordStructureToRecord();
                foreach (var elem in rec.SubRecords
                    .SelectMany(sr => sr.EnumerateElements())
                    .Where(elem => elem.Structure != null && elem.Structure.type == ElementValueType.FormID) )
                {
                    var value = elem.GetValue<uint>();
                    if ((value >> 24) >= masterIdx)
                        elem.AssignValue<uint>((value & 0x00FFFFFF) | (((value >> 24) + 1) << 24));
                }
            }

            return true;
        }
开发者ID:figment,项目名称:tesvsnip,代码行数:60,代码来源:Plugin.cs

示例7: newToolStripMenuItem_Click

 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!ValidateMakeChange())
         return;
     Plugin p = new Plugin();
     Record r = new Record();
     r.Name = "TES4";
     SubRecord 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(System.Text.Encoding.ASCII.GetBytes("Default\0"));
     r.AddRecord(sr);
     p.AddRecord(r);
     TreeNode tn = new TreeNode(p.Name);
     tn.Tag = p;
     TreeNode tn2 = new TreeNode(r.DescriptiveName);
     tn2.Tag = r;
     tn.Nodes.Add(tn2);
     PluginTree.Nodes.Add(tn);
     UpdateStringEditor();
 }
开发者ID:robjer,项目名称:tesvsnip,代码行数:24,代码来源:MainView.cs


注:本文中的SubRecord.SetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。