Th128/Binary hacks

From Touhou Patch Center
Jump to: navigation, search

Bugs

Safe sprintf (call #1)
(sprintf_call_1)
Address
v1.00a0x46639f
Code
  1. 50
  2. e8 [strings_vsprintf]
  3. 8985 7cffffff
  4. 89bd 78ffffff
  1. push eax
  2. call [strings_vsprintf]
  3. mov dword ptr ss:[ebp-0x84],eax
  4. mov dword ptr ss:[ebp-0x88],edi
Safe sprintf (call #2)
(sprintf_call_2)
Address
v1.00a0x466234
Code
  1. 50
  2. e8 [strings_vsprintf]
  3. 8985 78ffffff
  1. push eax
  2. call [strings_vsprintf]
  3. mov dword ptr ss:[ebp-0x88],eax
Safe sprintf (call #3)
(sprintf_call_3)
Address
v1.00a0x4662cf
Code
  1. 50
  2. e8 [strings_vsprintf]
  3. 8985 74ffffff
  1. push eax
  2. call [strings_vsprintf]
  3. mov dword ptr ss:[ebp-0x8c],eax
Safe sprintf (replace pointer)
(sprintf_rep)
Address
v1.00a0x466272, 0x466342, 0x46640f
Code
  1. 8b
  1. mov ebx, dword ptr ss:[

Logging

Restore the game's built-in logging
(log_restore)
Description Very useful for debugging.
Address
v1.00a0x46c320
Code
  1. e9 [log_printf]
  1. jmp [log_printf]

Textbox size

Correct text length calculation for Fairy Wars-style text boxes
(fw_textbox_size)
Description This replaces the basic text box length calculation (string length * 8) with a call to GetTextExtent.

To apply these for later games, do an instruction search for:

  1. sub eax, edx
  2. lea ecx,[eax*8]
  3. and ecx,fffffff0
and don't forget to change the PUSH opcode to reflect the register with the string buffer address (EDI in this case).
Address
v1.00a0x423960, 0x423b20
Code
  1. ff35 bc2a4d00
  2. 57
  3. e8 [GetTextExtentForFont]
  4. 89c1
  5. 90 90 90
  1. push dword ptr ds:[th128.4d2abc]
  2. push edi
  3. call [GetTextExtentForFont]
  4. mov ecx,eax
  5. nop (*3)

Spells

Spell card alignment
(spell_align)
Description In this game, the fonts for dialog and spell cards have different sizes. For this reason, we would have to reset the font after the SelectObject setup - otherwise, dialog text width calculation would use the wrong font for the rest of the game. Thus, GetTextExtentForFont is used, which takes the font for the calculation as a parameter and does temporary font selection on its own.
Address
v1.00a0x466307
Code
  1. c1e9 04
  2. 83e1 01
  3. 51
  4. ff75 0c
  5. ff75 08
  6. ff35 cc2a4d00
  7. ff75 18
  8. e8 [GetTextExtentForFont]
  9. 50
  10. db04e4
  11. 58
  12. 90 90 90
  1. shr ecx, 4
  2. and ecx, 00000001
  3. push ecx
  4. push dword ptr ss:[ebp+0C]
  5. push dword ptr ss:[ebp+8]
  6. push dword ptr ds:[th128.004d2acc]
  7. push dword ptr ss:[ebp+18]
  8. call [GetTextExtentForFont]
  9. push eax
  10. fild dword ptr ss:[esp]
  11. pop eax
  12. nop (*3)

Player data

Remove spell "alignment" in the result screen
(result_spell_align)
Address
v1.00a0x466409
Code
  1. 31c0
  1. xor eax,eax