Thursday, August 24, 2017

Gamepad is accessible using...

A gamepad can be found and its state read by many interfaces.
Here are some that I saw used:

Detect and read state
XInput
Dinput
HID
Raw Input

Only Detect
WbemLocator
SetupDiEnumDeviceInfo and SetupDiGetDeviceInstanceId

Tuesday, May 23, 2017

WM_CHAR is not a real message

While investigating how to send capital-letter to an application, I found the message WM_CHAR.
Apparently, this message is not generated by the OS, but by TranslateMessage.

TranslateMessage get the WM_KEYDOWN, and if it is a character, check the modifiers, (such as shift, caps-lock, and other keys) and emit a WM_CHAR.

TranslateMessage is an kernel-level function, and check the status of the physical keys. so you can't mess with it. Also, because it is kernel-level, the message looks like the OS sent it.

Tuesday, March 21, 2017

How to make you game easy to be added to cloud gaming service


There are a few cloud gaming services active. If you want to sell them you game, and make it easy for them to use your game, here are a few tips:


  1. Use the popular Direct3D version.
    Most of the games use 9, 9ex, 11.0/1.
  2. Make rendering in a dedicated thread.
    Everything that can hinder rendering is bad. especially loading.
  3. Always show something.
    Even if it is a stupid loading animation. because you can never know how long doing that operation will take.
  4. Load data / save file / whatever in a separate thread.
  5. Test your game under extreme CPU condition.
    Something running in the background?
    run with only 1 CPU?
    How many cores your game need to function? cores is money.
  6. Test your game under extreme FPS conditions.
    Does your game runs OK in 20 fps? 100 fps?
  7. How GPU intensive is your game?
    While heavy games will take half of the GPU time per frame, (=60 fps)
    There is no reason why your side-scroller will take more then quarter, or even a sixth of the GPU.
    GPU time is money. 
  8. Test your game under heavy disk load.
    If the disk is very busy doing other things when the game is running, how is the experience?
  9. Make your menus clean and simple.
    We are blocking the user from doing certain things, and if the menus are messy, moving and dynamic it will be very difficult.
  10. Separate user-configs and system configs
    Things that user should be able to change: volume, subtitles.
    Should not be able to change: graphic settings, controller.
    Should be changes system-wise: language.
    Keep these in separate places.
    The Registry is considered separate places. 
  11. Run the game under various graphic settings
    Full screen, windowed, vsync on, vsync off. and such. 

Activating Windows Loader debug messages

When you want to know what went wrong in loading the process.

My sources:
Entry Point Not Found, and other DLL Loading Problems
Microsoft System Journal, Under the Hood, September 1999

Basically, they highlight the usage of Windows Debugging Tools utility Global Flags.
It should be able to add a flag "Show Loader Snaps" to the target process.

Well, it doesn't do anything on my machine. So:

Go to
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
Add a key with your EXE name, such as "ConsoleApplication1.exe" (without path)
Add a value to that key, Type: DWORD,  name: "GlobalFlag", value 2.

Now run the process under debugger.
Running and external debug messages collectors such as WinDbg or DebugView won't work.
But running it using Visual Studio or Ollydbg, the loader messages are showing in the output window.

Tuesday, February 7, 2017

Errors in Windows header files

From time to time I find errors in the WinAPI header files.
Usually, they are small errors, which can be very annoying in certain cases.

Example #1:
Some function definitions lack the DECLSPEC_IMPORT (which is a macro for DLL import/export tag)
Usually, it is not a problem. The compiler identify it as external, and the linker finds it in the WinAPI. But it means that the function pointer does not point directly to the DLL, but indirectly using stubs. On normal usage you won't notice that, but it causes problems with MSDetour library.

Example #2:
EnumPageFiles accept a callback of type PENUM_PAGE_CALLBACK.
But in the definition of that in Psapi.h, they forgot to add the CALLBACK modifier, that should make it to stdcall.
So, if you are using the function, at best you get a weird compilation error, or simply a crash.