Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heretic and Hexen: check for valid, existing characters in font drawing functions #1201

Merged
merged 5 commits into from
Apr 24, 2024

Conversation

JNechaevsky
Copy link
Collaborator

This should fix possible crashes in cases like:

  • Using lowercased designation (am/pm instead of AM/PM) in savegame time. This was fixed by not drawing lowercase characters.
  • Lowecased text can be used for both big and small fonts, probably good for compatibility with mods.
  • Unknown characters (not existing in font graphics) are still replaced with spaces.

@JNechaevsky
Copy link
Collaborator Author

@fabiangreffrath, how about this approach? There is definitely some potential for readability improvement, like using macros instead of bare ACSII indexes (const int's probably won't be happy about [\\]^_'{|}~ charaters) and comments improvement. But in general, is it acceptable and should I proceed?

// allow [ (91, cursor) only in small fonts.
return 32;
}
else if (ascii_index >= 97 && ascii_index <= 122)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use char literals instead of magic numbers, i.e. 'a' instead of 97 and 'z' instead of 122.

else if (ascii_index >= 97 && ascii_index <= 122)
{
// Force lowercase "a...z" characters to uppercase "A...Z".
return ascii_index -= 32;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return ascii_index + 'A' - 'a';

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, look much better now! Both corrections are done, but I'd like to polish everything more. This is complicated right now - too much distractions on day job. 🥵 Hexen should be straight forwards well, it have just extra small gold font, it's pretty much same to white one.

@@ -224,7 +224,7 @@ static Menu_t MainMenu = {
};

static MenuItem_t EpisodeItems[] = {
{ITT_EFUNC, "CITY OF THE DAMNED", SCEpisode, 1, MENU_NONE},
{ITT_EFUNC, "a small [\\]^_`{|}~ text z" /*"CITY OF THE DAMNED"*/, SCEpisode, 1, MENU_NONE},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this before merging. 😉

Co-Authored-By: Fabian Greffrath <fabian@greffrath.com>

static const char MN_CheckValidChar (char ascii_index, int have_cursor)
{
if ((ascii_index >= '[' + have_cursor && ascii_index <= '`') || ascii_index >= '{')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Could you write > 'Z' and < 'a' and > 'z' here? This would make it clearer why these restrictions are there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do. My idea of using >= was to point to exact chararacter, not to next one. Another thing is - we also have a F_TextWrite font drawing function on finale screen, better I double check it too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also have a F_TextWrite font drawing function on finale screen

Well, I think we are fine with this one, since it have toupper() correction, and the texts are in lowercase format right in source code. Characters check is still possible here, but not sure it's really needed - I'm sure that mod authors will never especially use non existing characters for finale texts.

Copy link
Owner

@fabiangreffrath fabiangreffrath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@JNechaevsky
Copy link
Collaborator Author

Just a moment, just a moment, there is still Hexen to take care.

@JNechaevsky
Copy link
Collaborator Author

Allright, it's all done! Hexen is using MN_DrTextA() for automap strings drawing, that is now safe for CaSe SeNsItivItY. Intermission and finale texts are using toupper() correction and all such texts are in lowercase right in Hexen.wad (CLUS1-3MSG and WIN1-3MSG lumps). In-game ACS prints are obliviously MN_DrTextA() and MN_DrTextAYellow()'s.

Thank you very much for recommendations, it's much cleaner and readable now than my prototype I wrote in the morning, almost right after getting from bed. 😀

Ah yes, and of course, initial issue fixed and time is now appearing as it should for lowercase am/pm:

image

@JNechaevsky JNechaevsky marked this pull request as ready for review April 24, 2024 19:02
@JNechaevsky JNechaevsky merged commit 3a7e9fc into master Apr 24, 2024
5 checks passed
@JNechaevsky JNechaevsky deleted the rav_validchar branch April 24, 2024 19:03
JNechaevsky added a commit to JNechaevsky/international-doom that referenced this pull request Apr 24, 2024
…awing functions

See: fabiangreffrath/crispy-doom#1201
Co-Authored-By: Fabian Greffrath <fabian@greffrath.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants