Public/Debugging.General.ps1


function Get-ASDObject
{
    Param(
        [Parameter(Mandatory=$false)][String]$Shell,
        [Parameter()][String]$Name,
        [ArgumentCompletions(
        #this is going to be a long list...
        'UnityEngine.Transform',
        'UnityEngine.Light', 
        'UnityEngine.MeshRenderer',
        'UnityEngine.Canvas'
        )]
        [Parameter()][String]$Type,
        [Parameter()][switch]$IgnoreCase,
        [Parameter()][switch]$ActiveOnly,
        [Parameter()][switch]$InactiveOnly,
        [Parameter()][String[]]$Scene
    )

    $shellLocal = Get-ASDefaultShell
    if($PSBoundParameters['Shell'])
    {
        $shellLocal = $Shell
    }
    if([System.String]::IsNullOrEmpty($shellLocal))
    {
        Write-Error 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.' -ErrorAction Stop
    }

    # if no parameter is set, it's an error. we don't get all objects
    if(!($Name) -and !($Type))
    {
        Write-Error 'You must provide either a Name and/or a Type to look for.' -ErrorAction Stop
    }

    $uri = "http://$($shellLocal):4444/api/debugging/GetObject?" 
        
    if($Type)
    {
        $uri += "type=$([uri]::EscapeDataString($Type))"
    }
    
    #depending on the parameter, we send different query
    if($Name)
    {
        if($Type) { $uri += "&" }
        $uri += "name=$([uri]::EscapeDataString($Name))"
    } 
    
    if($IgnoreCase)
    {
        $uri += "&ignoreCase=true"
    }
    if($ActiveOnly)
    {
        $uri += "&onlyActive=true"
    }
    if($InactiveOnly)
    {
        $uri += "&onlyInactive=true"
    }

    if($Scene)
    {
        $uri += "&scene=$([uri]::EscapeDataString($Scene))"
    }
    
    $responce = (Invoke-RestMethod -Uri $uri -Method GET -SkipCertificateCheck -AllowUnencryptedAuthentication)  

    if(!$responce.success)
    {
        Write-Error $responce.error -ErrorAction Stop
    }
    else {
        $responce.value
    }
}

function Get-ASDObjects
{
    Param(
        [Parameter(Mandatory=$false)][String]$Shell,
        [Parameter()][String]$Name,
        [Parameter()][String]$Type,
        [Parameter()][switch]$IgnoreCase,
        [Parameter()][switch]$ActiveOnly,
        [Parameter()][switch]$InactiveOnly,
        [Parameter()][String[]]$Scene
    )

    $shellLocal = Get-ASDefaultShell
    if($PSBoundParameters['Shell'])
    {
        $shellLocal = $Shell
    }
    if([System.String]::IsNullOrEmpty($shellLocal))
    {
        Write-Error 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.' -ErrorAction Stop
    }

    # if no parameter is set, it's an error. we don't get all objects
    if(!($Name) -and !($Type))
    {
        Write-Error 'You must provide either a Name and/or a Type to look for.' -ErrorAction Stop
    }

    $uri = "http://$($shellLocal):4444/api/debugging/GetObjects?" 
        
    if($Type)
    {
        $uri += "type=$([uri]::EscapeDataString($Type))"
    }
    
    #depending on the parameter, we send different query
    if($Name)
    {
        if($Type) { $uri += "&" }
        $uri += "name=$([uri]::EscapeDataString($Name))"
    } 
    
    $responce = (Invoke-RestMethod -Uri $uri -Method GET -SkipCertificateCheck -AllowUnencryptedAuthentication)  

    if(!$responce.success)
    {
        Write-Error $responce.error -ErrorAction Stop
    }
    else {
        $responce.value
    }
}

function Set-ASDValue
{
    Param(
        [Parameter(Mandatory=$false)][String]$Shell,
        [Parameter()][string]$ObjectPath,
        [Parameter(Mandatory)][string]$FieldPath,
        [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName)][int]$InstanceId,
        [Parameter(Mandatory)][String]$Value,
        [Parameter(Mandatory=$false)][bool]$IgnoreCase,
        [Parameter(Mandatory=$false)][bool]$IsSingleton
        )

    begin 
    {
        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell'])
        {
            $shellLocal = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal))
        {
            Write-Error 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.' -ErrorAction Stop
        }

        $ids = @() 
    }
    process { if($InstanceId) { $ids += $InstanceId } }
    end{
        $body = @{
            instanceId=$ids[0]
            ObjectPath=$ObjectPath
            FieldPath=$FieldPath
            Value=$Value
            IgnoreCase=$IgnoreCase
            IsSingleton=$IsSingleton
        } | ConvertTo-Json -Depth 8;

        $uri = "http://$($shellLocal):4444/api/debugging/SetObjectPropertyFieldValue" 
        $result = Invoke-RestMethod -Uri $uri -Body $body -Method POST -ContentType 'application/json'
        
        if(!$result.success) {
            Write-Error $result.error -ErrorAction Stop
        }
        else {
            $result.value
        }
    }
}

function Get-ASDPropertiesAndFields
{
    Param(
        [Parameter(Mandatory=$false)][String]$Shell,
        [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName)][int]$InstanceId
        )

    begin 
    {
        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell'])
        {
            $shellLocal = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal))
        {
            Write-Error 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.' -ErrorAction Stop
        }

        $ids = @() 
    }
    process { if($InstanceId) { $ids += $InstanceId } }
    end{
        $instanceId=$ids[0]

        $uri = "http://$($shellLocal):4444/api/debugging/GetObjectPropertiesFields?objectInstanceId=$($instanceId)" 
        $result = Invoke-RestMethod -Uri $uri -Method GET
        
        if(!$result.success) {
            Write-Error $result.error -ErrorAction Stop
        }
        else {
            $result.value
        }
    }
}

function Get-ASDValue
{
    Param(
        [Parameter(Mandatory=$false)][String]$Shell,
        [Parameter()][string]$ObjectPath,
        [Parameter(Mandatory)][string]$FieldPath,
        [Parameter(Mandatory=$false, ValueFromPipelineByPropertyName)][int]$InstanceId,
        
        [Parameter(Mandatory=$false)][bool]$IgnoreCase,
        [Parameter(Mandatory=$false)][bool]$IsSingleton
        )

    begin 
    {
        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell'])
        {
            $shellLocal = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal))
        {
            Write-Error 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.' -ErrorAction Stop
        }

        $ids = @() 
    }
    process { if($InstanceId) { $ids += $InstanceId } }
    end{
        $body = @{
            instanceId=$ids[0]
            ObjectPath=$ObjectPath
            FieldPath=$FieldPath
            Value=$Value
            IgnoreCase=$IgnoreCase
            IsSingleton=$IsSingleton
        } | ConvertTo-Json -Depth 8;

        $uri = "http://$($shellLocal):4444/api/debugging/GetObjectPropertyFieldValue" 
        $result = Invoke-RestMethod -Uri $uri -Body $body -Method POST -ContentType 'application/json'
        
        if(!$result.success) {
            Write-Error $result.error -ErrorAction Stop
        }
        else {
            $result.value
        }
    }
}

function Set-ASDGraphy
{
    Param(
        [Parameter(Mandatory=$false)][String]$Shell,
        [Parameter(Mandatory=$false)][bool]$Enable,
        [Parameter(Mandatory=$false)][bool]$LightMode,
        [Parameter(Mandatory=$false)][bool]$Background,
        [ValidateSet("Full", "Text", "Basic", "Background", "Off" )] [Parameter(Mandatory=$false)][String]$FpsModule,
        [ValidateSet("Full", "Text", "Basic", "Background", "Off" )] [Parameter(Mandatory=$false)][String]$RamModule,
        [ValidateSet("Full", "Text", "Basic", "Background", "Off" )] [Parameter(Mandatory=$false)][String]$AudioModule,
        [ValidateSet("Full", "Text", "Basic", "Background", "Off" )] [Parameter(Mandatory=$false)][String]$AdvancedModule,
        [Parameter(Mandatory=$false)][Int]$GoodFpsThreshold,
        [Parameter(Mandatory=$false)][Int]$CautionFpsThreshold,
        [Parameter(Mandatory=$false)][Int]$CriticialFpsThreshold
        )

        # first, get Shell we want to talk to
        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell'])
        {
            $shellLocal  = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal))
        {
            Write-Host 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.'
            return
        }

        # now, create object from all our parameters

        $object = New-Object –TypeName PSObject
        foreach ($boundParam in $PSBoundParameters.GetEnumerator())
        {
            $object | Add-Member –MemberType NoteProperty –Name $boundParam.Key –Value $boundParam.Value
        }
        
        $body = $object | ConvertTo-Json -Depth 8
        $uri = "http://$($shellLocal):4444/api/debugging/setgraphysettings" 
        $result = Invoke-RestMethod -Uri $uri -Body $body -Method POST -ContentType 'application/json'
        Write-Host $result
}


function Send-ASDSignal
{
    Param(
        [Parameter(Mandatory=$false)][String]$Shell,
        [Parameter(Mandatory, Position=0)][string]$Type,
        [Parameter()][hashtable] $Fields
        )

        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell'])
        {
            $shellLocal = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal))
        {
            Write-Host 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.'
            return
        }

        $object = New-Object –TypeName PSObject
        foreach ($boundParam in $PSBoundParameters.GetEnumerator())
        {
            $object | Add-Member –MemberType NoteProperty –Name $boundParam.Key –Value $boundParam.Value
        }
        
        $body = $object | ConvertTo-Json -Depth 8

        $uri = "http://$($shellLocal):4444/api/debugging/SendSignal" 
        $result = Invoke-RestMethod -Body $body -Uri $uri -Method POST -ContentType 'application/json'

        if($result.success) {
            if ($result.message) {
                $result.message
            }
        }
        else {
            Write-Error $result.error -ErrorAction Stop
        }
}

function Clear-ASDPlayerPrefs
{
    Param(
        [Parameter(Mandatory=$false)][String]$Shell
        )

        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell'])
        {
            $shellLocal = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal))
        {
            Write-Host 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.'
            return
        }
        $uri = "http://$($shellLocal):4444/api/debugging/clearplayerprefs" 
        $result = Invoke-RestMethod -Uri $uri -Method POST
        Write-Host $result
}

function Set-ASDStreamingOptions
{
    Param(
        [Parameter(Mandatory=$false)][String]$Shell,

        [ValidateSet("Default", "Base", "Assets", "Details", "Foreground", "Transparency", "Background", "SceneSetup", "Effects", "Audio", "Logic" )] [Parameter(Mandatory=$false)][String]$Mode,
        [Parameter(Mandatory=$false)][String]$Chunks,
        [Parameter(Mandatory=$false)][bool]$EnableDisableHelp,
        [Parameter(Mandatory=$false)][bool]$LightsLoaded,
        [Parameter(Mandatory=$false)][bool]$ResetCameraZoom,
        [Parameter(Mandatory=$false)][float]$CameraZoomOffset,
        [Parameter(Mandatory=$false)][bool]$ShowBounds
        )

        # first, get Shell we want to talk to
        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell'])
        {
            $shellLocal  = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal))
        {
            Write-Host 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.'
            return
        }

        # now, create object from all our parameters

        $object = New-Object –TypeName PSObject
        foreach ($boundParam in $PSBoundParameters.GetEnumerator())
        {
            $object | Add-Member –MemberType NoteProperty –Name $boundParam.Key –Value $boundParam.Value
        }
        
        $body = $object | ConvertTo-Json -Depth 8
        $uri = "http://$($shellLocal):4444/api/debugging/SetStreamingOptions" 
        $result = Invoke-RestMethod -Uri $uri -Body $body -Method POST -ContentType 'application/json'
}



function Clear-ASDConsole
{
    Param(
        [Parameter(Mandatory=$false)][String]$Shell
        )

        $shellLocal = Get-ASDefaultShell
        if($PSBoundParameters['Shell'])
        {
            $shellLocal = $Shell
        }
        if([System.String]::IsNullOrEmpty($shellLocal))
        {
            Write-Host 'Target shell is not set. Please specify target shell with -Shell parameter or by Set-ASDefaultShellTarget snippet.'
            return
        }
        $uri = "http://$($shellLocal):4444/api/debugging/disableonscreenconsole" 
        $result = Invoke-RestMethod -Uri $uri -Method POST
        Write-Host $result
}