• Log in or sign up for an account here: https://www.sythe.org/login

HD RS World Loader

Flaming Idiots

Active Member

Visual Basic Programmers
Joined
Dec 22, 2005
Sythe Gold
0
Messages
235
Age
36
Location
Alberta Canada
Two Factor Authentication User
HD RS World Loader
Here is a world loader that I made that supports the new resizable clients. To load a world, call the controls LoadWorld method, give the prefix, detail and if you want it to use safe mode.

If you tell it to load high detail, it will stretch the client to fill the control like below.


If you tell it to load normal detail, it will center the client in the center of the control like below.


Code:
Imports System.Runtime.InteropServices

Public Class RSLoader
    Inherits Control

    Private Loader As WFRSLoader

    Sub New()
        BackColor = Color.Black
        If Me.DesignMode Then Return

        Loader = New WFRSLoader With {.Size = New System.Drawing.Size(1000, 1000)}
        Dim Panel As New Windows.Forms.TableLayoutPanel()
        Panel.Padding = New Padding(0)
        Panel.Dock = DockStyle.Fill
        Panel.ColumnCount = 1
        Panel.RowCount = 1
        Panel.BackColor = System.Drawing.Color.Black
        Dim Host As New Windows.Forms.Control
        Host.Margin = New Padding(0)
        Host.Padding = New Padding(0)
        Host.BackColor = System.Drawing.Color.Black
        Host.Visible = False
        Host.Dock = DockStyle.None
        Host.Anchor = AnchorStyles.None
        Host.Controls.Add(Loader)
        Panel.Controls.Add(Host)
        Me.Controls.Add(Panel)

    End Sub

    Public Sub LoadWorld(ByVal World As String, ByVal Detail As DetailMode, ByVal SafeMode As Boolean)
        If Loader Is Nothing Then Return
        Loader.LoadWorld(World, Detail, SafeMode)
    End Sub

    Private Class WFRSLoader
        Inherits WebBrowser

        Public Sub LoadWorld(ByVal World As String, ByVal Detail As DetailMode, ByVal SafeMode As Boolean)
            Dim Url = String.Format("http://{0}.runescape.com/p0", World)
            If Detail = DetailMode.HD Then Url &= ",g1"
            If SafeMode Then Url &= ",s1"
            Me.Navigate(Url)
        End Sub

        Protected Overrides Sub OnDocumentCompleted(ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
            MyBase.OnDocumentCompleted(e)
            Dim U = e.Url.ToString
            If Not e.Url.ToString.Contains("/p0") Then Return
            Dim Detail = If(e.Url.ToString().Contains(",g1"), DetailMode.HD, DetailMode.Normal)
            Dim [Handles] = From I In Native.EnumChildWindows(Me.Handle) Select Handle = I, Size = Native.BoundsFromHandle(I)
            Dim Target = Aggregate I In [Handles] _
                         Where I.Size.Height >= 503 AndAlso I.Size.Height < Me.Height _
                         Select I.Handle _
                         Into FirstOrDefault()
            If Target = 0 Then Return
            Dim TargetBounds = Native.BoundsFromHandle(Target)
            TargetBounds.Location -= Me.PointToScreen(New System.Drawing.Point())
            Select Case Detail
                Case DetailMode.Normal
                    Parent.Size = TargetBounds.Size
                    Me.Location = New Point(-TargetBounds.X, -TargetBounds.Y)
                Case DetailMode.HD
                    Me.Anchor = AnchorStyles.Left Or AnchorStyles.Bottom Or AnchorStyles.Right Or AnchorStyles.Top
                    Me.Bounds = New System.Drawing.Rectangle(-TargetBounds.X, -TargetBounds.Y, Parent.Width + (Width - TargetBounds.Width), Parent.Height + (Height - TargetBounds.Height))
                    Parent.Anchor = AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top Or AnchorStyles.Bottom
            End Select
            Me.AllowNavigation = False
            Parent.Visible = True
        End Sub

        Private Class Native

            Public Delegate Function EnumWindowProc(ByVal hWnd As IntPtr, ByVal parameter As IntPtr) As Boolean

            Private Declare Auto Function GetWindowRect Lib "user32.dll" _
                (ByVal ControlHandle As IntPtr, ByRef OutputRectangle As Rect) As Boolean

            Private Declare Auto Function EnumChildWindows Lib "user32.dll" _
                (ByVal Window As IntPtr, ByVal Callback As EnumWindowProc, ByVal ListHandle As IntPtr) As Boolean

            Public Shared Function BoundsFromHandle(ByVal WindowHandle As IntPtr) As System.Drawing.Rectangle
                Dim r As New Rect
                GetWindowRect(WindowHandle, r)
                Return r
            End Function

            Public Shared Function EnumChildWindows(ByVal ParentHandle As IntPtr) As IntPtr()
                Dim result As New List(Of IntPtr)()
                Dim listHandle As GCHandle = GCHandle.Alloc(result)
                Try
                    Dim childProc As New EnumWindowProc(AddressOf EnumWindow)
                    EnumChildWindows(ParentHandle, childProc, GCHandle.ToIntPtr(listHandle))
                Finally
                    If listHandle.IsAllocated Then
                        listHandle.Free()
                    End If
                End Try
                Return result.ToArray
            End Function
            Private Shared Function EnumWindow(ByVal handle As IntPtr, ByVal pointer As IntPtr) As Boolean
                Dim gch As GCHandle = GCHandle.FromIntPtr(pointer)
                Dim list As List(Of IntPtr) = TryCast(gch.Target, List(Of IntPtr))
                If list Is Nothing Then
                    Throw New InvalidCastException("GCHandle Target could not be cast as List(Of IntPtr)")
                End If
                list.Add(handle)
                Return True
            End Function

            <StructLayout(LayoutKind.Sequential)> _
            Public Structure Rect
                Public Left As Integer
                Public Top As Integer
                Public Right As Integer
                Public Bottom As Integer
                Public Sub New(ByVal pLeft As Integer, ByVal pTop As Integer, ByVal pRight As Integer, ByVal pBottom As Integer)
                    Left = pLeft
                    Top = pTop
                    Right = pRight
                    Bottom = pBottom
                End Sub

                Public Shared Widening Operator CType(ByVal Value As Rect) As System.Drawing.Rectangle
                    Return System.Drawing.Rectangle.FromLTRB(Value.Left, Value.Top, Value.Right, Value.Bottom)
                End Operator

            End Structure
        End Class
    End Class
End Class

Public Enum DetailMode
    Normal
    HD
End Enum
 
Runescape Gamblingrunescape gambling
Back
Top