123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using MaidStatus.Old;
- namespace MaidStatus
- {
- public class OldDataConverter
- {
- public string saveTime { get; private set; }
- public int gameDay { get; private set; }
- public string playerName { get; private set; }
- public int maidCount { get; private set; }
- public string userComment { get; private set; }
- public int days { get; private set; }
- public List<OldDataConverter.MaidData> OpenFile(string filePath)
- {
- NDebug.Assert(File.Exists(filePath), "ファイルを開けません。" + filePath);
- List<OldDataConverter.MaidData> list = new List<OldDataConverter.MaidData>();
- using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
- {
- using (BinaryReader binaryReader = new BinaryReader(fileStream))
- {
- string a = binaryReader.ReadString();
- NDebug.Assert(a == "CM3D2_SAVE", "セーブデータファイルのヘッダーが不正です。_SAVE 3");
- binaryReader.ReadInt32();
- this.saveTime = binaryReader.ReadString();
- this.gameDay = binaryReader.ReadInt32();
- this.playerName = binaryReader.ReadString();
- this.maidCount = binaryReader.ReadInt32();
- this.userComment = binaryReader.ReadString();
- a = binaryReader.ReadString();
- NDebug.Assert(a == "CM3D2_CHR_MGR", "セーブデータファイルのヘッダーが不正です。_CHR_MGR 2");
- binaryReader.ReadInt32();
- this.days = this.ReadOnPlayerParam(binaryReader);
- int num = binaryReader.ReadInt32();
- for (int i = 0; i < num; i++)
- {
- this.ReadOnMaidProp(binaryReader);
- this.ReadOnMaidMisc(binaryReader);
- }
- int num2 = binaryReader.ReadInt32();
- for (int j = 0; j < num2; j++)
- {
- long num3 = fileStream.Seek(0L, SeekOrigin.Current);
- this.ReadOnMaidProp(binaryReader);
- this.ReadOnMultiColor(binaryReader);
- int appearanceByteSize = (int)(fileStream.Seek(0L, SeekOrigin.Current) - num3);
- StatusReader statusReader = new StatusReader(binaryReader, this.days);
- KeyValuePair<long, int> keyValuePair = this.ReadOnMaidMisc(binaryReader);
- OldDataConverter.MaidData item = new OldDataConverter.MaidData(filePath, statusReader, num3, appearanceByteSize, keyValuePair.Key, keyValuePair.Value);
- list.Add(item);
- }
- }
- }
- return list;
- }
- private int ReadOnPlayerParam(BinaryReader reader)
- {
- string a = reader.ReadString();
- NDebug.Assert(a == "CM3D2_PPARAM", "主人公パラメータのヘッダーが不正です。");
- int num = reader.ReadInt32();
- reader.ReadString();
- reader.ReadInt32();
- reader.ReadInt32();
- int result = reader.ReadInt32();
- reader.ReadInt64();
- reader.ReadInt64();
- if (num > 8)
- {
- reader.ReadInt64();
- }
- reader.ReadInt64();
- reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadInt32();
- if (num > 5)
- {
- reader.ReadBoolean();
- }
- reader.ReadInt32();
- reader.ReadInt32();
- for (int i = 0; i < 6; i++)
- {
- reader.ReadString();
- reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadBoolean();
- this.ReadOnDirectoryStringAndInt32(reader);
- }
- this.ReadOnDirectoryStringAndInt32(reader);
- int num2 = reader.ReadInt32();
- for (int j = 0; j < num2; j++)
- {
- reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadString();
- reader.ReadBoolean();
- }
- this.ReadOnDirectoryInt32AndInt32(reader);
- this.ReadOnDirectoryStringAndBool(reader);
- this.ReadOnListInt32(reader);
- if (num > 9)
- {
- this.ReadOnListInt32(reader);
- this.ReadOnListInt32(reader);
- }
- if (117 <= num)
- {
- num2 = reader.ReadInt32();
- for (int k = 0; k < num2; k++)
- {
- reader.ReadString();
- reader.ReadString();
- reader.ReadInt32();
- this.ReadOnDirectoryStringAndInt32(reader);
- }
- }
- int num3 = reader.ReadInt32();
- NDebug.Assert(348195810 == num3, "主人公パラメータのロードに失敗しました");
- return result;
- }
- private void ReadOnMaidProp(BinaryReader reader)
- {
- string a = reader.ReadString();
- NDebug.Assert(a == "CM3D2_MPROP_LIST", "メイドプロパティリストのヘッダーが不正です。");
- int num = reader.ReadInt32();
- int num2 = reader.ReadInt32();
- for (int i = 0; i < num2; i++)
- {
- reader.ReadString();
- reader.ReadString();
- int num3 = reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadString();
- reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadInt32();
- if (101 <= num3)
- {
- reader.ReadInt32();
- }
- reader.ReadInt32();
- reader.ReadString();
- reader.ReadInt32();
- reader.ReadBoolean();
- reader.ReadInt32();
- reader.ReadInt32();
- }
- }
- private void ReadOnMultiColor(BinaryReader reader)
- {
- string a = reader.ReadString();
- NDebug.Assert(a == "CM3D2_MULTI_COL", "無限色のヘッダーが不正です。");
- reader.ReadInt32();
- int num = reader.ReadInt32();
- for (int i = 0; i < num; i++)
- {
- reader.ReadBoolean();
- reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadInt32();
- reader.ReadInt32();
- }
- }
- private KeyValuePair<long, int> ReadOnMaidMisc(BinaryReader reader)
- {
- string a = reader.ReadString();
- NDebug.Assert(a == "CM3D2_MAID_MISC", "メイドMiscのヘッダーが不正です。");
- int num = reader.ReadInt32();
- reader.ReadInt32();
- int num2 = reader.ReadInt32();
- long key = reader.BaseStream.Seek(0L, SeekOrigin.Current);
- if (num2 != 0)
- {
- reader.ReadBytes(num2);
- }
- if (8 <= num)
- {
- reader.ReadString();
- }
- reader.ReadSingle();
- reader.ReadSingle();
- reader.ReadSingle();
- reader.ReadSingle();
- return new KeyValuePair<long, int>(key, num2);
- }
- private void ReadOnListInt32(BinaryReader reader)
- {
- int num = reader.ReadInt32();
- for (int i = 0; i < num; i++)
- {
- reader.ReadInt32();
- }
- }
- private void ReadOnDirectoryStringAndInt32(BinaryReader reader)
- {
- int num = reader.ReadInt32();
- for (int i = 0; i < num; i++)
- {
- reader.ReadString();
- reader.ReadInt32();
- }
- }
- private void ReadOnDirectoryStringAndString(BinaryReader reader)
- {
- int num = reader.ReadInt32();
- for (int i = 0; i < num; i++)
- {
- reader.ReadString();
- reader.ReadInt32();
- }
- }
- private void ReadOnDirectoryInt32AndInt32(BinaryReader reader)
- {
- int num = reader.ReadInt32();
- for (int i = 0; i < num; i++)
- {
- reader.ReadInt32();
- reader.ReadInt32();
- }
- }
- private void ReadOnDirectoryStringAndBool(BinaryReader reader)
- {
- int num = reader.ReadInt32();
- for (int i = 0; i < num; i++)
- {
- reader.ReadString();
- reader.ReadBoolean();
- }
- }
- public class MaidData
- {
- public MaidData(string saveFilePath, StatusReader statusReader, long appearanceBytePos, int appearanceByteSize, long thumbnailBytePos, int thumbnailByteSize)
- {
- this.saveFilePath = saveFilePath;
- this.statusReader = statusReader;
- this.appearanceBytePos = appearanceBytePos;
- this.appearanceByteSize = appearanceByteSize;
- this.thumbnailBytePos = thumbnailBytePos;
- this.thumbnailByteSize = thumbnailByteSize;
- }
- public byte[] ReadAppearanceByte()
- {
- byte[] result = null;
- using (FileStream fileStream = new FileStream(this.saveFilePath, FileMode.Open))
- {
- using (BinaryReader binaryReader = new BinaryReader(fileStream))
- {
- long offset = binaryReader.BaseStream.Seek(0L, SeekOrigin.Current);
- binaryReader.BaseStream.Seek(this.appearanceBytePos, SeekOrigin.Begin);
- result = binaryReader.ReadBytes(this.appearanceByteSize);
- binaryReader.BaseStream.Seek(offset, SeekOrigin.Begin);
- }
- }
- return result;
- }
- public byte[] ReadThumbnailByte()
- {
- byte[] result = null;
- using (FileStream fileStream = new FileStream(this.saveFilePath, FileMode.Open))
- {
- using (BinaryReader binaryReader = new BinaryReader(fileStream))
- {
- long offset = binaryReader.BaseStream.Seek(0L, SeekOrigin.Current);
- binaryReader.BaseStream.Seek(this.thumbnailBytePos, SeekOrigin.Begin);
- result = binaryReader.ReadBytes(this.thumbnailByteSize);
- binaryReader.BaseStream.Seek(offset, SeekOrigin.Begin);
- }
- }
- return result;
- }
- public readonly StatusReader statusReader;
- public readonly string saveFilePath;
- private long appearanceBytePos;
- private int appearanceByteSize;
- private long thumbnailBytePos;
- private int thumbnailByteSize;
- }
- }
- }
|