Constants.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  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. 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. 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. 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. 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. {
  447. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  448. {
  449. if (csvParser.IsCellToExistData(3, cell_y))
  450. {
  451. string bg = csvParser.GetCellAsString(3, cell_y);
  452. BGList.Add(bg);
  453. }
  454. }
  455. }
  456. }
  457. Dictionary<string, string> saveDataDict = CreativeRoomManager.GetSaveDataDic();
  458. if (saveDataDict != null)
  459. {
  460. MyRoomCustomBGIndex = BGList.Count;
  461. MyRoomCustomBGList.AddRange(saveDataDict);
  462. }
  463. }
  464. public static void InitializeDogu()
  465. {
  466. foreach (string customCategory in customDoguCategories.Values)
  467. {
  468. DoguDict[customCategory] = new List<string>();
  469. }
  470. InitializeDeskItems();
  471. InitializePhotoBGItems();
  472. InitializeOtherDogu();
  473. InitializeHandItems();
  474. foreach (string category in PhotoBGObjectData.popup_category_list.Select(kvp => kvp.Key))
  475. {
  476. if (category == "マイオブジェクト") continue;
  477. DoguCategories.Add(category);
  478. }
  479. foreach (DoguCategory category in Enum.GetValues(typeof(DoguCategory)))
  480. {
  481. DoguCategories.Add(customDoguCategories[category]);
  482. }
  483. }
  484. private static void InitializeOtherDogu()
  485. {
  486. DoguDict[customDoguCategories[DoguCategory.BGSmall]] = BGList;
  487. DoguDict[customDoguCategories[DoguCategory.Mob]].AddRange(new[] {
  488. "Mob_Man_Stand001", "Mob_Man_Stand002", "Mob_Man_Stand003", "Mob_Man_Sit001", "Mob_Man_Sit002",
  489. "Mob_Man_Sit003", "Mob_Girl_Stand001", "Mob_Girl_Stand002", "Mob_Girl_Stand003", "Mob_Girl_Sit001",
  490. "Mob_Girl_Sit002", "Mob_Girl_Sit003", "Salon:65", "Salon:63", "Salon:69"
  491. });
  492. List<string> DoguList = DoguDict[customDoguCategories[DoguCategory.Other]];
  493. // bg object extend
  494. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  495. doguHashSet.UnionWith(BGList);
  496. try
  497. {
  498. string ignoreListPath = Path.Combine(databasePath, "bg_ignore_list.json");
  499. string ignoreListJson = File.ReadAllText(ignoreListPath);
  500. string[] ignoreList = JsonConvert.DeserializeObject<string[]>(ignoreListJson);
  501. doguHashSet.UnionWith(ignoreList);
  502. }
  503. catch (IOException e)
  504. {
  505. Utility.LogWarning($"Could not open ignored BG database because {e.Message}");
  506. }
  507. catch { }
  508. foreach (List<string> doguList in DoguDict.Values)
  509. {
  510. doguHashSet.UnionWith(doguList);
  511. }
  512. foreach (string path in GameUty.FileSystem.GetList("bg", AFileSystemBase.ListType.AllFile))
  513. {
  514. if (Path.GetExtension(path) == ".asset_bg" && !path.Contains("myroomcustomize"))
  515. {
  516. string file = Path.GetFileNameWithoutExtension(path);
  517. if (!doguHashSet.Contains(file) && !file.EndsWith("_hit"))
  518. {
  519. DoguList.Add(file);
  520. doguHashSet.Add(file);
  521. }
  522. }
  523. }
  524. // Get cherry picked dogu that I can't find in the game files
  525. try
  526. {
  527. string doguExtendPath = Path.Combine(databasePath, "extra_dogu.json");
  528. string doguExtendJson = File.ReadAllText(doguExtendPath);
  529. DoguList.AddRange(JsonConvert.DeserializeObject<IEnumerable<string>>(doguExtendJson));
  530. }
  531. catch (IOException e)
  532. {
  533. Utility.LogError($"Could not open extra prop database because {e.Message}");
  534. }
  535. catch (Exception e)
  536. {
  537. Utility.LogError($"Could not parse extra prop database because {e.Message}");
  538. }
  539. foreach (string path in GameUty.FileSystemOld.GetList("bg", AFileSystemBase.ListType.AllFile))
  540. {
  541. if (Path.GetExtension(path) == ".asset_bg")
  542. {
  543. string file = Path.GetFileNameWithoutExtension(path);
  544. if (!doguHashSet.Contains(file) && !file.EndsWith("_not_optimisation"))
  545. {
  546. DoguList.Add(file);
  547. }
  548. }
  549. }
  550. }
  551. private static void InitializeDeskItems()
  552. {
  553. HashSet<int> enabledIDs = new HashSet<int>();
  554. CsvCommonIdManager.ReadEnabledIdList(
  555. CsvCommonIdManager.FileSystemType.Normal, true, "desk_item_enabled_id", ref enabledIDs
  556. );
  557. CsvCommonIdManager.ReadEnabledIdList(
  558. CsvCommonIdManager.FileSystemType.Old, true, "desk_item_enabled_id", ref enabledIDs
  559. );
  560. List<string> com3d2DeskDogu = DoguDict[customDoguCategories[DoguCategory.Desk]];
  561. void GetDeskItems(AFileSystemBase fs)
  562. {
  563. using (CsvParser csvParser = OpenCsvParser("desk_item_detail.nei", fs))
  564. {
  565. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  566. {
  567. if (csvParser.IsCellToExistData(0, cell_y))
  568. {
  569. int cell = csvParser.GetCellAsInteger(0, cell_y);
  570. if (enabledIDs.Contains(cell))
  571. {
  572. string dogu = string.Empty;
  573. if (csvParser.IsCellToExistData(3, cell_y))
  574. {
  575. dogu = csvParser.GetCellAsString(3, cell_y);
  576. }
  577. else if (csvParser.IsCellToExistData(4, cell_y))
  578. {
  579. dogu = csvParser.GetCellAsString(4, cell_y);
  580. }
  581. if (!string.IsNullOrEmpty(dogu))
  582. {
  583. com3d2DeskDogu.Add(dogu);
  584. }
  585. }
  586. }
  587. }
  588. }
  589. }
  590. GetDeskItems(GameUty.FileSystem);
  591. }
  592. private static void InitializePhotoBGItems()
  593. {
  594. PhotoBGObjectData.Create();
  595. List<PhotoBGObjectData> photoBGObjectList = PhotoBGObjectData.data;
  596. List<string> doguCategories = new List<string>();
  597. HashSet<string> addedCategories = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  598. foreach (PhotoBGObjectData photoBGObject in photoBGObjectList)
  599. {
  600. string category = photoBGObject.category;
  601. if (!addedCategories.Contains(category))
  602. {
  603. addedCategories.Add(category);
  604. doguCategories.Add(category);
  605. }
  606. if (!DoguDict.ContainsKey(category))
  607. {
  608. DoguDict[category] = new List<string>();
  609. }
  610. string dogu = string.Empty;
  611. if (!string.IsNullOrEmpty(photoBGObject.create_prefab_name))
  612. {
  613. dogu = photoBGObject.create_prefab_name;
  614. }
  615. else if (!string.IsNullOrEmpty(photoBGObject.create_asset_bundle_name))
  616. {
  617. dogu = photoBGObject.create_asset_bundle_name;
  618. }
  619. else if (!string.IsNullOrEmpty(photoBGObject.direct_file))
  620. {
  621. dogu = photoBGObject.direct_file;
  622. }
  623. if (!string.IsNullOrEmpty(dogu))
  624. {
  625. DoguDict[category].Add(dogu);
  626. }
  627. }
  628. DoguDict["パーティクル"].AddRange(new[] {
  629. "Particle/pLineY", "Particle/pLineP02", "Particle/pHeart01",
  630. "Particle/pLine_act2", "Particle/pstarY_act2"
  631. });
  632. }
  633. private static void InitializeHandItems()
  634. {
  635. if (HandItemsInitialized) return;
  636. if (!MenuFilesReady)
  637. {
  638. if (!beginHandItemInit) MenuFilesReadyChange += (s, a) => InitializeHandItems();
  639. beginHandItemInit = true;
  640. return;
  641. }
  642. MenuDataBase menuDataBase = GameMain.Instance.MenuDataBase;
  643. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  644. doguHashSet.UnionWith(BGList);
  645. try
  646. {
  647. string ignoreListPath = Path.Combine(databasePath, "bg_ignore_list.json");
  648. string ignoreListJson = File.ReadAllText(ignoreListPath);
  649. string[] ignoreList = JsonConvert.DeserializeObject<string[]>(ignoreListJson);
  650. doguHashSet.UnionWith(ignoreList);
  651. }
  652. catch (IOException e)
  653. {
  654. Utility.LogWarning($"Could not open ignored BG database because {e.Message}");
  655. }
  656. catch (Exception e)
  657. {
  658. Utility.LogError($"Could not parse ignored BG database because {e.Message}");
  659. }
  660. foreach (List<string> doguList in DoguDict.Values)
  661. {
  662. doguHashSet.UnionWith(doguList);
  663. }
  664. string category = customDoguCategories[DoguCategory.HandItem];
  665. for (int i = 0; i < menuDataBase.GetDataSize(); i++)
  666. {
  667. menuDataBase.SetIndex(i);
  668. if ((MPN)menuDataBase.GetCategoryMpn() == MPN.handitem)
  669. {
  670. string menuFileName = menuDataBase.GetMenuFileName();
  671. if (menuDataBase.GetBoDelOnly() || menuFileName.EndsWith("_del.menu")) continue;
  672. string handItemAsOdogu = Utility.HandItemToOdogu(menuFileName);
  673. string isolatedHandItem = menuFileName.Substring(menuFileName.IndexOf('_') + 1);
  674. if (!doguHashSet.Contains(handItemAsOdogu) && !doguHashSet.Contains(isolatedHandItem))
  675. {
  676. doguHashSet.Add(isolatedHandItem);
  677. DoguDict[category].Add(menuFileName);
  678. // Check for a half deck of cards to add the full deck as well
  679. if (menuFileName == "handitemd_cards_i_.menu")
  680. {
  681. DoguDict[category].Add("handiteml_cards_i_.menu");
  682. }
  683. }
  684. }
  685. }
  686. HandItemsInitialized = true;
  687. OnMenuFilesChange(MenuFilesEventArgs.EventType.HandItems);
  688. }
  689. private static void InitializeMpnAttachProps()
  690. {
  691. if (MpnAttachInitialized) return;
  692. if (!MenuFilesReady)
  693. {
  694. if (!beginMpnAttachInit) MenuFilesReadyChange += (s, a) => InitializeMpnAttachProps();
  695. beginMpnAttachInit = true;
  696. return;
  697. }
  698. MenuDataBase menuDataBase = GameMain.Instance.MenuDataBase;
  699. MPN[] attachMpn = { MPN.kousoku_lower, MPN.kousoku_upper };
  700. for (int i = 0; i < menuDataBase.GetDataSize(); i++)
  701. {
  702. menuDataBase.SetIndex(i);
  703. MPN itemMpn = (MPN)menuDataBase.GetCategoryMpn();
  704. if (attachMpn.Any(mpn => mpn == itemMpn))
  705. {
  706. string menuFileName = menuDataBase.GetMenuFileName();
  707. string mpnTag = menuDataBase.GetCategoryMpnText();
  708. if (menuDataBase.GetBoDelOnly() || menuFileName.EndsWith("_del.menu")) continue;
  709. MpnAttachPropList.Add(new MpnAttachProp(itemMpn, menuFileName));
  710. }
  711. }
  712. MpnAttachInitialized = true;
  713. OnMenuFilesChange(MenuFilesEventArgs.EventType.MpnAttach);
  714. }
  715. private static void InitializeMyRoomProps()
  716. {
  717. PlacementData.CreateData();
  718. List<PlacementData.Data> myRoomData = PlacementData.GetAllDatas(false);
  719. myRoomData.Sort((a, b) =>
  720. {
  721. int res = a.categoryID.CompareTo(b.categoryID);
  722. if (res == 0) res = a.ID.CompareTo(b.ID);
  723. return res;
  724. });
  725. foreach (PlacementData.Data data in myRoomData)
  726. {
  727. string category = PlacementData.GetCategoryName(data.categoryID);
  728. if (!MyRoomPropDict.ContainsKey(category))
  729. {
  730. MyRoomPropCategories.Add(category);
  731. MyRoomPropDict[category] = new List<MyRoomItem>();
  732. }
  733. string asset = !string.IsNullOrEmpty(data.resourceName) ? data.resourceName : data.assetName;
  734. MyRoomItem item = new MyRoomItem() { PrefabName = asset, ID = data.ID };
  735. MyRoomPropDict[category].Add(item);
  736. }
  737. }
  738. private static void InitializeModProps()
  739. {
  740. for (int i = 1; i < MenuCategories.Length; i++)
  741. {
  742. ModPropDict[MenuCategories[i]] = new List<ModItem>();
  743. }
  744. if (!PropManager.ModItemsOnly)
  745. {
  746. MenuDataBase menuDatabase = GameMain.Instance.MenuDataBase;
  747. for (int i = 0; i < menuDatabase.GetDataSize(); i++)
  748. {
  749. menuDatabase.SetIndex(i);
  750. ModItem modItem = new ModItem();
  751. if (ParseNativeMenuFile(i, modItem))
  752. {
  753. ModPropDict[modItem.Category].Add(modItem);
  754. }
  755. }
  756. }
  757. MenuFileCache cache = new MenuFileCache();
  758. foreach (string modMenuFile in GameUty.ModOnlysMenuFiles)
  759. {
  760. ModItem modItem;
  761. if (cache.Has(modMenuFile)) modItem = cache[modMenuFile];
  762. else
  763. {
  764. modItem = ModItem.Mod(modMenuFile);
  765. ParseMenuFile(modMenuFile, modItem);
  766. cache[modMenuFile] = modItem;
  767. }
  768. if (ValidBG2MenuFile(modItem)) ModPropDict[modItem.Category].Add(modItem);
  769. }
  770. cache.Serialize();
  771. foreach (string modFile in Menu.GetModFiles())
  772. {
  773. ModItem modItem = ModItem.OfficialMod(modFile);
  774. if (ParseModMenuFile(modFile, modItem))
  775. {
  776. ModPropDict[modItem.Category].Add(modItem);
  777. }
  778. }
  779. MenuFilesInitialized = true;
  780. }
  781. public static List<ModItem> GetModPropList(string category)
  782. {
  783. if (!PropManager.ModItemsOnly && !MenuFilesReady)
  784. {
  785. Utility.LogMessage("Menu files are not ready yet");
  786. return null;
  787. }
  788. if (!MenuFilesInitialized) InitializeModProps();
  789. if (!ModPropDict.ContainsKey(category)) return null;
  790. List<ModItem> selectedList = ModPropDict[category];
  791. if (selectedList[0].Icon == null)
  792. {
  793. selectedList.Sort((a, b) =>
  794. {
  795. int res = a.Priority.CompareTo(b.Priority);
  796. if (res == 0) res = string.Compare(a.Name, b.Name);
  797. return res;
  798. });
  799. string previousMenuFile = string.Empty;
  800. selectedList.RemoveAll(item =>
  801. {
  802. if (item.Icon == null)
  803. {
  804. Texture2D icon;
  805. string iconFile = item.IconFile;
  806. if (string.IsNullOrEmpty(iconFile) || !GameUty.FileSystem.IsExistentFile(iconFile))
  807. {
  808. Utility.LogWarning($"Could not find icon '{iconFile}' for menu '{item.MenuFile}");
  809. return true;
  810. }
  811. try
  812. {
  813. icon = ImportCM.CreateTexture(iconFile);
  814. }
  815. catch
  816. {
  817. try
  818. {
  819. icon = ImportCM.CreateTexture($"tex\\{iconFile}");
  820. }
  821. catch
  822. {
  823. Utility.LogWarning($"Could not load '{iconFile}' for menu '{item.MenuFile}");
  824. return true;
  825. }
  826. }
  827. item.Icon = icon;
  828. }
  829. return false;
  830. });
  831. }
  832. return selectedList;
  833. }
  834. private static CsvParser OpenCsvParser(string nei, AFileSystemBase fs)
  835. {
  836. try
  837. {
  838. if (fs.IsExistentFile(nei))
  839. {
  840. AFileBase file = fs.FileOpen(nei);
  841. CsvParser csvParser = new CsvParser();
  842. if (csvParser.Open(file)) return csvParser;
  843. file?.Dispose();
  844. }
  845. }
  846. catch { }
  847. return null;
  848. }
  849. private static void OnMenuFilesChange(MenuFilesEventArgs.EventType eventType)
  850. {
  851. MenuFilesChange?.Invoke(null, new MenuFilesEventArgs(eventType));
  852. }
  853. private class SerializePoseList
  854. {
  855. public string UIName { get; set; }
  856. public List<string> PoseList { get; set; }
  857. }
  858. }
  859. public class MenuFilesEventArgs : EventArgs
  860. {
  861. public EventType Type { get; }
  862. public enum EventType
  863. {
  864. HandItems, MenuFiles, MpnAttach
  865. }
  866. public MenuFilesEventArgs(EventType type) => Type = type;
  867. }
  868. public class PresetChangeEventArgs : EventArgs
  869. {
  870. public string Category { get; }
  871. public string Path { get; }
  872. public static new PresetChangeEventArgs Empty { get; } = new PresetChangeEventArgs(string.Empty, string.Empty);
  873. public PresetChangeEventArgs(string path, string category)
  874. {
  875. Path = path;
  876. Category = category;
  877. }
  878. }
  879. public struct MpnAttachProp
  880. {
  881. public MPN Tag { get; }
  882. public string MenuFile { get; }
  883. public MpnAttachProp(MPN tag, string menuFile)
  884. {
  885. Tag = tag;
  886. MenuFile = menuFile;
  887. }
  888. }
  889. }