code wiki / (root) / nx_witch_skin_replace_t140.nx

nx_witch_skin_replace_t140.nx source

↩ module page · 59 lines · 2411 B

1import "nx_nxa_write_lib.nx" 2func main(argc:i64,argv:*i64)->i64 { 3 if argc!=4 {return 2} 4 let sizes:*i64=sys_mmap(16) 5 if (sizes as i64)<=0 {return 3} 6 let source:*u8=sys_read_file(argv[1] as *u8,sizes) 7 let donor:*u8=sys_read_file(argv[2] as *u8,((sizes as i64)+8) as *i64) 8 if (source as i64)<=0||(donor as i64)<=0 {return 3} 9 let sh:*i64=source as *i64;let dh:*i64=donor as *i64 10 let skin:i64=nxa_tag4("SKIN" as *u8) 11 let se:i64=nxa_section_entry(source,sizes[0],skin) 12 let de:i64=nxa_section_entry(donor,sizes[1],skin) 13 let je:i64=nxa_section_entry(source,sizes[0],nxa_tag4("SKEL" as *u8)) 14 if se<0||de<0||je<0 {return 4} 15 let payload:*i64=((donor as i64)+dh[de+1]) as *i64 16 let joints:*i64=((source as i64)+sh[je+1]) as *i64 17 if dh[de+2]<1||sh[je+2]<1 {return 4} 18 let nv:i64=payload[0] 19 if nv<1||(dh[de+2]-1)%8!=0||nv!=(dh[de+2]-1)/8||dh[de+2]!=sh[se+2] {return 4} 20 var v:i64=0 21 while v<nv { 22 var sum:i64=0;var k:i64=0 23 while k<4 { 24 let j:i64=payload[1+v*8+k];let w:i64=payload[1+v*8+4+k] 25 if j<0||j>=joints[0]||w<0||w>NXW_Q12 {return 5} 26 sum=sum+w;k=k+1 27 } 28 if sum!=NXW_Q12 {return 5} 29 v=v+1 30 } 31 let out:*u8=sys_mmap(sizes[0]) 32 if (out as i64)<=0 {return 3} 33 let rc:i64=nxw_replace_same_size(source,sizes[0],skin,payload,dh[de+2],out,sizes[0]) 34 if rc!=sizes[0] {return 6} 35 let oh:*i64=out as *i64 36 var i:i64=0 37 while i<sh[2] { 38 let e:i64=4+i*4 39 if nxa_section_entry(out,rc,sh[e])!=e {return 6} 40 if sh[e]!=skin { 41 let a:*u8=((source as i64)+sh[e+1]) as *u8 42 let b:*u8=((out as i64)+oh[e+1]) as *u8 43 var n:i64=0 44 while n<sh[e+2]*8 {if a[n]!=b[n] {return 6}n=n+1} 45 } 46 i=i+1 47 } 48 let fd:i64=sys_openat_exclusive(argv[3] as *u8,NXW_MODE) 49 if fd<0 {return 7} 50 var sent:i64=0 51 while sent<rc {let wrote:i64=sys_write(fd,((out as i64)+sent) as *u8,rc-sent);if wrote<=0 {sys_close(fd);return 7}sent=sent+wrote} 52 let synced:i64=sys_fsync(fd);let closed:i64=sys_close(fd) 53 if synced!=0||closed!=0 {return 7} 54 let message:*u8="SKIN-REPLACE PASS semantic_weights all_sections_checked unrelated_payloads_identical exclusive_checked_write\n" as *u8 55 var length:i64=0 56 while message[length]!=0 as u8 {length=length+1} 57 sys_write(1,message,length) 58 return 0 59}