From f124b27cfb334ff15c0ef891cb0dc6e71ac17dea Mon Sep 17 00:00:00 2001
From: azurecloudminingscript <azurecloudminingscript@gmail.com>
Date: Sun, 24 Nov 2019 16:05:24 +0100
Subject: [PATCH]

---
 azure_script/run_xmr_stak.pl | 61 +++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 28 deletions(-)

diff --git a/azure_script/run_xmr_stak.pl b/azure_script/run_xmr_stak.pl
index ba3d309..5c5dc3c 100755
--- a/azure_script/run_xmr_stak.pl
+++ b/azure_script/run_xmr_stak.pl
@@ -350,37 +350,37 @@ do
     CreateUserConfig($Threads, $Intensity,15);
     $base=GetHashRate();
     
-    my $plus;
+    my $plus=0;
+    my $minus=0;
     my $diff=0;
+
+    if($Intensity >=2)
+    {
+        CreateUserConfig($Threads, $Intensity-1,15);
+        $minus=GetHashRate();
+    }
     
-    CreateUserConfig($Threads, $Intensity+1,15);
-    $plus=GetHashRate();
-    
-    if($plus > $base)
+    if($minus > $base)
     {
-        $Intensity+=1;
-        $diff=1;
-        $base=$plus;
+        $Intensity-=1;
+        $diff=-1;
+        $base=$minus;
     }
     else
     {
-        my $minus;
+        CreateUserConfig($Threads, $Intensity+1,15);
+        $plus=GetHashRate();
         
-        if($Intensity >1)
+        if($plus > $base)
         {
-            CreateUserConfig($Threads, $Intensity-1,15);
-            $minus=GetHashRate();
-            
-            if ($minus > $base)
-            {
-                $Intensity-=1;
-                $diff=-1;
-                $base=$minus;
-            }
+            $Intensity+=1;
+            $diff=1;
+            $base=$plus;
         }
     }
+
     
-    if($diff !=0 && $Intensity >=2)
+    if($diff !=0)
     {
 
         my $OldHash=$base;
@@ -389,18 +389,23 @@ do
         do
         {
             $OldHash=$CurHash;
-            
-            
             $Intensity+=$diff;
             
-            CreateUserConfig($Threads, $Intensity,15);
-            $CurHash=GetHashRate();
-            
+            if($Intensity<=0)
+            {
+                $CurHash=0;
+            }
+            else
+            {
+                CreateUserConfig($Threads, $Intensity,15);
+                $CurHash=GetHashRate();
+            }
+                
         }
-        while($CurHash>$OldHash && $Intensity>=2);
+        while($CurHash>$OldHash);
+        $Intensity-=$diff;
     }
-
-    $Intensity-=$diff;
+    
     CreateUserConfig($Threads, $Intensity,60);
     CreateDonationConfig($Threads, $Intensity);
     
-- 
GitLab