Constants.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using Newtonsoft.Json;
  6. using MyRoomCustom;
  7. using UnityEngine;
  8. using wf;
  9. namespace COM3D2.MeidoPhotoStudio.Plugin
  10. {
  11. using static MenuFileUtility;
  12. internal class Constants
  13. {
  14. private static bool beginHandItemInit;
  15. public static readonly string customPosePath;
  16. public static readonly string scenesPath;
  17. public static readonly string kankyoPath;
  18. public static readonly string configPath;
  19. public static readonly int mainWindowID = 765;
  20. public static readonly int messageWindowID = 961;
  21. public static readonly int sceneManagerWindowID = 876;
  22. public static readonly int sceneManagerModalID = 283;
  23. public static readonly int dropdownWindowID = 777;
  24. public enum Window
  25. {
  26. Call, Pose, Face, BG, BG2, Main, Message, Save, SaveModal
  27. }
  28. public enum Scene
  29. {
  30. Daily = 3, Edit = 5
  31. }
  32. public static readonly List<string> PoseGroupList = new List<string>();
  33. public static readonly Dictionary<string, List<string>> PoseDict = new Dictionary<string, List<string>>();
  34. public static readonly Dictionary<string, List<KeyValuePair<string, string>>> CustomPoseDict
  35. = new Dictionary<string, List<KeyValuePair<string, string>>>();
  36. public static readonly List<string> FaceBlendList = new List<string>();
  37. public static readonly List<string> BGList = new List<string>();
  38. public static readonly List<KeyValuePair<string, string>> MyRoomCustomBGList
  39. = new List<KeyValuePair<string, string>>();
  40. public static readonly List<string> DoguCategories = new List<string>();
  41. public static readonly Dictionary<string, List<string>> DoguDict = new Dictionary<string, List<string>>();
  42. public static readonly List<string> MyRoomPropCategories = new List<string>();
  43. public static readonly Dictionary<string, List<MyRoomItem>> MyRoomPropDict
  44. = new Dictionary<string, List<MyRoomItem>>();
  45. public static readonly Dictionary<string, List<ModItem>> ModPropDict
  46. = new Dictionary<string, List<ModItem>>(StringComparer.InvariantCultureIgnoreCase);
  47. public static int CustomPoseGroupsIndex { get; private set; } = -1;
  48. public static int MyRoomCustomBGIndex { get; private set; } = -1;
  49. public static bool HandItemsInitialized { get; private set; } = false;
  50. public static bool MenuFilesInitialized { get; private set; } = false;
  51. public static event EventHandler<MenuFilesEventArgs> MenuFilesChange;
  52. public enum DoguCategory
  53. {
  54. Other, Mob, Desk, HandItem, BGSmall
  55. }
  56. public static readonly Dictionary<DoguCategory, string> customDoguCategories =
  57. new Dictionary<DoguCategory, string>()
  58. {
  59. [DoguCategory.Other] = "other",
  60. [DoguCategory.Mob] = "mob",
  61. [DoguCategory.Desk] = "desk",
  62. [DoguCategory.HandItem] = "handItem",
  63. [DoguCategory.BGSmall] = "bgSmall"
  64. };
  65. static Constants()
  66. {
  67. string modsPath = Path.Combine(Path.GetFullPath(".\\"), @"Mod\MeidoPhotoStudio");
  68. customPosePath = Path.Combine(modsPath, "Custom Poses");
  69. scenesPath = Path.Combine(modsPath, "Scenes");
  70. kankyoPath = Path.Combine(modsPath, "Environments");
  71. configPath = Path.Combine(
  72. Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
  73. @"Config\MeidoPhotoStudio"
  74. );
  75. foreach (string directory in new[] { customPosePath, scenesPath, kankyoPath, configPath })
  76. {
  77. if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
  78. }
  79. }
  80. public static void Initialize()
  81. {
  82. InitializePoses();
  83. InitializeFaceBlends();
  84. InitializeBGs();
  85. InitializeDogu();
  86. InitializeMyRoomProps();
  87. }
  88. public static void InitializePoses()
  89. {
  90. // Load Poses
  91. string poseListJson = File.ReadAllText(Path.Combine(configPath, "mm_pose_list.json"));
  92. List<SerializePoseList> poseLists = JsonConvert.DeserializeObject<List<SerializePoseList>>(poseListJson);
  93. foreach (SerializePoseList poseList in poseLists)
  94. {
  95. PoseDict[poseList.UIName] = poseList.PoseList;
  96. PoseGroupList.Add(poseList.UIName);
  97. }
  98. // Get Other poses that'll go into Normal 2 and Ero 2
  99. string[] com3d2MotionList = GameUty.FileSystem.GetList("motion", AFileSystemBase.ListType.AllFile);
  100. if (com3d2MotionList != null && com3d2MotionList.Length > 0)
  101. {
  102. HashSet<string> poseSet = new HashSet<string>();
  103. foreach (KeyValuePair<string, List<string>> poses in PoseDict)
  104. {
  105. foreach (string pose in poses.Value)
  106. {
  107. poseSet.Add(pose);
  108. }
  109. }
  110. List<string> editPoseList = new List<string>();
  111. List<string> otherPoseList = new List<string>();
  112. List<string> eroPoseList = new List<string>();
  113. foreach (string path in com3d2MotionList)
  114. {
  115. if (Path.GetExtension(path) == ".anm")
  116. {
  117. string file = Path.GetFileNameWithoutExtension(path);
  118. if (!poseSet.Contains(file))
  119. {
  120. if (file.StartsWith("edit_"))
  121. {
  122. editPoseList.Add(file);
  123. }
  124. else if (file != "dance_cm3d2_001_zoukin" && file != "dance_cm3d2_001_mop"
  125. && file != "aruki_1_idougo_f" && file != "sleep2" && file != "stand_akire2"
  126. && !file.EndsWith("_3_") && !file.EndsWith("_5_") && !file.StartsWith("vr_")
  127. && !file.StartsWith("dance_mc") && !file.Contains("_kubi_") && !file.Contains("a01_")
  128. && !file.Contains("b01_") && !file.Contains("b02_") && !file.EndsWith("_m2")
  129. && !file.EndsWith("_m2_once_") && !file.StartsWith("h_") && !file.StartsWith("event_")
  130. && !file.StartsWith("man_") && !file.EndsWith("_m") && !file.Contains("_m_")
  131. && !file.Contains("_man_")
  132. )
  133. {
  134. if (!path.Contains(@"\sex\")) otherPoseList.Add(file);
  135. else eroPoseList.Add(file);
  136. }
  137. }
  138. }
  139. }
  140. PoseDict["normal"].AddRange(editPoseList);
  141. PoseDict["normal2"] = otherPoseList;
  142. PoseDict["ero2"] = eroPoseList;
  143. PoseGroupList.AddRange(new[] { "normal2", "ero2" });
  144. }
  145. CustomPoseGroupsIndex = PoseGroupList.Count;
  146. Action<string> GetPoses = directory =>
  147. {
  148. List<KeyValuePair<string, string>> poseList = new List<KeyValuePair<string, string>>();
  149. foreach (string file in Directory.GetFiles(directory))
  150. {
  151. if (Path.GetExtension(file) == ".anm")
  152. {
  153. string fileName = Path.GetFileNameWithoutExtension(file);
  154. poseList.Add(new KeyValuePair<string, string>(fileName, file));
  155. }
  156. }
  157. if (poseList.Count > 0)
  158. {
  159. string poseGroupName = new DirectoryInfo(directory).Name;
  160. PoseGroupList.Add(poseGroupName);
  161. CustomPoseDict[poseGroupName] = poseList;
  162. }
  163. };
  164. GetPoses(customPosePath);
  165. foreach (string directory in Directory.GetDirectories(customPosePath))
  166. {
  167. GetPoses(directory);
  168. }
  169. }
  170. public static void InitializeFaceBlends()
  171. {
  172. using (CsvParser csvParser = OpenCsvParser("phot_face_list.nei"))
  173. {
  174. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  175. {
  176. if (csvParser.IsCellToExistData(3, cell_y))
  177. {
  178. string blendValue = csvParser.GetCellAsString(3, cell_y);
  179. FaceBlendList.Add(blendValue);
  180. }
  181. }
  182. }
  183. }
  184. public static void InitializeBGs()
  185. {
  186. // Load BGs
  187. PhotoBGData.Create();
  188. List<PhotoBGData> photList = PhotoBGData.data;
  189. // COM3D2 BGs
  190. foreach (PhotoBGData bgData in photList)
  191. {
  192. if (!string.IsNullOrEmpty(bgData.create_prefab_name))
  193. {
  194. string bg = bgData.create_prefab_name;
  195. BGList.Add(bg);
  196. }
  197. }
  198. // CM3D2 BGs
  199. if (GameUty.IsEnabledCompatibilityMode)
  200. {
  201. using (CsvParser csvParser = OpenCsvParser("phot_bg_list.nei", GameUty.FileSystemOld))
  202. {
  203. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  204. {
  205. if (csvParser.IsCellToExistData(3, cell_y))
  206. {
  207. string bg = csvParser.GetCellAsString(3, cell_y);
  208. BGList.Add(bg);
  209. }
  210. }
  211. }
  212. }
  213. Dictionary<string, string> saveDataDict = MyRoomCustom.CreativeRoomManager.GetSaveDataDic();
  214. if (saveDataDict != null)
  215. {
  216. MyRoomCustomBGIndex = BGList.Count;
  217. MyRoomCustomBGList.AddRange(saveDataDict);
  218. }
  219. }
  220. public static void InitializeDogu()
  221. {
  222. foreach (string customCategory in customDoguCategories.Values)
  223. {
  224. DoguDict[customCategory] = new List<string>();
  225. }
  226. InitializeDeskItems();
  227. InitializePhotoBGItems();
  228. InitializeOtherDogu();
  229. InitializeHandItems();
  230. foreach (KeyValuePair<string, UnityEngine.Object> keyValuePair in PhotoBGObjectData.popup_category_list)
  231. {
  232. string category = keyValuePair.Key;
  233. if (category == "マイオブジェクト") continue;
  234. DoguCategories.Add(keyValuePair.Key);
  235. }
  236. foreach (DoguCategory category in Enum.GetValues(typeof(DoguCategory)))
  237. {
  238. DoguCategories.Add(customDoguCategories[category]);
  239. }
  240. }
  241. private static void InitializeOtherDogu()
  242. {
  243. DoguDict[customDoguCategories[DoguCategory.BGSmall]] = BGList;
  244. DoguDict[customDoguCategories[DoguCategory.Mob]].AddRange(new[] {
  245. "Mob_Man_Stand001", "Mob_Man_Stand002", "Mob_Man_Stand003", "Mob_Man_Sit001", "Mob_Man_Sit002",
  246. "Mob_Man_Sit003", "Mob_Girl_Stand001", "Mob_Girl_Stand002", "Mob_Girl_Stand003", "Mob_Girl_Sit001",
  247. "Mob_Girl_Sit002", "Mob_Girl_Sit003", "Salon:65", "Salon:63", "Salon:69"
  248. });
  249. List<string> DoguList = DoguDict[customDoguCategories[DoguCategory.Other]];
  250. string ignoreListPath = Path.Combine(configPath, "mm_ignore_list.json");
  251. string ignoreListJson = File.ReadAllText(ignoreListPath);
  252. string[] ignoreList = JsonConvert.DeserializeObject<IEnumerable<string>>(ignoreListJson).ToArray();
  253. // bg object extend
  254. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  255. doguHashSet.UnionWith(BGList);
  256. doguHashSet.UnionWith(ignoreList);
  257. foreach (KeyValuePair<string, List<string>> keyValuePair in DoguDict)
  258. {
  259. doguHashSet.UnionWith(keyValuePair.Value);
  260. }
  261. string[] com3d2BgList = GameUty.FileSystem.GetList("bg", AFileSystemBase.ListType.AllFile);
  262. foreach (string path in com3d2BgList)
  263. {
  264. if (Path.GetExtension(path) == ".asset_bg" && !path.Contains("myroomcustomize"))
  265. {
  266. string file = Path.GetFileNameWithoutExtension(path);
  267. if (!doguHashSet.Contains(file) && !file.EndsWith("_hit"))
  268. {
  269. DoguList.Add(file);
  270. doguHashSet.Add(file);
  271. }
  272. }
  273. }
  274. // Get cherry picked dogu that I can't find in the game files
  275. string doguExtendPath = Path.Combine(configPath, "mm_dogu_extend.json");
  276. string doguExtendJson = File.ReadAllText(doguExtendPath);
  277. DoguList.AddRange(JsonConvert.DeserializeObject<IEnumerable<string>>(doguExtendJson));
  278. string[] cm3d2BgList = GameUty.FileSystemOld.GetList("bg", AFileSystemBase.ListType.AllFile);
  279. foreach (string path in cm3d2BgList)
  280. {
  281. if (Path.GetExtension(path) == ".asset_bg")
  282. {
  283. string file = Path.GetFileNameWithoutExtension(path);
  284. if (!doguHashSet.Contains(file) && !file.EndsWith("_not_optimisation"))
  285. {
  286. DoguList.Add(file);
  287. }
  288. }
  289. }
  290. }
  291. private static void InitializeDeskItems()
  292. {
  293. HashSet<int> enabledIDs = new HashSet<int>();
  294. CsvCommonIdManager.ReadEnabledIdList(
  295. CsvCommonIdManager.FileSystemType.Normal, true, "desk_item_enabled_id", ref enabledIDs
  296. );
  297. CsvCommonIdManager.ReadEnabledIdList(
  298. CsvCommonIdManager.FileSystemType.Old, true, "desk_item_enabled_id", ref enabledIDs
  299. );
  300. List<string> com3d2DeskDogu = DoguDict[customDoguCategories[DoguCategory.Desk]];
  301. Action<AFileSystemBase> GetDeskItems = fs =>
  302. {
  303. using (CsvParser csvParser = OpenCsvParser("desk_item_detail.nei", fs))
  304. {
  305. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  306. {
  307. if (csvParser.IsCellToExistData(0, cell_y))
  308. {
  309. int cell = csvParser.GetCellAsInteger(0, cell_y);
  310. if (enabledIDs.Contains(cell))
  311. {
  312. string dogu = String.Empty;
  313. if (csvParser.IsCellToExistData(3, cell_y))
  314. {
  315. dogu = csvParser.GetCellAsString(3, cell_y);
  316. }
  317. else if (csvParser.IsCellToExistData(4, cell_y))
  318. {
  319. dogu = csvParser.GetCellAsString(4, cell_y);
  320. }
  321. if (!string.IsNullOrEmpty(dogu))
  322. {
  323. com3d2DeskDogu.Add(dogu);
  324. }
  325. }
  326. }
  327. }
  328. }
  329. };
  330. GetDeskItems(GameUty.FileSystem);
  331. }
  332. private static void InitializePhotoBGItems()
  333. {
  334. PhotoBGObjectData.Create();
  335. List<PhotoBGObjectData> photoBGObjectList = PhotoBGObjectData.data;
  336. List<string> doguCategories = new List<string>();
  337. HashSet<string> addedCategories = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  338. foreach (PhotoBGObjectData photoBGObject in photoBGObjectList)
  339. {
  340. string category = photoBGObject.category;
  341. if (!addedCategories.Contains(category))
  342. {
  343. addedCategories.Add(category);
  344. doguCategories.Add(category);
  345. }
  346. if (!DoguDict.ContainsKey(category))
  347. {
  348. DoguDict[category] = new List<string>();
  349. }
  350. string dogu = String.Empty;
  351. if (!string.IsNullOrEmpty(photoBGObject.create_prefab_name))
  352. {
  353. dogu = photoBGObject.create_prefab_name;
  354. }
  355. else if (!string.IsNullOrEmpty(photoBGObject.create_asset_bundle_name))
  356. {
  357. dogu = photoBGObject.create_asset_bundle_name;
  358. }
  359. else if (!string.IsNullOrEmpty(photoBGObject.direct_file))
  360. {
  361. dogu = photoBGObject.direct_file;
  362. }
  363. if (!string.IsNullOrEmpty(dogu))
  364. {
  365. DoguDict[category].Add(dogu);
  366. }
  367. }
  368. DoguDict["パーティクル"].AddRange(new[] {
  369. "Particle/pLineY", "Particle/pLineP02", "Particle/pHeart01",
  370. "Particle/pLine_act2", "Particle/pstarY_act2"
  371. });
  372. }
  373. private static void InitializeHandItems()
  374. {
  375. if (HandItemsInitialized) return;
  376. if (!MenuFileUtility.MenuFilesReady)
  377. {
  378. if (!beginHandItemInit) MenuFileUtility.MenuFilesReadyChange += (s, a) => InitializeHandItems();
  379. beginHandItemInit = true;
  380. return;
  381. }
  382. MenuDataBase menuDataBase = GameMain.Instance.MenuDataBase;
  383. string ignoreListJson = File.ReadAllText(Path.Combine(configPath, "mm_ignore_list.json"));
  384. string[] ignoreList = JsonConvert.DeserializeObject<IEnumerable<string>>(ignoreListJson).ToArray();
  385. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  386. doguHashSet.UnionWith(BGList);
  387. doguHashSet.UnionWith(ignoreList);
  388. foreach (List<string> doguList in DoguDict.Values)
  389. {
  390. doguHashSet.UnionWith(doguList);
  391. }
  392. string category = customDoguCategories[DoguCategory.HandItem];
  393. for (int i = 0; i < menuDataBase.GetDataSize(); i++)
  394. {
  395. menuDataBase.SetIndex(i);
  396. if ((MPN)menuDataBase.GetCategoryMpn() == MPN.handitem)
  397. {
  398. string menuFileName = menuDataBase.GetMenuFileName();
  399. if (menuDataBase.GetBoDelOnly() || menuFileName.EndsWith("_del.menu")) continue;
  400. string handItemAsOdogu = Utility.HandItemToOdogu(menuFileName);
  401. string isolatedHandItem = menuFileName.Substring(menuFileName.IndexOf('_') + 1);
  402. if (!doguHashSet.Contains(handItemAsOdogu) && !doguHashSet.Contains(isolatedHandItem))
  403. {
  404. doguHashSet.Add(isolatedHandItem);
  405. DoguDict[category].Add(menuFileName);
  406. // Check for a half deck of cards to add the full deck as well
  407. if (menuFileName == "handitemd_cards_i_.menu")
  408. {
  409. DoguDict[category].Add("handiteml_cards_i_.menu");
  410. }
  411. }
  412. }
  413. }
  414. OnMenuFilesChange(MenuFilesEventArgs.HandItems);
  415. HandItemsInitialized = true;
  416. }
  417. private static void InitializeMyRoomProps()
  418. {
  419. PlacementData.CreateData();
  420. List<PlacementData.Data> myRoomData = PlacementData.GetAllDatas(false);
  421. myRoomData.Sort((a, b) =>
  422. {
  423. int res = a.categoryID.CompareTo(b.categoryID);
  424. if (res == 0) res = a.ID.CompareTo(b.ID);
  425. return res;
  426. });
  427. foreach (PlacementData.Data data in myRoomData)
  428. {
  429. string category = PlacementData.GetCategoryName(data.categoryID);
  430. if (!MyRoomPropDict.ContainsKey(category))
  431. {
  432. MyRoomPropCategories.Add(category);
  433. MyRoomPropDict[category] = new List<MyRoomItem>();
  434. }
  435. string asset = !string.IsNullOrEmpty(data.resourceName) ? data.resourceName : data.assetName;
  436. MyRoomItem item = new MyRoomItem() { PrefabName = asset, ID = data.ID };
  437. MyRoomPropDict[category].Add(item);
  438. }
  439. }
  440. private static void InitializeModProps()
  441. {
  442. // TODO: cache menu files
  443. for (int i = 1; i < MenuFileUtility.MenuCategories.Length; i++)
  444. {
  445. ModPropDict[MenuCategories[i]] = new List<ModItem>();
  446. }
  447. if (!Configuration.ModItemsOnly)
  448. {
  449. MenuDataBase menuDatabase = GameMain.Instance.MenuDataBase;
  450. for (int i = 0; i < menuDatabase.GetDataSize(); i++)
  451. {
  452. menuDatabase.SetIndex(i);
  453. ModItem modItem = new ModItem();
  454. if (MenuFileUtility.ParseNativeMenuFile(i, modItem))
  455. {
  456. ModPropDict[modItem.Category].Add(modItem);
  457. }
  458. }
  459. }
  460. MenuFileCache cache = new MenuFileCache();
  461. foreach (string modMenuFile in GameUty.ModOnlysMenuFiles)
  462. {
  463. ModItem modItem;
  464. if (cache.Has(modMenuFile))
  465. {
  466. modItem = cache[modMenuFile];
  467. }
  468. else
  469. {
  470. modItem = new ModItem() { MenuFile = modMenuFile, IsMod = true };
  471. MenuFileUtility.ParseMenuFile(modMenuFile, modItem);
  472. cache[modMenuFile] = modItem;
  473. }
  474. if (MenuFileUtility.ValidBG2MenuFile(modItem)) ModPropDict[modItem.Category].Add(modItem);
  475. }
  476. cache.Serialize();
  477. foreach (string modFile in Menu.GetModFiles())
  478. {
  479. ModItem modItem = new ModItem()
  480. {
  481. MenuFile = modFile,
  482. IsMod = true,
  483. IsOfficialMod = true,
  484. Priority = 1000f
  485. };
  486. if (ParseModMenuFile(modFile, modItem))
  487. {
  488. ModPropDict[modItem.Category].Add(modItem);
  489. }
  490. }
  491. MenuFilesInitialized = true;
  492. }
  493. public static List<ModItem> GetModPropList(string category)
  494. {
  495. if (!Configuration.ModItemsOnly)
  496. {
  497. if (!MenuFileUtility.MenuFilesReady)
  498. {
  499. Debug.Log("Menu files are not ready yet");
  500. return null;
  501. }
  502. }
  503. if (!MenuFilesInitialized) InitializeModProps();
  504. if (!ModPropDict.ContainsKey(category)) return null;
  505. List<ModItem> selectedList = ModPropDict[category];
  506. if (selectedList[0].Icon == null)
  507. {
  508. selectedList.Sort((a, b) =>
  509. {
  510. int res = a.Priority.CompareTo(b.Priority);
  511. if (res == 0) res = string.Compare(a.Name, b.Name);
  512. return res;
  513. });
  514. string previousMenuFile = String.Empty;
  515. selectedList.RemoveAll(item =>
  516. {
  517. if (item.Icon == null)
  518. {
  519. Texture2D icon;
  520. string iconFile = item.IconFile;
  521. if (string.IsNullOrEmpty(iconFile) || !GameUty.FileSystem.IsExistentFile(iconFile))
  522. {
  523. Debug.LogWarning($"Could not find icon '{iconFile}' for menu '{item.MenuFile}");
  524. return true;
  525. }
  526. else
  527. {
  528. try
  529. {
  530. icon = ImportCM.CreateTexture(iconFile);
  531. }
  532. catch
  533. {
  534. try
  535. {
  536. icon = ImportCM.CreateTexture($"tex\\{iconFile}");
  537. }
  538. catch
  539. {
  540. Debug.LogWarning($"Could not load '{iconFile}' for menu '{item.MenuFile}");
  541. return true;
  542. }
  543. }
  544. }
  545. item.Icon = icon;
  546. }
  547. return false;
  548. });
  549. }
  550. return selectedList;
  551. }
  552. private static CsvParser OpenCsvParser(string nei, AFileSystemBase fs)
  553. {
  554. try
  555. {
  556. if (fs.IsExistentFile(nei))
  557. {
  558. AFileBase file = fs.FileOpen(nei);
  559. CsvParser csvParser = new CsvParser();
  560. if (csvParser.Open(file)) return csvParser;
  561. else file?.Dispose();
  562. }
  563. }
  564. catch { }
  565. return null;
  566. }
  567. private static CsvParser OpenCsvParser(string nei)
  568. {
  569. return OpenCsvParser(nei, GameUty.FileSystem);
  570. }
  571. public static void WriteToFile(string name, IEnumerable<string> list)
  572. {
  573. if (Path.GetExtension(name) != ".txt") name += ".txt";
  574. File.WriteAllLines(Path.Combine(configPath, name), list.ToArray());
  575. }
  576. private static void OnMenuFilesChange(MenuFilesEventArgs args)
  577. {
  578. MenuFilesChange?.Invoke(null, args);
  579. }
  580. private class SerializePoseList
  581. {
  582. public string UIName { get; set; }
  583. public List<string> PoseList { get; set; }
  584. }
  585. }
  586. public class MenuFilesEventArgs : EventArgs
  587. {
  588. public EventType Type { get; }
  589. public enum EventType
  590. {
  591. HandItems, MenuFiles
  592. }
  593. public static MenuFilesEventArgs HandItems => new MenuFilesEventArgs(EventType.HandItems);
  594. public static MenuFilesEventArgs MenuFiles => new MenuFilesEventArgs(EventType.MenuFiles);
  595. public MenuFilesEventArgs(EventType type)
  596. {
  597. this.Type = type;
  598. }
  599. }
  600. }