@zebbedaja/er-save-parser 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +28 -1
- package/dist/index.mjs +39 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -143,6 +143,12 @@ interface EventFlag {
|
|
|
143
143
|
location?: string;
|
|
144
144
|
state?: boolean;
|
|
145
145
|
}
|
|
146
|
+
interface BitDifference {
|
|
147
|
+
offset: number;
|
|
148
|
+
bitIndex: number;
|
|
149
|
+
oldBit: 0 | 1;
|
|
150
|
+
newBit: 0 | 1;
|
|
151
|
+
}
|
|
146
152
|
//#endregion
|
|
147
153
|
//#region src/parser.d.ts
|
|
148
154
|
/**
|
|
@@ -218,5 +224,26 @@ declare const getEventFlagState: (bstMap: Map<number, number>, eventFlags: Uint8
|
|
|
218
224
|
* @returns The event ID corresponding to the given position
|
|
219
225
|
*/
|
|
220
226
|
declare const getEventIdFromPosition: (bstMap: Map<number, number>, bytePos: number, bitIndex: number) => number;
|
|
227
|
+
/**
|
|
228
|
+
* Compares two Uint8Arrays and returns all bit-level differences.
|
|
229
|
+
*
|
|
230
|
+
* Arrays of different lengths are supported — missing bytes in the shorter
|
|
231
|
+
* array are treated as `0`.
|
|
232
|
+
*
|
|
233
|
+
* @param a - The original Uint8Array.
|
|
234
|
+
* @param b - The Uint8Array to compare against.
|
|
235
|
+
* @returns An array of {@link BitDifference} objects, one per differing bit.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* const a = new Uint8Array([0b00001111, 0b11110000]);
|
|
239
|
+
* const b = new Uint8Array([0b00001111, 0b10110001]);
|
|
240
|
+
*
|
|
241
|
+
* const diffs = compareUint8Arrays(a, b);
|
|
242
|
+
* // [
|
|
243
|
+
* // { offset: 1, bitIndex: 0, oldBit: 0, newBit: 1 },
|
|
244
|
+
* // { offset: 1, bitIndex: 6, oldBit: 1, newBit: 0 },
|
|
245
|
+
* // ]
|
|
246
|
+
*/
|
|
247
|
+
declare const compareUint8Arrays: (a: Uint8Array, b: Uint8Array) => BitDifference[];
|
|
221
248
|
//#endregion
|
|
222
|
-
export { type Character, type EventFlag, type LogLevel, type ParseOptions, type ProfileSummary, type Save, type Settings, type Slot, arrayBuffersEqual, getBstMap, getEventFlagState, getEventIdFromPosition, parse, parseToMap, stringToBytes, toHexString, trim };
|
|
249
|
+
export { type BitDifference, type Character, type EventFlag, type LogLevel, type ParseOptions, type ProfileSummary, type Save, type Settings, type Slot, arrayBuffersEqual, compareUint8Arrays, getBstMap, getEventFlagState, getEventIdFromPosition, parse, parseToMap, stringToBytes, toHexString, trim };
|
package/dist/index.mjs
CHANGED
|
@@ -12030,6 +12030,44 @@ const getEventIdFromPosition = (bstMap, bytePos, bitIndex) => {
|
|
|
12030
12030
|
}
|
|
12031
12031
|
throw new Error(`Byte position ${bytePos} not found in any known block`);
|
|
12032
12032
|
};
|
|
12033
|
+
/**
|
|
12034
|
+
* Compares two Uint8Arrays and returns all bit-level differences.
|
|
12035
|
+
*
|
|
12036
|
+
* Arrays of different lengths are supported — missing bytes in the shorter
|
|
12037
|
+
* array are treated as `0`.
|
|
12038
|
+
*
|
|
12039
|
+
* @param a - The original Uint8Array.
|
|
12040
|
+
* @param b - The Uint8Array to compare against.
|
|
12041
|
+
* @returns An array of {@link BitDifference} objects, one per differing bit.
|
|
12042
|
+
*
|
|
12043
|
+
* @example
|
|
12044
|
+
* const a = new Uint8Array([0b00001111, 0b11110000]);
|
|
12045
|
+
* const b = new Uint8Array([0b00001111, 0b10110001]);
|
|
12046
|
+
*
|
|
12047
|
+
* const diffs = compareUint8Arrays(a, b);
|
|
12048
|
+
* // [
|
|
12049
|
+
* // { offset: 1, bitIndex: 0, oldBit: 0, newBit: 1 },
|
|
12050
|
+
* // { offset: 1, bitIndex: 6, oldBit: 1, newBit: 0 },
|
|
12051
|
+
* // ]
|
|
12052
|
+
*/
|
|
12053
|
+
const compareUint8Arrays = (a, b) => {
|
|
12054
|
+
const differences = [];
|
|
12055
|
+
const length = Math.max(a.length, b.length);
|
|
12056
|
+
for (let offset = 0; offset < length; offset++) {
|
|
12057
|
+
const byteA = offset < a.length ? a[offset] : 0;
|
|
12058
|
+
const byteB = offset < b.length ? b[offset] : 0;
|
|
12059
|
+
if (byteA !== byteB) {
|
|
12060
|
+
const xor = byteA ^ byteB;
|
|
12061
|
+
for (let bitIndex = 0; bitIndex < 8; bitIndex++) if (xor & 1 << bitIndex) differences.push({
|
|
12062
|
+
offset,
|
|
12063
|
+
bitIndex,
|
|
12064
|
+
oldBit: byteA >> bitIndex & 1,
|
|
12065
|
+
newBit: byteB >> bitIndex & 1
|
|
12066
|
+
});
|
|
12067
|
+
}
|
|
12068
|
+
}
|
|
12069
|
+
return differences;
|
|
12070
|
+
};
|
|
12033
12071
|
//#endregion
|
|
12034
12072
|
//#region src/event-flags.ts
|
|
12035
12073
|
const eventFlags = [
|
|
@@ -18819,4 +18857,4 @@ function parse(buffer, options = {
|
|
|
18819
18857
|
return save;
|
|
18820
18858
|
}
|
|
18821
18859
|
//#endregion
|
|
18822
|
-
export { arrayBuffersEqual, getBstMap, getEventFlagState, getEventIdFromPosition, parse, parseToMap, stringToBytes, toHexString, trim };
|
|
18860
|
+
export { arrayBuffersEqual, compareUint8Arrays, getBstMap, getEventFlagState, getEventIdFromPosition, parse, parseToMap, stringToBytes, toHexString, trim };
|