Constants.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  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<PresetChangeEventArgs> CustomPoseChange;
  72. public static event EventHandler<PresetChangeEventArgs> CustomHandChange;
  73. public static event EventHandler<PresetChangeEventArgs> 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. CustomFaceDict[category] = new List<string>();
  154. }
  155. else category = faceGroup;
  156. CustomFaceDict[category].Add(fullPath);
  157. CustomFaceDict[category].Sort();
  158. CustomFaceChange?.Invoke(null, new PresetChangeEventArgs(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 PresetChangeEventArgs(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. int gameVersion = Misc.GAME_VERSION; // get game version from user's Assembly-CSharp
  216. XDocument finalXml = new XDocument(new XDeclaration("1.0", "utf-8", "true"),
  217. new XComment("CM3D2 FingerData"),
  218. new XElement("FingerData",
  219. new XElement("GameVersion", gameVersion),
  220. new XElement("RightData", right),
  221. new XElement("BinaryData", Convert.ToBase64String(handBinary))
  222. )
  223. );
  224. finalXml.Save(fullPath);
  225. FileInfo fileInfo = new FileInfo(fullPath);
  226. string category = fileInfo.Directory.Name;
  227. string handGroup = CustomHandGroupList.Find(
  228. group => string.Equals(category, group, StringComparison.InvariantCultureIgnoreCase)
  229. );
  230. if (string.IsNullOrEmpty(handGroup))
  231. {
  232. CustomHandGroupList.Add(category);
  233. CustomHandDict[category] = new List<string>();
  234. }
  235. else category = handGroup;
  236. CustomHandDict[category].Add(fullPath);
  237. CustomHandDict[category].Sort();
  238. CustomHandChange?.Invoke(null, new PresetChangeEventArgs(fullPath, category));
  239. }
  240. public static void InitializeScenes()
  241. {
  242. SceneDirectoryList.Clear();
  243. KankyoDirectoryList.Clear();
  244. SceneDirectoryList.Add(sceneDirectory);
  245. foreach (string directory in Directory.GetDirectories(scenesPath))
  246. {
  247. SceneDirectoryList.Add(new DirectoryInfo(directory).Name);
  248. }
  249. KankyoDirectoryList.Add(kankyoDirectory);
  250. foreach (string directory in Directory.GetDirectories(kankyoPath))
  251. {
  252. KankyoDirectoryList.Add(new DirectoryInfo(directory).Name);
  253. }
  254. }
  255. public static void InitializePoses()
  256. {
  257. // Load Poses
  258. string poseListJson = File.ReadAllText(Path.Combine(configPath, "Database\\mm_pose_list.json"));
  259. foreach (SerializePoseList poseList in JsonConvert.DeserializeObject<List<SerializePoseList>>(poseListJson))
  260. {
  261. PoseDict[poseList.UIName] = poseList.PoseList;
  262. PoseGroupList.Add(poseList.UIName);
  263. }
  264. // Get Other poses that'll go into Normal 2 and Ero 2
  265. string[] com3d2MotionList = GameUty.FileSystem.GetList("motion", AFileSystemBase.ListType.AllFile);
  266. if (com3d2MotionList?.Length > 0)
  267. {
  268. HashSet<string> poseSet = new HashSet<string>();
  269. foreach (List<string> poses in PoseDict.Values)
  270. {
  271. poseSet.UnionWith(poses);
  272. }
  273. List<string> editPoseList = new List<string>();
  274. List<string> otherPoseList = new List<string>();
  275. List<string> eroPoseList = new List<string>();
  276. foreach (string path in com3d2MotionList)
  277. {
  278. if (Path.GetExtension(path) == ".anm")
  279. {
  280. string file = Path.GetFileNameWithoutExtension(path);
  281. if (!poseSet.Contains(file))
  282. {
  283. if (file.StartsWith("edit_"))
  284. {
  285. editPoseList.Add(file);
  286. }
  287. else if (file != "dance_cm3d2_001_zoukin" && file != "dance_cm3d2_001_mop"
  288. && file != "aruki_1_idougo_f" && file != "sleep2" && file != "stand_akire2"
  289. && !file.EndsWith("_3_") && !file.EndsWith("_5_") && !file.StartsWith("vr_")
  290. && !file.StartsWith("dance_mc") && !file.Contains("_kubi_") && !file.Contains("a01_")
  291. && !file.Contains("b01_") && !file.Contains("b02_") && !file.EndsWith("_m2")
  292. && !file.EndsWith("_m2_once_") && !file.StartsWith("h_") && !file.StartsWith("event_")
  293. && !file.StartsWith("man_") && !file.EndsWith("_m") && !file.Contains("_m_")
  294. && !file.Contains("_man_")
  295. )
  296. {
  297. if (path.Contains(@"\sex\")) eroPoseList.Add(file);
  298. else otherPoseList.Add(file);
  299. }
  300. }
  301. }
  302. }
  303. PoseDict["normal"].AddRange(editPoseList);
  304. PoseDict["normal2"] = otherPoseList;
  305. PoseDict["ero2"] = eroPoseList;
  306. PoseGroupList.AddRange(new[] { "normal2", "ero2" });
  307. }
  308. InitializeCustomPoses();
  309. }
  310. public static void InitializeCustomPoses()
  311. {
  312. void GetPoses(string directory)
  313. {
  314. List<string> poseList = Directory.GetFiles(directory)
  315. .Where(file => Path.GetExtension(file) == ".anm").ToList();
  316. if (poseList.Count > 0)
  317. {
  318. string poseGroupName = new DirectoryInfo(directory).Name;
  319. if (poseGroupName != customPoseDirectory) CustomPoseGroupList.Add(poseGroupName);
  320. CustomPoseDict[poseGroupName] = poseList;
  321. }
  322. }
  323. CustomPoseGroupList.Clear();
  324. CustomPoseDict.Clear();
  325. CustomPoseGroupList.Add(customPoseDirectory);
  326. CustomPoseDict[customPoseDirectory] = new List<string>();
  327. GetPoses(customPosePath);
  328. foreach (string directory in Directory.GetDirectories(customPosePath)) GetPoses(directory);
  329. CustomPoseChange?.Invoke(null, PresetChangeEventArgs.Empty);
  330. }
  331. public static void InitializeHandPresets()
  332. {
  333. void GetPresets(string directory)
  334. {
  335. IEnumerable<string> presetList = Directory.GetFiles(directory)
  336. .Where(file => Path.GetExtension(file) == ".xml");
  337. if (presetList.Any())
  338. {
  339. string presetCategory = new DirectoryInfo(directory).Name;
  340. if (presetCategory != customHandDirectory) CustomHandGroupList.Add(presetCategory);
  341. CustomHandDict[presetCategory] = new List<string>(presetList);
  342. }
  343. }
  344. CustomHandGroupList.Clear();
  345. CustomHandDict.Clear();
  346. CustomHandGroupList.Add(customHandDirectory);
  347. CustomHandDict[customHandDirectory] = new List<string>();
  348. GetPresets(customHandPath);
  349. foreach (string directory in Directory.GetDirectories(customHandPath)) GetPresets(directory);
  350. CustomHandChange?.Invoke(null, PresetChangeEventArgs.Empty);
  351. }
  352. public static void InitializeFaceBlends()
  353. {
  354. PhotoFaceData.Create();
  355. FaceGroupList.AddRange(PhotoFaceData.popup_category_list.Select(kvp => kvp.Key));
  356. foreach (KeyValuePair<string, List<PhotoFaceData>> kvp in PhotoFaceData.category_list)
  357. {
  358. FaceDict[kvp.Key] = kvp.Value.Select(data => data.setting_name).ToList();
  359. }
  360. InitializeCustomFaceBlends();
  361. }
  362. public static void InitializeCustomFaceBlends()
  363. {
  364. void GetFacePresets(string directory)
  365. {
  366. List<string> presetList = Directory.GetFiles(directory)
  367. .Where(file => Path.GetExtension(file) == ".xml").ToList();
  368. if (presetList.Count > 0)
  369. {
  370. string faceGroupName = new DirectoryInfo(directory).Name;
  371. if (faceGroupName != customFaceDirectory) CustomFaceGroupList.Add(faceGroupName);
  372. CustomFaceDict[faceGroupName] = presetList;
  373. }
  374. }
  375. CustomFaceGroupList.Clear();
  376. CustomFaceDict.Clear();
  377. CustomFaceGroupList.Add(customFaceDirectory);
  378. CustomFaceDict[customFaceDirectory] = new List<string>();
  379. GetFacePresets(customFacePath);
  380. foreach (string directory in Directory.GetDirectories(customFacePath)) GetFacePresets(directory);
  381. CustomFaceChange?.Invoke(null, PresetChangeEventArgs.Empty);
  382. }
  383. public static void InitializeBGs()
  384. {
  385. // Load BGs
  386. PhotoBGData.Create();
  387. // COM3D2 BGs
  388. foreach (PhotoBGData bgData in PhotoBGData.data)
  389. {
  390. if (!string.IsNullOrEmpty(bgData.create_prefab_name))
  391. {
  392. string bg = bgData.create_prefab_name;
  393. BGList.Add(bg);
  394. }
  395. }
  396. // CM3D2 BGs
  397. if (GameUty.IsEnabledCompatibilityMode)
  398. {
  399. using (CsvParser csvParser = OpenCsvParser("phot_bg_list.nei", GameUty.FileSystemOld))
  400. {
  401. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  402. {
  403. if (csvParser.IsCellToExistData(3, cell_y))
  404. {
  405. string bg = csvParser.GetCellAsString(3, cell_y);
  406. BGList.Add(bg);
  407. }
  408. }
  409. }
  410. }
  411. Dictionary<string, string> saveDataDict = CreativeRoomManager.GetSaveDataDic();
  412. if (saveDataDict != null)
  413. {
  414. MyRoomCustomBGIndex = BGList.Count;
  415. MyRoomCustomBGList.AddRange(saveDataDict);
  416. }
  417. }
  418. public static void InitializeDogu()
  419. {
  420. foreach (string customCategory in customDoguCategories.Values)
  421. {
  422. DoguDict[customCategory] = new List<string>();
  423. }
  424. InitializeDeskItems();
  425. InitializePhotoBGItems();
  426. InitializeOtherDogu();
  427. InitializeHandItems();
  428. foreach (string category in PhotoBGObjectData.popup_category_list.Select(kvp => kvp.Key))
  429. {
  430. if (category == "マイオブジェクト") continue;
  431. DoguCategories.Add(category);
  432. }
  433. foreach (DoguCategory category in Enum.GetValues(typeof(DoguCategory)))
  434. {
  435. DoguCategories.Add(customDoguCategories[category]);
  436. }
  437. }
  438. private static void InitializeOtherDogu()
  439. {
  440. DoguDict[customDoguCategories[DoguCategory.BGSmall]] = BGList;
  441. DoguDict[customDoguCategories[DoguCategory.Mob]].AddRange(new[] {
  442. "Mob_Man_Stand001", "Mob_Man_Stand002", "Mob_Man_Stand003", "Mob_Man_Sit001", "Mob_Man_Sit002",
  443. "Mob_Man_Sit003", "Mob_Girl_Stand001", "Mob_Girl_Stand002", "Mob_Girl_Stand003", "Mob_Girl_Sit001",
  444. "Mob_Girl_Sit002", "Mob_Girl_Sit003", "Salon:65", "Salon:63", "Salon:69"
  445. });
  446. List<string> DoguList = DoguDict[customDoguCategories[DoguCategory.Other]];
  447. string ignoreListPath = Path.Combine(configPath, "Database\\bg_ignore_list.json");
  448. string ignoreListJson = File.ReadAllText(ignoreListPath);
  449. string[] ignoreList = JsonConvert.DeserializeObject<string[]>(ignoreListJson);
  450. // bg object extend
  451. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  452. doguHashSet.UnionWith(BGList);
  453. doguHashSet.UnionWith(ignoreList);
  454. foreach (List<string> doguList in DoguDict.Values)
  455. {
  456. doguHashSet.UnionWith(doguList);
  457. }
  458. foreach (string path in GameUty.FileSystem.GetList("bg", AFileSystemBase.ListType.AllFile))
  459. {
  460. if (Path.GetExtension(path) == ".asset_bg" && !path.Contains("myroomcustomize"))
  461. {
  462. string file = Path.GetFileNameWithoutExtension(path);
  463. if (!doguHashSet.Contains(file) && !file.EndsWith("_hit"))
  464. {
  465. DoguList.Add(file);
  466. doguHashSet.Add(file);
  467. }
  468. }
  469. }
  470. // Get cherry picked dogu that I can't find in the game files
  471. string doguExtendPath = Path.Combine(configPath, "Database\\extra_dogu.json");
  472. string doguExtendJson = File.ReadAllText(doguExtendPath);
  473. DoguList.AddRange(JsonConvert.DeserializeObject<IEnumerable<string>>(doguExtendJson));
  474. foreach (string path in GameUty.FileSystemOld.GetList("bg", AFileSystemBase.ListType.AllFile))
  475. {
  476. if (Path.GetExtension(path) == ".asset_bg")
  477. {
  478. string file = Path.GetFileNameWithoutExtension(path);
  479. if (!doguHashSet.Contains(file) && !file.EndsWith("_not_optimisation"))
  480. {
  481. DoguList.Add(file);
  482. }
  483. }
  484. }
  485. }
  486. private static void InitializeDeskItems()
  487. {
  488. HashSet<int> enabledIDs = new HashSet<int>();
  489. CsvCommonIdManager.ReadEnabledIdList(
  490. CsvCommonIdManager.FileSystemType.Normal, true, "desk_item_enabled_id", ref enabledIDs
  491. );
  492. CsvCommonIdManager.ReadEnabledIdList(
  493. CsvCommonIdManager.FileSystemType.Old, true, "desk_item_enabled_id", ref enabledIDs
  494. );
  495. List<string> com3d2DeskDogu = DoguDict[customDoguCategories[DoguCategory.Desk]];
  496. void GetDeskItems(AFileSystemBase fs)
  497. {
  498. using (CsvParser csvParser = OpenCsvParser("desk_item_detail.nei", fs))
  499. {
  500. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  501. {
  502. if (csvParser.IsCellToExistData(0, cell_y))
  503. {
  504. int cell = csvParser.GetCellAsInteger(0, cell_y);
  505. if (enabledIDs.Contains(cell))
  506. {
  507. string dogu = string.Empty;
  508. if (csvParser.IsCellToExistData(3, cell_y))
  509. {
  510. dogu = csvParser.GetCellAsString(3, cell_y);
  511. }
  512. else if (csvParser.IsCellToExistData(4, cell_y))
  513. {
  514. dogu = csvParser.GetCellAsString(4, cell_y);
  515. }
  516. if (!string.IsNullOrEmpty(dogu))
  517. {
  518. com3d2DeskDogu.Add(dogu);
  519. }
  520. }
  521. }
  522. }
  523. }
  524. }
  525. GetDeskItems(GameUty.FileSystem);
  526. }
  527. private static void InitializePhotoBGItems()
  528. {
  529. PhotoBGObjectData.Create();
  530. List<PhotoBGObjectData> photoBGObjectList = PhotoBGObjectData.data;
  531. List<string> doguCategories = new List<string>();
  532. HashSet<string> addedCategories = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  533. foreach (PhotoBGObjectData photoBGObject in photoBGObjectList)
  534. {
  535. string category = photoBGObject.category;
  536. if (!addedCategories.Contains(category))
  537. {
  538. addedCategories.Add(category);
  539. doguCategories.Add(category);
  540. }
  541. if (!DoguDict.ContainsKey(category))
  542. {
  543. DoguDict[category] = new List<string>();
  544. }
  545. string dogu = string.Empty;
  546. if (!string.IsNullOrEmpty(photoBGObject.create_prefab_name))
  547. {
  548. dogu = photoBGObject.create_prefab_name;
  549. }
  550. else if (!string.IsNullOrEmpty(photoBGObject.create_asset_bundle_name))
  551. {
  552. dogu = photoBGObject.create_asset_bundle_name;
  553. }
  554. else if (!string.IsNullOrEmpty(photoBGObject.direct_file))
  555. {
  556. dogu = photoBGObject.direct_file;
  557. }
  558. if (!string.IsNullOrEmpty(dogu))
  559. {
  560. DoguDict[category].Add(dogu);
  561. }
  562. }
  563. DoguDict["パーティクル"].AddRange(new[] {
  564. "Particle/pLineY", "Particle/pLineP02", "Particle/pHeart01",
  565. "Particle/pLine_act2", "Particle/pstarY_act2"
  566. });
  567. }
  568. private static void InitializeHandItems()
  569. {
  570. if (HandItemsInitialized) return;
  571. if (!MenuFilesReady)
  572. {
  573. if (!beginHandItemInit) MenuFilesReadyChange += (s, a) => InitializeHandItems();
  574. beginHandItemInit = true;
  575. return;
  576. }
  577. MenuDataBase menuDataBase = GameMain.Instance.MenuDataBase;
  578. string ignoreListJson = File.ReadAllText(Path.Combine(configPath, "Database\\bg_ignore_list.json"));
  579. string[] ignoreList = JsonConvert.DeserializeObject<IEnumerable<string>>(ignoreListJson).ToArray();
  580. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  581. doguHashSet.UnionWith(BGList);
  582. doguHashSet.UnionWith(ignoreList);
  583. foreach (List<string> doguList in DoguDict.Values)
  584. {
  585. doguHashSet.UnionWith(doguList);
  586. }
  587. string category = customDoguCategories[DoguCategory.HandItem];
  588. for (int i = 0; i < menuDataBase.GetDataSize(); i++)
  589. {
  590. menuDataBase.SetIndex(i);
  591. if ((MPN)menuDataBase.GetCategoryMpn() == MPN.handitem)
  592. {
  593. string menuFileName = menuDataBase.GetMenuFileName();
  594. if (menuDataBase.GetBoDelOnly() || menuFileName.EndsWith("_del.menu")) continue;
  595. string handItemAsOdogu = Utility.HandItemToOdogu(menuFileName);
  596. string isolatedHandItem = menuFileName.Substring(menuFileName.IndexOf('_') + 1);
  597. if (!doguHashSet.Contains(handItemAsOdogu) && !doguHashSet.Contains(isolatedHandItem))
  598. {
  599. doguHashSet.Add(isolatedHandItem);
  600. DoguDict[category].Add(menuFileName);
  601. // Check for a half deck of cards to add the full deck as well
  602. if (menuFileName == "handitemd_cards_i_.menu")
  603. {
  604. DoguDict[category].Add("handiteml_cards_i_.menu");
  605. }
  606. }
  607. }
  608. }
  609. HandItemsInitialized = true;
  610. OnMenuFilesChange(MenuFilesEventArgs.EventType.HandItems);
  611. }
  612. private static void InitializeMpnAttachProps()
  613. {
  614. if (MpnAttachInitialized) return;
  615. if (!MenuFilesReady)
  616. {
  617. if (!beginMpnAttachInit) MenuFilesReadyChange += (s, a) => InitializeMpnAttachProps();
  618. beginMpnAttachInit = true;
  619. return;
  620. }
  621. MenuDataBase menuDataBase = GameMain.Instance.MenuDataBase;
  622. MPN[] attachMpn = { MPN.kousoku_lower, MPN.kousoku_upper };
  623. for (int i = 0; i < menuDataBase.GetDataSize(); i++)
  624. {
  625. menuDataBase.SetIndex(i);
  626. MPN itemMpn = (MPN)menuDataBase.GetCategoryMpn();
  627. if (attachMpn.Any(mpn => mpn == itemMpn))
  628. {
  629. string menuFileName = menuDataBase.GetMenuFileName();
  630. string mpnTag = menuDataBase.GetCategoryMpnText();
  631. if (menuDataBase.GetBoDelOnly() || menuFileName.EndsWith("_del.menu")) continue;
  632. MpnAttachPropList.Add(new MpnAttachProp(itemMpn, menuFileName));
  633. }
  634. }
  635. MpnAttachInitialized = true;
  636. OnMenuFilesChange(MenuFilesEventArgs.EventType.MpnAttach);
  637. }
  638. private static void InitializeMyRoomProps()
  639. {
  640. PlacementData.CreateData();
  641. List<PlacementData.Data> myRoomData = PlacementData.GetAllDatas(false);
  642. myRoomData.Sort((a, b) =>
  643. {
  644. int res = a.categoryID.CompareTo(b.categoryID);
  645. if (res == 0) res = a.ID.CompareTo(b.ID);
  646. return res;
  647. });
  648. foreach (PlacementData.Data data in myRoomData)
  649. {
  650. string category = PlacementData.GetCategoryName(data.categoryID);
  651. if (!MyRoomPropDict.ContainsKey(category))
  652. {
  653. MyRoomPropCategories.Add(category);
  654. MyRoomPropDict[category] = new List<MyRoomItem>();
  655. }
  656. string asset = !string.IsNullOrEmpty(data.resourceName) ? data.resourceName : data.assetName;
  657. MyRoomItem item = new MyRoomItem() { PrefabName = asset, ID = data.ID };
  658. MyRoomPropDict[category].Add(item);
  659. }
  660. }
  661. private static void InitializeModProps()
  662. {
  663. for (int i = 1; i < MenuCategories.Length; i++)
  664. {
  665. ModPropDict[MenuCategories[i]] = new List<ModItem>();
  666. }
  667. if (!PropManager.ModItemsOnly)
  668. {
  669. MenuDataBase menuDatabase = GameMain.Instance.MenuDataBase;
  670. for (int i = 0; i < menuDatabase.GetDataSize(); i++)
  671. {
  672. menuDatabase.SetIndex(i);
  673. ModItem modItem = new ModItem();
  674. if (ParseNativeMenuFile(i, modItem))
  675. {
  676. ModPropDict[modItem.Category].Add(modItem);
  677. }
  678. }
  679. }
  680. MenuFileCache cache = new MenuFileCache();
  681. foreach (string modMenuFile in GameUty.ModOnlysMenuFiles)
  682. {
  683. ModItem modItem;
  684. if (cache.Has(modMenuFile)) modItem = cache[modMenuFile];
  685. else
  686. {
  687. modItem = ModItem.Mod(modMenuFile);
  688. ParseMenuFile(modMenuFile, modItem);
  689. cache[modMenuFile] = modItem;
  690. }
  691. if (ValidBG2MenuFile(modItem)) ModPropDict[modItem.Category].Add(modItem);
  692. }
  693. cache.Serialize();
  694. foreach (string modFile in Menu.GetModFiles())
  695. {
  696. ModItem modItem = ModItem.OfficialMod(modFile);
  697. if (ParseModMenuFile(modFile, modItem))
  698. {
  699. ModPropDict[modItem.Category].Add(modItem);
  700. }
  701. }
  702. MenuFilesInitialized = true;
  703. }
  704. public static List<ModItem> GetModPropList(string category)
  705. {
  706. if (!PropManager.ModItemsOnly && !MenuFilesReady)
  707. {
  708. Utility.LogMessage("Menu files are not ready yet");
  709. return null;
  710. }
  711. if (!MenuFilesInitialized) InitializeModProps();
  712. if (!ModPropDict.ContainsKey(category)) return null;
  713. List<ModItem> selectedList = ModPropDict[category];
  714. if (selectedList[0].Icon == null)
  715. {
  716. selectedList.Sort((a, b) =>
  717. {
  718. int res = a.Priority.CompareTo(b.Priority);
  719. if (res == 0) res = string.Compare(a.Name, b.Name);
  720. return res;
  721. });
  722. string previousMenuFile = string.Empty;
  723. selectedList.RemoveAll(item =>
  724. {
  725. if (item.Icon == null)
  726. {
  727. Texture2D icon;
  728. string iconFile = item.IconFile;
  729. if (string.IsNullOrEmpty(iconFile) || !GameUty.FileSystem.IsExistentFile(iconFile))
  730. {
  731. Utility.LogWarning($"Could not find icon '{iconFile}' for menu '{item.MenuFile}");
  732. return true;
  733. }
  734. try
  735. {
  736. icon = ImportCM.CreateTexture(iconFile);
  737. }
  738. catch
  739. {
  740. try
  741. {
  742. icon = ImportCM.CreateTexture($"tex\\{iconFile}");
  743. }
  744. catch
  745. {
  746. Utility.LogWarning($"Could not load '{iconFile}' for menu '{item.MenuFile}");
  747. return true;
  748. }
  749. }
  750. item.Icon = icon;
  751. }
  752. return false;
  753. });
  754. }
  755. return selectedList;
  756. }
  757. private static CsvParser OpenCsvParser(string nei, AFileSystemBase fs)
  758. {
  759. try
  760. {
  761. if (fs.IsExistentFile(nei))
  762. {
  763. AFileBase file = fs.FileOpen(nei);
  764. CsvParser csvParser = new CsvParser();
  765. if (csvParser.Open(file)) return csvParser;
  766. file?.Dispose();
  767. }
  768. }
  769. catch { }
  770. return null;
  771. }
  772. private static void OnMenuFilesChange(MenuFilesEventArgs.EventType eventType)
  773. {
  774. MenuFilesChange?.Invoke(null, new MenuFilesEventArgs(eventType));
  775. }
  776. private class SerializePoseList
  777. {
  778. public string UIName { get; set; }
  779. public List<string> PoseList { get; set; }
  780. }
  781. }
  782. public class MenuFilesEventArgs : EventArgs
  783. {
  784. public EventType Type { get; }
  785. public enum EventType
  786. {
  787. HandItems, MenuFiles, MpnAttach
  788. }
  789. public MenuFilesEventArgs(EventType type) => Type = type;
  790. }
  791. public class PresetChangeEventArgs : EventArgs
  792. {
  793. public string Category { get; }
  794. public string Path { get; }
  795. public static new PresetChangeEventArgs Empty { get; } = new PresetChangeEventArgs(string.Empty, string.Empty);
  796. public PresetChangeEventArgs(string path, string category)
  797. {
  798. Path = path;
  799. Category = category;
  800. }
  801. }
  802. public struct MpnAttachProp
  803. {
  804. public MPN Tag { get; }
  805. public string MenuFile { get; }
  806. public MpnAttachProp(MPN tag, string menuFile)
  807. {
  808. Tag = tag;
  809. MenuFile = menuFile;
  810. }
  811. }
  812. }