Skip to content

Commit

Permalink
x64 build - no collision bug found(
Browse files Browse the repository at this point in the history
Either lost in decompilation or introduced in x64 port.
  • Loading branch information
oz authored and oz committed Jan 29, 2021
1 parent 6756c54 commit cd46791
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 79 deletions.
6 changes: 4 additions & 2 deletions SpaceCadetPinball/SpaceCadetPinball.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>NotSet</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -114,6 +114,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Comctl32.lib;Winmm.lib;Htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down Expand Up @@ -153,6 +154,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Comctl32.lib;Winmm.lib;Htmlhelp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions SpaceCadetPinball/TLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

struct gdrv_bitmap8;

struct __declspec(align(4)) flasher_type
struct flasher_type
{
render_sprite_type_struct* Sprite;
gdrv_bitmap8* BmpArr[2];
Expand All @@ -15,7 +15,7 @@ struct __declspec(align(4)) flasher_type
};


struct __declspec(align(4)) TLight_player_backup
struct TLight_player_backup
{
int MessageField;
int BmpIndex1;
Expand Down
18 changes: 9 additions & 9 deletions SpaceCadetPinball/WaveMix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ HANDLE WaveMix::ConfigureInit(MIXCONFIG* lpConfig)
{
MIXCONFIG mixConfig{};

memset(&mixConfig, 0, 0x1Cu);
unsigned int copySize = 30;
memset(&mixConfig, 0, sizeof(MIXCONFIG));
unsigned int copySize = sizeof(MIXCONFIG);
mixConfig.RegistryKey = nullptr;
mixConfig.wSize = 30;
mixConfig.wSize = sizeof(MIXCONFIG);
if (lpConfig)
{
if (lpConfig->wSize < 30u)
if (lpConfig->wSize < sizeof(MIXCONFIG))
copySize = lpConfig->wSize;
memcpy(&mixConfig, lpConfig, copySize);
}
Expand All @@ -63,7 +63,7 @@ HANDLE WaveMix::ConfigureInit(MIXCONFIG* lpConfig)

if (GetPrivateProfileIntA("general", "ShowDevices", 0, FileName))
ShowWaveOutDevices();
auto globals = static_cast<GLOBALS*>(LocalAlloc(0x40u, 0x1C0u));
auto globals = static_cast<GLOBALS*>(LocalAlloc(0x40u, sizeof(GLOBALS)));
Globals = globals;
if (!globals)
return nullptr;
Expand Down Expand Up @@ -262,7 +262,7 @@ MIXWAVE* WaveMix::OpenWave(HANDLE hMixSession, LPCSTR szWaveFilename, HINSTANCE
return nullptr;
}

auto mixWave = static_cast<MIXWAVE*>(GlobalLock(GlobalAlloc(0x2040u, 0x42u)));
auto mixWave = static_cast<MIXWAVE*>(GlobalLock(GlobalAlloc(0x2040u, sizeof(MIXWAVE))));
if (!mixWave)
{
if (ShowDebugDialogs)
Expand Down Expand Up @@ -1180,7 +1180,7 @@ int WaveMix::Configure(GLOBALS* hMixSession, HWND hWndParent, MIXCONFIG* lpConfi

if (!mixConfig)
{
mixConfigLocal.wSize = 30;
mixConfigLocal.wSize = sizeof(MIXCONFIG);
mixConfigLocal.dwFlags = 1023;
GetConfig(static_cast<GLOBALS*>(hMixSession), &mixConfigLocal);
auto dialog = MakeSettingsDlgTemplate();
Expand Down Expand Up @@ -1821,7 +1821,7 @@ int WaveMix::Settings_OnInitDialog(HWND hWnd, int wParam, MIXCONFIG* lpMixconfig
GetWindowTextA(hWnd, String, 256);
wsprintfA(string_buffer, String, 2, 81);
SetWindowTextA(hWnd, string_buffer);
SetWindowLongA(hWnd, -21, (LONG)lpMixconfig);
SetWindowLongPtr(hWnd, -21, reinterpret_cast<LONG_PTR>(lpMixconfig));
SendMessageA(GetDlgItem(hWnd, 1000), 0xF1u, lpMixconfig->wChannels > 1u, 0);
SendMessageA(GetDlgItem(hWnd, 1001), 0xF1u, lpMixconfig->ResetMixDefaultFlag != 0, 0);
SendMessageA(GetDlgItem(hWnd, 1004), 0xF1u, lpMixconfig->GoodWavePos != 0, 0);
Expand Down Expand Up @@ -1880,7 +1880,7 @@ int WaveMix::Settings_OnInitDialog(HWND hWnd, int wParam, MIXCONFIG* lpMixconfig

int WaveMix::Settings_OnCommand(HWND hWnd, int command, int lParam, int wParam)
{
auto userData = (MIXCONFIG*)GetWindowLongA(hWnd, -21);
auto userData = reinterpret_cast<MIXCONFIG*>(GetWindowLongPtrA(hWnd, -21));
if (command == 1)
{
if (userData)
Expand Down
6 changes: 3 additions & 3 deletions SpaceCadetPinball/fullscrn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int fullscrn::enableFullscreen()
if (trick)
{
GetWindowRect(GetDesktopWindow(), &Rect);
SetWindowPos(hWnd, (HWND)((int)HWND_MESSAGE | 0x2), 0, 0, Rect.right - Rect.left + 1,
SetWindowPos(hWnd, (HWND)-1, 0, 0, Rect.right - Rect.left + 1,
Rect.bottom - Rect.top + 1, 8u);
}
SmthFullScrnFlag2 = 1;
Expand All @@ -126,7 +126,7 @@ int fullscrn::enableFullscreen()
}
GetWindowRect(GetDesktopWindow(), &Rect);
disableWindowFlagsDisDlg();
SetWindowPos(hWnd, (HWND)0xFFFFFFFE, 0, 0, Rect.right - Rect.left + 1, Rect.bottom - Rect.top + 1, 8u);
SetWindowPos(hWnd, (HWND)-1, 0, 0, Rect.right - Rect.left + 1, Rect.bottom - Rect.top + 1, 8u);
return 0;
}

Expand All @@ -138,7 +138,7 @@ int fullscrn::disableFullscreen()
SmthFullScrnFlag2 = 1;
ChangeDisplaySettingsA(nullptr, 4u);
if (trick)
SetWindowPos(hWnd, (HWND)0xFFFFFFFE, 0, 0, 0, 0, 0x13u);
SetWindowPos(hWnd, (HWND)-1, 0, 0, 0, 0, 0x13u);
}
setWindowFlagsDisDlg();
SetWindowPos(
Expand Down
9 changes: 2 additions & 7 deletions SpaceCadetPinball/gdrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ enum class BitmapType : char
{
None = 0,
RawBitmap = 1,
DibBitmap=2,
DibBitmap = 2,
};


#pragma pack(push, 1)
struct __declspec(align(1)) gdrv_bitmap8
struct gdrv_bitmap8
{
BITMAPINFO* Dib;
char* BmpBufPtr2;
Expand All @@ -22,8 +20,6 @@ struct __declspec(align(1)) gdrv_bitmap8
int XPosition;
int YPosition;
};
#pragma pack(pop)


struct LOGPALETTEx256
{
Expand All @@ -36,7 +32,6 @@ struct LOGPALETTEx256
}
};

static_assert(sizeof(gdrv_bitmap8) == 37, "Wrong size of gdrv_bitmap8");

class gdrv
{
Expand Down
8 changes: 4 additions & 4 deletions SpaceCadetPinball/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ struct soundListStruct
char* PtrToSmth;
};

struct __declspec(align(4)) visualKickerStruct
struct visualKickerStruct
{
float Threshold;
float Boost;
float ThrowBallMult;
vector_type ThrowBallAcceleration;
vector_type ThrowBallAcceleration;
float ThrowBallAngleMult;
int HardHitSoundId;
};


struct __declspec(align(4)) visualStruct
struct visualStruct
{
float Smoothness;
float Elasticity;
Expand Down Expand Up @@ -69,7 +69,7 @@ class loader
static float play_sound(int soundIndex);
static datFileStruct* loader_table;
private:
static errorMsg loader_errors[];
static errorMsg loader_errors[];
static datFileStruct* sound_record_table;
static int sound_count;
static int loader_sound_count;
Expand Down
11 changes: 6 additions & 5 deletions SpaceCadetPinball/maths.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct vector_type
};


struct __declspec(align(4)) rectangle_type
struct rectangle_type
{
int XPosition;
int YPosition;
Expand All @@ -24,7 +24,7 @@ struct circle_type
float RadiusSq;
};

struct __declspec(align(4)) ray_type
struct ray_type
{
vector_type Origin;
vector_type Direction;
Expand All @@ -35,7 +35,7 @@ struct __declspec(align(4)) ray_type
int FieldFlag;
};

struct __declspec(align(4)) line_type
struct line_type
{
vector_type PerpendicularL;
vector_type Direction;
Expand All @@ -59,7 +59,7 @@ struct wall_point_type
float Y1;
};

struct __declspec(align(4)) ramp_plane_type
struct ramp_plane_type
{
vector_type BallCollisionOffset;
vector_type2 V1;
Expand All @@ -84,7 +84,8 @@ class maths
static void cross(vector_type* vec1, vector_type* vec2, vector_type* dstVec);
static float magnitude(vector_type* vec);
static void vector_add(vector_type* vec1Dst, vector_type* vec2);
static float basic_collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float elasticity, float smoothness,
static float basic_collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float elasticity,
float smoothness,
float threshold, float boost);
static float Distance_Squared(vector_type vec1, vector_type vec2);
static float DotProduct(vector_type* vec1, vector_type* vec2);
Expand Down
1 change: 0 additions & 1 deletion SpaceCadetPinball/objlist_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ struct objlist_struct1
int Count;
void* Array[1];
};
static_assert(sizeof(objlist_struct1) == 12, "Wrong size of objlist_struct1");

class objlist_class
{
Expand Down
2 changes: 1 addition & 1 deletion SpaceCadetPinball/options.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "pinball.h"

struct __declspec(align(4)) optionsStruct
struct optionsStruct
{
int Sounds;
int Music;
Expand Down
20 changes: 17 additions & 3 deletions SpaceCadetPinball/partman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#include "partman.h"
#include "gdrv.h"
#include "memory.h"
#include "zdrv.h"

short partman::_field_size[] =
short partman::_field_size[] =
{
2, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0
};
Expand All @@ -14,6 +15,7 @@ datFileStruct* partman::load_records(LPCSTR lpFileName)
_OFSTRUCT ReOpenBuff{};
datFileHeader header{};
dat8BitBmpHeader bmpHeader{};
dat16BitBmpHeader zMapHeader{};

const HFILE fileHandle = OpenFile(lpFileName, &ReOpenBuff, 0);
if (fileHandle == -1)
Expand Down Expand Up @@ -90,11 +92,11 @@ datFileStruct* partman::load_records(LPCSTR lpFileName)
{
auto entryType = static_cast<datFieldTypes>(_lread_char(fileHandle));
entryData->EntryType = entryType;

int fieldSize = _field_size[static_cast<int>(entryType)];
if (fieldSize < 0)
{
fieldSize = _lread_long(fileHandle);
}

if (entryType == datFieldTypes::Bitmap8bit)
{
_hread(fileHandle, &bmpHeader, sizeof(dat8BitBmpHeader));
Expand All @@ -117,6 +119,18 @@ datFileStruct* partman::load_records(LPCSTR lpFileName)
bmp->XPosition = bmpHeader.XPosition;
bmp->YPosition = bmpHeader.YPosition;
}
else if (entryType == datFieldTypes::Bitmap16bit)
{
_hread(fileHandle, &zMapHeader, sizeof(dat16BitBmpHeader));
int length = fieldSize - sizeof(dat16BitBmpHeader);

auto zmap = reinterpret_cast<zmap_header_type*>(memory::allocate(sizeof(zmap_header_type) + length));
zmap->Width = zMapHeader.Width;
zmap->Height = zMapHeader.Height;
zmap->Stride = zMapHeader.Stride;
_hread(fileHandle, zmap->ZBuffer, length);
entryData->Buffer = reinterpret_cast<char*>(zmap);
}
else
{
char* entryBuffer = static_cast<char*>(memory::allocate(fieldSize));
Expand Down
16 changes: 16 additions & 0 deletions SpaceCadetPinball/partman.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ struct dat8BitBmpHeader
static_assert(sizeof(dat8BitBmpHeader) == 14, "Wrong size of dat8BitBmpHeader");



#pragma pack(push, 1)
struct __declspec(align(1)) dat16BitBmpHeader
{
__int16 Width;
__int16 Height;
__int16 Stride;
int Unknown0;
__int16 Unknown1_0;
__int16 Unknown1_1;
};

#pragma pack(pop)

static_assert(sizeof(dat16BitBmpHeader) == 14, "Wrong size of zmap_header_type");

class partman
{
public:
Expand Down
26 changes: 16 additions & 10 deletions SpaceCadetPinball/pinball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int pinball::get_rc_int(int uID, int* dst)
void pinball::FindShiftKeys()
{
signed int i;
int rightShift;
int rightShift;
CHAR stringBuf[20];

RightShift = -1;
Expand Down Expand Up @@ -80,26 +80,32 @@ void pinball::FindShiftKeys()
}


HANDLE pinball::adjust_priority(int priority)
void pinball::adjust_priority(int priority)
{
HANDLE result = GetCurrentThread();
auto thread = GetCurrentThread();
switch (priority)
{
case -2:
return (HANDLE)SetThreadPriority(result, -2);
SetThreadPriority(thread, -2);
break;
case -1:
return (HANDLE)SetThreadPriority(result, -1);
SetThreadPriority(thread, -1);
break;
case 0:
return (HANDLE)SetThreadPriority(result, 0);
SetThreadPriority(thread, 0);
break;
case 1:
return (HANDLE)SetThreadPriority(result, 1);
SetThreadPriority(thread, 1);
break;
case 2:
return (HANDLE)SetThreadPriority(result, 2);
SetThreadPriority(thread, 2);
break;
case 3:
result = (HANDLE)SetThreadPriority(result, 15);
SetThreadPriority(thread, 15);
break;
default:
break;
}
return result;
}

int pinball::make_path_name(LPSTR lpFilename, LPCSTR lpString2, int nSize)
Expand Down
Loading

0 comments on commit cd46791

Please sign in to comment.