Created
February 11, 2020 09:11
-
-
Save goaaats/149d3ea03779c8416916f0dfa14a1e68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
namespace FFXIVGenerateENPCSheet | |
{ | |
public class GenCharaSaveDat | |
{ | |
public static byte[] Generate(byte[] originalLook, string msg) | |
{ | |
byte[] buffer = new byte[0xD4]; | |
using (MemoryStream memstream = new MemoryStream(buffer)) | |
{ | |
using (BinaryWriter binwriter = new BinaryWriter(memstream)) | |
{ | |
binwriter.Write(0x2013FF14); //Magic | |
binwriter.Write(0x03); //Version | |
memstream.Position = 0x10; | |
binwriter.Write(originalLook); //Look data | |
memstream.Position = 0x30; | |
binwriter.Write(Encoding.UTF8.GetBytes(msg)); | |
byte[] toSum = new byte[0xD4]; | |
Array.Copy(memstream.ToArray(), 0, toSum, 0, 0xD4); | |
int chksum = CalcChecksum(toSum); | |
memstream.Position = 0x8; | |
binwriter.Write(chksum); | |
} | |
return memstream.ToArray(); | |
} | |
} | |
private static int CalcChecksum(byte[] data) //Mino is cool | |
{ | |
var checksum = 0; | |
var prevY = 0; | |
for (var offset = 0x10; offset < 0xD4; offset += 4) | |
{ | |
var processed = offset - 0x10; | |
var x = (data[offset + 2] << (processed - 24 * ((processed + 2) / 0x18) + 2)) ^ | |
(data[offset + 1] << (processed - 24 * ((processed + 1) / 0x18) + 1)); | |
var y = (data[offset] << processed % 0x18) ^ | |
(data[offset + 3] << (processed - 24 * ((processed + 3) / 0x18) + 3)) ^ x; | |
checksum = y ^ prevY; | |
prevY ^= y; | |
} | |
return checksum; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment