Example #1
0
 static Cheat()
 {
     CheatManager = new LoadedTypeManager(new Assembly[] { Assembly.GetExecutingAssembly() }, typeof(Cheat), null);
     foreach (var iterate in CheatManager.ManagedTypes)
     {
         ConstructorInfo findconstructor = iterate.GetConstructor(new Type[] { });
         if (findconstructor != null)
         {
             Cheat CheatInstance = (Cheat)findconstructor.Invoke(new object[] { });
             CheatDictionary.Add(CheatInstance.CheatName, CheatInstance);
         }
     }
 }
        public MultiTypeManager(Assembly[] lookassemblies, Type[] typesload, IEnumerable <String> IgnoreAssemblies, IEnumerable <String> IncludeAssemblies, iManagerCallback pcallback, TypeManagerLoadProgressCallback pprog, Assembly[] preloadedassemblies)
        {
            //each Type corresponds to a new LoadedTypeManager to load for that type.
            //LoadedTypeManager[] ltm = new LoadedTypeManager[typesload.Length];

            //create the Dictionary first...
            if (IgnoreAssemblies == null)
            {
                IgnoreAssemblies = new String[] { }
            }
            ;
            List <Assembly> buildcheck = new List <Assembly>();

            if (preloadedassemblies != null)
            {
                buildcheck.AddRange(preloadedassemblies);
            }
            buildcheck.AddRange(lookassemblies);

            Assembly[] checkassemblies = buildcheck.ToArray();

            loadeddata = new Dictionary <Type, LoadedTypeManager>();
            foreach (Type looptype in typesload)
            {
                LoadedTypeManager addtm = new LoadedTypeManager(looptype, pcallback);
                loadeddata.Add(looptype, addtm);
            }



            //now that we have the LoadedTypeManager objects, uninitialized- we can iterate through each assembly and the types
            //in each assembly for matches.
            //assemblyprogressincrement: the amount of progress we will go through after checking each assembly.
            float assemblyprogressincrement = 1f / (float)checkassemblies.Count();
            float currprogress = 0;

            foreach (Assembly loopassembly in checkassemblies)
            {
                if ((loopassembly.GetName().Name.StartsWith("script_", StringComparison.OrdinalIgnoreCase)) || (!IgnoreAssemblies.Any((w) => loopassembly.GetName().Name.TestRegex(w))))
                {
                    pcallback.ShowMessage("Inspecting Assembly:" + loopassembly.GetName().Name);
                    //iterate through each type...
                    currprogress += assemblyprogressincrement;
                    Type[] typesiterate;
                    try
                    {
                        typesiterate = loopassembly.GetTypes();
                    }
                    catch (ReflectionTypeLoadException rtle)
                    {
                        pcallback.ShowMessage("ReflectionTypeLoadException occured;" + rtle.StackTrace +
                                              " InnerExceptions:");
                        foreach (Exception loopexception in rtle.LoaderExceptions)
                        {
                            pcallback.ShowMessage("RTLE Loader Exception:" + loopexception.Message + " Source:" +
                                                  loopexception.Source + "stack Trace:" + loopexception.StackTrace);
                        }
                        pcallback.ShowMessage("End of RTLE Loader Exceptions");
                        currprogress += assemblyprogressincrement;
                        if (pprog != null)
                        {
                            pprog(currprogress);
                        }
                        typesiterate = null;
                    }
                    if (typesiterate != null)
                    {
                        //iterate through each type...

                        //get appropriate percent per type...
                        // float percentpertype = assemblyprogressincrement / typesiterate.Length;

                        foreach (Type looptype in typesiterate)
                        {
                            //currprogress+=percentpertype;



                            // pcallback.ShowMessage("Checking type:" + looptype.FullName);
                            //And... for each type, iterate through all the LoadedTypeManagers in our dictionary...
                            foreach (var checkmanager in loadeddata)
                            {
                                if (LoadedTypeManager.CheckType(looptype, checkmanager.Key, pcallback))
                                {
                                    pcallback.ShowMessage("Type:" + looptype.FullName + " is a, or implements, " +
                                                          checkmanager.Key.Name);
                                    //add it to that manager...
                                    checkmanager.Value.ManagedTypes.Add(looptype);
                                }
                            }
                        }
                    }
                }
                else
                {
                    currprogress += assemblyprogressincrement;
                    pprog(currprogress);
                    pcallback.ShowMessage("Skipped Assembly " + loopassembly.FullName);
                }
            }

            //at the conclusion of the loop, show a summary.
            if (!(pcallback is Nullcallback))
            {
                pcallback.ShowMessage("Assembly enumeration complete.(" + checkassemblies.Count().ToString() + " Assemblies ");
                //^save time by not doing this for a Nullcallback...
                foreach (var loopltm in loadeddata)
                {
                    pcallback.ShowMessage(" found " + loopltm.Value.ManagedTypes.Count + " instances of type " + loopltm.Key.Name);
                }
            }
        }
    }