EusthEnoptEron / RaiLTools

MIT License
17 stars 10 forks source link

Old game font #4

Closed Gax24 closed 2 years ago

Gax24 commented 2 years ago

Hello! I want to translate this game: https://vndb.org/v601 into french language, but in this case, this Liar soft game doesn't have a font selector, could you give me a hand to resolve that?

EusthEnoptEron commented 2 years ago

I take it you want to replace the font with something that looks better for roman text?

There are actually two problems here:

  1. The font itself.
  2. The encoding of text. (The engine uses Shift-JIS and thus does not support special chars like the accent aigu)

Replacing the font

To replace the font, you have two options:

a.) Find and replace the font name using x32dbg or a similar tool. b.) Hook CreateFontA and use a different font.

Encoding of text

Again, two options:

a.) Define a mapping from Shift-JIS characters to ANSI characters and create a font accordingly. b.) Define a mapping from Shift-JIS characters to ANSI characters and hook GetGlyphOutlineA to replace characters at runtime.


Using some kind of hooking is arguably the cleaner / easier solution, but it'll take some digging either way. Someone actually had a similar problem in the past (seems the issue disappeared, though) and back then I threw together this example here:

HookExample.zip

Which makes something like this possible:

image

This is only a demonstration, though.

Gax24 commented 2 years ago

thank you very much, what is the name of the font you are using in that image? Also, another question, is there any way to change the size of it?

Cosetto commented 1 year ago

@EusthEnoptEron Do you have any example for shift-jis mapping?

EusthEnoptEron commented 1 year ago

@Cosetto

Here's the code I used to achieve the example above: HookExample.zip

In this example you need to drag & drop the game exe on HookExample.exe if I'm not mistaken.

Of course, if you want to go the hooking route, I would recommend doing it in a lower level language (C++ or maybe Rust) and using some form of DLL bootstrapping / proxying, so that you don't have to execute a separate exe.

The principle is simple:

  1. You replace one of the DLLs the game loads with your own.
  2. The game starts and loads its DLLs.
  3. Your DLL proxy gets loaded, injects your hooks, and loads the original DLL.
  4. Your hooks get executed.

Now that I think of it, you could probably write a DLL proxy for gdi32.dll and intercept the relevant calls directly.

Also: there may be more elegant ways out there. This is just a quick & dirty way to achieve the desired effect.

Cosetto commented 1 year ago

@Cosetto

Here's the code I used to achieve the example above: HookExample.zip

In this example you need to drag & drop the game exe on HookExample.exe if I'm not mistaken.

Of course, if you want to go the hooking route, I would recommend doing it in a lower level language (C++ or maybe Rust) and using some form of DLL bootstrapping / proxying, so that you don't have to execute a separate exe.

The principle is simple:

  1. You replace one of the DLLs the game loads with your own.
  2. The game starts and loads its DLLs.
  3. Your DLL proxy gets loaded, injects your hooks, and loads the original DLL.
  4. Your hooks get executed.

Now that I think of it, you could probably write a DLL proxy for gdi32.dll and intercept the relevant calls directly.

Also: there may be more elegant ways out there. This is just a quick & dirty way to achieve the desired effect.

Thank you. Also, I think I have an idea for non-sjis characters by using a crazy method: _ First, using SjisTunnelEncoding from vntextpatch, this will handle non-sjis characters and output sjisext.bin Next, using proxy and sjis_ext.bin to display the characters in the game.

This only work on shift-jis scripts though, and I'm using the utf8 .txt dump by your tool, switching between shift-jis and utf8 doesn't retain the tunnel characters (like in the picture). So, which part of the code of this tool should I change to dump/insert shift-jis only? image

EusthEnoptEron commented 1 year ago

Ah, nice. That's pretty much the approach I described, just with everything integrated.

So let me get this straight:

If that's the case, you might have to explicitly set the encoding to Shift-JIS in TransFile.cs like so, which would allow for translation files in Shift-JIS:

using (var reader = new StreamReader(stream, Encoding.GetEncoding("shift_jis")))

That, or you integrate the tunnel encoding stuff into ReplaceUmlauts. (That's a remnant of my own initial attempts at translating something to German.)

Or you integrate this library into VNTranslationTools. :P

Cosetto commented 1 year ago

Ah, nice. That's pretty much the approach I described, just with everything integrated.

So let me get this straight:

  • The output of step 1 is a binary file with the mappings and a .txt file in Shift-JIS with the Unicode chars replaced by tunnel chars?
  • When packing the translations with my library, the tunnel chars get garbled?

If that's the case, you might have to explicitly set the encoding to Shift-JIS in TransFile.cs like so, which would allow for translation files in Shift-JIS:

using (var reader = new StreamReader(stream, Encoding.GetEncoding("shift_jis")))

That, or you integrate the tunnel encoding stuff into ReplaceUmlauts. (That's a remnant of my own initial attempts at translating something to German.)

Or you integrate this library into VNTranslationTools. :P

Just like what you said, converting between utf8 and shift-jis will mess up the tunnel characters. I have already requested vntranslationtool's owner to add support for Liar soft but it seems like he won't do it any times soon. Anyway, thanks for the tip.

Cosetto commented 1 year ago

@EusthEnoptEron I know this is late to ask, but where can I config word-wrap count?

imKota commented 8 months ago

@EusthEnoptEron I know this is late to ask, but where can I config word-wrap count?

here https://github.com/EusthEnoptEron/RaiLTools/blob/cad296272c6f46596ba157eeca83da7180e4ea35/RailTools/TransFile.cs#L22