Constants.cs 33 KB

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