Skip to content

Instantly share code, notes, and snippets.

@vexx32
Last active October 2, 2024 19:56
Show Gist options
  • Save vexx32/fb3131b740af1602c7eed974ea8d2e46 to your computer and use it in GitHub Desktop.
Save vexx32/fb3131b740af1602c7eed974ea8d2e46 to your computer and use it in GitHub Desktop.
Starts Noita from the given path, optionally with a specific seed set.
function Start-Noita {
<#
.SYNOPSIS
Starts Noita from a PowerShell prompt, optionally with a specific set seed for a new game.
.DESCRIPTION
To use this function, copy and paste the complete function definition into a PowerShell
session, and then invoke it with `Start-Noita`. Supply `-Seed somevalue` if you would like
to run a specific seed (see the examples below).
.EXAMPLE
PS> Start-Noita
Starts Noita normally.
.EXAMPLE
PS> Start-Noita -Seed 1
Starts Noita with a fixed seed value of 1.
.EXAMPLE
PS> Start-Noita -Seed 1 -Path C:\Noita\noita.exe
Starts Noita from the requested location with a fixed seed value of 1.
Use this form if your copy of Noita was not installed via Steam, or modify the default
setting for $Path below before loading the function into your PowerShell session.
.NOTES
If you want, you can load this function into your PowerShell profile as follows:
1. Copy the entire function definition from top to bottom to your Windows clipboard (Ctrl+C).
2. Run the following code in PowerShell:
Get-Clipboard | Add-Content -Path $profile
3. Close and reopen PowerShell to load the newly modified profile.
4. Run `Start-Noita` directly as needed. It will be automatically loaded in any future PowerShell sessions.
#>
[CmdletBinding(DefaultParameterSetName = 'Default')]
param(
[Parameter()]
[string]
$Path = "C:\Program Files (x86)\Steam\steamapps\common\Noita",
[Parameter(Position = 0, ParameterSetName = 'Default')]
[long]
$Seed,
[Parameter(ParameterSetName = 'Default')]
[switch]
$DevMode,
[Parameter(Mandatory, ParameterSetName = 'Unpack')]
[switch]
$UnpackData
)
$noitaArgs = @()
$noitaFolder = $Path | Split-Path -Parent
if ($Seed) {
$xml = [System.Xml.XmlDocument]::new()
$node = $xml.CreateElement('MagicNumbers')
$xml.AppendChild($node) > $null
$blank = $xml.CreateTextNode([Environment]::NewLine)
$node.AppendChild($blank) > $null
$node.SetAttribute('WORLD_SEED', $Seed)
$node.SetAttribute('_DEBUG_DONT_LOAD_OTHER_MAGIC_NUMBERS', 1)
$node.SetAttribute('_DEBUG_DONT_SAVE_MAGIC_NUMBERS', 1)
$magicPath = $Path | Join-Path -ChildPath 'magic.txt'
$sb = [System.Text.StringBuilder]::new()
$xmlWriter = [System.Xml.XmlWriter]::Create(
$sb,
@{
Indent = $true
NewLineOnAttributes = $true
OmitXmlDeclaration = $true
}
)
$xml.Save($xmlWriter)
$xmlText = $sb.ToString()
Write-Verbose $xmlText
$xmlText | Set-Content -Path $magicPath
$noitaArgs = @(
'-no_logo_splashes'
'-magic_numbers', 'magic.txt'
)
}
elseif ($UnpackData) {
$noitaArgs = @(
'-wizard_unpak'
)
}
$filename = if ($DevMode) {
'noita_dev.exe'
}
else {
'noita.exe'
}
$executable = Join-Path $Path -ChildPath $filename
try {
Push-Location $Path
& $executable @noitaArgs
}
finally {
Pop-Location
}
}
@JordanShurmer
Copy link

There's a mod for starting with a Seed now. FYI for others who find this looking for that functionality:
https://steamcommunity.com/sharedfiles/filedetails/?id=2284931352

@vexx32
Copy link
Author

vexx32 commented Aug 24, 2021

Aye, mods work, but certain game functionality is disabled with mods enabled, which is why this script exists. 🙂

@bartekzwartek
Copy link

https://imgur.com/a/4TyuEGM
It seems fine to me, but it doesn't want to work.
Maybe I missed something

@vexx32
Copy link
Author

vexx32 commented Aug 26, 2021

Like I said, you need to copy the whole file. Help comments at the start are inside of the function declaration, so if you cut those off, you've also cut off the function Start-Noita { declaration. If you copy the file as a whole, without leaving bits out, it'll work. 🙂

@bartekzwartek
Copy link

I'm an idiot :D :D
Thank you

@jaymes-bearden
Copy link

You may need to adjust the execution policy if this is your first time messing with PowerShell. Start PowerShell as administrator, run Set-ExecutionPolicy -ExecutionPolicy AllSigned or Set-ExecutionPolicy -ExecutionPolicy Unrestricted. Note: doing so will remove some script running protections so you may want to undo this later on with Set-ExecutionPolicy -ExecutionPolicy Undefined

@Aliepay
Copy link

Aliepay commented Dec 1, 2023

Thanks.
Although as a person who doesn't know much about PowerShell and doesn't know much about computers, after unremitting efforts and your guidance, I finally succeeded as I wished

@Zrashin
Copy link

Zrashin commented Feb 10, 2024

Not sure if this still works, It opens the game but the seed still is random

@MiiaBestLamia
Copy link

Not sure if this still works, It opens the game but the seed still is random

I believe it doesn't work with the newest version (January 18th 2024 patch), it also just opens the game, but the seed is random. Worked just fine previously.

@Javeloz
Copy link

Javeloz commented Mar 21, 2024

Any chance of an update that works with the latest version? I'm not sure why it refuses to actually set the seed

Edit: I get no errors, it just launches with a random seed each time anyways.

@KZander93
Copy link

KZander93 commented May 10, 2024

Not sure if it'd help typing here but I had the magic.txt file open while starting a new game, playing for a while, and closing. Went back and forth between the txt file window and the game a few times to see if anything has changed. Noita creates a new magic.txt file when opening or closing the game. So even if you edit the variables inside manually, it wouldn't work. (Technically, its not something wrong from the script)

@Aliepay
Copy link

Aliepay commented May 10, 2024 via email

@an-tonic
Copy link

an-tonic commented May 10, 2024

Yes, when I try the scripts around April, I found it doesn't work. So I use the mod to change the seed. | | @.*** | | @.*** |

---- Replied Message ---- | From | @.> | | Date | 05/10/2024 22:28 | | To | @.> | | Cc | @.***> | | Subject | Re: vexx32/start-noita.ps1 | @KZander93 commented on this gist. Not sure if it'd help typing here but I had the magic.txt file open while starting a new game, playing for a while, and closing. Went back and forth between the txt file window and the game a few times to see if anything has changed. Noita creates a new magic.txt file when starting a new run and when closing the game. So even if you edit the variables inside manually, it wouldn't work. (Technically, its not something wrong from the script) — Reply to this email directly, view it on GitHub or unsubscribe. You are receiving this email because you commented on the thread. Triage notifications on the go with GitHub Mobile for iOS or Android.

Which mod are you refering to? Does it work correctly and reliably?

@Aliepay
Copy link

Aliepay commented May 10, 2024

just a mod in the steam called Seed changer,working well

@KZander93
Copy link

just a mod in the steam called Seed changer,working well

Wouldn't it disable achievements and progress if used a mod ?

@SydBal
Copy link

SydBal commented May 10, 2024

I also noticed the script is no longer working with the newer version. I made sure my installation matched the script, It was working last year, but there were a number of updates recently which are likely breaking this in the Apr 30 2024 build.

@NathanHoyes
Copy link

I've tried editting magic.txt manually, then setting it as read only. The contents remain, instead of resetting to WORLD_SEED="0", etc.
Noita still loads a random seed though.

@PolkageistHS
Copy link

Can confirm it no longer works. A pity, I wanted to be able to do this without mods.

@Xiarno
Copy link

Xiarno commented Aug 9, 2024

Any update on this or does anyone have an alternative that works?

@vexx32
Copy link
Author

vexx32 commented Sep 8, 2024

There doesn't seem to be any way I can find to do this now without mods at present. Other methods may be discovered in future, but presently I think the mods are the best bet.

@junkbox666
Copy link

There doesn't seem to be any way I can find to do this now without mods at present. Other methods may be discovered in future, but presently I think the mods are the best bet.

OK, then how do the mods accomplish it? Mean to say, the 'functionality' still exists and should be scriptable. I haven't looked at any of the seed changer mods. Which simple mod still works? I'll look at the files.

@vexx32
Copy link
Author

vexx32 commented Oct 2, 2024

The seed changer mods are lua scripts loaded by Noita itself. It seems the magic_numbers.xml file processing feature was changed in a recent(ish) update to no longer allow setting the world seed via this mechanism.

So the only way currently that I am aware of is you must load a mod in order to force a set seed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment