Actions

Key def.dat: Difference between revisions

From Populous Wiki

No edit summary
Line 4: Line 4:


== Introduction ==
== Introduction ==
Key def.dat is a file that you have to create by using the Populous key editor included in the game ([http://www.brandanlasley.com/releases/Thread/Popre/Best%20Patches/key_def.dat Key def download]). Once you save, the file is created and it is located in ./save/Key def.dat. Each key is stored in a hexadecimal address, the combination key is always 1 in front of it. So if 0x1 is pause 0x2 will be the combination key. The combination key is like shift + key but in the file format it reads key + shift.  
Key def.dat is a file that you have to create by using the Populous key editor included in the game ([http://www.brandanlasley.com/releases/Thread/Popre/Best%20Patches/key_def.dat Key def download]). Once you save, the file is created and it is located in ./save/Key def.dat. Each key is stored in a hexadecimal address, the combination key is always 1 in front of it. So if 1 is pause 2 will be the combination key. The combination key is like shift + key but in the file format it reads key + shift.  


Each key needs to be converted from hexadecimal to a integer. This can be done in programming by simply reading information from the address, else if you're using a hex editor (like HxD) you'll have to that by hand using a converter like [http://home.paulschou.net/tools/xlate/ Paulschou] (use the values from CHAR), once you got the number it should range from 1-105, if it exceeds that, you're reading the wrong location or you got your math wrong. In [[#In Programming]] you will be told how to convert the values from keycode (the integer number you just got) to ASCII using programming methods. If you want to change them by hand without programming, all the key definitions are on this list [http://www.penticoff.com/nb/kbds/ibm104kb.htm keycode list for US QWERTY], remember that you have to convert those numbers back to hex from the [http://home.paulschou.net/tools/xlate/ Paulschou]'s link, or by [[#In Programming|programming]].
Each key needs to be converted from hexadecimal to a integer. This can be done in programming by simply reading information from the address, else if you're using a hex editor (like HxD) you'll have to that by hand using a converter like [http://home.paulschou.net/tools/xlate/ Paulschou] (use the values from CHAR), once you got the number it should range from 1-105, if it exceeds that, you're reading the wrong location or you got your math wrong. In [[#In Programming]] you will be told how to convert the values from keycode (the integer number you just got) to ASCII using programming methods. If you want to change them by hand without programming, all the key definitions are on this list [http://www.penticoff.com/nb/kbds/ibm104kb.htm keycode list for US QWERTY], remember that you have to convert those numbers back to hex from the [http://home.paulschou.net/tools/xlate/ Paulschou]'s link, or by [[#In Programming|programming]].
Line 26: Line 26:


=== Toggle view key ===
=== Toggle view key ===
     0x23 = Key
     23 = Key
     0x24 = modifier key
     24 = modifier key


=== Encyclopaedia key ===
=== Encyclopaedia key ===
     0x38 = Key
     38 = Key
     0x39 = modifier key
     39 = modifier key




=== Set Map Marker 1 key ===
=== Set Map Marker 1 key ===
     0x35 = Key
     35 = Key
     0x36 = modifier key
     36 = modifier key




=== Set Map Marker 2 key ===
=== Set Map Marker 2 key ===
     0x68 = Key
     68 = Key
     0x69 = modifier key
     69 = modifier key




=== Set Map Marker 3 key ===
=== Set Map Marker 3 key ===
     0x83 = Key
     83 = Key
     0x84 = modifier key
     84 = modifier key




=== Set Map Marker 4 key ===
=== Set Map Marker 4 key ===
     0x88 = Key
     88 = Key
     0x99 = modifier key
     99 = modifier key




=== Goto Map Marker 1 ===
=== Goto Map Marker 1 ===
     0x113 = Key
     113 = Key
     0x114 = modifier key
     114 = modifier key




=== Goto Map Marker 2 ===
=== Goto Map Marker 2 ===
     0x128 = Key
     128 = Key
     0x129 = modifier key
     129 = modifier key




=== Goto Map Marker 3 ===
=== Goto Map Marker 3 ===
     0x143 = Key
     143 = Key
     0x144 = modifier key
     144 = modifier key




=== Goto Map Marker 4 ===
=== Goto Map Marker 4 ===
     0x158 = Key
     158 = Key
     0x159 = modifier key
     159 = modifier key




=== Zoom view in key ===
=== Zoom view in key ===
     0x173 = Key
     173 = Key
     0x174 = modifier key
     174 = modifier key




=== Zoom view out key ===
=== Zoom view out key ===
     0x188 = Key
     188 = Key
     0x189 = modifier key
     189 = modifier key




=== Quick Load key ===
=== Quick Load key ===
     0x203 = Key
     203 = Key
     0x204 = modifier key
     204 = modifier key




=== Quick Save key ===
=== Quick Save key ===
     0x218 = Key
     218 = Key
     0x219 = modifier key
     219 = modifier key




=== Zoom to shaman key ===
=== Zoom to shaman key ===
     0x233 = Key
     233 = Key
     0x234 = modifier key
     234 = modifier key




=== Chat message key ===
=== Chat message key ===
     0x248 = Key
     248 = Key
     0x249 = modifier key
     249 = modifier key




=== Command Tracking key ===
=== Command Tracking key ===
     0x263 = Key
     263 = Key
     0x264 = modifier key
     264 = modifier key
     * Had problems w/ this key
     * Had problems w/ this key




=== Release guarding people key ===
=== Release guarding people key ===
     0x278 = Key
     278 = Key
     0x279 = modifier key
     279 = modifier key




=== Toggle Level Stats  key ===
=== Toggle Level Stats  key ===
     0x293 = Key
     293 = Key
     0x294 = modifier key
     294 = modifier key




=== Rotate building key ===
=== Rotate building key ===
     0x308 = Key
     308 = Key
     0x309 = modifier key
     309 = modifier key




=== Assign people to group 1 key ===
=== Assign people to group 1 key ===
     0x323 = Key
     323 = Key
     0x324 = modifier key
     324 = modifier key




=== Assign people to group 2 key ===
=== Assign people to group 2 key ===
     0x338 = Key
     338 = Key
     0x339 = modifier key
     339 = modifier key




=== Assign people to group 3 key ===
=== Assign people to group 3 key ===
     0x353 = Key
     353 = Key
     0x354 = modifier key
     354 = modifier key




=== Assign people to group 4 key ===
=== Assign people to group 4 key ===
     0x368 = Key
     368 = Key
     0x369 = modifier key
     369 = modifier key




=== Assign people to group 5 key ===
=== Assign people to group 5 key ===
     0x383 = Key
     383 = Key
     0x384 = modifier key
     384 = modifier key




=== Assign people to group 6 key ===
=== Assign people to group 6 key ===
     0x398 = Key
     398 = Key
     0x399 = modifier key
     399 = modifier key




=== Select people in group 1 key ===
=== Select people in group 1 key ===
     0x413 = Key
     413 = Key
     0x414 = modifier key
     414 = modifier key




=== Select people in group 2 key ===
=== Select people in group 2 key ===
     0x428 = Key
     428 = Key
     0x429 = modifier key
     429 = modifier key




=== Select people in group 3 key ===
=== Select people in group 3 key ===
     0x443 = Key
     443 = Key
     0x444 = modifier key
     444 = modifier key


=== Select people in group 4 key ===
=== Select people in group 4 key ===
     0x458 = Key
     458 = Key
     0x459 = modifier key
     459 = modifier key


=== Select people in group 5 key ===
=== Select people in group 5 key ===
     0x473 = Key
     473 = Key
     0x474 = modifier key
     474 = modifier key




=== Select people in group 6 key ===
=== Select people in group 6 key ===
     0x488 = Key
     488 = Key
     0x489 = modifier key
     489 = modifier key




=== Zoom to people in group 1 key ===
=== Zoom to people in group 1 key ===
     0x503 = Key
     503 = Key
     0x504 = modifier key
     504 = modifier key




=== Zoom to people in group 2 key ===
=== Zoom to people in group 2 key ===
     0x518 = Key
     518 = Key
     0x519 = modifier key
     519 = modifier key




=== Zoom to people in group 3 key ===
=== Zoom to people in group 3 key ===
     0x533 = Key
     533 = Key
     0x534 = modifier key
     534 = modifier key




=== Zoom to people in group 4 key ===
=== Zoom to people in group 4 key ===
     0x548 = Key
     548 = Key
     0x549 = modifier key
     549 = modifier key




=== Zoom to people in group 5 key ===
=== Zoom to people in group 5 key ===
     0x563 = Key
     563 = Key
     0x564 = modifier key
     564 = modifier key




=== Zoom to people in group 6 key ===
=== Zoom to people in group 6 key ===
     0x578 = Key
     578 = Key
     0x579 = modifier key
     579 = modifier key




=== Zoom to Reincarnation site key ===
=== Zoom to Reincarnation site key ===
     0x593 = Key
     593 = Key
     0x594 = modifier key
     594 = modifier key




=== Toggle Local Selection key ===
=== Toggle Local Selection key ===
     0x608 = Key
     608 = Key
     0x609 = modifier key
     609 = modifier key




=== Reselect last selection key ===
=== Reselect last selection key ===
     0x623 = Key
     623 = Key
     0x624 = modifier key
     624 = modifier key




=== Reorient view key ===
=== Reorient view key ===
     0x638 = Key
     638 = Key
     0x639 = modifier key
     639 = modifier key




=== Display last dialog key ===
=== Display last dialog key ===
     0x653 = Key
     653 = Key
     0x654 = modifier key
     654 = modifier key




=== Toggle auto deselect key ===
=== Toggle auto deselect key ===
     0x668 = Key
     668 = Key
     0x669 = modifier key
     669 = modifier key




=== Call to arms key ===
=== Call to arms key ===
     0x683 = Key
     683 = Key
     0x684 = modifier key
     684 = modifier key




=== Scatter people key ===
=== Scatter people key ===
     0x698 = Key
     698 = Key
     0x699 = modifier key
     699 = modifier key


== In Programming ==
== In Programming ==

Revision as of 06:31, 26 November 2013

Change Populous default keys using programming or hex editor. The file was decoded on November 23rd 2013.

All the addresses are correct, but typos can and will exist. If there is a typo or wrong address let me know or correct it!

Introduction

Key def.dat is a file that you have to create by using the Populous key editor included in the game (Key def download). Once you save, the file is created and it is located in ./save/Key def.dat. Each key is stored in a hexadecimal address, the combination key is always 1 in front of it. So if 1 is pause 2 will be the combination key. The combination key is like shift + key but in the file format it reads key + shift.

Each key needs to be converted from hexadecimal to a integer. This can be done in programming by simply reading information from the address, else if you're using a hex editor (like HxD) you'll have to that by hand using a converter like Paulschou (use the values from CHAR), once you got the number it should range from 1-105, if it exceeds that, you're reading the wrong location or you got your math wrong. In #In Programming you will be told how to convert the values from keycode (the integer number you just got) to ASCII using programming methods. If you want to change them by hand without programming, all the key definitions are on this list keycode list for US QWERTY, remember that you have to convert those numbers back to hex from the Paulschou's link, or by programming.

This is not a complete decode of the file, however its most of the common key commands for Populous, if you find more, feel free to add them!

Combination keys

The combination keys use a different keycode format. I don't know if there is a pattern to this or if the game has custom keycodes for these.

Not all of these are tested.

    No modifier key = 0
    Shift = 1
    Shift + CTRL (or App button?) = 3
    CTRL = 4
    Shift + ALT = 5
    Ctrl + alt = 6
    Shift + ctrl + alt = 7
    Alt = 20

Available keys

Toggle view key

    23 = Key
    24 = modifier key

Encyclopaedia key

    38 = Key
    39 = modifier key


Set Map Marker 1 key

    35 = Key
    36 = modifier key


Set Map Marker 2 key

    68 = Key
    69 = modifier key


Set Map Marker 3 key

    83 = Key
    84 = modifier key


Set Map Marker 4 key

    88 = Key
    99 = modifier key


Goto Map Marker 1

    113 = Key
    114 = modifier key


Goto Map Marker 2

    128 = Key
    129 = modifier key


Goto Map Marker 3

    143 = Key
    144 = modifier key


Goto Map Marker 4

    158 = Key
    159 = modifier key


Zoom view in key

    173 = Key
    174 = modifier key


Zoom view out key

    188 = Key
    189 = modifier key


Quick Load key

    203 = Key
    204 = modifier key


Quick Save key

    218 = Key
    219 = modifier key


Zoom to shaman key

    233 = Key
    234 = modifier key


Chat message key

    248 = Key
    249 = modifier key


Command Tracking key

    263 = Key
    264 = modifier key
    * Had problems w/ this key


Release guarding people key

    278 = Key
    279 = modifier key


Toggle Level Stats key

    293 = Key
    294 = modifier key


Rotate building key

    308 = Key
    309 = modifier key


Assign people to group 1 key

    323 = Key
    324 = modifier key


Assign people to group 2 key

    338 = Key
    339 = modifier key


Assign people to group 3 key

    353 = Key
    354 = modifier key


Assign people to group 4 key

    368 = Key
    369 = modifier key


Assign people to group 5 key

    383 = Key
    384 = modifier key


Assign people to group 6 key

    398 = Key
    399 = modifier key


Select people in group 1 key

    413 = Key
    414 = modifier key


Select people in group 2 key

    428 = Key
    429 = modifier key


Select people in group 3 key

    443 = Key
    444 = modifier key

Select people in group 4 key

    458 = Key
    459 = modifier key

Select people in group 5 key

    473 = Key
    474 = modifier key


Select people in group 6 key

    488 = Key
    489 = modifier key


Zoom to people in group 1 key

    503 = Key
    504 = modifier key


Zoom to people in group 2 key

    518 = Key
    519 = modifier key


Zoom to people in group 3 key

    533 = Key
    534 = modifier key


Zoom to people in group 4 key

    548 = Key
    549 = modifier key


Zoom to people in group 5 key

    563 = Key
    564 = modifier key


Zoom to people in group 6 key

    578 = Key
    579 = modifier key


Zoom to Reincarnation site key

    593 = Key
    594 = modifier key


Toggle Local Selection key

    608 = Key
    609 = modifier key


Reselect last selection key

    623 = Key
    624 = modifier key


Reorient view key

    638 = Key
    639 = modifier key


Display last dialog key

    653 = Key
    654 = modifier key


Toggle auto deselect key

    668 = Key
    669 = modifier key


Call to arms key

    683 = Key
    684 = modifier key


Scatter people key

    698 = Key
    699 = modifier key

In Programming

VB .NET

This is code that will decode all the unknown keys seen above to ACSII, table

Use a code converter to translate to C#.

' Brandan Tyler Lasley
' Populous TB Key Mapper
' Read Populous TB key configuration keycodes, then convert it to ASCII
Imports System.Runtime.InteropServices
Imports System.IO

Module Module1
    Public Declare Function GetKeyboardLayout Lib "user32" (ByVal idThread As UInteger) As IntPtr

    <DllImport("User32.dll")> _
    Public Function GetKeyboardLayout(idThread As Integer) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Public Function MapVirtualKeyEx(uCode As Integer, uMapType As Integer, dwhkl As Integer) As Integer
    End Function

    <DllImport("user32.dll")> _
    Private Function GetKeyboardState(ByVal keyState() As Byte) As Boolean
    End Function

    <DllImport("user32.dll")> _
    Public Function ToAsciiEx(uVirtKey As Integer, uScanCode As Integer, lpKeyState As Byte, lpChar As Integer, uFlags As Integer, dwhkl As Integer) As Integer
    End Function

    Dim strings = New String() {"Pause", _
                                "Toggle View", _
                                "Encyclopaedia", _
                                "Set map marker 1", _
                                "Set map marker 2", _
                                "Set map marker 3", _
                                "Set map marker 4", _
                                "Goto map marker 1", _
                                "Goto map marker 2", _
                                "Goto map marker 3", _
                                "Goto map marker 4", _
                                "Zoom in", _
                                "Zoom out", _
                                "Quick load", _
                                "Quick save", _
                                "Goto shaman", _
                                "Chat/Message", _
                                "Command tracking", _
                                "Release Guarding", _
                                "Toggle level stats", _
                                "Rotate building", _
                                "Assign units to group 1", _
                                "Assign units to group 2", _
                                "Assign units to group 3", _
                                "Assign units to group 4", _
                                "Assign units to group 5", _
                                "Assign units to group 6", _
                                "Select units to group 1", _
                                "Select units to group 2", _
                                "Select units to group 3", _
                                "Select units to group 4", _
                                "Select units to group 5", _
                                "Select units to group 6", _
                                "Goto units to group 1", _
                                "Goto units to group 2", _
                                "Goto units to group 3", _
                                "Goto units to group 4", _
                                "Goto units to group 5", _
                                "Goto units to group 6", _
                                "Goto reincarnation site", _
                                "Toggle local selection", _
                                "Reselect last selection", _
                                "Reorient view", _
                                "Display last dialog", _
                                "Toggle auto deselect", _
                                "Call to arms", _
                                "Scatter people"}

    Dim keys = New Integer() {8, 23, 38, 53, 68, 83, 98, 113, 128, 143, _
                          158, 173, 188, 203, 218, 233, 248, 263, 278, _
                          293, 308, 323, 338, 353, 368, 383, 398, 413, _
                          428, 443, 458, 473, 488, 503, 518, 533, 548, _
                          563, 578, 593, 608, 623, 638, 653, 668, 683, _
                          698}

    Dim populousin As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Bullfrog Productions Ltd\Populous: The Beginning", "InstallPath", "")

    Sub Main()

        Dim i = 0
        For Each Strs In strings

            Dim modifier = Reader(keys(i) + 1).ToString
            On Error Resume Next
            If modifier = 0 Then
                modifier = "NONE"
            ElseIf modifier = 2 Then
                modifier = "CTRL"
            ElseIf modifier = 3 Then
                modifier = "SHIFT + CTRL"
            ElseIf modifier = 5 Then
                modifier = "SHIFT + ALT"
            ElseIf modifier = 6 Then
                modifier = "CTRL + ALT"
            ElseIf modifier = 7 Then
                modifier = "SHIFT + CTRL + ALT"
            ElseIf modifier = 3 Then
                modifier = "APP"
            ElseIf modifier = 20 Then
                modifier = "ALT"
            ElseIf modifier = 1 Then
                modifier = "SHIFT"
            Else
                modifier = "NONE"
            End If
            Console.WriteLine(Strs & " = " & modifier & " + " & (scan2ascii(Reader(keys(i)))).ToString & vbNewLine)
            i = i + 1
        Next

        Console.ReadLine()
    End Sub

    Public Function scan2ascii(ByVal scancode)
        Dim hKL As IntPtr = GetKeyboardLayout(0)

        Dim State = New Byte(255) {}

        If GetKeyboardState(State) = False Then
            Return 0
        End If

        Return MapVirtualKeyEx(scancode, 1, hKL)
    End Function

    Function Reader(ByVal position As Integer)
        Dim Keysconfig As Boolean = My.Computer.FileSystem.FileExists(populousin & "\SAVE\key_def.dat")

        If Keysconfig = False Then
            Console.Write("Error: Populous keys configuration file could not be loaded, download it off the wiki and place it into ./saves/ file of pop.")
            Console.ReadLine()
            End
        End If

        Dim breader As New BinaryReader(New FileStream(populousin & "\SAVE\key_def.dat", FileMode.Open))
        breader.BaseStream.Position = position
        Dim output = breader.Read
        breader.Close()
        Return output
    End Function

End Module

C++

This is code that will decode all the unknown keys seen above to ACSII, table

This code does not automatically get PopTB's filepath.

// Brandan Tyler Lasley
// Populous TB Key Mapper
// Read Populous TB key configuration keycodes, then convert it to ASCII

#include <iostream>
#include <fstream>
#include <string>
#include <Windows.h>
using namespace std;

int scantoascii(int scancode);
int bReader(int position);
int bWriter(int value, int position);

string strings[50] =  {"Pause", 
			"Toggle View", 
			"Encyclopaedia", 
			"Set map marker 1", 
			"Set map marker 2", 
			"Set map marker 3", 
			"Set map marker 4", 
			"Goto map marker 1", 
			"Goto map marker 2", 
			"Goto map marker 3", 
			"Goto map marker 4", 
			"Zoom in", 
			"Zoom out", 
			"Quick load", 
			"Quick save", 
			"Goto shaman", 
			"Chat/Message", 
			"Command tracking", 
			"Release Guarding", 
			"Toggle level stats", 
			"Rotate building", 
			"Assign units to group 1", 
			"Assign units to group 2", 
			"Assign units to group 3", 
			"Assign units to group 4", 
			"Assign units to group 5", 
			"Assign units to group 6", 
			"Select units to group 1", 
			"Select units to group 2", 
			"Select units to group 3", 
			"Select units to group 4", 
			"Select units to group 5", 
			"Select units to group 6", 
			"Goto units to group 1", 
			"Goto units to group 2", 
			"Goto units to group 3", 
			"Goto units to group 4", 
			"Goto units to group 5", 
			"Goto units to group 6", 
			"Goto reincarnation site", 
			"Toggle local selection", 
			"Reselect last selection", 
			"Reorient view", 
			"Display last dialog", 
			"Toggle auto deselect", 
			"Call to arms", 
			"Scatter people"};


    int keys[50] = {8, 23, 38, 53, 68, 83, 98, 113, 128, 143, 
                   158, 173, 188, 203, 218, 233, 248, 263, 278, 
                   293, 308, 323, 338, 353, 368, 383, 398, 413, 
                   428, 443, 458, 473, 488, 503, 518, 533, 548, 
                   563, 578, 593, 608, 623, 638, 653, 668, 683, 
                   698};

int main() { 
	bReader(8);

	for (int i = 0; i < sizeof strings/sizeof(string) - 3; i++) {
	int modifiercode = bReader(keys[i] + 1);
	string modifier;

	switch (modifiercode) {
		case 0:
			modifier = "None";
			break;
		case 1:
			modifier = "Shift";
			break;
		case 2:
			modifier = "CTRL";
			break;
		case 3:
			modifier = "SHIFT + CTRL";
			break;
		case 5:
			modifier = "SHIFT + ALT";
			break;
		case 6:
			modifier = "CTRL + ALT";
			break;
		case 7:
			modifier = "SHIFT + CTRL + ALT";
			break;
		case 20:
			modifier = "ALT";
			break;
		default:
		modifier = "Unknown";
	}

	 cout << strings[i] << " = " << modifier << " + " << scantoascii(bReader(keys[i])) << endl;
	}


	getchar();
	getchar();
    return 0; 
}

int scantoascii(int scancode) {
	static HKL layout=GetKeyboardLayout(0);
    static byte State[256];

	 if (GetKeyboardState(State)==FALSE) {
      return 0;
	 }
   UINT vk=MapVirtualKeyEx(scancode,1,layout);
   return vk;
}

int bReader(int position) {
	unsigned char x;
	int i = 0;
	std::ifstream input("C:\\Program Files (x86)\\Bullfrog\\Populous\\SAVE\\key_def.dat", std::ios::binary);
	input >> std::noskipws;
	while (input >> x) {
		if (i == position) {
			return x;
		}
		i++;
	}
	return 0;
}