############################
# 0 — How to use the patch #
############################

Step 1: Install the game. For instructions how to install it on newer Windows versions, see Section 1.

Step 2: IMPORTANT! Copy (or move) ubi.ini from <Windows Directory>\UbiSoft\ to <Game Directory>\UbiSoft\ (need to create the folder in the game directory first). E.g., if your Windows folder is C:\Windows and you installed the game to C:\Games\Hype, then you need to create a new folder C:\Games\Hype\UbiSoft and copy the ubi.ini from C:\Windows\UbiSoft there.

Step 3: From the patch folder, copy MAID3DVR_BLEU.exe from either the "English" or "Spanish" subdirectory to your game folder. The English EXE also works with the German version of the game. For most other localizations, one of the two EXE-files should work. If your localization is not compatible (or you are just curious how I created the patch), read Section 2!

Step 4: Make sure you have Python 3 installed as well as the python-lzo module ("pip install python-lzo"). Copy Widescreen_FPS_fix.py and FOV_fix.py to your game folder (for convenience! You can also run them from anywhere else - the script will then ask you for the path). Run them and follow the instructions on screen. MAKE SURE YOU NOTE DOWN THE INTERNAL RESOLUTION (the script will tell you)!

Step 5: Configure a Direct3D wrapper to support the custom resolution that was set in Widescreen_FPS_fix.exe. Instructions for dgVoodoo and DDrawCompat are given in Section 3.

Step 6: Fix issues with FMV playback. See Section 4. If your game crashes on startup, this is most likely the reason.


##############################
# 1 — Help with installation #
##############################

The original game installer doesn't seem to work on Windows 10 or newer. There are several ways around this.

(a) Manual installation:
	(1) Create a new folder "Hype" wherever you want. I will call it <Game Directory>.
	(2) Copy the folders "DLL", "GameData" and "InstData" from the CD to <Game Directory>.
	(3) Copy LangData\XXX\world (XXX is your language) from the CD to <Game Directory>\GameData (there should already be a folder "world", just integrate the new one into it).
	(4) Move all files from <Game Directory>\GameData\World\Sound\XXX\ to <Game Directory>\GameData\World\Sound\ (XXX is your language).
	(5) Create a new folder "UbiSoft" inside <Game Directory> and copy ubi.ini from <Patch Directory>\manual install\ to <Game Directory>\UbiSoft\. You can skip Step 2 of Section 0 after this.
	(6) In ubi.ini, edit the line "Language=English" to match your version of the game (otherwise there will be no speech).
	
(b) Install the game in a virtual machine and copy the game directory over. You will also need the ubi.ini from the virtual machine's Windows directory (see Section 0, Step 2).
	
(c) Use the alternative installer from here (not tested): https://www.pcgamingwiki.com/wiki/Hype:_The_Time_Quest#Installing_on_modern_versions_of_Windows
	
#########################################
# 2 — Create your own MaiD3Dvr_bleu.exe #
#########################################

NOTE: This is not necessary if one of the two EXE files (English/Spanish) provided with the patch work for you.

I have written a script that applies the changes contained in the "nGlide patch" (that you will frequently find on the internet) to ANY version of the game's executable (e.g. the Direct3D EXE).
The "nGlide patch" is basically just the original MaiDFXvr_bleu.exe with its SafeDisc encryption removed and the following changes:
- Additional checks if the CD is in the drive (independent of SafeDisc) are removed.
- The file ubi.ini is expected to be in the game directory rather than the Windows directory, thus making the game portable.

So if you would like to patch your own MaiD3Dvr_bleu.exe to run on modern systems, consider the following steps:
(1) Check if the folder "<Hype CD>\exe\D3D\" contains an ICD-file. If not (e.g. in the Spanish version of the game), then the EXE is not encrypted by SafeDisc (go to the next step). Otherwise you first have to remove the SafeDisc encryption. For this you need the files MaiD3Dvr_bleu.exe, MaiD3Dvr_bleu.icd and dplayerx.dll (from the discs main directory) as well as a tool that decrypts the EXE. You can find one here: https://community.pcgamingwiki.com/files/file/646-unsafedisc/.
(2) Make sure you have Python 3 installed as well es the pefile module ("pip install pefile"). Place the script Hype_patch_EXE.py from the "src" subfolder and your decrypted MaiD3Dvr_bleu.exe in the same directory and run the python script.

######################################
# 3 — Configure the Direct3D Wrapper #
######################################

The widescreen patch changes the games INTERNAL resolution to 640xXXX (depending on chosen aspect ratio). In order for the game to accept this resolution, a Direct3D wrapper needs to "tell" the game that this resolution is supported by your system. In the following, you can find instructions how to set up either dgVoodoo or DDrawCompat (whichever you prefer).

#-----------------#
#---- dgVoodoo ---#
#-----------------#

(1) Download the latest stable version of dgVoodoo from here: https://github.com/dege-diosg/dgVoodoo2/releases
(2) Copy dgVoodooCpl.exe & dgVoodoo.conf from the main directory as well as D3DImm.dll & DDraw.dll from the \MS\x86\ directory to your game's main folder (where MaiD3Dvr_bleu.exe is).
(3) Open the configurator dgVoodooCpl.exe and right-click anywhere in the window to select "Show all sections of the configuration" (activates advanced options).
(4) In the tab "DirectX":
	- Under "Resolution, select your monitors native resolution (e.g. 1920x1080).
	- Under "Videocard", select "ATI Radeon 8500". This will resolve some graphical glitches related to colorkeying.
	- You probably also want to uncheck the "dgVoodoo Watermark".
(5) In the tab "DirectXExt"
	- Under "Enumerated resolution" after "Extras", enter the custom resolution that the Widescreen & FPS Fix showed you (e.g. "640x360", without quotes).
(6) [Optional] The game really doesn't like Alt+Tabbing. With the following settings, I was able to make it work:
		- In the tab "DirectX" under "Behavior", uncheck both "Application controlled fullscreen/windowed state" and "Disable Alt+Enter to toggle screen state".
		- In the tab "GeneralExt" under "Fullscreen mode attributes", check "Fake".
		Now you should be able to Alt+Tab out of the game IF you toggle window mode first (by pressing Alt+Enter). Once are back in the game, you can press Alt+Enter again to go back to fake-fullscreen mode.

#--------------------#
#---- DDrawCompat ---#
#--------------------#

(1) Download the latest realease of DDrawCompat from here: https://github.com/narzoul/DDrawCompat/releases.
	Download DDrawCompat.ini from here: https://github.com/narzoul/DDrawCompat/blob/master/Tools/DDrawCompat.ini
(2) Copy ddraw.dll as well as DDrawCompat.ini to your game's main folder (where MaiD3Dvr_bleu.exe is).
(3) Open DDrawCompat.ini in a text editor and make the following changes:
	- Uncomment (remove the #) "ResolutionScale" and set it to "ResolutionScale = display(1)".
	- Uncomment "SupportedResolutions" and add the custom resolution that the Widescreen & FPS Fix showed you (e.g. "SupportedResolutions = native, 640x480, 800x600, 1024x768, 640x360").
	- Uncomment AltTabFix and set "AltTabFix = noactivateapp(1)". This should allow you to Alt+Tab.
NOTE: There might be issues with FMV playback using DDrawCompat. See possible workarounds in Section 4 and if nothing works, turn off FMV playback altogether (workaround d).

#--------------------#
#---- DDrawCompat ---#
#--------------------#

######################################
# 4 — Solve issues with FMV playback #
######################################

The main reason why FMV playback does not work properly is that the videos are encoded with the Indeo 5 codec. Due to security holes, Microsoft disabled Indeo 5 playback in newer versions of Windows.
Here are a few workarounds you can try to make the FMVs play again (and possibly avoid crashes when the game starts):

(a) [Recommended] Convert the FMVs to the more compatible Cinepak format. To do this, download ffmpeg from here: https://ffmpeg.org/download.html (the "essentials" build should suffice). Move the FMV files from <Game Directory>\GameData\Videos\ to the "bin" subfolder in your ffmpeg folder. Next, open a command prompt, navigate to the "bin" folder and run the following commands:
	- ffmpeg -i "HypeConclusion.avi" -c:a copy -c:v cinepak "HypeConclusion_NEW.avi"
	- ffmpeg -i "HypeIntro.avi" -c:a copy -c:v cinepak "HypeIntro_NEW.avi"
	- ffmpeg -i "LOGO.AVI" -c:a copy -c:v cinepak "LOGO_NEW.AVI"
	Ignore the occasional error that might pop up during the conversion process. Note that the conversion may take a CONSIDERABLE amount of time, even on fast machines! Luckily, this only needs to be done once. After everything is done, make a backup of (or delete) the "old" files and rename the new ones by removing the suffix "_NEW". Then copy the new FMV files back to <Game Directory>\GameData\Videos\.

(b) [Thanks to https://www.pcgamingwiki.com/wiki/Windows] Re-enable the Indeo 5 code by starting the command prompt as administrator and running the following command:
	- regsvr32 "%WINDIR%\SysWOW64\ir50_32.dll"
	Once you are done playing the game, I advise you to disable the codec again (due to the aforementioned security issues):
	- regsvr32 /u "%WINDIR%\SysWOW64\ir50_32.dll" (Ignore the runtime error that may come up)

(c) If you are still experiencing issues, play around with the FMV playback settings in ubi.ini (in <Game Directory>\UbiSoft\). You can try to add one of the following lines to the [Hype - The Time Quest] section in ubi.ini and see if this changes anything:
	- ForceVideoMode=Default
	- ForceVideoMode=ChildWindow
	- ForceVideoMode=DXMedia

(d) If nothing works, you can always disable FMV playback to avoid crashes. Besides the logo, there are only two FMVs: One plays at the very beginning of the game and one at the end. You might as well just watch them with VLC player.
	To completely disable FMVs, open ubi.ini (in <Game Directory>\UbiSoft\) and set PlayVideo=0.

###########
# 5 — FAQ #
###########

- Why do I need to move ubi.ini to the game's folder? Shouldn't it be in the Windows directory?
I have patched the game's executable to only look for the file in <Game Directory>\UbiSoft\ and not in the Windows directory. This is exactly the same behavior as the nGlide patch (MaiDFXvr_bleu.exe) that circulates the internet. This makes the game portable (no need for anything in the Windows folder)!

- How to set a custom FOV?
The horizontal field of view (FOV) value is automatically determined from the aspect ratio (AR) that you enter so that the vertical field of view does not change with the new resolution. The formula is FOV = 2 * arctan(tan(1.5/2)*(3/4)*AR). If you solve for AR, you get AR = 4/3 * cot(3/4) * tan(x/2). So if, e.g., you would like to have a custom FOV of 2, simply enter an aspect ratio of "2.229:1" into the FOV changing tool.

- The main menu is really hard to navigate! Whenever I press a button it skips one item...
This happens when you run the game at high framerates! The game was designed to run at 50 FPS. Even at 60 FPS you sometimes skip over a menu item if you just keep the button pressed. The solution is to just tap the button for a short time. At 60 FPS, the menu should still be quite easy to navigate. However, at very high framerates, it can become difficult. Note that the framerate in the main menu is independent of the actual in-game framerate that we patched from 48 FPS to our desired value. Your DirectX Wrapper should be configured to either limit the framerate or use vSync. As far as I know, dgVoodoo and DDrawCompat have vSync turned on by default (in dgVoodoo it might say it's turned off, but I have yet to find a way to ACTUALLY turn it off for this game).

- Why do the backgrounds (e.g. main menu / loading screen) have a lower resolution than normal?
This is because internally, the game is running at a resolution of 640xXXX (depending on your aspect ratio). This is a lower resolution than normal, so every 2D element gets scaled down.

- Why are you setting an internal resolution of 640xXXX and let the Direct3D wrapper do the scaling? Can't you just set it to a higher resolution?
I would love to do that, in particular because of the downscaling of the backgrounds etc. Unfortunately there are two problems: First, setting the resolution too high (e.g. 1280x720) will crash the game due to some memory issues. Second, changing the internal x-Resolution messes up the placement of almost every 2D element on screen, e.g. dialogue boxes, HUD elements... Keeping the x-resolution at 640 and only changing the y-Resolution only messes with the circle around your spells that indiactes how much magic you have left (which btw. is a 3D object) and luckily I have found a hack to fix this - see the source code if you are curious.

- Why does the FPS value that you set the game to differ from the actual FPS?
The way that the timing in the game works is that it renders one frame every x milliseconds. The problem here is that x is stored as an integer! So a framerate of 50 FPS is possible since it means that a new frame is rendered every 20 ms. A framerate of 60 is not possible (at least not internally - you can always use an external FPS limiter) since it would mean that a new frame is rendered every 16.67 ms, which is not an integer. Now FOR SOME REASON (which I don't fully understand), the game always takes one additional millisecond to render a frame than you would expect from the provided FPS value. Therefore, the formula for the actual framerate, if y is the provided FPS value, is 1000/(floor(1000/y) + 1). Hence, if you set the FPS value to 50 (which the developers did, since it's a PAL game), you will get an actual framerate of 47.62 (the infamous 48 frames that you observe in the unpatched game).

- Why is setting the FPS value to anything greater than 66 experimental?
The game uses so-called delta timing to adjust the game's logic to the actual (!) framerate (see the previous question why the provided FPS value and the actual framerate differ). This means that the game doesn't "slow down" when the framerate drops and doesn't "speed up" when the framerate increases. However, the game has an internal floor of 12.5 FPS and a cap of 62.5 FPS. If the actual framerate drops below this floor, the game will slow down and when it rises above this cap, the game will speed up. If you set the FPS value to 67 or higher, the actual FPS will be above 62.5 (see the previous question). To avoid speed-up, I patched the game's delta timing by setting the cap to 1000 FPS. Since I have no clue if this messes up anything else (e.g. jump physics), this feature is experimental.