zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/Model/Entity/Hotfix.cs

87 lines
2.8 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using ET;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
#if UNITY
2021-04-08 20:09:59 +08:00
using UnityEngine;
#endif
2021-04-08 20:09:59 +08:00
namespace ET
{
public sealed class Hotfix : Object
{
private static Hotfix _instance;
public static Hotfix instance => _instance = _instance ?? new Hotfix();
#if ILRuntime
private ILRuntime.Runtime.Enviorment.AppDomain appDomain;
private MemoryStream dllStream;
private MemoryStream pdbStream;
#else
private Assembly assembly;
#endif
private IStaticMethod start;
private List<Type> hotfixTypes;
public Assembly hotfix;
public Assembly hotfixView;
//public Action Update;
//public Action LateUpdate;
//public Action OnApplicationQuit;
public void GotoHotfix()
{
Log.Info($"开始加载热更逻辑");
Log.Info($"{start}");
this.start.Run();
}
public List<Type> GetHotfixTypes()
{
return this.hotfixTypes;
}
public async ETTask LoadHotfixAssembly()
{
try
{
#if UNITY
2021-04-08 20:09:59 +08:00
byte[] assBytes = (await ResourceHelper.LoadAssetAsync<TextAsset>(PathHelper.HotfixDll)).bytes;
byte[] pdbBytes = (await ResourceHelper.LoadAssetAsync<TextAsset>(PathHelper.HotfixPdb)).bytes;
byte[] assViewBytes = (await ResourceHelper.LoadAssetAsync<TextAsset>(PathHelper.HotfixViewDll)).bytes;
byte[] pdbViewBytes = (await ResourceHelper.LoadAssetAsync<TextAsset>(PathHelper.HotfixViewPdb)).bytes;
2021-04-08 20:09:59 +08:00
if (!Define.IsEditorMode)
{
2021-04-11 19:50:39 +08:00
string key = GameKeyComponent.Instance.key;
string keyIV = GameKeyComponent.Instance.keyIV;
2021-04-08 20:09:59 +08:00
assBytes = Utility.Encryption.AesCBCDecrypt(assBytes,key ,keyIV);
pdbBytes = Utility.Encryption.AesCBCDecrypt(pdbBytes, key,keyIV);
assViewBytes = Utility.Encryption.AesCBCDecrypt(assViewBytes,key ,keyIV);
pdbViewBytes = Utility.Encryption.AesCBCDecrypt(pdbViewBytes, key,keyIV);
}
#else
byte[] assBytes = null;
byte[] pdbBytes = null;
byte[] assViewBytes = null;
byte[] pdbViewBytes = null;
#endif
2021-04-08 20:09:59 +08:00
hotfix = Assembly.Load(assBytes, pdbBytes);
Type hotfixInit = hotfix.GetType("ET.InitHotfix");
this.start = new MonoStaticMethod(hotfixInit, "Start");
//this.hotfixTypes = assembly.GetTypes().ToList();
hotfixView = Assembly.Load(assViewBytes, pdbViewBytes);
//this.hotfixTypes.AddRange(viewAssembly.GetTypes());
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}