private static XElement CloneTo(string testFile, NetFramework targetFrameworkVersion)
        {
            FileInfo testFileInfo = testFile.GetTestFileInfo();
            var      synchronizer = new VSProjectCloner(testFileInfo);

            return(XElement.Parse(File.ReadAllText(synchronizer.CloneTo(targetFrameworkVersion).FullName)));
        }
        private static ProjectModel MapProject(Project p)
        {
            var projectModel = new ProjectModel
            {
                Name       = p.Name,
                DteProject = p,
            };

            if (p.Properties != null)
            {
                try
                {
                    var frameworkModel = new NetFramework
                    {
                        Id   = (uint)p.Properties.Item("TargetFramework").Value,
                        Name = (string)p.Properties.Item("TargetFrameworkMoniker").Value
                    };
                    projectModel.NetFrameworkInUse = frameworkModel;
                }
                catch (ArgumentException e) //possible when project still loading
                {
                    Debug.WriteLine("ArgumentException on " + projectModel + e);
                }
                catch (InvalidCastException e) //for some projects with wrong types
                {
                    Debug.WriteLine("InvalidCastException on " + projectModel + e);
                }
            }
            return(projectModel);
        }
Пример #3
0
        public void Inject(int aProcessId, NetFramework aFrameworkVersion, IntPtr aMonoModule)
        {
            _readerTask = new Task(async() => await NamedPipeReader());
            _readerTask.Start();

            var handle = Native.OpenProcess(ProcessAccessRights.PROCESS_ALL_ACCESS, false, aProcessId);

            if (handle == IntPtr.Zero)
            {
                _log.Error("Failed to open process");
                return;
            }

            byte[] file;

            try
            {
                if (aFrameworkVersion == NetFramework.NET45)
                {
                    file = File.ReadAllBytes("./GHRUnityVRModNet45.dll");
                }
                else if (aFrameworkVersion == NetFramework.NET35)
                {
                    file = File.ReadAllBytes("./GHRUnityVRModNet35.dll");
                }
                else
                {
                    throw new ArgumentException($"Passed unusable framework version {aFrameworkVersion} to Inject");
                }
            }
            catch (IOException)
            {
                _log.Error($"Failed to read the mod file");
                return;
            }

            _isExecuting = true;
            _log.Info($"Injecting");

            using (Injector injector = new Injector(handle, aMonoModule))
            {
                try
                {
                    IntPtr asm = injector.Inject(file, "GHRUnityVRMod", "GHRUnityVRModFuncs", "Load");
                    _log.Info("Injection successful");
                }
                catch (InjectorException ie)
                {
                    _log.Error("Injection failed: " + ie.Message);
                }
                catch (Exception e)
                {
                    _log.Error("Injection failed (unknown error): " + e.Message);
                }
            }

            _isExecuting = false;
        }
Пример #4
0
 static int BrokenConnect(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 0);
         NetFramework.BrokenConnect();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #5
0
 static int onData(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 0);
         NetFramework.onData();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #6
0
 static int read(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         byte[] arg0 = ToLua.CheckByteBuffer(L, 1);
         NetFramework.read(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #7
0
 static int SendMessage(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         ByteArray arg0 = (ByteArray)ToLua.CheckObject <ByteArray>(L, 1);
         NetFramework.SendMessage(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #8
0
 static int SendCmdMessage(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         int    arg0 = (int)LuaDLL.luaL_checknumber(L, 1);
         byte[] arg1 = ToLua.CheckByteBuffer(L, 2);
         NetFramework.SendCmdMessage(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #9
0
 static int DecodeBuffer(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         byte[] arg0 = ToLua.CheckByteBuffer(L, 1);
         byte[] o    = NetFramework.DecodeBuffer(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #10
0
 static int Connect(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         string arg0 = ToLua.CheckString(L, 1);
         int    arg1 = (int)LuaDLL.luaL_checknumber(L, 2);
         NetFramework.Connect(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #11
0
 static int writer(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         int       arg0 = (int)LuaDLL.luaL_checknumber(L, 1);
         byte[]    arg1 = ToLua.CheckByteBuffer(L, 2);
         ByteArray o    = NetFramework.writer(arg0, arg1);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #12
0
 static int decode(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         System.Collections.Generic.List <byte> arg0 = (System.Collections.Generic.List <byte>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <byte>));
         byte[] o = NetFramework.decode(ref arg0);
         ToLua.Push(L, o);
         ToLua.PushSealed(L, arg0);
         return(2);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #13
0
        public FileInfo CloneTo(NetFramework targetFrameworkVersion)
        {
            ProjectFile cloned           = Clone(targetFrameworkVersion.MsbuildTag);
            string      projectName      = Path.GetFileNameWithoutExtension(_projectFileInfo.Name);
            string      targetFolderName = projectName + "." + targetFrameworkVersion.NugetFolder;
            string      targetFolder     = Path.Combine(_projectFileInfo.DirectoryName, "..", targetFolderName);

            if (!Directory.Exists(targetFolder))
            {
                Directory.CreateDirectory(targetFolder);
            }
            string clonedProjectFile = Path.Combine(targetFolder, projectName + Path.GetExtension(_projectFileInfo.Name));

            File.WriteAllText(clonedProjectFile, cloned.ToString());
            Trace.TraceInformation($"project file generated: {clonedProjectFile}");
            return(new FileInfo(clonedProjectFile));
        }
        protected static bool GetNetFrameworkVersion(string aProcessPath, out NetFramework frameworkVersion)
        {
            // If someone is asking us this, we can assume they've already checked they can use this mod.
            // We'll also assume it's Unity, and that there's an Assembly-CSharp.dll file somewhere in the tree below the process file.
            Path.GetDirectoryName(aProcessPath);
            var assemblyFiles = Directory.GetFiles(Path.GetDirectoryName(aProcessPath), "*Assembly-CSharp.dll",
                                                   SearchOption.AllDirectories);

            if (assemblyFiles.Length == 0)
            {
                // See if there's a netstandard DLL. Newer Unity games can compile against either Mono or .Net Standard, and if it's .Net
                // Standard we're fine going with the NET45 mod. This is a horrible hack, but really, what isn't in this program.
                if (Directory.GetFiles(Path.GetDirectoryName(aProcessPath), "*netstandard.dll", SearchOption.AllDirectories).Length > 0)
                {
                    frameworkVersion = NetFramework.NET45;
                    return(true);
                }
                frameworkVersion = NetFramework.UNKNOWN;
                return(false);
            }

            // There are instances where we may have multiple Assembly-CSharp files in a tree. This is usually because some other
            // plugin architecture is already there, and has made backups of the originals. We can assume they'll all be the same
            // CLR version, and that's really all we care about, so just load the first one we find.
            //
            // Also, use a ReflectionOnly load on this. We don't want to try to bring the functions into our own process space,
            // we just want to query the CLR version.
            //
            // Finally, ImageRuntimeVersion is NOT a .Net Framework version. It's a CLR version, so it'll either be v2 or v4. We
            // can basically assume that if we see v2 here, we're actually talking .Net Framework 3.5. See comment in NetFramework
            // enum. Which I guess should actually be called NetCLR, but f**k it, whatever.
            var netVersion = Assembly.ReflectionOnlyLoadFrom(assemblyFiles[0]).ImageRuntimeVersion;

            if (netVersion.Contains("v4"))
            {
                frameworkVersion = NetFramework.NET45;
                return(true);
            }
            if (netVersion.Contains("v2"))
            {
                frameworkVersion = NetFramework.NET35;
                return(true);
            }
            frameworkVersion = NetFramework.UNKNOWN;
            return(false);
        }
Пример #15
0
    static int _CreateNetFramework(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                NetFramework obj = new NetFramework();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: NetFramework.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #16
0
        public static bool CanUseMod(IntPtr handle, string processPath, out IntPtr module, out NetFramework frameworkVersion)
        {
            frameworkVersion = NetFramework.UNKNOWN;
            try
            {
                if (!ProcessUtils.GetMonoModule(handle, out module))
                {
                    return(false);
                }

                if (!GetNetFrameworkVersion(processPath, out frameworkVersion))
                {
                    return(false);
                }

                return(true);
            }
            catch (InjectorException ex)
            {
                // Noop and just return false.
                LogManager.GetCurrentClassLogger().Error(ex);
            }

            module = IntPtr.Zero;
            return(false);
        }
Пример #17
0
 /// <summary>
 /// Packages with target framework
 /// </summary>
 /// <param name="feedQuery"></param>
 /// <param name="netFramework"></param>
 /// <param name="version"></param>
 /// <returns></returns>
 public static IQueryable <NuGetPackage> ForFramework(this IQueryable <NuGetPackage> feedQuery, NetFramework netFramework, string version)
 => ForFramework(feedQuery, netFramework, new Version(version));
Пример #18
0
 public CSChatSettingMsg(NetFramework.Auto.ChatSettingInfo chatSetting) : this() {
   this.ChatSetting = chatSetting;
 }
Пример #19
0
 public CSLoginMsg(NetFramework.Auto.Terminal terminal, NetFramework.Auto.OSType osType, string osVersion, string deviceModel) : this() {
   this.Terminal = terminal;
   this.OsType = osType;
   this.OsVersion = osVersion;
   this.DeviceModel = deviceModel;
 }
Пример #20
0
 public SCChatMsg(NetFramework.Auto.ChatChannel chatChannel, NetFramework.Auto.SendChatCharInfo sendCharCharInfo, string content) : this() {
   this.ChatChannel = chatChannel;
   this.SendCharCharInfo = sendCharCharInfo;
   this.Content = content;
 }
Пример #21
0
 public CSChatMsg(NetFramework.Auto.ChatChannel chatChannel) : this() {
   this.ChatChannel = chatChannel;
 }
Пример #22
0
 /// <summary>
 /// Packages with target framework
 /// </summary>
 /// <param name="feedQuery"></param>
 /// <param name="netFramework"></param>
 /// <param name="majorVersion"></param>
 /// <param name="minorVersion"></param>
 /// <param name="buildVersion"></param>
 /// <returns></returns>
 public static IQueryable <NuGetPackage> ForFramework(this IQueryable <NuGetPackage> feedQuery, NetFramework netFramework, int majorVersion, int minorVersion, int buildVersion)
 => ForFramework(feedQuery, netFramework, new Version(majorVersion, minorVersion, buildVersion));
Пример #23
0
        /// <summary>
        /// Packages with target framework
        /// </summary>
        /// <param name="feedQuery"></param>
        /// <param name="netFramework"></param>
        /// <param name="version"></param>
        /// <returns></returns>
        public static IQueryable <NuGetPackage> ForFramework(this IQueryable <NuGetPackage> feedQuery, NetFramework netFramework, Version version)
        {
            var framework = new FrameworkName($".{netFramework.ToString().ToLowerInvariant()}", version);

            return(feedQuery.Where(x => x.Filter.SupportedFrameworks.Contains(framework)));
        }
Пример #24
0
 public SCSystemInfoMsg(NetFramework.Auto.SystemInfo systemInfo) : this() {
   this.SystemInfo = systemInfo;
 }