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