Constants.cs 21 KB

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