Removed windows.h dependency.
Added support for music in MDS format.
This commit is contained in:
@@ -15,7 +15,7 @@ int Sound::Init(int voices)
|
||||
num_channels = channelCount;
|
||||
enabled_flag = -1;
|
||||
|
||||
return Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) == -1;
|
||||
return Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
|
||||
}
|
||||
|
||||
void Sound::Enable(int channelFrom, int channelTo, int enableFlag)
|
||||
|
||||
@@ -38,7 +38,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
auto xx = sizeof(datFileHeader);
|
||||
|
||||
lstrcpyA(winmain::DatFileName, "PINBALL.DAT");
|
||||
strcpy_s(winmain::DatFileName, "PINBALL.DAT");
|
||||
pb::init();
|
||||
auto datFile = pb::record_table;
|
||||
|
||||
|
||||
@@ -229,14 +229,14 @@ TPinballComponent* TPinballTable::find_component(LPCSTR componentName)
|
||||
for (int index = 0; index < objCount; ++index)
|
||||
{
|
||||
TPinballComponent* obj = ComponentList->Get(index);
|
||||
const CHAR* groupName = obj->GroupName;
|
||||
if (groupName && !lstrcmpA(groupName, componentName))
|
||||
const char* groupName = obj->GroupName;
|
||||
if (groupName && !strcmp(groupName, componentName))
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
MessageBoxA(nullptr, "Table cant find:", componentName, 0x2000u);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find:", componentName, nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ TPinballComponent* TPinballTable::find_component(int groupIndex)
|
||||
}
|
||||
}
|
||||
_itoa_s(groupIndex, Buffer, 10);
|
||||
MessageBoxA(nullptr, "Table cant find (lh):", Buffer, 0x2000u);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find (lh):", Buffer, nullptr);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,9 +117,8 @@ int fullscrn::get_max_supported_resolution()
|
||||
if (!pb::FullTiltMode)
|
||||
return 0;
|
||||
|
||||
auto resolutionWH = get_screen_resolution();
|
||||
auto width = LOWORD(resolutionWH);
|
||||
auto height = HIWORD(resolutionWH);
|
||||
int width = 0, height = 0;
|
||||
get_screen_resolution(&width, &height);
|
||||
auto result = 0;
|
||||
|
||||
for (auto index = 1; index < 3; ++index)
|
||||
@@ -131,10 +130,16 @@ int fullscrn::get_max_supported_resolution()
|
||||
return result;
|
||||
}
|
||||
|
||||
int fullscrn::get_screen_resolution()
|
||||
int fullscrn::get_screen_resolution(int* width, int* height)
|
||||
{
|
||||
auto height = static_cast<uint16_t>(GetSystemMetrics(SM_CYSCREEN));
|
||||
return static_cast<uint16_t>(GetSystemMetrics(SM_CXSCREEN)) | (height << 16);
|
||||
SDL_DisplayMode dm;
|
||||
if (SDL_GetDesktopDisplayMode(0, &dm) == 0)
|
||||
{
|
||||
*width = dm.w;
|
||||
*height = dm.h;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void fullscrn::window_size_changed()
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
static int GetMaxResolution();
|
||||
static void SetMaxResolution(int resolution);
|
||||
static int get_max_supported_resolution();
|
||||
static int get_screen_resolution();
|
||||
static int get_screen_resolution(int* width, int* height);
|
||||
static void window_size_changed();
|
||||
private :
|
||||
static int resolution;
|
||||
|
||||
@@ -33,17 +33,6 @@ union ColorRgba
|
||||
};
|
||||
static_assert(sizeof(ColorRgba) == 4, "Wrong size of RGBA color");
|
||||
|
||||
struct LOGPALETTEx256 : LOGPALETTE
|
||||
{
|
||||
PALETTEENTRY palPalEntry2[256 - 1];
|
||||
|
||||
LOGPALETTEx256() : palPalEntry2{}
|
||||
{
|
||||
palVersion = 0x300;
|
||||
palNumEntries = 256;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class gdrv
|
||||
{
|
||||
|
||||
@@ -54,15 +54,15 @@ int high_score::read(high_score_struct* table, int* ptrToSmth)
|
||||
{
|
||||
auto tablePtr = &table[position];
|
||||
_itoa_s(position, Buffer, 10);
|
||||
lstrcatA(Buffer, ".Name");
|
||||
strcat_s(Buffer, ".Name");
|
||||
options::get_string(optPath, Buffer, buf1, "", 32);
|
||||
buf1[32] = 0;
|
||||
lstrcpyA(tablePtr->Name, buf1);
|
||||
strcpy_s(tablePtr->Name, buf1);
|
||||
_itoa_s(position, Buffer, 10);
|
||||
lstrcatA(Buffer, ".Score");
|
||||
strcat_s(Buffer, ".Score");
|
||||
options::get_string(optPath, Buffer, buf1, "", 300);
|
||||
tablePtr->Score = atol(buf1);
|
||||
for (int i = lstrlenA(tablePtr->Name); --i >= 0; scoreSum += tablePtr->Name[i])
|
||||
for (int i = (int)strlen(tablePtr->Name); --i >= 0; scoreSum += tablePtr->Name[i])
|
||||
{
|
||||
}
|
||||
scoreSum += tablePtr->Score;
|
||||
@@ -70,7 +70,7 @@ int high_score::read(high_score_struct* table, int* ptrToSmth)
|
||||
|
||||
scramble_number_string(scoreSum, buf1);
|
||||
options::get_string(optPath, "Verification", buf2, "", 300);
|
||||
if (lstrcmpA(buf1, buf2))
|
||||
if (strcmp(buf1, buf2) != 0)
|
||||
clear_table(table);
|
||||
memory::free(buf1);
|
||||
memory::free(buf2);
|
||||
@@ -83,20 +83,20 @@ int high_score::write(high_score_struct* table, int* ptrToSmth)
|
||||
|
||||
high_score_struct* tablePtr = table;
|
||||
int scoreSum = 0;
|
||||
CHAR* buf = memory::allocate(300u);
|
||||
char* buf = memory::allocate(300u);
|
||||
if (!buf)
|
||||
return 1;
|
||||
const CHAR* optPath = pinball::get_rc_string(166, 0);
|
||||
const char* optPath = pinball::get_rc_string(166, 0);
|
||||
for (auto position = 0; position < 5; ++position)
|
||||
{
|
||||
_itoa_s(position, Buffer, 10);
|
||||
lstrcatA(Buffer, ".Name");
|
||||
strcat_s(Buffer, ".Name");
|
||||
options::set_string(optPath, Buffer, tablePtr->Name);
|
||||
_itoa_s(position, Buffer, 10);
|
||||
lstrcatA(Buffer, ".Score");
|
||||
strcat_s(Buffer, ".Score");
|
||||
_ltoa_s(tablePtr->Score, buf, 300, 10);
|
||||
options::set_string(optPath, Buffer, buf);
|
||||
for (int i = lstrlenA(tablePtr->Name); --i >= 0; scoreSum += tablePtr->Name[i])
|
||||
for (int i = (int)strlen(tablePtr->Name); --i >= 0; scoreSum += tablePtr->Name[i])
|
||||
{
|
||||
}
|
||||
scoreSum += tablePtr->Score;
|
||||
@@ -150,9 +150,9 @@ int high_score::place_new_score_into(high_score_struct* table, int score, LPSTR
|
||||
}
|
||||
high_score_struct* posTable = &table[position];
|
||||
posTable->Score = score;
|
||||
if (lstrlenA(scoreStr) >= 31)
|
||||
if (strlen(scoreStr) >= 31)
|
||||
scoreStr[31] = 0;
|
||||
lstrcpyA(posTable->Name, scoreStr);
|
||||
strcpy_s(posTable->Name, scoreStr);
|
||||
posTable->Name[31] = 0;
|
||||
}
|
||||
return position;
|
||||
|
||||
@@ -12,8 +12,7 @@ errorMsg loader::loader_errors[] =
|
||||
{
|
||||
errorMsg{0, "Bad Handle"},
|
||||
errorMsg{1, "No Type Field"},
|
||||
errorMsg{2, "No Attributes Field"},
|
||||
errorMsg{0x0B, "No float Attributes Field"},
|
||||
errorMsg{2, "No Attributes Field"},
|
||||
errorMsg{3, "Wrong Type: MATERIAL Expected"},
|
||||
errorMsg{4, "Wrong Type: KICKER Expected"},
|
||||
errorMsg{5, "Wrong Type: AN_OBJECT Expected"},
|
||||
@@ -21,6 +20,7 @@ errorMsg loader::loader_errors[] =
|
||||
errorMsg{7, "STATES (re)defined in a state"},
|
||||
errorMsg{9, "Unrecognized Attribute"},
|
||||
errorMsg{0x0A, "Unrecognized float Attribute"},
|
||||
errorMsg{0x0B, "No float Attributes Field"},
|
||||
errorMsg{0x0D, "float Attribute not found"},
|
||||
errorMsg{0x0C, "state_index out of range"},
|
||||
errorMsg{0x0F, "loader_material() reports failure"},
|
||||
@@ -63,7 +63,7 @@ int loader::error(int errorCode, int captionCode)
|
||||
|
||||
if (!errorText)
|
||||
errorText = loader_errors[index].Message;
|
||||
MessageBoxA(nullptr, errorText, errorCaption, 0x2000u);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, errorCaption, errorText, nullptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,18 +1,18 @@
|
||||
#pragma once
|
||||
#include "objlist_class.h"
|
||||
|
||||
struct midi_struct
|
||||
constexpr uint32_t SwapByteOrderInt(uint32_t val)
|
||||
{
|
||||
DWORD Magic;
|
||||
DWORD DwTimeFormat;
|
||||
DWORD CbMaxBuffer;
|
||||
DWORD DwFlagsFormat;
|
||||
midihdr_tag* DataPtr1;
|
||||
HMIDISTRM StreamHandle;
|
||||
int SomeFlag2;
|
||||
int BlockCount;
|
||||
int PreparedBlocksCount;
|
||||
};
|
||||
return (val >> 24) |
|
||||
((val << 8) & 0x00FF0000) |
|
||||
((val >> 8) & 0x0000FF00) |
|
||||
(val << 24);
|
||||
}
|
||||
|
||||
constexpr uint16_t SwapByteOrderShort(uint16_t val)
|
||||
{
|
||||
return static_cast<uint16_t>((val >> 8) | (val << 8));
|
||||
}
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
@@ -44,35 +44,71 @@ struct riff_header
|
||||
riff_data Data;
|
||||
};
|
||||
|
||||
struct midi_event_x2
|
||||
{
|
||||
DWORD iTicks;
|
||||
DWORD iEvent;
|
||||
};
|
||||
|
||||
struct midi_event_x3
|
||||
{
|
||||
DWORD iTicks;
|
||||
DWORD iStreamID;
|
||||
DWORD iEvent;
|
||||
};
|
||||
|
||||
struct midi_header
|
||||
{
|
||||
explicit midi_header(uint16_t tickdiv)
|
||||
: tickdiv(tickdiv)
|
||||
{
|
||||
}
|
||||
|
||||
const char MThd[4]{ 'M','T','h','d' };
|
||||
const uint32_t chunklen = SwapByteOrderInt(6);
|
||||
const int16_t format = SwapByteOrderShort(0);
|
||||
const uint16_t ntracks = SwapByteOrderShort(1);
|
||||
uint16_t tickdiv;
|
||||
};
|
||||
|
||||
struct midi_track
|
||||
{
|
||||
explicit midi_track(uint32_t chunklen)
|
||||
: chunklen(chunklen)
|
||||
{
|
||||
}
|
||||
|
||||
const char MTrk[4]{ 'M','T','r','k' };
|
||||
uint32_t chunklen;
|
||||
};
|
||||
|
||||
static_assert(sizeof(riff_block) == 0xC, "Wrong size of riff_block");
|
||||
static_assert(sizeof(riff_data) == 0x18, "Wrong size of riff_data");
|
||||
static_assert(sizeof(riff_header) == 0x38, "Wrong size of riff_header");
|
||||
static_assert(sizeof(midi_event_x3) == 12, "Wrong size of midi_event3");
|
||||
static_assert(sizeof(midi_event_x2) == 8, "Wrong size of midi_event2");
|
||||
static_assert(sizeof(midi_header) == 14, "Wrong size of midi_header");
|
||||
static_assert(sizeof(midi_track) == 8, "Wrong size of midi_track");
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
class midi
|
||||
{
|
||||
public:
|
||||
static MCIERROR play_pb_theme(int flag);
|
||||
static MCIERROR music_stop();
|
||||
static int play_pb_theme(int flag);
|
||||
static int music_stop();
|
||||
static int music_init();
|
||||
static MCIERROR restart_midi_seq(LPARAM param);
|
||||
static void music_shutdown();
|
||||
private:
|
||||
private:
|
||||
static Mix_Music* currentMidi;
|
||||
|
||||
static objlist_class<midi_struct>* TrackList;
|
||||
static midi_struct *track1, *track2, *track3, *active_track, *active_track2;
|
||||
static objlist_class<Mix_Music>* TrackList;
|
||||
static Mix_Music *track1, *track2, *track3, *active_track, *active_track2;
|
||||
static int some_flag1;
|
||||
static int music_init_ft();
|
||||
static void music_shutdown_ft();
|
||||
static midi_struct* load_track(LPCSTR fileName);
|
||||
static int load_file(midi_struct** midi_res, void* filePtrOrPath, int fileSizeP, int flags);
|
||||
static int read_file(midi_struct* midi, riff_header* filePtr, unsigned int fileSize);
|
||||
static int play_ft(midi_struct* midi);
|
||||
static Mix_Music* load_track(LPCSTR fileName);
|
||||
static int play_ft(Mix_Music* midi);
|
||||
static int stop_ft();
|
||||
static int unload_track(midi_struct* midi);
|
||||
static int stream_open(midi_struct* midi, char flags);
|
||||
static int stream_close(midi_struct* midi);
|
||||
static void CALLBACK midi_callback(HMIDIOUT hmo, UINT wMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1,
|
||||
DWORD_PTR dwParam2);
|
||||
static std::vector<uint8_t>* MdsToMidi(char* file);
|
||||
};
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
LPCSTR options::OptionsRegPath;
|
||||
LPSTR options::OptionsRegPathCur;
|
||||
HMENU options::MenuHandle;
|
||||
optionsStruct options::Options{};
|
||||
|
||||
winhelp_entry options::keymap_help[18]
|
||||
@@ -68,14 +67,12 @@ short options::vk_list[28]
|
||||
-1
|
||||
};
|
||||
|
||||
void options::init(HMENU menuHandle)
|
||||
void options::init()
|
||||
{
|
||||
MenuHandle = menuHandle;
|
||||
Options.Sounds = 1;
|
||||
Options.Music = 0;
|
||||
Options.FullScreen = 0;
|
||||
Options.Average = 5;
|
||||
Options.PriorityAdj = 2;
|
||||
Options.LeftFlipperKeyDft = SDLK_z;
|
||||
Options.RightFlipperKeyDft = SDLK_SLASH;
|
||||
Options.PlungerKeyDft = SDLK_SPACE;
|
||||
@@ -109,29 +106,7 @@ void options::init(HMENU menuHandle)
|
||||
Options.RightTableBumpKey = get_int(nullptr, "Right Table Bump key", Options.RightTableBumpKey);
|
||||
Options.BottomTableBumpKey = get_int(nullptr, "Bottom Table Bump key", Options.BottomTableBumpKey);
|
||||
Options.UniformScaling = get_int(nullptr, "Uniform scaling", true);*/
|
||||
menu_check(Menu1_Sounds, Options.Sounds);
|
||||
Sound::Enable(0, 7, Options.Sounds);
|
||||
menu_check(Menu1_Music, Options.Music);
|
||||
menu_check(Menu1_Full_Screen, Options.FullScreen);
|
||||
menu_check(Menu1_1Player, Options.Players == 1);
|
||||
menu_check(Menu1_2Players, Options.Players == 2);
|
||||
menu_check(Menu1_3Players, Options.Players == 3);
|
||||
menu_check(Menu1_4Players, Options.Players == 4);
|
||||
menu_check(Menu1_WindowUniformScale, Options.UniformScaling);
|
||||
auto tmpBuf = memory::allocate(0x1F4u);
|
||||
if (tmpBuf)
|
||||
{
|
||||
get_string(nullptr, "Shell Exe", tmpBuf, "", 500);
|
||||
if (!*tmpBuf)
|
||||
{
|
||||
if (MenuHandle)
|
||||
{
|
||||
DeleteMenu(MenuHandle, Menu1_Select_Table, 0);
|
||||
DrawMenuBar(nullptr);
|
||||
}
|
||||
}
|
||||
memory::free(tmpBuf);
|
||||
}
|
||||
|
||||
update_resolution_menu();
|
||||
}
|
||||
@@ -154,10 +129,10 @@ void options::uninit()
|
||||
|
||||
void options::path_init(LPCSTR regPath)
|
||||
{
|
||||
char* buf = memory::allocate(lstrlenA(regPath) + 1);
|
||||
char* buf = memory::allocate(strlen(regPath) + 1);
|
||||
OptionsRegPath = buf;
|
||||
if (buf)
|
||||
lstrcpyA(buf, regPath);
|
||||
strcpy_s(buf, strlen(regPath) + 1, regPath);
|
||||
}
|
||||
|
||||
void options::path_uninit()
|
||||
@@ -172,16 +147,16 @@ LPCSTR options::path(LPCSTR regPath)
|
||||
char* buf = OptionsRegPathCur;
|
||||
if (!OptionsRegPathCur)
|
||||
{
|
||||
buf = memory::allocate(0x7D0u);
|
||||
buf = memory::allocate(2000);
|
||||
OptionsRegPathCur = buf;
|
||||
if (!buf)
|
||||
return OptionsRegPath;
|
||||
}
|
||||
lstrcpyA(buf, OptionsRegPath);
|
||||
strcpy_s(buf, 2000, OptionsRegPath);
|
||||
if (!regPath)
|
||||
return OptionsRegPathCur;
|
||||
lstrcatA(OptionsRegPathCur, "\\");
|
||||
lstrcatA(OptionsRegPathCur, regPath);
|
||||
strcat_s(OptionsRegPathCur, 2000, "\\");
|
||||
strcat_s(OptionsRegPathCur, 2000, regPath);
|
||||
return OptionsRegPathCur;
|
||||
}
|
||||
|
||||
@@ -195,92 +170,45 @@ void options::path_free()
|
||||
|
||||
int options::get_int(LPCSTR optPath, LPCSTR lpValueName, int defaultValue)
|
||||
{
|
||||
DWORD dwDisposition;
|
||||
HKEY hKey;
|
||||
|
||||
auto result = defaultValue;
|
||||
if (!OptionsRegPath)
|
||||
return result;
|
||||
|
||||
auto regPath = path(optPath);
|
||||
if (!RegCreateKeyExA(HKEY_CURRENT_USER, regPath, 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, &hKey, &dwDisposition))
|
||||
{
|
||||
DWORD bufferSize = 4;
|
||||
RegQueryValueExA(hKey, lpValueName, nullptr, nullptr, reinterpret_cast<LPBYTE>(&result), &bufferSize);
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
path_free();
|
||||
return result;
|
||||
}
|
||||
|
||||
void options::set_int(LPCSTR optPath, LPCSTR lpValueName, int data)
|
||||
{
|
||||
DWORD dwDisposition;
|
||||
HKEY hKey;
|
||||
|
||||
if (!OptionsRegPath)
|
||||
return;
|
||||
|
||||
auto regPath = path(optPath);
|
||||
if (!RegCreateKeyExA(HKEY_CURRENT_USER, regPath, 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, &hKey, &dwDisposition))
|
||||
{
|
||||
RegSetValueExA(hKey, lpValueName, 0, 4u, reinterpret_cast<LPBYTE>(&data), 4u);
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
auto regPath = path(optPath);
|
||||
path_free();
|
||||
}
|
||||
|
||||
void options::get_string(LPCSTR optPath, LPCSTR lpValueName, LPSTR dst, LPCSTR defaultValue, int iMaxLength)
|
||||
{
|
||||
DWORD dwDisposition;
|
||||
HKEY hKey;
|
||||
|
||||
lstrcpynA(dst, defaultValue, iMaxLength);
|
||||
strncpy_s(dst, iMaxLength, defaultValue, iMaxLength);
|
||||
if (!OptionsRegPath)
|
||||
return;
|
||||
|
||||
auto regPath = path(optPath);
|
||||
if (!RegCreateKeyExA(HKEY_CURRENT_USER, regPath, 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, &hKey, &dwDisposition))
|
||||
{
|
||||
DWORD bufferSize = iMaxLength;
|
||||
RegQueryValueExA(hKey, lpValueName, nullptr, nullptr, reinterpret_cast<LPBYTE>(dst), &bufferSize);
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
auto regPath = path(optPath);
|
||||
path_free();
|
||||
}
|
||||
|
||||
void options::set_string(LPCSTR optPath, LPCSTR lpValueName, LPCSTR value)
|
||||
{
|
||||
DWORD dwDisposition;
|
||||
HKEY hKey;
|
||||
|
||||
if (!OptionsRegPath)
|
||||
return;
|
||||
|
||||
auto regPath = path(optPath);
|
||||
if (!RegCreateKeyExA(HKEY_CURRENT_USER, regPath, 0, nullptr, 0, KEY_ALL_ACCESS, nullptr, &hKey, &dwDisposition))
|
||||
{
|
||||
RegSetValueExA(hKey, lpValueName, 0, 1u, LPBYTE(value), lstrlenA(value) + 1);
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
auto regPath = path(optPath);
|
||||
path_free();
|
||||
}
|
||||
|
||||
|
||||
void options::menu_check(UINT uIDCheckItem, int check)
|
||||
{
|
||||
if (MenuHandle)
|
||||
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)
|
||||
void options::toggle(uint32_t uIDCheckItem)
|
||||
{
|
||||
int newValue;
|
||||
switch (uIDCheckItem)
|
||||
@@ -289,7 +217,6 @@ void options::toggle(UINT uIDCheckItem)
|
||||
newValue = Options.Sounds == 0;
|
||||
Options.Sounds = Options.Sounds == 0;
|
||||
Sound::Enable(0, 7, newValue);
|
||||
menu_check(uIDCheckItem, newValue);
|
||||
return;
|
||||
case Menu1_Music:
|
||||
newValue = Options.Music == 0;
|
||||
@@ -298,31 +225,25 @@ void options::toggle(UINT uIDCheckItem)
|
||||
midi::music_stop();
|
||||
else
|
||||
midi::play_pb_theme(0);
|
||||
menu_check(uIDCheckItem, newValue);
|
||||
return;
|
||||
case Menu1_Full_Screen:
|
||||
newValue = Options.FullScreen == 0;
|
||||
Options.FullScreen = Options.FullScreen == 0;
|
||||
fullscrn::set_screen_mode(newValue);
|
||||
menu_check(uIDCheckItem, newValue);
|
||||
return;
|
||||
case Menu1_1Player:
|
||||
case Menu1_2Players:
|
||||
case Menu1_3Players:
|
||||
case Menu1_4Players:
|
||||
Options.Players = uIDCheckItem - Menu1_1Player + 1;
|
||||
menu_check(Menu1_1Player, Options.Players == 1);
|
||||
menu_check(Menu1_2Players, Options.Players == 2);
|
||||
menu_check(Menu1_3Players, Options.Players == 3);
|
||||
menu_check(Menu1_4Players, Options.Players == 4);
|
||||
break;
|
||||
case Menu1_MaximumResolution:
|
||||
case Menu1_640x480:
|
||||
case Menu1_800x600:
|
||||
case Menu1_1024x768:
|
||||
{
|
||||
for (unsigned i = Menu1_MaximumResolution; i <= Menu1_1024x768; ++i)
|
||||
menu_check(i, i == uIDCheckItem);
|
||||
/*for (unsigned i = Menu1_MaximumResolution; i <= Menu1_1024x768; ++i)
|
||||
menu_check(i, i == uIDCheckItem);*/
|
||||
|
||||
int newResolution = uIDCheckItem - Menu1_640x480;
|
||||
if (uIDCheckItem == Menu1_MaximumResolution)
|
||||
@@ -340,7 +261,6 @@ void options::toggle(UINT uIDCheckItem)
|
||||
}
|
||||
case Menu1_WindowUniformScale:
|
||||
Options.UniformScaling ^= true;
|
||||
menu_check(Menu1_WindowUniformScale, Options.UniformScaling);
|
||||
fullscrn::window_size_changed();
|
||||
pb::paint();
|
||||
break;
|
||||
@@ -353,8 +273,8 @@ void options::update_resolution_menu()
|
||||
{
|
||||
auto maxResolution = fullscrn::get_max_supported_resolution();
|
||||
fullscrn::SetMaxResolution(maxResolution);
|
||||
const CHAR* maxResText = pinball::get_rc_string(maxResolution + 2030, 0);
|
||||
if (MenuHandle)
|
||||
const char* maxResText = pinball::get_rc_string(maxResolution + 2030, 0);
|
||||
/*if (MenuHandle)
|
||||
ModifyMenuA(MenuHandle, Menu1_MaximumResolution, 0, Menu1_MaximumResolution, maxResText);
|
||||
|
||||
for (auto resIndex = 0; resIndex < 3; resIndex++)
|
||||
@@ -368,7 +288,7 @@ void options::update_resolution_menu()
|
||||
if (Options.Resolution >= 0)
|
||||
menu_check(fullscrn::resolution_array[fullscrn::GetResolution()].ResolutionMenuId, 1);
|
||||
else
|
||||
menu_check(Menu1_MaximumResolution, 1);
|
||||
menu_check(Menu1_MaximumResolution, 1);*/
|
||||
}
|
||||
|
||||
void options::init_resolution()
|
||||
@@ -390,192 +310,3 @@ void options::keyboard()
|
||||
{
|
||||
//DialogBoxParamA(nullptr, "KEYMAPPER", nullptr, KeyMapDlgProc, 0);
|
||||
}
|
||||
|
||||
INT_PTR _stdcall options::KeyMapDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
char keyName[20];
|
||||
int keyBindings[6];
|
||||
char rcString[256];
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WM_HELP:
|
||||
WinHelpA(static_cast<HWND>(reinterpret_cast<HELPINFO*>(lParam)->hItemHandle), "pinball.hlp", HELP_WM_HELP,
|
||||
(ULONG_PTR)keymap_help);
|
||||
return 1;
|
||||
case WM_CONTEXTMENU:
|
||||
WinHelpA((HWND)wParam, "pinball.hlp", HELP_CONTEXTMENU, (ULONG_PTR)keymap_help);
|
||||
return 1;
|
||||
case WM_INITDIALOG:
|
||||
for (auto vkPtr = vk_list; *vkPtr != -1; vkPtr++)
|
||||
{
|
||||
short vk = *vkPtr;
|
||||
auto vk2And = vk & 0x4000;
|
||||
auto vkChar = static_cast<uint8_t>(vk);
|
||||
unsigned short maxVk;
|
||||
|
||||
if (vk2And)
|
||||
{
|
||||
auto index = 128;
|
||||
do
|
||||
{
|
||||
if (vkChar == MapVirtualKeyA(index, MAPVK_VK_TO_CHAR))
|
||||
break;
|
||||
++index;
|
||||
}
|
||||
while (index < 256);
|
||||
|
||||
if (index == 256)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
keyName[0] = static_cast<char>(vkChar);
|
||||
keyName[1] = 0;
|
||||
vkChar = index;
|
||||
maxVk = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vk >= 0)
|
||||
{
|
||||
maxVk = vkChar;
|
||||
}
|
||||
else
|
||||
{
|
||||
++vkPtr;
|
||||
maxVk = *vkPtr;
|
||||
}
|
||||
if (vkChar > maxVk)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
for (int curVK = vkChar; curVK <= maxVk; curVK++)
|
||||
{
|
||||
if (vk2And || get_vk_key_name(curVK, keyName))
|
||||
{
|
||||
auto ind = SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperL,CB_INSERTSTRING, -1, (LPARAM)keyName);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperL, CB_SETITEMDATA, ind, curVK);
|
||||
if (curVK == Options.LeftFlipperKey)
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperL, CB_SETCURSEL, ind, 0);
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperR, CB_INSERTSTRING, -1, (LPARAM)keyName);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperR, CB_SETITEMDATA, ind, curVK);
|
||||
if (curVK == Options.RightFlipperKey)
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperR, CB_SETCURSEL, ind, 0);
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_Plunger, CB_INSERTSTRING, -1, (LPARAM)keyName);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_Plunger, CB_SETITEMDATA, ind, curVK);
|
||||
if (curVK == Options.PlungerKey)
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_Plunger, CB_SETCURSEL, ind, 0);
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_BumpLeft, CB_INSERTSTRING, -1, (LPARAM)keyName);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_BumpLeft, CB_SETITEMDATA, ind, curVK);
|
||||
if (curVK == Options.LeftTableBumpKey)
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_BumpLeft, CB_SETCURSEL, ind, 0);
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_BumpRight, CB_INSERTSTRING, -1, (LPARAM)keyName);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_BumpRight, CB_SETITEMDATA, ind, curVK);
|
||||
if (curVK == Options.RightTableBumpKey)
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_BumpRight, CB_SETCURSEL, ind, 0);
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_BumpBottom, CB_INSERTSTRING, -1, (LPARAM)keyName);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_BumpBottom, CB_SETITEMDATA, ind, curVK);
|
||||
if (curVK == Options.BottomTableBumpKey)
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_BumpBottom, CB_SETCURSEL, ind, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
case WM_COMMAND:
|
||||
switch (wParam)
|
||||
{
|
||||
case KEYMAPPER_Ok:
|
||||
{
|
||||
auto ind = SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperL, CB_GETCURSEL, 0, 0);
|
||||
keyBindings[0] = static_cast<int>(SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperL, CB_GETITEMDATA, ind, 0));
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperR, CB_GETCURSEL, 0, 0);
|
||||
keyBindings[1] = static_cast<int>(SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperR, CB_GETITEMDATA, ind, 0));
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_Plunger, CB_GETCURSEL, 0, 0);
|
||||
keyBindings[2] = static_cast<int>(SendDlgItemMessageA(hDlg, KEYMAPPER_Plunger, CB_GETITEMDATA, ind, 0));
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_BumpLeft, CB_GETCURSEL, 0, 0);
|
||||
keyBindings[3] = static_cast<int>(SendDlgItemMessageA(hDlg, KEYMAPPER_BumpLeft, CB_GETITEMDATA, ind, 0));
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_BumpRight, CB_GETCURSEL, 0, 0);
|
||||
keyBindings[4] = static_cast<int>(SendDlgItemMessageA(hDlg, KEYMAPPER_BumpRight, CB_GETITEMDATA, ind, 0));
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_BumpBottom, CB_GETCURSEL, 0, 0);
|
||||
keyBindings[5] = static_cast<int>(SendDlgItemMessageA(hDlg, KEYMAPPER_BumpBottom, CB_GETITEMDATA, ind, 0));
|
||||
|
||||
auto sameKeyBound = 0;
|
||||
auto index = 1;
|
||||
auto optPtr = keyBindings;
|
||||
while (!sameKeyBound)
|
||||
{
|
||||
for (auto keyInd = index; keyInd < 6; keyInd++)
|
||||
{
|
||||
if (sameKeyBound)
|
||||
break;
|
||||
if (*optPtr == keyBindings[keyInd])
|
||||
{
|
||||
lstrcpyA(rcString, pinball::get_rc_string(43, 0));
|
||||
MessageBoxA(hDlg, pinball::get_rc_string(39, 0), rcString, 0x2000u);
|
||||
sameKeyBound = 1;
|
||||
}
|
||||
}
|
||||
++index;
|
||||
++optPtr;
|
||||
if (index - 1 >= 5)
|
||||
{
|
||||
if (sameKeyBound)
|
||||
return 1;
|
||||
Options.LeftFlipperKey = keyBindings[0];
|
||||
Options.RightFlipperKey = keyBindings[1];
|
||||
Options.PlungerKey = keyBindings[2];
|
||||
Options.LeftTableBumpKey = keyBindings[3];
|
||||
Options.RightTableBumpKey = keyBindings[4];
|
||||
Options.BottomTableBumpKey = keyBindings[5];
|
||||
EndDialog(hDlg, wParam);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
case KEYMAPPER_Cancel:
|
||||
EndDialog(hDlg, wParam);
|
||||
return 1;
|
||||
case KEYMAPPER_Default:
|
||||
{
|
||||
auto name = (LPARAM)get_vk_key_name(Options.LeftFlipperKeyDft, keyName);
|
||||
auto ind = SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperL, CB_FINDSTRINGEXACT, 0, name);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperL, CB_SETCURSEL, ind, 0);
|
||||
name = (LPARAM)get_vk_key_name(Options.RightFlipperKeyDft, keyName);
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperR, CB_FINDSTRINGEXACT, 0, name);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_FlipperR, CB_SETCURSEL, ind, 0);
|
||||
name = (LPARAM)get_vk_key_name(Options.PlungerKeyDft, keyName);
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_Plunger, CB_FINDSTRINGEXACT, 0, name);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_Plunger, CB_SETCURSEL, ind, 0);
|
||||
name = (LPARAM)get_vk_key_name(Options.LeftTableBumpKeyDft, keyName);
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_BumpLeft, CB_FINDSTRINGEXACT, 0, name);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_BumpLeft, CB_SETCURSEL, ind, 0);
|
||||
name = (LPARAM)get_vk_key_name(Options.RightTableBumpKeyDft, keyName);
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_BumpRight, CB_FINDSTRINGEXACT, 0, name);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_BumpRight, CB_SETCURSEL, ind, 0);
|
||||
name = (LPARAM)get_vk_key_name(Options.BottomTableBumpKeyDft, keyName);
|
||||
ind = SendDlgItemMessageA(hDlg, KEYMAPPER_BumpBottom, CB_FINDSTRINGEXACT, 0, name);
|
||||
SendDlgItemMessageA(hDlg, KEYMAPPER_BumpBottom, CB_SETCURSEL, ind, 0);
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
LPSTR options::get_vk_key_name(uint16_t vk, LPSTR keyName)
|
||||
{
|
||||
LONG scanCode = MapVirtualKeyA(vk, MAPVK_VK_TO_VSC) << 16;
|
||||
if (vk >= 0x21u && vk <= 0x2Eu)
|
||||
scanCode |= 0x1000000u;
|
||||
return GetKeyNameTextA(scanCode, keyName, 19) != 0 ? keyName : nullptr;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ struct optionsStruct
|
||||
int Music;
|
||||
int Average;
|
||||
int FullScreen;
|
||||
int PriorityAdj;
|
||||
int Players;
|
||||
int LeftFlipperKey;
|
||||
int RightFlipperKey;
|
||||
@@ -29,7 +28,7 @@ struct optionsStruct
|
||||
class options
|
||||
{
|
||||
public:
|
||||
static void init(HMENU menuHandle);
|
||||
static void init();
|
||||
static void uninit();
|
||||
static void path_init(LPCSTR regPath);
|
||||
static void path_uninit();
|
||||
@@ -37,15 +36,11 @@ public:
|
||||
static void set_int(LPCSTR optPath, LPCSTR lpValueName, int data);
|
||||
static void get_string(LPCSTR optPath, LPCSTR lpValueName, LPSTR dst, LPCSTR defaultValue, int iMaxLength);
|
||||
static void set_string(LPCSTR optPath, LPCSTR lpValueName, LPCSTR value);
|
||||
static void menu_check(UINT uIDCheckItem, int check);
|
||||
static void menu_set(UINT uIDEnableItem, int enable);
|
||||
static void toggle(UINT uIDCheckItem);
|
||||
static void toggle(uint32_t uIDCheckItem);
|
||||
static void update_resolution_menu();
|
||||
static void init_resolution();
|
||||
|
||||
static void keyboard();
|
||||
static INT_PTR _stdcall KeyMapDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static LPSTR get_vk_key_name(uint16_t vk, LPSTR keyName);
|
||||
|
||||
static optionsStruct Options;
|
||||
private:
|
||||
@@ -53,7 +48,6 @@ private:
|
||||
static LPSTR OptionsRegPathCur;
|
||||
static LPCSTR path(LPCSTR regPath);
|
||||
static void path_free();
|
||||
static HMENU MenuHandle;
|
||||
static winhelp_entry keymap_help[18];
|
||||
static short vk_list[28];
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ datFileStruct* partman::load_records(LPCSTR lpFileName, int resolution, bool ful
|
||||
if (fileHandle == nullptr)
|
||||
return nullptr;
|
||||
fread(&header, 1, sizeof datFileHeader, fileHandle);
|
||||
if (lstrcmpA("PARTOUT(4.0)RESOURCE", header.FileSignature))
|
||||
if (strcmp("PARTOUT(4.0)RESOURCE", header.FileSignature) != 0)
|
||||
{
|
||||
fclose(fileHandle);
|
||||
return nullptr;
|
||||
@@ -31,13 +31,13 @@ datFileStruct* partman::load_records(LPCSTR lpFileName, int resolution, bool ful
|
||||
fclose(fileHandle);
|
||||
return nullptr;
|
||||
}
|
||||
if (lstrlenA(header.Description) <= 0)
|
||||
if (strlen(header.Description) <= 0)
|
||||
{
|
||||
datFile->Description = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
int lenOfStr = lstrlenA(header.Description);
|
||||
auto lenOfStr = strlen(header.Description);
|
||||
auto descriptionBuf = memory::allocate(lenOfStr + 1);
|
||||
datFile->Description = descriptionBuf;
|
||||
if (!descriptionBuf)
|
||||
@@ -46,7 +46,7 @@ datFileStruct* partman::load_records(LPCSTR lpFileName, int resolution, bool ful
|
||||
memory::free(datFile);
|
||||
return nullptr;
|
||||
}
|
||||
lstrcpyA(descriptionBuf, header.Description);
|
||||
strcpy_s(descriptionBuf, lenOfStr + 1, header.Description);
|
||||
}
|
||||
|
||||
if (header.Unknown)
|
||||
@@ -256,7 +256,7 @@ int partman::field_size(datFileStruct* datFile, int groupIndex, datFieldTypes ta
|
||||
|
||||
int partman::record_labeled(datFileStruct* datFile, LPCSTR targetGroupName)
|
||||
{
|
||||
auto targetLength = lstrlenA(targetGroupName);
|
||||
auto targetLength = strlen(targetGroupName);
|
||||
for (int groupIndex = datFile->NumberOfGroups - 1; groupIndex >= 0; --groupIndex)
|
||||
{
|
||||
auto groupName = field(datFile, groupIndex, datFieldTypes::GroupName);
|
||||
|
||||
@@ -36,11 +36,11 @@ bool pb::FullTiltMode = false;
|
||||
int pb::init()
|
||||
{
|
||||
float projMat[12], zMin = 0, zScaler = 0;
|
||||
CHAR datFileName[300];
|
||||
CHAR dataFilePath[300];
|
||||
char datFileName[300];
|
||||
char dataFilePath[300];
|
||||
|
||||
++memory::critical_allocation;
|
||||
lstrcpyA(datFileName, winmain::DatFileName);
|
||||
strcpy_s(datFileName, winmain::DatFileName);
|
||||
pinball::make_path_name(dataFilePath, datFileName, 300);
|
||||
record_table = partman::load_records(dataFilePath, fullscrn::GetResolution(), FullTiltMode);
|
||||
|
||||
@@ -148,9 +148,9 @@ void pb::mode_change(int mode)
|
||||
case 1:
|
||||
if (demo_mode)
|
||||
{
|
||||
options::menu_set(Menu1_Launch_Ball, 0);
|
||||
options::menu_set(Menu1_High_Scores, 0);
|
||||
options::menu_check(Menu1_Demo, 1);
|
||||
winmain::LaunchBallEnabled = false;
|
||||
winmain::HighScoresEnabled = false;
|
||||
winmain::DemoActive = true;
|
||||
if (MainTable)
|
||||
{
|
||||
if (MainTable->Demo)
|
||||
@@ -159,9 +159,9 @@ void pb::mode_change(int mode)
|
||||
}
|
||||
else
|
||||
{
|
||||
options::menu_set(Menu1_High_Scores, 1);
|
||||
options::menu_set(Menu1_Launch_Ball, 1);
|
||||
options::menu_check(Menu1_Demo, 0);
|
||||
winmain::LaunchBallEnabled = true;
|
||||
winmain::HighScoresEnabled = true;
|
||||
winmain::DemoActive = false;
|
||||
if (MainTable)
|
||||
{
|
||||
if (MainTable->Demo)
|
||||
@@ -170,19 +170,19 @@ void pb::mode_change(int mode)
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
options::menu_set(Menu1_Launch_Ball, 0);
|
||||
winmain::LaunchBallEnabled = false;
|
||||
if (!demo_mode)
|
||||
{
|
||||
options::menu_set(Menu1_High_Scores, 1);
|
||||
options::menu_check(Menu1_Demo, 0);
|
||||
winmain::HighScoresEnabled = true;
|
||||
winmain::DemoActive = false;
|
||||
}
|
||||
if (MainTable && MainTable->LightGroup)
|
||||
MainTable->LightGroup->Message(29, 1.4f);
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
options::menu_set(Menu1_Launch_Ball, 0);
|
||||
options::menu_set(Menu1_High_Scores, 0);
|
||||
winmain::LaunchBallEnabled = false;
|
||||
winmain::HighScoresEnabled = false;
|
||||
mode_countdown_ = 5000;
|
||||
break;
|
||||
}
|
||||
@@ -479,7 +479,7 @@ void pb::keydown(int key)
|
||||
break;
|
||||
case 'h':
|
||||
char String1[200];
|
||||
lstrcpyA(String1, pinball::get_rc_string(26, 0));
|
||||
strcpy_s(String1, pinball::get_rc_string(26, 0));
|
||||
high_score::show_and_set_high_score_dialog(highscore_table, 1000000000, 1, String1);
|
||||
break;
|
||||
case 'm':
|
||||
@@ -490,10 +490,10 @@ void pb::keydown(int key)
|
||||
case 'r':
|
||||
control::cheat_bump_rank();
|
||||
break;
|
||||
case VK_F11:
|
||||
case SDLK_F11:
|
||||
gdrv::get_focus();
|
||||
break;
|
||||
case VK_F12:
|
||||
case SDLK_F12:
|
||||
MainTable->port_draw();
|
||||
break;
|
||||
}
|
||||
@@ -569,7 +569,7 @@ void pb::end_game()
|
||||
int position = high_score::get_score_position(highscore_table, scores[i]);
|
||||
if (position >= 0)
|
||||
{
|
||||
lstrcpyA(String1, pinball::get_rc_string(scoreIndex[i] + 26, 0));
|
||||
strcpy_s(String1, pinball::get_rc_string(scoreIndex[i] + 26, 0));
|
||||
high_score::show_and_set_high_score_dialog(highscore_table, scores[i], position, String1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,18 +10,17 @@
|
||||
#define PCH_H
|
||||
|
||||
// TODO: add headers that you want to pre-compile here
|
||||
#include <Windows.h>
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <CommCtrl.h>
|
||||
#include <htmlhelp.h>
|
||||
#include <cstdint>
|
||||
#include <type_traits> /*For control template*/
|
||||
#include <chrono>
|
||||
//#include <iostream>
|
||||
#include <iomanip>
|
||||
//#include <iomanip>
|
||||
//#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include "SDL.h"
|
||||
@@ -33,9 +32,12 @@
|
||||
//https://github.com/Tyyppi77/imgui_sdl 01deb04b102b6a1c15c7fdec1977a2c96a885e6f
|
||||
#include "imgui_sdl.h"
|
||||
|
||||
//typedef const char* LPCSTR;
|
||||
//typedef int HINSTANCE;
|
||||
//typedef int HWND;
|
||||
typedef unsigned long DWORD;
|
||||
typedef char* LPSTR;
|
||||
typedef const char* LPCSTR;
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
|
||||
/*Use (void) to silent unused warnings.*/
|
||||
#define assertm(exp, msg) assert(((void)msg, exp))
|
||||
|
||||
@@ -206,7 +206,7 @@ std::map<uint32_t, LPCSTR> rc_strings
|
||||
{2032, "Use &Maximum Resolution (1024 x 768)"}
|
||||
};
|
||||
|
||||
int LoadStringAlt(UINT uID, LPSTR lpBuffer, int cchBufferMax)
|
||||
int LoadStringAlt(uint32_t uID, LPSTR lpBuffer, int cchBufferMax)
|
||||
{
|
||||
auto str = rc_strings.find(uID);
|
||||
if (str == rc_strings.end())
|
||||
@@ -246,100 +246,15 @@ int pinball::get_rc_int(int uID, int* dst)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void pinball::FindShiftKeys()
|
||||
{
|
||||
signed int i;
|
||||
int rightShift;
|
||||
CHAR stringBuf[20];
|
||||
|
||||
RightShift = -1;
|
||||
LeftShift = -1;
|
||||
for (i = 0; i < 256; ++i)
|
||||
{
|
||||
if (MapVirtualKeyA(i, 1u) == 16)
|
||||
{
|
||||
LeftShift = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (++i < 256)
|
||||
{
|
||||
if (MapVirtualKeyA(i, 1u) == 16)
|
||||
{
|
||||
RightShift = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!GetKeyNameTextA(LeftShift << 16, stringBuf, 19) || !_strnicmp(stringBuf, "right", 5u))
|
||||
{
|
||||
rightShift = RightShift;
|
||||
}
|
||||
else
|
||||
{
|
||||
rightShift = LeftShift;
|
||||
LeftShift = RightShift;
|
||||
RightShift = rightShift;
|
||||
}
|
||||
if (GetKeyNameTextA(rightShift << 16, stringBuf, 19))
|
||||
{
|
||||
if (_strnicmp(stringBuf, "left", 4u) != 0)
|
||||
{
|
||||
auto tmp = LeftShift;
|
||||
LeftShift = RightShift;
|
||||
RightShift = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void pinball::adjust_priority(int priority)
|
||||
{
|
||||
auto thread = GetCurrentThread();
|
||||
switch (priority)
|
||||
{
|
||||
case -2:
|
||||
SetThreadPriority(thread, -2);
|
||||
break;
|
||||
case -1:
|
||||
SetThreadPriority(thread, -1);
|
||||
break;
|
||||
case 0:
|
||||
SetThreadPriority(thread, 0);
|
||||
break;
|
||||
case 1:
|
||||
SetThreadPriority(thread, 1);
|
||||
break;
|
||||
case 2:
|
||||
SetThreadPriority(thread, 2);
|
||||
break;
|
||||
case 3:
|
||||
SetThreadPriority(thread, 15);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int pinball::make_path_name(LPSTR lpFilename, LPCSTR lpString2, int nSize)
|
||||
{
|
||||
int nameSize = GetModuleFileNameA(nullptr, lpFilename, nSize);
|
||||
if (!nameSize || nameSize == nSize)
|
||||
auto base_path = SDL_GetBasePath();
|
||||
if (!base_path)
|
||||
{
|
||||
strcat_s(lpFilename, nSize, "?");
|
||||
return 1;
|
||||
for (CHAR* i = &lpFilename[nameSize]; i > lpFilename; --i)
|
||||
{
|
||||
if (*i == '\\' || *i == ':')
|
||||
{
|
||||
i[1] = 0;
|
||||
break;
|
||||
}
|
||||
--nameSize;
|
||||
}
|
||||
if (nameSize + 13 < nSize)
|
||||
{
|
||||
lstrcatA(lpFilename, lpString2);
|
||||
return 0;
|
||||
}
|
||||
lstrcatA(lpFilename, "?");
|
||||
return 1;
|
||||
strcpy_s(lpFilename, nSize, base_path);
|
||||
strcat_s(lpFilename, nSize, lpString2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ public:
|
||||
|
||||
static char* get_rc_string(int uID, int a2);
|
||||
static int get_rc_int(int uID, int* dst);
|
||||
static void FindShiftKeys();
|
||||
static void adjust_priority(int priority);
|
||||
static int make_path_name(LPSTR lpFilename, LPCSTR lpString2, int nSize = 0x12Cu);
|
||||
private:
|
||||
static char getRcBuffer[256 * 6];
|
||||
|
||||
@@ -273,7 +273,7 @@ void score::update(scoreStruct* score)
|
||||
|
||||
void score::string_format(int score, char* str)
|
||||
{
|
||||
CHAR separator[12];
|
||||
char separator[12];
|
||||
|
||||
if (score == -999)
|
||||
{
|
||||
@@ -281,25 +281,7 @@ void score::string_format(int score, char* str)
|
||||
}
|
||||
else
|
||||
{
|
||||
lstrcpyA(separator, ",");
|
||||
|
||||
HKEY phkResult;
|
||||
DWORD dwDisposition;
|
||||
if (!RegCreateKeyExA(
|
||||
HKEY_CURRENT_USER,
|
||||
"Control Panel\\International",
|
||||
0,
|
||||
nullptr,
|
||||
0,
|
||||
KEY_ALL_ACCESS,
|
||||
nullptr,
|
||||
&phkResult,
|
||||
&dwDisposition))
|
||||
{
|
||||
DWORD cbData = 10;
|
||||
RegQueryValueExA(phkResult, "sThousand", nullptr, nullptr, (LPBYTE)separator, &cbData);
|
||||
RegCloseKey(phkResult);
|
||||
}
|
||||
strcpy_s(separator, ",");
|
||||
int scoreMillions = score % 1000000000 / 1000000;
|
||||
if (score / 1000000000 <= 0)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
const double TargetFps = 60, TargetFrameTime = 1000 / TargetFps;
|
||||
|
||||
HCURSOR winmain::mouse_hsave;
|
||||
SDL_Window* winmain::MainWindow = nullptr;
|
||||
SDL_Renderer* winmain::Renderer = nullptr;
|
||||
ImGuiIO* winmain::ImIO = nullptr;
|
||||
@@ -31,13 +30,15 @@ int winmain::no_time_loss;
|
||||
|
||||
DWORD winmain::then;
|
||||
DWORD winmain::now;
|
||||
UINT winmain::iFrostUniqueMsg;
|
||||
bool winmain::restart = false;
|
||||
|
||||
gdrv_bitmap8 winmain::gfr_display{};
|
||||
char winmain::DatFileName[300]{};
|
||||
bool winmain::ShowAboutDialog = false;
|
||||
bool winmain::ShowImGuiDemo = false;
|
||||
bool winmain::LaunchBallEnabled = true;
|
||||
bool winmain::HighScoresEnabled = true;
|
||||
bool winmain::DemoActive = false;
|
||||
|
||||
|
||||
uint32_t timeGetTimeAlt()
|
||||
@@ -79,8 +80,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
||||
strcpy_s(DatFileName, "CADET.DAT");
|
||||
pb::FullTiltMode = true;
|
||||
}
|
||||
|
||||
pinball::FindShiftKeys();
|
||||
|
||||
options::init_resolution();
|
||||
|
||||
// SDL window
|
||||
@@ -125,21 +125,22 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
||||
{
|
||||
++memory::critical_allocation;
|
||||
|
||||
options::init(nullptr);
|
||||
options::init();
|
||||
auto voiceCount = options::get_int(nullptr, "Voices", 8);
|
||||
if (!Sound::Init(voiceCount))
|
||||
options::menu_set(Menu1_Sounds, 0);
|
||||
if (Sound::Init(voiceCount))
|
||||
options::Options.Sounds = 0;
|
||||
Sound::Activate();
|
||||
|
||||
if (!pinball::quickFlag && !midi::music_init())
|
||||
options::menu_set(Menu1_Music, 0);
|
||||
options::Options.Music = 0;
|
||||
|
||||
if (pb::init())
|
||||
if (pb::init())
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not load game data", "The .dat file is missing", window);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not load game data",
|
||||
"The .dat file is missing", window);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
fullscrn::init();
|
||||
|
||||
--memory::critical_allocation;
|
||||
@@ -151,13 +152,10 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
||||
if (strstr(lpCmdLine, "-fullscreen"))
|
||||
{
|
||||
options::Options.FullScreen = 1;
|
||||
options::menu_check(Menu1_Full_Screen, 1);
|
||||
}
|
||||
|
||||
SDL_ShowWindow(window);
|
||||
fullscrn::set_screen_mode(options::Options.FullScreen);
|
||||
|
||||
pinball::adjust_priority(options::Options.PriorityAdj);
|
||||
fullscrn::set_screen_mode(options::Options.FullScreen);
|
||||
|
||||
if (strstr(lpCmdLine, "-demo"))
|
||||
pb::toggle_demo();
|
||||
@@ -249,7 +247,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
||||
|
||||
if (curTime == then)
|
||||
{
|
||||
Sleep(8u);
|
||||
SDL_Delay(8);
|
||||
}
|
||||
else if (pb::frame(curTime - then))
|
||||
{
|
||||
@@ -308,7 +306,8 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
||||
|
||||
if (restart)
|
||||
{
|
||||
char restartPath[300]{};
|
||||
// Todo: get rid of restart to change resolution.
|
||||
/*char restartPath[300]{};
|
||||
if (GetModuleFileNameA(nullptr, restartPath, 300))
|
||||
{
|
||||
STARTUPINFO si{};
|
||||
@@ -320,7 +319,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
return return_value;
|
||||
@@ -342,7 +341,7 @@ void winmain::RenderUi()
|
||||
{
|
||||
new_game();
|
||||
}
|
||||
if (ImGui::MenuItem("Launch Ball"))
|
||||
if (ImGui::MenuItem("Launch Ball", nullptr, false, LaunchBallEnabled))
|
||||
{
|
||||
end_pause();
|
||||
pb::launch_ball();
|
||||
@@ -353,13 +352,13 @@ void winmain::RenderUi()
|
||||
}
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::MenuItem("High Scores..."))
|
||||
if (ImGui::MenuItem("High Scores...", nullptr, false, HighScoresEnabled))
|
||||
{
|
||||
if (!single_step)
|
||||
pause();
|
||||
pb::high_scores();
|
||||
}
|
||||
if (ImGui::MenuItem("Demo"))
|
||||
if (ImGui::MenuItem("Demo", nullptr, DemoActive))
|
||||
{
|
||||
end_pause();
|
||||
pb::toggle_demo();
|
||||
@@ -450,7 +449,7 @@ void winmain::RenderUi()
|
||||
{
|
||||
if (!single_step)
|
||||
pause();
|
||||
help_introduction(nullptr, (HWND)MainWindow);
|
||||
help_introduction();
|
||||
}
|
||||
ImGui::Separator();
|
||||
|
||||
@@ -507,7 +506,6 @@ int winmain::event_handler(const SDL_Event* event)
|
||||
case SDL_QUIT:
|
||||
end_pause();
|
||||
bQuit = 1;
|
||||
PostQuitMessage(0);
|
||||
fullscrn::shutdown();
|
||||
return_value = 0;
|
||||
return 0;
|
||||
@@ -525,7 +523,7 @@ int winmain::event_handler(const SDL_Event* event)
|
||||
SDL_MinimizeWindow(MainWindow);
|
||||
break;
|
||||
case SDLK_F1:
|
||||
help_introduction(nullptr, (HWND)MainWindow);
|
||||
help_introduction();
|
||||
break;
|
||||
case SDLK_F2:
|
||||
new_game();
|
||||
@@ -637,7 +635,6 @@ int winmain::event_handler(const SDL_Event* event)
|
||||
if (options::Options.Music && !single_step)
|
||||
midi::play_pb_theme(0);
|
||||
no_time_loss = 1;
|
||||
pinball::adjust_priority(options::Options.PriorityAdj);
|
||||
has_focus = 1;
|
||||
gdrv::get_focus();
|
||||
pb::paint();
|
||||
@@ -646,9 +643,7 @@ int winmain::event_handler(const SDL_Event* event)
|
||||
case SDL_WINDOWEVENT_HIDDEN:
|
||||
activated = 0;
|
||||
fullscrn::activate(0);
|
||||
options::menu_check(Menu1_Full_Screen, 0);
|
||||
options::Options.FullScreen = 0;
|
||||
SetThreadPriority(GetCurrentThread(), 0);
|
||||
Sound::Deactivate();
|
||||
midi::music_stop();
|
||||
has_focus = 0;
|
||||
@@ -693,7 +688,7 @@ void winmain::memalloc_failure()
|
||||
gdrv::uninit();
|
||||
char* caption = pinball::get_rc_string(170, 0);
|
||||
char* text = pinball::get_rc_string(179, 0);
|
||||
MessageBoxA(nullptr, text, caption, 0x2030u);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, caption, text, MainWindow);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
@@ -732,9 +727,7 @@ void winmain::end_pause()
|
||||
void winmain::new_game()
|
||||
{
|
||||
end_pause();
|
||||
HCURSOR prevCursor = SetCursor(LoadCursorA(nullptr, IDC_WAIT));
|
||||
pb::replay_level(0);
|
||||
SetCursor(prevCursor);
|
||||
}
|
||||
|
||||
void winmain::pause()
|
||||
@@ -743,26 +736,8 @@ void winmain::pause()
|
||||
no_time_loss = 1;
|
||||
}
|
||||
|
||||
void winmain::help_introduction(HINSTANCE a1, HWND a2)
|
||||
void winmain::help_introduction()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void winmain::Restart()
|
||||
|
||||
@@ -9,6 +9,9 @@ public:
|
||||
static SDL_Window* MainWindow;
|
||||
static SDL_Renderer* Renderer;
|
||||
static ImGuiIO* ImIO;
|
||||
static bool LaunchBallEnabled;
|
||||
static bool HighScoresEnabled;
|
||||
static bool DemoActive;
|
||||
|
||||
static int WinMain(LPCSTR lpCmdLine);
|
||||
static int event_handler(const SDL_Event* event);
|
||||
@@ -18,15 +21,13 @@ public:
|
||||
static void end_pause();
|
||||
static void new_game();
|
||||
static void pause();
|
||||
static void help_introduction(HINSTANCE a1, HWND a2);
|
||||
static void help_introduction();
|
||||
static void Restart();
|
||||
private:
|
||||
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 bool restart;
|
||||
static bool ShowAboutDialog;
|
||||
static bool ShowImGuiDemo;
|
||||
|
||||
Reference in New Issue
Block a user