public TXM Load(Stream TXMStream, Stream TXVStream) { this.TXVStream = TXVStream; if (!IsValid(TXMStream.Slice().ReadBytesUpTo(0x100))) { throw(new Exception("Invalid TXM!")); } this.ImageVersion = TXMStream.Slice().ReadStruct <ImageVersionStruct>(); if (ImageVersion.Version == 1) { this.Surface2DEntriesByName = new Dictionary <string, Surface2DEntryInfo>(); this.Surface2DEntries = new Surface2DEntryInfo[0]; this.Surface3DEntriesByName = new Dictionary <string, Surface3DEntryInfo>(); this.Surface3DEntries = new Surface3DEntryInfo[0]; Console.Error.WriteLine("Not Implemented TXM V1!!!!!!!"); } else { this.ImageHeader = TXMStream.ReadStruct <ImageHeaderStructV2>(); this.Surface2DEntriesByName = new Dictionary <string, Surface2DEntryInfo>(); this.Surface2DEntries = new Surface2DEntryInfo[ImageHeader.Surface2DCount]; for (int n = 0; n < ImageHeader.Surface2DCount; n++) { var ImageEntry = TXMStream.ReadStruct <Surface2DInfoStructV2>(); var Name = TXMStream.SliceWithLength(TXMStream.Position + Marshal.OffsetOf(typeof(Surface2DInfoStructV2), "StringOffset").ToInt32() - sizeof(Surface2DInfoStructV2) + ImageEntry.StringOffset).ReadStringz(); var Entry = new Surface2DEntryInfo(this, n, ImageEntry, Name); this.Surface2DEntries[n] = Entry; this.Surface2DEntriesByName[Name] = Entry; } this.Surface3DEntriesByName = new Dictionary <string, Surface3DEntryInfo>(); this.Surface3DEntries = new Surface3DEntryInfo[ImageHeader.Surface3DCount]; if (this.ImageHeader.VersionInfo.Version != 1) { for (int n = 0; n < ImageHeader.Surface3DCount; n++) { var ImageEntry = TXMStream.ReadStruct <Surface3DInfoStructV2>(); var Name = TXMStream.SliceWithLength(TXMStream.Position + Marshal.OffsetOf(typeof(Surface3DInfoStructV2), "StringOffset").ToInt32() - sizeof(Surface3DInfoStructV2) + ImageEntry.StringOffset).ReadStringz(); var Entry = new Surface3DEntryInfo(this, n, ImageEntry, Name); this.Surface3DEntries[n] = Entry; this.Surface3DEntriesByName[Entry.Name] = Entry; } } } return(this); }
public void Relink(Surface2DEntryInfo that) { if (this.TXM != that.TXM) { throw(new InvalidOperationException("Relinked items must be in the same TXM")); } if (this.ImageEntry.ContentOffset == that.ImageEntry.ContentOffset) { // Already linked } else { // Not linked yet throw (new NotImplementedException()); } }