├── .gitattributes ├── .gitignore ├── LDPlayerNTC ├── ADBKeyEvent.cs ├── ImageScanOpenCV.cs ├── Info_Devices.cs ├── LDController.cs ├── LDPlayerNTC.csproj └── Properties │ └── AssemblyInfo.cs └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /LDPlayerNTC/ADBKeyEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LDPlayerNTC 8 | { 9 | public enum ADBKeyEvent 10 | { 11 | KEYCODE_0, 12 | KEYCODE_SOFT_LEFT, 13 | KEYCODE_SOFT_RIGHT, 14 | KEYCODE_HOME, 15 | KEYCODE_BACK, 16 | KEYCODE_CALL, 17 | KEYCODE_ENDCALL, 18 | KEYCODE_0_, 19 | KEYCODE_1, 20 | KEYCODE_2, 21 | KEYCODE_3, 22 | KEYCODE_4, 23 | KEYCODE_5, 24 | KEYCODE_6, 25 | KEYCODE_7, 26 | KEYCODE_8, 27 | KEYCODE_9, 28 | KEYCODE_STAR, 29 | KEYCODE_POUND, 30 | KEYCODE_DPAD_UP, 31 | KEYCODE_DPAD_DOWN, 32 | KEYCODE_DPAD_LEFT, 33 | KEYCODE_DPAD_RIGHT, 34 | KEYCODE_DPAD_CENTER, 35 | KEYCODE_VOLUME_UP, 36 | KEYCODE_VOLUME_DOWN, 37 | KEYCODE_POWER, 38 | KEYCODE_CAMERA, 39 | KEYCODE_CLEAR, 40 | KEYCODE_A, 41 | KEYCODE_B, 42 | KEYCODE_C, 43 | KEYCODE_D, 44 | KEYCODE_E, 45 | KEYCODE_F, 46 | KEYCODE_G, 47 | KEYCODE_H, 48 | KEYCODE_I, 49 | KEYCODE_J, 50 | KEYCODE_K, 51 | KEYCODE_L, 52 | KEYCODE_M, 53 | KEYCODE_N, 54 | KEYCODE_O, 55 | KEYCODE_P, 56 | KEYCODE_Q, 57 | KEYCODE_R, 58 | KEYCODE_S, 59 | KEYCODE_T, 60 | KEYCODE_U, 61 | KEYCODE_V, 62 | KEYCODE_W, 63 | KEYCODE_X, 64 | KEYCODE_Y, 65 | KEYCODE_Z, 66 | KEYCODE_COMMA, 67 | KEYCODE_PERIOD, 68 | KEYCODE_ALT_LEFT, 69 | KEYCODE_ALT_RIGHT, 70 | KEYCODE_SHIFT_LEFT, 71 | KEYCODE_SHIFT_RIGHT, 72 | KEYCODE_TAB, 73 | KEYCODE_SPACE, 74 | KEYCODE_SYM, 75 | KEYCODE_EXPLORER, 76 | KEYCODE_ENVELOPE, 77 | KEYCODE_ENTER, 78 | KEYCODE_DEL, 79 | KEYCODE_GRAVE, 80 | KEYCODE_MINUS, 81 | KEYCODE_EQUALS, 82 | KEYCODE_LEFT_BRACKET, 83 | KEYCODE_RIGHT_BRACKET, 84 | KEYCODE_BACKSLASH, 85 | KEYCODE_SEMICOLON, 86 | KEYCODE_APOSTROPHE, 87 | KEYCODE_SLASH, 88 | KEYCODE_AT, 89 | KEYCODE_NUM, 90 | KEYCODE_HEADSETHOOK, 91 | KEYCODE_FOCUS, 92 | KEYCODE_PLUS, 93 | KEYCODE_MENU, 94 | KEYCODE_NOTIFICATION, 95 | KEYCODE_APP_SWITCH = 187 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /LDPlayerNTC/ImageScanOpenCV.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Drawing.Imaging; 5 | using System.IO; 6 | using System.Runtime.InteropServices; 7 | using Emgu.CV; 8 | using Emgu.CV.CvEnum; 9 | using Emgu.CV.Structure; 10 | 11 | namespace LDPlayerNTC 12 | { 13 | public static class ImageScanOpenCV 14 | { 15 | public static Bitmap GetImage(string path) 16 | { 17 | return new Bitmap(path); 18 | } 19 | 20 | public static Bitmap Find(string main, string sub, double percent = 0.9) 21 | { 22 | Bitmap mainImg = ImageScanOpenCV.GetImage(main); 23 | Bitmap subImg = ImageScanOpenCV.GetImage(sub); 24 | return ImageScanOpenCV.Find(main, sub, percent); 25 | } 26 | 27 | public static Bitmap Find(Bitmap mainBitmap, Bitmap subBitmap, double percent = 0.9) 28 | { 29 | Image source = new Image(mainBitmap); 30 | Image template = new Image(subBitmap); 31 | Image imageToShow = source.Copy(); 32 | using (Image result = source.MatchTemplate(template, TemplateMatchingType.CcoeffNormed)) 33 | { 34 | double[] minValues; 35 | double[] maxValues; 36 | Point[] minLocations; 37 | Point[] maxLocations; 38 | result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations); 39 | bool flag = maxValues[0] > percent; 40 | if (flag) 41 | { 42 | Rectangle match = new Rectangle(maxLocations[0], template.Size); 43 | imageToShow.Draw(match, new Bgr(System.Drawing.Color.Red), 2, LineType.EightConnected, 0); 44 | } 45 | else 46 | { 47 | imageToShow = null; 48 | } 49 | } 50 | return (imageToShow == null) ? null : imageToShow.ToBitmap(); 51 | } 52 | 53 | [DllImport("gdi32.dll")] 54 | public static extern bool DeleteObject(IntPtr hObject); 55 | 56 | public static Point? FindOutPoint(Bitmap mainBitmap, Bitmap subBitmap, double percent = 0.9) 57 | { 58 | bool flag = subBitmap == null || mainBitmap == null; 59 | Point? result2; 60 | if (flag) 61 | { 62 | result2 = null; 63 | } 64 | else 65 | { 66 | bool flag2 = subBitmap.Width > mainBitmap.Width || subBitmap.Height > mainBitmap.Height; 67 | if (flag2) 68 | { 69 | result2 = null; 70 | } 71 | else 72 | { 73 | Image source = new Image(mainBitmap); 74 | Image template = new Image(subBitmap); 75 | Point? resPoint = null; 76 | using (Image result = source.MatchTemplate(template, TemplateMatchingType.CcoeffNormed)) 77 | { 78 | double[] minValues; 79 | double[] maxValues; 80 | Point[] minLocations; 81 | Point[] maxLocations; 82 | result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations); 83 | bool flag3 = maxValues[0] > percent; 84 | if (flag3) 85 | { 86 | resPoint = new Point?(maxLocations[0]); 87 | } 88 | } 89 | GC.Collect(); 90 | GC.WaitForPendingFinalizers(); 91 | result2 = resPoint; 92 | } 93 | } 94 | return result2; 95 | } 96 | 97 | public static List FindOutPoints(Bitmap mainBitmap, Bitmap subBitmap, double percent = 0.9) 98 | { 99 | Image source = new Image(mainBitmap); 100 | Image template = new Image(subBitmap); 101 | List resPoint = new List(); 102 | for (; ; ) 103 | { 104 | using (Image result = source.MatchTemplate(template, TemplateMatchingType.CcoeffNormed)) 105 | { 106 | double[] minValues; 107 | double[] maxValues; 108 | Point[] minLocations; 109 | Point[] maxLocations; 110 | result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations); 111 | bool flag = maxValues[0] > percent; 112 | if (!flag) 113 | { 114 | break; 115 | } 116 | Rectangle match = new Rectangle(maxLocations[0], template.Size); 117 | source.Draw(match, new Bgr(System.Drawing.Color.Blue), -1, LineType.EightConnected, 0); 118 | resPoint.Add(maxLocations[0]); 119 | } 120 | } 121 | return resPoint; 122 | } 123 | 124 | public static List FindColor(Bitmap mainBitmap, System.Drawing.Color color) 125 | { 126 | int searchValue = color.ToArgb(); 127 | List result = new List(); 128 | try 129 | { 130 | for (int x = 0; x < mainBitmap.Width; x++) 131 | { 132 | for (int y = 0; y < mainBitmap.Height; y++) 133 | { 134 | bool flag = searchValue.Equals(mainBitmap.GetPixel(x, y).ToArgb()); 135 | if (flag) 136 | { 137 | result.Add(new Point(x, y)); 138 | } 139 | } 140 | } 141 | } 142 | finally 143 | { 144 | if (mainBitmap != null) 145 | { 146 | ((IDisposable)mainBitmap).Dispose(); 147 | } 148 | } 149 | return result; 150 | } 151 | 152 | public static void TestDilate(Bitmap bmp) 153 | { 154 | for (; ; ) 155 | { 156 | Image imgOld = new Image(bmp); 157 | imgOld.Save("old.png"); 158 | Image img2 = new Image(imgOld.Width, imgOld.Height, new Gray(255.0)).Sub(imgOld); 159 | img2.Save("img23.png"); 160 | Image eroded = new Image(img2.Size); 161 | Image temp = new Image(img2.Size); 162 | Image skel = new Image(img2.Size); 163 | skel.SetValue(0.0, null); 164 | CvInvoke.Threshold(img2, img2, 127.0, 255.0, ThresholdType.Binary); 165 | Mat element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(2, 2), new Point(-1, -1)); 166 | CvInvoke.Dilate(imgOld, eroded, element, new Point(-1, -1), 1, BorderType.Reflect, default(MCvScalar)); 167 | eroded.CopyTo(img2); 168 | skel.Bitmap.Save("ele.png"); 169 | img2.Save("img2.png"); 170 | eroded.Save("eroded.png"); 171 | temp.Save("temp.png"); 172 | } 173 | } 174 | 175 | public static Bitmap ThreshHoldBinary(Bitmap bmp, byte threshold = 190) 176 | { 177 | Image img = new Image(bmp); 178 | Image bmp2 = img.ThresholdBinary(new Gray((double)threshold), new Gray(255.0)); 179 | return bmp2.ToBitmap(); 180 | } 181 | 182 | public static Bitmap NotWhiteToTransparentPixelReplacement(Bitmap bmp) 183 | { 184 | bmp = ImageScanOpenCV.CreateNonIndexedImage(bmp); 185 | for (int x = 0; x < bmp.Width; x++) 186 | { 187 | for (int y = 0; y < bmp.Height; y++) 188 | { 189 | System.Drawing.Color pixel = bmp.GetPixel(x, y); 190 | bool flag = pixel.R > 200 && pixel.G > 200 && pixel.B > 200; 191 | if (flag) 192 | { 193 | bmp.SetPixel(x, y, System.Drawing.Color.Transparent); 194 | } 195 | } 196 | } 197 | return bmp; 198 | } 199 | 200 | public static Bitmap WhiteToBlackPixelReplacement(Bitmap bmp) 201 | { 202 | bmp = ImageScanOpenCV.CreateNonIndexedImage(bmp); 203 | for (int x = 0; x < bmp.Width; x++) 204 | { 205 | for (int y = 0; y < bmp.Height; y++) 206 | { 207 | System.Drawing.Color pixel = bmp.GetPixel(x, y); 208 | bool flag = pixel.R > 20 && pixel.G > 230 && pixel.B > 230; 209 | if (flag) 210 | { 211 | bmp.SetPixel(x, y, System.Drawing.Color.Black); 212 | } 213 | } 214 | } 215 | return bmp; 216 | } 217 | 218 | public static Bitmap TransparentToWhitePixelReplacement(Bitmap bmp) 219 | { 220 | bmp = ImageScanOpenCV.CreateNonIndexedImage(bmp); 221 | for (int x = 0; x < bmp.Width; x++) 222 | { 223 | for (int y = 0; y < bmp.Height; y++) 224 | { 225 | bool flag = bmp.GetPixel(x, y).A >= 1; 226 | if (flag) 227 | { 228 | bmp.SetPixel(x, y, System.Drawing.Color.White); 229 | } 230 | } 231 | } 232 | return bmp; 233 | } 234 | 235 | public static Bitmap CreateNonIndexedImage(Image src) 236 | { 237 | Bitmap newBmp = new Bitmap(src.Width, src.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); 238 | using (Graphics gfx = Graphics.FromImage(newBmp)) 239 | { 240 | gfx.DrawImage(src, 0, 0); 241 | } 242 | return newBmp; 243 | } 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /LDPlayerNTC/Info_Devices.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LDPlayerNTC 8 | { 9 | public struct Info_Devices 10 | { 11 | public int index; 12 | public string name; 13 | public string adb_id; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LDPlayerNTC/LDController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Drawing; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | 11 | namespace LDPlayerNTC 12 | { 13 | public static class LDController 14 | { 15 | //-----------Path của ldconsole----------// 16 | public static string pathLD = @"D:\LDPlayer\LDPlayer3.0\ldconsole.exe"; 17 | 18 | //----------CMD-------------------// 19 | public static void ExecuteLD(string cmd) 20 | { 21 | Process p = new Process(); 22 | p.StartInfo.FileName = pathLD; 23 | p.StartInfo.Arguments = cmd; 24 | p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 25 | p.StartInfo.UseShellExecute = false; 26 | p.StartInfo.CreateNoWindow = true; 27 | p.EnableRaisingEvents = true; 28 | p.Start(); 29 | p.WaitForExit(); 30 | p.Close(); 31 | } 32 | 33 | public static string ExecuteLD_Result(string cmdCommand) 34 | { 35 | string result; 36 | try 37 | { 38 | Process process = new Process(); 39 | process.StartInfo = new ProcessStartInfo 40 | { 41 | FileName = pathLD, 42 | Arguments = cmdCommand, 43 | CreateNoWindow = true, 44 | UseShellExecute = false, 45 | WindowStyle = ProcessWindowStyle.Hidden, 46 | RedirectStandardInput = true, 47 | RedirectStandardOutput = true 48 | }; 49 | process.Start(); 50 | process.WaitForExit(); 51 | string text = process.StandardOutput.ReadToEnd(); 52 | result = text; 53 | } 54 | catch 55 | { 56 | result = null; 57 | } 58 | return result; 59 | } 60 | //----------Tương tác với các tab giả lập ---------// 61 | 62 | /// 63 | /// Mở giả lập 64 | /// 65 | /// 66 | /// name : Nếu điều khiển theo tên giả lập 67 | /// index : Nếu điều khiển theo index giả lập 68 | /// Giá trị tên hoặc index giả lập 69 | public static void Open(string param, string NameOrIndex) 70 | { 71 | ExecuteLD(string.Format("launch --{0} {1}", param, NameOrIndex)); 72 | } 73 | 74 | /// 75 | /// Kiểm tra LD đã khởi động xong chưa 76 | /// 77 | /// 78 | /// 79 | /// 80 | public static bool CheckLDStartDone(string param, string NameOrIndex) 81 | { 82 | string str = string.Format("adb --{0} {1} --command \"{2}\"", param, NameOrIndex, "shell input tap 0 0"); 83 | int num = 0; 84 | Process process = new Process(); 85 | process.StartInfo = new ProcessStartInfo() 86 | { 87 | FileName = pathLD, 88 | Arguments = str, 89 | CreateNoWindow = true, 90 | UseShellExecute = false, 91 | //WindowStyle = ProcessWindowStyle.Hidden, 92 | RedirectStandardInput = true, 93 | RedirectStandardOutput = true 94 | }; 95 | do 96 | { 97 | process.Start(); 98 | process.WaitForExit(3000); 99 | if (!(process.StandardOutput.ReadToEnd() == "")) 100 | { 101 | Thread.Sleep(2000); 102 | ++num; 103 | } 104 | else 105 | goto label_1; 106 | } 107 | while (num != 30); 108 | goto label_3; 109 | label_1: 110 | return true; 111 | label_3: 112 | return false; 113 | } 114 | /// 115 | /// Khởi động ứng dụng 116 | /// 117 | /// 118 | /// 119 | /// Tên package ứng dụng 120 | public static void Open_App(string param, string NameOrIndex, string Package_Name) 121 | { 122 | ExecuteLD(string.Format("launchex --{0} {1} --packagename {2}", param, NameOrIndex, Package_Name)); 123 | } 124 | 125 | /// 126 | /// Đóng giả lập 127 | /// 128 | /// 129 | /// 130 | public static void Close(string param, string NameOrIndex) 131 | { 132 | ExecuteLD(string.Format("quit --{0} {1}", param, NameOrIndex)); 133 | } 134 | 135 | /// 136 | /// Đóng tất cả giả lập 137 | /// 138 | public static void CloseAll() 139 | { 140 | ExecuteLD("quitall"); 141 | } 142 | 143 | /// 144 | /// Khởi động lại giả lập 145 | /// 146 | /// 147 | /// 148 | public static void ReBoot(string param, string NameOrIndex) 149 | { 150 | ExecuteLD(string.Format("reboot --{0} {1}", param, NameOrIndex)); 151 | } 152 | 153 | //------------Tùy chỉnh thông tin giả lập--------------// 154 | 155 | /// 156 | /// Tạo giả lập 157 | /// 158 | /// 159 | public static void Create(string Name) 160 | { 161 | ExecuteLD("add --name " + Name); 162 | } 163 | 164 | /// 165 | /// Copy giả lập 166 | /// 167 | /// 168 | /// 169 | public static void Copy(string Name, string From_NameOrIndex) 170 | { 171 | ExecuteLD(string.Format("copy --name \"{0}\" --from {1}", Name, From_NameOrIndex)); 172 | } 173 | 174 | /// 175 | /// Xóa giả lập 176 | /// 177 | /// 178 | /// 179 | public static void Delete(string param, string NameOrIndex) 180 | { 181 | ExecuteLD(string.Format("remove --{0} {1}", param, NameOrIndex)); 182 | } 183 | 184 | /// 185 | /// Thay đổi tên giả lập 186 | /// 187 | /// 188 | /// 189 | /// 190 | public static void ReName(string param, string NameOrIndex, string title_new) 191 | { 192 | ExecuteLD(string.Format("rename --{0} {1} --title {2}", param, NameOrIndex, title_new)); 193 | } 194 | 195 | //-----------Tùy chỉnh sâu giả lập--------------// 196 | 197 | /// 198 | /// Install app từ File trên PC 199 | /// 200 | /// 201 | /// 202 | /// 203 | public static void InstallApp_File(string param, string NameOrIndex, string File_Name) 204 | { 205 | ExecuteLD(string.Format(@"installapp --{0} {1} --filename ""{2}""", param, NameOrIndex, File_Name)); 206 | } 207 | 208 | /// 209 | /// Install App từ Package 210 | /// 211 | /// 212 | /// 213 | /// 214 | public static void InstallApp_Package(string param, string NameOrIndex, string Package_Name) 215 | { 216 | ExecuteLD(string.Format("installapp --{0} {1} --packagename {2}", param, NameOrIndex, Package_Name)); 217 | } 218 | 219 | /// 220 | /// UnInstall App 221 | /// 222 | /// 223 | /// 224 | /// 225 | public static void UnInstallApp(string param, string NameOrIndex, string Package_Name) 226 | { 227 | ExecuteLD(string.Format("uninstallapp --{0} {1} --packagename {2}", param, NameOrIndex, Package_Name)); 228 | } 229 | 230 | /// 231 | /// Run App 232 | /// 233 | /// 234 | /// 235 | /// 236 | public static void RunApp(string param, string NameOrIndex, string Package_Name) 237 | { 238 | ExecuteLD(string.Format("runapp --{0} {1} --packagename {2}", param, NameOrIndex, Package_Name)); 239 | } 240 | 241 | /// 242 | /// Kill App 243 | /// 244 | /// 245 | /// 246 | /// 247 | public static void KillApp(string param, string NameOrIndex, string Package_Name) 248 | { 249 | ExecuteLD(string.Format("killapp --{0} {1} --packagename {2}", param, NameOrIndex, Package_Name)); 250 | } 251 | 252 | /// 253 | /// Thay đổi Property giả lập 254 | /// 255 | /// 256 | /// 257 | /// thông số của giả lập 258 | ///[--resolution ] 259 | ///[--cpu < 1 | 2 | 3 | 4 >] 260 | ///[--memory < 512 | 1024 | 2048 | 4096 | 8192 >] 261 | ///[--manufacturer asus] 262 | ///[--model ASUS_Z00DUO] 263 | ///[--pnumber 13812345678] 264 | ///[--imei ] 265 | ///[--imsi ] 266 | ///[--simserial ] 267 | ///[--androidid ] 268 | ///[--mac ] 269 | ///[--autorotate < 1 | 0 >] 270 | ///[--lockwindow < 1 | 0 >] 271 | /// 272 | public static void Change_Property(string param, string NameOrIndex, string cmd) 273 | { 274 | ExecuteLD(string.Format("modify --{0} {1} {2}", param, NameOrIndex, cmd)); 275 | } 276 | 277 | /// 278 | /// ADB 279 | /// 280 | /// 281 | /// 282 | /// cmd adb 283 | /// Result cmd 284 | public static string ADB(string param, string NameOrIndex, string cmd) 285 | { 286 | return ExecuteLD_Result(string.Format("adb --{0} {1} --command \"{2}\"", param, NameOrIndex, cmd)); 287 | } 288 | /// 289 | /// Pull file 290 | /// 291 | /// 292 | /// 293 | /// 294 | /// 295 | public static void Pull(string param, string NameOrIndex, string remote_file_path, string local_file_path) 296 | { 297 | ExecuteLD(string.Format(@"pull --{0} {1} --remote ""{2}"" --local ""{3}""", param, NameOrIndex, remote_file_path, local_file_path)); 298 | } 299 | 300 | /// 301 | /// Push file 302 | /// 303 | /// 304 | /// 305 | /// 306 | /// 307 | public static void Push(string param, string NameOrIndex, string remote_file_path, string local_file_path) 308 | { 309 | ExecuteLD(string.Format(@"push --{0} {1} --remote ""{2}"" --local ""{3}""", param, NameOrIndex, remote_file_path, local_file_path)); 310 | } 311 | 312 | /// 313 | /// Backup File 314 | /// 315 | /// 316 | /// 317 | /// 318 | /// 319 | public static void BackupApp(string param, string NameOrIndex, string Package_Name, string file_path) 320 | { 321 | ExecuteLD(string.Format(@"backupapp --{0} {1} --packagename {2} --file ""{3}""", param, NameOrIndex, Package_Name, file_path)); 322 | } 323 | 324 | /// 325 | /// Restore App 326 | /// 327 | /// 328 | /// 329 | /// 330 | /// 331 | public static void RestoreApp(string param, string NameOrIndex, string Package_Name, string file_path) 332 | { 333 | ExecuteLD(string.Format(@"restoreapp --{0} {1} --packagename {2} --file ""{3}""", param, NameOrIndex, Package_Name, file_path)); 334 | } 335 | 336 | /// 337 | /// Global config 338 | /// 339 | /// 340 | /// 341 | /// 342 | /// 343 | /// 344 | /// 345 | public static void Global_Config(string param, string NameOrIndex, string fps, string audio, string fast_play, string clean_mode) 346 | { 347 | // [--fps <0~60>] [--audio <1 | 0>] [--fastplay <1 | 0>] [--cleanmode <1 | 0>] 348 | ExecuteLD(string.Format("globalsetting --{0} {1} --audio {2} --fastplay {3} --cleanmode {4}", param, NameOrIndex, audio, fast_play, clean_mode)); 349 | } 350 | 351 | //---------Lấy thông tin multi giả lập-------------// 352 | 353 | /// 354 | /// Lấy danh sách giả lập 355 | /// 356 | /// List tên các giả lập 357 | public static List GetDevices() 358 | { 359 | string[] arr = ExecuteLD_Result("list").Trim().Split('\n'); 360 | for (int i = 0; i < arr.Length; i++) 361 | { 362 | if (arr[i] == "") 363 | return new List(); 364 | arr[i] = arr[i].Trim(); 365 | } 366 | //System.Windows.Forms.MessageBox.Show(string.Join("|", arr)); 367 | return arr.ToList(); 368 | } 369 | 370 | /// 371 | /// List tên giả lập đang chạy 372 | /// 373 | /// List tên các giả lập đang chạy 374 | public static List GetDevices_Running() 375 | { 376 | string[] arr = ExecuteLD_Result("runninglist").Trim().Split('\n'); 377 | for (int i = 0; i < arr.Length; i++) 378 | { 379 | if (arr[i] == "") 380 | return new List(); 381 | arr[i] = arr[i].Trim(); 382 | } 383 | return arr.ToList(); 384 | } 385 | 386 | /// 387 | /// List chi tiết giả lập đang chạy 388 | /// 389 | /// 390 | public static List GetDevices2_Running() 391 | { 392 | List list_running = new List(); 393 | string[] arr = ExecuteLD_Result("runninglist").Trim().Split('\n'); 394 | for (int i = 0; i < arr.Length; i++) 395 | { 396 | if (arr[i] != "") 397 | { 398 | Info_Devices item = new Info_Devices(); 399 | item.name = arr[i].Trim(); 400 | item.index = Int32.Parse(GetNameOrIndex("name", item.name)); 401 | list_running.Add(item); 402 | } 403 | } 404 | return list_running; 405 | } 406 | 407 | /// 408 | /// Từ Index hoặc Tên của giả lập đưa ra gia trị còn lại 409 | /// 410 | /// 411 | /// 412 | /// String index hoặc tên 413 | public static string GetNameOrIndex(string param, string NameOrIndex) 414 | { 415 | List listDevices = GetDevices2(); 416 | if (param == "index") 417 | { 418 | foreach (Info_Devices item in listDevices) 419 | { 420 | if (item.index.ToString() == NameOrIndex) 421 | { 422 | return item.name; 423 | } 424 | } 425 | } 426 | if (param == "name") 427 | { 428 | foreach (Info_Devices item in listDevices) 429 | { 430 | if (item.name == NameOrIndex) 431 | { 432 | return item.index.ToString(); 433 | } 434 | } 435 | } 436 | 437 | return null; 438 | } 439 | /// 440 | /// Kiểm tra xem giả lập có đang chạy không 441 | /// 442 | /// 443 | /// 444 | /// 445 | public static bool IsDevice_Running(string param, string NameOrIndex) 446 | { 447 | string result = ExecuteLD_Result(string.Format("isrunning --{0} {1}", param, NameOrIndex)).Trim(); 448 | if (result == "running") 449 | return true; 450 | return false; 451 | } 452 | 453 | /// 454 | /// List2 chi tiết các giả lập 455 | /// 456 | /// 457 | public static List GetDevices2() 458 | { 459 | try 460 | { 461 | List listLDPlayer = new List(); 462 | string[] arr = ExecuteLD_Result("list2").Trim().Split('\n'); 463 | for (int i = 0; i < arr.Length; i++) 464 | { 465 | Info_Devices devices = new Info_Devices(); 466 | string[] aDetail = arr[i].Trim().Split(','); 467 | devices.index = int.Parse(aDetail[0]); 468 | devices.name = aDetail[1]; 469 | devices.adb_id = "-1"; 470 | listLDPlayer.Add(devices); 471 | } 472 | //System.Windows.Forms.MessageBox.Show(string.Join("\n", arr)); 473 | return listLDPlayer; 474 | } 475 | catch 476 | { 477 | return new List(); 478 | } 479 | } 480 | 481 | 482 | //--------------------Viết lại KautoHelper------------------// 483 | 484 | 485 | private static string TAP_DEVICES = "shell input tap {0} {1}"; 486 | private static string SWIPE_DEVICES = "shell input swipe {0} {1} {2} {3} {4}"; 487 | private static string KEY_DEVICES = "shell input keyevent {0}"; 488 | private static string INPUT_TEXT_DEVICES = "shell input text \"{0}\""; 489 | private static string CAPTURE_SCREEN_TO_DEVICES = "shell screencap -p \"{0}\""; 490 | private static string PULL_SCREEN_FROM_DEVICES = "pull \"{0}\""; 491 | private static string REMOVE_SCREEN_FROM_DEVICES = "shell rm -f \"{0}\""; 492 | private static string GET_SCREEN_RESOLUTION = "shell dumpsys display | grep mCurrentDisplayRect"; 493 | 494 | /// 495 | /// Delay 496 | /// 497 | /// 498 | public static void Delay(double delayTime) 499 | { 500 | for (double count = 0.0; count < delayTime; count += 100.0) 501 | { 502 | Thread.Sleep(TimeSpan.FromMilliseconds(100.0)); 503 | } 504 | } 505 | 506 | /// 507 | /// Lấy kích thước màn hình 508 | /// 509 | /// 510 | /// 511 | /// 512 | public static Point GetScreenResolution(string param, string NameOrIndex) 513 | { 514 | string cmdCommand = string.Format(GET_SCREEN_RESOLUTION); 515 | string result = LDController.ADB(param, NameOrIndex, cmdCommand); 516 | result = result.Substring(result.IndexOf("- ")); 517 | result = result.Substring(result.IndexOf(' '), result.IndexOf(')') - result.IndexOf(' ')); 518 | string[] temp = result.Split(new char[] 519 | { 520 | ',' 521 | }); 522 | int x = Convert.ToInt32(temp[0].Trim()); 523 | int y = Convert.ToInt32(temp[1].Trim()); 524 | return new Point(x, y); 525 | } 526 | 527 | /// 528 | /// Click tọa độ phần trăm 529 | /// 530 | /// 531 | /// 532 | /// 533 | /// 534 | /// 535 | public static void TapByPercent(string param, string NameOrIndex, double x, double y, int count = 1) 536 | { 537 | Start: 538 | try 539 | { 540 | Point resolution = LDController.GetScreenResolution(param, NameOrIndex); 541 | int X = (int)(x * ((double)resolution.X * 1.0 / 100.0)); 542 | int Y = (int)(y * ((double)resolution.Y * 1.0 / 100.0)); 543 | string cmdCommand = string.Format(LDController.TAP_DEVICES, X, Y); 544 | for (int i = 1; i < count; i++) 545 | { 546 | cmdCommand = cmdCommand + " && " + string.Format(LDController.TAP_DEVICES, X, Y); 547 | } 548 | string result = LDController.ADB(param, NameOrIndex, cmdCommand); 549 | } 550 | catch (Exception) 551 | { 552 | goto Start; 553 | } 554 | 555 | } 556 | 557 | /// 558 | /// Click theo tọa độ 559 | /// 560 | /// 561 | /// 562 | /// 563 | /// 564 | /// 565 | public static void Tap(string param, string NameOrIndex, int x, int y, int count = 1) 566 | { 567 | string cmdCommand = string.Format(LDController.TAP_DEVICES, x, y); 568 | for (int i = 1; i < count; i++) 569 | { 570 | cmdCommand = cmdCommand + " && " + string.Format(LDController.TAP_DEVICES, x, y); 571 | } 572 | string result = LDController.ADB(param, NameOrIndex, cmdCommand); 573 | } 574 | 575 | /// 576 | /// Send Key 577 | /// 578 | /// 579 | /// 580 | /// 581 | public static void Key(string param, string NameOrIndex, ADBKeyEvent key) 582 | { 583 | string cmdCommand = string.Format(LDController.KEY_DEVICES, key); 584 | string result = LDController.ADB(param, NameOrIndex, cmdCommand); 585 | } 586 | 587 | /// 588 | /// Input Text 589 | /// 590 | /// 591 | /// 592 | /// 593 | public static void InputText(string param, string NameOrIndex, string text) 594 | { 595 | string cmdCommand = string.Format(LDController.INPUT_TEXT_DEVICES, text.Replace(" ", "%s").Replace("&", "\\&").Replace("<", "\\<").Replace(">", "\\>").Replace("?", "\\?").Replace(":", "\\:").Replace("{", "\\{").Replace("}", "\\}").Replace("[", "\\[").Replace("]", "\\]").Replace("|", "\\|")); 596 | string result = LDController.ADB(param, NameOrIndex, cmdCommand); 597 | } 598 | /// 599 | /// Kéo theo phần trăm 600 | /// 601 | /// 602 | /// 603 | /// 604 | /// 605 | /// 606 | /// 607 | /// 608 | public static void SwipeByPercent(string param, string NameOrIndex, double x1, double y1, double x2, double y2, int duration = 100) 609 | { 610 | Start: 611 | try 612 | { 613 | Point resolution = LDController.GetScreenResolution(param, NameOrIndex); 614 | int X = (int)(x1 * ((double)resolution.X * 1.0 / 100.0)); 615 | int Y = (int)(y1 * ((double)resolution.Y * 1.0 / 100.0)); 616 | int X2 = (int)(x2 * ((double)resolution.X * 1.0 / 100.0)); 617 | int Y2 = (int)(y2 * ((double)resolution.Y * 1.0 / 100.0)); 618 | string cmdCommand = string.Format(LDController.SWIPE_DEVICES, new object[] 619 | { 620 | X, 621 | Y, 622 | X2, 623 | Y2, 624 | duration 625 | }); 626 | string result = LDController.ADB(param, NameOrIndex, cmdCommand); 627 | } 628 | catch (Exception) 629 | { 630 | goto Start; 631 | } 632 | 633 | } 634 | /// 635 | /// Kéo 636 | /// 637 | /// 638 | /// 639 | /// 640 | /// 641 | /// 642 | /// 643 | /// 644 | public static void Swipe(string param, string NameOrIndex, int x1, int y1, int x2, int y2, int duration = 100) 645 | { 646 | string cmdCommand = string.Format(LDController.SWIPE_DEVICES, new object[] 647 | { 648 | x1, 649 | y1, 650 | x2, 651 | y2, 652 | duration 653 | }); 654 | string result = LDController.ADB(param, NameOrIndex, cmdCommand); 655 | } 656 | 657 | /// 658 | /// Bật chế độ trên máy bay 659 | /// 660 | /// 661 | /// 662 | /// 663 | public static void PlanModeON(string param, string NameOrIndex, CancellationToken cancellationToken) 664 | { 665 | bool isCancellationRequested = cancellationToken.IsCancellationRequested; 666 | if (!isCancellationRequested) 667 | { 668 | string cmdClearShoppe = "settings put global airplane_mode_on 1"; 669 | cmdClearShoppe = string.Concat(new string[] 670 | { 671 | cmdClearShoppe, 672 | Environment.NewLine, 673 | " am broadcast -a android.intent.action.AIRPLANE_MODE" 674 | }); 675 | LDController.ADB(param, NameOrIndex, cmdClearShoppe); 676 | } 677 | } 678 | /// 679 | /// Tắt chế độ trên máy bay 680 | /// 681 | /// 682 | /// 683 | /// 684 | public static void PlanModeOFF(string param, string NameOrIndex, CancellationToken cancellationToken) 685 | { 686 | bool isCancellationRequested = cancellationToken.IsCancellationRequested; 687 | if (!isCancellationRequested) 688 | { 689 | string cmdClearShoppe = "settings put global airplane_mode_on 0"; 690 | cmdClearShoppe = string.Concat(new string[] 691 | { 692 | cmdClearShoppe, 693 | Environment.NewLine, 694 | " am broadcast -a android.intent.action.AIRPLANE_MODE" 695 | }); 696 | LDController.ADB(param, NameOrIndex, cmdClearShoppe); 697 | } 698 | } 699 | /// 700 | /// LongPress 701 | /// 702 | /// 703 | /// 704 | /// 705 | /// 706 | /// Thời gian dí 707 | public static void LongPress(string param, string NameOrIndex, int x, int y, int duration = 100) 708 | { 709 | string cmdCommand = string.Format(LDController.SWIPE_DEVICES, new object[] 710 | { 711 | x, 712 | y, 713 | x, 714 | y, 715 | duration 716 | }); 717 | string result = LDController.ADB(param, NameOrIndex, cmdCommand); 718 | } 719 | /// 720 | /// Chụp ảnh màn hình 721 | /// 722 | /// 723 | /// 724 | /// 725 | /// 726 | /// 727 | public static Bitmap ScreenShoot(string param, string NameOrIndex, bool isDeleteImageAfterCapture = true, string fileName = "screenShoot.png") 728 | { 729 | string nameToSave = Path.GetFileNameWithoutExtension(fileName) + NameOrIndex + Path.GetExtension(fileName); 730 | for (; ; ) 731 | { 732 | bool flag3 = File.Exists(nameToSave); 733 | bool flag6 = !flag3; 734 | if (flag6) 735 | { 736 | break; 737 | } 738 | try 739 | { 740 | File.Delete(nameToSave); 741 | break; 742 | } 743 | catch (Exception ex) 744 | { 745 | break; 746 | } 747 | } 748 | string Current = Directory.GetCurrentDirectory() + "\\" + nameToSave; 749 | string CurrentPath = Directory.GetCurrentDirectory().Replace("\\\\", "\\"); 750 | CurrentPath = "\"" + CurrentPath + "\""; 751 | string cmdCommand = string.Format("shell screencap -p \"{0}\"", "/sdcard/" + nameToSave); 752 | string cmdCommand2 = string.Format(string.Concat(new string[] 753 | { 754 | " pull /sdcard/", 755 | nameToSave, 756 | " ", 757 | CurrentPath 758 | }), new object[0]); 759 | string result = ADB(param, NameOrIndex, cmdCommand); 760 | string result2 = ADB(param, NameOrIndex, cmdCommand2); 761 | Bitmap result3 = null; 762 | try 763 | { 764 | using (Bitmap bitmap = new Bitmap(Current)) 765 | { 766 | result3 = new Bitmap(bitmap); 767 | } 768 | } 769 | catch 770 | { 771 | } 772 | if (isDeleteImageAfterCapture) 773 | { 774 | try 775 | { 776 | File.Delete(nameToSave); 777 | } 778 | catch 779 | { 780 | } 781 | } 782 | return result3; 783 | } 784 | 785 | // ----------------------- Xử lý Ảnh -----------------------// 786 | 787 | /// 788 | /// Kiểm tra xem ảnh có tồn tại 789 | /// 790 | /// 791 | /// 792 | /// Đường dẫn ảnh ảnh 793 | /// 794 | public static bool FindImage(string param, string NameOrIndex, string pathPNG) 795 | { 796 | Bitmap subBitmap = ImageScanOpenCV.GetImage(pathPNG); 797 | Bitmap screen = LDController.ScreenShoot(param, NameOrIndex); 798 | Point? poinImage = ImageScanOpenCV.FindOutPoint(screen, subBitmap); 799 | if (poinImage != null) 800 | { 801 | return true; 802 | } 803 | else 804 | { 805 | return false; 806 | } 807 | } 808 | 809 | /// 810 | /// Tìm vị trí hình ảnh 811 | /// 812 | /// 813 | /// 814 | /// 815 | /// 816 | public static Point? FindImageOutPoint(string param, string NameOrIndex, string pathPNG) 817 | { 818 | Bitmap subBitmap = ImageScanOpenCV.GetImage(pathPNG); 819 | Bitmap screen = LDController.ScreenShoot(param, NameOrIndex); 820 | Point? poinImage = ImageScanOpenCV.FindOutPoint(screen, subBitmap); 821 | return poinImage; 822 | } 823 | 824 | public static void addProxy(string param, string NameOrIndex, string ip, string port) 825 | { 826 | LDController.ADB(param, NameOrIndex, "shell settings put global http_proxy " + ip + ":" + port); 827 | LDController.ADB(param, NameOrIndex, "shell settings put global global_http_proxy_host " + ip); 828 | LDController.ADB(param, NameOrIndex, "shell settings put global global_http_proxy_port " + port); 829 | } 830 | 831 | public static void removeProxy(string param, string NameOrIndex) 832 | { 833 | LDController.ADB(param, NameOrIndex, "shell settings put global http_proxy :0"); 834 | } 835 | } 836 | } 837 | -------------------------------------------------------------------------------- /LDPlayerNTC/LDPlayerNTC.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {2A5C3921-6B39-4F32-A589-5D43B8EFE0C3} 8 | Library 9 | Properties 10 | LDPlayerNTC 11 | LDPlayerNTC 12 | v4.7.2 13 | 512 14 | true 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | False 36 | bin\Debug\Emgu.CV.World.dll 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /LDPlayerNTC/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("LDPlayerNTC")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("LDPlayerNTC")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 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("2a5c3921-6b39-4f32-a589-5d43b8efe0c3")] 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoLDPlayerNCT 2 | Auto ADB LDPlayer 3 | Release Bao Gồm 4 | - ldconsole.exe 5 | - Emgu.CV.World.dll 6 | - LDController.dll 7 | 8 | Viết bởi Nhật Thích Codee https://www.facebook.com/nhat.canh.1998/ 9 | 10 | 11 | # List Command 12 | 0. Set Path LDPlayer "ldconsole.exe" 13 | ```js 14 | LDController.pathLD = "Your Path ldconsole.exe"; //VD: "C:\LDPlayer\LDPlayer4.0\ldconsole.exe" 15 | ``` 16 | 17 | 1. Initialization 18 | ```js 19 | using LDPlayerNTC; 20 | ``` 21 | 22 | 2. Manipulation Emulator 23 | ```js 24 | void Open(string param, string NameOrId) 25 | void Open_App(string param, string NameOrId, string Package_Name) //Mở LD cùng app khi chạy 26 | void Close(string param, string NameOrId) 27 | void CloseAll() 28 | void ReBoot(string param, string NameOrId) 29 | ``` 30 | ```js 31 | Exam: ldplayer.Open("name", "ld0"); 32 | ldplayer.Open("index", "0"); 33 | ``` 34 | 3. Custom Emulator 35 | ```js 36 | void Create(string Name) 37 | void Copy(string Name, string From_NameOrId) 38 | void Delete(string param, string NameOrId) 39 | void ReName(string param, string NameOrId, string title_new) 40 | ``` 41 | 42 | 4. App 43 | ```js 44 | void InstallApp_File(string param, string NameOrId, string File_Name) //File_Name trỏ tới file apk 45 | void InstallApp_Package(string param, string NameOrId, string Package_Name) //Cài qua LD Store, hơi dỏm, tốt nhất tự cài apk 46 | void UnInstallApp(string param, string NameOrId, string Package_Name) 47 | void RunApp(string param, string NameOrId, string Package_Name) 48 | void KillApp(string param, string NameOrId, string Package_Name) 49 | ``` 50 | 51 | 5. Orther 52 | ```js 53 | void Locate(string param, string NameOrId, string Lng, string Lat) //Set Toạ Độ GPS 54 | ``` 55 | 56 | ```js 57 | void Change_Property(string param, string NameOrId, string cmd) 58 | cmd use: 59 | [--resolution ] 60 | [--cpu < 1 | 2 | 3 | 4 >] 61 | [--memory < 512 | 1024 | 2048 | 4096 | 8192 >] 62 | [--manufacturer asus] 63 | [--model ASUS_Z00DUO] 64 | [--pnumber 13812345678] 65 | [--imei ] 66 | [--imsi ] 67 | [--simserial ] 68 | [--androidid ] 69 | [--mac ] 70 | [--autorotate < 1 | 0 >] 71 | [--lockwindow < 1 | 0 >] 72 | Exam: ldplayer.Change_Property("name", "ld0", " --cpu 1 --memory 1024 --imei 123456789"); 73 | ``` 74 | ```js 75 | string ADB(string param, string NameOrId, string cmd)) 76 | void Backup(string param, string NameOrId, string file_path) 77 | void Restore(string param, string NameOrId, string file_path) 78 | void Pull(string param, string NameOrId, string remote_file_path, string local_file_path) 79 | void Push(string param, string NameOrId, string remote_file_path, string local_file_path) 80 | ``` 81 | ```js 82 | void Golabal_Config(string param, string NameOrId, string fps, string audio, string fast_play, string clean_mode) 83 | [--fps <0~60>] [--audio <1 | 0>] [--fastplay <1 | 0>] [--cleanmode <1 | 0>] 84 | Exam: ldplayer.Golabal_Config("name", "ld0", "60", "0", "0", "0"); 85 | ``` 86 | 5. Get List Devices 87 | ```js 88 | List GetDevices() 89 | List GetDevices_Running() 90 | bool IsDevice_Running(string param, string NameOrId) 91 | List GetDevices2() 92 | List GetDevices2_Running() 93 | string GetNameOrIndex(string param, string NameOrIndex) 94 | bool IsDevice_Running(string param, string NameOrIndex) 95 | ``` 96 | 97 | 6. Cmd 98 | ```js 99 | void ExecuteLD(string cmd) 100 | string ExecuteLD_Result(string cmdCommand) 101 | ``` 102 | 103 | 7. Rewrite KAutoHelper 104 | ```js 105 | void Delay(double delayTime) 106 | Point GetScreenResolution(string param, string NameOrIndex) 107 | void TapByPercent(string param, string NameOrIndex, double x, double y, int count = 1) 108 | void Tap(string param, string NameOrIndex, int x, int y, int count = 1) 109 | void Key(string param, string NameOrIndex, ADBKeyEvent key) 110 | void InputText(string param, string NameOrIndex, string text) 111 | void SwipeByPercent(string param, string NameOrIndex, double x1, double y1, double x2, double y2, int duration = 100) 112 | void Swipe(string param, string NameOrIndex, int x1, int y1, int x2, int y2, int duration = 100) 113 | void PlanModeON(string param, string NameOrIndex, CancellationToken cancellationToken) 114 | void PlanModeOFF(string param, string NameOrIndex, CancellationToken cancellationToken) 115 | void LongPress(string param, string NameOrIndex, int x, int y, int duration = 100) 116 | Bitmap ScreenShoot(string param, string NameOrIndex, bool isDeleteImageAfterCapture = true, string fileName = "screenShoot.png") 117 | bool FindImage(string param, string NameOrIndex, string pathPNG) 118 | Point? FindImageOutPoint(string param, string NameOrIndex, string pathPNG) 119 | void addProxy(string param, string NameOrIndex, string ip, string port) 120 | void removeProxy(string param, string NameOrIndex) 121 | ``` 122 | --------------------------------------------------------------------------------