-
Notifications
You must be signed in to change notification settings - Fork 96
/
SCANreflection.cs
210 lines (165 loc) · 6.25 KB
/
SCANreflection.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#region license
/*
* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* SCANreflection - assigns reflection methods 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.Reflection;
using FinePrint;
using FinePrint.Contracts.Parameters;
using FinePrint.Utilities;
using UnityEngine;
namespace SCANsat
{
static class SCANreflection
{
//private const string KOPERNICUSASSEMBLY = "Kopernicus.OnDemand.ScaledSpaceOnDemand";
public const string KOPERNICUSONDEMANDTYPE = "ScaledSpaceOnDemand";
private const string KOPERNICUSONDEMANDLOAD = "LoadTextures";
private const string KOPERNICUSONDEMANDUNLOAD = "UnloadTextures";
private static bool FinePrintFlightBandRun = false;
private static bool FinePrintStationaryWaypointRun = false;
private static FieldInfo _FinePrintFlightBand;
private static FieldInfo _FinePrintStationaryWaypoint;
//private static Type _scaledSpaceOnDemand;
//private static MethodInfo _scaledSpaceOnDemandLoad;
//private static MethodInfo _scaledSpaceOnDemandUnload;
internal static void LoadOnDemand(MonoBehaviour scaledSpaceOnDemand)
{
//if (_scaledSpaceOnDemandLoad == null)
// return;
scaledSpaceOnDemand.GetType().InvokeMember(KOPERNICUSONDEMANDLOAD
, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreReturn | BindingFlags.InvokeMethod, null, scaledSpaceOnDemand, null);
//_scaledSpaceOnDemandLoad.Invoke(scaledSpaceOnDemand, null);
}
internal static void UnloadOnDemand(MonoBehaviour scaledSpaceOnDemand)
{
//if (_scaledSpaceOnDemandUnload == null)
// return;
scaledSpaceOnDemand.GetType().InvokeMember(KOPERNICUSONDEMANDUNLOAD
, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreReturn | BindingFlags.InvokeMethod, null, scaledSpaceOnDemand, null);
//_scaledSpaceOnDemandUnload.Invoke(scaledSpaceOnDemand, null);
}
//internal static void LoadKopernicusReflection()
//{
// //try
// //{
// // AssemblyLoader.loadedAssemblies.TypeOperation(t =>
// // {
// // if (t.FullName == KOPERNICUSASSEMBLY)
// // {
// // _scaledSpaceOnDemand = t;
// // }
// // });
// // if (_scaledSpaceOnDemand == null)
// // {
// // SCANUtil.SCANlog("Error in detecting Kopernicus On Demand Scaled Space Loader Type");
// // return;
// // }
// // _scaledSpaceOnDemandLoad = _scaledSpaceOnDemand.GetMethod(KOPERNICUSONDEMANDLOAD, BindingFlags.Instance | BindingFlags.Public);
// // if (_scaledSpaceOnDemandLoad == null)
// // {
// // SCANUtil.SCANlog("Error in detecting Kopernicus On Demand Scaled Space Loader Method");
// // return;
// // }
// // SCANUtil.SCANlog("Kopernicus On Demand Scaled Space Loader Method Assigned");
// // _scaledSpaceOnDemandUnload = _scaledSpaceOnDemand.GetMethod(KOPERNICUSONDEMANDUNLOAD, BindingFlags.Instance | BindingFlags.Public);
// // if (_scaledSpaceOnDemandUnload == null)
// // {
// // SCANUtil.SCANlog("Error in detecting Kopernicus On Demand Scaled Space Unloader Method");
// // return;
// // }
// // SCANUtil.SCANlog("Kopernicus On Demand Scaled Space Unloader Method Assigned");
// //}
// //catch (Exception e)
// //{
// // SCANUtil.SCANlog("Error Kopernicus On Demand Scaled Space Reflection Methods: {0}", e);
// //}
//}
internal static Waypoint FinePrintStationaryWaypointObject(StationaryPointParameter p)
{
Waypoint w = null;
try
{
w = (Waypoint)_FinePrintStationaryWaypoint.GetValue(p);
}
catch (Exception e)
{
SCANUtil.SCANlog("Error in detecting FinePrint Stationary Waypoint object: {0}", e);
}
return w;
}
internal static FlightBand FinePrintFlightBandValue(SurveyWaypointParameter p)
{
FlightBand b = FlightBand.NONE;
try
{
b = (FlightBand)_FinePrintFlightBand.GetValue(p);
}
catch (Exception e)
{
SCANUtil.SCANlog("Error in detecting FinePrint FlightBand object: {0}", e);
}
return b;
}
internal static bool FinePrintStationaryWaypointReflection()
{
if (_FinePrintStationaryWaypoint != null)
return true;
if (FinePrintStationaryWaypointRun)
return false;
FinePrintStationaryWaypointRun = true;
try
{
Type sType = typeof(StationaryPointParameter);
var field = sType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
_FinePrintStationaryWaypoint = field[0];
if (_FinePrintStationaryWaypoint == null)
{
SCANUtil.SCANlog("FinePrint Stationary Waypoint Field Not Found");
return false;
}
SCANUtil.SCANlog("FinePrint Stationary Waypoint Field Assigned");
return _FinePrintStationaryWaypoint != null;
}
catch (Exception e)
{
SCANUtil.SCANlog("Error in assigning FinePrint Stationary Waypoint method: {0}", e);
}
return false;
}
internal static bool FinePrintFlightBandReflection()
{
if (_FinePrintFlightBand != null)
return true;
if (FinePrintFlightBandRun)
return false;
FinePrintFlightBandRun = true;
try
{
Type sType = typeof(SurveyWaypointParameter);
var field = sType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
_FinePrintFlightBand = field[2];
if (_FinePrintFlightBand == null)
{
SCANUtil.SCANlog("FinePrint FlightBand Field Not Found");
return false;
}
SCANUtil.SCANlog("FinePrint FlightBand Field Assigned");
return _FinePrintFlightBand != null;
}
catch (Exception e)
{
SCANUtil.SCANlog("Error in assigning FinePrint FlightBand method: {0}", e);
}
return false;
}
}
}