Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support editing ER SystemParam #825

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<PARAMDEF XmlVersion="2">
<ParamType>CS_RAYTRACING_QUALITY_DETAIL</ParamType>
<DataVersion>1</DataVersion>
<BigEndian>False</BigEndian>
<Unicode>True</Unicode>
<FormatVersion>203</FormatVersion>
<Fields>
<Field Def="u8 enableRaytraceAO"></Field>
<Field Def="u8 enableRaytraceShadows"></Field>
<Field Def="u8 Unk0x02"></Field>
<Field Def="u8 Unk0x03"></Field>
<Field Def="f32 UnkFloat0x04"></Field>
<Field Def="s32 Unk0x08"></Field>
<Field Def="f32 UnkFloat0x0C"></Field>
<Field Def="s32 Unk0x10"></Field>
<Field Def="f32 UnkFloat0x14"></Field>
<Field Def="f32 UnkFloat0x18"></Field>
</Fields>
</PARAMDEF>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PARAMMETA XmlVersion="0">
<Enums>
</Enums>
<Field>
<enableRaytraceAO IsBool="" />
<enableRaytraceShadows IsBool="" />
</Field>
<Self />
</PARAMMETA>
95 changes: 66 additions & 29 deletions src/StudioCore/ParamEditor/ParamBank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -905,16 +905,41 @@ private void LoadParamsER(bool partial)
}
}
}

string sysParam = AssetLocator.GetAssetPath(@"param\systemparam\systemparam.parambnd.dcx");
if (File.Exists(sysParam))
{
LoadParamsERFromFile(sysParam, false);
}
else
{
TaskLogs.AddLog("Systemparam could not be found. These require an unpacked game to modify.", LogLevel.Information, TaskLogs.LogPriority.Normal);
}
}

private void LoadVParamsER()
{
LoadParamsERFromFile($@"{AssetLocator.GameRootDirectory}\regulation.bin");

var sysParam = $@"{AssetLocator.GameRootDirectory}\param\systemparam\systemparam.parambnd.dcx";
if (File.Exists(sysParam))
{
LoadParamsERFromFile(sysParam, false);
}
}

private void LoadParamsERFromFile(string path)
private void LoadParamsERFromFile(string path, bool encrypted = true)
{
LoadParamFromBinder(SFUtil.DecryptERRegulation(path), ref _params, out _paramVersion, true);
if (encrypted)
{
using BND4 bnd = SFUtil.DecryptERRegulation(path);
LoadParamFromBinder(bnd, ref _params, out _paramVersion, true);
}
else
{
using BND4 bnd = BND4.Read(path);
LoadParamFromBinder(bnd, ref _params, out _, false);
}
}

private void LoadParamsAC6()
Expand Down Expand Up @@ -1755,6 +1780,37 @@ private void SaveParamsDES()

private void SaveParamsER(bool partial)
{
void OverwriteParamsER(BND4 paramBnd)
{
// Replace params with edited ones
foreach (BinderFile p in paramBnd.Files)
{
if (_params.ContainsKey(Path.GetFileNameWithoutExtension(p.Name)))
{
Param paramFile = _params[Path.GetFileNameWithoutExtension(p.Name)];
IReadOnlyList<Param.Row> backup = paramFile.Rows;
List<Param.Row> changed = new();
if (partial)
{
TaskManager.WaitAll(); //wait on dirtycache update
HashSet<int> dirtyCache = _vanillaDiffCache[Path.GetFileNameWithoutExtension(p.Name)];
foreach (Param.Row row in paramFile.Rows)
{
if (dirtyCache.Contains(row.ID))
{
changed.Add(row);
}
}

paramFile.Rows = changed;
}

p.Bytes = paramFile.Write();
paramFile.Rows = backup;
}
}
}

var dir = AssetLocator.GameRootDirectory;
var mod = AssetLocator.GameModDirectory;
if (!File.Exists($@"{dir}\\regulation.bin"))
Expand All @@ -1771,37 +1827,18 @@ private void SaveParamsER(bool partial)
param = $@"{dir}\regulation.bin";
}

BND4 paramBnd = SFUtil.DecryptERRegulation(param);
BND4 regParams = SFUtil.DecryptERRegulation(param);
OverwriteParamsER(regParams);
Utils.WriteWithBackup(dir, mod, @"regulation.bin", regParams, GameType.EldenRing);

// Replace params with edited ones
foreach (BinderFile p in paramBnd.Files)
string sysParam = AssetLocator.GetAssetPath(@"param\systemparam\systemparam.parambnd.dcx");
if (File.Exists(sysParam))
{
if (_params.ContainsKey(Path.GetFileNameWithoutExtension(p.Name)))
{
Param paramFile = _params[Path.GetFileNameWithoutExtension(p.Name)];
IReadOnlyList<Param.Row> backup = paramFile.Rows;
List<Param.Row> changed = new();
if (partial)
{
TaskManager.WaitAll(); //wait on dirtycache update
HashSet<int> dirtyCache = _vanillaDiffCache[Path.GetFileNameWithoutExtension(p.Name)];
foreach (Param.Row row in paramFile.Rows)
{
if (dirtyCache.Contains(row.ID))
{
changed.Add(row);
}
}

paramFile.Rows = changed;
}

p.Bytes = paramFile.Write();
paramFile.Rows = backup;
}
using BND4 sysParams = BND4.Read(sysParam);
OverwriteParamsER(sysParams);
Utils.WriteWithBackup(dir, mod, @"param\systemparam\systemparam.parambnd.dcx", sysParams);
}

Utils.WriteWithBackup(dir, mod, @"regulation.bin", paramBnd, GameType.EldenRing);
_pendingUpgrade = false;
}

Expand Down
Loading