#include "StdAfx.h" #include "256CheckDialog.h" #include "T2DLL/GlobalFunc.h" #include "T2.h" #include "T2DLL/T2ClassFactory.h" #include "T2DLL/T2DLL.h" #include "T2DLL/T2GlobalData.h" #include "T2DLL/T2Message.h" #include "T2OpenFileDialog.h" #include "T2OpenningWindow.h" #include "T2OpenSelectDlg.h" #include "T2DLL/T2PluginLoader.h" #include "T2DLL/T2PluginSpecifier.h" #include "T2MainWindow.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) //{{AFX_MSG_MAP(CT2App) ON_COMMAND(ID_APP_ABOUT, OnCmdAbout) ON_COMMAND(ID_FILE_OPEN, OnCmdOpen) //}}AFX_MSG_MAP ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, CWinApp::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(_T("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) { C256CheckDialog dlg(NULL); if (dlg.DoModal() != IDOK) return false; } #line 154 (new T2OpenningWindow)->ShowOpenningWindow(); #line 161 CDocTemplate *pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, 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 CAboutDlg : public CDialog { public: CAboutDlg(); //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange *pDX); //}}AFX_VIRTUAL protected: //{{AFX_MSG(CAboutDlg) afx_msg void OnTimer(UINT nIDEvent); afx_msg void OnDestroy(); afx_msg void OnShowWindow(BOOL bShow, UINT nStatus); //}}AFX_MSG DECLARE_MESSAGE_MAP() int mCounter; CBitmap mBitmap; int mCreditsWidth; int mCreditsViewHeight; int mCreditsFullHeight; BOOL mIsSetUp; }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT mIsSetUp = false; } /*virtual*/ void CAboutDlg::DoDataExchange(CDataExchange *pDX) { CWnd::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } void CAboutDlg::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(IDC_LOGO); logoItem->SetWindowPos(NULL, 16, 16, 0, 0, SWP_NOSIZE); RECT logoRect; logoItem->GetClientRect(&logoRect); CWnd *serialLabelItem = GetDlgItem(IDC_SERIAL_LABEL); 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(IDC_SERIAL_NUMBER); serialItem->SetWindowText(niceSerialNo); serialItem->SetWindowPos(NULL, serialLabelRect.right + 20, logoRect.bottom + 32, 0, 0, SWP_NOSIZE); mBitmap.LoadBitmap(IDB_CREDITS); BITMAP bitmap; mBitmap.GetBitmap(&bitmap); CWnd *creditsWnd = GetDlgItem(IDC_CREDITS); mCreditsWidth = bitmap.bmWidth; mCreditsViewHeight = logoRect.bottom; creditsWnd->SetWindowPos(NULL, logoRect.right + 32, 16, mCreditsWidth, mCreditsViewHeight, 0); mCreditsFullHeight = bitmap.bmHeight; CWnd *okButton = GetDlgItem(IDOK); 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 CAboutDlg::OnDestroy() { KillTimer(1); mBitmap.DeleteObject(); CWnd::OnDestroy(); } void CAboutDlg::OnTimer(UINT nIDEvent) { #pragma var_order(prevBitmap, dc, newDC, creditsWnd) mCounter++; if (mCounter > (mCreditsFullHeight - mCreditsViewHeight)) mCounter = 0; CWnd *creditsWnd = GetDlgItem(IDC_CREDITS); 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(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) ON_WM_TIMER() ON_WM_DESTROY() ON_WM_SHOWWINDOW() //}}AFX_MSG_MAP END_MESSAGE_MAP() void CT2App::OnCmdAbout() { CAboutDlg aboutDlg; aboutDlg.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(); }