void Start() { GameApplication.Instance.HotFix = this; Initialize(); var dab = ResourceLoader.GetAssetBundle("flymodel.dll").LoadAllAssets <TextAsset>(); var dllAsset = dab[0]; var msDll = new System.IO.MemoryStream(dllAsset.bytes); //var pab = ResourceLoader.GetAssetBundle("flymodel.pdb").LoadAllAssets<TextAsset>(); ; //var pdbAsset = pab[0]; //var msPdb = new System.IO.MemoryStream(pdbAsset.bytes); //env.LoadModule(msDll, msPdb, new Mono.Cecil.Pdb.PdbReaderProvider()); env.LoadModule(msDll); Debug.Log("LoadModule HotFixCode.dll done."); context = new CLRSharp.ThreadContext(env); Debug.Log("Create ThreadContext for L#."); commandType = env.GetType("FlyModel.CommandHandle"); commandInstance = new CLRSharp_Instance(commandType as CLRSharp.ICLRType_Sharp); IMethod methodctor = commandType.GetMethod(".ctor", CLRSharp.MethodParamList.constEmpty()); if (methodctor != null) { methodctor.Invoke(context, commandInstance, null); } DoStaticMethod(context, "FlyModel.GameMain", "Start"); }
public void Notify(eMonoMessageType mType, params object[] data) { callBack.Notify(mType, data); if (method_notify == null) { method_notify = class_type.GetMethod("Notify", MethodParamList.Make(LSharpModule.env.GetType(typeof(eMonoMessageType)))); } method_notify.Invoke(ThreadContext.activeContext, inst, new object[] { mType }); }
public ScriptableController(ICLRSharp_Environment env, ICLRType type, string name) { var method = type.GetMethod(".ctor", MethodParamList.constEmpty()); mRuntimeObject = method.Invoke(ThreadContext.activeContext, null, null); mName = name; Init(env, (CLRSharp_Instance)mRuntimeObject); }
public static MainUIThread GetInstance() { if (ui == null) { ui = GameObject.FindObjectOfType(typeof(MainUIThread)) as MainUIThread; if (!ui) { GameObject obj = new GameObject("_MainUIThread"); GameObject.DontDestroyOnLoad(obj); ui = obj.AddComponent <MainUIThread>(); ICLRType program = LSharpModule.env.GetType("GameUI.Program"); IMethod main = program.GetMethod("GetInstance", MethodParamList.constEmpty()); object program_object = main.Invoke(ThreadContext.activeContext, null, null); IMethod method_AddNotifys = program.GetMethod("AddNotifys", MethodParamList.Make(LSharpModule.env.GetType(typeof(MainUIThread)))); method_AddNotifys.Invoke(ThreadContext.activeContext, program_object, new object[] { ui }); } } return(ui); }
private void LoadModule(string name) { string path = name + ".dll"; string path2 = name + ".pdb"; byte[] bytes = Resources.Load <TextAsset>(path).bytes; byte[] bytes2 = Resources.Load <TextAsset>(path2).bytes; MemoryStream dllStream = new MemoryStream(bytes); MemoryStream pdbStream = new MemoryStream(bytes2); try { this.mRunEnv.LoadModule(dllStream, pdbStream, new PdbReaderProvider()); } catch (Exception var_6_59) { } this.mRunEnv.GetType(typeof(Dictionary <int, string>)); this.mRunEnv.GetType(typeof(Dictionary <ShopType, UIToggle>)); this.mRunEnv.GetType(typeof(Dictionary <int, CLRSharp_Instance>)); this.mRunEnv.GetType(typeof(Dictionary <int, Action>)); this.mRunEnv.GetType(typeof(Dictionary <short, Action>)); this.mRunEnv.GetType(typeof(LinkedList <int>)); this.mRunEnv.GetType(typeof(int[, ])); this.mRunEnv.GetType(typeof(List <Vector3>)); this.mRunEnv.GetType(typeof(List <ShopData>)); this.mRunEnv.GetType(typeof(List <EquipmentInfoData>)); this.mRunEnv.GetType(typeof(List <HeroInfoData>)); this.mRunEnv.GetType(typeof(List <SummSkinData>)); this.mRunEnv.GetType(typeof(List <int>[])); this.mRunEnv.GetType(typeof(List <List <int> >)); this.mRunEnv.GetType(typeof(List <List <List <int> > >)); this.mRunEnv.GetType(typeof(Vector3[])); this.mRunEnv.GetType(typeof(IEnumerable <int>)); Delegate_Binder.RegBind(typeof(Action <int>), new Delegate_BindTool <int>()); Delegate_Binder.RegBind(typeof(Action <bool, ShopData>), new Delegate_BindTool_Ret <bool, ShopData>()); Delegate_Binder.RegBind(typeof(Action <bool, EquipmentInfoData>), new Delegate_BindTool_Ret <bool, EquipmentInfoData>()); Delegate_Binder.RegBind(typeof(Action <bool, SummSkinData>), new Delegate_BindTool_Ret <bool, SummSkinData>()); Delegate_Binder.RegBind(typeof(Action <int, int>), new Delegate_BindTool <int, int>()); Delegate_Binder.RegBind(typeof(Action <int, int, int>), new Delegate_BindTool <int, int, int>()); Delegate_Binder.RegBind(typeof(Func <int, int, int>), new Delegate_BindTool_Ret <int, int, int>()); Delegate_Binder.RegBind(typeof(Action <int, string>), new Delegate_BindTool <int, string>()); Delegate_Binder.RegBind(typeof(Action <string>), new Delegate_BindTool <string>()); Delegate_Binder.RegBind(typeof(Action <bool>), new Delegate_BindTool <bool>()); this.mRunEnv.RegCrossBind(new IViewCrossBind()); if (ThreadContext.activeContext == null) { this.mContext = new ThreadContext(this.mRunEnv, 2); } ICLRType type = this.mRunEnv.GetType("GUIScript.ShellClass"); IMethod method = type.GetMethod("Initialize", MethodParamList.constEmpty()); method.Invoke(this.mContext, null, null); }
public void SetShopType(ShopType type) { ICLRType type2 = this.mRunEnv.GetType("GUIScript.ShopCtrl"); IMethod method = type2.GetMethod("SetType", MethodParamList.Make(new ICLRType[] { this.mContext.environment.GetType(typeof(ShopType)) })); method.Invoke(this.mContext, null, new object[] { type }); }
public void OpenWindow(WindowID winId) { ICLRType type = this.mRunEnv.GetType("GUIScript.ShellClass"); IMethod method = type.GetMethod("OpenWindow", MethodParamList.Make(new ICLRType[] { this.mContext.environment.GetType(typeof(WindowID)) })); method.Invoke(this.mContext, null, new object[] { winId }); }
private void Init() { if (class_name_L == "") { class_name_L = default_class_name; Debug.LogWarning("传入的L#类名为空,将使用L#基类进行绑定!"); } class_type = LSharpModule.env.GetType(class_name_L); if (inst == null) { IMethod ctor = class_type.GetMethod(".ctor", MethodParamList.Make(LSharpModule.env.GetType(typeof(GameObject)))); inst = ctor.Invoke(ThreadContext.activeContext, null, new object[] { gameObject }); } }
IMethod GetNewForArray(object token) { IMethod __method = null; if (methodCache.TryGetValue(token.GetHashCode(), out __method)) { return(__method); } Mono.Cecil.ModuleDefinition module = null; string typename = null; if (token is Mono.Cecil.TypeDefinition) { Mono.Cecil.TypeDefinition _def = (token as Mono.Cecil.TypeDefinition); module = _def.Module; typename = _def.FullName; } else if (token is Mono.Cecil.TypeReference) { Mono.Cecil.TypeReference _ref = (token as Mono.Cecil.TypeReference); module = _ref.Module; typename = _ref.FullName; } else { throw new NotImplementedException(); } ICLRType _type = null; ICLRType _Itype = GetType(typename); if (_Itype is ICLRType_Sharp) { _type = environment.GetType(typeof(CLRSharp.CLRSharp_Instance[])); } else { typename += "[]"; //var _type = context.environment.GetType(typename, type.Module); _type = GetType(typename); } MethodParamList tlist = MethodParamList.const_OneParam_Int(environment); var m = _type.GetMethod(".ctor", tlist); methodCache[token.GetHashCode()] = m; return(m); }
public IMethod GetMethod(object token) { IMethod result; try { IMethod method = null; bool flag = this.methodCache.TryGetValue(token.GetHashCode(), out method); if (flag) { result = method; } else { MethodParamList methodParamList = null; bool flag2 = token is MethodReference; string name; string text; MethodParamList types; if (flag2) { MethodReference methodReference = token as MethodReference; ModuleDefinition module = methodReference.Module; name = methodReference.Name; text = methodReference.DeclaringType.FullName; types = new MethodParamList(this.environment, methodReference); bool isGenericInstance = methodReference.IsGenericInstance; if (isGenericInstance) { GenericInstanceMethod method2 = methodReference as GenericInstanceMethod; methodParamList = new MethodParamList(this.environment, method2); } } else { bool flag3 = token is MethodDefinition; if (!flag3) { throw new NotImplementedException(); } MethodDefinition methodDefinition = token as MethodDefinition; ModuleDefinition module = methodDefinition.Module; name = methodDefinition.Name; text = methodDefinition.DeclaringType.FullName; types = new MethodParamList(this.environment, methodDefinition); bool isGenericInstance2 = methodDefinition.IsGenericInstance; if (isGenericInstance2) { throw new NotImplementedException(); } } ICLRType type = this.GetType(text); bool flag4 = type == null; if (flag4) { text = text.Replace("0...", ""); type = this.GetType(text); } bool flag5 = type == null; if (flag5) { throw new Exception("type can't find:" + text); } bool flag6 = methodParamList != null; IMethod method3; if (flag6) { method3 = type.GetMethodT(name, methodParamList, types); } else { method3 = type.GetMethod(name, types); } this.methodCache[token.GetHashCode()] = method3; result = method3; } } catch (Exception innerException) { throw new Exception("Error GetMethod==<这意味着这个函数无法被L#找到>" + token, innerException); } return(result); }
/// <summary> /// 获取方法,可以获取继承的方法 /// </summary> /// <param name="clrType">类型</param> /// <param name="funName">方法名</param> /// <param name="paramTypes">参数类型</param> /// <returns></returns> public IMethod GetMethod(ICLRType clrType, string funName, MethodParamList paramTypes = null) { if (paramTypes == null) { paramTypes = MethodParamList.constEmpty(); } IMethod fun = clrType.GetMethod(funName, paramTypes); if (fun == null) { Type_Common_CLRSharp subType = clrType as Type_Common_CLRSharp; if (subType != null && subType.BaseType != null) { fun = GetMethod(subType.BaseType, funName, paramTypes); } } return fun; }
//============================================================ /// <summary> /// 获取GMonoBehaviour事件的方法 /// </summary> /// <param name="clrType"></param> /// <param name="method"></param> /// <param name="paramTypes"></param> /// <returns></returns> public IMethod getGMBEventMethod(ICLRType clrType, GMBEventMethod method, MethodParamList paramTypes = null) { if (paramTypes == null) { paramTypes = MethodParamList.constEmpty(); } if (clrType == null || clrType.FullName == "Freamwork.GMB") { return null; } Dictionary<string, IMethod> methodDic; if (!dic.ContainsKey(clrType.FullName)) { methodDic = new Dictionary<string, IMethod>(); dic.Add(clrType.FullName, methodDic); } else { methodDic = dic[clrType.FullName]; } string methodName = totalMethodNameList[(int)method]; if (methodDic.ContainsKey(methodName)) { return methodDic[methodName]; } IMethod eventMethod = clrType.GetMethod(methodName, paramTypes); if (eventMethod == null) { Type_Common_CLRSharp type = clrType as Type_Common_CLRSharp; if (type != null) { eventMethod = getGMBEventMethod(type.BaseType, method, paramTypes); } } methodDic[methodName] = eventMethod; return eventMethod; }