-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
65 lines (60 loc) · 2.26 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using RTCV.Common;
namespace NetStub
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Make sure we resolve our dlls
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
Initialize();
}
private static void Initialize()
{
var frm = new StubForm();
S.SET(frm);
Application.Run(frm);
}
//Lifted from Bizhawk
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
try
{
string requested = args.Name;
lock (AppDomain.CurrentDomain)
{
var asms = AppDomain.CurrentDomain.GetAssemblies();
foreach (var asm in asms)
if (asm.FullName == requested)
return asm;
//load missing assemblies by trying to find them in the dll directory
string dllname = new AssemblyName(requested).Name + ".dll";
string directory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "RTCV");
string simpleName = new AssemblyName(requested).Name;
string fname = Path.Combine(directory, dllname);
if (!File.Exists(fname)) return null;
//it is important that we use LoadFile here and not load from a byte array; otherwise mixed (managed/unamanged) assemblies can't load
return Assembly.UnsafeLoadFrom(fname);
}
}
catch (Exception e)
{
MessageBox.Show("Something went really wrong in AssemblyResolve. Send this to the devs\n" + e);
return null;
}
}
}
}