diff --git a/bin/PL01T.BIN b/bin/PL01T.BIN new file mode 100644 index 0000000..deb7edb Binary files /dev/null and b/bin/PL01T.BIN differ diff --git a/bun.lockb b/bun.lockb index 6c58055..9a3b6c3 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/head_debug.bin b/head_debug.bin new file mode 100644 index 0000000..8c814f6 Binary files /dev/null and b/head_debug.bin differ diff --git a/index.ts b/index.ts index 0bb8849..d0bc505 100644 --- a/index.ts +++ b/index.ts @@ -1,28 +1,28 @@ -import { doReplace } from './src/Encode'; +import { encodeModel } from './src/Encode'; -doReplace( - "Miku/miku_body.png", - "Miku/miku_face.png", +// No helmet + Normal Shoes +encodeModel( + "PL00P010.BIN", // Body Encoding - "Miku/02_BODY.obj", - "Miku/03_HIPS.obj", - "Miku/10_LEG_RIGHT_TOP.obj", - "Miku/11_LEG_RIGHT_BOTTOM.obj", - "Miku/13_LEG_LEFT_TOP.obj", - "Miku/14_LEG_LEFT_BOTTOM.obj", + "obj/02_BODY.obj", + "obj/03_HIPS.obj", + "obj/10_LEG_RIGHT_TOP.obj", + "obj/11_LEG_RIGHT_BOTTOM.obj", + "obj/13_LEG_LEFT_TOP.obj", + "obj/14_LEG_LEFT_BOTTOM.obj", // Feet - "Miku/12_RIGHT_FOOT.obj", - "Miku/15_LEFT_FOOT.obj", + "obj/12_RIGHT_FOOT.obj", + "obj/15_LEFT_FOOT.obj", // Left Arm - "Miku/07_LEFT_SHOULDER.obj", - "Miku/08_LEFT_ARM.obj", - "Miku/09_LEFT_HAND.obj", + "obj/07_LEFT_SHOULDER.obj", + "obj/08_LEFT_ARM.obj", + "obj/09_LEFT_HAND.obj", // Right Arm - "Miku/04_RIGHT_SHOULDER.obj", - "Miku/05_RIGHT_ARM.obj", - "Miku/06_RIGHT_HAND.obj", + "obj/04_RIGHT_SHOULDER.obj", + "obj/05_RIGHT_ARM.obj", + "obj/06_RIGHT_HAND.obj", // Head - "Miku/01_HEAD_HAIR.obj", - "Miku/01_HEAD_FACE.obj", - "Miku/01_HEAD_MOUTH.obj" + "obj/01_HEAD_HAIR.obj", + "obj/01_HEAD_FACE.obj", + "obj/01_HEAD_MOUTH.obj" ) \ No newline at end of file diff --git a/mod/PL00P010.BIN b/mod/PL00P010.BIN new file mode 100644 index 0000000..22ba8e5 Binary files /dev/null and b/mod/PL00P010.BIN differ diff --git a/package-lock.json b/package-lock.json index 481968d..7bc16c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,10 +7,12 @@ "name": "miku-legends-2", "dependencies": { "bytereader": "^0.1.0", + "pngjs": "^7.0.0", "three": "^0.165.0" }, "devDependencies": { "@types/bun": "latest", + "@types/pngjs": "^6.0.5", "@types/three": "^0.165.0" }, "peerDependencies": { @@ -41,6 +43,15 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/pngjs": { + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/@types/pngjs/-/pngjs-6.0.5.tgz", + "integrity": "sha512-0k5eKfrA83JOZPppLtS2C7OUtyNAl2wKNxfyYl9Q5g9lPkgBl/9hNyAu6HuEH2J4XmIv2znEpkDd0SaZVxW6iQ==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/stats.js": { "version": "0.17.3", "resolved": "https://registry.npmjs.org/@types/stats.js/-/stats.js-0.17.3.tgz", @@ -101,6 +112,14 @@ "integrity": "sha512-ZhoIoL7TNV4s5B6+rx5mC//fw8/POGyNxS/DZyCJeiZ12ScLfVwRE/GfsxwiTkMYYD5DmK2/JXnEVXqL4rF+Sw==", "dev": true }, + "node_modules/pngjs": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-7.0.0.tgz", + "integrity": "sha512-LKWqWJRhstyYo9pGvgor/ivk2w94eSjE3RGVuzLGlr3NmD8bf7RcYGze1mNdEHRP6TRP6rMuDHk5t44hnTRyow==", + "engines": { + "node": ">=14.19.0" + } + }, "node_modules/three": { "version": "0.165.0", "license": "MIT" diff --git a/package.json b/package.json index 7bb4561..ee28260 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "type": "module", "devDependencies": { "@types/bun": "latest", + "@types/pngjs": "^6.0.5", "@types/three": "^0.165.0" }, "peerDependencies": { @@ -11,6 +12,7 @@ }, "dependencies": { "bytereader": "^0.1.0", + "pngjs": "^7.0.0", "three": "^0.165.0" } } diff --git a/src/Encode.ts b/src/Encode.ts index d38f066..559a380 100644 --- a/src/Encode.ts +++ b/src/Encode.ts @@ -1,3 +1,4 @@ +import { write } from 'bun'; import { readFileSync, writeFileSync } from 'fs' import { PNG } from 'pngjs'; import { @@ -1073,9 +1074,8 @@ const replaceModel = ( return modded; } -const doReplace = ( - bodyTexture: string, - faceTexture: string, +const encodeModel = ( + filename: string, // Body Section bodyObject: string, hipsObject: string, @@ -1100,32 +1100,30 @@ const doReplace = ( mouthObject: string ) => { - // Read the source ROM file - const ROM = readFileSync('/home/kion/.pcsxr/roms/TRACK_01_READONLY.bin') - - // Encode the body and face texture to write to ROM - const srcTexture = readFileSync('pl01t.bin') - const bodyBuffer = readFileSync(bodyTexture); - const faceBuffer = readFileSync(faceTexture); - const modTexture = replaceTexture(srcTexture, bodyBuffer, faceBuffer) - const PL01T_POS = 0x3ebbd8; - replaceInRom(modTexture, PL01T_POS, ROM); - // Encode the body - const srcModel = readFileSync('pl01p000.bin') + const srcModel = readFileSync(`bin/${filename}`) const body = encodeModelBody(bodyObject, hipsObject, rLegTopObject, rLegBtmObject, lLegTopObject, lLegBtmObject); const feet = encodeModelFeet(rightFootObject, leftFootObject); const lArm = encodeModelLeftArm(leftShoulder, leftArm, leftHand); const rArm = encodeModelRightArm(rightShoulder, rightArm, rightHand); const head = encodeModelHead(hairObject, eyesObject, mouthObject); const updatedModel = replaceModel(srcModel, body, feet, lArm, rArm, head); - writeFileSync('miku_test.bin', updatedModel.subarray(0x30, 0x1f00 + 0x30)) + writeFileSync(`mod/${filename}`, updatedModel.subarray(0x30, 0x1f00 + 0x30)) +} - const PL01P000_POS = 0x3d4c58; - replaceInRom(updatedModel, PL01P000_POS, ROM); +const encodeTexture = ( + bodyTexture: string, + faceTexture: string, +) => { - // Write the updated ROM to be tested - writeFileSync('/home/kion/.pcsxr/roms/Mega Man Legends 2 (USA) (Track 1).bin', ROM) + // Encode the body and face texture to write to ROM + const srcTexture = readFileSync('bin/PL01T.BIN') + const bodyBuffer = readFileSync(bodyTexture); + const faceBuffer = readFileSync(faceTexture); + const modTexture = replaceTexture(srcTexture, bodyBuffer, faceBuffer) + writeFileSync('mod/PL01T.BIN', modTexture) } -export { doReplace } \ No newline at end of file + + +export { encodeModel, encodeTexture } \ No newline at end of file