Initial commit

This commit is contained in:
Ferdinando 2026-07-30 19:00:13 +02:00
commit c4a24c9fdf
142 changed files with 15491 additions and 0 deletions

194
scripts/RenameSolution.ps1 Normal file
View file

@ -0,0 +1,194 @@
param([string]$cmdarg = "")
#Contibuted by Kpro#3271
#uncomment to enable logging
#Start-Transcript -OutputDirectory "C:\transcripts\"
Write-Host ""
Write-Host ""
Write-Host "WELCOME TO JOTUNNMODSTUB RENAMING UTILITY"
Write-Host "-----------------------------------------"
Write-Host ""
Write-Host "This script will do the following:"
Write-Host ""
Write-Host ""
Write-Host "1. Change the file names, folder names, and project references from the JotunnModStub to your custom solution name."
Write-Host ""
Write-Host "2. Change the DoPrebuild.props file."
Write-Host ""
Write-Host "3. Create the Environment.props file."
$modstubpath = Get-Location
$modstubpath = Split-Path $modstubpath -Parent
$modstubfoldername = Split-Path -Path $modstubpath -leaf
Write-Host ""
if ($cmdarg -eq "-nocopy") {
$Name = $modstubfoldername
} else {
#Check for rename and copy use-case
Write-Host "Step 1. Choose one of the following options:"
Write-Host ""
Write-Host "1. Create a solution in this folder named '$modstubfoldername'"
Write-Host ""
Write-Host "2. Copy this folder to a new folder with a solution name I will choose"
Write-Host ""
$yn = Read-Host "Select (1/2)?"
if ($yn -eq "1")
{
$Name = $modstubfoldername
}
else
{
Write-Host ""
Write-Host "Got it. A copy of this folder will be created with a new folder and solution name that you choose"
$Name = Read-Host "Enter a new name for the solution."
Write-Host ""
#Copy modstub folder
Copy-Item "..\..\$modstubfoldername" -Destination "..\..\$Name" -Recurse -Exclude @(".vs",".idea",".git")
Set-Location "..\..\$Name"
Write-Host "Current location set to: $(Get-Location)"
}
}
#Rename folders and files
if ($Name -ne "")
{
Write-Host " . . . Renaming files and folders to '$Name' . . ."
Move-Item -Path ..\$Name\JotunnModStub -Destination ..\$Name\$Name
$unity = $Name + "Unity"
Move-Item -Path ..\$Name\JotunnModStubUnity -Destination ..\$Name\$unity
Get-ChildItem -Path ..\$Name\ -File -Recurse | % -Process{if($_.Name -ne "JotunnModStub.zip") {Rename-Item -Path $_.PSPath -NewName $_.Name.replace("JotunnModStub", $Name)}}
}
else{
Write-Host "Error: empty solution name"
Read-Host "Enter to exit"
Exit 0
}
#Rename internal references
$msg = " . . . Replacing internal references to 'JotunnModStub' with " + '($Name)' + " . . ."
Write-Host $msg
((Get-Content -path ..\$Name\$Name.sln -Raw) -replace 'JotunnModStub',$Name) | Set-Content -Path ..\$Name\$Name.sln
((Get-Content -path ..\$Name\$Name\$Name.cs -Raw) -replace 'JotunnModStub',$Name) | Set-Content -Path ..\$Name\$Name\$Name.cs
$landed = $Name + " has landed"
((Get-Content -path ..\$Name\$Name\$Name.cs -Raw) -replace 'ModStub has landed',$landed) | Set-Content -Path ..\$Name\$Name\$Name.cs
((Get-Content -path ..\$Name\$Name\$Name.csproj -Raw) -replace 'JotunnModStub',$Name) | Set-Content -Path ..\$Name\$Name\$Name.csproj
((Get-Content -path ..\$Name\$Name\$Name.csproj -Raw) -replace 'JotunnModStubUnity',$unity) | Set-Content -Path ..\$Name\$Name\$Name.csproj
((Get-Content -path ..\$Name\$Name\Properties\AssemblyInfo.cs -Raw) -replace 'JotunnModStub',$Name) | Set-Content -Path ..\$Name\$Name\Properties\AssemblyInfo.cs
#setting DoPrebuild.props to true
Write-Host ""
Write-Host "Step 2. . . . setting DoPrebuid.props <ExecutePrebuild> to true..."
((Get-Content -path ..\$Name\DoPreBuild.props -Raw) -replace 'False','True') | Set-Content -Path ..\$Name\DoPreBuild.props
Write-Host ""
#Test whether Environment.props exists in parent directory
if (Test-Path -Path ..\Environment.props) {
Write-Host ""
$yn = Read-Host "Step 3. . . . An Environment.Props file is dectected in the parent directory. Copy this file to solution directory (y/n)?"
if ($yn -eq "y") {
Copy-Item "..\Environment.props" -Destination ".\"
} else {
Write-Host ""
Write-Host "WARNING"
Write-Host "-------"
Write-Host ""
Write-Host "You must create an environment.props file inside the solution directory PRIOR to building the solution."
Write-Host "Instructions for creating this file can be found at"
Write-Host "https://github.com/Valheim-Modding/JotunnModStub"
Write-Host ""
Write-Host ""
Read-Host "Hit Enter to Exit"
Exit 1
}
} else {
Write-Host ""
Write-Host "Step 3 . . . . You must create an environment.props file inside the solution directory PRIOR to building the solution."
Write-Host ""
$yn3 = Read-Host " -- Would you like to create an environment.props file now (y/n)"
if ($yn3 -eq "y")
{
#Initially assume typical install location
$TypicalInstallFolder = "c:\Program Files (x86)\Steam\steamapps\common\Valheim"
#Test for existence of typical install
if (Test-Path -Path $TypicalInstallFolder) {
$ValheimFolder = $TypicalInstallFolder
} else {
$ValheimFolder = "$env:SystemDrive"
}
#Ask user to verify install folder
function Get-InstallFolder($initialDirectory="") {
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
$OpenFolderDialog = New-Object System.Windows.Forms.FolderBrowserDialog
$OpenFolderDialog.SelectedPath = $initialDirectory
$OpenFolderDialog.Description = "Select Valheim Install Folder"
$OpenFolderDialog.rootfolder = "MyComputer"
[void] $OpenFolderDialog.ShowDialog()
return $OpenFolderDialog.SelectedPath
}
Write-Host ""
Write-Host " -- Hit ENTER to select your Valheim install folder"
$verifiedinstallfolder = Get-InstallFolder($ValheimFolder)
#Build environment.props
New-Item .\environment.props
Add-Content -Path .\environment.props -Value '<?xml version="1.0" encoding="utf-8"?>'
Add-Content -Path .\environment.props -Value '<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">'
Add-Content -Path .\environment.props -Value ' <PropertyGroup>'
Add-Content -Path .\environment.props -Value ' <!-- Needs to be your path to the base Valheim folder -->'
#Build Install Path
$installpath = " <VALHEIM_INSTALL>$verifiedinstallfolder</VALHEIM_INSTALL>"
Add-Content -Path .\environment.props -Value $installpath
Add-Content -Path .\environment.props -Value ' <!-- This is the folder where your build gets copied to when using the post-build automations -->'
Add-Content -Path .\environment.props -Value ' <MOD_DEPLOYPATH>$(VALHEIM_INSTALL)\BepInEx\plugins</MOD_DEPLOYPATH>'
Add-Content -Path .\environment.props -Value ' </PropertyGroup>'
Add-Content -Path .\environment.props -Value '</Project>'
#Copy environment.props to parent folder for reuse
Copy-Item ".\environment.props" -Destination "..\"
#check for existence of BepInEx folder
if (Test-Path -Path $verifiedinstallfolder\BepInEx) {
} else {
Write-Host "WARNING: BepInEx is not installed."
}
}
}
#Exit
Write-Host ""
Write-Host ""
Write-Host "Success"
Write-Host "-------"
Write-Host ""
Write-Host "The process is complete."
Write-Host "Note that, as stated in the wiki, the compiler will generate reference errors the first time you build the solution."
Write-Host "This is normal. Close VS2019/2022. Reopen the solution. Build. The errors should be resolved."
Write-Host ""
Write-Host ""
Read-Host "Hit Enter to Exit"
Write-Host ""
Write-Host ""
Exit 0

70
scripts/publish.ps1 Normal file
View file

@ -0,0 +1,70 @@
param(
[Parameter(Mandatory)]
[ValidateSet('Debug','Release')]
[System.String]$Target,
[Parameter(Mandatory)]
[System.String]$TargetPath,
[Parameter(Mandatory)]
[System.String]$TargetAssembly,
[Parameter(Mandatory)]
[System.String]$ValheimPath,
[Parameter(Mandatory)]
[System.String]$ProjectPath,
[System.String]$DeployPath
)
# Make sure Get-Location is the script path
Push-Location -Path (Split-Path -Parent $MyInvocation.MyCommand.Path)
# Test some preliminaries
("$TargetPath",
"$ValheimPath",
"$(Get-Location)\..\libraries"
) | % {
if (!(Test-Path "$_")) {Write-Error -ErrorAction Stop -Message "$_ folder is missing"}
}
# Plugin name without ".dll"
$name = "$TargetAssembly" -Replace('.dll')
# Create the mdb file
$pdb = "$TargetPath\$name.pdb"
if (Test-Path -Path "$pdb") {
Write-Host "Create mdb file for plugin $name"
Invoke-Expression "& `"$(Get-Location)\..\libraries\Debug\pdb2mdb.exe`" `"$TargetPath\$TargetAssembly`""
}
# Main Script
Write-Host "Publishing for $Target from $TargetPath"
if ($Target.Equals("Debug")) {
if ($DeployPath.Equals("")){
$DeployPath = "$ValheimPath\BepInEx\plugins"
}
$plug = New-Item -Type Directory -Path "$DeployPath\$name" -Force
Write-Host "Copy $TargetAssembly to $plug"
Copy-Item -Path "$TargetPath\$name.dll" -Destination "$plug" -Force
Copy-Item -Path "$TargetPath\$name.pdb" -Destination "$plug" -Force
Copy-Item -Path "$TargetPath\$name.dll.mdb" -Destination "$plug" -Force
}
if($Target.Equals("Release")) {
Write-Host "Packaging for ThunderStore..."
$Package="Package"
$PackagePath="$ProjectPath\$Package"
Write-Host "$PackagePath\$TargetAssembly"
New-Item -Type Directory -Path "$PackagePath\plugins" -Force
Copy-Item -Path "$TargetPath\$TargetAssembly" -Destination "$PackagePath\plugins\$TargetAssembly" -Force
Copy-Item -Path "$ProjectPath\README.md" -Destination "$PackagePath\README.md" -Force
Compress-Archive -Path "$PackagePath\*" -DestinationPath "$TargetPath\$name.zip" -Force
}
# Pop Location
Pop-Location

72
scripts/publish.sh Normal file
View file

@ -0,0 +1,72 @@
#!/bin/sh
target="Debug"
targetPath="JotunnModStub/bin/$target/net48"
targetAssembly="JotunnModStub.dll"
valheimPath=""
bepinexPath=""
deployPath=""
projectPath="./JotunnModStub"
while [ "$#" -gt 0 ]; do
case "$1" in
--target)
target="$2"; shift 2 ;;
--target-path)
targetPath="$2"; shift 2 ;;
--target-assembly)
targetAssembly="$2"; shift 2 ;;
--valheim-path)
valheimPath="$2"; shift 2 ;;
--bepinex-path)
bepinexPath="$2"; shift 2 ;;
--deploy-path)
deployPath="$2"; shift 2 ;;
--project-path)
projectPath="$2"; shift 2 ;;
*)
echo "Warning: Unknown argument $1" >&2; shift ;;
esac
done
# order of precedence: MOD_DEPLOYPATH > BEPINEX_PATH > VALHEIM_INSTALL > default path
if [ -z "$deployPath" ]; then
if [ -z "$bepinexPath" ]; then
if [ -z "$valheimPath" ]; then
deployPath="$HOME/.local/share/Steam/steamapps/common/Valheim/BepInEx/plugins"
else
deployPath="$valheimPath/BepInEx/plugins"
fi
else
deployPath="$bepinexPath/plugins"
fi
fi
# strip .dll extension
name=$(echo "$targetAssembly" | sed 's/\.dll//')
if [ "$target" = "Debug" ]; then
plug="$deployPath/$name"
echo "Copying $targetAssembly to $plug"
mkdir -p "$plug"
cp "$targetPath/$targetAssembly" "$plug"
# copy if it exists
[ -e "$targetPath/$name.pdb" ] && cp "$targetPath/$name.pdb" "$plug"
fi
if [ "$target" = "Release" ]; then
packagePath="$projectPath/Package"
mkdir -p "$packagePath/plugins"
cp "$targetPath/$targetAssembly" "$packagePath/plugins/"
cp "$projectPath/README.md" "$packagePath/"
if command -v zip > /dev/null; then
[ -e "$name.zip" ] && rm "$name.zip"
cd "$packagePath"
zip -r "../$name.zip" . > /dev/null
echo "Build successful, your zip is ready for upload at $(realpath ../$name.zip)."
else
echo "Skipping plugin zipping, zip command isn't available."
fi
fi

16
scripts/rename.sh Normal file
View file

@ -0,0 +1,16 @@
#!/bin/bash
if [ $# -ne 2 ]; then
echo "Usage: $0 <old string> <new string>"
exit 1
fi
directory="."
oldstring="$1"
newstring="$2"
# Replace string in file and folder names
find "$directory" -depth -not -path '*/.git/*' -name "*$oldstring*" -execdir bash -c 'mv -- "$1" "${1//'"$oldstring"'/'"$newstring"'}"' _ {} \;
# Replace string in file contents
find "$directory" -not -path '*/.git/*' -type f -exec sed -i "s/$oldstring/$newstring/g" {} +