Build Sonic Mania Decompilation With MSYS2

by Alex Johnson 43 views

Are you eager to dive into the world of Sonic Mania decompilation and build the project using MSYS2? This comprehensive guide will walk you through the necessary steps, ensuring a smooth and successful build. We'll cover everything from setting up your environment to resolving potential build errors. Let's get started!

Prerequisites: Setting Up Your MSYS2 Environment

Before we begin, ensure you have the necessary tools and dependencies installed. This involves downloading and installing MSYS2, a software distribution and building platform for Windows, providing a Unix-like environment. Navigate to the MSYS2 website and download the latest msys2-x86_64-YYYYMMDD.exe installer (replace YYYYMMDD with the actual date).

Once downloaded, run the installer. During the installation, you'll be prompted with a few options; you can generally accept the defaults. After installation, locate the "MSYS2 MINGW64" application shortcut (it's crucial to select this one, not the default "MSYS2 UCRT64" shortcut). Launching "MSYS2 MINGW64" will open a terminal where you'll execute the commands to install essential packages. The choice of MINGW64 is important as it provides the compiler toolchain that we will use to build the decompilation.

Installing Essential Packages

Inside the MSYS2 MINGW64 terminal, execute the following command to install the required packages. This command utilizes pacman, the package manager for MSYS2:

pacman -S --needed git base-devel cmake mingw-w64-x86_64-toolchain mingw-w64-x86_64-glew mingw-w64-x86_64-glfw mingw-w64-x86_64-libtheora

This command does a couple of things. First, it syncs the package database and downloads the latest information about available packages. Then, it installs several critical packages. git is for version control, allowing you to clone the Sonic Mania Decompilation repository. base-devel contains essential build tools. cmake is a cross-platform build system generator that we'll use to configure the project. mingw-w64-x86_64-toolchain provides the compiler, linker, and other build tools. The remaining packages (mingw-w64-x86_64-glew, mingw-w64-x86_64-glfw, and mingw-w64-x86_64-libtheora) are libraries required by the project. Specifically, they provide OpenGL support, windowing functionality, and Theora video decoding. After you've entered the command, the system will prompt you to confirm the installation; type Y and press Enter to proceed. The installation process might take some time depending on your internet connection and system configuration.

Cloning the Decompilation Repository and Initial Setup

With MSYS2 and the necessary packages installed, the next step involves cloning the Sonic Mania Decompilation repository from GitHub. This is where the source code for the project resides. Use the git clone command within your MSYS2 MINGW64 terminal to clone the repository:

git clone --recursive https://github.com/RSDKModding/Sonic-Mania-Decompilation

The --recursive flag ensures that any submodules (other repositories included within the main project) are also cloned. Once the cloning process is complete, navigate into the Sonic-Mania-Decompilation directory using the cd command:

cd Sonic-Mania-Decompilation

Configuring the Build System

To prepare the build system for MSYS2, you'll need to create a copy of a platform-specific CMake configuration file and then run CMake to generate the build files. First, copy the Linux platform configuration file to a new file suitable for MSYS2:

cp dependencies/RSDKv5/platforms/Linux.cmake dependencies/RSDKv5/platforms/MSYS.cmake

This copy operation provides a template for MSYS2, allowing you to tailor the build process for your environment. Now, use CMake to configure the project. CMake will examine the project files and generate the necessary build files for your environment. Run the following command:

cmake -B build

The -B build option tells CMake to create the build directory named build. The build directory will contain the generated build files that are used by the make command to compile the project. If you encounter any issues during the CMake configuration process, make sure to review the error messages carefully and double-check your installation and commands.

Resolving Build Errors and Making Necessary Code Modifications

At this stage, you might encounter build errors. These errors are often related to differences between the target platform (in this case, MSYS2) and the original build configuration. Don't worry; we will address these issues with specific code modifications.

Fixing void* and Function Pointer Conversion Errors

One common error is related to an invalid conversion between void (*)(void*) and void*. This error arises because of how function pointers are handled in C and C++. To rectify this issue, edit both dependencies/RSDKv5/RSDKv5/main.cpp and dependencies/RSDKv5/RSDKv5/main.hpp. Change the function prototype for RDSK_main like this:

//int32 RSDK_main(int32 argc, char **argv, void *linkLogicPtr);
int32 RSDK_main(int32 argc, char **argv, void (*linkLogicPtr)(void*));

This modification ensures that the function signature correctly matches the expected type, resolving the conversion error.

Suppressing Compiler Warnings

Another potential issue involves compiler warnings related to pragmas. These warnings typically do not prevent the build from completing, but it's good practice to address them. In dependencies/RSDKv5/RSDKv5/RSDK/Audio/XAudio/XAudioDevice.hpp, comment out the following line:

//#pragma GCC diagnostic ignored "-Wmicrosoft-exception-spec"

This comment disables the warning, preventing it from cluttering the build output.

Adding Libraries to the Linker Command

The final fix involves adding specific libraries to the linker command. These libraries provide necessary functionality. Edit build/dependencies/RSDKv5/CMakeFiles/RetroEngine.dir/link.txt and append -lopengl32 -lole32 -lxaudio2_9 to the end of the line. This ensures that the linker includes these libraries when creating the executable, resolving any missing dependencies.

-lopengl32 -lole32 -lxaudio2_9

These modifications should resolve most common build errors encountered when building with MSYS2. After making these changes, you can proceed to the next step, where we build the project.

Building the Project

With all the prerequisites and modifications in place, it's time to build the project. The build process involves compiling the source code and linking it to create the executable.

Running the Build Command

Before running the build command, it's a good practice to set the CMAKE_BUILD_PARALLEL_LEVEL environment variable. This variable tells the build system how many processes to use for parallel compilation, speeding up the build process. Set this to the number of processors your computer has by running this in the MSYS2 MINGW64 terminal:

export CMAKE_BUILD_PARALLEL_LEVEL=$NUMBER_OF_PROCESSORS

Replace $NUMBER_OF_PROCESSORS with the actual number of processors your system has. To initiate the build, execute the following command:

cmake --build build --config release

The --build option tells CMake to build the project, and --config release specifies that you want to build the release version, optimized for performance. If the build succeeds, the executable RSDKv5U.exe will be located in the build directory. If you encounter any errors during this step, review the error messages and ensure that you've followed all the previous steps correctly, especially the code modifications and library additions. If you have already built, and want to restart, you may want to clean the build by running the command

rm -rf build && cmake -B build

Copying Required DLLs and Resources

To run the executable outside the build environment, you'll need to copy some DLLs (dynamic-link libraries) to the same directory as the executable. These DLLs provide necessary dependencies for the game to function. From the mingw64/bin directory, copy the following DLLs to the directory containing RSDKv5U.exe:

  • glew32.dll
  • libgcc_s_seh-1.dll
  • glfw3.dll
  • libogg-0.dll
  • libstdc++-6.dll
  • libtheora-1.dll
  • libwinpthread-1.dll

You'll also need to rename or copy msys-Game.dll to Game.dll. Also, ensure that you copy the resource file Data.rsdk to the same directory as the executable. This file contains the game's data and assets. Once you have copied all the required files, you should be able to run the executable.

Running the Executable

After copying the required DLLs and the data file, double-click RSDKv5U.exe to run the decompiled game. If you have followed all the steps correctly, the game should launch without issues. If you encounter any problems, double-check that you have copied all the necessary files and that the DLLs are in the correct directory. Also, make sure that you are using the correct game version. Congratulations, you have successfully built and run the Sonic Mania Decompilation using MSYS2!

Conclusion

Building the Sonic Mania Decompilation with MSYS2 requires careful attention to detail, but with this guide, you should be able to build the project. Remember to always consult the official documentation and the project's issue tracker for the most up-to-date information and troubleshooting tips. This guide offers a comprehensive walkthrough of the build process, including setting up the environment, resolving potential build errors, and running the executable.

For more information and help, consider visiting the official Sonic Mania Decompilation repository on GitHub and the MSYS2 documentation.


External Link:

  • RSDKModding GitHub - Visit the official repository for the latest updates and discussions.