Constants.cs 41 KB

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