MCPcopy Create free account
hub / github.com/Shazbot/WH3-Mod-Manager / readLoc

Function readLoc

src/packFileSerializer.ts:2820–2894  ·  view source on GitHub ↗
(
  packReadingOptions: PackReadingOptions,
  locPackFile: PackedFile,
  buffer: Buffer,
  modPath: string,
)

Source from the content-addressed store, hash-verified

2818 }
2819};
2820const readLoc = async (
2821 packReadingOptions: PackReadingOptions,
2822 locPackFile: PackedFile,
2823 buffer: Buffer,
2824 modPath: string,
2825) => {
2826 let currentPos = 0;
2827 // console.log("READING LOC file", locPackFile.name);
2828 const marker = await buffer.subarray(currentPos, currentPos + 2);
2829 currentPos += 2;
2830 if (marker.toString("hex") != "fffe") {
2831 console.log("FF FE marker is wrong!");
2832 return;
2833 }
2834 const locMarker = await buffer.subarray(currentPos, currentPos + 3);
2835 currentPos += 3;
2836 if (locMarker.toString("hex") != "4c4f43") {
2837 console.log("LOC marker is wrong!");
2838 return;
2839 }
2840 currentPos += 1; // null byte
2841 currentPos += 4; // pack file version, loc is always 1
2842 const entryCount = buffer.readInt32LE(currentPos);
2843 currentPos += 4;
2844 try {
2845 for (let i = 0; i < entryCount; i++) {
2846 for (const field of LocFields) {
2847 const { name, field_type, is_key } = field;
2848 // console.log("reading", name, field_type, currentPos);
2849 const lastPos = currentPos;
2850 try {
2851 const fieldsRet = await parseTypeBuffer(buffer, currentPos, field_type);
2852 const fields = fieldsRet[0];
2853 currentPos = fieldsRet[1];
2854 // console.log("after read:", fieldsRet);
2855 // console.log("fields 0:", fields[0] && fields[0].val);
2856 // console.log("fields 1:", fields[1] && fields[1].val);
2857 if (!fields[1] && !fields[0]) {
2858 console.log(name);
2859 console.log(field_type);
2860 }
2861 if (fields[0].val == undefined) {
2862 console.log(name);
2863 console.log(field_type);
2864 }
2865 if (fields.length == 0) {
2866 console.log(name);
2867 console.log(field_type);
2868 }
2869 const schemaField: SchemaField = {
2870 // name,
2871 type: field_type,
2872 fields,
2873 };
2874 if (is_key) {
2875 schemaField.isKey = true;
2876 }
2877 locPackFile.schemaFields = locPackFile.schemaFields || [];

Callers 1

readPackFunction · 0.85

Calls 1

parseTypeBufferFunction · 0.70

Tested by

no test coverage detected