/// <summary> /// Initialize Game /// </summary> public static void Initialize() { if (initialized) { return; } initialized = true; RegisterTypes(); PacketObject.CollectAllRegisteredPackets(); }
private void TransformLog(string rLogFile, Assembly assembly) { if (!rLogFile.EndsWith(".log")) { EditorUtility.DisplayDialog("错误提示", "不是有效的日志文件,只能转换.log后缀的文件", "确定"); return; } var file = rLogFile; PacketObject.CollectAllRegisteredPackets(); Stream stream = File.OpenRead(file); if (file.EndsWith(".log")) { byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); stream = new MemoryStream(Util.DecompressData(bytes)); } StringBuilder sb = new StringBuilder(); Command command = Command.Create(); while (stream.CanRead && stream.Position < stream.Length) { command.UnSerialize(stream); EditorUtility.DisplayProgressBar("格式转换", command.cache._name, (float)stream.Position / stream.Length); var stack = command.cache as LogStack; if (stack != null) { for (var i = 0; i < stack.method.Length; i++) { var m = stack.method[i]; ArrayList arr; if (!cache.TryGetValue(m.typeHash, out arr)) { arr = TypeSearch.Search(t => t.Name.GetHashCode() == m.typeHash, assembly); cache.Add(m.typeHash, arr); } if (arr.Count > 0) { var type = (System.Type)arr[0]; if (type != null) { var methods = type.GetMethods(); if (m.methodIndex < methods.Length) { var method = methods[m.methodIndex]; sb.AppendLine($"({type.Name}) {method}"); } } } } continue; } var s = LitJson.JsonMapper.ToJson(command.cache); var index = s.IndexOf("tag"); if (index >= 0) { var endIndex = s.IndexOf(',', index); var old = s.Substring(index, endIndex > index ? endIndex - index : s.Length - index); s = s.Replace(old, $"tag\":\"{(TagType) (byte) command.cache.GetType().GetField("tag").GetValue(command.cache)}\""); } sb.AppendLine(s); } command.Destroy(); EditorUtility.ClearProgressBar(); var writer = File.CreateText(file.Replace(".log", ".txt")); writer.Write(sb.ToString()); writer.Close(); }