Skip to content

Commit d467a46

Browse files
author
HyperPolygon64
committed
Added WriteBytes function
modified: Sonic-06-Mod-Manager/src/UnifyPatcher.cs modified: Sonic-06-Mod-Manager/src/UnifySerialisers.cs
1 parent c48102c commit d467a46

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

Sonic-06-Mod-Manager/src/UnifyPatcher.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,19 @@ public static void InstallPatches(string patch, string name)
465465
WriteByte(Literal.CoreReplace(_WriteByte[0]), Convert.ToInt32(_WriteByte[1], 16), Convert.ToByte(_WriteByte[2], 16));
466466
break;
467467

468+
// Writes a byte array to the specified offset in the file.
469+
case string x when x.StartsWith("WriteBytes("):
470+
// Deserialise 'WriteBytes' parameter
471+
string[] _WriteBytes = Lua.DeserialiseParameterList("WriteBytes", line, false);
472+
473+
// Convert the string to a byte array
474+
byte[] _WriteBytesArray = Bytes.StringToByteArray(_WriteBytes[2].Replace(" ", ""));
475+
476+
// Iterate through byte array to write from the offset
477+
for (int i = 0; i < _WriteBytesArray.Length; i++)
478+
WriteByte(Literal.CoreReplace(_WriteBytes[0]), Convert.ToInt32(_WriteBytes[1], 16) + i, _WriteBytesArray[i]);
479+
break;
480+
468481
// Writes null bytes to the specified offset in the file.
469482
case string x when x.StartsWith("WriteNullBytes("):
470483
// Deserialise 'WriteNullBytes' parameter

Sonic-06-Mod-Manager/src/UnifySerialisers.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,15 @@ public static bool IsSubdirectory(string candidate, string other) {
477477
return isChild;
478478
}
479479
}
480+
481+
class Bytes
482+
{
483+
public static byte[] StringToByteArray(string hex)
484+
{
485+
return Enumerable.Range(0, hex.Length)
486+
.Where(x => x % 2 == 0)
487+
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
488+
.ToArray();
489+
}
490+
}
480491
}

0 commit comments

Comments
 (0)