Skip to content

Commit

Permalink
merge Sewer56/main into main
Browse files Browse the repository at this point in the history
  • Loading branch information
oceanstuck committed Jan 19, 2024
1 parent 4412ffa commit a412902
Show file tree
Hide file tree
Showing 84 changed files with 3,462 additions and 89 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/reloaded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ env:
PUBLISH_GAMEBANANA_BF_PATH: ./Publish/ToUpload/BF/GameBanana
PUBLISH_GITHUB_BF_PATH: ./Publish/ToUpload/BF/Generic
PUBLISH_NUGET_BF_PATH: ./Publish/ToUpload/BF/NuGet

PUBLISH_GAMEBANANA_SPD_PATH: ./Publish/ToUpload/SPD/GameBanana
PUBLISH_GITHUB_SPD_PATH: ./Publish/ToUpload/SPD/Generic
PUBLISH_NUGET_SPD_PATH: ./Publish/ToUpload/SPD/NuGet

PUBLISH_GAMEBANANA_FRAMEWORK_PATH: ./Publish/ToUpload/Framework/GameBanana
PUBLISH_GITHUB_FRAMEWORK_PATH: ./Publish/ToUpload/Framework/Generic
Expand Down Expand Up @@ -119,6 +123,7 @@ jobs:
${{ env.PUBLISH_GITHUB_ARC_PATH }}/*
${{ env.PUBLISH_GITHUB_PAK_PATH }}/*
${{ env.PUBLISH_GITHUB_BF_PATH }}/*
${{ env.PUBLISH_GITHUB_SPD_PATH }}/*
${{ env.PUBLISH_GITHUB_FRAMEWORK_PATH }}/*
- name: Upload GameBanana Release Artifact
Expand All @@ -134,6 +139,7 @@ jobs:
${{ env.PUBLISH_GAMEBANANA_ARC_PATH }}/*
${{ env.PUBLISH_GAMEBANANA_PAK_PATH }}/*
${{ env.PUBLISH_GAMEBANANA_BF_PATH }}/*
${{ env.PUBLISH_GAMEBANANA_SPD_PATH }}/*
${{ env.PUBLISH_GAMEBANANA_FRAMEWORK_PATH }}/*
- name: Upload NuGet Release Artifact
Expand All @@ -149,6 +155,7 @@ jobs:
${{ env.PUBLISH_NUGET_ARC_PATH }}/*
${{ env.PUBLISH_NUGET_PAK_PATH }}/*
${{ env.PUBLISH_NUGET_BF_PATH }}/*
${{ env.PUBLISH_NUGET_SPD_PATH }}/*
${{ env.PUBLISH_NUGET_FRAMEWORK_PATH }}/*
- name: Upload Changelog Artifact
Expand All @@ -174,6 +181,7 @@ jobs:
${{ env.PUBLISH_GITHUB_ARC_PATH }}/*
${{ env.PUBLISH_GITHUB_PAK_PATH }}/*
${{ env.PUBLISH_GITHUB_BF_PATH }}/*
${{ env.PUBLISH_GITHUB_SPD_PATH }}/*
${{ env.PUBLISH_GITHUB_FRAMEWORK_PATH }}/*
- name: Push to NuGet (on Tag)
Expand Down
1 change: 0 additions & 1 deletion .idea/.idea.FileEmulationFramework/.idea/.name

This file was deleted.

4 changes: 2 additions & 2 deletions Emulator/AFS.Stream.Emulator/AFS.Stream.Emulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AFSLib" Version="1.1.0" />
<PackageReference Include="Reloaded.Memory" Version="8.0.1" />
<PackageReference Include="AFSLib" Version="1.1.1" />
<PackageReference Include="Reloaded.Memory" Version="9.3.2" />
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.3.0" ExcludeAssets="runtime" />
</ItemGroup>

Expand Down
5 changes: 3 additions & 2 deletions Emulator/AFS.Stream.Emulator/Afs/AfsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using FileEmulationFramework.Lib.IO.Struct;
using FileEmulationFramework.Lib.Utilities;
using Microsoft.Win32.SafeHandles;
using Reloaded.Memory.Extensions;
using Reloaded.Memory.Streams;

// Aliasing for readability, since our assembly name has priority over 'stream'
Expand Down Expand Up @@ -75,8 +76,8 @@ public unsafe MultiStream Build(IntPtr handle, string filepath, Logger? logger =
headerStream.SetLength(headerLength);

// Write header magic and file count
headerStream.Write<int>(0x00534641); // 'AFS '
headerStream.Write<int>(numFiles);
headerStream.Write(0x00534641); // 'AFS '
headerStream.Write(numFiles);

// Make MultiStream
var pairs = new List<StreamOffsetPair<Strim>>()
Expand Down
2 changes: 1 addition & 1 deletion Emulator/ARC.Stream.Emulator/ARC.Stream.Emulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Memory" Version="8.0.1" />
<PackageReference Include="Reloaded.Memory" Version="9.3.2" />
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.3.0" ExcludeAssets="runtime" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions Emulator/ARC.Stream.Emulator/Arc/ArcBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using FileEmulationFramework.Lib.IO.Struct;
using FileEmulationFramework.Lib.Utilities;
using Microsoft.Win32.SafeHandles;
using Reloaded.Memory.Extensions;
using Reloaded.Memory.Streams;

// Aliasing for readability, since our assembly name has priority over 'stream'
Expand Down Expand Up @@ -42,7 +43,7 @@ public unsafe MultiStream Build(IntPtr handle, string filepath, Logger? logger =
MemoryStream headerStream = new MemoryStream(headerLength);

// Write header magic and file count
headerStream.Write( 0x4C435241 ); // 'ARCL'
headerStream.Write(0x4C435241); // 'ARCL'
headerStream.Write(numFiles);

// Make MultiStream
Expand Down Expand Up @@ -70,7 +71,6 @@ public unsafe MultiStream Build(IntPtr handle, string filepath, Logger? logger =
}
else if (x < entries.Length)
{

length = (int)entries[x].Length;

var originalEntry = new FileSlice(entries[x].Offset, length, filepath);
Expand Down
2 changes: 1 addition & 1 deletion Emulator/AWB.Stream.Emulator/AWB.Stream.Emulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Memory" Version="8.0.1" />
<PackageReference Include="Reloaded.Memory" Version="9.3.2" />
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.3.0" ExcludeAssets="runtime" />
<PackageReference Include="Reloaded.Memory.SigScan.ReloadedII.Interfaces" Version="1.2.0" />
</ItemGroup>
Expand Down
17 changes: 9 additions & 8 deletions Emulator/AWB.Stream.Emulator/Awb/AwbBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using FileEmulationFramework.Lib.IO.Struct;
using FileEmulationFramework.Lib.Utilities;
using Microsoft.Win32.SafeHandles;
using Reloaded.Memory.Extensions;
using Reloaded.Memory.Streams;

// Aliasing for readability, since our assembly name has priority over 'stream'
Expand Down Expand Up @@ -73,14 +74,14 @@ public MultiStream Build(IntPtr handle, string filepath, Logger? logger = null)
headerStream.SetLength(headerLength);

// Write header magic and file count
headerStream.Write<int>(Afs2Header.ExpectedMagic); // 'AFS2'
headerStream.Write<byte>((byte)(subKey != 0 ? 2 : 1)); // 'Type'
headerStream.Write<byte>(posFieldSize); // 'PosLength'
headerStream.Write<byte>(idFieldSize); // 'IdLength'
headerStream.Write<byte>(0); // 'Pad'
headerStream.Write<int>(numFiles); // 'Entry Count'
headerStream.Write<short>(AwbAlignment); // 'Alignment'
headerStream.Write<short>(subKey); // 'Encryption Key'
headerStream.Write(Afs2Header.ExpectedMagic); // 'AFS2'
headerStream.Write((byte)(subKey != 0 ? 2 : 1)); // 'Type'
headerStream.Write(posFieldSize); // 'PosLength'
headerStream.Write(idFieldSize); // 'IdLength'
headerStream.Write((byte)0); // 'Pad'
headerStream.Write(numFiles); // 'Entry Count'
headerStream.Write((short)AwbAlignment); // 'Alignment'
headerStream.Write((short)subKey); // 'Encryption Key'

// Make MultiStream
var pairs = new List<StreamOffsetPair<Strim>>()
Expand Down
11 changes: 6 additions & 5 deletions Emulator/AWB.Stream.Emulator/Awb/Utilities/ValueWriters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Reloaded.Memory.Streams;
using Reloaded.Memory.Extensions;
using Reloaded.Memory.Streams;
// ReSharper disable RedundantTypeArgumentsOfMethod

namespace AWB.Stream.Emulator.Awb.Utilities;
Expand All @@ -19,16 +20,16 @@ public static void WriteNumber(this MemoryStream stream, long value, int size)
switch (size)
{
case 1:
stream.Write<byte>((byte)value);
stream.Write((byte)value);
break;
case 2:
stream.Write<short>((short)value);
stream.Write((short)value);
break;
case 4:
stream.Write<int>((int)value);
stream.Write((int)value);
break;
case 8:
stream.Write<long>(value);
stream.Write(value);
break;
default:
ThrowHelpers.ThrowBadFieldSizeException();
Expand Down
6 changes: 5 additions & 1 deletion Emulator/BF.File.Emulator/BfEmulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ public void OnModLoading(string modFolder)
/// Invalidates a BF file with a specified name.
/// </summary>
/// <param name="bfPath">Full path to the file.</param>
public void UnregisterFile(string bfPath) => _pathToStream!.Remove(bfPath, out _);
public void UnregisterFile(string bfPath)
{
_pathToStream!.Remove(bfPath, out var stream);
stream?.Dispose();
}

public void RegisterFile(string destinationPath, Stream stream)
{
Expand Down
10 changes: 3 additions & 7 deletions Emulator/BF.File.Emulator/BfEmulatorApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@ public void RegisterBf(string sourcePath, string destinationPath)
}

Native.SetFilePointerEx(handle, 0, IntPtr.Zero, 0);

var fileStream = new FileStream(new SafeFileHandle(handle, false), FileAccess.Read);
var stream = StreamUtils.CreateMemoryStream(fileStream.Length);
fileStream.CopyTo(stream);

var emulated = new EmulatedFile<Stream>(stream);
_bfEmulator.RegisterFile(destinationPath, stream);
var fileStream = new FileStream(new SafeFileHandle(handle, true), FileAccess.Read);
var emulated = new EmulatedFile<FileStream>(fileStream);
_bfEmulator.RegisterFile(destinationPath, fileStream);
_framework.RegisterVirtualFile(destinationPath, emulated, false);

_logger.Info("[BfEmulatorApi] Registered bf {0} at {1}", sourcePath, destinationPath);
Expand Down
57 changes: 57 additions & 0 deletions Emulator/Interfaces/SPD.File.Emulator.Interfaces/ISpdEmulator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using SPD.File.Emulator.Interfaces.Structures.IO;

namespace SPD.File.Emulator.Interfaces;

/// <summary>
/// APIs exposed by Spd Emulator.
/// </summary>
public interface ISpdEmulator
{
/// <summary>
/// Tries to create an emulated SPD file using an SPD file embedded inside another file as source.
/// </summary>
/// <param name="sourcePath">Path to the file from which the data will be sourced.</param>
/// <param name="offset">Offset in the file where the SPD starts.</param>
/// <param name="route">The route of the emulated file.</param>
/// <param name="destinationPath">Path to where the emulated file should be put.</param>
public bool TryCreateFromFileSlice(string sourcePath, long offset, string route, string destinationPath);

/// <summary>
/// Tries to create an emulated SPD file by merging any applicable sprite or texture files, using the input as the base
/// </summary>
/// <param name="sourcePath">Path to the SPD file to use as a base.</param>
/// <param name="route">The route of the emulated SPD file.</param>
/// <param name="destinationPath">Path to where the emulated SPD file should be put.</param>
public bool TryCreateFromSpd(string sourcePath, string route, string destinationPath);

/// <summary>
/// Invalidates a file, i.e. unregisters it, will be recreated on next access.
/// </summary>
/// <param name="SPDPath">Path of the SPD file.</param>
public void InvalidateFile(string SPDPath);

/// <summary>
/// Gets the list of input files from other mods fed into the emulator.
/// </summary>
public RouteGroupTuple[] GetEmulatorInput();

/// <summary>
/// Registers an already merged SPD as an emulated one
/// </summary>
/// <param name="sourcePath">The path to the SPD file to register</param>
/// <param name="destinationPath">The path where the emulated SPD file should be put</param>
public void RegisterSpd(string sourcePath, string destinationPath);

/// <summary>
/// Adds a new file to be injected into emulated SPDs
/// </summary>
/// <param name="file">The path to the file to add</param>
/// <param name="route">The route the file is in</param>
public void AddFile(string file, string route);

/// <summary>
/// Adds a directory to SPD Emulator so it's like the files were in FEmulator\SPD
/// </summary>
/// <param name="dir">The directory to add the files from</param>
public void AddDirectory(string dir);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace SPD.File.Emulator.Interfaces.Structures.IO;


/// <summary>
/// Represents information tied to an individual directory.
/// </summary>
public struct DirectoryInformation
{
/// <summary>
/// Full path to the directory.
/// </summary>
public string FullPath;

/// <summary>
/// Last time this directory was modified.
/// </summary>
public DateTime LastWriteTime;
}

/// <summary>
/// Groups a single directory and a list of files associated with it.
/// </summary>
public class DirectoryFilesGroup
{
/// <summary>
/// The directory in question.
/// </summary>
public DirectoryInformation Directory;

/// <summary>
/// The relative file paths tied to this directory.
/// </summary>
public string[] Files = Array.Empty<string>();
}

/// <summary>
/// A tuple representing a group and a route.
/// </summary>
public struct RouteGroupTuple
{
/// <summary>
/// Route associated with this tuple.
/// </summary>
public string Route;

/// <summary>
/// Files bound by this route.
/// </summary>
public DirectoryFilesGroup Files;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Memory" Version="8.0.1" />
<PackageReference Include="Reloaded.Memory" Version="9.3.2" />
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.3.0" ExcludeAssets="runtime" />
<PackageReference Include="Reloaded.SharedLib.CSharp.Prs.Interfaces" Version="1.0.2" />
</ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions Emulator/ONE.Heroes.Stream.Emulator/One/OneBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Heroes.SDK.Definitions.Structures.Archive.OneFile;
using Heroes.SDK.Definitions.Structures.RenderWare;
using Microsoft.Win32.SafeHandles;
using Reloaded.Memory.Extensions;
using Reloaded.Memory.Streams;

// Aliasing for readability, since our assembly name has priority over 'stream'
Expand Down Expand Up @@ -145,7 +146,7 @@ private unsafe Dictionary<string, OneBuilderItem> GetExistingFiles(IntPtr hFile,
{
var fileStream = new FileStream(new SafeFileHandle(hFile, false), FileAccess.Read);
var originalPos = fileStream.Position;
using var reader = new BufferedStreamReader(fileStream, 4096); // common cluster size on Windows
using var reader = new BufferedStreamReader<FileStream>(fileStream, 4096); // common cluster size on Windows
var result = new Dictionary<string, OneBuilderItem>();

// Read headers.
Expand All @@ -163,13 +164,13 @@ private unsafe Dictionary<string, OneBuilderItem> GetExistingFiles(IntPtr hFile,
// Note: Heroes leaves 2 blank name slots that are unused at runtime, so file count is that and 2 less.
for (int x = 0; x < fileNameCount - 2; x++)
{
var stillMoreData = reader.Position() < fileStream.Length;
var stillMoreData = reader.Position < fileStream.Length;
if (!stillMoreData)
break;

reader.Read<OneFileEntry>(out var currentEntry);
var fileName = fileNames[currentEntry.FileNameIndex].ToString();
var fileDataPos = reader.Position();
var fileDataPos = reader.Position;
var fileSize = currentEntry.FileSize;
#if DEBUG
if (fileSize == 0)
Expand Down
2 changes: 1 addition & 1 deletion Emulator/PAK.Stream.Emulator/PAK.Stream.Emulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Memory" Version="8.0.1" />
<PackageReference Include="Reloaded.Memory" Version="9.3.2" />
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.3.0" ExcludeAssets="runtime" />
<PackageReference Include="Reloaded.Memory.SigScan.ReloadedII.Interfaces" Version="1.2.0" />
</ItemGroup>
Expand Down
Loading

0 comments on commit a412902

Please sign in to comment.