Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.37 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. using PluginSystem;
  10.  
  11. namespace MEAExplorerWV
  12. {
  13.     public static class Plugins
  14.     {
  15.         public static List<IPlugin> PluginList = new List<IPlugin>();
  16.         public static IPluginHost Host;
  17.         public static void Init()
  18.         {
  19.             try
  20.             {
  21.                 Host = new PluginHost();
  22.                 if (!Directory.Exists("plugins"))
  23.                     return;
  24.                 string[] files = Directory.GetFiles("plugins\\", "*.dll", SearchOption.AllDirectories);
  25.                 ICollection<Assembly> assemblies = new List<Assembly>();
  26.                 foreach (string file in files)
  27.                 {
  28.                     try
  29.                     {
  30.                         AssemblyName an = AssemblyName.GetAssemblyName(file);
  31.                         Assembly assembly = Assembly.Load(an);
  32.                         assemblies.Add(assembly);
  33.                     }
  34.                     catch { }
  35.                 }
  36.                 Type pluginType = typeof(IPlugin);
  37.                 ICollection<Type> pluginTypes = new List<Type>();
  38.                 foreach (Assembly assembly in assemblies)
  39.                     if (assembly != null)
  40.                     {
  41.                         Type[] types = assembly.GetTypes();
  42.                         foreach (Type type in types)
  43.                             if (type.IsInterface || type.IsAbstract)
  44.                                 continue;
  45.                             else
  46.                                 if (type.GetInterface(pluginType.FullName) != null)
  47.                                     pluginTypes.Add(type);
  48.                     }
  49.                 foreach (Type type in pluginTypes)
  50.                 {
  51.                     IPlugin plugin = (IPlugin)Activator.CreateInstance(type);
  52.                     plugin.Host = Host;
  53.                     PluginList.Add(plugin);
  54.                 }
  55.             }
  56.             catch (Exception ex)
  57.             {
  58.                 Log.WriteLine("Error loading plugins: " + ex.Message);
  59.                 Log.WriteLine(ex.StackTrace);
  60.             }
  61.         }
  62.  
  63.         public class PluginHost : IPluginHost
  64.         {
  65.             public List<string> getTOCFiles()
  66.             {
  67.                 List<string> result = new List<string>();
  68.                 foreach (FS.TOCEntry toc in FS.TOClist)
  69.                     result.Add(toc.filePath);
  70.                 return result;
  71.             }
  72.             public List<string> getTOCFileLabels()
  73.             {
  74.                 List<string> result = new List<string>();
  75.                 foreach (FS.TOCEntry toc in FS.TOClist)
  76.                     result.Add(toc.displayName);
  77.                 return result;
  78.             }
  79.             public List<string> getBundleNames(string toc)
  80.             {
  81.                 return FS.getAllBundleNames(toc);
  82.             }
  83.             public List<DataInfo> getAllEBX(string toc, string bundle)
  84.             {
  85.                 return FS.getAllBundleEntries(toc, bundle, "ebx");
  86.             }
  87.             public List<DataInfo> getAllRES(string toc, string bundle)
  88.             {
  89.                 return FS.getAllBundleEntries(toc, bundle, "res");
  90.             }
  91.             public List<ChunkInfo> getAllTocCHUNKs(string toc)
  92.             {
  93.                 return FS.getAllTocChunks(toc);
  94.             }
  95.             public List<ChunkInfo> getAllBundleCHUNKs(string toc, string bundle)
  96.             {
  97.                 return FS.getAllBundleChunks(toc, bundle);
  98.             }
  99.  
  100.             public byte[] getDataBySha1(byte[] sha1)
  101.             {
  102.                 return FS.FindDataBySha1(sha1);
  103.             }
  104.  
  105.             public int setDataBySha1(byte[] data, byte[] sha1, string toc)
  106.             {
  107.                 return FS.SetDataBySha1(data, sha1, toc);
  108.             }
  109.  
  110.             public void setAutoPatching(bool value)
  111.             {
  112.                 FS.autoPatchData = value;
  113.             }
  114.  
  115.             public void AddModJob(string pname, string desc, byte[] payload)
  116.             {
  117.                 Mods.Jobs.Add(new Mods.ModJob(pname, desc, payload));
  118.             }
  119.  
  120.             public Dictionary<string, string> getEBXGuids()
  121.             {
  122.                 return FS.ebxGUIDs;
  123.             }
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement