CPP - AlsoGhostglowDev/Ghost-s-Utilities GitHub Wiki
a Utility dedicated to FFI related functions.
local cpp = require 'ghostutil.cpp'Authored by TBar.
cpp.SWP_NOMOVE = 0x0002
cpp.SWP_NOSIZE = 0x0001cpp.setWindowZPos. This tells the function not to move the window and to not resize the window respectively.
cpp.S_OK = 0x00000000cpp.setWindowColorMode to tell the function to run the backup color mode function if the first one fails.This is done due to Windows 10 using DWM window attribute 19, while Windows 11 uses attribute 20. This prevents running attribute 20 if 19 works.
cpp.DWMWA_COLOR_NONE = 0xFFFFFFFEcpp.setWindowBorderColor to remove the window border entirely.
cpp.DWMWA_COLOR_DEFAULT = 0xFFFFFFFFcpp.setWindowBorderColor to set the border color to the default settings set by system preferences.
cpp.windowColorMode = {
DARK = 1,
LIGHT = 0
}cpp.addressOf.
cpp.windowCornerType = {
DEFAULT = 0,
DONOTROUND = 1,
ROUND = 2,
ROUNDSMALL = 3
}cpp.setWindowCornerType to set the window corners to different modes.
--Message Formats
cpp.ABORTRETRYIGNORE = ffi.C.MB_ABORTRETRYIGNORE
cpp.CANCELTRYCONTINUE = ffi.C.MB_CANCELTRYCONTINUE
cpp.HELP = ffi.C.MB_HELP
cpp.OKCANCEL = ffi.C.MB_OKCANCEL
cpp.RETRYCANCEL = ffi.C.MB_RETRYCANCEL
cpp.YESNO = ffi.C.MB_YESNO
cpp.YESNOCANCEL = ffi.C.MB_YESNOCANCEL
cpp.OK = ffi.C.MB_OKcpp.makeMessageBox.
--Message Icons
cpp.INFORMATION = ffi.C.MB_ICONINFORMATION
cpp.QUESTION = ffi.C.MB_ICONQUESTION
cpp.WARNING = ffi.C.MB_ICONWARNING
cpp.ERROR = ffi.C.MB_ICONERRORcpp.makeMessageBox.
cpp.messageAnswer = {
ABORT = 3,
CANCEL = 2,
CONTINUE = 11,
IGNORE = 5,
OK = 1,
YES = 6,
NO = 7,
RETRY = 4,
TRYAGAIN = 10
}cpp.makeMessageBox.
cpp.activeWindow = ffi.C.GetActiveWindow()cpp.getActiveWindow.Unlike it's method counterpart, which gets the active window when it's called, this one gets the active window when this module is imported.
cpp.os = ffi.osWindows, Linux, OSX, BSD, POSIX, and Other.
cpp.arch = ffi.archx86, x64, arm, arm64, arm64be, ppc, mips, mipsel, mips64, mips64el, mips64r6, and mips64r6el.
makeMessageBox(title: string, message: string, ?msgForm: number, ?msgIcon: number): numberA more advanced version of the window.alert function. Allows for message icons, different message options, and returns the option that was clicked.
Parameters:
-
title: The message box's title. -
a: The message box's main text. -
msgForm(optional): What combination of message answers the message box will show. Refer to theMessage Formatslist for possible combinations. -
msgIcon(optional): The alert icon the message box will use. Refer to theMessage Iconslist for possible icons.
Returns: A number of the option clicked. Refer to the cpp.messageAnswer table for a list of possible answers.
View Example
-- Creates a message box with a "Yes" and "No" option and a question mark icon.
local foo = cpp.makeMessageBox("Title", "Are you awesome?", cpp.YESNO, cpp.QUESTION)
if foo == cpp.messageAnswer.YES then
debugPrint("You are awesome")
else
debugPrint("You are not awesome")
end─────────────────────────
setWindowZPos(zPos: string): voidLayers the active window's Z order on the moniter.
Parameters:
-
zPos: The Z order type to use.
(can betopmost,bottom,nottopmost, ortop)
View Example
-- The window will be layered over all windows, including the taskbar.
cpp.setWindowZPos("topmost")─────────────────────────
getActiveWindow(): hWndGets the current active window, usually the game window.
Returns: The window handle (hWnd).
View Example
-- Closes the active window
cpp.destroyWindow(cpp.getActiveWindow()) ─────────────────────────
findWindow(windowName: string): hWndFinds the specified window using it's window name.
Parameters:
-
windowName: The name of the window.
Returns: The window handle (hWnd).
View Example
-- Returns the window with the title "Friday Night Funkin': Psych Engine"
cpp.findWindow("Friday Night Funkin': Psych Engine") ─────────────────────────
isWindowEnabled(windowHWND: hWnd): booleanChecks whether the specified window is focused on/enabled.
Parameters:
-
windowHWND: The window handle.
Returns: If the specified window is enabled, returns true, otherwise false.
View Example
-- Returns true if the game window is focused on.
cpp.isWindowEnabled(cpp.activeWindow) ─────────────────────────
windowExists(windowHWND: hWnd): booleanChecks whether the specified window exists.
Parameters:
-
windowHWND: The window handle.
Returns: If the specified window exists, returns true, otherwise false.
View Example
-- Returns true if the window with the name "Task Manager" is currently opened.
local foo = cpp.findWindow("Task Manager")
cpp.windowExists(foo) ─────────────────────────
disableCrashHandler(): voidDisables that annoying "Report this issue to Microsoft" popup that appears whenever the game freezes.
─────────────────────────
destroyWindow(windowHWND: hWnd): booleanDestroys the specified window.
(This function respects windows that restrict destroy access, e.g. Task Manager)
Parameters:
-
windowHWND: The window handle.
Returns: If the specified window was sucessfully destroyed, returns true, otherwise false.
View Example
-- Closes the window with the name "My Window"
local myWin = cpp.findWindow("My Window")
local closedWin = cpp.destroyWindow(myWin)
if closedWin then
debugPrint("Window has been closed!")
else
debugPrint("Window wasn't closed")
end─────────────────────────
registerDPICompatible(): voidSimilar to Psych Engine 1.0.4, this registers the game as DPI compatible.
─────────────────────────
getMonitorCount(): numberGets the number of monitors hooked up to the computer.
Returns: The number of monitors connected to your PC.
View Example
local monitors = cpp.getMonitorCount()
if monitors > 1 then
debugPrint("You have more than one monitor")
elseif monitors <= 0 then
debugPrint("No monitors? How?!")
end─────────────────────────
setWindowLayered(): voidSets the window as layered, which is good for functions like setWindowAlpha and setWindowTransparency.
─────────────────────────
setWindowAlpha(alpha: number): voidSimilar to setting the alpha property of a sprite, this sets the alpha of the current active window.
Parameters:
-
alpha: The window's alpha, from 0 (transparent) to 1 (opaque).
View Example
cpp.setWindowLayered()
cpp.setWindowAlpha(math.random(0, 1))─────────────────────────
setWindowTransparency(win: hWnd, chroma: number): voidSets a color to be transparent on the window.
Parameters:
-
win(optional): The target window. If this isnil, then it uses the active window. -
chroma(optional): The color to set transparent, formatted as0x00RRGGBB. If this isnil, then it removes the effect.
View Example
cpp.setWindowLayered()
-- The color black will be replaced with transparent pixels
cpp.setWindowTransparency(cpp.activeWindow, 0x00000000)
-- Sets the window back to normal
cpp.setWindowTransparency(cpp.activeWindow, nil)─────────────────────────
setDarkMode(): voidSets the window header to dark mode.
(Shortcut to cpp.setWindowColorMode(true))
View Example
-- Sets the window to dark mode
cpp.setDarkMode()
cpp.redrawWindowHeader()─────────────────────────
setLightMode(): voidSets the window header to light mode.
(Shortcut to cpp.setWindowColorMode(false))
View Example
-- Sets the window to light mode
cpp.setLightMode()
cpp.redrawWindowHeader()─────────────────────────
setWindowColorMode(isDark: boolean): voidSets the window header to dark mode or light mode.
Parameters:
-
isDark: Sets the window to dark mode if true, otherwise it sets the window to light mode.
View Example
-- Sets the window to dark mode
cpp.setWindowColorMode(true)
cpp.redrawWindowHeader()
-- Sets the window to light mode
cpp.setWindowColorMode(false)
cpp.redrawWindowHeader()─────────────────────────
setWindowBorderColor(colorHex: string|number, setHeader: boolean, setBorder: boolean): voidSets the window header to the color specified.
(This function only has an effect on Windows 11)
Parameters:
-
colorHex: The color specified. Allowed formats are'#RRGGBB','0xRRGGBB','RRGGBB', or0xRRGGBB. -
setHeader: Whether to affect the window header. -
setBorder: Whether to affect the window border.
View Example
-- Makes the border & header red
cpp.setWindowBorderColor(0xFF0000, true, true)
-- Makes the border green
cpp.setWindowBorderColor(0x00FF00, false, true)
-- Resets the window's color
cpp.setWindowBorderColor(cpp.DWMWA_COLOR_DEFAULT, true, true)─────────────────────────
setWindowTextColor(colorHex: string|number): voidSets the window title text to the color specified.
(This function only has an effect on Windows 11)
Parameters:
-
colorHex: The color specified. Allowed formats are'#RRGGBB','0xRRGGBB','RRGGBB', or0xRRGGBB.
View Example
-- Makes the window title text blue
cpp.setWindowTextColor(0x0000FF)
-- Resets the window's text color
cpp.setWindowTextColor(cpp.DWMWA_COLOR_DEFAULT)─────────────────────────
setWindowCornerType(cornerType: number): voidSets the window border corners to the type specified.
(This function only has an effect on Windows 11)
Parameters:
-
cornerType: The corner type. Refer tocpp.windowCornerTypefor a list of possible values.
View Example
-- Makes the window's corners non-round
cpp.setWindowCornerType(cpp.windowCornerType.DONOTROUND)
-- Resets the window's corners to default
cpp.setWindowCornerType(cpp.windowCornerType.DEFAULT)─────────────────────────
redrawWindowHeader(): voidReloads the window header to force a window header effect. This is useful for Windows 10 users, but is not needed for Windows 11.
View Example
cpp.setDarkMode()
cpp.redrawWindowHeader()─────────────────────────
cast(varToConvert: any, toType: string, isCType: boolean): dynamicCasts a variable into the type specified, similar to traditional casts in other languages.
Parameters:
-
varToConvert: The variable to convert. -
toType: The type to convert the variable to. -
isCType(optional): Set this to true if you wanna use C types.
(This will make the function useffi.cast)
Returns: The casted variable.
View Example
-- Converts the bool into a string. This would read "That is true"
local aBool = true
debugPrint("That is " ..cpp.cast(aBool, "string"))
-- Casts the integer 1 into a DWORD unsigned 32bit integer
local coolInt = cpp.cast(1, "DWORD", true)─────────────────────────
alignof(var: any): dynamicReturns the alignment of a variable.
(This function only has an effect on C / FFI types)
Parameters:
-
var: The variable.
Returns: The variable's alignment.
View Example
local aInt = cpp.alignof("int") -- Returns 4
local aChar = cpp.alignof("char") -- Returns 1─────────────────────────
sizeof(var: any): integerReturns the byte size of a variable.
(This function only has an effect on C / FFI types)
Parameters:
-
var: The variable.
Returns: The variable's byte size.
View Example
-- Since an int is 4, we multiply it by 10 to get a size of 40
local aInt = cpp.sizeof("int[10]")
-- A size of 256
local aChar = cpp.sizeof("char[256]")─────────────────────────
addressOf(target: any): integerReturns the address of a variable. Very useful for some C functions.
Parameters:
-
target: The variable.
Returns: The variable's address.
View Example
-- Returns the address of 1
local myAdd = cpp.addressOf(1)─────────────────────────
compress(text: string): stringCompresses a string to save on resources.
(Taken from the offical luajit docs)
Parameters:
-
text: The string of text to compress.
Returns: The compressed text.
View Example
-- Compresses the string, duh
local myTxt = "Hello from Ghostutil!"
local myAdd = cpp.compress(myTxt)─────────────────────────
uncompress(compressedText: string, txtLength: integer): stringUncompresses a string from cpp.compress.
(Taken from the offical luajit docs)
Parameters:
-
compressedText: The string of text to uncompress. -
txtLength: The length of the string. It's best to set this to#compressedText.
Returns: The uncompressed text.
View Example
-- Compresses the string, duh
local myTxt = "Hello from Ghostutil!"
local foo = cpp.compress(myTxt)
local coolTxt = cpp.uncompress(foo, #foo)
-- "Hello from Ghostutil!"
debugPrint(coolTxt)
GhostUtil 3.0.0 • Docs 3.0.0, Revision 1
a Lua Library made by GhostglowDev; for Psych Engine
© 2025 GhostglowDev — Ghost's Utilities
Licensed under the MIT License.