News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Changing text alignment in a Windows applications.  (Read 1765 times)

MeshGearFox

  • Jr. Member
  • **
  • Posts: 28
    • View Profile
Changing text alignment in a Windows applications.
« on: August 07, 2016, 02:38:45 am »
I'm working on a translation project for a 32-bit Windows game that uses standard Windows GUI resources for... nearly everything. Anyway, I'm having a problem with text alignment in ListBox resources that automatically expand tab characters. Refer to the below screenshot:

https://dl.dropboxusercontent.com/u/22006397/Lunatic%20Dawn%20translation/infobrokergui.png

The name substring on the left and the 10000G substring are aligned on every row in the original Japanese, but when converted to English, the Iltal' name substring is short enough that it doesn't push the 10000G substring on its line over to the next tab position, I guess, so the text gets out of alignment.

Any suggestions on how to approach getting the text aligned properly? I can't find anything in Resource Hacker for setting tab positions, and it sounds like if you were, say, doing this in C# you'd pass a message to the control after it was already created (https://support.microsoft.com/en-us/kb/318601)

(For instance, could I find whatever code creates the ListBox resource and find something that pushes the default tabstop positions somewhere in the assembly? Could I swap the ListBox out for a different control that DOES give me more control over tab positions (The MSDN article mentions ListViews) and have the game load the text into that? etc.)

Thanks!
« Last Edit: August 27, 2016, 06:59:07 pm by MeshGearFox »

jonk

  • Sr. Member
  • ****
  • Posts: 273
    • View Profile
Re: Changing text alignment in a Windows ListBox control in a GUI resource.
« Reply #1 on: August 07, 2016, 02:51:19 am »
It's my recollection that you need to use Windows messages, SEND or POST, to achieve this in a listbox control. I think I remember doing it that way, when the .NET wrapper didn't have a mechanism for tabs for some project I was dinking around with. The .NET folks have been working really hard. But they haven't gotten all of the old Win32 API features rolled over into .NET properties and methods, yet. Would be nice if they got it all done, because Microsoft is really pushing people hard against using Win32 API. But then they leave things out, or make the performance a lot worse, in .NET and this pushes people back into using the API despite all their work and hopes. Look up LB_SETTABSTOPS.

EDIT: Ah, here's the page.
An equal right to an opinion isn't a right to an equal opinion. -- 1995, me
Saying religion is the source of morality is like saying a squirrel is the source of acorns.  -- 2002, me

MeshGearFox

  • Jr. Member
  • **
  • Posts: 28
    • View Profile
Re: Changing text alignment in a Windows ListBox control in a GUI resource.
« Reply #2 on: August 07, 2016, 03:26:09 am »
It's my recollection that you need to use Windows messages, SEND or POST, to achieve this in a listbox control. I think I remember doing it that way, when the .NET wrapper didn't have a mechanism for tabs for some project I was dinking around with. The .NET folks have been working really hard. But they haven't gotten all of the old Win32 API features rolled over into .NET properties and methods, yet. Would be nice if they got it all done, because Microsoft is really pushing people hard against using Win32 API. But then they leave things out, or make the performance a lot worse, in .NET and this pushes people back into using the API despite all their work and hopes. Look up LB_SETTABSTOPS.

EDIT: Ah, here's the page.

Thanks!

So I found some VB source code that looks like it does what you're talking about:

http://www.devx.com/vb2themax/Tip/18592

As I don't have access to the actual source code for the game I'm hacking, how might I go about dropping in code to send the LB_SETTABSTOPS message via a hex editor/disassembler/whatever?

--

Also, another question. Changing the font on a resource in Resource Hacker doesn't actually change the font on that resource. I'm suspecting that it's inheriting the font that it actually uses either from some parent control or from. Any idea how to change the fonts, in light of this?
« Last Edit: August 07, 2016, 10:47:49 am by MeshGearFox »

Klarth

  • Sr. Member
  • ****
  • Posts: 484
    • View Profile
Re: Changing text alignment in a Windows ListBox control in a GUI resource.
« Reply #3 on: August 07, 2016, 12:35:25 pm »
As I don't have access to the actual source code for the game I'm hacking, how might I go about dropping in code to send the LB_SETTABSTOPS message via a hex editor/disassembler/whatever?
In this case, you probably want to test the hack. I'm not aware of any program specifically designed for this, but you can make your own. I suggest downloading something like WinSpy++ that can view and edit some visual properties of user controls.

If this is a game that doesn't have security measures and you are relatively competent in C/C++, I would suggest creating a DLL project in Visual Studio with your code changes. You can then use DLL injection to get your code into the game's address space and modify the game to call those functions. Cheat Engine has some support for runtime assembly modification and DLL injection, but I'm not sure if you can apply modifications permanently.

Quote
Also, another question. Changing the font on a resource in Resource Hacker doesn't actually change the font on that resource. I'm suspecting that it's inheriting the font that it actually uses either from some parent control or from. Any idea how to change the fonts, in light of this?
Every control is rendered using a default font (ie. GetStockObject(DEFAULT_GUI_FONT); ) unless you explicitly SendMessage a WM_SETFONT message. You would need the font handle or to use CreateFont to obtain a handle to use WM_SETFONT.

MeshGearFox

  • Jr. Member
  • **
  • Posts: 28
    • View Profile
Re: Changing text alignment in a Windows ListBox control in a GUI resource.
« Reply #4 on: August 07, 2016, 11:32:54 pm »
In the screenshot, there's an apostrophe after the first substring. This is actually the kanji for country, rendering incorrectly.

Replacing this kanji with a pair of spaces fixed the tab issue. Not really sure WHY, since adding two spaces to the substring itself didn't.

So I... guess this resolved itself? Somehow?

In any case, the DLL injection advice was really useful and I'll definitely look into that approach if this starts happening again.

mrrichard999

  • Hero Member
  • *****
  • Posts: 686
  • So Goooood! :D
    • View Profile
    • GameFAQS Profile
Re: Changing text alignment in a Windows ListBox control in a GUI resource.
« Reply #5 on: August 10, 2016, 07:56:04 am »
Im also having the same problems with my game too :O

http://imgur.com/f3FHSnv

August 10, 2016, 08:03:52 am - (Auto Merged - Double Posts are not allowed before 7 days.)
I figured out something which may help, Where I had the last job for my Job Listing area, I went out the 7 character norm as the other jobs has limitations to which spaced out everything all weird. This same principle may apply to your country names. See how many letters max you can use for your towns above the last one you have in the code and try to work with that. It should fix the spacing.
« Last Edit: August 10, 2016, 01:26:07 pm by mrrichard999 »

MeshGearFox

  • Jr. Member
  • **
  • Posts: 28
    • View Profile
Re: Changing text alignment in a Windows ListBox control in a GUI resource.
« Reply #6 on: August 27, 2016, 06:58:45 pm »
In this case, you probably want to test the hack. I'm not aware of any program specifically designed for this, but you can make your own. I suggest downloading something like WinSpy++ that can view and edit some visual properties of user controls.

If this is a game that doesn't have security measures and you are relatively competent in C/C++, I would suggest creating a DLL project in Visual Studio with your code changes. You can then use DLL injection to get your code into the game's address space and modify the game to call those functions. Cheat Engine has some support for runtime assembly modification and DLL injection, but I'm not sure if you can apply modifications permanently.
Every control is rendered using a default font (ie. GetStockObject(DEFAULT_GUI_FONT); ) unless you explicitly SendMessage a WM_SETFONT message. You would need the font handle or to use CreateFont to obtain a handle to use WM_SETFONT.

I'm running into another problem, the solution to which I'm thinking may be along these lines.

The game renders text by first drawing some shadow text in gray, and then drawing the regular black text one pixel behind that. The problem is, sometimes the shadow text is JUST past the point where the text wraps, and the normal text isn't, so this happens:

https://dl.dropboxusercontent.com/u/22006397/Lunatic%20Dawn%20translation/broken%20text%20shadowing.png

I found the instructions adding one to the text start position for drawing the shadow text, and then removing one for drawing the regular text. What I want to do is have another pair of instructions that add one to, and then subtract one from, the length in pixels at which the text wraps (to account for the shadow text being offset by one pixel).

Problem is, I don't have any space to add these extra instructions.

I tried putting my new code (original add/sub instructions, plus the new ones for changing the max line length) in some unused space in the executable, but jumping to those locations and trying to run code there gives me a C0000005 ACCESS_VIOLATION exception (which is... pretty much what I expected).

How would I go about adding new code to the program in a manner such that it will actually run?

(For what it's worth, I could also just set the shadow text to NOT have a on pixel offset, in which case the text has no shadow and there are, naturally, no issues with the shadow wrapping when the normal text doesn't. And I might end up doing this anyway because the shadow causes some really gross kerning issues, even in the original Japanese.

This is more just me wanting to sate my curiosity :S).

Klarth

  • Sr. Member
  • ****
  • Posts: 484
    • View Profile
Re: Changing text alignment in a Windows ListBox control in a GUI resource.
« Reply #7 on: August 28, 2016, 11:17:47 am »
I tried putting my new code (original add/sub instructions, plus the new ones for changing the max line length) in some unused space in the executable, but jumping to those locations and trying to run code there gives me a C0000005 ACCESS_VIOLATION exception (which is... pretty much what I expected).

How would I go about adding new code to the program in a manner such that it will actually run?
I'm not sure about access_violation. Does the program crash at launch or only when your code is called? I would guess either bad code (dereferencing a pointer to an inaccessible memory location) or you put your code in the wrong spot of an exe. I'm not sure how tight the access controls are in Windows, but I would ensure your new code is put into the .text section of the Portable Executable. You should probably learn a bit more about the Portable Executable (PE) format and how Windows loads PE sections into memory, rebases offsets, etc.

MeshGearFox

  • Jr. Member
  • **
  • Posts: 28
    • View Profile
Re: Changing text alignment in a Windows applications.
« Reply #8 on: August 28, 2016, 08:34:39 pm »
Well, I feel dumb now.

I was sticking the new code in the header section.

Stuffing it in the blank space between the .text and .data section makes everything work perfectly.

Thanks for the help :S