Constants.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using Newtonsoft.Json;
  6. using MyRoomCustom;
  7. using UnityEngine;
  8. using wf;
  9. namespace COM3D2.MeidoPhotoStudio.Plugin
  10. {
  11. using static MenuFileUtility;
  12. internal class Constants
  13. {
  14. private static bool beginHandItemInit;
  15. private static bool startModItemInit;
  16. public static readonly string customPosePath;
  17. public static readonly string scenesPath;
  18. public static readonly string kankyoPath;
  19. public static readonly string configPath;
  20. public static readonly int mainWindowID = 765;
  21. public static readonly int messageWindowID = 961;
  22. public static readonly int sceneManagerWindowID = 876;
  23. public static readonly int sceneManagerModalID = 283;
  24. public static readonly int dropdownWindowID = 777;
  25. public enum Window
  26. {
  27. Call, Pose, Face, BG, BG2, Main, Message, Save, SaveModal
  28. }
  29. public enum Scene
  30. {
  31. Daily = 3, Edit = 5
  32. }
  33. public static readonly List<string> PoseGroupList = new List<string>();
  34. public static readonly Dictionary<string, List<string>> PoseDict = new Dictionary<string, List<string>>();
  35. public static readonly Dictionary<string, List<KeyValuePair<string, string>>> CustomPoseDict
  36. = new Dictionary<string, List<KeyValuePair<string, string>>>();
  37. public static readonly List<string> FaceBlendList = new List<string>();
  38. public static readonly List<string> BGList = new List<string>();
  39. public static readonly List<KeyValuePair<string, string>> MyRoomCustomBGList
  40. = new List<KeyValuePair<string, string>>();
  41. public static readonly List<string> DoguCategories = new List<string>();
  42. public static readonly Dictionary<string, List<string>> DoguDict = new Dictionary<string, List<string>>();
  43. public static readonly List<string> MyRoomPropCategories = new List<string>();
  44. public static readonly Dictionary<string, List<MyRoomItem>> MyRoomPropDict
  45. = new Dictionary<string, List<MyRoomItem>>();
  46. public static readonly Dictionary<string, List<ModItem>> ModPropDict
  47. = new Dictionary<string, List<ModItem>>(StringComparer.InvariantCultureIgnoreCase);
  48. public static int CustomPoseGroupsIndex { get; private set; } = -1;
  49. public static int MyRoomCustomBGIndex { get; private set; } = -1;
  50. public static bool HandItemsInitialized { get; private set; } = false;
  51. public static bool MenuFilesInitialized { get; private set; } = false;
  52. public static event EventHandler<MenuFilesEventArgs> MenuFilesChange;
  53. public enum DoguCategory
  54. {
  55. Other, Mob, Desk, HandItem, BGSmall
  56. }
  57. public static readonly Dictionary<DoguCategory, string> customDoguCategories =
  58. new Dictionary<DoguCategory, string>()
  59. {
  60. [DoguCategory.Other] = "other",
  61. [DoguCategory.Mob] = "mob",
  62. [DoguCategory.Desk] = "desk",
  63. [DoguCategory.HandItem] = "handItem",
  64. [DoguCategory.BGSmall] = "bgSmall"
  65. };
  66. static Constants()
  67. {
  68. string modsPath = Path.Combine(Path.GetFullPath(".\\"), @"Mod\MeidoPhotoStudio");
  69. customPosePath = Path.Combine(modsPath, "Custom Poses");
  70. scenesPath = Path.Combine(modsPath, "Scenes");
  71. kankyoPath = Path.Combine(modsPath, "Environments");
  72. configPath = Path.Combine(
  73. Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
  74. @"Config\MeidoPhotoStudio"
  75. );
  76. foreach (string directory in new[] { customPosePath, scenesPath, kankyoPath, configPath })
  77. {
  78. if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
  79. }
  80. }
  81. public static void Initialize()
  82. {
  83. InitializePoses();
  84. InitializeFaceBlends();
  85. InitializeBGs();
  86. InitializeDogu();
  87. InitializeMyRoomProps();
  88. }
  89. public static void InitializePoses()
  90. {
  91. // Load Poses
  92. string poseListJson = File.ReadAllText(Path.Combine(configPath, "mm_pose_list.json"));
  93. List<SerializePoseList> poseLists = JsonConvert.DeserializeObject<List<SerializePoseList>>(poseListJson);
  94. foreach (SerializePoseList poseList in poseLists)
  95. {
  96. PoseDict[poseList.UIName] = poseList.PoseList;
  97. PoseGroupList.Add(poseList.UIName);
  98. }
  99. // Get Other poses that'll go into Normal 2 and Ero 2
  100. string[] com3d2MotionList = GameUty.FileSystem.GetList("motion", AFileSystemBase.ListType.AllFile);
  101. if (com3d2MotionList != null && com3d2MotionList.Length > 0)
  102. {
  103. HashSet<string> poseSet = new HashSet<string>();
  104. foreach (KeyValuePair<string, List<string>> poses in PoseDict)
  105. {
  106. foreach (string pose in poses.Value)
  107. {
  108. poseSet.Add(pose);
  109. }
  110. }
  111. List<string> editPoseList = new List<string>();
  112. List<string> otherPoseList = new List<string>();
  113. List<string> eroPoseList = new List<string>();
  114. foreach (string path in com3d2MotionList)
  115. {
  116. if (Path.GetExtension(path) == ".anm")
  117. {
  118. string file = Path.GetFileNameWithoutExtension(path);
  119. if (!poseSet.Contains(file))
  120. {
  121. if (file.StartsWith("edit_"))
  122. {
  123. editPoseList.Add(file);
  124. }
  125. else if (file != "dance_cm3d2_001_zoukin" && file != "dance_cm3d2_001_mop"
  126. && file != "aruki_1_idougo_f" && file != "sleep2" && file != "stand_akire2"
  127. && !file.EndsWith("_3_") && !file.EndsWith("_5_") && !file.StartsWith("vr_")
  128. && !file.StartsWith("dance_mc") && !file.Contains("_kubi_") && !file.Contains("a01_")
  129. && !file.Contains("b01_") && !file.Contains("b02_") && !file.EndsWith("_m2")
  130. && !file.EndsWith("_m2_once_") && !file.StartsWith("h_") && !file.StartsWith("event_")
  131. && !file.StartsWith("man_") && !file.EndsWith("_m") && !file.Contains("_m_")
  132. && !file.Contains("_man_")
  133. )
  134. {
  135. if (!path.Contains(@"\sex\")) otherPoseList.Add(file);
  136. else eroPoseList.Add(file);
  137. }
  138. }
  139. }
  140. }
  141. PoseDict["normal"].AddRange(editPoseList);
  142. PoseDict["normal2"] = otherPoseList;
  143. PoseDict["ero2"] = eroPoseList;
  144. PoseGroupList.AddRange(new[] { "normal2", "ero2" });
  145. }
  146. CustomPoseGroupsIndex = PoseGroupList.Count;
  147. Action<string> GetPoses = directory =>
  148. {
  149. List<KeyValuePair<string, string>> poseList = new List<KeyValuePair<string, string>>();
  150. foreach (string file in Directory.GetFiles(directory))
  151. {
  152. if (Path.GetExtension(file) == ".anm")
  153. {
  154. string fileName = Path.GetFileNameWithoutExtension(file);
  155. poseList.Add(new KeyValuePair<string, string>(fileName, file));
  156. }
  157. }
  158. if (poseList.Count > 0)
  159. {
  160. string poseGroupName = new DirectoryInfo(directory).Name;
  161. PoseGroupList.Add(poseGroupName);
  162. CustomPoseDict[poseGroupName] = poseList;
  163. }
  164. };
  165. GetPoses(customPosePath);
  166. foreach (string directory in Directory.GetDirectories(customPosePath))
  167. {
  168. GetPoses(directory);
  169. }
  170. }
  171. public static void InitializeFaceBlends()
  172. {
  173. using (CsvParser csvParser = OpenCsvParser("phot_face_list.nei"))
  174. {
  175. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  176. {
  177. if (csvParser.IsCellToExistData(3, cell_y))
  178. {
  179. string blendValue = csvParser.GetCellAsString(3, cell_y);
  180. FaceBlendList.Add(blendValue);
  181. }
  182. }
  183. }
  184. }
  185. public static void InitializeBGs()
  186. {
  187. // Load BGs
  188. PhotoBGData.Create();
  189. List<PhotoBGData> photList = PhotoBGData.data;
  190. // COM3D2 BGs
  191. foreach (PhotoBGData bgData in photList)
  192. {
  193. if (!string.IsNullOrEmpty(bgData.create_prefab_name))
  194. {
  195. string bg = bgData.create_prefab_name;
  196. BGList.Add(bg);
  197. }
  198. }
  199. // CM3D2 BGs
  200. if (GameUty.IsEnabledCompatibilityMode)
  201. {
  202. using (CsvParser csvParser = OpenCsvParser("phot_bg_list.nei", GameUty.FileSystemOld))
  203. {
  204. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  205. {
  206. if (csvParser.IsCellToExistData(3, cell_y))
  207. {
  208. string bg = csvParser.GetCellAsString(3, cell_y);
  209. BGList.Add(bg);
  210. }
  211. }
  212. }
  213. }
  214. Dictionary<string, string> saveDataDict = MyRoomCustom.CreativeRoomManager.GetSaveDataDic();
  215. if (saveDataDict != null)
  216. {
  217. MyRoomCustomBGIndex = BGList.Count;
  218. MyRoomCustomBGList.AddRange(saveDataDict);
  219. }
  220. }
  221. public static void InitializeDogu()
  222. {
  223. foreach (string customCategory in customDoguCategories.Values)
  224. {
  225. DoguDict[customCategory] = new List<string>();
  226. }
  227. InitializeDeskItems();
  228. InitializePhotoBGItems();
  229. InitializeOtherDogu();
  230. InitializeHandItems();
  231. foreach (KeyValuePair<string, UnityEngine.Object> keyValuePair in PhotoBGObjectData.popup_category_list)
  232. {
  233. string category = keyValuePair.Key;
  234. if (category == "マイオブジェクト") continue;
  235. DoguCategories.Add(keyValuePair.Key);
  236. }
  237. foreach (DoguCategory category in Enum.GetValues(typeof(DoguCategory)))
  238. {
  239. DoguCategories.Add(customDoguCategories[category]);
  240. }
  241. }
  242. private static void InitializeOtherDogu()
  243. {
  244. DoguDict[customDoguCategories[DoguCategory.BGSmall]] = BGList;
  245. DoguDict[customDoguCategories[DoguCategory.Mob]].AddRange(new[] {
  246. "Mob_Man_Stand001", "Mob_Man_Stand002", "Mob_Man_Stand003", "Mob_Man_Sit001", "Mob_Man_Sit002",
  247. "Mob_Man_Sit003", "Mob_Girl_Stand001", "Mob_Girl_Stand002", "Mob_Girl_Stand003", "Mob_Girl_Sit001",
  248. "Mob_Girl_Sit002", "Mob_Girl_Sit003", "Salon:65", "Salon:63", "Salon:69"
  249. });
  250. List<string> DoguList = DoguDict[customDoguCategories[DoguCategory.Other]];
  251. string ignoreListPath = Path.Combine(configPath, "mm_ignore_list.json");
  252. string ignoreListJson = File.ReadAllText(ignoreListPath);
  253. string[] ignoreList = JsonConvert.DeserializeObject<IEnumerable<string>>(ignoreListJson).ToArray();
  254. // bg object extend
  255. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  256. doguHashSet.UnionWith(BGList);
  257. doguHashSet.UnionWith(ignoreList);
  258. foreach (KeyValuePair<string, List<string>> keyValuePair in DoguDict)
  259. {
  260. doguHashSet.UnionWith(keyValuePair.Value);
  261. }
  262. string[] com3d2BgList = GameUty.FileSystem.GetList("bg", AFileSystemBase.ListType.AllFile);
  263. foreach (string path in com3d2BgList)
  264. {
  265. if (Path.GetExtension(path) == ".asset_bg" && !path.Contains("myroomcustomize"))
  266. {
  267. string file = Path.GetFileNameWithoutExtension(path);
  268. if (!doguHashSet.Contains(file) && !file.EndsWith("_hit"))
  269. {
  270. DoguList.Add(file);
  271. doguHashSet.Add(file);
  272. }
  273. }
  274. }
  275. // Get cherry picked dogu that I can't find in the game files
  276. string doguExtendPath = Path.Combine(configPath, "mm_dogu_extend.json");
  277. string doguExtendJson = File.ReadAllText(doguExtendPath);
  278. DoguList.AddRange(JsonConvert.DeserializeObject<IEnumerable<string>>(doguExtendJson));
  279. string[] cm3d2BgList = GameUty.FileSystemOld.GetList("bg", AFileSystemBase.ListType.AllFile);
  280. foreach (string path in cm3d2BgList)
  281. {
  282. if (Path.GetExtension(path) == ".asset_bg")
  283. {
  284. string file = Path.GetFileNameWithoutExtension(path);
  285. if (!doguHashSet.Contains(file) && !file.EndsWith("_not_optimisation"))
  286. {
  287. DoguList.Add(file);
  288. }
  289. }
  290. }
  291. }
  292. private static void InitializeDeskItems()
  293. {
  294. HashSet<int> enabledIDs = new HashSet<int>();
  295. CsvCommonIdManager.ReadEnabledIdList(
  296. CsvCommonIdManager.FileSystemType.Normal, true, "desk_item_enabled_id", ref enabledIDs
  297. );
  298. CsvCommonIdManager.ReadEnabledIdList(
  299. CsvCommonIdManager.FileSystemType.Old, true, "desk_item_enabled_id", ref enabledIDs
  300. );
  301. List<string> com3d2DeskDogu = DoguDict[customDoguCategories[DoguCategory.Desk]];
  302. Action<AFileSystemBase> GetDeskItems = fs =>
  303. {
  304. using (CsvParser csvParser = OpenCsvParser("desk_item_detail.nei", fs))
  305. {
  306. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  307. {
  308. if (csvParser.IsCellToExistData(0, cell_y))
  309. {
  310. int cell = csvParser.GetCellAsInteger(0, cell_y);
  311. if (enabledIDs.Contains(cell))
  312. {
  313. string dogu = String.Empty;
  314. if (csvParser.IsCellToExistData(3, cell_y))
  315. {
  316. dogu = csvParser.GetCellAsString(3, cell_y);
  317. }
  318. else if (csvParser.IsCellToExistData(4, cell_y))
  319. {
  320. dogu = csvParser.GetCellAsString(4, cell_y);
  321. }
  322. if (!string.IsNullOrEmpty(dogu))
  323. {
  324. com3d2DeskDogu.Add(dogu);
  325. }
  326. }
  327. }
  328. }
  329. }
  330. };
  331. GetDeskItems(GameUty.FileSystem);
  332. }
  333. private static void InitializePhotoBGItems()
  334. {
  335. PhotoBGObjectData.Create();
  336. List<PhotoBGObjectData> photoBGObjectList = PhotoBGObjectData.data;
  337. List<string> doguCategories = new List<string>();
  338. HashSet<string> addedCategories = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  339. foreach (PhotoBGObjectData photoBGObject in photoBGObjectList)
  340. {
  341. string category = photoBGObject.category;
  342. if (!addedCategories.Contains(category))
  343. {
  344. addedCategories.Add(category);
  345. doguCategories.Add(category);
  346. }
  347. if (!DoguDict.ContainsKey(category))
  348. {
  349. DoguDict[category] = new List<string>();
  350. }
  351. string dogu = String.Empty;
  352. if (!string.IsNullOrEmpty(photoBGObject.create_prefab_name))
  353. {
  354. dogu = photoBGObject.create_prefab_name;
  355. }
  356. else if (!string.IsNullOrEmpty(photoBGObject.create_asset_bundle_name))
  357. {
  358. dogu = photoBGObject.create_asset_bundle_name;
  359. }
  360. else if (!string.IsNullOrEmpty(photoBGObject.direct_file))
  361. {
  362. dogu = photoBGObject.direct_file;
  363. }
  364. if (!string.IsNullOrEmpty(dogu))
  365. {
  366. DoguDict[category].Add(dogu);
  367. }
  368. }
  369. DoguDict["パーティクル"].AddRange(new[] {
  370. "Particle/pLineY", "Particle/pLineP02", "Particle/pHeart01",
  371. "Particle/pLine_act2", "Particle/pstarY_act2"
  372. });
  373. }
  374. private static void InitializeHandItems()
  375. {
  376. if (HandItemsInitialized) return;
  377. if (!MenuFileUtility.MenuFilesReady)
  378. {
  379. if (!beginHandItemInit) MenuFileUtility.MenuFilesReadyChange += (s, a) => InitializeHandItems();
  380. beginHandItemInit = true;
  381. return;
  382. }
  383. MenuDataBase menuDataBase = GameMain.Instance.MenuDataBase;
  384. string ignoreListJson = File.ReadAllText(Path.Combine(configPath, "mm_ignore_list.json"));
  385. string[] ignoreList = JsonConvert.DeserializeObject<IEnumerable<string>>(ignoreListJson).ToArray();
  386. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  387. doguHashSet.UnionWith(BGList);
  388. doguHashSet.UnionWith(ignoreList);
  389. foreach (List<string> doguList in DoguDict.Values)
  390. {
  391. doguHashSet.UnionWith(doguList);
  392. }
  393. string category = customDoguCategories[DoguCategory.HandItem];
  394. for (int i = 0; i < menuDataBase.GetDataSize(); i++)
  395. {
  396. menuDataBase.SetIndex(i);
  397. if ((MPN)menuDataBase.GetCategoryMpn() == MPN.handitem)
  398. {
  399. string menuFileName = menuDataBase.GetMenuFileName();
  400. if (menuDataBase.GetBoDelOnly() || menuFileName.EndsWith("_del.menu")) continue;
  401. string handItemAsOdogu = Utility.HandItemToOdogu(menuFileName);
  402. string isolatedHandItem = menuFileName.Substring(menuFileName.IndexOf('_') + 1);
  403. if (!doguHashSet.Contains(handItemAsOdogu) && !doguHashSet.Contains(isolatedHandItem))
  404. {
  405. doguHashSet.Add(isolatedHandItem);
  406. DoguDict[category].Add(menuFileName);
  407. // Check for a half deck of cards to add the full deck as well
  408. if (menuFileName == "handitemd_cards_i_.menu")
  409. {
  410. DoguDict[category].Add("handiteml_cards_i_.menu");
  411. }
  412. }
  413. }
  414. }
  415. OnMenuFilesChange(MenuFilesEventArgs.HandItems);
  416. HandItemsInitialized = true;
  417. }
  418. private static void InitializeMyRoomProps()
  419. {
  420. PlacementData.CreateData();
  421. List<PlacementData.Data> myRoomData = PlacementData.GetAllDatas(false);
  422. myRoomData.Sort((a, b) =>
  423. {
  424. int res = a.categoryID.CompareTo(b.categoryID);
  425. if (res == 0) res = a.ID.CompareTo(b.ID);
  426. return res;
  427. });
  428. foreach (PlacementData.Data data in myRoomData)
  429. {
  430. string category = PlacementData.GetCategoryName(data.categoryID);
  431. if (!MyRoomPropDict.ContainsKey(category))
  432. {
  433. MyRoomPropCategories.Add(category);
  434. MyRoomPropDict[category] = new List<MyRoomItem>();
  435. }
  436. string asset = !string.IsNullOrEmpty(data.resourceName) ? data.resourceName : data.assetName;
  437. MyRoomItem item = new MyRoomItem() { PrefabName = asset, ID = data.ID };
  438. MyRoomPropDict[category].Add(item);
  439. }
  440. }
  441. private static CsvParser OpenCsvParser(string nei, AFileSystemBase fs)
  442. {
  443. try
  444. {
  445. if (fs.IsExistentFile(nei))
  446. {
  447. AFileBase file = fs.FileOpen(nei);
  448. CsvParser csvParser = new CsvParser();
  449. if (csvParser.Open(file)) return csvParser;
  450. else file?.Dispose();
  451. }
  452. }
  453. catch { }
  454. return null;
  455. }
  456. private static CsvParser OpenCsvParser(string nei)
  457. {
  458. return OpenCsvParser(nei, GameUty.FileSystem);
  459. }
  460. public static void WriteToFile(string name, IEnumerable<string> list)
  461. {
  462. if (Path.GetExtension(name) != ".txt") name += ".txt";
  463. File.WriteAllLines(Path.Combine(configPath, name), list.ToArray());
  464. }
  465. private static void OnMenuFilesChange(MenuFilesEventArgs args)
  466. {
  467. MenuFilesChange?.Invoke(null, args);
  468. }
  469. private class SerializePoseList
  470. {
  471. public string UIName { get; set; }
  472. public List<string> PoseList { get; set; }
  473. }
  474. }
  475. public class MenuFilesEventArgs : EventArgs
  476. {
  477. public EventType Type { get; }
  478. public enum EventType
  479. {
  480. HandItems, MenuFiles
  481. }
  482. public static MenuFilesEventArgs HandItems => new MenuFilesEventArgs(EventType.HandItems);
  483. public static MenuFilesEventArgs MenuFiles => new MenuFilesEventArgs(EventType.MenuFiles);
  484. public MenuFilesEventArgs(EventType type)
  485. {
  486. this.Type = type;
  487. }
  488. }
  489. }