Skip to content

Commit

Permalink
Update Program.cs
Browse files Browse the repository at this point in the history
More Comments
  • Loading branch information
0vm authored Jun 27, 2023
1 parent b897035 commit ab7bdcb
Showing 1 changed file with 41 additions and 69 deletions.
110 changes: 41 additions & 69 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand All @@ -10,15 +10,14 @@

namespace RAMLIMITER
{

class Program
{

public static string variableger = "Discord";

[DllImport("kernel32.dll")]
static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);

// Method to get the process ID of Discord
public static int GetDiscord()
{
int DiscordId = -1;
Expand All @@ -34,6 +33,7 @@ public static int GetDiscord()
return DiscordId;
}

// Method to get the process ID of Chrome
public static int GetChrome()
{
int chromeId = -1;
Expand All @@ -49,6 +49,7 @@ public static int GetChrome()
return chromeId;
}

// Method to get the process ID of a custom process
public static int GetCustom()
{
int OBSId = -1;
Expand All @@ -64,8 +65,7 @@ public static int GetCustom()
return OBSId;
}



// Method to get the process ID of OBS
public static int GetOBS()
{
int OBSId = -1;
Expand All @@ -81,7 +81,7 @@ public static int GetOBS()
return OBSId;
}


// Method to limit both Chrome and Discord
static void Both(int min, int max)
{
new Thread(() =>
Expand All @@ -94,7 +94,6 @@ static void Both(int min, int max)
if (GetChrome() != -1)
{
GC.Collect();

GC.WaitForPendingFinalizers();

if (Environment.OSVersion.Platform == PlatformID.Win32NT)
Expand All @@ -111,11 +110,9 @@ static void Both(int min, int max)

if (memoryValues != null)
{


var percent = ((memoryValues.TotalVisibleMemorySize - memoryValues.FreePhysicalMemory) / memoryValues.TotalVisibleMemorySize) * 100;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("CHROME: Total ram usage: {0}", percent);
Console.WriteLine("CHROME: Total RAM usage: {0}", percent);
Thread.Sleep(3000);
}

Expand All @@ -126,7 +123,6 @@ static void Both(int min, int max)
}).Start();
Thread.Sleep(5000);


new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
Expand All @@ -137,7 +133,6 @@ static void Both(int min, int max)
if (GetDiscord() != -1)
{
GC.Collect();

GC.WaitForPendingFinalizers();

if (Environment.OSVersion.Platform == PlatformID.Win32NT)
Expand All @@ -155,11 +150,9 @@ static void Both(int min, int max)

if (memoryValues != null)
{


var percent = ((memoryValues.TotalVisibleMemorySize - memoryValues.FreePhysicalMemory) / memoryValues.TotalVisibleMemorySize) * 100;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("DISCORD: Total ram usage: {0}", percent);
Console.WriteLine("DISCORD: Total RAM usage: {0}", percent);
Thread.Sleep(3000);
}

Expand All @@ -170,21 +163,16 @@ static void Both(int min, int max)

}).Start();
Thread.Sleep(-1);





}

// Method to limit Discord RAM usage
static void DiscordRamLimiter(int min, int max)
{
while (GetDiscord() != -1)
{
if (GetDiscord() != -1)
{
GC.Collect();

GC.WaitForPendingFinalizers();

if (Environment.OSVersion.Platform == PlatformID.Win32NT)
Expand All @@ -201,11 +189,9 @@ static void DiscordRamLimiter(int min, int max)

if (memoryValues != null)
{


var percent = ((memoryValues.TotalVisibleMemorySize - memoryValues.FreePhysicalMemory) / memoryValues.TotalVisibleMemorySize) * 100;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("DISCORD: Total ram usage: {0}", percent);
Console.WriteLine("DISCORD: Total RAM usage: {0}", percent);
Thread.Sleep(10000);
}

Expand All @@ -214,53 +200,49 @@ static void DiscordRamLimiter(int min, int max)
}
}


// Method to limit Chrome RAM usage
static void ChromeRamLimiter(int min, int max)
{
while (GetChrome() != -1)
{
if (GetChrome() != -1)
{
GC.Collect();

GC.WaitForPendingFinalizers();

if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(Process.GetProcessById(GetChrome()).Handle, min, max);
}

var wmiObject = new ManagementObjectSearcher("select * from Win32_OperatingSystem");
while (GetChrome() != -1)
{
if (GetChrome() != -1)
{
GC.Collect();
GC.WaitForPendingFinalizers();

var memoryValues = wmiObject.Get().Cast<ManagementObject>().Select(mo => new {
FreePhysicalMemory = Double.Parse(mo["FreePhysicalMemory"].ToString()),
TotalVisibleMemorySize = Double.Parse(mo["TotalVisibleMemorySize"].ToString())
}).FirstOrDefault();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(Process.GetProcessById(GetChrome()).Handle, min, max);
}

if (memoryValues != null)
{
var wmiObject = new ManagementObjectSearcher("select * from Win32_OperatingSystem");

var memoryValues = wmiObject.Get().Cast<ManagementObject>().Select(mo => new {
FreePhysicalMemory = Double.Parse(mo["FreePhysicalMemory"].ToString()),
TotalVisibleMemorySize = Double.Parse(mo["TotalVisibleMemorySize"].ToString())
}).FirstOrDefault();

var percent = ((memoryValues.TotalVisibleMemorySize - memoryValues.FreePhysicalMemory) / memoryValues.TotalVisibleMemorySize) * 100;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("CHROME: Total ram usage: {0}", percent);
if (memoryValues != null)
{
var percent = ((memoryValues.TotalVisibleMemorySize - memoryValues.FreePhysicalMemory) / memoryValues.TotalVisibleMemorySize) * 100;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("CHROME: Total RAM usage: {0}", percent);
Thread.Sleep(5000);
}

Thread.Sleep(1);
}
}
}

Thread.Sleep(1);
}
}
}

// Method to limit OBS RAM usage
static void OBSRamLimiter(int min, int max)
{
while (GetOBS() != -1)
{
if (GetOBS() != -1)
{
GC.Collect();

GC.WaitForPendingFinalizers();

if (Environment.OSVersion.Platform == PlatformID.Win32NT)
Expand All @@ -277,11 +259,9 @@ static void OBSRamLimiter(int min, int max)

if (memoryValues != null)
{


var percent = ((memoryValues.TotalVisibleMemorySize - memoryValues.FreePhysicalMemory) / memoryValues.TotalVisibleMemorySize) * 100;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("OBS: Total ram usage: {0}", percent);
Console.WriteLine("OBS: Total RAM usage: {0}", percent);
Thread.Sleep(5000);
}

Expand All @@ -290,10 +270,9 @@ static void OBSRamLimiter(int min, int max)
}
}


// Method to limit RAM usage of a custom process
static void CustomRamLimiter(int min, int max)
{

Console.WriteLine("Type Process Name Like Chrome or OBS");
variableger = Console.ReadLine();

Expand All @@ -302,7 +281,6 @@ static void CustomRamLimiter(int min, int max)
if (GetCustom() != -1)
{
GC.Collect();

GC.WaitForPendingFinalizers();

if (Environment.OSVersion.Platform == PlatformID.Win32NT)
Expand All @@ -319,11 +297,9 @@ static void CustomRamLimiter(int min, int max)

if (memoryValues != null)
{


var percent = ((memoryValues.TotalVisibleMemorySize - memoryValues.FreePhysicalMemory) / memoryValues.TotalVisibleMemorySize) * 100;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(variableger + ": Total ram usage: {0}", percent);
Console.WriteLine(variableger + ": Total RAM usage: {0}", percent);
Thread.Sleep(3000);
}

Expand All @@ -332,14 +308,11 @@ static void CustomRamLimiter(int min, int max)
}
}


static void Main(string[] args)
{
new Thread(() => // taken from pinger, originally from zf9
{

var s = " "; // 8 spaces for the titles spacing, looks very messy but who cares.

Thread.CurrentThread.IsBackground = true;
for (int i = 0; i < int.MaxValue; i++)
{
Expand Down Expand Up @@ -370,7 +343,8 @@ static void Main(string[] args)
}
Thread.Sleep(-1);
}).Start();
start:

start:
Console.WriteLine("Just Limit Discord: 1");
Console.WriteLine("Just Limit Chrome: 2");
Console.WriteLine("Just Limit OBS: 3");
Expand Down Expand Up @@ -411,8 +385,6 @@ static void Main(string[] args)
Thread.Sleep(2500);
goto start;
}


}
}
}

0 comments on commit ab7bdcb

Please sign in to comment.