Skip to content

Commit

Permalink
Fix DATA_TYPE tag and improve performance of rearranging tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Darxoon committed Jun 18, 2023
1 parent 7fb2fbc commit 7a78992
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 32 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PUBLIC_OW_VERSION=Development Build
PUBLIC_VERSION_TIMESTAMP=""
PUBLIC_IS_DEV_VERSION=1
PUBLIC_DEBUG=1
PUBLIC_TRACE=0
2 changes: 1 addition & 1 deletion publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ git switch master > /dev/null

echo
echo 'Build instruction (ran in build branch):'
echo PUBLIC_OW_VERSION='"'"$tag"'"' PUBLIC_VERSION_TIMESTAMP=$(date +%s)000 PUBLIC_IS_DEV_VERSION=0 npm run build
echo PUBLIC_OW_VERSION='"'"$tag"'"' PUBLIC_VERSION_TIMESTAMP=$(date +%s)000 PUBLIC_IS_DEV_VERSION=0 PUBLIC_DEBUG=0 npm run build
41 changes: 21 additions & 20 deletions src/elf/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Instance } from "./fileTypes";
import { BinaryReader, Vector3 } from "./misc";
import { demangle, mangleIdentifier } from "./nameMangling";
import { Relocation, Section, Symbol } from "./types";
import { ValueUuid, VALUE_UUID, DATA_TYPE } from "./valueIdentifier";
import { ValueUuid, VALUE_UUID, DATA_TYPE, type UuidTagged } from "./valueIdentifier";

type Typedef<T> = {[fieldName: string]: T}

Expand Down Expand Up @@ -127,7 +127,7 @@ export default function parseElfBinary(dataType: DataType, arrayBuffer: ArrayBuf
allRelocations.get('.rodata'),
symbolTable,

parseRawDataSection(rodataSection, count, offset.value, FILE_TYPES[dataType].typedef),
parseRawDataSection(rodataSection, count, offset.value, dataType),
)

offsetReference?.set(offset.value, result)
Expand Down Expand Up @@ -260,7 +260,7 @@ export default function parseElfBinary(dataType: DataType, arrayBuffer: ArrayBuf
Pointer.ZERO, dataType, dataStringSection,
allRelocations.get('.data'), symbolTable,

parseRawDataSection(dataSection, dataCount, 0, FILE_TYPES[dataType].typedef),
parseRawDataSection(dataSection, dataCount, 0, dataType),
)

modelSymbolReference = new WeakMap(data.main.map(obj => [obj, obj.id as string]))
Expand All @@ -286,7 +286,7 @@ export default function parseElfBinary(dataType: DataType, arrayBuffer: ArrayBuf
Pointer.ZERO, dataType, dataStringSection,
allRelocations.get('.data'), symbolTable,

parseRawDataSection(dataSection, count, 0, FILE_TYPES[dataType].typedef),
parseRawDataSection(dataSection, count, 0, dataType),
)

break
Expand Down Expand Up @@ -314,7 +314,7 @@ export default function parseElfBinary(dataType: DataType, arrayBuffer: ArrayBuf
dataSymbol.location, DataType.ConfettiData, dataStringSection,
allRelocations.get('.rodata'), symbolTable,

parseRawDataSection(rodataSection, 1, dataSymbol.location.value, FILE_TYPES[DataType.ConfettiData].typedef),
parseRawDataSection(rodataSection, 1, dataSymbol.location.value, DataType.ConfettiData),
)

data.dataHeader = dataArray
Expand All @@ -326,7 +326,7 @@ export default function parseElfBinary(dataType: DataType, arrayBuffer: ArrayBuf
mapListOffset, DataType.ConfettiMap, dataStringSection,
allRelocations.get('.rodata'), symbolTable,

parseRawDataSection(rodataSection, mapCount, mapListOffset.value, FILE_TYPES[DataType.ConfettiMap].typedef),
parseRawDataSection(rodataSection, mapCount, mapListOffset.value, DataType.ConfettiMap),
)
console.log(maps)

Expand All @@ -342,7 +342,7 @@ export default function parseElfBinary(dataType: DataType, arrayBuffer: ArrayBuf
holeOffset, DataType.ConfettiHole, dataStringSection,
allRelocations.get('.rodata'), symbolTable,

parseRawDataSection(rodataSection, holeCount, holeOffset.value, FILE_TYPES[DataType.ConfettiHole].typedef),
parseRawDataSection(rodataSection, holeCount, holeOffset.value, DataType.ConfettiHole),
)

holesByOffset.set(holeOffset.value, result)
Expand Down Expand Up @@ -392,7 +392,7 @@ export default function parseElfBinary(dataType: DataType, arrayBuffer: ArrayBuf
dataSymbol.location, dataType, dataStringSection,
allRelocations.get('.rodata'), symbolTable,

parseRawDataSection(rodataSection, dataCount, dataSymbol.location.value, FILE_TYPES[dataType].typedef),
parseRawDataSection(rodataSection, dataCount, dataSymbol.location.value, dataType),
)

data.main = dataObjects
Expand Down Expand Up @@ -429,7 +429,7 @@ export default function parseElfBinary(dataType: DataType, arrayBuffer: ArrayBuf
offset, DataType.UiModelProperty, stringSection,
allRelocations.get('.data'), symbolTable,

parseRawDataSection(dataSection, propertyCount, offset, FILE_TYPES[DataType.UiModelProperty].typedef),
parseRawDataSection(dataSection, propertyCount, offset, DataType.UiModelProperty),
)

// TODO: try to find the symbol name at offset `offset` rather than making this assumption
Expand Down Expand Up @@ -553,7 +553,7 @@ export default function parseElfBinary(dataType: DataType, arrayBuffer: ArrayBuf
offset, DataType.BtlAttackRange, stringSection,
allRelocations.get('.data'), symbolTable,

parseRawDataSection(dataSection, 1, offset, FILE_TYPES[DataType.BtlAttackRange].typedef),
parseRawDataSection(dataSection, 1, offset, DataType.BtlAttackRange),
)

let attackRange = {
Expand Down Expand Up @@ -711,7 +711,7 @@ export default function parseElfBinary(dataType: DataType, arrayBuffer: ArrayBuf
Pointer.ZERO, dataType, dataStringSection,
allRelocations.get('.data'), symbolTable,

parseRawDataSection(dataSection, count, 0, FILE_TYPES[dataType].typedef),
parseRawDataSection(dataSection, count, 0, dataType),
)

break
Expand Down Expand Up @@ -740,13 +740,13 @@ export default function parseElfBinary(dataType: DataType, arrayBuffer: ArrayBuf
return applyStrings(
symbol.location, dataType, stringSection, allRelocations.get(containingSection.name), symbolTable,

parseRawDataSection(containingSection, count, symbol.location, FILE_TYPES[dataType].typedef),
parseRawDataSection(containingSection, count, symbol.location, dataType),
)
}
}


function parseRawDataSection(section: Section, count: number, initialPosition: number | Pointer, typedef: Typedef<string>): object[] {
function parseRawDataSection(section: Section, count: number, initialPosition: number | Pointer, dataType: DataType): UuidTagged[] {
const reader = new BinaryReader(section.content)

reader.position = initialPosition instanceof Pointer ? initialPosition.value : initialPosition
Expand All @@ -755,18 +755,19 @@ function parseRawDataSection(section: Section, count: number, initialPosition: n
let i = 0

while (reader.position < section.content.byteLength && i < count) {
result.push(objFromReader(reader, typedef))
result.push(objFromReader(reader, dataType))
i += 1
}

return result

function objFromReader(reader: BinaryReader, typedef: {[fieldName: string]: string}): object {
let result = {}

result[VALUE_UUID] = ValueUuid()
function objFromReader(reader: BinaryReader, dataType: DataType): UuidTagged {
let result = {
[VALUE_UUID]: ValueUuid(),
[DATA_TYPE]: dataType,
}

for (const [fieldName, fieldType] of Object.entries(typedef)) {
for (const [fieldName, fieldType] of Object.entries(FILE_TYPES[dataType].typedef)) {

switch (fieldType) {
case "string":
Expand Down Expand Up @@ -820,7 +821,7 @@ function parseRawDataSection(section: Section, count: number, initialPosition: n
}

function applyStrings<T extends DataType>(baseOffsetPointer: Pointer, dataType: T, stringSection: Section,
relocationTable: Map<number, Relocation>, symbolTable: Symbol[], objects: object[]): Instance<T>[] {
relocationTable: Map<number, Relocation>, symbolTable: Symbol[], objects: UuidTagged[]): Instance<T>[] {

let result = []

Expand Down
8 changes: 8 additions & 0 deletions src/lib/editor/fileEditor/ElfEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
export let dataType: DataType
// TODO: will be replaced by separate tab object types for implicit objects or explicitly added objects
export let overrideObjects: UuidTagged[] | undefined = undefined
// TODO: move this into the future tab switch component
export let tabVisible: boolean
let initialized = tabVisible
let arrayComponent: BasicObjectArray
Expand All @@ -26,6 +30,8 @@
$: objects = overrideObjects ?? binary.data[FILE_TYPES[dataType].objectType]
$: index = createIndex(objects)
$: if (tabVisible) initialized = true
$: highlightedFields = searchResults && new WeakMap(
searchResultObjects.map(obj => [
obj,
Expand Down Expand Up @@ -132,6 +138,7 @@
}
</script>

{#if initialized}
<div class="editor">
<!-- TODO: if objects contain symbol references, it's important that there is always one object left -->
<!-- Ask for confirmation in this case when pressing Delete All -->
Expand All @@ -154,6 +161,7 @@
dataType={DataType.MaplinkHeader} showButtons={false} binary={binary} />
{/if}
</div>
{/if}

<style lang="scss">
.resultlabel {
Expand Down
27 changes: 20 additions & 7 deletions src/lib/editor/fileEditor/objectList/BasicObjectArray.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script lang="ts">
import ObjectEditor from "$lib/editor/objectEditor/ObjectEditor.svelte";
import type { DataType, ElfBinary } from "paper-mario-elfs/elfBinary";
import { DataType, type ElfBinary } from "paper-mario-elfs/elfBinary";
import { FILE_TYPES } from "paper-mario-elfs/fileTypes";
import { demangle } from "paper-mario-elfs/nameMangling";
import { duplicateObjectInBinary, duplicateSymbolInBinary } from "paper-mario-elfs/util";
import { VALUE_UUID, type UuidTagged } from "paper-mario-elfs/valueIdentifier";
import { VALUE_UUID, type UuidTagged, DATA_TYPE } from "paper-mario-elfs/valueIdentifier";
import Debouncer from "./Debouncer.svelte";
import { onMount } from "svelte";
import { PUBLIC_DEBUG } from "$env/static/public";
export let binary: ElfBinary
export let objects: UuidTagged[]
Expand All @@ -23,10 +25,21 @@
$: if (objects && debouncer) debouncer.reset()
$: if (objects.find(x => x[VALUE_UUID] == undefined) != undefined) {
console.error("Not all objects have a UUID")
debugger
}
onMount(() => {
let isDebug = !!parseInt(PUBLIC_DEBUG)
if (isDebug && !objects.every(x => x[VALUE_UUID] != undefined)) {
debugger
throw new Error("Not all objects have a UUID")
}
// TODO: replace with opt-in entry-specific data type handling
if (isDebug && !objects.every(value => value[DATA_TYPE] == dataType)) {
debugger
throw new Error("Objects of inconsistent data types passed to BasicObjectArray of data type " + DataType[dataType])
}
})
export function scrollIntoView(object?: UuidTagged) {
let index = object ? objects.indexOf(object) : objects.length - 1
Expand Down Expand Up @@ -97,7 +110,7 @@
}
</script>

<Debouncer bind:this={debouncer} autoStart={true} on:finished={() => countShown += 80} />
<Debouncer bind:this={debouncer} requiredDelaySeconds={2} autoStart={true} on:finished={() => countShown += 80} />

{#each objectSlice as obj, i (obj[VALUE_UUID])}
<ObjectEditor bind:this={objectEditors[i]} bind:obj={obj} bind:open={areEditorsOpen[i]}
Expand Down
10 changes: 8 additions & 2 deletions src/lib/editor/windowing/EditorTabBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@
return
if (state == 'dragging') {
console.log('ending movement', debugIndex, floatingInsertIndex, floating)
logging.trace('ending movement', debugIndex, floatingInsertIndex, floating)
let tabsUnchanged = immediateTabs.length == tabs.length
&& immediateTabs.every((value, index) => value === tabs[index])
if (!tabsUnchanged) {
tabs = [...immediateTabs]
}
tabs = [...immediateTabs]
activeIndex = clamp(floatingInsertIndex, 0, tabs.length - 1)
if (!hasFloatingOwnership) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/editor/windowing/EditorWindow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ Do you want to close those too?`,
<p class="loadinglabel">Loading...</p>
{/if}

{#each tabs as tab, i}
{#each tabs as tab, i (tab.id)}
<div class:invisible={selectedIndex != i}>
<svelte:component this={tab.component} {...tab.properties} bind:this={contentElements[i]} on:open on:valueChanged />
<svelte:component this={tab.component} tabVisible={selectedIndex == i} {...tab.properties} bind:this={contentElements[i]} on:open on:valueChanged />
</div>
{/each}

Expand Down

0 comments on commit 7a78992

Please sign in to comment.