From 1c55becab36b1e42a8d050bc6f4376de394b629e Mon Sep 17 00:00:00 2001 From: Troye Date: Thu, 17 Nov 2022 22:09:39 -0600 Subject: [PATCH 1/9] bye software --- tomb3/specific/dxdialog.cpp | 19 +++++++++++++------ tomb3/specific/dxshell.cpp | 9 ++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/tomb3/specific/dxdialog.cpp b/tomb3/specific/dxdialog.cpp index 24320a78..01330026 100644 --- a/tomb3/specific/dxdialog.cpp +++ b/tomb3/specific/dxdialog.cpp @@ -106,32 +106,34 @@ BOOL CALLBACK DXSetupDlgProc(HWND dlg, UINT message, WPARAM wParam, LPARAM lPara break; - case IDC_HARDWARE: + case IDC_SOFTWARE: +#ifndef TROYESTUFF if (!HIWORD(wParam)) { - SendMessage(output_setting, CB_SETCURSEL, 1, 0); + SendMessage(output_setting, CB_SETCURSEL, 0, 0); + SendMessage(resolution, CB_SETCURSEL, 0, 0); DXInitD3DDrivers(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0)); DXInitVideoModes(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0), SendMessage(GetDlgItem(dlg, IDC_OUTPUT_SETTINGS), CB_GETCURSEL, 0, 0)); DXInitTextures(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0), SendMessage(GetDlgItem(dlg, IDC_OUTPUT_SETTINGS), CB_GETCURSEL, 0, 0)); + EnableWindow(GetDlgItem(dlg, IDC_8BIT_TEXTURES), 0); } break; +#endif - case IDC_SOFTWARE: + case IDC_HARDWARE: if (!HIWORD(wParam)) { - SendMessage(output_setting, CB_SETCURSEL, 0, 0); - SendMessage(resolution, CB_SETCURSEL, 0, 0); + SendMessage(output_setting, CB_SETCURSEL, 1, 0); DXInitD3DDrivers(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0)); DXInitVideoModes(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0), SendMessage(GetDlgItem(dlg, IDC_OUTPUT_SETTINGS), CB_GETCURSEL, 0, 0)); DXInitTextures(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0), SendMessage(GetDlgItem(dlg, IDC_OUTPUT_SETTINGS), CB_GETCURSEL, 0, 0)); - EnableWindow(GetDlgItem(dlg, IDC_8BIT_TEXTURES), 0); } break; @@ -740,6 +742,11 @@ void DXInitDialogBox(HWND hwnd) else nDD = G_DeviceInfo->nDDInfo - 1; +#ifdef TROYESTUFF + SendMessage(GetDlgItem(hwnd, IDC_SOFTWARE), BM_SETCHECK, 0, 0); + EnableWindow(GetDlgItem(hwnd, IDC_SOFTWARE), 0); +#endif + SendMessage(gfx, CB_SETCURSEL, nDD, 0); DXCheckMMXTechnology(hwnd); DXInitD3DDrivers(hwnd, nDD); diff --git a/tomb3/specific/dxshell.cpp b/tomb3/specific/dxshell.cpp index 8aa01346..9f4905ef 100644 --- a/tomb3/specific/dxshell.cpp +++ b/tomb3/specific/dxshell.cpp @@ -761,9 +761,15 @@ HRESULT CALLBACK DXEnumDirect3D(LPGUID lpGuid, LPSTR description, LPSTR name, LP if (!lpHWDesc->dwFlags) { if (lpHELDesc->dcmColorModel & D3DCOLOR_MONO || SoftwareRenderer == 1) - return 1; + return D3DENUMRET_OK; } +#ifdef TROYESTUFF + SoftwareRenderer = 0; + + if (!lpHWDesc->dwFlags) //disable software + return D3DENUMRET_OK; +#else if (!lpHWDesc->dwFlags) { SoftwareRenderer = 1; @@ -779,6 +785,7 @@ HRESULT CALLBACK DXEnumDirect3D(LPGUID lpGuid, LPSTR description, LPSTR name, LP strcpy(name, "RGB Emulation"); } } +#endif if (lpHWDesc->dwFlags && !lpHWDesc->dpcTriCaps.dwTextureCaps) return D3DENUMRET_OK; From f9d6219c1b8b7baf50acbed9046431cfd629370c Mon Sep 17 00:00:00 2001 From: Troye Date: Fri, 18 Nov 2022 10:31:09 -0600 Subject: [PATCH 2/9] experimental windowed support --- CHANGELOG.md | 1 + tomb3/3dsystem/3d_gen.cpp | 2 + tomb3/global/types.h | 6 ++ tomb3/specific/dxdialog.cpp | 32 +++++- tomb3/specific/dxshell.cpp | 65 +++++++++++- tomb3/specific/dxshell.h | 4 + tomb3/specific/file.cpp | 4 + tomb3/specific/fmv.cpp | 13 +++ tomb3/specific/output.cpp | 4 + tomb3/specific/picture.cpp | 46 +++++++-- tomb3/specific/winmain.cpp | 200 +++++++++++++++++++++++++++++++----- tomb3/specific/winmain.h | 4 + tomb3/tomb3/tomb3.cpp | 7 ++ 13 files changed, 349 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11025791..71bbd5cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Add option for PSX mono screen colors. - Move saves to a designated folder. - Add support for The Lost Artifact. +- Add experimental Windowed support. ### tomb3 bug fixes diff --git a/tomb3/3dsystem/3d_gen.cpp b/tomb3/3dsystem/3d_gen.cpp index c144aabb..bb2c0534 100644 --- a/tomb3/3dsystem/3d_gen.cpp +++ b/tomb3/3dsystem/3d_gen.cpp @@ -489,7 +489,9 @@ void phd_InitWindow(long x, long y, long w, long h, long znear, long zfar, long phd_WindowRect.top = phd_winymin; phd_WindowRect.right = phd_winxmin + phd_winwidth; +#ifndef TROYESTUFF if (!App.nRenderMode || App.nRenderMode == 1) +#endif { InsertObjectGT3 = HWI_InsertObjectGT3_Sorted; InsertObjectGT4 = HWI_InsertObjectGT4_Sorted; diff --git a/tomb3/global/types.h b/tomb3/global/types.h index 06c4d9b4..87064424 100644 --- a/tomb3/global/types.h +++ b/tomb3/global/types.h @@ -2044,6 +2044,12 @@ struct TOMB3_OPTIONS float INV_Scale; float unwater_music_mute; float inv_music_mute; + + //windowed stuff, move to WINAPP when possible + RECT rScreen; + RECT rViewport; + ulong WindowStyle; + bool Windowed; }; #endif #pragma pack(pop) \ No newline at end of file diff --git a/tomb3/specific/dxdialog.cpp b/tomb3/specific/dxdialog.cpp index 01330026..ad2da3d2 100644 --- a/tomb3/specific/dxdialog.cpp +++ b/tomb3/specific/dxdialog.cpp @@ -3,6 +3,7 @@ #include "winmain.h" #ifdef TROYESTUFF #include "smain.h" +#include "../tomb3/tomb3.h" #endif //these are the BOXES/BUTTONS not the text @@ -39,6 +40,14 @@ BOOL CALLBACK DXSetupDlgProc(HWND dlg, UINT message, WPARAM wParam, LPARAM lPara DXInitDialogBox(dlg); output_setting = GetDlgItem(dlg, IDC_OUTPUT_SETTINGS); resolution = GetDlgItem(dlg, IDC_RESOLUTION); +#ifdef TROYESTUFF + SendMessage(output_setting, CB_SETCURSEL, 1, 0); + DXInitD3DDrivers(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0)); + DXInitVideoModes(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0), + SendMessage(GetDlgItem(dlg, IDC_OUTPUT_SETTINGS), CB_GETCURSEL, 0, 0)); + DXInitTextures(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0), + SendMessage(GetDlgItem(dlg, IDC_OUTPUT_SETTINGS), CB_GETCURSEL, 0, 0)); +#endif return 1; } @@ -61,6 +70,9 @@ BOOL CALLBACK DXSetupDlgProc(HWND dlg, UINT message, WPARAM wParam, LPARAM lPara G_DXConfig->Filter = (bool)SendMessage(GetDlgItem(dlg, IDC_BILINEAR), BM_GETCHECK, 0, 0); G_DXConfig->sound = !(bool)SendMessage(GetDlgItem(dlg, IDC_DISABLE_SOUND), BM_GETCHECK, 0, 0); G_DXConfig->Joystick = !(bool)SendMessage(GetDlgItem(dlg, IDC_DISABLE_JOYSTICK), BM_GETCHECK, 0, 0); +#ifdef TROYESTUFF + tomb3.Windowed = (bool)SendMessage(GetDlgItem(dlg, IDC_SOFTWARE), BM_GETCHECK, 0, 0); +#endif if ((ushort)wParam == IDOK) { @@ -108,9 +120,11 @@ BOOL CALLBACK DXSetupDlgProc(HWND dlg, UINT message, WPARAM wParam, LPARAM lPara case IDC_SOFTWARE: -#ifndef TROYESTUFF if (!HIWORD(wParam)) { +#ifdef TROYESTUFF + SendMessage(GetDlgItem(dlg, IDC_HARDWARE), BM_SETCHECK, 0, 0); +#else SendMessage(output_setting, CB_SETCURSEL, 0, 0); SendMessage(resolution, CB_SETCURSEL, 0, 0); DXInitD3DDrivers(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0)); @@ -119,21 +133,25 @@ BOOL CALLBACK DXSetupDlgProc(HWND dlg, UINT message, WPARAM wParam, LPARAM lPara DXInitTextures(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0), SendMessage(GetDlgItem(dlg, IDC_OUTPUT_SETTINGS), CB_GETCURSEL, 0, 0)); EnableWindow(GetDlgItem(dlg, IDC_8BIT_TEXTURES), 0); +#endif } break; -#endif case IDC_HARDWARE: if (!HIWORD(wParam)) { +#ifdef TROYESTUFF + SendMessage(GetDlgItem(dlg, IDC_SOFTWARE), BM_SETCHECK, 0, 0); +#else SendMessage(output_setting, CB_SETCURSEL, 1, 0); DXInitD3DDrivers(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0)); DXInitVideoModes(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0), SendMessage(GetDlgItem(dlg, IDC_OUTPUT_SETTINGS), CB_GETCURSEL, 0, 0)); DXInitTextures(dlg, SendMessage(GetDlgItem(dlg, IDC_GRAPHICS_ADAPTER), CB_GETCURSEL, 0, 0), SendMessage(GetDlgItem(dlg, IDC_OUTPUT_SETTINGS), CB_GETCURSEL, 0, 0)); +#endif } break; @@ -267,8 +285,10 @@ void DXInitD3DDrivers(HWND hwnd, long nDrivers) SendMessage(agp_mem, BM_SETCHECK, 1, 0); } +#ifndef TROYESTUFF SendMessage(HWR, BM_SETCHECK, 1, 0); SendMessage(SWR, BM_SETCHECK, 0, 0); +#endif SendMessage(zbuffer, BM_SETCHECK, 1, 0); SendMessage(filter, BM_SETCHECK, 1, 0); SendMessage(dither, BM_SETCHECK, 1, 0); @@ -276,6 +296,7 @@ void DXInitD3DDrivers(HWND hwnd, long nDrivers) } else { +#ifndef TROYESTUFF SendMessage(zbuffer, BM_SETCHECK, 0, 0); SendMessage(filter, BM_SETCHECK, 0, 0); SendMessage(dither, BM_SETCHECK, 0, 0); @@ -301,6 +322,7 @@ void DXInitD3DDrivers(HWND hwnd, long nDrivers) SendMessage(tex_8bit, BM_SETCHECK, 0, 0); SendMessage(agp_mem, BM_SETCHECK, 0, 0); +#endif } } @@ -466,6 +488,7 @@ void DXInitTextures(HWND hwnd, long nDD, long nD3D) else EnableWindow(GetDlgItem(hwnd, IDC_8BIT_TEXTURES), 0); +#ifndef TROYESTUFF if (G_DXConfig->MMX && SendMessage(GetDlgItem(hwnd, IDC_SOFTWARE), BM_GETCHECK, 0, 0)) { if (!found) @@ -485,6 +508,7 @@ void DXInitTextures(HWND hwnd, long nDD, long nD3D) } } } +#endif if (!found) { @@ -743,8 +767,10 @@ void DXInitDialogBox(HWND hwnd) nDD = G_DeviceInfo->nDDInfo - 1; #ifdef TROYESTUFF + SendMessage(GetDlgItem(hwnd, IDC_HARDWARE), WM_SETTEXT, 0, (LPARAM)("Fullscreen")); + SendMessage(GetDlgItem(hwnd, IDC_HARDWARE), BM_SETCHECK, 1, 0); + SendMessage(GetDlgItem(hwnd, IDC_SOFTWARE), WM_SETTEXT, 0, (LPARAM)("Windowed")); SendMessage(GetDlgItem(hwnd, IDC_SOFTWARE), BM_SETCHECK, 0, 0); - EnableWindow(GetDlgItem(hwnd, IDC_SOFTWARE), 0); #endif SendMessage(gfx, CB_SETCURSEL, nDD, 0); diff --git a/tomb3/specific/dxshell.cpp b/tomb3/specific/dxshell.cpp index 9f4905ef..bd8cf35e 100644 --- a/tomb3/specific/dxshell.cpp +++ b/tomb3/specific/dxshell.cpp @@ -6,6 +6,9 @@ #include "mmx.h" #include "drawprimitive.h" #include "display.h" +#ifdef TROYESTUFF +#include "../tomb3/tomb3.h" +#endif //statics #define G_ddraw VAR_(0x006CA0F8, LPDIRECTDRAWX) @@ -502,7 +505,11 @@ bool DXCheckForLostSurfaces() pass = pass || SUCCEEDED(DD_EnsureSurfaceAvailable(App.lpPictureBuffer, 0, 0)); +#ifdef TROYESTUFF + if (pass && !GtWindowClosed) +#else if (pass && !GtWindowClosed && App.nRenderMode == 1) +#endif HWR_GetAllTextureHandles(); return pass; @@ -522,7 +529,9 @@ void DXClearBuffers(ulong flags, ulong color) r.right = dm->w; r.bottom = dm->h; +#ifndef TROYESTUFF if (App.nRenderMode == 1) +#endif { sflags = 0; @@ -541,8 +550,10 @@ void DXClearBuffers(ulong flags, ulong color) App.lpViewPort->Clear(1, &vr, sflags); } } +#ifndef TROYESTUFF else if (flags & 2) DD_ClearSurface(App.lpBackBuffer, &r, color); +#endif if (flags & 1) DD_ClearSurface(App.lpFrontBuffer, &r, color); @@ -583,7 +594,14 @@ bool DXUpdateFrame(bool runMessageLoop, LPRECT rect) w = d3dinfo->DisplayMode[App.DXConfigPtr->nVMode].w; if (d3dinfo->bHardware) - App.lpFrontBuffer->Flip(0, DDFLIP_WAIT); + { +#ifdef TROYESTUFF + if (tomb3.Windowed) + App.lpFrontBuffer->Blt(&tomb3.rScreen, App.lpBackBuffer, &tomb3.rViewport, DDBLT_WAIT, 0); + else +#endif + App.lpFrontBuffer->Flip(0, DDFLIP_WAIT); + } else { memset(&desc, 0, sizeof(DDSURFACEDESCX)); @@ -999,6 +1017,51 @@ bool DXSwitchVideoMode(long needed, long current, bool disableZBuffer) return change; } +#ifdef TROYESTUFF +long DXToggleFullScreen() +{ + if (tomb3.Windowed) + { + Log("DXToggleFullScreen: Switching to Fullscreen"); + tomb3.Windowed = 0; + } + else + { + Log("DXToggleFullScreen: Switching to Windowed"); + tomb3.Windowed = 1; + } + + if (WinDXInit(&App.DeviceInfo, &App.DXConfig, 0)) + { + Log("DXToggleFullScreen: Switched successfully"); + return 1; + } + + Log("DXToggleFullScreen: Switching failed, try to revert"); + tomb3.Windowed = !tomb3.Windowed; + + if (WinDXInit(&App.DeviceInfo, &App.DXConfig, 0)) + { + Log("DXToggleFullScreen: reverted fine"); + return 0; + } + + S_ExitSystem("Failed to reinit DX after DXToggleFullScreen"); + return -1; +} + +void DXMove(long x, long y) +{ + DISPLAYMODE* dm; + + if (!tomb3.Windowed) + return; + + dm = &App.DeviceInfoPtr->DDInfo[App.DXConfigPtr->nDD].D3DInfo[App.DXConfigPtr->nD3D].DisplayMode[App.DXConfigPtr->nVMode]; + SetRect(&tomb3.rScreen, x, y, x + dm->w, y + dm->h); +} +#endif + void inject_dxshell(bool replace) { INJECT(0x0048FDB0, BPPToDDBD, replace); diff --git a/tomb3/specific/dxshell.h b/tomb3/specific/dxshell.h index 8936286f..0b4d6fe9 100644 --- a/tomb3/specific/dxshell.h +++ b/tomb3/specific/dxshell.h @@ -32,3 +32,7 @@ void DXGetDeviceInfo(DEVICEINFO* device, HWND hWnd, HINSTANCE hInstance); void SWRBlit32to15(ulong* dest, ulong* src, ulong w); HRESULT CALLBACK DXEnumDirect3D(LPGUID lpGuid, LPSTR description, LPSTR name, LPD3DDEVICEDESC lpHWDesc, LPD3DDEVICEDESC lpHELDesc, LPVOID lpContext); bool DXSwitchVideoMode(long needed, long current, bool disableZBuffer); +#ifdef TROYESTUFF +long DXToggleFullScreen(); +void DXMove(long x, long y); +#endif diff --git a/tomb3/specific/file.cpp b/tomb3/specific/file.cpp index bb488040..7ac07fce 100644 --- a/tomb3/specific/file.cpp +++ b/tomb3/specific/file.cpp @@ -76,6 +76,7 @@ long LoadTexturePages(HANDLE file) MyReadFile(file, &nPages, sizeof(long), &read, 0); +#ifndef TROYESTUFF if (!App.nRenderMode) { for (int i = 0; i < nPages; i++) @@ -89,6 +90,7 @@ long LoadTexturePages(HANDLE file) SetFilePointer(file, nPages << 17, 0, FILE_CURRENT); return 1; } +#endif _16bit = !App.DeviceInfoPtr->DDInfo[App.DXConfigPtr->nDD].D3DInfo[App.DXConfigPtr->nD3D].Texture[App.DXConfigPtr->D3DTF].bPalette; size = _16bit ? 0x20000 : 0x10000; @@ -769,7 +771,9 @@ long LoadLevel(const char* name, long number) void S_UnloadLevelFile() { +#ifndef TROYESTUFF if (App.nRenderMode == 1) +#endif HWR_FreeTexturePages(); LastLoadedLevelPath[0] = 0; diff --git a/tomb3/specific/fmv.cpp b/tomb3/specific/fmv.cpp index 774fe626..faadf0dd 100644 --- a/tomb3/specific/fmv.cpp +++ b/tomb3/specific/fmv.cpp @@ -3,11 +3,19 @@ #include "specific.h" #include "winmain.h" #include "file.h" +#ifdef TROYESTUFF +#include "../tomb3/tomb3.h" +#endif long fmv_playing; long FMV_Play(char* name) { +#ifdef TROYESTUFF + if (tomb3.Windowed) + return 0; +#endif + fmv_playing = 1; S_CDStop(); ShowCursor(0); @@ -25,6 +33,11 @@ long FMV_Play(char* name) long FMV_PlayIntro(char* name1, char* name2) { +#ifdef TROYESTUFF + if (tomb3.Windowed) + return 0; +#endif + fmv_playing = 1; ShowCursor(0); WinFreeDX(0); diff --git a/tomb3/specific/output.cpp b/tomb3/specific/output.cpp index 5c46061d..46c6276f 100644 --- a/tomb3/specific/output.cpp +++ b/tomb3/specific/output.cpp @@ -574,7 +574,9 @@ void S_InitialiseScreen(long type) //Empty function call here +#ifndef TROYESTUFF if (App.nRenderMode) +#endif HWR_InitState(); } @@ -682,9 +684,11 @@ void S_InitialisePolyList(bool clearBackBuffer) clearBackBuffer = 0; } +#ifndef TROYESTUFF if (!App.nRenderMode) flags = 272; else +#endif { if (clearBackBuffer || HWConfig.nFillMode < D3DFILL_SOLID) flags = 258; diff --git a/tomb3/specific/picture.cpp b/tomb3/specific/picture.cpp index 0d0333c1..7eadcde5 100644 --- a/tomb3/specific/picture.cpp +++ b/tomb3/specific/picture.cpp @@ -315,12 +315,27 @@ void CreateMonoScreen() dm = &App.DeviceInfoPtr->DDInfo[App.DXConfigPtr->nDD].D3DInfo[App.DXConfigPtr->nD3D].DisplayMode[App.DXConfigPtr->nVMode]; - if (dm->w == 640 && dm->h == 480) - ConvertSurfaceToTextures(App.lpFrontBuffer); +#ifdef TROYESTUFF + if (tomb3.Windowed) + { + if (dm->w == 640 && dm->h == 480) + ConvertSurfaceToTextures(App.lpBackBuffer); + else + { + App.lpPictureBuffer->Blt(0, App.lpBackBuffer, 0, DDBLT_WAIT, 0); + ConvertSurfaceToTextures(App.lpPictureBuffer); + } + } else +#endif { - App.lpPictureBuffer->Blt(0, App.lpFrontBuffer, 0, DDBLT_WAIT, 0); - ConvertSurfaceToTextures(App.lpPictureBuffer); + if (dm->w == 640 && dm->h == 480) + ConvertSurfaceToTextures(App.lpFrontBuffer); + else + { + App.lpPictureBuffer->Blt(0, App.lpFrontBuffer, 0, DDBLT_WAIT, 0); + ConvertSurfaceToTextures(App.lpPictureBuffer); + } } HWR_GetAllTextureHandles(); @@ -432,12 +447,27 @@ void S_FadeToBlack() dm = &App.DeviceInfoPtr->DDInfo[App.DXConfigPtr->nDD].D3DInfo[App.DXConfigPtr->nD3D].DisplayMode[App.DXConfigPtr->nVMode]; - if (dm->w == 640 && dm->h == 480) - ConvertSurfaceToTextures(App.lpFrontBuffer); +#ifdef TROYESTUFF + if (tomb3.Windowed) + { + if (dm->w == 640 && dm->h == 480) + ConvertSurfaceToTextures(App.lpBackBuffer); + else + { + App.lpPictureBuffer->Blt(0, App.lpBackBuffer, 0, DDBLT_WAIT, 0); + ConvertSurfaceToTextures(App.lpPictureBuffer); + } + } +#endif else { - App.lpPictureBuffer->Blt(0, App.lpFrontBuffer, 0, DDBLT_WAIT, 0); - ConvertSurfaceToTextures(App.lpPictureBuffer); + if (dm->w == 640 && dm->h == 480) + ConvertSurfaceToTextures(App.lpFrontBuffer); + else + { + App.lpPictureBuffer->Blt(0, App.lpFrontBuffer, 0, DDBLT_WAIT, 0); + ConvertSurfaceToTextures(App.lpPictureBuffer); + } } HWR_GetAllTextureHandles(); diff --git a/tomb3/specific/winmain.cpp b/tomb3/specific/winmain.cpp index d896717f..7b7e5c9e 100644 --- a/tomb3/specific/winmain.cpp +++ b/tomb3/specific/winmain.cpp @@ -31,9 +31,18 @@ bool WinDXInit(DEVICEINFO* device, DXCONFIG* config, bool createNew) D3DMATERIALX m; DDSCAPSX caps; D3DMATERIALHANDLE handle; +#ifdef TROYESTUFF + LPDIRECTDRAWCLIPPER clipper; + RECT r; + HWND desktop; + DEVMODE dev; + HDC hDC; +#endif Log("Starting WinDXInit"); +#ifndef TROYESTUFF App.nRenderMode = 1; +#endif if (createNew) { @@ -44,55 +53,142 @@ bool WinDXInit(DEVICEINFO* device, DXCONFIG* config, bool createNew) } } - if (!DXSetCooperativeLevel(App.lpDD, App.WindowHandle, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE)) +#ifdef TROYESTUFF + if (tomb3.Windowed) { - Log("DXSetCooperativeLevel failed: DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE, exitting.."); - return 0; + if (!DXSetCooperativeLevel(App.lpDD, App.WindowHandle, DDSCL_NORMAL)) + { + Log("DXSetCooperativeLevel failed: DDSCL_NORMAL, exitting.."); + return 0; + } + } + else +#endif + { + if (!DXSetCooperativeLevel(App.lpDD, App.WindowHandle, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE)) + { + Log("DXSetCooperativeLevel failed: DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE, exitting.."); + return 0; + } } dm = &device->DDInfo[config->nDD].D3DInfo[config->nD3D].DisplayMode[config->nVMode]; - if (!DXSetVideoMode(App.lpDD, dm->w, dm->h, dm->bpp)) +#ifdef TROYESTUFF + if (tomb3.Windowed) { - Log("DXSetVideoMode failed, exitting.."); - return 0; + desktop = GetDesktopWindow(); + hDC = GetDC(desktop); + ReleaseDC(desktop, hDC); + dev.dmBitsPerPel = dm->bpp; + dev.dmSize = sizeof(DEVMODE); + dev.dmFields = DM_BITSPERPEL; + ChangeDisplaySettings(&dev, 0); + } + else +#endif + { + if (!DXSetVideoMode(App.lpDD, dm->w, dm->h, dm->bpp)) + { + Log("DXSetVideoMode failed, exitting.."); + return 0; + } } memset(&desc, 0, sizeof(DDSURFACEDESCX)); desc.dwSize = sizeof(DDSURFACEDESCX); - desc.dwBackBufferCount = 1; - desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; - desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE; - if (!DXCreateSurface(App.lpDD, &desc, (LPDIRECTDRAWSURFACEX)&App.lpFrontBuffer)) +#ifdef TROYESTUFF + if (tomb3.Windowed) { - Log("DXCreateSurface failed to create front buffer, exitting.."); - return 0; - } + Log("Creating windowed mode!"); + d3d = &device->DDInfo[config->nDD].D3DInfo[config->nD3D]; + dm = &d3d->DisplayMode[config->nVMode]; + r.top = 0; + r.left = 0; + r.right = dm->w; + r.bottom = dm->h; + AdjustWindowRect(&r, tomb3.WindowStyle, 0); + SetWindowPos(App.WindowHandle, 0, 0, 0, r.right - r.left, r.bottom - r.top, SWP_NOMOVE | SWP_NOZORDER); + GetClientRect(App.WindowHandle, &tomb3.rViewport); + GetClientRect(App.WindowHandle, &tomb3.rScreen); + ClientToScreen(App.WindowHandle, (LPPOINT)&tomb3.rScreen); + ClientToScreen(App.WindowHandle, (LPPOINT)&tomb3.rScreen.right); + desc.dwFlags = DDSD_CAPS; + desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + + if (!DXCreateSurface(App.lpDD, &desc, (LPDIRECTDRAWSURFACEX)&App.lpFrontBuffer)) + { + Log("DXCreateSurface failed to create front buffer (windowed mode), exitting.."); + return 0; + } - App.lpFrontBuffer->GetSurfaceDesc(&desc); - d3d = &device->DDInfo[config->nDD].D3DInfo[config->nD3D]; - dm = &d3d->DisplayMode[config->nVMode]; + if (FAILED(App.lpDD->CreateClipper(0, &clipper, 0))) + { + Log("Failed to CreateClipper"); + return 0; + } - DXBitMask2ShiftCnt(desc.ddpfPixelFormat.dwRBitMask, &dm->rshift, &dm->rbpp); - DXBitMask2ShiftCnt(desc.ddpfPixelFormat.dwGBitMask, &dm->gshift, &dm->gbpp); - DXBitMask2ShiftCnt(desc.ddpfPixelFormat.dwBBitMask, &dm->bshift, &dm->bbpp); + clipper->SetHWnd(0, App.WindowHandle); + App.lpFrontBuffer->SetClipper(clipper); + clipper->Release(); + clipper = 0; - if (d3d->bHardware) - { - caps.dwCaps = DDSCAPS_BACKBUFFER; + desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; + desc.dwWidth = dm->w; + desc.dwHeight = dm->h; + desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; - if (!DXGetAttachedSurface(App.lpFrontBuffer, &caps, &App.lpBackBuffer)) + if (!DXCreateSurface(App.lpDD, &desc, (LPDIRECTDRAWSURFACEX)&App.lpBackBuffer)) { - Log("DXGetAttachedSurface failed to get back buffer, exitting.."); + Log("DXCreateSurface failed to create back buffer (windowed mode), exitting.."); return 0; } } else +#endif { - App.unk = (ulong*)malloc(4 * dm->w * dm->h); - caps.dwCaps = DDSCAPS_BACKBUFFER; - DXGetAttachedSurface(App.lpFrontBuffer, &caps, &App.lpBackBuffer); + desc.dwBackBufferCount = 1; + desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; + desc.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE; + + if (!DXCreateSurface(App.lpDD, &desc, (LPDIRECTDRAWSURFACEX)&App.lpFrontBuffer)) + { + Log("DXCreateSurface failed to create front buffer, exitting.."); + return 0; + } + + App.lpFrontBuffer->GetSurfaceDesc(&desc); + d3d = &device->DDInfo[config->nDD].D3DInfo[config->nD3D]; + dm = &d3d->DisplayMode[config->nVMode]; + + DXBitMask2ShiftCnt(desc.ddpfPixelFormat.dwRBitMask, &dm->rshift, &dm->rbpp); + DXBitMask2ShiftCnt(desc.ddpfPixelFormat.dwGBitMask, &dm->gshift, &dm->gbpp); + DXBitMask2ShiftCnt(desc.ddpfPixelFormat.dwBBitMask, &dm->bshift, &dm->bbpp); + + if (d3d->bHardware) + { + caps.dwCaps = DDSCAPS_BACKBUFFER; + + if (!DXGetAttachedSurface(App.lpFrontBuffer, &caps, &App.lpBackBuffer)) + { + Log("DXGetAttachedSurface failed to get back buffer, exitting.."); + return 0; + } + } + else + { + App.unk = (ulong*)malloc(4 * dm->w * dm->h); + caps.dwCaps = DDSCAPS_BACKBUFFER; + DXGetAttachedSurface(App.lpFrontBuffer, &caps, &App.lpBackBuffer); + } + +#ifdef TROYESTUFF + tomb3.rViewport.top = 0; + tomb3.rViewport.left = 0; + tomb3.rViewport.right = dm->w; + tomb3.rViewport.bottom = dm->h; +#endif } if (!DXCreateZBuffer(device, config)) @@ -160,7 +256,9 @@ LRESULT CALLBACK WinAppProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) switch (uMsg) { case WM_CREATE: +#ifndef TROYESTUFF ShowCursor(0); +#endif break; case WM_ACTIVATE: @@ -183,6 +281,12 @@ LRESULT CALLBACK WinAppProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) WinAppExit(); PostQuitMessage(0); break; + +#ifdef TROYESTUFF + case WM_MOVE: + DXMove(LOWORD(lParam), HIWORD(lParam)); + break; +#endif } return DefWindowProc(hwnd, uMsg, wParam, lParam); @@ -199,14 +303,26 @@ long WinRegisterWindow(HINSTANCE hinstance) App.WindowClass.lpfnWndProc = WinAppProc; App.WindowClass.cbClsExtra = 0; App.WindowClass.cbWndExtra = 0; +#ifdef TROYESTUFF + App.WindowClass.hCursor = LoadCursor(0, IDC_ARROW); +#endif return RegisterClass(&App.WindowClass); } +#ifdef TROYESTUFF +HWND WinCreateWindow(HINSTANCE hinstance, long nCmdShow, RECT* r) +#else HWND WinCreateWindow(HINSTANCE hinstance, long nCmdShow) +#endif { HWND hwnd; +#ifdef TROYESTUFF + hwnd = CreateWindowEx(WS_EX_APPWINDOW, "Window Class", "Tomb Raider III", tomb3.WindowStyle, + CW_USEDEFAULT, CW_USEDEFAULT, r->right - r->left, r->bottom - r->top, 0, 0, hinstance, 0); +#else hwnd = CreateWindowEx(WS_EX_APPWINDOW, "Window Class", "Tomb Raider III", WS_POPUP, 0, 0, 0, 0, 0, 0, hinstance, 0); +#endif if (hwnd) { @@ -313,19 +429,36 @@ void WinFreeDX(bool free_dd) int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd) { DIRECT3DINFO* d3dinfo; +#ifdef TROYESTUFF + RECT r; +#endif bool hw; G_lpCmdLine = lpCmdLine; memset(&App, 0, sizeof(WINAPP)); App.hInstance = hInstance; +#ifdef TROYESTUFF + tomb3.WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION; +#endif + if (!hPrevInstance && !WinRegisterWindow(hInstance)) { MessageBox(0, "Unable To Register Window Class", "", MB_OK); return 0; } +#ifdef TROYESTUFF + r.left = 0; + r.top = 0; + r.right = 640; + r.bottom = 480; + AdjustWindowRect(&r, tomb3.WindowStyle, 0); + App.WindowHandle = WinCreateWindow(hInstance, nShowCmd, &r); +#else App.WindowHandle = WinCreateWindow(hInstance, nShowCmd); +#endif + if (!App.WindowHandle) { @@ -364,6 +497,19 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd return 0; } +#ifdef TROYESTUFF + if (!tomb3.Windowed) + { + SetWindowLongPtr(App.WindowHandle, GWL_STYLE, WS_POPUP); + SetWindowPos(App.WindowHandle, 0, tomb3.rScreen.left, tomb3.rScreen.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); + UpdateWindow(App.WindowHandle); + ShowWindow(App.WindowHandle, nShowCmd); + + SetCursor(0); + ShowCursor(0); + } +#endif + d3dinfo = &App.DeviceInfoPtr->DDInfo[App.DXConfigPtr->nDD].D3DInfo[App.DXConfigPtr->nD3D]; if (!(d3dinfo->DeviceDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_ALPHA)) diff --git a/tomb3/specific/winmain.h b/tomb3/specific/winmain.h index d7d267c9..d07e6ccf 100644 --- a/tomb3/specific/winmain.h +++ b/tomb3/specific/winmain.h @@ -7,7 +7,11 @@ bool WinDXInit(DEVICEINFO* device, DXCONFIG* config, bool createNew); void WinAppExit(); LRESULT CALLBACK WinAppProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); long WinRegisterWindow(HINSTANCE hinstance); +#ifdef TROYESTUFF +HWND WinCreateWindow(HINSTANCE hinstance, long nCmdShow, RECT* r); +#else HWND WinCreateWindow(HINSTANCE hinstance, long nCmdShow); +#endif float WinFrameRate(); void WinFreeDX(bool free_dd); int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd); diff --git a/tomb3/tomb3/tomb3.cpp b/tomb3/tomb3/tomb3.cpp index d1e4c9f2..f0bdc417 100644 --- a/tomb3/tomb3/tomb3.cpp +++ b/tomb3/tomb3/tomb3.cpp @@ -56,6 +56,7 @@ static void T3_InitSettings() Option_SFX_Volume = 10; S_CDVolume(25 * Option_Music_Volume + 5); S_SoundSetMasterVolume(6 * Option_SFX_Volume + 4); + tomb3.Windowed = 0; tomb3.footprints = 1; tomb3.pickup_display = 1; @@ -119,6 +120,9 @@ void T3_SaveSettings() REG_WriteLong((char*)"MMX", App.DXConfigPtr->MMX); REG_WriteLong((char*)"SFXVolume", Option_SFX_Volume); REG_WriteLong((char*)"MusicVolume", Option_Music_Volume); + REG_WriteBool((char*)"Window", tomb3.Windowed); + REG_WriteLong((char*)"WindowX", tomb3.rScreen.left); + REG_WriteLong((char*)"WindowY", tomb3.rScreen.top); REG_WriteFloat((char*)"Gamma", GammaOption); REG_WriteBlock((char*)"keyLayout", &layout[1][0], sizeof(layout) / 2); @@ -191,6 +195,9 @@ bool T3_LoadSettings() REG_ReadLong((char*)"MMX", (ulong&)App.DXConfigPtr->MMX, 0); REG_ReadLong((char*)"SFXVolume", (ulong&)Option_SFX_Volume, 0); REG_ReadLong((char*)"MusicVolume", (ulong&)Option_Music_Volume, 0); + REG_ReadBool((char*)"Window", tomb3.Windowed, 0); + REG_ReadLong((char*)"WindowX", (ulong&)tomb3.rScreen.left, 0); + REG_ReadLong((char*)"WindowY", (ulong&)tomb3.rScreen.top, 0); REG_ReadFloat((char*)"Gamma", GammaOption, 0); REG_ReadBlock((char*)"keyLayout", &layout[1][0], sizeof(layout) / 2, 0); From 603201c318d67bb8b692ae1180f2768ffbd43c52 Mon Sep 17 00:00:00 2001 From: Troye Date: Fri, 18 Nov 2022 17:49:12 -0600 Subject: [PATCH 3/9] fix track pausing --- tomb3/specific/audio.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tomb3/specific/audio.cpp b/tomb3/specific/audio.cpp index 162a8b0d..1f1bbb20 100644 --- a/tomb3/specific/audio.cpp +++ b/tomb3/specific/audio.cpp @@ -178,14 +178,32 @@ long ACMGetTrackLocation() return long((float(timeGetTime() - acm_start_time) / (float)CLOCKS_PER_SEC) * 60.0F); } +#ifdef TROYESTUFF +static bool ACMIsTrackPlaying() +{ + ulong status; + + if (DSBuffer->GetStatus(&status) == DS_OK) + { + if (status & DSBSTATUS_PLAYING) + return 1; + } + + return 0; +} +#endif + void ACMSetVolume(long volume) { #ifdef TROYESTUFF static bool paused; + if (!DSBuffer) + return; + if (!volume) { - if (!paused) + if (!paused && ACMIsTrackPlaying()) { DSBuffer->Stop(); paused = 1; From 0882bdbc5260341bc306eb61a863ef1e4ae8685c Mon Sep 17 00:00:00 2001 From: Troye Date: Fri, 18 Nov 2022 18:13:40 -0600 Subject: [PATCH 4/9] improve window --- tomb3/specific/winmain.cpp | 43 +++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/tomb3/specific/winmain.cpp b/tomb3/specific/winmain.cpp index 7b7e5c9e..5a520350 100644 --- a/tomb3/specific/winmain.cpp +++ b/tomb3/specific/winmain.cpp @@ -294,7 +294,7 @@ LRESULT CALLBACK WinAppProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) long WinRegisterWindow(HINSTANCE hinstance) { - App.WindowClass.hIcon = LoadIconA(hinstance, (LPCSTR)115); //todo: icon resource define + App.WindowClass.hIcon = LoadIcon(hinstance, (LPCSTR)115); //todo: icon resource define App.WindowClass.lpszMenuName = 0; App.WindowClass.lpszClassName = "Window Class"; App.WindowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); @@ -315,14 +315,13 @@ HWND WinCreateWindow(HINSTANCE hinstance, long nCmdShow, RECT* r) HWND WinCreateWindow(HINSTANCE hinstance, long nCmdShow) #endif { - HWND hwnd; - #ifdef TROYESTUFF - hwnd = CreateWindowEx(WS_EX_APPWINDOW, "Window Class", "Tomb Raider III", tomb3.WindowStyle, + return CreateWindowEx(WS_EX_APPWINDOW, "Window Class", "Tomb Raider III", tomb3.WindowStyle, CW_USEDEFAULT, CW_USEDEFAULT, r->right - r->left, r->bottom - r->top, 0, 0, hinstance, 0); #else + HWND hwnd; + hwnd = CreateWindowEx(WS_EX_APPWINDOW, "Window Class", "Tomb Raider III", WS_POPUP, 0, 0, 0, 0, 0, 0, hinstance, 0); -#endif if (hwnd) { @@ -331,6 +330,7 @@ HWND WinCreateWindow(HINSTANCE hinstance, long nCmdShow) } return hwnd; +#endif } float WinFrameRate() @@ -431,6 +431,10 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd DIRECT3DINFO* d3dinfo; #ifdef TROYESTUFF RECT r; + HWND desktop; + HDC hdc; + DEVMODE devmode; + static ulong bpp; #endif bool hw; @@ -488,6 +492,14 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd return 0; } +#ifdef TROYESTUFF + SetWindowPos(App.WindowHandle, 0, tomb3.rScreen.left, tomb3.rScreen.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); + desktop = GetDesktopWindow(); + hdc = GetDC(desktop); + bpp = GetDeviceCaps(hdc, BITSPIXEL); + ReleaseDC(desktop, hdc); +#endif + if (!WinDXInit(&App.DeviceInfo, &App.DXConfig, 1)) { WinFreeDX(1); @@ -502,12 +514,18 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd { SetWindowLongPtr(App.WindowHandle, GWL_STYLE, WS_POPUP); SetWindowPos(App.WindowHandle, 0, tomb3.rScreen.left, tomb3.rScreen.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); - UpdateWindow(App.WindowHandle); - ShowWindow(App.WindowHandle, nShowCmd); SetCursor(0); ShowCursor(0); } + else + { + SetCursor(LoadCursor(0, IDC_ARROW)); + ShowCursor(1); + } + + UpdateWindow(App.WindowHandle); + ShowWindow(App.WindowHandle, nShowCmd); #endif d3dinfo = &App.DeviceInfoPtr->DDInfo[App.DXConfigPtr->nDD].D3DInfo[App.DXConfigPtr->nD3D]; @@ -541,6 +559,17 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd GtWindowClosed = 0; GtFullScreenClearNeeded = 0; GameMain(); + +#ifdef TROYESTUFF + desktop = GetDesktopWindow(); + hdc = GetDC(desktop); + devmode.dmSize = sizeof(DEVMODE); + devmode.dmBitsPerPel = bpp; + ReleaseDC(desktop, hdc); + devmode.dmFields = DM_BITSPERPEL; + ChangeDisplaySettings(&devmode, 0); +#endif + return 0; } From 8ffbea02874b4fefbf65661b6334caaed516c980 Mon Sep 17 00:00:00 2001 From: Troye Date: Fri, 18 Nov 2022 20:30:18 -0600 Subject: [PATCH 5/9] redecomp ControlFish --- tomb3/game/fish.cpp | 53 ++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/tomb3/game/fish.cpp b/tomb3/game/fish.cpp index 9a50c801..fef9d2d3 100644 --- a/tomb3/game/fish.cpp +++ b/tomb3/game/fish.cpp @@ -229,7 +229,6 @@ void ControlFish(short item_number) return; leader = item->hit_points; - pLeader = &lead_info[leader]; if (!pLeader->on) @@ -267,7 +266,7 @@ void ControlFish(short item_number) if (pirahna_attack != 1) enemy = &items[CarcassItem]; - pFish->angle = (-((long)mGetAngle(pFish->x + item->pos.x_pos, pFish->z + item->pos.z_pos, enemy->pos.x_pos, enemy->pos.z_pos) + 0x4000) >> 4) & 0xFFF; + pFish->angle = ((-(long)mGetAngle(pFish->x + item->pos.x_pos, pFish->z + item->pos.z_pos, enemy->pos.x_pos, enemy->pos.z_pos) - 0x4000) >> 4) & 0xFFF; pLeader->angle = pFish->angle; pLeader->speed = (GetRandomControl() & 0x3F) - 64; } @@ -431,7 +430,7 @@ void ControlFish(short item_number) fx = x; fz = z; - for (int i = 0; i < 24; i++) + for (int i = 0, j = 32; i < 24; i++, j += 2) { pFish = &fish[(leader * 24) + 8 + i]; @@ -455,11 +454,9 @@ void ControlFish(short item_number) } } - angle = (-((long)mGetAngle(pFish->x, pFish->z, fx, fz) + 0x4000) >> 4) & 0xFFF; - dx = pFish->x - fx + ((24 - i) << 7); - dz = pFish->z - fz - ((24 - i) << 7); - dx *= dx; - dz *= dz; + angle = ((-(long)mGetAngle(pFish->x, pFish->z, fx, fz) - 0x4000) >> 4) & 0xFFF; + dx = SQUARE(pFish->x - fx + ((24 - i) << 7)); + dz = SQUARE(pFish->z - fz - ((24 - i) << 7)); diff = pFish->angle - angle; if (diff > 2048) @@ -478,8 +475,8 @@ void ControlFish(short item_number) { pFish->angadd += 4; - if (pFish->angadd > 92 + (i >> 1)) - pFish->angadd = 92 + (i >> 1); + if (pFish->angadd > (i >> 1) + 92) + pFish->angadd = (i >> 1) + 92; } else { @@ -498,16 +495,16 @@ void ControlFish(short item_number) if (dx + dz < SQUARE(i << 7) + 0x100000) { - if (pFish->speed > 32 + (i << 1)) + if (pFish->speed > j) pFish->speed -= pFish->speed >> 5; } else { - if (pFish->speed < 160 + (i >> 1)) - pFish->speed += uchar((GetRandomControl() & 3) + 1 + (i >> 1)); + if (pFish->speed < (i >> 1) + 160) + pFish->speed += uchar((i >> 1) + (GetRandomControl() & 3) + 1); - if (pFish->speed > 160 + (i >> 1) - (i << 2)) - pFish->speed = 160 + (i >> 1) - (i << 2); + if (pFish->speed > (i >> 1) - (i << 2) + 160) + pFish->speed = (i >> 1) - (i << 2) + 160; } if (GetRandomControl() & 1) @@ -525,30 +522,28 @@ void ControlFish(short item_number) x = pFish->x - ((pFish->speed * rcossin_tbl[pFish->angle << 1]) >> 13); z = pFish->z + ((pFish->speed * rcossin_tbl[(pFish->angle << 1) + 1]) >> 13); - if (z < -32000) - z = -32000; - else if (z > 32000) - z = 32000; - if (x < -32000) - x = -32000; - else if (x > 32000) - x = 32000; + if (z < -0x7D00) + z = -0x7D00; + else if (z > 0x7D00) + z = 0x7D00; + + if (x < -0x7D00) + x = -0x7D00; + else if (x > 0x7D00) + x = 0x7D00; pFish->x = (short)x; pFish->z = (short)z; - if (!pirahna_attack) - { - if (abs(pFish->y - pFish->desty) < 16) - pFish->desty = GetRandomControl() % lead_info[leader].Yrange; - } - else + if (pirahna_attack) { diff = enemy->pos.y_pos - item->pos.y_pos; if (abs(pFish->y - pFish->desty) < 16) pFish->desty = short(diff + (GetRandomControl() & 0xFF)); } + else if (abs(pFish->y - pFish->desty) < 16) + pFish->desty = GetRandomControl() % lead_info[leader].Yrange; pFish->y += (pFish->desty - pFish->y) >> 4; } From 1c3c62581fe5aaeaf804166b4711b1104fc13a37 Mon Sep 17 00:00:00 2001 From: Troye Date: Fri, 18 Nov 2022 20:52:55 -0600 Subject: [PATCH 6/9] clarify dxdialog def --- tomb3/specific/dxdialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tomb3/specific/dxdialog.cpp b/tomb3/specific/dxdialog.cpp index ad2da3d2..c5e6c0cb 100644 --- a/tomb3/specific/dxdialog.cpp +++ b/tomb3/specific/dxdialog.cpp @@ -15,8 +15,8 @@ #define IDC_ZBUFFER 1004 #define IDC_DITHER 1005 #define IDC_BILINEAR 1006 -#define IDC_HARDWARE 1007 -#define IDC_SOFTWARE 1008 +#define IDC_HARDWARE 1007 //now "Fullscreen" +#define IDC_SOFTWARE 1008 //now "Windowed" #define IDC_8BIT_TEXTURES 1009 #define IDC_SOUND 1010 #define IDC_JOYSTICK 1011 From ac8fad8817a8e9639635a3c98341ca433fe43a98 Mon Sep 17 00:00:00 2001 From: Troye Date: Sat, 19 Nov 2022 05:42:09 -0600 Subject: [PATCH 7/9] make setup window save and exit --- tomb3/specific/dxdialog.cpp | 6 ++++++ tomb3/specific/winmain.cpp | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/tomb3/specific/dxdialog.cpp b/tomb3/specific/dxdialog.cpp index c5e6c0cb..ba299996 100644 --- a/tomb3/specific/dxdialog.cpp +++ b/tomb3/specific/dxdialog.cpp @@ -90,6 +90,9 @@ BOOL CALLBACK DXSetupDlgProc(HWND dlg, UINT message, WPARAM wParam, LPARAM lPara pass = WinDXInit(&App.DeviceInfo, &App.DXConfig, 1); WinFreeDX(1); ShowWindow(App.WindowHandle, 0); +#ifdef TROYESTUFF + UpdateWindow(dlg); +#endif ShowCursor(1); if (pass) @@ -767,8 +770,11 @@ void DXInitDialogBox(HWND hwnd) nDD = G_DeviceInfo->nDDInfo - 1; #ifdef TROYESTUFF + SendMessage(GetDlgItem(hwnd, IDOK), WM_SETTEXT, 0, (LPARAM)("Save")); + SendMessage(GetDlgItem(hwnd, IDC_HARDWARE), WM_SETTEXT, 0, (LPARAM)("Fullscreen")); SendMessage(GetDlgItem(hwnd, IDC_HARDWARE), BM_SETCHECK, 1, 0); + SendMessage(GetDlgItem(hwnd, IDC_SOFTWARE), WM_SETTEXT, 0, (LPARAM)("Windowed")); SendMessage(GetDlgItem(hwnd, IDC_SOFTWARE), BM_SETCHECK, 0, 0); #endif diff --git a/tomb3/specific/winmain.cpp b/tomb3/specific/winmain.cpp index 5a520350..9c4dba78 100644 --- a/tomb3/specific/winmain.cpp +++ b/tomb3/specific/winmain.cpp @@ -486,11 +486,33 @@ int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd memcpy(LevelSecrets, gLevelSecrets, sizeof(LevelSecrets)); #endif +#ifdef TROYESTUFF + if ((!S_LoadSettings() || UT_FindArg("setup"))) + { + DXUserDialog(&App.DeviceInfo, &App.DXConfig, App.hInstance); + DXFreeDeviceInfo(&App.DeviceInfo); + + desktop = GetDesktopWindow(); + hdc = GetDC(desktop); + bpp = GetDeviceCaps(hdc, BITSPIXEL); + ReleaseDC(desktop, hdc); + + desktop = GetDesktopWindow(); + hdc = GetDC(desktop); + devmode.dmSize = sizeof(DEVMODE); + devmode.dmBitsPerPel = bpp; + ReleaseDC(desktop, hdc); + devmode.dmFields = DM_BITSPERPEL; + ChangeDisplaySettings(&devmode, 0); + return 0; + } +#else if ((!S_LoadSettings() || UT_FindArg("setup")) && !DXUserDialog(&App.DeviceInfo, &App.DXConfig, App.hInstance)) { DXFreeDeviceInfo(&App.DeviceInfo); return 0; } +#endif #ifdef TROYESTUFF SetWindowPos(App.WindowHandle, 0, tomb3.rScreen.left, tomb3.rScreen.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER); From 6e6f120a8447810f44fc39132d70d96321f6b37f Mon Sep 17 00:00:00 2001 From: Troye Date: Sat, 19 Nov 2022 06:48:01 -0600 Subject: [PATCH 8/9] fix ambient reload --- CHANGELOG.md | 1 + tomb3/game/setup.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71bbd5cd..19b7fee4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Original bug fixes - Fix underwater pickups rotating with Lara. +- Fix the wrong ambient track being played after reloading. ### tomb3 additions diff --git a/tomb3/game/setup.cpp b/tomb3/game/setup.cpp index 6095d528..0dc57ccb 100644 --- a/tomb3/game/setup.cpp +++ b/tomb3/game/setup.cpp @@ -190,7 +190,12 @@ long InitialiseLevel(long level, long type) if (objects[FINAL_LEVEL].loaded) InitialiseFinalLevel(); +#ifdef TROYESTUFF + if (type == 2) //mid_level_save is not used on PC (right now), on PSX it means any save that's NOT from the level stats prompt + //so on PC this check will never pass, although it should since PC cannot save other than "mid level". +#else if (type == 2 && savegame.mid_level_save) +#endif { S_CDPlay(CurrentAtmosphere, 1); IsAtmospherePlaying = 1; From 0a0cc0d9e9dd2b521d32fd8034d0e571c913d088 Mon Sep 17 00:00:00 2001 From: Troye Date: Sat, 19 Nov 2022 12:12:39 -0600 Subject: [PATCH 9/9] remove x64 config --- tomb3.sln | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tomb3.sln b/tomb3.sln index 9ef07dcd..65cb9a98 100644 --- a/tomb3.sln +++ b/tomb3.sln @@ -7,18 +7,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tomb3", "tomb3.vcxproj", "{ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 - Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CB038090-6E9C-48AE-8D36-56EB883F9040}.Debug|x64.ActiveCfg = Debug|x64 - {CB038090-6E9C-48AE-8D36-56EB883F9040}.Debug|x64.Build.0 = Debug|x64 {CB038090-6E9C-48AE-8D36-56EB883F9040}.Debug|x86.ActiveCfg = Debug|Win32 {CB038090-6E9C-48AE-8D36-56EB883F9040}.Debug|x86.Build.0 = Debug|Win32 - {CB038090-6E9C-48AE-8D36-56EB883F9040}.Release|x64.ActiveCfg = Release|x64 - {CB038090-6E9C-48AE-8D36-56EB883F9040}.Release|x64.Build.0 = Release|x64 {CB038090-6E9C-48AE-8D36-56EB883F9040}.Release|x86.ActiveCfg = Release|Win32 {CB038090-6E9C-48AE-8D36-56EB883F9040}.Release|x86.Build.0 = Release|Win32 EndGlobalSection