protected override void ReadData(DataBuffer buf, FileFormat fmt) { NextScriptPointer = buf.ReadUInt32(); PrevScriptPointer = buf.ReadUInt32(); Name = buf.ReadString(MaxNameLength); InstructionPointer = buf.ReadInt32(); Stack = buf.ReadArray <int>(GetMaxStackDepth(fmt)); StackPointer = buf.ReadInt16(); buf.Align4(); Locals = buf.ReadArray <int>(NumLocalVariables); TimerA = buf.ReadUInt32(); TimerB = buf.ReadUInt32(); ConditionResult = buf.ReadBool(); IsMissionScript = buf.ReadBool(); ClearMessages = buf.ReadBool(); buf.Align4(); WakeTime = buf.ReadUInt32(); AndOrState = buf.ReadInt16(); NotFlag = buf.ReadBool(); WastedBustedCheckEnabled = buf.ReadBool(); WastedBustedCheckResult = buf.ReadBool(); MissionFlag = buf.ReadBool(); buf.Align4(); Debug.Assert(buf.Offset == GetSize(fmt)); }
protected override void WriteData(DataBuffer buf, FileFormat fmt) { buf.Write(NextScriptPointer); buf.Write(PrevScriptPointer); buf.Write(Name, MaxNameLength); buf.Write(InstructionPointer); buf.Write(Stack, GetMaxStackDepth(fmt)); buf.Write(StackPointer); buf.Align4(); buf.Write(Locals, NumLocalVariables); buf.Write(TimerA); buf.Write(TimerB); buf.Write(ConditionResult); buf.Write(IsMissionScript); buf.Write(ClearMessages); buf.Align4(); buf.Write(WakeTime); buf.Write(AndOrState); buf.Write(NotFlag); buf.Write(WastedBustedCheckEnabled); buf.Write(WastedBustedCheckResult); buf.Write(MissionFlag); buf.Align4(); Debug.Assert(buf.Offset == GetSize(fmt)); }
protected override void ReadData(DataBuffer buf, FileFormat fmt) { int size = SaveFileGTA3VC.ReadBlockHeader(buf, "SCR"); int varSpace = buf.ReadInt32(); ScriptSpace = buf.ReadArray <byte>(varSpace); buf.Align4(); int scriptDataSize = buf.ReadInt32(); Debug.Assert(scriptDataSize == ScriptDataSize); OnAMissionFlag = buf.ReadInt32(); Contacts = buf.ReadArray <Contact>(NumContacts); Collectives = buf.ReadArray <Collective>(NumCollectives); NextFreeCollectiveIndex = buf.ReadInt32(); BuildingSwaps = buf.ReadArray <BuildingSwap>(NumBuildingSwaps); InvisibilitySettings = buf.ReadArray <InvisibleObject>(NumInvisibilitySettings); UsingAMultiScriptFile = buf.ReadBool(); buf.ReadByte(); buf.ReadUInt16(); MainScriptSize = buf.ReadInt32(); LargestMissionScriptSize = buf.ReadInt32(); NumberOfMissionScripts = buf.ReadInt16(); buf.ReadUInt16(); int runningScripts = buf.ReadInt32(); Threads = buf.ReadArray <RunningScript>(runningScripts, fmt); Debug.Assert(buf.Offset == size + SaveFileGTA3VC.BlockHeaderSize); Debug.Assert(size == SizeOfObject(this, fmt) - SaveFileGTA3VC.BlockHeaderSize); }
protected override void WriteData(DataBuffer buf, FileFormat fmt) { int size = SizeOfObject(this, fmt); SaveFileGTA3VC.WriteBlockHeader(buf, "SCR", size - SaveFileGTA3VC.BlockHeaderSize); buf.Write(ScriptSpace.Count); buf.Write(ScriptSpace); buf.Align4(); buf.Write(ScriptDataSize); buf.Write(OnAMissionFlag); buf.Write(Contacts, NumContacts); buf.Write(Collectives, NumCollectives); buf.Write(NextFreeCollectiveIndex); buf.Write(BuildingSwaps, NumBuildingSwaps); buf.Write(InvisibilitySettings, NumInvisibilitySettings); buf.Write(UsingAMultiScriptFile); buf.Write((byte)0); buf.Write((short)0); buf.Write(MainScriptSize); buf.Write(LargestMissionScriptSize); buf.Write(NumberOfMissionScripts); buf.Write((short)0); buf.Write(Threads.Count); buf.Write(Threads, fmt); Debug.Assert(buf.Offset == size); }
public void Alignment() { Faker f = new Faker(); bool b0 = f.Random.Bool(); int i0 = f.Random.Int(); float f0 = f.Random.Float(); byte[] data; int i1; bool b1; float f1; using (DataBuffer wb = new DataBuffer()) { wb.Write(b0); wb.Align4(); wb.Write(i0); wb.Write(f0); data = wb.GetBuffer(); } using (DataBuffer wb = new DataBuffer(data)) { b1 = wb.ReadBool(); wb.Align4(); i1 = wb.ReadInt32(); f1 = wb.ReadFloat(); } Assert.Equal(b0, b1); Assert.Equal(i0, i1); Assert.Equal(f0, f1); Assert.Equal(12, data.Length); }
protected override void ReadData(DataBuffer buf, FileFormat fmt) { int size = SaveFileGTA3VC.ReadBlockHeader(buf, "SCR"); int varSpace = buf.ReadInt32(); Globals = buf.ReadArray <int>(varSpace / sizeof(int)); buf.Align4(); int scriptDataSize = buf.ReadInt32(); Debug.Assert(scriptDataSize == ScriptDataSize); OnAMissionFlag = buf.ReadInt32(); LastMissionPassedTime = buf.ReadUInt32(); BuildingSwaps = buf.ReadArray <BuildingSwap>(NumBuildingSwaps); InvisibilitySettings = buf.ReadArray <InvisibleObject>(NumInvisibilitySettings); UsingAMultiScriptFile = buf.ReadBool(); PlayerHasMetDebbieHarry = buf.ReadBool(); buf.ReadUInt16(); MainScriptSize = buf.ReadInt32(); LargestMissionScriptSize = buf.ReadInt32(); NumberOfMissionScripts = buf.ReadInt16(); buf.ReadUInt16(); int runningScripts = buf.ReadInt32(); Threads = buf.ReadArray <RunningScript>(runningScripts, fmt); Debug.Assert(buf.Offset == size + SaveFileGTA3VC.BlockHeaderSize); Debug.Assert(size == SizeOfObject(this, fmt) - SaveFileGTA3VC.BlockHeaderSize); }
protected override void WriteData(DataBuffer buf, FileFormat fmt) { int size = SizeOfObject(this, fmt); SaveFileGTA3VC.WriteBlockHeader(buf, "SCR", size - SaveFileGTA3VC.BlockHeaderSize); buf.Write(Globals.Count * sizeof(int)); buf.Write(Globals); buf.Align4(); buf.Write(ScriptDataSize); buf.Write(OnAMissionFlag); buf.Write(LastMissionPassedTime); buf.Write(BuildingSwaps, NumBuildingSwaps); buf.Write(InvisibilitySettings, NumInvisibilitySettings); buf.Write(UsingAMultiScriptFile); buf.Write(PlayerHasMetDebbieHarry); buf.Write((short)0); buf.Write(MainScriptSize); buf.Write(LargestMissionScriptSize); buf.Write(NumberOfMissionScripts); buf.Write((short)0); buf.Write(Threads.Count); buf.Write(Threads, fmt); Debug.Assert(buf.Offset == size); }
protected override void ReadData(DataBuffer buf, FileFormat fmt) { if (fmt.IsMobile) { SaveVersionNumber = buf.ReadInt32(); LastMissionPassedName = buf.ReadString(MaxMissionPassedNameLengthMobile, unicode: true); } else { LastMissionPassedName = buf.ReadString(MaxMissionPassedNameLength, unicode: true); TimeStamp = buf.ReadStruct <SystemTime>(); } SizeOfGameInBytes = buf.ReadInt32(); CurrLevel = (Level)buf.ReadInt32(); CameraPosition = buf.ReadStruct <Vector3>(); if (fmt.IsPC && fmt.IsSteam) { SteamMagicNumber = buf.ReadInt32(); } MillisecondsPerGameMinute = buf.ReadInt32(); LastClockTick = buf.ReadUInt32(); GameClockHours = (byte)buf.ReadInt32(); buf.Align4(); GameClockMinutes = (byte)buf.ReadInt32(); buf.Align4(); CurrPadMode = buf.ReadInt16(); buf.Align4(); TimeInMilliseconds = buf.ReadUInt32(); TimerTimeScale = buf.ReadFloat(); TimerTimeStep = buf.ReadFloat(); TimerTimeStepNonClipped = buf.ReadFloat(); FrameCounter = buf.ReadUInt32(); TimeStep = buf.ReadFloat(); FramesPerUpdate = buf.ReadFloat(); TimeScale = buf.ReadFloat(); OldWeatherType = (WeatherType)buf.ReadInt16(); buf.Align4(); NewWeatherType = (WeatherType)buf.ReadInt16(); buf.Align4(); ForcedWeatherType = (WeatherType)buf.ReadInt16(); buf.Align4(); WeatherInterpolation = buf.ReadFloat(); WeatherTypeInList = buf.ReadInt32(); CameraCarZoomIndicator = buf.ReadFloat(); CameraPedZoomIndicator = buf.ReadFloat(); CurrArea = (Interior)buf.ReadInt32(); AllTaxisHaveNitro = buf.ReadBool(); buf.Align4(); InvertLook4Pad = buf.ReadBool(); buf.Align4(); ExtraColour = buf.ReadInt32(); ExtraColourOn = buf.ReadBool(4); ExtraColourInterpolation = buf.ReadFloat(); RadioStationPositionList = buf.ReadArray <int>(RadioStationListCount); Debug.Assert(buf.Offset == GetSize(fmt)); }
protected override void WriteData(DataBuffer buf, FileFormat fmt) { if (fmt.IsMobile) { buf.Write(SaveVersionNumber); buf.Write(LastMissionPassedName, MaxMissionPassedNameLengthMobile, unicode: true); } else { buf.Write(LastMissionPassedName, MaxMissionPassedNameLength, unicode: true); buf.Write(TimeStamp); } buf.Write(SizeOfGameInBytes); buf.Write((int)CurrLevel); buf.Write(CameraPosition); if (fmt.IsPC && fmt.IsSteam) { buf.Write(SteamMagicNumber); } buf.Write(MillisecondsPerGameMinute); buf.Write(LastClockTick); buf.Write(GameClockHours); buf.Align4(); buf.Write(GameClockMinutes); buf.Align4(); buf.Write(CurrPadMode); buf.Align4(); buf.Write(TimeInMilliseconds); buf.Write(TimerTimeScale); buf.Write(TimerTimeStep); buf.Write(TimerTimeStepNonClipped); buf.Write(FrameCounter); buf.Write(TimeStep); buf.Write(FramesPerUpdate); buf.Write(TimeScale); buf.Write((short)OldWeatherType); buf.Align4(); buf.Write((short)NewWeatherType); buf.Align4(); buf.Write((short)ForcedWeatherType); buf.Align4(); buf.Write(WeatherInterpolation); buf.Write(WeatherTypeInList); buf.Write(CameraCarZoomIndicator); buf.Write(CameraPedZoomIndicator); buf.Write((int)CurrArea); buf.Write(AllTaxisHaveNitro); buf.Align4(); buf.Write(InvertLook4Pad); buf.Align4(); buf.Write(ExtraColour); buf.Write(ExtraColourOn, 4); buf.Write(ExtraColourInterpolation); buf.Write(RadioStationPositionList, RadioStationListCount); Debug.Assert(buf.Offset == GetSize(fmt)); }
protected override int GetSize(FileFormat fmt) { return(SizeOfType <RunningScript>(fmt) * Threads.Count + DataBuffer.Align4(ScriptSpace.Count) + ScriptDataSize + SaveFileGTA3VC.BlockHeaderSize + 3 * sizeof(int)); }
protected override void WriteData(DataBuffer buf, FileFormat fmt) { buf.Write(VehicleModel); buf.Write(PedModelOverride); buf.Align4(); buf.Write((int)Weapon1); buf.Write((int)Weapon2); Debug.Assert(buf.Offset == SizeOfType <Gang>()); }
protected override void ReadData(DataBuffer buf, FileFormat fmt) { VehicleModel = buf.ReadInt32(); PedModelOverride = buf.ReadSByte(); buf.Align4(); Weapon1 = (WeaponType)buf.ReadInt32(); Weapon2 = (WeaponType)buf.ReadInt32(); Debug.Assert(buf.Offset == SizeOfType <Gang>()); }
protected override void ReadData(DataBuffer buf, FileFormat fmt) { if (!fmt.IsPS2) { buf.Skip(4); } buf.Skip(48); Position = buf.ReadStruct <Vector3>(); buf.Skip(4); if (!(fmt.IsPS2 && fmt.IsJapanese)) { buf.Skip(8); } if (fmt.IsPS2 && !fmt.IsJapanese) { buf.Skip(24); } NextParticleObjectPointer = buf.ReadUInt32(); PrevParticleObjectPointer = buf.ReadUInt32(); ParticlePointer = buf.ReadUInt32(); Timer = buf.ReadUInt32(); Type = (ParticleObjectType)buf.ReadInt32(); ParticleType = (ParticleType)buf.ReadInt32(); NumEffectCycles = buf.ReadByte(); SkipFrames = buf.ReadByte(); buf.Align4(); FrameCounter = buf.ReadUInt16(); State = (ParticleObjectState)buf.ReadInt16(); Target = buf.ReadStruct <Vector3>(); Spread = buf.ReadFloat(); Size = buf.ReadFloat(); Color = buf.ReadUInt32(); DestroyWhenFar = buf.ReadBool(); CreationChance = buf.ReadSByte(); buf.Align4(); if (fmt.IsPS2) { Unknown = buf.ReadInt32(); } Debug.Assert(buf.Offset == SizeOfType <ParticleObject>(fmt)); }
protected override void WriteData(DataBuffer buf, FileFormat fmt) { if (!fmt.IsPS2) { buf.Skip(4); } buf.Skip(48); buf.Write(Position); buf.Skip(4); if (!(fmt.IsPS2 && fmt.IsJapanese)) { buf.Skip(8); } if (fmt.IsPS2 && !fmt.IsJapanese) { buf.Skip(24); } buf.Write(NextParticleObjectPointer); buf.Write(PrevParticleObjectPointer); buf.Write(ParticlePointer); buf.Write(Timer); buf.Write((int)Type); buf.Write((int)ParticleType); buf.Write(NumEffectCycles); buf.Write(SkipFrames); buf.Align4(); buf.Write(FrameCounter); buf.Write((short)State); buf.Write(Target); buf.Write(Spread); buf.Write(Size); buf.Write(Color); buf.Write(DestroyWhenFar); buf.Write(CreationChance); buf.Align4(); if (fmt.IsPS2) { buf.Write(Unknown); } Debug.Assert(buf.Offset == SizeOfType <ParticleObject>(fmt)); }
protected override void ReadData(DataBuffer buf, FileFormat fmt) { Position = buf.ReadStruct <Vector3>(); Messages = buf.ReadArray <uint>(MaxNumMessages); RepeatedMessageStartTime = buf.ReadUInt32(); Handle = buf.ReadInt32(); State = (PhoneState)buf.ReadUInt32(); VisibleToCam = buf.ReadBool(); buf.Align4(); Debug.Assert(buf.Offset == SizeOfType <Phone>()); }
protected override void WriteData(DataBuffer buf, FileFormat fmt) { buf.Write(Position); buf.Write(Messages, MaxNumMessages); buf.Write(RepeatedMessageStartTime); buf.Write(Handle); buf.Write((int)State); buf.Write(VisibleToCam); buf.Align4(); Debug.Assert(buf.Offset == SizeOfType <Phone>()); }
/// <summary> /// Loads an object from the buffer. /// </summary> protected int LoadObject <T>(T obj) where T : SaveDataObject { int size = WorkBuff.ReadInt32(); int bytesRead = Serializer.Read(obj, WorkBuff, FileFormat); WorkBuff.Align4(); Debug.WriteLine($"{typeof(T).Name}: {bytesRead} bytes read."); Debug.Assert(bytesRead <= DataBuffer.Align4(size)); return(bytesRead); }
private int WriteDataBlock <T>(DataBuffer file, string tag, T obj) where T : SaveDataObject { int size = SerializeData(obj, out byte[] data); int sizeAligned = Align4(size); file.Mark(); file.Write(tag, length: 4, zeroTerminate: false); file.Write(size); file.Write(data); file.Align4(); Debug.Assert(file.Offset == sizeAligned + 8); m_checkSum += file.GetBytesFromMark().Sum(x => x); return(size + 8); }
private void LoadWorkBuffer() { int count; count = m_bufferSize; if (m_file.Position + count > m_file.Length) { count = m_file.Length - m_file.Position; } if (count != 0 && count == DataBuffer.Align4(count)) { m_workBuffer.Reset(); m_workBuffer.Write(m_file.ReadBytes(count)); m_workBuffer.Reset(); } }
private int ReadDummyBlock(DataBuffer file, string tag, out Dummy obj) { file.Mark(); string savedTag = file.ReadString(4); Debug.Assert(savedTag == tag); int size = file.ReadInt32(); Debug.Assert(file.Position + size <= file.Length); obj = new Dummy(size); Serializer.Read(obj, file, FileFormat); file.Align4(); return(file.Offset); }
private int ReadDataBlock <T>(DataBuffer file, string tag, out T obj) where T : SaveDataObject, new() { file.Mark(); string savedTag = file.ReadString(4); Debug.Assert(savedTag == tag); int size = file.ReadInt32(); Debug.Assert(file.Position + size < file.Length); obj = file.ReadObject <T>(FileFormat); file.Align4(); return(file.Offset); }
/// <summary> /// Allocates the required space for the specified type, /// then loads in an instance of that type. /// </summary> protected T LoadTypePreAlloc <T>() where T : SaveDataObject { int size = WorkBuff.ReadInt32(); if (!(Activator.CreateInstance(typeof(T), size) is T obj)) { throw new SerializationException(Strings.Error_Serialization_NoPreAlloc, typeof(T)); } Debug.WriteLine($"{typeof(T).Name}: {size} bytes pre-allocated."); int bytesRead = Serializer.Read(obj, WorkBuff, FileFormat); WorkBuff.Align4(); Debug.WriteLine($"{typeof(T).Name}: {bytesRead} bytes read."); Debug.Assert(bytesRead <= DataBuffer.Align4(size)); return(obj); }
/// <summary> /// Reads a block of data from the file into the work buffer. /// </summary> protected int ReadBlock(DataBuffer file) { file.Mark(); WorkBuff.Reset(); int size = file.ReadInt32(); if ((uint)size > WorkBuff.Length) { throw new SerializationException(Strings.Error_Serialization_BadBlockSize, (uint)size); } WorkBuff.Write(file.ReadBytes(size)); file.Align4(); Debug.Assert(file.Offset == size + 4); WorkBuff.Reset(); return(size); }
/// <summary> /// Writes a block of data from the work buffer into the file. /// </summary> protected int WriteBlock(DataBuffer file) { file.Mark(); byte[] data = WorkBuff.GetBytes(); int size = data.Length; file.Write(size); file.Write(data); file.Align4(); Debug.Assert(file.Offset == size + 4); CheckSum += file.GetBytesFromMark().Sum(x => x); WorkBuff.Reset(); // game code has a bug where the size of the 'size' itself is not // factored in to the total file size, so savefiles are always // 4 * numBlocks bytes larger than told by SizeOfGameInBytes return(size); }
protected override void WriteData(DataBuffer buf, FileFormat fmt) { if (!fmt.IsPS2) { buf.Write($"{LastMissionPassedName}\0", MaxMissionPassedNameLength, unicode: true, zeroTerminate: false); } if (fmt.IsPC || fmt.IsXbox) { buf.Write(TimeStamp); } buf.Write(SizeOfGameInBytes); buf.Write((int)CurrentLevel); buf.Write(CameraPosition); buf.Write(MillisecondsPerGameMinute); buf.Write(LastClockTick); buf.Write(GameClockHours); buf.Align4(); buf.Write(GameClockMinutes); buf.Align4(); buf.Write(CurrPadMode); buf.Align4(); buf.Write(TimeInMilliseconds); buf.Write(TimeScale); buf.Write(TimeStep); buf.Write(TimeStepNonClipped); buf.Write(FrameCounter); buf.Write(TimeStep2); buf.Write(FramesPerUpdate); buf.Write(TimeScale2); buf.Write((short)OldWeatherType); buf.Align4(); buf.Write((short)NewWeatherType); buf.Align4(); buf.Write((short)ForcedWeatherType); buf.Align4(); buf.Write(WeatherInterpolation); if (fmt.IsPS2) { buf.Write(MusicVolume); buf.Write(SfxVolume); if (!fmt.IsAustralian) { buf.Write(CurrPadMode); buf.Align4(); } buf.Write(UseVibration); buf.Align4(); buf.Write(StereoOutput); buf.Align4(); buf.Write((byte)RadioStation); buf.Align4(); buf.Write(Brightness); if (!fmt.IsAustralian) { buf.Write(BlurOn); buf.Align4(); } buf.Write(ShowSubtitles); buf.Align4(); buf.Write((int)Language); buf.Write(UseWideScreen); buf.Align4(); buf.Write(CurrPadMode); buf.Align4(); buf.Write(BlurOn); buf.Align4(); } buf.Write(CompileDateAndTime.Second); buf.Write(CompileDateAndTime.Minute); buf.Write(CompileDateAndTime.Hour); buf.Write(CompileDateAndTime.Day); buf.Write(CompileDateAndTime.Month); buf.Write(CompileDateAndTime.Year); buf.Write(WeatherTypeInList); buf.Write(CameraModeInCar); buf.Write(CameraModeOnFoot); if (fmt.IsMobile) { buf.Write((int)IsQuickSave); } Debug.Assert(buf.Offset == GetSize(fmt)); }
protected override void ReadData(DataBuffer buf, FileFormat fmt) { if (!fmt.IsPS2) { LastMissionPassedName = buf.ReadString(MaxMissionPassedNameLength, unicode: true); } if (fmt.IsPC || fmt.IsXbox) { TimeStamp = buf.ReadStruct <SystemTime>(); } SizeOfGameInBytes = buf.ReadInt32(); CurrentLevel = (Level)buf.ReadInt32(); CameraPosition = buf.ReadStruct <Vector3>(); MillisecondsPerGameMinute = buf.ReadInt32(); LastClockTick = buf.ReadUInt32(); GameClockHours = (byte)buf.ReadInt32(); buf.Align4(); GameClockMinutes = (byte)buf.ReadInt32(); buf.Align4(); CurrPadMode = buf.ReadInt16(); buf.Align4(); TimeInMilliseconds = buf.ReadUInt32(); TimeScale = buf.ReadFloat(); TimeStep = buf.ReadFloat(); TimeStepNonClipped = buf.ReadFloat(); FrameCounter = buf.ReadUInt32(); TimeStep2 = buf.ReadFloat(); FramesPerUpdate = buf.ReadFloat(); TimeScale2 = buf.ReadFloat(); OldWeatherType = (WeatherType)buf.ReadInt16(); buf.Align4(); NewWeatherType = (WeatherType)buf.ReadInt16(); buf.Align4(); ForcedWeatherType = (WeatherType)buf.ReadInt16(); buf.Align4(); WeatherInterpolation = buf.ReadFloat(); if (fmt.IsPS2) { MusicVolume = buf.ReadInt32(); SfxVolume = buf.ReadInt32(); if (!fmt.IsAustralian) { buf.ReadInt16(); // duplicate of CurrPadMode buf.Align4(); } UseVibration = buf.ReadBool(); buf.Align4(); StereoOutput = buf.ReadBool(); buf.Align4(); RadioStation = (RadioStation)buf.ReadByte(); buf.Align4(); Brightness = buf.ReadInt32(); if (!fmt.IsAustralian) { buf.ReadBool(); // duplicate of BlurOn buf.Align4(); } ShowSubtitles = buf.ReadBool(); buf.Align4(); Language = (Language)buf.ReadInt32(); UseWideScreen = buf.ReadBool(); buf.Align4(); buf.ReadInt16(); // duplicate of CurrPadMode buf.Align4(); BlurOn = buf.ReadBool(); buf.Align4(); } CompileDateAndTime = buf.ReadStruct <Date>(); WeatherTypeInList = buf.ReadInt32(); CameraModeInCar = buf.ReadFloat(); CameraModeOnFoot = buf.ReadFloat(); if (fmt.IsMobile) { IsQuickSave = (QuickSaveState)buf.ReadInt32(); } Debug.Assert(buf.Offset == GetSize(fmt)); }
protected override void WriteData(DataBuffer buf, FileFormat fmt) { buf.Write(VersionId); buf.Write(LastMissionPassedName, MaxNameLength); buf.Write(MissionPackGame); buf.Align4(); buf.Write((int)CurrLevel); buf.Write(CameraPosition); buf.Write(MillisecondsPerGameMinute); buf.Write(LastClockTick); buf.Write(GameClockMonths); buf.Write(GameClockDays); buf.Write(GameClockHours); buf.Write(GameClockMinutes); buf.Write(GameClockDayOfWeek); buf.Write(StoredGameClockMonths); buf.Write(StoredGameClockDays); buf.Write(StoredGameClockHours); buf.Write(StoredGameClockMinutes); buf.Write(ClockHasBeenStored); buf.Write(CurrPadMode); buf.Write(HasPlayerCheated); buf.Align4(); buf.Write(TimeInMilliseconds); buf.Write(TimeScale); buf.Write(TimeStep); buf.Write(TimeStepNonClipped); buf.Write(FrameCounter); buf.Write((short)OldWeatherType); buf.Write((short)NewWeatherType); buf.Write((short)ForcedWeatherType); buf.Align4(); buf.Write(WeatherInterpolation); buf.Write(WeatherTypeInList); buf.Write(Rain); buf.Write(CameraCarZoomIndicator); buf.Write(CameraPedZoomIndicator); buf.Write(CurrArea); buf.Write(InvertLook4Pad); buf.Align4(); buf.Write(ExtraColour); buf.Write(ExtraColourOn); buf.Align4(); buf.Write(ExtraColourInterpolation); buf.Write((int)ExtraColourWeatherType); buf.Write(WaterConfiguration); buf.Write(LARiots); buf.Write(LARiotsNoPoliceCars); buf.Align4(); buf.Write(MaximumWantedLevel); buf.Write(MaximumChaosLevel); buf.Write(GermanGame); buf.Write(FrenchGame); buf.Write(NastyGame); buf.Align4(); buf.Skip(0x2C); buf.Write(CinematicCamMessagesLeftToDisplay); buf.Skip(1); // Android: BlurOn buf.Write(TimeLastSaved); buf.Align4(); buf.Write(TargetMarkerHandle); buf.Write(HasDisplayedPlayerQuitEnterCarHelpText); buf.Write(AllTaxisHaveNitro); buf.Write(ProstiutesPayYou); buf.Align4(); Debug.Assert(buf.Offset == GetSize(fmt)); }
protected override void ReadData(DataBuffer buf, FileFormat fmt) { VersionId = buf.ReadUInt32(); LastMissionPassedName = buf.ReadString(MaxNameLength); MissionPackGame = buf.ReadByte(); buf.Align4(); CurrLevel = (LevelType)buf.ReadInt32(); CameraPosition = buf.ReadStruct <Vector3>(); MillisecondsPerGameMinute = buf.ReadInt32(); LastClockTick = buf.ReadUInt32(); GameClockMonths = buf.ReadByte(); GameClockDays = buf.ReadByte(); GameClockHours = buf.ReadByte(); GameClockMinutes = buf.ReadByte(); GameClockDayOfWeek = buf.ReadByte(); StoredGameClockMonths = buf.ReadByte(); StoredGameClockDays = buf.ReadByte(); StoredGameClockHours = buf.ReadByte(); StoredGameClockMinutes = buf.ReadByte(); ClockHasBeenStored = buf.ReadBool(); CurrPadMode = buf.ReadInt16(); HasPlayerCheated = buf.ReadBool(); buf.Align4(); TimeInMilliseconds = buf.ReadUInt32(); TimeScale = buf.ReadFloat(); TimeStep = buf.ReadFloat(); TimeStepNonClipped = buf.ReadFloat(); FrameCounter = buf.ReadUInt32(); OldWeatherType = (WeatherType)buf.ReadInt16(); NewWeatherType = (WeatherType)buf.ReadInt16(); ForcedWeatherType = (WeatherType)buf.ReadInt16(); buf.Align4(); WeatherInterpolation = buf.ReadFloat(); WeatherTypeInList = buf.ReadInt32(); Rain = buf.ReadFloat(); CameraCarZoomIndicator = buf.ReadInt32(); CameraPedZoomIndicator = buf.ReadInt32(); CurrArea = buf.ReadInt32(); InvertLook4Pad = buf.ReadBool(); buf.Align4(); ExtraColour = buf.ReadInt32(); ExtraColourOn = buf.ReadBool(); buf.Align4(); ExtraColourInterpolation = buf.ReadFloat(); ExtraColourWeatherType = (WeatherType)buf.ReadInt32(); WaterConfiguration = buf.ReadInt32(); LARiots = buf.ReadBool(); LARiotsNoPoliceCars = buf.ReadBool(); buf.Align4(); MaximumWantedLevel = buf.ReadInt32(); MaximumChaosLevel = buf.ReadInt32(); GermanGame = buf.ReadBool(); FrenchGame = buf.ReadBool(); NastyGame = buf.ReadBool(); buf.Align4(); buf.Skip(0x2C); CinematicCamMessagesLeftToDisplay = buf.ReadByte(); buf.Skip(1); // Android: BlurOn TimeLastSaved = buf.ReadStruct <SystemTime>(); buf.Align4(); TargetMarkerHandle = buf.ReadInt32(); HasDisplayedPlayerQuitEnterCarHelpText = buf.ReadBool(); AllTaxisHaveNitro = buf.ReadBool(); ProstiutesPayYou = buf.ReadBool(); buf.Align4(); Debug.Assert(buf.Offset == GetSize(fmt)); }
protected override bool DetectFileFormat(byte[] data, out FileFormat fmt) { // TODO: PS2, Xbox bool isMobile = false; int saveSizeOffset = data.FindFirst(BitConverter.GetBytes(DataSize + 1)); int saveSizeOffsetJP = data.FindFirst(BitConverter.GetBytes(DataSize)); int scrOffset = data.FindFirst("SCR\0".GetAsciiBytes()); if ((saveSizeOffset < 0 && saveSizeOffsetJP < 0) || scrOffset < 0) { goto DetectionFailed; } if (saveSizeOffset == 0x40) { isMobile = true; } else if (saveSizeOffset == 0x44) { if (scrOffset == 0xEC) { fmt = FileFormats.PC; return(true); } else if (scrOffset == 0xF0) { fmt = FileFormats.PC_Steam; return(true); } } int sizeOfPlayerPed; using (DataBuffer s = new DataBuffer(data)) { int block0Size = s.ReadInt32(); if (block0Size > s.Length) { goto DetectionFailed; } s.Skip(block0Size + sizeof(int)); int sizeOfPedPool = DataBuffer.Align4(s.ReadInt32() - sizeof(int)); int numPlayerPeds = s.ReadInt32(); sizeOfPlayerPed = sizeOfPedPool / numPlayerPeds; } if (isMobile) { if (sizeOfPlayerPed == 0x754) { fmt = FileFormats.iOS; return(true); } else if (sizeOfPlayerPed == 0x75C) { fmt = FileFormats.Android; return(true); } } DetectionFailed: fmt = FileFormat.Default; return(false); }