We sort through the engine through the exhaust pipe, or how to get normal keyboard control in FIFA 12
How did it happen
In the long hidden past
Was the world just like ours
Once beautiful, but every flower dies ...
- All Mankind, “Break the spell”
The plot of history is trivial. Once upon a time, in a distant, distant galaxy, there was a great game called Fifa. She would have remained such, and if
I decided to
As it was before
Until the landmark 2010, Fifa had quite tolerable keyboard controls. The greatest advantage of the gamepad (at least in my opinion) was the significantly greater availability of special
How keyboardists were killed in Fifa 11
But very simple. In this version, the right stick was completely transferred to numpad, and the movement was left on the arrows.
What is bad here? Exceptionally, now these are different buttons. The whole familiar scheme based on the cipher flew to hell, and it was quite obvious that it was not possible to restore such a scheme. It worked, there were much less keyboard players than in 10k.
It should be noted that I was going for a long time. I endured such management for a whole year, but just a couple of days ago the cup of patience was finally overfilled.
The beginning of hostilities
Having brewed a stronger tea, I downloaded WDK, opened an example of a keyboard filter, and decided to adjust it to my own needs. But the trouble was that it was my first (and almost unsuccessful) experience creating a driver. In short, after about fifty reboots of the virtual machine (changing the keyboard driver required a reboot), I was a little bored with picking the code at six in the morning, and I fell asleep.
Morning, as you know, is always even wiser than the evening, and it brought a fresh thought. If Fifa loves a gamepad so much - why not? We emulate it ... I must say, many guys did just that, using a thing called KeyToJoy. She did not know what I wanted, but was popular, since in the 11th fiif, for example, the keyboard was not a full-fledged controller at all. I will warn you right awayA search for this keyword once led me to the archive in which the virus was sitting. I warned.
In general, I decided that it would be nice to find some kind of gamepad emulator, preferably with open source code, and fix it so that the keyboard controls are as close as possible to my usual ones.
And found. Here it is: VJoy homepage .
The author of this product is a big nyasha and just a good person, because he provided him with an excellent example of work, which was not difficult to remake in the way I needed.
Installing a virtual gamepad
Nothing complicated. We download the distribution kit (link to the site above), several times click "next" - and you're done.
No really. And what is there to write about?
Setting device parameters
After installation, you will need to configure the gamepad settings (number of buttons, axes ...), which will require the vJoyConf utility . Everything is also very simple there. For fifa, 10 buttons (A, B, X, Y, start, back, LT, RT, LB, RB), four axes (x, y, z, rz), a D-Pad with four directions are enough. The program does not reflect the current settings of the virtual gamepad, but only allows you to set new ones, so there is no need to be afraid that "the settings have not been saved" - everything was saved there.
Configured, where to check?
Everything is very simple - we launch the app “game devices” of the control panel (joy.cpl in “execute” is the fastest access option) and look at our virtual gamepad. What to do with him? Nothing yet. nobody controls them yet.
We control the joystick
And for this we need, for example, MS Visual C ++ Express. Well, yes, now we will listen to the keyboard and tell our gamepad which buttons to consider pressed. But what, should I play Fifu without feints?
So, here the creator of VJoy gives the world a simple C ++ console application that sends the gamepad commands to install a new state.
The example code is well documented, and in a couple of minutes it is redone as we need in the context of a specific task (for playing Fifu). For example, this code provides the switch I need so much from left stick to right stick:
bool shift = 0!=GetAsyncKeyState(VK_LSHIFT);
bool leftKey = 0!=GetAsyncKeyState(VK_LEFT);
bool rightKey = 0!=GetAsyncKeyState(VK_RIGHT);
bool upKey = 0!=GetAsyncKeyState(VK_UP);
bool downKey = 0!=GetAsyncKeyState(VK_DOWN);
Y = X = 0x3fff; //оси изначально в нейтральном положении
Z = ZR = 0x3fff;
//Вообще это очень топорное решение. Нужно плавнее.
//Но финты относительно сносно работают уже даже так.
if(!leftKey != !rightKey)
{
if (!shift)
X = leftKey ? 0 : 0x7FFF; //Это такие крайние положения у осей
else
Z = leftKey ? 0 : 0x7FFF;
}
if(!upKey != !downKey)
{
if(!shift)
Y = upKey ? 0 : 0x7FFF;
else
ZR = upKey ? 0 : 0x7FFF;
}
//Где-то много дальше по коду, после впиленных мной
//тривиальных обработчиков для кнопок джойстика
if (!DeviceIoControl (hDevice, IoCode, pPositionMessage, IoSize, NULL, 0, &bytes, NULL))
{
_tprintf(_T("Ioctl to vJoy device failed\n"));
break;
}
In fact, everything is very simple. We track the buttons, transfer them to the gamepad.
What is the bonus? Obviously, the complexity of the logic for pressing buttons can be absolutely any,
and not just “one keyboard button = one gamepad button”, as it happens in simple ready-made emulators. You can configure as you like, and this can be of interest.
Conclusion
Who needs all this? I don’t know, I’m just writing about how I conceived something and successfully fulfilled my plan. Suddenly someone would find such a solution useful?
A few words about the resulting emulator. The full sources of raw, non-configurable, but the working product can be seen here , in them, as it seems to me, there is nothing that should be written separately and in detail. Moreover, this thing is not very effective from the point of view of performance, I am sure that it can be done much more literally if you sit with it longer. However, on that momentous evening my hands were scratching my hands too much to try out the creation, so as soon as the compiler spat out the exe file, all thoughts about modifications instantly disappeared somewhere.
It is also worth noting that in order to introduce FIFA to the new joystick, you need to cheat slightly with the buttonDataSetup.ini file in the FIFA user directory. I’m not sure that these details (also set independently in five to ten minutes) make sense here, but if someone is interested in this issue, I will cover it as well.
UPD New version of the feeder . Now it emulates the analog stick smoother, which positively affects the quality of perception by the game of feints. At the same time, the feeder is smart enough not to create a delay in reaction to sudden changes in the direction of movement. Who knows, suddenly someone will take advantage.