import { SaveFileReader } from "../../save-file/SaveFileReader" ; import { Character } from "../types" ; import { parseAttributes } from "./parseAttributes" ; import { parseItemList } from "../../items/parsing/parseItemList" ; import { parseMercenary } from "./parseMercenary" ; import { postProcessCharacter } from "./postProcessCharacter" ; import { parseCorpses } from "./parseCorpses" ; export function parseCharacter ( raw , file ? ) { const reader = new SaveFileReader ( raw ) ; const header = reader . readInt32LE ( ) . toString ( 16 ) ; if ( header !== "aa55aa55" ) { throw new Error ( "This does not look like a Diablo 2 character save (.d2s)" ) ; } const character = { filename : file ?. name ?? "" , lastModified : file ?. lastModified ?? 0 , version : reader . readInt32LE ( 4 ) , name : reader . readNullTerminatedString ( 20 ) , class : reader . readInt8 ( 40 ) , hasCorpse : false , hasMercenary : ! ! reader . readInt32LE ( 179 ) , characterData : new Uint8Array ( ) , golem : new Uint8Array ( ) , items : [ ] , } ; parseAttributes ( reader ) ; reader . readString ( 32 ) ; character . characterData = reader . read ( reader . nextIndex - 16 , 16 ) ; character . items . push ( ... parseItemList ( reader , character ) ) ; parseCorpses ( reader , character ) ; const expansionChar = true ; if ( expansionChar ) { parseMercenary ( reader , character ) ; character . golem = reader . readRemaining ( ) ; } postProcessCharacter ( character ) ; return character ; }