Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Undo/Redo to ReClass.NET #263

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
05c13a1
Added alt-shortcuts to main context menu
FransBouma Jul 3, 2023
e3660a7
Defined various shortcut keys on the node type menu items. Changed to…
FransBouma Jul 3, 2023
4d3ac22
Moved ReadFromBuffer to MemoryBuffer where it belongs, and it's now u…
FransBouma Jul 3, 2023
4d2f079
Redefined some kb shortcuts, as ctrl-shift-c/v aren't used elsewhere
FransBouma Jul 3, 2023
208454e
Added a way to name a class after RTTI information associated with th…
FransBouma Jul 3, 2023
b61edca
Changed 'Auto-name' into 'Init from RTTI' and it now also inits the v…
FransBouma Jul 3, 2023
68b44d5
Removed alt-key shortcuts from context menu as they can't be viewed a…
FransBouma Jul 3, 2023
c831f9b
Added a toolstrip button for Init class from RTTI so the shortcut wor…
FransBouma Jul 4, 2023
5931050
Initial packages update
FransBouma Jul 4, 2023
dc5225e
Marked Init class from RTTI toolbar button as 'Overflow as needed' so…
FransBouma Jul 4, 2023
7bc89c7
Merge branch 'master' into UndoRedo
FransBouma Jul 4, 2023
35afcee
Defined some node type toolbar buttons as 'As Needed' for overflow if…
FransBouma Jul 4, 2023
fb7b4d6
Initial undo/redo system in place. Class name is now undo/redo aware
FransBouma Jul 4, 2023
aa8a857
Removed 2nd empty lines when introduced, added 32bit version of ReadF…
FransBouma Jul 4, 2023
a01ba4c
Merge branch 'master' into UndoRedo
FransBouma Jul 4, 2023
528708d
Added undo/redo for Class AddressFormula. Wired up auto-exception han…
FransBouma Jul 4, 2023
69790cd
Implemented class list undo/redo, and further class node undo/redo. M…
FransBouma Jul 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ReClass.NET/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ReClassNET
namespace ReClassNET
{
public class Constants
{
Expand Down Expand Up @@ -39,5 +39,14 @@ public static class CommandLineOptions
public const string FileExtRegister = "registerfileext";
public const string FileExtUnregister = "unregisterfileext";
}

/// <summary>
/// Change type for commandified members in classes which is used to signal what change occurred exactly. As we don't use this feature of the commandified
/// class, this enum is defined to simply signal 'no specific change other than it changed' happened.
/// </summary>
public enum GeneralPurposeChangeType
{
None
}
}
}
18 changes: 18 additions & 0 deletions ReClass.NET/Controls/MemoryViewControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -704,5 +704,23 @@ public void Reset()

VerticalScroll.Value = VerticalScroll.Minimum;
}

public void InitCurrentClassFromRTTI(ClassNode classNode)
{
var args = new DrawContextRequestEventArgs { Node = classNode };

var requestHandler = DrawContextRequested;
requestHandler?.Invoke(this, args);
var view = new DrawContext
{
Settings = args.Settings,
Process = args.Process,
Memory = args.Memory,
CurrentTime = args.CurrentTime,
Address = args.BaseAddress,
Level = 0,
};
classNode.InitFromRTTI(view);
}
}
}
72 changes: 64 additions & 8 deletions ReClass.NET/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions ReClass.NET/Forms/MainForm.Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using ReClassNET.Nodes;
using ReClassNET.Project;
using ReClassNET.UI;
using SD.Tools.Algorithmia.Commands;

namespace ReClassNET.Forms
{
Expand Down Expand Up @@ -213,6 +214,10 @@ public void LoadProjectFromPath(string path)
{
Contract.Requires(path != null);

CommandQueueManagerSingleton.GetInstance().ResetActiveCommandQueue();
CommandQueueManagerSingleton.GetInstance().BeginNonUndoablePeriod(); // we don't want to trigger undo/redo activity while loading
CommandQueueManagerSingleton.GetInstance().RaiseEvents = false;

var project = new ReClassNetProject();

LoadProjectFromPath(path, ref project);
Expand All @@ -224,6 +229,10 @@ public void LoadProjectFromPath(string path)
}

SetProject(project);

// Done loading, resume undo/redo activity
CommandQueueManagerSingleton.GetInstance().RaiseEvents = true;
CommandQueueManagerSingleton.GetInstance().EndNonUndoablePeriod();
}

/// <summary>Loads the file into the given project.</summary>
Expand Down Expand Up @@ -310,6 +319,9 @@ public void ReplaceSelectedNodesWithType(Type type)
{
var selected = hotSpotsToReplace.Dequeue();

// Use a single command here to wrap all state changes into one single undoable object, so everything gets undone/redone in 1 go
var cmd = new UndoablePeriodCommand("Replace node");
CommandQueueManagerSingleton.GetInstance().BeginUndoablePeriod(cmd);
var node = BaseNode.CreateInstanceFromType(type);

var createdNodes = new List<BaseNode>();
Expand All @@ -329,6 +341,8 @@ public void ReplaceSelectedNodesWithType(Type type)
hotSpotsToReplace.Enqueue(new MemoryViewControl.SelectedNodeInfo(createdNode, selected.Process, selected.Memory, selected.Address + createdNode.Offset - node.Offset, selected.Level));
}
}
// Mark the end of the activities that have to be tracked with this single command
CommandQueueManagerSingleton.GetInstance().EndUndoablePeriod(cmd);
}
}

Expand Down
50 changes: 49 additions & 1 deletion ReClass.NET/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using ReClassNET.UI;
using ReClassNET.Util;
using ReClassNET.Util.Conversion;
using SD.Tools.Algorithmia.Commands;

namespace ReClassNET.Forms
{
Expand Down Expand Up @@ -95,8 +96,11 @@ public MainForm()
};

pluginManager = new PluginManager(new DefaultPluginHost(this, Program.RemoteProcess, Program.Logger));

CommandQueueManagerSingleton.GetInstance().CommandQueueActionPerformed += OnCommandQueueActionPerformed;
}


protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Expand Down Expand Up @@ -135,6 +139,8 @@ protected override void OnLoad(EventArgs e)
{
AttachToProcess(Program.CommandLineArgs[Constants.CommandLineOptions.AttachTo]);
}

SetStateOfUndoRedoButtons();
}

protected override void OnFormClosed(FormClosedEventArgs e)
Expand Down Expand Up @@ -835,6 +841,8 @@ private void memoryViewControl_SelectionChanged(object sender, EventArgs e)

addBytesToolStripDropDownButton.Enabled = parentContainer != null || isContainerNode;
insertBytesToolStripDropDownButton.Enabled = selectedNodes.Count == 1 && parentContainer != null && !isContainerNode;
initClassToolStripMenuItem.Enabled = nodeIsClass;
initClassFromRTTIToolStripBarMenuItem.Enabled = nodeIsClass;

var enabled = selectedNodes.Count > 0 && !nodeIsClass;
toolStrip.Items.OfType<TypeToolStripButton>().ForEach(b => b.Enabled = enabled);
Expand Down Expand Up @@ -1027,7 +1035,7 @@ private void memoryViewControl_DrawContextRequested(object sender, DrawContextRe
{
var process = Program.RemoteProcess;

var classNode = CurrentClassNode;
var classNode = (args.Node as ClassNode) ?? CurrentClassNode;
if (classNode != null)
{
memoryViewBuffer.Size = classNode.MemorySize;
Expand All @@ -1051,5 +1059,45 @@ private void memoryViewControl_DrawContextRequested(object sender, DrawContextRe
args.BaseAddress = address;
}
}

private void initClassToolStripMenuItem_Click(object sender, EventArgs e)
{
var selectedNodes = memoryViewControl.GetSelectedNodes();
var node = selectedNodes.FirstOrDefault()?.Node;
if (node == null || !(node is ClassNode))
{
return;
}

var cmd = new UndoablePeriodCommand("InitClassFromRTTI");
CommandQueueManagerSingleton.GetInstance().BeginUndoablePeriod(cmd);
memoryViewControl.InitCurrentClassFromRTTI(node as ClassNode);
CommandQueueManagerSingleton.GetInstance().EndUndoablePeriod(cmd);
}


private void SetStateOfUndoRedoButtons()
{
undoToolbarMenuItem.Enabled = CommandQueueManagerSingleton.GetInstance().CanUndo(Program.CommandQueueID);
redoToolbarMenuItem.Enabled = CommandQueueManagerSingleton.GetInstance().CanDo(Program.CommandQueueID);
}


private void OnCommandQueueActionPerformed(object sender, CommandQueueActionPerformedEventArgs e)
{
SetStateOfUndoRedoButtons();
}


private void undoToolbarMenuItem_Click(object sender, EventArgs e)
{
CommandQueueManagerSingleton.GetInstance().UndoLastCommand();
}


private void redoToolbarMenuItem_Click(object sender, EventArgs e)
{
CommandQueueManagerSingleton.GetInstance().RedoLastCommand();
}
}
}
2 changes: 1 addition & 1 deletion ReClass.NET/Forms/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,6 @@
</value>
</data>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>42</value>
<value>104</value>
</metadata>
</root>
12 changes: 12 additions & 0 deletions ReClass.NET/Memory/MemoryBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,17 @@ public bool HasChanged(int offset, int length)

return false;
}

public UInt64FloatDoubleData InterpretData64(int offset) => new UInt64FloatDoubleData
{
Raw1 = ReadInt32(offset),
Raw2 = ReadInt32(offset + sizeof(int))
};


public UInt32FloatData InterpretData32(int offset) => new UInt32FloatData
{
Raw = ReadInt32(offset)
};
}
}
Loading