private void Tokens_ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { BytecodeSingularToken selectedToken = Tokens_ListBox.SelectedItem as BytecodeSingularToken; if (selectedToken != null && !HexBoxSelectionChanging) { TokenChanging = true; ScriptEditor_Hexbox.SelectionStart = selectedToken.StartPos; ScriptEditor_Hexbox.SelectionLength = 1; TokenChanging = false; } }
public BytecodeSingularToken ToBytecodeSingularToken(int scriptStartOffset) { BytecodeSingularToken bcst = new BytecodeSingularToken(); string opcodetext = OpCode.ToString(); if (NativeIndex > 0) { var function = CachedNativeFunctionInfo.GetNativeFunction(NativeIndex); //this could be done dynamically. But if you're able to add native functions to the exe you probably know more about the engine than me if (function != null) { opcodetext = function.Name; } } opcodetext = $"[{((byte)OpCode):X2}] {opcodetext}"; bcst.CurrentStack = _text; bcst.OpCode = opcodetext; bcst.StartPos = _offset + scriptStartOffset; return(bcst); }
private void hb1_SelectionChanged(object sender, EventArgs e) { if (!TokenChanging) { HexBoxSelectionChanging = true; int start = (int)ScriptEditor_Hexbox.SelectionStart; int len = (int)ScriptEditor_Hexbox.SelectionLength; int size = (int)ScriptEditor_Hexbox.ByteProvider.Length; //TODO: Optimize this so this is only called when data has changed byte[] currentData = (ScriptEditor_Hexbox.ByteProvider as DynamicByteProvider).Bytes.ToArray(); try { if (currentData != null && start != -1 && start < size) { string s = $"Byte: {currentData[start]}"; //if selection is same as size this will crash. if (start <= currentData.Length - 4) { int val = BitConverter.ToInt32(currentData, start); s += $", Int: {val}"; s += $", Float: {BitConverter.ToSingle(currentData, start)}"; if (CurrentLoadedExport.FileRef.isName(val)) { s += $", Name: {CurrentLoadedExport.FileRef.getNameEntry(val)}"; } if (CurrentLoadedExport.FileRef.Game == MEGame.ME1) { ME1OpCodes m = (ME1OpCodes)currentData[start]; s += $", OpCode: {m}"; } if (CurrentLoadedExport.FileRef.getEntry(val) is IEntry ent) { string type = ent is IExportEntry ? "Export" : "Import"; if (ent.ObjectName == CurrentLoadedExport.ObjectName) { s += $", {type}: {ent.GetFullPath}"; } else { s += $", {type}: {ent.ObjectName}"; } } } s += $" | Start=0x{start.ToString("X8")} "; if (len > 0) { s += $"Length=0x{len.ToString("X8")} "; s += $"End=0x{(start + len - 1).ToString("X8")}"; } StatusBar_LeftMostText.Text = s; } else { StatusBar_LeftMostText.Text = "Nothing Selected"; } } catch (Exception) { } //Find which decompiled script block the cursor belongs to ListBox selectedBox = null; List <ListBox> allBoxesToUpdate = new List <ListBox>(new ListBox[] { Function_ListBox, Function_Header, Function_Footer }); if (start >= 0x20 && start < CurrentLoadedExport.DataSize - 6) { Token token = null; foreach (object o in DecompiledScriptBlocks) { if (o is Token x && start >= x.pos && start < (x.pos + x.raw.Length)) { token = x; break; } } if (token != null) { Function_ListBox.SelectedItem = token; Function_ListBox.ScrollIntoView(token); } BytecodeSingularToken bst = TokenList.FirstOrDefault(x => x.StartPos == start); if (bst != null) { Tokens_ListBox.SelectedItem = bst; Tokens_ListBox.ScrollIntoView(bst); } selectedBox = Function_ListBox; } if (start >= 0x0C && start < 0x20) { //header int index = (start - 0xC) / 4; Function_Header.SelectedIndex = index; selectedBox = Function_Header; } if (start > CurrentLoadedExport.DataSize - 6) { //footer //yeah yeah I know this is very specific code. if (start == CurrentLoadedExport.DataSize - 6 || start == CurrentLoadedExport.DataSize - 5) { Function_Footer.SelectedIndex = 0; } else { Function_Footer.SelectedIndex = 1; } selectedBox = Function_Footer; } //deselect the other boxes if (selectedBox != null) { allBoxesToUpdate.Remove(selectedBox); } allBoxesToUpdate.ForEach(x => x.SelectedIndex = -1); HexBoxSelectionChanging = false; } }