Ejemplo n.º 1
0
        public void Compile()
        {
            var cpu = new Cpu(2048, 256);
            cpu.IdleProcess.Code.Append(cpu.Ram.Allocate(cpu.IdleProcess));

            var ms = cpu.GetMemoryStream(cpu.IdleProcess.Code);
            var writer = new CodeWriter(ms);
            Array.ForEach(IdleProcess.TerminatingIdle, writer.Write);
            writer.Close();

            var codeReader = new CodeReader(cpu.GetMemoryStream(cpu.IdleProcess.Code));

            var actual = codeReader.GetEnumerator();
            var expected = IdleProcess.TerminatingIdle.Cast<Instruction>().GetEnumerator();

            while ( actual.MoveNext() )
            {
                if ( expected.MoveNext() )
                {
                    Assert.That(actual.Current.OpCode, Is.EqualTo(expected.Current.OpCode));
                    Assert.That(actual.Current.Parameters, Is.EqualTo(expected.Current.Parameters));
                    Assert.That(actual.Current.Comment, Is.EqualTo(expected.Current.Comment));
                    continue;
                }

                Assert.That(actual.Current.OpCode, Is.EqualTo(OpCode.Noop));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the CodeLexer class.
        /// </summary>
        /// <param name="parser">The C# parser.</param>
        /// <param name="source">The source to read.</param>
        /// <param name="codeReader">Used for reading the source code.</param>
        internal CodeLexer(CsParser parser, SourceCode source, CodeReader codeReader)
        {
            Param.AssertNotNull(parser, "parser");
            Param.AssertNotNull(source, "source");
            Param.AssertNotNull(codeReader, "codeReader");

            this.parser = parser;
            this.source = source;
            this.codeReader = codeReader;
        }
Ejemplo n.º 3
0
        public void Decompile(string file)
        {
            file = string.Concat(_testPaths[Environment.MachineName], file);

            var objData = Compile(file);
            var reader = new CodeReader(objData);
            var writer = new InstructionTextWriter(Console.Out);
            foreach  (var instruction in reader)
            {
                writer.Write(instruction);
            }
        }
Ejemplo n.º 4
0
        public static bool TryScan(CodeReader reader, out AssignmentCommand command)
        {
            command = null;
            string line = reader.NextLine().Trim(';');

            if (!Regex.IsMatch(line, RegEx))
            {
                return(false);
            }
            string name  = line.Split(':')[0];
            string value = String.Join(":", line.Split(':').Skip(1));

            if (TryScan(value, out Command constructor))
            {
                command = new AssignmentCommand(name, constructor, constructor.ReturnType);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
 public Trigger(string checkInterval, string delayInterval, string rearmInterval) : base(checkInterval, ObjectType.Trigger)
 {
     if (ImportantMethods.IsNumeric(delayInterval, true))
     {
         DelayInterval = ReplaceIntervalWithCode(double.Parse(CodeReader.Repl_DotWComma(delayInterval)));
     }
     else
     {
         DelayInterval = delayInterval;
     }
     if (ImportantMethods.IsNumeric(rearmInterval, true))
     {
         ReArmInterval = ReplaceIntervalWithCode(double.Parse(CodeReader.Repl_DotWComma(rearmInterval)));
     }
     else
     {
         ReArmInterval = rearmInterval;
     }
 }
Ejemplo n.º 6
0
        private ProjectAuthenticationSettings InferApplicationParameters(
            ProvisioningToolOptions provisioningToolOptions,
            ProjectDescription projectDescription,
            IEnumerable <ProjectDescription> projectDescriptions)
        {
            CodeReader reader = new CodeReader();
            ProjectAuthenticationSettings projectSettings = reader.ReadFromFiles(provisioningToolOptions.ProjectPath, projectDescription, projectDescriptions);

            // Override with the tools options
            projectSettings.ApplicationParameters.ApplicationDisplayName ??= Path.GetFileName(provisioningToolOptions.ProjectPath);
            projectSettings.ApplicationParameters.ClientId ??= provisioningToolOptions.ClientId;
            projectSettings.ApplicationParameters.TenantId ??= provisioningToolOptions.TenantId;
            projectSettings.ApplicationParameters.CalledApiScopes ??= provisioningToolOptions.CalledApiScopes;
            if (!string.IsNullOrEmpty(provisioningToolOptions.AppIdUri))
            {
                projectSettings.ApplicationParameters.AppIdUri = provisioningToolOptions.AppIdUri;
            }
            return(projectSettings);
        }
Ejemplo n.º 7
0
        public bool TryInterpret(CodeInterpreter compiler, CodeReader reader, out IProcess process)
        {
            var backup = reader.Backup();

            process = null;

            if (reader.ReadName(out var name) && reader.ReadChar(out var bracketBegin) && bracketBegin == '(')
            {
                var parameters = new List <IProcess>();

Loop:

                if (reader.CurrentChar(out var bracketEnd) && bracketEnd == ')')
                {
                    reader.Next();

                    process = new InvokeFunctionProcess(name, parameters.ToArray());

                    return(true);
                }
Ejemplo n.º 8
0
        protected override void LoadSettingsAndLists()
        {
            base.LoadSettingsAndLists();

            CodeReader cr = new CodeReader(CodeReader.ModPath + CodeReader.Files[(int)Skriptum.ObjectType.Item]);

            itemsRList.AddRange(cr.ReadItem());

            for (int i = 0; i < CodeReader.Items.Count; i++)
            {
                items.Add(i + " - " + CodeReader.Items[i]);
            }

            if (Has3DView)
            {
                AddBrfFileEntryToModuleIni("Troop3DPreview");
            }

            LoadSets();
        }
Ejemplo n.º 9
0
            private static Token ReadStringLiteralNoEscape(CodeReader cr)
            {
                StringBuilder sb = new StringBuilder();

                int index = cr.Position;

                char quoteChar = cr.ReadChar();

                while (!cr.EOF && cr.PeekChar() != quoteChar)
                {
                    sb.Append(cr.ReadChar());
                }

                if (!cr.EOF)
                {
                    cr.AdvancePosition();
                }

                return(new Token(Token.TokenKind.String, sb.ToString(), cr.GetPositionInfo(index)));
            }
Ejemplo n.º 10
0
        public bool TryInterpret(CodeInterpreter compiler, CodeReader reader, out IProcess process)
        {
            var backup = reader.Backup();

            if (reader.ReadChar(out var bracketBegin) && bracketBegin == '(')
            {
                process = compiler.Interpret(reader, Priorities.None);

                if (reader.ReadChar(out var bracketEnd) && bracketEnd == ')')
                {
                    return(true);
                }
            }

            process = null;

            backup.Restore();

            return(false);
        }
Ejemplo n.º 11
0
        private void ReadDeclaring(string source)
        {
            var reader = new CodeReader(source);

            if (reader.IsNextNonWhiteSpace("({"))
            {
                Attributes    = reader.ReadAttributes();
                DeclaringType = DeclaringType.Attributes;
            }
            else if (reader.IsNextNonWhiteSpace('('))
            {
                Parameters    = reader.ReadParameters();
                DeclaringType = DeclaringType.Parameters;
            }
            else
            {
                Declare       = source;
                DeclaringType = DeclaringType.Declare;
            }
        }
Ejemplo n.º 12
0
        public static void UnloadCommonModules(MetadataPackage mp, string folder)
        {
            var requestModules = from o in mp.MetadataObjects.OfType <CommonModule>()
                                 select o;

            var requestContent = from module in requestModules
                                 join ir in mp.MetadataObjects on module.ImageRow.FileName + ".0" equals ir.ImageRow.FileName
                                 where ir.ImageRow.Body is Image
                                 orderby module.Name
                                 select new { FileName = module.Name, OriginalImage = ((Image)ir.ImageRow.Body), Module = ((Image)ir.ImageRow.Body).Rows.Where(i => i.FileName == "info").FirstOrDefault(), Image = ((Image)ir.ImageRow.Body).Rows.Where(i => i.FileName == "image").FirstOrDefault() };

            var files = requestContent.ToArray();

            foreach (var file in files)
            {
                if (file.Image == null)
                {
                    continue;
                }

                string fileName     = file.FileName;
                string opCodeString = file.Image.Body.ToString();

                //if (!(fileName == "Инт_СистемаСервер" || fileName == "Инт_СистемаСерверКэшируемый"))
                //    continue;

                using (StreamWriter outfile =
                           new StreamWriter(folder + fileName + ".opcode"))
                {
                    outfile.Write(opCodeString);
                }

                CodeReader reader           = new CodeReader(opCodeString, false);
                string     decompiledString = reader.GetSourceCode();
                using (StreamWriter outfile =
                           new StreamWriter(folder + fileName + ".txt"))
                {
                    outfile.Write(decompiledString);
                }
            }
        }
Ejemplo n.º 13
0
        public void Parse(CodeReader codeReader)
        {
            string nonParsedCode = codeReader.ReadCode();

            string[] parsedCode = codeReader.ParseCode(nonParsedCode);
            foreach (string word in parsedCode)
            {
                if (!Forth.IsCompiling())
                {
                    System.Console.Write("Running "); // 2do del
                    System.Console.WriteLine(word);   // 2do del
                    Forth.Run(word);
                }
                else
                {
                    System.Console.Write("Compiling "); // 2do del
                    System.Console.WriteLine(word);     // 2do del
                    Forth.Compile(word);
                };
            }
        }
Ejemplo n.º 14
0
        private void AddTriggers(string[] values, int ix, int x2)
        {
            int           endI         = ix + x2;
            List <string> triggerCodes = new List <string>();

            for (int i = ix; i < endI; i++)
            {
                triggerCodes.Add(values[i]);
            }

            foreach (string triggerCode in triggerCodes)
            {
                string[]      scriptLines   = triggerCode.Split();
                SimpleTrigger simpleTrigger = new SimpleTrigger(scriptLines[0]);
                string[]      tmpS          = new string[int.Parse(scriptLines[1]) + 1];
                tmpS[0]     = "SIMPLE_TRIGGER";
                scriptLines = CodeReader.GetStringArrayStartFromIndex(scriptLines, 1);
                simpleTrigger.ConsequencesBlock = CodeReader.GetStringArrayStartFromIndex(CodeReader.DecompileScriptCode(tmpS, scriptLines), 1);
                SimpleTriggers.Add(simpleTrigger);
            }
        }
Ejemplo n.º 15
0
        public void GetNonEndSnippetInfo()
        {
            var codeLines = new[]
            {
                "XXX",
                "//$Hoge",
                "YYY",
                "ZZZ",
                "//$Piyo",
                "AAA",
            };

            var exp = new[]
            {
                new ErrorSnippet("Hoge", "path", "Not exist snippet end tag."),
                new ErrorSnippet("Piyo", "path", "Not exist snippet end tag."),
            };
            var act = new CodeReader("path", codeLines).GetSnippetInfos();

            Assert.Equal(exp, act);
        }
Ejemplo n.º 16
0
        protected override void Language_cbb_SelectedIndexChanged(object sender, EventArgs e)
        {
            base.Language_cbb_SelectedIndexChanged(sender, e);

            if (CurrentTypeIndex >= 0)
            {
                GameMenu menu = (GameMenu)types[CurrentTypeIndex];

                if (language_cbb.SelectedIndex == LANGUAGE_EN_GZ && singleNameTranslation_txt.Text.Length == 0)
                {
                    singleNameTranslation_txt.Text = menu.Text.Replace('_', ' ');
                }

                if (language_cbb.SelectedIndex >= 0 && designer != null)
                {
                    designer.UpdateGameMenuText(singleNameTranslation_txt.Text);
                    PrepareOptionsLanguage();

                    string[] a = null;
                    if (mno_translations.Length > 0)
                    {
                        if (mno_translations[0] == null)
                        {
                            a = new string[menu.MenuOptions.Length];
                            for (int i = 0; i < a.Length; i++)
                            {
                                a[i] = menu.MenuOptions[i].Text.Replace('_', ' ');
                            }
                        }
                    }

                    if (a == null)
                    {
                        a = CodeReader.GetStringArrayStartFromIndex(mno_translations, 0, mno_translations.Length - menu.MenuOptions.Length);
                    }

                    designer.UpdateGameMenuOptionsTexts(a);
                }
            }
        }
Ejemplo n.º 17
0
        public bool TryInterpret(CodeInterpreter compiler, CodeReader reader, out IProcess process)
        {
            var backup = reader.Backup();

            process = null;

            if (reader.ReadName(out var _var) && _var == "var")
            {
Loop:

                if (reader.ReadName(out var name))
                {
                    IProcess initValue = null;

                    if (reader.CurrentChar(out var c) && c == '=')
                    {
                        reader.Next();

                        initValue = compiler.Interpret(reader, Priorities.AssignValueOperator);
                    }

                    if (reader.CurrentChar(out var c1) && c1 == ',')
                    {
                        reader.Next();

                        process = new VarProcess(name, initValue, process);

                        goto Loop;
                    }

                    process = new VarProcess(name, initValue, process);

                    return(true);
                }
            }

            backup.Restore();

            return(false);
        }
Ejemplo n.º 18
0
 public Scene(string[] raw_data, string[] otherScenes, string[] chestTroops, string terrainBase) : base(raw_data[1], ObjectType.Scene)
 {
     if (ImportantMethods.IsNumericGZ(raw_data[2]))
     {
         FlagsGZ = ulong.Parse(raw_data[2]);
         SetFlags();
     }
     else
     {
         Flags = raw_data[2];
         SetFlagsGZ();
     }
     MeshName    = raw_data[3];
     BodyName    = raw_data[4];
     MinPosition = new double[] { double.Parse(CodeReader.Repl_DotWComma(raw_data[5])), double.Parse(CodeReader.Repl_DotWComma(raw_data[6])) };
     MaxPosition = new double[] { double.Parse(CodeReader.Repl_DotWComma(raw_data[7])), double.Parse(CodeReader.Repl_DotWComma(raw_data[8])) };
     WaterLevel  = double.Parse(CodeReader.Repl_DotWComma(raw_data[9]));
     TerrainCode = raw_data[10];
     OtherScenes = otherScenes;
     ChestTroops = chestTroops;
     TerrainBase = terrainBase;
 }
Ejemplo n.º 19
0
 public Party(string[] raw_data) : base(raw_data[3].Substring(2), ObjectType.Party)
 {
     Name    = raw_data[4];
     FlagsGZ = ulong.Parse(raw_data[5]);
     SetFlagsString();
     MenuID                = int.Parse(raw_data[6]);
     PartyTemplateID       = int.Parse(raw_data[7]);
     PartyTemplate         = CodeReader.PartyTemplates[PartyTemplateID];
     FactionID             = int.Parse(raw_data[8]);
     Faction               = CodeReader.Factions[FactionID];
     Personality           = int.Parse(raw_data[9]);  //was ulong before
     AIBehavior            = int.Parse(raw_data[11]); //was ulong before
     AITargetParty         = int.Parse(raw_data[12]); //was ulong before
     InitialCoordinates[0] = Math.Round(double.Parse(CodeReader.Repl_DotWComma(raw_data[14])), 6);
     InitialCoordinates[1] = Math.Round(double.Parse(CodeReader.Repl_DotWComma(raw_data[15])), 6);
     Members               = new PMember[int.Parse(raw_data[21])];
     for (int i = 0; i < Members.Length; i++)
     {
         Members[i] = new PMember(new string[] { raw_data[(i * 4) + 22], raw_data[(i * 4) + 23], raw_data[(i * 4) + 24], raw_data[(i * 4) + 25] });
     }
     PartyDirectionInDegrees = Math.Round(double.Parse(CodeReader.Repl_DotWComma(raw_data[raw_data.Length - 1])), 6);//this.degrees = degrees;
 }
Ejemplo n.º 20
0
        public Task <Response <BarCodeData> > SendBarCodImage(CodeReader model)
        {
            var responseData = new  Response <BarCodeData>();

            try
            {
                model.Image = System.IO.File.ReadAllBytes(model.FileURL);
                var apiResponse = _barCodeRepo.GetCodeFromImage(model.Image);
                responseData.Succeeded = true;
                responseData.Data      = apiResponse.Result;
                responseData.Message   = "Success";
            }

            catch (Exception ex)
            {
                responseData.Succeeded = false;
                responseData.Errors.Add(ex.Message);
                responseData.Message = "Error in getting data";
            }

            return(Task.FromResult(responseData));
        }
Ejemplo n.º 21
0
        public static bool TryScan(CodeReader reader, Slide parent, out Step scanned)
        {
            scanned = null;
            string line = reader.NextLine();

            if (!Regex.IsMatch(line, RegEx))
            {
                return(false);
            }
            string name = Regex.Match(line, RegExHelper.String).Value.Trim('\'');

            scanned = new Step(name, parent);
            line    = reader.NextLine();

            while (!reader.Done && !reader.EndingKeyword && !Regex.IsMatch(line, RegEx))
            {
                if (String.IsNullOrWhiteSpace(line))
                {
                    line = reader.NextLine();
                    continue;
                }
                if (Command.TryScan(reader.Copy(), out Command command))
                {
                    reader.Skip(command.Lines - 1);
                    scanned.Add(command);
                }
                else if (StaticFunctionCallCommand.TryScan(line, out StaticFunctionCallCommand functionCallCommand))
                {
                    reader.Skip(functionCallCommand.Lines - 1);
                    scanned.Add(functionCallCommand);
                }
                else
                {
                    throw new ArgumentException("Unknwon Command in Line " + reader.TextLine + ".");
                }
                line = reader.NextLine();
            }
            return(true);
        }
Ejemplo n.º 22
0
        private static string[] ProcessBlock(string[] raw_data, int tmp, int start_index)
        {
            int xx = 0;
            int x  = -1;

            string[] tmpSX;
            string[] resArray = new string[tmp + 1];
            for (int i = start_index; i < raw_data.Length; i++)
            {
                if (!raw_data[i].Equals(string.Empty))
                {
                    x++;
                }
                else
                {
                    i = raw_data.Length;
                }
            }
            if (raw_data.Length > (start_index + x + 2))
            {
                if (raw_data[start_index + x + 2].Equals("NO_TEXT"))
                {
                    noErrorCode = !noErrorCode;
                }
            }
            resArray[0] = "TEXT";
            if (!noErrorCode)
            {
                xx++;
            }
            tmpSX = new string[x + 1 + xx];
            for (int i = start_index; i < (tmpSX.Length + start_index - 1); i++)
            {
                tmpSX[i - start_index + 1] = raw_data[i];
            }
            tmpSX[0] = resArray[0];
            return(CodeReader.GetStringArrayStartFromIndex(CodeReader.DecompileScriptCode(resArray, tmpSX), 1));
        }
        public void When_read_a_simple_tag()
        {
            var sourceCode = " dada\n<div class=\"login box1\" id=\"div1\" data-tooltip=\"salut, ça va?\">login: \n\t romcy</div>"
                             + "<img src=\"http://popo.fr/titi.gif\" />";

            var codeReader        = new CodeReader(sourceCode);
            var declarationReader = new HtmlDeclarationReader(codeReader);

            var element = declarationReader.ReadTagDeclaration();

            Assert.AreEqual(" dada\n", element.InnerText);
            Assert.AreEqual(DeclarationType.TextElement, element.Type);

            element = declarationReader.ReadTagDeclaration();
            Assert.AreEqual("div", element.Name);
            Assert.AreEqual(DeclarationType.OpenTag, element.Type);
            Assert.AreEqual(3, element.Attributes.Count);
            Assert.AreEqual("login box1", element.Attributes["class"]);
            Assert.AreEqual("div1", element.Attributes["id"]);
            Assert.AreEqual("salut, ça va?", element.Attributes["data-tooltip"]);

            element = declarationReader.ReadTagDeclaration();
            Assert.IsNull(element.Name);
            Assert.AreEqual("login: \n\t romcy", element.InnerText);
            Assert.AreEqual(DeclarationType.TextElement, element.Type);

            element = declarationReader.ReadTagDeclaration();
            Assert.AreEqual("div", element.Name);
            Assert.AreEqual(DeclarationType.CloseTag, element.Type);

            element = declarationReader.ReadTagDeclaration();
            Assert.AreEqual("img", element.Name);
            Assert.AreEqual(DeclarationType.SelfClosedTag, element.Type);
            Assert.AreEqual("http://popo.fr/titi.gif", element.Attributes["src"]);

            element = declarationReader.ReadTagDeclaration();
            Assert.IsNull(element);
        }
Ejemplo n.º 24
0
        public void Index()
        {
            var builder = new StringBuilder();

            builder.AppendLine("<!-- start generated table -->")
            .AppendLine("<table>");
            foreach (var info in DescriptorsWithDocs.OrderBy(x => x.DiagnosticDescriptor.Id))
            {
                builder.AppendLine("<tr>");
                builder.AppendLine($@"  <td><a href=""{info.DiagnosticDescriptor.HelpLinkUri}"">{info.DiagnosticDescriptor.Id}</a></td>");
                builder.AppendLine($"  <td>{info.DiagnosticDescriptor.Title}</td>");
                builder.AppendLine("</tr>");
            }

            builder.AppendLine("<table>")
            .Append("<!-- end generated table -->");
            var expected = new CodeReader(builder.ToString());

            DumpIfDebug(expected.ToString());
            var actual = new CodeReader(GetTable(File.ReadAllText(Path.Combine(SolutionDirectory, "Readme.md"))));

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 25
0
        public bool TryInterpret(CodeInterpreter compiler, CodeReader reader, out IProcess process)
        {
            var backup = reader.Backup();

            process = null;

            if (compiler.TryInterpret(reader, Priority, out var before))
            {
                if (reader.ReadOperator(out var operatorText) && OperatorText == operatorText)
                {
                    if (compiler.TryInterpret(reader, Priority, out var after))
                    {
                        process = CreateProcess(before, after);

                        return(true);
                    }
                }
            }

            backup.Restore();

            return(false);
        }
Ejemplo n.º 26
0
        public void GetNestedSnippetInfo()
        {
            var codeLines = new[]
            {
                "XXX",
                "//$Hoge",
                "YYY",
                "//$Fuga",
                "OOO",
                "//$Fuga",
                "//$Hoge",
                "ZZZ",
            };

            var exp = new[]
            {
                new Snippet("Hoge", new[] { "YYY", "//$Fuga", "OOO", "//$Fuga" }),
                new Snippet("Fuga", new [] { "OOO" }),
            };
            var act = new CodeReader("path", codeLines).GetSnippetInfos();

            Assert.Equal(exp, act);
        }
Ejemplo n.º 27
0
        public MapIcon(string[] raw_data) : base(raw_data[0], ObjectType.MapIcon)
        {
            if (ImportantMethods.IsNumericGZ(raw_data[1]))
            {
                FlagsGZ = int.Parse(raw_data[1]);
                SetFlags();
            }
            else
            {
                Flags = raw_data[1];
                SetFlagsGZ();
            }

            MapIconName = raw_data[2];
            Scale       = double.Parse(CodeReader.Repl_DotWComma(raw_data[3]));

            SoundID = int.Parse(raw_data[4]);
            Sound   = CodeReader.Sounds[SoundID];

            string x = CodeReader.Repl_DotWComma(raw_data[5]);
            string y = CodeReader.Repl_DotWComma(raw_data[6]);
            string z = CodeReader.Repl_DotWComma(raw_data[7]);

            if (x.Length > 1 && y.Length > 1 && z.Length > 1)
            {
                OffsetX = double.Parse(x);
                OffsetY = double.Parse(y);
                OffsetZ = double.Parse(z);
            }
            else
            {
                OffsetX = double.NaN;
                OffsetY = double.NaN;
                OffsetZ = double.NaN;
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDecode_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtBarcodeImageFile.Text))
            {
                return;
            }


            List <string> result = CodeReader.MultiRead(txtBarcodeImageFile.Text);

            tbResult.Text = string.Format("共获取到{0}条结果", result?.Count ?? 0);

            foreach (var item in result)
            {
                if (string.IsNullOrEmpty(tbResult.Text))
                {
                    tbResult.Text = item;
                }
                else
                {
                    tbResult.Text = tbResult.Text + "\r\n" + item;
                }
            }
        }
Ejemplo n.º 29
0
        public void When_reading_2_colapsed_spans()
        {
            var sourceCode = "<span>text 1</span><span>text 2</span>";
            var codeReader = new CodeReader(sourceCode);

            var word = codeReader.ReadWord();

            Assert.AreEqual("<", word.Value);

            word = codeReader.ReadWord();
            Assert.AreEqual("span", word.Value);

            word = codeReader.ReadWord();
            Assert.AreEqual(">", word.Value);

            word = codeReader.ReadWord();
            Assert.AreEqual("text", word.Value);

            word = codeReader.ReadWord();
            Assert.AreEqual(" ", word.Value);

            word = codeReader.ReadWord();
            Assert.AreEqual("1", word.Value);

            word = codeReader.ReadWord();
            Assert.AreEqual("<", word.Value);

            word = codeReader.ReadWord();
            Assert.AreEqual("/", word.Value);

            word = codeReader.ReadWord();
            Assert.AreEqual("span", word.Value);

            word = codeReader.ReadWord();
            Assert.AreEqual(">", word.Value);
        }
Ejemplo n.º 30
0
 internal void EnterTry()
 {
     _currentTryBlock = new TryBlockInfo(CodeReader.ReadInteger(), LocalScope, _currentTryBlock);
 }
Ejemplo n.º 31
0
        public void Tick()
        {
            if (CurrentProcess == null || CurrentProcess.Quanta == 0 || CurrentProcess == IdleProcess)
            {
                CurrentProcess = SwitchToNextProcess();
            }

            Stream codeStream = GetMemoryStream(CurrentProcess.Code);
            var codeReader = new CodeReader(codeStream);
            var instruction = codeReader[Ip];
            if (instruction != null)
            {
                Execute(instruction);
            }
            else
            {
                foreach (var page in CurrentProcess.PageTable)
                    Ram.Free(page);

                CurrentProcess.IsRunning = false;
                CurrentProcess = null;
            }

            TickSleepTimer();
            ReadTerminal();
            WriteTerminal();

            TickCount++;
        }
Ejemplo n.º 32
0
 protected override void Deserialize(CodeReader reader)
 {
     //do nothing
 }
Ejemplo n.º 33
0
        public Party(string[] source_data, bool hasDegree) : base(source_data[0], ObjectType.Party)
        {
            int curIdx = 0;

            Name = source_data[curIdx++];

            Flags = source_data[curIdx++];
            SetFlagsGZ();

            Menu = source_data[curIdx++];
            if (Menu.Equals("no_menu"))
            {
                MenuID = 0;
            }
            else
            {
                MenuID = CodeReader.GameMenus.IndexOf(Menu);
            }

            PartyTemplate   = source_data[curIdx++];
            PartyTemplateID = CodeReader.PartyTemplates.IndexOf(PartyTemplate);

            //faction = source_data[curIdx++];
            //if (faction.Equals("no_faction"))
            //    factionID = -1;
            //else
            FactionID = CodeReader.Factions.IndexOf(source_data[curIdx++]);

            string tmpS = source_data[curIdx++].Replace("soldier_personality", "aggressiveness_8|courage_9");

            tmpS = tmpS.Replace("merchant_personality", "aggressiveness_0|courage_7");
            tmpS = tmpS.Replace("escorted_merchant_personality", "aggressiveness_0|courage_11");
            tmpS = tmpS.Replace("bandit_personality", "aggressiveness_3|courage_8|banditness");

            int x = 0;

            string[] tmp = tmpS.Split('|');
            string[] tmp2;
            foreach (string s in tmp)
            {
                tmp2 = s.Trim().Split('_');
                if (tmp2[0].Equals("courage"))
                {
                    x |= int.Parse(tmp2[1]);
                }
                else if (tmp2[0].Equals("aggressiveness"))
                {
                    x |= int.Parse(tmp2[1]) << 4;
                }
                else if (tmp2[0].Equals("banditness"))
                {
                    x |= 0x0100;
                }
            }
            Personality = x;

            x   = 0;
            tmp = source_data[curIdx++].Split('|');
            foreach (string s in tmp)
            {
                for (int i = 0; i < AiBehaviors.Length; i++)
                {
                    if (AiBehaviors[i].Equals(s))
                    {
                        x |= i;
                        i  = AiBehaviors.Length;
                    }
                }
            }
            AIBehavior = x;

            tmp = new string[] { source_data[curIdx++] };
            x   = CodeReader.Parties.IndexOf(tmp[0]);
            if (x < 0)
            {
                x = 0;
            }
            AITargetParty = x;

            InitialCoordinates[0] = Math.Round(double.Parse(CodeReader.Repl_DotWComma(source_data[curIdx++].TrimStart('(', ' '))), 6);
            InitialCoordinates[1] = Math.Round(double.Parse(CodeReader.Repl_DotWComma(source_data[curIdx++].TrimEnd(')', ' '))), 6);

            x = 0;
            if (hasDegree)
            {
                x++;
            }
            x = (source_data.Length - (11 + x)) / 3;

            Members = new PMember[x];
            for (int i = 0; i < x; i++)
            {
                curIdx = 11 + i * 3;
                if (!ImportantMethods.IsNumericGZ(source_data[curIdx]))
                {
                    source_data[curIdx] = CodeReader.Troops.IndexOf(source_data[curIdx]).ToString();
                }
                curIdx += 2;
                if (source_data[curIdx].Equals("pmf_is_prisoner"))
                {
                    source_data[curIdx] = "1";
                }
                if (!ImportantMethods.IsNumericGZ(source_data[curIdx]))
                {
                    DisplayErrorMessage();
                }
                curIdx    -= 2;
                Members[i] = new PMember(new string[] { source_data[curIdx], source_data[curIdx++], source_data[curIdx++] });
            }

            if (hasDegree)
            {
                PartyDirectionInDegrees = Math.Round(double.Parse(CodeReader.Repl_DotWComma(source_data[source_data.Length - 1].TrimEnd(')', ' '))), 6);
            }
            else
            {
                PartyDirectionInDegrees = 0d;
            }
        }
Ejemplo n.º 34
0
        protected override void SetupType(Skriptum type)
        {
            base.SetupType(type);

            Party party = (Party)type;

            name_txt.Text = party.Name;

            #region GROUP2 - Flags

            List <string> flags    = new List <string>(party.Flags.Split('|'));
            List <string> mapicons = new List <string>(CodeReader.MapIcons);

            map_icon_cbb.SelectedIndex = mapicons.IndexOf(flags[0]);

            if (flags.Contains("pf_label_large"))
            {
                large_label_rb.Checked = true;
            }
            else if (flags.Contains("pf_label_medium"))
            {
                medium_label_rb.Checked = true;
            }
            else if (flags.Contains("pf_label_small"))
            {
                small_label_rb.Checked = true;
            }
            if (flags.Contains("pf_no_label"))
            {
                no_label_rb.Checked = true;
            }

            Control c;
            string  nameEnd;
            bool    found = false;
            foreach (string flag in flags)
            {
                for (int i = 0; i < groupBox_1_gb.Controls.Count; i++)
                {
                    c       = groupBox_1_gb.Controls[i];
                    nameEnd = GetNameEndOfControl(c);
                    if (flag.Equals("pf_" + c.Name.Remove(c.Name.LastIndexOf('_'))))
                    {
                        if (nameEnd.Equals("rb"))
                        {
                            ((RadioButton)c).Checked = true;
                        }
                        else
                        {
                            ((CheckBox)c).CheckState = CheckState.Checked;
                        }
                        found = true;
                    }
                    else if (flag.Contains("carries_"))
                    {
                        string f = flag.Substring(flag.IndexOf('(') + 1).Split(')')[0];
                        if (flag.Contains("goods"))
                        {
                            carries_goods_txt.Text = f;
                        }
                        else
                        {
                            carries_gold_txt.Text = f;
                        }
                        found = true;
                    }
                    if (found)
                    {
                        i = groupBox_1_gb.Controls.Count;
                    }
                }
            }

            #endregion

            #region GROUP3

            menuID_cbb.SelectedIndex         = party.MenuID;
            party_template_cbb.SelectedIndex = party.PartyTemplateID;
            faction_cbb.SelectedIndex        = party.FactionID;
            ai_bhvr_cbb.SelectedIndex        = party.AIBehavior;
            ai_target_p_cbb.SelectedIndex    = party.AITargetParty;

            #endregion

            #region GROUP4

            char[] personality = HexConverter.Dec2Hex(party.Personality).ToString().Substring(5).ToCharArray();
            courage_num.Value        = int.Parse(personality[0].ToString());
            aggressiveness_num.Value = int.Parse(personality[1].ToString());
            if (personality[2] != '0')
            {
                banditness_cb.CheckState = CheckState.Checked;
            }
            double[] coords = party.InitialCoordinates;
            x_axis_txt.Text = CodeReader.Repl_CommaWDot(coords[0].ToString());
            y_axis_txt.Text = CodeReader.Repl_CommaWDot(coords[1].ToString());
            direction_in_degrees_txt.Text = CodeReader.Repl_CommaWDot(party.PartyDirectionInDegrees.ToString());

            #endregion

            #region Stack Troops - GROUP5

            memberValues.Clear();
            stack_troops_lb.Items.Clear();
            if (party.Members.Length > 0)
            {
                foreach (PMember member in party.Members)
                {
                    stack_troops_lb.Items.Add(member.Troop);
                    int[] values = new int[3];
                    values[0] = member.MinimumTroops;
                    values[1] = member.MaximumTroops;
                    values[2] = member.Flags;
                    memberValues.Add(values);
                }
                if (party.Members.Length > 0)
                {
                    stack_troops_lb.SelectedIndex = 0;
                }
            }

            #endregion
        }