Meido.cs 25 KB

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