Overview
Thelib/ directory contains reusable utility functions and external libraries that power Natro Macro’s automation capabilities.
Location: lib/
Graphics and Image Processing
Gdip_All.ahk
Source: buliasz/AHKv2-Gdip Version: 1.61 (modified for Natro Macro) Provides GDI+ wrapper functions for advanced graphics operations.Initializes GDI+ library.Returns: Token for GDI+ session (required for all other GDI+ functions)Must call:
Gdip_Shutdown(pToken) on exitCaptures a screenshot region as a GDI+ bitmap.Parameters:
Screen- Region string: “x|y|w|h” or 0 for full screenRaster- Raster operation mode (optional)
Creates a blank bitmap of specified dimensions.Returns: Pointer to GDI+ bitmap
Frees memory used by a GDI+ bitmap.Important: Always dispose bitmaps after use to prevent memory leaks
Updates a layered window with GDI+ bitmap.Parameters:
hwnd- Window handlehdc- Device context handlex,y- Position (optional, uses current if omitted)w,h- Dimensions (optional, uses current if omitted)Alpha- Transparency (0-255, default 255)
Gdip_ImageSearch.ahk
Author: MasterFocus (ported to AHKv2 by SP) Advanced image search function with variation tolerance and multiple search modes.Searches for a needle bitmap within a haystack bitmap.Parameters:Returns:
GDI+ bitmap pointer to search within
GDI+ bitmap pointer to search for
Variable to receive coordinates of matches (format: “x,y”)
Search region bounds (0 = full haystack)
Color variation tolerance (0-255). Higher values allow more color difference.
RGB transparent color (0x000000 to 0xFFFFFF). Pixels of this color in needle are ignored.
Search pattern direction:
1- Top→left→right→bottom (default)2- Bottom→left→right→top3- Bottom→right→left→top4- Top→right→left→bottom5- Left→top→bottom→right6- Left→bottom→top→right7- Right→bottom→top→left8- Right→top→bottom→left
Maximum matches to find (0 = find all, 1 = stop after first)
>= 0- Number of instances found-1001- Invalid bitmap pointer-1002- Invalid variation value-1003- Negative coordinates-1004- Unable to lock haystack bits-1005- Unable to lock needle bits
Data Serialization
JSON.ahk
Author: thqby, HotKeyIt Version: 1.0.7 JSON serialization and deserialization with support for AutoHotkey v2 objects.Converts JSON string to AutoHotkey object.Parameters:
text- Valid JSON stringkeepbooltype- If true, converts to JSON.true/JSON.false/JSON.null; if false, uses 1/0/""as_map- If true, returns Map objects; if false, returns regular Objects
Converts AutoHotkey object to JSON string.Parameters:
obj- AutoHotkey value (Object/Map/Array/primitive)indent- Indentation string (e.g., ” ” or “\t”) for pretty-printingkeepbooltype- If true, converts JSON.true/false/null to JSON literals
Special ComValue objects representing JSON null, true, and false.
Roblox Automation
Roblox.ahk
Author: SP Functions for automating and interacting with the Roblox window.Gets the window handle for the Roblox client.Returns:
- Window handle (integer) if found
0if Roblox window not found
- Standard Roblox client (RobloxPlayerBeta.exe)
- UWP version (ApplicationFrameHost.exe)
Updates global window position variables.Parameters:
hwnd- Optional window handle (calls GetRobloxHWND if omitted)
windowX- Client X positionwindowY- Client Y positionwindowWidth- Client widthwindowHeight- Client height
1- Success0- Target error (window not found)
Calculates the Y-axis offset for GUI elements in Roblox.Parameters:
hwnd- Optional window handlefail- ByRef variable set to 1 on failure, 0 on success
- Searches for the pollen counter icon at top of screen
- Uses image detection to find exact GUI position
- Compensates for red vignette effects (20 attempts)
- Caches result per window handle
bitmaps["toppollen"]bitmaps["toppollenfill"]
Activates the Roblox window.Returns:
1- Success0- Target error
Walk.ahk
Author: SP Precision movement system with haste detection and compensation.Walks a specified distance with automatic haste compensation.Parameters:
n- Distance in tiles (1 tile = 4 studs)hasteCap- Haste cap threshold (0 = no cap)
- Uses high-precision QueryPerformanceCounter for timing
- Continuously detects movement speed during walk
- Compensates for haste, haste+, bear morphs, oil, smoothie buffs
- Formula:
v = base * (1 + coconut*0.1) * (1 + bear*0.04) * hasty_guard * gifted_hasty * (1 + haste*0.1) * haste_plus * oil * smoothie
- If
hasteCap = 0: Full compensation for all haste levels - If
hasteCap > 0: No compensation below cap, full compensation above - Example:
hasteCap = 5ignores haste 1-5, compensates for haste 6-10 as if always 5
Detects current movement speed from buff icons.Parameters:
s- ByRef start timestampf- ByRef finish timestamphasteCap- Haste cap threshold
- Captures screen bitmap of buff area (top 30px of window)
- Searches for buff icons using Gdip_ImageSearch
- Reads stack numbers from buff counter digits
- Calculates speed using movespeed formula
- Haste (with stack detection 1-10x)
- Coconut Haste
- Melody (distinguished from haste)
- Haste+ (2x boost)
- Oil (1.2x boost)
- Super Smoothie (1.25x boost)
- Bear morphs (Brown, Black, Panda, Polar, Gummy, Science, Mother)
base_movespeed- Base movement speed from settingshasty_guard- Boolean for Hasty Guard bonus (1.1x)gifted_hasty- Boolean for Gifted Hasty Bee bonus (1.15x)buff_characters- Map of digit bitmaps (0-9)bitmaps- Map of buff icon bitmapsoffsetY- GUI offset from GetYOffset()
Discord Integration
Discord.ahk
Author: SP Class for sending messages, embeds, and files to Discord via webhooks and bot API.Sends an embed message to Discord.Parameters:
message- Embed description textcolor- Embed color (integer, default blue)content- Message content outside embedpBitmap- GDI+ bitmap pointer for image attachmentchannel- Channel ID (uses default if blank)replyID- Message ID to reply to
Sends a file or folder to Discord.Parameters:
filepath- Full path to file or folderreplyID- Message ID to reply to
0- Success-1- File too large (>10MB limit)-2- File not found-3- Folder zip failed
- Automatically zips folders (Windows 10+ only)
- Detects MIME types for images
- Deletes temp files after upload
Sends a GDI+ bitmap as an image.Parameters:
pBitmap- GDI+ bitmap pointerimgname- Filename for attachmentreplyID- Message ID to reply to
Utility Functions
DurationFromSeconds.ahk
Formats seconds into duration string using Windows API.Parameters:
secs- Duration in secondsformat- Format string (h, m, s, hh, mm, ss)capacity- Buffer capacity
Formats seconds into human-readable duration.Example:
HashFile.ahk
Author: Deo (modified by lexikos for v2)Calculates cryptographic hash of a file.Parameters:
filePath- Full path to filehashType- Hash algorithm:1- MD22- MD5 (default)3- SHA-14- SHA-2565- SHA-3846- SHA-512
HyperSleep.ahk
High-precision sleep using QueryPerformanceCounter.Parameters:
ms- Duration in milliseconds
- Uses busy-wait for precise timing
- Calls
Sleep 1with timeBeginPeriod for durations >30ms - More accurate than standard Sleep for short durations
- Higher CPU usage than Sleep
nm_InventorySearch.ahk
Searches for an item in the Roblox inventory.Parameters:
item- Item name (bitmap key)direction- Scroll direction: “down” or “up”prescroll- Number of scrolls before switching directionprescrolldir- Direction for prescrolls (blank = same as direction)scrolltoend- If 1, scrolls to top/bottom after prescrollsmax- Maximum scroll attempts
- Array
[x, y]- Coordinates for dragging item 0- Item not found or error
nm_OpenMenu.ahk
Opens/closes menu tabs in Roblox.Parameters:
tab- Menu tab to open:"itemmenu"- Inventory"questlog"- Quests"beemenu"- Bees"badgelist"- Badges"settingsmenu"- Settings"shopmenu"- Shop""- Close all menus
refresh- If 1, closes and reopens the tab
1- Success0- Roblox window not found
See Also
- Main Script Reference - Integration with main macro
- Background Script Reference - Usage in background monitoring