Skip to content

Commit

Permalink
update pathofexile-dat
Browse files Browse the repository at this point in the history
  • Loading branch information
SnosMe committed Nov 15, 2023
1 parent 243dac3 commit 981e6e2
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: wasm-artifact
path: lib/src/dat-analysis/zig-out/lib/analysis.wasm
path: lib/src/dat-analysis/zig-out/bin/analysis.wasm
retention-days: 1
if-no-files-found: error

Expand Down
11 changes: 5 additions & 6 deletions lib/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
{
"name": "pathofexile-dat",
"version": "8.0.0",
"version": "9.0.0",
"type": "module",
"bin": "./dist/cli/run.js",
"exports": {
"./bundles.js": "./dist/bundles.js",
"./dat.js": "./dist/dat.js",
"./analysis.wasm": "./dist/analysis.wasm"
"./dat.js": "./dist/dat.js"
},
"files": ["dist/**/*"],
"license": "MIT",
"repository": {
"url": "https://github.com/SnosMe/poe-dat-viewer"
},
"dependencies": {
"ooz-wasm": "^1.0.0",
"pathofexile-dat-schema": "^3.0.0"
"ooz-wasm": "^2.0.0",
"pathofexile-dat-schema": "^4.0.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"typescript": "^4.3.0"
"typescript": "^5.2.0"
},
"engines": {
"node": ">=18.0.0"
Expand Down
6 changes: 3 additions & 3 deletions lib/src/bundles/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const S_CHUNK_COUNT$ = 36
const S_COMPRESSION_GRANULARITY$ = 40
const S_CHUNK_SIZES$ = 60

export async function decompressSliceInBundle (
export function decompressSliceInBundle (
bundle: Uint8Array,
sliceOffset = 0,
sliceSize = 0
): Promise<Uint8Array> {
): Uint8Array {
const reader = new DataView(bundle.buffer, bundle.byteOffset, bundle.byteLength)
const decompressedBundleSize = reader.getInt32(S_DECOMPRESSED_DATA_SIZE$, true)
const chunksCount = reader.getInt32(S_CHUNK_COUNT$, true)
Expand Down Expand Up @@ -40,7 +40,7 @@ export async function decompressSliceInBundle (
const begin = Math.max(sliceOffset - bundleDecomprOffset, 0)
const end = Math.min((sliceOffset + sliceSize) - bundleDecomprOffset, decomprChunkSize)

const raw = await Ooz.decompressUnsafe(chunk, decomprChunkSize)
const raw = Ooz.decompressUnsafe(chunk, decomprChunkSize)
decompressedSlice.set(raw.subarray(begin, end), sliceDecomprOffset)

sliceDecomprOffset += (end - begin)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/cli/bundle-loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class FileLoader {
console.log('Loading bundles index...')

const indexBin = await bundleLoader.fetchFile('_.index.bin')
const indexBundle = await decompressSliceInBundle(new Uint8Array(indexBin))
const indexBundle = decompressSliceInBundle(new Uint8Array(indexBin))
const _index = readIndexBundle(indexBundle)

return new FileLoader(bundleLoader, {
Expand All @@ -41,7 +41,7 @@ export class FileLoader {
async getFileContents (fullPath: string) {
const location = getFileInfo(fullPath, this.index.bundlesInfo, this.index.filesInfo)
const bundleBin = await this.fetchBundle(location.bundle)
return await decompressSliceInBundle(new Uint8Array(bundleBin), location.offset, location.size)
return decompressSliceInBundle(new Uint8Array(bundleBin), location.offset, location.size)
}

clearBundleCache () {
Expand Down
7 changes: 5 additions & 2 deletions lib/src/dat-analysis/analysis.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const std = @import("std");
const readInt = std.mem.readIntSliceLittle;

inline fn readInt(comptime T: type, buffer: []const u8) T {
return std.mem.readInt(T, buffer[0..@sizeOf(T)], .little);
}

pub export fn malloc(size: usize) [*]u8 {
const slice = std.heap.page_allocator.alloc(u8, size) catch unreachable;
Expand Down Expand Up @@ -81,7 +84,7 @@ fn analyzeDat(

var ri: usize = 0;
while (ri < rowCount) : (ri += 1) {
const row = dataFixed[ri*rowLength .. (ri + 1)*rowLength];
const row = dataFixed[ri*rowLength..][0..rowLength];

for (stats, 0..) |*stat, bi| {
const byte = row[bi];
Expand Down
3 changes: 2 additions & 1 deletion lib/src/dat-analysis/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn build(b: *std.Build) void {
});
const optimize = b.standardOptimizeOption(.{});

const module = b.addSharedLibrary(.{
const module = b.addExecutable(.{
.name = "analysis",
.root_source_file = .{ .path = "./analysis.zig" },
.target = target,
Expand All @@ -20,5 +20,6 @@ pub fn build(b: *std.Build) void {
module.export_symbol_names = &[_][]const u8{
"malloc", "free", "fast_analyze_dat64",
};
module.entry = .disabled;
b.installArtifact(module);
}
8 changes: 3 additions & 5 deletions lib/src/dat-analysis/wasm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { DatFile } from '../dat/dat-file.js'
import type { ColumnStats } from './stats.js'

let _module: ModuleExports
const _module = (await WebAssembly.instantiateStreaming(
fetch(new URL('../analysis.wasm', import.meta.url))
)).instance.exports as unknown as ModuleExports

type AnalyzeFn = (
dataFixedPtr: number, dataFixed_len: number,
Expand All @@ -17,10 +19,6 @@ interface ModuleExports {
free: (ptr: number, size: number) => void
}

export function setWasmExports (module: ModuleExports) {
_module = module
}

export function analyzeDatFile (file: DatFile): ColumnStats[] {
if (!file.dataFixed.byteLength) return []

Expand Down
2 changes: 1 addition & 1 deletion lib/src/dat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { type DatFile, readDatFile } from './dat/dat-file.js'
export { getFieldReader, readColumn } from './dat/reader.js'
export { type Header, getHeaderLength } from './dat/header.js'
export { analyzeDatFile, setWasmExports } from './dat-analysis/wasm.js'
export { analyzeDatFile } from './dat-analysis/wasm.js'
export { validateHeader } from './dat-analysis/validation.js'
export { type ColumnStats } from './dat-analysis/stats.js'

0 comments on commit 981e6e2

Please sign in to comment.