mirror of
https://github.com/kwsch/NLSE.git
synced 2026-04-24 07:27:11 -05:00
parent
66a0a0d522
commit
9a7ea098ee
25
Misc/Util.cs
25
Misc/Util.cs
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace NLSE
|
||||
|
|
@ -70,5 +71,29 @@ internal static int getIndex(ComboBox cb)
|
|||
|
||||
return val;
|
||||
}
|
||||
// Find Code off of Reference
|
||||
internal static int IndexOfBytes(byte[] array, byte[] pattern, int startIndex, int count)
|
||||
{
|
||||
int i = startIndex;
|
||||
int endIndex = count > 0 ? startIndex + count : array.Length;
|
||||
int fidx = 0;
|
||||
|
||||
while (i++ != endIndex - 1)
|
||||
{
|
||||
if (array[i] != pattern[fidx]) i -= fidx;
|
||||
fidx = (array[i] == pattern[fidx]) ? ++fidx : 0;
|
||||
if (fidx == pattern.Length)
|
||||
return i - fidx + 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
internal static void ReplaceAllBytes(byte[] array, byte[] oldPattern, byte[] newPattern)
|
||||
{
|
||||
if (oldPattern.SequenceEqual(newPattern))
|
||||
return;
|
||||
int offset; // Loop until no instances of oldPattern are found
|
||||
while ((offset = IndexOfBytes(array, oldPattern, 0, 0)) != -1)
|
||||
Array.Copy(newPattern, 0, array, offset, newPattern.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,12 +192,18 @@ public GardenData(byte[] data)
|
|||
}
|
||||
public byte[] Write()
|
||||
{
|
||||
// Replace all instances of Town Data with Updated Data
|
||||
byte[] oldTownIDData = Data.Skip(0x5C7B8).Take(0x14).ToArray();
|
||||
byte[] newTownIDData = new[]
|
||||
{
|
||||
(byte) ((Data[0x5C7B8] & 0xFC) | TownHallColor),
|
||||
(byte) ((Data[0x5C7B9] & 0xFC) | TrainStationColor)
|
||||
}.Concat(Encoding.Unicode.GetBytes(TownName.PadRight(9, '\0'))).ToArray();
|
||||
Util.ReplaceAllBytes(Data, oldTownIDData, newTownIDData);
|
||||
|
||||
Data[0x4DA81] = (byte)GrassType;
|
||||
Data[0x5C7B8] = (byte)((Data[0x5C7B8] & 0xFC) | TownHallColor);
|
||||
Data[0x5C7B9] = (byte)((Data[0x5C7B9] & 0xFC) | TrainStationColor);
|
||||
Data[0x5C836] = (byte)NativeFruit;
|
||||
|
||||
Array.Copy(Encoding.Unicode.GetBytes(TownName.PadRight(9, '\0')), 0, Data, 0x5C7BA, 0x12);
|
||||
Array.Copy(BitConverter.GetBytes(SecondsPlayed), 0, Data, 0x5C7B0, 4);
|
||||
Array.Copy(BitConverter.GetBytes(PlayDays), 0, Data, 0x5C83A, 2);
|
||||
return Data;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user