PhotoMotionData.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. PhotoMotionData.popup_category_term_list = new List<string>();
  139. for (int l = 0; l < list2.Count; l++)
  140. {
  141. string text = list2[l];
  142. if (!hashSet2.Contains(text))
  143. {
  144. bool flag2 = false;
  145. List<PhotoMotionData> list3 = PhotoMotionData.category_list_[text];
  146. foreach (PhotoMotionData photoMotionData4 in list3)
  147. {
  148. if (!photoMotionData4.is_man_pose)
  149. {
  150. flag2 = true;
  151. break;
  152. }
  153. }
  154. if (flag2)
  155. {
  156. hashSet2.Add(text);
  157. PhotoMotionData.popup_menu_list_.Add(new KeyValuePair<string, UnityEngine.Object>(text, null));
  158. PhotoMotionData.popup_category_term_list.Add("ScenePhotoMode/ポーズ/カテゴリー/" + text);
  159. }
  160. }
  161. }
  162. if (!PhotoMotionData.category_list_.ContainsKey("マイポーズ"))
  163. {
  164. PhotoMotionData.popup_menu_list_.Add(new KeyValuePair<string, UnityEngine.Object>("マイポーズ", null));
  165. PhotoMotionData.popup_category_term_list.Add("ScenePhotoMode/ポーズ/カテゴリー/マイポーズ");
  166. PhotoMotionData.category_list_.Add("マイポーズ", new List<PhotoMotionData>());
  167. }
  168. hashSet2.Clear();
  169. PhotoMotionData.popup_menu_list_for_man_ = new List<KeyValuePair<string, UnityEngine.Object>>();
  170. PhotoMotionData.popup_category_term_list_for_man = new List<string>();
  171. for (int m = 0; m < list2.Count; m++)
  172. {
  173. string text2 = list2[m];
  174. if (!hashSet2.Contains(text2))
  175. {
  176. bool flag3 = false;
  177. List<PhotoMotionData> list4 = PhotoMotionData.category_list_[text2];
  178. foreach (PhotoMotionData photoMotionData5 in list4)
  179. {
  180. if (photoMotionData5.is_man_pose)
  181. {
  182. flag3 = true;
  183. break;
  184. }
  185. }
  186. if (flag3)
  187. {
  188. hashSet2.Add(text2);
  189. PhotoMotionData.popup_menu_list_for_man_.Add(new KeyValuePair<string, UnityEngine.Object>(text2, null));
  190. PhotoMotionData.popup_category_term_list_for_man.Add("ScenePhotoMode/ポーズ/カテゴリー/" + text2);
  191. }
  192. }
  193. }
  194. }
  195. public static PhotoMotionData AddMyPose(string fullpath)
  196. {
  197. string fileName = Path.GetFileName(fullpath);
  198. PhotoMotionData photoMotionData = new PhotoMotionData();
  199. photoMotionData.id = (long)fileName.GetHashCode();
  200. photoMotionData.category = "マイポーズ";
  201. photoMotionData.name = Path.GetFileNameWithoutExtension(fileName);
  202. photoMotionData.direct_file = fullpath;
  203. photoMotionData.is_loop = false;
  204. photoMotionData.call_script_fil = string.Empty;
  205. photoMotionData.call_script_label = string.Empty;
  206. photoMotionData.is_mod = false;
  207. photoMotionData.is_mypose = true;
  208. byte[] array = new byte[2];
  209. try
  210. {
  211. using (FileStream fileStream = new FileStream(photoMotionData.direct_file, FileMode.Open, FileAccess.Read))
  212. {
  213. using (BinaryReader binaryReader = new BinaryReader(fileStream))
  214. {
  215. string b = binaryReader.ReadString();
  216. if ("CM3D2_ANIM" != b)
  217. {
  218. return null;
  219. }
  220. int num = binaryReader.ReadInt32();
  221. if (1001 <= num)
  222. {
  223. fileStream.Seek(-2L, SeekOrigin.End);
  224. fileStream.Read(array, 0, array.Length);
  225. photoMotionData.use_animekey_mune_l = (array[0] != 0);
  226. photoMotionData.use_animekey_mune_r = (array[1] != 0);
  227. }
  228. else
  229. {
  230. photoMotionData.use_animekey_mune_l = (photoMotionData.use_animekey_mune_r = false);
  231. }
  232. }
  233. }
  234. }
  235. catch
  236. {
  237. }
  238. PhotoMotionData.motion_data_.Add(photoMotionData);
  239. return photoMotionData;
  240. }
  241. public string nameTerm
  242. {
  243. get
  244. {
  245. return (!(this.category == "マイルーム")) ? ("ScenePhotoMode/ポーズ/" + this.id.ToString() + "/名前") : string.Empty;
  246. }
  247. }
  248. public void Apply(Maid maid)
  249. {
  250. GameMain.Instance.ScriptMgr.StopMotionScript();
  251. if (maid == null || maid.body0 == null || maid.body0.m_Bones == null || maid.IsBusy)
  252. {
  253. return;
  254. }
  255. if (!maid.boMAN)
  256. {
  257. maid.body0.MuneYureL((float)((!this.use_animekey_mune_l) ? 1 : 0));
  258. maid.body0.MuneYureR((float)((!this.use_animekey_mune_r) ? 1 : 0));
  259. maid.body0.jbMuneL.enabled = !this.use_animekey_mune_l;
  260. maid.body0.jbMuneR.enabled = !this.use_animekey_mune_l;
  261. }
  262. if (!string.IsNullOrEmpty(this.direct_file))
  263. {
  264. maid.IKTargetToBone("左手", null, "無し", Vector3.zero, IKCtrlData.IKAttachType.Point, false, false, IKCtrlData.IKExecTiming.Normal);
  265. maid.IKTargetToBone("右手", null, "無し", Vector3.zero, IKCtrlData.IKAttachType.Point, false, false, IKCtrlData.IKExecTiming.Normal);
  266. if (!this.is_mod && !this.is_mypose)
  267. {
  268. maid.CrossFade(this.direct_file, false, this.is_loop, false, 0f, 1f);
  269. }
  270. else
  271. {
  272. byte[] array = new byte[0];
  273. try
  274. {
  275. using (FileStream fileStream = new FileStream(this.direct_file, FileMode.Open, FileAccess.Read))
  276. {
  277. array = new byte[fileStream.Length];
  278. fileStream.Read(array, 0, array.Length);
  279. }
  280. }
  281. catch
  282. {
  283. }
  284. if (0 < array.Length)
  285. {
  286. maid.body0.CrossFade(this.id.ToString(), array, false, this.is_loop, false, 0f, 1f);
  287. Maid.AutoTwist[] array2 = new Maid.AutoTwist[]
  288. {
  289. Maid.AutoTwist.ShoulderL,
  290. Maid.AutoTwist.ShoulderR,
  291. Maid.AutoTwist.WristL,
  292. Maid.AutoTwist.WristR,
  293. Maid.AutoTwist.ThighL,
  294. Maid.AutoTwist.ThighR
  295. };
  296. for (int i = 0; i < array2.Length; i++)
  297. {
  298. maid.SetAutoTwist(array2[i], true);
  299. }
  300. }
  301. }
  302. }
  303. else if (!string.IsNullOrEmpty(this.call_script_fil) && !string.IsNullOrEmpty(this.call_script_label))
  304. {
  305. CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  306. int sloat = 0;
  307. for (int j = 0; j < characterMgr.GetMaidCount(); j++)
  308. {
  309. if (maid == characterMgr.GetMaid(j))
  310. {
  311. sloat = j;
  312. break;
  313. }
  314. }
  315. GameMain.Instance.ScriptMgr.LoadMotionScript(sloat, false, this.call_script_fil, this.call_script_label, maid.status.guid, string.Empty, true, true, false);
  316. }
  317. }
  318. public static List<PhotoMotionData> data
  319. {
  320. get
  321. {
  322. return PhotoMotionData.motion_data_;
  323. }
  324. }
  325. public static PhotoMotionData init_data
  326. {
  327. get
  328. {
  329. return PhotoMotionData.init_data_;
  330. }
  331. }
  332. public static PhotoMotionData init_data_for_man
  333. {
  334. get
  335. {
  336. return PhotoMotionData.init_data_for_man_;
  337. }
  338. }
  339. public static Dictionary<string, List<PhotoMotionData>> category_list
  340. {
  341. get
  342. {
  343. return PhotoMotionData.category_list_;
  344. }
  345. }
  346. public static List<string> popup_category_term_list { get; private set; }
  347. public static List<KeyValuePair<string, UnityEngine.Object>> popup_category_list
  348. {
  349. get
  350. {
  351. return PhotoMotionData.popup_menu_list_;
  352. }
  353. }
  354. public static List<string> popup_category_term_list_for_man { get; private set; }
  355. public static List<KeyValuePair<string, UnityEngine.Object>> popup_category_list_for_man
  356. {
  357. get
  358. {
  359. return PhotoMotionData.popup_menu_list_for_man_;
  360. }
  361. }
  362. public static PhotoMotionData Get(long id)
  363. {
  364. for (int i = 0; i < PhotoMotionData.motion_data_.Count; i++)
  365. {
  366. if (PhotoMotionData.motion_data_[i].id == id)
  367. {
  368. return PhotoMotionData.motion_data_[i];
  369. }
  370. }
  371. return null;
  372. }
  373. public long id;
  374. public string category;
  375. public string name;
  376. public string direct_file;
  377. public bool is_loop;
  378. public string call_script_fil;
  379. public string call_script_label;
  380. public bool is_mod;
  381. public bool is_mypose;
  382. public bool use_animekey_mune_l;
  383. public bool use_animekey_mune_r;
  384. public bool is_man_pose;
  385. private static PhotoMotionData init_data_;
  386. private static PhotoMotionData init_data_for_man_;
  387. private static List<PhotoMotionData> motion_data_;
  388. private static Dictionary<string, List<PhotoMotionData>> category_list_;
  389. private static List<KeyValuePair<string, UnityEngine.Object>> popup_menu_list_;
  390. private static List<KeyValuePair<string, UnityEngine.Object>> popup_menu_list_for_man_;
  391. }