Kyiro
Kyiro
DDeno
Created by Kyiro on 7/7/2023 in #help
FFI string corrupted?
Is there anything i'm doing wrong here? I'm confused on why it's crashing on setVerisonUE5 in particular. The code without FFI in C++ works fine
import { Dataminer } from "./mod.ts";

Dataminer.withLogs(true);
Dataminer.setOodle("...");

const core = new Dataminer("...");
console.log(core); // printed
core.setVersionUE5(1008); // crashes here?
console.log("set version"); // not printed
import { Dataminer } from "./mod.ts";

Dataminer.withLogs(true);
Dataminer.setOodle("...");

const core = new Dataminer("...");
console.log(core); // printed
core.setVersionUE5(1008); // crashes here?
console.log("set version"); // not printed
const DLL_PATH = "...";

const library = Deno.dlopen(DLL_PATH, {
"dataminer_options_with_oodle": {
parameters: ["buffer"],
result: "void"
},
"dataminer_with_logging": {
parameters: ["bool"],
result: "void"
},
"dataminer_construct": {
parameters: ["buffer"],
result: "pointer"
},
"dataminer_set_version_ue5": {
parameters: ["pointer", "i32"],
result: "void"
}
});

function encode(text: string) {
return new TextEncoder().encode(text);
}

export class Dataminer {
pointer: Deno.PointerValue;

constructor(paksDir: string) {
this.pointer = library.symbols.dataminer_construct(encode(paksDir));
}

checkPointer() {
if (!this.pointer) throw new Error("pointer is null");
}

static setOodle(oodlePath: string) {
library.symbols.dataminer_options_with_oodle(encode(oodlePath));
}

static withLogs(shouldLog: boolean) {
library.symbols.dataminer_with_logging(shouldLog);
}

setVersionUE5(version: number) {
this.checkPointer();
library.symbols.dataminer_set_version_ue5(this.pointer, version);
}
}
const DLL_PATH = "...";

const library = Deno.dlopen(DLL_PATH, {
"dataminer_options_with_oodle": {
parameters: ["buffer"],
result: "void"
},
"dataminer_with_logging": {
parameters: ["bool"],
result: "void"
},
"dataminer_construct": {
parameters: ["buffer"],
result: "pointer"
},
"dataminer_set_version_ue5": {
parameters: ["pointer", "i32"],
result: "void"
}
});

function encode(text: string) {
return new TextEncoder().encode(text);
}

export class Dataminer {
pointer: Deno.PointerValue;

constructor(paksDir: string) {
this.pointer = library.symbols.dataminer_construct(encode(paksDir));
}

checkPointer() {
if (!this.pointer) throw new Error("pointer is null");
}

static setOodle(oodlePath: string) {
library.symbols.dataminer_options_with_oodle(encode(oodlePath));
}

static withLogs(shouldLog: boolean) {
library.symbols.dataminer_with_logging(shouldLog);
}

setVersionUE5(version: number) {
this.checkPointer();
library.symbols.dataminer_set_version_ue5(this.pointer, version);
}
}
23 replies
DDeno
Created by Kyiro on 6/19/2023 in #help
deno_core usage
Are there any repos using deno_core in their code + how would I enable the unstable features and URL imports?
20 replies