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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
#include "256CheckDialog.h"
#include "GlobalFunc.h"
#include "T2.h"
#include "T2ClassFactory.h"
#include "T2DLL.h"
#include "T2GlobalData.h"
#include "T2MainWindow.h"
#include "T2Message.h"
#include "T2OpenFileDialog.h"
#include "T2OpenningWindow.h"
#include "T2OpenSelectDlg.h"
#include "T2PluginLoader.h"
#include "T2PluginSpecifier.h"
#include "T2TowerDoc.h"
#include "T2TowerMainView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CT2App, CWinApp)
ON_COMMAND(ID_APP_ABOUT, OnCmdAbout)
ON_COMMAND(ID_FILE_OPEN, OnCmdOpen)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
END_MESSAGE_MAP()
CT2App::CT2App() {
gT2App = this;
_E4 = 0;
}
CT2App theApp;
static void setRegValue(HKEY rootKey, const char *subKey, const char *name, const char *value);
/*virtual*/ BOOL CT2App::InitInstance() {
SetRegistryKey("OPeNBooK9003");
_DC = 1;
char *theStr = (char *) malloc(1000);
setRegValue(HKEY_CLASSES_ROOT, "CLSID\\{F6FC9820-57D7-11d2-A2FD-0040056140CF}", NULL, "Tower2 Plugin Helper");
GetTowerDirectory(theStr);
strcat(theStr, "T2Icons.dll");
setRegValue(HKEY_CLASSES_ROOT, "CLSID\\{F6FC9820-57D7-11d2-A2FD-0040056140CF}\\InProcServer32", NULL, theStr);
setRegValue(HKEY_CLASSES_ROOT, "CLSID\\{F6FC9820-57D7-11d2-A2FD-0040056140CF}\\InProcServer32", "ThreadingModel", "Apartment");
setRegValue(HKEY_CLASSES_ROOT, ".t2p", NULL, "Tower2 plugin");
setRegValue(HKEY_CLASSES_ROOT, "Tower2 plugin", NULL, "Tower2 plugin");
GetModuleFileName(NULL, theStr, 1000);
strcat(theStr, ",1");
setRegValue(HKEY_CLASSES_ROOT, "Tower2 plugin\\DefaultIcon", NULL, theStr);
setRegValue(HKEY_CLASSES_ROOT, "Tower2 plugin\\shellex\\IconHandler", NULL, "{F6FC9820-57D7-11d2-A2FD-0040056140CF}");
setRegValue(HKEY_CLASSES_ROOT, "Tower2 plugin\\shellex\\PropertySheetHandlers", NULL, "T2Page");
setRegValue(HKEY_CLASSES_ROOT, "Tower2 plugin\\shellex\\PropertySheetHandlers\\T2Page", NULL, "{F6FC9820-57D7-11d2-A2FD-0040056140CF}");
setRegValue(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", "{F6FC9820-57D7-11d2-A2FD-0040056140CF}", "Tower2 Plugin Helper");
setRegValue(HKEY_CLASSES_ROOT, ".bld", NULL, "Tower2 Building");
setRegValue(HKEY_CLASSES_ROOT, "Tower2 Building", NULL, "Tower2 Building");
GetModuleFileName(NULL, theStr, 1000);
strcat(theStr, ",1");
setRegValue(HKEY_CLASSES_ROOT, "Tower2 Building\\DefaultIcon", NULL, theStr);
GetModuleFileName(NULL, theStr, 1000);
strcat(theStr, " %1");
setRegValue(HKEY_CLASSES_ROOT, "Tower2 Building\\shell\\open\\command", NULL, theStr);
free(theStr);
#line 99
mPluginLoader = new T2PluginLoader;
mPluginLoader->InitFileList();
CoInitialize(NULL);
T2ClassFactory::Initialize();
T2PluginSpecifier *thePluginSpecifier;
POSITION pos;
mPluginLoader->SetTypeFilter(pos, 'CLAS');
while ((thePluginSpecifier = mPluginLoader->GetNext(pos))) {
if (!thePluginSpecifier->mAttrib) {
CLASSFACTORY_CLASSINFO *clsInfo = (CLASSFACTORY_CLASSINFO *) T2PluginLoader::LoadPlugin(thePluginSpecifier);
T2ClassFactory::Register(clsInfo);
free(clsInfo);
}
}
#line 118
mGlobalData = new T2GlobalData;
if (!mGlobalData->IsCheckSerial()) {
MessageBox(
NULL,
// "シリアル番号が間違っています。"
"\x83\x56\x83\x8A\x83\x41\x83\x8B\x94\xD4\x8D\x86\x82\xAA\x8A\xD4\x88\xE1\x82\xC1\x82\xC4\x82\xA2\x82\xDC\x82\xB7\x81\x42",
// "The Tower Ⅱ"
"The Tower \x87\x55",
MB_ICONERROR);
return false;
}
Enable3dControls();
SetDialogBkColor();
LoadStdProfileSettings();
BOOL isPaletteMode = false;
HDC hdc = GetDC(NULL);
if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
isPaletteMode = true;
ReleaseDC(NULL, hdc);
if (!isPaletteMode) {
C256ColorDialog dlg(NULL);
if (dlg.DoModal() != IDOK)
return false;
}
#line 154
(new T2OpenningWindow)->ShowOpenningWindow();
#line 161
CDocTemplate *pDocTemplate = new CSingleDocTemplate(
128,
RUNTIME_CLASS(T2TowerDoc),
RUNTIME_CLASS(T2MainWindow),
RUNTIME_CLASS(T2TowerMainView)
);
AddDocTemplate(pDocTemplate);
app_vfB4();
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
BOOL bResult = true;
switch (cmdInfo.m_nShellCommand) {
case CCommandLineInfo::FileNew:
if (!AfxGetApp()->OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL))
CWinApp::OnFileNew();
if (!m_pMainWnd)
bResult = false;
break;
case CCommandLineInfo::FileOpen:
mStrE0 = cmdInfo.m_strFileName;
if (!AfxGetApp()->OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL))
CWinApp::OnFileNew();
if (!m_pMainWnd)
bResult = false;
break;
}
return true;
}
static void setRegValue(HKEY rootKey, const char *subKey, const char *name, const char *value) {
HKEY key;
RegCreateKey(rootKey, subKey, &key);
RegSetValueEx(key, name, 0, REG_SZ, (const BYTE *) value, strlen(value));
RegCloseKey(key);
}
class AboutDialog : public CDialog {
DECLARE_MESSAGE_MAP();
public:
AboutDialog();
protected:
virtual void DoDataExchange(CDataExchange *pDX);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnDestroy();
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
int mCounter;
CBitmap mBitmap;
int mCreditsWidth;
int mCreditsViewHeight;
int mCreditsFullHeight;
BOOL mIsSetUp;
};
AboutDialog::AboutDialog()
: CDialog(100)
{
mIsSetUp = false;
}
/*virtual*/ void AboutDialog::DoDataExchange(CDataExchange *pDX) {
CWnd::DoDataExchange(pDX);
}
void AboutDialog::OnShowWindow(BOOL bShow, UINT nStatus) {
CWnd::OnShowWindow(bShow, nStatus);
if (!mIsSetUp) {
#pragma var_order(windowRect, okRect, serialNo, logoItem, bitmap, serialLabelItem, serialItem, app, okButton, niceSerialNo, serialLabelRect, clientRect, logoRect, creditsWnd)
mIsSetUp = true;
mCounter = 0;
SetTimer(1, 50, NULL);
CWnd *logoItem = GetDlgItem(1026);
logoItem->SetWindowPos(NULL, 16, 16, 0, 0, SWP_NOSIZE);
RECT logoRect;
logoItem->GetClientRect(&logoRect);
CWnd *serialLabelItem = GetDlgItem(1027);
serialLabelItem->SetWindowPos(NULL, 16, logoRect.bottom + 32, 0, 0, SWP_NOSIZE);
RECT serialLabelRect;
serialLabelItem->GetClientRect(&serialLabelRect);
CT2App *app = T2_APP;
CString serialNo = app->app_vfB0()->mSerial;
CString niceSerialNo;
niceSerialNo = serialNo.Mid(0, 4);
niceSerialNo += " - ";
niceSerialNo += serialNo.Mid(4, 4);
niceSerialNo += " - ";
niceSerialNo += serialNo.Mid(8, 4);
niceSerialNo += " - ";
niceSerialNo += serialNo.Mid(12, 4);
CWnd *serialItem = GetDlgItem(1024);
serialItem->SetWindowText(niceSerialNo);
serialItem->SetWindowPos(NULL, serialLabelRect.right + 20, logoRect.bottom + 32, 0, 0, SWP_NOSIZE);
mBitmap.LoadBitmap(224);
BITMAP bitmap;
mBitmap.GetBitmap(&bitmap);
CWnd *creditsWnd = GetDlgItem(1025);
mCreditsWidth = bitmap.bmWidth;
mCreditsViewHeight = logoRect.bottom;
creditsWnd->SetWindowPos(NULL, logoRect.right + 32, 16, mCreditsWidth, mCreditsViewHeight, 0);
mCreditsFullHeight = bitmap.bmHeight;
CWnd *okButton = GetDlgItem(1);
RECT okRect;
okButton->GetClientRect(&okRect);
okButton->SetWindowPos(NULL, logoRect.right + 32 + mCreditsWidth - okRect.right, mCreditsViewHeight + 32, 0, 0, SWP_NOSIZE);
RECT windowRect, clientRect;
GetWindowRect(&windowRect);
windowRect.bottom -= windowRect.top;
GetClientRect(&clientRect);
windowRect.bottom -= clientRect.bottom;
SetWindowPos(NULL, 0, 0, logoRect.right + 48 + mCreditsWidth, mCreditsViewHeight + 48 + okRect.bottom + windowRect.bottom, SWP_NOMOVE);
}
}
void AboutDialog::OnDestroy() {
KillTimer(1);
mBitmap.DeleteObject();
CWnd::OnDestroy();
}
void AboutDialog::OnTimer(UINT nIDEvent) {
#pragma var_order(prevBitmap, dc, newDC, creditsWnd)
mCounter++;
if (mCounter > (mCreditsFullHeight - mCreditsViewHeight))
mCounter = 0;
CWnd *creditsWnd = GetDlgItem(1025);
CDC newDC;
CDC *dc = creditsWnd->GetDC();
newDC.CreateCompatibleDC(dc);
CBitmap *prevBitmap = newDC.SelectObject(&mBitmap);
dc->BitBlt(0, 0, mCreditsWidth, mCreditsViewHeight, &newDC, 0, mCounter, SRCCOPY);
newDC.SelectObject(prevBitmap);
newDC.DeleteDC();
CWnd::OnTimer(nIDEvent);
}
BEGIN_MESSAGE_MAP(AboutDialog, CDialog)
ON_WM_TIMER()
ON_WM_DESTROY()
ON_WM_SHOWWINDOW()
END_MESSAGE_MAP()
void CT2App::OnCmdAbout() {
AboutDialog dlg;
dlg.DoModal();
}
/*virtual*/ int CT2App::ExitInstance() {
T2ClassFactory::Discard();
CoUninitialize();
delete mGlobalData;
delete mPluginLoader;
OutputDebugString("***** TowerII : PROGRAM TERMINATED *****\n");
return CWinApp::ExitInstance();
}
/*virtual*/ BOOL CT2App::OnIdle(LONG lCount) {
if (_E4 && _DC > 0) {
T2MainWindow *mainWindow = T2_MAIN_WINDOW;
if (mainWindow) {
T2TowerDoc *doc = (T2TowerDoc *) mainWindow->GetActiveDocument();
if (doc)
doc->towerDoc_vfC0(0);
}
}
return true;
}
/*virtual*/ void CT2App::app_vfA4(BOOL inEnable) {
if (inEnable)
_DC++;
else
_DC--;
}
/*virtual*/ void CT2App::app_vfA8(T2Message *inMessage) {
mMessage = inMessage;
}
/*virtual*/ void CT2App::app_vfAC() {
mMessage = NULL;
}
/*virtual*/ BOOL CT2App::PreTranslateMessage(MSG *pMsg) {
if (mMessage)
mMessage->SendMessage(WM_USER + 10, 0, (LPARAM) pMsg);
return CWinThread::PreTranslateMessage(pMsg);
}
/*virtual*/ void CT2App::app_vfB4() {
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, 0))
PumpMessage();
}
/*virtual*/ int CT2App::Run() {
// this is just CWinThread::Run()'s body
#line 451
ASSERT_VALID(this);
// for tracking the idle time state
BOOL bIdle = TRUE;
LONG lIdleCount = 0;
// acquire and dispatch messages until a WM_QUIT message is received.
for (;;) {
// phase1: check to see if we can do idle work
while (bIdle &&
!::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
{
// call OnIdle while in bIdle state
if (!OnIdle(lIdleCount++))
bIdle = FALSE; // assume "no idle" state
}
// phase2: pump messages while available
do
{
// pump message, but quit on WM_QUIT
if (!PumpMessage())
return ExitInstance();
// reset "no idle" state after pumping "normal" message
if (IsIdleMessage(&m_msgCur))
{
bIdle = TRUE;
lIdleCount = 0;
}
} while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
}
#line 485
ASSERT(FALSE); // not reachable
}
void CT2App::OnCmdOpen() {
CString str;
T2OpenFileDialog ofd(
true,
"bld",
NULL,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_EXPLORER,
// "Tower2.0ビルファイル (*.bld)|*.bld|すべてのファイル (*.*)|*.*||"
"Tower2.0\xCB\xDE\xD9\xCC\xA7\xB2\xD9 (*.bld)|*.bld|\x82\xB7\x82\xD7\x82\xC4\x82\xCC\xCC\xA7\xB2\xD9 (*.*)|*.*||",
AfxGetMainWnd()
);
if (ofd.DoModal() == IDOK) {
str = ofd.GetPathName();
if (g_TowerDoc->SaveModified()) {
if (!g_TowerDoc->OnOpenDocument(str)) {
if (g_TowerDoc->mErrorFlag) {
g_TowerDoc->SetModifiedFlag(false);
OnFileNew();
}
} else {
g_TowerDoc->SetPathName(str);
}
}
} else if (GetCurrentT2TowerDoc()->Get228()) {
T2MainWindow *mainWindow = T2_MAIN_WINDOW;
if (mainWindow) {
T2TowerDoc *theDoc = (T2TowerDoc *) mainWindow->GetActiveDocument();
if (theDoc) {
#line 535
T2OpenSelectDlg *dlg = new T2OpenSelectDlg(theDoc);
dlg->ShowOpenSelectDialog();
}
}
}
}
static BOOL CALLBACK EnumFFJoysticksCallback(LPCDIDEVICEINSTANCE pinst, LPVOID lpvContext);
void ffInit(HWND hwnd) {
HINSTANCE hInstance = AfxGetApp()->m_hInstance;
HRESULT hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &FFgpdi, NULL);
if (FAILED(hr))
return;
hr = FFgpdi->EnumDevices(DIDEVTYPE_JOYSTICK, EnumFFJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK);
if (!FFJoystick)
return;
hr = FFJoystick->SetDataFormat(&c_dfDIJoystick);
if (FAILED(hr))
return;
hr = FFJoystick->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_BACKGROUND);
if (FAILED(hr))
return;
DIEFFECT eff;
DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y };
LONG rglDirection[2] = { 0, 0 };
DICONSTANTFORCE cf = { 0 };
eff.dwSize = sizeof(DIEFFECT);
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
eff.dwDuration = INFINITE;
eff.dwSamplePeriod = 0;
eff.dwGain = DI_FFNOMINALMAX;
eff.dwTriggerButton = DIEB_NOTRIGGER;
eff.dwTriggerRepeatInterval = 0;
eff.cAxes = 2;
eff.rgdwAxes = rgdwAxes;
eff.rglDirection = rglDirection;
eff.lpEnvelope = NULL;
eff.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
eff.lpvTypeSpecificParams = &cf;
hr = FFJoystick->CreateEffect(GUID_ConstantForce, &eff, &FFStatic, NULL);
if (FAILED(hr))
return;
FFJoystick->Acquire();
FFStatic->Start(1, 0);
FFEnable = true;
}
static BOOL CALLBACK EnumFFJoysticksCallback(LPCDIDEVICEINSTANCE pinst, LPVOID lpvContext) {
HRESULT hr;
LPDIRECTINPUTDEVICE pdev;
LPDIRECTINPUTDEVICE2 pdev2;
hr = FFgpdi->CreateDevice(pinst->guidInstance, &pdev, NULL);
if (FAILED(hr))
return DIENUM_CONTINUE;
hr = pdev->QueryInterface(IID_IDirectInputDevice2, (LPVOID *) &pdev2);
pdev->Release();
if (FAILED(hr))
return DIENUM_CONTINUE;
FFJoystick = pdev2;
return DIENUM_STOP;
}
void ffDestroy() {
if (FFBuild)
FFBuild->Release();
if (FFStatic)
FFStatic->Release();
if (FFJoystick) {
FFJoystick->Unacquire();
FFJoystick->Release();
}
if (FFgpdi)
FFgpdi->Release();
}
|