PhotoMotionData.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. using wf;
  6. public class PhotoMotionData
  7. {
  8. private PhotoMotionData()
  9. {
  10. }
  11. public static void Create()
  12. {
  13. PhotoMotionData.motion_data_ = new List<PhotoMotionData>();
  14. HashSet<int> hashSet = new HashSet<int>();
  15. CsvCommonIdManager.ReadEnabledIdList(CsvCommonIdManager.FileSystemType.Normal, true, "phot_motion_enabled_list", ref hashSet);
  16. using (AFileBase afileBase = GameUty.FileSystem.FileOpen("phot_motion_list.nei"))
  17. {
  18. using (CsvParser csvParser = new CsvParser())
  19. {
  20. bool condition = csvParser.Open(afileBase);
  21. NDebug.Assert(condition, "phot_motion_list.nei\nopen failed.");
  22. for (int i = 1; i < csvParser.max_cell_y; i++)
  23. {
  24. if (csvParser.IsCellToExistData(0, i) && hashSet.Contains(csvParser.GetCellAsInteger(0, i)))
  25. {
  26. int num = 0;
  27. PhotoMotionData photoMotionData = new PhotoMotionData();
  28. photoMotionData.id = (long)csvParser.GetCellAsInteger(num++, i);
  29. photoMotionData.category = csvParser.GetCellAsString(num++, i);
  30. photoMotionData.name = csvParser.GetCellAsString(num++, i);
  31. photoMotionData.direct_file = csvParser.GetCellAsString(num++, i);
  32. photoMotionData.is_loop = (csvParser.GetCellAsString(num++, i) == "○");
  33. photoMotionData.call_script_fil = csvParser.GetCellAsString(num++, i);
  34. photoMotionData.call_script_label = csvParser.GetCellAsString(num++, i);
  35. photoMotionData.is_mod = false;
  36. string cellAsString = csvParser.GetCellAsString(num++, i);
  37. bool flag = csvParser.GetCellAsString(num++, i) == "○";
  38. photoMotionData.use_animekey_mune_l = (photoMotionData.use_animekey_mune_r = flag);
  39. photoMotionData.is_man_pose = (csvParser.GetCellAsString(num++, i) == "○");
  40. if (string.IsNullOrEmpty(cellAsString) || PluginData.IsEnabled(cellAsString))
  41. {
  42. PhotoMotionData.motion_data_.Add(photoMotionData);
  43. if (photoMotionData.call_script_fil == "h_edit_pose_001.ks" && photoMotionData.call_script_label == "*ポーズ001")
  44. {
  45. PhotoMotionData.init_data_ = photoMotionData;
  46. }
  47. else if (photoMotionData.is_man_pose && PhotoMotionData.init_data_for_man_ == null)
  48. {
  49. PhotoMotionData.init_data_for_man_ = photoMotionData;
  50. }
  51. }
  52. }
  53. }
  54. }
  55. }
  56. Action<string, List<string>> CheckModFile = null;
  57. CheckModFile = delegate(string path, List<string> result_list)
  58. {
  59. string[] files = Directory.GetFiles(path);
  60. for (int n = 0; n < files.Length; n++)
  61. {
  62. if (Path.GetExtension(files[n]) == ".anm")
  63. {
  64. result_list.Add(files[n]);
  65. }
  66. }
  67. string[] directories = Directory.GetDirectories(path);
  68. for (int num4 = 0; num4 < directories.Length; num4++)
  69. {
  70. CheckModFile(directories[num4], result_list);
  71. }
  72. };
  73. List<string> list = new List<string>();
  74. CheckModFile(PhotoWindowManager.path_photo_mod_motion, list);
  75. CRC32 crc = new CRC32();
  76. for (int j = 0; j < list.Count; j++)
  77. {
  78. long num2 = 0L;
  79. try
  80. {
  81. using (FileStream fileStream = new FileStream(list[j], FileMode.Open, FileAccess.Read))
  82. {
  83. byte[] array = new byte[fileStream.Length];
  84. fileStream.Read(array, 0, array.Length);
  85. uint num3 = crc.ComputeChecksum(array);
  86. num2 = (long)((ulong)-1 + (ulong)num3);
  87. }
  88. }
  89. catch
  90. {
  91. }
  92. if ((ulong)-1 <= (ulong)num2)
  93. {
  94. string fileName = Path.GetFileName(list[j]);
  95. PhotoMotionData photoMotionData2 = new PhotoMotionData();
  96. photoMotionData2.id = num2;
  97. photoMotionData2.category = "Mod";
  98. photoMotionData2.name = Path.GetFileNameWithoutExtension(fileName);
  99. photoMotionData2.direct_file = list[j];
  100. photoMotionData2.is_loop = false;
  101. photoMotionData2.call_script_fil = string.Empty;
  102. photoMotionData2.call_script_label = string.Empty;
  103. photoMotionData2.is_mod = true;
  104. PhotoMotionData.motion_data_.Add(photoMotionData2);
  105. }
  106. }
  107. Action<string, List<string>> action = delegate(string path, List<string> result_list)
  108. {
  109. string[] files = Directory.GetFiles(path);
  110. for (int n = 0; n < files.Length; n++)
  111. {
  112. if (Path.GetExtension(files[n]) == ".anm")
  113. {
  114. result_list.Add(files[n]);
  115. }
  116. }
  117. };
  118. list.Clear();
  119. action(PhotoModePoseSave.folder_path, list);
  120. foreach (string fullpath in list)
  121. {
  122. PhotoMotionData.AddMyPose(fullpath);
  123. }
  124. List<string> list2 = new List<string>();
  125. PhotoMotionData.category_list_ = new Dictionary<string, List<PhotoMotionData>>();
  126. for (int k = 0; k < PhotoMotionData.data.Count; k++)
  127. {
  128. PhotoMotionData photoMotionData3 = PhotoMotionData.data[k];
  129. if (!PhotoMotionData.category_list_.ContainsKey(photoMotionData3.category))
  130. {
  131. PhotoMotionData.category_list_.Add(photoMotionData3.category, new List<PhotoMotionData>());
  132. list2.Add(photoMotionData3.category);
  133. }
  134. PhotoMotionData.category_list_[photoMotionData3.category].Add(photoMotionData3);
  135. }
  136. HashSet<string> hashSet2 = new HashSet<string>();
  137. PhotoMotionData.popup_menu_list_ = new List<KeyValuePair<string, UnityEngine.Object>>();
  138. for (int l = 0; l < list2.Count; l++)
  139. {
  140. string text = list2[l];
  141. if (!hashSet2.Contains(text))
  142. {
  143. bool flag2 = false;
  144. List<PhotoMotionData> list3 = PhotoMotionData.category_list_[text];
  145. foreach (PhotoMotionData photoMotionData4 in list3)
  146. {
  147. if (!photoMotionData4.is_man_pose)
  148. {
  149. flag2 = true;
  150. break;
  151. }
  152. }
  153. if (flag2)
  154. {
  155. hashSet2.Add(text);
  156. PhotoMotionData.popup_menu_list_.Add(new KeyValuePair<string, UnityEngine.Object>(text, null));
  157. }
  158. }
  159. }
  160. if (!PhotoMotionData.category_list_.ContainsKey("マイポーズ"))
  161. {
  162. PhotoMotionData.popup_menu_list_.Add(new KeyValuePair<string, UnityEngine.Object>("マイポーズ", null));
  163. PhotoMotionData.category_list_.Add("マイポーズ", new List<PhotoMotionData>());
  164. }
  165. hashSet2.Clear();
  166. PhotoMotionData.popup_menu_list_for_man_ = new List<KeyValuePair<string, UnityEngine.Object>>();
  167. for (int m = 0; m < list2.Count; m++)
  168. {
  169. string text2 = list2[m];
  170. if (!hashSet2.Contains(text2))
  171. {
  172. bool flag3 = false;
  173. List<PhotoMotionData> list4 = PhotoMotionData.category_list_[text2];
  174. foreach (PhotoMotionData photoMotionData5 in list4)
  175. {
  176. if (photoMotionData5.is_man_pose)
  177. {
  178. flag3 = true;
  179. break;
  180. }
  181. }
  182. if (flag3)
  183. {
  184. hashSet2.Add(text2);
  185. PhotoMotionData.popup_menu_list_for_man_.Add(new KeyValuePair<string, UnityEngine.Object>(text2, null));
  186. }
  187. }
  188. }
  189. }
  190. public static PhotoMotionData AddMyPose(string fullpath)
  191. {
  192. string fileName = Path.GetFileName(fullpath);
  193. PhotoMotionData photoMotionData = new PhotoMotionData();
  194. photoMotionData.id = (long)fileName.GetHashCode();
  195. photoMotionData.category = "マイポーズ";
  196. photoMotionData.name = Path.GetFileNameWithoutExtension(fileName);
  197. photoMotionData.direct_file = fullpath;
  198. photoMotionData.is_loop = false;
  199. photoMotionData.call_script_fil = string.Empty;
  200. photoMotionData.call_script_label = string.Empty;
  201. photoMotionData.is_mod = false;
  202. photoMotionData.is_mypose = true;
  203. byte[] array = new byte[2];
  204. try
  205. {
  206. using (FileStream fileStream = new FileStream(photoMotionData.direct_file, FileMode.Open, FileAccess.Read))
  207. {
  208. using (BinaryReader binaryReader = new BinaryReader(fileStream))
  209. {
  210. string b = binaryReader.ReadString();
  211. if ("CM3D2_ANIM" != b)
  212. {
  213. return null;
  214. }
  215. int num = binaryReader.ReadInt32();
  216. if (1001 <= num)
  217. {
  218. fileStream.Seek(-2L, SeekOrigin.End);
  219. fileStream.Read(array, 0, array.Length);
  220. photoMotionData.use_animekey_mune_l = (array[0] != 0);
  221. photoMotionData.use_animekey_mune_r = (array[1] != 0);
  222. }
  223. else
  224. {
  225. photoMotionData.use_animekey_mune_l = (photoMotionData.use_animekey_mune_r = false);
  226. }
  227. }
  228. }
  229. }
  230. catch
  231. {
  232. }
  233. PhotoMotionData.motion_data_.Add(photoMotionData);
  234. return photoMotionData;
  235. }
  236. public void Apply(Maid maid)
  237. {
  238. GameMain.Instance.ScriptMgr.StopMotionScript();
  239. if (maid == null || maid.body0 == null || maid.body0.m_Bones == null || maid.IsBusy)
  240. {
  241. return;
  242. }
  243. if (!maid.boMAN)
  244. {
  245. maid.body0.MuneYureL((float)((!this.use_animekey_mune_l) ? 1 : 0));
  246. maid.body0.MuneYureR((float)((!this.use_animekey_mune_r) ? 1 : 0));
  247. maid.body0.jbMuneL.enabled = (maid.body0.GetMuneYureL() != 0f);
  248. maid.body0.jbMuneR.enabled = (maid.body0.GetMuneYureR() != 0f);
  249. }
  250. if (!string.IsNullOrEmpty(this.direct_file))
  251. {
  252. maid.IKTargetToBone("左手", null, "無し", Vector3.zero, IKMgrData.IKAttachType.Point, false);
  253. maid.IKTargetToBone("右手", null, "無し", Vector3.zero, IKMgrData.IKAttachType.Point, false);
  254. if (!this.is_mod && !this.is_mypose)
  255. {
  256. maid.CrossFade(this.direct_file, false, this.is_loop, false, 0f, 1f);
  257. }
  258. else
  259. {
  260. byte[] array = new byte[0];
  261. try
  262. {
  263. using (FileStream fileStream = new FileStream(this.direct_file, FileMode.Open, FileAccess.Read))
  264. {
  265. array = new byte[fileStream.Length];
  266. fileStream.Read(array, 0, array.Length);
  267. }
  268. }
  269. catch
  270. {
  271. }
  272. if (0 < array.Length)
  273. {
  274. maid.body0.CrossFade(this.id.ToString(), array, false, this.is_loop, false, 0f, 1f);
  275. Maid.AutoTwist[] array2 = new Maid.AutoTwist[]
  276. {
  277. Maid.AutoTwist.ShoulderL,
  278. Maid.AutoTwist.ShoulderR,
  279. Maid.AutoTwist.WristL,
  280. Maid.AutoTwist.WristR,
  281. Maid.AutoTwist.ThighL,
  282. Maid.AutoTwist.ThighR
  283. };
  284. for (int i = 0; i < array2.Length; i++)
  285. {
  286. maid.SetAutoTwist(array2[i], true);
  287. }
  288. }
  289. }
  290. }
  291. else if (!string.IsNullOrEmpty(this.call_script_fil) && !string.IsNullOrEmpty(this.call_script_label))
  292. {
  293. CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  294. int sloat = 0;
  295. for (int j = 0; j < characterMgr.GetMaidCount(); j++)
  296. {
  297. if (maid == characterMgr.GetMaid(j))
  298. {
  299. sloat = j;
  300. break;
  301. }
  302. }
  303. GameMain.Instance.ScriptMgr.LoadMotionScript(sloat, false, this.call_script_fil, this.call_script_label, maid.status.guid, string.Empty, true, true);
  304. }
  305. }
  306. public static List<PhotoMotionData> data
  307. {
  308. get
  309. {
  310. return PhotoMotionData.motion_data_;
  311. }
  312. }
  313. public static PhotoMotionData init_data
  314. {
  315. get
  316. {
  317. return PhotoMotionData.init_data_;
  318. }
  319. }
  320. public static PhotoMotionData init_data_for_man
  321. {
  322. get
  323. {
  324. return PhotoMotionData.init_data_for_man_;
  325. }
  326. }
  327. public static Dictionary<string, List<PhotoMotionData>> category_list
  328. {
  329. get
  330. {
  331. return PhotoMotionData.category_list_;
  332. }
  333. }
  334. public static List<KeyValuePair<string, UnityEngine.Object>> popup_category_list
  335. {
  336. get
  337. {
  338. return PhotoMotionData.popup_menu_list_;
  339. }
  340. }
  341. public static List<KeyValuePair<string, UnityEngine.Object>> popup_category_list_for_man
  342. {
  343. get
  344. {
  345. return PhotoMotionData.popup_menu_list_for_man_;
  346. }
  347. }
  348. public static PhotoMotionData Get(long id)
  349. {
  350. for (int i = 0; i < PhotoMotionData.motion_data_.Count; i++)
  351. {
  352. if (PhotoMotionData.motion_data_[i].id == id)
  353. {
  354. return PhotoMotionData.motion_data_[i];
  355. }
  356. }
  357. return null;
  358. }
  359. public long id;
  360. public string category;
  361. public string name;
  362. public string direct_file;
  363. public bool is_loop;
  364. public string call_script_fil;
  365. public string call_script_label;
  366. public bool is_mod;
  367. public bool is_mypose;
  368. public bool use_animekey_mune_l;
  369. public bool use_animekey_mune_r;
  370. public bool is_man_pose;
  371. private static PhotoMotionData init_data_;
  372. private static PhotoMotionData init_data_for_man_;
  373. private static List<PhotoMotionData> motion_data_;
  374. private static Dictionary<string, List<PhotoMotionData>> category_list_;
  375. private static List<KeyValuePair<string, UnityEngine.Object>> popup_menu_list_;
  376. private static List<KeyValuePair<string, UnityEngine.Object>> popup_menu_list_for_man_;
  377. }