5a199429b6
Consider this program:
#include <cstdio>
int main(void) {
const char *filename = u8"ディセント3.txt";
auto fp = std::fopen(filename, "r");
if (fp) {
std::fclose(fp);
return 0;
} else {
return 1;
};
}
If a file named ディセント3.txt exists, then will that program
successfully open it? The answer is: it depends.
filename is going to point to these bytes:
Raw bytes: e3 83 87 e3 82 a3 e3 82 bb e3 83 b3 e3 83 88 33 2e 74 78 74 00
Characters: ディセント3.txt␀
Internally, Windows uses UTF-16. When you call fopen(), Windows will
convert the filename parameter into UTF-16 [1]. If the program is run
with a UTF-8 Windows code page, then the above bytes will be correctly
interpreted as UTF-8 when being converted into UTF-16 [2]. The final
UTF-16 string will be this*:
Raw bytes: ff fe c7 30 a3 30 bb 30 f3 30 c8 30 33 00 2e 00 74 00 78 00 74 00
Characters: ディセント3.txt
On the other hand, if the program is run with code page 932, then the
original bytes will be incorrectly interpreted as code page 932 when
being converted into UTF-16. The final UTF-16 string will be this*:
Raw bytes: ff fe 5d 7e fd ff 67 7e 63 ff 67 7e 7b ff 5d 7e 73 ff 5d 7e fd ff 33 00 2e 00 74 00 78 00 74 00
Characters: 繝�繧」繧サ繝ウ繝�3.txt
In other words, if that program gets compiled on Windows with a UTF-8
execution character set, then it needs to be run with a UTF-8 Windows
code page. Otherwise, mojibake might happen.
*Unlike the first string, this one does not have a null terminator. This
is because the Windows kernel doesn’t use null terminated strings for
paths [3][4].
---
Before this commit, Descent 3 would pass UTF-8 to fopen(), even if
Descent 3 is run with a non-UTF-8 Windows code page [5]. This commit
makes sure that Descent 3 gets run with a UTF-8 Windows code page.
The Windows code page isn’t just used by fopen(). It also gets used by
many other functions in the Windows API [6]. I don’t know if Descent 3
uses any of those other functions, but if it does, then this commit will
also help make sure that those functions receive strings with the
correct character encoding. Descent 3 uses UTF-8 for strings by default
[7]. Making sure that Descent 3 uses UTF-8 everywhere will make
encoding-related mistakes less likely in the future.
Fixes #483.
[1]: <https://stackoverflow.com/a/7950569/7593853>
[2]: <https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen?view=msvc-170#remarks>
[3]: <https://stackoverflow.com/a/52372115/7593853>
[4]: <https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html>
[5]: <https://github.com/DescentDevelopers/Descent3/pull/475#discussion_r1664888080>
[6]: <https://learn.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page#-a-vs--w-apis>
[7]:
|
||
---|---|---|
.github | ||
2dlib | ||
AudioEncode | ||
bitmap | ||
cfile | ||
cmake | ||
czip | ||
d3music | ||
dd_grwin32 | ||
dd_video | ||
ddebug | ||
ddio | ||
Descent3 | ||
editor | ||
fix | ||
grtext | ||
legacy | ||
lib | ||
libacm | ||
libmve | ||
linux | ||
manage | ||
md5 | ||
mem | ||
misc | ||
model | ||
module | ||
movie | ||
music | ||
netcon | ||
netgames | ||
networking | ||
physics | ||
renderer | ||
rtperformance | ||
scripts | ||
sndlib | ||
stream_audio | ||
tests | ||
third_party | ||
tools | ||
ui | ||
unzip | ||
vecmat | ||
win32 | ||
.clang-format | ||
.clang-format-ignore | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
Brewfile | ||
CMakeLists.txt | ||
CMakePresets.json | ||
LICENSE | ||
README.md | ||
THIRD_PARTY.md | ||
vcpkg.json |
This is the Descent 3 open source engine, licensed under GPL-3.0. It includes the '1.5' patch written by Kevin Bentley and Jeff Slutter several years ago and brought to a stable condition by the Descent community.
In order to use this, you must provide your own game files. See the Usage section for details.
Version 1.5 Notes
There is no "release" yet. The current milestone is "1.5 Stable", which is meant to more or less be Descent 3 as it might have been if the 1.5 patch had made it to retail years ago. Artifacts can be downloaded from the Actions tab. The milestone needs testing on all platforms. Please report issues when found.
Usage
-
Make sure that you have a copy of Descent 3. You can purchase a copy of Descent 3 from GOG or Steam.
-
Install Descent 3.
-
Note for Steam users: If you own Descent 3 on Steam, then it’s recommended that you install the Windows version of the game even if you’re running macOS or Linux, otherwise movies will not work due to current lack of Ogv support. You can use either Steam Play or SteamCMD to install the Windows version of the game on macOS or Linux.
-
Note for non-Windows users: If you have the Windows version of the game on CDs but you don’t want to use Windows to install them, then you can follow these instructions:
How to install the Windows Dual-Jewel version of Descent 3 in Wine
- Make sure that you have Wine installed.
- (Recommended) Run
winecfg
and make sure that “Emulate a virtual desktop” is enabled. -
(Optional) Determine if you’re going to be affected by a bug with Descent 3’s installer, and potentially apply a workaround:
- Download Environment Size Checker.
- Run
wine environment-size-checker.exe
. - If that program tells you that your environment is more than 32,724 bytes large, then you’ll need to unset or shorten environment variables before running Descent 3’s installer. If you don’t, then the installer will page fault.
-
Install Descent 3:
- Insert disc 1.
- Make sure that disc 1 is mounted.
- Determine which drive letter Wine is using for your CD drive. (Hint: try running
wine explorer
). - Run
wine '<drive-letter>:\Setup.exe'
. - Follow the installation wizard’s instructions until it asks you to choose a “Setup Type”.
- Select the “Full” Setup Type, then click “Next”.
- Continue following the installation wizard’s instructions until it asks you to insert disc 2.
-
Switch to disc 2:
- Run
wine eject <drive-letter>:
. - Make sure that the disc was unmounted and ejected.
- Insert disc 2.
- Mount disc 2.
- Run
- Continue following the installation wizard’s instructions until it asks you to insert disc 1 again.
- Switch back to disc 1. Follow a similar procedure to the one that you used to switch to disc 2.
- Finish the going through the installation wizard.
- When the installation wizard finishes, it will open an explorer window. Close out of that window.
- Unmount the disc.
- Eject the disc.
-
Install Descent 3: Mercenary:
- Insert disc 3.
- Make sure that disc 3 is mounted.
- Run
wine start /d <drive-letter>: setup.exe -autorun
. - Follow the instructions in the installation wizard.
-
-
If your version of Descent 3 is older than v1.4, then update it to v1.4.
-
Create a new folder named
D3-open-source
. -
Copy the following files from your installation of Descent 3 to
D3-open-source
:- All
.hog
files - The
missions
folder - (Optional) All
.pld
files - (Optional) The
demo
folder - (Optional) The
movies
folder
- All
-
Create the following folders in
D3-open-source
:custom/
custom/cache/
-
Obtain new Descent 3 engine files:
- If you want to use pre-built binaries, then download one of the artifacts from our latest CI run. You can find a list of CI runs here.
- If you want to build the engine files yourself, the follow these instructions. Once you build the engine files, they’ll be put in
builds/<platform>/Descent3/<build-type>/
. For example, if you’re using Linux and you create a “Release” build, then the files will be located atbuilds/linux/Descent3/Release
.
-
Copy all of the new engine files into
D3-open-source
and overwrite any conflicts. -
Run the game:
- On Windows, run
D3-open-source\Descent3.exe
. - On other platforms, run
D3-open-source/Descent3
.
- On Windows, run
-
Special notes:
- D3 Open Source compiles level scripts in their own hogfiles. Make sure you copy and overwrite
d3-{platform}.hog
.
- D3 Open Source compiles level scripts in their own hogfiles. Make sure you copy and overwrite
Building
Building - Windows
-
Make sure that you have Git and Visual Studio 2022 with the “Desktop development with C++” workload and the “C++ MFC for latest v143 build tools (x86 & x64)” component. If you don’t already have those installed or you aren’t sure, then open an elevated Command Prompt and run:
winget install Git.Git Microsoft.VisualStudio.2022.Community "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\setup.exe" modify^ --passive^ --channelId VisualStudio.17.Release^ --productId Microsoft.VisualStudio.Product.Community^ --add Microsoft.VisualStudio.Workload.NativeDesktop;includeRecommended^ --add Microsoft.VisualStudio.Component.VC.ATLMFC
-
Open a “x64 Native Tools Command Prompt” and run:
git clone https://github.com/DescentDevelopers/Descent3 cd Descent3 cmake --preset win -D ENABLE_LOGGER=[ON|OFF] -D BUILD_EDITOR=[ON|OFF] cmake --build --preset win --config [Debug|Release]
Once CMake finishes, the built files will be put in builds\win\Descent3\Debug
or builds\win\Descent3\Release
.
Building - macOS
-
Make sure that Xcode is installed.
-
Make sure that Homebrew is installed.
-
Run these commands:
git clone https://github.com/DescentDevelopers/Descent3 cd Descent3 brew bundle install cmake --preset mac -D ENABLE_LOGGER=[ON|OFF] cmake --build --preset mac --config [Debug|Release]
Once CMake finishes, the built files will be put in builds/mac/Descent3/Debug
or builds/mac/Descent3/Release
.
Building - Linux (Ubuntu)
Run these commands:
sudo apt update
sudo apt install -y --no-install-recommends git ninja-build cmake g++ libsdl2-dev zlib1g-dev
git clone https://github.com/DescentDevelopers/Descent3
cd Descent3
cmake --preset linux -D ENABLE_LOGGER=[ON|OFF]
cmake --build --preset linux --config [Debug|Release]
Once CMake finishes, the built files will be put in builds/linux/Descent3/Debug
or builds/linux/Descent3/Release
.
Building - Linux (Fedora)
Run these commands:
sudo dnf update --refresh
sudo dnf install -y git ninja-build cmake gcc-c++ SDL2-devel zlib-devel
git clone https://github.com/DescentDevelopers/Descent3
cd Descent3
cmake --preset linux -D ENABLE_LOGGER=[ON|OFF]
cmake --build --preset linux --config [Debug|Release]
Once CMake finishes, the built files will be put in builds/linux/Descent3/Debug
or builds/linux/Descent3/Release
.
Contributing
Anyone can contribute! We have an active Discord presence at Descent Developer Network. If you are interested in maintaining the project on a regular basis, please contact Kevin Bentley.