/// <summary> /// Check if the chunk is present, if not it'll be created with a size of 0 if create is true /// Additionnal chunks between the starting pos and the chunk will be deleted /// </summary> /// <param name="pos">starting pos for the search</param> /// <param name="chunk">magic value of the wanted chunk</param> /// <param name="create">if this is set to true and the chunk isn't there it will create it empty</param> /// <returns>the new pos after the chunk</returns> private int CheckChunk(int pos, GroupChunk chunk, bool create = true, bool delete = true) { int found = FindChunk(pos, chunk); if (found == -1 && create) { AddEmptyBytes(pos, 8); WriteInt(pos, (int)chunk); return(pos + 0x8); } if (found > pos) { if (delete) { RemoveBytes(pos, found - pos); } else { pos = found; } } if (found != -1) { pos += ReadInt(pos + 0x4) + 0x8; } // return the current pos return(pos); }
private int FindChunk(int pos, GroupChunk chunk) { int found = -1; for (int i = pos; i + 8 <= Size(); i += (ReadInt(i + 0x4) + 0x8)) { if (ReadInt(i) == (int)chunk) { found = i; break; } } return(found); }