What is LoadAcceleratorA?

Reverse engineering and decompiling LEGO Island's main game binary (LEGO1.DLL)
Post Reply
TylerJaacks
Posts: 1
Joined: Sun Jun 11, 2023 6:48 am

What is LoadAcceleratorA?

Post by TylerJaacks »

So while reading the source from the decompile, I found this line

Code: Select all

  // Load accelerator (don't know what this does)  LoadAcceleratorsA(hInstance, "AppAccel");
. I decided to do some research and found that this is the function for loading Accelerator Tables in Windows found here https://learn.microsoft.com/en-us/windo ... eleratorsa. So what exactly is a Accelerator Table? Well according to the Windows API documentation found here https://learn.microsoft.com/en-us/windo ... tor-tables are a way of defining application shortcuts associated with your application this system is supposed to make easier to implement this functionality. For example:

Imagine we had the following shortcuts associated with the following commands:

Shortcut Command
CTRL+M Toggle between modes.
F1 Switch to draw mode.
F2 Switch to selection mode.

We would write the following code to define a Accelerator Table like this

Code: Select all

#define IDR_ACCEL1                        101
#define ID_TOGGLE_MODE               40002
#define ID_DRAW_MODE                  40003
#define ID_SELECT_MODE                40004
Where IDR_ACCEL1 is our Accelerator Table and its id (these are completely arbitrary), and ID_TOGGLE_MODE, ID_DRAW_MODE, and ID_SELECT_MODE are commands that we wish to implement shortcuts for.

We would then define the Accelerator Table like the following

Code: Select all

#include "resource.h"

IDR_ACCEL1 ACCELERATORS
{
    0x4D,   ID_TOGGLE_MODE, VIRTKEY, CONTROL    // ctrl-M
    0x70,   ID_DRAW_MODE, VIRTKEY               // F1
    0x71,   ID_SELECT_MODE, VIRTKEY             // F2
}
Here the first values on each row (0x4D, 0x70, and 0x71) represent the key codes for the shortcut. Next we put the Id of the command,
and then we add VIRTUALKEY ("The keyword VIRTKEY means the first entry is a virtual-key code. The other option is to use ASCII characters.")
and finally we can add modifiers for our shortcut.

Finally we can load this accelerator like the following.

Code: Select all

HACCEL hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCEL1));
The signature for this function is the following.

Code: Select all

HACCEL LoadAcceleratorsA(
  [in, optional] HINSTANCE hInstance,
  [in]           LPCSTR    lpTableName
);
There is more documentation on the page to discuss how to use these Accelerators. I would recommend reading the page as I may have made some mistakes and the Windows documentation is pretty good.
User avatar
MattKC
Site Admin
Posts: 323
Joined: Mon Aug 22, 2022 1:05 am
Contact:

Re: What is LoadAcceleratorA?

Post by MattKC »

Oh yeah, since writing that, I figured out what this did. I just forgot to remove the comment.

I actually confirmed that this call achieves absolutely nothing. There is no "AppAccel" resource in ISLE.EXE in any version, and LoadAccelerator even returns NULL indicating failure. I was initially going to mention this in the video, but it felt like one of those "too nerdy" details to mention, so I cut it. I'll probably make a bonus video for Patreon mentioning the stuff that I cut from the public video.

Thanks for going to the effort of collecting this info though!
Post Reply