-
Notifications
You must be signed in to change notification settings - Fork 16
/
GameRunnerBase.cs
105 lines (94 loc) · 3.1 KB
/
GameRunnerBase.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
103
104
105
using System.Diagnostics;
using System.IO;
using AutomaticTypeMapper;
using EndlessClient.Initialization;
using EOLib.Config;
using EOLib.Graphics;
using EOLib.Localization;
#if !LINUX
using System.Windows.Forms;
#endif
namespace EndlessClient.GameExecution
{
public abstract class GameRunnerBase : IGameRunner
{
private readonly ITypeRegistry _registry;
private readonly string[] _args;
protected GameRunnerBase(ITypeRegistry registry, string[] args)
{
_registry = registry;
_args = args;
}
public virtual bool SetupDependencies()
{
_registry.RegisterDiscoveredTypes();
var initializers = _registry.ResolveAll<IGameInitializer>();
try
{
foreach (var initializer in initializers)
{
initializer.Initialize();
}
}
catch (ConfigLoadException cle)
{
ShowErrorMessage(cle.Message, "Error loading config file!");
return false;
}
catch (DataFileLoadException dfle)
{
ShowErrorMessage(dfle.Message, "Error loading data files!");
return false;
}
catch (DirectoryNotFoundException dnfe)
{
ShowErrorMessage(dnfe.Message, "Missing required directory");
return false;
}
catch (FileNotFoundException fnfe)
{
ShowErrorMessage(fnfe.Message, "Missing required file");
return false;
}
catch (LibraryLoadException lle)
{
var message =
$"There was an error loading GFX{(int) lle.WhichGFX:000}.EGF : {lle.WhichGFX}. Place all .GFX files in .\\gfx\\. The error message is:\n\n\"{lle.Message}\"";
ShowErrorMessage(message, "GFX Load Error");
return false;
}
for (int i = 0; i < _args.Length; ++i)
{
var arg = _args[i];
if (string.Equals(arg, "--host") && i < _args.Length - 1)
{
var host = _args[i + 1];
_registry.Resolve<IConfigurationRepository>()
.Host = host;
i++;
}
else if(string.Equals(arg, "--clonecompat"))
{
_registry.Resolve<IConfigurationRepository>()
.MainCloneCompat = true;
}
else
{
Debug.WriteLine($"Unrecognized argument: {arg}. Will be ignored.");
}
}
return true;
}
private void ShowErrorMessage(string message, string caption)
{
#if !LINUX
MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
}
public virtual void RunGame()
{
var game = _registry.Resolve<IEndlessGame>();
game.Run();
}
}
}