Skip to content

Commit

Permalink
try ncoding model
Browse files Browse the repository at this point in the history
  • Loading branch information
kion-dgl committed Jul 11, 2024
1 parent 992e997 commit 82498fd
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 42 deletions.
Binary file added bin/PL01T.BIN
Binary file not shown.
Binary file modified bun.lockb
Binary file not shown.
Binary file added head_debug.bin
Binary file not shown.
42 changes: 21 additions & 21 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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"
)
Binary file added mod/PL00P010.BIN
Binary file not shown.
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"type": "module",
"devDependencies": {
"@types/bun": "latest",
"@types/pngjs": "^6.0.5",
"@types/three": "^0.165.0"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"bytereader": "^0.1.0",
"pngjs": "^7.0.0",
"three": "^0.165.0"
}
}
40 changes: 19 additions & 21 deletions src/Encode.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { write } from 'bun';
import { readFileSync, writeFileSync } from 'fs'
import { PNG } from 'pngjs';
import {
Expand Down Expand Up @@ -1073,9 +1074,8 @@ const replaceModel = (
return modded;
}

const doReplace = (
bodyTexture: string,
faceTexture: string,
const encodeModel = (
filename: string,
// Body Section
bodyObject: string,
hipsObject: string,
Expand All @@ -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 }


export { encodeModel, encodeTexture }

0 comments on commit 82498fd

Please sign in to comment.