@Wulf , Can you add methods(nested type) to handle hook
[DOUBLEPOST=1490279093][/DOUBLEPOST]ExampleCode:// CSPlugin.cs line: 64// Find all hooks in the plugin and any base classes derived from CSPlugin var types = new List<Type>(); var type = GetType(); types.Add(type);//REPLACE while (type != typeof(CSPlugin)) types.Add(type = type.BaseType); //TO while (type != typeof(CSPlugin)) { types.AddRange(type.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Public)); types.Add(type = type.BaseType); } // END// Add hooks implemented in base classes before user implemented methods for (var i = types.Count - 1; i >= 0; i--) { foreach (var method in types[i].GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) { var attr = method.GetCustomAttributes(typeof(HookMethodAttribute), true); if (attr.Length < 1) continue; var hookmethod = attr[0] as HookMethodAttribute; AddHookMethod(hookmethod?.Name, method); }
Code:namespace Oxide.Plugins { [Info("EpicStuff", "Unknown", 0.1)] [Description("Makes epic stuff happen")] class EpicStuff : RustPlugin { class Foo { [HookMethod("OnServerInitialized")] void OnServerInitialized() { Puts("It's work!"); } } } }
Solved Calling a hook in nested type?
Discussion in 'Rust Development' started by bazuka5801, Mar 23, 2017.