Toukiden: Kiwami

Toukiden: Kiwami

Not enough ratings
Mouse Emulation V2
By kei10 and 1 collaborators
Mouse emulation version 2, using FreePie, VJoy, X360CE, and Autohotkey!
Wew...wew...wew...
   
Award
Favorite
Favorited
Unfavorite
Introduction
... Greetings...

My friend was raving about not having mouse support about the game. So I decided to try and implement a little mouse emulation.

I did it in the first version which rebinds the keyboard to the mouse.
Here is the first version:

http://steamcommunity.com/sharedfiles/filedetails/?id=834876072
But it was very unstable, then my friend came up with another idea that sliiped my mind -- why don't I remap the mouse to the Xbox (Xinput) instead?

All kudos to him!

The scripts are programmed for efficiency. So far, the mouse emulation script algorithm is the best I could think of -- and very complicated, for many reasons. If you have any better approaches, please feel free to modify it, and/or share!

Additionally, if you're following the game, please disregard of what keyboard controls you are going to remap, since it only relies on the Controller buttons...

But be sure to set the Camera and Target Camera settings, which I will be explaining at the next sections...
Problems with vJoy
WARNING!

vJoy virtual controller device can interfere with games!
As the device itself may bug out and causes one of its buttons and/or joystick to be held down, and games that supports controller will detect it.

However, once you are not using the mouse emulation script for Toukiden Kiwami, open up Configure vJoy (vJoyConf.exe within the vJoy install directory), and untick "Enable vJoy", If enabled, the [1] tab will appear as green.

That will disable the virtual controller device, and games will not detect the virtual controller anymore.

WARNING! Make sure you've closed any application that has detected the virtual controller, or you won't able to disable it!

To use it, just tick again the "Enable vJoy".

Problems with the game
There are a few breahtroughs of the game that we have to concern about before then...
  • Controller Camera Sensitivity Thresholds
    • There is a sh*t problem with the in-game camera using the game controller. The camera sensitivity is split into multiple thresholds, there are; slow, medium, fast, and max depending on how much you push the joystick. This causes jittery camera movement with the mouse emulation v2...

      I have spent as much time as possible to make the camera as smooth as possible, but then the whole algorithm became a nightmare...

  • Windowed
    • Windowed mode of the game causes the framerate to drop in certain areas, especially in the villages and such. Thus we have to play the game in Full-Screen.

  • Full-Screen Alt+Tab
    • The next problem is that if we alt+tab out of the Full-Screen, now if you enter back into the game, any mouse clicks will cause the game to alt+tab back to the desktop.

      It's annoying and it just so happened that my friend gave me an idea of how to fix it; and that is by turning the game into Borderless while Full-Screen.

  • Steam Overlay
    • For some strange reason, Steam Overlay doesn't want to work. But with the help of turning the game into Borderless, it makes the Steam Overlay work -- it may not work sometimes, I have no idea why...

      However, just like first version of my mouse emulation, this does still cause some problem with the overlay. But it's less annoying.

  • Hard-coded controls
    • Many controls weren't rebindable in the game, they're probably hard-coded into the game, as I have no idea how to change them. This guide will begin with default control settings.

Warning! Do not alt+tab while the game is loading! It may freeze the game!
The required files
To begin, five (5) files are required.

  1. vJoy 2.1.6 (for FreePie 1.9.629)

  2. x360ce
    • http://www.x360ce.com/

    • This software is required to convert and feed the emulated joystick into XBox Controller (XInput).

  3. FreePie 1.9.629 (vJoy 2.1.6 support)

  4. FreePie Mouse Camera Script (python)

  5. Window Borderless Toggle
    • https://www.dropbox.com/s/54l9rteb7kn995p/Window_Borderless_Toggle.rar?dl=0

    • This is the folder that contains the Autohotkey files that responsible for toggling borderless mode for the game, so that it will not cause alt+tabbing problems. It contains files with the following extensions:
      1. .ahk
        • This is the Autohotkey source code for the borderless toggle.

      2. .exe
        • This is the compiled version of the borderless toggle. If you are feeling insecure of launching this, then you may go to https://autohotkey.com/download/ to get the software to launch and execute the .ahk source code instead.

      3. .ini
        • This is the main configuration file for the borderless toggle. It has a default setting that binds the hotkey for borderless toggle as Windows Key + B, and you can change it.

          For reference, please take a look at https://autohotkey.com/docs/KeyList.htm
Getting started
Here are the steps to make the mouse emulation work...

  1. Download the required files from the previous section...

  2. Install vJoy 2.1.6. (if it says driver install fails, that means that the driver might be no longer be signed... I hope it won't become like PPJoy, which I didn't bother with it as it is required to enter test mode to install it...)

  3. Install FreePie 1.9.629.

  4. Extract the x360ce.exe from the x360ce compressed file into your Toukiden Kiwami game directory (where the main executable is located). The XInput dll is required to be loaded by the game to work -- however, it does not exist yet, so...

  5. Launch the x360ce.exe. It should pop up an error saying...
    'xinput1_3.dll' was not found.
    This file is required for emulator to function properly.

    Do you want to create this file?
    Click Create, you baffoon (just kidding). Next it will load up and says...
    New device with unique instance id was detected. How do you want to search for settings?
    If this did not came up, please make sure that you've installed vJoy 2.1.6 correctly.
    Now, don't touch anything, just... click Next... It will search for best settings from the internet. Hopefully...

    Give it a wait, and once it is done, click Finish. If you do not wait, it will explode with a error. Actually I am not sure if search for best settings from the internet is preferred -- well, not matter...

  6. Now you can close x360ce.exe ... AND NEVER AGAIN TOUCH IT! BECAUSE... uh... I think there's no need to touch it ever again, in my opinion...

  7. Extract Window_Borderless_Toggle somewhere where you can easily launch it, it does not need to be in the game directory.

  8. Launch window_borderless_toggle.exe from Window_Borderless_Toggle directory.

  9. Launch FreePie.

  10. Load the FreePie Mouse Camera script into FreePie (freepie-mouse-to-vjoy.py) by the context menu > file > open and locate the script.

  11. Launch the game in full-screen mode -- do not alt+tab! Now, hold Windows Key + B to change the game into Borderless Mode. Now you should be safe to alt+tab.

  12. In FreePie window, run the script by context menu > script > run script, or press F5. To stop, hold Shift + F5, or stop it from the same context menu.

  13. Return to the game, load your save, enter a mission, and press Equals (=) key to toggle the mouse camera emulation!

  14. ???

  15. Profit!
Getting started (tl;dr)
Allowing Steam Overlay, Alt+Tabbing, and prevent Alt+Tab when mouse clicking

The keybinding toggle for autohotkey window_borderless_toggle.exe is Windows Key + B, press it in-game to toggle it as soon as you launched the game to make it borderless, so that alt+tab and mouse clicks will not interfere within each other.

Mouse camera emulation, and mouse buttons for attacks

The keybinding toggle for FreePie freepie-mouse-to-vjoy script is Equals (=) key, use it to toggle the mouse camera movement and mouse clicks LButton, RButton, and MButton which is binded to Attack1, Attack2, and Attack3 respectively.

Warning! When the mouse camera is enabled, your mouse will be kept centered to the screen for detection purposes. FreePie came with mouse.DeltaX and mouse.DeltaY, but I find them unreliable.
How it works and Configurations
*Takes a deep breath* ...

Within the FreePie mouse camera emulation script (freepie-mouse-to-vjoy.py), there are roughly twelve (12) variables that are responsible for making the whole sh*t work flawlessly -- okay I admit that it is probably not perfect.

BUT DAMNIT I HAD ENOUGH OF CALIBRATING THIS! LET'S MOVE ON... Shall we...? *Ahem* ... My apology for raising my voice, but here we go, I hope you can bear with me...

WARNING! Make sure all values are type float, FreePie uses Python 2.7.5, which means the division is *not* a true division, true multiplication, or something. There will be errors. However, the script has been programmed to ensure that the variables will not be accidentally assigned as anything else beside floating point values.

FreePie vJoy variables

  1. v = vJoy[0]
    • For simplification and performance purposes, the object vJoy[0] is assigned to a single-letter variable called v. The [0] stands for getting the first activated virtual device of vJoy, which is initialized after installation of vJoy 2.1.6.

  2. v.rx and v.ry
    • First and foremost, these two are the vJoy feed that are responsible for reponding the in-game camera.

  3. v.axisMax
    • vJoy came with something called axisMax, which defines how much the joystick can push to the maximum. The value is defaulted at 16,328, which means it has a range between -16,328 to 16,328, and 0 is the neutral value (center).

Terminology

  1. Mouse Delta, mc_mouse_delta...
    • This refers to the delta distance acquired from comparing the distance between the mouse position and the center of the screen. This is important to know which direction and how much your mouse has moved.

  2. Mouse Camera Delta, Camera Delta, just Delta, mc_delta...
    • This refers to the accumulation of delta values acquired from the Mouse Delta. Many variables and operations are performed together into the main mc_delta to make sure the camera is smooth and calibrated.

Configuration

  1. mc_framerate (default: 30.0 fps)
    • FreePie comes with a setting called system.threadExecutionInterval, which allows the user to define how fast the script will run in each interval in miliseconds. Since the game is capped at framerate of 30, the variable mc_framerate is meant the script to be in sync with the game framerate, for accuracy purposes. Changing this will affect the entire mouse camera emulation.

  2. mc_mouse_delta_start_threshold (default: x = 0.0, y = 0.0)
    • This is the main concern for Target Lock fix. As you can see, a slight movement to the mouse will cause the Target Lock to lock onto the next target. This variable is the starting threshold in pixels used to prevent that. The default is zero, set it to 16.0 (my personal setting) if you use Target Lock.

  3. mc_sensitivity (default: x = 32.0, y = 32.0)
    • This is the base multiplier for the Mouse Delta to be added to the Camera Delta. This is working alongside with mc_sensitivity2.

  4. mc_delta_damping (range: 0.0 <= k <= 1.0, default: x = 0.1, y = 0.1)
    • This is the base damping for the Camera Delta to be slowed down to a stop. This is working alongside with mc_delta_damping2.

  5. mc_delta_max (default: x = v.axisMax * 2.0, y = v.axisMax * 2.0)
    • This is the maximum Camera Delta that can reach. Since the v.axisMax is the max, we can define this variable above the v.axisMax to allow the camera to move longer for mouse camera acceleration.

  6. mc_delta_initial (default: x = v.axisMax * 0.75, y = v.axisMax * 0.75)
    • The camera does not move until the v.rx or v.ry is above or below v.axisMax * 0.36 or -v.axisMax * 0.36, without an initial value, the camera will not move and extremely annoying no matter how hard to fling your mouse across the room through the window all the way to the white house...

  7. mc_delta_stop_threshold (default: x = v.axisMax * 0.5, y = v.axisMax * 0.5)
    • Since the sh*t in-game camera doesn't response beneath v.axisMax * 0.37, a threshold is used to stop the Camera Delta early, this variable is very important to make sure the mouse camera doesn't go too smooth, or too strict -- beside the damping.

  8. mc_delta_damping_origin (range: mc_delta_stop_threshold < k < v.axisMax ,default: y = v.axisMax * 0.49, y = v.axisMax * 0.49)
    • This is the Delta Camera value that it will attempt to dampen towards. This is used to smoothen the damping and prevent jittery camera when the mouse camera is moving at slow.

  9. mc_delta_sensitivity_sigmoid_constant (range: -1.0 < k < 1.0, default: x = -0.5, y = -0.5)
    • As the in-game camera has some sh*t implementation for its camera movement using the controller joystick, I have to go through this effort to add curve-based sensitivity output to enhance the calibration.

      The constant is for the formula used is by Dino Dini's Tunable Sigmoid:
      # Sigmoid Tunable def sigmoid_tunable(k, x): return (x - x * k) / (k - abs(x) * 2.0 * k + 1.0)
      The default value is graphed as follows:

      The high output at the beginning is to prevent jittery camera movement when it moves at slow. Then it slows down to normalize the sensitivity output.

  10. mc_sensitivity2 (default: x = 32.0, y = 32.0)
    • This is the secondary multiplier which is fed into the sigmoid of mc_delta_sensitivity_sigmoid_constant to produce a curved sensitivity for the Camera Delta. As mentioned, this works alongside with mc_sensitivity2.

  11. mc_delta_damping_sigmoid_constant (range: -1.0 < k < 1.0, default: x = 0.5, y = 0.5)
    • Once again, due to the sh*t implementation of the in-game camera, I have to add a sigmoid-based damping for the Camera Delta as well.

      The default value is graphed as follows:

      The low output at the beginning is, again, to stop the god forsaken jittery camera when it moves at slow. Then it increases up to normalize the damping.

  12. mc_delta_damping2 (range: 0.0 <= k <= 1.0, default: x = 0.2, y = 0.2)
    • This is the secondary damping which is fed into the sigmoid of mc_delta_damping_sigmoid_constant to produce a curved damping for the Camera Delta. As mentioned, this works alongside with mc_delta_damping.

These aren't necessarily the best settings, if anyone have found a better settings or perhaps a better script as a replacement, please do kindly share! :D


Target Lock fix
This deserves a section.

This script is same as my first version, it has problem with Target Lock. A nudge of your mouse will switch its locked target to another.

To fix that, I've added a variable called mc_mouse_delta_start_threshold, which is default at (x = 0.0, y = 0.0).

If you use Target Lock, set it to (x = 16.0, y = 16.0), this is my personal value that I find comfortable.

For example:
# Mouse Delta Start Threshold mc_mouse_delta_start_threshold = PointF(16.0, 16.0)
In-Game Keybindings and Settings
You may set your controls to as you like. However, since the Dive/Dodge is nowhere near your WASD control settings, you may find it unable to perform certain actions combining with your mouse clicks, which is mapped to the attacks.

Here are my personal controls for the game that I find comfortable:
  • Dodge/Dive as Space
  • Communion/Purification/Run as Left Shift
  • Turn Target Locking On as Left Control
  • Eye of Truth as G
Set both Camera Rotation Speed to higest.

However, Targeting Rotation Camera Speed is the manual aiming, you can set this to whatever you desire.

Desktop Mouse Settings

My desktop mouse speed slider is set to max, with acceleration turned on when I created the mouse emulation script.
Credits
Thanks to these softwares that existed:
  • FreePie 1.9.629
  • Autohotkey
  • VJoy 2.1.6
  • x360ce
  • Python
Thanks to Dino Dini's Tunable Sigmoid function!

And thanks to my friend for testing the script!

Thank you for reading!
11 Comments
kei10  [author] Oct 18, 2018 @ 9:31am 
Well yes, freepie is capable of emulating both ways, Still, Toukiden already works with Joystick, why would you want to emulate Joystick with mouse? Unless you're intended to use it somewhere else outside the game, then that's up to you to program it, perhaps you can find samples around on the internet.

On the other hand, no, I don't have a gyroscope joystick or whatever that is. So I'm sorry, I cannot help you other than what the guide has already been explicably attempted to explain with my best effort.

I've never encountered crash so I don't know how to reproduce that and fix anything without the problem at hand.

Thanks.
Jepa.CaptPrice  [author] Oct 11, 2018 @ 7:49pm 
Uhh LOL you'd have to ask kei about that, he did all of the work in this one. I just helped out with testing it xD
anand Oct 11, 2018 @ 2:31pm 
I see. Anyways it's very cool i was looking for something like this. I made a sort of giroscope joystick that i intended to work a mouse. After a while i realized why there's people who dedicate their lives to invent stuff like that. The movement was quite jiggery because i was using only a mouse.move(1, 1) command. So i was looking for a script like yours that could turn my stuttery gyroscopic mouse into a proper joystick. Is it possible remove those jumpy snaps that are meant for Toukiden: Kiwami and have the more classic joystick movement ? Or at least make it move the camera slower? Once it snaps, it move the camera very quickly even at the least sensitivity. I'll specifiy that i'd like to use this for other games than Toukiden: Kiwami.
Jepa.CaptPrice  [author] Oct 10, 2018 @ 11:21pm 
:O Not sure about dat
anand Oct 10, 2018 @ 9:25am 
Hi, very nice, could this go the other way? To use a joystick to move the cursor?
Raynerd May 30, 2018 @ 11:39am 
Worked on the first try but after it crashed, it all went down into the ground. Had to set the compatibility mode to Windows 7 so that it wouldn't crash anymore but all it did so far was to stop your fix in its tracks.
kei10  [author] Mar 24, 2017 @ 1:19am 
The guide for Toukiden 2 has been created with tweaks and changes.
http://steamcommunity.com/sharedfiles/filedetails/?id=889963575
kei10  [author] Mar 23, 2017 @ 5:03am 
Oh, yes, this isn't for Toukiden 2. My bad.
Lou Mar 23, 2017 @ 3:21am 
i followed all the instructions my game is in window borderless "ahk", installed x360ce in the folder, script is running in freepie ( since my mouse is like stuck in a tiny box) but once i alt-tab to the game my mouse is not working.

edited: im using it for toukiden 2. i just noticed that its not for toukiden 2 :/
Jepa.CaptPrice  [author] Mar 22, 2017 @ 10:51pm 
Hello :D Could you care to explain more about the problem , it could be that you forgot to run the script itself from FreePie with Script -> Run Script or by pressing F5