-
Notifications
You must be signed in to change notification settings - Fork 96
/
SCANmechjebMainMenu.cs
83 lines (63 loc) · 2.23 KB
/
SCANmechjebMainMenu.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
#region license
/*
* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* SCANmechjebMainMenu - A monobehaviour that checks the status of SCANsat and MechJeb at startup
*
* Copyright (c)2014 David Grandy <david.grandy@gmail.com>;
* Copyright (c)2014 technogeeky <technogeeky@gmail.com>;
* Copyright (c)2014 (Your Name Here) <your email here>; see LICENSE.txt for licensing details.
*/
#endregion
using System;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace SCANmechjeb
{
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class SCANmechjebMainMenu : MonoBehaviour
{
private const string SCANsatName = "SCANsat";
private const string MechJeb = "MechJeb2";
private readonly Version MechJebVersion = new Version(2, 5, 1, 0);
private static bool loaded = false;
private void Awake()
{
loaded = checkLoaded();
print(loaded ? "[SCANsatMechJeb] SCANsat and MechJeb Assemblies Detected" : "[SCANsatMechJeb] SCANsat or MechJeb Assembly Not Detected; Shutting Down...");
Destroy(gameObject);
}
public static bool Loaded
{
get { return loaded; }
}
private bool checkLoaded()
{
var SCANassembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name == SCANsatName);
if (SCANassembly == null)
return false;
var infoV = Attribute.GetCustomAttribute(SCANassembly.assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute;
if (infoV == null)
return false;
var SCANmechjebAssembly = Assembly.GetExecutingAssembly();
if (SCANmechjebAssembly == null)
return false;
var SMinfoV = Attribute.GetCustomAttribute(SCANmechjebAssembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute;
if (SMinfoV == null)
return false;
if (infoV.InformationalVersion != SMinfoV.InformationalVersion)
return false;
var MechJebAssembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name == MechJeb);
if (MechJebAssembly == null)
return false;
if (MechJebAssembly.assembly.GetName().Version == MechJebVersion)
{
SCANsat.SCANmainMenuLoader.MechJebLoaded = true;
return true;
}
return false;
}
}
}