Constants.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. public 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, 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. // ew
  196. if (bg == "Yashiki") BGList.Add("Yashiki_Pillow");
  197. else if (bg == "Train") BGList.Add("train_notsurikawa");
  198. }
  199. }
  200. }
  201. }
  202. Dictionary<string, string> saveDataDict = MyRoomCustom.CreativeRoomManager.GetSaveDataDic();
  203. if (saveDataDict != null)
  204. {
  205. MyRoomCustomBGIndex = BGList.Count;
  206. MyRoomCustomBGList.AddRange(saveDataDict);
  207. }
  208. }
  209. public static void InitializeDogu()
  210. {
  211. InitializeDeskItems();
  212. InitializePhotoBGItems();
  213. // InitializeHandItems();
  214. }
  215. private static void InitializeDeskItems()
  216. {
  217. // enabled id
  218. HashSet<int> enabledIDs = new HashSet<int>();
  219. CsvCommonIdManager.ReadEnabledIdList(
  220. CsvCommonIdManager.FileSystemType.Normal, true, "desk_item_enabled_id", ref enabledIDs
  221. );
  222. CsvCommonIdManager.ReadEnabledIdList(
  223. CsvCommonIdManager.FileSystemType.Old, true, "desk_item_enabled_id", ref enabledIDs
  224. );
  225. List<string> com3d2DeskDogu = new List<string>(new[] {
  226. "Mob_Man_Stand001", "Mob_Man_Stand002", "Mob_Man_Stand003", "Mob_Man_Sit001", "Mob_Man_Sit002",
  227. "Mob_Man_Sit003", "Mob_Girl_Stand001", "Mob_Girl_Stand002", "Mob_Girl_Stand003", "Mob_Girl_Sit001",
  228. "Mob_Girl_Sit002", "Mob_Girl_Sit003", "Salon:65", "Salon:63", "Salon:69"
  229. });
  230. Action<AFileSystemBase> GetDeskItems = fs =>
  231. {
  232. using (CsvParser csvParser = OpenCsvParser("desk_item_detail.nei", fs))
  233. {
  234. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  235. {
  236. if (csvParser.IsCellToExistData(0, cell_y))
  237. {
  238. int cell = csvParser.GetCellAsInteger(0, cell_y);
  239. if (enabledIDs.Contains(cell))
  240. {
  241. string dogu = String.Empty;
  242. if (csvParser.IsCellToExistData(3, cell_y))
  243. {
  244. dogu = csvParser.GetCellAsString(3, cell_y);
  245. }
  246. else if (csvParser.IsCellToExistData(4, cell_y))
  247. {
  248. dogu = csvParser.GetCellAsString(4, cell_y);
  249. }
  250. if (!string.IsNullOrEmpty(dogu))
  251. {
  252. com3d2DeskDogu.Add(dogu);
  253. }
  254. }
  255. }
  256. }
  257. }
  258. };
  259. GetDeskItems(GameUty.FileSystem);
  260. // GetDeskItems(GameUty.FileSystemOld);
  261. OtherDoguList.AddRange(com3d2DeskDogu);
  262. }
  263. private static void InitializePhotoBGItems()
  264. {
  265. PhotoBGObjectData.Create();
  266. List<PhotoBGObjectData> photoBGObjectList = PhotoBGObjectData.data;
  267. List<string> particleList = new List<string>();
  268. List<string> doguPrefabList = new List<string>();
  269. List<string> doguAssetList = new List<string>();
  270. List<string> directFileList = new List<string>();
  271. foreach (PhotoBGObjectData photoBgObject in photoBGObjectList)
  272. {
  273. if (!string.IsNullOrEmpty(photoBgObject.create_prefab_name))
  274. {
  275. List<string> list = photoBgObject.category == "パーティクル"
  276. ? particleList
  277. : doguPrefabList;
  278. list.Add(photoBgObject.create_prefab_name);
  279. }
  280. else if (!string.IsNullOrEmpty(photoBgObject.create_asset_bundle_name))
  281. {
  282. doguAssetList.Add(photoBgObject.create_asset_bundle_name);
  283. }
  284. else if (!string.IsNullOrEmpty(photoBgObject.direct_file))
  285. {
  286. directFileList.Add(photoBgObject.direct_file);
  287. }
  288. }
  289. OtherDoguList.AddRange(new[] {
  290. "Particle/pLineY", "Particle/pLineP02", "Particle/pHeart01",
  291. "Particle/pLine_act2", "Particle/pstarY_act2"
  292. });
  293. OtherDoguList.AddRange(particleList);
  294. DoguList.AddRange(doguPrefabList);
  295. DoguList.AddRange(doguAssetList);
  296. DoguList.AddRange(directFileList);
  297. string ignoreListPath = Path.Combine(configPath, "mm_ignore_list.json");
  298. string ignoreListJson = File.ReadAllText(ignoreListPath);
  299. string[] bgList = JsonConvert.DeserializeObject<IEnumerable<string>>(ignoreListJson).ToArray();
  300. // bg object extend
  301. HashSet<string> doguHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
  302. foreach (string bg in bgList)
  303. {
  304. doguHashSet.Add(bg);
  305. }
  306. foreach (string dogu in DoguList)
  307. {
  308. doguHashSet.Add(dogu);
  309. }
  310. foreach (string dogu in OtherDoguList)
  311. {
  312. doguHashSet.Add(dogu);
  313. }
  314. string[] com3d2BgList = GameUty.FileSystem.GetList("bg", AFileSystemBase.ListType.AllFile);
  315. foreach (string path in com3d2BgList)
  316. {
  317. if (Path.GetExtension(path) == ".asset_bg" && !path.Contains("myroomcustomize"))
  318. {
  319. string file = Path.GetFileNameWithoutExtension(path);
  320. if (!doguHashSet.Contains(file) && !file.EndsWith("_hit"))
  321. {
  322. DoguList.Add(file);
  323. doguHashSet.Add(file);
  324. }
  325. }
  326. }
  327. // Get cherry picked dogu that I can't find in the game files
  328. string doguExtendPath = Path.Combine(configPath, "mm_dogu_extend.json");
  329. string doguExtendJson = File.ReadAllText(doguExtendPath);
  330. DoguList.AddRange(JsonConvert.DeserializeObject<IEnumerable<string>>(doguExtendJson));
  331. string[] cm3d2BgList = GameUty.FileSystemOld.GetList("bg", AFileSystemBase.ListType.AllFile);
  332. foreach (string path in cm3d2BgList)
  333. {
  334. if (Path.GetExtension(path) == ".asset_bg")
  335. {
  336. string file = Path.GetFileNameWithoutExtension(path);
  337. if (!doguHashSet.Contains(file) && !file.EndsWith("_not_optimisation"))
  338. {
  339. DoguList.Add(file);
  340. }
  341. }
  342. }
  343. }
  344. private static CsvParser OpenCsvParser(string nei, AFileSystemBase fs)
  345. {
  346. try
  347. {
  348. if (fs.IsExistentFile(nei))
  349. {
  350. AFileBase file = fs.FileOpen(nei);
  351. CsvParser csvParser = new CsvParser();
  352. if (csvParser.Open(file)) return csvParser;
  353. else file?.Dispose();
  354. }
  355. }
  356. catch { }
  357. return null;
  358. }
  359. private static CsvParser OpenCsvParser(string nei)
  360. {
  361. return OpenCsvParser(nei, GameUty.FileSystem);
  362. }
  363. public static void WriteToFile(string name, IEnumerable<string> list)
  364. {
  365. if (Path.GetExtension(name) != ".txt") name += ".txt";
  366. File.WriteAllLines(Path.Combine(configPath, name), list.ToArray());
  367. }
  368. public class SerializePoseList
  369. {
  370. public string UIName { get; set; }
  371. public List<string> PoseList { get; set; }
  372. }
  373. }
  374. }