OldDataConverter.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using MaidStatus.Old;
  5. namespace MaidStatus
  6. {
  7. public class OldDataConverter
  8. {
  9. public string saveTime { get; private set; }
  10. public int gameDay { get; private set; }
  11. public string playerName { get; private set; }
  12. public int maidCount { get; private set; }
  13. public string userComment { get; private set; }
  14. public int days { get; private set; }
  15. public List<OldDataConverter.MaidData> OpenFile(string filePath)
  16. {
  17. NDebug.Assert(File.Exists(filePath), "ファイルを開けません。" + filePath);
  18. List<OldDataConverter.MaidData> list = new List<OldDataConverter.MaidData>();
  19. using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
  20. {
  21. using (BinaryReader binaryReader = new BinaryReader(fileStream))
  22. {
  23. string a = binaryReader.ReadString();
  24. NDebug.Assert(a == "CM3D2_SAVE", "セーブデータファイルのヘッダーが不正です。_SAVE 3");
  25. binaryReader.ReadInt32();
  26. this.saveTime = binaryReader.ReadString();
  27. this.gameDay = binaryReader.ReadInt32();
  28. this.playerName = binaryReader.ReadString();
  29. this.maidCount = binaryReader.ReadInt32();
  30. this.userComment = binaryReader.ReadString();
  31. a = binaryReader.ReadString();
  32. NDebug.Assert(a == "CM3D2_CHR_MGR", "セーブデータファイルのヘッダーが不正です。_CHR_MGR 2");
  33. binaryReader.ReadInt32();
  34. this.days = this.ReadOnPlayerParam(binaryReader);
  35. int num = binaryReader.ReadInt32();
  36. for (int i = 0; i < num; i++)
  37. {
  38. this.ReadOnMaidProp(binaryReader);
  39. this.ReadOnMaidMisc(binaryReader);
  40. }
  41. int num2 = binaryReader.ReadInt32();
  42. for (int j = 0; j < num2; j++)
  43. {
  44. long num3 = fileStream.Seek(0L, SeekOrigin.Current);
  45. this.ReadOnMaidProp(binaryReader);
  46. this.ReadOnMultiColor(binaryReader);
  47. int appearanceByteSize = (int)(fileStream.Seek(0L, SeekOrigin.Current) - num3);
  48. StatusReader statusReader = new StatusReader(binaryReader, this.days);
  49. KeyValuePair<long, int> keyValuePair = this.ReadOnMaidMisc(binaryReader);
  50. OldDataConverter.MaidData item = new OldDataConverter.MaidData(filePath, statusReader, num3, appearanceByteSize, keyValuePair.Key, keyValuePair.Value);
  51. list.Add(item);
  52. }
  53. }
  54. }
  55. return list;
  56. }
  57. private int ReadOnPlayerParam(BinaryReader reader)
  58. {
  59. string a = reader.ReadString();
  60. NDebug.Assert(a == "CM3D2_PPARAM", "主人公パラメータのヘッダーが不正です。");
  61. int num = reader.ReadInt32();
  62. reader.ReadString();
  63. reader.ReadInt32();
  64. reader.ReadInt32();
  65. int result = reader.ReadInt32();
  66. reader.ReadInt64();
  67. reader.ReadInt64();
  68. if (num > 8)
  69. {
  70. reader.ReadInt64();
  71. }
  72. reader.ReadInt64();
  73. reader.ReadInt32();
  74. reader.ReadInt32();
  75. reader.ReadInt32();
  76. if (num > 5)
  77. {
  78. reader.ReadBoolean();
  79. }
  80. reader.ReadInt32();
  81. reader.ReadInt32();
  82. for (int i = 0; i < 6; i++)
  83. {
  84. reader.ReadString();
  85. reader.ReadInt32();
  86. reader.ReadInt32();
  87. reader.ReadBoolean();
  88. this.ReadOnDirectoryStringAndInt32(reader);
  89. }
  90. this.ReadOnDirectoryStringAndInt32(reader);
  91. int num2 = reader.ReadInt32();
  92. for (int j = 0; j < num2; j++)
  93. {
  94. reader.ReadInt32();
  95. reader.ReadInt32();
  96. reader.ReadString();
  97. reader.ReadBoolean();
  98. }
  99. this.ReadOnDirectoryInt32AndInt32(reader);
  100. this.ReadOnDirectoryStringAndBool(reader);
  101. this.ReadOnListInt32(reader);
  102. if (num > 9)
  103. {
  104. this.ReadOnListInt32(reader);
  105. this.ReadOnListInt32(reader);
  106. }
  107. if (117 <= num)
  108. {
  109. num2 = reader.ReadInt32();
  110. for (int k = 0; k < num2; k++)
  111. {
  112. reader.ReadString();
  113. reader.ReadString();
  114. reader.ReadInt32();
  115. this.ReadOnDirectoryStringAndInt32(reader);
  116. }
  117. }
  118. int num3 = reader.ReadInt32();
  119. NDebug.Assert(348195810 == num3, "主人公パラメータのロードに失敗しました");
  120. return result;
  121. }
  122. private void ReadOnMaidProp(BinaryReader reader)
  123. {
  124. string a = reader.ReadString();
  125. NDebug.Assert(a == "CM3D2_MPROP_LIST", "メイドプロパティリストのヘッダーが不正です。");
  126. int num = reader.ReadInt32();
  127. int num2 = reader.ReadInt32();
  128. for (int i = 0; i < num2; i++)
  129. {
  130. reader.ReadString();
  131. reader.ReadString();
  132. int num3 = reader.ReadInt32();
  133. reader.ReadInt32();
  134. reader.ReadString();
  135. reader.ReadInt32();
  136. reader.ReadInt32();
  137. reader.ReadInt32();
  138. if (101 <= num3)
  139. {
  140. reader.ReadInt32();
  141. }
  142. reader.ReadInt32();
  143. reader.ReadString();
  144. reader.ReadInt32();
  145. reader.ReadBoolean();
  146. reader.ReadInt32();
  147. reader.ReadInt32();
  148. }
  149. }
  150. private void ReadOnMultiColor(BinaryReader reader)
  151. {
  152. string a = reader.ReadString();
  153. NDebug.Assert(a == "CM3D2_MULTI_COL", "無限色のヘッダーが不正です。");
  154. reader.ReadInt32();
  155. int num = reader.ReadInt32();
  156. for (int i = 0; i < num; i++)
  157. {
  158. reader.ReadBoolean();
  159. reader.ReadInt32();
  160. reader.ReadInt32();
  161. reader.ReadInt32();
  162. reader.ReadInt32();
  163. reader.ReadInt32();
  164. reader.ReadInt32();
  165. reader.ReadInt32();
  166. reader.ReadInt32();
  167. reader.ReadInt32();
  168. }
  169. }
  170. private KeyValuePair<long, int> ReadOnMaidMisc(BinaryReader reader)
  171. {
  172. string a = reader.ReadString();
  173. NDebug.Assert(a == "CM3D2_MAID_MISC", "メイドMiscのヘッダーが不正です。");
  174. int num = reader.ReadInt32();
  175. reader.ReadInt32();
  176. int num2 = reader.ReadInt32();
  177. long key = reader.BaseStream.Seek(0L, SeekOrigin.Current);
  178. if (num2 != 0)
  179. {
  180. reader.ReadBytes(num2);
  181. }
  182. if (8 <= num)
  183. {
  184. reader.ReadString();
  185. }
  186. reader.ReadSingle();
  187. reader.ReadSingle();
  188. reader.ReadSingle();
  189. reader.ReadSingle();
  190. return new KeyValuePair<long, int>(key, num2);
  191. }
  192. private void ReadOnListInt32(BinaryReader reader)
  193. {
  194. int num = reader.ReadInt32();
  195. for (int i = 0; i < num; i++)
  196. {
  197. reader.ReadInt32();
  198. }
  199. }
  200. private void ReadOnDirectoryStringAndInt32(BinaryReader reader)
  201. {
  202. int num = reader.ReadInt32();
  203. for (int i = 0; i < num; i++)
  204. {
  205. reader.ReadString();
  206. reader.ReadInt32();
  207. }
  208. }
  209. private void ReadOnDirectoryStringAndString(BinaryReader reader)
  210. {
  211. int num = reader.ReadInt32();
  212. for (int i = 0; i < num; i++)
  213. {
  214. reader.ReadString();
  215. reader.ReadInt32();
  216. }
  217. }
  218. private void ReadOnDirectoryInt32AndInt32(BinaryReader reader)
  219. {
  220. int num = reader.ReadInt32();
  221. for (int i = 0; i < num; i++)
  222. {
  223. reader.ReadInt32();
  224. reader.ReadInt32();
  225. }
  226. }
  227. private void ReadOnDirectoryStringAndBool(BinaryReader reader)
  228. {
  229. int num = reader.ReadInt32();
  230. for (int i = 0; i < num; i++)
  231. {
  232. reader.ReadString();
  233. reader.ReadBoolean();
  234. }
  235. }
  236. public class MaidData
  237. {
  238. public MaidData(string saveFilePath, StatusReader statusReader, long appearanceBytePos, int appearanceByteSize, long thumbnailBytePos, int thumbnailByteSize)
  239. {
  240. this.saveFilePath = saveFilePath;
  241. this.statusReader = statusReader;
  242. this.appearanceBytePos = appearanceBytePos;
  243. this.appearanceByteSize = appearanceByteSize;
  244. this.thumbnailBytePos = thumbnailBytePos;
  245. this.thumbnailByteSize = thumbnailByteSize;
  246. }
  247. public byte[] ReadAppearanceByte()
  248. {
  249. byte[] result = null;
  250. using (FileStream fileStream = new FileStream(this.saveFilePath, FileMode.Open))
  251. {
  252. using (BinaryReader binaryReader = new BinaryReader(fileStream))
  253. {
  254. long offset = binaryReader.BaseStream.Seek(0L, SeekOrigin.Current);
  255. binaryReader.BaseStream.Seek(this.appearanceBytePos, SeekOrigin.Begin);
  256. result = binaryReader.ReadBytes(this.appearanceByteSize);
  257. binaryReader.BaseStream.Seek(offset, SeekOrigin.Begin);
  258. }
  259. }
  260. return result;
  261. }
  262. public byte[] ReadThumbnailByte()
  263. {
  264. byte[] result = null;
  265. using (FileStream fileStream = new FileStream(this.saveFilePath, FileMode.Open))
  266. {
  267. using (BinaryReader binaryReader = new BinaryReader(fileStream))
  268. {
  269. long offset = binaryReader.BaseStream.Seek(0L, SeekOrigin.Current);
  270. binaryReader.BaseStream.Seek(this.thumbnailBytePos, SeekOrigin.Begin);
  271. result = binaryReader.ReadBytes(this.thumbnailByteSize);
  272. binaryReader.BaseStream.Seek(offset, SeekOrigin.Begin);
  273. }
  274. }
  275. return result;
  276. }
  277. public readonly StatusReader statusReader;
  278. public readonly string saveFilePath;
  279. private long appearanceBytePos;
  280. private int appearanceByteSize;
  281. private long thumbnailBytePos;
  282. private int thumbnailByteSize;
  283. }
  284. }
  285. }