Constants.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using UnityEngine;
  6. using Newtonsoft.Json;
  7. using Newtonsoft.Json.Linq;
  8. using wf;
  9. namespace COM3D2.MeidoPhotoStudio.Plugin
  10. {
  11. internal class Constants
  12. {
  13. public static readonly string customPosePath;
  14. public static readonly string scenesPath;
  15. public static readonly string kankyoPath;
  16. public static readonly string configPath;
  17. public static readonly int mainWindowID = 765;
  18. public static readonly int messageWindowID = 961;
  19. public static readonly int sceneManagerWindowID = 876;
  20. public static readonly int sceneManagerModalID = 283;
  21. public static readonly int dropdownWindowID = 777;
  22. public enum Window
  23. {
  24. Call, Pose, Face, BG, BG2, Main, Message, Save, SaveModal
  25. }
  26. public enum Scene
  27. {
  28. Daily = 3, Edit = 5
  29. }
  30. public static readonly List<string> PoseGroupList;
  31. public static readonly Dictionary<string, List<string>> PoseDict;
  32. public static readonly Dictionary<string, List<KeyValuePair<string, string>>> CustomPoseDict;
  33. public static int CustomPoseGroupsIndex { get; private set; } = -1;
  34. public static int MyRoomCustomBGIndex { get; private set; } = -1;
  35. public static readonly List<string> FaceBlendList;
  36. public static readonly List<string> BGList;
  37. public static readonly List<KeyValuePair<string, string>> MyRoomCustomBGList;
  38. public static readonly List<string> DoguList;
  39. public static readonly List<string> OtherDoguList;
  40. static Constants()
  41. {
  42. string modsPath = Path.Combine(Path.GetFullPath(".\\"), @"Mod\MeidoPhotoStudio");
  43. customPosePath = Path.Combine(modsPath, "Custom Poses");
  44. scenesPath = Path.Combine(modsPath, "Scenes");
  45. kankyoPath = Path.Combine(modsPath, "Environments");
  46. configPath = Path.Combine(
  47. Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
  48. @"Config\MeidoPhotoStudio"
  49. );
  50. foreach (string directory in new[] { customPosePath, scenesPath, kankyoPath, configPath })
  51. {
  52. if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
  53. }
  54. PoseDict = new Dictionary<string, List<string>>();
  55. PoseGroupList = new List<string>();
  56. CustomPoseDict = new Dictionary<string, List<KeyValuePair<string, string>>>();
  57. FaceBlendList = new List<string>();
  58. BGList = new List<string>();
  59. MyRoomCustomBGList = new List<KeyValuePair<string, string>>();
  60. DoguList = new List<string>();
  61. OtherDoguList = new List<string>();
  62. }
  63. public static void Initialize()
  64. {
  65. InitializePoses();
  66. InitializeFaceBlends();
  67. InitializeBGs();
  68. InitializeDogu();
  69. }
  70. public static void InitializePoses()
  71. {
  72. // Load Poses
  73. string poseListJson = File.ReadAllText(Path.Combine(configPath, "mm_pose_list.json"));
  74. List<SerializePoseList> poseLists = JsonConvert.DeserializeObject<List<SerializePoseList>>(poseListJson);
  75. foreach (SerializePoseList poseList in poseLists)
  76. {
  77. PoseDict[poseList.UIName] = poseList.PoseList;
  78. PoseGroupList.Add(poseList.UIName);
  79. }
  80. // Get Other poses that'll go into Normal 2 and Ero 2
  81. string[] com3d2MotionList = GameUty.FileSystem.GetList("motion", AFileSystemBase.ListType.AllFile);
  82. if (com3d2MotionList != null && com3d2MotionList.Length > 0)
  83. {
  84. HashSet<string> poseSet = new HashSet<string>();
  85. foreach (KeyValuePair<string, List<string>> poses in PoseDict)
  86. {
  87. foreach (string pose in poses.Value)
  88. {
  89. poseSet.Add(pose);
  90. }
  91. }
  92. List<string> editPoseList = new List<string>();
  93. List<string> otherPoseList = new List<string>();
  94. List<string> eroPoseList = new List<string>();
  95. foreach (string path in com3d2MotionList)
  96. {
  97. if (Path.GetExtension(path) == ".anm")
  98. {
  99. string file = Path.GetFileNameWithoutExtension(path);
  100. if (!poseSet.Contains(file))
  101. {
  102. if (file.StartsWith("edit_"))
  103. {
  104. editPoseList.Add(file);
  105. }
  106. else if (file != "dance_cm3d2_001_zoukin" && file != "dance_cm3d2_001_mop"
  107. && file != "aruki_1_idougo_f" && file != "sleep2" && file != "stand_akire2"
  108. && !file.EndsWith("_3_") && !file.EndsWith("_5_") && !file.StartsWith("vr_")
  109. && !file.StartsWith("dance_mc") && !file.Contains("_kubi_") && !file.Contains("a01_")
  110. && !file.Contains("b01_") && !file.Contains("b02_") && !file.EndsWith("_m2")
  111. && !file.EndsWith("_m2_once_") && !file.StartsWith("h_") && !file.StartsWith("event_")
  112. && !file.StartsWith("man_") && !file.EndsWith("_m") && !file.Contains("_m_")
  113. && !file.Contains("_man_")
  114. )
  115. {
  116. if (!path.Contains(@"\sex\")) otherPoseList.Add(file);
  117. else eroPoseList.Add(file);
  118. }
  119. }
  120. }
  121. }
  122. PoseDict["normal"].AddRange(editPoseList);
  123. PoseDict["normal2"] = otherPoseList;
  124. PoseDict["ero2"] = eroPoseList;
  125. PoseGroupList.AddRange(new[] { "normal2", "ero2" });
  126. }
  127. CustomPoseGroupsIndex = PoseGroupList.Count;
  128. Action<string> GetPoses = directory =>
  129. {
  130. List<KeyValuePair<string, string>> poseList = new List<KeyValuePair<string, string>>();
  131. foreach (string file in Directory.GetFiles(directory))
  132. {
  133. if (Path.GetExtension(file) == ".anm")
  134. {
  135. string fileName = Path.GetFileNameWithoutExtension(file);
  136. poseList.Add(new KeyValuePair<string, string>(fileName, file));
  137. }
  138. }
  139. if (poseList.Count > 0)
  140. {
  141. string poseGroupName = new DirectoryInfo(directory).Name;
  142. PoseGroupList.Add(poseGroupName);
  143. CustomPoseDict[poseGroupName] = poseList;
  144. }
  145. };
  146. GetPoses(customPosePath);
  147. foreach (string directory in Directory.GetDirectories(customPosePath))
  148. {
  149. GetPoses(directory);
  150. }
  151. }
  152. public static void InitializeFaceBlends()
  153. {
  154. using (CsvParser csvParser = OpenCsvParser("phot_face_list.nei"))
  155. {
  156. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  157. {
  158. if (csvParser.IsCellToExistData(3, cell_y))
  159. {
  160. string blendValue = csvParser.GetCellAsString(3, cell_y);
  161. FaceBlendList.Add(blendValue);
  162. }
  163. }
  164. }
  165. }
  166. public static void InitializeBGs()
  167. {
  168. // Load BGs
  169. PhotoBGData.Create();
  170. List<PhotoBGData> photList = PhotoBGData.data;
  171. // COM3D2 BGs
  172. foreach (PhotoBGData bgData in photList)
  173. {
  174. if (!string.IsNullOrEmpty(bgData.create_prefab_name))
  175. {
  176. string bg = bgData.create_prefab_name;
  177. BGList.Add(bg);
  178. }
  179. }
  180. // CM3D2 BGs
  181. if (GameUty.IsEnabledCompatibilityMode)
  182. {
  183. using (CsvParser csvParser = OpenCsvParser("phot_bg_list.nei", GameUty.FileSystemOld))
  184. {
  185. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  186. {
  187. if (csvParser.IsCellToExistData(3, cell_y))
  188. {
  189. string bg = csvParser.GetCellAsString(3, cell_y);
  190. BGList.Add(bg);
  191. }
  192. }
  193. }
  194. }
  195. Dictionary<string, string> saveDataDict = MyRoomCustom.CreativeRoomManager.GetSaveDataDic();
  196. if (saveDataDict != null)
  197. {
  198. MyRoomCustomBGIndex = BGList.Count;
  199. MyRoomCustomBGList.AddRange(saveDataDict);
  200. }
  201. }
  202. public static void InitializeDogu()
  203. {
  204. InitializeDeskItems();
  205. InitializePhotoBGItems();
  206. // InitializeHandItems();
  207. }
  208. private static void InitializeDeskItems()
  209. {
  210. // enabled id
  211. HashSet<int> enabledIDs = new HashSet<int>();
  212. CsvCommonIdManager.ReadEnabledIdList(
  213. CsvCommonIdManager.FileSystemType.Normal, true, "desk_item_enabled_id", ref enabledIDs
  214. );
  215. CsvCommonIdManager.ReadEnabledIdList(
  216. CsvCommonIdManager.FileSystemType.Old, true, "desk_item_enabled_id", ref enabledIDs
  217. );
  218. List<string> com3d2DeskDogu = new List<string>(new[] {
  219. "Mob_Man_Stand001", "Mob_Man_Stand002", "Mob_Man_Stand003", "Mob_Man_Sit001", "Mob_Man_Sit002",
  220. "Mob_Man_Sit003", "Mob_Girl_Stand001", "Mob_Girl_Stand002", "Mob_Girl_Stand003", "Mob_Girl_Sit001",
  221. "Mob_Girl_Sit002", "Mob_Girl_Sit003", "Salon:65", "Salon:63", "Salon:69"
  222. });
  223. Action<AFileSystemBase> GetDeskItems = fs =>
  224. {
  225. using (CsvParser csvParser = OpenCsvParser("desk_item_detail.nei", fs))
  226. {
  227. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  228. {
  229. if (csvParser.IsCellToExistData(0, cell_y))
  230. {
  231. int cell = csvParser.GetCellAsInteger(0, cell_y);
  232. if (enabledIDs.Contains(cell))
  233. {
  234. string dogu = String.Empty;
  235. if (csvParser.IsCellToExistData(3, cell_y))
  236. {
  237. dogu = csvParser.GetCellAsString(3, cell_y);
  238. }
  239. else if (csvParser.IsCellToExistData(4, cell_y))
  240. {
  241. dogu = csvParser.GetCellAsString(4, cell_y);
  242. }
  243. if (!string.IsNullOrEmpty(dogu))
  244. {
  245. com3d2DeskDogu.Add(dogu);
  246. }
  247. }
  248. }
  249. }
  250. }
  251. };
  252. GetDeskItems(GameUty.FileSystem);
  253. // GetDeskItems(GameUty.FileSystemOld);
  254. OtherDoguList.AddRange(com3d2DeskDogu);
  255. }
  256. private static void InitializePhotoBGItems()
  257. {
  258. PhotoBGObjectData.Create();
  259. List<PhotoBGObjectData> photoBGObjectList = PhotoBGObjectData.data;
  260. List<string> particleList = new List<string>();
  261. List<string> doguPrefabList = new List<string>();
  262. List<string> doguAssetList = new List<string>();
  263. List<string> directFileList = new List<string>();
  264. foreach (PhotoBGObjectData photoBgObject in photoBGObjectList)
  265. {
  266. if (!string.IsNullOrEmpty(photoBgObject.create_prefab_name))
  267. {
  268. List<string> list = photoBgObject.category == "パーティクル"
  269. ? particleList
  270. : doguPrefabList;
  271. list.Add(photoBgObject.create_prefab_name);
  272. }
  273. else if (!string.IsNullOrEmpty(photoBgObject.create_asset_bundle_name))
  274. {
  275. doguAssetList.Add(photoBgObject.create_asset_bundle_name);
  276. }
  277. else if (!string.IsNullOrEmpty(photoBgObject.direct_file))
  278. {
  279. directFileList.Add(photoBgObject.direct_file);
  280. }
  281. }
  282. OtherDoguList.AddRange(new[] {
  283. "Particle/pLineY", "Particle/pLineP02", "Particle/pHeart01",
  284. "Particle/pLine_act2", "Particle/pstarY_act2"
  285. });
  286. OtherDoguList.AddRange(particleList);
  287. DoguList.AddRange(doguPrefabList);
  288. DoguList.AddRange(doguAssetList);
  289. DoguList.AddRange(directFileList);
  290. string ignoreListPath = Path.Combine(configPath, "mm_ignore_list.json");
  291. string ignoreListJson = File.ReadAllText(ignoreListPath);
  292. string[] ignoreList = JsonConvert.DeserializeObject<IEnumerable<string>>(ignoreListJson).ToArray();
  293. // bg object extend
  294. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  295. foreach (string bg in BGList)
  296. {
  297. doguHashSet.Add(bg);
  298. }
  299. foreach (string bg in ignoreList)
  300. {
  301. doguHashSet.Add(bg);
  302. }
  303. foreach (string dogu in DoguList)
  304. {
  305. doguHashSet.Add(dogu);
  306. }
  307. foreach (string dogu in OtherDoguList)
  308. {
  309. doguHashSet.Add(dogu);
  310. }
  311. string[] com3d2BgList = GameUty.FileSystem.GetList("bg", AFileSystemBase.ListType.AllFile);
  312. foreach (string path in com3d2BgList)
  313. {
  314. if (Path.GetExtension(path) == ".asset_bg" && !path.Contains("myroomcustomize"))
  315. {
  316. string file = Path.GetFileNameWithoutExtension(path);
  317. if (!doguHashSet.Contains(file) && !file.EndsWith("_hit"))
  318. {
  319. DoguList.Add(file);
  320. doguHashSet.Add(file);
  321. }
  322. }
  323. }
  324. // Get cherry picked dogu that I can't find in the game files
  325. string doguExtendPath = Path.Combine(configPath, "mm_dogu_extend.json");
  326. string doguExtendJson = File.ReadAllText(doguExtendPath);
  327. DoguList.AddRange(JsonConvert.DeserializeObject<IEnumerable<string>>(doguExtendJson));
  328. string[] cm3d2BgList = GameUty.FileSystemOld.GetList("bg", AFileSystemBase.ListType.AllFile);
  329. foreach (string path in cm3d2BgList)
  330. {
  331. if (Path.GetExtension(path) == ".asset_bg")
  332. {
  333. string file = Path.GetFileNameWithoutExtension(path);
  334. if (!doguHashSet.Contains(file) && !file.EndsWith("_not_optimisation"))
  335. {
  336. DoguList.Add(file);
  337. }
  338. }
  339. }
  340. }
  341. private static void InitializeHandItems()
  342. {
  343. List<string> handItems = new List<string>(
  344. GameUty.MenuFiles.Where(menu => menu.StartsWith("handiteml") || menu.StartsWith("handitemr"))
  345. );
  346. }
  347. private static CsvParser OpenCsvParser(string nei, AFileSystemBase fs)
  348. {
  349. try
  350. {
  351. if (fs.IsExistentFile(nei))
  352. {
  353. AFileBase file = fs.FileOpen(nei);
  354. CsvParser csvParser = new CsvParser();
  355. if (csvParser.Open(file)) return csvParser;
  356. else file?.Dispose();
  357. }
  358. }
  359. catch { }
  360. return null;
  361. }
  362. private static CsvParser OpenCsvParser(string nei)
  363. {
  364. return OpenCsvParser(nei, GameUty.FileSystem);
  365. }
  366. public static void WriteToFile(string name, IEnumerable<string> list)
  367. {
  368. if (Path.GetExtension(name) != ".txt") name += ".txt";
  369. File.WriteAllLines(Path.Combine(configPath, name), list.ToArray());
  370. }
  371. private class SerializePoseList
  372. {
  373. public string UIName { get; set; }
  374. public List<string> PoseList { get; set; }
  375. }
  376. }
  377. }