public void InjectPatches() { try { if (null == m_ModData) { throw new NullReferenceException("Mod data is not available"); } UMMData data = (m_ModData as UMMData); if (null == data) { throw new NullReferenceException("Invalid UMM mod data"); } string strEntryMethod = data.EntryMethod; int idx = strEntryMethod.LastIndexOf('.'); string strMethodName = strEntryMethod.Substring(idx + 1); string strClassName = strEntryMethod.Substring(0, idx); if (m_ModAssembly == null) { VortexPatcher.Logger.Info("Mod assembly is null"); string modAssemblyPath = Directory.GetFiles(VortexPatcher.CurrentModsPath, "*.dll", SearchOption.AllDirectories) .Where(file => file.EndsWith(data.AssemblyName)) .SingleOrDefault(); m_ModAssembly = Assembly.LoadFile(modAssemblyPath); } Type[] types = m_ModAssembly.GetTypes(); Type type = types.Where(ty => ty.FullName == strClassName).SingleOrDefault(); if (type == null) { throw new NullReferenceException("Failed to find entry Type in mod assembly"); } BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; MethodInfo methodInfo = type.GetMethod(strMethodName, bindingFlags); if (null == methodInfo) { throw new NullReferenceException("Failed to find entry Method in mod assembly"); } ModEntry modEntry = ModEntry.GetModEntry(data, m_ModAssembly.Location); object[] param = new object[] { modEntry }; methodInfo.Invoke(null, param); AddExposedMod(modEntry); } catch (ReflectionTypeLoadException ex) { foreach (Exception inner in ex.LoaderExceptions) { VortexPatcher.Logger.Error($"Loader exception: {inner.Message}", inner); } } catch (Exception exc) { VortexPatcher.Logger.Error("Failed to invoke starter method", exc); return; } }
public bool ParseManifest(string strManifestPath) { string dirPath = Path.GetDirectoryName(strManifestPath); string fileName = Path.GetFileName(strManifestPath); try { if (!File.Exists(strManifestPath)) { fileName = fileName.ToLower(); strManifestPath = Path.Combine(dirPath, fileName); } string json = File.ReadAllText(strManifestPath); UMMData modData = JsonConvert.DeserializeObject <UMMData>(json); if (modData.Base_Id != null) { AssignBaseData(modData); m_strAssemblyName = modData.AssemblyName; return(true); } else { return(false); } } catch (Exception exc) { bool isParserError = (exc is JsonException) ? true : false; if (!isParserError) { LoggerDelegates.LogError("Failed to parse mod data", exc); } return(false); } }
public string GetModName() { UMMData data = (m_ModData as UMMData); if (data == null) { throw new NullReferenceException("Invalid UMM Data"); } return(data.Base_Id); }
public bool ParseManifest(string strManifestPath) { try { string json = File.ReadAllText(strManifestPath); UMMData modData = JsonConvert.DeserializeObject <UMMData>(json); if (modData.Base_Id != null) { AssignBaseData(modData); m_strAssemblyName = modData.AssemblyName; return(true); } else { return(false); } } catch (Exception exc) { return(false); } }
public void InjectPatches() { try { if (null == m_ModData) { throw new ArgumentNullException("Mod data is not available"); } UMMData data = (m_ModData as UMMData); if (null == data) { throw new InvalidDataException("Invalid UMM mod data"); } string strEntryMethod = (m_ModData as UMMData).EntryMethod; int idx = strEntryMethod.LastIndexOf('.'); string strMethodName = strEntryMethod.Substring(idx + 1); string strClassName = strEntryMethod.Substring(0, idx); Type type = m_ModAssembly.GetType(strClassName); if (null == type) { throw new NullReferenceException("Failed to find entry Type in mod assembly"); } MethodInfo methodInfo = type.GetMethod(strMethodName); if (null == methodInfo) { throw new NullReferenceException("Failed to find entry Method in mod assembly"); } ModEntry modEntry = ModEntry.GetModEntry(data, m_ModAssembly.Location); object[] param = new object[] { modEntry }; methodInfo.Invoke(null, param); } catch (Exception exc) { VortexPatcher.Logger.Error("Failed to invoke starter method", exc); return; } }
public static ModEntry GetModEntry(UMMData data, string strModPath) { return(new ModEntry(data, strModPath)); }
public ModEntry(UMMData data, string strModPath) { m_ModData = data; m_strModPath = strModPath; }