Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AnimatedSwine37 committed Jun 22, 2024
2 parents b2c9dd8 + 97be84b commit 6cf50e8
Show file tree
Hide file tree
Showing 45 changed files with 2,309 additions and 136 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/reloaded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ env:
PUBLISH_GITHUB_BF_PATH: ./Publish/ToUpload/BF/Generic
PUBLISH_NUGET_BF_PATH: ./Publish/ToUpload/BF/NuGet

PUBLISH_GAMEBANANA_BMD_PATH: ./Publish/ToUpload/BMD/GameBanana
PUBLISH_GITHUB_BMD_PATH: ./Publish/ToUpload/BMD/Generic
PUBLISH_NUGET_BMD_PATH: ./Publish/ToUpload/BMD/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
Expand Down Expand Up @@ -123,6 +127,7 @@ jobs:
${{ env.PUBLISH_GITHUB_ARC_PATH }}/*
${{ env.PUBLISH_GITHUB_PAK_PATH }}/*
${{ env.PUBLISH_GITHUB_BF_PATH }}/*
${{ env.PUBLISH_GITHUB_BMD_PATH }}/*
${{ env.PUBLISH_GITHUB_SPD_PATH }}/*
${{ env.PUBLISH_GITHUB_FRAMEWORK_PATH }}/*
Expand All @@ -139,6 +144,7 @@ jobs:
${{ env.PUBLISH_GAMEBANANA_ARC_PATH }}/*
${{ env.PUBLISH_GAMEBANANA_PAK_PATH }}/*
${{ env.PUBLISH_GAMEBANANA_BF_PATH }}/*
${{ env.PUBLISH_GAMEBANANA_BMD_PATH }}/*
${{ env.PUBLISH_GAMEBANANA_SPD_PATH }}/*
${{ env.PUBLISH_GAMEBANANA_FRAMEWORK_PATH }}/*
Expand All @@ -155,6 +161,7 @@ jobs:
${{ env.PUBLISH_NUGET_ARC_PATH }}/*
${{ env.PUBLISH_NUGET_PAK_PATH }}/*
${{ env.PUBLISH_NUGET_BF_PATH }}/*
${{ env.PUBLISH_NUGET_BMD_PATH }}/*
${{ env.PUBLISH_NUGET_SPD_PATH }}/*
${{ env.PUBLISH_NUGET_FRAMEWORK_PATH }}/*
Expand All @@ -181,6 +188,7 @@ jobs:
${{ env.PUBLISH_GITHUB_ARC_PATH }}/*
${{ env.PUBLISH_GITHUB_PAK_PATH }}/*
${{ env.PUBLISH_GITHUB_BF_PATH }}/*
${{ env.PUBLISH_GITHUB_BMD_PATH }}/*
${{ env.PUBLISH_GITHUB_SPD_PATH }}/*
${{ env.PUBLISH_GITHUB_FRAMEWORK_PATH }}/*
Expand Down
22 changes: 19 additions & 3 deletions Emulator/BF.File.Emulator/Bf/BfBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,27 @@ private Library OverrideLibraries(Library library)
// Override existing functions
foreach (var func in _libraryFuncs)
{
int module = -1;
int index = -1;

for (int i = 0; i < library.FlowScriptModules.Count; i++)
{
var existing = library.FlowScriptModules[i].Functions.FindIndex(x => x.Index == func.Index);
if (existing != -1)
library.FlowScriptModules[i].Functions[existing] = func;
index = library.FlowScriptModules[i].Functions.FindIndex(x => x.Index == func.Index);

if (index != -1)
{
module = i;
break;
}
}

if (module != -1 && index != -1)
{
library.FlowScriptModules[module].Functions[index] = func;
}
else
{
library.FlowScriptModules.Last().Functions.Add(func);
}
}

Expand Down
149 changes: 149 additions & 0 deletions Emulator/BMD.File.Emulator/.github/workflows/reloaded.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Script to build and publish a Reloaded Mod.
# by Sewer56

# Produces:
# - Build to Upload to GameBanana
# - Build to Upload to GitHub
# - Build to Upload to NuGet
# - Changelog

# When pushing a tag
# - Upload to GitHub Releases
# - Upload to Reloaded NuGet Repository (if GitHub Secret RELOADED_NUGET_KEY is specified)

name: Build and Publish Reloaded Mod

on:
push:
branches: [ main ]
tags:
- '*'
pull_request:
branches: [ main ]
workflow_dispatch:

env:
PUBLISH_COMMON_PATH: ./Publish/ToUpload/

PUBLISH_GAMEBANANA_PATH: ./Publish/ToUpload/GameBanana
PUBLISH_GITHUB_PATH: ./Publish/ToUpload/Generic
PUBLISH_NUGET_PATH: ./Publish/ToUpload/NuGet

PUBLISH_CHANGELOG_PATH: ./Publish/Changelog.md
PUBLISH_PATH: ./Publish

RELOADEDIIMODS: .

# Default value is official Reloaded package server.
NUGET_URL: http://packages.sewer56.moe:5000/v3/index.json

IS_RELEASE: ${{ startsWith(github.ref, 'refs/tags/') }}
RELEASE_TAG: ${{ github.ref_name }}

jobs:
build:
runs-on: windows-latest
defaults:
run:
shell: pwsh

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: 'recursive'

- name: Setup .NET Core SDK (5.0)
uses: actions/[email protected]
with:
dotnet-version: 5.0.x

- name: Setup .NET Core SDK (6.0)
uses: actions/[email protected]
with:
dotnet-version: 6.0.x

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Setup AutoChangelog
run: npm install -g auto-changelog

- name: Create Changelog
run: |
[System.IO.Directory]::CreateDirectory("$env:PUBLISH_PATH")
if ($env:IS_RELEASE -eq 'true') {
auto-changelog --sort-commits date --hide-credit --template keepachangelog --commit-limit false --starting-version "$env:RELEASE_TAG" --output "$env:PUBLISH_CHANGELOG_PATH"
}
else {
auto-changelog --sort-commits date --hide-credit --template keepachangelog --commit-limit false --unreleased --output "$env:PUBLISH_CHANGELOG_PATH"
}
- name: Build
run: ./Publish.ps1 -ChangelogPath "$env:PUBLISH_CHANGELOG_PATH"

- name: Upload GitHub Release Artifact
uses: actions/[email protected]
with:
# Artifact name
name: GitHub Release
# A file, directory or wildcard pattern that describes what to upload
path: |
${{ env.PUBLISH_GITHUB_PATH }}/*
- name: Upload GameBanana Release Artifact
uses: actions/[email protected]
with:
# Artifact name
name: GameBanana Release
# A file, directory or wildcard pattern that describes what to upload
path: |
${{ env.PUBLISH_GAMEBANANA_PATH }}/*
- name: Upload NuGet Release Artifact
uses: actions/[email protected]
with:
# Artifact name
name: NuGet Release
# A file, directory or wildcard pattern that describes what to upload
path: |
${{ env.PUBLISH_NUGET_PATH }}/*
- name: Upload Changelog Artifact
uses: actions/[email protected]
with:
# Artifact name
name: Changelog
# A file, directory or wildcard pattern that describes what to upload
path: ${{ env.PUBLISH_CHANGELOG_PATH }}
retention-days: 0

- name: Upload to GitHub Releases (on Tag)
uses: softprops/[email protected]
if: env.IS_RELEASE == 'true'
with:
# Path to load note-worthy description of changes in release from
body_path: ${{ env.PUBLISH_CHANGELOG_PATH }}
# Newline-delimited list of path globs for asset files to upload
files: |
${{ env.PUBLISH_GITHUB_PATH }}/*
- name: Push to NuGet (on Tag)
env:
NUGET_KEY: ${{ secrets.RELOADED_NUGET_KEY }}
if: env.IS_RELEASE == 'true'
run: |
if ([string]::IsNullOrEmpty("$env:NUGET_KEY"))
{
Write-Host "NuGet Repository Key (GitHub Secrets -> RELOADED_NUGET_KEY) Not Specified. Skipping."
return
}
$items = Get-ChildItem -Path "$env:PUBLISH_NUGET_PATH/*.nupkg"
Foreach ($item in $items)
{
Write-Host "Pushing $item"
dotnet nuget push "$item" -k "$env:NUGET_KEY" -s "$env:NUGET_URL" --skip-duplicate
}
60 changes: 60 additions & 0 deletions Emulator/BMD.File.Emulator/BMD.File.Emulator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<OutputPath>$(RELOADEDIIMODS)/reloaded.universal.fileemulationframework.bmd</OutputPath>
<Deterministic>true</Deterministic>
<ImplicitUsings>enable</ImplicitUsings>

<!-- IL Trimming Support for Framework Dependent Apps. Unofficial.
If you set this to true, trimming will be enabled when you publish the mod.
Test trimming with: `BuildLinked.ps1` in PowerShell. -->
<ReloadedILLink>true</ReloadedILLink>
</PropertyGroup>

<ItemGroup>
<ReloadedLinkRoots Include="AtlusScriptLibrary" />
<!-- Add assemblies to be trimmed. You might need to add their dependencies too! -->
<ReloadedLinkAssemblies Include="Antlr4.Runtime" />
<ReloadedLinkAssemblies Include="MoreLinq" />
<ReloadedLinkAssemblies Include="Reloaded.Hooks.Definitions" />
<ReloadedLinkAssemblies Include="FileEmulationFramework.Lib" />
<ReloadedLinkAssemblies Include="BMD.File.Emulator" />
</ItemGroup>

<Import Project="Reloaded.Trimming.targets" />

<ItemGroup>
<None Remove="ModConfig.json" />
<None Remove="Publish.ps1" />
<None Remove="BuildLinked.ps1" />
<None Remove="Reloaded.Trimming.targets" />
</ItemGroup>

<ItemGroup>
<Content Include="ModConfig.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Update="Preview.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Reloaded.Mod.Interfaces" Version="2.3.0" ExcludeAssets="runtime" />
<PackageReference Include="Reloaded.SharedLib.Hooks" Version="1.9.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\FileEmulationFramework.Interfaces\FileEmulationFramework.Interfaces.csproj" />
<ProjectReference Include="..\..\FileEmulationFramework.Lib\FileEmulationFramework.Lib.csproj" />
<ProjectReference Include="..\..\Submodules\Atlus-Script-Tools\Source\AtlusScriptLibrary\AtlusScriptLibrary.csproj" />
<ProjectReference Include="..\Interfaces\BMD.File.Emulator.Interfaces\BMD.File.Emulator.Interfaces.csproj" />
</ItemGroup>

</Project>
84 changes: 84 additions & 0 deletions Emulator/BMD.File.Emulator/Bmd/BmdBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using FileEmulationFramework.Lib.IO;
using FileEmulationFramework.Lib.Utilities;
using FileEmulationFramework.Lib.Memory;
using AtlusScriptLibrary.MessageScriptLanguage.Compiler;
using MessageFormatVersion = AtlusScriptLibrary.MessageScriptLanguage.FormatVersion;
using AtlusScriptLibrary.Common.Libraries;
using System.Text;
using Microsoft.Win32.SafeHandles;
using AtlusScriptLibrary.MessageScriptLanguage;
using System.Text.Json;
using BMD.File.Emulator.Utilities;

// Aliasing for readability, since our assembly name has priority over 'File'
using Fiel = System.IO.File;

namespace BMD.File.Emulator.Bmd;

public class BmdBuilder
{
private readonly List<string> _msgFiles = new List<string>();
private readonly HashSet<string> _addedOverrides = new();

private MessageFormatVersion? _messageFormat = null;
private Library? _library = null;
private Encoding? _encoding = null;
private Logger? _log = null;

public BmdBuilder(MessageFormatVersion? messageFormat, Library? library, Encoding? encoding, Logger? log)
{
_messageFormat = messageFormat;
_library = library;
_encoding = encoding;
_log = log;
}

public BmdBuilder() { }

/// <summary>
/// Adds a msg file that will be imported when compiling the bmd
/// </summary>
/// <param name="filePath">Full path to the file.</param>
public void AddMsgFile(string filePath)
{
if (!filePath.EndsWith(Constants.MessageExtension, StringComparison.OrdinalIgnoreCase)) return;
_msgFiles.Add(filePath);
}

/// <summary>
/// Builds a BMD file.
/// </summary>
public unsafe Stream? Build(IntPtr originalHandle, string originalPath, MessageFormatVersion msgFormat, Library library, Encoding encoding, AtlusLogListener? listener = null, bool noBaseBmd = false)
{
_log?.Info("[BmdEmulator] Building BMD File | {0}", originalPath);

// Use compiler arg overrides (if they're there)
if (_library != null) library = _library;
if (_encoding != null) encoding = _encoding;
if (_messageFormat != null) msgFormat = (MessageFormatVersion)_messageFormat;

var compiler = new MessageScriptCompiler(msgFormat, encoding);
compiler.Library = library;
compiler.OverwriteExistingMsgs = true;
if (listener != null)
compiler.AddListener(listener);

FileStream? bmdStream = null;
if (!noBaseBmd)
bmdStream = new FileStream(new SafeFileHandle(originalHandle, false), FileAccess.Read);

if (!compiler.TryCompileWithImports(bmdStream, _msgFiles, out MessageScript messageScript))
{
_log?.Error("[BmdEmulator] Failed to compile BMD File | {0}", originalPath);
return null;
}

// Return the compiled bmd
var bmdBinary = messageScript.ToBinary();
var stream = StreamUtils.CreateMemoryStream(bmdBinary.Header.FileSize);
bmdBinary.ToStream(stream, true);
stream.Position = 0;

return stream;
}
}
Loading

0 comments on commit 6cf50e8

Please sign in to comment.