Merge branch 'nibu/rtd-release-pkg' into nibu/rtd-integrate-w2
This commit is contained in:
commit
7a30d84345
12 changed files with 723 additions and 90 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,6 +2,7 @@
|
|||
__pycache__/
|
||||
/out/
|
||||
/scratch/
|
||||
/dist/
|
||||
bin/
|
||||
obj/
|
||||
.godot/
|
||||
|
|
|
|||
42
client/ClientAssets.cs
Normal file
42
client/ClientAssets.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Godot;
|
||||
using RustToDust.Core;
|
||||
|
||||
namespace RustToDust.Client;
|
||||
|
||||
internal static class ClientAssets
|
||||
{
|
||||
private static bool _registered;
|
||||
|
||||
internal static void EnsureAssetsRootRegistered()
|
||||
{
|
||||
if (_registered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_registered = true;
|
||||
|
||||
if (OS.HasFeature("template"))
|
||||
{
|
||||
string exeAssets = Path.Combine(OS.GetExecutablePath().GetBaseDir(), "assets");
|
||||
if (Directory.Exists(exeAssets))
|
||||
{
|
||||
AssetPathResolver.RegisterAssetsRoot(exeAssets);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string baseAssets = Path.Combine(AppContext.BaseDirectory, "assets");
|
||||
if (Directory.Exists(baseAssets))
|
||||
{
|
||||
AssetPathResolver.RegisterAssetsRoot(baseAssets);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string LocateAssetsDirectory()
|
||||
{
|
||||
EnsureAssetsRootRegistered();
|
||||
return AssetPathResolver.LocateAssetsRoot();
|
||||
}
|
||||
}
|
||||
|
|
@ -136,6 +136,7 @@ public partial class Main : Node3D
|
|||
|
||||
public override void _Ready()
|
||||
{
|
||||
ClientAssets.EnsureAssetsRootRegistered();
|
||||
GetViewport().UseTaa = true;
|
||||
_atmosphere = new AtmosphereSystem { Name = "AtmosphereSystem" };
|
||||
AddChild(_atmosphere);
|
||||
|
|
@ -322,6 +323,14 @@ public partial class Main : Node3D
|
|||
}
|
||||
_menuPreviewOut = System.Environment.GetEnvironmentVariable("RTD_MENU_PREVIEW_OUT");
|
||||
|
||||
bool hasWindowOverride = GetCliArg("--windowed", allowBareFlag: true) is not null
|
||||
|| GetCliArg("--resolution", allowBareFlag: true) is not null
|
||||
|| GetCliArg("-w", allowBareFlag: true) is not null;
|
||||
if (!IsAutomatedRun && !hasWindowOverride)
|
||||
{
|
||||
DisplayServer.WindowSetMode(DisplayServer.WindowMode.Fullscreen);
|
||||
}
|
||||
|
||||
bool perfCombat = _perfTargetFrames > 0 && System.Environment.GetEnvironmentVariable("RTD_PERF_COMBAT") == "1";
|
||||
bool skipInitialDrop = InitialSkipDropOverride || perfCombat;
|
||||
bool autoBypassMenu = InitialMapKindOverride.HasValue
|
||||
|
|
@ -912,10 +921,59 @@ public partial class Main : Node3D
|
|||
SyncMouseMode();
|
||||
}
|
||||
|
||||
private bool IsAutomatedRun =>
|
||||
DisplayServer.GetName() == "headless"
|
||||
|| InitialMapKindOverride.HasValue
|
||||
|| InitialSkipDropOverride
|
||||
|| InitialSkipMenuOverride
|
||||
|| _perfTargetFrames > 0
|
||||
|| _menuPreviewTargetFrames > 0
|
||||
|| !string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("RTD_PERF_FRAMES"))
|
||||
|| !string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("RTD_AUTO_EXIT_FRAMES"))
|
||||
|| !string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("RTD_MENU_EXIT_FRAMES"));
|
||||
|
||||
public override void _Notification(int what)
|
||||
{
|
||||
if (what == NotificationApplicationFocusOut || what == NotificationWMWindowFocusOut)
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
}
|
||||
else if (what == NotificationApplicationFocusIn || what == NotificationWMWindowFocusIn)
|
||||
{
|
||||
if (IsInsideTree())
|
||||
{
|
||||
SyncMouseMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleBorderlessFullscreen()
|
||||
{
|
||||
if (DisplayServer.GetName() == "headless")
|
||||
{
|
||||
return;
|
||||
}
|
||||
var mode = DisplayServer.WindowGetMode();
|
||||
if (mode == DisplayServer.WindowMode.Fullscreen || mode == DisplayServer.WindowMode.ExclusiveFullscreen)
|
||||
{
|
||||
DisplayServer.WindowSetMode(DisplayServer.WindowMode.Windowed);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisplayServer.WindowSetMode(DisplayServer.WindowMode.Fullscreen);
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncMouseMode()
|
||||
{
|
||||
if (DisplayServer.GetName() == "headless" || _perfTargetFrames > 0)
|
||||
if (IsAutomatedRun)
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
return;
|
||||
}
|
||||
if (!IsInsideTree() || GetWindow() is not { } win || !win.HasFocus())
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
return;
|
||||
}
|
||||
if (_screenMode != ClientScreenMode.InMatch)
|
||||
|
|
@ -929,10 +987,10 @@ public partial class Main : Node3D
|
|||
|
||||
private static string? GetCliArg(string flag, bool allowBareFlag = false)
|
||||
{
|
||||
static string? SearchArgs(string[] args, string flagName, bool bare)
|
||||
static string? SearchArgs(string[] args, string flagName, bool bare, int startIndex = 0)
|
||||
{
|
||||
string prefix = flagName + "=";
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
for (int i = startIndex; i < args.Length; i++)
|
||||
{
|
||||
string a = args[i];
|
||||
if (a.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
|
||||
|
|
@ -955,7 +1013,8 @@ public partial class Main : Node3D
|
|||
}
|
||||
|
||||
return SearchArgs(OS.GetCmdlineUserArgs(), flag, allowBareFlag)
|
||||
?? SearchArgs(OS.GetCmdlineArgs(), flag, allowBareFlag);
|
||||
?? SearchArgs(OS.GetCmdlineArgs(), flag, allowBareFlag)
|
||||
?? SearchArgs(System.Environment.GetCommandLineArgs(), flag, allowBareFlag, startIndex: 1);
|
||||
}
|
||||
|
||||
private static void ParseBindAndPort(string? raw, IPAddress defaultIp, int defaultPort, out IPAddress bindIp, out int port)
|
||||
|
|
@ -1037,6 +1096,21 @@ public partial class Main : Node3D
|
|||
|
||||
public void SetScriptedInput(PlayerInput? input) => _scriptedInput = input;
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventKey key && key.Pressed && !key.Echo)
|
||||
{
|
||||
bool isAltEnter = (key.Keycode == Key.Enter || key.Keycode == Key.KpEnter)
|
||||
&& key.AltPressed && !key.CtrlPressed && !key.ShiftPressed;
|
||||
bool isF11 = key.Keycode == Key.F11 && !key.AltPressed && !key.CtrlPressed && !key.ShiftPressed;
|
||||
if (isAltEnter || isF11)
|
||||
{
|
||||
ToggleBorderlessFullscreen();
|
||||
GetViewport().SetInputAsHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventKey key && key.Pressed && !key.Echo)
|
||||
|
|
@ -1149,10 +1223,9 @@ public partial class Main : Node3D
|
|||
Input.MouseMode == Input.MouseModeEnum.Visible &&
|
||||
!_hud.GarageExpanded &&
|
||||
!_hud.NetworkPanelOpen &&
|
||||
!_hud.IsPointerOverInteractiveHud(mb.Position) &&
|
||||
DisplayServer.GetName() != "headless")
|
||||
!_hud.IsPointerOverInteractiveHud(mb.Position))
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
SyncMouseMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,13 +29,28 @@ internal static class NativeLibraries
|
|||
|
||||
if (OS.HasFeature("template"))
|
||||
{
|
||||
string exportPath = Path.Combine(
|
||||
Path.GetDirectoryName(OS.GetExecutablePath())!,
|
||||
$"data_RustToDust.Client_{Platform()}_{Arch()}",
|
||||
fileName);
|
||||
return File.Exists(exportPath) && NativeLibrary.TryLoad(exportPath, out var exportHandle)
|
||||
? exportHandle
|
||||
: IntPtr.Zero;
|
||||
string exePath = OS.GetExecutablePath();
|
||||
string exeDir = exePath.GetBaseDir();
|
||||
string exeStem = Path.GetFileNameWithoutExtension(exePath);
|
||||
string platArch = $"{Platform()}_{Arch()}";
|
||||
|
||||
string[] candidates =
|
||||
{
|
||||
Path.Combine(exeDir, fileName),
|
||||
Path.Combine(exeDir, $"data_{exeStem}_{platArch}", fileName),
|
||||
Path.Combine(exeDir, $"data_RustToDust_{platArch}", fileName),
|
||||
Path.Combine(exeDir, $"data_RustToDust.Client_{platArch}", fileName),
|
||||
Path.Combine(AppContext.BaseDirectory, fileName),
|
||||
};
|
||||
|
||||
foreach (string candidate in candidates)
|
||||
{
|
||||
if (File.Exists(candidate) && NativeLibrary.TryLoad(candidate, out var exportHandle))
|
||||
{
|
||||
return exportHandle;
|
||||
}
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
string debugPath = Path.Combine(ProjectSettings.GlobalizePath("res://.godot/mono/temp/bin/Debug"), fileName);
|
||||
|
|
|
|||
|
|
@ -58,9 +58,7 @@ public partial class PomDecalPool : Node3D
|
|||
Shader shader = GD.Load<Shader>("res://decal_pom.gdshader")
|
||||
?? throw new InvalidOperationException("Failed to load res://decal_pom.gdshader");
|
||||
|
||||
string vehiclesDir = VehicleCatalogLoader.LocateVehiclesDirectory();
|
||||
string assetsDir = Directory.GetParent(vehiclesDir)?.FullName
|
||||
?? throw new DirectoryNotFoundException("Could not locate assets directory.");
|
||||
string assetsDir = ClientAssets.LocateAssetsDirectory();
|
||||
string decalsDir = Path.Combine(assetsDir, "decals");
|
||||
|
||||
_albedoTex = LoadTextureWithMips(Path.Combine(decalsDir, "decal_atlas_albedo.png"));
|
||||
|
|
|
|||
|
|
@ -56,9 +56,7 @@ public sealed class ProceduralAudioBank
|
|||
|
||||
public static string LocateHavenAudioDirectory()
|
||||
{
|
||||
string vehiclesDir = VehicleCatalogLoader.LocateVehiclesDirectory();
|
||||
string assetsDir = Directory.GetParent(vehiclesDir)?.FullName
|
||||
?? throw new DirectoryNotFoundException("Could not locate assets directory.");
|
||||
string assetsDir = ClientAssets.LocateAssetsDirectory();
|
||||
string havenDir = Path.Combine(assetsDir, "audio", "haven");
|
||||
if (!Directory.Exists(havenDir))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -132,9 +132,9 @@ public sealed class VehicleAssetCache : IDisposable
|
|||
|
||||
public VehicleAssetCache()
|
||||
{
|
||||
ClientAssets.EnsureAssetsRootRegistered();
|
||||
_vehiclesDir = VehicleCatalogLoader.LocateVehiclesDirectory();
|
||||
string assetsDir = Directory.GetParent(_vehiclesDir)?.FullName
|
||||
?? throw new DirectoryNotFoundException($"Could not locate assets parent directory of '{_vehiclesDir}'.");
|
||||
string assetsDir = ClientAssets.LocateAssetsDirectory();
|
||||
_gearDir = Path.Combine(assetsDir, "gear");
|
||||
if (!Directory.Exists(_gearDir))
|
||||
{
|
||||
|
|
|
|||
48
client/export_presets.cfg
Normal file
48
client/export_presets.cfg
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
[preset.0]
|
||||
|
||||
name="Windows Desktop"
|
||||
platform="Windows Desktop"
|
||||
runnable=true
|
||||
advanced_options=false
|
||||
dedicated_server=false
|
||||
custom_features=""
|
||||
export_filter="all_resources"
|
||||
include_filter=""
|
||||
exclude_filter="tests/*,*.uid"
|
||||
export_path=""
|
||||
patches=PackedStringArray()
|
||||
encryption_include_filters=""
|
||||
encryption_exclude_filters=""
|
||||
seed=0
|
||||
encrypt_pck=false
|
||||
encrypt_directory=false
|
||||
script_export_mode=2
|
||||
|
||||
[preset.0.options]
|
||||
|
||||
custom_template/debug=""
|
||||
custom_template/release=""
|
||||
debug/export_console_wrapper=1
|
||||
binary_format/embed_pck=false
|
||||
texture_format/s3tc_bptc=true
|
||||
texture_format/etc2_astc=false
|
||||
shader_baker/enabled=false
|
||||
binary_format/architecture="x86_64"
|
||||
codesign/enable=false
|
||||
application/modify_resources=true
|
||||
application/icon=""
|
||||
application/console_wrapper_icon=""
|
||||
application/icon_interpolation=4
|
||||
application/file_version=""
|
||||
application/product_version=""
|
||||
application/company_name="GameCult"
|
||||
application/product_name="Rust to Dust"
|
||||
application/file_description="Rust to Dust"
|
||||
application/copyright=""
|
||||
application/trademarks=""
|
||||
application/export_angle=0
|
||||
application/export_d3d12=0
|
||||
application/d3d12_agility_sdk_multiarch=true
|
||||
ssh_remote_deploy/enabled=false
|
||||
dotnet/include_scripts_content=false
|
||||
dotnet/include_debug_symbols=false
|
||||
99
src/RustToDust.Core/AssetPathResolver.cs
Normal file
99
src/RustToDust.Core/AssetPathResolver.cs
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace RustToDust.Core
|
||||
{
|
||||
public static class AssetPathResolver
|
||||
{
|
||||
private static readonly object Gate = new();
|
||||
private static string? _explicitAssetsRoot;
|
||||
|
||||
/// <summary>
|
||||
/// Registers an explicit assets root directory (for example,
|
||||
/// <c>Path.Combine(OS.GetExecutablePath().GetBaseDir(), "assets")</c> in exported Godot builds).
|
||||
/// Checked after <c>RTD_ASSETS_DIR</c> and before ancestor probing.
|
||||
/// </summary>
|
||||
public static void RegisterAssetsRoot(string? assetsDirectory)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(assetsDirectory))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (Gate)
|
||||
{
|
||||
_explicitAssetsRoot = Path.GetFullPath(assetsDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
public static string LocateSubdirectory(
|
||||
string relativeSubpath,
|
||||
Func<string, bool> validator,
|
||||
string missingDescription)
|
||||
{
|
||||
string? envRoot = Environment.GetEnvironmentVariable("RTD_ASSETS_DIR");
|
||||
if (!string.IsNullOrWhiteSpace(envRoot))
|
||||
{
|
||||
string envCandidate = Path.Combine(envRoot, relativeSubpath);
|
||||
if (validator(envCandidate))
|
||||
{
|
||||
return Path.GetFullPath(envCandidate);
|
||||
}
|
||||
}
|
||||
|
||||
string? registeredRoot;
|
||||
lock (Gate)
|
||||
{
|
||||
registeredRoot = _explicitAssetsRoot;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(registeredRoot))
|
||||
{
|
||||
string regCandidate = Path.Combine(registeredRoot, relativeSubpath);
|
||||
if (validator(regCandidate))
|
||||
{
|
||||
return Path.GetFullPath(regCandidate);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string start in GetProbeStartDirectories())
|
||||
{
|
||||
var dir = new DirectoryInfo(Path.GetFullPath(start));
|
||||
while (dir is not null)
|
||||
{
|
||||
string candidate = Path.Combine(dir.FullName, "assets", relativeSubpath);
|
||||
if (validator(candidate))
|
||||
{
|
||||
return Path.GetFullPath(candidate);
|
||||
}
|
||||
dir = dir.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
throw new DirectoryNotFoundException(
|
||||
$"Could not locate 'assets/{relativeSubpath.Replace('\\', '/')}' {missingDescription} from BaseDirectory '{AppContext.BaseDirectory}' or CurrentDirectory '{Directory.GetCurrentDirectory()}'.");
|
||||
}
|
||||
|
||||
public static string LocateAssetsRoot()
|
||||
{
|
||||
string vehiclesDir = VehicleCatalogLoader.LocateVehiclesDirectory();
|
||||
return Directory.GetParent(vehiclesDir)?.FullName
|
||||
?? throw new DirectoryNotFoundException($"Could not locate assets parent directory of '{vehiclesDir}'.");
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetProbeStartDirectories()
|
||||
{
|
||||
string? processDir = !string.IsNullOrWhiteSpace(Environment.ProcessPath)
|
||||
? Path.GetDirectoryName(Environment.ProcessPath)
|
||||
: null;
|
||||
|
||||
foreach (string? start in new[] { AppContext.BaseDirectory, processDir, Directory.GetCurrentDirectory() })
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(start) && Directory.Exists(start))
|
||||
{
|
||||
yield return start;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -320,40 +320,11 @@ namespace RustToDust.Core
|
|||
private static readonly object CacheLock = new();
|
||||
private static readonly Dictionary<string, SionMapData> Cache = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public static string LocateSionDirectory()
|
||||
{
|
||||
string? envRoot = Environment.GetEnvironmentVariable("RTD_ASSETS_DIR");
|
||||
if (!string.IsNullOrWhiteSpace(envRoot))
|
||||
{
|
||||
string envSion = Path.Combine(envRoot, "maps", "sion");
|
||||
if (IsValidSionDirectory(envSion))
|
||||
{
|
||||
return Path.GetFullPath(envSion);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string start in new[] { AppContext.BaseDirectory, Directory.GetCurrentDirectory() })
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(start) || !Directory.Exists(start))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var dir = new DirectoryInfo(Path.GetFullPath(start));
|
||||
while (dir is not null)
|
||||
{
|
||||
string candidate = Path.Combine(dir.FullName, "assets", "maps", "sion");
|
||||
if (IsValidSionDirectory(candidate))
|
||||
{
|
||||
return Path.GetFullPath(candidate);
|
||||
}
|
||||
dir = dir.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
throw new DirectoryNotFoundException(
|
||||
$"Could not locate 'assets/maps/sion' containing metadata.json and heightmap.f32 from BaseDirectory '{AppContext.BaseDirectory}' or CurrentDirectory '{Directory.GetCurrentDirectory()}'.");
|
||||
}
|
||||
public static string LocateSionDirectory() =>
|
||||
AssetPathResolver.LocateSubdirectory(
|
||||
Path.Combine("maps", "sion"),
|
||||
IsValidSionDirectory,
|
||||
"containing metadata.json and heightmap.f32");
|
||||
|
||||
private static bool IsValidSionDirectory(string dir) =>
|
||||
Directory.Exists(dir) &&
|
||||
|
|
|
|||
|
|
@ -7,40 +7,11 @@ namespace RustToDust.Core
|
|||
{
|
||||
public static class VehicleCatalogLoader
|
||||
{
|
||||
public static string LocateVehiclesDirectory()
|
||||
{
|
||||
string? envRoot = Environment.GetEnvironmentVariable("RTD_ASSETS_DIR");
|
||||
if (!string.IsNullOrWhiteSpace(envRoot))
|
||||
{
|
||||
string envVehicles = Path.Combine(envRoot, "vehicles");
|
||||
if (HasVehiclePackages(envVehicles))
|
||||
{
|
||||
return Path.GetFullPath(envVehicles);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string start in new[] { AppContext.BaseDirectory, Directory.GetCurrentDirectory() })
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(start) || !Directory.Exists(start))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var dir = new DirectoryInfo(Path.GetFullPath(start));
|
||||
while (dir is not null)
|
||||
{
|
||||
string candidate = Path.Combine(dir.FullName, "assets", "vehicles");
|
||||
if (HasVehiclePackages(candidate))
|
||||
{
|
||||
return candidate;
|
||||
}
|
||||
dir = dir.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
throw new DirectoryNotFoundException(
|
||||
$"Could not locate 'assets/vehicles' containing vehicle.cc packages from BaseDirectory '{AppContext.BaseDirectory}' or CurrentDirectory '{Directory.GetCurrentDirectory()}'.");
|
||||
}
|
||||
public static string LocateVehiclesDirectory() =>
|
||||
AssetPathResolver.LocateSubdirectory(
|
||||
"vehicles",
|
||||
HasVehiclePackages,
|
||||
"containing vehicle.cc packages");
|
||||
|
||||
private static bool HasVehiclePackages(string vehiclesDir)
|
||||
{
|
||||
|
|
|
|||
417
tools/build_release.ps1
Normal file
417
tools/build_release.ps1
Normal file
|
|
@ -0,0 +1,417 @@
|
|||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$OutDir = "dist",
|
||||
[string]$Tag = "",
|
||||
[switch]$Publish,
|
||||
[string]$ForgeUrl = "https://eureka.gamecult.org/forge",
|
||||
[string]$Repo = "GameCult/RustToDust",
|
||||
[string]$Token = "",
|
||||
[string]$GodotExe = "",
|
||||
[string]$YmirRoot = "",
|
||||
[string]$CultLibRoot = ""
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
try {
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
||||
}
|
||||
catch {
|
||||
# Ignore on runtimes where SecurityProtocol is managed by OS
|
||||
}
|
||||
|
||||
$ExpectedYmirDllBytes = 776192L
|
||||
|
||||
function Resolve-RepoPath {
|
||||
param([string]$PathValue, [string]$BaseDir)
|
||||
if ([System.IO.Path]::IsPathRooted($PathValue)) {
|
||||
return [System.IO.Path]::GetFullPath($PathValue)
|
||||
}
|
||||
return [System.IO.Path]::GetFullPath((Join-Path $BaseDir $PathValue))
|
||||
}
|
||||
|
||||
function Resolve-DependencyRoot {
|
||||
param(
|
||||
[string]$Explicit,
|
||||
[string]$EnvName,
|
||||
[string]$SiblingName,
|
||||
[string]$FallbackPath,
|
||||
[string]$RepoRoot
|
||||
)
|
||||
if (-not [string]::IsNullOrWhiteSpace($Explicit) -and (Test-Path $Explicit)) {
|
||||
return (Resolve-Path $Explicit).Path
|
||||
}
|
||||
$envVal = [Environment]::GetEnvironmentVariable($EnvName)
|
||||
if (-not [string]::IsNullOrWhiteSpace($envVal) -and (Test-Path $envVal)) {
|
||||
return (Resolve-Path $envVal).Path
|
||||
}
|
||||
$sibling = Join-Path (Split-Path $RepoRoot -Parent) $SiblingName
|
||||
if (Test-Path $sibling) {
|
||||
return (Resolve-Path $sibling).Path
|
||||
}
|
||||
if (Test-Path $FallbackPath) {
|
||||
return (Resolve-Path $FallbackPath).Path
|
||||
}
|
||||
throw "Could not locate $SiblingName root. Set -$($SiblingName)Root or `$env:$EnvName."
|
||||
}
|
||||
|
||||
function Resolve-GodotConsoleExe {
|
||||
param([string]$Explicit)
|
||||
if (-not [string]::IsNullOrWhiteSpace($Explicit)) {
|
||||
if (-not (Test-Path $Explicit)) {
|
||||
throw "Godot console executable not found at '$Explicit'."
|
||||
}
|
||||
return (Resolve-Path $Explicit).Path
|
||||
}
|
||||
$candidates = @(
|
||||
$env:GODOT_CONSOLE_EXE,
|
||||
"F:\Applications\Godot_v4.7.2-stable_mono_win64\Godot_v4.7.2-stable_mono_win64_console.exe",
|
||||
"C:\Program Files\Godot\Godot_v4.7.2-stable_mono_win64_console.exe"
|
||||
)
|
||||
foreach ($c in $candidates) {
|
||||
if (-not [string]::IsNullOrWhiteSpace($c) -and (Test-Path $c)) {
|
||||
return (Resolve-Path $c).Path
|
||||
}
|
||||
}
|
||||
$cmd = Get-Command "Godot_v4.7.2-stable_mono_win64_console.exe" -ErrorAction SilentlyContinue
|
||||
if ($cmd) {
|
||||
return $cmd.Source
|
||||
}
|
||||
throw "Could not locate Godot_v4.7.2-stable_mono_win64_console.exe. Pass -GodotExe or set GODOT_CONSOLE_EXE."
|
||||
}
|
||||
|
||||
function Resolve-ForgejoToken {
|
||||
param([string]$Explicit, [string]$ForgeBaseUrl)
|
||||
if (-not [string]::IsNullOrWhiteSpace($Explicit)) {
|
||||
return $Explicit.Trim()
|
||||
}
|
||||
if (-not [string]::IsNullOrWhiteSpace($env:FORGEJO_TOKEN)) {
|
||||
return $env:FORGEJO_TOKEN.Trim()
|
||||
}
|
||||
|
||||
$eurekaTokenPath = Join-Path $env:USERPROFILE ".config\forgejo\eureka-pr-token"
|
||||
if (Test-Path $eurekaTokenPath) {
|
||||
$tok = (Get-Content $eurekaTokenPath -Raw).Trim()
|
||||
if (-not [string]::IsNullOrWhiteSpace($tok)) {
|
||||
return $tok
|
||||
}
|
||||
}
|
||||
|
||||
$teaPaths = @(
|
||||
(Join-Path $env:USERPROFILE ".config\tea\config.yml"),
|
||||
(Join-Path $env:APPDATA "tea\config.yml")
|
||||
)
|
||||
$forgeHost = ([Uri]$ForgeBaseUrl).Host
|
||||
foreach ($teaPath in $teaPaths) {
|
||||
if (Test-Path $teaPath) {
|
||||
$blockUrl = ""
|
||||
$blockToken = ""
|
||||
foreach ($line in (Get-Content $teaPath)) {
|
||||
if ($line -match "^\s*-\s+") {
|
||||
if ($blockUrl -match [regex]::Escape($forgeHost) -and -not [string]::IsNullOrWhiteSpace($blockToken)) {
|
||||
return $blockToken
|
||||
}
|
||||
$blockUrl = ""
|
||||
$blockToken = ""
|
||||
}
|
||||
if ($line -match "url:\s*(.+)") {
|
||||
$blockUrl = $Matches[1].Trim().Trim('"').Trim("'")
|
||||
}
|
||||
elseif ($line -match "token:\s*(.+)") {
|
||||
$blockToken = $Matches[1].Trim().Trim('"').Trim("'")
|
||||
}
|
||||
}
|
||||
if ($blockUrl -match [regex]::Escape($forgeHost) -and -not [string]::IsNullOrWhiteSpace($blockToken)) {
|
||||
return $blockToken
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$gitCredPath = Join-Path $env:USERPROFILE ".git-credentials"
|
||||
if (Test-Path $gitCredPath) {
|
||||
foreach ($line in Get-Content $gitCredPath) {
|
||||
if ($line -match "^https?://[^:]+:([^@]+)@$([regex]::Escape($forgeHost))") {
|
||||
return [Uri]::UnescapeDataString($Matches[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw "Forgejo token not found. Pass -Token, set `$env:FORGEJO_TOKEN, or store a token in ~/.config/forgejo/eureka-pr-token or ~/.config/tea/config.yml."
|
||||
}
|
||||
|
||||
function Copy-FilteredTree {
|
||||
param(
|
||||
[string]$SourceDir,
|
||||
[string]$DestDir,
|
||||
[string[]]$IncludeExtensions
|
||||
)
|
||||
if (-not (Test-Path $SourceDir)) {
|
||||
throw "Required asset source directory missing: '$SourceDir'"
|
||||
}
|
||||
$srcFull = (Resolve-Path $SourceDir).Path.TrimEnd('\', '/')
|
||||
New-Item -ItemType Directory -Force -Path $DestDir | Out-Null
|
||||
$files = Get-ChildItem -Path $srcFull -Recurse -File
|
||||
$count = 0
|
||||
foreach ($file in $files) {
|
||||
if ($IncludeExtensions -notcontains $file.Extension.ToLowerInvariant()) {
|
||||
continue
|
||||
}
|
||||
$rel = $file.FullName.Substring($srcFull.Length + 1)
|
||||
$target = Join-Path $DestDir $rel
|
||||
$targetParent = Split-Path $target -Parent
|
||||
if (-not (Test-Path $targetParent)) {
|
||||
New-Item -ItemType Directory -Force -Path $targetParent | Out-Null
|
||||
}
|
||||
Copy-Item -Path $file.FullName -Destination $target -Force
|
||||
$count++
|
||||
}
|
||||
return $count
|
||||
}
|
||||
|
||||
function Invoke-ForgeApiJson {
|
||||
param(
|
||||
[string]$Method,
|
||||
[string]$Url,
|
||||
[string]$Token,
|
||||
[object]$Body = $null
|
||||
)
|
||||
$headers = @{
|
||||
"Authorization" = "token $Token"
|
||||
"Accept" = "application/json"
|
||||
}
|
||||
$params = @{
|
||||
Method = $Method
|
||||
Uri = $Url
|
||||
Headers = $headers
|
||||
ErrorAction = "Stop"
|
||||
}
|
||||
if ($null -ne $Body) {
|
||||
$params["ContentType"] = "application/json"
|
||||
$params["Body"] = ($Body | ConvertTo-Json -Depth 6)
|
||||
}
|
||||
return Invoke-RestMethod @params
|
||||
}
|
||||
|
||||
$RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
||||
$ClientDir = Join-Path $RepoRoot "client"
|
||||
$AssetsSrcDir = Join-Path $RepoRoot "assets"
|
||||
|
||||
$fullSha = (& git -C $RepoRoot rev-parse HEAD).Trim()
|
||||
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($fullSha)) {
|
||||
throw "Failed to resolve git HEAD SHA."
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Tag)) {
|
||||
$shortSha = (& git -C $RepoRoot rev-parse --short HEAD).Trim()
|
||||
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($shortSha)) {
|
||||
throw "Failed to resolve git short SHA for default tag."
|
||||
}
|
||||
$dateStamp = (Get-Date).ToUniversalTime().ToString("yyyyMMdd")
|
||||
$Tag = "rtd-$dateStamp-$shortSha"
|
||||
}
|
||||
|
||||
$ResolvedOutDir = Resolve-RepoPath -PathValue $OutDir -BaseDir $RepoRoot
|
||||
$StageDir = Join-Path $ResolvedOutDir "stage-$Tag"
|
||||
$ZipName = "RustToDust-win64-$Tag.zip"
|
||||
$ZipPath = Join-Path $ResolvedOutDir $ZipName
|
||||
$ShaPath = Join-Path $ResolvedOutDir "SHA256SUMS.txt"
|
||||
|
||||
$YmirRoot = Resolve-DependencyRoot -Explicit $YmirRoot -EnvName "YMIR_ROOT" -SiblingName "Ymir" -FallbackPath "F:\Projects\Ymir" -RepoRoot $RepoRoot
|
||||
$CultLibRoot = Resolve-DependencyRoot -Explicit $CultLibRoot -EnvName "CULTLIB_ROOT" -SiblingName "CultLib" -FallbackPath "F:\Projects\CultLib" -RepoRoot $RepoRoot
|
||||
$GodotConsole = Resolve-GodotConsoleExe -Explicit $GodotExe
|
||||
|
||||
$TemplateDir = Join-Path $env:APPDATA "Godot\export_templates\4.7.2.stable.mono"
|
||||
if (-not (Test-Path $TemplateDir)) {
|
||||
throw "Godot 4.7.2.stable.mono export templates missing at '$TemplateDir'."
|
||||
}
|
||||
|
||||
$env:YMIR_ROOT = $YmirRoot
|
||||
$env:CULTLIB_ROOT = $CultLibRoot
|
||||
$env:MSBUILDDISABLENODEREUSE = "1"
|
||||
$env:DOTNET_CLI_DO_NOT_USE_MSBUILD_SERVER = "1"
|
||||
$env:UseSharedCompilation = "false"
|
||||
|
||||
Write-Host "=== Rust to Dust win64 Release Build ==="
|
||||
Write-Host "RepoRoot : $RepoRoot"
|
||||
Write-Host "Tag : $Tag"
|
||||
Write-Host "YmirRoot : $YmirRoot"
|
||||
Write-Host "CultLibRoot: $CultLibRoot"
|
||||
Write-Host "Godot : $GodotConsole"
|
||||
Write-Host "OutDir : $ResolvedOutDir"
|
||||
|
||||
# Step 1: Build Release ymir_box3d.dll and verify exact Release binary size
|
||||
Write-Host "`n[1/5] Building Release ymir_box3d.dll..."
|
||||
$ymirProj = Join-Path $YmirRoot "src\Ymir.Box3D\Ymir.Box3D.csproj"
|
||||
& dotnet build $ymirProj -c Release -p:YmirNativeConfiguration=Release --disable-build-servers -p:UseSharedCompilation=false -nr:false
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "dotnet build Ymir.Box3D failed with exit code $LASTEXITCODE."
|
||||
}
|
||||
|
||||
$ymirDllPath = Join-Path $YmirRoot "artifacts\box3d-native\production\Release\bin\Release\ymir_box3d.dll"
|
||||
if (-not (Test-Path $ymirDllPath)) {
|
||||
throw "Release ymir_box3d.dll not found at '$ymirDllPath'."
|
||||
}
|
||||
$ymirDllLen = (Get-Item $ymirDllPath).Length
|
||||
if ($ymirDllLen -ne $ExpectedYmirDllBytes) {
|
||||
throw "ymir_box3d.dll size mismatch: expected $ExpectedYmirDllBytes bytes (Release), got $ymirDllLen bytes at '$ymirDllPath'."
|
||||
}
|
||||
Write-Host "Verified Release ymir_box3d.dll ($ymirDllLen B)."
|
||||
|
||||
# Step 2: Export Windows Desktop Release via Godot
|
||||
Write-Host "`n[2/5] Exporting Windows Desktop Release..."
|
||||
if (Test-Path $StageDir) {
|
||||
Remove-Item -Recurse -Force $StageDir
|
||||
}
|
||||
New-Item -ItemType Directory -Force -Path $StageDir | Out-Null
|
||||
|
||||
$exportExePath = Join-Path $StageDir "RustToDust.exe"
|
||||
$clientSlnPath = Join-Path $ClientDir "RustToDust.Client.sln"
|
||||
$createdTempSln = $false
|
||||
|
||||
try {
|
||||
if (-not (Test-Path $clientSlnPath)) {
|
||||
Write-Host "Creating temporary client/RustToDust.Client.sln for Godot export..."
|
||||
& dotnet new sln -n "RustToDust.Client" -o $ClientDir --format sln | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "dotnet new sln failed with exit code $LASTEXITCODE."
|
||||
}
|
||||
$createdTempSln = $true
|
||||
& dotnet sln $clientSlnPath add (Join-Path $ClientDir "RustToDust.Client.csproj") | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "dotnet sln add failed with exit code $LASTEXITCODE."
|
||||
}
|
||||
}
|
||||
|
||||
if (-not (Test-Path (Join-Path $ClientDir ".godot"))) {
|
||||
Write-Host "Bootstrapping client/.godot import cache (headless)..."
|
||||
& $GodotConsole --headless --audio-driver Dummy --path $ClientDir --import --quit
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Godot headless --import failed with exit code $LASTEXITCODE."
|
||||
}
|
||||
}
|
||||
|
||||
& $GodotConsole --headless --audio-driver Dummy --path $ClientDir --quit --export-release "Windows Desktop" $exportExePath
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Godot --export-release failed with exit code $LASTEXITCODE."
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if ($createdTempSln -and (Test-Path $clientSlnPath)) {
|
||||
Remove-Item -Force $clientSlnPath -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
if (-not (Test-Path $exportExePath)) {
|
||||
throw "Expected exported executable missing: '$exportExePath'."
|
||||
}
|
||||
|
||||
$dataDirCandidates = @(
|
||||
(Join-Path $StageDir "data_RustToDust_windows_x86_64"),
|
||||
(Join-Path $StageDir "data_RustToDust.Client_windows_x86_64")
|
||||
)
|
||||
$stagedDataDir = $dataDirCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
|
||||
if (-not $stagedDataDir) {
|
||||
throw "Expected Godot Mono data directory missing under '$StageDir'."
|
||||
}
|
||||
|
||||
# Remove PDBs if any slipped through
|
||||
Get-ChildItem -Path $StageDir -Recurse -Filter "*.pdb" -File | Remove-Item -Force
|
||||
|
||||
# Step 3: Stage Release ymir_box3d.dll & runtime assets/
|
||||
Write-Host "`n[3/5] Staging Release ymir_box3d.dll and runtime assets/..."
|
||||
Copy-Item -Path $ymirDllPath -Destination (Join-Path $StageDir "ymir_box3d.dll") -Force
|
||||
Copy-Item -Path $ymirDllPath -Destination (Join-Path $stagedDataDir "ymir_box3d.dll") -Force
|
||||
|
||||
$stagedAssetsDir = Join-Path $StageDir "assets"
|
||||
$vCount = Copy-FilteredTree -SourceDir (Join-Path $AssetsSrcDir "vehicles") -DestDir (Join-Path $stagedAssetsDir "vehicles") -IncludeExtensions @(".glb", ".cc", ".json")
|
||||
$gCount = Copy-FilteredTree -SourceDir (Join-Path $AssetsSrcDir "gear") -DestDir (Join-Path $stagedAssetsDir "gear") -IncludeExtensions @(".glb")
|
||||
$dCount = Copy-FilteredTree -SourceDir (Join-Path $AssetsSrcDir "decals") -DestDir (Join-Path $stagedAssetsDir "decals") -IncludeExtensions @(".png")
|
||||
$aCount = Copy-FilteredTree -SourceDir (Join-Path $AssetsSrcDir "audio") -DestDir (Join-Path $stagedAssetsDir "audio") -IncludeExtensions @(".wav", ".md")
|
||||
$mCount = Copy-FilteredTree -SourceDir (Join-Path $AssetsSrcDir "maps\sion") -DestDir (Join-Path $stagedAssetsDir "maps\sion") -IncludeExtensions @(".json", ".f32", ".png", ".bin", ".glb")
|
||||
Write-Host "Staged runtime assets: vehicles=$vCount gear=$gCount decals=$dCount audio=$aCount sion=$mCount"
|
||||
|
||||
# Step 4: Create ZIP and SHA256SUMS.txt
|
||||
Write-Host "`n[4/5] Packaging $ZipName..."
|
||||
New-Item -ItemType Directory -Force -Path $ResolvedOutDir | Out-Null
|
||||
if (Test-Path $ZipPath) {
|
||||
Remove-Item -Force $ZipPath
|
||||
}
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
[System.IO.Compression.ZipFile]::CreateFromDirectory($StageDir, $ZipPath, [System.IO.Compression.CompressionLevel]::Optimal, $false)
|
||||
|
||||
$zipInfo = Get-Item $ZipPath
|
||||
$zipHash = (Get-FileHash -Path $ZipPath -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
"$zipHash $ZipName" | Set-Content -Path $ShaPath -Encoding ASCII
|
||||
Write-Host "Created $ZipPath ($($zipInfo.Length) B, sha256=$zipHash)"
|
||||
|
||||
# Remove intermediate stage directory so dist/ holds clean release outputs
|
||||
Remove-Item -Recurse -Force $StageDir
|
||||
|
||||
# Step 5: Optional Forgejo Release publish
|
||||
if ($Publish) {
|
||||
Write-Host "`n[5/5] Publishing release '$Tag' to $ForgeUrl ($Repo)..."
|
||||
$resolvedToken = Resolve-ForgejoToken -Explicit $Token -ForgeBaseUrl $ForgeUrl
|
||||
$apiBase = "$($ForgeUrl.TrimEnd('/'))/api/v1/repos/$Repo"
|
||||
|
||||
$release = $null
|
||||
try {
|
||||
$release = Invoke-ForgeApiJson -Method "GET" -Url "$apiBase/releases/tags/$Tag" -Token $resolvedToken
|
||||
Write-Host "Found existing release id=$($release.id) for tag '$Tag'."
|
||||
}
|
||||
catch {
|
||||
$statusCode = $null
|
||||
$ex = $_.Exception
|
||||
if ($ex -is [System.Net.WebException] -and $ex.Response) {
|
||||
$statusCode = [int]$ex.Response.StatusCode
|
||||
}
|
||||
elseif ($ex.PSObject.Properties['Response'] -and $ex.Response -and $ex.Response.PSObject.Properties['StatusCode']) {
|
||||
$statusCode = [int]$ex.Response.StatusCode
|
||||
}
|
||||
if ($statusCode -ne 404) {
|
||||
throw
|
||||
}
|
||||
}
|
||||
|
||||
$releaseNotes = "Standalone Windows x64 build ($Tag). Unzip and run RustToDust.exe."
|
||||
if ($null -eq $release) {
|
||||
$release = Invoke-ForgeApiJson -Method "POST" -Url "$apiBase/releases" -Token $resolvedToken -Body @{
|
||||
tag_name = $Tag
|
||||
target_commitish = $fullSha
|
||||
name = $Tag
|
||||
body = $releaseNotes
|
||||
draft = $false
|
||||
prerelease = $false
|
||||
}
|
||||
Write-Host "Created release id=$($release.id) for tag '$Tag' ($fullSha)."
|
||||
}
|
||||
else {
|
||||
$release = Invoke-ForgeApiJson -Method "PATCH" -Url "$apiBase/releases/$($release.id)" -Token $resolvedToken -Body @{
|
||||
name = $Tag
|
||||
body = $releaseNotes
|
||||
draft = $false
|
||||
prerelease = $false
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($assetPath in @($ZipPath, $ShaPath)) {
|
||||
$assetName = [System.IO.Path]::GetFileName($assetPath)
|
||||
if ($release.assets) {
|
||||
foreach ($existing in $release.assets) {
|
||||
if ($existing.name -eq $assetName) {
|
||||
Write-Host "Removing existing release asset '$assetName' (id=$($existing.id))..."
|
||||
Invoke-ForgeApiJson -Method "DELETE" -Url "$apiBase/releases/$($release.id)/assets/$($existing.id)" -Token $resolvedToken | Out-Null
|
||||
}
|
||||
}
|
||||
}
|
||||
Write-Host "Uploading '$assetName'..."
|
||||
$uploadUrl = "$apiBase/releases/$($release.id)/assets?name=$([Uri]::EscapeDataString($assetName))"
|
||||
& curl.exe -fsS -X POST -H "Authorization: token $resolvedToken" -F "attachment=@$assetPath" $uploadUrl | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "curl.exe failed uploading '$assetName' (exit $LASTEXITCODE)."
|
||||
}
|
||||
}
|
||||
Write-Host "Published: $($ForgeUrl.TrimEnd('/'))/$Repo/releases/tag/$Tag"
|
||||
}
|
||||
else {
|
||||
Write-Host "`n[5/5] Skipping Forgejo publish (-Publish not set)."
|
||||
}
|
||||
Loading…
Reference in a new issue