public void Save(IDiskImage di) { if (RawData == null) { throw new InvalidOperationException("Cannot save a file without loading one first."); } RawData[SexOffset] = (byte)Sex; RawData[ClassOffset] = (byte)Class; RawData[RaceOffset] = (byte)Race; RawData[HitPointsOffset] = (byte)(HitPoints & 0x00ff); RawData[HitPointsOffset + 1] = (byte)(HitPoints >> 8); RawData[ExperienceOffset] = (byte)(Experience & 0x00ff); RawData[ExperienceOffset + 1] = (byte)(Experience >> 8); RawData[StrengthOffset] = (byte)Strength; RawData[AgilityOffset] = (byte)Agility; RawData[StaminaOffset] = (byte)Stamina; RawData[CharismaOffset] = (byte)Charisma; RawData[WisdomOffset] = (byte)Wisdom; RawData[IntelligenceOffset] = (byte)Intelligence; for (int i = 0; i < 10; ++i) { RawData[SpellsOffset + i] = (byte)Spells[i]; } for (int i = 0; i < 5; ++i) { RawData[ArmorOffset + i] = (byte)Armor[i]; } for (int i = 0; i < 15; ++i) { RawData[WeaponsOffset + i] = (byte)Weapons[i]; } RawData[FoodOffset] = (byte)(Food & 0x00ff); RawData[FoodOffset + 1] = (byte)(Food >> 8); RawData[CoinsOffset] = (byte)(Coins & 0x00ff); RawData[CoinsOffset + 1] = (byte)(Coins >> 8); for (int i = 0; i < 4; ++i) { RawData[GemsOffset + i] = (byte)Gems[i]; } RawData[EnemyShipsOffset] = (byte)EnemyShips; RawData[LocationOffset] = (byte)Location.X; RawData[LocationOffset + 1] = (byte)Location.Y; IImageFile image = di.Open("P" + RosterId, C64FileType.PRG, "wb"); if (image == null) { throw new System.IO.FileLoadException("Cannot open save file 'P" + RosterId + ".PRG' for write."); } int len = image.Write(RawData, RawData.Length); if (len != RawData.Length) { throw new System.IO.IOException("There was an error writing file 'P" + RosterId + ".PRG'."); } image.Close(); }
public void Load(IDiskImage di, int rosterNumber) { byte[] buffer = new byte[200000]; // they seem to be 460 bytes, but screw it better safe than sorry. IImageFile image = di.Open("P" + rosterNumber, C64FileType.PRG, "rb"); if (image == null) { throw new System.IO.FileLoadException("Cannot open save file 'P" + RosterId + ".PRG' for read."); } int len = image.Read(buffer, buffer.Length); RawData = new byte[len]; Buffer.BlockCopy(buffer, 0, RawData, 0, len); image.Close(); RosterId = rosterNumber; m_name = ProcessName(); Sex = (U1Sex)RawData[SexOffset]; Class = (U1Class)RawData[ClassOffset]; Race = (U1Race)RawData[RaceOffset]; HitPoints = RawData[HitPointsOffset] | (RawData[HitPointsOffset + 1] << 8); Experience = RawData[ExperienceOffset] | (RawData[ExperienceOffset + 1] << 8); Strength = RawData[StrengthOffset]; Agility = RawData[AgilityOffset]; Stamina = RawData[StaminaOffset]; Charisma = RawData[CharismaOffset]; Wisdom = RawData[WisdomOffset]; Intelligence = RawData[IntelligenceOffset]; for (int i = 0; i < 10; ++i) { Spells[i] = RawData[SpellsOffset + i]; } for (int i = 0; i < 5; ++i) { Armor[i] = RawData[ArmorOffset + i]; } for (int i = 0; i < 15; ++i) { Weapons[i] = RawData[WeaponsOffset + i]; } Food = RawData[FoodOffset] | (RawData[FoodOffset + 1] << 8); Coins = RawData[CoinsOffset] | (RawData[CoinsOffset + 1] << 8); for (int i = 0; i < 4; ++i) { Gems[i] = RawData[GemsOffset + i]; } for (int i = 0; i < 6; ++i) { m_transportation[i] = RawData[TransportationOffset + i]; } m_transportation[6] = RawData[TimeMachineOffset]; EnemyShips = RawData[EnemyShipsOffset]; Location.X = RawData[LocationOffset]; Location.Y = RawData[LocationOffset + 1]; }