Constants.cs 33 KB

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