From 9fe1cfb10f93c1e8c5a1204dda0f3549c1d546c3 Mon Sep 17 00:00:00 2001 From: copperpixel <48454166+copperpixel@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:53:53 +0100 Subject: [PATCH 1/3] vpc: remove python dependency for embedding vscripts at compile-time --- src/devtools/bin/texttoarray.ps1 | 25 +++++++++++++++++++++++++ src/devtools/bin/texttoarray.py | 22 ---------------------- src/devtools/bin/texttoarray.sh | 29 +++++++++++++++++++++++++++++ src/game/server/server_base.vpc | 4 ++-- 4 files changed, 56 insertions(+), 24 deletions(-) create mode 100644 src/devtools/bin/texttoarray.ps1 delete mode 100755 src/devtools/bin/texttoarray.py create mode 100644 src/devtools/bin/texttoarray.sh diff --git a/src/devtools/bin/texttoarray.ps1 b/src/devtools/bin/texttoarray.ps1 new file mode 100644 index 00000000000..b6d733dcb0e --- /dev/null +++ b/src/devtools/bin/texttoarray.ps1 @@ -0,0 +1,25 @@ +param +( + [ Parameter( Mandatory=$true ) ][ string ]$sFileName, + [ Parameter( Mandatory=$true ) ][ string ]$sObjName +) + +$Bytes = [ System.IO.File ]::ReadAllBytes( $sFileName ) + +Write-Host "static unsigned char $sObjName[] = {" +Write-Host " " -NoNewline + +for ( $i = 0; $i -lt $Bytes.Length; $i++ ) +{ + $Byte = $Bytes[ $i ] + Write-Host ( "0x{0:x2}," -f $Byte ) -NoNewline + + if ( ( $i % 20 ) -eq 19 ) + { + Write-Host "" + Write-Host " " -NoNewline + } +} + +Write-Host "0x00" +Write-Host "};" \ No newline at end of file diff --git a/src/devtools/bin/texttoarray.py b/src/devtools/bin/texttoarray.py deleted file mode 100755 index ec04c8c280f..00000000000 --- a/src/devtools/bin/texttoarray.py +++ /dev/null @@ -1,22 +0,0 @@ -import sys - -def main(filename, objname): - with open(filename, 'rb') as file: - data = file.read() - - output = f"static unsigned char {objname}[] = {{\n " - - for i in range(len(data)): - output += f"0x{data[i]:02x}," - if i % 20 == 19: - output += "\n " - - output += "0x00\n};\n" - print(output) - -if __name__ == "__main__": - if len(sys.argv) < 3: - print("Usage: python texttoarray.py ") - sys.exit(1) - - main(sys.argv[1], sys.argv[2]) diff --git a/src/devtools/bin/texttoarray.sh b/src/devtools/bin/texttoarray.sh new file mode 100644 index 00000000000..b66f0398827 --- /dev/null +++ b/src/devtools/bin/texttoarray.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +if [ $# -lt 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +sFileName="$1" +sObjName="$2" + +exec 3< "$sFileName" + +printf "static unsigned char %s[] = {\n " "$sObjName" + +i=0 +while :; do + Byte=$(dd bs=1 count=1 <&3 2>/dev/null | od -An -t u1) + [ -z "$Byte" ] && break + + Byte=$(printf "%s" "$Byte" | tr -d '[:space:]') + printf "0x%02x," "$Byte" + + i=$(( i + 1 )) + if [ $(( i % 20 )) -eq 0 ]; then + printf "\n " + fi +done + +printf "0x00\n};\n" diff --git a/src/game/server/server_base.vpc b/src/game/server/server_base.vpc index 32567c5dfd2..699734e89e7 100644 --- a/src/game/server/server_base.vpc +++ b/src/game/server/server_base.vpc @@ -45,8 +45,8 @@ $Configuration "Release" $CustomBuildStep "nut" { - $CommandLine "python $SRCDIR\devtools\bin\texttoarray.py $(InputPath) g_Script_$(InputName)> $(InputName)_nut.h" [$WINDOWS] - $CommandLine "python $SRCDIR\devtools\bin\texttoarray.py $(InputPath) g_Script_$(InputName)> $(InputName)_nut.h" [$POSIX] + $CommandLine "powershell $SRCDIR\devtools\bin\texttoarray.ps1 $(InputPath) g_Script_$(InputName)> $(InputName)_nut.h" [$WINDOWS] + $CommandLine "sh $SRCDIR\devtools\bin\texttoarray.sh $(InputPath) g_Script_$(InputName)> $(InputName)_nut.h" [$POSIX] $Description "$(InputFileName) produces $(InputName)_nut.h" $Outputs "$(InputName)_nut.h" } From fcada18d49fd49bcbea5a983ca3312c6c18a5df3 Mon Sep 17 00:00:00 2001 From: copperpixel <48454166+copperpixel@users.noreply.github.com> Date: Wed, 19 Nov 2025 16:49:47 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 89e7d7d5aba..0954b2892f7 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ Requirements: - Desktop development with C++: - MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest) - Windows 11 SDK (10.0.22621.0) or Windows 10 SDK (10.0.19041.1) - - Python 3.13 or later Inside the cloned directory, navigate to `src`, run: ```bat From a43807e5b2356859c524993bea4c17bb776c248f Mon Sep 17 00:00:00 2001 From: copperpixel <48454166+copperpixel@users.noreply.github.com> Date: Fri, 21 Nov 2025 00:10:54 +0100 Subject: [PATCH 3/3] vpc: fix issues with powershell script --- src/devtools/bin/texttoarray.ps1 | 24 +++++++++++++++--------- src/game/server/server_base.vpc | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/devtools/bin/texttoarray.ps1 b/src/devtools/bin/texttoarray.ps1 index b6d733dcb0e..4509e44daac 100644 --- a/src/devtools/bin/texttoarray.ps1 +++ b/src/devtools/bin/texttoarray.ps1 @@ -1,25 +1,31 @@ param ( - [ Parameter( Mandatory=$true ) ][ string ]$sFileName, - [ Parameter( Mandatory=$true ) ][ string ]$sObjName + [ Parameter( Mandatory = $true ) ][ string ]$sFileName, + [ Parameter( Mandatory = $true ) ][ string ]$sObjName ) $Bytes = [ System.IO.File ]::ReadAllBytes( $sFileName ) -Write-Host "static unsigned char $sObjName[] = {" -Write-Host " " -NoNewline +Write-Output "static unsigned char $sObjName[] = {" +$sLine = " " for ( $i = 0; $i -lt $Bytes.Length; $i++ ) { $Byte = $Bytes[ $i ] - Write-Host ( "0x{0:x2}," -f $Byte ) -NoNewline + + if ( ( $i % 20 ) -ne 0 ) + { + $sLine += " " + } + $sLine += ( "0x{0:x2}," -f $Byte ) if ( ( $i % 20 ) -eq 19 ) { - Write-Host "" - Write-Host " " -NoNewline + Write-Output $sLine + $sLine = " " } } -Write-Host "0x00" -Write-Host "};" \ No newline at end of file +$sLine += " 0x00" +Write-Output $sLine +Write-Output "};" \ No newline at end of file diff --git a/src/game/server/server_base.vpc b/src/game/server/server_base.vpc index 699734e89e7..09df866987e 100644 --- a/src/game/server/server_base.vpc +++ b/src/game/server/server_base.vpc @@ -45,7 +45,7 @@ $Configuration "Release" $CustomBuildStep "nut" { - $CommandLine "powershell $SRCDIR\devtools\bin\texttoarray.ps1 $(InputPath) g_Script_$(InputName)> $(InputName)_nut.h" [$WINDOWS] + $CommandLine "powershell -NoProfile -ExecutionPolicy Bypass -File $SRCDIR\devtools\bin\texttoarray.ps1 $(InputPath) g_Script_$(InputName)> $(InputName)_nut.h" [$WINDOWS] $CommandLine "sh $SRCDIR\devtools\bin\texttoarray.sh $(InputPath) g_Script_$(InputName)> $(InputName)_nut.h" [$POSIX] $Description "$(InputFileName) produces $(InputName)_nut.h" $Outputs "$(InputName)_nut.h"