public static string[] TestFolder(string folderName, TestFlags flags, ref int filesRead, ref int filesToRead, ref string recentMessage) { DirectoryInfo directoryInfo = new DirectoryInfo(folderName); FileInfo[] fileInfos = directoryInfo.GetFiles("*.*", SearchOption.AllDirectories); fileInfos = Array.FindAll(fileInfos, info => (info.Extension == ".pcm" || info.Extension == ".drm")); List <string> physObs = new List <string>(); List <string> genericTunes = new List <string>(); List <string> monAttributes = new List <string>(); List <string> monFuncTables = new List <string>(); List <string> results = new List <string>(); int numSucceeded = 0; int numSkipped = 0; System.Threading.Interlocked.Exchange(ref filesRead, 0); System.Threading.Interlocked.Exchange(ref filesToRead, fileInfos.Length); foreach (FileInfo fileInfo in fileInfos) { string cleanName = Path.GetFileNameWithoutExtension(fileInfo.Name).PadRight(20); if ((flags & TestFlags.IgnoreDuplicates) != 0 && cleanName.Contains("duplicate")) { System.Threading.Interlocked.Increment(ref filesRead); numSkipped++; continue; } System.Threading.Interlocked.Exchange(ref recentMessage, (string)fileInfo.Name.Clone()); string fileDesc = fileInfo.Name.PadRight(20) + "(Size = 0xFFFFFFFF bytes)"; try { SR1_File file = new SR1_File(); file.Import(fileInfo.FullName, ImportFlags.LogErrors); fileDesc = fileInfo.Name.PadRight(20) + "(Size = 0x" + file._FileLength.ToString("X8") + " bytes)"; if (file.TestExport()) { if ((flags & TestFlags.ListAllFiles) != 0) { results.Add(fileDesc + " - Success"); } numSucceeded++; } else { results.Add(fileDesc + " - Fail"); } if (!file._IsLevel) { if ((flags & TestFlags.ListObjectTypes) != 0) { SR1Structures.Object obj = (SR1Structures.Object)file._Structures[0]; SR1_Structure data = file._Structures[obj.data.Offset]; if (data is PhysObPropertiesBase) { PhysObPropertiesBase physOb = (PhysObPropertiesBase)data; physObs.Add("\t" + cleanName + "\t{ oflags = " + obj.oflags.ToString() + ", oflags2 = " + obj.oflags2.ToString() + ", physOb.Properties.Type = " + physOb.Properties.ID.ToString() + " }"); } else if (data is GenericTune) { GenericTune genericTune = (GenericTune)data; genericTunes.Add("\t" + cleanName + "\t{ oflags = " + obj.oflags.ToString() + ", oflags2 = " + obj.oflags2.ToString() + ", genericTune.flags = " + genericTune.flags.ToString() + " }"); } else if (data is MonsterAttributes) { MonsterAttributes monsterAttributes = (MonsterAttributes)data; monAttributes.Add("\t" + cleanName + "\t{ oflags = " + obj.oflags.ToString() + ", oflags2 = " + obj.oflags2.ToString() + ", monsterAttributes.magicNum = " + monsterAttributes.magicnum.ToString() + ", monsterAttributes.whatAmI = " + monsterAttributes.whatAmI.ToString() + " }"); } } if ((flags & TestFlags.ListRelocModules) != 0) { SR1Structures.Object obj = (SR1Structures.Object)file._Structures[0]; if (obj.relocModule.Offset != 0) { SR1_Structure relocModule = file._Structures[obj.relocModule.Offset]; if (relocModule is MonsterFunctionTable) { MonsterFunctionTable mft = (MonsterFunctionTable)relocModule; string relocStart = "Start = 0x" + mft.stateChoices.Start.ToString("X8"); string relocEnd = "End = 0x" + mft.stateChoices.End.ToString("X8"); string relocSize = "Size = 0x" + (mft.stateChoices.End - mft.stateChoices.Start).ToString("X8"); monFuncTables.Add( "\t" + cleanName + "\t{ MonsterFunctionTable (" + relocStart + ", " + relocEnd + ", " + relocSize + ") }"); } } } } } catch { results.Add(fileDesc + " - Error"); } System.Threading.Interlocked.Increment(ref filesRead); } if ((flags & TestFlags.ListObjectTypes) != 0) { results.Add("\r\nPhysObs:"); results.AddRange(physObs); results.Add("\r\nGenericTunes:"); results.AddRange(genericTunes); results.Add("\r\nMonsterAttibutes:"); results.AddRange(monAttributes); results.Add(""); } if ((flags & TestFlags.ListRelocModules) != 0) { results.Add("\r\nMonsterFunctionTables:"); results.AddRange(monFuncTables); results.Add(""); } //results.Add("\r\nCollectibles:"); //results.AddRange(collectibles); //results.Add(""); results.Add("Files Read: " + (filesRead - numSkipped)); results.Add("Succeeded: " + numSucceeded); results.Add("Failed: " + (filesRead - numSkipped - numSucceeded)); return(results.ToArray()); }
private void Import(Stream inputStream) { Reset(); MemoryStream dataStream = new MemoryStream(); BinaryWriter dataWriter = new BinaryWriter(dataStream, System.Text.Encoding.UTF8, true); SR1_Reader dataReader = new SR1_Reader(this, dataStream, System.Text.Encoding.UTF8, true); using (BinaryReader inputReader = new BinaryReader(inputStream, System.Text.Encoding.UTF8, true)) { uint dataStart = ((inputReader.ReadUInt32() >> 9) << 11) + 0x00000800; _FileLength = (uint)inputStream.Length - dataStart; _IsLevel = inputReader.ReadUInt32() == 0; inputReader.BaseStream.Position = dataStart; dataWriter.BaseStream.Position = 0; inputReader.BaseStream.CopyTo(dataWriter.BaseStream); dataWriter.BaseStream.Position = 0; } SR1_Structure root; if (_IsLevel) { bool validVersion = false; if (!validVersion && ((_ImportFlags & ImportFlags.DetectPCRetail) != 0)) { dataReader.BaseStream.Position = 0x9C; if (dataReader.ReadUInt64() == 0xFFFFFFFFFFFFFFFF) { _Version = Version.Retail_PC; validVersion = true; } } if (!validVersion) { dataReader.BaseStream.Position = 0xF0; UInt32 version = dataReader.ReadUInt32(); if (!validVersion && version == RETAIL_VERSION) { _Version = Version.Jun01; validVersion = true; } if (!validVersion && version == BETA_19990512_VERSION) { _Version = Version.May12; validVersion = true; } if (!validVersion) { dataReader.BaseStream.Position = 0xE4; version = dataReader.ReadUInt32(); } if (!validVersion && version == ALPHA_19990216_VERSION_3) { _Version = Version.Feb16; validVersion = true; } if (!validVersion) { dataReader.BaseStream.Position = 0xE0; version = dataReader.ReadUInt32(); } if (!validVersion && version == ALPHA_19990204_VERSION_2) { _Version = Version.Feb04; validVersion = true; } } if (!validVersion) { _Version = Version.Jun01; validVersion = true; } root = new SR1Structures.Level(); } else { bool validVersion = false; if (!validVersion) { dataReader.BaseStream.Position = 0x2C; UInt32 oflags2 = dataReader.ReadUInt32(); if ((oflags2 & 0x00080000) != 0) { dataReader.BaseStream.Position = 0x1C; UInt32 dataPos = dataReader.ReadUInt32(); if (dataPos != 0) { dataReader.BaseStream.Position = dataPos; UInt32 magicNum = dataReader.ReadUInt32(); if (magicNum == 0xACE00065) { _Version = Version.Jul14; validVersion = true; } else if (magicNum == 0xACE00064) { _Version = Version.Jun10; validVersion = true; } else if (magicNum == 0xACE00063) { _Version = Version.Jun01; validVersion = true; } else if (magicNum == 0xACE00062) { _Version = Version.May12; validVersion = true; } else if (magicNum == 0xACE0005C) { _Version = Version.Feb16; validVersion = true; } } } else { dataWriter.BaseStream.Position = 0x24; uint namePos = dataReader.ReadUInt32(); if (namePos == 0x00000044) { _Version = Version.Feb16; validVersion = true; } if (!validVersion) { dataReader.BaseStream.Position = 0x50; char[] objectName = dataReader.ReadChars(8); string objectNameStr = new string(objectName); if (objectNameStr == "flamegs_") { _Version = Version.Feb16; validVersion = true; } } if (!validVersion) { dataReader.BaseStream.Position = 0x4C; char[] objectName = dataReader.ReadChars(8); string objectNameStr = new string(objectName); if (objectNameStr == "particle") { dataReader.BaseStream.Position = 0x0424; if (dataReader.ReadUInt32() == 0x00000440 && dataReader.ReadUInt32() == 0x00003000 && dataReader.ReadUInt32() == 0x00003150 && dataReader.ReadUInt32() == 0x0000355C && dataReader.ReadUInt32() == 0x00003B60 && dataReader.ReadUInt32() == 0x00003EE8 && dataReader.ReadUInt32() == 0x00003EA0) { _Version = Version.May12; } else { _Version = Version.Jun01; } validVersion = true; } } } } if (!validVersion) { _Version = Version.Jun01; validVersion = true; } root = new SR1Structures.Object(); } dataReader.BaseStream.Position = 0; root.Read(dataReader, null, ""); if (_IsLevel && (_ImportFlags & ImportFlags.LogScripts) != 0) { dataReader.ScriptParser.ParseAll(dataReader); } dataReader.Dispose(); dataWriter.Dispose(); dataStream.Close(); }