SUBSIM Radio Room Forums



SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997

Go Back   SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > SHIII Mods Workshop
Forget password? Reset here

Reply
 
Thread Tools Display Modes
Old 01-15-26, 10:56 AM   #1
Kedishen
Seaman
 
Join Date: Feb 2012
Posts: 36
Downloads: 107
Uploads: 0
Default menu_1024_768.ini Renumbering Powershell Script

I couldn't get the renumbering program to work properly for me. Even though it output the file to C:/, it didn't seem to change anything. Soo...

Code:
# ================================
# USER SETTINGS
# ================================
$inputFile  = "menu_1024_768.ini"
$outputFile = "menu_1024_768_RENUMBERED.ini"
$targetG = "31"
# ================================

$counter = 1

$lines = Get-Content $inputFile
$pattern = "\[G$targetG([A-Za-z]*) I(\d+)\]"

for ($i = 0; $i -lt $lines.Length; $i++) {
    $line = $lines[$i]

    # Skip full-line comments
    if ($line.TrimStart().StartsWith(";")) { continue }

    # Find first semicolon
    $semicolonPos = $line.IndexOf(";")
    if ($semicolonPos -eq -1) { $semicolonPos = $line.Length }

    # Split code and comment
    $codePart = $line.Substring(0, $semicolonPos)
    $commentPart = if ($semicolonPos -lt $line.Length) { $line.Substring($semicolonPos) } else { "" }

    # Find all matches in code part
    $matches = [regex]::Matches($codePart, $pattern)

    if ($matches.Count -gt 0) {
        $newCode = ""
        $lastIndex = 0

        foreach ($m in $matches) {
            # Append text before match
            $newCode += $codePart.Substring($lastIndex, $m.Index - $lastIndex)
            # Append renumbered match
            $newCode += "[G$targetG$($m.Groups[1].Value) I$counter]"
            $counter++
            # Move lastIndex past this match
            $lastIndex = $m.Index + $m.Length
        }

        # Append remaining text after last match
        $newCode += $codePart.Substring($lastIndex)

        # Recombine code + comment
        $lines[$i] = $newCode + $commentPart
    }
}

# Save output
Set-Content $outputFile ($lines -join "`n") -Encoding UTF8

Write-Host "Renumbered G$targetG entries sequentially (comment-safe). Total entries: $($counter - 1)"
Write-Host "Output written to: $outputFile"
It is abit slow being a powershell script (expect it to take a good minute or two depending on the file size), but this will parse each line of your input file looking for [G# I#] based on the G number you entered in the user settings.

It will change the I number for each entry (ignoring any comments found on same line) based on the order that it appears in the file. Everything else will remain the same.

Put input.txt and [scriptname].ps1 in the same folder. The original file is not altered so you can run it directly on your Menu .ini file if you like. Just change the input file name in user settings. Still good to make a backup of the menu.ini file though.

Open that folder

Hold Shift + Right Click → choose Open PowerShell window here

Run:
Code:
powershell -ExecutionPolicy Bypass -File [scriptname].ps1
Enjoy.

Last edited by Kedishen; 01-15-26 at 12:07 PM.
Kedishen is offline   Reply With Quote
Old 01-15-26, 05:16 PM   #2
FUBAR295
Krusty Krab
 
FUBAR295's Avatar
 
Join Date: Mar 2002
Location: Decks awash in the North Atlantic
Posts: 1,568
Downloads: 624
Uploads: 0
Default

Thanks ! Have to check it out.
__________________
Good judgment comes from experience. Unfortunately, the experience usually comes from bad judgment.


FUBAR295 is offline   Reply With Quote
Old 02-10-26, 02:56 PM   #3
Hebe Vollmaus
Frogman
 
Join Date: Jun 2010
Location: Germany
Posts: 290
Downloads: 3
Uploads: 1
Default

Quote:
Originally Posted by Kedishen View Post
I couldn't get the renumbering program to work properly for me. Even though it output the file to C:/, it didn't seem to change anything. Soo...

[8<--]
Thanks for the Script!
Yes, this Bypass is a nice option. I use it every (work)day.

"the renumbering program".
I hope its not my tool that does not work for you.
Please be more specific. Whats the Name or from what Author do you talking about. I am aware of at least four (4) different menu.ini-Renumbering-Tools. One from H.Sie, one from Stiebler, one from Fader Berg and my own Tool.

H.Sie - SH3MenuIniRenumber (exe/jar)
Stiebler - SH3Menu_Renumber
Fader Berg - SH3rryPick
mySH3-TooL

Greetings.
Hebe Vollmaus is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:22 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright © 1995- 2026 Subsim®
"Subsim" is a registered trademark, all rights reserved.