diff --git a/.gitignore b/.gitignore index 8c44c2fa..7fee2209 100644 --- a/.gitignore +++ b/.gitignore @@ -102,4 +102,5 @@ Sandbox/ #Luban Luban/.cache.meta -GenerateDatas/ \ No newline at end of file +GenerateDatas/ +Assets/HybridCLRData.meta diff --git a/Assets/GameScripts/HotFix/BattleCore/Empty.cs b/Assets/GameScripts/HotFix/BattleCore/Empty.cs new file mode 100644 index 00000000..ff2bccb0 --- /dev/null +++ b/Assets/GameScripts/HotFix/BattleCore/Empty.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace BattleCore.Runtime +{ + public class Empty : MonoBehaviour + { + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } + } +} diff --git a/Assets/GameScripts/HotFix/BattleCore/Empty.cs.meta b/Assets/GameScripts/HotFix/BattleCore/Empty.cs.meta new file mode 100644 index 00000000..94b676bf --- /dev/null +++ b/Assets/GameScripts/HotFix/BattleCore/Empty.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1fc394f8c6ad5304a82ff84b4263756f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameScripts/HotFix/GameProto/GameProtocol.meta b/Assets/GameScripts/HotFix/GameProto/GameProtocol.meta new file mode 100644 index 00000000..b90a92f1 --- /dev/null +++ b/Assets/GameScripts/HotFix/GameProto/GameProtocol.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 86ce21ac2bf6d5543b8b0cc7f1972046 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameScripts/HotFix/GameProto/GameProtocol/ProtoBase.cs b/Assets/GameScripts/HotFix/GameProto/GameProtocol/ProtoBase.cs new file mode 100644 index 00000000..6189efbf --- /dev/null +++ b/Assets/GameScripts/HotFix/GameProto/GameProtocol/ProtoBase.cs @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using ProtoBuf; +using TEngine; +using System.Collections.Generic; + +namespace GameProto +{ + // 这个文件只放协议,和协议头 + // 消息协议 + [Serializable,global::ProtoBuf.ProtoContract(Name = @"CSPkg")] + public partial class CSPkg + { + [global::ProtoBuf.ProtoMember(1)] + public CSPkgHead Head { get; set; } + + [global::ProtoBuf.ProtoMember(2)] + public CSPkgBody Body { get; set; } + + } + + // 消息协议头 + [Serializable,global::ProtoBuf.ProtoContract(Name = @"CSPkgHead")] + public partial class CSPkgHead + { + [global::ProtoBuf.ProtoMember(1)] + public uint MsgId { get; set; } + + [global::ProtoBuf.ProtoMember(2)] + public uint MsgLength { get; set; } + + [global::ProtoBuf.ProtoMember(3)] + public uint MsgVersion { get; set; } + + [global::ProtoBuf.ProtoMember(4)] + public uint Echo { get; set; } + + [global::ProtoBuf.ProtoMember(5)] + public uint SvrTime { get; set; } + + } + + // 消息协议体 + [Serializable,global::ProtoBuf.ProtoContract(Name = @"CSPkgBody")] + public partial class CSPkgBody + { + } + + // 协议ID + [global::ProtoBuf.ProtoContract()] + public enum CSMsgID + { + CS_START = 0, + + CS_HeartBeat = 10001, + + CS_END = 10000, + + } + +} \ No newline at end of file diff --git a/Assets/GameScripts/HotFix/GameProto/GameProtocol/ProtoBase.cs.meta b/Assets/GameScripts/HotFix/GameProto/GameProtocol/ProtoBase.cs.meta new file mode 100644 index 00000000..6c89bcdd --- /dev/null +++ b/Assets/GameScripts/HotFix/GameProto/GameProtocol/ProtoBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6d59eaaad20d9234ba941173b39361fc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameScripts/Main/Procedure/ProcedureLoadAssembly.cs b/Assets/GameScripts/Main/Procedure/ProcedureLoadAssembly.cs index 7ab2c23b..01931900 100644 --- a/Assets/GameScripts/Main/Procedure/ProcedureLoadAssembly.cs +++ b/Assets/GameScripts/Main/Procedure/ProcedureLoadAssembly.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; using System.IO; -#if HybridCLR_Enable using HybridCLR; -#endif using UnityEngine; using TEngine; using System.Reflection; @@ -21,287 +19,264 @@ namespace GameMain /// public bool NeedLoadDll => GameModule.Resource.playMode == EPlayMode.HostPlayMode || GameModule.Resource.playMode == EPlayMode.OfflinePlayMode; - public override bool UseNativeDialog => true; -// private int m_LoadAssetCount; -// private int m_LoadMetadataAssetCount; -// private int m_FailureAssetCount; -// private int m_FailureMetadataAssetCount; -// private bool m_LoadAssemblyComplete; -// private bool m_LoadMetadataAssemblyComplete; -// private bool m_LoadAssemblyWait; -// private bool m_LoadMetadataAssemblyWait; -// private System.Reflection.Assembly m_MainLogicAssembly; -// private List m_HotfixAssemblys; -// private IFsm m_procedureOwner; -// -// protected override void OnEnter(IFsm procedureOwner) -// { -// base.OnEnter(procedureOwner); -// Log.Debug("HyBridCLR ProcedureLoadAssembly OnEnter"); -// m_procedureOwner = procedureOwner; -// m_LoadAssemblyComplete = false; -// m_HotfixAssemblys = new List(); -// -// if (!NeedLoadDll || GameModule.Resource.playMode == EPlayMode.EditorSimulateMode) -// { -// m_MainLogicAssembly = GetMainLogicAssembly(); -// } -// else -// { -// if (SettingsUtils.HybridCLRCustomGlobalSettings.Enable) -// { -// m_LoadAssetCallbacks ??= new LoadAssetCallbacks(LoadAssetSuccess, LoadAssetFailure); -// foreach (var hotUpdateDllName in SettingsUtils.HybridCLRCustomGlobalSettings.HotUpdateAssemblies) -// { -// var assetPath = Utility.Path.GetRegularPath( -// Path.Combine( -// "Assets", -// SettingsUtils.HybridCLRCustomGlobalSettings.AssemblyTextAssetPath, -// $"{hotUpdateDllName}{SettingsUtils.HybridCLRCustomGlobalSettings.AssemblyTextAssetExtension}")); -// Log.Debug($"LoadAsset: [ {assetPath} ]"); -// m_LoadAssetCount++; -// GameModule.Resource.LoadAssetAsync(assetPath,typeof(UnityEngine.TextAsset), m_LoadAssetCallbacks, hotUpdateDllName); -// } -// -// m_LoadAssemblyWait = true; -// } -// else -// { -// m_MainLogicAssembly = GetMainLogicAssembly(); -// } -// } -// -// if (SettingsUtils.HybridCLRCustomGlobalSettings.Enable) -// { -// #if !UNITY_EDITOR -// m_LoadMetadataAssemblyComplete = false; -// LoadMetadataForAOTAssembly(); -// #else -// m_LoadMetadataAssemblyComplete = true; -// #endif -// } -// else -// { -// m_LoadMetadataAssemblyComplete = true; -// } -// -// if (m_LoadAssetCount == 0) -// { -// m_LoadAssemblyComplete = true; -// } -// } -// -// protected override void OnUpdate(IFsm procedureOwner, float elapseSeconds, float realElapseSeconds) -// { -// base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds); -// if (!m_LoadAssemblyComplete) -// { -// return; -// } -// if (!m_LoadMetadataAssemblyComplete) -// { -// return; -// } -// AllAssemblyLoadComplete(); -// } -// -// private void AllAssemblyLoadComplete() -// { -// if (GameModule.Resource.playMode == EPlayMode.EditorSimulateMode) -// { -// ChangeState(m_procedureOwner); -// return; -// } -// if (m_MainLogicAssembly == null) -// { -// Log.Fatal($"Main logic assembly missing."); -// return; -// } -// var appType = m_MainLogicAssembly.GetType("GameMain"); -// if (appType == null) -// { -// Log.Fatal($"Main logic type 'GameMain' missing."); -// return; -// } -// var entryMethod = appType.GetMethod("Entrance"); -// if (entryMethod == null) -// { -// Log.Fatal($"Main logic entry method 'Entrance' missing."); -// return; -// } -// object[] objects = new object[] { new object[] { m_HotfixAssemblys } }; -// entryMethod.Invoke(appType, objects); -// ChangeState(m_procedureOwner); -// } -// -// private Assembly GetMainLogicAssembly() -// { -// Assembly mainLogicAssembly = null; -// foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) -// { -// if (string.Compare(SettingsUtils.HybridCLRCustomGlobalSettings.LogicMainDllName, $"{assembly.GetName().Name}.dll", -// StringComparison.Ordinal) == 0) -// { -// mainLogicAssembly = assembly; -// } -// -// foreach (var hotUpdateDllName in SettingsUtils.HybridCLRCustomGlobalSettings.HotUpdateAssemblies) -// { -// if (hotUpdateDllName == $"{assembly.GetName().Name}.dll") -// { -// m_HotfixAssemblys.Add(assembly); -// } -// } -// -// if (mainLogicAssembly != null && m_HotfixAssemblys.Count == SettingsUtils.HybridCLRCustomGlobalSettings.HotUpdateAssemblies.Count) -// { -// break; -// } -// } -// -// return mainLogicAssembly; -// } -// -// /// -// /// 加载代码资源成功回调。 -// /// -// /// 资源名称。 -// /// 资源实例。 -// /// 加载耗时。 -// /// 用户数据。 -// private void LoadAssetSuccess(string assetName, object asset, float duration, object userData) -// { -// m_LoadAssetCount--; -// Log.Debug($"LoadAssetSuccess, assetName: [ {assetName} ], duration: [ {duration} ], userData: [ {userData} ]"); -// var textAsset = asset as TextAsset; -// if (textAsset == null) -// { -// Log.Warning($"Load text asset [ {assetName} ] failed."); -// return; -// } -// -// try -// { -// var assembly = Assembly.Load(textAsset.bytes); -// if (string.Compare(SettingsUtils.HybridCLRCustomGlobalSettings.LogicMainDllName, userData as string, StringComparison.Ordinal) == 0) -// { -// m_MainLogicAssembly = assembly; -// } -// m_HotfixAssemblys.Add(assembly); -// Log.Debug($"Assembly [ {assembly.GetName().Name} ] loaded"); -// } -// catch (Exception e) -// { -// m_FailureAssetCount++; -// Log.Fatal(e); -// throw; -// } -// finally -// { -// m_LoadAssemblyComplete = m_LoadAssemblyWait && 0 == m_LoadAssetCount; -// } -// } -// -// /// -// /// 加载代码资源失败回调。 -// /// -// /// 资源名称。 -// /// 加载状态。 -// /// 错误信息。 -// /// 自定义数据。 -// private void LoadAssetFailure(string assetName, LoadResourceStatus status, string errorMessage, object userData) -// { -// Log.Fatal($"LoadAssetFailure, assetName: [ {assetName} ], status: [ {status} ], errorMessage: [ {errorMessage} ], userData: [ {userData} ]"); -// m_LoadAssetCount--; -// m_FailureAssetCount++; -// } -// -// /// -// /// 为Aot Assembly加载原始metadata, 这个代码放Aot或者热更新都行。 -// /// 一旦加载后,如果AOT泛型函数对应native实现不存在,则自动替换为解释模式执行。 -// /// -// public void LoadMetadataForAOTAssembly() -// { -// // 可以加载任意aot assembly的对应的dll。但要求dll必须与unity build过程中生成的裁剪后的dll一致,而不能直接使用原始dll。 -// // 我们在BuildProcessor_xxx里添加了处理代码,这些裁剪后的dll在打包时自动被复制到 {项目目录}/HybridCLRData/AssembliesPostIl2CppStrip/{Target} 目录。 -// -// // 注意,补充元数据是给AOT dll补充元数据,而不是给热更新dll补充元数据。 -// // 热更新dll不缺元数据,不需要补充,如果调用LoadMetadataForAOTAssembly会返回错误 -// if (SettingsUtils.HybridCLRCustomGlobalSettings.AOTMetaAssemblies.Count == 0) -// { -// m_LoadMetadataAssemblyComplete = true; -// return; -// } -// m_LoadMetadataAssetCallbacks ??= new LoadAssetCallbacks(LoadMetadataAssetSuccess, LoadMetadataAssetFailure); -// foreach (var aotDllName in SettingsUtils.HybridCLRCustomGlobalSettings.AOTMetaAssemblies) -// { -// var assetPath = Utility.Path.GetRegularPath( -// Path.Combine( -// "Assets", -// SettingsUtils.HybridCLRCustomGlobalSettings.AssemblyTextAssetPath, -// $"{aotDllName}{SettingsUtils.HybridCLRCustomGlobalSettings.AssemblyTextAssetExtension}")); -// Log.Debug($"LoadMetadataAsset: [ {assetPath} ]"); -// m_LoadMetadataAssetCount++; -// GameModule.Resource.LoadAssetAsync(assetPath,typeof(UnityEngine.TextAsset), m_LoadMetadataAssetCallbacks, aotDllName); -// } -// m_LoadMetadataAssemblyWait = true; -// } -// -// /// -// /// 加载元数据资源成功回调。 -// /// -// /// 资源名称。 -// /// 资源实例。 -// /// 加载耗时。 -// /// 用户数据。 -// private unsafe void LoadMetadataAssetSuccess(string assetName, object asset, float duration, object userData) -// { -// m_LoadMetadataAssetCount--; -// Log.Debug($"LoadMetadataAssetSuccess, assetName: [ {assetName} ], duration: [ {duration} ], userData: [ {userData} ]"); -// var textAsset = asset as TextAsset; -// if (null == textAsset) -// { -// Log.Debug($"LoadMetadataAssetSuccess:Load text asset [ {assetName} ] failed."); -// return; -// } -// -// try -// { -// byte[] dllBytes = textAsset.bytes; -// fixed (byte* ptr = dllBytes) -// { -// #if HybridCLR_Enable -// // 加载assembly对应的dll,会自动为它hook。一旦Aot泛型函数的native函数不存在,用解释器版本代码 -// HomologousImageMode mode = HomologousImageMode.SuperSet; -// LoadImageErrorCode err = (LoadImageErrorCode)HybridCLR.RuntimeApi.LoadMetadataForAOTAssembly(dllBytes,mode); -// Log.Warning($"LoadMetadataForAOTAssembly:{userData as string}. mode:{mode} ret:{err}"); -// #endif -// } -// } -// catch (Exception e) -// { -// m_FailureMetadataAssetCount++; -// Log.Fatal(e.Message); -// throw; -// } -// finally -// { -// m_LoadMetadataAssemblyComplete = m_LoadMetadataAssemblyWait && 0 == m_LoadMetadataAssetCount; -// } -// } -// -// /// -// /// 加载元数据资源失败回调。 -// /// -// /// 资源名称。 -// /// 加载状态。 -// /// 错误信息。 -// /// 自定义数据。 -// private void LoadMetadataAssetFailure(string assetName, LoadResourceStatus status, string errorMessage, object userData) -// { -// Log.Warning($"LoadAssetFailure, assetName: [ {assetName} ], status: [ {status} ], errorMessage: [ {errorMessage} ], userData: [ {userData} ]"); -// m_LoadMetadataAssetCount--; -// m_FailureMetadataAssetCount++; -// } + private bool m_enableAddressable = true; + public override bool UseNativeDialog => true; + private int m_LoadAssetCount; + private int m_LoadMetadataAssetCount; + private int m_FailureAssetCount; + private int m_FailureMetadataAssetCount; + private bool m_LoadAssemblyComplete; + private bool m_LoadMetadataAssemblyComplete; + private bool m_LoadAssemblyWait; + private bool m_LoadMetadataAssemblyWait; + private Assembly m_MainLogicAssembly; + private List m_HotfixAssemblys; + private IFsm m_procedureOwner; + + protected override void OnEnter(IFsm procedureOwner) + { + base.OnEnter(procedureOwner); + Log.Debug("HyBridCLR ProcedureLoadAssembly OnEnter"); + m_procedureOwner = procedureOwner; + m_LoadAssemblyComplete = false; + m_HotfixAssemblys = new List(); + + if (!NeedLoadDll || GameModule.Resource.playMode == EPlayMode.EditorSimulateMode) + { + m_MainLogicAssembly = GetMainLogicAssembly(); + } + else + { + if (SettingsUtils.HybridCLRCustomGlobalSettings.Enable) + { + foreach (string hotUpdateDllName in SettingsUtils.HybridCLRCustomGlobalSettings.HotUpdateAssemblies) + { + var assetLocation = hotUpdateDllName; + if (!m_enableAddressable) + { + assetLocation = Utility.Path.GetRegularPath( + Path.Combine( + "Assets", + SettingsUtils.HybridCLRCustomGlobalSettings.AssemblyTextAssetPath, + $"{hotUpdateDllName}{SettingsUtils.HybridCLRCustomGlobalSettings.AssemblyTextAssetExtension}")); + } + + Log.Debug($"LoadAsset: [ {assetLocation} ]"); + m_LoadAssetCount++; + GameModule.Resource.LoadAssetAsync(assetLocation,LoadAssetSuccess); + } + + m_LoadAssemblyWait = true; + } + else + { + m_MainLogicAssembly = GetMainLogicAssembly(); + } + } + + if (SettingsUtils.HybridCLRCustomGlobalSettings.Enable) + { +#if UNITY_EDITOR + m_LoadMetadataAssemblyComplete = false; + LoadMetadataForAOTAssembly(); +#else + m_LoadMetadataAssemblyComplete = true; +#endif + } + else + { + m_LoadMetadataAssemblyComplete = true; + } + + if (m_LoadAssetCount == 0) + { + m_LoadAssemblyComplete = true; + } + } + + protected override void OnUpdate(IFsm procedureOwner, float elapseSeconds, float realElapseSeconds) + { + base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds); + if (!m_LoadAssemblyComplete) + { + return; + } + if (!m_LoadMetadataAssemblyComplete) + { + return; + } + AllAssemblyLoadComplete(); + } + + private void AllAssemblyLoadComplete() + { + if (GameModule.Resource.playMode == EPlayMode.EditorSimulateMode) + { + ChangeState(m_procedureOwner); + return; + } + if (m_MainLogicAssembly == null) + { + Log.Fatal($"Main logic assembly missing."); + return; + } + var appType = m_MainLogicAssembly.GetType("GameApp"); + if (appType == null) + { + Log.Fatal($"Main logic type 'GameMain' missing."); + return; + } + var entryMethod = appType.GetMethod("Entrance"); + if (entryMethod == null) + { + Log.Fatal($"Main logic entry method 'Entrance' missing."); + return; + } + object[] objects = new object[] { new object[] { m_HotfixAssemblys } }; + entryMethod.Invoke(appType, objects); + ChangeState(m_procedureOwner); + } + + private Assembly GetMainLogicAssembly() + { + Assembly mainLogicAssembly = null; + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + if (string.Compare(SettingsUtils.HybridCLRCustomGlobalSettings.LogicMainDllName, $"{assembly.GetName().Name}.dll", + StringComparison.Ordinal) == 0) + { + mainLogicAssembly = assembly; + } + + foreach (var hotUpdateDllName in SettingsUtils.HybridCLRCustomGlobalSettings.HotUpdateAssemblies) + { + if (hotUpdateDllName == $"{assembly.GetName().Name}.dll") + { + m_HotfixAssemblys.Add(assembly); + } + } + + if (mainLogicAssembly != null && m_HotfixAssemblys.Count == SettingsUtils.HybridCLRCustomGlobalSettings.HotUpdateAssemblies.Count) + { + break; + } + } + + return mainLogicAssembly; + } + + /// + /// 加载代码资源成功回调。 + /// + /// 资源操作句柄。 + private void LoadAssetSuccess(AssetOperationHandle assetOperationHandle) + { + m_LoadAssetCount--; + var assetName = assetOperationHandle.AssetObject.name; + Log.Debug($"LoadAssetSuccess, assetName: [ {assetName} ]"); + + var textAsset = assetOperationHandle.AssetObject as TextAsset; + if (textAsset == null) + { + Log.Warning($"Load text asset [ {assetName} ] failed."); + return; + } + + try + { + var assembly = Assembly.Load(textAsset.bytes); + if (string.Compare(SettingsUtils.HybridCLRCustomGlobalSettings.LogicMainDllName, assetName, StringComparison.Ordinal) == 0) + { + m_MainLogicAssembly = assembly; + } + m_HotfixAssemblys.Add(assembly); + Log.Debug($"Assembly [ {assembly.GetName().Name} ] loaded"); + } + catch (Exception e) + { + m_FailureAssetCount++; + Log.Fatal(e); + throw; + } + finally + { + m_LoadAssemblyComplete = m_LoadAssemblyWait && 0 == m_LoadAssetCount; + } + } + + /// + /// 为Aot Assembly加载原始metadata, 这个代码放Aot或者热更新都行。 + /// 一旦加载后,如果AOT泛型函数对应native实现不存在,则自动替换为解释模式执行。 + /// + public void LoadMetadataForAOTAssembly() + { + // 可以加载任意aot assembly的对应的dll。但要求dll必须与unity build过程中生成的裁剪后的dll一致,而不能直接使用原始dll。 + // 我们在BuildProcessor_xxx里添加了处理代码,这些裁剪后的dll在打包时自动被复制到 {项目目录}/HybridCLRData/AssembliesPostIl2CppStrip/{Target} 目录。 + + // 注意,补充元数据是给AOT dll补充元数据,而不是给热更新dll补充元数据。 + // 热更新dll不缺元数据,不需要补充,如果调用LoadMetadataForAOTAssembly会返回错误 + if (SettingsUtils.HybridCLRCustomGlobalSettings.AOTMetaAssemblies.Count == 0) + { + m_LoadMetadataAssemblyComplete = true; + return; + } + foreach (string aotDllName in SettingsUtils.HybridCLRCustomGlobalSettings.AOTMetaAssemblies) + { + var assetLocation = aotDllName; + if (!m_enableAddressable) + { + assetLocation = Utility.Path.GetRegularPath( + Path.Combine( + "Assets", + SettingsUtils.HybridCLRCustomGlobalSettings.AssemblyTextAssetPath, + $"{aotDllName}{SettingsUtils.HybridCLRCustomGlobalSettings.AssemblyTextAssetExtension}")); + } + + + Log.Debug($"LoadMetadataAsset: [ {assetLocation} ]"); + m_LoadMetadataAssetCount++; + GameModule.Resource.LoadAssetAsync(assetLocation,LoadMetadataAssetSuccess); + } + m_LoadMetadataAssemblyWait = true; + } + + /// + /// 加载元数据资源成功回调。 + /// + /// 资源操作句柄。 + private unsafe void LoadMetadataAssetSuccess(AssetOperationHandle assetOperationHandle) + { + m_LoadMetadataAssetCount--; + string assetName = assetOperationHandle.AssetObject.name; + Log.Debug($"LoadMetadataAssetSuccess, assetName: [ {assetName} ]"); + var textAsset = assetOperationHandle.AssetObject as TextAsset; + if (null == textAsset) + { + Log.Debug($"LoadMetadataAssetSuccess:Load text asset [ {assetName} ] failed."); + return; + } + + try + { + byte[] dllBytes = textAsset.bytes; + fixed (byte* ptr = dllBytes) + { + // 加载assembly对应的dll,会自动为它hook。一旦Aot泛型函数的native函数不存在,用解释器版本代码 + HomologousImageMode mode = HomologousImageMode.SuperSet; + LoadImageErrorCode err = (LoadImageErrorCode)HybridCLR.RuntimeApi.LoadMetadataForAOTAssembly(dllBytes,mode); + Log.Warning($"LoadMetadataForAOTAssembly:{assetName}. mode:{mode} ret:{err}"); + } + } + catch (Exception e) + { + m_FailureMetadataAssetCount++; + Log.Fatal(e.Message); + throw; + } + finally + { + m_LoadMetadataAssemblyComplete = m_LoadMetadataAssemblyWait && 0 == m_LoadMetadataAssetCount; + } + } } } \ No newline at end of file diff --git a/Assets/TEngine/Editor/HybridCLR/BuildAssetsCommand.cs b/Assets/TEngine/Editor/HybridCLR/BuildAssetsCommand.cs index dab24ea1..05f5f1f0 100644 --- a/Assets/TEngine/Editor/HybridCLR/BuildAssetsCommand.cs +++ b/Assets/TEngine/Editor/HybridCLR/BuildAssetsCommand.cs @@ -1,4 +1,3 @@ -/* using System.Collections; using System.Collections.Generic; using HybridCLR.Editor; @@ -58,7 +57,4 @@ public static class BuildAssetsCommand Debug.Log($"[CopyHotUpdateAssembliesToStreamingAssets] copy hotfix dll {dllPath} -> {dllBytesPath}"); } } -} -*/ - - +} \ No newline at end of file diff --git a/Assets/TEngine/Editor/ProtoGenTools.meta b/Assets/TEngine/Editor/ProtoGenTools.meta new file mode 100644 index 00000000..48b7c5c8 --- /dev/null +++ b/Assets/TEngine/Editor/ProtoGenTools.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ad601c9f244a8ad4ea31b17228958eeb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Editor/ProtoGenTools/ProtoGenTools.cs b/Assets/TEngine/Editor/ProtoGenTools/ProtoGenTools.cs new file mode 100644 index 00000000..f9a7c809 --- /dev/null +++ b/Assets/TEngine/Editor/ProtoGenTools/ProtoGenTools.cs @@ -0,0 +1,291 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace TEngine.Editor +{ + public static class ProtoGenTools + { +#if UNITY_EDITOR + [MenuItem("TEngine/生成Proto|Gen Proto", false, 10)] +#endif + public static void Export() + { + InnerProto2CS.Proto2CS(); + Debug.Log("proto2cs succeed!"); + } + } + + public static class InnerProto2CS + { + private static string ProtoPath = UnityEngine.Application.dataPath + "/..\\Luban\\Proto\\pb_schemas\\"; + + private static string OutPutPath = + UnityEngine.Application.dataPath + "/..\\Luban\\Proto\\Gen\\"; + + private static readonly char[] splitChars = { ' ', '\t' }; + + public static void Proto2CS() + { + Proto2CS("GameProto", "ProtoBase.proto", OutPutPath,10001,false); + } + + public static void Proto2CS(string nameSpace, string protoName, string outputPath, int startOpcode,bool useMemoryPool = false) + { + if (!Directory.Exists(outputPath)) + { + Directory.CreateDirectory(outputPath); + } + + string proto = Path.Combine(ProtoPath, protoName); + string csPath = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(proto) + ".cs"); + + string s = File.ReadAllText(proto); + + StringBuilder sb = new StringBuilder(); + sb.Append("//------------------------------------------------------------------------------\n"); + sb.Append("// \n"); + sb.Append("// This code was generated by a tool.\n"); + sb.Append("// Changes to this file may cause incorrect behavior and will be lost if\n"); + sb.Append("// the code is regenerated.\n"); + sb.Append("// \n"); + sb.Append("//------------------------------------------------------------------------------\n"); + sb.Append("\n"); + sb.Append("using System;\n"); + sb.Append("using ProtoBuf;\n"); + sb.Append("using TEngine;\n"); + sb.Append("using System.Collections.Generic;\n"); + sb.Append("\n"); + sb.Append($"namespace {nameSpace}\n"); + sb.Append("{\n"); + + bool isMsgStart = false; + bool isEnumStart = false; + foreach (string line in s.Split('\n')) + { + string newline = line.Trim(); + + if (newline == "") + { + continue; + } + + if (newline.StartsWith("//ResponseType")) + { + string responseType = line.Split(' ')[1].TrimEnd('\r', '\n'); + sb.AppendLine($"\t[ResponseType(nameof({responseType}))]"); + continue; + } + + if (newline.StartsWith("//")) + { + sb.Append($"\t{newline}\n"); + continue; + } + + if (newline.StartsWith("message")) + { + string parentClass = ""; + isMsgStart = true; + string msgName = newline.Split(splitChars, StringSplitOptions.RemoveEmptyEntries)[1]; + string[] ss = newline.Split(new[] { "//" }, StringSplitOptions.RemoveEmptyEntries); + + if (ss.Length == 2) + { + parentClass = ss[1].Trim(); + } + + sb.Append($"\t[Serializable,global::ProtoBuf.ProtoContract(Name = @\"{msgName}\")]\n"); + if (useMemoryPool) + { + sb.Append($"\tpublic partial class {msgName}: IMemory"); + } + else + { + sb.Append($"\tpublic partial class {msgName}"); + } + if (parentClass != "") + { + sb.Append($", {parentClass}\n"); + } + else + { + sb.Append("\n"); + } + + continue; + } + + if (isMsgStart) + { + if (newline == "{") + { + sb.Append("\t{\n"); + continue; + } + + if (newline == "}") + { + isMsgStart = false; + sb.Append("\t}\n\n"); + continue; + } + + if (newline.Trim().StartsWith("//")) + { + sb.AppendLine(newline); + continue; + } + + if (newline.Trim() != "" && newline != "}") + { + if (newline.StartsWith("repeated")) + { + Repeated(sb, nameSpace, newline); + } + else + { + Members(sb, newline, true); + } + } + } + + + if (newline.StartsWith("enum")) + { + isEnumStart = true; + string enumName = newline.Split(splitChars, StringSplitOptions.RemoveEmptyEntries)[1]; + + sb.Append($"\t[global::ProtoBuf.ProtoContract()]\n"); + sb.Append($"\tpublic enum {enumName}"); + sb.Append("\n"); + continue; + } + + if (isEnumStart) + { + if (newline == "{") + { + sb.Append("\t{\n"); + continue; + } + + if (newline == "}") + { + isEnumStart = false; + sb.Append("\t}\n\n"); + continue; + } + + if (newline.Trim().StartsWith("//")) + { + sb.AppendLine(newline); + continue; + } + + int index = newline.IndexOf(";"); + newline = newline.Remove(index); + sb.Append($"\t\t{newline},\n\n"); + } + } + + sb.Append("}\n"); + using (FileStream txt = new FileStream(csPath, FileMode.Create, FileAccess.ReadWrite)) + { + using (StreamWriter sw = new StreamWriter(txt)) + { + Debug.Log(sb.ToString()); + sw.Write(sb.ToString()); + } + } + } + + private static void Repeated(StringBuilder sb, string ns, string newline) + { + try + { + int index = newline.IndexOf(";"); + newline = newline.Remove(index); + string[] ss = newline.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); + string type = ss[1]; + type = ConvertType(type); + string name = ss[2]; + int n = int.Parse(ss[4]); + + sb.Append($"\t\t[global::ProtoBuf.ProtoMember({n})]\n"); + sb.Append($"\t\tpublic List<{type}> {name} = new List<{type}>();\n\n"); + } + catch (Exception e) + { + Console.WriteLine($"{newline}\n {e}"); + } + } + + private static string ConvertType(string type) + { + string typeCs = ""; + switch (type) + { + case "int16": + typeCs = "short"; + break; + case "int32": + typeCs = "int"; + break; + case "bytes": + typeCs = "byte[]"; + break; + case "uint32": + typeCs = "uint"; + break; + case "long": + typeCs = "long"; + break; + case "int64": + typeCs = "long"; + break; + case "uint64": + typeCs = "ulong"; + break; + case "uint16": + typeCs = "ushort"; + break; + default: + typeCs = type; + break; + } + + return typeCs; + } + + private static void Members(StringBuilder sb, string newline, bool isRequired) + { + try + { + int index = newline.IndexOf(";"); + newline = newline.Remove(index); + string[] ss = newline.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); + string type = ss[0]; + string name = ss[1]; + int n = int.Parse(ss[3]); + string typeCs = ConvertType(type); + + sb.Append($"\t\t[global::ProtoBuf.ProtoMember({n})]\n"); + if (string.Equals(type,"string")) + { + sb.Append($"\t\t[global::System.ComponentModel.DefaultValue(\"\")]\n"); + } + sb.Append($"\t\tpublic {typeCs} {name} {{ get; set; }}\n\n"); + } + catch (Exception e) + { + Console.WriteLine($"{newline}\n {e}"); + } + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Editor/ProtoGenTools/ProtoGenTools.cs.meta b/Assets/TEngine/Editor/ProtoGenTools/ProtoGenTools.cs.meta new file mode 100644 index 00000000..6f646e6d --- /dev/null +++ b/Assets/TEngine/Editor/ProtoGenTools/ProtoGenTools.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e505998676d79fb47bc6b4ed97148fa1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Editor/TEngine.Editor.asmdef b/Assets/TEngine/Editor/TEngine.Editor.asmdef index a1b7c605..75efceef 100644 --- a/Assets/TEngine/Editor/TEngine.Editor.asmdef +++ b/Assets/TEngine/Editor/TEngine.Editor.asmdef @@ -3,7 +3,8 @@ "rootNamespace": "", "references": [ "TEngine.Runtime", - "YooAsset.Editor" + "YooAsset.Editor", + "HybridCLR.Editor" ], "includePlatforms": [ "Editor" diff --git a/Assets/TEngine/ResRaw/Resources/TEngineGlobalSettings.asset b/Assets/TEngine/ResRaw/Resources/TEngineGlobalSettings.asset index 2e1fec72..4e956b35 100644 --- a/Assets/TEngine/ResRaw/Resources/TEngineGlobalSettings.asset +++ b/Assets/TEngine/ResRaw/Resources/TEngineGlobalSettings.asset @@ -27,6 +27,7 @@ MonoBehaviour: m_FormalResourceSourceUrl: http://127.0.0.1:8088 m_AtlasFolder: Assets/AssetRaw/UIRaw m_ResourceVersionFileName: ResourceVersion.txt + HostServerURL: http://127.0.0.1:8081 CheckVersionUrl: http://127.0.0.1/Resources/{0}Version.txt WindowsAppUrl: http://127.0.0.1 MacOSAppUrl: http://127.0.0.1 @@ -39,9 +40,16 @@ MonoBehaviour: m_BybridCLRCustomGlobalSettings: m_Enable: 1 m_Gitee: 1 - HotUpdateAssemblies: [] - AOTMetaAssemblies: [] - LogicMainDllName: xxx.dll + HotUpdateAssemblies: + - GameLogic.dll + - GameBase.dll + - GameProto.dll + - BattleCore.Runtime.dll + AOTMetaAssemblies: + - mscorlib.dll + - System.dll + - System.Core.dll + LogicMainDllName: GameLogic.dll AssemblyTextAssetExtension: .bytes - AssemblyTextAssetPath: Assets/AssetRaw/DLL + AssemblyTextAssetPath: AssetRaw/DLL HybridCLRGlobalSettings: Settings/HybridCLRGlobalSettings diff --git a/Assets/TEngine/Runtime/GameSettings/HybridCLR/HybridCLRCustomGlobalSettings.cs b/Assets/TEngine/Runtime/GameSettings/HybridCLR/HybridCLRCustomGlobalSettings.cs index fb59b286..60054f44 100644 --- a/Assets/TEngine/Runtime/GameSettings/HybridCLR/HybridCLRCustomGlobalSettings.cs +++ b/Assets/TEngine/Runtime/GameSettings/HybridCLR/HybridCLRCustomGlobalSettings.cs @@ -28,15 +28,16 @@ public class HybridCLRCustomGlobalSettings set { m_Gitee = value; } } - [Header("Auto sync with [HybridCLRGlobalSettings]")] [Tooltip("You should modify the file form file path [Assets/CustomHybridCLR/Settings/HybridCLRGlobalSettings.asset]")] - public List HotUpdateAssemblies; + [Header("Auto sync with [HybridCLRGlobalSettings]")] + [Tooltip("You should modify the file form file path [Assets/CustomHybridCLR/Settings/HybridCLRGlobalSettings.asset]")] + public List HotUpdateAssemblies = new List() { "GameLogic.dll","GameBase.dll","GameProto.dll","BattleCore.Runtime.dll"}; - [Header("Need manual setting!")] public List AOTMetaAssemblies; + [Header("Need manual setting!")] public List AOTMetaAssemblies= new List() {"mscorlib.dll","System.dll","System.Core.dll" }; /// /// Dll of main business logic assembly /// - public string LogicMainDllName = "xxx.dll"; + public string LogicMainDllName = "GameLogic.dll"; /// /// 程序集文本资产打包Asset后缀名 @@ -46,7 +47,7 @@ public class HybridCLRCustomGlobalSettings /// /// 程序集文本资产资源目录 /// - public string AssemblyTextAssetPath = "Assets/AssetRaw/DLL"; + public string AssemblyTextAssetPath = "AssetRaw/DLL"; /// /// Resources HybridCLRGlobalSettings Dir diff --git a/Assets/TEngine/Runtime/Plugins/Android/BuglyPlugins/BuglyAgent.cs b/Assets/TEngine/Runtime/Plugins/Android/BuglyPlugins/BuglyAgent.cs index cb3e89db..0da4a0b1 100644 --- a/Assets/TEngine/Runtime/Plugins/Android/BuglyPlugins/BuglyAgent.cs +++ b/Assets/TEngine/Runtime/Plugins/Android/BuglyPlugins/BuglyAgent.cs @@ -682,7 +682,9 @@ public sealed class BuglyAgent #if UNITY_ANDROID // The crash reporter package name, default is 'com.tencent.bugly' +#pragma warning disable CS0414 private static string _crashReporterPackage = "com.tencent.bugly"; +#pragma warning restore CS0414 #endif #if UNITY_IPHONE || UNITY_IOS private static int _crashReproterCustomizedLogLevel = 2; // Off=0,Error=1,Warn=2,Info=3,Debug=4 diff --git a/Luban/Proto/Gen/ProtoBase.cs b/Luban/Proto/Gen/ProtoBase.cs new file mode 100644 index 00000000..3d388751 --- /dev/null +++ b/Luban/Proto/Gen/ProtoBase.cs @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using ProtoBuf; +using TEngine; +using System.Collections.Generic; + +namespace GameProto +{ + // 这个文件只放协议,和协议头 + // 消息协议 + [Serializable,global::ProtoBuf.ProtoContract(Name = @"CSPkg")] + public partial class CSPkg + { + [global::ProtoBuf.ProtoMember(1)] + public CSPkgHead Head { get; set; } + + [global::ProtoBuf.ProtoMember(2)] + public CSPkgBody Body { get; set; } + + } + + // 消息协议头 + [Serializable,global::ProtoBuf.ProtoContract(Name = @"CSPkgHead")] + public partial class CSPkgHead + { + [global::ProtoBuf.ProtoMember(1)] + public uint MsgId { get; set; } + + [global::ProtoBuf.ProtoMember(2)] + public uint MsgLength { get; set; } + + [global::ProtoBuf.ProtoMember(3)] + public uint MsgVersion { get; set; } + + [global::ProtoBuf.ProtoMember(4)] + public uint Echo { get; set; } + + [global::ProtoBuf.ProtoMember(5)] + public uint SvrTime { get; set; } + + } + + // 消息协议体 + [Serializable,global::ProtoBuf.ProtoContract(Name = @"CSPkgBody")] + public partial class CSPkgBody + { + } + + // 协议ID + [global::ProtoBuf.ProtoContract()] + public enum CSMsgID + { + CS_START = 0, + + CS_HeartBeat = 10001, + + CS_END = 10000, + + } + +} diff --git a/Luban/Proto/Log/ProtobufResolver.log b/Luban/Proto/Log/ProtobufResolver.log deleted file mode 100644 index 00a4418e..00000000 --- a/Luban/Proto/Log/ProtobufResolver.log +++ /dev/null @@ -1,5 +0,0 @@ -Info_2023/1/13 11:33:15: By AlanDu Time:2023/1/13 11:33:15 -Info_2023/1/13 11:33:15: Version 0.1 -Info_2023/1/13 11:33:15: Function Protobuf Resolver -Info_2023/1/13 11:33:15: protoDirPath:G:\WorkSpace\DinGameFrame\Luban\Proto\pb_message -Info_2023/1/13 11:33:15: ProtoOutputPath:../../Assets\GameMain\HotFix\Scripts\Proto\Definition\Constant diff --git a/Luban/Proto/ProtobufResolver.exe b/Luban/Proto/ProtobufResolver.exe deleted file mode 100644 index 0d97384d..00000000 Binary files a/Luban/Proto/ProtobufResolver.exe and /dev/null differ diff --git a/Luban/Proto/gen_pb_code.bat b/Luban/Proto/gen_pb_code.bat index 2c65d8ba..faa0cd9b 100644 --- a/Luban/Proto/gen_pb_code.bat +++ b/Luban/Proto/gen_pb_code.bat @@ -1,18 +1,21 @@ -@echo off & setlocal enabledelayedexpansion -cd %~dp0 -echo =================start gen proto code================= -set pb_path=pb_message -set out_path=..\..\Assets\GameMain\HotFix\Scripts\Proto -del /f /s /q %out_path%\*.* -for /f "delims=" %%i in ('dir /b %pb_path%') do ( -echo ------------%%i start gen -protoc -I=pb_message --csharp_out=../../Assets/GameMain/HotFix/Scripts/Proto pb_message\%%i -echo ------------%%i gen success -) -echo =================end gen proto code================= -set cur_path=%~dp0 -set outEventPath=../../Assets\GameMain\HotFix\Scripts\Proto\Definition\Constant -call ProtobufResolver.exe %cur_path%pb_message %outEventPath% -echo =================end gen proto event================= -pause +@REM @echo off & setlocal enabledelayedexpansion +@REM cd %~dp0 +@REM echo =================start gen proto code================= +@REM set pb_path=pb_message +@REM set out_path=..\..\Assets\GameMain\HotFix\Scripts\Proto +@REM del /f /s /q %out_path%\*.* +@REM for /f "delims=" %%i in ('dir /b %pb_path%') do ( +@REM echo ------------%%i start gen +@REM protoc -I=pb_message --csharp_out=../../Assets/GameMain/HotFix/Scripts/Proto pb_message\%%i +@REM echo ------------%%i gen success +@REM ) +@REM echo =================end gen proto code================= +@REM set cur_path=%~dp0 +@REM set outEventPath=../../Assets\GameMain\HotFix\Scripts\Proto\Definition\Constant +@REM call ProtobufResolver.exe %cur_path%pb_message %outEventPath% +@REM echo =================end gen proto event================= +@REM pause +protoc -I=pb_schemas --csharp_out=Gen pb_schemas\ProtoBase.proto + +pause \ No newline at end of file diff --git a/Luban/Proto/pb_message/DPLogin.proto b/Luban/Proto/pb_message/DPLogin.proto deleted file mode 100644 index c6186b02..00000000 --- a/Luban/Proto/pb_message/DPLogin.proto +++ /dev/null @@ -1,191 +0,0 @@ -syntax = "proto3"; - -import "GameBase.proto"; - -option java_package ="com.game.juhe.server.protobuf.proto"; - -package DPLogin; - -// 客户端向服务端发送登录协议,发送账号和密码 -// PTC_C2G_LOGININFO -message DPUserLoginInfoReq -{ - string szAccount = 1; // 账号 - string szPassword = 2; // 密码 - string szMacAdress = 3; // mac地址 - int32 nClientVersion = 4; // 客户端版本号 - string szUserName = 5; // 用户名字 - string extensionJson = 6; // 透传字段 -} - -// 登陆角色服返回验证结果 -enum AccountLoginVerifyResult -{ - ACC_VERIFY_RET_SUCCESS = 0; // 允许进入角色服务器 - ACC_VERIFY_RET_FAILED = 1; // 未知错误 - ACC_VERIFY_RET_ACCOUNT_OR_PASSWORD_ERROR = 2; // 账号或者密码错误 - ACC_VERIFY_RET_MAINTENANCE = 3; // 服务器维护中 - ACC_VERIFY_RET_IS_FULL = 4; // 服务器人数已满 - ACC_VERIFY_RET_TIMEOUT = 5; // 验证超时 - ACC_VERIFY_RET_PAYSYSHTTPERROR = 6; // http验证系统异常请联系客服 - ACC_VERIFY_RET_FULLACCOUNT_INLIST = 7; // 因为人数过多在排队队列 - ACC_VERIFY_RET_FULLACCOUNT_OUTLIST = 8; // 因为人数过多连排队队列都排不上 - ACC_VERIFY_RET_FULLVERIFYACOUNT = 9; // 验证账号人数过多请耐心等待 - ACC_VERIFY_RET_CLIENTVERSIONERROR = 10; // 客户端版本不对 -} - -// 玩家登陆,身份验证的结果 -// PTC_G2C_ACC_VERIFY_RESULT -message DPAccountVerifyResultResp -{ - string szAccount = 1; // 账号 - AccountLoginVerifyResult nResult = 2; // 结果 - string szLoginGuid = 3; // 登陆guid - string szServerIP = 4; // 服务器ip - int32 nPort = 5; // 端口 - int32 nServerID = 6; // 服务器ID - int32 nWaitNum = 7; // 排队人数 - int32 nMaxWaitNum = 8; // 最大排队人数 - string szGatewayName = 9; // 服务器名 -} - - -// 客户端发起登陆协议 -// PTC_C2S_LOGICLOGIN -message DPGSLogicLoginReq -{ - string szLoginGuid = 1; // 登陆guid - string szAccount = 2; // 账号 - int32 nServerId = 3; // serverID - string szMacAdress = 4; // mac地址 -} - -// 登陆逻辑服失败 -enum BEGSLogicLoginRet -{ - GS_LOGIN_RET_FAILED = 0; // 未知错误 - GS_LOGIN_RET_SUCCESS = 1; // 成功 - GS_LOGIN_RET_FAILED_NEED_AUTH = 2; // 需要重新账号密码验证 - GS_LOGIN_RET_FAILED_DIRECTLOGIN = 3; // 断线重连失败 - GS_LOGIN_RET_FAILED_ACCOUNTLOGINPROXY = 4; // 登录代理服务器失败 - GS_LOGIN_RET_FAILED_GSDIRECTLOGIN = 5; // 登录gs失败 - GS_LOGIN_RET_FAILED_ACCOUNTLOGINBEGIN = 6; // account登录失败 - GS_LOGIN_RET_FAILED_ASKGCROLEINFO = 7; // 登陆失败 - GS_LOGIN_RET_FAILED_ROLELIST = 8; // 获取角色列表 - GS_LOGIN_RET_FAILED_ASKGSPERMISSION = 9; // 询问gs登录失败 - GS_LOGIN_RET_FAILED_ASKGSPERMISSIONRET = 10; // 询问gs登录失败 - GS_LOGIN_RET_FAILED_SELECTROLEFAILED = 11; // 选择角色登录失败 -} - -// 客户端登陆逻辑服失败返回错误码 -// PTC_S2C_LOGICLOIN_RET -message DPGSLogicLoginRetResp -{ - string szAccount = 1; // 账号 - BEGSLogicLoginRet eRet = 2; // 返回登陆结果 -} - -// 角色列表中的角色信息 -message DPGSRoleItemInfo -{ - GameBase.DPRoleBaseInfo stBaseInfo = 1; - int64 nCreateTime = 2; // 创建角色时间 - int32 nPlatformId = 3; // 平台类型 - int32 nCreateServerId = 4; // 创建角色的服务器ID -} - -// 网关服务端把角色列表发回到客户端,里面有账号,角色数和角色列表 -// PTC_G2C_ROLELIST_RESPONE -message DPRoleListResponeResp -{ - string szAccount = 1; // 账号 - int32 nRoleCount = 2; // 角色数 - repeated DPGSRoleItemInfo arrayRoleList = 3; // 角色列表 -} - -// 玩家确定选取角色登录游戏 -// PTC_C2G_GAMELOGIN_REQUEST -message DPGameLoginRequestReq -{ - string szAccount = 1; // 账号 - uint64 nRoleGuid = 2; // 玩家唯一标识id guid - string szRoleName = 3; // 玩家名 -} - -// 创建角色发送创建的角色名到网关服务器 -// PTC_C2G_CREATE_ROLE -message DPCreateRoleReq -{ - string szAccount = 1; // 账号 - string szRoleName = 2; // 角色名 - int32 nProfessionId = 3; // 角色ID - int32 nPortrait = 4; // 头像 - int32 nClothId = 5; // 选择的时装 - int32 nPlatformId = 6; // 平台ID -} - -// 创建角色失败原因 -enum RoleCreateFailedResult -{ - ROLECREATE_FAIL_REASON_NONE = 0; // 角色创建成功 - ROLECREATE_FAIL_REASON_UNKNOWN = 1; // 未知错误 - ROLECREATE_FAIL_REASON_NAME_FILTER = 2; // 角色名非法 - ROLECREATE_FAIL_REASON_NAME_EXIST = 3; // 角色名已存在 - ROLECREATE_FAIL_REASON_OVER_MAX_ROLE_PER_GATEWAY = 4; // 创建角色超过本服上限 - ROLECREATE_FAIL_REASON_OVER_MAX_ROLE_PER_ZONE = 5; // 创建角色超过整个大区上限 - ROLECREATE_FAIL_MAX_NAME_LEN = 6; // 角色名长度超过上限 - ROLECREATE_FAIL_MIN_NAME_LEN = 7; // 角色名长度低于下限 -} - -// 创建角色返回结果给客户端 -// PTC_G2C_CREATEROLE_RESULT -message DPCreateRoleResultResp -{ - string szAccount = 1; // 账号 - string szRoleName = 2; // 角色名 - uint64 nRoleGuid = 3; // 玩家唯一标识id guid - bool bSuccessed = 4; // 是否成功 - RoleCreateFailedResult nFailedReason = 5; // 如果失败,返回原因 -} - -// 踢掉玩家的原因 -enum KickOutClientResult -{ - KICKOUT_REASON_NULL = 0; //默认踢掉角色 - KICKOUT_REASON_SAMEACCOUNTLOGIN = 1; //账号重复登录 - KICKOUT_REASON_KICKHANGUP = 2; //踢掉挂机的玩家 - KICKOUT_REASON_LOGINFAILED = 3; //客户端登录失败 - KICKOUT_REASON_CLIENTDISCONNECT = 4; //客户端断开连接 - KICKOUT_REASON_CLIENTREQUESTEXIT = 5; //客户端请求退出 - KICKOUT_REASON_SERVERKICK = 6; //服务器因错误挫人 - KICKOUT_REASON_UNLEGALCLIENT = 7; //非法的客户端 - KICKOUT_REASON_BACKENDKICK = 8; //后台踢人 - KICKOUT_REASON_ONLINEGMKICK = 9; //GM在线踢人 - KICKOUT_REASON_GSCRASH = 10; //GS宕机踢人 - KICKOUT_REASON_GCCRASH = 11; //GC宕机踢人 - KICKOUT_REASON_SCENECHANGE = 12; //场景切换失败 - KICKOUT_REASON_BANPLAYER = 13; //封号 - KICKOUT_REASON_SWITCHSERVER = 14; //切换gs的踢人 - KICKOUT_REASON_EXITROLE = 15; //切换角色 - KICKOUT_REASON_DIRECTLOGIN = 16; //断线重连失败 - KICKOUT_REASON_BISHOPKICKOUT = 17; //bishop踢人 -} - -// 踢掉客户端 -// PTC_G2C_KICKOUTCLIENT -message DPKickOutClientResp -{ - KickOutClientResult eKickOut = 1; // 踢掉原因 -} - -// 退出账号,到账号登录界面 -// PTC_C2S_EXITACCOUNT -message DPGSExitAccountReq -{ -} - -// 退出角色,到选择角色界面 -// PTC_C2S_EXITROLE -message DPGSExitRoleReq -{ -} diff --git a/Luban/Proto/pb_message/GameBase.proto b/Luban/Proto/pb_message/GameBase.proto deleted file mode 100644 index 0ea992c4..00000000 --- a/Luban/Proto/pb_message/GameBase.proto +++ /dev/null @@ -1,45 +0,0 @@ -syntax = "proto3"; - -option java_package ="com.game.juhe.server.protobuf.proto"; - -package GameBase; -// 游戏全局基础数据,和协议无关,就放结构 - -enum PacketType -{ - Undefined = 0; - ClientToServer = 1; - ServerToClient = 2; -} - -message PacketHeader -{ - PacketType packetType = 1; - int64 id = 2; - int64 packetLength = 3; - bool isValid = 4; -} - -// PTC_C2S_HeartBeat -message CSHeartBeat -{ - int64 dwTime = 1; -} - -// PTC_S2C_HeartBeat -message SCHeartBeat -{ - int64 dwTime = 1; -} - -// 玩家角色基础数据数据 -message DPRoleBaseInfo -{ - uint64 ullRoleGuid = 1; // guid - string szRoleName = 2; // 角色名 - int32 nLevel = 3; // 角色等级 - int32 nProfessionId = 4; // 角色ID - int32 nPortraitId = 5; // 头像 - int32 nFightPower = 6; // 战斗力 - int32 nClothId = 7; // 时装ID -} \ No newline at end of file diff --git a/Luban/Proto/pb_message/ProtoBase.proto b/Luban/Proto/pb_message/ProtoBase.proto deleted file mode 100644 index 57862d54..00000000 --- a/Luban/Proto/pb_message/ProtoBase.proto +++ /dev/null @@ -1,35 +0,0 @@ -syntax = "proto3"; - -option java_package ="com.game.juhe.server.protobuf.proto"; - -package ProtoBase; -// 这个文件只放协议,和协议头 - -// 协议头 -message BGProtocolHeader -{ - int32 uProtocolId = 1; // 协议号 - int32 uKeyLen = 2; // 验证码长度 - bytes szSessionKey = 3; //[MAX_SESSIONKEY_LEN=64] -} - -// 协议ID -enum ProtocolID -{ - PTC_START = 0; - - PTC_C2S_HeartBeat = 10001; // 客户端向网关服务器的协议id - PTC_S2C_HeartBeat = 10002; // 网关服务器向客户端的协议id - PTC_C2G_LOGININFO = 10003; - PTC_G2C_ACC_VERIFY_RESULT = 1004; - PTC_C2S_LOGICLOGIN = 10005; - PTC_S2C_LOGICLOIN_RET = 10006; - PTC_G2C_ROLELIST_RESPONE = 10007; - PTC_C2G_GAMELOGIN_REQUEST = 10008; - PTC_C2G_CREATE_ROLE = 1009; - PTC_G2C_CREATEROLE_RESULT = 10010; - PTC_G2C_KICKOUTCLIENT = 10011; - PTC_C2S_EXITACCOUNT = 10012; - PTC_C2S_EXITROLE = 10013; - PTC_END = 10000; -} diff --git a/Luban/Proto/pb_message/ExternalMessage.proto b/Luban/Proto/pb_schemas/ExternalMessage.proto similarity index 97% rename from Luban/Proto/pb_message/ExternalMessage.proto rename to Luban/Proto/pb_schemas/ExternalMessage.proto index adc90070..350bc930 100644 --- a/Luban/Proto/pb_message/ExternalMessage.proto +++ b/Luban/Proto/pb_schemas/ExternalMessage.proto @@ -1,5 +1,7 @@ syntax = "proto3"; -package pb.message; + +package GameProto; + // 对外服数据协议 message ExternalMessage { // 请求命令类型: 0 心跳,1 业务 diff --git a/Luban/Proto/pb_schemas/GameProto.proto b/Luban/Proto/pb_schemas/GameProto.proto new file mode 100644 index 00000000..6f476e76 --- /dev/null +++ b/Luban/Proto/pb_schemas/GameProto.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; + +package GameProto; +// 游戏全局基础数据,和协议无关,就放结构 + +// 导入定义 +import "ProtoBase"; + diff --git a/Luban/Proto/pb_schemas/ProtoBase.proto b/Luban/Proto/pb_schemas/ProtoBase.proto new file mode 100644 index 00000000..55a40694 --- /dev/null +++ b/Luban/Proto/pb_schemas/ProtoBase.proto @@ -0,0 +1,36 @@ +syntax = "proto3"; + +package GameProto; +// 这个文件只放协议,和协议头 + +// 消息协议 +message CSPkg +{ + CSPkgHead Head = 1; //消息协议头 + CSPkgBody Body = 2; //消息协议体 +} + +// 消息协议头 +message CSPkgHead +{ + uint32 MsgId = 1; //协议号 + uint32 MsgLength = 2; //协议长度 + uint32 MsgVersion = 3; //协议版本 + uint32 Echo = 4; //回带字段 + uint32 SvrTime = 5; //服务器时间 +} + +// 消息协议体 +message CSPkgBody +{ + +} + + +// 协议ID +enum CSMsgID +{ + CS_START = 0; + CS_HeartBeat = 10001; + CS_END = 10000; +} diff --git a/Packages/manifest.json b/Packages/manifest.json index 26999f53..5ad0ac32 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,5 +1,6 @@ { "dependencies": { + "com.focus-creative-games.hybridclr_unity": "https://gitee.com/focus-creative-games/hybridclr_unity.git", "com.unity.2d.animation": "5.2.0", "com.unity.2d.pixel-perfect": "4.0.1", "com.unity.2d.psdimporter": "4.3.0", @@ -47,5 +48,14 @@ "com.unity.modules.vr": "1.0.0", "com.unity.modules.wind": "1.0.0", "com.unity.modules.xr": "1.0.0" - } + }, + "scopedRegistries": [ + { + "name": "hybridclr_unity", + "url": "https://package.openupm.cn", + "scopes": [ + "com.focus-creative-games.hybridclr_unity" + ] + } + ] } diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 33e2922b..fefd6b6e 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,5 +1,12 @@ { "dependencies": { + "com.focus-creative-games.hybridclr_unity": { + "version": "https://gitee.com/focus-creative-games/hybridclr_unity.git", + "depth": 0, + "source": "git", + "dependencies": {}, + "hash": "bf6ae99dadfbc64e3a6f2dc7f63509a5b6b12621" + }, "com.unity.2d.animation": { "version": "5.2.0", "depth": 0, diff --git a/ProjectSettings/HybridCLRSettings.asset b/ProjectSettings/HybridCLRSettings.asset new file mode 100644 index 00000000..62f21bf1 --- /dev/null +++ b/ProjectSettings/HybridCLRSettings.asset @@ -0,0 +1,36 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &1 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e189374413a3f00468e49d51d8b27a09, type: 3} + m_Name: + m_EditorClassIdentifier: + enable: 1 + useGlobalIl2cpp: 0 + hybridclrRepoURL: https://gitee.com/focus-creative-games/hybridclr + il2cppPlusRepoURL: https://gitee.com/focus-creative-games/il2cpp_plus + hotUpdateAssemblyDefinitions: + - {fileID: 5897886265953266890, guid: aa06d4cc755c979489c256c1bcca1dfb, type: 3} + - {fileID: 5897886265953266890, guid: 08c3762f54316454ca6b6fbcb22b40e5, type: 3} + - {fileID: 5897886265953266890, guid: acd6baa97ba40d3478c29cd9c76ff9e3, type: 3} + - {fileID: 5897886265953266890, guid: a90b2d3377c5e4a4db95cc44fb82045e, type: 3} + - {fileID: 5897886265953266890, guid: 641632c4f8079b94f963b5284d859a12, type: 3} + hotUpdateAssemblies: + - Assembly-CSharp + preserveHotUpdateAssemblies: [] + hotUpdateDllCompileOutputRootDir: HybridCLRData/HotUpdateDlls + externalHotUpdateAssembliyDirs: [] + strippedAOTDllOutputRootDir: HybridCLRData/AssembliesPostIl2CppStrip + patchAOTAssemblies: [] + collectAssetReferenceTypes: 0 + outputLinkFile: HybridCLRData/Generated/link.xml + outputAOTGenericReferenceFile: HybridCLRData/Generated/AOTGenericReferences.cs + maxGenericReferenceIteration: 10 + maxMethodBridgeGenericIteration: 10 diff --git a/ProjectSettings/PackageManagerSettings.asset b/ProjectSettings/PackageManagerSettings.asset index 1691ae21..8af7a773 100644 --- a/ProjectSettings/PackageManagerSettings.asset +++ b/ProjectSettings/PackageManagerSettings.asset @@ -12,8 +12,8 @@ MonoBehaviour: m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0} m_Name: m_EditorClassIdentifier: - m_EnablePreviewPackages: 0 - m_EnablePackageDependencies: 0 + m_EnablePreviewPackages: 1 + m_EnablePackageDependencies: 1 m_AdvancedSettingsExpanded: 1 m_ScopedRegistriesSettingsExpanded: 1 oneTimeWarningShown: 1 @@ -24,20 +24,28 @@ MonoBehaviour: m_Scopes: [] m_IsDefault: 1 m_Capabilities: 7 + - m_Id: scoped:hybridclr_unity + m_Name: hybridclr_unity + m_Url: https://package.openupm.cn + m_Scopes: + - com.focus-creative-games.hybridclr_unity + m_IsDefault: 0 + m_Capabilities: 0 m_UserSelectedRegistryName: m_UserAddingNewScopedRegistry: 0 m_RegistryInfoDraft: m_ErrorMessage: m_Original: - m_Id: - m_Name: - m_Url: - m_Scopes: [] + m_Id: scoped:hybridclr_unity + m_Name: hybridclr_unity + m_Url: https://package.openupm.cn + m_Scopes: + - com.focus-creative-games.hybridclr_unity m_IsDefault: 0 m_Capabilities: 0 m_Modified: 0 - m_Name: - m_Url: + m_Name: hybridclr_unity + m_Url: https://package.openupm.cn m_Scopes: - - + - com.focus-creative-games.hybridclr_unity m_SelectedScopeIndex: 0 diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 1aff11a4..7ded31aa 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -164,7 +164,9 @@ PlayerSettings: androidSupportedAspectRatio: 1 androidMaxAspectRatio: 2.1 applicationIdentifier: + Android: com.dinstudio.tengine Standalone: com.DefaultCompany.2DProject + iPhone: com.dinstudio.tengine buildNumber: Standalone: 0 iPhone: 0 @@ -253,7 +255,7 @@ PlayerSettings: useCustomBaseGradleTemplate: 0 useCustomGradlePropertiesTemplate: 0 useCustomProguardFile: 0 - AndroidTargetArchitectures: 1 + AndroidTargetArchitectures: 3 AndroidTargetDevices: 0 AndroidSplashScreenScale: 0 androidSplashScreen: {fileID: 0} @@ -426,9 +428,9 @@ PlayerSettings: enableInternalProfiler: 0 logObjCUncaughtExceptions: 1 enableCrashReportAPI: 0 - cameraUsageDescription: - locationUsageDescription: - microphoneUsageDescription: + cameraUsageDescription: "\u662F\u5426\u5141\u8BB8\u6253\u5F00\u6444\u50CF\u5934" + locationUsageDescription: "\u662F\u5426\u5141\u8BB8\u8BBF\u95EE\u5B9A\u4F4D" + microphoneUsageDescription: "\u662F\u5426\u5141\u8BB8\u8BBF\u95EE\u7535\u8BDD" bluetoothUsageDescription: switchNMETAOverride: switchNetLibKey: @@ -674,7 +676,8 @@ PlayerSettings: 14: ENABLE_LOG additionalCompilerArguments: {} platformArchitecture: {} - scriptingBackend: {} + scriptingBackend: + Android: 1 il2cppCompilerConfiguration: {} managedStrippingLevel: {} incrementalIl2cppBuild: {} @@ -685,10 +688,11 @@ PlayerSettings: enableRoslynAnalyzers: 1 additionalIl2CppArgs: scriptingRuntimeVersion: 1 - gcIncremental: 1 + gcIncremental: 0 assemblyVersionValidation: 1 gcWBarrierValidation: 0 - apiCompatibilityLevelPerPlatform: {} + apiCompatibilityLevelPerPlatform: + Android: 3 m_RenderingPath: 1 m_MobileRenderingPath: 1 metroPackageName: 2D_BuiltInRenderer diff --git a/ReadmeSrc/Editor-RunSuccessed.png b/ReadmeSrc/Editor-RunSuccessed.png new file mode 100644 index 00000000..9068d93b Binary files /dev/null and b/ReadmeSrc/Editor-RunSuccessed.png differ