Skip to content

Commit

Permalink
Fix typed arrays of scripts not being decoded properly (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
mihe authored Oct 11, 2024
1 parent 4404b76 commit 0a632d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/debugger/godot4/variables/variant_decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import {
Projection,
ENCODE_FLAG_64,
ENCODE_FLAG_OBJECT_AS_ID,
ENCODE_FLAG_TYPED_ARRAY,
ENCODE_FLAG_TYPED_ARRAY_MASK,
ENCODE_FLAG_TYPED_ARRAY_BUILTIN,
ENCODE_FLAG_TYPED_ARRAY_CLASS_NAME,
ENCODE_FLAG_TYPED_ARRAY_SCRIPT,
RID,
Callable,
Signal,
Expand Down Expand Up @@ -144,8 +147,10 @@ export class VariantDecoder {
case GDScriptTypes.DICTIONARY:
return this.decode_Dictionary(model);
case GDScriptTypes.ARRAY:
if (type & ENCODE_FLAG_TYPED_ARRAY) {
return this.decode_TypedArray(model);
if (type & ENCODE_FLAG_TYPED_ARRAY_MASK) {
const with_script_name = (type & ENCODE_FLAG_TYPED_ARRAY_CLASS_NAME) != 0;
const with_script_path = (type & ENCODE_FLAG_TYPED_ARRAY_SCRIPT) != 0;
return this.decode_TypedArray(model, with_script_name || with_script_path);
} else {
return this.decode_Array(model);
}
Expand Down Expand Up @@ -231,13 +236,12 @@ export class VariantDecoder {
return output;
}

private decode_TypedArray(model: BufferModel) {
private decode_TypedArray(model: BufferModel, with_scripts: boolean) {
const output: Array<any> = [];

// TODO: the type information is currently discarded
// it needs to be decoded and then packed into the output somehow

const type = this.decode_UInt32(model);
const type = with_scripts ? this.decode_String(model) : this.decode_UInt32(model);
const count = this.decode_UInt32(model);

for (let i = 0; i < count; i++) {
Expand Down
5 changes: 4 additions & 1 deletion src/debugger/godot4/variables/variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export enum GDScriptTypes {

export const ENCODE_FLAG_64 = 1 << 16;
export const ENCODE_FLAG_OBJECT_AS_ID = 1 << 16;
export const ENCODE_FLAG_TYPED_ARRAY = 1 << 16;
export const ENCODE_FLAG_TYPED_ARRAY_MASK = 3 << 16;
export const ENCODE_FLAG_TYPED_ARRAY_BUILTIN = 1 << 16;
export const ENCODE_FLAG_TYPED_ARRAY_CLASS_NAME = 2 << 16;
export const ENCODE_FLAG_TYPED_ARRAY_SCRIPT = 3 << 16;

export interface BufferModel {
buffer: Buffer;
Expand Down

0 comments on commit 0a632d6

Please sign in to comment.