2020-11-05 16:44:34 +01:00
|
|
|
#include "pch.h"
|
|
|
|
#include "winmain.h"
|
2020-11-06 14:56:32 +01:00
|
|
|
|
|
|
|
#include "fullscrn.h"
|
2020-11-05 16:44:34 +01:00
|
|
|
#include "memory.h"
|
2020-12-02 18:12:34 +01:00
|
|
|
#include "midi.h"
|
2020-11-05 16:44:34 +01:00
|
|
|
#include "pinball.h"
|
|
|
|
#include "options.h"
|
2020-11-06 14:56:32 +01:00
|
|
|
#include "pb.h"
|
2020-11-29 16:50:49 +01:00
|
|
|
#include "Sound.h"
|
2020-12-04 16:35:47 +01:00
|
|
|
#include "resource.h"
|
2020-11-05 16:44:34 +01:00
|
|
|
|
2020-12-03 15:47:36 +01:00
|
|
|
HINSTANCE winmain::hinst = nullptr;
|
|
|
|
HWND winmain::hwnd_frame = nullptr;
|
|
|
|
HCURSOR winmain::mouse_hsave;
|
|
|
|
|
|
|
|
int winmain::return_value = 0;
|
|
|
|
int winmain::bQuit = 0;
|
|
|
|
int winmain::activated;
|
|
|
|
int winmain::DispFrameRate = 1;
|
|
|
|
int winmain::DispGRhistory = 0;
|
|
|
|
int winmain::single_step = 0;
|
|
|
|
int winmain::has_focus = 1;
|
|
|
|
int winmain::last_mouse_x;
|
|
|
|
int winmain::last_mouse_y;
|
|
|
|
int winmain::mouse_down;
|
|
|
|
int winmain::no_time_loss;
|
|
|
|
|
|
|
|
DWORD winmain::then;
|
|
|
|
DWORD winmain::now;
|
2020-12-02 18:12:34 +01:00
|
|
|
UINT winmain::iFrostUniqueMsg;
|
2020-12-03 15:47:36 +01:00
|
|
|
|
2020-11-29 16:50:49 +01:00
|
|
|
gdrv_bitmap8 winmain::gfr_display{};
|
2020-12-02 18:12:34 +01:00
|
|
|
char winmain::DatFileName[300]{};
|
2020-12-03 15:47:36 +01:00
|
|
|
|
2020-11-05 16:44:34 +01:00
|
|
|
|
2020-11-07 16:41:14 +01:00
|
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
2020-11-05 16:44:34 +01:00
|
|
|
{
|
2020-11-07 16:41:14 +01:00
|
|
|
return winmain::WinMain(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
|
2020-11-05 16:44:34 +01:00
|
|
|
}
|
|
|
|
|
2020-11-07 16:41:14 +01:00
|
|
|
int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
2020-11-05 16:44:34 +01:00
|
|
|
{
|
2020-11-07 16:41:14 +01:00
|
|
|
memory::init(memalloc_failure);
|
2020-11-05 16:44:34 +01:00
|
|
|
++memory::critical_allocation;
|
|
|
|
auto optionsRegPath = pinball::get_rc_string(165, 0);
|
|
|
|
options::path_init(optionsRegPath);
|
|
|
|
auto regSpaceCadet = pinball::get_rc_string(166, 0);
|
|
|
|
|
|
|
|
if (options::get_int(regSpaceCadet, "Table Version", 1) <= 1)
|
|
|
|
{
|
|
|
|
auto tmpBuf = memory::allocate(0x1F4u);
|
|
|
|
if (!tmpBuf)
|
|
|
|
{
|
|
|
|
options::path_uninit();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
options::set_int(regSpaceCadet, "Table Version", 1u);
|
2020-12-03 15:47:36 +01:00
|
|
|
GetModuleFileNameA(hinst, tmpBuf, 0x1F4u);
|
2020-11-05 16:44:34 +01:00
|
|
|
options::set_string(regSpaceCadet, "Table Exe", tmpBuf);
|
|
|
|
options::set_string(regSpaceCadet, "Table Name", pinball::get_rc_string(169, 0));
|
|
|
|
options::set_string(nullptr, "Last Table Played", regSpaceCadet);
|
|
|
|
memory::free(static_cast<void*>(tmpBuf));
|
|
|
|
tmpBuf = memory::allocate(0x1F4u);
|
|
|
|
if (tmpBuf)
|
|
|
|
{
|
|
|
|
auto tmpBuf2 = memory::allocate(0x1F4u);
|
|
|
|
if (tmpBuf2)
|
|
|
|
{
|
|
|
|
char Buffer[40];
|
2020-12-04 16:35:47 +01:00
|
|
|
bool setOption = false;
|
2020-11-05 16:44:34 +01:00
|
|
|
for (int i = 0; i < 32700; ++i)
|
|
|
|
{
|
|
|
|
sprintf_s(Buffer, "Table%d", i);
|
|
|
|
options::get_string(nullptr, Buffer, tmpBuf, pinball::WindowName, 500);
|
|
|
|
if (!*tmpBuf)
|
|
|
|
break;
|
|
|
|
options::get_string(tmpBuf, "Table Name", tmpBuf2, pinball::WindowName, 500);
|
|
|
|
if (!lstrcmpA(tmpBuf2, pinball::get_rc_string(169, 0)))
|
2020-12-04 16:35:47 +01:00
|
|
|
{
|
|
|
|
setOption = false;
|
|
|
|
break;
|
|
|
|
}
|
2020-11-05 16:44:34 +01:00
|
|
|
if (!*tmpBuf2)
|
|
|
|
break;
|
|
|
|
}
|
2020-12-04 16:35:47 +01:00
|
|
|
if (setOption)
|
|
|
|
options::set_string(nullptr, Buffer, regSpaceCadet);
|
2020-11-05 16:44:34 +01:00
|
|
|
memory::free(tmpBuf2);
|
|
|
|
}
|
|
|
|
memory::free(tmpBuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto tmpBuf = memory::allocate(0x1F4u);
|
|
|
|
if (!tmpBuf)
|
|
|
|
{
|
|
|
|
options::path_uninit();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
options::get_string(regSpaceCadet, "Shell Exe", tmpBuf, pinball::WindowName, 500);
|
|
|
|
auto execRes = WinExec(tmpBuf, 5u);
|
|
|
|
memory::free(tmpBuf);
|
|
|
|
if (execRes >= 32)
|
|
|
|
{
|
|
|
|
options::path_uninit();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--memory::critical_allocation;
|
|
|
|
|
2020-11-06 14:56:32 +01:00
|
|
|
pinball::quickFlag = strstr(lpCmdLine, "-quick") != nullptr;
|
2020-12-03 15:47:36 +01:00
|
|
|
hinst = hInstance;
|
2020-12-02 18:12:34 +01:00
|
|
|
options::get_string(regSpaceCadet, "Pinball Data", DatFileName, pinball::get_rc_string(168, 0), 300);
|
2020-11-05 16:44:34 +01:00
|
|
|
|
|
|
|
iFrostUniqueMsg = RegisterWindowMessageA("PinballThemeSwitcherUniqueMsgString");
|
2020-12-04 16:35:47 +01:00
|
|
|
auto windowClass = pinball::get_rc_string(167, 0);
|
|
|
|
auto windowHandle = FindWindowA(windowClass, nullptr);
|
2020-11-05 16:44:34 +01:00
|
|
|
if (windowHandle)
|
|
|
|
{
|
|
|
|
SendMessageA(windowHandle, iFrostUniqueMsg, 0, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_expiration_date())
|
|
|
|
return 0;
|
|
|
|
|
2020-11-07 16:41:14 +01:00
|
|
|
INITCOMMONCONTROLSEX picce;
|
2020-11-05 16:44:34 +01:00
|
|
|
picce.dwSize = 8;
|
|
|
|
picce.dwICC = 5885;
|
|
|
|
InitCommonControlsEx(&picce);
|
2020-12-06 14:21:56 +01:00
|
|
|
|
2020-11-06 14:56:32 +01:00
|
|
|
WNDCLASSA WndClass{};
|
2020-11-05 16:44:34 +01:00
|
|
|
WndClass.style = 4104;
|
|
|
|
WndClass.lpfnWndProc = message_handler;
|
|
|
|
WndClass.cbClsExtra = 0;
|
|
|
|
WndClass.cbWndExtra = 0;
|
|
|
|
WndClass.hInstance = hInstance;
|
|
|
|
WndClass.hIcon = LoadIconA(hInstance, "ICON_1");
|
2020-12-11 17:03:13 +01:00
|
|
|
WndClass.hCursor = LoadCursorA(nullptr, IDC_ARROW);
|
2020-11-05 16:44:34 +01:00
|
|
|
WndClass.hbrBackground = (HBRUSH)16;
|
|
|
|
WndClass.lpszMenuName = "MENU_1";
|
2020-11-06 14:56:32 +01:00
|
|
|
WndClass.lpszClassName = windowClass;
|
|
|
|
//auto tmpBuf = splash_screen((int)hInstance, "splash_bitmap", "splash_bitmap"); // No splash for now
|
2020-11-05 16:44:34 +01:00
|
|
|
RegisterClassA(&WndClass);
|
2020-11-06 14:56:32 +01:00
|
|
|
|
|
|
|
pinball::FindShiftKeys();
|
|
|
|
|
|
|
|
char windowName[40];
|
|
|
|
lstrcpyA(windowName, pinball::get_rc_string(38, 0));
|
|
|
|
windowHandle = CreateWindowExA(0, windowClass, windowName, 0x3CA0000u, 0, 0, 640, 480, nullptr, nullptr, hInstance,
|
|
|
|
nullptr);
|
2020-12-03 15:47:36 +01:00
|
|
|
hwnd_frame = windowHandle;
|
2020-11-06 14:56:32 +01:00
|
|
|
if (!windowHandle)
|
|
|
|
{
|
|
|
|
PostQuitMessage(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto menuHandle = GetMenu(windowHandle);
|
|
|
|
options::init(menuHandle);
|
|
|
|
pb::reset_table();
|
|
|
|
pb::firsttime_setup();
|
|
|
|
|
|
|
|
if (strstr(lpCmdLine, "-fullscreen"))
|
|
|
|
{
|
|
|
|
options::Options.FullScreen = 1;
|
2020-12-06 14:21:56 +01:00
|
|
|
options::menu_check(Menu1_Full_Screen, 1);
|
2020-11-06 14:56:32 +01:00
|
|
|
}
|
|
|
|
|
2020-12-03 15:47:36 +01:00
|
|
|
ShowWindow(hwnd_frame, nShowCmd);
|
2020-11-06 14:56:32 +01:00
|
|
|
fullscrn::set_screen_mode(options::Options.FullScreen);
|
2020-12-03 15:47:36 +01:00
|
|
|
UpdateWindow(hwnd_frame);
|
2020-11-06 14:56:32 +01:00
|
|
|
|
|
|
|
/*if (tmpBuf) //Close splash
|
|
|
|
{
|
|
|
|
splash_hide(tmpBuf);
|
|
|
|
splash_destroy(tmpBuf);
|
|
|
|
}*/
|
|
|
|
|
|
|
|
pinball::adjust_priority(options::Options.PriorityAdj);
|
|
|
|
const auto startTime = timeGetTime();
|
|
|
|
MSG wndMessage{};
|
2020-12-04 16:35:47 +01:00
|
|
|
while (timeGetTime() >= startTime && timeGetTime() - startTime < 0) // Don't wait for now, was 2000
|
2020-12-03 15:47:36 +01:00
|
|
|
PeekMessageA(&wndMessage, hwnd_frame, 0, 0, 1u);
|
2020-11-07 16:41:14 +01:00
|
|
|
|
2020-11-29 16:50:49 +01:00
|
|
|
if (strstr(lpCmdLine, "-demo"))
|
|
|
|
pb::toggle_demo();
|
|
|
|
else
|
|
|
|
pb::replay_level(0);
|
|
|
|
|
|
|
|
DWORD someTimeCounter = 300u, prevTime = 0u;
|
|
|
|
then = timeGetTime();
|
2020-11-06 14:56:32 +01:00
|
|
|
while (true)
|
|
|
|
{
|
2020-11-29 16:50:49 +01:00
|
|
|
if (!someTimeCounter)
|
2020-11-13 17:04:58 +01:00
|
|
|
{
|
2020-11-29 16:50:49 +01:00
|
|
|
someTimeCounter = 300;
|
|
|
|
if (DispFrameRate)
|
2020-11-13 17:04:58 +01:00
|
|
|
{
|
2020-11-29 16:50:49 +01:00
|
|
|
auto curTime = timeGetTime();
|
|
|
|
if (prevTime)
|
2020-11-13 17:04:58 +01:00
|
|
|
{
|
2020-11-29 16:50:49 +01:00
|
|
|
char buf[60];
|
|
|
|
sprintf_s(buf, "Frames/sec = %02.02f", 300.0f / (static_cast<float>(curTime - prevTime) * 0.001f));
|
2020-12-03 15:47:36 +01:00
|
|
|
SetWindowTextA(hwnd_frame, buf);
|
2020-11-29 16:50:49 +01:00
|
|
|
|
|
|
|
if (DispGRhistory)
|
|
|
|
{
|
|
|
|
if (!gfr_display.BmpBufPtr1)
|
|
|
|
{
|
|
|
|
auto plt = static_cast<PALETTEENTRY*>(malloc(1024u));
|
|
|
|
auto pltPtr = &plt[10];
|
|
|
|
for (int i1 = 0, i2 = 0; i1 < 256 - 10; ++i1, i2 += 8)
|
|
|
|
{
|
|
|
|
unsigned char blue = i2, redGreen = i2;
|
|
|
|
if (i2 > 255)
|
|
|
|
{
|
|
|
|
blue = 255;
|
|
|
|
redGreen = i1;
|
|
|
|
}
|
2020-11-13 17:04:58 +01:00
|
|
|
|
2020-11-29 16:50:49 +01:00
|
|
|
*pltPtr++ = {redGreen, redGreen, blue};
|
|
|
|
}
|
|
|
|
gdrv::display_palette(plt);
|
|
|
|
free(plt);
|
|
|
|
gdrv::create_bitmap(&gfr_display, 400, 15);
|
|
|
|
}
|
|
|
|
|
|
|
|
gdrv::blit(&gfr_display, 0, 0, 0, 0, 300, 10);
|
|
|
|
gdrv::fill_bitmap(&gfr_display, 300, 10, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prevTime = curTime;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prevTime = 0;
|
2020-11-13 17:04:58 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-29 16:50:49 +01:00
|
|
|
|
|
|
|
Sound::Idle();
|
2020-11-06 14:56:32 +01:00
|
|
|
if (!ProcessWindowMessages() || bQuit)
|
|
|
|
break;
|
2020-11-29 16:50:49 +01:00
|
|
|
|
|
|
|
if (has_focus)
|
|
|
|
{
|
|
|
|
if (mouse_down)
|
|
|
|
{
|
|
|
|
now = timeGetTime();
|
|
|
|
if (now - then >= 2)
|
|
|
|
{
|
|
|
|
POINT Point;
|
|
|
|
GetCursorPos(&Point);
|
|
|
|
pb::ballset(last_mouse_x - Point.x, Point.y - last_mouse_y);
|
|
|
|
SetCursorPos(last_mouse_x, last_mouse_y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!single_step)
|
|
|
|
{
|
|
|
|
auto curTime = timeGetTime();
|
|
|
|
now = curTime;
|
|
|
|
if (no_time_loss)
|
|
|
|
{
|
|
|
|
then = curTime;
|
|
|
|
no_time_loss = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curTime == then)
|
|
|
|
{
|
|
|
|
Sleep(8u);
|
|
|
|
}
|
|
|
|
else if (pb::frame(curTime - then))
|
|
|
|
{
|
|
|
|
if (gfr_display.BmpBufPtr1)
|
|
|
|
{
|
|
|
|
auto deltaT = now - then + 10;
|
|
|
|
auto fillChar = static_cast<char>(deltaT);
|
|
|
|
if (deltaT > 236)
|
|
|
|
{
|
|
|
|
fillChar = -7;
|
|
|
|
}
|
2020-12-04 16:35:47 +01:00
|
|
|
gdrv::fill_bitmap(&gfr_display, 1, 10, 299 - someTimeCounter, 0, fillChar);
|
2020-11-29 16:50:49 +01:00
|
|
|
}
|
|
|
|
--someTimeCounter;
|
|
|
|
then = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-06 14:56:32 +01:00
|
|
|
}
|
|
|
|
|
2020-12-04 16:35:47 +01:00
|
|
|
gdrv::destroy_bitmap(&gfr_display);
|
|
|
|
options::uninit();
|
|
|
|
midi::music_shutdown();
|
|
|
|
pb::uninit();
|
|
|
|
Sound::Close();
|
|
|
|
gdrv::uninit();
|
|
|
|
DestroyWindow(hwnd_frame);
|
|
|
|
options::path_uninit();
|
|
|
|
UnregisterClassA(windowClass, hinst);
|
2020-11-06 14:56:32 +01:00
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:41:14 +01:00
|
|
|
LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
2020-11-06 14:56:32 +01:00
|
|
|
{
|
2020-12-02 18:12:34 +01:00
|
|
|
if (Msg == iFrostUniqueMsg)
|
|
|
|
{
|
|
|
|
if (IsIconic(hWnd))
|
|
|
|
ShowWindow(hWnd, 9);
|
|
|
|
SetForegroundWindow(hWnd);
|
|
|
|
return 0;
|
|
|
|
}
|
2021-01-06 15:06:13 +01:00
|
|
|
|
2020-12-02 18:12:34 +01:00
|
|
|
if (Msg <= WM_ACTIVATEAPP)
|
|
|
|
{
|
|
|
|
switch (Msg)
|
|
|
|
{
|
|
|
|
case WM_ACTIVATEAPP:
|
|
|
|
if (wParam)
|
|
|
|
{
|
|
|
|
activated = 1;
|
|
|
|
Sound::Activate();
|
|
|
|
if (options::Options.Music && !single_step)
|
|
|
|
midi::play_pb_theme(0);
|
|
|
|
no_time_loss = 1;
|
|
|
|
pinball::adjust_priority(options::Options.PriorityAdj);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
activated = 0;
|
|
|
|
fullscrn::activate(0);
|
2020-12-06 14:21:56 +01:00
|
|
|
options::menu_check(Menu1_Full_Screen, 0);
|
2020-12-02 18:12:34 +01:00
|
|
|
options::Options.FullScreen = 0;
|
|
|
|
SetThreadPriority(GetCurrentThread(), 0);
|
|
|
|
Sound::Deactivate();
|
|
|
|
midi::music_stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_KILLFOCUS:
|
|
|
|
has_focus = 0;
|
|
|
|
gdrv::get_focus();
|
|
|
|
pb::loose_focus();
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_CREATE:
|
|
|
|
{
|
|
|
|
RECT rect{};
|
|
|
|
++memory::critical_allocation;
|
|
|
|
|
|
|
|
GetWindowRect(GetDesktopWindow(), &rect);
|
|
|
|
int width = rect.right - rect.left;
|
|
|
|
int height = rect.bottom - rect.top;
|
|
|
|
pb::window_size(&width, &height);
|
|
|
|
|
2020-12-11 17:03:13 +01:00
|
|
|
auto prevCursor = SetCursor(LoadCursorA(nullptr, IDC_WAIT));
|
2020-12-03 15:47:36 +01:00
|
|
|
gdrv::init(hinst, hWnd);
|
2020-12-02 18:12:34 +01:00
|
|
|
|
|
|
|
auto voiceCount = options::get_int(nullptr, "Voices", 8);
|
2020-12-03 15:47:36 +01:00
|
|
|
if (!Sound::Init(hinst, voiceCount, nullptr))
|
2020-12-06 14:21:56 +01:00
|
|
|
options::menu_set(Menu1_Sounds, 0);
|
2020-12-02 18:12:34 +01:00
|
|
|
Sound::Activate();
|
|
|
|
|
|
|
|
if (!pinball::quickFlag && !midi::music_init(hWnd))
|
2020-12-06 14:21:56 +01:00
|
|
|
options::menu_set(Menu1_Music, 0);
|
2020-12-02 18:12:34 +01:00
|
|
|
|
|
|
|
if (pb::init())
|
|
|
|
_exit(0);
|
|
|
|
SetCursor(prevCursor);
|
|
|
|
auto changeDisplayFg = options::get_int(nullptr, "Change Display", 1);
|
|
|
|
auto menuHandle = GetMenu(hWnd);
|
2020-12-27 16:19:36 +01:00
|
|
|
fullscrn::init(width, height, options::Options.FullScreen, hWnd, menuHandle,
|
2020-12-02 18:12:34 +01:00
|
|
|
changeDisplayFg);
|
|
|
|
|
|
|
|
--memory::critical_allocation;
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
case WM_MOVE:
|
|
|
|
no_time_loss = 1;
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_SETFOCUS:
|
|
|
|
has_focus = 1;
|
|
|
|
no_time_loss = 1;
|
|
|
|
gdrv::get_focus();
|
|
|
|
fullscrn::force_redraw();
|
|
|
|
pb::paint();
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
|
|
|
PAINTSTRUCT paint{};
|
|
|
|
_BeginPaint(hWnd, &paint);
|
|
|
|
fullscrn::paint();
|
|
|
|
EndPaint(hWnd, &paint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WM_CLOSE:
|
|
|
|
case WM_QUIT:
|
|
|
|
case WM_DESTROY:
|
|
|
|
end_pause();
|
|
|
|
bQuit = 1;
|
|
|
|
PostQuitMessage(0);
|
|
|
|
fullscrn::shutdown();
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_ERASEBKGND:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-06 15:06:13 +01:00
|
|
|
switch (Msg)
|
2020-12-02 18:12:34 +01:00
|
|
|
{
|
2021-01-06 15:06:13 +01:00
|
|
|
case WM_MENUSELECT:
|
|
|
|
if (lParam)
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
if (fullscrn::screen_mode)
|
|
|
|
fullscrn::set_menu_mode(0);
|
|
|
|
return 0;
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
no_time_loss = 1;
|
|
|
|
if (fullscrn::screen_mode)
|
|
|
|
fullscrn::set_menu_mode(1);
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_GETMINMAXINFO:
|
|
|
|
fullscrn::getminmaxinfo((MINMAXINFO*)lParam);
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_DISPLAYCHANGE:
|
|
|
|
if (fullscrn::displaychange())
|
2020-12-02 18:12:34 +01:00
|
|
|
{
|
2021-01-06 15:06:13 +01:00
|
|
|
options::Options.FullScreen = 0;
|
|
|
|
options::menu_check(Menu1_Full_Screen, 0);
|
|
|
|
}
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_KEYUP:
|
|
|
|
pb::keyup(wParam);
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
if (!(lParam & 0x40000000))
|
|
|
|
pb::keydown(wParam);
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case VK_ESCAPE:
|
|
|
|
if (options::Options.FullScreen)
|
|
|
|
options::toggle(0x193u);
|
|
|
|
SendMessageA(hwnd_frame, 0x112u, 0xF020u, 0);
|
|
|
|
break;
|
|
|
|
case VK_F1:
|
|
|
|
help_introduction(hinst, hWnd);
|
|
|
|
break;
|
|
|
|
case VK_F2:
|
|
|
|
new_game();
|
|
|
|
break;
|
|
|
|
case VK_F3:
|
|
|
|
pause();
|
|
|
|
break;
|
|
|
|
case VK_F4:
|
|
|
|
options::toggle(0x193u);
|
|
|
|
break;
|
|
|
|
case VK_F8:
|
|
|
|
if (!single_step)
|
|
|
|
pause();
|
|
|
|
options::keyboard();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!pb::cheat_mode)
|
2020-12-02 18:12:34 +01:00
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
2021-01-06 15:06:13 +01:00
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case 'H':
|
|
|
|
DispGRhistory = 1;
|
2020-12-02 18:12:34 +01:00
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
2021-01-06 15:06:13 +01:00
|
|
|
case 'Y':
|
|
|
|
SetWindowTextA(hWnd, "Pinball");
|
|
|
|
DispFrameRate = DispFrameRate == 0;
|
2020-12-02 18:12:34 +01:00
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
2021-01-06 15:06:13 +01:00
|
|
|
case VK_F1:
|
|
|
|
pb::frame(10);
|
2020-12-02 18:12:34 +01:00
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
2021-01-06 15:06:13 +01:00
|
|
|
case VK_F15:
|
|
|
|
single_step = single_step == 0;
|
|
|
|
if (single_step == 0)
|
|
|
|
no_time_loss = 1;
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
default:
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
switch (wParam & 0xFFF0)
|
|
|
|
{
|
|
|
|
case SC_MOVE:
|
|
|
|
if (fullscrn::screen_mode)
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case SC_MINIMIZE:
|
|
|
|
if (!single_step)
|
2020-12-02 18:12:34 +01:00
|
|
|
pause();
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
2021-01-06 15:06:13 +01:00
|
|
|
case SC_SCREENSAVE:
|
|
|
|
fullscrn::activate(0);
|
2020-12-02 18:12:34 +01:00
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
2021-01-06 15:06:13 +01:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
end_pause();
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_INITMENU:
|
|
|
|
no_time_loss = 1;
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_COMMAND:
|
|
|
|
no_time_loss = 1;
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case Menu1_Launch_Ball:
|
|
|
|
end_pause();
|
|
|
|
pb::launch_ball();
|
|
|
|
break;
|
|
|
|
case Menu1_Pause_Resume_Game:
|
|
|
|
pause();
|
|
|
|
break;
|
|
|
|
case Menu1_Demo:
|
|
|
|
end_pause();
|
|
|
|
pb::toggle_demo();
|
|
|
|
break;
|
|
|
|
case Menu1_Select_Table:
|
2020-12-02 18:12:34 +01:00
|
|
|
{
|
2021-01-06 15:06:13 +01:00
|
|
|
if (!single_step)
|
|
|
|
pause();
|
|
|
|
auto tmpBuf = memory::allocate(0x1F4u);
|
|
|
|
if (tmpBuf)
|
2020-12-02 18:12:34 +01:00
|
|
|
{
|
2021-01-06 15:06:13 +01:00
|
|
|
char cmdLine[0x1F4u];
|
|
|
|
options::get_string(nullptr, "Shell Exe", tmpBuf, pinball::WindowName, 500);
|
|
|
|
sprintf_s(
|
|
|
|
cmdLine,
|
|
|
|
"%s %s%lX %s%lX",
|
|
|
|
tmpBuf,
|
|
|
|
"select=",
|
|
|
|
(int)hwnd_frame,
|
|
|
|
"confirm=",
|
|
|
|
(int)hwnd_frame
|
|
|
|
* (int)hwnd_frame
|
|
|
|
* (int)hwnd_frame
|
|
|
|
* (int)hwnd_frame
|
|
|
|
* (int)hwnd_frame
|
|
|
|
* (int)hwnd_frame
|
|
|
|
* (int)hwnd_frame);
|
|
|
|
if (static_cast<int>(WinExec(cmdLine, 5u)) < 32)
|
2020-12-02 18:12:34 +01:00
|
|
|
{
|
2021-01-06 15:06:13 +01:00
|
|
|
auto caption = pinball::get_rc_string(170, 0);
|
|
|
|
auto text = pinball::get_rc_string(171, 0);
|
|
|
|
MessageBoxA(hwnd_frame, text, caption, 0x2010u);
|
2020-12-02 18:12:34 +01:00
|
|
|
}
|
2021-01-06 15:06:13 +01:00
|
|
|
memory::free(tmpBuf);
|
2020-12-02 18:12:34 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-01-06 15:06:13 +01:00
|
|
|
case Menu1_1Player:
|
|
|
|
case Menu1_2Players:
|
|
|
|
case Menu1_3Players:
|
|
|
|
case Menu1_4Players:
|
|
|
|
options::toggle(wParam);
|
|
|
|
new_game();
|
2020-12-02 18:12:34 +01:00
|
|
|
break;
|
2021-01-06 15:06:13 +01:00
|
|
|
case Menu1_Help_Topics:
|
|
|
|
if (!single_step)
|
|
|
|
pause();
|
|
|
|
help_introduction(hinst, hWnd);
|
|
|
|
break;
|
|
|
|
case 106: // End game button?
|
|
|
|
pb::end_game();
|
|
|
|
break;
|
|
|
|
case Menu1_Full_Screen:
|
|
|
|
case Menu1_Sounds:
|
|
|
|
case Menu1_Music:
|
|
|
|
if (!single_step)
|
|
|
|
pause();
|
|
|
|
options::toggle(wParam);
|
|
|
|
break;
|
|
|
|
case Menu1_Player_Controls:
|
|
|
|
case 204: // Second controls button?
|
|
|
|
if (!single_step)
|
|
|
|
pause();
|
|
|
|
options::keyboard();
|
|
|
|
break;
|
|
|
|
case Menu1_Exit:
|
|
|
|
PostMessageA(hWnd, WM_QUIT, 0, 0);
|
|
|
|
break;
|
|
|
|
case Menu1_New_Game:
|
|
|
|
new_game();
|
|
|
|
break;
|
|
|
|
case Menu1_About_Pinball:
|
|
|
|
if (!single_step)
|
|
|
|
pause();
|
|
|
|
a_dialog(hinst, hWnd);
|
2020-12-02 18:12:34 +01:00
|
|
|
break;
|
2021-01-06 15:06:13 +01:00
|
|
|
case Menu1_High_Scores:
|
|
|
|
if (!single_step)
|
|
|
|
pause();
|
|
|
|
pb::high_scores();
|
|
|
|
break;
|
|
|
|
case 1: // Unknown button
|
|
|
|
midi::restart_midi_seq(lParam);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
if (pb::game_mode)
|
|
|
|
{
|
|
|
|
if (pb::cheat_mode)
|
2020-12-02 18:12:34 +01:00
|
|
|
{
|
2021-01-06 15:06:13 +01:00
|
|
|
mouse_down = 1;
|
|
|
|
mouse_hsave = SetCursor(nullptr);
|
|
|
|
auto mouseXY = fullscrn::convert_mouse_pos(lParam);
|
|
|
|
last_mouse_x = mouseXY & 0xffFFu;
|
|
|
|
last_mouse_y = mouseXY >> 16;
|
|
|
|
SetCapture(hWnd);
|
2020-12-02 18:12:34 +01:00
|
|
|
}
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
2021-01-06 15:06:13 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
if (mouse_down)
|
|
|
|
{
|
|
|
|
mouse_down = 0;
|
|
|
|
SetCursor(mouse_hsave);
|
|
|
|
ReleaseCapture();
|
|
|
|
}
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
if (pb::game_mode)
|
2020-12-02 18:12:34 +01:00
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
2021-01-06 15:06:13 +01:00
|
|
|
break;
|
|
|
|
case WM_POWERBROADCAST:
|
|
|
|
if (wParam == 4 && options::Options.FullScreen)
|
|
|
|
{
|
|
|
|
options::Options.FullScreen = 0;
|
|
|
|
options::menu_check(Menu1_Full_Screen, 0);
|
|
|
|
fullscrn::set_screen_mode(options::Options.FullScreen);
|
2020-12-02 18:12:34 +01:00
|
|
|
}
|
2021-01-06 15:06:13 +01:00
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_PALETTECHANGED:
|
|
|
|
InvalidateRect(hWnd, nullptr, 0);
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
case WM_POINTERDEVICEINRANGE | LB_ADDSTRING:
|
|
|
|
if (wParam == 1)
|
|
|
|
midi::restart_midi_seq(lParam);
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
default:
|
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
2020-12-02 18:12:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pb::mode_countdown(-1);
|
2020-11-06 14:56:32 +01:00
|
|
|
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:41:14 +01:00
|
|
|
int winmain::ProcessWindowMessages()
|
2020-11-06 14:56:32 +01:00
|
|
|
{
|
2020-12-27 16:19:36 +01:00
|
|
|
MSG Msg{};
|
2020-11-06 14:56:32 +01:00
|
|
|
|
2020-11-29 16:50:49 +01:00
|
|
|
if (has_focus && !single_step)
|
2020-11-06 14:56:32 +01:00
|
|
|
{
|
|
|
|
while (PeekMessageA(&Msg, nullptr, 0, 0, 1u))
|
|
|
|
{
|
|
|
|
TranslateMessage(&Msg);
|
|
|
|
DispatchMessageA(&Msg);
|
|
|
|
if (Msg.message == 18)
|
|
|
|
{
|
|
|
|
return_value = Msg.wParam;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2020-12-03 15:47:36 +01:00
|
|
|
GetMessageA(&Msg, hwnd_frame, 0, 0);
|
2020-11-06 14:56:32 +01:00
|
|
|
TranslateMessage(&Msg);
|
|
|
|
DispatchMessageA(&Msg);
|
|
|
|
if (Msg.message == 18)
|
|
|
|
{
|
|
|
|
return_value = Msg.wParam;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2020-11-05 16:44:34 +01:00
|
|
|
}
|
|
|
|
|
2020-11-07 16:41:14 +01:00
|
|
|
void winmain::memalloc_failure()
|
2020-11-05 16:44:34 +01:00
|
|
|
{
|
2020-12-02 18:12:34 +01:00
|
|
|
midi::music_stop();
|
|
|
|
Sound::Close();
|
2020-11-13 17:04:58 +01:00
|
|
|
gdrv::uninit();
|
2020-11-05 16:44:34 +01:00
|
|
|
char* caption = pinball::get_rc_string(170, 0);
|
|
|
|
char* text = pinball::get_rc_string(179, 0);
|
|
|
|
MessageBoxA(nullptr, text, caption, 0x2030u);
|
|
|
|
_exit(1);
|
|
|
|
}
|
2020-11-07 16:41:14 +01:00
|
|
|
|
|
|
|
int winmain::check_expiration_date()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HDC winmain::_BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint)
|
|
|
|
{
|
|
|
|
HDC context = BeginPaint(hWnd, lpPaint);
|
|
|
|
if (hWnd && GetLayout(context) & 1)
|
|
|
|
SetLayout(context, 0);
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
HDC winmain::_GetDC(HWND hWnd)
|
|
|
|
{
|
|
|
|
HDC context = GetDC(hWnd);
|
|
|
|
if (hWnd && GetLayout(context) & 1)
|
|
|
|
SetLayout(context, 0);
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
int winmain::a_dialog(HINSTANCE hInstance, HWND hWnd)
|
|
|
|
{
|
|
|
|
char appName[100];
|
|
|
|
char szOtherStuff[100];
|
|
|
|
|
|
|
|
lstrcpyA(appName, pinball::get_rc_string(38, 0));
|
|
|
|
lstrcpyA(szOtherStuff, pinball::get_rc_string(102, 0));
|
|
|
|
auto icon = LoadIconA(hInstance, "ICON_1");
|
|
|
|
return ShellAboutA(hWnd, appName, szOtherStuff, icon);
|
|
|
|
}
|
2020-12-02 18:12:34 +01:00
|
|
|
|
|
|
|
void winmain::end_pause()
|
|
|
|
{
|
|
|
|
if (single_step)
|
|
|
|
{
|
|
|
|
if (fullscrn::screen_mode)
|
|
|
|
fullscrn::set_menu_mode(0);
|
|
|
|
pb::pause_continue();
|
|
|
|
no_time_loss = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void winmain::new_game()
|
|
|
|
{
|
|
|
|
end_pause();
|
2020-12-11 17:03:13 +01:00
|
|
|
HCURSOR prevCursor = SetCursor(LoadCursorA(nullptr, IDC_WAIT));
|
2020-12-02 18:12:34 +01:00
|
|
|
pb::replay_level(0);
|
|
|
|
SetCursor(prevCursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void winmain::pause()
|
|
|
|
{
|
|
|
|
if (fullscrn::screen_mode)
|
|
|
|
{
|
|
|
|
if (single_step)
|
|
|
|
fullscrn::set_menu_mode(0);
|
|
|
|
else
|
|
|
|
fullscrn::set_menu_mode(1);
|
|
|
|
}
|
|
|
|
pb::pause_continue();
|
|
|
|
no_time_loss = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void winmain::help_introduction(HINSTANCE a1, HWND a2)
|
|
|
|
{
|
|
|
|
char* buf1 = memory::allocate(0x1F4u);
|
|
|
|
if (buf1)
|
|
|
|
{
|
|
|
|
char* buf2 = memory::allocate(0x1F4u);
|
|
|
|
if (buf2)
|
|
|
|
{
|
|
|
|
options::get_string(nullptr, "HelpFile", buf1, pinball::get_rc_string(178, 0), 500);
|
|
|
|
options::get_string(pinball::get_rc_string(166, 0), "HelpFile", buf1, buf1, 500);
|
|
|
|
lstrcpyA(buf2, buf1);
|
|
|
|
memory::free(buf1);
|
|
|
|
HtmlHelpA(GetDesktopWindow(), buf2, 0, 0);
|
|
|
|
memory::free(buf2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memory::free(buf1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|