Constants.cs 40 KB

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