├── _resources ├── Remapper.png ├── CmdShortcut.png ├── Screenshot_0_1_0.png ├── Screenshot_0_2_0.png ├── Screenshot_0_2_1.png ├── Screenshot_0_2_2.png ├── Screenshot_0_3_0.png ├── Screenshot_0_3_1.png ├── Screenshot_0_4_0.png ├── Screenshot_0_5_0.png ├── Screenshot_0_5_1.png ├── Screenshot_0_5_2.png └── EmulateControllerTroubleshoot.png ├── PS4Macro ├── Resources │ ├── icon.ico │ ├── icon_img.png │ ├── icon_repeat.png │ └── icon_joystick.png ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── packages.config ├── Classes │ ├── Remapping │ │ ├── BaseAction.cs │ │ ├── MacroAction.cs │ │ ├── MappingAction.cs │ │ ├── MouseStroke.cs │ │ └── BindingsContainer.cs │ ├── MacroUtility.cs │ ├── Settings.cs │ ├── ConsoleHelper.cs │ ├── SaveLoadHelper.cs │ ├── ScriptHostUtility.cs │ └── StatusChecker.cs ├── Forms │ ├── AboutForm.cs │ ├── ResizeRemotePlayForm.cs │ ├── StatusCheckerForm.cs │ ├── ResizeRemotePlayForm.Designer.cs │ ├── AboutForm.Designer.cs │ ├── ImageHashForm.cs │ ├── AboutForm.resx │ ├── ImageHashForm.resx │ ├── StatusCheckerForm.resx │ ├── MacroCompressorForm.resx │ ├── ResizeRemotePlayForm.resx │ ├── RemapperForm.resx │ └── MacroCompressorForm.Designer.cs ├── Controls │ └── AxisDisplay.cs └── Program.cs ├── LICENSE.md ├── PS4Macro.sln ├── PS4MacroAPI ├── Properties │ └── AssemblyInfo.cs ├── Structures │ ├── PixelMap.cs │ └── RectMap.cs ├── Internal │ ├── ForegroundCapture.cs │ ├── BackgroundCapture.cs │ ├── ImageHashing.cs │ └── ScriptUtility.cs ├── Bridge │ ├── Scene.cs │ ├── IScriptHost.cs │ ├── ScriptConfig.cs │ └── DualShockState.cs └── PS4MacroAPI.csproj ├── .gitignore └── README.md /_resources/Remapper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/Remapper.png -------------------------------------------------------------------------------- /PS4Macro/Resources/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/PS4Macro/Resources/icon.ico -------------------------------------------------------------------------------- /_resources/CmdShortcut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/CmdShortcut.png -------------------------------------------------------------------------------- /PS4Macro/Resources/icon_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/PS4Macro/Resources/icon_img.png -------------------------------------------------------------------------------- /_resources/Screenshot_0_1_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/Screenshot_0_1_0.png -------------------------------------------------------------------------------- /_resources/Screenshot_0_2_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/Screenshot_0_2_0.png -------------------------------------------------------------------------------- /_resources/Screenshot_0_2_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/Screenshot_0_2_1.png -------------------------------------------------------------------------------- /_resources/Screenshot_0_2_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/Screenshot_0_2_2.png -------------------------------------------------------------------------------- /_resources/Screenshot_0_3_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/Screenshot_0_3_0.png -------------------------------------------------------------------------------- /_resources/Screenshot_0_3_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/Screenshot_0_3_1.png -------------------------------------------------------------------------------- /_resources/Screenshot_0_4_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/Screenshot_0_4_0.png -------------------------------------------------------------------------------- /_resources/Screenshot_0_5_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/Screenshot_0_5_0.png -------------------------------------------------------------------------------- /_resources/Screenshot_0_5_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/Screenshot_0_5_1.png -------------------------------------------------------------------------------- /_resources/Screenshot_0_5_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/Screenshot_0_5_2.png -------------------------------------------------------------------------------- /PS4Macro/Resources/icon_repeat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/PS4Macro/Resources/icon_repeat.png -------------------------------------------------------------------------------- /PS4Macro/Resources/icon_joystick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/PS4Macro/Resources/icon_joystick.png -------------------------------------------------------------------------------- /_resources/EmulateControllerTroubleshoot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/komefai/PS4Macro/HEAD/_resources/EmulateControllerTroubleshoot.png -------------------------------------------------------------------------------- /PS4Macro/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PS4Macro/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2017 Komefai 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /PS4Macro/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace PS4Macro.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /PS4Macro.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PS4Macro", "PS4Macro\PS4Macro.csproj", "{2AF33C2D-3BCD-467C-BC81-08025C164799}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PS4MacroAPI", "PS4MacroAPI\PS4MacroAPI.csproj", "{63B26590-8DD4-4534-8E5E-C72750F29934}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {2AF33C2D-3BCD-467C-BC81-08025C164799}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {2AF33C2D-3BCD-467C-BC81-08025C164799}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {2AF33C2D-3BCD-467C-BC81-08025C164799}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {2AF33C2D-3BCD-467C-BC81-08025C164799}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {63B26590-8DD4-4534-8E5E-C72750F29934}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {63B26590-8DD4-4534-8E5E-C72750F29934}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {63B26590-8DD4-4534-8E5E-C72750F29934}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {63B26590-8DD4-4534-8E5E-C72750F29934}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /PS4MacroAPI/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PS4MacroAPI")] 9 | [assembly: AssemblyDescription("Scripting API for PS4 Macro")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Komefai")] 12 | [assembly: AssemblyProduct("PS4MacroAPI")] 13 | [assembly: AssemblyCopyright("Komefai Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("63b26590-8dd4-4534-8e5e-c72750f29934")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /PS4Macro/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PS4 Macro")] 9 | [assembly: AssemblyDescription("Automation utility for PS4 Remote Play")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Komefai")] 12 | [assembly: AssemblyProduct("PS4 Macro")] 13 | [assembly: AssemblyCopyright("Copyright © 2018 Komefai")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("2af33c2d-3bcd-467c-bc81-08025c164799")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("0.5.2.0")] 36 | [assembly: AssemblyFileVersion("0.5.2.0")] 37 | -------------------------------------------------------------------------------- /PS4Macro/Classes/Remapping/BaseAction.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro(File: Classes/Remapping/BaseAction.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | using System.Windows.Forms; 30 | 31 | namespace PS4Macro.Classes.Remapping 32 | { 33 | public class BaseAction 34 | { 35 | public string Name { get; set; } 36 | public Keys Key { get; set; } 37 | 38 | public override string ToString() 39 | { 40 | return Name; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /PS4Macro/Forms/AboutForm.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Forms/AboutForm.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.ComponentModel; 28 | using System.Data; 29 | using System.Drawing; 30 | using System.Linq; 31 | using System.Text; 32 | using System.Windows.Forms; 33 | 34 | namespace PS4Macro.Forms 35 | { 36 | public partial class AboutForm : Form 37 | { 38 | public AboutForm() 39 | { 40 | InitializeComponent(); 41 | } 42 | 43 | private void bioLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 44 | { 45 | System.Diagnostics.Process.Start("http://komefai.com"); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /PS4Macro/Classes/Remapping/MacroAction.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro(File: Classes/Remapping/MacroAction.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | using System.Windows.Forms; 30 | 31 | namespace PS4Macro.Classes.Remapping 32 | { 33 | public class MacroAction : BaseAction 34 | { 35 | public string Path { get; set; } 36 | 37 | public MacroAction() 38 | { 39 | 40 | } 41 | 42 | public MacroAction(string name, Keys key, string path) 43 | { 44 | Name = name; 45 | Key = key; 46 | Path = path; 47 | } 48 | 49 | public MacroAction Clone() 50 | { 51 | return new MacroAction(Name, Key, Path); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /PS4Macro/Classes/Remapping/MappingAction.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro(File: Classes/Remapping/MappingAction.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | using System.Windows.Forms; 30 | 31 | namespace PS4Macro.Classes.Remapping 32 | { 33 | public class MappingAction : BaseAction 34 | { 35 | public string Property { get; set; } 36 | public object Value { get; set; } 37 | 38 | public MappingAction() 39 | { 40 | 41 | } 42 | 43 | public MappingAction(string name, Keys key, string property, object value) 44 | { 45 | Name = name; 46 | Key = key; 47 | Property = property; 48 | Value = value; 49 | } 50 | 51 | public MappingAction Clone() 52 | { 53 | return new MappingAction(Name, Key, Property, Value); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /PS4MacroAPI/Structures/PixelMap.cs: -------------------------------------------------------------------------------- 1 | // PS4MacroAPI (File: Structures/PixelMap.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | 30 | namespace PS4MacroAPI 31 | { 32 | /// 33 | /// Pixel template for matching 34 | /// 35 | public struct PixelMap 36 | { 37 | /// 38 | /// Gets or sets the ID of this 39 | /// 40 | public string ID { get; set; } 41 | 42 | /// 43 | /// Gets or sets the x-coordinate of this 44 | /// 45 | public int X { get; set; } 46 | 47 | /// 48 | /// Gets or sets the y-coordinate of this 49 | /// 50 | public int Y { get; set; } 51 | 52 | /// 53 | /// Gets or sets the color this 54 | /// 55 | public int Color { get; set; } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /PS4Macro/Classes/Remapping/MouseStroke.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro(File: Classes/Remapping/MouseStroke.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | using PS4Macro.Classes.GlobalHooks; 30 | using System.Reflection; 31 | 32 | namespace PS4Macro.Classes.Remapping 33 | { 34 | public class MouseStroke 35 | { 36 | public GlobalMouseHookEventArgs RawData { get; set; } 37 | public DateTime Timestamp { get; set; } 38 | public bool DidMoved { get; set; } 39 | public int X { get; set; } 40 | public int Y { get; set; } 41 | public double VelocityX { get; set; } 42 | public double VelocityY { get; set; } 43 | 44 | private PropertyInfo[] _PropertyInfos = null; 45 | public override string ToString() 46 | { 47 | if (_PropertyInfos == null) 48 | _PropertyInfos = GetType().GetProperties(); 49 | 50 | var sb = new StringBuilder(); 51 | 52 | foreach (var info in _PropertyInfos) 53 | { 54 | var value = info.GetValue(this, null) ?? "(null)"; 55 | sb.AppendLine(info.Name + ": " + value.ToString()); 56 | } 57 | 58 | return sb.ToString(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /PS4MacroAPI/Structures/RectMap.cs: -------------------------------------------------------------------------------- 1 | // PS4MacroAPI (File: Structures/RectMap.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Drawing; 28 | using System.Linq; 29 | using System.Text; 30 | 31 | namespace PS4MacroAPI 32 | { 33 | /// 34 | /// Retangle template for matching 35 | /// 36 | public struct RectMap 37 | { 38 | /// 39 | /// Gets or sets the ID of this 40 | /// 41 | public string ID { get; set; } 42 | 43 | /// 44 | /// Gets or sets the x-coordinate of this 45 | /// 46 | public int X { get; set; } 47 | 48 | /// 49 | /// Gets or sets the y-coordinate of this 50 | /// 51 | public int Y { get; set; } 52 | 53 | /// 54 | /// Gets or sets the width of this 55 | /// 56 | public int Width { get; set; } 57 | 58 | /// 59 | /// Gets or sets the height of this 60 | /// 61 | public int Height { get; set; } 62 | 63 | /// 64 | /// Gets or sets the hash of this 65 | /// 66 | public ulong Hash { get; set; } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /PS4MacroAPI/Internal/ForegroundCapture.cs: -------------------------------------------------------------------------------- 1 | // PS4MacroAPI (File: Internal/ForegroundCapture.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Drawing; 28 | using System.Drawing.Imaging; 29 | using System.Linq; 30 | using System.Runtime.InteropServices; 31 | using System.Text; 32 | 33 | namespace PS4MacroAPI.Internal 34 | { 35 | class ForegroundCapture 36 | { 37 | public static Bitmap CaptureWindow(IntPtr handle) 38 | { 39 | var rect = new User32.Rect(); 40 | User32.GetWindowRect(handle, ref rect); 41 | 42 | int width = rect.right - rect.left; 43 | int height = rect.bottom - rect.top; 44 | 45 | var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); 46 | Graphics graphics = Graphics.FromImage(bmp); 47 | graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); 48 | 49 | return bmp; 50 | } 51 | } 52 | 53 | class User32 54 | { 55 | [StructLayout(LayoutKind.Sequential)] 56 | public struct Rect 57 | { 58 | public int left; 59 | public int top; 60 | public int right; 61 | public int bottom; 62 | } 63 | 64 | [DllImport("user32.dll")] 65 | public static extern IntPtr GetWindowRect(IntPtr hWnd, ref Rect rect); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /PS4Macro/Forms/ResizeRemotePlayForm.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Forms/ResizeRemotePlayForm.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using PS4MacroAPI; 26 | using PS4MacroAPI.Internal; 27 | using System; 28 | using System.Collections.Generic; 29 | using System.ComponentModel; 30 | using System.Data; 31 | using System.Drawing; 32 | using System.Linq; 33 | using System.Text; 34 | using System.Windows.Forms; 35 | 36 | namespace PS4Macro.Forms 37 | { 38 | public partial class ResizeRemotePlayForm : Form 39 | { 40 | public ResizeRemotePlayForm() 41 | { 42 | InitializeComponent(); 43 | } 44 | 45 | private void ResizeRemotePlayForm_Load(object sender, EventArgs e) 46 | { 47 | try 48 | { 49 | var size = ScriptUtility.GetWindowSize(); 50 | widthNumericUpDown.Value = size.Width; 51 | heightNumericUpDown.Value = size.Height; 52 | } 53 | catch {} 54 | } 55 | 56 | private void resizeButton_Click(object sender, EventArgs e) 57 | { 58 | try 59 | { 60 | Size size = new Size((int)widthNumericUpDown.Value, (int)heightNumericUpDown.Value); 61 | ScriptUtility.ResizeWindow(size); 62 | Close(); 63 | } 64 | catch (Exception ex) 65 | { 66 | MessageBox.Show(ex.Message, "Resize Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /PS4MacroAPI/Bridge/Scene.cs: -------------------------------------------------------------------------------- 1 | // PS4MacroAPI (File: Bridge/Scene.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | using System.Text; 29 | 30 | namespace PS4MacroAPI 31 | { 32 | /// 33 | /// Base class for all scenes 34 | /// 35 | public abstract class Scene 36 | { 37 | /// 38 | /// Name of the scene 39 | /// 40 | abstract public string Name { get; } 41 | 42 | /// 43 | /// Test a condition to match this scene 44 | /// 45 | /// 46 | /// Returns true if matched 47 | abstract public bool Match(ScriptBase script); 48 | 49 | /// 50 | /// Called when the scene is matched 51 | /// 52 | /// 53 | abstract public void OnMatched(ScriptBase script); 54 | 55 | /// 56 | /// Sort by search priority (frequent scenes first) 57 | /// 58 | /// 59 | /// The matched scene 60 | public static Scene Search(ScriptBase script) 61 | { 62 | if (script.Config == null || script.Config.Scenes == null) 63 | return null; 64 | 65 | foreach (var scene in script.Config.Scenes) 66 | { 67 | if (scene.Match(script)) 68 | return scene; 69 | } 70 | 71 | return null; 72 | } 73 | 74 | /// 75 | /// Create a unique ID for a scene 76 | /// 77 | /// 78 | /// 79 | /// The ID string 80 | public static string CreateID(Scene instance, string name) 81 | { 82 | return $"{instance.Name}_{name}"; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /PS4Macro/Classes/Remapping/BindingsContainer.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Classes/Remapping/BindingsContainer.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.IO; 28 | using System.Linq; 29 | using System.Text; 30 | using System.Xml.Serialization; 31 | 32 | namespace PS4Macro.Classes.Remapping 33 | { 34 | public class BindingsContainer 35 | { 36 | public List Mappings { get; set; } 37 | public List Macros { get; set; } 38 | 39 | public bool EnableMouseInput { get; set; } 40 | public double MouseSensitivity { get; set; } 41 | public double MouseDecayRate { get; set; } 42 | public double MouseDecayThreshold { get; set; } 43 | public double MouseAnalogDeadzone { get; set; } 44 | public double MouseMakeupSpeed { get; set; } 45 | public AnalogStick MouseMovementAnalog { get; set; } 46 | public bool MouseInvertXAxis { get; set; } 47 | public bool MouseInvertYAxis { get; set; } 48 | public int LeftMouseMapping { get; set; } 49 | public int RightMouseMapping { get; set; } 50 | public int MiddleMouseMapping { get; set; } 51 | 52 | public static void Serialize(string path, BindingsContainer container) 53 | { 54 | XmlSerializer serializer = new XmlSerializer(typeof(BindingsContainer)); 55 | using (TextWriter writer = new StreamWriter(path)) 56 | { 57 | serializer.Serialize(writer, container); 58 | } 59 | } 60 | 61 | public static BindingsContainer Deserialize(string path) 62 | { 63 | XmlSerializer deserializer = new XmlSerializer(typeof(BindingsContainer)); 64 | using (TextReader reader = new StreamReader(path)) 65 | { 66 | object obj = deserializer.Deserialize(reader); 67 | BindingsContainer container = obj as BindingsContainer; 68 | return container; 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /PS4MacroAPI/PS4MacroAPI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {63B26590-8DD4-4534-8E5E-C72750F29934} 8 | Library 9 | Properties 10 | PS4MacroAPI 11 | PS4MacroAPI 12 | v4.0 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | bin\Debug\PS4MacroAPI.xml 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | bin\Release\PS4MacroAPI.xml 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 68 | -------------------------------------------------------------------------------- /PS4Macro/Classes/MacroUtility.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Classes/MacroUtility.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using PS4RemotePlayInterceptor; 26 | using System; 27 | using System.Collections.Generic; 28 | using System.Linq; 29 | using System.Text; 30 | 31 | namespace PS4Macro.Classes 32 | { 33 | public class MacroUtility 34 | { 35 | public static List TrimMacro(List sequence) 36 | { 37 | var newSequence = sequence.Select(item => item == null ? null : item.Clone()).ToList(); 38 | 39 | // Edit sequence 40 | TrimMacroInPlace(newSequence); 41 | 42 | return newSequence; 43 | } 44 | 45 | public static void TrimMacroInPlace(List sequence) 46 | { 47 | // Edit sequence 48 | TrimSequence(sequence, false); // Trim start 49 | TrimSequence(sequence, true); // Trim end 50 | } 51 | 52 | public static void TrimSequence(List sequence, bool fromEnd) 53 | { 54 | if (!fromEnd) 55 | { 56 | int offset = 5; 57 | for (var i = 0; i < sequence.Count; i++) 58 | { 59 | var isDefaultState = DualShockState.IsDefaultState(sequence.ElementAt(i)); 60 | if (!isDefaultState) 61 | { 62 | if (i == 0) return; 63 | var offsetVal = i - offset; 64 | if (offsetVal == 0) return; 65 | sequence.RemoveRange(0, offsetVal); 66 | return; 67 | } 68 | } 69 | } 70 | else 71 | { 72 | int offset = 5; 73 | for (var i = sequence.Count - 1; i >= 0; i--) 74 | { 75 | var isDefaultState = DualShockState.IsDefaultState(sequence.ElementAt(i)); 76 | if (!isDefaultState) 77 | { 78 | if (i == sequence.Count - 1) return; 79 | var count = i + offset; 80 | var offsetVal = sequence.Count - count; 81 | if (count + offsetVal > sequence.Count) return; 82 | sequence.RemoveRange(count, offsetVal); 83 | return; 84 | } 85 | } 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /PS4Macro/Classes/Settings.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Classes/Settings.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.IO; 28 | using System.Linq; 29 | using System.Text; 30 | using System.Xml.Serialization; 31 | 32 | namespace PS4Macro.Classes 33 | { 34 | public class Settings 35 | { 36 | public const string FILE_PATH = "settings.xml"; 37 | 38 | public bool AutoInject { get; set; } 39 | public bool BypassInjection { get; set; } 40 | public bool EmulateController { get; set; } 41 | public bool ShowConsole { get; set; } 42 | public string StartupFile { get; set; } 43 | 44 | public Settings() 45 | { 46 | AutoInject = false; 47 | BypassInjection = false; 48 | EmulateController = false; 49 | ShowConsole = false; 50 | StartupFile = null; 51 | } 52 | 53 | public static Settings LoadDefaultOrCreate() 54 | { 55 | var loaded = Load(FILE_PATH); 56 | 57 | if (loaded == null) 58 | return new Settings(); 59 | 60 | return loaded; 61 | } 62 | 63 | public static Settings Load(string path) 64 | { 65 | try 66 | { 67 | if (File.Exists(path)) 68 | { 69 | return Deserialize(path); 70 | } 71 | } 72 | catch (Exception ex) 73 | { 74 | Console.WriteLine("Settings Error: {0}", ex.Message); 75 | } 76 | 77 | return null; 78 | } 79 | public static void Serialize(string path, Settings settings) 80 | { 81 | XmlSerializer serializer = new XmlSerializer(typeof(Settings)); 82 | using (TextWriter writer = new StreamWriter(path)) 83 | { 84 | serializer.Serialize(writer, settings); 85 | } 86 | } 87 | 88 | public static Settings Deserialize(string path) 89 | { 90 | XmlSerializer deserializer = new XmlSerializer(typeof(Settings)); 91 | using (TextReader reader = new StreamReader(path)) 92 | { 93 | object obj = deserializer.Deserialize(reader); 94 | Settings settings = obj as Settings; 95 | return settings; 96 | } 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /PS4MacroAPI/Bridge/IScriptHost.cs: -------------------------------------------------------------------------------- 1 | // PS4MacroAPI (File: Bridge/IScriptHost.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.ComponentModel; 28 | using System.Linq; 29 | using System.Text; 30 | using System.Windows.Forms; 31 | 32 | namespace PS4MacroAPI 33 | { 34 | /// 35 | /// Interface for ScriptHost class 36 | /// 37 | public interface IScriptHost 38 | { 39 | /// 40 | /// The host form 41 | /// 42 | Form HostForm { get; } 43 | 44 | /// 45 | /// Is the host running 46 | /// 47 | bool IsRunning { get; } 48 | 49 | /// 50 | /// Is the host paused 51 | /// 52 | bool IsPaused { get; } 53 | 54 | /// 55 | /// The background worker 56 | /// 57 | BackgroundWorker Worker { get; } 58 | 59 | 60 | /* Relay Methods */ 61 | 62 | /// 63 | /// Wait and block execution for a certian amount of time 64 | /// 65 | /// 66 | /// 67 | void Sleep(int timeout, int checkInterval = 100); 68 | 69 | /// 70 | /// Suspend update for a certain amount of time 71 | /// 72 | /// 73 | void Suspend(int delay); 74 | 75 | /// 76 | /// Play a macro 77 | /// 78 | /// 79 | /// 80 | void PlayMacro(List sequence, int suspendDelay = 0); 81 | 82 | /// 83 | /// Play a macro from path 84 | /// 85 | /// 86 | /// 87 | void PlayMacro(string path, int suspendDelay = 0); 88 | 89 | /// 90 | /// Stop the macro 91 | /// 92 | void StopMacro(); 93 | 94 | /* Emergency Methods */ 95 | 96 | /// 97 | /// Play the script 98 | /// 99 | void Play(); 100 | 101 | /// 102 | /// Pause the script 103 | /// 104 | void Pause(); 105 | 106 | /// 107 | /// Stop the script 108 | /// 109 | void Stop(); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /PS4Macro/Controls/AxisDisplay.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro(File: Controls/AxisDisplay.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Drawing; 28 | using System.Drawing.Drawing2D; 29 | using System.Drawing.Text; 30 | using System.Linq; 31 | using System.Text; 32 | using System.Windows.Forms; 33 | 34 | namespace PS4Macro.Controls 35 | { 36 | class AxisDisplay : UserControl 37 | { 38 | private Color m_OuterColor; 39 | public Color OuterColor 40 | { 41 | get { return m_OuterColor; } 42 | set 43 | { 44 | m_OuterBrush = new SolidBrush(value); 45 | m_OuterColor = value; 46 | } 47 | } 48 | private Brush m_OuterBrush = null; 49 | 50 | private Color m_InnerColor; 51 | public Color InnerColor 52 | { 53 | get { return m_InnerColor; } 54 | set 55 | { 56 | m_InnerBrush = new SolidBrush(value); 57 | m_InnerColor = value; 58 | } 59 | } 60 | private Brush m_InnerBrush = null; 61 | 62 | public int InnerSize { get; set; } 63 | 64 | public PointF Value { get; set; } 65 | 66 | public AxisDisplay() 67 | { 68 | OuterColor = Color.DodgerBlue; 69 | InnerColor = Color.GhostWhite; 70 | InnerSize = 12; 71 | Value = new PointF(0f, 0f); 72 | 73 | SetStyle(ControlStyles.UserPaint, true); 74 | DoubleBuffered = true; 75 | } 76 | 77 | protected override void OnPaint(PaintEventArgs e) 78 | { 79 | // Draw with smoothing. 80 | e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; 81 | e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; 82 | e.Graphics.InterpolationMode = InterpolationMode.High; 83 | 84 | Rectangle rect = e.ClipRectangle; 85 | rect.Width -= 2; 86 | rect.Height -= 2; 87 | 88 | // Outer 89 | e.Graphics.FillEllipse(m_OuterBrush, rect); 90 | 91 | // Inner 92 | var halfSize = InnerSize / 2; 93 | var innerRect = new Rectangle(((rect.Width / 2) - halfSize), ((rect.Height / 2) - halfSize), InnerSize, InnerSize); 94 | innerRect.X += (int)(((rect.Width / 2) - halfSize) * Value.X); 95 | innerRect.Y -= (int)(((rect.Height / 2) - halfSize) * Value.Y); 96 | e.Graphics.FillEllipse(m_InnerBrush, innerRect); 97 | 98 | //e.Graphics.FillEllipse(m_InnerBrush, new Rectangle(((rect.Width / 2) - halfSize) * Value.X, ((rect.Height / 2) - halfSize) * Value.Y, InnerSize, InnerSize)); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /PS4Macro/Forms/StatusCheckerForm.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Forms/StatusCheckerForm.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using PS4Macro.Classes; 26 | using System; 27 | using System.Collections.Generic; 28 | using System.ComponentModel; 29 | using System.Data; 30 | using System.Drawing; 31 | using System.Linq; 32 | using System.Runtime.InteropServices; 33 | using System.Text; 34 | using System.Windows.Forms; 35 | 36 | namespace PS4Macro.Forms 37 | { 38 | public partial class StatusCheckerForm : Form 39 | { 40 | #region Native API 41 | [DllImport("user32.dll")] 42 | static extern bool HideCaret(IntPtr hWnd); 43 | #endregion 44 | 45 | public StatusChecker StatusChecker { get; set; } 46 | 47 | public StatusCheckerForm(StatusChecker statusChecker) 48 | { 49 | InitializeComponent(); 50 | 51 | StatusChecker = statusChecker; 52 | } 53 | 54 | private void SetStatusText(StatusCheckData status, Label label, string textOverride = null) 55 | { 56 | label.Text = status.IsWorking ? "Working" : "Not Working"; 57 | label.ForeColor = status.IsWorking ? Color.Green : Color.Red; 58 | 59 | if (textOverride != null && !status.IsWorking) 60 | { 61 | label.Text = textOverride; 62 | } 63 | } 64 | 65 | private void OnStatusChanged() 66 | { 67 | BeginInvoke(new Action(() => 68 | { 69 | // Update process 70 | remotePlayProcessLabel.Text = StatusChecker.RemotePlayProcess == null ? "-" : "PID=" + StatusChecker.RemotePlayProcess.Id; 71 | remotePlayHandleLabel.Text = StatusChecker.MainWindowHandle == IntPtr.Zero ? "-" : StatusChecker.MainWindowHandle.ToString(); 72 | foregroundWindowLabel.Text = StatusChecker.ForegroundWindowHandle == IntPtr.Zero ? "-" : StatusChecker.ForegroundWindowHandle.ToString(); 73 | 74 | // Update status labels 75 | SetStatusText(StatusChecker.InterceptorStatus, interceptorStatusLabel); 76 | SetStatusText(StatusChecker.KeyboardStatus, keyboardStatusLabel, "Press Any Key"); 77 | SetStatusText(StatusChecker.MouseStatus, mouseStatusLabel, "Move/Click Mouse"); 78 | })); 79 | } 80 | 81 | private void StatusCheckerForm_Load(object sender, EventArgs e) 82 | { 83 | // Trigger on load 84 | OnStatusChanged(); 85 | 86 | // Refresh process 87 | StatusChecker.RefreshProcess(); 88 | 89 | // Get settings 90 | settingsRichTextBox.Text = StatusChecker.GetSettingsText(); 91 | 92 | StatusChecker.OnStatusChanged += OnStatusChanged; 93 | } 94 | 95 | private void StatusCheckerForm_FormClosed(object sender, FormClosedEventArgs e) 96 | { 97 | StatusChecker.OnStatusChanged -= OnStatusChanged; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /PS4Macro/Classes/ConsoleHelper.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Classes/ConsoleHelper.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.IO; 28 | using System.Linq; 29 | using System.Runtime.InteropServices; 30 | using System.Text; 31 | using Microsoft.Win32.SafeHandles; 32 | 33 | namespace PS4Macro.Classes 34 | { 35 | class ConsoleHelper 36 | { 37 | #region Win32 API 38 | [DllImport("kernel32.dll", 39 | EntryPoint = "AllocConsole", 40 | SetLastError = true, 41 | CharSet = CharSet.Auto, 42 | CallingConvention = CallingConvention.StdCall)] 43 | public static extern int AllocConsole(); 44 | 45 | [DllImport("kernel32.dll", 46 | CallingConvention = CallingConvention.StdCall, 47 | CharSet = CharSet.Auto, 48 | ExactSpelling = false, 49 | SetLastError = true)] 50 | public static extern IntPtr GetStdHandle(int nStdHandle); 51 | 52 | [DllImport("kernel32.dll", SetLastError = true)] 53 | private static extern IntPtr CreateFile( 54 | string lpFileName, 55 | uint dwDesiredAccess, 56 | uint dwShareMode, 57 | uint lpSecurityAttributes, 58 | uint dwCreationDisposition, 59 | uint dwFlagsAndAttributes, 60 | uint hTemplateFile); 61 | 62 | private const int MY_CODE_PAGE = 437; 63 | private const string CONSOLE_FILENAME = "CONOUT$"; 64 | private const uint GENERIC_WRITE = 0x40000000; 65 | private const uint FILE_SHARE_WRITE = 0x2; 66 | private const uint OPEN_EXISTING = 0x3; 67 | #endregion 68 | 69 | internal static void SetOut() 70 | { 71 | // Without debugger 72 | try 73 | { 74 | SafeFileHandle safeFileHandle = new SafeFileHandle(GetStdHandle(-11), true); 75 | FileStream fileStream = new FileStream(safeFileHandle, FileAccess.Write); 76 | StreamWriter standardOutput = new StreamWriter(fileStream, Encoding.GetEncoding(MY_CODE_PAGE)) 77 | { 78 | AutoFlush = true 79 | }; 80 | Console.SetOut(standardOutput); 81 | } 82 | // With debugger 83 | catch (Exception) 84 | { 85 | IntPtr stdHandle = CreateFile( 86 | CONSOLE_FILENAME, 87 | GENERIC_WRITE, 88 | FILE_SHARE_WRITE, 89 | 0, OPEN_EXISTING, 0, 0 90 | ); 91 | 92 | SafeFileHandle safeFileHandle = new SafeFileHandle(stdHandle, true); 93 | FileStream fileStream = new FileStream(safeFileHandle, FileAccess.Write); 94 | StreamWriter standardOutput = new StreamWriter(fileStream, Encoding.GetEncoding(MY_CODE_PAGE)) 95 | { 96 | AutoFlush = true 97 | }; 98 | Console.SetOut(standardOutput); 99 | } 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /PS4MacroAPI/Bridge/ScriptConfig.cs: -------------------------------------------------------------------------------- 1 | // PS4MacroAPI (File: Bridge/ScriptConfig.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Drawing; 28 | using System.Linq; 29 | using System.Text; 30 | 31 | namespace PS4MacroAPI 32 | { 33 | /// 34 | /// Config for scripts 35 | /// 36 | public class ScriptConfig 37 | { 38 | /// 39 | /// Default width for TargetSize 40 | /// 41 | public const int DEFAULT_SCREEN_WIDTH = 1024; 42 | /// 43 | /// Default height for TargetSize 44 | /// 45 | public const int DEFAULT_SCREEN_HEIGHT = 768; 46 | 47 | /// 48 | /// Name of the script 49 | /// 50 | public string Name { get; set; } 51 | 52 | /// 53 | /// Delay between updates 54 | /// 55 | public int LoopDelay { get; set; } 56 | 57 | /// 58 | /// Target size for PS4 Remote Play 59 | /// 60 | public Size TargetSize { get; set; } 61 | 62 | /// 63 | /// Should throw exceptions 64 | /// 65 | public bool ThrowExceptions { get; set; } 66 | 67 | /// 68 | /// Show stack trace when exception is thrown 69 | /// 70 | public bool ShowStackTrace { get; set; } 71 | 72 | /// 73 | /// Show error message box 74 | /// 75 | public bool ShowError { get; set; } 76 | 77 | /// 78 | /// Enable capture screenshots 79 | /// 80 | public bool EnableCapture { get; set; } 81 | 82 | /// 83 | /// Enable capture from background 84 | /// 85 | public bool CaptureFromBackground { get; set; } 86 | 87 | /// 88 | /// Show form when script is started 89 | /// 90 | public bool ShowFormOnStart { get; set; } 91 | 92 | /// 93 | /// Automatically move form when shown 94 | /// 95 | public bool AutoFormLocation { get; set; } 96 | 97 | /// 98 | /// List of scenes for scenes API 99 | /// 100 | public List Scenes { get; set; } 101 | 102 | /// 103 | /// Initializes a new instance of 104 | /// 105 | public ScriptConfig() 106 | { 107 | Name = "Untitled Script"; 108 | LoopDelay = 500; 109 | TargetSize = new Size(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT); 110 | ThrowExceptions = true; 111 | ShowStackTrace = true; 112 | ShowError = true; 113 | EnableCapture = true; 114 | CaptureFromBackground = true; 115 | ShowFormOnStart = true; 116 | AutoFormLocation = true; 117 | Scenes = null; 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /PS4Macro/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace PS4Macro.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PS4Macro.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 65 | /// 66 | internal static System.Drawing.Icon icon { 67 | get { 68 | object obj = ResourceManager.GetObject("icon", resourceCulture); 69 | return ((System.Drawing.Icon)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// Looks up a localized resource of type System.Drawing.Bitmap. 75 | /// 76 | internal static System.Drawing.Bitmap icon_img { 77 | get { 78 | object obj = ResourceManager.GetObject("icon_img", resourceCulture); 79 | return ((System.Drawing.Bitmap)(obj)); 80 | } 81 | } 82 | 83 | /// 84 | /// Looks up a localized resource of type System.Drawing.Bitmap. 85 | /// 86 | internal static System.Drawing.Bitmap icon_joystick { 87 | get { 88 | object obj = ResourceManager.GetObject("icon_joystick", resourceCulture); 89 | return ((System.Drawing.Bitmap)(obj)); 90 | } 91 | } 92 | 93 | /// 94 | /// Looks up a localized resource of type System.Drawing.Bitmap. 95 | /// 96 | internal static System.Drawing.Bitmap icon_repeat { 97 | get { 98 | object obj = ResourceManager.GetObject("icon_repeat", resourceCulture); 99 | return ((System.Drawing.Bitmap)(obj)); 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # EasyHook files 2 | EasyHook32.dll 3 | EasyHook32Svc.exe 4 | EasyHook64.dll 5 | EasyHook64Svc.exe 6 | EasyLoad32.dll 7 | EasyLoad64.dll 8 | 9 | # Windows image file caches 10 | Thumbs.db 11 | ehthumbs.db 12 | 13 | ## Ignore Visual Studio temporary files, build results, and 14 | ## files generated by popular Visual Studio add-ons. 15 | 16 | # User-specific files 17 | *.suo 18 | *.user 19 | *.userosscache 20 | *.sln.docstates 21 | 22 | # User-specific files (MonoDevelop/Xamarin Studio) 23 | *.userprefs 24 | 25 | # Build results 26 | [Dd]ebug/ 27 | [Dd]ebugPublic/ 28 | [Rr]elease/ 29 | [Rr]eleases/ 30 | x64/ 31 | x86/ 32 | build/ 33 | bld/ 34 | [Bb]in/ 35 | [Oo]bj/ 36 | 37 | # Visual Studio 2015 cache/options directory 38 | .vs/ 39 | # Uncomment if you have tasks that create the project's static files in wwwroot 40 | #wwwroot/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUNIT 47 | *.VisualState.xml 48 | TestResult.xml 49 | 50 | # Build Results of an ATL Project 51 | [Dd]ebugPS/ 52 | [Rr]eleasePS/ 53 | dlldata.c 54 | 55 | # DNX 56 | project.lock.json 57 | artifacts/ 58 | 59 | *_i.c 60 | *_p.c 61 | *_i.h 62 | *.ilk 63 | *.meta 64 | *.obj 65 | *.pch 66 | *.pdb 67 | *.pgc 68 | *.pgd 69 | *.rsp 70 | *.sbr 71 | *.tlb 72 | *.tli 73 | *.tlh 74 | *.tmp 75 | *.tmp_proj 76 | *.log 77 | *.vspscc 78 | *.vssscc 79 | .builds 80 | *.pidb 81 | *.svclog 82 | *.scc 83 | 84 | # Chutzpah Test files 85 | _Chutzpah* 86 | 87 | # Visual C++ cache files 88 | ipch/ 89 | *.aps 90 | *.ncb 91 | *.opensdf 92 | *.sdf 93 | *.cachefile 94 | 95 | # Visual Studio profiler 96 | *.psess 97 | *.vsp 98 | *.vspx 99 | *.sap 100 | 101 | # TFS 2012 Local Workspace 102 | $tf/ 103 | 104 | # Guidance Automation Toolkit 105 | *.gpState 106 | 107 | # ReSharper is a .NET coding add-in 108 | _ReSharper*/ 109 | *.[Rr]e[Ss]harper 110 | *.DotSettings.user 111 | 112 | # JustCode is a .NET coding add-in 113 | .JustCode 114 | 115 | # TeamCity is a build add-in 116 | _TeamCity* 117 | 118 | # DotCover is a Code Coverage Tool 119 | *.dotCover 120 | 121 | # NCrunch 122 | _NCrunch_* 123 | .*crunch*.local.xml 124 | nCrunchTemp_* 125 | 126 | # MightyMoose 127 | *.mm.* 128 | AutoTest.Net/ 129 | 130 | # Web workbench (sass) 131 | .sass-cache/ 132 | 133 | # Installshield output folder 134 | [Ee]xpress/ 135 | 136 | # DocProject is a documentation generator add-in 137 | DocProject/buildhelp/ 138 | DocProject/Help/*.HxT 139 | DocProject/Help/*.HxC 140 | DocProject/Help/*.hhc 141 | DocProject/Help/*.hhk 142 | DocProject/Help/*.hhp 143 | DocProject/Help/Html2 144 | DocProject/Help/html 145 | 146 | # Click-Once directory 147 | publish/ 148 | 149 | # Publish Web Output 150 | *.[Pp]ublish.xml 151 | *.azurePubxml 152 | # TODO: Comment the next line if you want to checkin your web deploy settings 153 | # but database connection strings (with potential passwords) will be unencrypted 154 | *.pubxml 155 | *.publishproj 156 | 157 | # NuGet Packages 158 | *.nupkg 159 | # The packages folder can be ignored because of Package Restore 160 | **/packages/* 161 | # except build/, which is used as an MSBuild target. 162 | !**/packages/build/ 163 | # Uncomment if necessary however generally it will be regenerated when needed 164 | #!**/packages/repositories.config 165 | 166 | # Windows Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Windows Azure Emulator 171 | efc/ 172 | rfc/ 173 | 174 | # Windows Store app package directory 175 | AppPackages/ 176 | 177 | # Visual Studio cache files 178 | # files ending in .cache can be ignored 179 | *.[Cc]ache 180 | # but keep track of directories ending in .cache 181 | !*.[Cc]ache/ 182 | 183 | # Others 184 | ClientBin/ 185 | [Ss]tyle[Cc]op.* 186 | ~$* 187 | *~ 188 | *.dbmdl 189 | *.dbproj.schemaview 190 | *.pfx 191 | *.publishsettings 192 | node_modules/ 193 | orleans.codegen.cs 194 | 195 | # RIA/Silverlight projects 196 | Generated_Code/ 197 | 198 | # Backup & report files from converting an old project file 199 | # to a newer Visual Studio version. Backup files are not needed, 200 | # because we have git ;-) 201 | _UpgradeReport_Files/ 202 | Backup*/ 203 | UpgradeLog*.XML 204 | UpgradeLog*.htm 205 | 206 | # SQL Server files 207 | *.mdf 208 | *.ldf 209 | 210 | # Business Intelligence projects 211 | *.rdl.data 212 | *.bim.layout 213 | *.bim_*.settings 214 | 215 | # Microsoft Fakes 216 | FakesAssemblies/ 217 | 218 | # GhostDoc plugin setting file 219 | *.GhostDoc.xml 220 | 221 | # Node.js Tools for Visual Studio 222 | .ntvs_analysis.dat 223 | 224 | # Visual Studio 6 build log 225 | *.plg 226 | 227 | # Visual Studio 6 workspace options file 228 | *.opt 229 | 230 | # Visual Studio LightSwitch build output 231 | **/*.HTMLClient/GeneratedArtifacts 232 | **/*.DesktopClient/GeneratedArtifacts 233 | **/*.DesktopClient/ModelManifest.xml 234 | **/*.Server/GeneratedArtifacts 235 | **/*.Server/ModelManifest.xml 236 | _Pvt_Extensions 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ -------------------------------------------------------------------------------- /PS4Macro/Program.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Program.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using Mono.Options; 26 | using PS4Macro.Classes; 27 | using System; 28 | using System.Threading; 29 | using System.Windows.Forms; 30 | 31 | namespace PS4Macro 32 | { 33 | static class Program 34 | { 35 | private static Settings m_Settings = Settings.LoadDefaultOrCreate(); 36 | public static Settings Settings => m_Settings; 37 | 38 | /// 39 | /// The main entry point for the application. 40 | /// 41 | [STAThread] 42 | static void Main() 43 | { 44 | // Get command line arguments 45 | string[] args = Environment.GetCommandLineArgs(); 46 | 47 | // Parse command line arguments 48 | try 49 | { 50 | var p = new OptionSet() 51 | .Add("AutoInject:", "Automatically poll for PS4 Remote Play and inject whenever possible", v => m_Settings.AutoInject = v == null ? true : Convert.ToBoolean(v)) 52 | .Add("BypassInjection:", "Bypass the injection for debugging purposes", v => m_Settings.BypassInjection = v == null ? true : Convert.ToBoolean(v)) 53 | .Add("EmulateController:", "Run with controller emulation (use without a controller)", v => m_Settings.EmulateController = v == null ? true : Convert.ToBoolean(v)) 54 | .Add("ShowConsole:", "Open debugging console on launch", v => m_Settings.ShowConsole = v == null ? true : Convert.ToBoolean(v)) 55 | .Add("StartupFile=", "Absolute or relative path to the file to load on launch (can be xml or dll)", v => m_Settings.StartupFile = v); 56 | 57 | p.Add("SettingsFile=", "Absolute or relative path to the settings file (will take priority)", v => m_Settings = Settings.Load(v)); 58 | p.Add("h|?|help", "Displays this help message", v => { 59 | p.WriteOptionDescriptions(Console.Out); 60 | Environment.Exit(0); 61 | }); 62 | 63 | var extras = p.Parse(args); 64 | } 65 | catch (OptionException ex) 66 | { 67 | Console.WriteLine(ex.Message); 68 | Console.WriteLine("Try `PS4Macro --help` for usage."); 69 | } 70 | 71 | // Display console for debugging if enabled 72 | if (Settings.ShowConsole) 73 | { 74 | ConsoleHelper.AllocConsole(); 75 | ConsoleHelper.SetOut(); 76 | } 77 | 78 | // Add the event handler for handling UI thread exceptions to the event. 79 | Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException); 80 | 81 | // Set the unhandled exception mode to force all Windows Forms errors 82 | // to go through the handler. 83 | Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); 84 | 85 | // Add the event handler for handling non-UI thread exceptions to the event. 86 | AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException); 87 | 88 | Application.EnableVisualStyles(); 89 | Application.SetCompatibleTextRenderingDefault(false); 90 | Application.Run(new Forms.MainForm()); 91 | } 92 | 93 | static void OnThreadException(object sender, ThreadExceptionEventArgs e) 94 | { 95 | MessageBox.Show(e.Exception.ToString(), "Unhandled Thread Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 96 | } 97 | 98 | static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) 99 | { 100 | MessageBox.Show(e.ExceptionObject.ToString(), "Unhandled Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /PS4Macro/Forms/ResizeRemotePlayForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace PS4Macro.Forms 2 | { 3 | partial class ResizeRemotePlayForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.widthLabel = new System.Windows.Forms.Label(); 32 | this.heightLabel = new System.Windows.Forms.Label(); 33 | this.resizeButton = new System.Windows.Forms.Button(); 34 | this.widthNumericUpDown = new System.Windows.Forms.NumericUpDown(); 35 | this.heightNumericUpDown = new System.Windows.Forms.NumericUpDown(); 36 | ((System.ComponentModel.ISupportInitialize)(this.widthNumericUpDown)).BeginInit(); 37 | ((System.ComponentModel.ISupportInitialize)(this.heightNumericUpDown)).BeginInit(); 38 | this.SuspendLayout(); 39 | // 40 | // widthLabel 41 | // 42 | this.widthLabel.Location = new System.Drawing.Point(16, 6); 43 | this.widthLabel.Name = "widthLabel"; 44 | this.widthLabel.Size = new System.Drawing.Size(38, 23); 45 | this.widthLabel.TabIndex = 0; 46 | this.widthLabel.Text = "Width"; 47 | this.widthLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 48 | // 49 | // heightLabel 50 | // 51 | this.heightLabel.Location = new System.Drawing.Point(16, 31); 52 | this.heightLabel.Name = "heightLabel"; 53 | this.heightLabel.Size = new System.Drawing.Size(38, 23); 54 | this.heightLabel.TabIndex = 2; 55 | this.heightLabel.Text = "Height"; 56 | this.heightLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 57 | // 58 | // resizeButton 59 | // 60 | this.resizeButton.Location = new System.Drawing.Point(12, 61); 61 | this.resizeButton.Name = "resizeButton"; 62 | this.resizeButton.Size = new System.Drawing.Size(158, 23); 63 | this.resizeButton.TabIndex = 4; 64 | this.resizeButton.Text = "Resize"; 65 | this.resizeButton.UseVisualStyleBackColor = true; 66 | this.resizeButton.Click += new System.EventHandler(this.resizeButton_Click); 67 | // 68 | // widthNumericUpDown 69 | // 70 | this.widthNumericUpDown.Location = new System.Drawing.Point(88, 9); 71 | this.widthNumericUpDown.Maximum = new decimal(new int[] { 72 | 10000, 73 | 0, 74 | 0, 75 | 0}); 76 | this.widthNumericUpDown.Name = "widthNumericUpDown"; 77 | this.widthNumericUpDown.Size = new System.Drawing.Size(82, 20); 78 | this.widthNumericUpDown.TabIndex = 5; 79 | // 80 | // heightNumericUpDown 81 | // 82 | this.heightNumericUpDown.Location = new System.Drawing.Point(88, 34); 83 | this.heightNumericUpDown.Maximum = new decimal(new int[] { 84 | 10000, 85 | 0, 86 | 0, 87 | 0}); 88 | this.heightNumericUpDown.Name = "heightNumericUpDown"; 89 | this.heightNumericUpDown.Size = new System.Drawing.Size(82, 20); 90 | this.heightNumericUpDown.TabIndex = 6; 91 | // 92 | // ResizeRemotePlayForm 93 | // 94 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 95 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 96 | this.ClientSize = new System.Drawing.Size(182, 96); 97 | this.Controls.Add(this.heightNumericUpDown); 98 | this.Controls.Add(this.widthNumericUpDown); 99 | this.Controls.Add(this.resizeButton); 100 | this.Controls.Add(this.heightLabel); 101 | this.Controls.Add(this.widthLabel); 102 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; 103 | this.MaximizeBox = false; 104 | this.MinimizeBox = false; 105 | this.Name = "ResizeRemotePlayForm"; 106 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 107 | this.Text = "Resize"; 108 | this.Load += new System.EventHandler(this.ResizeRemotePlayForm_Load); 109 | ((System.ComponentModel.ISupportInitialize)(this.widthNumericUpDown)).EndInit(); 110 | ((System.ComponentModel.ISupportInitialize)(this.heightNumericUpDown)).EndInit(); 111 | this.ResumeLayout(false); 112 | 113 | } 114 | 115 | #endregion 116 | 117 | private System.Windows.Forms.Label widthLabel; 118 | private System.Windows.Forms.Label heightLabel; 119 | private System.Windows.Forms.Button resizeButton; 120 | private System.Windows.Forms.NumericUpDown widthNumericUpDown; 121 | private System.Windows.Forms.NumericUpDown heightNumericUpDown; 122 | } 123 | } -------------------------------------------------------------------------------- /PS4Macro/Forms/AboutForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace PS4Macro.Forms 2 | { 3 | partial class AboutForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.createdByLabel = new System.Windows.Forms.Label(); 32 | this.bioLinkLabel = new System.Windows.Forms.LinkLabel(); 33 | this.iconPictureBox = new System.Windows.Forms.PictureBox(); 34 | this.titleLabel = new System.Windows.Forms.Label(); 35 | this.githubLinkLabel = new System.Windows.Forms.LinkLabel(); 36 | ((System.ComponentModel.ISupportInitialize)(this.iconPictureBox)).BeginInit(); 37 | this.SuspendLayout(); 38 | // 39 | // createdByLabel 40 | // 41 | this.createdByLabel.AutoSize = true; 42 | this.createdByLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); 43 | this.createdByLabel.Location = new System.Drawing.Point(109, 64); 44 | this.createdByLabel.Name = "createdByLabel"; 45 | this.createdByLabel.Size = new System.Drawing.Size(154, 20); 46 | this.createdByLabel.TabIndex = 0; 47 | this.createdByLabel.Text = "Created By: Komefai"; 48 | // 49 | // bioLinkLabel 50 | // 51 | this.bioLinkLabel.AutoSize = true; 52 | this.bioLinkLabel.Location = new System.Drawing.Point(113, 87); 53 | this.bioLinkLabel.Name = "bioLinkLabel"; 54 | this.bioLinkLabel.Size = new System.Drawing.Size(98, 13); 55 | this.bioLinkLabel.TabIndex = 1; 56 | this.bioLinkLabel.TabStop = true; 57 | this.bioLinkLabel.Text = "http://komefai.com"; 58 | this.bioLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.bioLinkLabel_LinkClicked); 59 | // 60 | // iconPictureBox 61 | // 62 | this.iconPictureBox.BackgroundImage = global::PS4Macro.Properties.Resources.icon_img; 63 | this.iconPictureBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 64 | this.iconPictureBox.Location = new System.Drawing.Point(12, 12); 65 | this.iconPictureBox.Name = "iconPictureBox"; 66 | this.iconPictureBox.Size = new System.Drawing.Size(84, 87); 67 | this.iconPictureBox.TabIndex = 2; 68 | this.iconPictureBox.TabStop = false; 69 | // 70 | // titleLabel 71 | // 72 | this.titleLabel.AutoSize = true; 73 | this.titleLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222))); 74 | this.titleLabel.Location = new System.Drawing.Point(109, 12); 75 | this.titleLabel.Name = "titleLabel"; 76 | this.titleLabel.Size = new System.Drawing.Size(102, 24); 77 | this.titleLabel.TabIndex = 3; 78 | this.titleLabel.Text = "PS4 Macro"; 79 | // 80 | // githubLinkLabel 81 | // 82 | this.githubLinkLabel.AutoSize = true; 83 | this.githubLinkLabel.Location = new System.Drawing.Point(113, 36); 84 | this.githubLinkLabel.Name = "githubLinkLabel"; 85 | this.githubLinkLabel.Size = new System.Drawing.Size(192, 13); 86 | this.githubLinkLabel.TabIndex = 4; 87 | this.githubLinkLabel.TabStop = true; 88 | this.githubLinkLabel.Text = "https://github.com/komefai/PS4Macro"; 89 | // 90 | // AboutForm 91 | // 92 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 93 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 94 | this.ClientSize = new System.Drawing.Size(314, 113); 95 | this.Controls.Add(this.githubLinkLabel); 96 | this.Controls.Add(this.titleLabel); 97 | this.Controls.Add(this.iconPictureBox); 98 | this.Controls.Add(this.bioLinkLabel); 99 | this.Controls.Add(this.createdByLabel); 100 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 101 | this.MaximizeBox = false; 102 | this.MinimizeBox = false; 103 | this.Name = "AboutForm"; 104 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 105 | this.Text = "About"; 106 | ((System.ComponentModel.ISupportInitialize)(this.iconPictureBox)).EndInit(); 107 | this.ResumeLayout(false); 108 | this.PerformLayout(); 109 | 110 | } 111 | 112 | #endregion 113 | 114 | private System.Windows.Forms.Label createdByLabel; 115 | private System.Windows.Forms.LinkLabel bioLinkLabel; 116 | private System.Windows.Forms.PictureBox iconPictureBox; 117 | private System.Windows.Forms.Label titleLabel; 118 | private System.Windows.Forms.LinkLabel githubLinkLabel; 119 | } 120 | } -------------------------------------------------------------------------------- /PS4Macro/Forms/ImageHashForm.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Forms/ImageHashForm.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using PS4MacroAPI; 26 | using PS4MacroAPI.Internal; 27 | using System; 28 | using System.Collections.Generic; 29 | using System.ComponentModel; 30 | using System.Data; 31 | using System.Drawing; 32 | using System.IO; 33 | using System.Linq; 34 | using System.Text; 35 | using System.Threading; 36 | using System.Windows.Forms; 37 | 38 | namespace PS4Macro.Forms 39 | { 40 | public partial class ImageHashForm : Form 41 | { 42 | private string CurrentPath { get; set; } 43 | protected bool IsDataValid { get; set; } 44 | protected Image Image { get; set; } 45 | protected Thread GetDataThread { get; set; } 46 | 47 | public ImageHashForm() 48 | { 49 | InitializeComponent(); 50 | } 51 | 52 | private bool GetFilename(out string filename, DragEventArgs e) 53 | { 54 | bool ret = false; 55 | filename = String.Empty; 56 | if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) 57 | { 58 | Array data = e.Data.GetData("FileDrop") as Array; 59 | if (data != null) 60 | { 61 | if ((data.Length == 1) && (data.GetValue(0) is string)) 62 | { 63 | filename = ((string[])data)[0]; 64 | string ext = Path.GetExtension(filename).ToLower(); 65 | if ((ext == ".jpg") || (ext == ".png") || (ext == ".bmp")) 66 | { 67 | ret = true; 68 | } 69 | } 70 | } 71 | } 72 | return ret; 73 | } 74 | 75 | private void CompareImages() 76 | { 77 | if (imageAPictureBox.Image == null || imageBPictureBox.Image == null) 78 | return; 79 | 80 | var hashA = ImageHashing.AverageHash(imageAPictureBox.Image); 81 | var hashB = ImageHashing.AverageHash(imageBPictureBox.Image); 82 | 83 | //var similarity = ImageHashing.Similarity(imageAPictureBox.Image, imageBPictureBox.Image); 84 | var similarity = ImageHashing.Similarity(hashA, hashB); 85 | 86 | var message = String.Format("SIMILARITY: {0}%", similarity); 87 | //MessageBox.Show(message); 88 | compareButton.Text = message; 89 | } 90 | 91 | private void OnImageChanged(Image image, PictureBox pictureBox) 92 | { 93 | if (pictureBox == imageAPictureBox) 94 | { 95 | var hash = ImageHashing.AverageHash(imageAPictureBox.Image); 96 | imageAHashTextBox.Text = hash.ToString(); 97 | } 98 | else if (pictureBox == imageBPictureBox) 99 | { 100 | var hash = ImageHashing.AverageHash(imageBPictureBox.Image); 101 | imageBHashTextBox.Text = hash.ToString(); 102 | } 103 | } 104 | 105 | private void compareButton_Click(object sender, EventArgs e) 106 | { 107 | CompareImages(); 108 | } 109 | 110 | private void ImageHashForm_DragEnter(object sender, DragEventArgs e) 111 | { 112 | string inputPath; 113 | IsDataValid = GetFilename(out inputPath, e); 114 | if (IsDataValid) 115 | { 116 | CurrentPath = inputPath; 117 | GetDataThread = new Thread(new ThreadStart(() => 118 | { 119 | using (FileStream stream = new FileStream(CurrentPath, FileMode.Open, FileAccess.Read)) 120 | { 121 | Image = Image.FromStream(stream); 122 | } 123 | })); 124 | 125 | GetDataThread.Start(); 126 | e.Effect = DragDropEffects.Copy; 127 | } 128 | else 129 | e.Effect = DragDropEffects.None; 130 | } 131 | 132 | private void ImageHashForm_DragDrop(object sender, DragEventArgs e) 133 | { 134 | if (IsDataValid) 135 | { 136 | while (GetDataThread.IsAlive) 137 | { 138 | Application.DoEvents(); 139 | Thread.Sleep(0); 140 | } 141 | 142 | PictureBox pb = null; 143 | 144 | if (this.PointToClient(new Point(e.X, e.Y)).X <= Size.Width / 2) 145 | pb = imageAPictureBox; 146 | else 147 | pb = imageBPictureBox; 148 | 149 | pb.Image = Image; 150 | OnImageChanged(Image, pb); 151 | } 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /PS4Macro/Forms/AboutForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /PS4Macro/Forms/ImageHashForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /PS4Macro/Forms/StatusCheckerForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /PS4Macro/Forms/MacroCompressorForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /PS4Macro/Forms/ResizeRemotePlayForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /PS4Macro/Classes/SaveLoadHelper.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Classes/SaveLoadHelper.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using PS4Macro.Forms; 26 | using System; 27 | using System.Collections.Generic; 28 | using System.ComponentModel; 29 | using System.IO; 30 | using System.Linq; 31 | using System.Reflection; 32 | using System.Text; 33 | using System.Windows.Forms; 34 | 35 | namespace PS4Macro.Classes 36 | { 37 | public class SaveLoadHelper : INotifyPropertyChanged 38 | { 39 | public const string DEFAULT_FILE_NAME = "untitled.xml"; 40 | public const string XML_FILTER = "XML Files (*.xml)|*.xml|All files (*.*)|*.*"; 41 | public const string LOAD_FILTER = "Supported Files (*.xml, *.dll)|*.xml;*.dll|All files (*.*)|*.*"; 42 | 43 | #region INotifyPropertyChanged 44 | public event PropertyChangedEventHandler PropertyChanged; 45 | private void NotifyPropertyChanged(string propertyName = "") 46 | { 47 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 48 | } 49 | #endregion 50 | 51 | #region Properties 52 | private string m_CurrentFile = null; 53 | public string CurrentFile 54 | { 55 | get { return m_CurrentFile; } 56 | private set 57 | { 58 | if (value != m_CurrentFile) 59 | { 60 | m_CurrentFile = value; 61 | NotifyPropertyChanged("CurrentFile"); 62 | } 63 | } 64 | } 65 | #endregion 66 | 67 | private MainForm m_MainForm; 68 | private MacroPlayer m_MacroPlayer; 69 | 70 | /* Constructor */ 71 | public SaveLoadHelper(MainForm mainForm, MacroPlayer macroPlayer) 72 | { 73 | m_MainForm = mainForm; 74 | m_MacroPlayer = macroPlayer; 75 | } 76 | 77 | public void ClearCurrentFile() 78 | { 79 | CurrentFile = null; 80 | } 81 | 82 | public void DirectLoad(string filename) 83 | { 84 | // Load 85 | CurrentFile = filename; 86 | 87 | try 88 | { 89 | // Macro 90 | if (CurrentFile.EndsWith("xml")) 91 | { 92 | m_MainForm.LoadMacro(CurrentFile); 93 | } 94 | // Script 95 | else if (CurrentFile.EndsWith("dll")) 96 | { 97 | m_MainForm.LoadScript(CurrentFile); 98 | } 99 | // Invalid 100 | else 101 | { 102 | ClearCurrentFile(); 103 | } 104 | } 105 | catch (Exception ex) 106 | { 107 | ClearCurrentFile(); 108 | MessageBox.Show(ex.Message, "Open Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); 109 | } 110 | } 111 | 112 | public void Load() 113 | { 114 | OpenFileDialog openFileDialog = new OpenFileDialog(); 115 | 116 | openFileDialog.InitialDirectory = Assembly.GetExecutingAssembly().Location; 117 | openFileDialog.Filter = LOAD_FILTER; 118 | openFileDialog.FilterIndex = 0; 119 | openFileDialog.RestoreDirectory = true; 120 | 121 | if (openFileDialog.ShowDialog() == DialogResult.OK) 122 | { 123 | // Load 124 | DirectLoad(openFileDialog.FileName); 125 | } 126 | } 127 | 128 | public void Save() 129 | { 130 | // Currently has a file loaded 131 | if (!string.IsNullOrWhiteSpace(CurrentFile)) 132 | { 133 | if (File.Exists(CurrentFile)) 134 | { 135 | // Save 136 | m_MacroPlayer.SaveFile(CurrentFile); 137 | } 138 | else 139 | { 140 | // Save as 141 | SaveAs(DEFAULT_FILE_NAME); 142 | } 143 | } 144 | // No file loaded 145 | else 146 | { 147 | // Save as 148 | SaveAs(DEFAULT_FILE_NAME); 149 | } 150 | } 151 | 152 | public void SaveAs(string fileName = null) 153 | { 154 | SaveFileDialog saveFileDialog = new SaveFileDialog(); 155 | 156 | saveFileDialog.InitialDirectory = Assembly.GetExecutingAssembly().Location; 157 | saveFileDialog.Filter = XML_FILTER; 158 | saveFileDialog.FilterIndex = 0; 159 | saveFileDialog.RestoreDirectory = true; 160 | saveFileDialog.FileName = fileName == null ? Path.GetFileName(CurrentFile) : fileName; 161 | 162 | if (saveFileDialog.ShowDialog() == DialogResult.OK) 163 | { 164 | // Save 165 | CurrentFile = saveFileDialog.FileName; 166 | m_MacroPlayer.SaveFile(CurrentFile); 167 | } 168 | } 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /PS4Macro/Classes/ScriptHostUtility.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Classes/ScriptHostUtility.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.IO; 28 | using System.Linq; 29 | using System.Text; 30 | using System.Xml.Serialization; 31 | 32 | namespace PS4Macro.Classes 33 | { 34 | class ScriptHostUtility 35 | { 36 | public static PS4RemotePlayInterceptor.DualShockState ConvertAPIToInterceptorState(PS4MacroAPI.DualShockState state) 37 | { 38 | var serialized = SerializeAPIState(state); 39 | return DeserializeInterceptorState(serialized); 40 | } 41 | 42 | public static PS4MacroAPI.DualShockState ConvertInterceptorToAPIState(PS4RemotePlayInterceptor.DualShockState state) 43 | { 44 | var serialized = SerializeInterceptorState(state); 45 | return DeserializeAPIState(serialized); 46 | } 47 | 48 | public static string SerializeAPIState(PS4MacroAPI.DualShockState state) 49 | { 50 | XmlSerializer serializer = new XmlSerializer(typeof(PS4MacroAPI.DualShockState)); 51 | var sb = new StringBuilder(); 52 | 53 | using (StringWriter writer = new StringWriter(sb)) 54 | { 55 | serializer.Serialize(writer, state); 56 | return sb.ToString(); 57 | } 58 | } 59 | 60 | public static PS4MacroAPI.DualShockState DeserializeAPIState(string data) 61 | { 62 | XmlSerializer deserializer = new XmlSerializer(typeof(PS4MacroAPI.DualShockState)); 63 | using (StringReader reader = new StringReader(data)) 64 | { 65 | object obj = deserializer.Deserialize(reader); 66 | return obj as PS4MacroAPI.DualShockState; 67 | } 68 | } 69 | 70 | public static string SerializeInterceptorState(PS4RemotePlayInterceptor.DualShockState state) 71 | { 72 | XmlSerializer serializer = new XmlSerializer(typeof(PS4RemotePlayInterceptor.DualShockState)); 73 | var sb = new StringBuilder(); 74 | 75 | using (StringWriter writer = new StringWriter(sb)) 76 | { 77 | serializer.Serialize(writer, state); 78 | return sb.ToString(); 79 | } 80 | } 81 | 82 | public static PS4RemotePlayInterceptor.DualShockState DeserializeInterceptorState(string data) 83 | { 84 | XmlSerializer deserializer = new XmlSerializer(typeof(PS4RemotePlayInterceptor.DualShockState)); 85 | using (StringReader reader = new StringReader(data)) 86 | { 87 | object obj = deserializer.Deserialize(reader); 88 | return obj as PS4RemotePlayInterceptor.DualShockState; 89 | } 90 | } 91 | 92 | #region Sequence 93 | public static List ConvertAPIToInterceptorSequence(List sequence) 94 | { 95 | var serialized = SerializeAPISequence(sequence); 96 | return DeserializeInterceptorSequence(serialized); 97 | } 98 | 99 | public static List ConvertInterceptorToAPISequence(List sequence) 100 | { 101 | var serialized = SerializeInterceptorSequence(sequence); 102 | return DeserializeAPISequence(serialized); 103 | } 104 | 105 | public static string SerializeAPISequence(List sequence) 106 | { 107 | XmlSerializer serializer = new XmlSerializer(typeof(List)); 108 | var sb = new StringBuilder(); 109 | 110 | using (StringWriter writer = new StringWriter(sb)) 111 | { 112 | serializer.Serialize(writer, sequence); 113 | return sb.ToString(); 114 | } 115 | } 116 | 117 | public static List DeserializeAPISequence(string data) 118 | { 119 | XmlSerializer deserializer = new XmlSerializer(typeof(List)); 120 | using (StringReader reader = new StringReader(data)) 121 | { 122 | object obj = deserializer.Deserialize(reader); 123 | return obj as List; 124 | } 125 | } 126 | 127 | public static string SerializeInterceptorSequence(List sequence) 128 | { 129 | XmlSerializer serializer = new XmlSerializer(typeof(List)); 130 | var sb = new StringBuilder(); 131 | 132 | using (StringWriter writer = new StringWriter(sb)) 133 | { 134 | serializer.Serialize(writer, sequence); 135 | return sb.ToString(); 136 | } 137 | } 138 | 139 | public static List DeserializeInterceptorSequence(string data) 140 | { 141 | XmlSerializer deserializer = new XmlSerializer(typeof(List)); 142 | using (StringReader reader = new StringReader(data)) 143 | { 144 | object obj = deserializer.Deserialize(reader); 145 | return obj as List; 146 | } 147 | } 148 | #endregion 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /PS4MacroAPI/Internal/BackgroundCapture.cs: -------------------------------------------------------------------------------- 1 | // PS4MacroAPI (File: Internal/BackgroundCapture.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Drawing; 28 | using System.Drawing.Imaging; 29 | using System.Linq; 30 | using System.Runtime.InteropServices; 31 | using System.Text; 32 | 33 | namespace PS4MacroAPI.Internal 34 | { 35 | // References 36 | // http://www.developerfusion.com/code/4630/capture-a-screen-shot/ 37 | 38 | /// 39 | /// Provides functions to capture the entire screen, or a particular window, and save it to a file. 40 | /// 41 | public class BackgroundCapture 42 | { 43 | /// 44 | /// Creates an Image object containing a screen shot of the entire desktop 45 | /// 46 | /// 47 | public static Image CaptureScreen() 48 | { 49 | return CaptureWindow(User32.GetDesktopWindow()); 50 | } 51 | /// 52 | /// Creates an Image object containing a screen shot of a specific window 53 | /// 54 | /// The handle to the window. (In windows forms, this is obtained by the Handle property) 55 | /// 56 | public static Image CaptureWindow(IntPtr handle) 57 | { 58 | // get te hDC of the target window 59 | IntPtr hdcSrc = User32.GetWindowDC(handle); 60 | // get the size 61 | User32.RECT windowRect = new User32.RECT(); 62 | User32.GetWindowRect(handle, ref windowRect); 63 | int width = windowRect.right - windowRect.left; 64 | int height = windowRect.bottom - windowRect.top; 65 | // create a device context we can copy to 66 | IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc); 67 | // create a bitmap we can copy it to, 68 | // using GetDeviceCaps to get the width/height 69 | IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height); 70 | // select the bitmap object 71 | IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap); 72 | // bitblt over 73 | GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY); 74 | // restore selection 75 | GDI32.SelectObject(hdcDest, hOld); 76 | // clean up 77 | GDI32.DeleteDC(hdcDest); 78 | User32.ReleaseDC(handle, hdcSrc); 79 | // get a .NET image object for it 80 | Image img = Image.FromHbitmap(hBitmap); 81 | // free up the Bitmap object 82 | GDI32.DeleteObject(hBitmap); 83 | return img; 84 | } 85 | /// 86 | /// Captures a screen shot of a specific window, and saves it to a file 87 | /// 88 | /// 89 | /// 90 | /// 91 | public static void CaptureWindowToFile(IntPtr handle, string filename, ImageFormat format) 92 | { 93 | Image img = CaptureWindow(handle); 94 | img.Save(filename, format); 95 | } 96 | /// 97 | /// Captures a screen shot of the entire desktop, and saves it to a file 98 | /// 99 | /// 100 | /// 101 | public static void CaptureScreenToFile(string filename, ImageFormat format) 102 | { 103 | Image img = CaptureScreen(); 104 | img.Save(filename, format); 105 | } 106 | 107 | /// 108 | /// Helper class containing Gdi32 API functions 109 | /// 110 | private class GDI32 111 | { 112 | 113 | public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter 114 | [DllImport("gdi32.dll")] 115 | public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest, 116 | int nWidth, int nHeight, IntPtr hObjectSource, 117 | int nXSrc, int nYSrc, int dwRop); 118 | [DllImport("gdi32.dll")] 119 | public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth, 120 | int nHeight); 121 | [DllImport("gdi32.dll")] 122 | public static extern IntPtr CreateCompatibleDC(IntPtr hDC); 123 | [DllImport("gdi32.dll")] 124 | public static extern bool DeleteDC(IntPtr hDC); 125 | [DllImport("gdi32.dll")] 126 | public static extern bool DeleteObject(IntPtr hObject); 127 | [DllImport("gdi32.dll")] 128 | public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject); 129 | } 130 | 131 | /// 132 | /// Helper class containing User32 API functions 133 | /// 134 | private class User32 135 | { 136 | [StructLayout(LayoutKind.Sequential)] 137 | public struct RECT 138 | { 139 | public int left; 140 | public int top; 141 | public int right; 142 | public int bottom; 143 | } 144 | [DllImport("user32.dll")] 145 | public static extern IntPtr GetDesktopWindow(); 146 | [DllImport("user32.dll")] 147 | public static extern IntPtr GetWindowDC(IntPtr hWnd); 148 | [DllImport("user32.dll")] 149 | public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC); 150 | [DllImport("user32.dll")] 151 | public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect); 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /PS4Macro/Classes/StatusChecker.cs: -------------------------------------------------------------------------------- 1 | // PS4Macro (File: Classes/StatusChecker.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using PS4Macro.Classes.GlobalHooks; 26 | using PS4Macro.Classes.Remapping; 27 | using PS4RemotePlayInterceptor; 28 | using System; 29 | using System.Collections.Generic; 30 | using System.Diagnostics; 31 | using System.IO; 32 | using System.Linq; 33 | using System.Text; 34 | using System.Threading; 35 | using System.Xml.Serialization; 36 | 37 | namespace PS4Macro.Classes 38 | { 39 | public class StatusCheckData 40 | { 41 | public TimeSpan TimeoutInterval { get; private set; } 42 | 43 | public bool DidWorkOnce { get; set; } 44 | public bool IsWorking { get; set; } 45 | public DateTime LastWorkingTimestamp { get; set; } 46 | 47 | public StatusCheckData(TimeSpan timeoutInterval) 48 | { 49 | TimeoutInterval = timeoutInterval; 50 | } 51 | 52 | public StatusCheckData() 53 | { 54 | TimeoutInterval = TimeSpan.MinValue; 55 | } 56 | } 57 | 58 | public class StatusChecker 59 | { 60 | private const int TIMER_DUE_TIME = 0; 61 | private const int TIMER_PERIOD = 1000; 62 | 63 | // Delegates 64 | public delegate void OnStatusChangedDelegate(); 65 | public OnStatusChangedDelegate OnStatusChanged { get; set; } 66 | 67 | public Process RemotePlayProcess { get; set; } 68 | public IntPtr ForegroundWindowHandle { get; set; } 69 | public IntPtr MainWindowHandle { get; set; } 70 | 71 | public List StatusList { get; private set; } 72 | 73 | public StatusCheckData InterceptorStatus { get; private set; } 74 | public StatusCheckData KeyboardStatus { get; private set; } 75 | public StatusCheckData MouseStatus { get; private set; } 76 | 77 | public bool IsActive { get; private set; } 78 | 79 | private Timer m_Timer = null; 80 | private AutoResetEvent m_AutoEvent = null; 81 | 82 | public StatusChecker() 83 | { 84 | InterceptorStatus = new StatusCheckData(TimeSpan.FromSeconds(1)); 85 | KeyboardStatus = new StatusCheckData(); 86 | MouseStatus = new StatusCheckData(); 87 | 88 | StatusList = new List() 89 | { 90 | InterceptorStatus, KeyboardStatus, MouseStatus 91 | }; 92 | 93 | m_AutoEvent = new AutoResetEvent(false); 94 | m_Timer = new Timer(CheckStatus, m_AutoEvent, Timeout.Infinite, Timeout.Infinite); 95 | } 96 | 97 | public string GetSettingsText() 98 | { 99 | XmlSerializer serializer = new XmlSerializer(typeof(Settings)); 100 | using (StringWriter textWriter = new StringWriter()) 101 | { 102 | serializer.Serialize(textWriter, Program.Settings); 103 | return textWriter.ToString(); 104 | } 105 | } 106 | 107 | private void CheckStatus(object state) 108 | { 109 | // Process 110 | if (RemotePlayProcess != null) 111 | { 112 | var mainWindowHandle = RemotePlayProcess.MainWindowHandle; 113 | if (mainWindowHandle != MainWindowHandle) 114 | { 115 | MainWindowHandle = mainWindowHandle; 116 | OnStatusChanged?.Invoke(); 117 | } 118 | } 119 | 120 | var foregroundWindowHandle = RemapperUtility.GetForegroundWindow(); 121 | if (foregroundWindowHandle != ForegroundWindowHandle) 122 | { 123 | ForegroundWindowHandle = foregroundWindowHandle; 124 | OnStatusChanged?.Invoke(); 125 | } 126 | 127 | // Status 128 | foreach (var statusData in StatusList) 129 | { 130 | // Ignore infinite timeouts 131 | if (statusData.TimeoutInterval == TimeSpan.MinValue) 132 | continue; 133 | 134 | // Reset IsWorking flag if timeout 135 | var now = DateTime.Now; 136 | if (now - statusData.LastWorkingTimestamp >= statusData.TimeoutInterval) 137 | { 138 | statusData.IsWorking = false; 139 | } 140 | } 141 | } 142 | 143 | public void RefreshProcess() 144 | { 145 | try 146 | { 147 | if (RemotePlayProcess != null && !RemotePlayProcess.HasExited) 148 | { 149 | RemotePlayProcess.Refresh(); 150 | } 151 | } 152 | catch (Exception) { } 153 | } 154 | 155 | public void SetActive(bool active) 156 | { 157 | if (active == IsActive) return; 158 | 159 | if (active) 160 | { 161 | m_Timer.Change(TIMER_DUE_TIME, TIMER_PERIOD); 162 | } 163 | else 164 | { 165 | m_Timer.Change(Timeout.Infinite, Timeout.Infinite); 166 | } 167 | 168 | IsActive = active; 169 | } 170 | 171 | private void UpdateStatus(StatusCheckData status) 172 | { 173 | status.DidWorkOnce = true; 174 | status.IsWorking = true; 175 | status.LastWorkingTimestamp = DateTime.Now; 176 | OnStatusChanged?.Invoke(); 177 | } 178 | 179 | public void OnReceiveData(ref DualShockState state) 180 | { 181 | UpdateStatus(InterceptorStatus); 182 | } 183 | 184 | public void OnKeyPressed(object sender, GlobalKeyboardHookEventArgs e) 185 | { 186 | UpdateStatus(KeyboardStatus); 187 | } 188 | 189 | public void OnMouseEvent(object sender, GlobalMouseHookEventArgs e) 190 | { 191 | UpdateStatus(MouseStatus); 192 | } 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /PS4Macro/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\resources\icon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | 125 | ..\Resources\icon_img.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 126 | 127 | 128 | ..\resources\icon_joystick.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 129 | 130 | 131 | ..\resources\icon_repeat.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 132 | 133 | -------------------------------------------------------------------------------- /PS4Macro/Forms/RemapperForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | True 122 | 123 | 124 | True 125 | 126 | 127 | True 128 | 129 | 130 | True 131 | 132 | 133 | True 134 | 135 | 136 | True 137 | 138 | 139 | 140 | AAEAAAD/////AQAAAAAAAAAMAgAAAFFTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj00LjAuMC4wLCBDdWx0 141 | dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJh 142 | d2luZy5Qb2ludEYCAAAAAXgBeQAACwsCAAAAAAAAAAAAAAAL 143 | 144 | 145 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PS4 Macro 2 | 3 | [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/fold_left.svg?style=social&label=Follow%20Me)](https://twitter.com/itskomefai) 4 | [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](http://paypal.me/Komefai) 5 | 6 | Automation utility for PS4 Remote Play written in C# using [PS4RemotePlayInterceptor](https://github.com/komefai/PS4RemotePlayInterceptor). 7 | 8 | 🔔 **Download latest version [here](https://github.com/komefai/PS4Macro/releases)!** 9 | 10 | #### Screenshot 11 | 12 | ![Screenshot](https://raw.githubusercontent.com/komefai/PS4Macro/master/_resources/Screenshot_0_5_2.png) 13 | 14 | ## Usage 15 | 16 | ⚠️ To use WITHOUT a controller plugged in, see `EmulateController` in [Settings](https://github.com/komefai/PS4Macro#settings) section below. 17 | 18 | ##### Easy Way (shortcut) 19 | 20 | Press the touch button on your controller (touchpad) to start recording and press it again to stop. 21 | 22 | > NOTE: If you're using the touch button in the macro then disable it by going to Playback->Record On Touch 23 | 24 | ##### Manual Way 25 | 26 | To record, click on `RECORD` button (Ctrl+R) to arm recording then press `PLAY` to start recording controls. The red text on the bottom right indicates the number of frames recorded. You can stop recording by clicking on `RECORD` button (Ctrl+R) again. The macro will then play the controls in a loop. 27 | 28 | ## Settings 29 | 30 | You can create `settings.xml` using a text editor and place it in the same folder as `PS4Macro.exe` to override default settings. 31 | 32 | | Setting | Description | Default 33 | | --- | --- | --- | 34 | | AutoInject | Automatically poll for PS4 Remote Play and inject whenever possible | false | 35 | | BypassInjection | Bypass the injection for debugging purposes | false | 36 | | EmulateController | Run with controller emulation (use without a controller) | false | 37 | | ShowConsole | Open debugging console on launch | false | 38 | | StartupFile | Absolute or relative path to the file to load on launch (can be xml or dll) | null | 39 | 40 | ##### Example settings.xml 41 | 42 | ```xml 43 | 44 | 45 | true 46 | false 47 | true 48 | true 49 | MyMacro.xml 50 | 51 | ``` 52 | 53 | ## Command Line Arguments 54 | 55 | As of version 0.5.0, you can pass command line arguments to PS4Macro.exe and override the values in settings.xml. This also allows you to create multiple shortcuts to PS4Macro.exe and have each of them override the settings when switching between games (recommended for advanced users). 56 | 57 | #### Arguments 58 | 59 | | Argument | Description | Default 60 | | --- | --- | --- | 61 | | SettingsFile | Absolute or relative path to the settings file (will take priority) | null | 62 | 63 | #### Examples 64 | 65 | ##### Override settings using arguments 66 | 67 | ```bash 68 | C:\> PS4Macro.exe --AutoInject --EmulateController --ShowConsole=false --StartupFile="C:\macro.xml" 69 | ``` 70 | 71 | ##### Override default settings file (highest priority) 72 | 73 | ```bash 74 | C:\> PS4Macro.exe --SettingsFile="C:\custom-settings.xml" 75 | ``` 76 | 77 | ##### Using Windows shortcut 78 | 79 | Right-click on `PS4Macro.exe` and click on `Create shortcut` to create a new shortcut. Right-click on the newly created shortcut and select `Properties` and append your command line arguments after the existing text in the `Target` field. 80 | 81 | ![Command Line Shortcut](https://raw.githubusercontent.com/komefai/PS4Macro/master/_resources/CmdShortcut.png) 82 | 83 | ## Remapper 84 | 85 | Remapper allows you to use your keyboard to control PS4 games with customizable key bindings. To use Remapper, go to Tools->Remapper and focus on PS4 Remote Play to control the game. Simply close the window to return to marco or script mode. 86 | 87 | To map a key to a button or a macro, edit the **Key** cell and enter your desire key. You can find the key from the **Member name** column in [this table](https://msdn.microsoft.com/en-us/library/system.windows.forms.keys(v=vs.110).aspx) (eg. `Delete`, `NumPad4`, `PageDown`). Use key `None` to completely disable the key. 88 | 89 | To add a recorded macro, click on `...` to browse and select an xml macro file. 90 | 91 | ![Remapper](https://raw.githubusercontent.com/komefai/PS4Macro/master/_resources/Remapper.png) 92 | 93 | ## Scripting 94 | 95 | C# scripting support has been introduced in version 0.3.0 and later. This allows us to create custom behaviors beyond repeating macros with an easy-to-use API. The API also includes wrapped convenience functions such as pressing buttons, timing, and taking a screenshot from PS4 Remote Play. 96 | 97 | See the [scripting video tutorial](https://youtu.be/daCb97rbimA) to get started or see [the wiki](https://github.com/komefai/PS4Macro/wiki) for full documentation, examples, and other information. 98 | 99 | NOTE: The script have to include a reference to `PS4MacroAPI.dll` to interface with PS4Macro. At the moment the scripts has to be compiled into a DLL file to be able to open with PS4 Macro. 100 | 101 | ##### Basic Example Script 102 | 103 | This example script will press DPad up and wait one second, follow by pressing square. The loop repeats every 800ms. 104 | 105 | ```csharp 106 | using PS4MacroAPI; 107 | 108 | public class Script : ScriptBase 109 | { 110 | /* Constructor */ 111 | public Script() 112 | { 113 | Config.Name = "Example Script"; 114 | Config.LoopDelay = 800; 115 | } 116 | 117 | // Called when the user pressed play 118 | public override void Start() 119 | { 120 | base.Start(); 121 | } 122 | 123 | // Called every interval set by LoopDelay 124 | public override void Update() 125 | { 126 | Press(new DualShockState() { DPad_Up = true }); 127 | Sleep(1000); 128 | Press(new DualShockState() { Square = true }); 129 | } 130 | } 131 | ``` 132 | 133 | #### List of Scripts 134 | 135 | - [Keyboard Remapping Utility](https://github.com/komefai/PS4Macro.Remote) 136 | - [Marvel Heroes Omega Bot](https://github.com/komefai/PS4Macro.MarvelHeroesOmega) 137 | - [PES2018 Bot (Simulator Mode)](https://github.com/leguims/PS4Macro.PES2018Lite) by [leguims](https://github.com/leguims) 138 | 139 | --- 140 | 141 | ## Troubleshoot 142 | 143 | ##### Macro not playing/recording 144 | 145 | => Disable AutoInject in settings.xml since some machines does not support AutoInject. 146 | 147 | ##### EmulateController does not work 148 | 149 | => Make sure you unplug every DualShock 4 controllers from your computer (otherwise the real controller will take priority over the emulated one). Start PS4 Remote Play, follow by PS4 Macro and wait for this screen. If you see the text `Press the OPTIONS button on the controller to start.` then it means that the emulated controller is working correctly. You can then press the Start button. 150 | 151 | ![Emulate Controller Troubleshoot](https://raw.githubusercontent.com/komefai/PS4Macro/master/_resources/EmulateControllerTroubleshoot.png) 152 | 153 | ##### Visual Studio Build Error 154 | 155 | => Reinstall NuGet Package. 156 | 157 | ``` 158 | Update-Package –reinstall PS4RemotePlayInterceptor 159 | ``` 160 | 161 | ## To-Do List 162 | 163 | - Improve scripting API docs 164 | - Playback timeline UI 165 | - Macro editor tool 166 | - Mouse support for Remapper 167 | - ... 168 | 169 | ## Resources 170 | 171 | - [Making Of Video](https://youtu.be/txI9AOEAk58) 172 | - [Scripting Tutorial Video](https://youtu.be/daCb97rbimA) 173 | - [Prototype Demo Video](https://youtu.be/QjTZsPR-BcI) 174 | 175 | ## Credits 176 | 177 | - [EasyHook](https://easyhook.github.io/) 178 | - [Jays2Kings/DS4Windows](https://github.com/Jays2Kings/DS4Windows) 179 | - [jforshee/ImageHashing](https://github.com/jforshee/ImageHashing) 180 | - [Mono.Options](https://www.nuget.org/packages/Mono.Options/) 181 | -------------------------------------------------------------------------------- /PS4MacroAPI/Internal/ImageHashing.cs: -------------------------------------------------------------------------------- 1 | // PS4MacroAPI (File: Internal/ImageHashing.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.Drawing; 28 | using System.Drawing.Drawing2D; 29 | using System.Drawing.Imaging; 30 | using System.Linq; 31 | using System.Text; 32 | 33 | namespace PS4MacroAPI.Internal 34 | { 35 | // References 36 | // https://github.com/jforshee/ImageHashing 37 | 38 | /// 39 | /// Contains a variety of methods useful in generating image hashes for image comparison 40 | /// and recognition. 41 | /// 42 | /// Credit for the AverageHash implementation to David Oftedal of the University of Oslo. 43 | /// 44 | public class ImageHashing 45 | { 46 | #region Private constants and utility methods 47 | /// 48 | /// Bitcounts array used for BitCount method (used in Similarity comparisons). 49 | /// Don't try to read this or understand it, I certainly don't. Credit goes to 50 | /// David Oftedal of the University of Oslo, Norway for this. 51 | /// http://folk.uio.no/davidjo/computing.php 52 | /// 53 | private static byte[] bitCounts = { 54 | 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4, 55 | 2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, 56 | 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6, 57 | 4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 58 | 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5, 59 | 3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, 60 | 4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8 61 | }; 62 | 63 | /// 64 | /// Counts bits (duh). Utility function for similarity. 65 | /// I wouldn't try to understand this. I just copy-pasta'd it 66 | /// from Oftedal's implementation. It works. 67 | /// 68 | /// The hash we are counting. 69 | /// The total bit count. 70 | private static uint BitCount(ulong num) 71 | { 72 | uint count = 0; 73 | for (; num > 0; num >>= 8) 74 | count += bitCounts[(num & 0xff)]; 75 | return count; 76 | } 77 | #endregion 78 | 79 | #region Public interface methods 80 | /// 81 | /// Computes the average hash of an image according to the algorithm given by Dr. Neal Krawetz 82 | /// on his blog: http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html. 83 | /// 84 | /// The image to hash. 85 | /// The hash of the image. 86 | public static ulong AverageHash(Image image) 87 | { 88 | // Squeeze the image into an 8x8 canvas 89 | Bitmap squeezed = new Bitmap(8, 8, PixelFormat.Format32bppRgb); 90 | Graphics canvas = Graphics.FromImage(squeezed); 91 | canvas.CompositingQuality = CompositingQuality.HighQuality; 92 | canvas.InterpolationMode = InterpolationMode.HighQualityBilinear; 93 | canvas.SmoothingMode = SmoothingMode.HighQuality; 94 | canvas.DrawImage(image, 0, 0, 8, 8); 95 | 96 | // Reduce colors to 6-bit grayscale and calculate average color value 97 | byte[] grayscale = new byte[64]; 98 | uint averageValue = 0; 99 | for (int y = 0; y < 8; y++) 100 | for (int x = 0; x < 8; x++) 101 | { 102 | uint pixel = (uint)squeezed.GetPixel(x, y).ToArgb(); 103 | uint gray = (pixel & 0x00ff0000) >> 16; 104 | gray += (pixel & 0x0000ff00) >> 8; 105 | gray += (pixel & 0x000000ff); 106 | gray /= 12; 107 | 108 | grayscale[x + (y * 8)] = (byte)gray; 109 | averageValue += gray; 110 | } 111 | averageValue /= 64; 112 | 113 | // Compute the hash: each bit is a pixel 114 | // 1 = higher than average, 0 = lower than average 115 | ulong hash = 0; 116 | for (int i = 0; i < 64; i++) 117 | if (grayscale[i] >= averageValue) 118 | hash |= (1UL << (63 - i)); 119 | 120 | return hash; 121 | } 122 | 123 | /// 124 | /// Computes the average hash of the image content in the given file. 125 | /// 126 | /// Path to the input file. 127 | /// The hash of the input file's image content. 128 | public static ulong AverageHash(String path) 129 | { 130 | Bitmap bmp = new Bitmap(path); 131 | return AverageHash(bmp); 132 | } 133 | 134 | /// 135 | /// Returns a percentage-based similarity value between the two given hashes. The higher 136 | /// the percentage, the closer the hashes are to being identical. 137 | /// 138 | /// The first hash. 139 | /// The second hash. 140 | /// The similarity percentage. 141 | public static double Similarity(ulong hash1, ulong hash2) 142 | { 143 | return ((64 - BitCount(hash1 ^ hash2)) * 100) / 64.0; 144 | } 145 | 146 | /// 147 | /// Returns a percentage-based similarity value between the two given images. The higher 148 | /// the percentage, the closer the images are to being identical. 149 | /// 150 | /// The first image. 151 | /// The second image. 152 | /// The similarity percentage. 153 | public static double Similarity(Image image1, Image image2) 154 | { 155 | ulong hash1 = AverageHash(image1); 156 | ulong hash2 = AverageHash(image2); 157 | return Similarity(hash1, hash2); 158 | } 159 | 160 | /// 161 | /// Returns a percentage-based similarity value between the image content of the two given 162 | /// files. The higher the percentage, the closer the image contents are to being identical. 163 | /// 164 | /// The first image file. 165 | /// The second image file. 166 | /// The similarity percentage. 167 | public static double Similarity(String path1, String path2) 168 | { 169 | ulong hash1 = AverageHash(path1); 170 | ulong hash2 = AverageHash(path2); 171 | return Similarity(hash1, hash2); 172 | } 173 | #endregion 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /PS4MacroAPI/Bridge/DualShockState.cs: -------------------------------------------------------------------------------- 1 | // PS4MacroAPI (File: Bridge/DualShockState.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using System; 26 | using System.Collections.Generic; 27 | using System.IO; 28 | using System.Linq; 29 | using System.Text; 30 | using System.Xml.Serialization; 31 | 32 | namespace PS4MacroAPI 33 | { 34 | public class Touch 35 | { 36 | public byte TouchID { get; set; } 37 | public bool IsTouched { get; set; } 38 | public int X { get; set; } 39 | public int Y { get; set; } 40 | 41 | /* Constructors */ 42 | public Touch() { } 43 | public Touch(byte touchID, bool isTouched, int x, int y) 44 | { 45 | TouchID = touchID; 46 | IsTouched = isTouched; 47 | X = x; 48 | Y = y; 49 | } 50 | public Touch(Touch touch) 51 | { 52 | TouchID = touch.TouchID; 53 | IsTouched = touch.IsTouched; 54 | X = touch.X; 55 | Y = touch.Y; 56 | } 57 | 58 | public Touch Clone() 59 | { 60 | return new Touch(this); 61 | } 62 | } 63 | 64 | public class DualShockState 65 | { 66 | public const int TOUCHPAD_DATA_OFFSET = 35; 67 | 68 | private enum VK : byte 69 | { 70 | L2 = 1 << 2, 71 | R2 = 1 << 3, 72 | Triangle = 1 << 7, 73 | Circle = 1 << 6, 74 | Cross = 1 << 5, 75 | Square = 1 << 4, 76 | DPad_Up = 1 << 3, 77 | DPad_Down = 1 << 2, 78 | DPad_Left = 1 << 1, 79 | DPad_Right = 1 << 0, 80 | L1 = 1 << 0, 81 | R1 = 1 << 1, 82 | Share = 1 << 4, 83 | Options = 1 << 5, 84 | L3 = 1 << 6, 85 | R3 = 1 << 7, 86 | PS = 1 << 0, 87 | TouchButton = 1 << 2 - 1 88 | } 89 | 90 | public DateTime ReportTimeStamp { get; set; } 91 | public byte LX { get; set; } 92 | public byte LY { get; set; } 93 | public byte RX { get; set; } 94 | public byte RY { get; set; } 95 | public byte L2 { get; set; } 96 | public byte R2 { get; set; } 97 | public bool Triangle { get; set; } 98 | public bool Circle { get; set; } 99 | public bool Cross { get; set; } 100 | public bool Square { get; set; } 101 | public bool DPad_Up { get; set; } 102 | public bool DPad_Down { get; set; } 103 | public bool DPad_Left { get; set; } 104 | public bool DPad_Right { get; set; } 105 | public bool L1 { get; set; } 106 | public bool R1 { get; set; } 107 | public bool Share { get; set; } 108 | public bool Options { get; set; } 109 | public bool L3 { get; set; } 110 | public bool R3 { get; set; } 111 | public bool PS { get; set; } 112 | 113 | public Touch Touch1 { get; set; } 114 | public Touch Touch2 { get; set; } 115 | public bool TouchButton { get; set; } 116 | public byte TouchPacketCounter { get; set; } 117 | 118 | public byte FrameCounter { get; set; } 119 | public byte Battery { get; set; } 120 | public bool IsCharging { get; set; } 121 | 122 | public short AccelX { get; set; } 123 | public short AccelY { get; set; } 124 | public short AccelZ { get; set; } 125 | public short GyroX { get; set; } 126 | public short GyroY { get; set; } 127 | public short GyroZ { get; set; } 128 | 129 | /* Constructor */ 130 | public DualShockState() 131 | { 132 | LX = 0x80; 133 | LY = 0x80; 134 | RX = 0x80; 135 | RY = 0x80; 136 | FrameCounter = 255; // null 137 | TouchPacketCounter = 255; // null 138 | } 139 | 140 | public DualShockState(DualShockState state) 141 | { 142 | ReportTimeStamp = state.ReportTimeStamp; 143 | LX = state.LX; 144 | LY = state.LY; 145 | RX = state.RX; 146 | RY = state.RY; 147 | L2 = state.L2; 148 | R2 = state.R2; 149 | Triangle = state.Triangle; 150 | Circle = state.Circle; 151 | Cross = state.Cross; 152 | Square = state.Square; 153 | DPad_Up = state.DPad_Up; 154 | DPad_Down = state.DPad_Down; 155 | DPad_Left = state.DPad_Left; 156 | DPad_Right = state.DPad_Right; 157 | L1 = state.L1; 158 | R3 = state.R3; 159 | Share = state.Share; 160 | Options = state.Options; 161 | R1 = state.R1; 162 | L3 = state.L3; 163 | PS = state.PS; 164 | Touch1 = state.Touch1.Clone(); 165 | Touch2 = state.Touch2.Clone(); 166 | TouchButton = state.TouchButton; 167 | TouchPacketCounter = state.TouchPacketCounter; 168 | FrameCounter = state.FrameCounter; 169 | Battery = state.Battery; 170 | IsCharging = state.IsCharging; 171 | AccelX = state.AccelX; 172 | AccelY = state.AccelY; 173 | AccelZ = state.AccelZ; 174 | GyroX = state.GyroX; 175 | GyroY = state.GyroY; 176 | GyroZ = state.GyroZ; 177 | } 178 | 179 | public void CopyTo(DualShockState state) 180 | { 181 | state.ReportTimeStamp = ReportTimeStamp; 182 | state.LX = LX; 183 | state.LY = LY; 184 | state.RX = RX; 185 | state.RY = RY; 186 | state.L2 = L2; 187 | state.R2 = R2; 188 | state.Triangle = Triangle; 189 | state.Circle = Circle; 190 | state.Cross = Cross; 191 | state.Square = Square; 192 | state.DPad_Up = DPad_Up; 193 | state.DPad_Down = DPad_Down; 194 | state.DPad_Left = DPad_Left; 195 | state.DPad_Right = DPad_Right; 196 | state.L1 = L1; 197 | state.R3 = R3; 198 | state.Share = Share; 199 | state.Options = Options; 200 | state.R1 = R1; 201 | state.L3 = L3; 202 | state.PS = PS; 203 | state.Touch1 = Touch1.Clone(); 204 | state.Touch2 = Touch2.Clone(); 205 | state.TouchButton = TouchButton; 206 | state.TouchPacketCounter = TouchPacketCounter; 207 | state.FrameCounter = FrameCounter; 208 | state.Battery = Battery; 209 | state.IsCharging = IsCharging; 210 | state.AccelX = AccelX; 211 | state.AccelY = AccelY; 212 | state.AccelZ = AccelZ; 213 | state.GyroX = GyroX; 214 | state.GyroY = GyroY; 215 | state.GyroZ = GyroZ; 216 | } 217 | 218 | public DualShockState Clone() 219 | { 220 | return new DualShockState(this); 221 | } 222 | 223 | /// 224 | /// Serialize a list of DualShockState to xml file 225 | /// 226 | public static void Serialize(string path, List list) 227 | { 228 | XmlSerializer serializer = new XmlSerializer(typeof(List)); 229 | using (TextWriter writer = new StreamWriter(path)) 230 | { 231 | serializer.Serialize(writer, list); 232 | } 233 | } 234 | 235 | /// 236 | /// Deserialize a list of DualShockState from xml file 237 | /// 238 | public static List Deserialize(string path) 239 | { 240 | XmlSerializer deserializer = new XmlSerializer(typeof(List)); 241 | using (TextReader reader = new StreamReader(path)) 242 | { 243 | object obj = deserializer.Deserialize(reader); 244 | List list = obj as List; 245 | return list; 246 | } 247 | } 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /PS4Macro/Forms/MacroCompressorForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace PS4Macro.Forms 2 | { 3 | partial class MacroCompressorForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.inputGroupBox = new System.Windows.Forms.GroupBox(); 32 | this.framesCountLabel = new System.Windows.Forms.Label(); 33 | this.fileNameLabel = new System.Windows.Forms.Label(); 34 | this.exportButton = new System.Windows.Forms.Button(); 35 | this.filterGroupBox = new System.Windows.Forms.GroupBox(); 36 | this.deselectAllButton = new System.Windows.Forms.Button(); 37 | this.selectAllButton = new System.Windows.Forms.Button(); 38 | this.propertiesCheckedListBox = new System.Windows.Forms.CheckedListBox(); 39 | this.inputGroupBox.SuspendLayout(); 40 | this.filterGroupBox.SuspendLayout(); 41 | this.SuspendLayout(); 42 | // 43 | // inputGroupBox 44 | // 45 | this.inputGroupBox.Controls.Add(this.framesCountLabel); 46 | this.inputGroupBox.Controls.Add(this.fileNameLabel); 47 | this.inputGroupBox.Location = new System.Drawing.Point(12, 4); 48 | this.inputGroupBox.Name = "inputGroupBox"; 49 | this.inputGroupBox.Size = new System.Drawing.Size(191, 49); 50 | this.inputGroupBox.TabIndex = 3; 51 | this.inputGroupBox.TabStop = false; 52 | // 53 | // framesCountLabel 54 | // 55 | this.framesCountLabel.ForeColor = System.Drawing.SystemColors.ControlDark; 56 | this.framesCountLabel.Location = new System.Drawing.Point(6, 28); 57 | this.framesCountLabel.Name = "framesCountLabel"; 58 | this.framesCountLabel.Size = new System.Drawing.Size(179, 15); 59 | this.framesCountLabel.TabIndex = 1; 60 | this.framesCountLabel.Text = "..."; 61 | this.framesCountLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 62 | this.framesCountLabel.Click += new System.EventHandler(this.fileNameLabel_Click); 63 | // 64 | // fileNameLabel 65 | // 66 | this.fileNameLabel.Location = new System.Drawing.Point(6, 11); 67 | this.fileNameLabel.Name = "fileNameLabel"; 68 | this.fileNameLabel.Size = new System.Drawing.Size(179, 15); 69 | this.fileNameLabel.TabIndex = 0; 70 | this.fileNameLabel.Text = "Select or drop a macro here (*.xml)"; 71 | this.fileNameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 72 | this.fileNameLabel.Click += new System.EventHandler(this.fileNameLabel_Click); 73 | // 74 | // exportButton 75 | // 76 | this.exportButton.Enabled = false; 77 | this.exportButton.Location = new System.Drawing.Point(12, 306); 78 | this.exportButton.Name = "exportButton"; 79 | this.exportButton.Size = new System.Drawing.Size(191, 28); 80 | this.exportButton.TabIndex = 4; 81 | this.exportButton.Text = "Export Macro"; 82 | this.exportButton.UseVisualStyleBackColor = true; 83 | this.exportButton.Click += new System.EventHandler(this.exportButton_Click); 84 | // 85 | // filterGroupBox 86 | // 87 | this.filterGroupBox.Controls.Add(this.deselectAllButton); 88 | this.filterGroupBox.Controls.Add(this.selectAllButton); 89 | this.filterGroupBox.Controls.Add(this.propertiesCheckedListBox); 90 | this.filterGroupBox.Location = new System.Drawing.Point(12, 58); 91 | this.filterGroupBox.Name = "filterGroupBox"; 92 | this.filterGroupBox.Size = new System.Drawing.Size(191, 242); 93 | this.filterGroupBox.TabIndex = 5; 94 | this.filterGroupBox.TabStop = false; 95 | this.filterGroupBox.Text = "Include Filter"; 96 | // 97 | // deselectAllButton 98 | // 99 | this.deselectAllButton.Location = new System.Drawing.Point(101, 17); 100 | this.deselectAllButton.Name = "deselectAllButton"; 101 | this.deselectAllButton.Size = new System.Drawing.Size(75, 23); 102 | this.deselectAllButton.TabIndex = 5; 103 | this.deselectAllButton.Text = "Deselect All"; 104 | this.deselectAllButton.UseVisualStyleBackColor = true; 105 | this.deselectAllButton.Click += new System.EventHandler(this.deselectAllButton_Click); 106 | // 107 | // selectAllButton 108 | // 109 | this.selectAllButton.Location = new System.Drawing.Point(15, 17); 110 | this.selectAllButton.Name = "selectAllButton"; 111 | this.selectAllButton.Size = new System.Drawing.Size(75, 23); 112 | this.selectAllButton.TabIndex = 4; 113 | this.selectAllButton.Text = "Select All"; 114 | this.selectAllButton.UseVisualStyleBackColor = true; 115 | this.selectAllButton.Click += new System.EventHandler(this.selectAllButton_Click); 116 | // 117 | // propertiesCheckedListBox 118 | // 119 | this.propertiesCheckedListBox.CheckOnClick = true; 120 | this.propertiesCheckedListBox.FormattingEnabled = true; 121 | this.propertiesCheckedListBox.Items.AddRange(new object[] { 122 | "ReportTimeStamp", 123 | "LX", 124 | "LY", 125 | "RX", 126 | "RY", 127 | "L2", 128 | "R2", 129 | "Triangle", 130 | "Circle", 131 | "Cross", 132 | "Square", 133 | "DPad_Up", 134 | "DPad_Down", 135 | "DPad_Left", 136 | "DPad_Right", 137 | "L1", 138 | "R3", 139 | "Share", 140 | "Options", 141 | "R1", 142 | "L3", 143 | "PS", 144 | "TouchButton", 145 | "Touch1", 146 | "Touch2", 147 | "TouchPacketCounter", 148 | "FrameCounter", 149 | "Battery", 150 | "IsCharging", 151 | "AccelX", 152 | "AccelY", 153 | "AccelZ", 154 | "GyroX", 155 | "GyroY", 156 | "GyroZ"}); 157 | this.propertiesCheckedListBox.Location = new System.Drawing.Point(6, 48); 158 | this.propertiesCheckedListBox.Name = "propertiesCheckedListBox"; 159 | this.propertiesCheckedListBox.Size = new System.Drawing.Size(179, 184); 160 | this.propertiesCheckedListBox.TabIndex = 3; 161 | this.propertiesCheckedListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.propertiesCheckedListBox_ItemCheck); 162 | // 163 | // MacroCompressorForm 164 | // 165 | this.AllowDrop = true; 166 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 167 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 168 | this.ClientSize = new System.Drawing.Size(215, 341); 169 | this.Controls.Add(this.filterGroupBox); 170 | this.Controls.Add(this.exportButton); 171 | this.Controls.Add(this.inputGroupBox); 172 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; 173 | this.Name = "MacroCompressorForm"; 174 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 175 | this.Text = "Macro Compressor"; 176 | this.DragDrop += new System.Windows.Forms.DragEventHandler(this.MacroCompressorForm_DragDrop); 177 | this.DragEnter += new System.Windows.Forms.DragEventHandler(this.MacroCompressorForm_DragEnter); 178 | this.inputGroupBox.ResumeLayout(false); 179 | this.filterGroupBox.ResumeLayout(false); 180 | this.ResumeLayout(false); 181 | 182 | } 183 | 184 | #endregion 185 | private System.Windows.Forms.GroupBox inputGroupBox; 186 | private System.Windows.Forms.Label fileNameLabel; 187 | private System.Windows.Forms.Label framesCountLabel; 188 | private System.Windows.Forms.Button exportButton; 189 | private System.Windows.Forms.GroupBox filterGroupBox; 190 | private System.Windows.Forms.Button deselectAllButton; 191 | private System.Windows.Forms.Button selectAllButton; 192 | private System.Windows.Forms.CheckedListBox propertiesCheckedListBox; 193 | } 194 | } -------------------------------------------------------------------------------- /PS4MacroAPI/Internal/ScriptUtility.cs: -------------------------------------------------------------------------------- 1 | // PS4MacroAPI (File: Internal/ScriptUtility.cs) 2 | // 3 | // Copyright (c) 2018 Komefai 4 | // 5 | // Visit http://komefai.com for more information 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | 25 | using PS4MacroAPI.Internal; 26 | using System; 27 | using System.Collections.Generic; 28 | using System.Diagnostics; 29 | using System.Drawing; 30 | using System.IO; 31 | using System.Linq; 32 | using System.Reflection; 33 | using System.Text; 34 | 35 | namespace PS4MacroAPI.Internal 36 | { 37 | /// 38 | /// Utility class for scripts 39 | /// 40 | public class ScriptUtility 41 | { 42 | /// 43 | /// Find PS4 Macro process 44 | /// 45 | /// 46 | public static Process FindProcess() 47 | { 48 | Process[] processes = Process.GetProcessesByName("PS4Macro"); 49 | foreach (var process in processes) 50 | { 51 | return process; 52 | } 53 | return null; 54 | } 55 | 56 | /// 57 | /// Find PS4 Remote Play process 58 | /// 59 | /// 60 | public static Process FindRemotePlayProcess() 61 | { 62 | Process[] processes = Process.GetProcessesByName("RemotePlay"); 63 | foreach (var process in processes) 64 | { 65 | return process; 66 | } 67 | return null; 68 | } 69 | 70 | /// 71 | /// Find the streaming panel of PS4 Remote Play 72 | /// 73 | /// 74 | /// 75 | public static IntPtr FindStreamingPanel(Process remotePlayProcess) 76 | { 77 | // Find panel in process 78 | var childHandles = WindowControl.GetAllChildHandles(remotePlayProcess.MainWindowHandle); 79 | var panelHandle = childHandles.Find(ptr => 80 | { 81 | var sb = new StringBuilder(50); 82 | WindowControl.GetClassName(ptr, sb, 50); 83 | var str = sb.ToString(); 84 | return str == "WindowsForms10.Window.8.app.0.141b42a_r9_ad1" || str == "WindowsForms10.Window.8.app.0.141b42a_r10_ad1"; 85 | }); 86 | 87 | // Try to find the best one possible instead 88 | if (panelHandle == IntPtr.Zero) 89 | { 90 | IntPtr biggestPanel = IntPtr.Zero; 91 | Rect biggestSize = new Rect(); 92 | foreach (var ptr in childHandles) 93 | { 94 | Rect rect = new Rect(); 95 | WindowControl.GetWindowRect(ptr, ref rect); 96 | 97 | if (rect.Bottom - rect.Top >= biggestSize.Bottom - biggestSize.Top) 98 | { 99 | biggestPanel = ptr; 100 | biggestSize = rect; 101 | } 102 | } 103 | 104 | panelHandle = biggestPanel; 105 | } 106 | 107 | return panelHandle; 108 | } 109 | 110 | /// 111 | /// Load scripts from path 112 | /// 113 | /// 114 | /// 115 | public static List LoadScripts(string path) 116 | { 117 | string[] dllFileNames = null; 118 | if (Directory.Exists(path)) 119 | { 120 | dllFileNames = Directory.GetFiles(path, "*.dll"); 121 | } 122 | 123 | ICollection assemblies = new List(dllFileNames.Length); 124 | foreach (string dllFile in dllFileNames) 125 | { 126 | AssemblyName an = AssemblyName.GetAssemblyName(dllFile); 127 | 128 | // Ignore self 129 | if (an.Name == "PS4MacroAPI") 130 | continue; 131 | 132 | Assembly assembly = Assembly.Load(an); 133 | assemblies.Add(assembly); 134 | } 135 | 136 | Type scriptType = typeof(ScriptBase); 137 | ICollection scriptTypes = new List(); 138 | foreach (Assembly assembly in assemblies) 139 | { 140 | if (assembly != null) 141 | { 142 | Type[] types = assembly.GetTypes(); 143 | foreach (Type type in types) 144 | { 145 | if (type.IsInterface || type.IsAbstract) 146 | { 147 | continue; 148 | } 149 | else 150 | { 151 | if (type.IsSubclassOf(scriptType)) 152 | { 153 | scriptTypes.Add(type); 154 | } 155 | } 156 | } 157 | } 158 | } 159 | 160 | List scripts = new List(scriptTypes.Count); 161 | foreach (Type type in scriptTypes) 162 | { 163 | ScriptBase script = (ScriptBase)Activator.CreateInstance(type); 164 | scripts.Add(script); 165 | } 166 | 167 | return scripts; 168 | } 169 | 170 | /// 171 | /// Load a script from path 172 | /// 173 | /// 174 | /// 175 | public static ScriptBase LoadScript(string dllFile) 176 | { 177 | AssemblyName an = AssemblyName.GetAssemblyName(dllFile); 178 | Assembly assembly = Assembly.Load(an); 179 | 180 | Type scriptType = typeof(ScriptBase); 181 | 182 | if (assembly != null) 183 | { 184 | Type[] types = assembly.GetTypes(); 185 | foreach (Type type in types) 186 | { 187 | if (type.IsInterface || type.IsAbstract) 188 | { 189 | continue; 190 | } 191 | else 192 | { 193 | if (type.IsSubclassOf(scriptType)) 194 | { 195 | ScriptBase script = (ScriptBase)Activator.CreateInstance(type); 196 | return script; 197 | } 198 | } 199 | } 200 | } 201 | 202 | return null; 203 | } 204 | 205 | /// 206 | /// Create a window control temporarily 207 | /// 208 | /// 209 | private static WindowControl CreateTempWindowControl() 210 | { 211 | var process = FindRemotePlayProcess(); 212 | var panel = FindStreamingPanel(process); 213 | return new WindowControl(process.MainWindowHandle, panel); 214 | } 215 | 216 | /// 217 | /// One shot method for CaptureFrame 218 | /// 219 | /// 220 | /// 221 | public static Bitmap CaptureFrame(bool backgroundMode = true) 222 | { 223 | var windowControl = CreateTempWindowControl(); 224 | return windowControl.CaptureFrame(backgroundMode); 225 | } 226 | 227 | /// 228 | /// One shot method for GetWindowSize 229 | /// 230 | /// 231 | public static Size GetWindowSize() 232 | { 233 | var windowControl = CreateTempWindowControl(); 234 | return windowControl.GetWindowSize(); 235 | } 236 | 237 | /// 238 | /// One shot method for ResizeWindow 239 | /// 240 | /// 241 | /// 242 | public static void ResizeWindow(Size size, bool fixedSize = false) 243 | { 244 | var windowControl = CreateTempWindowControl(); 245 | windowControl.ResizeWindow(size, fixedSize); 246 | } 247 | } 248 | } 249 | --------------------------------------------------------------------------------