Skip to content

Commit 2bdac5c

Browse files
Feature/renderer (#12)
* OpenGL renderer * Software renderer * DirectInput replacement * Refactoring
1 parent 6862a02 commit 2bdac5c

94 files changed

Lines changed: 116568 additions & 419 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/action-development.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
Rename-Item -Path README.md -NewName readme.txt
3232
Rename-Item -Path LICENSE -NewName license.txt
3333
$compress = @{
34-
Path = "Release/*.dll", "readme.txt", "license.txt"
34+
Path = "Release/*.dll", "readme.txt", "license.txt", "Release/*.ini"
3535
DestinationPath = "SubTitans.zip"
3636
Force = $True
3737
}

.github/workflows/action-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
Rename-Item -Path README.md -NewName readme.txt
3030
Rename-Item -Path LICENSE -NewName license.txt
3131
$compress = @{
32-
Path = "Release/*.dll", "readme.txt", "license.txt"
32+
Path = "Release/*.dll", "readme.txt", "license.txt", "Release/*.ini"
3333
DestinationPath = "SubTitans.zip"
3434
Force = $True
3535
}

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,13 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
352+
# Submarine Titans
353+
*.dkd
354+
*.dkx
355+
*.bik
356+
*.vps
357+
*.avi
358+
*.dll
359+
*.exe
360+
*.rpt

Debug/subtitans.ini

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[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)
4+
Width=0
5+
; Override the detected screen height (0: Ignore)
6+
Height=0
7+
8+
[FEATURE]
9+
; Allows the game to scale the GUI further than 1280x1024
10+
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
13+
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)
17+
; Set this variable to false if you're experiencing problems with mouse or keyboard input.
18+
CustomInput=true
19+
; Shader that tries to mimic CRT behavior. The OpenGL renderer is required for this effect.
20+
RetroShader=false
21+
22+
[FIX]
23+
; Fixes a crash caused by the movie player
24+
MovieHeap=true
25+
; Replaces the default FPS limiter with a more stable implementation
26+
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

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
# SubTitans
2-
Unofficial Submarine Titans patch
2+
Unofficial Submarine Titans patch \
3+
![GitHub all releases](https://img.shields.io/github/downloads/UnknownException/SubTitans/total)
34

45
**Requirements**
5-
* Windows 10
6+
* Windows 10 or Windows 11
67
* Supports Steam/Retail v1.0, Retail v1.1 and GOG v1.1
78

89
**Features**
9-
* Support for native resolution ingame (tested up to 3840x2160)
10-
* Improved scrolling (Requires v1.1)
11-
* Added mission skip cheat (Requires v1.1; workaround for progression bugs)
12-
* Performance boost (Steam; not required for GOG)
13-
* Fixes various internal errors (Steam; not required for GOG)
14-
* Support for high DPI display resolutions (Steam; not required for GOG)
15-
* Fixes alt-tab crashes (Steam; not required for GOG)
16-
* Windows 7 color fix (Steam; not required for GOG) - deprecated
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)
14+
* 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)
1719

1820
**Instructions**
1921
1. Copy & paste d3drm.dll and subtitans.dll in your Submarine Titans folder.
2022
2. Open STConfig.exe and select 1280x1024.
21-
3. Run the game (through ST.exe or Steam).
23+
3. Run the game.
2224

2325
**Q&A** \
2426
Q: How do I use the mission skip cheat? \
@@ -31,12 +33,14 @@ A: Install vc_redist.x86.exe ( https://support.microsoft.com/en-us/help/2977003/
3133
Q: How to update Submarine Titans to version 1.1? \
3234
A: https://steamcommunity.com/sharedfiles/filedetails/?id=2129291420 \
3335
\
34-
Q: Why is the game running so slow? (Steam/Retail only) \
35-
A: Submarine Titan uses DirectDraw, a deprecated piece of technology from a bygone era. \
36-
There are DirectDraw replacements/wrappers available that might improve performance (like DXWrapper, DDrawCompat, DXGL, dgVoodoo 2 and others). \
36+
Q: I've got a problem in-game with my mouse and/or keyboard. \
37+
A: Open SubTitans.ini and set CustomInput to false, this should revert the input handling changes. \
38+
\
39+
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.
3741

3842
**Known bugs**
39-
* 1366*768 does not function correctly, reverts to 1280x768 ingame.
43+
* None (yet)
4044

4145
**Uninstall**
4246
* Deleting SubTitans.dll will disable the ingame patches.

Release/subtitans.ini

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[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)
4+
Width=0
5+
; Override the detected screen height (0: Ignore)
6+
Height=0
7+
8+
[FEATURE]
9+
; Allows the game to scale the GUI further than 1280x1024
10+
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
13+
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)
17+
; Set this variable to false if you're experiencing problems with mouse or keyboard input.
18+
CustomInput=true
19+
; Shader that tries to mimic CRT behavior. The OpenGL renderer is required for this effect.
20+
RetroShader=false
21+
22+
[FIX]
23+
; Fixes a crash caused by the movie player
24+
MovieHeap=true
25+
; Replaces the default FPS limiter with a more stable implementation
26+
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

SubTitans.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00
44
VisualStudioVersion = 16.0.30011.22
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "d3drm", "d3drm\d3drm.vcxproj", "{229FEA89-DB14-4AD2-BD12-878FE36496F0}"
7+
ProjectSection(ProjectDependencies) = postProject
8+
{5F2C7921-4B31-4712-8722-C99EFF304EC4} = {5F2C7921-4B31-4712-8722-C99EFF304EC4}
9+
{033CA3B5-4016-489A-943E-663953F6F89A} = {033CA3B5-4016-489A-943E-663953F6F89A}
10+
EndProjectSection
711
EndProject
812
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "subtitans", "subtitans\subtitans.vcxproj", "{033CA3B5-4016-489A-943E-663953F6F89A}"
913
ProjectSection(ProjectDependencies) = postProject

d3drm/d3drm.cpp

Lines changed: 9 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
#include <cstdint>
44
#include "types.h"
55
#include "../shared/gameversion.h"
6+
#include "../shared/file.h"
67
#include "injector.h"
78

9+
#ifdef _DEBUG
10+
#pragma comment(lib, "../Debug/shared.lib")
11+
#else
12+
#pragma comment(lib, "../Release/shared.lib")
13+
#endif
14+
815
#pragma comment(linker, "/EXPORT:D3DRMVectorModulus=_D3DRMVectorModulus@4")
916
extern "C" float __stdcall D3DRMVectorModulus(D3DVector3* vector)
1017
{
@@ -14,75 +21,12 @@ extern "C" float __stdcall D3DRMVectorModulus(D3DVector3* vector)
1421
return static_cast<float>(sqrt(vector->x * vector->x + vector->y * vector->y + vector->z * vector->z));
1522
}
1623

17-
bool FileExists(const WCHAR* filePath)
18-
{
19-
WIN32_FIND_DATAW findData;
20-
HANDLE findHandle = FindFirstFileW(filePath, &findData);
21-
if (findHandle == INVALID_HANDLE_VALUE)
22-
return false;
23-
24-
FindClose(findHandle);
25-
return true;
26-
}
27-
28-
constexpr uint32_t CRC32_POLYNOMIAL = 0xEDB88320;
29-
uint32_t CalculateFileChecksum(WCHAR* filePath)
30-
{
31-
HANDLE fileHandle = CreateFileW(filePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
32-
if (fileHandle == INVALID_HANDLE_VALUE)
33-
return 0;
34-
35-
uint32_t allocatedSize = GetFileSize(fileHandle, NULL);
36-
37-
HANDLE processHeap = GetProcessHeap();
38-
if (processHeap == NULL)
39-
{
40-
CloseHandle(fileHandle);
41-
42-
return 0;
43-
}
44-
45-
void* allocatedMemory = HeapAlloc(processHeap, HEAP_ZERO_MEMORY, allocatedSize);
46-
DWORD bytesRead = 0;
47-
if (!ReadFile(fileHandle, allocatedMemory, allocatedSize, &bytesRead, 0) || bytesRead != allocatedSize)
48-
{
49-
CloseHandle(fileHandle);
50-
HeapFree(processHeap, 0, allocatedMemory);
51-
52-
return 0;
53-
}
54-
55-
CloseHandle(fileHandle);
56-
57-
uint32_t checkSumTable[256];
58-
for (uint32_t tableIt = 0; tableIt < sizeof(checkSumTable) / sizeof(uint32_t); ++tableIt)
59-
{
60-
checkSumTable[tableIt] = tableIt;
61-
for (uint32_t i = 0; i < 8; ++i)
62-
{
63-
checkSumTable[tableIt] = checkSumTable[tableIt] & 1 ?
64-
checkSumTable[tableIt] >> 1 ^ CRC32_POLYNOMIAL
65-
: checkSumTable[tableIt] >> 1;
66-
}
67-
}
68-
69-
uint32_t checkSumResult = ~0;
70-
for (uint32_t i = 0; i < allocatedSize; ++i)
71-
{
72-
checkSumResult = checkSumTable[checkSumResult & 0xFF ^ ((uint8_t*)allocatedMemory)[i]] ^ checkSumResult >> 8;
73-
}
74-
75-
HeapFree(processHeap, 0, allocatedMemory);
76-
77-
return ~checkSumResult;
78-
}
79-
8024
uint32_t GetSubTitansVersion()
8125
{
8226
WCHAR applicationPath[MAX_PATH];
8327
GetModuleFileName(NULL, applicationPath, MAX_PATH);
8428

85-
uint32_t checkSum = CalculateFileChecksum(applicationPath);
29+
uint32_t checkSum = File::CalculateChecksum(applicationPath);
8630

8731
switch (checkSum)
8832
{
@@ -106,7 +50,7 @@ BOOLEAN __stdcall DllMain(HINSTANCE handle, DWORD reason, LPVOID reserved)
10650
return FALSE;
10751

10852
// Allow uninstalling patch by removing SubTitans.dll
109-
if (!FileExists(L"SubTitans.dll"))
53+
if (!File::Exists(L"SubTitans.dll"))
11054
return TRUE;
11155

11256
return Injector::Apply(gameVersion);

d3drm/d3drm.vcxproj.user

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
4+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
5+
<LocalDebuggerCommand>$(SolutionDir)game\ST.exe</LocalDebuggerCommand>
6+
<LocalDebuggerWorkingDirectory>$(OutputPath)</LocalDebuggerWorkingDirectory>
7+
<LocalDebuggerDebuggerType>NativeOnly</LocalDebuggerDebuggerType>
8+
</PropertyGroup>
9+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
10+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
11+
<LocalDebuggerCommand>$(SolutionDir)game\ST.exe</LocalDebuggerCommand>
12+
<LocalDebuggerWorkingDirectory>$(OutputPath)</LocalDebuggerWorkingDirectory>
13+
<LocalDebuggerDebuggerType>NativeOnly</LocalDebuggerDebuggerType>
14+
</PropertyGroup>
15+
</Project>

d3drm/injector.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Injector {
99
typedef void(__stdcall* SubTitansLibrary_InitializeLibrary)(unsigned long);
1010
typedef void(__stdcall* SubTitansLibrary_ReleaseLibrary)();
1111

12-
void LoadModule()
12+
void __stdcall LoadModule()
1313
{
1414
SubTitansLibrary = LoadLibrary(L"subtitans.dll");
1515
if (!SubTitansLibrary)
@@ -37,7 +37,7 @@ namespace Injector {
3737
__asm pushad;
3838
__asm pushfd;
3939

40-
LoadModule();
40+
__asm call [LoadModule];
4141

4242
__asm popfd;
4343
__asm popad;
@@ -47,7 +47,7 @@ namespace Injector {
4747
__asm jmp [LoadModule_JmpBack];
4848
}
4949

50-
void UnloadModule()
50+
void __stdcall UnloadModule()
5151
{
5252
if (!SubTitansLibrary)
5353
{
@@ -74,7 +74,7 @@ namespace Injector {
7474
__asm pushad;
7575
__asm pushfd;
7676

77-
UnloadModule();
77+
__asm call [UnloadModule];
7878

7979
__asm popfd;
8080
__asm popad;

0 commit comments

Comments
 (0)