Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AnimatedSwine37 committed Apr 21, 2024
2 parents f0b848f + acddeab commit b2c9dd8
Show file tree
Hide file tree
Showing 92 changed files with 3,469 additions and 112 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
2 changes: 1 addition & 1 deletion Emulator/AWB.Stream.Emulator/ModConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ModR2RManagedDll64": "x64/AWB.Stream.Emulator.dll",
"ModNativeDll32": "",
"ModNativeDll64": "",
"IsLibrary": false,
"IsLibrary": true,
"ReleaseMetadataFileName": "AWB.Stream.Emulator.ReleaseMetadata.json",
"PluginData": {
"GitHubDependencies": {
Expand Down
4 changes: 1 addition & 3 deletions Emulator/BF.File.Emulator/Bf/BfBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using FileEmulationFramework.Lib.IO;
using FileEmulationFramework.Lib.Utilities;
using FileEmulationFramework.Lib.Memory;
using FileEmulationFramework.Lib.Utilities;
using AtlusScriptLibrary.FlowScriptLanguage.Compiler;
using FlowFormatVersion = AtlusScriptLibrary.FlowScriptLanguage.FormatVersion;
using AtlusScriptLibrary.Common.Libraries;
Expand Down
1 change: 0 additions & 1 deletion Emulator/BF.File.Emulator/Bf/BfBuilderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// Aliasing for readability, since our assembly name has priority over 'File'
using Fiel = System.IO.File;
using BF.File.Emulator.Utilities;
using System.Text.Json.Serialization;
using System.Text.Json;
using AtlusScriptLibrary.Common.Text.Encodings;
using static BF.File.Emulator.Utilities.CompilerArgs;
Expand Down
8 changes: 5 additions & 3 deletions Emulator/BF.File.Emulator/BfEmulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
using System.Collections.Concurrent;
using System.Text;
using BF.File.Emulator.Bf;
using FileEmulationFramework.Lib.Memory;
using BF.File.Emulator.Utilities;
using FlowFormatVersion = AtlusScriptLibrary.FlowScriptLanguage.FormatVersion;
using static BF.File.Emulator.Mod;
using AtlusScriptLibrary.Common.Libraries;
using AtlusScriptLibrary.Common.Text.Encodings;
using AtlusScriptLibrary.Common.Logging;
using Logger = FileEmulationFramework.Lib.Utilities.Logger;
using System.Diagnostics;

namespace BF.File.Emulator;

Expand Down Expand Up @@ -143,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
12 changes: 3 additions & 9 deletions Emulator/BF.File.Emulator/BfEmulatorApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
using BF.File.Emulator.Utilities;
using FileEmulationFramework.Interfaces;
using FileEmulationFramework.Interfaces.Reference;
using FileEmulationFramework.Lib.Memory;
using FileEmulationFramework.Lib.Utilities;
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace BF.File.Emulator;
Expand Down Expand Up @@ -58,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
2 changes: 1 addition & 1 deletion Emulator/BF.File.Emulator/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Mod(ModContext context)
var fileName = Path.GetFileName(mainModule.FileName);
if (fileName.StartsWith("p5r", StringComparison.OrdinalIgnoreCase))
_game = Game.P5R;
else if (fileName.StartsWith("p4g", StringComparison.OrdinalIgnoreCase))
else if (fileName.StartsWith("p4g", StringComparison.OrdinalIgnoreCase) || fileName.StartsWith("p4pc_DT_mc", StringComparison.OrdinalIgnoreCase))
_game = Game.P4G;
else if (fileName.StartsWith("p3p", StringComparison.OrdinalIgnoreCase))
_game = Game.P3P;
Expand Down
2 changes: 1 addition & 1 deletion Emulator/BF.File.Emulator/ModConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"ModId": "reloaded.universal.fileemulationframework.bf",
"ModName": "BF Emulator for File Emulation Framework",
"ModAuthor": "AnimatedSwine37",
"ModVersion": "1.1.0",
"ModVersion": "1.1.2",
"ModDescription": "Simulates Atlus BF files. Allows mods to add or replace existing files using files on disk.",
"ModDll": "BF.File.Emulator.dll",
"ModIcon": "Preview.png",
Expand Down
6 changes: 0 additions & 6 deletions Emulator/BF.File.Emulator/Utilities/BfChecker.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using FileEmulationFramework.Lib.Utilities;
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace BF.File.Emulator.Utilities;

Expand Down
5 changes: 0 additions & 5 deletions Emulator/BF.File.Emulator/Utilities/CompilerArgs.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using AtlusScriptLibrary.FlowScriptLanguage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BF.File.Emulator.Utilities;

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>
Loading

0 comments on commit b2c9dd8

Please sign in to comment.