Git Product home page Git Product logo

twinject's Introduction

twinject

Build status

This project is a work-in-progress.
If you have any questions, want to help, or are just having trouble getting 
something working, feel free to open a ticket or email me (my email address is on my GitHub profile). 

alt text?

What is this?

twinject (touhou windows injector) is an automated player for the bullet hell games from the Touhou Project. Instead of using computer vision techniques to extract data from the game, a DLL is injected and the relevant game data is directly extracted through trampolined functions. twinject's first goal is to expose game information and APIs to interact with the game.

For the unaware, bullet hells are a category of Shoot 'em Up video games where the player controls a ship, which must dodge large numbers of obstacles and destroy large numbers of enemies. In the demonstration videos, the fast moving projectiles are the obstacles which must be dodged - if the player hits any of these projectiles they die immediately. The player itself also fires projectiles, which damage enemies. Props to ZUN for making games that people still play 20 years later.

Documentation is currently incomplete/outdated, and is currently on my list of things to do. At the moment, I am prioritizing features and demonstrations.

So far, I plan to implement bindings for this bot for every mainline game. As of now, I have completed basic bindings for games listed in the table below. Some binding implementations or reverse engineering knowledge have been borrowed from other sources and are cited at the bottom. Thank you!

Demonstrations

As of now, I have implemented two player algorithms with varying degrees of success.

Constrained Velocity Obstacle Algorithm

The constrained velocity obstacle algorithm uses a linear velocity obstacle predictor based approach with an infinite horizon but constrained bounds, and picks the best possible move at the current instant in a greedy fashion.
Note that when these demonstrations were recorded, the bot was incapable of dodging lasers. Watch as it struggles to deathbomb through every laser it sees.

More demonstrations are available in the wiki.

Support

Bindings th07 th08 th10 th11 th15
Bullet Hook ✔️ ✔️ ✔️ ✔️ ✔️
Enemy Hook ✔️
Powerup Hook ✔️ ✔️
Laser Hook ✔️ ✔️
Stage Info Hook ✔️ ✔️ ✔️ ✔️ ✔️
Direct3D Hook ✔️ ✔️ ✔️ ✔️ ✔️
DirectInput Hook ✔️ ✔️ ✔️ ✔️* ✔️
Feature th07 th08 th10 th11 th15
Dodge Bullet ✔️ ✔️ ✔️ ✔️ ✔️
Dodge Enemy ✔️ ✔️
Dodge Laser ✔️ ✔️
Collect Powerups ✔️ ✔️
Target Enemies

... and some other undocumented features. Keep in mind that this table probably isn't kept up to date.

Building

The dependencies are included in the repository, and are referenced by relative path.

Build Instructions

1. git clone --recurse-submodules https://github.com/netdex/twinject.git
2. Build in Visual Studio 2017 with Release (x86) target.
The following components are required:
- VC++ 2017 version 15.8 v14.5 latest v141 tools (other verisons should be okay, you will need to retarget)
- Windows 10 SDK (10.0.17134.0) (other versions should be okay, you will need to retarget)
- Visual C++ ATL for x86 and x64 (technically this isn't required, but I used CString for convenience)

Place the following files into the game directory:
twinject.exe
twinhook.dll
twinject.toml (there is a sample included under twinhook/)

Obtain dx8->dx9 converter patch (included in releases in this repo as dxd8.dll and enbconvertor.ini),
and place into game directory if the game requires it.

If you don't want to build it, there are stable Releases in this repository. The tagged commits represent stable points, since sometimes I break the build and it doesn't work. If you want to test the latest features (since the Releases take effort to create, so I don't do them often), you can download the build artifacts from Appveyor. If you are having trouble getting it to build, feel free to open a ticket or contact me.

Usage

Refer to deploy/INSTRUCTIONS.TXT

You can click the IMGUI windows to control twinject as well.  
(note: key controls have been temporarily replaced with IMGUI while I sort stuff out.)

To close the bot, close the debug console window and the game will close after.
Closing the game first may cause cleanup to not occur.

If you are using the th_vo_algo (the default), make sure you only enable the bot after the stage loads and the player is able to move, 
since the th_vo_algo needs to calibrate the player by moving it around. You should see a log message after successful calibration.

Make sure DirectInput is not disabled, it is required for movement.

If you have any other problems, please read the troubleshooting section below. 
If you still have any other problems, feel free to contact me. 
You can either make an issue or email me (my email is on my GitHub profile).

Ethics

Replays

Note that this bot generates valid replays. Do not submit replays generated by this bot to replay aggregators such as royalflare, as they are prohibited. You may only submit to a tool-assisted category if they exist.

3rd Party

This code is licensed under the specified terms here.

Libraries and their licenses are documented under dependencies/.

Information regarding Touhou game internals to assist in reverse engineering have been used from the following sources:
TH10_DataReversing by binvec
thinput by Drake
Nice cheat.
Ethan Silver's Junkpile

Thank you.

twinject's People

Contributors

binvec avatar netdex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

twinject's Issues

Huge lag during lasers.

Drops FPS by huge percentages when a laser is present on the screen. This is on 1.2.108 on TH10.

Using `twinject` to tweak bullet and player movement speed?

Hello,

I have an idea in mind for a project. I'd like players to enjoy Touhou at higher refresh rates without changing the actual gameplay speed.

At the moment, increasing or decreasing the FPS in Touhou games also affects the speed of the simulation. So I thought: what is we increase the FPS to, say, 144, and then give the game's update loop a fake time delta that would keep the simulation speed similar to the original one?

For example, assume that the normal time delta in Touhou is 1 for 60FPS. If we raise the FPS to 144, I'd like the time delta to become 0.416 (60 / 144). The game engine currently doesn't do this, and the time delta is always 1 regardless of the FPS.

Do you think twinject could be used to detect and change these values? I'm an experienced C++ developer but I have almost no experience in reverse engineering.

Game Abstraction Project

Goal

Support as many games as possible. Currently, twinject is written to solely support th08. Some abstractions need to be made in order to support multiple games.

General Behaviour

The way the games have worked has changed a lot in the last 20 years. Thus, in order to make abstractions, we must use what is common between all the games.

  • Injection (Detours)
  • Graphical control for overlays (Direct3D)
  • Input control for player control (DirectInput)
  • Frame timing information (Direct3D)
  • Entity/relevant data (game-specific)

Abstractions Required

The following concepts must be abstracted:

  • Hooking Direct3D and DirectInput
  • Hooking frame end event and injecting tick code
  • Game specific entity processor (this is a difficult one)
  • Game specific code patches to correct unintended behaviour
  • Game specific player logic, to adapt to game mechanics (UFOs, time orbs etc.)
  • Game specific bot parameters (deathbomb threshold, safety threshold, aggressiveness)

Process Change

An overhaul needs to be made to the general flow of the bot's workings.

The following steps will describe the new process the bot will operate in per frame:

  1. Information Gathering - Update data table with gathered information regarding game state
  2. Processing - Use data table to calculate frame action
  3. Action - Execute frame action

Keys do not work; Z, X and C are all active in the GUI

Touhou 8 v1.00d
TWinJect v0.05 (Release)

None of the hotkeys activate on keyDown/keyPress.

Injection: OK
EXCEPTION_BREAKPOINT
DEBUG: DllMain injected
DEBUG: DllMain: Debugger attached
DEBUG: Detours: Hooked LoadLibraryA
DEBUG: Detours: Hooked sub_410A70
DEBUG: Detours: Hooked first stage sub_447A37
DEBUG: D3D9: Found Direct3DCreate9 at addr 1695102048
DEBUG: Detours: Hooked Direct3DCreate9
DEBUG: D3D9: Feeding fake IDirect3D9
DEBUG: Error 10 (object not found) in function enum EResult __thiscall SysAudioHook::CMMDeviceClient::EraseAudioClientInVector(struct IAudioClient *)

DEBUG: DI8Init: Hooking second stage DirectInputCreate
DEBUG: Detours: Hooked second stage DirectInput8Create
DEBUG: DI8Create: Feeding fake DirectInput

TH15 EXCEPTION_ACCESS_VIOLATION

Running twinject on Legacy of the Lunatic Kingdom causes the program as soon as you get into the game whether turning the bot on or off causes the game to completely freeze and twinject's cmd window to spam the error message EXCEPTION_ACCESS_VIOLATION.

Running unpatched v1.00a.

twinject.ini:

[twinject]
exename=th15.exe
dllname=twinhook.dll
env=th=th15

Does not work on Windows 7 due to XINPUT_1.4.DLL dependency

ImGui's example implementation that's used here causes a dependency on XINPUT_1.4.DLL. This version of xinput is not available on Windows 7 and earlier systems, which causes twinhook to error out due to the missing DLL if you're not on Windows 8 or later. An easy fix is making the example use an xinput version that's available on older systems:

imgui_impl_win32.cpp:150:

#pragma comment(lib, "xinput")

change to:

#pragma comment(lib, "xinput9_1_0")

Though, it's probably better to remove the dependency entirely, since I think it's only there because the ImGui example uses it, and twinhook does not actually require xinput at all.

AI is not working

twinject 1.2.104 release version
th08
windows 7
AI only press up and use deathbomb,not moving left,right or down.
It happened on my computer and my friend's.
(On my friend's computer,AI works well at lunatic mode,but on my computer the problem still exist.)
image
By the way,I have made an algorithm for TH10,it has reached lunatic no miss.
I'd like to apply it to th15.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.