HotUpdateCodeLoader.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections;
  3. using System.Reflection;
  4. using UnityEngine;
  5. using GFGGame.Launcher;
  6. namespace GFGGame
  7. {
  8. public class HotUpdateCodeLoader : SingletonMonoBase<HotUpdateCodeLoader>
  9. {
  10. public Type[] allTypes;
  11. public Type[] GetTypes()
  12. {
  13. return this.allTypes;
  14. }
  15. public void StartLoad()
  16. {
  17. StartCoroutine(StartLoadAssemblyHotfix());
  18. }
  19. IEnumerator StartLoadAssemblyHotfix()
  20. {
  21. LogServerHelperHttp.SendNodeLog((int)LogNode.StartLoadGameDll);
  22. //ET.Log.Debug("ILRuntimeLauncher StartLoadAssemblyHotfix");
  23. yield return new WaitForSeconds(0.1f);
  24. var dllPath = $"{LauncherConfig.DllDirHotfix}Game.HotUpdate.dll.bytes";
  25. var asset = GFGAsset.Load<TextAsset>(dllPath);
  26. byte[] assBytes = asset.bytes;
  27. var pdbPath = $"{LauncherConfig.DllDirHotfix}Game.HotUpdate.pdb.bytes";
  28. asset = GFGAsset.Load<TextAsset>(pdbPath);
  29. byte[] pdbBytes = asset.bytes;
  30. StartCoroutine(LoadAssemblyJustInTime(assBytes, pdbBytes));
  31. GFGAsset.Release(dllPath);
  32. GFGAsset.Release(pdbPath);
  33. }
  34. IEnumerator LoadAssemblyJustInTime(byte[] assBytes, byte[] pdbBytes)
  35. {
  36. //mono模式
  37. var assembly = Assembly.Load(assBytes, pdbBytes);
  38. this.allTypes = assembly.GetTypes();
  39. System.Type type = assembly.GetType("GFGGame.HotUpdate.HotUpdateEntry");
  40. type.GetMethod("Start").Invoke(type, null);
  41. yield break;
  42. }
  43. }
  44. }