Reverse engineering and patching a DirectX game? - directx

Background
I am playing Imperishable Night, one of the Touhou series of games. The shoot button is 'z', moving slower is 'shift', and the arrow keys move. Unfortunately for me, using shift-z ghosts my right arrow key, so I can't move to the right while shooting. This ghosting happens in all applications, and switching keyboards fixes it.
Goal
I want to locate in the disassembled code the directx function that gets the keyboard input and compares it against the 'z' key, and change that key to 'a'. I'm considering this a fun project. Assuming the size of the scan codes are the same, this should be fairly simple. And because the executable is only 400k, maybe this will provide a unique opportunity for me to explore the dark side of the computing underworld (kidding).
Relevant experience
I have some experience with coding in assembly, but not in the disassembly of such. I have no experience with the DirectX apis.
Question
I need some guidance. I've found a listing of directx keyboard scan codes, and a program called PEExplorer that looks like it will do what I need.
Is there a means by which I can turn some of the assembly with C function calls so it's more easily read? I will need to locate where the game retrieves the currently pressed keys, compares those against a list, and it's that list I need to modify.
Any input would be greatly appreciated.

You might be interested in the Detours library from Microsoft Research, it allows you to hook function calls and alter their arguments. Doing that your code can change the scan codes of keys that don't ghost into the ones the game expects.

Related

Keyboard to analog

I have not found any resource that helps me in what I am trying to do. I want to make a simple program that, when running, will convert a key press to an analog input. For example, if I hold A with a game open, it will move my character slowly to the left. I don't need the analog to be dynamic, it can output at a constant amount. To add more clarity, this is so a friend without a controller can sneak in a Pokemon game on his emulator. I'd love it if someone had any ideas or could point me in the right direction. I'm familiar with programming, so I don't need much more than the method of how or where I can accomplish this. Thank you!
Do this,
you can make a program having key event listener, in that listener check whether w,
a,s,d is pressed if so then use API to press analog keys (like in java Robot API) and return true as a Response, run this program in the background.
I don't know this will worth doing but give it a try.

How to capture keystrokes?

I'd like to make a simple Erlang console game. I need to control my "car" in that game by key strokes - key up or W key. Is there any way to do that? I read that wx library has such capability but I'm looking for something simple and in my opinion wx library is overkill. I want to grab an event not the character from stdin.
EDIT:
Ok, I've choosen ncurses and cecho as a Erlang library for that.
I know only 2 way to do this: gs and wx.
gs is a bit simpler but the first line of the documentation is a warning telling that gs is not recommended for new application, use wx instead :o)
wx isn't so complex, but its documentation is really poor, and simply refers to wxWidget one. at least there are some demo (demo, sudoku, xrc...) that helps to start to build something. And once you succeed to have your first panels and sizers working, it is really simple to get the key stroke or mouse events an react on them. My main difficulty was in displaying graphical things fast and smooth enough even if at the end it is only a few lines of code (a few 10s).
finally, the erlang console is meant to evaluate erlang expression, so there is no chance that you can capture simple event and control the display in that environment (at a reasonable effort at least).
You can try study kernel's modules group and user_drv but they both has undocumented interface and can be subject of change in any future Erlang/OPT version. You can also made your own driver or NIF to handle termios settings and make your own implementation.
BTW I would definitely stick with wx.

DMX software to control lights with programmable interface

I find myself in the need of a software to control lights with a programmable interface. Basically what I want to do is to automatically control the lights using some criteria that I programmed inside a program. My program will then control the lights passing through the software I'm searching for, of course this would need a programmable interface to which I should pass the commands to control the lights.
I've been searching for a software like that in the last couple of days without success, what I found are only softwares with GUIs for users, but no specification whatsoever about programming the light behavior instead of manipulating it by hand.
There's some really good information & code samples (including a working class that I wrote) here: Lighting USB OpenDMX FTD2XX DMXking
Ultimately, you end up setting byte values (between 0 and 255[FF] (brightest) in a byte array.
It's fairly trivial to implement simple effects such as fades or chases.
If you haven't got that far yet (e.g. up to the code) you'll need to get ahold of a USB DMX controller.
There are a number of them out there, but the thread above has sample code for two different flavours.
I also wanted an environment where I could quickly write code that would create interesting effects for my DMX effect lights and lasers, and ended up creating it myself. I just announced the first public release of Afterglow, my free, open-source live-coding environment for light shows. You can find it at https://github.com/brunchboy/afterglow
I needed precise control of individual mutli-channel (RGBAW) DMX512 lights and wanted to write code in C++ for Windows. I adapted the C# example from Enttec's website for OpenUSB and released the code:
https://github.com/chloelle/DMX_CPP

Is there a programming language with semantics close to English?

Most languages allow to 'tweek' to certain extend parts of the syntax (C++,C#) and/or semantics that you will be using in your code (Katahdin, lua). But I have not heard of a language that can just completely define how your code will look like. So isn't there some language which already exists that has such capabilities to override all syntax & define semantics ?
Example of what I want to do is basically from the C# code below:
foreach(Fruit fruit in Fruits)
{
if(fruit is Apple)
{
fruit.Price = fruit.Price/2;
}
}
I want do be able to to write the above code in my perfect language like this:
Check if any fruits are Macintosh apples and discount the price by 50%.
The advantages that come to my mind looking from a coder's perspective in this "imaginary" language are:
It's very clear what is going on (self descriptive) - it's plain English after all even kid would understand my program
Hides all complexities which I have to write in C#. But why should I care to learn that
if statements, arithmetic operators etc since there are already implemented
The disadvantages that I see for a coder who will maintain this program are:
Maybe you would express this program differently from me so you may not get all the
information that I've expressed in my sentence
Programs can be quite verbose and hard to debug but if possible to even proximate this type of syntax above maybe more people would start programming right? That would be amazing I think. I can go to work and just write an essay to draw a square on a winform like this:
Create a form called MyGreetingForm. Draw a square with in the middle of
MyGreetingFormwith a side of 100 points. In the middle of the square write "Hello! Click here to continue" in Arial font.
In the above code the parser must basically guess that I want to use
the unnamed square from the previous sentence, it'd be hard to write such a smart parser I guess, yet it's so simple what I want to do.
If the user clicks on square in the middle of MyGreetingForm show MyMainForm.
In the above code 'basically' the compiler must: 1)generate an event handler 2) check if there is any square in the middle of the form and if there is - 3) hide the form and show another form
It looks very hard to do but it doesn't look impossible IMO to me at least approximate this (I can personally generate a parser to perform the 3 steps above np & it's basically the same that it has to do any way when you add even in c# a.MyEvent=+handler; so I don't see a problem here) so I'm thinking maybe somebody already did something like this ? Or is there some practical burden of complexity to create such a 'essay style' programming language which I can't see ? I mean what's the worse that can happen if the parser is not that good? - your program will crash so you have to re-word it:)
Check out:
The Osmosian Order
of Plain English Programmers
Code Example:
The background is a picture.
A button has a box and a name.
To clear the status:
Clear the status' string.
Show everything.
To create the background:
Draw the screen's box with the white color.
Loop.
Pick a spot anywhere in the screen's box.
Pick a color between the lightest gray color and the white color.
Dab the color on the spot.
If a counter is past 80000, break.
If the counter is evenly divisible by 1000, refresh the screen.
Repeat.
Extract the background given the screen's box. \or Create the background from the screen. Or something.
Some Interactive fiction designers use a language syntax extremely close to the English language. Here's some Inform 7 code, which you can play online:
The foyer is a room.
The apple is in the foyer. It is edible. The description is "This is a ripe,
green granny smith apple."
The apple core is a thing. The description is "This apple core all that is
left of that granny smith apple you just consumed."
After eating the apple:
now the apple core is in the player;
say "You gobble down the apple careful not to eat any of those cyanide-
laced seeds you heard about."
I tutored a course that used Inform 7. One of the tutors had the impression the assignment was to design, not write a game. So he marked the programs by reading them, without realising they were actual programs.
I don't think that this would be an easy task nor do I think it is going to make life easier for debugging
How would you deal with these issues?
spelling mistakes
different dialects in different parts of world
different dialects in the same part of the world
synonyms
which part of sentence do you parse first?
tear (rip) and tear (from eye) both words spellings are the same but mean two different things.
Bring back COBOL or can you remember "Walk West", "Examine Door", "Push Door", "Open Door", "Use key on door" :)
edit - how would you strongly type this?
I have written an extensible English-to-Python compiler called EngScript, which converts structured English into working Python code.
This is an example of EngScript code:
print{create a string from the file called "README.txt"}
print{save the string "Woohoo!" to a file called "ExampleText.txt"}
print{the first 3 letters of "EngScript"}
This is the output that was generated by the EngScript compiler:
print(pythonFunctions.stringFromTextFile("README.txt"))
print(pythonFunctions.writeStringToFile("ExampleText.txt", "Woohoo!"))
print("EngScript"[0:(3 - 1)+1])
LiveCode!
There are a few "natural language", high-level, English-like programming or scripting languages. Probably all of them were inspired by the oldest, COBOL. My personal favorite of these languages is LiveCode. LiveCode is a decendent of MetaCard, a Linux clone of Apple’s now defunct HyperCard that used an English-like scripting language called HyperTalk, which was inspired by SmallTalk, and in turn inspired JavaScript (as well as the entire World-Wide-Web). HyperTalk was the basis for another English-Like scripting language called AppleScript (and later AppleScriptObjC), which still comes with macOS to this very day. LiveCode uses a language called LiveCodeScript, or LCS which, like other HyperCard clones and that have existed over the years (SuperCard, Adobe’s Lingo/Flash ActionScript, Open Xion, Oracle’s Toolbook, etc.), is very similar to HyperTalk at it’s core, often referred to as an X-Talk language. LiveCode has several advantages; it’s very much still in production, it has a dual license (open source and commercial versions), the engine is cross-platform (Mac, Win, Linux, HTML5, iOS, Android, and a server version), and like HyperCard it is also a GUI toolkit and it is extensible. The LiveCode team is currently working on new a lower-level programming language called LiveCode Builder, or LCB. LCB is also an English-like, although LCB is a bit less readable than LCS, it has a goals of having capabilities on par with lower-level languages like C++, Objective C, etc., allowing for extending the LiveCode platform with code libraries and frameworks produced by other programming language libraries, and ultimately allowing for the LiveCode IDE to be written in it’s own language.
Try using the programming language called 'Google' - it has a natural English interface and your code fragment throws back all the answers you are suggesting. Interestingly just six minutes after you asked this question, this very page is #1 for the query:
Check if any fruits are Macintosh
apples and discount the price by 50%
Use the Google API and I think you have the basis of a natural English programming language.

Can I map Caps Lock to something useful for the Delphi IDE?

OK, so I know I can remap the Caps Lock key in Windows registry, but is there something useful I can map it to in the Delphi 2009 IDE? I was hoping for Code Completion (Ctrl-Space), is there a way to map the single Caps Lock key to a Ctrl-key combination?
Do yourself a favour and just download Autohotkey. This will allow you to remap the CapsLock key to absolutely any other key combination or action.
It can also do this on an application context sensitive basis (ie CapsLock automatically does different things based on the active window).
There is a useful section in the GNU Emacs FAQ For MS Windows. Emacs users like to map Caps Lock to the Ctrl key, and it should prove useful as a starting point to assigning other key combinations.
Edit: Following the trail led me to this (official) documentation page: Scan Code Mapper for Windows. Hopefully the information it contains is still relevant.
Can't you first map it some obscure non-modifier-key in the registry, then map that to the desired function in Delphi using the keyboard preferences thingy?
I personally tried the emacs-style: binding Caps Lock to the Ctrl key.
The upside is that a lot of very common actions (not just in emacs, but everywhere) can be performed with less hand moving. As just on example, deleting words backwards (which is done by Ctrl+backspace) got a whole lot easier, and it is a shortcut that works just about everywhere. For this alone, I'd map Caps Lock to the Ctrl key.
The downside here is the same as for any other non-standard modification (like Dvorak): it makes it much harder to user other people's computers. When you sit down there, you're going to definitely have a problem changing your typing instincts.
I ended up returning the Caps Lock to it usual job because I couldn't cope with not being able to type at other people's computers.

Resources