This page contains fixes for various issues with the Klingon Academy game on new versions of Windows OS.
Multithreading crash fix
Multithreading crash fix
Sometimes the game crashes with Access violation error because its memory gets corrupted. This is caused by use of the no-serialize heap. This heap type assumes that it will be never accessed by more than one thread. Problem is that some callbacks from system functions are run in separate threads. This breaks that assumption. The result is a heap corruption. The fix removes the HEAP_NO_SERIALIZE flag from call to HeapCreate. For this to work properly, the game must not use its own heap implementation for small blocks. The small block heap is disabled on Windows 2000+ unless you run the executable in compatibility mode for earlier OS. If you run the game in Windows 95 or 98 compatibility mode, the fix does not work properly!.
How to apply automatically
The fix assumes that 1.02 patch (US, UK or German) is already applied.
If you plan to use the AI training variant kaai.exe, here is a patcher for it.
- Download the patcher
- Unpack it to game directory where the ka.exe file resides
- Run the extracted ka_patcher.exe file.
How to apply manually
The fix assumes that 1.02 patch (US, UK or German) is already applied. You need to open the ka.exe file in any hexadecimal editor and apply the changes mentioned bellow. The changes are described in following format:
offset: old_value new_value
Where the offset is offset from start of the file. At this offset is a single byte which should be changed. The old_value is value which should be there if you are at correct position in correct version of the ka.exe file. The new_value is value to which you should change the old value.
0030F1AB: 0F 90
0030F1AC: 94 90
0030F1AD: C0 90
If you are unsure how to do this change, there is a description how to do it with the free PSPad editor. Remember to back-up you original file so you can revert to it if you do something incorrectly.
The manual change for kaai.exe is:
- Open the file in the PSPad. The program should open in the hexadecimal mode
- Press Ctrl+G or select "Goto Line" from the Search menu.
- Ensure that the "From file beginning" choice is selected.
- Enter $0030F1AB into the "Bytes" field
- Starting from the cursor position you should see following: 0F 94C0 50FF. If that is not true, you are in incorrect version of file or you did something wrong in the previous steps so do NOT continue with the editing and try again from the beginning.
- Ensure that the overwrite mode is selected (visible in the status bar at the bottom of the window)
- Type 909090
- The result should now look like: 90 9090 50FF
- Save the file
0030F4CB: 0F 90
0030F4CC: 94 90
0030F4CD: C0 90
The resolution selection window in the standard launcher presents only limited number of resolutions. This patch disables the check so all resolutions enumerated on the system are available.
How to apply automatically
- Download the patcher
- Unpack it to game directory where the kalaunch.exe file resides
- Run the extracted kalaunch_patcher.exe file.
How to apply manually
Apply following changes to kalaunch.exe. Similar to the manual use of the multithreading patch.
000012CA: 75 90
000012CB: 1D 90
000012D2: 0F E9
000012D3: 84 85
000012D4: 84 00
Rendering fix & improvements
The game has some graphical issues on new OS and GPUs. The most annoying one are white flashes in the background during movement. Another problem is absence of dithering on latest cards which makes the limitations of the 16bit color mode even more noticeable. I made a wrapper which translates game calls to the DX9 to fix the first issue. It also converts part of the rendering to 24bit colors to reduce the second issue (the textures are still 16 bit so additional dithering would still help), generates mipmaps and forces the textures to use trilinear filtering.<
To use it, extract the file into the directory containing the ka.exe file. To remove it, delete the extracted ddraw.dll file. If you have any feedback, you can contact me at jiridvorak at centrum dot cz
Few screenshots of the improved rendering (click image for full scale version).
- The fog might be not fully correct
- Switching to another program is not supported on Windows XP.
- Limited error handling - assumes that the GPU supports all required DX9 functionality (PS/VS 2.0, depth format D32F_LOCKABLE or D16_LOCKABLE (untested)).
- The cloaking field image is 16bit so it can be more noticeable against the 24bit background.
- The game internal screenshot functionality reads a 16bit image instead of the 24bit one (result comparison) so use of external program like Fraps is preferred.
The wrapper provides limited configuration options to work around issues on various systems or to trade output quality for speed. The configuration is done by creating environmental variables with specific name and any value unless specified otherwise.
Following variables are available:
|Configuration you might want to maximize depending on your HW|
|D3DEMU_ANISOTROPY||The value must be number greater than or equal to 1 specifying quality of the filtering (1 - minimal). Alternatively a max might be used to indicate maximal supported quality. Quality values above the supported range are clamped to nearest valid value.|
|D3DEMU_MSAA_QUALITY||The value must be number greater than or equal to 1 specifying quality of the anti-aliasing. Alternatively a max might be used to indicate maximal supported quality. Quality values above the supported range are clamped to nearest valid value.|
|Configuration you might want to try|
|D3DEMU_NO_CPU_STARFIELD||Disables CPU drawn dots in the starfield for significant performance gain.|
|D3DEMU_NO_LOCKABLE_Z||Disables emulation of depth buffer reads. Increases speed and might fix compatibility issues with SLI solutions. Enabled automatically on ATI cards. No noticeable visual effect|
|D3DEMU_UI_30FPS||Allows the UI to be run on 30 fps instead of the default 16. Causes UI stalls on lower end HW or when Fraps video recording is active.|
|D3DEMU_FORCE_BLACK_ALPHA||Improves color consistency between surfaces with light sources (windows/impulse/warp) and surfaces without them.|
|Configuration for special uses|
|D3DEMU_3D_VISION||Enables support for Nvidia 3D Vision for KA (no SFA). As the game is old, there are few glitches - the PIP image is broken and the target reticle is drawn at the screen level. D3DEMU_NO_CPU_STARFIELD should be used|
|D3DEMU_KA_LOG||Reactivates remnants of the KA internal log and redirects its to wrapper's log.|
|D3DEMU_LOG_FLUSH||Flushes the log after each output to ensure that it contains all the data if the game crashes for some reason.|
|D3DEMU_NO_VISTA||Disables use of extended DirectX interfaces on Vista.|
|D3DEMU_NO_HW_PROCESSING||Switches between HW and SW vertex processing.|
|D3DEMU_NO_BUFFERS||Disables use of vertex and index buffers.|
|D3DEMU_NO_HW_COLOR_CONVERSION||Disables GPU based color conversion for render targets.|
|D3DEMU_NO_COMPOSITION_COMPARE||Disables check for changes in composition surface.|
|D3DEMU_NO_TIMER||Disables timer based screen refreshes in the UI mode.|
|D3DEMU_NO_TIME_REDIRECT||Disables redirection of GetTickCount to timeGetTime.|
Creation of environment variables on English versions of Vista+
Use the control panel to search for "environment" keyword. In Vista it finds entry "Edit environment variables for your account". Use it to add new user variable with the desired name and any value.
Compilation from source code
To directly compile the source code you need the Microsoft Visual Studio 2008 (otherwise you might have to update the project for your environment) and DirectX SDK for DX versions 7 and 9.
Version 1.22 (20.3.2015) - Stable.
- Fixed rendering of Nebulaes in Starfleet Academy.
- Fixed incorrect blending mode for first geometry drawn in scene in Starfleet Academy.
Version 1.21 (19.8.2014) - Experimental.
Version 1.19 (21.3.2011) - Stable.
- Improves smoothness on newer fast systems where precision of GetTickCount stays on 15ms.
Version 1.20 (9.4.2011) - Experimental.
- The out-of-system warp images work.
Version 1.18 (20.3.2011) - Experimental.
- Adds support for Nvidia 3D Vision. Does not work properly with SFA. Disabled by default and must be enabled using D3DEMU_3D_VISION.
Version 1.17 (24.2.2011) - Stable.
- Supports Starfleet Academy as well
- Uses timer to refresh the screen in the UI mode if the game does not issue draw calls for long period of time (script error message box, some message boxes in SFA).
Version 1.16 (23.2.2011) - Experimental.
- Supports the in-game screenshot functionality.
Version 1.15 (19.2.2011) - Experimental.
- Overrides use of non-black alpha channel on light source textures for better lighting consistency. Must be enabled using D3DEMU_FORCE_BLACK_ALPHA.
Version 1.14 (14.2.2011) - Experimental.
- Uses GPU for 16<->32 conversions on the render target for nice speed increase if cloaked ships are present. Can be disabled by D3DEMU_NO_HW_COLOR_CONVERSION.
- Avoids composition if nothing was changed in the surface. Can be disabled by D3DEMU_NO_COMPOSITION_COMPARE.
Version 1.13 (6.2.2011) - Stable
- Support for anisotropic filtering. The level if the filtering is specified by D3DEMU_ANISOTROPY.
- Support for MSAA. The quality is specified by D3DEMU_MSAA_QUALITY.
Version 1.12 (5.2.2011) - Stable
- Improved texture 16bit => 32bit conversion.
Version 1.11 (30.1.2011) - Stable
- Improved FPS when the "location description" text is visible at start of the mission.
Version 1.10 (29.1.2011) - Experimental, might contain new bugs
- Intercepts additional KA logging function for additional log output
- Log output can be flushed to prevent loss if the game crashes. Enable by D3DEMU_LOG_FLUSH
Version 1.09 (28.1.2011) - Experimental, might contain new bugs
- The faster UI FPS mode from 1.08 is now disabled by default for compatibility reasons. Create environmental variable D3DEMU_UI_30FPS to re-enable it.
Version 1.08 (27.1.2011) - Experimental, might contain new bugs
- Fixed crash in kamovies.exe
Version 1.07 (26.1.2011) - Experimental, might contain new bugs
- Support for kaai.exe
- Allows faster FPS in the UI
Version 1.06 (23.1.2011) - Experimental, might contain new bugs
- Ignores display mode changes when used by kalaunch.exe to speed up the resolution detection.
Version 1.05 (23.1.2011) - Experimental, might contain new bugs
- Fixed crash of KALaunch created in 1.05
- It is possible to enable output from the KA internal log by creating environment variable D3DEMU_KA_LOG
- Use of the D3DEMU_NO_CPU_STARFIELD mode is reported in the log
Version 1.04 (22.1.2011) - Stable
- Optimization of draw call batching.
- Various API optimizations
- Ability to disable the CPU drawn part of the starfield (the part of the starfield which remains when detailed starfield is disabled in the game.) by creating environment variable D3DEMU_NO_CPU_STARFIELD
Version 1.03 (20.1.2011)
- The KALaunch is supported by the wrapper.
Version 1.02 (20.1.2011)
- Compatibility fix for Nvidia cards on Windows XP. Tested on GeForce 6150LE.
Version 1.01 (15.1.2011)
- Emulation of depth buffer readback is disabled on ATI cards due to poor performance.
Version 1.00 (27.12.2010)
- Disabled Vista+ flag on XP
Version 0.07 (24.12.2010)
- I was able to complete the game using the 0.07 without any serious glitches (Vista 64bit, GeForce GTX 460, 260.63 drivers).
- Lightly tested support for switching to another program on Windows Vista+. I am lazy so it simply uses the Vista+ version of the DX9 interface which does not lose the device in that situation. If D3DEMU_NO_VISTA environment variable is present, it will behave as the previous versions.
Version 0.06 (23.12.2010)
- Fixed cloaking field effect
Version 0.05 (23.12.2010)
- Fixed depth buffer operation broken in 0.05
- Fixed drawing in presence of the letterbox border
- Fixed dropping out of 24 bit mode for the nebula background in the first mission
- Fixed cleanup of resources
- Forced texture mipmaps on drivers with support for mipmap autogeneration