ScoutMaidData.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Edit;
  5. using MaidStatus;
  6. using MaidStatus.CsvData;
  7. using UnityEngine;
  8. using Yotogis;
  9. namespace scoutmode
  10. {
  11. public class ScoutMaidData : ICloneable
  12. {
  13. public static string GetThumbnailFilePath(string guid, bool temp)
  14. {
  15. return Path.Combine(Maid.ThumbnailDictionary, ((!temp) ? "_scout_" : "_scout_tmp_thum_") + guid + ".png");
  16. }
  17. public static string GetIconThumbnailFilePath(string guid, bool temp)
  18. {
  19. return Path.Combine(Maid.ThumbnailDictionary, ((!temp) ? "_scout_icon_thum_" : "_scout_tmp_icon_thum_") + guid + ".png");
  20. }
  21. public static string GetKasizukiThumbnailFilePath(string guid, bool temp)
  22. {
  23. return Path.Combine(Maid.ThumbnailDictionary, ((!temp) ? "_scout_kasizuki_" : "_scout_tmp_kasizuki_") + guid + ".png");
  24. }
  25. public ScoutMaidData.SimpleStatus status { get; private set; }
  26. public byte[] iconImageBinary { get; private set; }
  27. public byte[] pressetBinary { get; private set; }
  28. public byte[] statusBinary { get; private set; }
  29. public ScoutMaidOverrideData overrideData { get; private set; }
  30. public ScoutInstanceData instanceData { get; private set; }
  31. public bool isOverRideData
  32. {
  33. get
  34. {
  35. return this.overrideData.enabled;
  36. }
  37. }
  38. public void CreateData(Maid maid)
  39. {
  40. Status status = maid.status;
  41. this.pressetBinary = GameMain.Instance.CharacterMgr.PresetSaveNotWriteFile(maid, CharacterMgr.PresetType.All);
  42. MemoryStream memoryStream = new MemoryStream();
  43. BinaryWriter binary = new BinaryWriter(memoryStream);
  44. status.isScoutMaid = true;
  45. status.Serialize(binary);
  46. status.isScoutMaid = false;
  47. this.statusBinary = memoryStream.ToArray();
  48. this.iconImageBinary = maid.GetThumIcon().EncodeToPNG();
  49. this.status = new ScoutMaidData.SimpleStatus();
  50. this.status.guid = status.guid;
  51. this.status.creationTimeNum = status.creationTimeNum;
  52. NamePair charaName = status.charaName;
  53. this.status.name1 = charaName.name1;
  54. this.status.name2 = charaName.name2;
  55. this.status.personalId = status.personal.id;
  56. this.status.initSeikeiken = status.initSeikeiken;
  57. this.status.seikeiken = status.seikeiken;
  58. this.status.height = status.body.height;
  59. this.status.weight = status.body.weight;
  60. this.status.bust = status.body.bust;
  61. this.status.waist = status.body.waist;
  62. this.status.hip = status.body.hip;
  63. this.status.cup = status.body.cup;
  64. this.status.lovely = status.lovely;
  65. this.status.elegance = status.elegance;
  66. this.status.charm = status.charm;
  67. this.status.care = status.care;
  68. this.status.reception = status.reception;
  69. this.status.cooking = status.cooking;
  70. this.status.dance = status.dance;
  71. this.status.vocal = status.vocal;
  72. this.status.teachRate = status.teachRate;
  73. this.status.studyRate = status.studyRate;
  74. this.status.maxHp = status.maxHp;
  75. this.status.maxMind = status.maxMind;
  76. this.status.inyoku = status.inyoku;
  77. this.status.mvalue = status.mvalue;
  78. this.status.hentai = status.hentai;
  79. this.status.housi = status.housi;
  80. this.status.maidPoint = GameMain.Instance.CharacterMgr.status.maidPoint;
  81. this.status.playCountYotogi = status.playCountYotogi;
  82. this.overrideData = new ScoutMaidOverrideData();
  83. this.instanceData = new ScoutInstanceData();
  84. }
  85. public void Apply(Maid maid)
  86. {
  87. if (maid == null)
  88. {
  89. return;
  90. }
  91. byte[] pressetBinary = this.pressetBinary;
  92. if (this.overrideData.pressetBinary != null && this.overrideData.pressetBinary.Length > 0)
  93. {
  94. pressetBinary = this.overrideData.pressetBinary;
  95. }
  96. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(pressetBinary)))
  97. {
  98. GameMain.Instance.CharacterMgr.PresetSet(maid, GameMain.Instance.CharacterMgr.PresetLoad(binaryReader, string.Empty));
  99. }
  100. using (BinaryReader binaryReader2 = new BinaryReader(new MemoryStream(this.statusBinary)))
  101. {
  102. maid.status.Deserialize(binaryReader2);
  103. }
  104. this.overrideData.Apply(maid);
  105. this.instanceData.Apply(maid);
  106. foreach (int featureId in maid.status.features.GetKeyArray())
  107. {
  108. maid.status.RemoveFeature(featureId);
  109. }
  110. List<Feature.Data> allDatas = Feature.GetAllDatas(true);
  111. foreach (Personal.Data.LearnFeature learnFeature in maid.status.personal.acquisitionFeatureList)
  112. {
  113. if (learnFeature.isLearnPossible(maid.status))
  114. {
  115. maid.status.AddFeature(learnFeature.feature);
  116. }
  117. }
  118. AbstractClassData.ClassType classTypeFlags = AbstractClassData.ClassType.Share | AbstractClassData.ClassType.New | AbstractClassData.ClassType.Old;
  119. maid.status.yotogiClass.Clear();
  120. foreach (YotogiClass.Data data in maid.status.yotogiClass.GetLearnPossibleClassDatas(false, classTypeFlags))
  121. {
  122. if (GameMain.Instance.CharacterMgr.status.IsYotogiClassOpenFlag(data.id))
  123. {
  124. maid.status.yotogiClass.Add(data.id, false, true);
  125. }
  126. }
  127. int id = maid.status.selectedJobClass.data.id;
  128. HashSet<int> hashSet = new HashSet<int>();
  129. foreach (KeyValuePair<int, ClassData<JobClass.Data>> keyValuePair in maid.status.jobClass.GetAllDatas())
  130. {
  131. hashSet.Add(keyValuePair.Key);
  132. }
  133. HashSet<int> hashSet2 = new HashSet<int>();
  134. foreach (JobClass.Data data2 in maid.status.jobClass.GetLearnPossibleClassDatas(false, classTypeFlags))
  135. {
  136. if (GameMain.Instance.CharacterMgr.status.IsJobClassOpenFlag(data2.id))
  137. {
  138. hashSet2.Add(data2.id);
  139. }
  140. }
  141. HashSet<int> hashSet3 = new HashSet<int>();
  142. foreach (int item in hashSet)
  143. {
  144. if (!hashSet2.Contains(item))
  145. {
  146. hashSet3.Add(item);
  147. }
  148. }
  149. HashSet<int> hashSet4 = new HashSet<int>();
  150. foreach (int item2 in hashSet2)
  151. {
  152. if (!hashSet.Contains(item2))
  153. {
  154. hashSet4.Add(item2);
  155. }
  156. }
  157. foreach (int id2 in hashSet3)
  158. {
  159. maid.status.jobClass.Remove(id2, true);
  160. }
  161. int num = -1;
  162. foreach (int num2 in hashSet4)
  163. {
  164. maid.status.jobClass.Add(num2, false, true);
  165. num = ((num >= num2) ? num : num2);
  166. }
  167. if (num != -1)
  168. {
  169. maid.status.ChangeJobClass(num);
  170. }
  171. maid.status.yotogiSkill.Clear();
  172. List<Skill.Data> learnPossibleSkills = Skill.GetLearnPossibleSkills(maid.status);
  173. foreach (Skill.Data data3 in learnPossibleSkills)
  174. {
  175. maid.status.yotogiSkill.Add(data3.id);
  176. }
  177. maid.status.UpdateClassBonusStatus();
  178. maid.status.sexPlayNumberOfPeople = MaidProfile.UpdateInitPlayNumber(maid.status.maid);
  179. maid.status.UpdateBodyParam();
  180. maid.status.profileComment = MaidProfile.Create(maid.status.maid, true);
  181. maid.status.SetFlag("__スカウトメイド", 1);
  182. }
  183. public byte[] GetIconImageBinary()
  184. {
  185. return (this.overrideData.iconImageBinary == null || this.overrideData.iconImageBinary.Length <= 0) ? this.iconImageBinary : this.overrideData.iconImageBinary;
  186. }
  187. public byte[] GetPressetBinary()
  188. {
  189. return (this.overrideData.pressetBinary == null || this.overrideData.pressetBinary.Length <= 0) ? this.pressetBinary : this.overrideData.pressetBinary;
  190. }
  191. public byte[] Serialize()
  192. {
  193. MemoryStream memoryStream = new MemoryStream();
  194. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  195. binaryWriter.Write("COM3D2_SCOUT_DATA");
  196. binaryWriter.Write(1000);
  197. binaryWriter.Write(JsonUtility.ToJson(this.status));
  198. binaryWriter.Write(this.iconImageBinary.Length);
  199. binaryWriter.Write(this.iconImageBinary);
  200. binaryWriter.Write(this.pressetBinary.Length);
  201. binaryWriter.Write(this.pressetBinary);
  202. binaryWriter.Write(this.statusBinary.Length);
  203. binaryWriter.Write(this.statusBinary);
  204. byte[] array = this.overrideData.Serialize();
  205. binaryWriter.Write(array.Length);
  206. binaryWriter.Write(array);
  207. binaryWriter.Write(JsonUtility.ToJson(this.instanceData));
  208. return memoryStream.ToArray();
  209. }
  210. public void DeSerialize(byte[] data)
  211. {
  212. MemoryStream input = new MemoryStream(data);
  213. BinaryReader binaryReader = new BinaryReader(input);
  214. NDebug.Assert(binaryReader.ReadString() == "COM3D2_SCOUT_DATA", "ScoutMaidData::DeSerialize Header Check error.");
  215. int num = binaryReader.ReadInt32();
  216. this.status = JsonUtility.FromJson<ScoutMaidData.SimpleStatus>(binaryReader.ReadString());
  217. int count = binaryReader.ReadInt32();
  218. this.iconImageBinary = binaryReader.ReadBytes(count);
  219. count = binaryReader.ReadInt32();
  220. this.pressetBinary = binaryReader.ReadBytes(count);
  221. count = binaryReader.ReadInt32();
  222. this.statusBinary = binaryReader.ReadBytes(count);
  223. this.overrideData = new ScoutMaidOverrideData();
  224. count = binaryReader.ReadInt32();
  225. this.overrideData.DeSerialize(binaryReader.ReadBytes(count));
  226. this.instanceData = JsonUtility.FromJson<ScoutInstanceData>(binaryReader.ReadString());
  227. }
  228. public object Clone()
  229. {
  230. ScoutMaidData scoutMaidData = (ScoutMaidData)base.MemberwiseClone();
  231. scoutMaidData.status = JsonUtility.FromJson<ScoutMaidData.SimpleStatus>(JsonUtility.ToJson(this.status));
  232. scoutMaidData.iconImageBinary = (byte[])this.iconImageBinary.Clone();
  233. scoutMaidData.pressetBinary = (byte[])this.pressetBinary.Clone();
  234. scoutMaidData.statusBinary = (byte[])this.statusBinary.Clone();
  235. scoutMaidData.overrideData = (this.overrideData.Clone() as ScoutMaidOverrideData);
  236. scoutMaidData.instanceData = (this.instanceData.Clone() as ScoutInstanceData);
  237. return scoutMaidData;
  238. }
  239. private const int FixVersion = 1000;
  240. [Serializable]
  241. public class SimpleStatus : ISerializationCallbackReceiver
  242. {
  243. public Personal.Data personal
  244. {
  245. get
  246. {
  247. return Personal.GetData(this.personalId);
  248. }
  249. }
  250. public void OnBeforeSerialize()
  251. {
  252. this.version = 1000;
  253. }
  254. public void OnAfterDeserialize()
  255. {
  256. }
  257. public int version = 1000;
  258. public string guid;
  259. public ulong creationTimeNum;
  260. public string name1;
  261. public string name2;
  262. public int personalId;
  263. public Seikeiken initSeikeiken;
  264. public Seikeiken seikeiken;
  265. public int height;
  266. public int weight;
  267. public int bust;
  268. public int waist;
  269. public int hip;
  270. public string cup;
  271. public int care;
  272. public int reception;
  273. public int teachRate;
  274. public int studyRate;
  275. public int maxHp;
  276. public int maxMind;
  277. public int lovely;
  278. public int elegance;
  279. public int charm;
  280. public int cooking;
  281. public int dance;
  282. public int vocal;
  283. public int inyoku;
  284. public int mvalue;
  285. public int hentai;
  286. public int housi;
  287. public int maidPoint;
  288. public int playCountYotogi;
  289. }
  290. }
  291. }