Meido.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. using System;
  2. using System.IO;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Xml.Linq;
  7. using UnityEngine;
  8. using static TBody;
  9. namespace COM3D2.MeidoPhotoStudio.Plugin
  10. {
  11. internal class Meido : ISerializable
  12. {
  13. public const int meidoDataVersion = 1000;
  14. public static readonly PoseInfo DefaultPose =
  15. new PoseInfo(Constants.PoseGroupList[0], Constants.PoseDict[Constants.PoseGroupList[0]][0]);
  16. public static readonly string defaultFaceBlendSet = "通常";
  17. public static readonly string[] faceKeys = new string[24]
  18. {
  19. "eyeclose", "eyeclose2", "eyeclose3", "eyebig", "eyeclose6", "eyeclose5", "hitomih",
  20. "hitomis", "mayuha", "mayuw", "mayuup", "mayuv", "mayuvhalf", "moutha", "mouths",
  21. "mouthc", "mouthi", "mouthup", "mouthdw", "mouthhe", "mouthuphalf", "tangout",
  22. "tangup", "tangopen"
  23. };
  24. public static readonly string[] faceToggleKeys = new string[12]
  25. {
  26. // blush, shade, nose up, tears, drool, teeth
  27. "hoho2", "shock", "nosefook", "namida", "yodare", "toothoff",
  28. // cry 1, cry 2, cry 3, blush 1, blush 2, blush 3
  29. "tear1", "tear2", "tear3", "hohos", "hoho", "hohol"
  30. };
  31. public enum Curl
  32. {
  33. front, back, shift
  34. }
  35. private bool initialized;
  36. public event EventHandler<MeidoUpdateEventArgs> UpdateMeido;
  37. public int StockNo { get; }
  38. public Maid Maid { get; private set; }
  39. public TBody Body => Maid.body0;
  40. public MeidoDragPointManager IKManager { get; private set; }
  41. public Texture2D Portrait { get; private set; }
  42. public PoseInfo CachedPose { get; private set; } = DefaultPose;
  43. public string FaceBlendSet { get; private set; } = defaultFaceBlendSet;
  44. public int Slot { get; private set; }
  45. public bool Loading { get; private set; }
  46. public string FirstName => Maid.status.firstName;
  47. public string LastName => Maid.status.lastName;
  48. public bool Busy => Maid.IsBusy && Loading;
  49. public bool CurlingFront => Maid.IsItemChange("skirt", "めくれスカート")
  50. || Maid.IsItemChange("onepiece", "めくれスカート");
  51. public bool CurlingBack => Maid.IsItemChange("skirt", "めくれスカート後ろ")
  52. || Maid.IsItemChange("onepiece", "めくれスカート後ろ");
  53. public bool PantsuShift => Maid.IsItemChange("panz", "パンツずらし")
  54. || Maid.IsItemChange("mizugi", "パンツずらし");
  55. private bool freeLook;
  56. public bool FreeLook
  57. {
  58. get => freeLook;
  59. set
  60. {
  61. if (this.freeLook == value) return;
  62. this.freeLook = value;
  63. Body.trsLookTarget = this.freeLook ? null : GameMain.Instance.MainCamera.transform;
  64. OnUpdateMeido();
  65. }
  66. }
  67. public bool HeadToCam
  68. {
  69. get => !Body.isLoadedBody ? false : Body.boHeadToCam;
  70. set
  71. {
  72. if (!Body.isLoadedBody || HeadToCam == value) return;
  73. Body.boHeadToCam = value;
  74. if (!HeadToCam && !EyeToCam) FreeLook = false;
  75. OnUpdateMeido();
  76. }
  77. }
  78. public bool EyeToCam
  79. {
  80. get => !Body.isLoadedBody ? false : Body.boEyeToCam;
  81. set
  82. {
  83. if (!Body.isLoadedBody || EyeToCam == value) return;
  84. Body.boEyeToCam = value;
  85. if (!HeadToCam && !EyeToCam) FreeLook = false;
  86. OnUpdateMeido();
  87. }
  88. }
  89. public bool Stop
  90. {
  91. get
  92. {
  93. if (!Body.isLoadedBody) return true;
  94. else return !Maid.GetAnimation().isPlaying;
  95. }
  96. set
  97. {
  98. if (!Body.isLoadedBody || value == Stop) return;
  99. else
  100. {
  101. if (value) Maid.GetAnimation().Stop();
  102. else
  103. {
  104. Body.boEyeToCam = true;
  105. Body.boHeadToCam = true;
  106. this.SetPose(this.CachedPose.Pose);
  107. }
  108. OnUpdateMeido();
  109. }
  110. }
  111. }
  112. public bool IK
  113. {
  114. get => IKManager.Active;
  115. set
  116. {
  117. if (value == IKManager.Active) return;
  118. else IKManager.Active = value;
  119. }
  120. }
  121. public bool Bone
  122. {
  123. get => IKManager.IsBone;
  124. set
  125. {
  126. if (value == Bone) return;
  127. else IKManager.IsBone = value;
  128. OnUpdateMeido();
  129. }
  130. }
  131. public float[] BlendValuesBackup { get; private set; }
  132. public float[] BlendValues { get; private set; }
  133. public Quaternion DefaultEyeRotL { get; private set; }
  134. public Quaternion DefaultEyeRotR { get; private set; }
  135. public Meido(int stockMaidIndex)
  136. {
  137. this.StockNo = stockMaidIndex;
  138. this.Maid = GameMain.Instance.CharacterMgr.GetStockMaid(stockMaidIndex);
  139. this.Portrait = Maid.GetThumIcon();
  140. IKManager = new MeidoDragPointManager(this);
  141. IKManager.SelectMaid += (s, args) => OnUpdateMeido((MeidoUpdateEventArgs)args);
  142. }
  143. public void BeginLoad()
  144. {
  145. FreeLook = false;
  146. Maid.Visible = true;
  147. Body.boHeadToCam = true;
  148. Body.boEyeToCam = true;
  149. Body.SetBoneHitHeightY(-1000f);
  150. }
  151. public void Load(int slot)
  152. {
  153. Slot = slot;
  154. Loading = true;
  155. if (!Body.isLoadedBody)
  156. {
  157. Maid.DutPropAll();
  158. Maid.AllProcPropSeqStart();
  159. }
  160. GameMain.Instance.StartCoroutine(Load());
  161. }
  162. private IEnumerator Load()
  163. {
  164. while (Maid.IsBusy) yield return null;
  165. yield return new WaitForEndOfFrame();
  166. OnBodyLoad();
  167. }
  168. public void Unload()
  169. {
  170. if (Body.isLoadedBody)
  171. {
  172. DetachAllMpnAttach();
  173. Body.jbMuneL.enabled = true;
  174. Body.jbMuneR.enabled = true;
  175. Body.quaDefEyeL = DefaultEyeRotL;
  176. Body.quaDefEyeR = DefaultEyeRotR;
  177. }
  178. Body.MuneYureL(1f);
  179. Body.MuneYureR(1f);
  180. Body.SetMaskMode(MaskMode.None);
  181. Body.SetBoneHitHeightY(0f);
  182. Maid.Visible = false;
  183. IKManager.Destroy();
  184. }
  185. public void Deactivate()
  186. {
  187. Unload();
  188. Maid.SetPos(Vector3.zero);
  189. Maid.SetRot(Vector3.zero);
  190. Maid.SetPosOffset(Vector3.zero);
  191. Body.transform.localScale = Vector3.one;
  192. Maid.ResetAll();
  193. Maid.ActiveSlotNo = -1;
  194. }
  195. public void SetPose(PoseInfo poseInfo)
  196. {
  197. CachedPose = poseInfo;
  198. SetPose(poseInfo.Pose);
  199. }
  200. public void SetPose(string pose)
  201. {
  202. if (!Body.isLoadedBody) return;
  203. if (pose.StartsWith(Constants.customPosePath))
  204. {
  205. byte[] poseBuffer = File.ReadAllBytes(pose);
  206. string hash = Path.GetFileName(pose).GetHashCode().ToString();
  207. Body.CrossFade(hash, poseBuffer, loop: true, fade: 0f);
  208. }
  209. else
  210. {
  211. string[] poseComponents = pose.Split(',');
  212. pose = poseComponents[0] + ".anm";
  213. Maid.CrossFade(pose, loop: true, val: 0f);
  214. Maid.GetAnimation().Play();
  215. if (poseComponents.Length > 1)
  216. {
  217. Maid.GetAnimation()[pose].time = float.Parse(poseComponents[1]);
  218. Maid.GetAnimation()[pose].speed = 0f;
  219. }
  220. }
  221. Maid.SetAutoTwistAll(true);
  222. SetMune();
  223. }
  224. public void CopyPose(Meido fromMeido)
  225. {
  226. byte[] poseBinary = fromMeido.SerializePose();
  227. string tag = $"copy_{fromMeido.Maid.status.guid}";
  228. Body.CrossFade(tag, poseBinary, false, true, false, 0f);
  229. Maid.SetAutoTwistAll(true);
  230. Maid.transform.rotation = fromMeido.Maid.transform.rotation;
  231. SetMune();
  232. }
  233. public void SetMune(bool drag = false)
  234. {
  235. bool momiOrPaizuri = CachedPose.Pose.Contains("_momi") || CachedPose.Pose.Contains("paizuri_");
  236. float onL = (drag || momiOrPaizuri) ? 0f : 1f;
  237. Body.MuneYureL(onL);
  238. Body.MuneYureR(onL);
  239. Body.jbMuneL.enabled = !drag;
  240. Body.jbMuneR.enabled = !drag;
  241. }
  242. public void SetHandPreset(string filename, bool right)
  243. {
  244. XDocument handDocument = XDocument.Load(filename);
  245. XElement handElement = handDocument.Element("FingerData");
  246. if (handElement.IsEmpty || handElement.Element("GameVersion").IsEmpty
  247. || handElement.Element("RightData").IsEmpty || handElement.Element("BinaryData").IsEmpty
  248. ) return;
  249. Stop = true;
  250. bool rightData = bool.Parse(handElement.Element("RightData").Value);
  251. string base64Data = handElement.Element("BinaryData").Value;
  252. byte[] handData = Convert.FromBase64String(base64Data);
  253. IKManager.DeserializeHand(handData, right, rightData != right);
  254. }
  255. public byte[] SerializePose(bool frameBinary = false)
  256. {
  257. CacheBoneDataArray cache = GetCacheBoneData();
  258. return frameBinary ? cache.GetFrameBinary(true, true) : cache.GetAnmBinary(true, true);
  259. }
  260. public void SetFaceBlendSet(string blendSet)
  261. {
  262. FaceBlendSet = blendSet;
  263. Maid.boMabataki = false;
  264. TMorph morph = Body.Face.morph;
  265. morph.EyeMabataki = 0f;
  266. morph.MulBlendValues(blendSet, 1f);
  267. morph.FixBlendValues_Face();
  268. OnUpdateMeido();
  269. }
  270. public void SetFaceBlendValue(string hash, float value)
  271. {
  272. TMorph morph = Body.Face.morph;
  273. if (hash == "nosefook")
  274. {
  275. morph.boNoseFook = value > 0f;
  276. Maid.boNoseFook = morph.boNoseFook;
  277. }
  278. else
  279. {
  280. bool gp01FBFace = morph.bodyskin.PartsVersion >= 120;
  281. float[] blendValues = hash.StartsWith("eyeclose") && !(gp01FBFace && (hash == "eyeclose3"))
  282. ? this.BlendValuesBackup
  283. : this.BlendValues;
  284. hash = Utility.GP01FbFaceHash(morph, hash);
  285. try
  286. {
  287. blendValues[(int)morph.hash[hash]] = value;
  288. }
  289. catch { }
  290. }
  291. Maid.boMabataki = false;
  292. morph.EyeMabataki = 0f;
  293. morph.FixBlendValues_Face();
  294. }
  295. public void SetMaskMode(MaskMode maskMode)
  296. {
  297. bool invisibleBody = !Body.GetMask(SlotID.body);
  298. Body.SetMaskMode(maskMode);
  299. if (invisibleBody) SetBodyMask(false);
  300. }
  301. public void SetBodyMask(bool enabled)
  302. {
  303. Hashtable table = Utility.GetFieldValue<TBody, Hashtable>(Body, "m_hFoceHide");
  304. foreach (SlotID bodySlot in MaidDressingPane.bodySlots)
  305. {
  306. table[bodySlot] = enabled;
  307. }
  308. if (Body.goSlot[19].m_strModelFileName.Contains("melala_body"))
  309. {
  310. table[SlotID.accHana] = enabled;
  311. }
  312. Body.FixMaskFlag();
  313. Body.FixVisibleFlag(false);
  314. }
  315. public void SetCurling(Curl curling, bool enabled)
  316. {
  317. string[] name = curling == Curl.shift
  318. ? new[] { "panz", "mizugi" }
  319. : new[] { "skirt", "onepiece" };
  320. if (enabled)
  321. {
  322. string action = curling == Curl.shift
  323. ? "パンツずらし" : curling == Curl.front
  324. ? "めくれスカート" : "めくれスカート後ろ";
  325. Maid.ItemChangeTemp(name[0], action);
  326. Maid.ItemChangeTemp(name[1], action);
  327. }
  328. else
  329. {
  330. Maid.ResetProp(name[0]);
  331. Maid.ResetProp(name[1]);
  332. }
  333. Maid.AllProcProp();
  334. }
  335. public void SetMpnProp(MpnAttachProp prop, bool detach)
  336. {
  337. if (detach) Maid.ResetProp(prop.Tag, false);
  338. else Maid.SetProp(prop.Tag, prop.MenuFile, 0, true);
  339. Maid.AllProcProp();
  340. }
  341. public void DetachAllMpnAttach(bool unload = false)
  342. {
  343. Maid.ResetProp(MPN.kousoku_lower, false);
  344. Maid.ResetProp(MPN.kousoku_upper, false);
  345. Maid.AllProcProp();
  346. }
  347. private CacheBoneDataArray GetCacheBoneData()
  348. {
  349. CacheBoneDataArray cache = this.Maid.gameObject.GetComponent<CacheBoneDataArray>();
  350. if (cache == null)
  351. {
  352. cache = this.Maid.gameObject.AddComponent<CacheBoneDataArray>();
  353. cache.CreateCache(this.Maid.body0.GetBone("Bip01"));
  354. }
  355. return cache;
  356. }
  357. private void OnBodyLoad()
  358. {
  359. if (!initialized)
  360. {
  361. TMorph faceMorph = Body.Face.morph;
  362. BlendValuesBackup = Utility.GetFieldValue<TMorph, float[]>(faceMorph, "BlendValuesBackup");
  363. BlendValues = Utility.GetFieldValue<TMorph, float[]>(faceMorph, "BlendValues");
  364. DefaultEyeRotL = Body.quaDefEyeL;
  365. DefaultEyeRotR = Body.quaDefEyeR;
  366. initialized = true;
  367. }
  368. IKManager.Initialize();
  369. IK = true;
  370. Stop = false;
  371. Bone = false;
  372. Loading = false;
  373. }
  374. public void OnUpdateMeido(MeidoUpdateEventArgs args = null)
  375. {
  376. this.UpdateMeido?.Invoke(this, args ?? MeidoUpdateEventArgs.Empty);
  377. }
  378. public void Serialize(BinaryWriter binaryWriter)
  379. {
  380. using (MemoryStream memoryStream = new MemoryStream())
  381. using (BinaryWriter tempWriter = new BinaryWriter(memoryStream))
  382. {
  383. // transform
  384. tempWriter.WriteVector3(Maid.transform.position);
  385. tempWriter.WriteQuaternion(Maid.transform.rotation);
  386. tempWriter.WriteVector3(Maid.transform.localScale);
  387. // pose
  388. byte[] poseBuffer = SerializePose(true);
  389. tempWriter.Write(poseBuffer.Length);
  390. tempWriter.Write(poseBuffer);
  391. CachedPose.Serialize(tempWriter);
  392. // eye direction
  393. tempWriter.WriteQuaternion(Body.quaDefEyeL * Quaternion.Inverse(DefaultEyeRotL));
  394. tempWriter.WriteQuaternion(Body.quaDefEyeR * Quaternion.Inverse(DefaultEyeRotR));
  395. // free look
  396. tempWriter.Write(FreeLook);
  397. if (FreeLook)
  398. {
  399. tempWriter.WriteVector3(Body.offsetLookTarget);
  400. tempWriter.WriteVector3(Utility.GetFieldValue<TBody, Vector3>(Body, "HeadEulerAngle"));
  401. }
  402. // face
  403. SerializeFace(tempWriter);
  404. // body visible
  405. tempWriter.Write(Body.GetMask(SlotID.body));
  406. // clothing
  407. foreach (SlotID clothingSlot in MaidDressingPane.clothingSlots)
  408. {
  409. bool value = true;
  410. if (clothingSlot == SlotID.wear)
  411. {
  412. if (MaidDressingPane.wearSlots.Any(slot => Body.GetSlotLoaded(slot)))
  413. {
  414. value = MaidDressingPane.wearSlots.Any(slot => Body.GetMask(slot));
  415. }
  416. }
  417. else if (clothingSlot == SlotID.megane)
  418. {
  419. SlotID[] slots = new[] { SlotID.megane, SlotID.accHead };
  420. if (slots.Any(slot => Body.GetSlotLoaded(slot)))
  421. {
  422. value = slots.Any(slot => Body.GetMask(slot));
  423. }
  424. }
  425. else if (Body.GetSlotLoaded(clothingSlot))
  426. {
  427. value = Body.GetMask(clothingSlot);
  428. }
  429. tempWriter.Write(value);
  430. }
  431. // zurashi and mekure
  432. tempWriter.Write(CurlingFront);
  433. tempWriter.Write(CurlingBack);
  434. tempWriter.Write(PantsuShift);
  435. bool hasKousokuUpper = Body.GetSlotLoaded(SlotID.kousoku_upper);
  436. tempWriter.Write(hasKousokuUpper);
  437. if (hasKousokuUpper) tempWriter.Write(Maid.GetProp(MPN.kousoku_upper).strTempFileName);
  438. bool hasKousokuLower = Body.GetSlotLoaded(SlotID.kousoku_lower);
  439. tempWriter.Write(hasKousokuLower);
  440. if (hasKousokuLower) tempWriter.Write(Maid.GetProp(MPN.kousoku_lower).strTempFileName);
  441. binaryWriter.Write(memoryStream.Length);
  442. binaryWriter.Write(memoryStream.ToArray());
  443. }
  444. }
  445. private void SerializeFace(BinaryWriter binaryWriter)
  446. {
  447. binaryWriter.Write("MPS_FACE");
  448. TMorph morph = Maid.body0.Face.morph;
  449. bool gp01FBFace = morph.bodyskin.PartsVersion >= 120;
  450. foreach (string hash in faceKeys)
  451. {
  452. float[] blendValues = hash.StartsWith("eyeclose") && !(gp01FBFace && (hash == "eyeclose3"))
  453. ? this.BlendValuesBackup
  454. : this.BlendValues;
  455. string faceKey = Utility.GP01FbFaceHash(morph, hash);
  456. try
  457. {
  458. float value = blendValues[(int)morph.hash[faceKey]];
  459. binaryWriter.Write(hash);
  460. binaryWriter.Write(value);
  461. }
  462. catch { }
  463. }
  464. foreach (string hash in faceToggleKeys)
  465. {
  466. bool value = this.BlendValues[(int)morph.hash[hash]] > 0f;
  467. if (hash == "nosefook") value = morph.boNoseFook;
  468. binaryWriter.Write(hash);
  469. binaryWriter.Write(value);
  470. }
  471. binaryWriter.Write("END_FACE");
  472. }
  473. public void Deserialize(BinaryReader binaryReader) => Deserialize(binaryReader, meidoDataVersion, false);
  474. public void Deserialize(BinaryReader binaryReader, int dataVersion, bool mmScene)
  475. {
  476. Maid.GetAnimation().Stop();
  477. DetachAllMpnAttach();
  478. binaryReader.ReadInt64(); // meido buffer length
  479. // transform
  480. Maid.transform.position = binaryReader.ReadVector3();
  481. Maid.transform.rotation = binaryReader.ReadQuaternion();
  482. Maid.transform.localScale = binaryReader.ReadVector3();
  483. // pose
  484. if (mmScene) IKManager.Deserialize(binaryReader);
  485. else
  486. {
  487. int poseBufferLength = binaryReader.ReadInt32();
  488. byte[] poseBuffer = binaryReader.ReadBytes(poseBufferLength);
  489. GetCacheBoneData().SetFrameBinary(poseBuffer);
  490. }
  491. Body.MuneYureL(0f);
  492. Body.MuneYureR(0f);
  493. Body.jbMuneL.enabled = false;
  494. Body.jbMuneR.enabled = false;
  495. CachedPose = PoseInfo.Deserialize(binaryReader);
  496. // eye direction
  497. Body.quaDefEyeL = binaryReader.ReadQuaternion() * DefaultEyeRotL;
  498. Body.quaDefEyeR = binaryReader.ReadQuaternion() * DefaultEyeRotR;
  499. // free look
  500. FreeLook = binaryReader.ReadBoolean();
  501. if (FreeLook)
  502. {
  503. Body.offsetLookTarget = binaryReader.ReadVector3();
  504. // Head angle cannot be resolved with just the offsetLookTarget
  505. if (!mmScene)
  506. {
  507. Utility.SetFieldValue<TBody, Vector3>(Body, "HeadEulerAngleG", Vector3.zero);
  508. Utility.SetFieldValue<TBody, Vector3>(Body, "HeadEulerAngle", binaryReader.ReadVector3());
  509. }
  510. }
  511. // face
  512. DeserializeFace(binaryReader);
  513. // body visible
  514. SetBodyMask(binaryReader.ReadBoolean());
  515. // clothing
  516. foreach (SlotID clothingSlot in MaidDressingPane.clothingSlots)
  517. {
  518. bool value = binaryReader.ReadBoolean();
  519. if (mmScene) continue;
  520. if (clothingSlot == SlotID.wear)
  521. {
  522. Body.SetMask(SlotID.wear, value);
  523. Body.SetMask(SlotID.mizugi, value);
  524. Body.SetMask(SlotID.onepiece, value);
  525. }
  526. else if (clothingSlot == SlotID.megane)
  527. {
  528. Body.SetMask(SlotID.megane, value);
  529. Body.SetMask(SlotID.accHead, value);
  530. }
  531. else if (Body.GetSlotLoaded(clothingSlot))
  532. {
  533. Body.SetMask(clothingSlot, value);
  534. }
  535. }
  536. // zurashi and mekure
  537. bool curlingFront = binaryReader.ReadBoolean();
  538. bool curlingBack = binaryReader.ReadBoolean();
  539. bool curlingPantsu = binaryReader.ReadBoolean();
  540. if (!mmScene)
  541. {
  542. if (CurlingFront != curlingFront) SetCurling(Curl.front, curlingFront);
  543. if (CurlingBack != curlingBack) SetCurling(Curl.back, curlingBack);
  544. SetCurling(Curl.shift, curlingPantsu);
  545. }
  546. bool hasKousokuUpper = binaryReader.ReadBoolean();
  547. if (hasKousokuUpper)
  548. {
  549. try
  550. {
  551. SetMpnProp(new MpnAttachProp(MPN.kousoku_upper, binaryReader.ReadString()), false);
  552. }
  553. catch { }
  554. }
  555. bool hasKousokuLower = binaryReader.ReadBoolean();
  556. if (hasKousokuLower)
  557. {
  558. try
  559. {
  560. SetMpnProp(new MpnAttachProp(MPN.kousoku_lower, binaryReader.ReadString()), false);
  561. }
  562. catch { }
  563. }
  564. // OnUpdateMeido();
  565. }
  566. private void DeserializeFace(BinaryReader binaryReader)
  567. {
  568. binaryReader.ReadString(); // read face header
  569. TMorph morph = Maid.body0.Face.morph;
  570. bool gp01FBFace = morph.bodyskin.PartsVersion >= 120;
  571. HashSet<string> faceKeys = new HashSet<string>(Meido.faceKeys);
  572. string header;
  573. while ((header = binaryReader.ReadString()) != "END_FACE")
  574. {
  575. if (faceKeys.Contains(header))
  576. {
  577. float[] blendValues = header.StartsWith("eyeclose") && !(gp01FBFace && (header == "eyeclose3"))
  578. ? this.BlendValuesBackup
  579. : this.BlendValues;
  580. string hash = Utility.GP01FbFaceHash(morph, header);
  581. try
  582. {
  583. float value = binaryReader.ReadSingle();
  584. blendValues[(int)morph.hash[hash]] = value;
  585. }
  586. catch { }
  587. }
  588. else
  589. {
  590. bool value = binaryReader.ReadBoolean();
  591. if (header == "nosefook") this.Maid.boNoseFook = value;
  592. else this.BlendValues[(int)morph.hash[header]] = value ? 1f : 0f;
  593. }
  594. }
  595. Maid.boMabataki = false;
  596. morph.EyeMabataki = 0f;
  597. morph.FixBlendValues_Face();
  598. }
  599. }
  600. public struct PoseInfo
  601. {
  602. public string PoseGroup { get; }
  603. public string Pose { get; }
  604. public bool CustomPose { get; }
  605. public PoseInfo(string poseGroup, string pose, bool customPose = false)
  606. {
  607. this.PoseGroup = poseGroup;
  608. this.Pose = pose;
  609. this.CustomPose = customPose;
  610. }
  611. public void Serialize(BinaryWriter binaryWriter)
  612. {
  613. binaryWriter.Write(PoseGroup);
  614. binaryWriter.Write(Pose);
  615. binaryWriter.Write(CustomPose);
  616. }
  617. public static PoseInfo Deserialize(BinaryReader binaryReader)
  618. {
  619. return new PoseInfo
  620. (
  621. binaryReader.ReadString(),
  622. binaryReader.ReadString(),
  623. binaryReader.ReadBoolean()
  624. );
  625. }
  626. }
  627. }