Commit MetaInfo

Revisionf4a0595dc36f8569ae9372834a67f5ab9d57dbd1 (tree)
Time2009-08-15 01:54:43
AuthorFace
CommiterFace

Log Message

Renamed MFD to PAX.

Change Summary

Incremental Difference

diff -r 3d2c886c31ea -r f4a0595dc36f Orbitersdk/samples/UMMUFB/PAX.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Orbitersdk/samples/UMMUFB/PAX.cpp Fri Aug 14 18:54:43 2009 +0200
@@ -0,0 +1,270 @@
1+#define STRICT
2+#define ORBITER_MODULE
3+#define DOCKSTRUCTOFFSET_CURRENTDOCKOBJECT 0x48
4+#define ADDRESS_GETDOCKSTATUS 0x004217E0
5+#include <stdio.h>
6+#include "orbitersdk.h"
7+#include "UMMUFB.h"
8+
9+// ==============================================================
10+// Global variables
11+
12+int g_MFDmode; // identifier for new MFD mode
13+DWORD g_Hook;
14+OBJHANDLE g_Transfer;
15+byte g_original[10]={0x8b,0x44,0x24,0x04,0x8b,0x40,0x48,0xc2,0x04,0x00};
16+//The following array is:
17+//_asm
18+//{
19+// pop eax;
20+// push ecx;
21+// push eax;
22+// jmp dword ptr [GetDockStatus]; //Dynamically detected address
23+// nop;
24+//}
25+byte g_code[10] = {0x58, 0x51, 0x50, 0xff, 0x25, 0, 0, 0, 0, 0x90};
26+
27+// ==============================================================
28+// API interface
29+
30+void _stdcall GetLandedPad(VESSEL *vessel, OBJHANDLE &base, DWORD &port)
31+{
32+ VESSELSTATUS2 s;
33+ s.version=2;
34+ s.flag=0;
35+ vessel->GetStatusEx(&s);
36+ base=NULL;
37+ port=0;
38+ if (s.status==1 && s.rbody!=NULL)
39+ {
40+ int k=oapiGetBaseCount(s.rbody);
41+ VECTOR3 distance;
42+ OBJHANDLE nearest=NULL;
43+ double nearestDistance=-1;
44+ for(int i=0;i<k;i++)
45+ {
46+ base=oapiGetBaseByIndex(s.rbody, i);
47+ int l=oapiGetBasePadCount(base);
48+ vessel->GetRelativePos(base, distance);
49+ double len=length(distance);
50+ if (nearestDistance<0 || nearestDistance>len)
51+ {
52+ nearestDistance=len;
53+ nearest=base;
54+ }
55+ }
56+ if (nearest!=NULL)
57+ {
58+ k=oapiGetBasePadCount(nearest);
59+ double vlng, vlat, vrad;
60+ vessel->GetEquPos(vlng, vlat, vrad);
61+ for(int i=0;i<k;i++)
62+ {
63+ double lng, lat;
64+ oapiGetBasePadEquPos(nearest, i, &lng, &lat);
65+ lng-=vlng;
66+ lat-=vlat;
67+ if (sqrt(lng*lng+lat*lat)*vrad<50)
68+ {
69+ port=i+1;
70+ break;
71+ }
72+ }
73+ }
74+ if (port>0) base=nearest;
75+ else base=NULL;
76+ }
77+}
78+
79+OBJHANDLE _stdcall GetDockStatus(VESSEL *vessel, DOCKHANDLE dock)
80+{
81+ //Do my own GetDockStatus
82+ if (g_Transfer!=NULL)
83+ {
84+ OBJHANDLE base;
85+ DWORD port;
86+ GetLandedPad(vessel, base, port);
87+ if (port>0) return g_Transfer;
88+ }
89+ //Original function content
90+ return *(OBJHANDLE *)(void *)((char *)dock+DOCKSTRUCTOFFSET_CURRENTDOCKOBJECT);
91+}
92+
93+int WriteCode(void *address, void *code, DWORD len)
94+{
95+ //Get process information
96+ HANDLE hSelf = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ::GetCurrentProcessId());
97+ MEMORY_BASIC_INFORMATION mbi;
98+
99+ //Open up page of linked address
100+ if(VirtualQueryEx(hSelf, (LPVOID)address, &mbi, sizeof(mbi)) != sizeof(mbi)) return -1;
101+ PVOID pvRgnBaseAddress = mbi.BaseAddress;
102+ DWORD dwOldProtect1, dwOldProtect2, dwFake;
103+ if(!::VirtualProtectEx(hSelf, pvRgnBaseAddress, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect1)) return -2;
104+ BOOL bStridePage = FALSE;
105+ LPBYTE lpByte = (LPBYTE)pvRgnBaseAddress;
106+ lpByte += 4096;
107+ if((DWORD)lpByte < (DWORD)address + 4) bStridePage = TRUE;
108+ PVOID pvRgnBaseAddress2 = (LPVOID)lpByte;
109+ if(bStridePage)
110+ if(!::VirtualProtectEx(hSelf, pvRgnBaseAddress2, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect2))
111+ {
112+ ::VirtualProtectEx(hSelf, pvRgnBaseAddress, 4, dwOldProtect1, &dwFake);
113+ return -3;
114+ }
115+
116+ //Write code
117+ memcpy(address, code, len);
118+
119+ //Lock vtables again
120+ ::VirtualProtectEx(hSelf, pvRgnBaseAddress, 4, dwOldProtect1, &dwFake);
121+ if(bStridePage) ::VirtualProtectEx(hSelf, pvRgnBaseAddress2, 4, dwOldProtect2, &dwFake);
122+}
123+
124+DLLCLBK void InitModule (HINSTANCE hDLL)
125+{
126+ //Hook
127+ union
128+ {
129+ void *pointer;
130+ byte bytes[4];
131+ DWORD value;
132+ } p;
133+ g_Hook=(DWORD)(void *)GetDockStatus;
134+ g_Transfer=NULL;
135+ p.pointer=(void *)&g_Hook;
136+ for(int i=0;i<4;i++) g_code[5+i] = p.bytes[i];
137+ if (memcmp((void *)g_original, (void *)ADDRESS_GETDOCKSTATUS, 10)==0)
138+ WriteCode((void *)ADDRESS_GETDOCKSTATUS, (void *)g_code, 10);
139+
140+ static char *name = "UMMUFB";
141+ MFDMODESPEC spec;
142+ spec.name = name;
143+ spec.key = OAPI_KEY_U;
144+ spec.msgproc = UMMUFB::MsgProc;
145+
146+ // Register the new MFD mode with Orbiter
147+ g_MFDmode = oapiRegisterMFDMode (spec);
148+}
149+
150+DLLCLBK void ExitModule (HINSTANCE hDLL)
151+{
152+ // Unregister the custom MFD mode when the module is unloaded
153+ oapiUnregisterMFDMode (g_MFDmode);
154+
155+ //Unhook
156+ if (memcmp((void *)g_code, (void *)ADDRESS_GETDOCKSTATUS, 10)==0)
157+ WriteCode((void *)ADDRESS_GETDOCKSTATUS, (void *)g_original, 10);
158+}
159+
160+// ==============================================================
161+// MFD class implementation
162+
163+// Constructor
164+UMMUFB::UMMUFB (DWORD w, DWORD h, VESSEL *vessel)
165+: MFD (w, h, vessel)
166+{
167+ this->vessel=vessel;
168+ this->object=vessel->GetHandle();
169+ this->width=(int)w/35;
170+ this->heigth=(int)h/28;
171+}
172+
173+// Destructor
174+UMMUFB::~UMMUFB ()
175+{
176+ // Add MFD cleanup code here
177+}
178+
179+// Return button labels
180+char *UMMUFB::ButtonLabel (int bt)
181+{
182+ // The labels for the two buttons used by our MFD mode
183+ static char *label[2] = {"REL", "TST"};
184+ return (bt < 2 ? label[bt] : 0);
185+}
186+
187+// Return button menus
188+int UMMUFB::ButtonMenu (const MFDBUTTONMENU **menu) const
189+{
190+ // The menu descriptions for the two buttons
191+ static const MFDBUTTONMENU mnu[2] = {
192+ {"Release from parents", 0, 'D'},
193+ {"Test UMMU", 0, 'T'}
194+ };
195+ if (menu) *menu = mnu;
196+ return 2; // return the number of buttons used
197+}
198+
199+// Repaint the MFD
200+void UMMUFB::Update (HDC hDC)
201+{
202+ ATTACHMENTHANDLE point;
203+ DWORD i, j=vessel->AttachmentCount(true);
204+ char buffer[80];
205+ strcpy(buffer, "F R E E");
206+ /*for(i=0;i<j;i++)
207+ {
208+ point=vessel->GetAttachmentHandle(true, i);
209+ if (point!=0)
210+ if (vessel->GetAttachmentStatus(point)!=0)
211+ {
212+ strcpy(buffer, "A T T A C H E D");
213+ break;
214+ }
215+ }*/
216+ DOCKHANDLE port=vessel->GetDockHandle(0);
217+ OBJHANDLE dock=vessel->GetDockStatus(port);//GetDockStatus(vessel, port);
218+ if (dock!=NULL) strcpy(buffer, "D O C K E D");
219+ int l=strlen(buffer);
220+ SelectDefaultFont (hDC, 0);
221+ SelectDefaultPen (hDC, 4);
222+ TextOut(hDC, (35-l)/2*this->width, 13*this->heigth, buffer, l);
223+}
224+
225+// MFD message parser
226+int UMMUFB::MsgProc (UINT msg, UINT mfd, WPARAM wparam, LPARAM lparam)
227+{
228+ switch (msg) {
229+ case OAPI_MSG_MFD_OPENED:
230+ // Our new MFD mode has been selected, so we create the MFD and
231+ // return a pointer to it.
232+ return (int)(new UMMUFB (LOWORD(wparam), HIWORD(wparam), (VESSEL*)lparam));
233+ }
234+ return 0;
235+}
236+
237+bool UMMUFB::ConsumeKeyBuffered(DWORD key)
238+{
239+ switch(key)
240+ {
241+ case OAPI_KEY_D:
242+ return true;
243+ case OAPI_KEY_T:
244+ TestUMMU();
245+ return true;
246+ default:
247+ return false;
248+ }
249+}
250+
251+bool UMMUFB::ConsumeButton(int bt, int event)
252+{
253+ if (event==PANEL_MOUSE_LBPRESSED)
254+ {
255+ switch(bt)
256+ {
257+ case 0:
258+ return ConsumeKeyBuffered(OAPI_KEY_D);
259+ case 1:
260+ return ConsumeKeyBuffered(OAPI_KEY_T);
261+ }
262+ }
263+ return false;
264+}
265+
266+void UMMUFB::TestUMMU()
267+{
268+ g_Transfer=object;
269+ return;
270+}
diff -r 3d2c886c31ea -r f4a0595dc36f Orbitersdk/samples/UMMUFB/PAX.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Orbitersdk/samples/UMMUFB/PAX.h Fri Aug 14 18:54:43 2009 +0200
@@ -0,0 +1,26 @@
1+#ifndef __UMMUFB_H
2+#define __UMMUFB_H
3+
4+#include "UMmuSDK.h"
5+
6+class UMMUFB: public MFD {
7+public:
8+ UMMUFB (DWORD w, DWORD h, VESSEL *vessel);
9+ ~UMMUFB ();
10+ char *ButtonLabel (int bt);
11+ int ButtonMenu (const MFDBUTTONMENU **menu) const;
12+ bool ConsumeKeyBuffered (DWORD key);
13+ bool ConsumeButton (int bt, int event);
14+ void Update (HDC hDC);
15+ static int MsgProc (UINT msg, UINT mfd, WPARAM wparam, LPARAM lparam);
16+private:
17+ // UMMU 1.5 DECLARATION
18+ UMMUCREWMANAGMENT Crew;
19+ VESSEL *vessel;
20+ OBJHANDLE object;
21+ void TestUMMU();
22+ int width;
23+ int heigth;
24+};
25+
26+#endif // !__UMMUFB_H
\ No newline at end of file
diff -r 3d2c886c31ea -r f4a0595dc36f Orbitersdk/samples/UMMUFB/UMMUFB.cpp
--- a/Orbitersdk/samples/UMMUFB/UMMUFB.cpp Thu Aug 13 15:36:46 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,270 +0,0 @@
1-#define STRICT
2-#define ORBITER_MODULE
3-#define DOCKSTRUCTOFFSET_CURRENTDOCKOBJECT 0x48
4-#define ADDRESS_GETDOCKSTATUS 0x004217E0
5-#include <stdio.h>
6-#include "orbitersdk.h"
7-#include "UMMUFB.h"
8-
9-// ==============================================================
10-// Global variables
11-
12-int g_MFDmode; // identifier for new MFD mode
13-DWORD g_Hook;
14-OBJHANDLE g_Transfer;
15-byte g_original[10]={0x8b,0x44,0x24,0x04,0x8b,0x40,0x48,0xc2,0x04,0x00};
16-//The following array is:
17-//_asm
18-//{
19-// pop eax;
20-// push ecx;
21-// push eax;
22-// jmp dword ptr [GetDockStatus]; //Dynamically detected address
23-// nop;
24-//}
25-byte g_code[10] = {0x58, 0x51, 0x50, 0xff, 0x25, 0, 0, 0, 0, 0x90};
26-
27-// ==============================================================
28-// API interface
29-
30-void _stdcall GetLandedPad(VESSEL *vessel, OBJHANDLE &base, DWORD &port)
31-{
32- VESSELSTATUS2 s;
33- s.version=2;
34- s.flag=0;
35- vessel->GetStatusEx(&s);
36- base=NULL;
37- port=0;
38- if (s.status==1 && s.rbody!=NULL)
39- {
40- int k=oapiGetBaseCount(s.rbody);
41- VECTOR3 distance;
42- OBJHANDLE nearest=NULL;
43- double nearestDistance=-1;
44- for(int i=0;i<k;i++)
45- {
46- base=oapiGetBaseByIndex(s.rbody, i);
47- int l=oapiGetBasePadCount(base);
48- vessel->GetRelativePos(base, distance);
49- double len=length(distance);
50- if (nearestDistance<0 || nearestDistance>len)
51- {
52- nearestDistance=len;
53- nearest=base;
54- }
55- }
56- if (nearest!=NULL)
57- {
58- k=oapiGetBasePadCount(nearest);
59- double vlng, vlat, vrad;
60- vessel->GetEquPos(vlng, vlat, vrad);
61- for(int i=0;i<k;i++)
62- {
63- double lng, lat;
64- oapiGetBasePadEquPos(nearest, i, &lng, &lat);
65- lng-=vlng;
66- lat-=vlat;
67- if (sqrt(lng*lng+lat*lat)*vrad<50)
68- {
69- port=i+1;
70- break;
71- }
72- }
73- }
74- if (port>0) base=nearest;
75- else base=NULL;
76- }
77-}
78-
79-OBJHANDLE _stdcall GetDockStatus(VESSEL *vessel, DOCKHANDLE dock)
80-{
81- //Do my own GetDockStatus
82- if (g_Transfer!=NULL)
83- {
84- OBJHANDLE base;
85- DWORD port;
86- GetLandedPad(vessel, base, port);
87- if (port>0) return g_Transfer;
88- }
89- //Original function content
90- return *(OBJHANDLE *)(void *)((char *)dock+DOCKSTRUCTOFFSET_CURRENTDOCKOBJECT);
91-}
92-
93-int WriteCode(void *address, void *code, DWORD len)
94-{
95- //Get process information
96- HANDLE hSelf = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ::GetCurrentProcessId());
97- MEMORY_BASIC_INFORMATION mbi;
98-
99- //Open up page of linked address
100- if(VirtualQueryEx(hSelf, (LPVOID)address, &mbi, sizeof(mbi)) != sizeof(mbi)) return -1;
101- PVOID pvRgnBaseAddress = mbi.BaseAddress;
102- DWORD dwOldProtect1, dwOldProtect2, dwFake;
103- if(!::VirtualProtectEx(hSelf, pvRgnBaseAddress, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect1)) return -2;
104- BOOL bStridePage = FALSE;
105- LPBYTE lpByte = (LPBYTE)pvRgnBaseAddress;
106- lpByte += 4096;
107- if((DWORD)lpByte < (DWORD)address + 4) bStridePage = TRUE;
108- PVOID pvRgnBaseAddress2 = (LPVOID)lpByte;
109- if(bStridePage)
110- if(!::VirtualProtectEx(hSelf, pvRgnBaseAddress2, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect2))
111- {
112- ::VirtualProtectEx(hSelf, pvRgnBaseAddress, 4, dwOldProtect1, &dwFake);
113- return -3;
114- }
115-
116- //Write code
117- memcpy(address, code, len);
118-
119- //Lock vtables again
120- ::VirtualProtectEx(hSelf, pvRgnBaseAddress, 4, dwOldProtect1, &dwFake);
121- if(bStridePage) ::VirtualProtectEx(hSelf, pvRgnBaseAddress2, 4, dwOldProtect2, &dwFake);
122-}
123-
124-DLLCLBK void InitModule (HINSTANCE hDLL)
125-{
126- //Hook
127- union
128- {
129- void *pointer;
130- byte bytes[4];
131- DWORD value;
132- } p;
133- g_Hook=(DWORD)(void *)GetDockStatus;
134- g_Transfer=NULL;
135- p.pointer=(void *)&g_Hook;
136- for(int i=0;i<4;i++) g_code[5+i] = p.bytes[i];
137- if (memcmp((void *)g_original, (void *)ADDRESS_GETDOCKSTATUS, 10)==0)
138- WriteCode((void *)ADDRESS_GETDOCKSTATUS, (void *)g_code, 10);
139-
140- static char *name = "UMMUFB";
141- MFDMODESPEC spec;
142- spec.name = name;
143- spec.key = OAPI_KEY_U;
144- spec.msgproc = UMMUFB::MsgProc;
145-
146- // Register the new MFD mode with Orbiter
147- g_MFDmode = oapiRegisterMFDMode (spec);
148-}
149-
150-DLLCLBK void ExitModule (HINSTANCE hDLL)
151-{
152- // Unregister the custom MFD mode when the module is unloaded
153- oapiUnregisterMFDMode (g_MFDmode);
154-
155- //Unhook
156- if (memcmp((void *)g_code, (void *)ADDRESS_GETDOCKSTATUS, 10)==0)
157- WriteCode((void *)ADDRESS_GETDOCKSTATUS, (void *)g_original, 10);
158-}
159-
160-// ==============================================================
161-// MFD class implementation
162-
163-// Constructor
164-UMMUFB::UMMUFB (DWORD w, DWORD h, VESSEL *vessel)
165-: MFD (w, h, vessel)
166-{
167- this->vessel=vessel;
168- this->object=vessel->GetHandle();
169- this->width=(int)w/35;
170- this->heigth=(int)h/28;
171-}
172-
173-// Destructor
174-UMMUFB::~UMMUFB ()
175-{
176- // Add MFD cleanup code here
177-}
178-
179-// Return button labels
180-char *UMMUFB::ButtonLabel (int bt)
181-{
182- // The labels for the two buttons used by our MFD mode
183- static char *label[2] = {"REL", "TST"};
184- return (bt < 2 ? label[bt] : 0);
185-}
186-
187-// Return button menus
188-int UMMUFB::ButtonMenu (const MFDBUTTONMENU **menu) const
189-{
190- // The menu descriptions for the two buttons
191- static const MFDBUTTONMENU mnu[2] = {
192- {"Release from parents", 0, 'D'},
193- {"Test UMMU", 0, 'T'}
194- };
195- if (menu) *menu = mnu;
196- return 2; // return the number of buttons used
197-}
198-
199-// Repaint the MFD
200-void UMMUFB::Update (HDC hDC)
201-{
202- ATTACHMENTHANDLE point;
203- DWORD i, j=vessel->AttachmentCount(true);
204- char buffer[80];
205- strcpy(buffer, "F R E E");
206- /*for(i=0;i<j;i++)
207- {
208- point=vessel->GetAttachmentHandle(true, i);
209- if (point!=0)
210- if (vessel->GetAttachmentStatus(point)!=0)
211- {
212- strcpy(buffer, "A T T A C H E D");
213- break;
214- }
215- }*/
216- DOCKHANDLE port=vessel->GetDockHandle(0);
217- OBJHANDLE dock=vessel->GetDockStatus(port);//GetDockStatus(vessel, port);
218- if (dock!=NULL) strcpy(buffer, "D O C K E D");
219- int l=strlen(buffer);
220- SelectDefaultFont (hDC, 0);
221- SelectDefaultPen (hDC, 4);
222- TextOut(hDC, (35-l)/2*this->width, 13*this->heigth, buffer, l);
223-}
224-
225-// MFD message parser
226-int UMMUFB::MsgProc (UINT msg, UINT mfd, WPARAM wparam, LPARAM lparam)
227-{
228- switch (msg) {
229- case OAPI_MSG_MFD_OPENED:
230- // Our new MFD mode has been selected, so we create the MFD and
231- // return a pointer to it.
232- return (int)(new UMMUFB (LOWORD(wparam), HIWORD(wparam), (VESSEL*)lparam));
233- }
234- return 0;
235-}
236-
237-bool UMMUFB::ConsumeKeyBuffered(DWORD key)
238-{
239- switch(key)
240- {
241- case OAPI_KEY_D:
242- return true;
243- case OAPI_KEY_T:
244- TestUMMU();
245- return true;
246- default:
247- return false;
248- }
249-}
250-
251-bool UMMUFB::ConsumeButton(int bt, int event)
252-{
253- if (event==PANEL_MOUSE_LBPRESSED)
254- {
255- switch(bt)
256- {
257- case 0:
258- return ConsumeKeyBuffered(OAPI_KEY_D);
259- case 1:
260- return ConsumeKeyBuffered(OAPI_KEY_T);
261- }
262- }
263- return false;
264-}
265-
266-void UMMUFB::TestUMMU()
267-{
268- g_Transfer=object;
269- return;
270-}
diff -r 3d2c886c31ea -r f4a0595dc36f Orbitersdk/samples/UMMUFB/UMMUFB.h
--- a/Orbitersdk/samples/UMMUFB/UMMUFB.h Thu Aug 13 15:36:46 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
1-#ifndef __UMMUFB_H
2-#define __UMMUFB_H
3-
4-#include "UMmuSDK.h"
5-
6-class UMMUFB: public MFD {
7-public:
8- UMMUFB (DWORD w, DWORD h, VESSEL *vessel);
9- ~UMMUFB ();
10- char *ButtonLabel (int bt);
11- int ButtonMenu (const MFDBUTTONMENU **menu) const;
12- bool ConsumeKeyBuffered (DWORD key);
13- bool ConsumeButton (int bt, int event);
14- void Update (HDC hDC);
15- static int MsgProc (UINT msg, UINT mfd, WPARAM wparam, LPARAM lparam);
16-private:
17- // UMMU 1.5 DECLARATION
18- UMMUCREWMANAGMENT Crew;
19- VESSEL *vessel;
20- OBJHANDLE object;
21- void TestUMMU();
22- int width;
23- int heigth;
24-};
25-
26-#endif // !__UMMUFB_H
\ No newline at end of file
Show on old repository browser