Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apologies For opening an Issue: Fantastic Script - Thankyou #7

Open
baggypants71 opened this issue Feb 26, 2019 · 46 comments
Open

apologies For opening an Issue: Fantastic Script - Thankyou #7

baggypants71 opened this issue Feb 26, 2019 · 46 comments

Comments

@baggypants71
Copy link

Hi Leguims,
You clearly know how to use the PS4Macro library by the looks of your script for it!. Is there any chnce you could help me out on my project. I need some direction on a few issues I'm having. Using PS4Macro library how do I add a delay between each button press?. I know you can use "int waitDelay = 100;" but this would apply the same value to all presses. I wish to assign a value to each button individually.

Once again, thanks for sharing your talent for scripting and coding!.

@leguims
Copy link
Owner

leguims commented Feb 26, 2019

Thanks for All.

You can do like in this file : PS4Macro.PES2018Lite/MyClub/Match/AcceptNewContract.cs

using System.Threading;
...
         // Cost and kind of money
         while (!script.MatchTemplate(script.CaptureFrame(), extension2Focus, 98))
         {
             Thread.Sleep(1000);
             Log.LogMessage(Name, "Waiting for 'Pay with GP money'");
         }

@baggypants71
Copy link
Author

Thanks for All.

You can do like in this file : PS4Macro.PES2018Lite/MyClub/Match/AcceptNewContract.cs

using System.Threading;
...
         // Cost and kind of money
         while (!script.MatchTemplate(script.CaptureFrame(), extension2Focus, 98))
         {
             Thread.Sleep(1000);
             Log.LogMessage(Name, "Waiting for 'Pay with GP money'");
         }

I will give this a go now!. Thank you so much for replying!. I'm in Australia so apologies for any delay in replying.

@baggypants71
Copy link
Author

Using System Threading works great!, thank you so much!. I seem to be having another problem and wondered if you could take a look for me. When an image is detected and the interactionMenu script starts, it skips this part of the script:

script.Press(new DualShockState() { Cross = true });
Thread.Sleep(2500);
script.Press(new DualShockState() { Triangle = true });
Thread.Sleep(2000);
script.Press(new DualShockState() { DPad_Down = true });


Here is the full InterationMenu.cs script:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using PS4MacroAPI;

namespace ExampleScript
{
class InteractionMenu : Scene
{
public override string Name => "Interaction Menu";

    public static RectMap HeaderBar = new RectMap()
    {
        X = 349,
        Y = 510,
        Width = 24,
        Height = 15,
        Hash = 9160074286331952511
    };

    public override bool Match(ScriptBase script)
    {
        return script.MatchTemplate(HeaderBar, 90);
    }
    public override void OnMatched(ScriptBase script)
    {
     
        script.Press(new DualShockState() { Cross = true });
        Thread.Sleep(1000);
        script.Press(new DualShockState() { DPad_Down = true });
        Thread.Sleep(1000);
        script.Press(new DualShockState() { Cross = true }); 
        Thread.Sleep(1000);
        script.Press(new DualShockState() { DPad_Up = true });
        Thread.Sleep(2000);
        script.Press(new DualShockState() { Cross = true }); 
        Thread.Sleep(2500);
        script.Press(new DualShockState() { Triangle = true }); 
        Thread.Sleep(2000);
        script.Press(new DualShockState() { DPad_Down = true });

    }

Any help would be most gratefully received.

@leguims
Copy link
Owner

leguims commented Feb 26, 2019

That's ok to communicate in this issue. No problem.
Australia is really far from here, Yeah ! :-)

For your issue, are sure that it skip last Cross/Triangle/DPad_Down or it has no effect on your game ?
I don't see any error in your code.

PS4Macro.PES2018Lite/MyClub/Sim/ManageTeamScreen.cs
In ths example, I need to delay only when I repeat the same key (like Cross + Cross), then I need to wait before the repeated key. You do not need to wait as long as 2 seconds between each key.

Are you sure that when you press key, PS4 is waiting for this key ?

Good luck to find the bug. Don't worry to reply in time. :)

@baggypants71
Copy link
Author

I think it may be analyzing and finding the same hashed image in more than one screen update, this is the only explanation I can think of why its repeating part of the button press. I will have to run some tests. Is there a way to turn the analyzing off once its found the correct image and then turn it back on once the button sequence has been completed?.

@leguims
Copy link
Owner

leguims commented Feb 26, 2019

I do not know if the matching process is looking for hash while you process a treatment.

May be you can improve the match by combination of detail of screenshot. Then you match by :

Return script.MatchTemplate(HeaderBarDetail1, 90) and script.MatchTemplate(HeaderBarDetail2, 90);

In this case, you have to give XY Offset in HeaderBarDetailX and give the XY size of detail.

Or you can reduce the sleep instructions to achieve treatment before the screen change.

@baggypants71
Copy link
Author

Hi Leguims, Could you tell me how I create more than one image search. for example:

class InteractionMenu : Scene
{
public override string Name => "Interaction Menu";

    private static RectMap LiveSearch = new RectMap()
    {
        X = 238,
        Y = 200,
        Width = 120,
        Height = 17,
        Hash = 9187061906611961983
    };

    private static RectMap BiddingOption = new RectMap()
    {
        X = 344,
        Y = 234,
        Width = 97,
        Height = 17,
        Hash = 1266085483478784
    };

    public override bool Match(ScriptBase script)

    {
        return script.MatchTemplate(LiveSearch, 98);
    }
    public override void OnMatched(ScriptBase script)
    {
        script.Press(new DualShockState() { Cross = true }); // X on Live Search Result
        Thread.Sleep(1000);

Both RectMaps are on different pages, I wish the script to react to each one differently ( private static RectMap LiveSearch = new RectMap() Causes script.Press(new DualShockState() { Cross = true }); and
private static RectMap BiddingOption = new RectMap() Causes Dpad_Down.

Appreciate your help!

@baggypants71
Copy link
Author

baggypants71 commented Feb 27, 2019

I do notre know if the matching process is looking for hash while you process a treatment.

May be you can improve the match by combination of detail of screenshots. Then you match by :

Return script.MatchTemplate(HeaderBarDetail1, 90) and script.MatchTemplate(HeaderBarDetail2, 90);

In this case, you have to give XY Offset in HeaderBarDetailX ans give the XY size of detail.

Or you can reduce the sleeps instructions to achieve treatment before the screen change.

I found out that the interaction script is running through a second time because it returns to the original screen, and the matching process picks up the same hash. Is there a way to either bypass or ignore the second time it detects it?.

@baggypants71
Copy link
Author

Hi, I think I found the solution to one problem:

private static RectMap PurchaseItem = new RectMap()
{
X = 375,
Y = 328,
Width = 105,
Height = 25,
Hash = 140185576603648
};

    public override bool Match(ScriptBase script)

    {
        return script.MatchTemplate(Search, 98)
        || script.MatchTemplate(BOption, 98)
        || script.MatchTemplate(PItem, 98);
    }
    public override void OnMatched(ScriptBase script)
    {
        script.Press(new DualShockState() { Cross = true }); // X on Search Result
        Thread.Sleep(2000);

        script.MatchTemplate(BOption, 98);

        script.Press(new DualShockState() { DPad_Down = true });
        Thread.Sleep(2000);

        script.MatchTemplate(PItem, 98);

        script.Press(new DualShockState() { DPad_Up = true });
        Thread.Sleep(5000);

Is this the way to do it?, it seems to work.

@baggypants71
Copy link
Author

I don't think the above script is reacting to the Hashes, so I think I need help :)

@leguims
Copy link
Owner

leguims commented Feb 27, 2019

You can combine many details of a screenshot to prevent "miss match" on many different pages. By this way, you use AND between each HASH you use.
example : PS4Macro.PES2018Lite/MyClub/Sim/ManageTeamScreen.cs

You can use the same treatment for different pages, in this case, you use OR between each HASH you use.
example : your post

If you need to memorize that you already process a treatment, the easier way is to memorize it in variable like a boolean.

Public static bool HeaderBarDone = False;
...
public override bool Match(ScriptBase script)
    {
        if(!HeaderBarDone)
                return script.MatchTemplate(Search, 98)
                || script.MatchTemplate(BOption, 98)
                || script.MatchTemplate(PItem, 98);
        else
                return False;
    }
    public override void OnMatched(ScriptBase script)
    {
        HeaderBarDone = True;
        ...
    }

@baggypants71
Copy link
Author

baggypants71 commented Mar 1, 2019

Hi Leguims, Could you show me where in my script I should put:

Public static bool HeaderBarDone = False;
public override bool Match(ScriptBase script)
    {
        if(!HeaderBarDone)
         
        else
                return False;
    }
    public override void OnMatched(ScriptBase script)
    {
        HeaderBarDone = True;

Here is my Script:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using PS4MacroAPI;

namespace PS4Macro
{
    class InteractionMenu : Scene
    {
        public override string Name => "Interaction Menu";

        public static RectMap LiveSearch = new RectMap()
        {
            X = 239,
            Y = 199,
            Width = 120,
            Height = 18,
            Hash = 9223090703630925951
        };

        public static RectMap AssignNow = new RectMap()
        {
            X = 287,
            Y = 317,
            Width = 428,
            Height = 47,
            Hash = 35887505487722528
        };

        public static RectMap MainMenu = new RectMap()
        {
            X = 294,
            Y = 234,
            Width = 62,
            Height = 28,
            Hash = 9169114436558946303
        };

        public static RectMap NoResult = new RectMap()
        {
            X = 289,
            Y = 349,
            Width = 46,
            Height = 21,
            Hash = 18129295318662912
        };

        public static RectMap PlaceOnTL = new RectMap()
        {
            X = 372,
            Y = 231,
            Width = 129,
            Height = 24,
            Hash = 17802464409370431
        };

        public static RectMap BackToMENU1 = new RectMap()
        {
            X = 67,
            Y = 231,
            Width = 112,
            Height = 26,
            Hash = 213852855729920
        };

        public override bool Match(ScriptBase script)
        {
            return script.MatchTemplate(LiveSearch, 90)
            || script.MatchTemplate(AssignNow, 90)
            || script.MatchTemplate(MainMenu, 98)
            || script.MatchTemplate(NoResult, 98)
            || script.MatchTemplate(PlaceOnTL, 98)
            || script.MatchTemplate(BackToMENU1, 98);
        }


        public override void OnMatched(ScriptBase script)
        {

            if (script.MatchTemplate(LiveSearch, 90)) // Live Search Result
            {

                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { DPad_Down = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { DPad_Up = true });
                Thread.Sleep(1000);
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(1000);
            }
            else if (script.MatchTemplate(MainMenu, 98)) // Main Menu Loop
            {
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { DPad_Left = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { Circle = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { Triangle = true });
                Thread.Sleep(10);
            }
            else if (script.MatchTemplate(NoResult, 98)) // Main Menu Loop - No Search Result
            {
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(100);
            }
            else if (script.MatchTemplate(AssignNow, 90)) 
            {
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(10);
            }
            else if (script.MatchTemplate(PlaceOnTL, 98))
            {
                script.Press(new DualShockState() { Triangle = true });
                Thread.Sleep(3500);
                script.Press(new DualShockState() { Circle = true });
                Thread.Sleep(10);
            }
            else if (script.MatchTemplate(BackToMENU1, 98))
            {
                script.Press(new DualShockState() { DPad_Down = true });
                Thread.Sleep(1000);
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(1000);
                script.Press(new DualShockState() { DPad_Down = true });
                Thread.Sleep(1000);
                script.Press(new DualShockState() { Circle = true });
                Thread.Sleep(100);
            }
        }



    }

}

@baggypants71
Copy link
Author

I have two screens the same, I just want it to react once on the first loop.

@leguims
Copy link
Owner

leguims commented Mar 1, 2019

Hi Baggy,
Sorry to not answer to all your questions, but I did not have time those last days.
And now, I am going on holydays.

Good Luck, i'm sure you will improve your program and your skill with C#.

I'll be back in one week.

@leguims
Copy link
Owner

leguims commented Mar 1, 2019

You are brave to learn C# with PS4Macro.

@baggypants71
Copy link
Author

Thank you. I will wait for you to return from off your holiday. Have a good time.

@MysteryDash
Copy link

Why not read a short book on C# like C# Succinctly. It's for C# 6.0 but it's good enough for you to get started quickly.
(I'm not answering your question directly because it won't help you learn.)

@baggypants71
Copy link
Author

Why not read a short book on C# like C# Succinctly. It's for C# 6.0 but it's good enough for you to get started quickly.
(I'm not answering your question directly because it won't help you learn.)

Thanks for the reply. I have C# 7.0 In A Nutshell which has taught me many of the fundamentals. However from time to time we all need a little help for one reason or another. Considering I'm a Graphic Artist by profession and only been learning C# for the past week I don't think I'm doing too badly.

@baggypants71
Copy link
Author

If I want to search for an image anywhere instead of x = .... y = .... , how would I do this?

@leguims
Copy link
Owner

leguims commented Mar 7, 2019

You cannot do this or you change x;y yourself before the matching method.

@baggypants71
Copy link
Author

Is it possible to do it via C#?

@leguims
Copy link
Owner

leguims commented Mar 7, 2019

Make 2 for loop and inside them, you modify the x;y values.
1 loop for y and inside 1 loop for x.

It will be very slow. This is probably not a good idea.

@baggypants71
Copy link
Author

Make 2 for loop and inside them, you modify the x;y values.
1 loop for y and inside 1 loop for x.

It will be very slow. This is probably not a good idea.

How would I write the code for that to try?

@baggypants71
Copy link
Author

baggypants71 commented Mar 7, 2019

Hi Again!
How did you get the Color code? from your script:

private static PixelMap clubHouseSelected = new PixelMap()
        {
            ID = "clubHouseSelected",
            X = 315,
            Y = 168,
            Color = 0xbcc4c4

I used photoshop color picker which gives me "e53212" for the color, however I get an error saying "e53212" does not exist in the current context...

@baggypants71
Copy link
Author

Hi Again!
How did you get the Color code? from your script:

private static PixelMap clubHouseSelected = new PixelMap()
        {
            ID = "clubHouseSelected",
            X = 315,
            Y = 168,
            Color = 0xbcc4c4

I used photoshop color picker which gives me "e53212" for the color, however I get an error saying "e53212" does not exist in the current context...

@baggypants71
Copy link
Author

I just figured out I have to include "0x" at the start - 0xe53212

@leguims
Copy link
Owner

leguims commented Mar 9, 2019

@baggypants71 you have to prefix by 0x (zero and x) the color value.

@leguims
Copy link
Owner

leguims commented Mar 9, 2019

Ok, next Time, I will read every comment before answer.

@leguims leguims reopened this Mar 9, 2019
@baggypants71
Copy link
Author

Thanks for reopening it Leguims! 👍

@baggypants71
Copy link
Author

I want the Thread.sleep method value to be randomized between a range (1-3seconds) how would I implement that into my script?. Help is most appreciated @leguims

            if (script.MatchTemplate(screenone, 90))
            {
                script.Press(new DualShockState() { Circle = true });
                Thread.Sleep(100);
            }

            else if (script.MatchTemplate(screentwo, 90))
            {
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(1000);
                script.Press(new DualShockState() { Square = true });
                Thread.Sleep(1000);
            }

            else if (script.MatchTemplate(screenthree, 90))
            {
                script.Press(new DualShockState() { Triangle = true });
                Thread.Sleep(1000);
                script.Press(new DualShockState() { Square = true });
                Thread.Sleep(1000);
        }



    }

}

@leguims
Copy link
Owner

leguims commented Mar 9, 2019

You already ask it on another thread. The answer is with the question.

OCR + random

@baggypants71
Copy link
Author

@leguims Hi Again!,

If I want the script to do something else if it does not find the following, how would I do it?:

            else if (script.MatchTemplate(Position01, 90))
            {
                script.Press(new DualShockState() { DPad_Right = true });
                Thread.Sleep(100);
            }

            else if (script.MatchTemplate(Position02, 90))
            {
                script.Press(new DualShockState() { DPad_Right = true });
                Thread.Sleep(100);

            }

            else if (script.MatchTemplate(Position03, 90))
            {
                script.Press(new DualShockState() { DPad_Right = true });
                Thread.Sleep(100);

            }

I want it to do something else if it returns false to any of the Positions.
Would I write:

else if (script.MatchTemplate(Position03, 90)) = False:
 {
                Do something Else
                Thread.Sleep(100);

            }

Would I need to change this part of the script?:

public override bool Match(ScriptBase script)
        {
            return script.MatchTemplate(TMt, 95)
            || script.MatchTemplate(NoResult, 95)
            || script.MatchTemplate(Position01, 90)
            || script.MatchTemplate(Position02, 90)
            || script.MatchTemplate(Position03, 90);

        }

@leguims
Copy link
Owner

leguims commented Mar 10, 2019

If matching is false on this method, the treatment method won't be called.

public override bool Match(ScriptBase script)

So, you cannot apply default treatment. You can write it, but it will not executed.

@baggypants71
Copy link
Author

If matching is false on this method, the treatment method won't be called.

public override bool Match(ScriptBase script)

So, you cannot apply default treatment. You can write it, but it will not executed.

So what would I need to do to make it do something else if Position 1,2,3 is not found?, or is this not possible?

@baggypants71
Copy link
Author

Do the images that have been cropped and hashed inside PS4Macro_0_5_2 / screenshots folder, do they have to be kept, or is it ok to delete them?.

@leguims
Copy link
Owner

leguims commented Mar 11, 2019

Do the images that have been cropped and hashed inside PS4Macro_0_5_2 / screenshots folder, do they have to be kept, or is it ok to delete them?.

Images is used only to have checksum and write it on C#.
It is usefull to help someone to translate to another langage by showing screenshot to capture and checksum to update.

@leguims
Copy link
Owner

leguims commented Mar 11, 2019

If matching is false on this method, the treatment method won't be called.
public override bool Match(ScriptBase script)
So, you cannot apply default treatment. You can write it, but it will not executed.

So what would I need to do to make it do something else if Position 1,2,3 is not found?, or is this not possible?

Yes it is possible, but I won't encourage this.

2 cases :

  1. You can add a "Position04" and you add it to "bool Match(ScriptBase script)" and add a new "else if" with it. This is a good solution and your programm will be efficient to execute.
  2. You cannot add a "Position04". In this case, you dont really know on which screen you will execute your default treatment. If you really want to do it, you have to inconditionnaly return "true" in "bool Match(ScriptBase script)". So the treatment method will be always launch on every screen, and the default treatment will always apply to all screen. I think this is a bad idea, but you technically can do it. I will probably mask other "bool Match(ScriptBase script)" of the other screen. Try it, and you will see that your program works only for Position 1, 2, 3 and default.

@baggypants71
Copy link
Author

If matching is false on this method, the treatment method won't be called.
public override bool Match(ScriptBase script)
So, you cannot apply default treatment. You can write it, but it will not executed.

So what would I need to do to make it do something else if Position 1,2,3 is not found?, or is this not possible?

Yes it is possible, but I won't encourage this.

2 cases :

1. You can add a "Position04" and you add it to "bool Match(ScriptBase script)" and add a new "else if" with it. This is a good solution and your programm will be efficient to execute.

2. You cannot add a "Position04". In this case, you dont really know on which screen you will execute your default treatment. If you really want to do it, you have to inconditionnaly return "true" in "bool Match(ScriptBase script)". So the treatment method will be always launch on every screen, and the default treatment will always apply to all screen. I think this is a bad idea, but you technically can do it. I will probably mask other "bool Match(ScriptBase script)" of the other screen. Try it, and you will see that your program works only for Position 1, 2, 3 and default.

The problem I have is that position 1,2,3 could be one of thousands of possible differences. I'm looking to make the program look for something other than what is normally in Position 1,2,3. I will upload some screenshots tomorrow (your evening!) to further explain.

bonne nuit! :)

@baggypants71
Copy link
Author

Hi leguims, I just tried using the Automation program "WinAutomation" with Remote Play. I was thinking that it would work but it doesn't. What is it that allows PS4Macro to work with Remote Play but not other Automation programs?.

@baggypants71
Copy link
Author

@leguims You wrote:

If you need to memorize that you already process a treatment, the easier way is to memorize it in variable like a boolean.

...
public override bool Match(ScriptBase script)
    {
        if(!HeaderBarDone)
                return script.MatchTemplate(Search, 98)
                || script.MatchTemplate(BOption, 98)
                || script.MatchTemplate(PItem, 98);
        else
                return False;
    }
    public override void OnMatched(ScriptBase script)
    {
        HeaderBarDone = True;
        ...
    }

Could you explain further where in the program these statements should go. I have tried, but its returning errors?.

@baggypants71
Copy link
Author

baggypants71 commented Mar 17, 2019

I think I should explain better!.

I have an identical image that appears on two pages. I wish the script to only react once to the image and then ignore the same image upon the second detection on another page. Once it has done that I want it to reset so the process is repeated.

namespace testpad
{
    class InteractionMenu: Scene
    {
        public override string Name => "InteractionMenu";

        public static RectMap imageone = new RectMap()
        {
            X = 239,
            Y = 199,
           Width = 125,
           Height = 18
           Hash = 3689764529392
        };
        public static RectMap imagetwo = new RectMap()
        {
            X = 217,
            Y = 317,
            Width = 428,
            Height = 12
            Hash = 232535847392
        };
        public static RectMap imagethree = new RectMap()
        {
            X = 217,
            Y = 317,
           Width = 428,
           Height = 12
           Hash = 3425335347392
        };
         public static imagefour = new RectMap()
        {
            X = 282,
            Y = 317,
           Width = 233,
           Height = 22
           Hash = 3434658734392
        };
        public override bool Match(ScriptBase script)
        {
            return script.MatchTemplate(imageone), 90),
                || script.MatchTemplate(screentwo, 90)
                || script.MatchTemplate(imagethree), 90), 
                || script.MatchTemplate(imagefour), 90);

        }
        public override void OnMatched(ScriptBase script)
        {
            if (script.MatchTemplate(imageone, 90))
            {
                script.Press(new DualShockState() { Square = true });
                Thread.Sleep(100);
            }
            else if (script.MatchTemplate(imagetwo, 90))
            {
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(1000);
            }
            else if (script.MatchTemplate(imagethree, 90))
            {
                script.Press(new DualShockState() { Circle = true });
                Thread.Sleep(1000);
            }
            else if script.MatchTemplate(imagefour, 90))
            {
                script.Press(new DualShockState() { Triangle = true });
                Thread.Sleep(1000);
            }
    }

@baggypants71
Copy link
Author

@leguims I am still confused:

You wrote:

If you need to memorize that you already process a treatment, the easier way is to memorize it in variable like a boolean.

...
public override bool Match(ScriptBase script)
{
if(!HeaderBarDone)
return script.MatchTemplate(Search, 98)
|| script.MatchTemplate(BOption, 98)
|| script.MatchTemplate(PItem, 98);
else
return False;
}
public override void OnMatched(ScriptBase script)
{
HeaderBarDone = True;
...
}

And here is my new script with what you said to do but it does not work, I am doing something wrong. Can you please help, Its so frustrating!.

namespace PS4Macro
{
    class InteractionMenu : Scene
    {
        public override string Name => "Interaction Menu";

        public static RectMap TM = new RectMap()
        {
            X = 65,
            Y = 400,
            Width = 69,
            Height = 30,
            Hash = 18142489458188033
        };

        public static RectMap NoResult = new RectMap()
        {
            X = 289,
            Y = 349,
            Width = 46,
            Height = 21,
            Hash = 18129295318662912
        };

        public static RectMap LiveSearch = new RectMap()
        {
            X = 239,
            Y = 199,
            Width = 120,
            Height = 18,
            Hash = 9223090703630925951
        };

        
        public static bool LiveSearch = false;
       
        public override bool Match(ScriptBase script)
        {
            if(!LiveSearch)
                return script.MatchTemplate(TM, 90)
                || script.MatchTemplate(NoResult, 90);

            else
                return false;



        }



        public override void OnMatched(ScriptBase script)
        {
            LiveSearch = true;

            //Stage One - Keep searching until Item found
            if (script.MatchTemplate(TM, 90))
            {
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(500);
                script.Press(new DualShockState() { DPad_Left = true });
                Thread.Sleep(500);
                script.Press(new DualShockState() { Circle = true });
                Thread.Sleep(500);
                script.Press(new DualShockState() { Triangle = true });
                Thread.Sleep(500);
            }

            else if (script.MatchTemplate(NoResult, 90)) 
            {
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(500);
            }

            // Stage Two - Found Item
            else if (script.MatchTemplate(LiveSearch, 85)) 

            {

                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(1500);
                script.Press(new DualShockState() { DPad_Down = true }); 
                Thread.Sleep(1500);
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(1500);
                script.Press(new DualShockState() { Cross= true });
                Thread.Sleep(1500);

            }

        }   
    }
}

@leguims
Copy link
Owner

leguims commented Jun 20, 2019

Hi leguims, I just tried using the Automation program "WinAutomation" with Remote Play. I was thinking that it would work but it doesn't. What is it that allows PS4Macro to work with Remote Play but not other Automation programs?.

Sorry, I do not know, i'm just a PS4Macro user.

@leguims
Copy link
Owner

leguims commented Jun 20, 2019

I add "Public static bool xxxxDone = False;"
and I modified these methods : Match and OnMatched

Here is your Script modified:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using PS4MacroAPI;

namespace PS4Macro
{
    class InteractionMenu : Scene
    {
        public override string Name ="Interaction Menu";

        public static RectMap LiveSearch = new RectMap()
        {
            X = 239,
            Y = 199,
            Width = 120,
            Height = 18,
            Hash = 9223090703630925951
        };
       Public static bool LiveSearchDone = False; // Add this

        public static RectMap AssignNow = new RectMap()
        {
            X = 287,
            Y = 317,
            Width = 428,
            Height = 47,
            Hash = 35887505487722528
        };
       Public static bool AssignNowDone = False; // Add this

        public static RectMap MainMenu = new RectMap()
        {
            X = 294,
            Y = 234,
            Width = 62,
            Height = 28,
            Hash = 9169114436558946303
        };
       Public static bool MainMenuDone = False; // Add this

        public static RectMap NoResult = new RectMap()
        {
            X = 289,
            Y = 349,
            Width = 46,
            Height = 21,
            Hash = 18129295318662912
        };
       Public static bool NoResultDone = False; // Add this

        public static RectMap PlaceOnTL = new RectMap()
        {
            X = 372,
            Y = 231,
            Width = 129,
            Height = 24,
            Hash = 17802464409370431
        };
       Public static bool PlaceOnTLDone = False; // Add this

        public static RectMap BackToMENU1 = new RectMap()
        {
            X = 67,
            Y = 231,
            Width = 112,
            Height = 26,
            Hash = 213852855729920
        };
       Public static bool BackToMENU1Done = False; // Add this

        public override bool Match(ScriptBase script) // Modify all the method
        {
            if(!LiveSearchDone)
                return script.MatchTemplate(LiveSearch, 90);
            if(!AssignNowDone)
                return script.MatchTemplate(AssignNow, 90);
            if(!MainMenuDone)
                return script.MatchTemplate(MainMenu, 98);
            if(!NoResultDone)
                return script.MatchTemplate(NoResult, 98);
            if(!PlaceOnTLDone)
                return script.MatchTemplate(PlaceOnTL, 98);
            if(!BackToMENU1Done)
                return script.MatchTemplate(BackToMENU1, 98);
            
            return False;
        }


        public override void OnMatched(ScriptBase script) // Modify if condition + set to true boolean before treatment
        {
            if (!LiveSearchDone && (script.MatchTemplate(LiveSearch, 90))) // Live Search Result
            {
                LiveSearchDone = True;
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { DPad_Down = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { DPad_Up = true });
                Thread.Sleep(1000);
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(1000);
            }
            else if (!MainMenuDone && (script.MatchTemplate(MainMenu, 98))) // Main Menu Loop
            {
                MainMenuDone = True;
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { DPad_Left = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { Circle = true });
                Thread.Sleep(100);
                script.Press(new DualShockState() { Triangle = true });
                Thread.Sleep(10);
            }
            else if (!NoResultDone && (script.MatchTemplate(NoResult, 98))) // Main Menu Loop - No Search Result
            {
                NoResultDone = True;
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(100);
            }
            else if (!AssignNowDone && (script.MatchTemplate(AssignNow, 90)) 
            {
                AssignNowDone = True;
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(10);
            }
            else if (!PlaceOnTLDone && (script.MatchTemplate(PlaceOnTL, 98)))
            {
                PlaceOnTLDone = True;
                script.Press(new DualShockState() { Triangle = true });
                Thread.Sleep(3500);
                script.Press(new DualShockState() { Circle = true });
                Thread.Sleep(10);
            }
            else if (!BackToMENU1Done && (script.MatchTemplate(BackToMENU1, 98))
            {
                BackToMENU1Done = True;
                script.Press(new DualShockState() { DPad_Down = true });
                Thread.Sleep(1000);
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(1000);
                script.Press(new DualShockState() { DPad_Down = true });
                Thread.Sleep(1000);
                script.Press(new DualShockState() { Circle = true });
                Thread.Sleep(100);
            }
        }
    }
}

@leguims
Copy link
Owner

leguims commented Jun 20, 2019

@leguims I am still confused:

You wrote:

If you need to memorize that you already process a treatment, the easier way is to memorize it in variable like a boolean.

...
public override bool Match(ScriptBase script)
{
if(!HeaderBarDone)
return script.MatchTemplate(Search, 98)
|| script.MatchTemplate(BOption, 98)
|| script.MatchTemplate(PItem, 98);
else
return False;
}
public override void OnMatched(ScriptBase script)
{
HeaderBarDone = True;
...
}

And here is my new script with what you said to do but it does not work, I am doing something wrong. Can you please help, Its so frustrating!.

namespace PS4Macro
{
    class InteractionMenu : Scene
    {
        public override string Name => "Interaction Menu";

        public static RectMap TM = new RectMap()
        {
            X = 65,
            Y = 400,
            Width = 69,
            Height = 30,
            Hash = 18142489458188033
        };

        public static RectMap NoResult = new RectMap()
        {
            X = 289,
            Y = 349,
            Width = 46,
            Height = 21,
            Hash = 18129295318662912
        };

        public static RectMap LiveSearch = new RectMap()
        {
            X = 239,
            Y = 199,
            Width = 120,
            Height = 18,
            Hash = 9223090703630925951
        };

        
        public static bool LiveSearch = false;
       
        public override bool Match(ScriptBase script)
        {
            if(!LiveSearch)
                return script.MatchTemplate(TM, 90)
                || script.MatchTemplate(NoResult, 90);

            else
                return false;



        }



        public override void OnMatched(ScriptBase script)
        {
            LiveSearch = true;

            //Stage One - Keep searching until Item found
            if (script.MatchTemplate(TM, 90))
            {
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(500);
                script.Press(new DualShockState() { DPad_Left = true });
                Thread.Sleep(500);
                script.Press(new DualShockState() { Circle = true });
                Thread.Sleep(500);
                script.Press(new DualShockState() { Triangle = true });
                Thread.Sleep(500);
            }

            else if (script.MatchTemplate(NoResult, 90)) 
            {
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(500);
            }

            // Stage Two - Found Item
            else if (script.MatchTemplate(LiveSearch, 85)) 

            {

                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(1500);
                script.Press(new DualShockState() { DPad_Down = true }); 
                Thread.Sleep(1500);
                script.Press(new DualShockState() { Cross = true });
                Thread.Sleep(1500);
                script.Press(new DualShockState() { Cross= true });
                Thread.Sleep(1500);

            }

        }   
    }
}

If you need to "keep searching" for stage 1, you have to set the boolean with the treatment to do when you find the "TM". Something looks like :

         public override void OnMatched(ScriptBase script)
         {
 
             //Stage One - Keep searching until Item found
             if (script.MatchTemplate(TM, 90))
             {
                 LiveSearch = true; // Set to true only if TM is found.
                 script.Press(new DualShockState() { Cross = true });
                 Thread.Sleep(500);
                 script.Press(new DualShockState() { DPad_Left = true });
                 Thread.Sleep(500);
                 script.Press(new DualShockState() { Circle = true });
                 Thread.Sleep(500);
                 script.Press(new DualShockState() { Triangle = true });
                 Thread.Sleep(500);
             }
 ...

Remember that when 'LiveSearch' is true, the 'match' method will always return 'false'. So, you will never execute again 'OnMatched' method.

If you need several step of treatment, you have to use several boolean variables. Each one is use to prevent previous treatment to not repeat and memorize what left to do.

@leguims
Copy link
Owner

leguims commented Jun 20, 2019

Sorry to answer so late, but I was in holydays and in my return have so much things to do. I hope it will help you and boost your motivation to finish your project. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants