-
Notifications
You must be signed in to change notification settings - Fork 127
/
YgoMasterBepInEx.cs
74 lines (72 loc) · 2.63 KB
/
YgoMasterBepInEx.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
66
67
68
69
70
71
72
73
74
using System;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;
using System.IO;
namespace YgoMasterBepInEx
{
[BepInPlugin("YgoMasterBepInEx", "YgoMasterBepInEx", "1.0.0")]
public class YgoMasterBepInExPlugin : BasePlugin
{
public override void Load()
{
// TODO: Support "live"
string targetDir = null;
string[] args = Environment.GetCommandLineArgs();
if (args != null)
{
string targetArg = "--YgoMasterDir=";
foreach (string arg in args)
{
if (arg.StartsWith(targetArg))
{
try
{
DirectoryInfo dirInfo = new DirectoryInfo(arg.Substring(targetArg.Length).Trim('\"'));
if (!dirInfo.Exists)
{
return;
}
targetDir = dirInfo.Name;
Console.WriteLine("YgoMasterDir: '" + targetDir + "'");
}
catch
{
}
}
}
}
if (string.IsNullOrEmpty(targetDir))
{
return;
}
string ygoMasterLoaderFile = Path.Combine(targetDir, "YgoMasterLoader.dll");
string ygoMasterClientFile = Path.Combine(targetDir, "YgoMasterClient.exe");
if (!File.Exists(ygoMasterLoaderFile))
{
Console.WriteLine("Failed to find '" + ygoMasterLoaderFile + "'");
return;
}
if (!File.Exists(ygoMasterClientFile))
{
Console.WriteLine("Failed to find '" + ygoMasterClientFile + "'");
return;
}
Console.WriteLine("Loading YgoMasterLoader.dll");
IntPtr handle = LoadLibrary(ygoMasterLoaderFile);
Console.WriteLine("YgoMasterLoader handle: " + handle);
if (handle == IntPtr.Zero)
{
return;
}
Assembly assembly = Assembly.LoadFile(Path.GetFullPath(ygoMasterClientFile));
string dllMainArg = null;//"live";
assembly.GetType("YgoMasterClient.Program").GetMethod("DllMain").Invoke(null, new object[] { dllMainArg });
}
[DllImport("kernel32")]
static extern IntPtr LoadLibrary(string lpFileName);
}
}