//call and return save function thread static public Thread saveChunk(chunk chunkToSave) { Thread save = new Thread(() => _SaveChunk(chunkToSave)); save.Start(); return(save); }
public TOCHandler(string tocFileName, string gamePath) { using (FileStream tocStream = File.OpenRead(tocFileName)) { if (tocStream.ReadValueU32() != 0x3AB70C13) { throw new Exception("not a toc.bin file"); } tocFilePath = Path.GetFullPath(tocFileName); this.gamePath = gamePath; chunkList = new List <chunk>(); tocStream.Seek(8, SeekOrigin.Begin); int numChunks = tocStream.ReadValueS32(); for (int i = 0; i < numChunks; i++) { chunk newChunk = new chunk(); newChunk.offset = tocStream.Position; newChunk.relPosition = tocStream.ReadValueS32(); int countBlockFiles = tocStream.ReadValueS32(); if (countBlockFiles == 0) { chunkList.Add(newChunk); continue; } newChunk.fileList = new List <fileStruct>(); tocStream.Seek(newChunk.relPosition - 8, SeekOrigin.Current); for (int j = 0; j < countBlockFiles; j++) { fileStruct newFileStruct = new fileStruct(); long fileOffset = tocStream.Position; tocStream.Seek(2, SeekOrigin.Current); newFileStruct.flag = tocStream.ReadValueS16(); newFileStruct.fileSize = tocStream.ReadValueS32(); newFileStruct.sha1 = tocStream.ReadBytes(20); newFileStruct.filePath = tocStream.ReadStringZ(); newFileStruct.exist = true; tocStream.Seek(fileOffset + newFileStruct.blockSize, SeekOrigin.Begin); newChunk.fileList.Add(newFileStruct); } tocStream.Seek(newChunk.offset + 8, SeekOrigin.Begin); chunkList.Add(newChunk); } } }
public TOCHandler(string tocFileName, string gamePath) { using (FileStream tocStream = File.OpenRead(tocFileName)) { if (tocStream.ReadValueU32() != 0x3AB70C13) throw new Exception("not a toc.bin file"); tocFilePath = Path.GetFullPath(tocFileName); this.gamePath = gamePath; chunkList = new List<chunk>(); tocStream.Seek(8, SeekOrigin.Begin); int numChunks = tocStream.ReadValueS32(); for (int i = 0; i < numChunks; i++) { chunk newChunk = new chunk(); newChunk.offset = tocStream.Position; newChunk.relPosition = tocStream.ReadValueS32(); int countBlockFiles = tocStream.ReadValueS32(); if (countBlockFiles == 0) { chunkList.Add(newChunk); continue; } newChunk.fileList = new List<fileStruct>(); tocStream.Seek(newChunk.relPosition - 8, SeekOrigin.Current); for (int j = 0; j < countBlockFiles; j++) { fileStruct newFileStruct = new fileStruct(); long fileOffset = tocStream.Position; tocStream.Seek(2, SeekOrigin.Current); newFileStruct.flag = tocStream.ReadValueS16(); newFileStruct.fileSize = tocStream.ReadValueS32(); newFileStruct.sha1 = tocStream.ReadBytes(20); newFileStruct.filePath = tocStream.ReadStringZ(); newFileStruct.exist = true; tocStream.Seek(fileOffset + newFileStruct.blockSize, SeekOrigin.Begin); newChunk.fileList.Add(newFileStruct); } tocStream.Seek(newChunk.offset + 8, SeekOrigin.Begin); chunkList.Add(newChunk); } } }
private void SpawnChunk() { chunk newChunk = Instantiate(ChunkPrefabs[Random.Range(0, ChunkPrefabs.Length)]); newChunk.transform.position = spawnedChunks[spawnedChunks.Count - 1].end.position - newChunk.begin.localPosition; spawnedChunks.Add(newChunk); if (spawnedChunks.Count >= 4) { Destroy(spawnedChunks[0].gameObject); spawnedChunks.RemoveAt(0); } }
private chunk[] MakeChunks(int[] items) { int chunksize = 30; int nItems = items.Length; int nChunks = (nItems + (chunksize - 1)) / chunksize; var chunks = new chunk[nChunks]; for (int i = 0, index = 0; i < nChunks; ++i, index += chunksize, nItems -= chunksize) { var cItems = new int[Math.Min(chunksize, nItems)]; Array.Copy(items, index, cItems, 0, cItems.Length); chunks[i] = new chunk(cItems, 0, cItems.Length); } return(chunks); }
//load thread static void LoadChunkThread(FileInfo chunkFile) { Debug.Log("loading file " + chunkFile.Name); if (useOdin) { byte[] bytes = File.ReadAllBytes(chunkFile.FullName); SerializationUtility.DeserializeValue <chunk>(bytes, DataFormat.Binary); } else { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(chunkFile.FullName, FileMode.Open); chunk save = formatter.Deserialize(new BufferedStream(stream)) as chunk; stream.Close(); } }
//save thread static void _SaveChunk(chunk _chunk) { string path = Dpath + "/chunk.chenv"; if (useOdin) { byte[] bytes = SerializationUtility.SerializeValue(_chunk, DataFormat.Binary); File.WriteAllBytes(path, bytes); } else { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Create); formatter.Serialize(new BufferedStream(stream), _chunk); stream.Close(); } }
public void ReadBegin(Stream stream) { if (_chunks.Count == 0) { _chunks.Add(new chunk()); } var chunk = _chunks[_chunks.Count - 1]; if (chunk.Data.Length - chunk.Length < 1000) { if (_captureEntire) { chunk = new chunk(); _chunks.Add(chunk); } else { chunk.Length = 0; } } stream.BeginRead(chunk.Data, chunk.Length, chunk.Data.Length - chunk.Length, result => { readComplete(result, stream); }, null); }
void loadChunks() { List <GameObject> children = new List <GameObject>(); int numChildren = map.transform.childCount; for (int i = 0; i < numChildren; i++) { GameObject toAdd = map.transform.GetChild(i).gameObject; if (toAdd.name.Contains("_")) { int[] vec = coordParse(toAdd.name); maxX = Mathf.Max(vec[0], maxX); maxY = Mathf.Max(vec[1], maxY); if (vec[0] != -1 && vec[1] != -1) { children.Add(toAdd); } } } chunks = new chunk[maxX + 1, maxY + 1]; for (int i = 0; i <= maxX; i++) { for (int j = 0; j <= maxY; j++) { chunks[i, j] = new chunk(this, new int[2] { i, j }); } } foreach (GameObject g in children) { int[] vec = coordParse(g.name); if (vec[0] != -1 && vec[1] != -1) { chunks[vec[0], vec[1]].add(g.transform); } } }
var(chunk, index) = AllocateSlot();
/// <summary> /// Tries to match the pattern against the URI path section and returns a JSONDataMap match object filled with pattern match or NULL if pattern could not be matched. /// JSONDataMap may be easily converted to dynamic by calling new JSONDynamicObject(map) /// </summary> public JSONDataMap MatchURIPath(Uri uri, bool senseCase = false) { JSONDataMap result = null; if (m_MatchChunks.Count == 0) { return(new JSONDataMap(false)); } var segs = uri.LocalPath.Split('/'); var ichunk = -1; chunk chunk = null; var wildCard = false; foreach (var seg in segs) { if (seg.Length == 0) { continue; //skip empty //// } if (!wildCard) { ichunk++; if (ichunk >= m_MatchChunks.Count) { return(null); } chunk = m_MatchChunks[ichunk]; } if (chunk.Portion != chunkPortion.Path) { return(null); } if (chunk.IsWildcard) { wildCard = true; if (result == null) { result = new JSONDataMap(false); } if (!result.ContainsKey(chunk.Name)) { result[chunk.Name] = seg; } else { result[chunk.Name] = (string)result[chunk.Name] + '/' + seg; } } else if (chunk.IsVar) { if (result == null) { result = new JSONDataMap(false); } result[chunk.Name] = seg; } else if (!chunk.Name.Equals(seg, senseCase ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase)) { return(null); } }//foreach ichunk++; while (ichunk < m_MatchChunks.Count) { chunk = m_MatchChunks[ichunk]; if (!chunk.IsVar) { return(null); //some trailing elements that are not vars and do not match } if (result == null) { result = new JSONDataMap(false); } if (!result.ContainsKey(chunk.Name)) { result[chunk.Name] = chunk.DefaultValue; } ichunk++; } return(result ?? new JSONDataMap(false)); }
private void SortChunk(chunk chunk) { Array.Sort(chunk.Items); }
public string saveToFile(bool fileOverwrite = true) { bChanged = false; string finalTocFile = fileOverwrite ? tocFilePath : tocFilePath + ".tmp"; using (FileStream newFileStream = File.Create(finalTocFile)) { newFileStream.WriteValueU32(0x3AB70C13); newFileStream.WriteValueS32(0x0); newFileStream.WriteValueS32(chunkList.Count); int chunkOffset = 12; int fileOffset = 12 + (chunkList.Count * 8); string lastFile = chunkList.Last(x => (x.fileList != null) && x.fileList.Count(/*y => y.exist*/) != 0).fileList.Last(/*z => z.exist*/).filePath; //foreach (chunk element in chunkList) for (int i = 0; i < chunkList.Count; i++) { chunk element = chunkList[i]; newFileStream.Seek(chunkOffset, SeekOrigin.Begin); if (element.countNextFiles == 0)// || element.fileList.Count(x => x.exist) == 0) { newFileStream.WriteValueS64(0x0); chunkOffset = (int)newFileStream.Position; } else { newFileStream.WriteValueS32(fileOffset - chunkOffset); newFileStream.WriteValueS32(element.fileList.Count /*(x => x.exist)*/); chunkOffset = (int)newFileStream.Position; newFileStream.Seek(fileOffset, SeekOrigin.Begin); //foreach (fileStruct fileElement in element.fileList.Where(x => x.exist)) for (int j = 0; j < element.fileList.Count; j++) { fileStruct fileElement = element.fileList[j]; //if (!fileElement.exist) // continue; MemoryStream buffer = new MemoryStream(fileElement.blockSize); { if (fileElement.filePath == lastFile) { buffer.WriteValueS16(0x0); } else { buffer.WriteValueS16(fileElement.blockSize); } buffer.WriteValueS16(fileElement.flag); buffer.WriteValueS32(fileElement.fileSize); buffer.WriteBytes(fileElement.sha1); buffer.WriteStringZ(fileElement.filePath); byte[] byteBuff = new byte[fileElement.blockSize]; buffer.ToArray().CopyTo(byteBuff, 0); newFileStream.WriteBytes(byteBuff); } //newFileStream.Seek(fileOffset, SeekOrigin.Begin); } fileOffset = (int)newFileStream.Position; } } } return(finalTocFile); }
var(chunk, rest) = _provider._providers[i].GetStartPosition().GetText(lengthRemaining);
void loadChunks() { List<GameObject> children = new List<GameObject>(); int numChildren = map.transform.childCount; for(int i = 0; i < numChildren; i++) { GameObject toAdd = map.transform.GetChild(i).gameObject; if (toAdd.name.Contains("_")) { int[] vec = coordParse(toAdd.name); maxX = Mathf.Max(vec[0], maxX); maxY = Mathf.Max(vec[1], maxY); if (vec[0] != -1 && vec[1] != -1) { children.Add(toAdd); } } } chunks = new chunk[maxX+1,maxY+1]; for (int i = 0; i <= maxX; i++) { for (int j = 0; j <= maxY; j++) { chunks[i, j] = new chunk(this,new int[2] { i, j }); } } foreach(GameObject g in children) { int[] vec = coordParse(g.name); if (vec[0] != -1 && vec[1] != -1) { chunks[vec[0], vec[1]].add(g.transform); } } }
var(chunk, _) = Position.GetText(maxLength);
var(chunk, pos) = _position.GetText(actualMax);
public void ReadBegin(Stream stream) { if (_chunks.Count == 0) _chunks.Add(new chunk()); var chunk = _chunks[_chunks.Count - 1]; if (chunk.Data.Length - chunk.Length < 1000) { if (_captureEntire) { chunk = new chunk(); _chunks.Add(chunk); } else chunk.Length = 0; } stream.BeginRead(chunk.Data, chunk.Length, chunk.Data.Length - chunk.Length, result => { readComplete(result, stream); }, null); }
/* public WavReader(Stream t,long startpos) * { * daten = new BufferedStream(t,1677216); * this.startpos = startpos; * reader = new BinaryReader(daten); * t.Seek(startpos,SeekOrigin.Begin ); * this.startpos += 44;// die 1. 44 bytes sollen nicht lesbar sein * position = 0; * header=new waveheader(); * byte[] tmp; * tmp = reader.ReadBytes(44); * int zuskippen = 44; * int i; * unsafe * { * fixed (waveheader* pointer = &header) * { * byte* bytepointer = (byte*)pointer; * for (i = 0; i < 44; i++) * { *(bytepointer + i) = tmp[i]; * } * } * } * * if ((header.bitspersample != 16) || (header.formattag != 1)) * { * throw new ArgumentException("Die Wavdaten sind nicht mit 16bit Samples oder nicht in PCM kodiert"); * } * waveheader h = header; * MessageBox.Show("bitps: " + h.bitspersample + "\nBlockal: " + h.blockalign + "\nBytps: " + h.bytespersecond + "\nChannels: " + h.channels + "\nData: " + h.data + "\nDatal: " + h.datalength + "\nFilesize: " + h.filesize + "\nFmt: " + h.fmt + "\nFmtl: " + h.fmtlength + "\nFormattag: " + h.formattag + "\nRiff: " + h.riff + "\nSamplerate: " + h.samplerate + "\nWave: " + h.wave + " "); * laenge = header.filesize+8-44; * }*/ public WavReader(Stream t, long startpos) { daten = new BufferedStream(t, 1677216); daten.Seek(startpos, SeekOrigin.Begin); reader = new BinaryReader(daten); uint zuskippen = 0; this.startpos = startpos; header = new waveheader(); chunk ch = new chunk(); do { //MessageBox.Show("Header lesend..."); ch.header = (uint)reader.ReadInt32(); ch.laenge = (uint)reader.ReadInt32(); //MessageBox.Show("Chunk gelesen..."); zuskippen += 8; // MessageBox.Show(""+ch.laenge+" "+ch.header); if (ch.header == 1179011410) { //MessageBox.Show("RIFF gefunden"); header.riff = ch.header; header.filesize = ch.laenge; header.wave = (uint)reader.ReadInt32(); zuskippen += 4; } else if (ch.header == 544501094)//fmt //MessageBox.Show("FMT gefunden "+ch.laenge); { int i; unsafe { fixed(waveheader *headerpointer = &header) { byte *zieladdr = (byte *)headerpointer; for (i = 20; i < 36; i++) { *(zieladdr + i) = reader.ReadByte(); } } } if (ch.laenge > 16) { reader.ReadBytes((int)(ch.laenge - 16)); } header.fmt = ch.header; header.fmtlength = ch.laenge; zuskippen += ch.laenge; } else if (ch.header == 1635017060) { // MessageBox.Show("DATA gefunden"); header.data = ch.header; header.datalength = ch.laenge; break; } else { // MessageBox.Show("WTF gefunden (wahrscheinlich list) "+ch.header+" "+ch.laenge); zuskippen += ch.laenge; reader.ReadBytes((int)ch.laenge); } }while(true); waveheader h = header; // MessageBox.Show("bitps: " + h.bitspersample + "\nBlockal: " + h.blockalign + "\nBytps: " + h.bytespersecond + "\nChannels: " + h.channels + "\nData: " + h.data + "\nDatal: " + h.datalength + "\nFilesize: " + h.filesize + "\nFmt: " + h.fmt + "\nFmtl: " + h.fmtlength + "\nFormattag: " + h.formattag + "\nRiff: " + h.riff + "\nSamplerate: " + h.samplerate + "\nWave: " + h.wave + " "); laenge = header.filesize + 8 - zuskippen; this.startpos += zuskippen; position = 0; seek(); }