diff --git a/Assets/XLua/Doc/Hotfix_EN.md b/Assets/XLua/Doc/Hotfix_EN.md
index 448f54f55..b10e77af7 100644
--- a/Assets/XLua/Doc/Hotfix_EN.md
+++ b/Assets/XLua/Doc/Hotfix_EN.md
@@ -156,6 +156,10 @@ xlua.hotfix(CS.HotfixTest, 'Update', function(self)
The premise is that hotfix_id_map.lua.txt is in a directory that can be referenced by require 'hotfix_id_map'.
+## Ignore Method
+Adding [Hotfix(HotfixFlag.IgnoreThisMethod)] attribute to a method will not GenDelegateBridge for that method and will not hotfix inject that method.
+Typically used for methods that cause xlua generation to cause compilation errors. For example methods with Span parameters in the signature.
+
## Usage suggestions
* Add the Hotfix flag to all types that are most likely to be modified.
diff --git a/Assets/XLua/Doc/hotfix.md b/Assets/XLua/Doc/hotfix.md
index 04a28b3df..0e0fe715c 100644
--- a/Assets/XLua/Doc/hotfix.md
+++ b/Assets/XLua/Doc/hotfix.md
@@ -171,6 +171,10 @@ xlua.hotfix(CS.HotfixTest, 'Update', function(self)
前提是 `hotfix_id_map.lua.txt` 放到可以通过 `require 'hotfix_id_map'` 引用到的地方。
+## 忽略特定方法
+在方法上添加[Hotfix(HotfixFlag.IgnoreThisMethod)]特性标记,则不会为该方法生成委托,也不会hotfix inject该方法。
+通常用于一些会导致xlua生成造成编译错误的函数。例如签名中含有Span参数的方法。
+
## 使用建议
* 对所有较大可能变动的类型加上 `Hotfix` 标识;
diff --git a/Assets/XLua/Src/Editor/Generator.cs b/Assets/XLua/Src/Editor/Generator.cs
index b20fa1d15..c3b8e3ecc 100644
--- a/Assets/XLua/Src/Editor/Generator.cs
+++ b/Assets/XLua/Src/Editor/Generator.cs
@@ -900,6 +900,28 @@ static bool HasFlag(this HotfixFlag toCheck, HotfixFlag flag)
return (toCheck != HotfixFlag.Stateless) && ((toCheck & flag) == flag);
}
+ ///
+ /// 方法是否由特性标记为忽略生成委托
+ ///
+ ///
+ ///
+ static bool isIgnoreGenDelegateBridgeByAttribute(MemberInfo member)
+ {
+ var ca = GetCustomAttribute(member, typeof(HotfixAttribute));
+ if (ca == null)
+ {
+ return false;
+ }
+
+#if XLUA_GENERAL
+ var hotfixType = (HotfixFlag)Convert.ToInt32(ca.GetType().GetProperty("Flag").GetValue(ca, null));
+#else
+ var hotfixType = (ca as HotfixAttribute).Flag;
+#endif
+
+ return hotfixType.HasFlag(HotfixFlag.IgnoreGenDelegateBridge);
+ }
+
static void GenDelegateBridge(IEnumerable types, string save_path, IEnumerable hotfix_check_types)
{
string filePath = save_path + "DelegatesGensBridge.cs";
@@ -945,6 +967,7 @@ static void GenDelegateBridge(IEnumerable types, string save_path, IEnumer
.Cast()
.Concat(kv.Key.GetConstructors(bindingAttrOfConstructor).Cast())
.Where(method => !injectByGeneric(method, kv.Value))
+ .Where(method => !isIgnoreGenDelegateBridgeByAttribute(method))
.Select(method => makeHotfixMethodInfoSimulation(method, kv.Value)));
}
hotfxDelegates = hotfxDelegates.Distinct(comparer).ToList();
diff --git a/Assets/XLua/Src/Editor/Hotfix.cs b/Assets/XLua/Src/Editor/Hotfix.cs
index cb1b02b4c..a0b2851c3 100644
--- a/Assets/XLua/Src/Editor/Hotfix.cs
+++ b/Assets/XLua/Src/Editor/Hotfix.cs
@@ -170,6 +170,18 @@ enum HotfixFlagInTool
AdaptByDelegate = 64,
IgnoreCompilerGenerated = 128,
NoBaseProxy = 256,
+ ///
+ /// 仅标记在方法上有效。忽略此方法生成委托。
+ ///
+ IgnoreGenDelegateBridge = 512,
+ ///
+ /// 仅标记在方法上有效。忽略此方法注入。
+ ///
+ IgnoreHotfixInject = 1024,
+ ///
+ /// 仅标记在方法上有效。忽略此方法生成委托和注入。
+ ///
+ IgnoreThisMethod = IgnoreGenDelegateBridge | IgnoreHotfixInject,
}
static class ExtentionMethods
@@ -685,6 +697,25 @@ static bool genericInOut(MethodDefinition method, HotfixFlagInTool hotfixType)
return false;
}
+ ///
+ /// 方法是否由特性标记为忽略注入
+ ///
+ ///
+ ///
+ ///
+ public bool isIgnoreInjectMethodByAttribute(TypeReference hotfixAttributeType, MethodDefinition method)
+ {
+ CustomAttribute hotfixAttr = method.CustomAttributes.FirstOrDefault(ca => ca.AttributeType == hotfixAttributeType);
+ HotfixFlagInTool hotfixType = default;
+ if (hotfixAttr != null)
+ {
+ hotfixType = (HotfixFlagInTool)(int)hotfixAttr.ConstructorArguments[0].Value;
+ }
+
+ bool ignore = hotfixType.HasFlag(HotfixFlagInTool.IgnoreHotfixInject);
+ return ignore;
+ }
+
public bool InjectType(TypeReference hotfixAttributeType, TypeDefinition type)
{
foreach(var nestedTypes in type.NestedTypes)
@@ -747,6 +778,10 @@ public bool InjectType(TypeReference hotfixAttributeType, TypeDefinition type)
{
continue;
}
+ if (isIgnoreInjectMethodByAttribute(hotfixAttributeType,method))
+ {
+ continue;
+ }
if (method.Name != ".cctor" && !method.IsAbstract && !method.IsPInvokeImpl && method.Body != null && !method.Name.Contains("<"))
{
//Debug.Log(method);
diff --git a/Assets/XLua/Src/GenAttributes.cs b/Assets/XLua/Src/GenAttributes.cs
index a0339be45..a641edf5a 100644
--- a/Assets/XLua/Src/GenAttributes.cs
+++ b/Assets/XLua/Src/GenAttributes.cs
@@ -103,6 +103,18 @@ public enum HotfixFlag
AdaptByDelegate = 64,
IgnoreCompilerGenerated = 128,
NoBaseProxy = 256,
+ ///
+ /// 仅标记在方法上有效。忽略此方法生成委托。
+ ///
+ IgnoreGenDelegateBridge = 512,
+ ///
+ /// 仅标记在方法上有效。忽略此方法注入。
+ ///
+ IgnoreHotfixInject = 1024,
+ ///
+ /// 仅标记在方法上有效。忽略此方法生成委托和注入。
+ ///
+ IgnoreThisMethod = IgnoreGenDelegateBridge | IgnoreHotfixInject,
}
public class HotfixAttribute : Attribute
diff --git a/Tools/FilesSignature.exe b/Tools/FilesSignature.exe
index cf98ac108..6664198d7 100644
Binary files a/Tools/FilesSignature.exe and b/Tools/FilesSignature.exe differ
diff --git a/Tools/FilesSignature.pdb b/Tools/FilesSignature.pdb
index 047ca2f6c..1f375d33c 100644
Binary files a/Tools/FilesSignature.pdb and b/Tools/FilesSignature.pdb differ
diff --git a/Tools/KeyPairsGen.exe b/Tools/KeyPairsGen.exe
index dba057676..e63cb92cd 100644
Binary files a/Tools/KeyPairsGen.exe and b/Tools/KeyPairsGen.exe differ
diff --git a/Tools/KeyPairsGen.pdb b/Tools/KeyPairsGen.pdb
index 129d845f8..2a0181560 100644
Binary files a/Tools/KeyPairsGen.pdb and b/Tools/KeyPairsGen.pdb differ
diff --git a/Tools/XLua.Mini.dll b/Tools/XLua.Mini.dll
index 35ace6081..0b405de4a 100644
Binary files a/Tools/XLua.Mini.dll and b/Tools/XLua.Mini.dll differ
diff --git a/Tools/XLua.Mini.pdb b/Tools/XLua.Mini.pdb
index 906e8663e..09b9c0a61 100644
Binary files a/Tools/XLua.Mini.pdb and b/Tools/XLua.Mini.pdb differ
diff --git a/Tools/XLuaGenerate.exe b/Tools/XLuaGenerate.exe
index 9681ceb65..76be64c54 100644
Binary files a/Tools/XLuaGenerate.exe and b/Tools/XLuaGenerate.exe differ
diff --git a/Tools/XLuaGenerate.pdb b/Tools/XLuaGenerate.pdb
index 9dc708975..4e1c64a93 100644
Binary files a/Tools/XLuaGenerate.pdb and b/Tools/XLuaGenerate.pdb differ
diff --git a/Tools/XLuaHotfixInject.exe b/Tools/XLuaHotfixInject.exe
index a51bf8ccf..8f92cf3ad 100644
Binary files a/Tools/XLuaHotfixInject.exe and b/Tools/XLuaHotfixInject.exe differ
diff --git a/Tools/XLuaHotfixInject.pdb b/Tools/XLuaHotfixInject.pdb
index 58f34fb3b..c21fe9a62 100644
Binary files a/Tools/XLuaHotfixInject.pdb and b/Tools/XLuaHotfixInject.pdb differ