Author Topic: SCAR-LIKE Program - SCOUT HAWK  (Read 1783 times)

Offline scar

  • Leecher
  • Posts: 9
  • Rep: 0
  • It's a freddytatorship.
    • View Profile
SCAR-LIKE Program - SCOUT HAWK
« on: December 19, 2010, 08:07:40 am »
<scout hawk>
I was learning a little bit about scar from a tutorial I found in the guide section and I thought of a great, weird idea! Scar- like program in visual basic?

<background>
Scout Hawk is a basic coding... language!?, which is very powerless and useless, at the moment! Currently it can do the following:
  • Pop-up a message box.
  • Has an output box, which messages can be put into.
  • A move mouse function.
  • Left click, right click, middle click functions.
  • Talk function (let's you say stuff).
  • Wait function (waits time, in milliseconds).
  • Sleep function (sleeps the thread; more accurate timing, but freezes the thread).
  • Click Colour (clicks the first colour using RGB values you specified).
  • Move to colour (same as above, but doesn't click).

<commands?>
Commands on scout hawk are simple...
  • message yourmessage
  • output outputyouwanttosay
  • moveMouseEx xcoord,ycoord
  • moveMouse xcoord,ycoord
  • talk whattosay
  • wait timeinmilliseconds
  • sleep timeinmilliseconds
  • clickColour alpha,red,green,blue
  • moveToColour alpha,red,green,blue

<self explanatory commands>
These are the commands where I cannot be bothered writing in what the mean, as it is very simple to figure it out for yourself.
  • leftClickDown
  • leftClickUp
  • rightClickDown
  • rightClickUp
  • middleClickDown
  • middleClickUp

<other stuff attached>
Not only does Scout Hawk have all these useless features; it also has a few little display features; such as:
  • A-R-G-B value of everything you put your mouse over.
  • Current Mouse Coordinates.

<what may be worked on>
This little section is for me! I'm basically going to put here everything I hope to make in the future:
  • Loop function
  • More precise colours.
  • Ability to select windows (like in scar).
  • Tabs? (I could do this right now, but I CBF'ed).
  • Colour picker tool (I probably could do this, too).
  • Picture to string.
  • DTM editor.
  • Forum editor (much like VB's).

<suggestions>
It would be nice if you guys could give me some suggestions on what to try to add to the program. It would help me out a lot!

<finally>
I hope you guys like the idea as much as I do  :love:. This program will probably never be released (due to me not having a domain name to host it on), so there should be no worry in keeping this thread up, and not locked  :P. Basically, it's a little something to do when I'm bored; and I find it, interesting. Well guys, see ya!

<updates>

7:19AM, 19th December 2010
I've figured out how to get the P2C (point to client) with a very simple piece of code:
Code: [Select]
        Dim p As Point = Me.PointToClient(MousePosition)
        Me.Text = p.X & "," & p.Y
Now, the only problem is that the client must be ran in Scout Hawk itself. In a way it makes it harder, but in a way, it's a little bit easier. Luckly, I'm planning on using it on a private server which seems to fit very well with my form...lucky me.

7:53AM, 19th December 2010
I've encountered a huge amount of problems. A few which are basically unfixable. The only solution is to make two separate programs, a client (which will hold the game itself, and the scripts), and a development kit (which you can use to make the script). To speed things up, i'm thinking about simply forgetting the Development kit (just for now), and moving on with making the client work properly (running scripts properly).

8:30AM, 19th December 2010
I'm finally getting some stuff together. I've fixed the code above to work with the new client I've made!
Code: [Select]
                Dim st As Point = New Point(X, Y)
                Cursor.Position = New Point(PointToScreen(st))
Hopefully I will be able to get things working soon...by the looks of it though, the next step would be to try to get the colour finder working...
« Last Edit: December 19, 2010, 01:28:38 pm by scar »
Take a look at Project Scout Hawk. It's a Scar- Like Program created by me!

Freddy1990.com

SCAR-LIKE Program - SCOUT HAWK
« on: December 19, 2010, 08:07:40 am »

Offline Freddy

  • Owner
  • *****
  • Posts: 2616
  • Rep: 19
    • MSN Messenger - freddy1990@gmail.com
    • AOL Instant Messenger - Freddy199O
    • View Profile
    • Email
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #1 on: December 19, 2010, 06:22:41 pm »
Sounds good, I made something like this in VB with basic as scripting language too long before I started working on SCAR, it was called FScript :)

Freddy1990.com

Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #1 on: December 19, 2010, 06:22:41 pm »

Offline scar

  • Leecher
  • Posts: 9
  • Rep: 0
  • It's a freddytatorship.
    • View Profile
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #2 on: December 19, 2010, 09:33:00 pm »
Thanks for the reply Freddy. I keep hitting problems with VB. Quick question, do you know how I can set a client window (like in scar)?
Take a look at Project Scout Hawk. It's a Scar- Like Program created by me!

Offline Freddy

  • Owner
  • *****
  • Posts: 2616
  • Rep: 19
    • MSN Messenger - freddy1990@gmail.com
    • AOL Instant Messenger - Freddy199O
    • View Profile
    • Email
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #3 on: December 21, 2010, 11:43:39 am »
Thanks for the reply Freddy. I keep hitting problems with VB. Quick question, do you know how I can set a client window (like in scar)?

Use WindowFromPoint to get the window where you drop the crosshair. Then use GetWindowRect to get the position of the window. Simple subtract the left coordinate of the window from all x coordinates you want to translate to the window and add them to translate them to screen coordinates. Do the same with the top coordinate for y.

Offline scar

  • Leecher
  • Posts: 9
  • Rep: 0
  • It's a freddytatorship.
    • View Profile
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #4 on: December 21, 2010, 09:27:56 pm »
<solved it>
Check accidental post below this one.

Thanks for the reply Freddy. I keep hitting problems with VB. Quick question, do you know how I can set a client window (like in scar)?

Use WindowFromPoint to get the window where you drop the crosshair. Then use GetWindowRect to get the position of the window. Simple subtract the left coordinate of the window from all x coordinates you want to translate to the window and add them to translate them to screen coordinates. Do the same with the top coordinate for y.
I've never had any experience with the WindowFromPoint function and I have no idea how to work with it. I created a new form to try to get used to it.
I came up with this:
Code: [Select]
Imports System.Runtime.InteropServices
Imports WindowFromPoint
Imports System.IntPtr
Imports System.Int32

Public Class mainform

    <DllImport("user32.dll", EntryPoint:="WindowFromPoint", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
    Public Shared Function WindowFromPoint(ByVal pt As POINTSTRUCT) As IntPtr

    End Function


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim r As New Point
        r = WindowFromPoint(New Point(MousePosition.X, MousePosition.Y))
        Me.Text = r.X & "," & r.Y

    End Sub
End Class

I'm having a problem though. "POINTSTRUCT" is not defined. Do you know the import or structure for it?

<edit>
I got it to sort of work. Each window has it's own number.
Code: [Select]
Imports System.Runtime.InteropServices
Imports WindowFromPoint
Imports System.IntPtr
Imports System.Int32


Public Class mainform

    <DllImport("user32.dll")> _
Public Shared Function WindowFromPoint(ByVal lpPoint As Point) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Public Shared Function GetCursorPos(ByRef lpPoint As Point) As Boolean
    End Function

    Public Shared Function GetWindowUnderCursor() As IntPtr
        Dim ptCursor As New Point()

        If Not (GetCursorPos(ptCursor)) Then
            Return IntPtr.Zero
        End If

        Return WindowFromPoint(ptCursor)
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim r
        r = GetWindowUnderCursor()
        Me.Text = r.ToString


    End Sub
End Class

Do you how get "r" into coordinates/rectangle?

<edit, edit>
I've also tried this: (but it only gives to a boolean) which always = true.
Code: [Select]
Imports System.Runtime.InteropServices
Imports WindowFromPoint
Imports System.IntPtr
Imports System.Int32


Public Class mainform

    <DllImport("user32.dll")> _
Private Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef rect As Rectangle) As Boolean
    End Function

    <DllImport("user32.dll")> _
    Public Shared Function WindowFromPoint(ByVal lpPoint As Point) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Public Shared Function GetCursorPos(ByRef lpPoint As Point) As Boolean
    End Function

    Public Shared Function GetWindowUnderCursor() As IntPtr
        Dim ptCursor As New Point()

        If Not (GetCursorPos(ptCursor)) Then
            Return IntPtr.Zero
        End If

        Return WindowFromPoint(ptCursor)
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim r
        r = GetWindowUnderCursor()
        Me.Text = r.ToString

        Dim c
        Dim a As Rectangle

        c = GetWindowRect(r, a)
        Me.Text = c.ToString


    End Sub
End Class
« Last Edit: December 21, 2010, 10:49:58 pm by scar »
Take a look at Project Scout Hawk. It's a Scar- Like Program created by me!

Freddy1990.com

Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #4 on: December 21, 2010, 09:27:56 pm »

Offline scar

  • Leecher
  • Posts: 9
  • Rep: 0
  • It's a freddytatorship.
    • View Profile
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #5 on: December 21, 2010, 10:34:42 pm »
<solved it>
This was an accidental post; but none the less, I've solved it.
Now, I can get the coordinates of the forms top, left, bottom, and right.
Thanks for the help, mate.

<another problem>
I've made it so when you select the client window button and drag, it basically does what scar does; but the problem is, that I cannot figure out how to remove the rectangle that is drawn. I know the Dispose() method, but VB will not do it due to it not being on the VB form itself. Any ideas on how to fix this?
« Last Edit: December 22, 2010, 05:39:02 am by scar »
Take a look at Project Scout Hawk. It's a Scar- Like Program created by me!

Offline Freddy

  • Owner
  • *****
  • Posts: 2616
  • Rep: 19
    • MSN Messenger - freddy1990@gmail.com
    • AOL Instant Messenger - Freddy199O
    • View Profile
    • Email
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #6 on: December 23, 2010, 05:24:27 am »
Types are irrelevant when programming as long as they have the same size and arrangement of members, you can use any point type with x and y as fields.

http://pinvoke.net/default.aspx/user32/WindowFromPoint.html

I'll write up an example for you when I get home.

Freddy1990.com

Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #6 on: December 23, 2010, 05:24:27 am »

Offline scar

  • Leecher
  • Posts: 9
  • Rep: 0
  • It's a freddytatorship.
    • View Profile
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #7 on: December 25, 2010, 02:58:11 am »
Thanks for help so far.
I've sent you the source code; just so you can see how it's going to far :P.

Also, on another interesting topic, do you have any idea how to read text from an image? I've tried removing the background (which is white) and attempting to read the black text left over (by finding the first black pixel, and finding out the shape it's making. So far, it's turning out miserably. I'm trying to do it without using any 3rd part OCR scripts.
Take a look at Project Scout Hawk. It's a Scar- Like Program created by me!

Offline Freddy

  • Owner
  • *****
  • Posts: 2616
  • Rep: 19
    • MSN Messenger - freddy1990@gmail.com
    • AOL Instant Messenger - Freddy199O
    • View Profile
    • Email
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #8 on: December 25, 2010, 04:46:03 am »
Heh, you should start off with color and bitmap finding first, OCR is a lot more complex to write :) I'll write up that example for you now, I didn't have time yesterday. And I'll check out the program :)

EDIT: Looks ok, but it needs a lot of work, you can seriously simplify most of the interface. I published the client selection example to my blog: http://ibeblog.com/?p=212
You should look into RemObjects Script for scripting, it's JavaScript based scripting: http://www.remobjects.com/script.aspx
« Last Edit: December 25, 2010, 05:31:44 am by Freddy1990 »

Offline scar

  • Leecher
  • Posts: 9
  • Rep: 0
  • It's a freddytatorship.
    • View Profile
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #9 on: December 25, 2010, 05:30:37 am »
Haha, thanks mate.
I'm basically making the framework first, so all the commands are ready to go before actually designing the application properly (What it looks like now is temporary).
Thanks again.

<edit>
I'm working on SH1.4 which will have all the different methods I have made in one application.

<edit edit>
I downloaded the first example code and got the following error upon startup:
Code: [Select]
   Failed to parse the following code: Me.components = New System.ComponentModel.Container() The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again.     
 
 
 
     
Instances of this error (1) 
 
1.   Hide Call Stack
 
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.CreateQuoteExpression(XmlElementData xmlElement)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.XmlElementData.get_CodeDomElement()
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.EndElement(String prefix, String name, String urn)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.Parse(XmlReader reader)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.ParseXml(String xmlStream, CodeStatementCollection statementCollection, String fileName, String methodName)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnMethodPopulateStatements(Object sender, EventArgs e)
at System.CodeDom.CodeMemberMethod.get_Statements()
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload) 
Due to this, I cannot view the programs code.
« Last Edit: December 25, 2010, 05:47:24 am by scar »
Take a look at Project Scout Hawk. It's a Scar- Like Program created by me!

Offline Freddy

  • Owner
  • *****
  • Posts: 2616
  • Rep: 19
    • MSN Messenger - freddy1990@gmail.com
    • AOL Instant Messenger - Freddy199O
    • View Profile
    • Email
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #10 on: December 25, 2010, 07:37:21 am »
I think you're probably using an older version of vb, I'm using visual studio 2010

Offline scar

  • Leecher
  • Posts: 9
  • Rep: 0
  • It's a freddytatorship.
    • View Profile
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #11 on: December 25, 2010, 10:09:21 pm »
That's true. I'm using VS2008.
Anyways, I will give you the new version when I've finished it.
Take a look at Project Scout Hawk. It's a Scar- Like Program created by me!

Offline Freddy

  • Owner
  • *****
  • Posts: 2616
  • Rep: 19
    • MSN Messenger - freddy1990@gmail.com
    • AOL Instant Messenger - Freddy199O
    • View Profile
    • Email
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #12 on: December 26, 2010, 02:59:04 am »
The important part is the source code anyway, it's just a form with a crosshair in a picturebox, 2 labels and a timer:
Code: [Select]
Public Class fSelWnd

    Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As Point) As Boolean
    Declare Function WindowFromPoint Lib "user32.dll" (ByVal Point As Point) As IntPtr
    Declare Function GetWindowRect Lib "user32.dll" (ByVal hWnd As IntPtr, ByRef lpRect As Rectangle) As Boolean

    Dim SelWnd As IntPtr = 0
    Dim WndRect As Rectangle = New Rectangle(0, 0, 0, 0)

    Private Sub ToClient(ByRef p As Point)
        p.X -= WndRect.Left
        p.Y -= WndRect.Top
    End Sub

    Private Sub ToScreen(ByRef p As Point)
        p.X += WndRect.Left
        p.Y += WndRect.Top
    End Sub

    Private Sub pbCrossHair_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pbCrossHair.MouseDown
        pbCrossHair.Visible = False
        Cursor.Current = Cursors.Cross
    End Sub

    Private Sub pbCrossHair_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pbCrossHair.MouseUp
        Dim p As Point
        GetCursorPos(p)
        SelWnd = WindowFromPoint(p)
        lblWindow.Text = "Selected Window: " + SelWnd.ToString()
        GetWindowRect(SelWnd, WndRect)
        Cursor.Current = Cursors.Default
        pbCrossHair.Visible = True
    End Sub

    Private Sub tmrCoords_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrCoords.Tick
        Dim p As Point
        GetCursorPos(p)
        ToClient(p)
        lblCoords.Text = "Coords: (" + p.X.ToString() + ", " + p.Y.ToString() + ")"
    End Sub

End Class

Offline scar

  • Leecher
  • Posts: 9
  • Rep: 0
  • It's a freddytatorship.
    • View Profile
Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #13 on: December 26, 2010, 05:58:30 am »
Thanks for the code. It works very well.
Will use.
Take a look at Project Scout Hawk. It's a Scar- Like Program created by me!

Freddy1990.com

Re: SCAR-LIKE Program - SCOUT HAWK
« Reply #13 on: December 26, 2010, 05:58:30 am »