Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
danielniccoli committed May 28, 2022
1 parent 7678605 commit e4d3cae
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 3 deletions.
76 changes: 74 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using System.Diagnostics;
using System.Runtime.InteropServices;

const uint PROCESS_VM_READ = 0x10;

[DllImport("kernel32.dll")]
static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, uint dwProcessId);

[DllImport("kernel32.dll")]
static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead);

const int NOITA_SEED_VM_ADDRESS = 0xBEE850;
//const int NOITA_PLAYTIME_VM_ADDRESS = 0x2670;
//const int NOITA_INGAMETIME_VM_ADDRESS = 0xBF10C0;

Process? noitaProcess = null;
int seed = 0;

ConsoleColor defaultColor = Console.ForegroundColor;

while (true)
{
#region WaitForNoitaProcess
Console.Write($"Waiting for Noita process... ");

do
{
IEnumerable<Process> processes = Process.GetProcessesByName("noita")
.Where(p => !p.HasExited);

switch (processes.Count())
{
case 1:
Console.WriteLine("Found!");
noitaProcess = processes.First();
break;
case > 1:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Found!");
Console.Error.WriteLine($"Warning: Found ${processes.Count()} Noita processes. Selecting most recent.");
Console.ForegroundColor = defaultColor;
noitaProcess = processes.OrderByDescending(p => p.StartTime).First();
break;
default:
Thread.Sleep(500);
break;
}
} while (noitaProcess == null);
#endregion WaitForNoitaProcess

#region ReadNoitaSeed
IntPtr processHandle = OpenProcess(PROCESS_VM_READ, false, (uint)noitaProcess.Id);
IntPtr noitaSeedOffset = IntPtr.Add(noitaProcess.MainModule.BaseAddress, NOITA_SEED_VM_ADDRESS);
int bytesRead = 0;
byte[] buffer = new byte[8];

do
{
ReadProcessMemory(processHandle, noitaSeedOffset, buffer, buffer.Length, ref bytesRead);
int currentSeed = BitConverter.ToInt32(buffer, 0);

if (currentSeed != 0 && currentSeed != seed)
{
seed = currentSeed;

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Seed: {seed} - https://cr4xy.dev/noita/?seed={seed}");
Console.ForegroundColor = defaultColor;
}

Thread.Sleep(500);
} while (!noitaProcess.HasExited);
#endregion ReadNoitaSeed
}
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# noisee
Reads the seed of your current Noita run from memory.

Reads the seed of your current Noita run from memory.

# How to run

Start noisee.exe before or after you start Noita.

# Build from source

To publish as a single-file binary (requires [.NET 6 Runtime](<https://dotnet.microsoft.com/en-us/download/dotnet/6.0/runtime>)), run

```
dotnet publish --output "C:\temp\" --runtime win-x64 --configuration Release -p:PublishSingleFile=true --self-contained false
```

To publish as a single-file and self-contained binary, run

```
dotnet publish --output "C:\temp\" --runtime win-x64 --configuration Release -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true
```

0 comments on commit e4d3cae

Please sign in to comment.