Skip to content

Commit 3a1c2e4

Browse files
Backporting, refactoring and bug fixing (#13)
* DInput bug workaround (whenever X and Y are equal to 0) * Added OpenGL and Software rendering support to the GOG release * Minimal support for the demo release * Ported the latest changes to the 1.0 release of the game * Removed obsolete patches * DInput alt-key bug fix (occurred when alt tabbing out of the game) * Cursor clipping fix (occurred when alt tabbing out of the game) * In-game briefing positioning fix (for 800x600 and 1024x768) * Disable IMGUI for release builds
1 parent 2bdac5c commit 3a1c2e4

28 files changed

Lines changed: 475 additions & 634 deletions

Debug/subtitans.ini

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
[SETTING]
2-
; Manual overriding of the screen resolution is useful when you have the need to stretch the game instead of scaling (performance reasons)
3-
; Override the detected screen width (0: Ignore)
2+
; Override the detected screen width (0: Ignore).
43
Width=0
5-
; Override the detected screen height (0: Ignore)
4+
; Override the detected screen height (0: Ignore).
65
Height=0
76

87
[FEATURE]
9-
; Allows the game to scale the GUI further than 1280x1024
8+
; Provides widescreen support with propper scaling of the GUI.
9+
; This patch overrides the in-game resolution of 1280x1024.
1010
NativeResolution=true
11-
; Provides an alternative to the default DirectDraw (obsolete) renderer (0: Automatic, 1: DirectDraw, 2: OpenGL, 3: Software)
12-
; When using the GOG release of Submarine Titans or when using a custom DirectDraw replacement/wrapper it is required to set this value on 1
11+
; Provides an alternative for the obsolete DirectDraw renderer (0: Automatic, 1: DirectDraw, 2: OpenGL, 3: Software).
12+
; Set the value to 1 when using a custom DirectDraw wrapper.
1313
Renderer=0
14-
; Add the cheat 'orbiton' for mission skipping, see the readme for more information
15-
MissionSkipCheat=1
16-
; Provides an alternative to the default DInput (obsolete) input handling (Doesn't work in combination with DirectDraw)
14+
; Add the 'orbiton' cheat for mission skipping, see the readme for more information.
15+
MissionSkipCheat=true
16+
; Provides an alternative for the obsolete DirectInput input handling.
1717
; Set this variable to false if you're experiencing problems with mouse or keyboard input.
18+
; This modification doesn't work in combination with the DirectDraw renderer.
1819
CustomInput=true
1920
; Shader that tries to mimic CRT behavior. The OpenGL renderer is required for this effect.
2021
RetroShader=false
2122

2223
[FIX]
23-
; Fixes a crash caused by the movie player
24+
; Fixes a crash caused by the video player.
2425
MovieHeap=true
25-
; Replaces the default FPS limiter with a more stable implementation
26+
; Replaces the default FPS limiter with a better implementation.
2627
ImprovedFPSLimiter=true
27-
; Improves the smoothness of scrolling in-game
28-
SmoothScroll=true
29-
30-
; Legacy patches only relevant for DirectDraw
31-
; Consider turning these settings off when using a DirectDraw wrapper
32-
[DIRECTDRAW]
33-
; Rendering fix for displays with scaling enabled
34-
DpiScaling=true
35-
; Fix for alt+tab crash
36-
AltTab=true
37-
; Improves the framerate
38-
DisableDrawStacking=true
28+
; Improves the smoothness of scrolling in-game.
29+
SmoothScroll=true

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ Unofficial Submarine Titans patch \
33
![GitHub all releases](https://img.shields.io/github/downloads/UnknownException/SubTitans/total)
44

55
**Requirements**
6-
* Windows 10 or Windows 11
6+
* Windows 7, Windows 10, Windows 11 or Wine (+ Ubuntu)
77
* Supports Steam/Retail v1.0, Retail v1.1 and GOG v1.1
88

99
**Features**
10-
* Support for any resolution in-game (All; tested up to 3840x2160)
11-
* OpenGL and Software rendering replacement for DirectDraw to improve compatibility and performance (Retail v1.1)
12-
* DInput replacement (Retail v1.1)
13-
* Improved scrolling (Retail/GOG v1.1)
10+
* Support for any resolution in-game (tested up to 3840x2160)
11+
* OpenGL and Software rendering replacement for DirectDraw to improve compatibility and performance
12+
* DInput replacement
13+
* Improved scrolling
1414
* Added mission skip cheat (Retail/GOG v1.1; workaround for progression bugs)
15-
* Fixes various internal errors (All)
16-
* Support for display scaling (Retail v1.0 & Retail v1.1)
17-
* Fixes alt-tab crashes (Retail v1.0 & Retail v1.1)
18-
* Windows 7 palette color fix (Retail v1.1)
15+
* Fixes various internal errors
16+
* Fixes alt-tab crashes
17+
* Support for display scaling
18+
* Windows 7 palette color fix
1919

2020
**Instructions**
21-
1. Copy & paste d3drm.dll and subtitans.dll in your Submarine Titans folder.
21+
1. Copy & paste d3drm.dll, subtitans.dll and subtitans.ini into your Submarine Titans folder.
2222
2. Open STConfig.exe and select 1280x1024.
2323
3. Run the game.
2424

@@ -37,10 +37,13 @@ Q: I've got a problem in-game with my mouse and/or keyboard. \
3737
A: Open SubTitans.ini and set CustomInput to false, this should revert the input handling changes. \
3838
\
3939
Q: I've got a problem with the OpenGL/Software renderer and want to use a custom DDraw wrapper. \
40-
A: Open SubTitans.ini and set Renderer to 1.
40+
A: Open SubTitans.ini and set Renderer to 1. \
41+
\
42+
Q: The Submarine Titans demo crashes with or without this patch. \
43+
A: The support for the demo version of Submarine Titans is bare minimum. Please don't report issues regarding the demo, it will be ignored.
4144

4245
**Known bugs**
43-
* None (yet)
46+
* Regions next to the in-game command panel aren't selectable/clickable.
4447

4548
**Uninstall**
46-
* Deleting SubTitans.dll will disable the ingame patches.
49+
* Deleting SubTitans.dll will disable the in-game patches.

Release/subtitans.ini

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
[SETTING]
2-
; Manual overriding of the screen resolution is useful when you have the need to stretch the game instead of scaling (performance reasons)
3-
; Override the detected screen width (0: Ignore)
2+
; Override the detected screen width (0: Ignore).
43
Width=0
5-
; Override the detected screen height (0: Ignore)
4+
; Override the detected screen height (0: Ignore).
65
Height=0
76

87
[FEATURE]
9-
; Allows the game to scale the GUI further than 1280x1024
8+
; Provides widescreen support with propper scaling of the GUI.
9+
; This patch overrides the in-game resolution of 1280x1024.
1010
NativeResolution=true
11-
; Provides an alternative to the default DirectDraw (obsolete) renderer (0: Automatic, 1: DirectDraw, 2: OpenGL, 3: Software)
12-
; When using the GOG release of Submarine Titans or when using a custom DirectDraw replacement/wrapper it is required to set this value on 1
11+
; Provides an alternative for the obsolete DirectDraw renderer (0: Automatic, 1: DirectDraw, 2: OpenGL, 3: Software).
12+
; Set the value to 1 when using a custom DirectDraw wrapper.
1313
Renderer=0
14-
; Add the cheat 'orbiton' for mission skipping, see the readme for more information
15-
MissionSkipCheat=1
16-
; Provides an alternative to the default DInput (obsolete) input handling (Doesn't work in combination with DirectDraw)
14+
; Add the 'orbiton' cheat for mission skipping, see the readme for more information.
15+
MissionSkipCheat=true
16+
; Provides an alternative for the obsolete DirectInput input handling.
1717
; Set this variable to false if you're experiencing problems with mouse or keyboard input.
18+
; This modification doesn't work in combination with the DirectDraw renderer.
1819
CustomInput=true
1920
; Shader that tries to mimic CRT behavior. The OpenGL renderer is required for this effect.
2021
RetroShader=false
2122

2223
[FIX]
23-
; Fixes a crash caused by the movie player
24+
; Fixes a crash caused by the video player.
2425
MovieHeap=true
25-
; Replaces the default FPS limiter with a more stable implementation
26+
; Replaces the default FPS limiter with a better implementation.
2627
ImprovedFPSLimiter=true
27-
; Improves the smoothness of scrolling in-game
28-
SmoothScroll=true
29-
30-
; Legacy patches only relevant for DirectDraw
31-
; Consider turning these settings off when using a DirectDraw wrapper
32-
[DIRECTDRAW]
33-
; Rendering fix for displays with scaling enabled
34-
DpiScaling=true
35-
; Fix for alt+tab crash
36-
AltTab=true
37-
; Improves the framerate
38-
DisableDrawStacking=true
28+
; Improves the smoothness of scrolling in-game.
29+
SmoothScroll=true

d3drm/d3drm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ uint32_t GetSubTitansVersion()
3333
case Shared::ST_GAMEVERSION_RETAIL_UNPATCHED:
3434
case Shared::ST_GAMEVERSION_RETAIL_PATCHED:
3535
case Shared::ST_GAMEVERSION_GOG_MODIFIED:
36+
case Shared::ST_GAMEVERSION_DEMO:
3637
return checkSum;
3738
default:
3839
return 0;

d3drm/injector.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ namespace Injector {
146146

147147
StartApplicationAddress = 0x00401FF5;
148148
} break;
149+
case Shared::ST_GAMEVERSION_DEMO:
150+
{
151+
LoadModule_JmpFrom = 0x0071A25E;
152+
LoadModule_JmpBack = LoadModule_JmpFrom + LoadModule_DetourSize;
153+
154+
UnloadModule_JmpFrom = 0x0071A263;
155+
UnloadModule_JmpBack = UnloadModule_JmpFrom + UnloadModule_DetourSize;
156+
157+
StartApplicationAddress = 0x00401FF0;
158+
} break;
149159
default:
150160
return false;
151161
}

game/subtitans.ini

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
[SETTING]
2-
; Manual overriding of the screen resolution is useful when you have the need to stretch the game instead of scaling (performance reasons)
3-
; Override the detected screen width (0: Ignore)
2+
; Override the detected screen width (0: Ignore).
43
Width=0
5-
; Override the detected screen height (0: Ignore)
4+
; Override the detected screen height (0: Ignore).
65
Height=0
76

87
[FEATURE]
9-
; Allows the game to scale the GUI further than 1280x1024
8+
; Provides widescreen support with propper scaling of the GUI.
9+
; This patch overrides the in-game resolution of 1280x1024.
1010
NativeResolution=true
11-
; Provides an alternative to the default DirectDraw (obsolete) renderer (0: Automatic, 1: DirectDraw, 2: OpenGL, 3: Software)
12-
; When using the GOG release of Submarine Titans or when using a custom DirectDraw replacement/wrapper it is required to set this value on 1
11+
; Provides an alternative for the obsolete DirectDraw renderer (0: Automatic, 1: DirectDraw, 2: OpenGL, 3: Software).
12+
; Set the value to 1 when using a custom DirectDraw wrapper.
1313
Renderer=0
14-
; Add the cheat 'orbiton' for mission skipping, see the readme for more information
15-
MissionSkipCheat=1
16-
; Provides an alternative to the default DInput (obsolete) input handling (Doesn't work in combination with DirectDraw)
14+
; Add the 'orbiton' cheat for mission skipping, see the readme for more information.
15+
MissionSkipCheat=true
16+
; Provides an alternative for the obsolete DirectInput input handling.
1717
; Set this variable to false if you're experiencing problems with mouse or keyboard input.
18+
; This modification doesn't work in combination with the DirectDraw renderer.
1819
CustomInput=true
1920
; Shader that tries to mimic CRT behavior. The OpenGL renderer is required for this effect.
2021
RetroShader=false
2122

2223
[FIX]
23-
; Fixes a crash caused by the movie player
24+
; Fixes a crash caused by the video player.
2425
MovieHeap=true
25-
; Replaces the default FPS limiter with a more stable implementation
26+
; Replaces the default FPS limiter with a better implementation.
2627
ImprovedFPSLimiter=true
27-
; Improves the smoothness of scrolling in-game
28-
SmoothScroll=true
29-
30-
; Legacy patches only relevant for DirectDraw
31-
; Consider turning these settings off when using a DirectDraw wrapper
32-
[DIRECTDRAW]
33-
; Rendering fix for displays with scaling enabled
34-
DpiScaling=true
35-
; Fix for alt+tab crash
36-
AltTab=true
37-
; Improves the framerate
38-
DisableDrawStacking=true
28+
; Improves the smoothness of scrolling in-game.
29+
SmoothScroll=true

shared/configuration.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ bool Configuration::GetBoolean(std::wstring category, std::wstring key, bool pla
3636
WCHAR buffer[6];
3737
GetPrivateProfileString(category.c_str(), key.c_str(), placeholder ? L"true" : L"false", buffer, sizeof(buffer) / 2, _configFilePath.c_str());
3838

39-
return _wcsicmp(L"true", buffer) == 0 ? true : false;
39+
bool result = _wcsicmp(L"true", buffer) == 0;
40+
result |= _wcsicmp(L"yes", buffer) == 0;
41+
result |= _wcsicmp(L"on", buffer) == 0;
42+
result |= _wcsicmp(L"1", buffer) == 0;
43+
44+
return result;
4045
}
4146

4247
std::wstring Configuration::GetString(std::wstring category, std::wstring key, std::wstring placeholder)

shared/gameversion.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ namespace Shared {
44
constexpr unsigned long ST_GAMEVERSION_RETAIL_UNPATCHED = 0x826D8625; // 1.0 from steam store/retail
55
constexpr unsigned long ST_GAMEVERSION_RETAIL_PATCHED = 0xB5BD8D15; // 1.1 retail patch
66
constexpr unsigned long ST_GAMEVERSION_GOG_MODIFIED = 0x18C26D0A; // 1.1 from gog store
7+
constexpr unsigned long ST_GAMEVERSION_DEMO = 0x6B08028C; // Demo
78

8-
constexpr unsigned long ST_LANGUAGE_ENGLISH = 0x0EB5715F; // 1.1 English
9+
constexpr unsigned long ST_LANGUAGE_ENGLISH_UNPATCHED = 0xCE56F1FC; // 1.0 English
10+
constexpr unsigned long ST_LANGUAGE_ENGLISH_PATCHED = 0x0EB5715F; // 1.1 English
11+
constexpr unsigned long ST_LANGUAGE_ENGLISH_DEMO = 0xE73A5959; // Demo English
912
}

subtitans/ddrawreplacementpatch.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ namespace WindowRegisterClassDetour {
8383
case WM_MOUSEMOVE:
8484
Global::MouseInformation.x = (int16_t)(lParam & 0xFFFF);
8585
Global::MouseInformation.y = (int16_t)(lParam >> 16);
86+
87+
// (BUG) Workaround for cursor issue when moving to 0, 0.
88+
// Requires further investigation.
89+
if (Global::MouseInformation.x == 0 && Global::MouseInformation.y == 0)
90+
Global::MouseInformation.y = 1;
91+
8692
break;
8793
case WM_MOUSEWHEEL:
8894
Global::MouseInformation.z += (int16_t)(wParam >> 16);
@@ -152,7 +158,25 @@ namespace WindowRegisterClassDetour {
152158
default:
153159
Global::KeyboardInformation.keyPressed[KeyTranslationTable[wParam & 0xFF]] = Global::KeyPressedFlag;
154160
break;
155-
} break;
161+
} break;
162+
case WM_ACTIVATEAPP:
163+
{
164+
memset(&Global::KeyboardInformation, 0, sizeof(Global::_KeyboardInformation));
165+
166+
if (wParam == 1)
167+
{
168+
RECT rect;
169+
rect.left = 0;
170+
rect.top = 0;
171+
rect.right = Global::InternalWidth;
172+
rect.bottom = Global::InternalHeight;
173+
ClipCursor(&rect);
174+
}
175+
else
176+
{
177+
ClipCursor(nullptr); // Free the cursor
178+
}
179+
} break;
156180
default:
157181
break;
158182
}

subtitans/demopatcher.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "subtitans.h"
2+
#include <VersionHelpers.h>
3+
#include "sleepwellpatch.h"
4+
#include "movieheapcorruptionpatch.h"
5+
#include "ddrawreplacementpatch.h"
6+
#include "demopatcher.h"
7+
8+
// The bare minimum to get the Submarine Titans demo running.
9+
// DirectDraw support is dropped, OpenGL or Software rendering is forced.
10+
// No support for custom resolutions/widescreen is provided.
11+
// If the game keeps crashing you must delete the savegame folder and create a profile in-game.
12+
// Disabling the intro video through stconfig.exe might help improve stability.
13+
14+
DemoPatcher::DemoPatcher()
15+
{
16+
17+
}
18+
19+
DemoPatcher::~DemoPatcher()
20+
{
21+
22+
}
23+
24+
void DemoPatcher::Configure()
25+
{
26+
auto sleepWellPatch = new SleepWellPatch();
27+
sleepWellPatch->DetourAddress = 0x006D1714;
28+
sleepWellPatch->FrameLimitMemoryAddress = 0x007EBF1C;
29+
sleepWellPatch->DisableOriginalLimiterSleepAddress = 0x006D173B;
30+
_patches.push_back(sleepWellPatch);
31+
32+
Global::RenderWidth = GetConfiguration()->GetInt32(L"SETTING", L"Width", 0);
33+
if (Global::RenderWidth == 0)
34+
Global::RenderWidth = Global::MonitorWidth;
35+
36+
Global::RenderHeight = GetConfiguration()->GetInt32(L"SETTING", L"Height", 0);
37+
if (Global::RenderHeight == 0)
38+
Global::RenderHeight = Global::MonitorHeight;
39+
40+
bool isWindows7 = IsWindows7OrGreater() && !IsWindows8OrGreater();
41+
auto renderingBackend = GetConfiguration()->GetInt32(L"FEATURE", L"Renderer", Global::RenderingBackend::Automatic);
42+
43+
auto ddrawReplacementPatch = new DDrawReplacementPatch();
44+
ddrawReplacementPatch->DDrawDetourAddress = 0x006A6B81;
45+
ddrawReplacementPatch->DInputDetourAddress = 0x00701C9E;
46+
ddrawReplacementPatch->WindowRegisterClassDetourAddress = 0x00561847;
47+
ddrawReplacementPatch->WindowCreateDetourAddress = 0x00561893;
48+
ddrawReplacementPatch->DInputAbsolutePositioningDetourAddress = 0x007020F0;
49+
ddrawReplacementPatch->ForceSoftwareRendering = renderingBackend == Global::RenderingBackend::Software
50+
|| (isWindows7 && renderingBackend == Global::RenderingBackend::Automatic); // Prefer software rendering on windows 7
51+
ddrawReplacementPatch->DInputReplacement = false; // Doesn't work that well with the demo
52+
_patches.push_back(ddrawReplacementPatch);
53+
54+
Global::RetroShader = GetConfiguration()->GetBoolean(L"FEATURE", L"RetroShader", false);
55+
}

0 commit comments

Comments
 (0)