Exemplo n.º 1
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));
        }
Exemplo n.º 2
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));
        }