EditBridge.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using System;
  2. using System.Collections;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using UnityEngine;
  6. namespace CRCEdit
  7. {
  8. public class EditBridge
  9. {
  10. public static string EditWorkDirectory
  11. {
  12. get
  13. {
  14. return Path.Combine(UTY.gameProjectPath, ".__EDITWORK__");
  15. }
  16. }
  17. public static string CREditSystemExePath
  18. {
  19. get
  20. {
  21. string text = Path.Combine(GameMain.Instance.CMSystem.CREditSystemPath, "CR EditSystem.exe");
  22. return (!File.Exists(text)) ? string.Empty : text;
  23. }
  24. }
  25. public static string CREditSystemLauncherExePath
  26. {
  27. get
  28. {
  29. string text = Path.Combine(GameMain.Instance.CMSystem.CREditSystemPath, "CR Launcher.exe");
  30. return (!File.Exists(text)) ? string.Empty : text;
  31. }
  32. }
  33. public static bool Import(Maid maid)
  34. {
  35. Action action = delegate()
  36. {
  37. if (Directory.Exists(EditBridge.EditWorkDirectory))
  38. {
  39. Directory.Delete(EditBridge.EditWorkDirectory, true);
  40. }
  41. };
  42. if (maid != null && maid.ActiveSlotNo != 0)
  43. {
  44. GameMain.Instance.CharacterMgr.SetActiveMaid(maid, 0);
  45. }
  46. if (maid == null || !File.Exists(Path.Combine(EditBridge.EditWorkDirectory, "__finishfile__")))
  47. {
  48. action();
  49. return false;
  50. }
  51. bool result = !GameMain.Instance.CharacterMgr.ImportBreadgeGP03(EditBridge.EditWorkDirectory, 0);
  52. action();
  53. return result;
  54. }
  55. public static bool StartEdit(Maid maid, Action onNewEditFinished)
  56. {
  57. return EditBridge.launcherProcess == null && EditBridge.editProcess == null && EditBridge.Initialize(maid, onNewEditFinished);
  58. }
  59. private static bool Initialize(Maid maid, Action onNewEditFinished)
  60. {
  61. if (DllBase.Win32.hWnd == IntPtr.Zero || maid == null || maid.body0 == null || GameMain.Instance.CharacterMgr.IsBusy())
  62. {
  63. return false;
  64. }
  65. try
  66. {
  67. string workDirectory = EditBridge.EditWorkDirectory;
  68. if (Directory.Exists(workDirectory))
  69. {
  70. Directory.Delete(workDirectory, true);
  71. }
  72. Directory.CreateDirectory(workDirectory);
  73. DllBase.Win32.ShowWindow(DllBase.Win32.hWnd, 6);
  74. EditBridge.CallLauncher(delegate
  75. {
  76. EditBridge.CallEdit(workDirectory, maid, onNewEditFinished);
  77. });
  78. }
  79. catch (Exception ex)
  80. {
  81. UnityEngine.Debug.LogError(ex.Message);
  82. EditBridge.editProcess = null;
  83. DllBase.Win32.ShowWindow(DllBase.Win32.hWnd, 1);
  84. return false;
  85. }
  86. return true;
  87. }
  88. private static bool CallLauncher(Action onFinished)
  89. {
  90. string[] array = new string[]
  91. {
  92. "-batchmode",
  93. "-clientid:com3d2",
  94. "-clientpath:" + UTY.gameProjectPath,
  95. "/dlcup"
  96. };
  97. string text = string.Empty;
  98. foreach (string str in array)
  99. {
  100. text = text + str + " ";
  101. }
  102. EditBridge.launcherProcess = new Process
  103. {
  104. StartInfo =
  105. {
  106. FileName = EditBridge.CREditSystemLauncherExePath,
  107. Arguments = text,
  108. WorkingDirectory = GameMain.Instance.CMSystem.CREditSystemPath
  109. }
  110. };
  111. if (!File.Exists(EditBridge.launcherProcess.StartInfo.FileName))
  112. {
  113. UnityEngine.Debug.LogError("Launcher not existed. -> " + EditBridge.CREditSystemLauncherExePath);
  114. return false;
  115. }
  116. EditBridge.onLauncherFinished = onFinished;
  117. EditBridge.launcherProcess.Start();
  118. GameMain.Instance.StartCoroutine(EditBridge.WaitLauncher());
  119. return true;
  120. }
  121. private static IEnumerator WaitLauncher()
  122. {
  123. while (EditBridge.launcherProcess == null || !EditBridge.launcherProcess.HasExited)
  124. {
  125. yield return null;
  126. }
  127. EditBridge.launcherProcess = null;
  128. if (EditBridge.onLauncherFinished != null)
  129. {
  130. EditBridge.onLauncherFinished();
  131. EditBridge.onLauncherFinished = null;
  132. }
  133. yield break;
  134. }
  135. private static bool CallEdit(string workDirectory, Maid maid, Action onNewEditFinished)
  136. {
  137. GameMain.Instance.CharacterMgr.ExportBridgeGP03(workDirectory, maid);
  138. string[] array = new string[]
  139. {
  140. "-workpath:" + workDirectory,
  141. "-maidguid:" + maid.status.guid,
  142. "-savemaidguid:" + maid.status.saveDataGuidGP03Temp,
  143. "-clientid:com3d2",
  144. "-clientpath:" + UTY.gameProjectPath,
  145. "-usenetwork:" + GameMain.Instance.CMSystem.NetUse.ToString()
  146. };
  147. string text = string.Empty;
  148. foreach (string str in array)
  149. {
  150. text = text + str + " ";
  151. }
  152. EditBridge.editProcess = new Process
  153. {
  154. StartInfo =
  155. {
  156. FileName = EditBridge.CREditSystemExePath,
  157. Arguments = text,
  158. WorkingDirectory = GameMain.Instance.CMSystem.CREditSystemPath
  159. }
  160. };
  161. if (!File.Exists(EditBridge.editProcess.StartInfo.FileName))
  162. {
  163. return false;
  164. }
  165. if (GameMain.Instance.Webs != null)
  166. {
  167. GameMain.Instance.Webs.Uninit();
  168. }
  169. EditBridge.editProcess.Start();
  170. EditBridge.onNewEditFinished = onNewEditFinished;
  171. GameMain.Instance.StartCoroutine(EditBridge.WaitEdit());
  172. return true;
  173. }
  174. private static IEnumerator WaitEdit()
  175. {
  176. while (EditBridge.editProcess == null || !EditBridge.editProcess.HasExited)
  177. {
  178. yield return null;
  179. }
  180. if (GameMain.Instance.Webs != null)
  181. {
  182. GameMain.Instance.Webs.Init();
  183. }
  184. EditBridge.editProcess = null;
  185. DllBase.Win32.ShowWindow(DllBase.Win32.hWnd, 1);
  186. if (EditBridge.onNewEditFinished != null)
  187. {
  188. EditBridge.onNewEditFinished();
  189. EditBridge.onNewEditFinished = null;
  190. }
  191. yield break;
  192. }
  193. public const string CrEditSystemLauncherExeName = "CR Launcher.exe";
  194. public const string CrEditSystemExeName = "CR EditSystem.exe";
  195. protected static Process editProcess;
  196. protected static Process launcherProcess;
  197. protected static Action onLauncherFinished;
  198. protected static Action onNewEditFinished;
  199. }
  200. }