diff --git a/index.js b/index.js index cd269c0..b756745 100644 --- a/index.js +++ b/index.js @@ -65,23 +65,20 @@ async function replace() { // Read .mogg const mogg_buffer = await readFile(`mogg_output/${mogg_file}`); - console.log('Mogg', mogg_buffer); // Modify .uexp const data_buffer = await readFile(`game_input/${game_file}.uexp`); const old_uexp_length = data_buffer.length; + + // Get the start offset by getting the first index of MoggSampleResource, then offset by 19 const start_offset = data_buffer.indexOf('MoggSampleResource') + 19; - console.log('uexp', data_buffer); - console.log('uexp length', old_uexp_length); // Write new MOGG Buffer length + 32 to offset start_offset data_buffer.writeInt32LE(mogg_buffer.length + 32, start_offset); // Write new MOGG Buffer length to offset start_offset + 36, store old for buffering const old_1_length = data_buffer.readInt32LE(start_offset + 36); - console.log("Old 1 length", old_1_length); data_buffer.writeInt32LE(mogg_buffer.length, start_offset + 36); - console.log("New 1 length", data_buffer.readInt32LE(start_offset + 36)); // Insert MOGG at start_offset + 36 + 4, then offset to the new position const pre_buffer_1 = data_buffer.slice(0, start_offset + 36 + 4); @@ -94,20 +91,16 @@ async function replace() { let final_buffer = song_1_insert_buffer; const filenameLength = final_buffer.readInt16LE(28); const numResourceFiles = final_buffer.readInt16LE(28 + filenameLength + 12); - console.log(final_buffer.length); if (numResourceFiles === 3) { + // Get the start offset by getting the first index of MoggSampleResource after our mogg_buffer, then offset by 19 const new_offset = song_1_insert_buffer.indexOf('MoggSampleResource', mogg_buffer.length) + 19; - console.log("New Offset", new_offset); - console.log("InsertBufferLength", song_1_insert_buffer.length); // Write new MOGG Buffer length + 32 to offset new_offset song_1_insert_buffer.writeInt32LE(mogg_buffer.length + 32, new_offset); // Write new MOGG Buffer length to offset new_offset + 36, store old for buffering const old_2_length = song_1_insert_buffer.readInt32LE(new_offset + 36); - console.log("Old 2 length", old_2_length); song_1_insert_buffer.writeInt32LE(mogg_buffer.length, new_offset + 36); - console.log("New 2 length", song_1_insert_buffer.readInt32LE(new_offset + 36)); // Insert MOGG at new_offset + 36 + 4, then offset to the new position const pre_buffer_2 = song_1_insert_buffer.slice(0, new_offset + 36 + 4); @@ -122,10 +115,8 @@ async function replace() { // Modify .uasset const uasset_buffer = await readFile(`game_input/${game_file}.uasset`); - console.log('Uassetbuffer', uasset_buffer); const update_size_offset = uasset_buffer.lastIndexOf(old_uexp_length - 4); - console.log("Update size offset", update_size_offset); uasset_buffer.writeInt32LE(final_buffer.length - 4, update_size_offset); // Finally, write