public void InjectPatches() { try { if (null == m_ModData) { throw new ArgumentNullException("Mod data is not available"); } VortexModData data = (m_ModData as VortexModData); if (null == data) { throw new InvalidDataException("Invalid Vortex mod data"); } string[] entryPoint = data.EntryPoint.Split(new string[] { "::" }, StringSplitOptions.None); if (entryPoint.Length != 2) { throw new InvalidDataException(string.Format("Invalid EntryPoint", entryPoint.Length)); } Type type = m_ModAssembly.GetType(entryPoint[0]); if (null == type) { throw new NullReferenceException("Failed to find entry Type in mod assembly"); } MethodInfo methodInfo = type.GetMethod(entryPoint[1]); if (null == methodInfo) { throw new NullReferenceException("Failed to find entry Method in mod assembly"); } bool hasVortexParam = methodInfo.GetParameters().SingleOrDefault() != null; if (hasVortexParam) { VortexMod mod = VortexMod.GetModEntry(data, "D:\\Games\\UntitledGooseGame\\Untitled_Data\\Managed"); object[] param = new object[] { mod }; try { methodInfo.Invoke(null, param); } catch (Exception exc) { VortexPatcher.Logger.Error("Failed to invoke starter method", exc); } } else { methodInfo.Invoke(null, null); } } catch (Exception exc) { VortexPatcher.Logger.Error("Failed to invoke starter method", exc); return; } }
public static void Save <T>(T data, VortexMod mod) where T : VortexModSettings { try { string strSettingsPath = data.GetSettingsPath(mod); string strSerializedSettings = JsonConvert.SerializeObject(data); File.WriteAllText(strSettingsPath, strSerializedSettings); } catch (Exception exc) { VortexPatcher.Logger.Error("Failed to save mod settings", exc); } }
public static T Load <T>(VortexMod mod) where T : VortexModSettings, new() { T t = new T(); string strSettingsPath = t.GetSettingsPath(mod); if (File.Exists(strSettingsPath)) { try { string fileContents = File.ReadAllText(strSettingsPath); T deserialized = JsonConvert.DeserializeObject <T>(fileContents); return(deserialized); } catch (Exception e) { LoggerDelegates.LogError($"Can't read {strSettingsPath}.", e); } } return(t); }
public virtual void Save(IExposedMod mod) { VortexMod vortexMod = mod as VortexMod; Save(this, vortexMod); }
public virtual string GetSettingsPath(IExposedMod mod) { VortexMod modEntry = mod as VortexMod; return(Path.Combine(modEntry.VortexData.ModPath, Constants.VORTEX_SETTINGS_FILE)); }