Last active
December 23, 2025 13:59
-
-
Save zatricky/ee173530196c620aef20db205002ebda to your computer and use it in GitHub Desktop.
Stationeers hash function for Powershell using ntdll.dll's RtlComputeCrc32 and BitConverter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is free and unencumbered software released into the public domain. | |
| # For more information, please refer to <https://unlicense.org> | |
| function Get-IC10Hash { | |
| <# | |
| .SYNOPSIS | |
| Generate IC10 hash values for Stationeers game objects. | |
| .DESCRIPTION | |
| Converts a text string to an IC10 hash value (signed 32-bit CRC32) and its hex notation. | |
| The hex notation is compatible with IC10's $ hex literal format. | |
| .PARAMETER Text | |
| The text string to hash (e.g., "StructureGasAnalyser") | |
| Can also accept pipeline input. | |
| .EXAMPLE | |
| Get-IC10Hash "StructureGasAnalyser" | |
| Text Hash Hex | |
| ---- ---- --- | |
| StructureGasAnalyser 1876147318 $6FD3BC76 | |
| .EXAMPLE | |
| Get-IC10Hash "StructureLiquidAnalyser" | |
| Text Hash Hex | |
| ---- ---- --- | |
| StructureLiquidAnalyser -1789102802 $FFFFFFFF955C752E | |
| .EXAMPLE | |
| "StructureGasAnalyser", "StructureLiquidAnalyser" | Get-IC10Hash | |
| Text Hash Hex | |
| ---- ---- --- | |
| StructureGasAnalyser 1876147318 $6FD3BC76 | |
| StructureLiquidAnalyser -1789102802 $FFFFFFFF955C752E | |
| #> | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] | |
| [string]$Text | |
| ) | |
| Begin { | |
| # Use Windows ntdll.dll native CRC32 function | |
| $signature = @' | |
| [DllImport("ntdll.dll")] | |
| public static extern uint RtlComputeCrc32(uint dwInitial, byte[] pData, int iLen); | |
| '@ | |
| # Only add the type if it hasn't been added yet | |
| if (-not ([System.Management.Automation.PSTypeName]'NtDll.Crc32').Type) { | |
| Add-Type -MemberDefinition $signature -Namespace "NtDll" -Name "Crc32" | |
| } | |
| } | |
| Process { | |
| $bytes = [System.Text.Encoding]::UTF8.GetBytes($Text) | |
| # Calculate CRC32 using native Windows function | |
| $crc32 = [NtDll.Crc32]::RtlComputeCrc32(0, $bytes, $bytes.Length) | |
| # Convert to signed 32-bit integer using BitConverter | |
| # This properly reinterprets the bytes without arithmetic conversion | |
| $crcBytes = [BitConverter]::GetBytes([uint32]$crc32) | |
| $hashValue = [BitConverter]::ToInt32($crcBytes, 0) | |
| # Generate hex notation | |
| if ($hashValue -lt 0) { | |
| # Negative: use 64-bit two's complement (16 hex digits) | |
| # For negatives, prepend FFFFFFFF to the unsigned 32-bit CRC hex | |
| $hexValue = '$FFFFFFFF' + $crc32.ToString("X8") | |
| } else { | |
| # Positive: compact format (strip leading zeros) | |
| $hexValue = '$' + $crc32.ToString("X") | |
| } | |
| # Output as custom object for better formatting | |
| [PSCustomObject]@{ | |
| Text = $Text | |
| Hash = $hashValue | |
| Hex = $hexValue | |
| } | |
| } | |
| } | |
| # Create alias for shorter usage | |
| #Set-Alias -Name ic10hash -Value Get-IC10Hash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment