Constants.cs 35 KB

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