Skip to content

Commit

Permalink
Add ISO support
Browse files Browse the repository at this point in the history
  • Loading branch information
IntelOrca committed Dec 27, 2023
1 parent 1ee786d commit f6e52a9
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[submodule "biohazard-utils"]
path = biohazard-utils
url = https://github.com/IntelOrca/biohazard-utils
[submodule "Ps2IsoTools"]
path = Ps2IsoTools
url = https://github.com/IntelOrca/Ps2IsoTools.git
branch = netstandard2
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\biohazard-utils\src\IntelOrca.Biohazard\IntelOrca.Biohazard.csproj" />
<ProjectReference Include="..\Ps2IsoTools\Ps2IsoTools\Ps2IsoTools.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Resources.Designer.cs">
Expand Down
56 changes: 44 additions & 12 deletions IntelOrca.Biohazard.BioRand/RECV/ReCvRandomiser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using IntelOrca.Biohazard.Extensions;
using IntelOrca.Biohazard.Room;
using IntelOrca.Biohazard.Script;
using Ps2IsoTools.UDF;
using Ps2IsoTools.UDF.Files;

namespace IntelOrca.Biohazard.BioRand.RECV
{
Expand Down Expand Up @@ -59,16 +60,11 @@ protected override string GetRdtPath(string dataPath, RdtId rdtId, int player, b

protected override RandomizedRdt ReadRdt(FileRepository fileRepository, RdtId rdtId, string path, string modPath)
{
if (_rdxAfs == null)
{
_rdxAfs = new AfsFile(File.ReadAllBytes(path));
}

var fileIndex = GetRdxFileIndex(rdtId);
if (_rdts[fileIndex] != null)
return _rdts[fileIndex];

var prs = new PrsFile(_rdxAfs.GetFileData(fileIndex));
var prs = new PrsFile(_rdxAfs!.GetFileData(fileIndex));
var rdt = new RdtCv(prs.Uncompressed);
var rrdt = new RandomizedRdt(rdt, rdtId);
rrdt.Ast = CreateAst(rdt);
Expand Down Expand Up @@ -131,17 +127,53 @@ public override void Generate(RandoConfig config, IRandoProgress progress, FileR
config.RandomEvents = false;
config.RandomBgm = false;

GenerateRdts(config, progress, fileRepository);
var isoDirectory = Path.GetDirectoryName(fileRepository.DataPath);
var input = Path.Combine(isoDirectory, "recvx.iso");
var output = Path.Combine(isoDirectory, "recvx_biorand.iso");

UdfEditor? udfEditor = null;
try
{
FileIdentifier? afsFileId;
using (progress.BeginTask(null, "Reading ISO file"))
{
udfEditor = new Ps2IsoTools.UDF.UdfEditor(input, output);
afsFileId = udfEditor.GetFileByName("RDX_LNK.AFS");
if (afsFileId == null)
throw new BioRandUserException("RDX_LNK.AFS not found in ISO");

_rdxAfs = ReadRdxAfs(udfEditor, afsFileId);
}

GenerateRdts(config, progress, fileRepository);

// base.Generate(config, progress, fileRepository);
// base.Generate(config, progress, fileRepository);

using (progress.BeginTask(null, "Compressing room files"))
using (progress.BeginTask(null, "Compressing room files"))
{
_rdxAfs = WriteRdxAfs();
}

using (progress.BeginTask(null, "Creating ISO file"))
{
udfEditor.ReplaceFileStream(afsFileId, new MemoryStream(_rdxAfs!.Data.ToArray()));
udfEditor.Rebuild(output);
}
}
finally
{
Directory.CreateDirectory(Path.Combine(fileRepository.ModPath, "data"));
WriteRdxAfs().Data.WriteToFile(Path.Combine(fileRepository.ModPath, "data", "RDX_LNK.AFS"));
udfEditor?.Dispose();
}
}

private AfsFile ReadRdxAfs(UdfEditor editor, FileIdentifier fileId)
{
var stream = editor.GetFileStream(fileId);
var data = new byte[stream.Length];
stream.Read(data, 0, data.Length);
return new AfsFile(data);
}

private AfsFile WriteRdxAfs()
{
if (_rdxAfs == null)
Expand Down
2 changes: 2 additions & 0 deletions IntelOrca.Biohazard.BioRand/ReInstallConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public string GetInstallPath(int index)
var result = _installPath[index];
if (result == null)
{
if (index == 3)
throw new Exception($"RE:CVX path not set up.");
throw new Exception($"RE {index + 1} path not set up.");
}
return result;
Expand Down
1 change: 1 addition & 0 deletions Ps2IsoTools
Submodule Ps2IsoTools added at c88361
14 changes: 14 additions & 0 deletions biorand.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntelOrca.Biohazard.BioRand
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntelOrca.Biohazard", "biohazard-utils\src\IntelOrca.Biohazard\IntelOrca.Biohazard.csproj", "{66E02DD8-9F1A-4D2F-84FE-5AB7157663B6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ps2IsoTools", "Ps2IsoTools\Ps2IsoTools\Ps2IsoTools.csproj", "{6E501365-ECF7-4B27-8058-9040FBBDD017}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -86,6 +88,18 @@ Global
{66E02DD8-9F1A-4D2F-84FE-5AB7157663B6}.Release|x64.Build.0 = Release|Any CPU
{66E02DD8-9F1A-4D2F-84FE-5AB7157663B6}.Release|x86.ActiveCfg = Release|Any CPU
{66E02DD8-9F1A-4D2F-84FE-5AB7157663B6}.Release|x86.Build.0 = Release|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Debug|x64.ActiveCfg = Debug|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Debug|x64.Build.0 = Debug|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Debug|x86.ActiveCfg = Debug|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Debug|x86.Build.0 = Debug|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Release|Any CPU.Build.0 = Release|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Release|x64.ActiveCfg = Release|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Release|x64.Build.0 = Release|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Release|x86.ActiveCfg = Release|Any CPU
{6E501365-ECF7-4B27-8058-9040FBBDD017}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit f6e52a9

Please sign in to comment.