private string AccumulatePartial(TextReader reader) { StringBuilder buffer = new StringBuilder(); buffer.Append(">"); do { reader.Read(); } while(char.IsWhiteSpace((char)reader.Peek())); while(true) { var peek = (char)reader.Peek(); if (peek == '}' || peek == '~' || char.IsWhiteSpace(peek)) { break; } var node = reader.Read(); if (node == -1) { throw new InvalidOperationException("Reached end of template before the expression was closed."); } else { buffer.Append((char)node); } } return buffer.ToString(); }
/// <summary> /// Processes text from TextReader and splits it into tokens. /// </summary> /// <param name="reader">The TextReader to read string from</param> /// <returns>The collection parsed tokens of the input string</returns> public static IEnumerable<WktToken> Tokenize(TextReader reader) { StringBuilder stringBuffer = new StringBuilder(); if (reader.Peek() == -1) { yield break; } char ch = (char)reader.Read(); stringBuffer.Append(ch); TokenType lastToken = WktTokenizer.GetTokenType(ch); while (reader.Peek() != -1) { ch = (char)reader.Read(); TokenType token = WktTokenizer.GetTokenType(ch); // tokens COMMA, LEFT_PARENTHESIS and RIGHT_PARENTHESIS can not be grupped together if ((token != lastToken) || token == TokenType.COMMA || token == TokenType.LEFT_PARENTHESIS || token == TokenType.RIGHT_PARENTHESIS) { yield return new WktToken() { Type = lastToken, Value = stringBuffer.ToString() }; stringBuffer.Clear(); lastToken = token; } stringBuffer.Append(ch); } yield return new WktToken() { Type = lastToken, Value = stringBuffer.ToString() }; }
public WktTokenQueue Tokenize(TextReader reader) { var queue = new WktTokenQueue(); var builder = new StringBuilder(); var nextCh = reader.Peek(); while (nextCh != -1) { var ch = (char)reader.Read(); var type = GetTokenType(ch); nextCh = reader.Peek(); var nextType = WktTokenType.None; if (nextCh != -1) nextType = GetTokenType((char)nextCh); if (type != WktTokenType.Whitespace) { builder.Append(ch); if (type != nextType || type == WktTokenType.Comma || type == WktTokenType.LeftParenthesis || type == WktTokenType.RightParenthesis) { if (type != WktTokenType.Whitespace) queue.Enqueue(new WktToken(type, builder.ToString())); builder.Remove(0, builder.Length); } } } return queue; }
/// <summary> /// Reads a number from a text reader. /// </summary> /// <param name="input">The input to read from.</param> /// <returns>The number read.</returns> public static double ReadNumber(TextReader input) { // TODO: Check whether this is used in the parser (move to ModMaker.Lua) and make this // consitent with the spec. StringBuilder build = new StringBuilder(); int c = input.Peek(); int l = c; bool hex = false; CultureInfo ci = CultureInfo.CurrentCulture; if (c == '0') { input.Read(); c = input.Peek(); if (c == 'x' || c == 'X') { input.Read(); hex = true; } } while (c != -1 && (char.IsNumber((char)c) || (hex && ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) || (!hex && (c == ci.NumberFormat.NumberDecimalSeparator[0] || c == '-' || (l != '.' && c == 'e'))))) { input.Read(); build.Append((char)c); l = c; c = input.Peek(); } return double.Parse(build.ToString(), ci); }
private static void readEmptyCharacters(TextReader reader) { while (reader.Peek() >= 0 && Char.IsWhiteSpace((char)reader.Peek())) { reader.Read(); } }
/// <summary> /// Escapes the characters in a String /// </summary> /// <param name="reader">the input string reader to escaping.</param> /// <returns>a string that has been escaped.</returns> public static string Escape(TextReader reader) { var sb = new StringBuilder(); var code = -1; while ((code = reader.Read()) >= 0) { var ch = (char)code; if (ch == '<') { sb.Append(ch); if (reader.Peek() != -1 && ((char)reader.Peek()) == '/') { sb.Append(@"\/"); reader.Read(); } } else { string escapeChar = null; if (_escapeSequences.TryGetValue(ch, out escapeChar)) { sb.Append(escapeChar); } else { sb.Append(ch); } } } return sb.ToString(); }
public static void CorrectIndent(TextReader code, int startOffset, int endOffset, Action<int, int, string> documentReplace, DFormattingOptions options = null, ITextEditorOptions textStyle = null, bool formatLastLine = true) { textStyle = textStyle ?? TextEditorOptions.Default; var eng = new IndentEngine(options ?? DFormattingOptions.CreateDStandard(), textStyle.TabsToSpaces, textStyle.IndentSize, textStyle.KeepAlignmentSpaces); var replaceActions = new List<DFormattingVisitor.TextReplaceAction>(); int originalIndent = 0; bool hadLineBreak = true; int n = 0; for (int i = 0; i <= endOffset && (n = code.Read()) != -1; i++) { if(n == '\r' || n == '\n') { if (i >= startOffset && !eng.LineBeganInsideString) replaceActions.Add(new DFormattingVisitor.TextReplaceAction(eng.Position - eng.LineOffset, originalIndent, eng.ThisLineIndent)); hadLineBreak = true; originalIndent = 0; if (code.Peek() == '\n') { eng.Push((char)code.Read()); i++; } } else if(hadLineBreak) { if(n == ' ' || n== '\t') originalIndent++; else hadLineBreak = false; // If there's code left, format the last line of the selection either if (i == endOffset && formatLastLine) endOffset++; } eng.Push((char)n); } // Also indent the last line if we're at the EOF. if (code.Peek() == -1 || (formatLastLine && n != '\r' && n != '\n')) { if(!eng.LineBeganInsideString) replaceActions.Add(new DFormattingVisitor.TextReplaceAction(eng.Position - eng.LineOffset, originalIndent, eng.ThisLineIndent)); } // Perform replacements from the back of the document to the front - to ensure offset consistency for(int k = replaceActions.Count - 1; k>=0; k--) { var rep = replaceActions[k]; if(rep.RemovalLength > 0 || rep.NewText.Length != 0) documentReplace(rep.Offset, rep.RemovalLength, rep.NewText); } }
public static object ParseImpl(TextReader reader, GRGEN_LIBGR.AttributeType attrType, GRGEN_LIBGR.IGraph graph) { char lookahead = (char)reader.Peek(); if(lookahead == 'o') { reader.Read(); // eat 'o' return new Own(); } else if(lookahead == 'p') { reader.Read(); // eat 'p' StringBuilder sb = new StringBuilder(); while(reader.Peek() != ',' && reader.Peek() != ')') // attributes are separated by , a node/edge terminated by ) in .grs sb.Append((char)reader.Read()); // eat non ',', ')' OwnPown op = new OwnPown(); op.ehe = sb.ToString(); return op; } else if(lookahead == 'h') { reader.Read(); // eat 'h' StringBuilder sb = new StringBuilder(); while(reader.Peek() != ';') sb.Append((char)reader.Read()); // eat non ';' string ehe = sb.ToString(); sb.Length = 0; reader.Read(); // eat ';' while(reader.Peek() != ',' && reader.Peek() != ')') // attributes are separated by , a node/edge terminated by ) in .grs sb.Append((char)reader.Read()); // eat non ',',')' OwnPownHome oph = new OwnPownHome(); oph.ehe = ehe; oph.aha = sb.ToString(); return oph; } else { if(reader.Peek() == 'n') { reader.Read(); if(reader.Peek() == 'u') { reader.Read(); if(reader.Peek() == 'l') { reader.Read(); if(reader.Peek() == 'l') { reader.Read(); return null; } } } } throw new Exception("parsing failure"); } }
public AssemblyQualifiedTypeName ParseTypeName(string text, string defaultNamespace, string defaultAssembly) { text = text.Trim(); StringBuilder type = new StringBuilder(text.Length); string assembly = StringHelper.IsEmpty(defaultAssembly) ? null : defaultAssembly; try { bool seenNamespace = false; input = new StringReader(text); int code; while ((code = input.Peek()) != -1) { char ch = (char) code; if (ch == '.') { seenNamespace = true; } if (ch == ',') { input.Read(); assembly = AssemblyName(); if (input.Peek() != -1) { throw new ParserException("Extra characters found at the end of the type name"); } } else if (ch == '[') { type.Append(BracketedPart()); } else { type.Append(PossiblyEscapedCharacter()); } } input.Close(); if (!seenNamespace && StringHelper.IsNotEmpty(defaultNamespace)) { type.Insert(0, '.') .Insert(0, defaultNamespace); } return new AssemblyQualifiedTypeName(type.ToString(), assembly); } catch (Exception e) { throw new ArgumentException("Invalid fully-qualified type name: " + text, "text", e); } }
public static char PeekNextChar(TextReader r, bool ignoreWhitespace) { var c = (char)r.Peek(); while (ignoreWhitespace && char.IsWhiteSpace(c)) { r.Read(); c = (char)r.Peek(); } return c; }
private static FormatToken ParseProperty(TextReader reader) { reader.Read(); // Consume if (reader.Peek() == -1) { return new LiteralToken("{"); } if ((char)reader.Peek() == '{') { reader.Read(); return new LiteralToken("{{"); } var builder = new StringBuilder(); while (true) { var current = reader.Peek(); if (current == -1) { break; } var character = (char)current; if (character == '}') { reader.Read(); var accumulated = builder.ToString(); var parts = accumulated.Split(new[] { ':' }, StringSplitOptions.None); if (parts.Length > 1) { var name = parts[0]; var format = string.Join(string.Empty, parts.Skip(1)); var positional = IsNumeric(name); if (!positional) { throw new FormatException("Input string was not in a correct format."); } var position = int.Parse(name, CultureInfo.InvariantCulture); return new PropertyToken(position, format); } else { var positional = IsNumeric(accumulated); if (!positional) { throw new FormatException("Input string was not in a correct format."); } var position = int.Parse(accumulated, CultureInfo.InvariantCulture); return new PropertyToken(position, null); } } builder.Append((char)reader.Read()); } return new LiteralToken(builder.ToString()); }
public static void GetNextWord(TextReader reader) { while (!IsEndOfBuffer(reader)) { if (!IsSeparator((char)reader.Peek()) || IsNewLine((char)reader.Peek())) { break; } reader.Read(); } }
private static void parseCommaSeparatedField( TextReader tr, List<string> fields ) { if( tr.Peek() != -1 ) { string field; if( tr.Peek() != '"' ) field = parseSimpleField( tr ); else field = parseQuotedField( tr ); fields.Add( field.Trim() ); } }
/// <summary> /// Parse the output from a TFS History check <see cref="Modification"/>s. /// </summary> /// <param name="vstsLog">The output of the "TF History command.</param> /// <param name="from">The starting timestamp.</param> /// <param name="to">The ending timestamp.</param> /// <returns>A list of modifications between the two timestamps, possibly empty.</returns> public Modification[] Parse(TextReader vstsLog, DateTime from, DateTime to) { startTime = from; endTime = to; string logFileLine; StringBuilder changeSet = new StringBuilder(null); var mods = new List<Modification>(); if (vstsLog.Peek() != -1 && Convert.ToChar(vstsLog.Peek()) == Convert.ToChar("-")) { while ((logFileLine = vstsLog.ReadLine()) != null) { if (logFileLine == "-------------------------------------------------------------------------------") { if (changeSet.Length != 0) { Modification[] tempMods = ParseChangeSet(changeSet); foreach (Modification change in tempMods) { mods.Add(change); } changeSet = new StringBuilder(null); } } else if (logFileLine == "No history entries were found for the item and version combination specified") { return new Modification[0]; } else { changeSet.AppendLine(logFileLine); } } if (!string.IsNullOrEmpty(changeSet.ToString())) { Modification[] tempMods = ParseChangeSet(changeSet); foreach (Modification change in tempMods) { mods.Add(change); } } } return mods.ToArray(); }
public static string CopyNextWord(TextReader sr) { StringBuilder sb = new StringBuilder(); GetNextWord(sr); while (!IsSeparator((char)sr.Peek()) && !IsEndOfBuffer(sr)) { sb.Append((char)sr.Read()); if (sr.Peek() == -1) { break; } } return sb.ToString(); }
/// <inheritdoc /> public override ITerm Read(TextReader reader) { // CONTRACT: Inherited from TermTextReader this.ReadWhitespace(reader); // TODO: Handle the case where Peek() returns -1. char ch = (char)reader.Peek(); switch (ch) { case '[': return ReadList(reader); case '(': return ReadTuple(reader); case '"': return ReadString(reader); case '<': return ReadPlaceholder(reader); } if (Char.IsNumber(ch)) return ReadNumber(reader); else if (Char.IsLetter(ch)) return ReadCons(reader); // TODO: Use the new string interpolation from C# 6. throw new TermParseException("Invalid term starting with '" + ch + "'."); }
/// <summary> /// Seeks the first character of a specified line in the text stream. /// </summary> /// <param name="reader">The reader.</param> /// <param name="line">Line number. The current position is assumed to be line #1.</param> /// <returns> /// Returns <c>true</c> if the line is found, <b>false</b> otherwise. /// </returns> public static bool SeekLine(TextReader reader, int line) { ContractUtils.RequiresNotNull(reader, "reader"); if (line < 1) throw new ArgumentOutOfRangeException("line"); if (line == 1) return true; int current_line = 1; for (; ; ) { int c = reader.Read(); if (c == '\r') { if (reader.Peek() == '\n') { reader.Read(); } current_line++; if (current_line == line) return true; } else if (c == '\n') { current_line++; if (current_line == line) return true; } else if (c == -1) { return false; } } }
public static void SkipLine(TextReader sr, ref uint line) { while (!IsEndOfBuffer(sr) && !IsNewLine((char)sr.Peek())) { sr.Read(); } if (sr.Peek() != -1) { sr.Read(); line++; } while ((sr.Peek() != -1) && (sr.Peek() == '\t' || sr.Peek() == ' ')) { sr.Read(); } }
internal PlainPPM(TextReader reader) { // Read width, height and range Width = ParseNumber(ReadToken(reader)); Height = ParseNumber(ReadToken(reader)); MaxVal = ParseNumber(ReadToken(reader), 1, 65535); float scale = 255 / MaxVal; // Skip single whitespace character reader.Read(); // Read raster InitializeRaster(); int length = Width * Height; for (int i = 0; i < length; i++) { int pik = reader.Peek(); byte r = Convert.ToByte(ParseNumber(ReadToken(reader), 0, MaxVal) * scale); byte g = Convert.ToByte(ParseNumber(ReadToken(reader), 0, MaxVal) * scale); byte b = Convert.ToByte(ParseNumber(ReadToken(reader), 0, MaxVal) * scale); SetPixel(i, r, g, b); } }
public static void GenerateResult (TextReader sr, TextWriter sw, Uri baseUri) { while (sr.Peek () > 0) { string uriString = sr.ReadLine (); if (uriString.Length == 0 || uriString [0] == '#') continue; Uri uri = (baseUri == null) ? new Uri (uriString) : new Uri (baseUri, uriString); sw.WriteLine ("-------------------------"); sw.WriteLine (uriString); sw.WriteLine (uri.ToString ()); sw.WriteLine (uri.AbsoluteUri); sw.WriteLine (uri.Scheme); sw.WriteLine (uri.Host); sw.WriteLine (uri.LocalPath); sw.WriteLine (uri.Query); sw.WriteLine (uri.Port); sw.WriteLine (uri.IsFile); sw.WriteLine (uri.IsUnc); sw.WriteLine (uri.IsLoopback); sw.WriteLine (uri.UserEscaped); sw.WriteLine (uri.HostNameType); sw.WriteLine (uri.AbsolutePath); sw.WriteLine (uri.PathAndQuery); sw.WriteLine (uri.Authority); sw.WriteLine (uri.Fragment); sw.WriteLine (uri.UserInfo); sw.Flush (); } sr.Close (); sw.Close (); }
/// <summary> /// Construct and return an array of Modifications describing the changes in /// the AccuRev workspace, based on the output of the "accurev hist" command. /// </summary> /// <param name="history">the stream of <code><modifications></code> input</param> /// <param name="from">the starting date and time for the range of modifications we want.</param> /// <param name="to">the ending date and time for the range of modifications we want.</param> /// <returns>the changes in the specified time range.</returns> public Modification[] Parse(TextReader history, DateTime from, DateTime to) { XmlSerializer serializer = new XmlSerializer(typeof (Modification[])); Modification[] mods = new Modification[0]; try { // return 0 modifications if "history" is empty. if (history.Peek() == -1) return mods; mods = (Modification[]) serializer.Deserialize(history); } catch (InvalidOperationException e) { Log.Error(e); if (e.InnerException is XmlException) return mods; throw; } var results = new List<Modification>(); foreach (Modification mod in mods) { if ((mod.ModifiedTime >= from) & (mod.ModifiedTime <= to)) results.Add(mod); } return results.ToArray(); }
private static string AccumulateLiteral(TextReader reader, bool captureDelimiter, params char[] delimiters) { StringBuilder buffer = new StringBuilder(); while (true) { var node = reader.Peek(); if (node == -1) { throw new InvalidOperationException("Reached end of template before the expression was closed."); } else { if (delimiters.Contains((char)node)) { if (captureDelimiter) { reader.Read(); } break; } else if ((char)node == '}') { break; } else { buffer.Append((char)reader.Read()); } } } return buffer.ToString(); }
public static string CalculateIndent(TextReader code, int line, bool tabsToSpaces = false, int indentWidth = 4) { if(line < 2) return string.Empty; var eng = new IndentEngine(DFormattingOptions.CreateDStandard(), tabsToSpaces, indentWidth); int curLine = 1; const int lf = (int)'\n'; const int cr = (int)'\r'; int c; while((c = code.Read()) != -1) { if(c == lf || c == cr) { if(c == cr && code.Peek() == lf) code.Read(); if(++curLine > line) break; } eng.Push((char)c); } return eng.ThisLineIndent; }
static void DeserializeArray(TextReader reader, ObjectBuilder builder) { int c; builder.StartArray(); while(true) { c = reader.Peek(); if (c == -1) throw new DeserializationException("Unexpected end of stream", reader); if (c == ']') { reader.Read(); // skip the ] break; } _DeserializeMember(reader, builder); Methods.ConsumeWhiteSpace(reader); c = reader.Read(); if(c == ',') continue; if(c == ']') break; if(c == -1) throw new DeserializationException("Unexpected end of stream", reader); throw new DeserializationException("Expected , or ], found "+(char)c, reader); } builder.EndArray(); }
private object ReadArray(System.IO.TextReader reader) { #pragma warning disable CS8604 // Possible null reference argument. IList?list = Activator.CreateInstance(DefaultArrayType) as IList; #pragma warning restore CS8604 // Possible null reference argument. reader.FastSeek('['); reader.Read(); // consume the '[' reader.EatWhiteSpace(); bool done = false; char ch = (char)reader.Peek(); if (ch == ']') { done = true; reader.Read(); // consume the ']' } else { if (ch != 't' && ch != 'f' && ch != 'n' && Char.IsLetter(ch)) { throw new InvalidDataException($"LoadArray char {ch} is not allowed after ["); } } while (!done) { reader.EatWhiteSpace(); list?.Add(Read(reader)); reader.EatWhiteSpace(); ch = (char)reader.Peek(); if (ch == ',') { reader.Read(); // consume ',' } reader.EatWhiteSpace(); ch = (char)reader.Peek(); if (ch == ']') { reader.Read(); // consume ']' done = true; } } #pragma warning disable CS8604 // Possible null reference argument. return(list.Simplify()); #pragma warning restore CS8604 // Possible null reference argument. }
public int Peek() { if (annotate) { linepos = oldlinepos; cpos = oldcpos; } return(rdr.Peek()); }
public void Parse(TextReader input) { while (input.Peek() != -1) { string current = input.ReadLine().Trim(); Result.Add(current); } }
public Lexer(TextReader reader) { this.reader = reader; if ((char)reader.Peek() == '#') { SkipToEndOfLine(); } }
private static void parseCommaSeparatedFields( TextReader tr, List<string> fields ) { parseCommaSeparatedField( tr, fields ); while( tr.Peek() == ',' ) { tr.Read(); parseCommaSeparatedFields( tr, fields ); } }
/// <summary> /// Read in the set of nodes and their connectivity /// </summary> /// <param name="reader"></param> private void readConnectivity(System.IO.TextReader reader) { _nodes = new Dictionary <string, GraphNode>(); while (reader.Peek() >= 0) { processLine(reader.ReadLine()); } }
/// <summary> /// Read in all the angles into the cache from the supplied open reader /// </summary> /// <param name="reader"></param> private void readAngles(System.IO.TextReader reader) { _dihedrals = new Dictionary <string, float>(); while (reader.Peek() >= 0) { processLine(reader.ReadLine()); } }
public static void ReadToCloseBracket(TextReader tr) { Char penultimateChar; while (Char.IsWhiteSpace((Char)tr.Peek())) { tr.Read(); } }
internal void Read(TextReader sr) { char c; Name = ""; sr.EatWS(); while (char.IsUpper((char)sr.Peek())) { c = (char)sr.Read(); Name += c; } sr.EatWS(); while (sr.Peek() == '[') { ReadValue(sr); sr.EatWS(); } }
/// <summary> /// Determines if the reader is at the end of a line. /// </summary> public bool IsEndOfLine() { int c; while (parenLevel > 0) { while ((c = text.Peek()) >= 0) { if (c == ' ' || c == '\t' || c == '\r' || c == '\n') { c = text.Read(); previousChar = c; continue; } if (c == ')') { --parenLevel; c = text.Read(); previousChar = c; break; } return(false); } } if (eolSeen) { return(true); } while ((c = text.Peek()) >= 0) { // Skip space or tab. if (c == ' ' || c == '\t') { c = text.Read(); previousChar = c; continue; } return(c == '\r' || c == '\n' || c == ';'); } // EOF is end of line return(true); }
private static bool CheckIfEscaped(TextReader reader, StringBuilder buffer) { bool escaped = false; if ((char)reader.Peek() == '-') { var first = reader.Read(); if ((char)reader.Peek() == '-') { reader.Read(); escaped = true; } else { buffer.Append(first); } } return escaped; }
private static object?ReadNull(System.IO.TextReader reader) { reader.EatWhiteSpace(); char ch = (char)reader.Peek(); if (ch == 'n') { reader.Read(); reader.Read(); reader.Read(); reader.Read(); // read chars n,u,l,l } return(null); }
/// <summary> /// /// </summary> /// <param name="context_name"></param> /// <param name="stringCodeReader"></param> /// <returns></returns> public override object Read(string context_name, System.IO.TextReader stringCodeReader, OutputDelegate WritResulteLine) { CmdResult res = null; int line = 0; while (stringCodeReader.Peek() != -1) { line++; res = BotClient.ExecuteCommand(stringCodeReader.ReadLine(), context_name, WriteLine, CMDFLAGS.ForceCompletion); } return(res); } // method: Read
/// <summary> /// /// </summary> /// <param name="context_name"></param> /// <param name="stringCodeReader"></param> /// <returns></returns> public virtual object Read(string context_name, System.IO.TextReader stringCodeReader, OutputDelegate WriteLine) { object res = null; int line = 0; while (stringCodeReader.Peek() != -1) { line++; res = Eval(stringCodeReader.ReadLine()); } return(res); } // method: Read
/// <summary> /// /// </summary> /// <param name="context_name"></param> /// <param name="stringCodeReader"></param> /// <returns></returns> public override object Read(string context_name, System.IO.TextReader stringCodeReader, OutputDelegate WriteLine) { object res = null; int line = 0; while (stringCodeReader.Peek() != -1) { line++; TextWriter tw = new OutputDelegateWriter(WriteLine); res = prologClient.Read(stringCodeReader.ReadLine(), tw); } return(res); } // method: Read
private static object ReadBool(System.IO.TextReader reader) { reader.EatWhiteSpace(); char ch = (char)reader.Peek(); if (ch == 't') { reader.Read(); reader.Read(); reader.Read(); reader.Read(); // read chars t,r,u,e return(true); } reader.Read(); reader.Read(); reader.Read(); reader.Read(); reader.Read(); // read char f,a,l,s,e return(false); }
private object?Read(System.IO.TextReader reader) { const char objectOpenCharacter = '{'; const char arrayOpenCharacter = '['; const char doubleQuote = '"'; const char singleQuote = '\''; reader.EatWhiteSpace(); int ichar = reader.Peek(); if (ichar < 0) { throw new InvalidDataException("end of stream reached"); } char c = (char)ichar; // char type // 'n' null // '\d' number // '"' or '\'' string // 'f' or 't' bool // '{' object (hash) // '[' array if (c == doubleQuote || c == singleQuote) { return(ReadString(reader)); } if (c == objectOpenCharacter) { return(ReadObject(reader)); } if (c == arrayOpenCharacter) { return(ReadArray(reader)); } if (c == 'f' || c == 't') { return(ReadBool(reader)); } if (c == 'n') { return(ReadNull(reader)); } return(ReadNumber(reader)); }
private void ReadContent(System.IO.TextReader textReader) { this.dict = new Dictionary <UInt64, string[]>(); string currentString = string.Empty; string[] splitted = null; string[] currentitem = null; string currentline; int linecount = 0; while (textReader.Peek() > -1) { currentline = textReader.ReadLine(); if (!string.IsNullOrWhiteSpace(currentline)) { if (currentline.StartsWith("id=", StringComparison.OrdinalIgnoreCase)) { splitted = currentline.Split('='); if (splitted.Length == 2) { currentitem = new string[this.Capacity]; linecount = 0; this.dict.Add(UInt64.Parse(splitted[1]), currentitem); } } else if (currentitem != null) { if (currentline == "0") { currentitem[linecount] = string.Empty; } else { currentitem[linecount] = currentline; } linecount++; } } } }
public static IEnumerable <string> ReadLines(this System.IO.TextReader reader, char[] delimiter) { List <char> chars = new List <char>(); int d = 0; /* Index of the current delimiter char to check against */ while (reader.Peek() >= 0) { char c = (char)reader.Read(); if (c == delimiter[d]) /* If the char matches the current delimiter char */ { d++; if (d == delimiter.Length) /* If all the delimiter char's were found, add the word and continue */ { d = 0; /* Reset the delimiter index */ yield return(new String(chars.ToArray())); chars.Clear(); continue; } } else if (d > 0) /* If the delimiter match failed, retroactively add those char's */ { for (int i = 0; i < d; i++) { chars.Add(delimiter[i]); } d = 0; chars.Add(c); } else { chars.Add(c); } } }
public override int Peek() { return(_in.Peek()); }
private object ReadObject(System.IO.TextReader reader) { const char objectOpenCharacter = '{'; const char objectCloseCharacter = '}'; const char comma = ','; #pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. IDictionary dictionary = null; #pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. if (ObjectCount == 0) { if (DefaultDocumentType == null) { throw new InvalidOperationException("DefaultDocumentType is null"); } #pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. dictionary = Activator.CreateInstance(DefaultDocumentType) as IDictionary; #pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. if (dictionary == null) { throw new InvalidOperationException($"Unable to create instance of {DefaultDocumentType.FullName}"); } } else { if (CreateDefaultObject != null) { dictionary = CreateDefaultObject(); if (dictionary == null) { throw new InvalidOperationException("CreateDefaultObject returned null"); } } else { if (DefaultObjectType == null) { throw new InvalidOperationException("DefaultObjectType is null"); } #pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type. dictionary = Activator.CreateInstance(DefaultObjectType) as IDictionary; #pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type. if (dictionary == null) { throw new InvalidOperationException($"Unable to create isntance of {DefaultObjectType.FullName}"); } } } ObjectCount++; reader.FastSeek(objectOpenCharacter); reader.Read(); // consume the '{' reader.EatWhiteSpace(); bool done = false; if ((char)(reader.Peek()) == objectCloseCharacter)// '}') { done = true; reader.Read(); // consume the '}' } while (!done) { reader.EatWhiteSpace(); string?key = ReadString(reader) as string; /* #if DEBUG * if (key == "string_symbol") * { * int x = 0; * } #endif*/ reader.EatWhiteSpace(); reader.Read(); //consume ':' #pragma warning disable CS8604 // Possible null reference argument. dictionary[key] = Read(reader); #pragma warning restore CS8604 // Possible null reference argument. reader.EatWhiteSpace(); char ch = (char)reader.Peek(); if (ch == comma) { reader.Read(); // consume ',' } reader.EatWhiteSpace(); ch = (char)reader.Peek(); if (ch == objectCloseCharacter)//'}') { reader.Read(); done = true; } } string?type = dictionary.Get <string>("Type", ""); if (type.Length > 0 && ConversionTypeNames.ContainsKey(type) && !ConversionTypeNames[type].IsInstanceOfType(dictionary)) { if (!(Activator.CreateInstance(ConversionTypeNames[type]) is IDictionary converted)) { throw new InvalidOperationException($"Unable to create instance of {ConversionTypeNames[type].FullName}"); } foreach (object?key in dictionary.Keys) { #pragma warning disable CS8604 // Possible null reference argument. if (!converted.Contains(key)) #pragma warning restore CS8604 // Possible null reference argument. { #pragma warning disable CS8604 // Possible null reference argument. #pragma warning disable CS8604 // Possible null reference argument. converted.Add(key, dictionary[key]); #pragma warning restore CS8604 // Possible null reference argument. #pragma warning restore CS8604 // Possible null reference argument. } } return(converted); } return(dictionary); }
void Scan(IO.TextReader input) { while (input.Peek() != -1) { char ch = (char)input.Peek(); if (ch == '%') { //eat '%' input.Read(); Text.StringBuilder accum = new Text.StringBuilder(); ch = (char)input.Peek(); while (ch != '%') { accum.Append((char)input.Read()); if (input.Peek() == -1) { break; } ch = (char)input.Peek(); } input.Read(); //eat '%' AppendToken(accum.ToString(), line, 2); } else if (ch == ',') { input.Read(); } else if (ch == '$') { //omg a function Text.StringBuilder accum = new Text.StringBuilder(); input.Read(); ch = (char)input.Peek(); while (char.IsLetterOrDigit(ch) || ch == '_') { accum.Append(ch); input.Read(); if (input.Peek() == -1) { break; } ch = (char)input.Peek(); } if (ch != '(') { throw new Exception("Invalid character in function name"); } AppendToken(accum.ToString(), line, 3); } else if (ch == '(') { input.Read(); AppendToken("", line, 4); } else if (ch == ')') { input.Read(); AppendToken("", line, 8); } else if (ch == '\r') { input.Read(); //eat CR char c = (char)input.Peek(); if (c == '\n') { input.Read(); //eat LF AppendToken("", line, 7); } else { line++; } } else if (ch == '#') { input.Read(); AppendToken("", line, 9); } else { Text.StringBuilder accum = new System.Text.StringBuilder(); while (ch != '$' & ch != '%' & ch != '\r' & ch != ')') { if (ch == '\\') { //skip escape char and insert next one immediately input.Read(); } accum.Append((char)input.Read()); if (input.Peek() == -1) { break; } else if (input.Peek() == ',') { input.Read(); break; } ch = (char)input.Peek(); } AppendToken(accum.ToString(), line, 1); } } }
private void Scan(IO.TextReader input) { while (input.Peek() != -1) { char caracter = (char)input.Peek(); // Scan individual tokens if (char.IsWhiteSpace(caracter)) { // eat the current char and skip ahead! input.Read(); } else if (char.IsLetter(caracter) || caracter == '_') { // keyword or identifier Text.StringBuilder accum = new Text.StringBuilder(); while (char.IsLetter(caracter) || caracter == '_') { accum.Append(caracter); input.Read(); if (input.Peek() == -1) { break; } else { caracter = (char)input.Peek(); } } this.resultado.Add(accum.ToString()); } else if (caracter == '"') { // string literal Text.StringBuilder accum = new Text.StringBuilder(); input.Read(); // skip the '"' if (input.Peek() == -1) { throw new System.Exception("Cadena sin terminar"); } while ((caracter = (char)input.Peek()) != '"') { accum.Append(caracter); input.Read(); if (input.Peek() == -1) { throw new System.Exception("Cadena sin terminar"); } } // skip the terminating " input.Read(); this.resultado.Add(accum); } else if (char.IsDigit(caracter)) { // numeric literal Text.StringBuilder accum = new Text.StringBuilder(); while (char.IsDigit(caracter)) { accum.Append(caracter); input.Read(); if (input.Peek() == -1) { break; } else { caracter = (char)input.Peek(); } } this.resultado.Add(int.Parse(accum.ToString())); } else { switch (caracter) { case '+': input.Read(); this.resultado.Add(Scanner.Sum); break; case '-': input.Read(); this.resultado.Add(Scanner.Res); break; case '*': input.Read(); this.resultado.Add(Scanner.Mul); break; case '/': input.Read(); this.resultado.Add(Scanner.Div); break; case '=': input.Read(); if (input.Peek() == '=') { input.Read(); this.resultado.Add(Scanner.Eq); } else { this.resultado.Add(Scanner.Igual); } break; case ';': input.Read(); this.resultado.Add(Scanner.PyC); break; case '>': input.Read(); if (input.Peek() == '=') { input.Read(); this.resultado.Add(Scanner.Gte); } else { this.resultado.Add(Scanner.Gt); } break; case '<': input.Read(); if (input.Peek() == '=') { input.Read(); this.resultado.Add(Scanner.Lte); } else { this.resultado.Add(Scanner.Lt); } break; case '!': input.Read(); if (input.Peek() == '=') { input.Read(); this.resultado.Add(Scanner.Neq); } else { throw new System.Exception("No se reconoce el siguiente caracter: '" + caracter + "'"); } break; default: throw new System.Exception("No se reconoce el siguiente caracter: '" + caracter + "'"); } } } }
public void GetObjectProperties() { // Путь к базовому файлу // Путь к файлу списка протофайлов // Пусть к файлам прототипа // Путь к файлу списка графики // Путь к файлам графики // Временная строка №1 string TempString = " "; // Временная строка №2 string TempString1 = " "; string baseFile = GamePath + @"\MASTER.DAT\text\english\game\pro_item.msg"; string listFile = GamePath + @"\MASTER.DAT\proto\items\items.lst"; string pathToProto = GamePath + @"\MASTER.DAT\proto\items\"; string pathToArt = string.Format(@"{0}\MASTER.DAT\art\items\", GamePath); string artListFile = GamePath + @"\MASTER.DAT\art\items\items.lst"; // Получение файла прототипа объекта System.IO.TextReader fListFile = System.IO.File.OpenText(listFile); for (int i = 1; i <= ObjectId; i++) { TempString = fListFile.ReadLine(); } fListFile.Close(); // Путь к файлу прототипа объекта ObjectProto = pathToProto + TempString; //Загоняем весь прото-файл в байтовый массив FileStream fProtoFile = new FileStream(ObjectProto, FileMode.Open); _buffer = new byte[Convert.ToInt32(fProtoFile.Length)]; fProtoFile.Read(_buffer, 0, Convert.ToInt16(fProtoFile.Length)); fProtoFile.Close(); System.IO.TextReader fArtListFile = System.IO.File.OpenText(artListFile); for (int i = 0; i <= (_buffer[10] * 256 + _buffer[11]); i++) { TempString = fArtListFile.ReadLine(); } fListFile.Close(); // Путь к файлу с графикой объекта ObjectFrame = TempString.Replace(".FRM", ""); // Открытие базового файла объектов System.IO.TextReader fBaseFile = System.IO.File.OpenText(baseFile); if (!(fBaseFile.Peek() == -1)) { do { TempString = fBaseFile.ReadLine(); }while (!(TempString.Substring(1, ObjectId.ToString().Length + 2) == (ObjectId * 100).ToString()) && !((fBaseFile.Peek() == -1))); if (!(TempString.Substring(1, ObjectId.ToString().Length) == ObjectId.ToString())) { TempString = " "; } } else { TempString = " "; } if ((TempString.Substring(1, ObjectId.ToString().Length) == ObjectId.ToString()) && !(TempString == " ")) { char[] aStrSplit = { '{', '}' }; // Получение наименования объекта ObjectName = TempString.Split(aStrSplit)[5]; if (!(fBaseFile.Peek() == -1)) { TempString1 = fBaseFile.ReadLine(); if (TempString1.Substring(1, TempString.Split(aStrSplit)[1].Length) == (ObjectId.ToString() + "01")) { // Получение описания объекта ObjectDesc = TempString1.Split(aStrSplit)[5]; } else { ObjectDesc = " "; } fBaseFile.Close(); } else { ObjectDesc = " "; } } else { ObjectDesc = " "; ObjectName = " "; } FrameIdType = _buffer[8]; FrameIdOffset = _buffer[9]; FrameId = _buffer[10] * 256 + _buffer[11]; LightDistance = (_buffer[12] << 24) + (_buffer[13] << 16) + (_buffer[14] << 8) + _buffer[15]; LightIntensity = (_buffer[16] << 24) + (_buffer[17] << 16) + (_buffer[18] << 8) + _buffer[19]; AttackMode1 = (_buffer[27] & 15); AttackMode2 = (_buffer[27] & 240) >> 4; int offset = 0x1C; ScriptId = (_buffer[offset] << 24) + (_buffer[offset + 1] << 16) + (_buffer[offset + 2] << 8) + _buffer[offset + 3]; offset = 0x20; ItemSubtype = (ItemSubtype)(_buffer[offset] << 24) + (_buffer[offset + 1] << 16) + (_buffer[offset + 2] << 8) + _buffer[offset + 3]; offset = 0x24; MaterialType = (_buffer[offset] << 24) + (_buffer[offset + 1] << 16) + (_buffer[offset + 2] << 8) + _buffer[offset + 3]; offset = 0x28; Volume = (_buffer[offset] << 24) + (_buffer[offset + 1] << 16) + (_buffer[offset + 2] << 8) + _buffer[offset + 3]; offset = 0x2C; Weight = (_buffer[offset] << 24) + (_buffer[offset + 1] << 16) + (_buffer[offset + 2] << 8) + _buffer[offset + 3]; offset = 0x30; BasePrice = (_buffer[offset] << 24) + (_buffer[offset + 1] << 16) + (_buffer[offset + 2] << 8) + _buffer[offset + 3]; offset = 0x34; InvenId = _buffer[offset]; offset = 0x36; InvenFrame = (_buffer[offset] << 8) + _buffer[offset + 1]; offset = 0x38; SoundId = (_buffer[offset] << 24) + (_buffer[offset + 1] << 16) + (_buffer[offset + 2] << 8) + _buffer[offset + 3]; }
private void Scan(IO.TextReader input) { while (input.Peek() != -1) { char ch = (char)input.Peek(); // Scan individual tokens if (ch != '\r' && char.IsWhiteSpace(ch) || ch == ',') { // eat the current char and skip ahead! input.Read(); } else if (char.IsLetter(ch) || ch == '_') { // keyword or identifier Text.StringBuilder accum = new Text.StringBuilder(); while (char.IsLetter(ch) || ch == '_') { accum.Append(ch); input.Read(); if (input.Peek() == -1) { break; } else { ch = (char)input.Peek(); } } this.result.Add(accum.ToString()); } else if (ch == '"') { // string literal Text.StringBuilder accum = new Text.StringBuilder(); input.Read(); // skip the '"' if (input.Peek() == -1) { throw new System.Exception("unterminated string literal"); } while ((ch = (char)input.Peek()) != '"') { byte[] unicode = Text.Encoding.Default.GetBytes(ch.ToString(CultureInfo.CurrentCulture)); byte[] ascii = Text.Encoding.Convert(Text.Encoding.Unicode, Text.Encoding.ASCII, unicode); char[] asciiChars = new char[Text.Encoding.ASCII.GetCharCount(ascii, 0, ascii.Length)]; Text.Encoding.ASCII.GetChars(ascii, 0, ascii.Length, asciiChars, 0); //accum.Append(asciiChars); accum.Append(ch); //accum.Append(ch.ToString(CultureInfo.CurrentCulture)); input.Read(); if (input.Peek() == -1) { throw new System.Exception("unterminated string literal"); } } // skip the terminating " input.Read(); this.result.Add(accum); } else if (char.IsDigit(ch)) { bool isDouble = false; // numeric literal Text.StringBuilder accum = new Text.StringBuilder(); while (char.IsDigit(ch)) { accum.Append(ch); input.Read(); if (input.Peek() == -1) { break; } else { ch = (char)input.Peek(); } } if (ch == '.') { accum.Append(ch); input.Read(); ch = (char)input.Peek(); while (char.IsDigit(ch)) { accum.Append(ch); input.Read(); if (input.Peek() == -1) { break; } else { ch = (char)input.Peek(); } } isDouble = true; } if (isDouble) { this.result.Add(double.Parse(accum.ToString().Replace(".", ","))); } else { this.result.Add(int.Parse(accum.ToString())); } } else { switch (ch) { case '+': input.Read(); this.result.Add(Scanner.Add); break; case '-': input.Read(); this.result.Add(Scanner.Sub); break; case '*': input.Read(); this.result.Add(Scanner.Mul); break; case '/': input.Read(); this.result.Add(Scanner.Div); break; case '=': input.Read(); this.result.Add(Scanner.Equal); break; case '>': // > | >= input.Read(); ch = (char)input.Peek(); if (ch == '=') { this.result.Add(Scanner.MoreEqual); input.Read(); } else { this.result.Add(Scanner.More); } break; case '<': // < | <= input.Read(); ch = (char)input.Peek(); if (ch == '=') { this.result.Add(Scanner.LessEqual); input.Read(); } else { this.result.Add(Scanner.Less); } break; case '\r': input.Read(); if (!this.result[this.result.Count - 1].ToString().Equals("then") && !this.result[this.result.Count - 1].ToString().Equals("else") && !this.result[this.result.Count - 1].ToString().Equals("to") && !this.result[this.result.Count - 1].ToString().Equals("do") && this.result[this.result.Count - 1] != Scanner.Semi) { this.result.Add(Scanner.Semi); } break; default: throw new System.Exception("Scanner encountered unrecognized character '" + ch + "'"); } } } }
private void ReadProgramFile(System.IO.TextReader programFile) { while (programFile.Peek() != -1) { char symbol = (char)programFile.Peek(); if (char.IsWhiteSpace(symbol)) { // if the symbol is whitespace then move to next symbol programFile.Read(); } else if (char.IsLetter(symbol) || symbol == '_') { //identify the tokens StringBuilder token = new StringBuilder(); while (char.IsLetter(symbol) || symbol == '_') { token.Append(symbol); programFile.Read(); if (programFile.Peek() == -1) { break; } else { symbol = (char)programFile.Peek(); } } listLexemes.Add(token.ToString()); } else if (symbol == '"') { // string literal StringBuilder stringLiteral = new StringBuilder(); programFile.Read(); // skip the '"' if (programFile.Peek() == -1) { throw new Exception("String literal is not terminated"); } while ((symbol = (char)programFile.Peek()) != '"') { stringLiteral.Append(symbol); programFile.Read(); if (programFile.Peek() == -1) { throw new Exception("String literal is not terminated"); } } // skip the terminating " programFile.Read(); listLexemes.Add(stringLiteral); } else if (char.IsDigit(symbol)) { // numeric literal StringBuilder numericLiteral = new StringBuilder(); while (char.IsDigit(symbol)) { numericLiteral.Append(symbol); programFile.Read(); if (programFile.Peek() == -1) { break; } else { symbol = (char)programFile.Peek(); } } listLexemes.Add(int.Parse(numericLiteral.ToString())); } else { switch (symbol) { case '(': programFile.Read(); listLexemes.Add(Tokens.OpenParen); break; case ')': programFile.Read(); listLexemes.Add(Tokens.CloseParen); break; case '=': programFile.Read(); listLexemes.Add(Tokens.EqualTo); break; case ';': programFile.Read(); listLexemes.Add(Tokens.Terminator); break; case '<': programFile.Read(); listLexemes.Add(Tokens.LessThan); break; case '>': programFile.Read(); listLexemes.Add(Tokens.GreaterThan); break; case ',': programFile.Read(); listLexemes.Add(Tokens.Comma); break; case '/': programFile.Read(); listLexemes.Add(Tokens.Divide); break; case '*': programFile.Read(); listLexemes.Add(Tokens.Multiply); break; case '-': programFile.Read(); listLexemes.Add(Tokens.Subtract); break; case '+': programFile.Read(); listLexemes.Add(Tokens.Add); break; case '{': programFile.Read(); listLexemes.Add(Tokens.OpenBrac); break; case '}': programFile.Read(); listLexemes.Add(Tokens.CloseBrac); break; default: ExceptionHandler("unidentified symbol '" + symbol + "'"); break; } } } }
public override int Peek() => _in.Peek();
//--------------------------------------------------------------------- public TokenList Tokenize(System.IO.TextReader Text) { TokenList tokens = new TokenList(); Token token = new Token(); int nChar = 0; while (true) { int CharCode = Text.Peek(); if (CharCode == -1) { break; } if (this.WhitespaceChars.Contains("" + (char)CharCode)) { // Accumulate a Whitespace character. if (token.Type != TokenType.Whitespace) { this.CollectToken_(tokens, token); token = this.NewToken_(TokenType.Whitespace, "", nChar); } token.Text += (char)Text.Read(); nChar++; } else if (this.SymbolChars.Contains("" + (char)CharCode)) { // Accumulate a single Symbol character. this.CollectToken_(tokens, token); token = this.NewToken_(TokenType.Symbol, ("" + (char)Text.Read()), nChar); this.CollectToken_(tokens, token); nChar++; token = this.NewToken_(TokenType.Unknown, "", nChar); } else if (this.LiteralDelimiters.Contains("" + (char)CharCode)) { // Accumulate a Literal character. this.CollectToken_(tokens, token); token = this.NewToken_(TokenType.Literal, ("" + (char)Text.Read()), nChar); nChar++; // Read until the closing delimiter. while (true) { int NextCharCode = Text.Peek(); if (NextCharCode == -1) { this.CollectToken_(tokens, token); token = this.NewToken_(TokenType.Unknown, "", nChar); break; } else if (NextCharCode == CharCode) { token.Text += (char)Text.Read(); nChar++; if (!token.Text.EndsWith(this.LiteralEscapeChar + (char)CharCode)) { this.CollectToken_(tokens, token); token = this.NewToken_(TokenType.Unknown, "", nChar); break; } } else { token.Text += (char)Text.Read(); nChar++; } } } else { // Accumulate an identifier. if (token.Type != TokenType.Identifier) { this.CollectToken_(tokens, token); token = this.NewToken_(TokenType.Identifier, "", nChar); } token.Text += (char)Text.Read(); nChar++; } } this.CollectToken_(tokens, token); // Return the tokens. return(tokens); }
public override int yylex() { char ch; char peek; int ord = reader.Read(); //this.text.Clear(); this.text.Length = 0; // // Must check for EOF // if (ord == -1) { return((int)Tokens.EOF); } else { ch = (char)ord; } if (ch == '\n') { linenum++; return(yylex()); } else if (char.IsWhiteSpace(ch)) { // Skip white space while (char.IsWhiteSpace(peek = (char)reader.Peek())) { ord = reader.Read(); if (ord == (int)'\n') { linenum++; continue; } } return(yylex()); } else if (char.IsDigit(ch)) { text.Append(ch); while (char.IsDigit(peek = (char)reader.Peek())) { text.Append((char)reader.Read()); } if ((peek = (char)reader.Peek()) == '.') { text.Append((char)reader.Read()); } while (char.IsDigit(peek = (char)reader.Peek())) { text.Append((char)reader.Read()); } try { yylval = Parser.MakeNumLeaf(double.Parse(text.ToString())); return((int)Tokens.NUMBER); } catch (FormatException) { this.yyerror("Illegal number \"{0}\"", text); return((int)Tokens.error); } } else if (char.IsLetter(ch)) { text.Append(char.ToLower(ch)); while (char.IsLetter(peek = (char)reader.Peek())) { text.Append(char.ToLower((char)reader.Read())); } switch (text.ToString()) { case "if": return((int)Tokens.IF); case "fi": return((int)Tokens.END_IF); case "do": return((int)Tokens.DO); case "od": return((int)Tokens.END_DO); case "print": return((int)Tokens.PRINT); default: if (text.Length >= 1) { yylval = Parser.MakeIdLeaf(text.ToString()); return((int)Tokens.ID); } else { this.yyerror("Illegal name \"{0}\"", text); return((int)Tokens.error); } } } else { switch (ch) { case '.': case '+': case '-': case '*': case '/': case '(': case ')': case '%': case '=': case ':': case '>': case '<': case '!': case ',': case ';': case '|': return(ch); default: yyerror("Illegal character '{0}' on line '{1}'", ch, linenum); return(yylex()); } } }
// Процедура получения свойств объекта public void GetObjectProperties() { // Путь к базовому файлу string baseFile; // Путь к файлу списка протофайлов string listFile; // Пусть к файлам прототипа string pathToProto; // Путь к файлу списка графики string artListFile; // Путь к файлам графики string pathToArt; // Временная строка №1 string tempString = " "; // Временная строка №2 string tempString1 = " "; // Определение путей для объекта baseFile = GamePath + @"\MASTER.DAT\text\english\game\pro_crit.msg"; listFile = GamePath + @"\MASTER.DAT\proto\critters\critters.lst"; pathToProto = GamePath + @"\MASTER.DAT\proto\critters\"; pathToArt = @".\CRITTER.DAT\art\critters\"; artListFile = GamePath + @"\CRITTER.DAT\art\critters\critters.lst"; // Получение файла прототипа объекта System.IO.TextReader fListFile = System.IO.File.OpenText(listFile); for (int i = 1; i <= ObjectId; i++) { tempString = fListFile.ReadLine(); } fListFile.Close(); // Путь к файлу прототипа объекта ObjectProto = pathToProto + tempString; //Загоняем весь прото-файл в байтовый массив FileStream fProtoFile = new FileStream(ObjectProto, FileMode.Open); byte[] buffer = new byte[Convert.ToInt32(fProtoFile.Length)]; fProtoFile.Read(buffer, 0, Convert.ToInt16(fProtoFile.Length)); fProtoFile.Close(); System.IO.TextReader fArtListFile = System.IO.File.OpenText(artListFile); for (int i = 0; i <= (buffer[10] * 256 + buffer[11]); i++) { tempString = fArtListFile.ReadLine(); } fListFile.Close(); // Путь к файлу с графикой объекта ObjectFrame = tempString.Replace(".FRM", ""); // Открытие базового файла объектов System.IO.TextReader fBaseFile = System.IO.File.OpenText(baseFile); if (!(fBaseFile.Peek() == -1)) { do { tempString = fBaseFile.ReadLine(); }while (!(tempString.Substring(1, ObjectId.ToString().Length + 2) == (ObjectId * 100).ToString()) && !((fBaseFile.Peek() == -1))); if (!(tempString.Substring(1, ObjectId.ToString().Length) == ObjectId.ToString())) { tempString = " "; } } else { tempString = " "; } if ((tempString.Substring(1, ObjectId.ToString().Length) == ObjectId.ToString()) && !(tempString == " ")) { char[] aStrSplit = { '{', '}' }; // Получение наименования объекта ObjectName = tempString.Split(aStrSplit)[5]; if (!(fBaseFile.Peek() == -1)) { tempString1 = fBaseFile.ReadLine(); if (tempString1.Substring(1, tempString.Split(aStrSplit)[1].Length) == (ObjectId.ToString() + "01")) { // Получение описания объекта ObjectDesc = tempString1.Split(aStrSplit)[5]; } else { ObjectDesc = " "; } fBaseFile.Close(); } else { ObjectDesc = " "; } } else { ObjectDesc = " "; ObjectName = " "; } FrameIdType = buffer[8]; FrameIdOffset = buffer[9]; FrameId = buffer[10] * 256 + buffer[11]; int offset = 0xc; LightDistance = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x10; LightIntensity = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x1C; ScriptId = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x20; TalkingHeadFrame = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x24; AIPaket_num = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x28; TeamNumber = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; // Базовые основные параметры offset = 0x30; Strength = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x34; Perception = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x38; Endurance = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x3C; Charisma = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x40; Intelligence = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x44; Agility = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x48; Luck = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x4C; HP = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x50; AP = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x54; AC = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x58; UnarmedDamage = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x5C; MeleeDamage = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x60; CarryWeight = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x64; Sequence = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x68; HealingRate = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x6C; CriticalChance = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x70; BetterCriticals = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; // Базовые сопротивления и трешхолды(Tresholds) offset = 0x74; DT_Normal = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x78; DT_Laser = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x7C; DT_Fire = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x80; DT_Plasma = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x84; DT_Electrical = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x88; DT_EMP = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x8C; DT_Explode = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x90; DR_Normal = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x94; DR_Laser = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x98; DR_Fire = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x9C; DR_Plasma = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xA0; DR_Electrical = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xA4; DR_EMP = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xA8; DR_Explode = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xAC; DR_Radiation = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xB0; DR_Poison = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; //Базовое разное offset = 0xB4; BaseAge = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xB8; BaseSex = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; //Дополнительные основные параметры offset = 0xBC; ExtraStrenght = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xC0; ExtraPerception = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xC4; ExtraEndurance = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xC8; ExtraCharisma = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xCC; ExtraIntelligence = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xD0; ExtraAgility = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xD4; ExtraLuck = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xD8; ExtraHP = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xDC; ExtraAP = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xE0; ExtraAC = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xE4; ExtraUnarmedDamage = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xE8; ExtraMeleeDamage = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xEC; ExtraCarryWeight = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xF0; ExtraSequence = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xF4; ExtraHealingRate = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xF8; ExtraCriticalChance = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0xFC; ExtraBetterCriticals = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; //Дополнительные сопротивления и трешхолды(Tresholds) offset = 0x100; ExtraDT_Normal = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x104; ExtraDT_Laser = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x108; ExtraDT_Fire = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x10C; ExtraDT_Plasma = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x110; ExtraDT_Electrical = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x114; ExtraDT_EMP = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x118; ExtraDT_Explode = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x11C; ExtraDR_Normal = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x120; ExtraDR_Laser = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x124; ExtraDR_Fire = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x128; ExtraDR_Plasma = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x12C; ExtraDR_Electrical = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x130; ExtraDR_EMP = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x134; ExtraDR_Explode = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x138; ExtraDR_Radiation = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x13C; ExtraDR_Poison = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; // Дополнительное разное offset = 0x140; ExtraAge = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x144; ExtraSex = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; // Навыки offset = 0x148; Skill_SmallGuns = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x14C; Skill_BigGuns = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x150; Skill_EnergyWeapons = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x154; Skill_Unarmed = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x158; Skill_Melee = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x15C; Skill_Throwing = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x160; Skill_FirstAid = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x164; Skill_Doctor = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x168; Skill_Sneak = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x16C; Skill_Lockpick = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x170; Skill_Steal = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x174; Skill_Traps = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x178; Skill_Science = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x17C; Skill_Repair = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x180; Skill_Speech = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x184; Skill_Barter = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x188; Skill_Gambling = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x18C; Skill_Outdoorsmanship = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; // Остальное offset = 0x190; BodyType = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x194; XPForKill = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x198; KillType = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; offset = 0x19C; DamageType = (buffer[offset] << 24) + (buffer[offset + 1] << 16) + (buffer[offset + 2] << 8) + buffer[offset + 3]; }
private void Scan(IO.TextReader input) { while (input.Peek() != -1) { char ch = (char)input.Peek(); // Scan individual tokens if (char.IsWhiteSpace(ch)) { // eat the current char and skip ahead! input.Read(); } else if (char.IsLetter(ch) || ch == '_') { // keyword or identifier Text.StringBuilder accum = new Text.StringBuilder(); while (char.IsLetter(ch) || ch == '_') { accum.Append(ch); input.Read(); if (input.Peek() == -1) { break; } else { ch = (char)input.Peek(); } } this.result.Add(accum.ToString()); } else if (ch == '"') { // string literal Text.StringBuilder accum = new Text.StringBuilder(); input.Read(); // skip the '"' if (input.Peek() == -1) { throw new System.Exception("unterminated string literal"); } while ((ch = (char)input.Peek()) != '"')// " { accum.Append(ch); input.Read(); if (input.Peek() == -1) { throw new System.Exception("unterminated string literal"); } } // skip the terminating " input.Read(); this.result.Add(accum); } else if (char.IsDigit(ch)) { // numeric literal Text.StringBuilder accum = new Text.StringBuilder(); while (char.IsDigit(ch)) { accum.Append(ch); input.Read(); if (input.Peek() == -1) { break; } else { ch = (char)input.Peek(); } } this.result.Add(int.Parse(accum.ToString())); } else { switch (ch) { case '+': input.Read(); this.result.Add(Scanner.Add); break; case '-': input.Read(); this.result.Add(Scanner.Sub); break; case '*': input.Read(); this.result.Add(Scanner.Mul); break; case '/': input.Read(); this.result.Add(Scanner.Div); break; case '=': input.Read(); this.result.Add(Scanner.Equal); break; case ';': input.Read(); this.result.Add(Scanner.Semi); break; default: throw new System.Exception("Scanner encountered unrecognized character '" + ch + "'"); } } } }
private void Scan(IO.TextReader input) { while (input.Peek() != -1) { char ch = (char)input.Peek(); // Scan individual tokens if (char.IsWhiteSpace(ch)) { // eat the current char and skip ahead! input.Read(); } else if (char.IsLetter(ch) || ch == '_') { // keyword or identifier Text.StringBuilder accum = new Text.StringBuilder(); while (char.IsLetter(ch) || ch == '_' || ch == '.') { accum.Append(ch); input.Read(); if (input.Peek() == -1) { break; } else { ch = (char)input.Peek(); } } if (IsAmExpression(accum) || IsFunctionCall(accum) || IsNewObjCall(accum) || IsLogicalExpression(accum)) { ; } else { if (result.Count > 0 && this.result[result.Count - 1] == Scanner.Call) { this.result.Add(languageSetting[accum.ToString()] ?? accum.ToString()); } else { this.result.Add(accum.ToString()); } } } else if (ch == '"') { // string literal Text.StringBuilder accum = new Text.StringBuilder(); input.Read(); // skip the '"' if (input.Peek() == -1) { throw new System.Exception("unterminated string literal"); } while ((ch = (char)input.Peek()) != '"') { accum.Append(ch); input.Read(); if (input.Peek() == -1) { throw new System.Exception("unterminated string literal"); } } // skip the terminating" input.Read(); this.result.Add(accum); } else if (char.IsDigit(ch)) { // numeric literal Text.StringBuilder accum = new Text.StringBuilder(); while (char.IsDigit(ch)) { accum.Append(ch); input.Read(); if (input.Peek() == -1) { break; } else { ch = (char)input.Peek(); } } this.result.Add(int.Parse(accum.ToString())); } //Obselete Code else { switch (ch) { case '+': input.Read(); this.result.Add(Scanner.Add); break; case '-': input.Read(); this.result.Add(Scanner.Sub); break; case '*': input.Read(); this.result.Add(Scanner.Mul); break; case '/': input.Read(); this.result.Add(Scanner.Div); break; case '=': input.Read(); this.result.Add(Scanner.Equal); break; case ';': input.Read(); this.result.Add(Scanner.Semi); break; case '(': input.Read(); this.result.Add(Scanner.OpeningParentheses); break; case ')': input.Read(); this.result.Add(Scanner.ClosingParentheses); break; case ',': input.Read(); this.result.Add(Scanner.Comma); break; default: throw new System.Exception("Scanner encountered unrecognized character '" + ch + "'"); } } } }
// Процедура получения свойств объекта public void GetObjectProperties() { // Путь к базовому файлу string baseFile; // Путь к файлу списка протофайлов string listFile; // Пусть к файлам прототипа string pathToProto; // Путь к файлу списка графики string artListFile; // Путь к файлам графики string pathToArt; // Временная строка №1 string tempString = " "; // Временная строка №2 string tempString1 = " "; // Определение путей для объекта baseFile = GamePath + @"\MASTER.DAT\text\english\game\pro_tile.msg"; listFile = GamePath + @"\MASTER.DAT\proto\tiles\tiles.lst"; pathToProto = GamePath + @"\MASTER.DAT\proto\tiles\"; pathToArt = @".\MASTER.DAT\art\tiles\"; artListFile = GamePath + @"\MASTER.DAT\art\tiles\tiles.lst"; // Получение файла прототипа объекта System.IO.TextReader fListFile = System.IO.File.OpenText(listFile); for (int i = 1; i <= ObjectId; i++) { tempString = fListFile.ReadLine(); } fListFile.Close(); // Путь к файлу прототипа объекта ObjectProto = pathToProto + tempString; //Загоняем весь прото-файл в байтовый массив FileStream fProtoFile = new FileStream(ObjectProto, FileMode.Open); byte[] buffer = new byte[Convert.ToInt32(fProtoFile.Length)]; fProtoFile.Read(buffer, 0, Convert.ToInt16(fProtoFile.Length)); fProtoFile.Close(); System.IO.TextReader fArtListFile = System.IO.File.OpenText(artListFile); for (int i = 0; i <= (buffer[10] * 256 + buffer[11]); i++) { tempString = fArtListFile.ReadLine(); } fListFile.Close(); // Путь к файлу с графикой объекта ObjectFrame = tempString.Replace(".FRM", ""); // Открытие базового файла объектов System.IO.TextReader fBaseFile = System.IO.File.OpenText(baseFile); if (!(fBaseFile.Peek() == -1)) { do { tempString = fBaseFile.ReadLine(); }while (!(tempString.Substring(1, ObjectId.ToString().Length + 2) == (ObjectId * 100).ToString()) && !((fBaseFile.Peek() == -1))); if (!(tempString.Substring(1, ObjectId.ToString().Length) == ObjectId.ToString())) { tempString = " "; } } else { tempString = " "; } if ((tempString.Substring(1, ObjectId.ToString().Length) == ObjectId.ToString()) && !(tempString == " ")) { char[] aStrSplit = { '{', '}' }; // Получение наименования объекта ObjectName = tempString.Split(aStrSplit)[5]; if (!(fBaseFile.Peek() == -1)) { tempString1 = fBaseFile.ReadLine(); if (tempString1.Substring(1, tempString.Split(aStrSplit)[1].Length) == (ObjectId.ToString() + "01")) { // Получение описания объекта ObjectDesc = tempString1.Split(aStrSplit)[5]; } else { ObjectDesc = " "; } fBaseFile.Close(); } else { ObjectDesc = " "; } } else { ObjectDesc = " "; ObjectName = " "; } FrameIdType = buffer[8]; FrameIdOffset = buffer[9]; FrameId = buffer[10] * 256 + buffer[11]; LightDistance = (buffer[12] << 24) + (buffer[13] << 16) + (buffer[14] << 8) + buffer[15]; LightIntensity = (buffer[16] << 24) + (buffer[17] << 16) + (buffer[18] << 8) + buffer[19]; }
public override int Peek() { lock (this){ return(reader.Peek()); } }