diff --git a/pk3DS/Subforms/OWSE.cs b/pk3DS/Subforms/OWSE.cs index 0bab2cd..4ce6e04 100644 --- a/pk3DS/Subforms/OWSE.cs +++ b/pk3DS/Subforms/OWSE.cs @@ -89,6 +89,21 @@ private void getEntry() private void setEntry() { //if (entry < 0) return; + // + //Force writeback of each overworld type + //changeFurniture(null, null); + //changeOverworld(null, null); + //changeWarp(null, null); + //changeTrigger(null, null); + // + //TODO: Reassemble the 5 files + //locationData[0] = locationData[0]; + //locationData[1] = setOWSData(); + //locationData[2] = locationData[2]; + //locationData[3] = locationData[3]; + //locationData[4] = locationData[4]; + // + //Package the files into the permanent package file. //byte[] raw = Util.packMini(locationData, "ZO"); //File.WriteAllBytes(filepaths[entry], raw); } @@ -161,6 +176,34 @@ private void getOWSData() } } + private byte[] setOWSData() + { + using (var s = new MemoryStream()) + using (var bw = new BinaryWriter(s)) + { + // Overworld Payload + bw.Write(0); // 4 Byte Length of 0 (Temporary) + bw.Write((byte)NUD_FurnCount.Value); + bw.Write((byte)NUD_NPCCount.Value); + bw.Write((byte)NUD_WarpCount.Value); + bw.Write((byte)NUD_TrigCount.Value); + for (int i = 0; i < NUD_FurnCount.Value; i++) bw.Write(fData[i]); + for (int i = 0; i < NUD_NPCCount.Value; i++) bw.Write(nData[i]); + for (int i = 0; i < NUD_WarpCount.Value; i++) bw.Write(wData[i]); + for (int i = 0; i < NUD_TrigCount.Value; i++) bw.Write(tData[i]); + // have to check for 00 padding + while (s.Length % 4 != 0) bw.Write((byte)0); + s.Position = 0; bw.Write((int)s.Length); + s.Position = s.Length - 1; + // Script Payload + byte[] scriptData = Util.StringToByteArray(RTB_S.Text); + bw.Write(scriptData.Length); + bw.Write(scriptData); // ScriptData + + return s.ToArray(); + } + } + // Overworld Functions private const int flen = 0x14; private const int nlen = 0x30; diff --git a/pk3DS/Util.cs b/pk3DS/Util.cs index f0e6f78..ffe5ffe 100644 --- a/pk3DS/Util.cs +++ b/pk3DS/Util.cs @@ -790,5 +790,12 @@ internal static void resizeJagged(ref byte[][] array, int size, int lowLen) array[i] = new byte[lowLen]; } } + internal static byte[] StringToByteArray(string hex) + { + return Enumerable.Range(0, hex.Length) + .Where(x => x % 2 == 0) + .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) + .ToArray(); + } } }