Skip to content

Commit

Permalink
BP_ruby_offset(): Set the game's string pointer to the second last co…
Browse files Browse the repository at this point in the history
…mma.

If any of the first two string parameters include one, the game would otherwise get the wrong string when doing its two strchr() calls and then render the wrong annotation text as a result.
  • Loading branch information
nmlgc committed Jan 24, 2014
1 parent e68f3bb commit 6f12955
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion thcrap_tsa/src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ static HDC text_dc = NULL;

/// Ruby
/// ----

char *strchr_backwards(char *str, char c)
{
while(*(--str) != c);
return str;
}
/**
* Calculates the X [offset] of a Ruby annotation centered over a section of
* text, when [font_dialog] is the font used for regular dialog text, and
Expand All @@ -39,10 +45,11 @@ int BP_ruby_offset(x86_reg_t *regs, json_t *bp_info)
{
// Parameters
// ----------
char *str = *(char**)json_object_get_register(bp_info, regs, "str");
char **str_reg = (char**)json_object_get_register(bp_info, regs, "str");
size_t *offset = json_object_get_register(bp_info, regs, "offset");
HFONT font_dialog = *(HFONT*)json_object_get_hex(bp_info, "font_dialog");
HFONT font_ruby = *(HFONT*)json_object_get_hex(bp_info, "font_ruby");
char *str = *str_reg;
// ----------
if(str && str[0] == '\t' && offset && font_dialog && font_ruby) {
char *str_offset = str + 1;
Expand All @@ -67,6 +74,11 @@ int BP_ruby_offset(x86_reg_t *regs, json_t *bp_info)
- (GetTextExtentForFont(str_ruby, font_ruby) / 2);
*str_offset_end = '\t';
*str_base_end = '\t';

// In case any of our parameters included a comma, adjust the original string
// pointer to point to the second comma before the annotation, so that the
// stupid game actually gets the right text after its two strchr() calls.
*str_reg = strchr_backwards(str_base_end, ',');
}
return 1;
}
Expand Down

0 comments on commit 6f12955

Please sign in to comment.