예제 #1
0
        async public Task <Dictionary <string, object> > IsPatchApplicable(JObject data,
                                                                           CoreDelegates coreDelegates)
        {
            string      message;
            bool        result   = false;
            PatchConfig config   = new PatchConfig((JObject)data ["patchConfig"]);
            string      dataPath = await coreDelegates.context.GetDataPath();

            try {
                if (IsReflectionEnabled(dataPath))
                {
                    // Reflection already enabled - no need to do anything.
                    message = "Reflection is enabled";
                    result  = false;
                }
                else
                {
                    message = "Can be applied";
                    result  = true;
                }
            } catch (Exception exc) {
                result  = false;
                message = exc.Message;
            }
            var addendum = new Dictionary <string, object> ()
            {
                { "Source", config.SourceEntryPoint.ToString() },
                { "Targets", config.TargetEntryPoints.ToString() }
            };

            return(PatchHelper.CreatePatchResult(result, message, addendum));
        }
예제 #2
0
 private async Task<Dictionary<string, object>> DeployVIGO (CoreDelegates core)
 {
     bool deployedBundle = false;
     string message = "Failed to deploy VIGO";
     try {
         string extensionPath = await core.context.GetExtensionPath ();
         string modLoaderPath = await core.context.GetModLoaderPath ();
         string [] uiFiles = new string [] {
         Path.Combine(extensionPath, Constants.UI_BUNDLE_FILENAME),
         Path.Combine(extensionPath, Constants.UI_BUNDLE_FILENAME + ".manifest"),
     };
         try {
             string bundledAssetsDest = Path.Combine (modLoaderPath, "VortexBundles", "UI");
             Directory.CreateDirectory (bundledAssetsDest);
             foreach (string file in uiFiles) {
                 string strDest = Path.Combine (bundledAssetsDest, Path.GetFileName (file));
                 File.Copy (file, strDest, true);
                 deployedBundle = true;
                 message = "VIGO deployed successfully";
             }
         } catch (Exception e) {
             // This is fine, some extensions might not provide bundled UI assets.
             //  all this means is that the in-game UI will not look that great.
             message = e.Message;
         }
     } catch (Exception e) {
         message = e.Message;
     }
     
     return PatchHelper.CreatePatchResult (deployedBundle, message);
 }
예제 #3
0
        /// <summary>
        /// Certain games distribute modified assemblies which disable
        ///  reflection and impede modding.
        /// </summary>
        private async Task <Dictionary <string, object> > EnableReflection(string dataPath, string modLoaderPath)
        {
            bool   result   = false;
            string message  = "Unhandled mscorlib version";
            string mscorlib = Path.Combine(dataPath, Constants.MSCORLIB);

            try {
                mscorlib = (Util.IsSymlink(mscorlib))
                    ? Path.Combine(dataPath, Constants.MSCORLIB + VortexInjectorIPC.Constants.VORTEX_BACKUP_TAG)
                    : Path.Combine(dataPath, Constants.MSCORLIB);
            } catch (Exception) {
                mscorlib = Path.Combine(dataPath, Constants.MSCORLIB + VortexInjectorIPC.Constants.VORTEX_BACKUP_TAG);
            }

            FileVersionInfo fvi     = FileVersionInfo.GetVersionInfo(mscorlib);
            string          version = fvi.FileVersion;
            string          strLib  = LIB_REPLACEMENTS
                                      .Where(replacement => replacement.Substring(Constants.MSCORLIB.Length + 1, 1) == version.Substring(0, 1))
                                      .SingleOrDefault();

            if (null != strLib)
            {
                try {
                    WebClient wc  = new WebClient();
                    Uri       uri = new Uri(Constants.GITHUB_LINK + strLib);
                    string    downloadDestination = (dataPath == modLoaderPath)
                        ? Path.Combine(dataPath, strLib)
                        : Path.Combine(modLoaderPath, Constants.MSCORLIB);
                    byte[] downloaded = await wc.DownloadDataTaskAsync(uri);

                    File.WriteAllBytes(downloadDestination, downloaded);
                    if (dataPath == modLoaderPath)
                    {
                        Util.ReplaceFile(mscorlib, downloadDestination);
                    }
                    result  = true;
                    message = "Reflection enabled";
                } catch (Exception exc) {
                    result  = false;
                    message = exc.Message;
                }
            }

            return(PatchHelper.CreatePatchResult(result, message));
        }
예제 #4
0
        /// <summary>
        /// Creates the folder structure inside the game's
        ///  folder.
        /// </summary>
        private async Task <Dictionary <string, object> > DeployFiles(CoreDelegates core)
        {
            bool   result  = true;
            string message = "VML dependencies deployed";

            try {
                string dataPath = await core.context.GetDataPath();

                if (!Directory.Exists(dataPath))
                {
                    throw new DirectoryNotFoundException(string.Format("Datapath {0} does not exist", dataPath));
                }

                string libPath = await core.context.GetVMLDepsPath();

                string modsPath = await core.context.GetModsPath();

                string modLoaderPath = await core.context.GetModLoaderPath();

                Directory.CreateDirectory(modsPath);
                string [] files = Directory.GetFiles(libPath, "*", SearchOption.TopDirectoryOnly)
                                  .Where(file => _LIB_FILES.Contains(Path.GetFileName(file)))
                                  .ToArray();

                foreach (string file in files)
                {
                    string dataPathDest      = Path.Combine(dataPath, Path.GetFileName(file));
                    string modLoaderPathDest = Path.Combine(modLoaderPath, Path.GetFileName(file));

                    if (!File.Exists(dataPathDest) || !File.Exists(modLoaderPathDest))
                    {
                        File.Copy(file, modLoaderPathDest);
                    }
                }
            } catch (Exception exc) {
                result  = false;
                message = exc.Message;
            }

            return(PatchHelper.CreatePatchResult(result, message));
        }