Constants.cs 11 KB

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