Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using System.Windows.Forms;
- namespace Redscript
- {
- class Program
- {
- [STAThread]
- static void Main(string[] args)
- {
- Console.Title = "Redscript reader by Traderain";
- using (var of = new OpenFileDialog())
- {
- of.Title = "Select a redscript file!";
- of.Filter = "Redscript files | *.redscripts";
- if (of.ShowDialog() == DialogResult.OK)
- {
- var strings = ParseRedscript(of.FileName);
- for (var index = 0; index < strings.Length; index++)
- {
- Console.WriteLine("[" + index + "]: " + strings[index]);
- }
- }
- }
- }
- public static string[] ParseRedscript(string filename)
- {
- var strings = new List<string>();
- using (var br = new BinaryReader(new FileStream(filename, FileMode.Open)))
- {
- br.BaseStream.Seek(-4, SeekOrigin.End);
- var offset = br.ReadUInt32();
- Console.WriteLine("Offset: " + offset);
- br.BaseStream.Seek(offset, SeekOrigin.Begin);
- var count = br.ReadUInt32();
- for (var i = 0; i < count; i++)
- {
- strings.Add(ReadString(br));
- }
- }
- return strings.ToArray();
- }
- public static string ReadString(BinaryReader br)
- {
- int len = br.ReadByte();
- if (len > 191)
- len = br.ReadByte()*64 + len - 192;
- else if (len > 127)
- len = len - 128;
- else
- {
- throw new Exception("Error can't read length of string at " + br.BaseStream.Position);
- }
- return br.ReadCr2WString(len);
- }
- }
- public static class RedscriptBinaryreaderExtensions
- {
- public static string ReadCr2WString(this BinaryReader file, int len = 0)
- {
- string str = null;
- if (len > 0)
- {
- str = Encoding.Default.GetString(file.ReadBytes(len));
- }
- else
- {
- var sb = new StringBuilder();
- while (true)
- {
- var c = (char)file.ReadByte();
- if (c == 0)
- break;
- sb.Append(c);
- }
- str = sb.ToString();
- }
- return str;
- }
- }
- }
Add Comment
Please, Sign In to add comment