-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start parsing monster information
- Loading branch information
Showing
12 changed files
with
214 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { LangReader, LangNode } from './lang/lang.reader'; | ||
export { MonsterReader, MonsterNode } from './monster/monster.stat.reader'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
import { bp } from 'binparse'; | ||
import { bp, StrutInfer } from 'binparse'; | ||
|
||
const Monster = bp.object('Monster', { | ||
const MonsterParser = bp.object('Monster', { | ||
id: bp.lu16, | ||
baseId: bp.lu16, | ||
baseNextId: bp.lu16, | ||
/** Name index, lookup inside of lang index */ | ||
name: bp.lu16, | ||
/** Description lookup inside of lang index */ | ||
description: bp.lu16, | ||
unk1: bp.lu16, | ||
flags: bp.lu32, | ||
code: bp.lu32, | ||
unk100: bp.skip(424 - 20), | ||
}); | ||
|
||
export type MonsterNode = StrutInfer<typeof MonsterParser>; | ||
|
||
export const MonsterReader = bp.object('Monsters', { | ||
count: bp.variable('count', bp.lu32), | ||
monsters: bp.array('Monster', Monster, 'count'), | ||
monsters: bp.array('Monster', MonsterParser, 'count'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import o from 'ospec'; | ||
import { NpcAssign } from '../server'; | ||
|
||
o.spec('NpcAssign', () => { | ||
o('should load a hungry dead', () => { | ||
const npc = NpcAssign.parse(Buffer.from('acc400000006005514fd13801131400400', 'hex'), { | ||
startOffset: 0, | ||
offset: 1, | ||
}); | ||
o(npc.unitId).equals(196); | ||
o(npc.x).equals(5205); | ||
o(npc.y).equals(5117); | ||
o(npc.life).equals(128); | ||
}); | ||
|
||
o('should parse a low health fallen', () => { | ||
const npc = NpcAssign.parse(Buffer.from('ace70000001300b114e4102a1111c80000', 'hex'), { | ||
startOffset: 0, | ||
offset: 1, | ||
}); | ||
o(npc.life).equals(42); | ||
}); | ||
o('should parse super unique Rakanishu', () => { | ||
const npc = NpcAssign.parse(Buffer.from('acc500000014003b14eb138019110480660020c2c002207219', 'hex'), { | ||
startOffset: 0, | ||
offset: 1, | ||
}); | ||
|
||
o(npc.x).equals(5179); | ||
o(npc.y).equals(5099); | ||
o(npc.life).equals(128); | ||
o(npc.code).equals(20); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Diablo2GameSession } from '@diablo2/core'; | ||
import { ItemActionType, ItemQuality } from '@diablo2/data'; | ||
import { ItemActionWorld } from '@diablo2/packets/build/packets-pod/server'; | ||
import * as c from 'ansi-colors'; | ||
import { Diablo2PacketSniffer } from '../sniffer'; | ||
|
||
/** Track all items dropped onto the ground */ | ||
export function sniffItems(sniffer: Diablo2PacketSniffer): void { | ||
sniffer.onNewGame((game: Diablo2GameSession) => { | ||
console.log('NewSessionStarted'); | ||
game.parser.on(ItemActionWorld, (pkt) => { | ||
// Ignore items being moved around | ||
if (pkt.action.id !== ItemActionType.AddToGround) return; | ||
// Ignore gold | ||
if (pkt.code == 'gld') return; | ||
// Ignore things like scrolls/ health potion | ||
if (pkt.flags.isSimpleItem) return; | ||
|
||
const obj = JSON.parse(JSON.stringify({ sockets: pkt.sockets, quality: pkt.quality?.name, def: pkt.defense })); | ||
switch (pkt.quality.id) { | ||
case ItemQuality.Inferior: | ||
case ItemQuality.Normal: | ||
case ItemQuality.Superior: | ||
case ItemQuality.Magic: | ||
case ItemQuality.Rare: | ||
console.log(pkt.code, sniffer.client.lang.get(pkt.code), obj); | ||
break; | ||
case ItemQuality.Set: | ||
console.log(c.green(pkt.code), sniffer.client.lang.get(pkt.code), obj); | ||
break; | ||
case ItemQuality.Unique: | ||
console.log(c.yellow(pkt.code), sniffer.client.lang.get(pkt.code), obj); | ||
break; | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Diablo2GameSession } from '@diablo2/core'; | ||
import { NpcAssign } from '@diablo2/packets/build/packets-pod/server'; | ||
import * as c from 'ansi-colors'; | ||
import { Diablo2PacketSniffer } from '../sniffer'; | ||
|
||
/** Track all NPCs that are being reported */ | ||
export function sniffNpc(sniffer: Diablo2PacketSniffer): void { | ||
sniffer.onNewGame((game: Diablo2GameSession) => { | ||
game.parser.on(NpcAssign, (npc) => { | ||
const npcInfo = game.client.monsters.get(npc.code); | ||
const monsterName = npcInfo == null ? 'Unknown' : game.client.lang.get(npcInfo.name); | ||
console.log(c.red('Npc'), monsterName, `@ ${npc.x},${npc.y}`); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createWriteStream, WriteStream } from 'fs'; | ||
|
||
/** Automatically close a write stream after 5 seconds of inactivity */ | ||
export class AutoClosingStream { | ||
_stream: WriteStream | null; | ||
_streamClose: NodeJS.Timer | null; | ||
fileName: string; | ||
closeTimeout: number; | ||
|
||
constructor(fileName: string, closeTimeout = 5 * 1000) { | ||
this.fileName = fileName; | ||
this.closeTimeout = closeTimeout; | ||
} | ||
|
||
closeStream = (): void => { | ||
this._stream?.close(); | ||
this._stream = null; | ||
this._streamClose = null; | ||
}; | ||
|
||
write(obj: unknown): void { | ||
if (this._streamClose != null) clearTimeout(this._streamClose); | ||
|
||
if (this._stream == null) { | ||
this._stream = createWriteStream(this.fileName, { flags: 'a' }); | ||
} | ||
this._streamClose = setTimeout(this.closeStream, 5 * 1000); | ||
this._stream.write(JSON.stringify(obj) + '\n'); | ||
} | ||
} |
Oops, something went wrong.