Exemplo n.º 1
0
 /// <summary>
 /// Initializes the Registry. This is automatically called when the bound mod is loaded
 /// </summary>
 public void Initialize()
 {
     if (!initialized)
     {
         WeaverLog.Log("Loading Registry = " + RegistryName + " for mod = " + ModName);
         //initialized = true;
         AllRegistries.Add(this);
         if (RegistryEnabled)
         {
             ActiveRegistries.Add(this);
         }
         // WeaverLog.Log("Feature Count = " + featuresRaw.Count);
         foreach (var feature in featuresRaw)
         {
             //WeaverLog.Log("Feature = " + feature);
             if (feature is IFeature && feature is IOnFeatureLoad)
             {
                 //WeaverLog.Log("Loading Feature: " + feature);
                 try
                 {
                     ((IOnFeatureLoad)feature).OnFeatureLoad(this);
                 }
                 catch (Exception e)
                 {
                     WeaverLog.LogError("Registry Load Error: " + e);
                 }
             }
         }
         // WeaverLog.Log("THIS = " + this);
         RunRegistryLoadFunctions(this);
     }
 }
Exemplo n.º 2
0
        /*private static void EditorApplication_playModeStateChanged(UnityEditor.PlayModeStateChange obj)
         * {
         *      Debug.Log("Play State = " + obj);
         * }*/

        static void PatchAssembly(Assembly assembly)
        {
            var patcherInstance = HarmonyPatcher.Create("com." + assembly.GetName().Name + ".patch");

            var patchParameters = new Type[] { typeof(HarmonyPatcher) };
            var patchArguments  = new object[] { patcherInstance };

            var inits = ReflectionUtilities.GetMethodsWithAttribute <OnHarmonyPatchAttribute>(assembly, patchParameters).ToList();

            inits.Sort(new PriorityAttribute.PrioritySorter <OnHarmonyPatchAttribute>());

            foreach (var initPair in ReflectionUtilities.GetMethodsWithAttribute <OnHarmonyPatchAttribute>(assembly, patchParameters))
            {
                try
                {
                    initPair.Item1.Invoke(null, patchArguments);
                }
                catch (Exception e)
                {
                    WeaverLog.LogError("Patch Error: " + e);
                }
            }
        }
Exemplo n.º 3
0
        private static void RunRegistryLoadFunctions(Registry registry)
        {
            var registryMethods = ReflectionUtilities.GetMethodsWithAttribute <OnRegistryLoadAttribute>().ToList();

            registryMethods.Sort(new PriorityAttribute.PairSorter <OnRegistryLoadAttribute>());

            var param = new object[] { registry };


            foreach (var method in registryMethods)
            {
                try
                {
                    //WeaverLog.Log("Executing Registry Method = " + method.Item1.DeclaringType.FullName + ":" + method.Item1.Name);
                    //WeaverLog.Log("Param Value = " + param[0]);
                    method.Item1.Invoke(null, param);
                }
                catch (Exception e)
                {
                    WeaverLog.LogError("Error Running Function: " + method.Item1.DeclaringType.FullName + ":" + method.Item1.Name);
                    WeaverLog.LogError(e);
                }
            }
        }