Constants.cs 37 KB

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