private ChunkList GetResourceRootChunks() { var map = GetResourceMap(); var result = new ChunkList(); Position = 0; ulong offset = Position; uint chunkSize = ReadU16LE(); var chunk = new SCUMM1Chunk(this, RootChunk, "ROOMv1", offset, chunkSize); result.Add(chunk); Position += chunkSize - 2; string chunkName; while (Position < Size) { offset = Position; chunkSize = ReadU16LE(); if (offset + chunkSize > Size) { chunkSize = (uint)(Size - offset); chunkName = "????v1"; } else { SCUMM1ResourceType type; if (!map.TryGetValue(offset, out type)) { chunkName = "????v1"; } else { switch (type) { case SCUMM1ResourceType.Costume: chunkName = "COSTv1"; break; case SCUMM1ResourceType.Script: chunkName = "SCRPv1"; break; case SCUMM1ResourceType.Sound: chunkName = "SOUNv1"; break; default: throw new FileFormatException("Unknown resource type: {0}", type); } } } result.Add(new SCUMM1Chunk(this, RootChunk, chunkName, offset, chunkSize)); Position += chunkSize - 2; } return(result); }
private ChunkList GetDirectoryRootChunks() { var result = new ChunkList(); result.Add(new UnknownChunk(this, RootChunk, 0, Size)); return(result); }
/// <summary> /// Function to read in the chunk table from the file. /// </summary> /// <param name="reader">The reader for the stream.</param> /// <param name="offset">Offset of the chunk table from the file start.</param> private void ReadChunkTable(GorgonBinaryReader reader, long offset) { long prevPosition = Stream.Position; try { Stream.Position = offset; ulong chunkID = reader.ReadUInt64(); if (chunkID != ChunkTableID) { throw new GorgonException(GorgonResult.CannotRead, Resources.GOR_ERR_CHUNK_FILE_TABLE_CHUNK_INVALID); } int count = reader.ReadInt32(); if (count < 0) { throw new GorgonException(GorgonResult.CannotRead, Resources.GOR_ERR_CHUNK_FILE_TABLE_INVALID_COUNT); } // Retrieve the chunk table. for (int i = 0; i < count; ++i) { ChunkList.Add(new GorgonChunk(reader.ReadUInt64(), reader.ReadInt32(), reader.ReadUInt64())); } } finally { Stream.Position = prevPosition; } }
public override ChunkList GetRootChunks() { Position = 0; ChunkList result = new ChunkList(); result.Add(new LB83Chunk(this, RootChunk)); return(result); }
private void buttonAddChunkClick(object sender, EventArgs e) { Chunk NewChunk = new Chunk(); NewChunk.CalculateModel(); ChunkList.Add(NewChunk); numericCurrentChunk.Minimum = 1; numericCurrentChunk.Maximum = ChunkList.Count(); numericCurrentChunk.Value = ChunkList.Count(); labelChunkAmount.Text = "Amount: " + ChunkList.Count(); }
private void LoadPixels(Pixel[] pixels) { if (ChunkList == null) { ChunkList = new List <ColorChunk>(); } List <Pixel> pixelList = new List <Pixel>(pixels); Stopwatch stopwatch = new Stopwatch(); Console.WriteLine("Loading pixels..."); int count = 0; stopwatch.Start(); pixelList = new List <Pixel>(pixelList.OrderBy(pixel => pixel.Color.AsInt())); int i; while (pixelList.Any()) { for (i = 0; i < pixelList.Count - 1; i++) { if (!pixelList[i].Color.Equals(pixelList[i + 1].Color)) { break; } } ChunkList.Add(new ColorChunk(pixelList.First().Color, i + 1)); pixelList.RemoveRange(0, i + 1); count++; } stopwatch.Restart(); // Sort by Count ChunkList = new List <ColorChunk>(ChunkList.OrderBy(chunk => chunk.Count)); ColorList = ChunkList.Select(chunk => chunk.Color).ToList(); stopwatch.Stop(); Console.WriteLine("Pixels was loaded successfully!"); Console.WriteLine("Elapsed: " + stopwatch.Elapsed.ToString()); Console.WriteLine("CaluculateTime: " + count.ToString()); }
public override ChunkList GetRootChunks() { ChunkList result = new ChunkList(); Position = 0; while (Position < Size) { Chunk chunk = new BUNDChunk(this, RootChunk, "BUND", 0, Size - 8); result.Add(chunk); Position = chunk.Offset + chunk.Size; } return(result); }
public override ChunkList GetRootChunks() { ChunkList result = new ChunkList(); Position = 0; while (Position < Size) { Chunk chunk = SCUMM3Chunk.ReadChunk(this, RootChunk); result.Add(chunk); Position = chunk.Offset + chunk.Size; } return(result); }
/// <summary> /// Function to close an open chunk. /// </summary> /// <remarks> /// <para> /// This will close the active chunk, and add it to the chunk table list. It will reposition the stream pointer for the stream passed to the constructor of this object to the next position for /// a chunk, or the end of the chunk data. /// </para> /// <para> /// If this method is not called, then the chunk will not be added to the chunk table in the file and the file will lose that chunk. This, however, does not mean the file is necessarily corrupt, /// just that the chunk will not exist. Regardless, this method should always be called when one of the <see cref="O:Gorgon.IO.GorgonChunkFile`1.OpenChunk"/> are called. /// </para> /// </remarks> public override void CloseChunk() { if (_activeChunk.ID == 0) { return; } // Move the stream forward by the amount written. _activeChunk = new GorgonChunk(_activeChunk.ID, (int)(_activeWriter.BaseStream.Length), _activeChunk.FileOffset); Stream.Position += _activeChunk.Size; ChunkList.Add(_activeChunk); _activeChunk = default; _activeWriter.Dispose(); _activeWriter = null; }
public Sentence(SentenceDefinition sd) { KanjiKana = sd.KanjiKana; Kana = sd.Kana; var charArray = Kana.ToCharArray(); var charList = new List <char>(charArray); var strList = charList.Select(c => c.ToString()).ToList(); var isSokuon = false; var from = 0; for (int i = 0; i < strList.Count(); i++) { if (i < strList.Count() - 1) //最終文字ならチャンク確定 { if (!isSokuon) { isSokuon = KanaUtils.IsSokuon(strList[i]); if (isSokuon) { from--; continue; } } var chkStr = strList[i] + strList[i + 1]; if (KanaUtils.Henkan.ContainsKey(chkStr)) { from--; continue; } } var chunkStr = ""; for (int j = from; j < 1; j++) { chunkStr = chunkStr + strList[i + j]; } ; ChunkList.Add(new Chunk(chunkStr, isSokuon)); isSokuon = false; from = 0; } }
private void ParseChunks(Stream st) { // When reaches the end, stop. if (st.Position == st.Length) { return; } // If it is a valid chunk, it has to be at least 8 Sanity.Requires(st.Position + 8 <= st.Length, $"Stream length mismatch, at position {st.Position}."); // Offset is the current position. int offset = (int)st.Position; // The first four bytes(of the 8 bytes) is the name. st.Read(ChunkNameBytes, 0, 4); string name = GetName(); // The next four bytes(of the 8 bytes) is the chunk siz/length. st.Read(Int32Bytes, 0, 4); int length = GetInt32(); // The chunk length should not exceed the end of the file. Sanity.Requires(st.Position + length <= st.Length, $"Stream length mismatch, at position {st.Position}, in chunk {name}."); // Move forward. st.Seek(length, SeekOrigin.Current); // Set the chunk. WaveChunk chunk = new WaveChunk { ChunkName = name, ChunkLength = length, ChunkOffset = offset }; // Format chunk is special. if (chunk.ChunkName == "fmt ") { // There should be only 1 format chunk. Sanity.Requires(FormatChunk.ChunkName == null, $"Format error, at most 1 format chunk."); // The smallest format chunk for PCM is 16. Sanity.Requires(chunk.ChunkLength >= 16, $"Format error, format chunk length {FormatChunk.ChunkLength}, should be at least 16."); FormatChunk = chunk; } // Data chunk is special. if (chunk.ChunkName == "data") { // There should be only 1 data chunk. // NOTE: I'M NOT SURE ABOUT THIS, THERE IS NOWHERE SAY ONLY 1 DATA CHUNK IS ALLOWED. // JUST FOR SIMPLE HERE. Sanity.Requires(DataChunk.ChunkName == null, $"Format error, at most 1 data chunk."); DataChunk = chunk; } // Add this chunk into the list. ChunkList.Add(chunk); // Parse the next chunk recursively. ParseChunks(st); }