From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/LuaEngine/HotfixPatch.cs | 75 ++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Client/Assets/Scripts/LuaEngine/HotfixPatch.cs (limited to 'Client/Assets/Scripts/LuaEngine/HotfixPatch.cs') diff --git a/Client/Assets/Scripts/LuaEngine/HotfixPatch.cs b/Client/Assets/Scripts/LuaEngine/HotfixPatch.cs new file mode 100644 index 00000000..af06701a --- /dev/null +++ b/Client/Assets/Scripts/LuaEngine/HotfixPatch.cs @@ -0,0 +1,75 @@ +using UnityEngine; +using System.Collections.Generic; +using LuaInterface; + +public class HotfixPatch +{ + static List list = new List(); + static LuaFunction lua_dispacher_func; + const string LUA_FILE = "HotfixPatch.lua"; + + public static void Init(LuaScriptMgr luamgr) + { + luamgr.lua.DoFile(LUA_FILE); + var func = luamgr.lua.GetFunction("Fetch"); + object[] ret = func.Call(); + Debug.Log("lua regist func cnt:" + (ret.Length)); + list.Clear(); + for (int i = 0, cnt = ret.Length; i < cnt; i++) + { + list.Add((string)ret[i]); + } + lua_dispacher_func = luamgr.lua.GetFunction("Dispacher"); + } + + + /// + /// 方法由IL层-注入代码调用 + /// + public static bool IsRegist(string class_name, string func_name) + { + string key = class_name + "|" + func_name; + return list.Contains(key); + } + + /// + /// 方法由IL层-注入代码调用 + /// + public static object Execute(string class_name, string func_name, string type, object[] args) + { + if (lua_dispacher_func != null) + { + Debug.Log("inject arg len: " + args.Length); + object val = lua_dispacher_func.Call(class_name, func_name, args)[0]; + if (val != null && typeof(System.Double) == val.GetType()) //先转换成double,再拆箱 + { + switch (type) + { + case "int": + case "Int32": + return (int)(double)val; + case "uint": + case "UInt32": + return (uint)(double)val; + case "float": + case "Single": + return (float)(double)val; + case "short": + case "Int16": + return (short)(double)val; + case "UInt64": + case "ulong": + return (ulong)(double)val; + } + return val; + } + else + { + return val; + } + } + return null; + } + + +} \ No newline at end of file -- cgit v1.1-26-g67d0