Files
ClaudeCode-Roblox-Studio-MCP/bg_inject.ps1
Gemini AI 3af46cf15d Add UIAutomation background injection for Roblox Studio
- bg_inject.ps1: PowerShell UIAutomation script that finds Studio command bar by AutomationId and injects Lua code without window focus
- bg_inject.py: Python wrapper for bg_inject.ps1
- bg_inject_uia2.ps1: Discovery/debugging script for finding Studio UI controls
- inject_full_gta.py: 7-step GTA city + COD weapons + enemies injection using background API
- inject_gta_bg.py: Alternative multi-file GTA injection loader

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 22:34:48 +04:00

112 lines
3.0 KiB
PowerShell

<#
.SYNOPSIS
Background Lua injection into Roblox Studio via UI Automation
.DESCRIPTION
Injects Lua code into Roblox Studio's command bar using UIAutomation.
Works when Studio is minimized, behind other windows, or in background.
No window focus required.
.PARAMETER Code
The Lua code to inject, or a path to a .lua file
.PARAMETER File
Path to a .lua file to inject
.EXAMPLE
.\bg_inject.ps1 -Code 'print("hello")'
.\bg_inject.ps1 -File C:\scripts\build_map.lua
#>
param(
[string]$Code = '',
[string]$File = ''
)
Add-Type -AssemblyName UIAutomationClient
Add-Type -AssemblyName UIAutomationTypes
function Find-StudioCommandBar {
$root = [System.Windows.Automation.AutomationElement]::RootElement
# Find Studio window
$windows = $root.FindAll(
[System.Windows.Automation.TreeScope]::Children,
[System.Windows.Automation.Condition]::TrueCondition
)
$studio = $null
foreach ($w in $windows) {
try {
$n = $w.Current.Name
if ($n -like "*Roblox Studio*") { $studio = $w; break }
} catch {}
}
if (-not $studio) {
$procs = Get-Process -Name "RobloxStudioBeta" -ErrorAction SilentlyContinue
if (-not $procs) { return $null }
$pidCond = New-Object System.Windows.Automation.PropertyCondition(
[System.Windows.Automation.AutomationElement]::ProcessIdProperty,
$procs[0].Id
)
$studio = $root.FindFirst([System.Windows.Automation.TreeScope]::Children, $pidCond)
}
if (-not $studio) { return $null }
# Find command bar by AutomationId
$autoIdCond = New-Object System.Windows.Automation.PropertyCondition(
[System.Windows.Automation.AutomationElement]::AutomationIdProperty,
"commandBarScriptEditor"
)
$cmdBar = $studio.FindFirst(
[System.Windows.Automation.TreeScope]::Descendants,
$autoIdCond
)
return $cmdBar
}
function Inject-LuaCode {
param([string]$luaCode)
$cmdBar = Find-StudioCommandBar
if (-not $cmdBar) {
Write-Error "ERROR: Roblox Studio command bar not found"
return $false
}
try {
$vp = $cmdBar.GetCurrentPattern([System.Windows.Automation.ValuePattern]::Pattern)
$vp.SetValue($luaCode)
# Send Enter via keyboard (requires brief focus)
Add-Type -AssemblyName System.Windows.Forms
$cmdBar.SetFocus()
Start-Sleep -Milliseconds 100
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
return $true
} catch {
Write-Error "Injection failed: $_"
return $false
}
}
# Main
if ($File -and (Test-Path $File)) {
$Code = Get-Content $File -Raw
}
elseif ($Code -eq '') {
# Read from stdin
$Code = @($input) -join "`n"
}
if ($Code.Trim() -eq '') {
Write-Error "No code provided. Use -Code or -File"
exit 1
}
$result = Inject-LuaCode -luaCode $Code
if ($result) {
Write-Output "OK: Code injected successfully"
} else {
exit 1
}