Jul 15, 2011 at 7:58 PM
Join Date: Jan 28, 2010
Location: Internet
Posts: 1369
Age: 35
Pronouns: he/him
LunarSoul said:No problem, always happy to help!
EDIT: Does anyone know how to run code when a key is pressed? I know there's a "key pressed" offset or something, and a table with the different keys, but are there certain things you need to do, like JMP to an offset (like JMPing to the beginning of the TSC parser after a command)? I want to add a gimmick to the "C" key. I think we're doing it for the deity project as well.
All you need to do is check if a key exists via ANDing (or even CMPing is technically possible for single-keypresses) on the offsets [49E210] and [49E214] at any point while the game is running.
In the Compendium, here's the keypressed table:
ANDing by the key_held or key_pressed offsets....:
0x000001 Left Arrow
0x000002 Right Arrow
0x000004 Up Arrow
0x000008 Down Arrow
0x000010 Show Mini-Map
0x000020 Shoot
0x000040 Jump
0x000080 Next Weapon
0x000100 Previous Weapon
0x000200 Shift
0x000400 F1
0x000800 F2
0x001000 Status/Menu Screen
0x008000 Escape
0x010000 "," Comma
0x020000 "." Period
0x040000 "?" Question Mark
0x080000 "L" The Letter L
0x100000 "=" Equal
And here are the offsets:
0049E210 Key_Held See Key Table.
0049E214 Key_Pressed See Key Table.
0049E218 LastKeyHeld
Now, I'm really too lazy to give a full explanation, so I'll give an example of a hack that lets you check for keypresses in TSC. I used this in my mod "The Witching Hour" to create a custom options menu for the player.
Basically, this command "gets" whether a keypress matches the the four-digit TSC number XXXX and jumps to event YYYY if true. Hopefully you'll be able to make sense of this:
Code:
=========== Carrotlord's <GET keypress hack ===========
[ How to use it ]
<GETXXXX:YYYY
If keypress X is held, then jump to TSC event Y. Otherwise, continue the code (much like <FLJ continues if flag is not set).
======= TSC Part
#0402 ;call TSC event 402 using a Horizontal trigger that you can jump through repeatedly.
<WAI0070<GET0008:0500
<GET0001:0501
<GET0002:0502
<GET0004:0503
<GET0016:0504
<GET0032:0505
<GET0064:0506
<KEY<MSGNo checked keys are held.<NOD<END
#0500
<KEY<MSGDown key is held.<NOD<CLO<EVE0402
#0501
<KEY<MSGLeft key is held.<NOD<CLO<EVE0402
#0502
<KEY<MSGRight key is held.<NOD<CLO<EVE0402
#0503
<KEY<MSGUp key is held.<NOD<CLO<EVE0402
#0504
<KEY<MSGMap key is held.<NOD<CLO<EVE0402
#0505
<KEY<MSGAttack key is held.<NOD<CLO<EVE0402
#0506
<KEY<MSGJump key is held.<NOD<CLO<EVE0402
========= The assembly part
CPU Disasm
Address Hex dump Command Comments
00424EAF \E9 C8590100 JMP 0043A87C ; JMP to <GET command
CPU Disasm
Address Hex dump Command Comments
0043A87C /> \A1 D85A4A00 MOV EAX,DWORD PTR DS:[4A5AD8]
0043A881 |. 0305 E05A4A00 ADD EAX,DWORD PTR DS:[4A5AE0] ;set up Scriptcheck
0043A887 |. 0FBE48 01 MOVSX ECX,BYTE PTR DS:[EAX+1] ;G
0043A88B |. 83F9 47 CMP ECX,47
0043A88E |.^ 0F85 9FA6FEFF JNE 00424F33
0043A894 |. 0FBE48 02 MOVSX ECX,BYTE PTR DS:[EAX+2] ;E
0043A898 |. 83F9 45 CMP ECX,45
0043A89B |.^ 0F85 92A6FEFF JNE 00424F33
0043A8A1 |. 0FBE48 03 MOVSX ECX,BYTE PTR DS:[EAX+3] ;T
0043A8A5 |. 83F9 54 CMP ECX,54
0043A8A8 |.^ 0F85 85A6FEFF JNE 00424F33 ;jump to <GIT command if unsuccessful
0043A8AE |. 8B15 E05A4A00 MOV EDX,DWORD PTR DS:[4A5AE0]
0043A8B4 |. 83C2 04 ADD EDX,4 ;otherwise, get the first parameter
0043A8B7 |. 52 PUSH EDX
0043A8B8 |. E8 4370FEFF CALL 00421900
0043A8BD |. 83C4 04 ADD ESP,4
0043A8C0 |. 3905 10E24900 CMP DWORD PTR DS:[49E210],EAX ;compar Param1 with KeyHeld.
0043A8C6 |. 74 0C JE SHORT 0043A8D4 ;if that key is Held, then goto A
0043A8C8 |. 8305 E05A4A00 ADD DWORD PTR DS:[4A5AE0],0D ;otherwise, fix the scriptPosition
0043A8CF |.^ E9 D3A9FEFF JMP 004252A7 ;jump back
0043A8D4 |> 8B15 E05A4A00 MOV EDX,DWORD PTR DS:[4A5AE0] ;LABEL A
0043A8DA |. 83C2 09 ADD EDX,9 ;get the second Parameter
0043A8DD |. 52 PUSH EDX
0043A8DE |. E8 1D70FEFF CALL 00421900
0043A8E3 |. 83C4 04 ADD ESP,4
0043A8E6 |. 50 PUSH EAX ;push the second parameter
0043A8E7 |. E8 0472FEFF CALL 00421AF0 ;jump to that TSC event.
0043A8EC |. 83C4 04 ADD ESP,4
0043A8EF \.^ E9 B3A9FEFF JMP 004252A7 ;exit. No script-fixing is needed.