Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Date: 27.7.2015, Time: 19:54 */
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- namespace walotcsres
- {
- class Program
- {
- public static void Main(string[] args)
- {
- string file = "warcr100.rsc";
- var stream = File.Open(file, FileMode.Open);
- using(BinaryReader reader = new BinaryReader(stream, Encoding.ASCII))
- {
- string sig = new string(reader.ReadChars(4));
- stream.Position = 0x10; //Start of the main "subfile"
- var first = new Subfile(reader, true); //Covers the whole file
- for(int i = 0; i < first.RecordData.Length; i++)
- {
- var data = first.RecordData[i];
- File.WriteAllBytes("out2/"+i, data);
- }
- }
- Console.ReadKey(true);
- }
- }
- class Subfile
- {
- public long SubfileStart{get; private set;} //Absolute starting offset
- public int Tags{get; private set;} //Number of "tags"
- public int Start{get; private set;} //Relative data offset (to SubfileStart)
- public int Records{get; private set;} //Number of records
- public byte[][] RecordData{get; private set;} //Record data
- public Dictionary<string, int> TagData{get; private set;} //Tags
- public long SubfileEnd{get; private set;} //Absolute end offset (computed as maximum record end offset)
- public Subfile(BinaryReader reader, bool first)
- {
- var stream = reader.BaseStream;
- SubfileStart = stream.Position;
- Tags = reader.ReadInt32();
- Start = reader.ReadInt32();
- if(first)
- {
- Start -= 0x10;
- }
- stream.Position += 0x08;
- TagData = new Dictionary<string, int>();
- for(int i = 0; i < Tags; i++)
- {
- TagData[new string(reader.ReadChars(4))] = reader.ReadInt32();
- }
- Records = (Start - 0x10 - Tags * 8)/20;
- RecordInfo[] infos = new RecordInfo[Records];
- for(int i = 0; i < Records; i++)
- {
- infos[i] = new RecordInfo(reader);
- }
- RecordData = new byte[Records][];
- for(int i = 0; i < Records; i++)
- {
- int start = infos[i].Start;
- int length = infos[i].Length;
- byte[] data = new byte[length];
- if(length > 0)
- {
- //stream.Position = SubfileStart+start;
- stream.Position = SubfileStart-0x10+start;
- stream.Read(data, 0, length);
- }
- RecordData[i] = data;
- }
- SubfileEnd = SubfileStart+infos.Max(i => i.Start+i.Length);
- }
- public struct RecordInfo
- {
- public int Start{get; private set;}
- public int Length{get; private set;}
- public RecordInfo(BinaryReader reader) : this()
- {
- Start = reader.ReadInt32();
- Length = reader.ReadInt32();
- reader.ReadBytes(20-8);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement