/// <summary> /// Parses camera data into BattleCamera struct. Main purpouse of this function is to /// actually read all the offsets and pointers to human readable form of struct. This /// function later calls ReadAnimation(n) where n is animation Id (i.e. 9 is camCollection=1 /// and cameraAnim=0) /// </summary> public static Camera Read(BinaryReader br) { Camera c = new Camera(); br.BaseStream.Seek(c.bs_cameraPointer, 0); uint cCameraHeaderSector = br.ReadUInt16(); uint pCameraSetting = br.ReadUInt16(); uint pCameraAnimationCollection = br.ReadUInt16(); uint sCameraDataSize = br.ReadUInt16(); //Camera settings parsing? BattleCameraSettings bcs = new BattleCameraSettings() { unk = br.ReadBytes(24) }; //end of camera settings parsing br.BaseStream.Seek(pCameraAnimationCollection + c.bs_cameraPointer, SeekOrigin.Begin); BattleCameraCollection bcc = new BattleCameraCollection { cAnimCollectionCount = br.ReadUInt16() }; BattleCameraSet[] bcset = new BattleCameraSet[bcc.cAnimCollectionCount]; bcc.battleCameraSet = bcset; for (int i = 0; i < bcc.cAnimCollectionCount; i++) { bcset[i] = new BattleCameraSet() { globalSetPointer = (uint)(br.BaseStream.Position + br.ReadUInt16() - i * 2 - 2) } } ; bcc.pCameraEOF = br.ReadUInt16(); for (int i = 0; i < bcc.cAnimCollectionCount; i++) { br.BaseStream.Seek(bcc.battleCameraSet[i].globalSetPointer, 0); bcc.battleCameraSet[i].animPointers = new uint[8]; for (int n = 0; n < bcc.battleCameraSet[i].animPointers.Length; n++) { bcc.battleCameraSet[i].animPointers[n] = (uint)(br.BaseStream.Position + br.ReadUInt16() * 2 - n * 2); } } CameraStruct cam = Extended.ByteArrayToStructure <CameraStruct>(new byte[Marshal.SizeOf(typeof(CameraStruct))]); //what about this kind of trick to initialize struct with a lot amount of fixed sizes in arrays? c.battleCameraCollection = bcc; c.battleCameraSettings = bcs; c.cam = cam; c.ReadAnimationById(c.GetRandomCameraN(Memory.Encounters.Current), br); c.EndOffset = c.bs_cameraPointer + sCameraDataSize; //br.BaseStream.Seek(c.EndOffset, 0); //step out return(c); } #endregion Methods }
public wm2field(byte[] buffer) { var structSize = Marshal.SizeOf(typeof(warpEntry)); warpEntries = new warpEntry[buffer.Length / structSize]; for (var i = 0; i < warpEntries.Length; i++) { warpEntries[i] = Extended.ByteArrayToStructure <warpEntry>(buffer.Skip(i * structSize).Take(structSize).ToArray()); } }
private RailEntry ParseBlock(byte[] block) { RailEntry entry = new RailEntry() { cKeypoints = block[0], unk = block[1], unk2 = BitConverter.ToUInt16(block, 2), trainStop1 = BitConverter.ToUInt32(block, 4), trainStop2 = BitConverter.ToUInt32(block, 8) }; entry.keypoints = new Keypoint[entry.cKeypoints]; for (int i = 0; i < entry.cKeypoints; i++) { entry.keypoints[i] = Extended.ByteArrayToStructure <Keypoint>(block.Skip(BLOCK_HEADER_SIZE + (i * 16)).Take(16).ToArray()); } return(entry); }
private Camera(BinaryReader br) : this() { br.BaseStream.Seek(_bsCameraPointer + 4, 0); //uint cCameraHeaderSector = br.ReadUInt16(); //uint pCameraSetting = br.ReadUInt16(); uint pCameraAnimationCollection = br.ReadUInt16(); uint sCameraDataSize = br.ReadUInt16(); //Camera settings parsing? //var battleCameraSettings = new BattleCameraSettings { unk = br.ReadBytes(24) }; //end of camera settings parsing br.BaseStream.Seek(pCameraAnimationCollection + _bsCameraPointer, SeekOrigin.Begin); _battleCameraCollection = new BattleCameraCollection { cAnimCollectionCount = br.ReadUInt16() }; var battleCameraSet = new BattleCameraSet[_battleCameraCollection.cAnimCollectionCount]; _battleCameraCollection.battleCameraSet = battleCameraSet; for (var i = 0; i < _battleCameraCollection.cAnimCollectionCount; i++) { battleCameraSet[i] = new BattleCameraSet { globalSetPointer = (uint)(br.BaseStream.Position + br.ReadUInt16() - i * 2 - 2) } } ; _battleCameraCollection.pCameraEOF = br.ReadUInt16(); for (var i = 0; i < _battleCameraCollection.cAnimCollectionCount; i++) { br.BaseStream.Seek(_battleCameraCollection.battleCameraSet[i].globalSetPointer, 0); _battleCameraCollection.battleCameraSet[i].animPointers = new uint[8]; for (var n = 0; n < _battleCameraCollection.battleCameraSet[i].animPointers.Length; n++) { _battleCameraCollection.battleCameraSet[i].animPointers[n] = (uint)(br.BaseStream.Position + br.ReadUInt16() * 2 - n * 2); } } Cam = Extended.ByteArrayToStructure <CameraStruct>(new byte[Marshal.SizeOf(typeof(CameraStruct))]); //what about this kind of trick to initialize struct with a lot amount of fixed sizes in arrays? ReadAnimationById(GetRandomCameraN(Memory.Encounters.Current), br); EndOffset = _bsCameraPointer + sCameraDataSize; //br.BaseStream.Seek(c.EndOffset, 0); //step out }
public Information CreateInstance(BinaryReader br, long byteOffset) { br.BaseStream.Seek(byteOffset, SeekOrigin.Begin); return(Extended.ByteArrayToStructure <Information>(br.ReadBytes(ByteSize))); }