123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- using System;
- using System.Collections;
- using System.Diagnostics;
- using System.IO;
- using UnityEngine;
- namespace CRCEdit
- {
- public class EditBridge
- {
- public static string EditWorkDirectory
- {
- get
- {
- return Path.Combine(UTY.gameProjectPath, ".__EDITWORK__");
- }
- }
- public static string CREditSystemExePath
- {
- get
- {
- string text = Path.Combine(GameMain.Instance.CMSystem.CREditSystemPath, "CR EditSystem.exe");
- return (!File.Exists(text)) ? string.Empty : text;
- }
- }
- public static string CREditSystemLauncherExePath
- {
- get
- {
- string text = Path.Combine(GameMain.Instance.CMSystem.CREditSystemPath, "CR Launcher.exe");
- return (!File.Exists(text)) ? string.Empty : text;
- }
- }
- public static bool Import(Maid maid)
- {
- Action action = delegate()
- {
- if (Directory.Exists(EditBridge.EditWorkDirectory))
- {
- Directory.Delete(EditBridge.EditWorkDirectory, true);
- }
- };
- if (maid != null && maid.ActiveSlotNo != 0)
- {
- GameMain.Instance.CharacterMgr.SetActiveMaid(maid, 0);
- }
- if (maid == null || !File.Exists(Path.Combine(EditBridge.EditWorkDirectory, "__finishfile__")))
- {
- action();
- return false;
- }
- bool result = !GameMain.Instance.CharacterMgr.ImportBreadgeGP03(EditBridge.EditWorkDirectory, 0);
- action();
- return result;
- }
- public static bool StartEdit(Maid maid, Action onNewEditFinished)
- {
- return EditBridge.launcherProcess == null && EditBridge.editProcess == null && EditBridge.Initialize(maid, onNewEditFinished);
- }
- private static bool Initialize(Maid maid, Action onNewEditFinished)
- {
- if (DllBase.Win32.hWnd == IntPtr.Zero || maid == null || maid.body0 == null || GameMain.Instance.CharacterMgr.IsBusy())
- {
- return false;
- }
- try
- {
- string workDirectory = EditBridge.EditWorkDirectory;
- if (Directory.Exists(workDirectory))
- {
- Directory.Delete(workDirectory, true);
- }
- Directory.CreateDirectory(workDirectory);
- DllBase.Win32.ShowWindow(DllBase.Win32.hWnd, 6);
- EditBridge.CallLauncher(delegate
- {
- EditBridge.CallEdit(workDirectory, maid, onNewEditFinished);
- });
- }
- catch (Exception ex)
- {
- UnityEngine.Debug.LogError(ex.Message);
- EditBridge.editProcess = null;
- DllBase.Win32.ShowWindow(DllBase.Win32.hWnd, 1);
- return false;
- }
- return true;
- }
- private static bool CallLauncher(Action onFinished)
- {
- string[] array = new string[]
- {
- "-batchmode",
- "-clientid:com3d2",
- "-clientpath:" + UTY.gameProjectPath,
- "/dlcup"
- };
- string text = string.Empty;
- foreach (string str in array)
- {
- text = text + str + " ";
- }
- EditBridge.launcherProcess = new Process
- {
- StartInfo =
- {
- FileName = EditBridge.CREditSystemLauncherExePath,
- Arguments = text,
- WorkingDirectory = GameMain.Instance.CMSystem.CREditSystemPath
- }
- };
- if (!File.Exists(EditBridge.launcherProcess.StartInfo.FileName))
- {
- UnityEngine.Debug.LogError("Launcher not existed. -> " + EditBridge.CREditSystemLauncherExePath);
- return false;
- }
- EditBridge.onLauncherFinished = onFinished;
- EditBridge.launcherProcess.Start();
- GameMain.Instance.StartCoroutine(EditBridge.WaitLauncher());
- return true;
- }
- private static IEnumerator WaitLauncher()
- {
- while (EditBridge.launcherProcess == null || !EditBridge.launcherProcess.HasExited)
- {
- yield return null;
- }
- EditBridge.launcherProcess = null;
- if (EditBridge.onLauncherFinished != null)
- {
- EditBridge.onLauncherFinished();
- EditBridge.onLauncherFinished = null;
- }
- yield break;
- }
- private static bool CallEdit(string workDirectory, Maid maid, Action onNewEditFinished)
- {
- GameMain.Instance.CharacterMgr.ExportBridgeGP03(workDirectory, maid);
- string[] array = new string[]
- {
- "-workpath:" + workDirectory,
- "-maidguid:" + maid.status.guid,
- "-savemaidguid:" + maid.status.saveDataGuidGP03Temp,
- "-clientid:com3d2",
- "-clientpath:" + UTY.gameProjectPath,
- "-usenetwork:" + GameMain.Instance.CMSystem.NetUse.ToString()
- };
- string text = string.Empty;
- foreach (string str in array)
- {
- text = text + str + " ";
- }
- EditBridge.editProcess = new Process
- {
- StartInfo =
- {
- FileName = EditBridge.CREditSystemExePath,
- Arguments = text,
- WorkingDirectory = GameMain.Instance.CMSystem.CREditSystemPath
- }
- };
- if (!File.Exists(EditBridge.editProcess.StartInfo.FileName))
- {
- return false;
- }
- if (GameMain.Instance.Webs != null)
- {
- GameMain.Instance.Webs.Uninit();
- }
- EditBridge.editProcess.Start();
- EditBridge.onNewEditFinished = onNewEditFinished;
- GameMain.Instance.StartCoroutine(EditBridge.WaitEdit());
- return true;
- }
- private static IEnumerator WaitEdit()
- {
- while (EditBridge.editProcess == null || !EditBridge.editProcess.HasExited)
- {
- yield return null;
- }
- if (GameMain.Instance.Webs != null)
- {
- GameMain.Instance.Webs.Init();
- }
- EditBridge.editProcess = null;
- DllBase.Win32.ShowWindow(DllBase.Win32.hWnd, 1);
- if (EditBridge.onNewEditFinished != null)
- {
- EditBridge.onNewEditFinished();
- EditBridge.onNewEditFinished = null;
- }
- yield break;
- }
- public const string CrEditSystemLauncherExeName = "CR Launcher.exe";
- public const string CrEditSystemExeName = "CR EditSystem.exe";
- protected static Process editProcess;
- protected static Process launcherProcess;
- protected static Action onLauncherFinished;
- protected static Action onNewEditFinished;
- }
- }
|