public static void ReadScenario(PrimitiveReader reader) { string version = reader.ReadASCIIString(4); version1 = version; majorVersion = GetDecimalValue(version[0]); minorVersion = GetDecimalValue(version[2]) * 10 + GetDecimalValue(version[3]); vv1 = Version.Parse(version); uint dataOffset = reader.ReadUInt32(); uint headerVersion = reader.ReadUInt32(); if (headerVersion >= 2) { uint timeStamp = reader.ReadUInt32(); DateTime utcTime = epoch.AddSeconds(timeStamp); DateTime localTime = utcTime.ToLocalTime(); } uint scenarioIntroductionLength = reader.ReadUInt32(); string scenarioIntroduction = ""; if (scenarioIntroductionLength > 0) { int length = (int)scenarioIntroductionLength; scenarioIntroduction = reader.ReadASCIIString(length); } uint unknown = reader.ReadUInt32(); uint playersCount = reader.ReadUInt32(); // Now read the compressed data. //reader.Stream.Seek( dataOffset, SeekOrigin.Begin ); ReadCompressedData(reader); throw new Exception(); }
public void ReadAiTextData(PrimitiveReader reader) { uint strategyLength = reader.ReadUInt32(); uint cityLength = reader.ReadUInt32(); uint personalityLength = reader.ReadUInt32(); AiStrategyText = reader.ReadASCIIString((int)strategyLength); AiCityPlanText = reader.ReadASCIIString((int)cityLength); AiPersonalityText = reader.ReadASCIIString((int)personalityLength); }
public void ReadData(PrimitiveReader reader, Version version1, Version version2) { uint strategyLength = version1.Minor >= 9 ? reader.ReadUInt32() : reader.ReadUInt16(); uint cityLength = version1.Minor >= 9 ? reader.ReadUInt32() : reader.ReadUInt16(); uint personalityLength = version1.Minor >= 9 ? reader.ReadUInt32() : reader.ReadUInt16(); StrategyFile = reader.ReadASCIIString((int)strategyLength); CityPlanFile = reader.ReadASCIIString((int)cityLength); PersonalityFile = reader.ReadASCIIString((int)personalityLength); }
static void ReadCompressedHeader(PrimitiveReader reader) { uint nextUnitId = reader.ReadUInt32(); float version2 = reader.ReadFloat32(); majorVersion2 = (int)version2; // Get rid of decimal portion. minorVersion2 = (int)((decimal)version2 * 100) % 100; // Otherwise some rounding errors are observable. // Good example on my machine: 1.3X -> 3X - 1, so 1.30 -> 29 Console.WriteLine(version1 + "," + version2); vv2 = Version.Parse(version2.ToString("0.00")); Console.WriteLine(vv1 + "," + vv2); if (minorVersion >= 9) { string[] playernames = new string[playersCount]; for (int i = 0; i < playernames.Length; i++) { playernames[i] = reader.ReadASCIIString(playerNameLength); } } if (minorVersion2 >= 17) { uint[] playernameIndices = new uint[playersCount]; for (int i = 0; i < playernameIndices.Length; i++) { playernameIndices[i] = reader.ReadUInt32(); } } if (minorVersion >= 9) { PlayerData1[] playersData = new PlayerData1[playersCount]; for (int i = 0; i < playersData.Length; i++) { PlayerData1 playerData; playerData.Active = reader.ReadUInt32() != 0; playerData.Human = reader.ReadUInt32() != 0; playerData.Civilization = reader.ReadUInt32(); playerData.Unknown = reader.ReadUInt32(); playersData[i] = playerData; } } uint unknown1 = reader.ReadUInt32(); if (minorVersion >= 9) { byte unknown2 = reader.ReadUInt8(); } float unknown3 = reader.ReadFloat32(); string originalFilename = ReadUInt16LengthPrefixedString(reader); //System.Diagnostics.Debugger.Break(); }
public static SlpFile FromStream(Stream stream) { PrimitiveReader reader = new PrimitiveReader(stream); string version = reader.ReadASCIIString(3); string unknown = reader.ReadASCIIString(1); int framesCount = reader.ReadInt32(); // Either 'ArtDesk SLP 1.00 writer' or // 'RGE RLE shape file' string comment = reader.ReadASCIIString(24); SlpFrameInfo[] frames = new SlpFrameInfo[framesCount]; for (int i = 0; i < frames.Length; i++) { frames[i] = SlpFrameInfo.ReadFrom(reader); SlpFrameInfo info = frames[i]; } ReadFrameData(reader, frames[0]); throw new NotImplementedException(); return(null); }
public static uint ReadScenarioUnknown(string file) { PrimitiveReader reader = new PrimitiveReader(file); string version = reader.ReadASCIIString(4); uint dataOffset = reader.ReadUInt32(); uint headerVersion = reader.ReadUInt32(); if (headerVersion >= 2) { uint timeStamp = reader.ReadUInt32(); } uint scenarioIntroductionLength = reader.ReadUInt32(); if (scenarioIntroductionLength > 0) { int length = (int)scenarioIntroductionLength; reader.ReadASCIIString(length); } uint unknown = reader.ReadUInt32(); reader.Dispose(); return(unknown); }
public static Campaign FromStream(Stream stream) { Campaign campaign = new Campaign(); PrimitiveReader reader = new PrimitiveReader(stream); string rawVersion = reader.ReadASCIIString(versionLength); campaign._campaignName = reader.ReadFixedString(campaignNameLength, Utils.TextEncoding); int scenariosCount = (int)reader.ReadUInt32(); List <CampaignScenario> scenarios = new List <CampaignScenario>(scenariosCount); uint[] offsets = new uint[scenariosCount]; uint[] sizes = new uint[scenariosCount]; // Scenarios layout // | All metadata | // | All raw scenarios | for (int i = 0; i < scenariosCount; i++) { CampaignScenario element = new CampaignScenario(); sizes[i] = reader.ReadUInt32(); offsets[i] = reader.ReadUInt32(); element.Name = reader.ReadFixedString(scenarioNameLength, Utils.TextEncoding); element.Filename = reader.ReadFixedString(scenarioFilenameLength, Utils.TextEncoding); scenarios.Add(element); } // TODO: This could probably be simplified to just reading // the scenarios without seeking, since the scenarios are // almost always stored in order. for (int i = 0; i < scenarios.Count; i++) { CampaignScenario element = scenarios[i]; uint offset = offsets[i]; int length = (int)sizes[i]; stream.Seek(offset, SeekOrigin.Begin); element.Data = reader.ReadBytes(length); } campaign._scenarios = scenarios; return(campaign); }
public static ProfileFile FromStream(PrimitiveReader reader) { ProfileFile profile = new ProfileFile(); profile.Version1 = Version.Parse(reader.ReadASCIIString(4)); if (profile.Version1.Minor >= 6) { profile.Version2 = Version.Parse(reader.ReadFloat32().ToString("0.00")); } profile.LastPlayerId = reader.ReadUInt32(); profile.SelectedPlayerIndex = reader.ReadUInt32(); int playersCount = reader.ReadInt32(); List <ProfilePlayer> players = new List <ProfilePlayer>(playersCount); for (int i = 0; i < playersCount; i++) { players.Add(ProfilePlayer.ReadFrom(reader)); } profile.Players = players; return(profile); }
public static Scenario FromStream(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } PrimitiveReader reader = new PrimitiveReader(stream); string version1 = reader.ReadASCIIString(versionLength); if (version1[1] != '.') { throw new InvalidDataException("Expected period for the second character of the version1 string."); } uint dataOffset = reader.ReadUInt32(); uint headerVersion = reader.ReadUInt32(); if (headerVersion > 2) { throw new InvalidDataException("Header version cannot be greater than 2."); } DateTime utcTime = unixEpoch; if (headerVersion >= 2) { uint secondsSinceEpoch = reader.ReadUInt32(); utcTime = unixEpoch.AddSeconds(secondsSinceEpoch); } string scenarioIntroduction = Utils.ReadUInt32LengthPrefixedString(reader); uint unknown = reader.ReadUInt32(); uint playersCount = reader.ReadUInt32(); if (playersCount > 16) // TODO: Should this be 8 instead? { throw new InvalidDataException("The genie engine only supports up to 16 characters at maximum."); } // Read the compressed header int compressedLength = (int)(stream.Length - stream.Position); byte[] buffer = reader.ReadBytes(compressedLength); byte[] data = Ionic.Zlib.DeflateStream.UncompressBuffer(buffer); #if DUMP_RAW string file = Path.GetFileNameWithoutExtension((stream as FileStream).Name); Console.WriteLine("FILE:" + file); File.WriteAllBytes(file + ".bin", data); #endif reader.Stream = new MemoryStream(data); uint nextUnitId = reader.ReadUInt32(); float version2Raw = reader.ReadFloat32(); string version2 = version2Raw.ToString("0.00"); Scenario scenario; if (version1 == "1.18" & version2 == "1.20") { scenario = new AokScenario(); } else if (version1 == "1.21" && version2 == "1.22") { scenario = new AokTcScenario(); } else { string message = String.Format("Processing versions: {0}, {1} is not supported.", version1, version2); throw new NotImplementedException(message); } scenario.Version1 = Version.Parse(version1); scenario.Version2 = Version.Parse(version2); scenario.UtcLastEdited = utcTime; scenario.ScenarioIntroductionText = scenarioIntroduction; scenario.PlayersCount = (int)playersCount; scenario.Unknown2222 = unknown; scenario.NextUnitId = nextUnitId; scenario.ReadCompressedData(reader); reader.Stream = stream; return(scenario); }
static string ReadUInt32LengthPrefixedString(PrimitiveReader reader) { uint length = reader.ReadUInt32(); return(reader.ReadASCIIString((int)length)); }
static string ReadUInt16LengthPrefixedString(PrimitiveReader reader) { ushort length = reader.ReadUInt16(); return(reader.ReadASCIIString(length)); }
public static DrsFile FromStream(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } DrsFile file = new DrsFile(); PrimitiveReader reader = new PrimitiveReader(stream); file.CopyrightInfo = reader.ReadASCIIString(copyrightLength); file.FileVersion = reader.ReadASCIIString(versionLength); file.FileType = reader.ReadASCIIString(typeLength); uint tablesCount = reader.ReadUInt32(); uint firstFileOffset = reader.ReadUInt32(); Table[] tables = new Table[(int)tablesCount]; for (int i = 0; i < tables.Length; i++) { Table table = new Table(); table.Unknown = reader.ReadUInt8(); byte[] extension = reader.ReadBytes(3); extension = new [] { extension[2], extension[1], extension[0] }; // Stored in reversed form in DRS file. table.Extension = Encoding.ASCII.GetString(extension); table.TableOffset = reader.ReadUInt32(); table.FilesCount = reader.ReadUInt32(); Console.WriteLine("Table {0}: {1} elements of {2}", i, table.FilesCount, table.Extension); tables[i] = table; } System.Diagnostics.Debugger.Break(); for (int i = 0; i < tables.Length; i++) { Table table = tables[i]; stream.Seek(table.TableOffset, SeekOrigin.Begin); TableFile[] files = new TableFile[(int)table.FilesCount]; string directory = "table_" + i; Directory.CreateDirectory(directory); string extension = "." + table.Extension; for (int j = 0; j < files.Length; j++) { TableFile element = new TableFile(); element.FileId = reader.ReadUInt32(); uint offset = reader.ReadUInt32(); uint size = reader.ReadUInt32(); long position = stream.Position; stream.Seek(offset, SeekOrigin.Begin); element.Data = reader.ReadBytes((int)size); stream.Seek(position, SeekOrigin.Begin); files[j] = element; string path = Path.Combine(directory, element.FileId + extension); File.WriteAllBytes(path, element.Data); } table.Files = files; } file.Tables = tables; System.Diagnostics.Debugger.Break(); return(file); }