summaryrefslogtreecommitdiffhomepage
path: root/X-Plane-SDK/Delphi/XPLM/XPLMPlugin.pas
blob: f053f803da18bf7d5b62f79303a9eb0cb8f1e9dc (plain)
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
{
   Copyright 2005-2012 Sandy Barbour and Ben Supnik
   
   All rights reserved.  See license.txt for usage.
   
   X-Plane SDK Version: 2.1.1                                                  
}

UNIT XPLMPlugin;
INTERFACE
{
   These APIs provide facilities to find and work with other plugins and 
   manage other plugins.                                                       
}

USES   XPLMDefs;
   {$A4}
{$IFDEF MSWINDOWS}
   {$DEFINE DELPHI}
{$ENDIF}
{___________________________________________________________________________
 * FINDING PLUGINS
 ___________________________________________________________________________}
{
   These APIs allow you to find another plugin or yourself, or iterate across 
   all plugins.  For example, if you wrote an FMS plugin that needed to talk 
   to an autopilot plugin, you could use these APIs to locate the autopilot 
   plugin.                                                                     
}



   {
    XPLMGetMyID
    
    This routine returns the plugin ID of the calling plug-in.  Call this to 
    get your own ID.                                                            
   }
   FUNCTION XPLMGetMyID: XPLMPluginID;
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMCountPlugins
    
    This routine returns the total number of plug-ins that are loaded, both 
    disabled and enabled.                                                       
   }
   FUNCTION XPLMCountPlugins: integer;
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMGetNthPlugin
    
    This routine returns the ID of a plug-in by index.  Index is 0 based from 0 
    to XPLMCountPlugins-1, inclusive. Plugins may be returned in any arbitrary 
    order.                                                                      
   }
   FUNCTION XPLMGetNthPlugin(
                                        inIndex             : integer) : XPLMPluginID;    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMFindPluginByPath
    
    This routine returns the plug-in ID of the plug-in whose file exists at the 
    passed in absolute file system path.  XPLM_NO_PLUGIN_ID is returned if the 
    path does not point to a currently loaded plug-in.                          
   }
   FUNCTION XPLMFindPluginByPath(
                                        inPath              : Pchar) : XPLMPluginID;    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMFindPluginBySignature
    
    This routine returns the plug-in ID of the plug-in whose signature matches 
    what is passed in or XPLM_NO_PLUGIN_ID if no running plug-in has this 
    signature.  Signatures are the best way to identify another plug-in as they 
    are independent of the file system path of a plug-in or the human-readable 
    plug-in name, and should be unique for all plug-ins.  Use this routine to 
    locate another plugin that your plugin interoperates with                   
   }
   FUNCTION XPLMFindPluginBySignature(
                                        inSignature         : Pchar) : XPLMPluginID;    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMGetPluginInfo
    
    This routine returns information about a plug-in.  Each parameter should be 
    a pointer to a buffer of at least 256 characters, or NULL to not receive 
    the information. 
    
    outName - the human-readable name of the plug-in.   outFilePath - the 
    absolute file path to the file that contains this plug-in. outSignature - a 
    unique string that identifies this plug-in. outDescription - a 
    human-readable description of this plug-in.                                 
   }
   PROCEDURE XPLMGetPluginInfo(
                                        inPlugin            : XPLMPluginID;    
                                        outName             : Pchar;    { Can be nil }
                                        outFilePath         : Pchar;    { Can be nil }
                                        outSignature        : Pchar;    { Can be nil }
                                        outDescription      : Pchar);    { Can be nil }
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

{___________________________________________________________________________
 * ENABLING/DISABLING PLUG-INS
 ___________________________________________________________________________}
{
   These routines are used to work with plug-ins and manage them.  Most 
   plugins will not need to use these APIs.                                    
}



   {
    XPLMIsPluginEnabled
    
    Returns whether the specified plug-in is enabled for running.               
   }
   FUNCTION XPLMIsPluginEnabled(
                                        inPluginID          : XPLMPluginID) : integer;    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMEnablePlugin
    
    This routine enables a plug-in if it is not already enabled.  It returns 1 
    if the plugin was enabled or successfully enables itself, 0 if it does not. 
    Plugins may fail to enable (for example, if resources cannot be acquired) 
    by returning 0 from their XPluginEnable callback.                           
   }
   FUNCTION XPLMEnablePlugin(
                                        inPluginID          : XPLMPluginID) : integer;    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMDisablePlugin
    
    This routine disableds an enabled plug-in.                                  
   }
   PROCEDURE XPLMDisablePlugin(
                                        inPluginID          : XPLMPluginID);    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMReloadPlugins
    
    This routine reloads all plug-ins.  Once this routine is called and you 
    return from the callback you were within (e.g. a menu select callback) you 
    will receive your XPluginDisable and XPluginStop callbacks and your  DLL 
    will be unloaded, then the start process happens as if the sim was starting 
    up.                                                                         
   }
   PROCEDURE XPLMReloadPlugins;
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

{___________________________________________________________________________
 * INTERPLUGIN MESSAGING
 ___________________________________________________________________________}
{
   Plugin messages are defined as 32-bit integers.  Messages below 0x00FFFFFF 
   are reserved for X-Plane and the plugin SDK.   
   
   Messages have two conceptual uses: notifications and commands.  Commands 
   are  sent from one plugin to another to induce behavior; notifications are 
   sent  from one plugin to all others for informational purposes.  It is 
   important that commands and notifications not have the same values because 
   this could cause a notification sent by one plugin to accidentally induce a 
   command in another. 
   
   By convention, plugin-defined notifications should have the high bit set  
   (e.g. be greater or equal to unsigned 0x8000000) while commands should have 
   this bit be cleared. 
   
   The following messages are sent to your plugin by x-plane.                  
}



CONST
    { This message is sent to your plugin whenever the user's plane crashes.      }
   XPLM_MSG_PLANE_CRASHED = 101;

    { This message is sent to your plugin whenever a new plane is loaded.  The    }
    { parameter is the number of the plane being loaded; 0 indicates the user's   }
    { plane.                                                                      }
   XPLM_MSG_PLANE_LOADED = 102;

    { This messages is called whenever the user's plane is positioned at a new    }
    { airport.                                                                    }
   XPLM_MSG_AIRPORT_LOADED = 103;

    { This message is sent whenever new scenery is loaded.  Use datarefs to       }
    { determine the new scenery files that were loaded.                           }
   XPLM_MSG_SCENERY_LOADED = 104;

    { This message is sent whenever the user adjusts the number of X-Plane        }
    { aircraft models.  You must use XPLMCountPlanes to find out how many planes  }
    { are now available.  This message will only be sent in XP7 and higher        }
    { because in XP6 the number of aircraft is not user-adjustable.               }
   XPLM_MSG_AIRPLANE_COUNT_CHANGED = 105;

{$IFDEF XPLM200}
    { This message is sent to your plugin whenever a plane is unloaded.  The      }
    { parameter is the number of the plane being unloaded; 0 indicates the user's }
    { plane.  The parameter is of type int, passed as the value of the pointer.   }
    { (That is: the parameter is an int, not a pointer to an int.)                }
   XPLM_MSG_PLANE_UNLOADED = 106;
{$ENDIF}

{$IFDEF XPLM210}
    { This message is sent to your plugin right before X-Plane writes its         }
    { preferences file.  You can use this for two purposes: to write your own     }
    { preferences, and to modify any datarefs to influence preferences output.    }
    { For example, if your plugin temporarily modifies saved preferences, you can }
    { put them back to their default values here to avoid  having the tweaks be   }
    { persisted if your plugin is not loaded on the next invocation of X-Plane.   }
   XPLM_MSG_WILL_WRITE_PREFS = 107;
{$ENDIF}

{$IFDEF XPLM210}
    { This message is sent to your plugin right after a livery is loaded for an   }
    { airplane.  You can use this to check the new livery (via datarefs) and      }
    { react accordingly.  The parameter is of type int, passed as the value of a  }
    { pointer and represents the aicraft plane number - 0 is the user's plane.    }
   XPLM_MSG_LIVERY_LOADED = 108;
{$ENDIF}

   {
    XPLMSendMessageToPlugin
    
    This function sends a message to another plug-in or X-Plane.  Pass 
    XPLM_NO_PLUGIN_ID to broadcast to all plug-ins.  Only enabled plug-ins with 
    a message receive function receive the message.                             
   }
   PROCEDURE XPLMSendMessageToPlugin(
                                        inPlugin            : XPLMPluginID;    
                                        inMessage           : integer;    
                                        inParam             : pointer);    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

{$IFDEF XPLM200}
{___________________________________________________________________________
 * Plugin Features API
 ___________________________________________________________________________}
{
   The plugin features API allows your plugin to "sign up" for additional 
   capabilities and plugin system features that are normally disabled for 
   backward compatibility.  This allows advanced plugins to "opt-in" to new 
   behavior. 
   
   Each feature is defined by a permanent string name.  The feature string 
   names will vary with the particular  installation of X-Plane, so plugins 
   should not expect a feature to be guaranteed present.                       
}




   {
    XPLMFeatureEnumerator_f
    
    You pass an XPLMFeatureEnumerator_f to get a list of all features supported 
    by a given version running version of X-Plane.  This routine is called once 
    for each feature.                                                           
   }
TYPE
     XPLMFeatureEnumerator_f = PROCEDURE(
                                    inFeature           : Pchar;    
                                    inRef               : pointer); cdecl;   

   {
    XPLMHasFeature
    
    This returns 1 if the given installation of X-Plane supports a feature, or 
    0 if it does not.                                                           
   }
   FUNCTION XPLMHasFeature(
                                        inFeature           : Pchar) : integer;    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMIsFeatureEnabled
    
    This returns 1 if a feature is currently enabled for your plugin, or 0 if 
    it is not enabled.  It is an error to call this routine with an unsupported 
    feature.                                                                    
   }
   FUNCTION XPLMIsFeatureEnabled(
                                        inFeature           : Pchar) : integer;    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMEnableFeature
    
    This routine enables or disables a feature for your plugin.  This will 
    change the running behavior of X-Plane and your plugin in some way, 
    depending on the feature.                                                   
   }
   PROCEDURE XPLMEnableFeature(
                                        inFeature           : Pchar;    
                                        inEnable            : integer);    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

   {
    XPLMEnumerateFeatures
    
    This routine calls your enumerator callback once for each feature that this 
    running version of X-Plane supports. Use this routine to determine all of 
    the features that X-Plane can support.                                      
   }
   PROCEDURE XPLMEnumerateFeatures(
                                        inEnumerator        : XPLMFeatureEnumerator_f;    
                                        inRef               : pointer);    
{$IFDEF DELPHI}
                                       cdecl; external 'XPLM.DLL';
{$ELSE}
                                       cdecl; external '';
{$ENDIF}

{$ENDIF}
IMPLEMENTATION
END.