Przejdź do treści

Windows Utilities

This part of Ikarus implements some WinAPI functions that can be used directly from Gothic scripts.

Initialization

The best way to initialize all Ikarus functions is to call MEM_InitAll() in the Init_Global() initialization function.

Warning

If you want to use Ikarus in Gothic 1, it is best to define your own Init_Global() function and call it from every world initialization function.

MEM_InitAll();

Implementation

Ikarus.d on GitHub

Functions

LoadLibrary

Loads the specified module into the address space of the calling process. Full documentation here.

func int LoadLibrary(var string lpFileName)
Parameters
  • var string lpFileName
    Name of loaded module

Return value

The function returns a handle to the module.

GetProcAddress

Retrieves the address from the specified dynamic-link library. Full documentation here.

func int GetProcAddress(var int hModule, var string lpProcName)
Parameters
  • var int hModule
    A handle to the DLL module that contains the function or variable. Can be obtained using the LoadLibrary function.
  • var string lpProcName
    The function or variable name.

Return value The function returns address of the function or variable.

FindKernelDllFunction

Uses GetProcAddress to find function inside the KERNEL32.DLL file.

func int FindKernelDllFunction(var string name)
Parameters
  • var string name
    Name of the looked function.

Return value

The function returns address of the function.

VirtualProtect

Changes the protection on a region of committed pages in the virtual address space of the calling process. Full documentation here.

func int VirtualProtect(var int lpAddress, var int dwSize, var int flNewProtect)
Parameters
  • var int lpAddress
    The address of the starting page of the region of pages whose access protection attributes are to be changed.
  • var int dwSize
    The size of the region whose access protection attributes are to be changed, in bytes.
  • var int flNewProtect
    The memory protection option. All options can be found here.

Return value

The function returns lpflOldProtectPtr - a pointer to a variable that receives the previous access protection value.

Author's comment:

I made lpflOldProtectPtr the return value and ignored the return Value of VirtualProtect.

MemoryProtectionOverride

Alias to VirtualProtect but with predefined PAGE_EXECUTE_READWRITE protection option

func void MemoryProtectionOverride(var int address, var int size)
Parameters
  • var int address
    The address of the starting page of the region of pages whose access protection attributes are to be changed.
  • var int size
    The size of the region whose access protection attributes are to be changed, in bytes.

MEM_MessageBox

Calls the WinAPI MessageBox function.

func int MEM_MessageBox(var string txt, var string caption, var int type)
Parameters
  • var string txt
    Content of the MessageBox.
  • var string caption
    Header of MessageBox.
  • var int type
    Type of MessageBox. All types listed here.

MEM_InfoBox

Alias to MEM_MessageBox with "Information:" header and MB_OK | MB_ICONINFORMATION type.

func void MEM_InfoBox(var string txt)
Parameters
  • var string txt
    Content of the InfoBox.

Examples

Sleep

Following function calls the Sleep function from the KERNEL32.DLL. A documentation of this function can be found here.

1
2
3
4
5
6
7
func void Sleep(var int ms) {
    var int adr;
    adr = GetProcAddress(LoadLibrary("KERNEL32.DLL"), "Sleep");

    CALL_IntParam(ms);
    CALL__stdcall(adr); // 0x007B47E6
};