Constants.cs 17 KB

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