1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-17 15:20:17 +01:00

winmain message_handler v1.

This commit is contained in:
oz 2020-12-02 20:12:34 +03:00
parent d83c4e2b26
commit 9ffab95d8e
21 changed files with 871 additions and 28 deletions

Binary file not shown.

View file

@ -1,6 +1,11 @@
#include "pch.h"
#include "Sound.h"
int Sound::Init(HINSTANCE hInstance, int voices, void(__stdcall* someFuncPtr)(int, int, int))
{
return 1;
}
void Sound::Enable(int a1, int a2, int a3)
{
}
@ -12,3 +17,15 @@ void Sound::nullsub_1(int a1, int a2, int a3)
void Sound::Idle()
{
}
void Sound::Activate()
{
}
void Sound::Deactivate()
{
}
void Sound::Close()
{
}

View file

@ -2,7 +2,11 @@
class Sound
{
public:
static int Init(HINSTANCE hInstance, int voices, void (__stdcall* someFuncPtr)(int, int, int));
static void Enable(int a1, int a2, int a3);
static void nullsub_1(int a1, int a2, int a3);
static void Idle();
static void Activate();
static void Deactivate();
static void Close();
};

View file

@ -14,17 +14,16 @@
#include "score.h"
#include "TPinballTable.h"
#include "TTextBox.h"
#include "winmain.h"
int main()
{
std::cout << "Hello World!\n";
{
// Testing with UI
/* lstrcpyA(pinball::DatFileName, "PINBALL.DAT");
pinball::hinst = GetModuleHandleA(nullptr);
char cmdLine[1]{};
pb::init();
WinMain(pinball::hinst, 0, cmdLine, 10);*/
WinMain(pinball::hinst, 0, cmdLine, 10);
}
gdrv::init(0, 0);
@ -40,7 +39,7 @@ int main()
auto xx = sizeof(datFileHeader);
lstrcpyA(pinball::DatFileName, "PINBALL.DAT");
lstrcpyA(winmain::DatFileName, "PINBALL.DAT");
pb::init();
auto datFile = pb::record_table;

View file

@ -96,7 +96,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Comctl32.lib;Winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Comctl32.lib;Winmm.lib;Htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -131,6 +131,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Comctl32.lib;Winmm.lib;Htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -159,6 +160,8 @@
<ClInclude Include="loader.h" />
<ClInclude Include="maths.h" />
<ClInclude Include="memory.h" />
<ClInclude Include="midi.h" />
<ClInclude Include="nudge.h" />
<ClInclude Include="objlist_class.h" />
<ClInclude Include="options.h" />
<ClInclude Include="partman.h" />
@ -217,6 +220,8 @@
<ClCompile Include="loader.cpp" />
<ClCompile Include="maths.cpp" />
<ClCompile Include="memory.cpp" />
<ClCompile Include="midi.cpp" />
<ClCompile Include="nudge.cpp" />
<ClCompile Include="objlist_class.cpp" />
<ClCompile Include="options.cpp" />
<ClCompile Include="partman.cpp" />

View file

@ -201,6 +201,12 @@
<ClInclude Include="timer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="midi.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="nudge.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
@ -368,6 +374,12 @@
<ClCompile Include="timer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="midi.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="nudge.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Natvis Include="NatvisFile.natvis" />

View file

@ -28,6 +28,7 @@ public:
static int convert_mouse_pos(unsigned int mouseXY);
static void getminmaxinfo(MINMAXINFO* maxMin);
static void paint();
static bool set_menu_mode(int menuEnabled);
private :
static int MenuEnabled;
static HMENU MenuHandle;
@ -37,6 +38,5 @@ private :
static int setWindowFlagsDisDlg();
static int enableFullscreen();
static int disableFullscreen();
static bool set_menu_mode(int menuEnabled);
static void fillRect(int right, int bottom);
};

View file

@ -206,9 +206,10 @@ int gdrv::display_palette(PALETTEENTRY* plt)
{
if (plt)
{
pltDst->peRed = pltSrc->peRed;
// Todo: verify RGB order
pltDst->peRed = pltSrc->peBlue;
pltDst->peGreen = pltSrc->peGreen;
pltDst->peBlue = pltSrc->peBlue;
pltDst->peBlue = pltSrc->peRed;
}
pltDst->peFlags = 4;
pltSrc++;

View file

@ -0,0 +1,22 @@
#include "pch.h"
#include "midi.h"
MCIERROR midi::play_pb_theme(int flag)
{
return MCIERROR();
}
MCIERROR midi::music_stop()
{
return MCIERROR();
}
int midi::music_init(HWND hwnd)
{
return 1;
}
MCIERROR midi::restart_midi_seq(int param)
{
return MCIERROR();
}

9
SpaceCadetPinball/midi.h Normal file
View file

@ -0,0 +1,9 @@
#pragma once
class midi
{
public:
static MCIERROR play_pb_theme(int flag);
static MCIERROR music_stop();
static int music_init(HWND hwnd);
static MCIERROR restart_midi_seq(int param);
};

View file

@ -0,0 +1,26 @@
#include "pch.h"
#include "nudge.h"
void nudge::un_nudge_right(int x, int y)
{
}
void nudge::un_nudge_left(int x, int y)
{
}
void nudge::un_nudge_up(int x, int y)
{
}
void nudge::nudge_right()
{
}
void nudge::nudge_left()
{
}
void nudge::nudge_up()
{
}

12
SpaceCadetPinball/nudge.h Normal file
View file

@ -0,0 +1,12 @@
#pragma once
class nudge
{
public :
static void un_nudge_right(int x, int y);
static void un_nudge_left(int x, int y);
static void un_nudge_up(int x, int y);
static void nudge_right();
static void nudge_left();
static void nudge_up();
};

View file

@ -1,6 +1,9 @@
#include "pch.h"
#include "options.h"
#include "fullscrn.h"
#include "memory.h"
#include "midi.h"
#include "pinball.h"
#include "Sound.h"
@ -185,10 +188,62 @@ void options::set_string(LPCSTR optPath, LPCSTR lpValueName, LPCSTR value)
}
HMENU options::menu_check(UINT uIDCheckItem, int value)
void options::menu_check(UINT uIDCheckItem, int check)
{
HMENU result = MenuHandle;
if (MenuHandle)
result = (HMENU)CheckMenuItem(MenuHandle, uIDCheckItem, value != 0 ? 8 : 0);
return result;
CheckMenuItem(MenuHandle, uIDCheckItem, check != 0 ? 8 : 0);
}
void options::menu_set(UINT uIDEnableItem, int enable)
{
if (MenuHandle)
EnableMenuItem(MenuHandle, uIDEnableItem, enable == 0);
}
void options::toggle(UINT uIDCheckItem)
{
int newValue;
switch (uIDCheckItem)
{
case 0xC9u:
newValue = Options.Sounds == 0;
Options.Sounds = Options.Sounds == 0;
Sound::Enable(0, 7, newValue);
menu_check(uIDCheckItem, newValue);
return;
case 0xCAu:
newValue = Options.Music == 0;
Options.Music = Options.Music == 0;
if (!newValue)
midi::music_stop();
else
midi::play_pb_theme(0);
menu_check(uIDCheckItem, newValue);
return;
case 0x193u:
newValue = Options.FullScreen == 0;
Options.FullScreen = Options.FullScreen == 0;
fullscrn::set_screen_mode(newValue);
menu_check(uIDCheckItem, newValue);
return;
}
if (uIDCheckItem > 407 && uIDCheckItem <= 411)
{
Options.Players = uIDCheckItem - 407;
menu_check(0x198u, uIDCheckItem == 408);
menu_check(0x199u, Options.Players == 2);
menu_check(0x19Au, Options.Players == 3);
menu_check(0x19Bu, Options.Players == 4);
}
}
void options::keyboard()
{
DialogBoxParamA(pinball::hinst, "KEYMAPPER", pinball::hwnd_frame, KeyMapDlgProc, 0);
}
INT_PTR _stdcall options::KeyMapDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
return 0;
}

View file

@ -33,8 +33,12 @@ public:
static void set_int(LPCSTR optPath, LPCSTR lpValueName, int data);
static void get_string(LPCSTR optPath, LPCSTR lpValueName, LPSTR lpString1, LPCSTR lpString2, int iMaxLength);
static void set_string(LPCSTR optPath, LPCSTR lpValueName, LPCSTR value);
static HMENU menu_check(UINT uIDCheckItem, int value);
static void menu_check(UINT uIDCheckItem, int check);
static void menu_set(UINT uIDEnableItem, int enable);
static void toggle(UINT uIDCheckItem);
static void keyboard();
static INT_PTR _stdcall KeyMapDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
static optionsStruct Options;
private:
static LPCSTR OptionsRegPath;

View file

@ -6,12 +6,17 @@
#include "proj.h"
#include "render.h"
#include "loader.h"
#include "midi.h"
#include "nudge.h"
#include "options.h"
#include "timer.h"
#include "winmain.h"
TPinballTable* pb::MainTable = nullptr;
datFileStruct* pb::record_table = nullptr;
int pb::time_ticks = 0, pb::demo_mode = 0;
int pb::time_ticks = 0, pb::demo_mode = 0, pb::cheat_mode = 0, pb::game_mode = 2, pb::mode_countdown_, pb::
ball_speed_limit;
float pb::time_now, pb::time_next;
int pb::init()
{
@ -20,7 +25,7 @@ int pb::init()
CHAR dataFilePath[300];
++memory::critical_allocation;
lstrcpyA(datFileName, pinball::DatFileName);
lstrcpyA(datFileName, winmain::DatFileName);
pinball::make_path_name(dataFilePath, datFileName, 300);
record_table = partman::load_records(dataFilePath);
@ -53,6 +58,7 @@ int pb::init()
}
render::init(nullptr, zMin, zScaler, tableSize[0], tableSize[1]);
gdrv::fill_bitmap(&render::vscreen, render::vscreen.Width, render::vscreen.Height, 0, 0, 0xff); // temp
gdrv::copy_bitmap(
&render::vscreen,
backgroundBmp->Width,
@ -130,15 +136,249 @@ void pb::replay_level(int demoMode)
demo_mode = demoMode;
mode_change(1);
//if (options::Options.Music)
//midi_play_pb_theme(0);
midi::play_pb_theme(0);
MainTable->Message(1014, static_cast<float>(options::Options.Players));
}
void pb::ballset(int x, int y)
{
{
}
int pb::frame(int time)
{
if (time > 100)
time = 100;
float timeMul = time * 0.001f;
if (!mode_countdown(time))
{
time_next = time_now + timeMul;
//pb::timed_frame(time_now, timeMul, 1);
time_now = time_next;
time_ticks += time;
/*if (nudged_left || nudged_right || nudged_up)
{
nudge_count = timeMul * 4.0 + nudge_count;
}
else
{
v2 = nudge_count - timeMul;
if (v2 <= 0.0)
v2 = 0.0;
nudge_count = v2;
}*/
//timer::check();
render::update();
//score::update(MainTable->Score1);
/*if (!MainTable->UnknownP83)
{
if (nudge_count > 0.5)
{
v3 = pinball:: get_rc_string(25, 0);
pinball::InfoTextBox->Display( v3, 2.0);
}
if (nudge_count > 1.0)
TPinballTable::tilt(MainTable, v1, time_now);
}*/
}
return 1;
}
}
void pb::window_size(int* width, int* height)
{
*width = 600;
*height = 416;
}
void pb::pause_continue()
{
winmain::single_step = winmain::single_step == 0;
pinball::InfoTextBox->Clear();
pinball::MissTextBox->Clear();
if (winmain::single_step)
{
if (MainTable)
MainTable->Message(1008, time_now);
pinball::InfoTextBox->Display(pinball::get_rc_string(22, 0), -1.0);
midi::music_stop();
}
else
{
if (MainTable)
MainTable->Message(1009, 0.0);
if (!demo_mode)
{
char* text;
float textTime;
if (game_mode == 2)
{
textTime = -1.0;
text = pinball::get_rc_string(24, 0);
}
else
{
textTime = 5.0;
text = pinball::get_rc_string(23, 0);
}
pinball::InfoTextBox->Display(text, textTime);
}
if (options::Options.Music && !winmain::single_step)
midi::play_pb_theme(0);
}
}
void pb::loose_focus()
{
if (MainTable)
MainTable->Message(1010, time_now);
}
void pb::keyup(int key)
{
if (game_mode == 1 && !winmain::single_step && !demo_mode)
{
if (key == options::Options.LeftFlipperKey)
{
MainTable->Message(1001, time_now);
}
else if (key == options::Options.RightFlipperKey)
{
MainTable->Message(1003, time_now);
}
else if (key == options::Options.PlungerKey)
{
MainTable->Message(1005, time_now);
}
else if (key == options::Options.LeftTableBumpKey)
{
nudge::un_nudge_right(0, 0);
}
else if (key == options::Options.RightTableBumpKey)
{
nudge::un_nudge_left(0, 0);
}
else if (key == options::Options.BottomTableBumpKey)
{
nudge::un_nudge_up(0, 0);
}
}
}
void pb::keydown(int key)
{
if (winmain::single_step || demo_mode)
return;
if (game_mode != 1)
{
mode_countdown(-1);
return;
}
ctrl_bdoor_controller(key);
if (key == options::Options.LeftFlipperKey)
{
MainTable->Message(1000, time_now);
return;
}
if (key == options::Options.RightFlipperKey)
{
MainTable->Message(1002, time_now);
}
else
{
if (key == options::Options.PlungerKey)
{
MainTable->Message(1004, time_now);
return;
}
if (key == options::Options.LeftTableBumpKey)
{
if (!MainTable->UnknownP83)
nudge::nudge_right();
return;
}
if (key == options::Options.RightTableBumpKey)
{
if (!MainTable->UnknownP83)
nudge::nudge_left();
return;
}
if (key == options::Options.BottomTableBumpKey)
{
if (!MainTable->UnknownP83)
nudge::nudge_up();
return;
}
}
if (cheat_mode)
{
switch (key)
{
case 'B':
/**/
break;
case 'H':
/*auto v1 = get_rc_string(26, 0);
lstrcpyA(&String1, v1);
show_and_set_high_score_dialog(highscore_table, 1000000000, 1, &String1);*/
break;
case 'M':
char buffer[20];
sprintf_s(buffer, "%ld", memory::use_total);
MessageBoxA(pinball::hwnd_frame, buffer, "Mem:", 0x2000u);
break;
case 'R':
cheat_bump_rank();
break;
case VK_F11:
gdrv::get_focus();
break;
case VK_F12:
MainTable->port_draw();
break;
}
}
}
void pb::ctrl_bdoor_controller(int key)
{
}
int pb::mode_countdown(int time)
{
if (!game_mode || game_mode <= 0)
return 1;
if (game_mode > 2)
{
if (game_mode == 3)
{
mode_countdown_ -= time;
if (mode_countdown_ < 0 || time < 0)
mode_change(4);
}
else if (game_mode == 4)
{
mode_countdown_ -= time;
if (mode_countdown_ < 0 || time < 0)
mode_change(1);
}
return 1;
}
return 0;
}
int pb::cheat_bump_rank()
{
return 0;
}
void pb::launch_ball()
{
}
int pb::end_game()
{
return 0;
}
void pb::high_scores()
{
}

View file

@ -7,6 +7,7 @@ class pb
public:
static int time_ticks;
static int ball_speed_limit;
static int cheat_mode, game_mode;
static datFileStruct* record_table;
static TPinballTable* MainTable;
@ -19,6 +20,18 @@ public:
static void replay_level(int demoMode);
static void ballset(int x, int y);
static int frame(int time);
static void window_size(int* width, int* height);
static void pause_continue();
static void loose_focus();
static void keyup(int key);
static void keydown(int key);
static void ctrl_bdoor_controller(int key);
static int mode_countdown(int time);
static int cheat_bump_rank();
static void launch_ball();
static int end_game();
static void high_scores();
private :
static int demo_mode;
static int demo_mode, mode_countdown_;
static float time_now, time_next;
};

View file

@ -15,6 +15,7 @@
#include <cassert>
#include <cmath>
#include <CommCtrl.h>
#include <htmlhelp.h>
//#include <cstdlib>
// Use (void) to silent unused warnings.

View file

@ -10,7 +10,6 @@ char pinball::getRcBuffer[6 * 256];
int pinball::rc_string_slot = 0;
HINSTANCE pinball::hinst;
char pinball::WindowName[2]{};
char pinball::DatFileName[300]{};
int pinball::LeftShift = -1;
int pinball::RightShift = -1;
HWND pinball::hwnd_frame = nullptr;

View file

@ -9,7 +9,6 @@ public:
static TTextBox* MissTextBox;
static HINSTANCE hinst;
static char WindowName[2];
static char DatFileName[300];
static int RightShift;
static int LeftShift;
static HWND hwnd_frame;

View file

@ -3,16 +3,20 @@
#include "fullscrn.h"
#include "memory.h"
#include "midi.h"
#include "pinball.h"
#include "options.h"
#include "pb.h"
#include "Sound.h"
int winmain::iFrostUniqueMsg, winmain::return_value = 0, winmain::bQuit = 0;
int winmain::return_value = 0, winmain::bQuit = 0, winmain::activated;
DWORD winmain::then, winmain::now;
UINT winmain::iFrostUniqueMsg;
gdrv_bitmap8 winmain::gfr_display{};
int winmain::DispFrameRate = 1, winmain::DispGRhistory = 1, winmain::single_step = 0;
int winmain::has_focus = 1, winmain::last_mouse_x, winmain::last_mouse_y, winmain::mouse_down, winmain::no_time_loss;
char winmain::DatFileName[300]{};
HCURSOR winmain::mouse_hsave;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
@ -89,7 +93,7 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
pinball::quickFlag = strstr(lpCmdLine, "-quick") != nullptr;
pinball::hinst = hInstance;
options::get_string(regSpaceCadet, "Pinball Data", pinball::DatFileName, pinball::get_rc_string(168, 0), 300);
options::get_string(regSpaceCadet, "Pinball Data", DatFileName, pinball::get_rc_string(168, 0), 300);
iFrostUniqueMsg = RegisterWindowMessageA("PinballThemeSwitcherUniqueMsgString");
auto windowHandle = FindWindowA(pinball::get_rc_string(167, 0), nullptr);
@ -272,6 +276,364 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
LRESULT CALLBACK winmain::message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (Msg == iFrostUniqueMsg)
{
if (IsIconic(hWnd))
ShowWindow(hWnd, 9);
SetForegroundWindow(hWnd);
return 0;
}
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);
options::menu_check(0x193u, 0);
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);
auto prevCursor = SetCursor(LoadCursorA(nullptr, (LPCSTR)IDC_WAIT));
gdrv::init(pinball::hinst, hWnd);
auto voiceCount = options::get_int(nullptr, "Voices", 8);
if (!Sound::Init(pinball::hinst, voiceCount, nullptr))
options::menu_set(0xC9u, 0);
Sound::Activate();
if (!pinball::quickFlag && !midi::music_init(hWnd))
options::menu_set(0xCAu, 0);
if (pb::init())
_exit(0);
SetCursor(prevCursor);
auto changeDisplayFg = options::get_int(nullptr, "Change Display", 1);
auto menuHandle = GetMenu(hWnd);
fullscrn::init(width, static_cast<int>(height), options::Options.FullScreen, hWnd, menuHandle,
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;
}
if (Msg <= WM_MENUSELECT)
{
switch (Msg)
{
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())
{
options::Options.FullScreen = 0;
options::menu_check(0x193u, 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(pinball::hwnd_frame, 0x112u, 0xF020u, 0);
break;
case VK_F1:
help_introduction(pinball::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)
return DefWindowProcA(hWnd, Msg, wParam, lParam);
switch (wParam)
{
case 'H':
DispGRhistory = 1;
return DefWindowProcA(hWnd, Msg, wParam, lParam);
case 'Y':
SetWindowTextA(hWnd, "Pinball");
DispFrameRate = DispFrameRate == 0;
return DefWindowProcA(hWnd, Msg, wParam, lParam);
case VK_F1:
pb::frame(10);
return DefWindowProcA(hWnd, Msg, wParam, lParam);
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;
case SC_MINIMIZE:
if (!single_step)
pause();
return DefWindowProcA(hWnd, Msg, wParam, lParam);
case SC_SCREENSAVE:
fullscrn::activate(0);
return DefWindowProcA(hWnd, Msg, wParam, lParam);
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 0x191u:
end_pause();
pb::launch_ball();
break;
case 0x192u:
pause();
break;
case 0x193u:
if (!single_step)
pause();
options::toggle(wParam);
break;
case 0x194u:
end_pause();
pb::toggle_demo();
break;
case 0x195u:
{
if (!single_step)
pause();
auto tmpBuf = memory::allocate(0x1F4u);
if (tmpBuf)
{
char cmdLine[0x1F4u];
options::get_string(nullptr, "Shell Exe", tmpBuf, pinball::WindowName, 500);
sprintf_s(
cmdLine,
"%s %s%lX %s%lX",
tmpBuf,
"select=",
(int)pinball::hwnd_frame,
"confirm=",
(int)pinball::hwnd_frame
* (int)pinball::hwnd_frame
* (int)pinball::hwnd_frame
* (int)pinball::hwnd_frame
* (int)pinball::hwnd_frame
* (int)pinball::hwnd_frame
* (int)pinball::hwnd_frame);
if (static_cast<int>(WinExec(cmdLine, 5u)) < 32)
{
auto caption = pinball::get_rc_string(170, 0);
auto text = pinball::get_rc_string(171, 0);
MessageBoxA(pinball::hwnd_frame, text, caption, 0x2010u);
}
memory::free(tmpBuf);
}
break;
}
case 0x196u:
if (!single_step)
pause();
options::keyboard();
break;
case 0x198u:
case 0x199u:
case 0x19Au:
case 0x19Bu:
options::toggle(wParam);
new_game();
break;
case 301:
if (!single_step)
pause();
help_introduction(pinball::hinst, hWnd);
return DefWindowProcA(hWnd, Msg, wParam, lParam);
case 0x6A:
pb::end_game();
return DefWindowProcA(hWnd, Msg, wParam, lParam);
case 201:
case 202:
if (!single_step)
pause();
options::toggle(wParam);
break;
case 204:
if (!single_step)
pause();
options::keyboard();
break;
case 0x69u:
PostMessageA(hWnd, 0x12u, 0, 0);
return DefWindowProcA(hWnd, Msg, wParam, lParam);
case 0x65u:
new_game();
return DefWindowProcA(hWnd, Msg, wParam, lParam);
case 0x66u:
if (!single_step)
pause();
a_dialog(pinball::hinst, hWnd);
return DefWindowProcA(hWnd, Msg, wParam, lParam);
case 0x67u:
if (!single_step)
pause();
pb::high_scores();
return DefWindowProcA(hWnd, Msg, wParam, lParam);
case 1:
midi::restart_midi_seq(lParam);
default:
break;
}
return DefWindowProcA(hWnd, Msg, wParam, lParam);
case WM_LBUTTONDOWN:
if (pb::game_mode)
{
if (pb::cheat_mode)
{
mouse_down = 1;
mouse_hsave = SetCursor(nullptr);
auto lParam2 = fullscrn::convert_mouse_pos(lParam);
last_mouse_x = static_cast<unsigned __int16>(lParam2);
last_mouse_y = static_cast<unsigned int>(lParam2) >> 16;
SetCapture(hWnd);
}
return DefWindowProcA(hWnd, Msg, wParam, lParam);
}
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)
return DefWindowProcA(hWnd, Msg, wParam, lParam);
break;
case WM_POWERBROADCAST:
if (wParam == 4 && options::Options.FullScreen)
{
options::Options.FullScreen = 0;
options::menu_check(0x193u, 0);
fullscrn::set_screen_mode(options::Options.FullScreen);
}
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);
}
}
pb::mode_countdown(-1);
return DefWindowProcA(hWnd, Msg, wParam, lParam);
}
@ -306,8 +668,8 @@ int winmain::ProcessWindowMessages()
void winmain::memalloc_failure()
{
/*midi_music_stop();
Sound_Close();*/
midi::music_stop();
Sound::Close();
gdrv::uninit();
char* caption = pinball::get_rc_string(170, 0);
char* text = pinball::get_rc_string(179, 0);
@ -347,3 +709,57 @@ int winmain::a_dialog(HINSTANCE hInstance, HWND hWnd)
auto icon = LoadIconA(hInstance, "ICON_1");
return ShellAboutA(hWnd, appName, szOtherStuff, icon);
}
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();
HCURSOR prevCursor = SetCursor(LoadCursorA(nullptr, (LPCSTR)IDC_WAIT));
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);
}
}
}

View file

@ -4,6 +4,9 @@
class winmain
{
public:
static char DatFileName[300];
static int single_step;
static int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
static LRESULT CALLBACK message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
static void memalloc_failure();
@ -11,11 +14,17 @@ public:
static int check_expiration_date();
static HDC _GetDC(HWND hWnd);
static int a_dialog(HINSTANCE hInstance, HWND hWnd);
static void end_pause();
static void new_game();
static void pause();
static void help_introduction(HINSTANCE a1, HWND a2);
private:
static int iFrostUniqueMsg, return_value, bQuit, DispFrameRate, DispGRhistory;
static int has_focus, single_step, mouse_down, last_mouse_x, last_mouse_y, no_time_loss;
static int return_value, bQuit, DispFrameRate, DispGRhistory, activated;
static int has_focus, mouse_down, last_mouse_x, last_mouse_y, no_time_loss;
static DWORD then, now;
static UINT iFrostUniqueMsg;
static gdrv_bitmap8 gfr_display;
static HCURSOR mouse_hsave;
static HDC _BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint);
};