-
Notifications
You must be signed in to change notification settings - Fork 2
/
Recsum.1sc
57 lines (51 loc) · 1.67 KB
/
Recsum.1sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//------------------------------------------------
//--- 010 Editor v14.0 Script File
//
// File: Recsum
// Authors: ClayAmore
// Version:
// Purpose: Recalculate checksums then save.
// Category:
// History:
//------------------------------------------------
int i = 0;
uint64 offset;
int slots_count = 0;
int active_slots_offset = 0x1901D04;
uchar buffer[0x280000];
uchar result[0x10];
string og_name = GetFileName();
int HEADER_SIZE = 0x300;
int CHARACTER_FILE_SIZE = 0x280000;
int CHECKSUM_SIZE = 0x10;
int USERDATA_10_SIZE = 0x60000;
int MAX_CHARACTER_COUNT = 10;
// Count active slots
while(i < 10) {
if((ReadByte(active_slots_offset + 0x1*i)) == 1) slots_count++;
i++;
}
// Recalculate checksum for active character slots
i = 0;
while(i < slots_count) {
// Calculate the offset to the start of a character, skipping checksum bytes.
offset = HEADER_SIZE + ((CHARACTER_FILE_SIZE + CHECKSUM_SIZE) * i);
// Move the cursor position to offset
SetCursorPos( offset );
// Read the bytes to buffer
ReadBytes(buffer, offset + CHECKSUM_SIZE, CHARACTER_FILE_SIZE);
// Calculcate checksum from bytes.
ChecksumAlgArrayBytes( CHECKSUM_MD5, result, buffer, CHARACTER_FILE_SIZE);
// Overwrite old checksum with the new checksum.
WriteBytes(result, offset, CHECKSUM_SIZE);
// Increment index
i++;
}
// Recalculate checksum for USER_DATA_10
offset = HEADER_SIZE + (CHARACTER_FILE_SIZE * MAX_CHARACTER_COUNT);
SetCursorPos( offset );
ReadBytes(buffer, offset + CHECKSUM_SIZE, USERDATA_10_SIZE);
ChecksumAlgArrayBytes( CHECKSUM_MD5, result, buffer, USERDATA_10_SIZE);
WriteBytes(result, offset, CHECKSUM_SIZE);
// Save file
FileSave(og_name);