private MsgProperties ReadProperties(ExtendedBinaryReader input, int offset, int count) { var pos = input.Position; input.Seek(offset, SeekOrigin.Begin); var data = input.ReadBytes(16 * count); input.Seek(pos, SeekOrigin.Begin); var result = new MsgProperties(data); return(result); }
private static MsgProperties ExtractProperties(string text) { var result = new MsgProperties(); var cleanText = Clean(text, true, true); var textWithTags = Clean(text, true, false); var shortPauses = Regex.Matches(cleanText, @"(,\s)|(、)"); foreach (Match pause in shortPauses) { var property = new PauseMsgProperty { Duration = 10, Position = (short)(pause.Index + 1), Order = -1 }; result.Add(property); } var longPauses = Regex.Matches(cleanText, @"([\?|?][\s|#])|([\!|!][\s|#])|(\.\s)|(。[\s]*)|(…[^…)?!])"); foreach (Match pause in longPauses) { var property = new PauseMsgProperty { Duration = 20, Position = (short)(pause.Index + 1), Order = -1 }; result.Add(property); } var openParenthesis = Regex.Matches(cleanText, @"([\(|(])"); foreach (Match parenthesis in openParenthesis) { var property = new ParenthesisStartMsgProperty { Position = (short)(parenthesis.Index), Order = -1 }; result.Add(property); } var closeParenthesis = Regex.Matches(cleanText, @"([\)|)])"); foreach (Match parenthesis in closeParenthesis) { var property = new ParenthesisEndMsgProperty { Position = (short)(parenthesis.Index + 1), Order = -1 }; result.Add(property); } var tagMatch = Regex.Match(textWithTags, @"(<Sign:(?<Code>\d+)>)|(<Color:(?<Code>(Default|\d+|\d+,\d+,\d+,\d+))>)"); while (tagMatch.Success) { if (tagMatch.Value.Contains("Sign")) { var property = new SignMsgProperty() { Position = (short)tagMatch.Index, Code = Convert.ToInt16(tagMatch.Groups["Code"].Value), TagLength = (short)tagMatch.Length, Order = -1 }; result.Add(property); textWithTags = string.Concat(textWithTags.Substring(0, tagMatch.Index), "#", textWithTags.Substring(tagMatch.Index + tagMatch.Length)); } if (tagMatch.Value.Contains("Color")) { var color = tagMatch.Groups["Code"].Value; if (color == "Default") { var property = new ColorEndMsgProperty() { Position = (short)(tagMatch.Index), Order = -1 }; result.Add(property); } else { if (color.Contains(",")) { var values = color.Split(','); var property = new ColorStartMsgProperty { Position = (short)(tagMatch.Index), Color = Convert.ToInt16(values[3]), Alpha = Convert.ToByte(values[3]), R = Convert.ToByte(values[0]), G = Convert.ToByte(values[1]), B = Convert.ToByte(values[2]), TagLength = (short)tagMatch.Length, Order = -1 }; result.Add(property); } else { var property = new ColorStartMsgProperty { Position = (short)(tagMatch.Index), Color = Convert.ToInt16(color), Alpha = 0, R = 0, G = 0, B = 0, TagLength = (short)tagMatch.Length, Order = -1 }; result.Add(property); } } textWithTags = string.Concat(textWithTags.Substring(0, tagMatch.Index), textWithTags.Substring(tagMatch.Index + tagMatch.Length)); } tagMatch = Regex.Match(textWithTags, @"(<Sign:(?<Code>\d+)>)|(<Color:(?<Code>(Default|\d+|\d+,\d+,\d+,\d+))>)"); } return(result); }