//发送新的lua代码 public static void SendLuaSciprtSource(string fileName, bool isFilePath) { if (HttpPushHostingService.GetAsyncSocket().isConnected) { string luaFullPath = fileName; if (!isFilePath) { luaFullPath = (G6HotFixConst.LUA_SOURCES_PATH + fileName).Replace('.', '/'); } if (File.Exists(luaFullPath)) { string luaName = LuaScriptManager.ConvertProjectPathToScriptPath(luaFullPath); var sendMsg = $"#LuaPush#luaName={luaName}#luaSrc={File.ReadAllText(luaFullPath)}"; HttpPushHostingService.GetAsyncSocket().Send(sendMsg); } else { G6Debugger.LogError("lua file does't exist!"); } } else { G6Debugger.LogErrorFormat("PushServer is't connected!"); } }
// 调用cmd private static void ProcessCommand(string command, string argument) { var info = new System.Diagnostics.ProcessStartInfo(command) { Arguments = argument, CreateNoWindow = false, ErrorDialog = true, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, RedirectStandardInput = true, StandardOutputEncoding = Encoding.UTF8, StandardErrorEncoding = Encoding.UTF8 }; System.Diagnostics.Process process = System.Diagnostics.Process.Start(info); Debug.Assert(process != null, nameof(process) + " != null"); G6Debugger.Log(process.StandardOutput); G6Debugger.Log(process.StandardError); process.WaitForExit(); process.Close(); }
protected virtual void ReceiveCallback(IAsyncResult ar) { SocketStateObject state = (SocketStateObject)ar.AsyncState; Socket handler = state.workSocket; try { int byteRead = handler.EndReceive(ar); if (byteRead > 0) { if (!isPackageSplit) { Buffer.BlockCopy(emptyArr, 0, dataArr, 0, 64 * 1024); //获取数据长度; byte[] datalengtharr = new byte[4]; Buffer.BlockCopy(state.buffer, 0, datalengtharr, 0, 4); packagelen = BitConverter.ToInt32(datalengtharr, 0); G6Debugger.LogFormat("receive: byteRead={0} length = {1}", byteRead, packagelen); //获取数据主体; Buffer.BlockCopy(state.buffer, 4, dataArr, 0, byteRead - 4); byteIndex = byteRead - 4; unreceiveLen = packagelen - (byteRead - 4); } else { int enableLen = Math.Min(byteRead, unreceiveLen); Buffer.BlockCopy(state.buffer, 0, dataArr, byteIndex, enableLen); byteIndex = byteIndex + enableLen; unreceiveLen = unreceiveLen - enableLen; G6Debugger.LogFormat("receive break: byteRead={0} length={1} byteIndex={2}", byteRead, packagelen, byteIndex); } G6Debugger.LogFormat("ReceiveCallback unreceiveLen:{0}", unreceiveLen); //判断数据长度,是否接收完全; if (unreceiveLen <= 0) { isPackageSplit = false; AddResponse(Encoding.UTF8.GetString(dataArr, 0, packagelen)); } else { isPackageSplit = true; } } handler.BeginReceive(state.buffer, 0, SocketStateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
// 利用adb,将dll从pc push到手机上 // 需要pc中安装adb并配置对应环境变量, 还需要手机上安装的apk是用修改后的UnityAndroidPlayer build出来的 private static void PushDll(string srcDllPath) { string dstDllPath = string.Format(ANDROID_REMOTE_CUSTOM_DLL_PATH, Application.identifier, DLL_NAME); if (!File.Exists(srcDllPath)) { G6Debugger.LogErrorFormat("File does 't exist in path {0}! ", srcDllPath); return; } //通过命令行的形式调用adb,并输出指令,第三方调用了。 //“adb push src dst” //命令的内容为更新一个dll ProcessCommand("adb", $"push {srcDllPath} {dstDllPath}"); LaunchGameOnAndroid(); }
protected override void SendCallback(IAsyncResult ar) { try { // Retrieve the socket from the state object. Socket client = (Socket)ar.AsyncState; // Complete sending the data to the remote device. int bytesSent = client.EndSend(ar); G6Debugger.LogFormat("Sent {0} bytes to server.", bytesSent); } catch (Exception e) { G6Debugger.LogError(e.ToString()); } }
// public static void InternalBuildAndPushDll(bool isScriptsOnly) { var buildPlayerOptions = new BuildPlayerOptions(); var scenes = new List <string>(); foreach (var t in EditorBuildSettings.scenes) { if (t.enabled) { scenes.Add(t.path); } } buildPlayerOptions.scenes = scenes.ToArray(); buildPlayerOptions.locationPathName = $"AndroidBuild/{Application.productName}.apk"; buildPlayerOptions.target = BuildTarget.Android; buildPlayerOptions.options = isScriptsOnly ? BuildOptions.Development | BuildOptions.BuildScriptsOnly : BuildOptions.Development; var report = BuildPipeline.BuildPlayer(buildPlayerOptions); var summary = report.summary; switch (summary.result) { case BuildResult.Succeeded: G6Debugger.Log("Build succeeded: " + summary.totalSize + " bytes"); string projectPath = Application.dataPath.Replace("Assets", ""); string srcDllPath = $@"{projectPath}{DLL_LOCAL_ORIGIN_PATH}{DLL_NAME}"; PushDll(srcDllPath); break; case BuildResult.Failed: G6Debugger.Log("Build failed"); break; case BuildResult.Unknown: break; case BuildResult.Cancelled: break; default: throw new ArgumentOutOfRangeException(); } }
public override void Start(IPEndPoint ioEndPoint) { // Connect to a remote device. try { // Create a TCP/IP socket. Socket client = new Socket(ioEndPoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); // Connect to the remote endpoint. G6Debugger.Log("ClientSocket begin connect!"); client.BeginConnect(ioEndPoint, new AsyncCallback(ConnectCallback), client); } catch (Exception e) { G6Debugger.LogError(e.ToString()); } }
private void ConnectCallback(IAsyncResult ar) { try { // Retrieve the socket from the state object. Socket client = (Socket)ar.AsyncState; curSocketStateObject = new SocketStateObject(); curSocketStateObject.workSocket = client; client.BeginReceive(curSocketStateObject.buffer, 0, SocketStateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), curSocketStateObject); G6Debugger.Log("Hotfix server Connected!!!!!!!!"); } catch (Exception e) { G6Debugger.LogError(e.ToString()); } }
public override void Start(IPEndPoint ipEndPoint) { // Socket // Bind the socket to the local endpoint and listen for incoming connections. try { socketListener = new Socket(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); socketListener.Bind(ipEndPoint); socketListener.Listen(5); // Start an asynchronous socket to listen for connections. G6Debugger.Log("Waiting for a connection..."); socketListener.BeginAccept( new AsyncCallback(AcceptCallback), socketListener); } catch (Exception e) { G6Debugger.LogError(e.ToString()); } }
//收到要更新的脚本信息 private void OnReceiveSocketData(string data) { if (data == null) { return; } if (data.StartsWith("#LuaPush#")) { Regex r = new Regex(@"^#LuaPush#luaName=(?<name>.+)#luaSrc=(?<src>.+)", RegexOptions.Singleline); string luaName = r.Match(data).Groups["name"].Value; string luaSrc = r.Match(data).Groups["src"].Value; G6Debugger.LogFormat("ReloadLua:{0}", luaName); LuaScriptManager.Instance.ReplaceLuaSrcText(luaName, luaSrc); } else { G6Debugger.LogFormat("HotfixServer Msg:{0}", data); } }