-
Notifications
You must be signed in to change notification settings - Fork 16
/
Engine.cs
102 lines (84 loc) · 3.56 KB
/
Engine.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using CEasyUO;
using CUO_API;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Assistant
{
public class Engine
{
public Engine()
{
}
public static ClientVersions ClientVersion { get; private set; }
public static bool UseNewMobileIncoming => ClientVersion >= ClientVersions.CV_70331;
public static bool UsePostHSChanges => ClientVersion >= ClientVersions.CV_7090;
public static bool UsePostSAChanges => ClientVersion >= ClientVersions.CV_7000;
public static bool UsePostKRPackets => ClientVersion >= ClientVersions.CV_6017;
private static string _rootPath = null;
public static string RootPath => _rootPath ?? ( _rootPath = Path.GetDirectoryName( Assembly.GetAssembly( typeof( Engine ) ).Location ) );
public static string UOFilePath { get; internal set; }
public static bool IsInstalled { get; internal set; }
public static CEasyUOMainForm m_MainForm;
public static unsafe void Install( PluginHeader* header )
{
Console.WriteLine( "Install Invoked CEasyUO" );
AppDomain.CurrentDomain.AssemblyResolve += ( sender, e ) =>
{
string[] fields = e.Name.Split( ',' );
string name = fields[0];
string culture = fields[2];
if ( name.EndsWith( ".resources" ) && !culture.EndsWith( "neutral" ) )
{
return null;
}
AssemblyName askedassembly = new AssemblyName( e.Name );
bool isdll = File.Exists( Path.Combine( RootPath, askedassembly.Name + ".dll" ) );
return Assembly.LoadFile( Path.Combine( RootPath, askedassembly.Name + ( isdll ? ".dll" : ".exe" ) ) );
};
try
{
ClientVersion = (ClientVersions)header->ClientVersion;
if ( !ClientCommunication.InstallHooks( header ) )
{
System.Diagnostics.Process.GetCurrentProcess().Kill();
return;
}
UOFilePath = Marshal.GetDelegateForFunctionPointer<OnGetUOFilePath>( header->GetUOFilePath )();
Ultima.Files.SetMulPath( UOFilePath );
Ultima.Multis.PostHSFormat = UsePostHSChanges;
// Thread t = new Thread( () =>
// {
//Thread.CurrentThread.Name = "EasyUO Main Thread";
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
m_MainForm= new CEasyUOMainForm() ;
m_MainForm.Show();
// } );
// t.SetApartmentState( ApartmentState.STA );
PacketHandlers.Initialize();
// Targeting.Initialize();
Spell.Initialize(); EUOVars.Initialize();
// t.IsBackground = true;
// t.Start();
IsInstalled = true;
}
catch (Exception e)
{
Debugger.Break();
Console.WriteLine( e.Message );
}
}
internal static void LogCrash( Exception e )
{
}
}
}