Constants.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. namespace COM3D2.MeidoPhotoStudio.Plugin
  9. {
  10. public class Constants
  11. {
  12. public static readonly string customPosePath;
  13. public static readonly string scenesPath;
  14. public static readonly string kankyoPath;
  15. public static readonly string configPath;
  16. public static readonly int mainWindowID = 765;
  17. public static readonly int messageWindowID = 961;
  18. public static readonly int sceneManagerWindowID = 876;
  19. public static readonly int sceneManagerModalID = 283;
  20. public static readonly int dropdownWindowID = 777;
  21. public enum Window
  22. {
  23. Call, Pose, Face, BG, BG2, Message, Save, SaveModal
  24. }
  25. public enum Scene
  26. {
  27. Daily = 3, Edit = 5
  28. }
  29. public static readonly List<string> PoseGroupList;
  30. public static readonly Dictionary<string, List<string>> PoseDict;
  31. public static readonly Dictionary<string, List<KeyValuePair<string, string>>> CustomPoseDict;
  32. public static int CustomPoseGroupsIndex { get; private set; } = -1;
  33. public static int MyRoomCustomBGIndex { get; private set; } = -1;
  34. public static readonly List<string> FaceBlendList;
  35. public static readonly List<string> BGList;
  36. public static List<KeyValuePair<string, string>> MyRoomCustomBGList;
  37. static Constants()
  38. {
  39. string modsPath = Path.Combine(Path.GetFullPath(".\\"), @"Mod\MeidoPhotoStudio");
  40. customPosePath = Path.Combine(modsPath, "Custom Poses");
  41. scenesPath = Path.Combine(modsPath, "Scenes");
  42. kankyoPath = Path.Combine(modsPath, "Environments");
  43. configPath = Path.Combine(
  44. Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
  45. @"Config\MeidoPhotoStudio"
  46. );
  47. PoseDict = new Dictionary<string, List<string>>();
  48. PoseGroupList = new List<string>();
  49. CustomPoseDict = new Dictionary<string, List<KeyValuePair<string, string>>>();
  50. FaceBlendList = new List<string>();
  51. BGList = new List<string>();
  52. MyRoomCustomBGList = new List<KeyValuePair<string, string>>();
  53. }
  54. public static void Initialize()
  55. {
  56. foreach (string dir in new[] { customPosePath, scenesPath, kankyoPath, configPath })
  57. {
  58. if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
  59. }
  60. // Load Poses
  61. string poseListJson = File.ReadAllText(Path.Combine(configPath, "mm_pose_list.json"));
  62. List<SerializePoseList> poseLists = JsonConvert.DeserializeObject<List<SerializePoseList>>(poseListJson);
  63. foreach (SerializePoseList poseList in poseLists)
  64. {
  65. PoseDict[poseList.UIName] = poseList.PoseList;
  66. PoseGroupList.Add(poseList.UIName);
  67. }
  68. // Get Other poses that'll go into Normal 2 and Ero 2
  69. string[] com3d2MotionList = GameUty.FileSystem.GetList("motion", AFileSystemBase.ListType.AllFile);
  70. if (com3d2MotionList != null && com3d2MotionList.Length > 0)
  71. {
  72. HashSet<string> poseSet = new HashSet<string>();
  73. foreach (KeyValuePair<string, List<string>> poses in PoseDict)
  74. {
  75. foreach (string pose in poses.Value)
  76. {
  77. poseSet.Add(pose);
  78. }
  79. }
  80. List<string> editPoseList = new List<string>();
  81. List<string> otherPoseList = new List<string>();
  82. List<string> eroPoseList = new List<string>();
  83. foreach (string path in com3d2MotionList)
  84. {
  85. if (Path.GetExtension(path) == ".anm")
  86. {
  87. string file = Path.GetFileNameWithoutExtension(path);
  88. if (!poseSet.Contains(file))
  89. {
  90. if (file.StartsWith("edit_"))
  91. {
  92. editPoseList.Add(file);
  93. }
  94. else if (file != "dance_cm3d2_001_zoukin" && file != "dance_cm3d2_001_mop"
  95. && file != "aruki_1_idougo_f" && file != "sleep2" && file != "stand_akire2"
  96. && !file.EndsWith("_3_") && !file.EndsWith("_5_") && !file.StartsWith("vr_")
  97. && !file.StartsWith("dance_mc") && !file.Contains("_kubi_") && !file.Contains("a01_")
  98. && !file.Contains("b01_") && !file.Contains("b02_") && !file.EndsWith("_m2")
  99. && !file.EndsWith("_m2_once_") && !file.StartsWith("h_") && !file.StartsWith("event_")
  100. && !file.StartsWith("man_") && !file.EndsWith("_m") && !file.Contains("_m_")
  101. && !file.Contains("_man_")
  102. )
  103. {
  104. if (!path.Contains(@"\sex\")) otherPoseList.Add(file);
  105. else eroPoseList.Add(file);
  106. }
  107. }
  108. }
  109. }
  110. // editPoseList.AddRange(otherPoseList);
  111. PoseDict["normal"].AddRange(editPoseList);
  112. PoseDict["normal2"] = otherPoseList;
  113. PoseDict["ero2"] = eroPoseList;
  114. PoseGroupList.AddRange(new[] { "normal2", "ero2" });
  115. }
  116. CustomPoseGroupsIndex = PoseDict.Count;
  117. Action<string> GetPoses = directory =>
  118. {
  119. List<KeyValuePair<string, string>> poseList = new List<KeyValuePair<string, string>>();
  120. foreach (string file in Directory.GetFiles(directory))
  121. {
  122. if (Path.GetExtension(file) == ".anm")
  123. {
  124. string fileName = Path.GetFileNameWithoutExtension(file);
  125. poseList.Add(new KeyValuePair<string, string>(fileName, file));
  126. }
  127. }
  128. if (poseList.Count > 0)
  129. {
  130. string poseGroupName = new DirectoryInfo(directory).Name;
  131. PoseGroupList.Add(poseGroupName);
  132. CustomPoseDict[poseGroupName] = poseList;
  133. }
  134. };
  135. GetPoses(customPosePath);
  136. foreach (string directory in Directory.GetDirectories(customPosePath))
  137. {
  138. GetPoses(directory);
  139. }
  140. // Load Face Blends Presets
  141. using (CsvParser csvParser = OpenCsvParser("phot_face_list.nei"))
  142. {
  143. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  144. {
  145. if (csvParser.IsCellToExistData(3, cell_y))
  146. {
  147. string blendValue = csvParser.GetCellAsString(3, cell_y);
  148. FaceBlendList.Add(blendValue);
  149. }
  150. }
  151. }
  152. // Load BGs
  153. PhotoBGData.Create();
  154. List<PhotoBGData> photList = PhotoBGData.data;
  155. // COM3D2 BGs
  156. foreach (PhotoBGData bgData in photList)
  157. {
  158. if (!string.IsNullOrEmpty(bgData.create_prefab_name))
  159. {
  160. string bg = bgData.create_prefab_name;
  161. BGList.Add(bg);
  162. }
  163. }
  164. // CM3D2 BGs
  165. if (GameUty.IsEnabledCompatibilityMode)
  166. {
  167. using (CsvParser csvParser = OpenCsvParser("phot_bg_list.nei", GameUty.FileSystemOld))
  168. {
  169. for (int cell_y = 1; cell_y < csvParser.max_cell_y; cell_y++)
  170. {
  171. if (csvParser.IsCellToExistData(3, cell_y))
  172. {
  173. string bg = csvParser.GetCellAsString(3, cell_y);
  174. BGList.Add(bg);
  175. // ew
  176. if (bg == "Yashiki") BGList.Add("Yashiki_Pillow");
  177. else if (bg == "Train") BGList.Add("train_notsurikawa");
  178. }
  179. }
  180. }
  181. }
  182. Dictionary<string, string> saveDataDict = MyRoomCustom.CreativeRoomManager.GetSaveDataDic();
  183. if (saveDataDict != null)
  184. {
  185. MyRoomCustomBGIndex = BGList.Count;
  186. MyRoomCustomBGList.AddRange(saveDataDict);
  187. }
  188. }
  189. private static CsvParser OpenCsvParser(string nei, AFileSystemBase fs)
  190. {
  191. try
  192. {
  193. if (fs.IsExistentFile(nei))
  194. {
  195. AFileBase file = fs.FileOpen(nei);
  196. CsvParser csvParser = new CsvParser();
  197. if (csvParser.Open(file)) return csvParser;
  198. }
  199. }
  200. catch { }
  201. return null;
  202. }
  203. private static CsvParser OpenCsvParser(string nei)
  204. {
  205. return OpenCsvParser(nei, GameUty.FileSystem);
  206. }
  207. public class SerializePoseList
  208. {
  209. public string UIName { get; set; }
  210. public List<string> PoseList { get; set; }
  211. }
  212. }
  213. public static class Translation
  214. {
  215. public static Dictionary<string, Dictionary<string, string>> Translations;
  216. public static string CurrentLanguage { get; set; }
  217. public static void Initialize(string language)
  218. {
  219. CurrentLanguage = language;
  220. string translationFile = $"translations.{language}.json";
  221. string translationPath = Path.Combine(Constants.configPath, translationFile);
  222. string translationJson = File.ReadAllText(translationPath);
  223. JObject translation = JObject.Parse(translationJson);
  224. Translations = new Dictionary<string, Dictionary<string, string>>(
  225. StringComparer.InvariantCultureIgnoreCase
  226. );
  227. foreach (JProperty translationProp in translation.AsJEnumerable())
  228. {
  229. JToken token = translationProp.Value;
  230. Translations[translationProp.Path] = token.ToObject<Dictionary<string, string>>();
  231. }
  232. }
  233. public static string Get(string category, string text)
  234. {
  235. if (!Translations.ContainsKey(category))
  236. {
  237. Debug.LogWarning($"Could not find category '{category}'");
  238. return null;
  239. }
  240. if (!Translations[category].ContainsKey(text))
  241. {
  242. Debug.LogWarning($"Could not find translation for '{text}'");
  243. return null;
  244. }
  245. return Translations[category][text];
  246. }
  247. public static string[] GetArray(string category, IEnumerable<string> list)
  248. {
  249. return GetList(category, list).ToArray();
  250. }
  251. public static IEnumerable<string> GetList(string category, IEnumerable<string> list)
  252. {
  253. return list.Select(uiName => Get(category, uiName) ?? uiName);
  254. }
  255. public static string[] GetList(string category, IEnumerable<KeyValuePair<string, string>> list)
  256. {
  257. return list.Select(kvp => Get(category, kvp.Key) ?? kvp.Key).ToArray();
  258. }
  259. }
  260. }