Meido.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. using System;
  2. using System.IO;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Reflection;
  6. using System.Linq;
  7. using System.Xml.Linq;
  8. using UnityEngine;
  9. using static TBody;
  10. namespace COM3D2.MeidoPhotoStudio.Plugin
  11. {
  12. public class Meido
  13. {
  14. private bool initialized;
  15. private float[] BlendSetValueBackup;
  16. private readonly FieldInfo m_eMaskMode = Utility.GetFieldInfo<TBody>("m_eMaskMode");
  17. public MaskMode CurrentMaskMode => !Body.isLoadedBody ? default : (MaskMode) m_eMaskMode.GetValue(Body);
  18. public DragPointGravity HairGravityControl { get; private set; }
  19. public DragPointGravity SkirtGravityControl { get; private set; }
  20. public bool HairGravityActive
  21. {
  22. get => HairGravityControl.Active;
  23. set
  24. {
  25. if (HairGravityControl.Valid) HairGravityControl.gameObject.SetActive(value);
  26. }
  27. }
  28. public bool SkirtGravityActive
  29. {
  30. get => SkirtGravityControl.Active;
  31. set
  32. {
  33. if (SkirtGravityControl.Valid) SkirtGravityControl.gameObject.SetActive(value);
  34. }
  35. }
  36. public static readonly string defaultFaceBlendSet = "通常";
  37. public static readonly string[] faceKeys = new string[24]
  38. {
  39. "eyeclose", "eyeclose2", "eyeclose3", "eyebig", "eyeclose6", "eyeclose5", "hitomih",
  40. "hitomis", "mayuha", "mayuw", "mayuup", "mayuv", "mayuvhalf", "moutha", "mouths",
  41. "mouthc", "mouthi", "mouthup", "mouthdw", "mouthhe", "mouthuphalf", "tangout",
  42. "tangup", "tangopen"
  43. };
  44. public static readonly string[] faceToggleKeys = new string[12]
  45. {
  46. // blush, shade, nose up, tears, drool, teeth
  47. "hoho2", "shock", "nosefook", "namida", "yodare", "toothoff",
  48. // cry 1, cry 2, cry 3, blush 1, blush 2, blush 3
  49. "tear1", "tear2", "tear3", "hohos", "hoho", "hohol"
  50. };
  51. public enum Curl { Front, Back, Shift }
  52. public enum Mask { All, Underwear, Nude }
  53. public event EventHandler<MeidoUpdateEventArgs> UpdateMeido;
  54. public int StockNo { get; }
  55. public Maid Maid { get; }
  56. public TBody Body => Maid.body0;
  57. public MeidoDragPointManager IKManager { get; }
  58. public Texture2D Portrait => Maid.GetThumIcon();
  59. public bool IsEditMaid { get; set; }
  60. public PoseInfo CachedPose { get; private set; } = PoseInfo.DefaultPose;
  61. public string CurrentFaceBlendSet { get; private set; } = defaultFaceBlendSet;
  62. public int Slot { get; private set; }
  63. public bool Loading { get; private set; }
  64. public string FirstName => Maid.status.firstName;
  65. public string LastName => Maid.status.lastName;
  66. public bool Busy => Maid.IsBusy || Loading;
  67. public bool CurlingFront => Maid.IsItemChange("skirt", "めくれスカート")
  68. || Maid.IsItemChange("onepiece", "めくれスカート");
  69. public bool CurlingBack => Maid.IsItemChange("skirt", "めくれスカート後ろ")
  70. || Maid.IsItemChange("onepiece", "めくれスカート後ろ");
  71. public bool PantsuShift => Maid.IsItemChange("panz", "パンツずらし")
  72. || Maid.IsItemChange("mizugi", "パンツずらし");
  73. private bool freeLook;
  74. public bool FreeLook
  75. {
  76. get => freeLook;
  77. set
  78. {
  79. if (freeLook == value) return;
  80. freeLook = value;
  81. Body.trsLookTarget = freeLook ? null : GameMain.Instance.MainCamera.transform;
  82. OnUpdateMeido();
  83. }
  84. }
  85. public bool HeadToCam
  86. {
  87. get => Body.isLoadedBody && Body.boHeadToCam;
  88. set
  89. {
  90. if (!Body.isLoadedBody || HeadToCam == value) return;
  91. Body.HeadToCamPer = 0f;
  92. Body.boHeadToCam = value;
  93. if (!HeadToCam && !EyeToCam) FreeLook = false;
  94. OnUpdateMeido();
  95. }
  96. }
  97. public bool EyeToCam
  98. {
  99. get => Body.isLoadedBody && Body.boEyeToCam;
  100. set
  101. {
  102. if (!Body.isLoadedBody || EyeToCam == value) return;
  103. Body.boEyeToCam = value;
  104. if (!HeadToCam && !EyeToCam) FreeLook = false;
  105. OnUpdateMeido();
  106. }
  107. }
  108. public bool Stop
  109. {
  110. get => !Body.isLoadedBody || !Maid.GetAnimation().isPlaying;
  111. set
  112. {
  113. if (!Body.isLoadedBody || value == Stop) return;
  114. if (value) Maid.GetAnimation().Stop();
  115. else
  116. {
  117. Body.boEyeToCam = true;
  118. Body.boHeadToCam = true;
  119. SetPose(CachedPose.Pose);
  120. }
  121. OnUpdateMeido();
  122. }
  123. }
  124. public bool IK
  125. {
  126. get => IKManager.Active;
  127. set
  128. {
  129. if (value == IKManager.Active) return;
  130. IKManager.Active = value;
  131. }
  132. }
  133. public bool Bone
  134. {
  135. get => IKManager.IsBone;
  136. set
  137. {
  138. if (value == Bone) return;
  139. IKManager.IsBone = value;
  140. OnUpdateMeido();
  141. }
  142. }
  143. public event EventHandler<GravityEventArgs> GravityMove;
  144. public Quaternion DefaultEyeRotL { get; private set; }
  145. public Quaternion DefaultEyeRotR { get; private set; }
  146. public Meido(int stockMaidIndex)
  147. {
  148. StockNo = stockMaidIndex;
  149. Maid = GameMain.Instance.CharacterMgr.GetStockMaid(stockMaidIndex);
  150. IKManager = new MeidoDragPointManager(this);
  151. IKManager.SelectMaid += (s, args) => OnUpdateMeido(args);
  152. }
  153. public void Load(int slot)
  154. {
  155. if (Busy) return;
  156. Slot = slot;
  157. FreeLook = false;
  158. Maid.Visible = true;
  159. Body.boHeadToCam = true;
  160. Body.boEyeToCam = true;
  161. Body.SetBoneHitHeightY(-1000f);
  162. if (!Body.isLoadedBody)
  163. {
  164. Maid.DutPropAll();
  165. Maid.AllProcPropSeqStart();
  166. }
  167. StartLoad(OnBodyLoad);
  168. }
  169. private void StartLoad(Action callback)
  170. {
  171. if (Loading) return;
  172. GameMain.Instance.StartCoroutine(Load(callback));
  173. }
  174. private IEnumerator Load(Action callback)
  175. {
  176. Loading = true;
  177. while (Maid.IsBusy) yield return null;
  178. yield return new WaitForEndOfFrame();
  179. callback();
  180. Loading = false;
  181. }
  182. private void OnBodyLoad()
  183. {
  184. if (!initialized)
  185. {
  186. DefaultEyeRotL = Body.quaDefEyeL;
  187. DefaultEyeRotR = Body.quaDefEyeR;
  188. initialized = true;
  189. }
  190. if (BlendSetValueBackup == null) BackupBlendSetValues();
  191. if (!HairGravityControl) InitializeGravityControls();
  192. HairGravityControl.Move += OnGravityEvent;
  193. SkirtGravityControl.Move += OnGravityEvent;
  194. if (MeidoPhotoStudio.EditMode) AllProcPropSeqStartPatcher.SequenceStart += ReinitializeBody;
  195. IKManager.Initialize();
  196. IK = true;
  197. Stop = false;
  198. Bone = false;
  199. }
  200. private void ReinitializeBody(object sender, ProcStartEventArgs args)
  201. {
  202. if (Loading || !Body.isLoadedBody) return;
  203. if (args.maid.status.guid == Maid.status.guid)
  204. {
  205. MPN[] gravityControlProps = new[] {
  206. MPN.skirt, MPN.onepiece, MPN.mizugi, MPN.panz, MPN.set_maidwear, MPN.set_mywear, MPN.set_underwear,
  207. MPN.hairf, MPN.hairr, MPN.hairs, MPN.hairt
  208. };
  209. // Change body
  210. if (Maid.GetProp(MPN.body).boDut)
  211. {
  212. IKManager.Destroy();
  213. StartLoad(reinitializeBody);
  214. }
  215. // Change face
  216. else if (Maid.GetProp(MPN.head).boDut)
  217. {
  218. SetFaceBlendSet(defaultFaceBlendSet);
  219. StartLoad(reinitializeFace);
  220. }
  221. // Gravity control clothing/hair change
  222. else if (gravityControlProps.Any(prop => Maid.GetProp(prop).boDut))
  223. {
  224. if (HairGravityControl) GameObject.Destroy(HairGravityControl.gameObject);
  225. if (SkirtGravityControl) GameObject.Destroy(SkirtGravityControl.gameObject);
  226. StartLoad(reinitializeGravity);
  227. }
  228. // Clothing/accessory changes
  229. // Includes null_mpn too but any button click results in null_mpn bodut I think
  230. else StartLoad(() => OnUpdateMeido());
  231. void reinitializeBody()
  232. {
  233. IKManager.Initialize();
  234. Stop = false;
  235. // Maid animation needs to be set again for custom parts edit
  236. GameObject uiRoot = GameObject.Find("UI Root");
  237. var customPartsWindow = UTY.GetChildObject(uiRoot, "Window/CustomPartsWindow")
  238. .GetComponent<SceneEditWindow.CustomPartsWindow>();
  239. Utility.SetFieldValue(customPartsWindow, "animation", Maid.GetAnimation());
  240. }
  241. void reinitializeFace()
  242. {
  243. DefaultEyeRotL = Body.quaDefEyeL;
  244. DefaultEyeRotR = Body.quaDefEyeR;
  245. BackupBlendSetValues();
  246. }
  247. void reinitializeGravity()
  248. {
  249. InitializeGravityControls();
  250. OnUpdateMeido();
  251. }
  252. }
  253. }
  254. public void Unload()
  255. {
  256. if (Body.isLoadedBody && Maid.Visible)
  257. {
  258. DetachAllMpnAttach();
  259. Body.jbMuneL.enabled = true;
  260. Body.jbMuneR.enabled = true;
  261. Body.quaDefEyeL = DefaultEyeRotL;
  262. Body.quaDefEyeR = DefaultEyeRotR;
  263. if (HairGravityControl)
  264. {
  265. HairGravityControl.Move -= OnGravityEvent;
  266. HairGravityActive = false;
  267. }
  268. if (SkirtGravityControl)
  269. {
  270. SkirtGravityControl.Move -= OnGravityEvent;
  271. SkirtGravityActive = false;
  272. }
  273. ApplyGravity(Vector3.zero, skirt: false);
  274. ApplyGravity(Vector3.zero, skirt: true);
  275. SetFaceBlendSet(defaultFaceBlendSet);
  276. }
  277. AllProcPropSeqStartPatcher.SequenceStart -= ReinitializeBody;
  278. Body.MuneYureL(1f);
  279. Body.MuneYureR(1f);
  280. Body.SetMaskMode(MaskMode.None);
  281. Body.SetBoneHitHeightY(0f);
  282. Maid.Visible = false;
  283. IKManager.Destroy();
  284. }
  285. public void Deactivate()
  286. {
  287. Unload();
  288. if (HairGravityControl) GameObject.Destroy(HairGravityControl.gameObject);
  289. if (SkirtGravityControl) GameObject.Destroy(SkirtGravityControl.gameObject);
  290. Maid.SetPos(Vector3.zero);
  291. Maid.SetRot(Vector3.zero);
  292. Maid.SetPosOffset(Vector3.zero);
  293. Body.transform.localScale = Vector3.one;
  294. Maid.ResetAll();
  295. Maid.MabatakiUpdateStop = false;
  296. Maid.ActiveSlotNo = -1;
  297. }
  298. public void SetPose(PoseInfo poseInfo)
  299. {
  300. CachedPose = poseInfo;
  301. SetPose(poseInfo.Pose);
  302. }
  303. public void SetPose(string pose)
  304. {
  305. if (!Body.isLoadedBody) return;
  306. if (pose.StartsWith(Constants.customPosePath))
  307. {
  308. string poseFilename = Path.GetFileNameWithoutExtension(pose);
  309. try
  310. {
  311. byte[] poseBuffer = File.ReadAllBytes(pose);
  312. string hash = Path.GetFileName(pose).GetHashCode().ToString();
  313. Body.CrossFade(hash, poseBuffer, loop: true, fade: 0f);
  314. }
  315. catch (Exception e) when (e is DirectoryNotFoundException || e is FileNotFoundException)
  316. {
  317. Utility.LogWarning($"{poseFilename}: Could not open because {e.Message}");
  318. Constants.InitializeCustomPoses();
  319. return;
  320. }
  321. catch (Exception e)
  322. {
  323. Utility.LogWarning($"{poseFilename}: Could not apply pose because {e.Message}");
  324. return;
  325. }
  326. SetMune(true, left: true);
  327. SetMune(true, left: false);
  328. }
  329. else
  330. {
  331. string[] poseComponents = pose.Split(',');
  332. pose = poseComponents[0] + ".anm";
  333. Maid.CrossFade(pose, loop: true, val: 0f);
  334. Maid.GetAnimation().Play();
  335. if (poseComponents.Length > 1)
  336. {
  337. Maid.GetAnimation()[pose].time = float.Parse(poseComponents[1]);
  338. Maid.GetAnimation()[pose].speed = 0f;
  339. }
  340. SetPoseMune();
  341. }
  342. Maid.SetAutoTwistAll(true);
  343. }
  344. public KeyValuePair<bool, bool> SetFrameBinary(byte[] poseBuffer)
  345. => GetCacheBoneData().SetFrameBinary(poseBuffer);
  346. public void CopyPose(Meido fromMeido)
  347. {
  348. Stop = true;
  349. SetFrameBinary(fromMeido.SerializePose(frameBinary: true));
  350. SetMune(fromMeido.Body.GetMuneYureL() != 0f, left: true);
  351. SetMune(fromMeido.Body.GetMuneYureR() != 0f, left: false);
  352. }
  353. public void SetMune(bool enabled, bool left = false)
  354. {
  355. float value = enabled ? 1f : 0f;
  356. if (left)
  357. {
  358. Body.MuneYureL(value);
  359. Body.jbMuneL.enabled = enabled;
  360. }
  361. else
  362. {
  363. Body.MuneYureR(value);
  364. Body.jbMuneR.enabled = enabled;
  365. }
  366. }
  367. private void SetPoseMune()
  368. {
  369. bool momiOrPaizuri = CachedPose.Pose.Contains("_momi") || CachedPose.Pose.Contains("paizuri_");
  370. SetMune(!momiOrPaizuri, left: true);
  371. SetMune(!momiOrPaizuri, left: false);
  372. }
  373. public void SetHandPreset(string filename, bool right)
  374. {
  375. string faceFilename = Path.GetFileNameWithoutExtension(filename);
  376. try
  377. {
  378. XDocument handDocument = XDocument.Load(filename);
  379. XElement handElement = handDocument.Element("FingerData");
  380. if (handElement?.Elements().Any(element => element?.IsEmpty ?? true) ?? true)
  381. {
  382. Utility.LogWarning($"{faceFilename}: Could not apply hand preset because it is invalid.");
  383. return;
  384. }
  385. Stop = true;
  386. bool rightData = bool.Parse(handElement.Element("RightData").Value);
  387. string base64Data = handElement.Element("BinaryData").Value;
  388. byte[] handData = Convert.FromBase64String(base64Data);
  389. IKManager.DeserializeHand(handData, right, rightData != right);
  390. }
  391. catch (System.Xml.XmlException e)
  392. {
  393. Utility.LogWarning($"{faceFilename}: Hand preset data is malformed because {e.Message}");
  394. }
  395. catch (Exception e) when (e is DirectoryNotFoundException || e is FileNotFoundException)
  396. {
  397. Utility.LogWarning($"{faceFilename}: Could not open hand preset because {e.Message}");
  398. Constants.InitializeHandPresets();
  399. }
  400. catch (Exception e)
  401. {
  402. Utility.LogWarning($"{faceFilename}: Could not parse hand preset because {e.Message}");
  403. }
  404. }
  405. public byte[] SerializePose(bool frameBinary = false)
  406. {
  407. CacheBoneDataArray cache = GetCacheBoneData();
  408. bool muneL = Body.GetMuneYureL() == 0f;
  409. bool muneR = Body.GetMuneYureR() == 0f;
  410. return frameBinary ? cache.GetFrameBinary(muneL, muneR) : cache.GetAnmBinary(true, true);
  411. }
  412. public Dictionary<string, float> SerializeFace()
  413. {
  414. Dictionary<string, float> faceData = new Dictionary<string, float>();
  415. foreach (string hash in faceKeys.Concat(faceToggleKeys))
  416. {
  417. try
  418. {
  419. float value = GetFaceBlendValue(hash);
  420. faceData.Add(hash, value);
  421. }
  422. catch { }
  423. }
  424. return faceData;
  425. }
  426. public void SetFaceBlendSet(string blendSet)
  427. {
  428. if (blendSet.StartsWith(Constants.customFacePath))
  429. {
  430. string blendSetFileName = Path.GetFileNameWithoutExtension(blendSet);
  431. try
  432. {
  433. XDocument faceDocument = XDocument.Load(blendSet, LoadOptions.SetLineInfo);
  434. XElement faceDataElement = faceDocument.Element("FaceData");
  435. if (faceDataElement?.IsEmpty ?? true)
  436. {
  437. Utility.LogWarning($"{blendSetFileName}: Could not apply face preset because it is invalid.");
  438. return;
  439. }
  440. HashSet<string> hashKeys = new HashSet<string>(faceKeys.Concat(faceToggleKeys));
  441. foreach (XElement element in faceDataElement.Elements())
  442. {
  443. System.Xml.IXmlLineInfo info = element;
  444. int line = info.HasLineInfo() ? info.LineNumber : -1;
  445. string key;
  446. if ((key = (string)element.Attribute("name")) == null)
  447. {
  448. Utility.LogWarning($"{blendSetFileName}: Could not read face blend key at line {line}.");
  449. continue;
  450. }
  451. if (!hashKeys.Contains(key))
  452. {
  453. Utility.LogWarning($"{blendSetFileName}: Invalid face blend key '{key}' at line {line}.");
  454. continue;
  455. }
  456. if (float.TryParse(element.Value, out float value))
  457. {
  458. try { SetFaceBlendValue(key, value); }
  459. catch { }
  460. }
  461. else Utility.LogWarning(
  462. $"{blendSetFileName}: Could not parse value '{element.Value}' of '{key}' at line {line}"
  463. );
  464. }
  465. }
  466. catch (System.Xml.XmlException e)
  467. {
  468. Utility.LogWarning($"{blendSetFileName}: Face preset data is malformed because {e.Message}");
  469. return;
  470. }
  471. catch (Exception e) when (e is DirectoryNotFoundException || e is FileNotFoundException)
  472. {
  473. Utility.LogWarning($"{blendSetFileName}: Could not open face preset because {e.Message}");
  474. Constants.InitializeCustomFaceBlends();
  475. return;
  476. }
  477. catch (Exception e)
  478. {
  479. Utility.LogWarning($"{blendSetFileName}: Could not parse face preset because {e.Message}");
  480. return;
  481. }
  482. }
  483. else
  484. {
  485. ApplyBackupBlendSet();
  486. CurrentFaceBlendSet = blendSet;
  487. BackupBlendSetValues();
  488. Maid.FaceAnime(blendSet, 0f);
  489. var morph = Body.Face.morph;
  490. foreach (var faceKey in faceKeys)
  491. {
  492. var hash = Utility.GP01FbFaceHash(morph, faceKey);
  493. if (!morph.Contains(hash)) continue;
  494. var blendIndex = (int) morph.hash[hash];
  495. var value = faceKey == "nosefook"
  496. ? Maid.boNoseFook || morph.boNoseFook ? 1f : 0f
  497. : morph.dicBlendSet[CurrentFaceBlendSet][blendIndex];
  498. morph.SetBlendValues(blendIndex, value);
  499. }
  500. morph.FixBlendValues();
  501. }
  502. StopBlink();
  503. OnUpdateMeido();
  504. }
  505. public void SetFaceBlendValue(string faceKey, float value)
  506. {
  507. TMorph morph = Body.Face.morph;
  508. var hash = Utility.GP01FbFaceHash(morph, faceKey);
  509. if (!morph.Contains(hash)) return;
  510. var blendIndex = (int) morph.hash[hash];
  511. if (faceKey == "nosefook") Maid.boNoseFook = morph.boNoseFook = value > 0f;
  512. else morph.dicBlendSet[CurrentFaceBlendSet][blendIndex] = value;
  513. morph.SetBlendValues(blendIndex, value);
  514. morph.FixBlendValues();
  515. }
  516. public float GetFaceBlendValue(string hash)
  517. {
  518. TMorph morph = Body.Face.morph;
  519. if (hash == "nosefook") return (Maid.boNoseFook || morph.boNoseFook) ? 1f : 0f;
  520. hash = Utility.GP01FbFaceHash(morph, hash);
  521. return morph.dicBlendSet[CurrentFaceBlendSet][(int)morph.hash[hash]];
  522. }
  523. public void StopBlink()
  524. {
  525. Maid.MabatakiUpdateStop = true;
  526. Body.Face.morph.EyeMabataki = 0f;
  527. Utility.SetFieldValue(Maid, "MabatakiVal", 0f);
  528. }
  529. public void SetMaskMode(Mask maskMode)
  530. => SetMaskMode(maskMode == Mask.Nude ? MaskMode.Nude : (MaskMode) maskMode);
  531. public void SetMaskMode(MaskMode maskMode)
  532. {
  533. bool invisibleBody = !Body.GetMask(SlotID.body);
  534. Body.SetMaskMode(maskMode);
  535. if (invisibleBody) SetBodyMask(false);
  536. }
  537. public void SetBodyMask(bool enabled)
  538. {
  539. Hashtable table = Utility.GetFieldValue<TBody, Hashtable>(Body, "m_hFoceHide");
  540. foreach (SlotID bodySlot in MaidDressingPane.BodySlots) table[bodySlot] = enabled;
  541. Body.FixMaskFlag();
  542. Body.FixVisibleFlag(false);
  543. }
  544. public void SetCurling(Curl curling, bool enabled)
  545. {
  546. string[] name = curling == Curl.Shift
  547. ? new[] { "panz", "mizugi" }
  548. : new[] { "skirt", "onepiece" };
  549. if (enabled)
  550. {
  551. var action = curling switch
  552. {
  553. Curl.Shift => "パンツずらし",
  554. Curl.Front => "めくれスカート",
  555. _ => "めくれスカート後ろ"
  556. };
  557. Maid.ItemChangeTemp(name[0], action);
  558. Maid.ItemChangeTemp(name[1], action);
  559. }
  560. else
  561. {
  562. Maid.ResetProp(name[0]);
  563. Maid.ResetProp(name[1]);
  564. }
  565. Maid.AllProcProp();
  566. HairGravityControl.Control.OnChangeMekure();
  567. SkirtGravityControl.Control.OnChangeMekure();
  568. }
  569. public void SetMpnProp(MpnAttachProp prop, bool detach)
  570. {
  571. if (detach) Maid.ResetProp(prop.Tag, false);
  572. else Maid.SetProp(prop.Tag, prop.MenuFile, 0, true);
  573. Maid.AllProcProp();
  574. }
  575. public void DetachAllMpnAttach()
  576. {
  577. Maid.ResetProp(MPN.kousoku_lower, false);
  578. Maid.ResetProp(MPN.kousoku_upper, false);
  579. Maid.AllProcProp();
  580. }
  581. public void ApplyGravity(Vector3 position, bool skirt = false)
  582. {
  583. DragPointGravity dragPoint = skirt ? SkirtGravityControl : HairGravityControl;
  584. if (dragPoint.Valid) dragPoint.Control.transform.localPosition = position;
  585. }
  586. private void BackupBlendSetValues()
  587. {
  588. float[] values = Body.Face.morph.dicBlendSet[CurrentFaceBlendSet];
  589. BlendSetValueBackup = new float[values.Length];
  590. values.CopyTo(BlendSetValueBackup, 0);
  591. }
  592. private void ApplyBackupBlendSet()
  593. {
  594. BlendSetValueBackup.CopyTo(Body.Face.morph.dicBlendSet[CurrentFaceBlendSet], 0);
  595. Maid.boNoseFook = false;
  596. }
  597. private CacheBoneDataArray GetCacheBoneData()
  598. {
  599. CacheBoneDataArray cache = Maid.gameObject.GetComponent<CacheBoneDataArray>();
  600. void CreateCache() => cache.CreateCache(Body.GetBone("Bip01"));
  601. if (cache == null)
  602. {
  603. cache = Maid.gameObject.AddComponent<CacheBoneDataArray>();
  604. CreateCache();
  605. }
  606. if (cache.bone_data?.transform == null)
  607. {
  608. Utility.LogDebug("Cache bone_data is null");
  609. CreateCache();
  610. }
  611. return cache;
  612. }
  613. private void InitializeGravityControls()
  614. {
  615. HairGravityControl = MakeGravityControl(skirt: false);
  616. SkirtGravityControl = MakeGravityControl(skirt: true);
  617. }
  618. private DragPointGravity MakeGravityControl(bool skirt = false)
  619. {
  620. DragPointGravity gravityDragpoint = DragPoint.Make<DragPointGravity>(
  621. PrimitiveType.Cube, Vector3.one * 0.12f
  622. );
  623. GravityTransformControl control = DragPointGravity.MakeGravityControl(Maid, skirt);
  624. gravityDragpoint.Initialize(() => control.transform.position, () => Vector3.zero);
  625. gravityDragpoint.Set(control.transform);
  626. gravityDragpoint.gameObject.SetActive(false);
  627. return gravityDragpoint;
  628. }
  629. private void OnUpdateMeido(MeidoUpdateEventArgs args = null)
  630. {
  631. UpdateMeido?.Invoke(this, args ?? MeidoUpdateEventArgs.Empty);
  632. }
  633. private void OnGravityEvent(object sender, EventArgs args) => OnGravityChange((DragPointGravity)sender);
  634. private void OnGravityChange(DragPointGravity dragPoint)
  635. {
  636. GravityEventArgs args = new GravityEventArgs(
  637. dragPoint == SkirtGravityControl, dragPoint.MyObject.transform.localPosition
  638. );
  639. GravityMove?.Invoke(this, args);
  640. }
  641. }
  642. public class GravityEventArgs : EventArgs
  643. {
  644. public Vector3 LocalPosition { get; }
  645. public bool IsSkirt { get; }
  646. public GravityEventArgs(bool isSkirt, Vector3 localPosition)
  647. {
  648. LocalPosition = localPosition;
  649. IsSkirt = isSkirt;
  650. }
  651. }
  652. public readonly struct PoseInfo
  653. {
  654. public string PoseGroup { get; }
  655. public string Pose { get; }
  656. public bool CustomPose { get; }
  657. private static readonly PoseInfo defaultPose =
  658. new PoseInfo(Constants.PoseGroupList[0], Constants.PoseDict[Constants.PoseGroupList[0]][0]);
  659. public static ref readonly PoseInfo DefaultPose => ref defaultPose;
  660. public PoseInfo(string poseGroup, string pose, bool customPose = false)
  661. {
  662. PoseGroup = poseGroup;
  663. Pose = pose;
  664. CustomPose = customPose;
  665. }
  666. }
  667. }