Maidens of the Kaleidoscope

~Hakurei Shrine~ => Help Me, Eirin! => Topic started by: Drake on December 13, 2013, 03:07:27 AM

Title: Touhou Input Display (thinput) - Release v2.1.0
Post by: Drake on December 13, 2013, 03:07:27 AM
(http://i.imgur.com/xJ7qLvV.png)

Download: https://mega.nz/#!5sNFHYAT!KFsHGu8ZQnZNiPEvCT_yG4JvlqTxOwb9OdEbrel9kgQ

A tiny tiny clever tool that reads the memory of Touhou games and gives a display of the game's inputs.
Auto-detects the running game based on its executable name.
Because it reads the game's memory, you can display the inputs of replays as well. It also isn't dependent on a specific key mapping or button config, or what input device you use at all. How fancy.

Currently supported games range from th06 to th165.


Instructions:
- Launch Touhou game, run thinput.


Configuration:
[Window]
- KeyUpImg: Path to the image used for the keys not pushed. Relative to the working directory.
- KeyDownImg: Path to the image used for the keys pushed down. Relative to the working directory.
- BGColor: Color value for the background. Just use hex color values (e.g. FFFFFF).

[Buttons]
- key = left, top, width, height
- left and top are x,y coordinates of where to position the key image; width and height specify the key image size (which can be resized). Window expands to fit.
- You can change these positions if you want a different button layout.
- To "remove" a button from view, just put it at some negative coordinates.

[AddressList]
- Each line lists a game's executable name, the address of its input bit vector, and the map of buttons to the corresponding bit flags.
- You can add or remove as many entries as you want, just make sure it works.
- Valid addresses start with 0x followed by 6~8 hex digits.
- The button map is 8 numbers, each one corresponding to a button. In order they represent Shot, Bomb, Slow, Up, Down, Left, Right, Skip.
    The number represents which bit flag in the vector that button activates. Look at the config file for examples.
- Using this config allows us to add new executable names (e.g. th11boss.exe) and to offer forward-compatibility for new games.


Known Bugs:
- None at the moment!



This was originally a small personal project for displaying my keyboard input that turned into something else.
Title: Re: Touhou Input Display (thinput)
Post by: monhan on December 13, 2013, 03:30:49 AM
Wow, thanks, Drake! This should help knowing what the hell happened during lucky dodges.
Title: Re: Touhou Input Display (thinput)
Post by: cactu on December 13, 2013, 08:16:38 AM
Thanks. Is it supposed to work in full screen or not?
Title: Re: Touhou Input Display (thinput)
Post by: Drake on December 13, 2013, 08:59:55 AM
Not really, unfortunately. It seems exceedingly difficult and arcane to render other windows on top of fullscreen d3d applications, so I'm not going to bother wasting my time trying.
Title: Re: Touhou Input Display (thinput)
Post by: chum on December 13, 2013, 09:02:28 AM
It doesn't start for me (assuming It's because I'm on XP)

Title: Re: Touhou Input Display (thinput)
Post by: Drake on December 13, 2013, 09:14:00 AM
Doesn't start as in doesn't even give you an error? Can any other XP users replicate this? EDIT: never mind replicated ok
Title: Re: Touhou Input Display (thinput)
Post by: chum on December 13, 2013, 09:18:17 AM
(http://i.imgur.com/fhRcUiU.jpg)
Title: Re: Touhou Input Display (thinput)
Post by: Drake on December 13, 2013, 09:47:03 AM
Oooops my bad. I compiled it as an x64 application instead. New link, should work.
Title: Re: Touhou Input Display (thinput)
Post by: chum on December 13, 2013, 11:22:21 AM
Thank you, it works and I love it!
Title: Re: Touhou Input Display (thinput)
Post by: ark on December 13, 2013, 11:27:52 AM
You should make it do a D3D hook thing so it works fullscreen.
Title: Re: Touhou Input Display (thinput)
Post by: chirpy13 on December 13, 2013, 01:12:07 PM
I like this.  And the potential applications of it.
You should make it do a D3D hook thing so it works fullscreen.
Too myon and myon.
Title: Re: Touhou Input Display (thinput)
Post by: Kaze_Senshi on December 14, 2013, 09:55:03 PM
Wow colored tetrominos, nice job.

You should make it do a D3D hook thing so it works fullscreen.
yeap yeap
Title: Re: Touhou Input Display (thinput)
Post by: Drake on December 14, 2013, 11:12:21 PM
Well you can replace the images and move them around so you really just have 8 of whatever button graphic.
Title: Re: Touhou Input Display (thinput)
Post by: ExPorygon on December 17, 2013, 06:51:50 AM
Well this seems interesting. Might as well try it out.
Title: Re: Touhou Input Display (thinput)
Post by: Pesco on December 18, 2013, 08:35:20 PM
Could it work out a player's APM and possibly identify cheating?
Title: Re: Touhou Input Display (thinput)
Post by: Ghaleon on December 18, 2013, 10:50:30 PM
I dont mean to sound jerkish or anything but why would someone want this? I mean you know the guy is pushing up if they're flying up? Im clearly missing something. Regardless thanks for continuing to work on these things!
Title: Re: Touhou Input Display (thinput)
Post by: Raekuul on December 18, 2013, 11:12:30 PM
It could also be used to detect frame-perfect play.

I'm guessing PCB uses a different method of handling input?
Title: Re: Touhou Input Display (thinput)
Post by: Drake on December 19, 2013, 01:53:20 AM
guys i didn't make this to detect cheating, even though it can incidentally help when identifying cheating
Could it work out a player's APM and possibly identify cheating?
Yes, but APM by itself isn't always an accurate indicator. I tap quickly and dance fairly sporadically while I play, and if you look at just how fast and randomly the buttons pop up you might watch me and think my weird play is cheating. I know for sure that it can help, but that adding a thing to track APM, or looking at quick inputs themselves, isn't necessarily a good measure, and I don't really want to encourage witchhunts.

I dont mean to sound jerkish or anything but why would someone want this? I mean you know the guy is pushing up if they're flying up? Im clearly missing something. Regardless thanks for continuing to work on these things!
I made it mainly so I could stream with it visible in the window. It was first supposed to just read keyboard input. I don't really have a solid application intended for it, but if you find that it's useful for whatever reason then that's good enough. Personally I would like to see streamers use it, I find watching player input adds to the experience.

I'm guessing PCB uses a different method of handling input?
PCB uses a convoluted system of storing velocities and doesn't seem to actually store the state of button inputs besides having like 1 2 3 4 mean up/down/left/right the frame after input (how the other buttons happen is mysterious). It's possible to add, isn't something I care enough to do. The rest of the games all use a similar structure that makes it really easy to read without having to adjust much for different inputs for each game. EoSD and PCB would require a lot more work I'm not really willing to put in without a good reason.
Title: Re: Touhou Input Display (thinput)
Post by: SIRookie on December 19, 2013, 06:13:47 AM
I was actually about to start looking for something like this. There are some replays I wanted to rewatch for key movements
Title: Re: Touhou Input Display (thinput)
Post by: Space Flower on December 22, 2013, 04:17:30 AM
This is actually very awesome. I can turn a lucky dodge into something reusable.
Title: Re: Touhou Input Display (thinput)
Post by: rsy_type1 on February 23, 2015, 12:07:00 PM
sorry for the necropost.
but we have found ways to support other games:
add this to thniput.ini [addresslist]


抢曽峠杺嫿.exe, 0x69D904  <=== for Japanese version  , 东方红魔郷.exe, 0x69D770 for Chinese verision.
th07.exe, 0x4B9E50 
th095.exe, 0x4BE244
th125.exe, 0x4D8FB8
alcostg.exe, 0x471620
---------------------------------

there are some bugs for DS, may be ZUN's fault.
th143.exe, 0x4E1BE8
[Buttons]
Shot = 25, 0
Bomb = 50, 0
Slow = 125, 0
Skip = 0, 25
Up = 125, 25
Left = 150, 25
Down = 100, 25
Right = 0, 0
------------------------
Title: Re: Touhou Input Display (thinput)
Post by: Drake on February 24, 2015, 02:53:57 AM
Thanks a bunch, actually! Finding working addresses for th06/07 is very useful since I wasn't able to find them myself. I did originally exclude the photo games because of the buggy buttons, but I really shouldn't have since you can always swap around the button graphics or just ignore the bugs. I'll update the first post.
Title: Re: Touhou Input Display (thinput)
Post by: rsy_type1 on February 25, 2015, 01:25:15 AM
for th125,use cheatengine to see 0x4D8DA0

press  z, x, shift, ctrl, up, down, left, right , they have different output values.
but in thinput , different keys have the same react.
maybe there are some bugs in this program.
Title: Re: Touhou Input Display (thinput)
Post by: Drake on February 25, 2015, 06:31:59 AM
No, it's more a matter of ZUN not being consistent in how he maps the buttons to the bit flags in the vector. In particular, before th11 it goes (shot, bomb, slow, [empty], up, down, left, right, skip, [empty]). Meanwhile in th11 and on, the 4-bit is reserved and the 8-bit is slow instead (and skip goes from the 256-bit to the 512-bit), so in the program I check both 4 and 8 for slow, and both 256 and 512 for skip. But in th125, he shifts the up button and onward right one bit, so the up button gets read as slow instead (the other mismatches follow similarly).

Code: [Select]
th06 ~ th10 (except th095):
    (shot, bomb, slow, [empty], up, down, left, right, skip, [empty])
th11 ~ th143 (except th125):
    (shot, bomb, [reserved], slow, up, down, left, right, [empty], skip)
th095:
    (bomb*, shot, slow*, [empty], up, down, left, right, skip, [empty])  *bomb and slow have the same behaviour, so bomb -> 1 and slow -> 4+1
th125:
    (shot, bomb, slow, up, down, left, right, skip, [empty], [empty])  <- why zun

The forward-compatibility of this relies on the input being consistent, basically. Since th095 and th125 aren't consistent, it doesn't work as intended. Does this clear things up?
Title: Re: Touhou Input Display (thinput) ver. th15
Post by: grayst on April 14, 2017, 04:13:05 PM
what does empty button mean? https://cdn.discordapp.com/attachments/189420985471074305/302476130936553474/112.jpeg
Title: Re: Touhou Input Display (thinput) ver. th15
Post by: Drake on April 15, 2017, 04:26:15 AM
Uh, I don't know. That shouldn't happen. Can you make sure the button isn't set to some weird negative position in the config? Because that's how you would hide the buttons. PoFV should work fine from my testing.
Title: Re: Touhou Input Display (thinput) ver. th15
Post by: grayst on April 15, 2017, 06:58:30 AM
i didn't change anything in files. and you misunderstood, i think. it's not permanent. It just looks like that on some frames. I was hoping that it has something to do with the problem that i encountered (was pointed at) in POFV http://www.youtube.com/watch?v=JwYGoJxomCc (http://www.youtube.com/watch?v=JwYGoJxomCc)
Title: Re: Touhou Input Display (thinput) ver. th15
Post by: Drake on April 15, 2017, 08:40:57 AM
Ok, that gave me the hint I needed. So the "actual" problem is that I'm dumb and didn't load the images in the correct way, so it seems to loads the image from disk every time it is needed rather than storing it in memory. You can confirm this by starting thinput, pushing a button, editing the image, then pushing a button again. Generally this will not cause any visible issues because it should be fast enough anyways, but if your framerate counter there is an actual representation of how slow your game runs, your computer might actually be bad enough that it can't load the images properly. I can't really say for sure though.
Title: Re: Touhou Input Display (thinput) ver. th15
Post by: grayst on April 15, 2017, 01:29:34 PM
ok
Title: Re: Touhou Input Display (thinput) ver. th16
Post by: Enko on May 02, 2018, 11:03:14 AM
Sorry for my reply,
is there a way to change the size of the buttons?
e.g. Slow Button shows not so long as it should be on the keyboard.
Title: Re: Touhou Input Display (thinput) - Release v2.0.0
Post by: Drake on May 03, 2018, 11:32:00 PM
An actual new version (2.0.0) has dropped! Download in the first post.

I've switched how the input bit vector read to an all-manual configuration so they are specified entirely by the config for each game. This simplifies the difference between pre-11 and post-11 input, and resolves the mapping issues with 9.5 and 12.5 (as described in an earlier post).

I've also allowed for manual configuration of individual button sizes, so they aren't all necessarily the size of the button image. Check below for an example.

Additionally, I stopped images from being reloaded from disk on each keypress (as also described in an earlier post), and I removed the ReadProcessMemory message on game close, so the program just silently quits when you close the game. Neither of these were significant but they were annoying me.

Basically, usage is exactly the same. You can continue using the previous version as it works just fine, but there's also no real reason not to use the new version.

Sorry for my reply,
is there a way to change the size of the buttons?
e.g. Slow Button shows not so long as it should be on the keyboard.
With this new version, something like
Code: [Select]
[Buttons]
Shot = 49, 0, 24, 24
Bomb = 74, 0, 24, 24
Slow = 0, 0, 48, 24
Skip = 0, 25, 30, 24
Up = 150, 0, 24, 24
Left = 125, 25, 24, 24
Down = 150, 25, 24, 24
Right = 175, 25, 24, 24
might better approximate real key size. Play with it as you will.
Title: Re: Touhou Input Display (thinput) - Release v2.0.0
Post by: 32th System on May 11, 2018, 05:07:03 PM
Will you release the source code for this? Or have you already?
Title: Re: Touhou Input Display (thinput) - Release v2.0.0
Post by: Drake on May 11, 2018, 05:26:23 PM
The honest answer is that the program is a hacky compiled AHK script so I'm a bit embarrassed by it and the source might not be as useful as one would expect. Like I say in the OP it expanded out from a much simpler personal project which is the only reason it stayed as AHK, but I'm sweeping that under the rug. If I were to remake it with something like C#, which I should, I don't have any problem with it being open-source.
Title: Re: Touhou Input Display (thinput) - Release v2.0.0
Post by: shockdude on May 12, 2018, 11:04:06 PM
The honest answer is that the program is a hacky compiled AHK script so I'm a bit embarrassed by it and the source might not be as useful as one would expect. Like I say in the OP it expanded out from a much simpler personal project which is the only reason it stayed as AHK, but I'm sweeping that under the rug. If I were to remake it with something like C#, which I should, I don't have any problem with it being open-source.
AHK is a great framework though. I have a custom volume OSD that's written in AHK, as well as AHK scripts to enable borderless fullscreen and to force-hide the mouse cursor.
I think it'd be cool to release the AHK source (with maybe some cleanup if it's really that embarrassing) before rewriting it in a different language/framework.
Title: Re: Touhou Input Display (thinput) - Release v2.1.0
Post by: Drake on August 12, 2018, 04:22:00 AM
Added 16.5 support. Updated link in the first post.

You could also simply add the relevant address to thinput.ini:
Code: [Select]
th165.exe,  0x4B1308, 01345679