public void AddChild(JORNode child) { if (!Children.Contains(child)) { Children.Add(child); } }
private void SyncPanelControls(JORNode node) { GroupBox panel = ControlPanel; if (panel.Controls.Count > 0) { var jorPanel = panel.Controls[0] as JORPanel; jorPanel.Destroy(); } panel.Controls.Clear(); if (jorServer != null && node != null) { if (node.Status == JORNodeStatus.GenRequestSent) { // If we haven't received a GenRequest response, it might have gotten stuck. Poke it again. jorServer.SendGenObjectInfo(node); } var jorPanel = new JORPanel(jorServer, node, stringDictionary); jorPanel.Dock = DockStyle.Fill; panel.Controls.Add(jorPanel); } }
private void SyncTreeNode(TreeNode treeNode, JORNode jorNode) { if (treeNode.Tag != jorNode) { treeNode.Tag = jorNode; } treeNode.Text = stringDictionary.Translate(jorNode.Name); var foundNodes = new List <TreeNode>(); foreach (var childJorNode in jorNode.Children) { TreeNode childTreeNode = FindTreeNodeChild(treeNode, childJorNode); if (childTreeNode == null) { childTreeNode = new TreeNode(); treeNode.Nodes.Add(childTreeNode); } SyncTreeNode(childTreeNode, childJorNode); foundNodes.Add(childTreeNode); } // remove extraneous tree nodes for (int i = treeNode.Nodes.Count - 1; i >= 0; i--) { if (!foundNodes.Contains(treeNode.Nodes[i])) { treeNode.Nodes.RemoveAt(i); } } }
private void SendNodeEvent(JORNode node, JORNodeEventType type) { MemoryOutputStream stream = this.BeginSendEvent(JOREventType.NodeEvent); stream.Write(node.NodePtr); stream.Write((uint)type); this.SendEvent(stream); }
public JORPanel(JORServer server, JORNode node, StringDictionary transDict) { this.AutoScroll = true; this.Server = server; this.Node = node; this.transDict = transDict; BuildPanel(Node); }
private void button3_Click(object sender, EventArgs e) { JORNode jorNode = treeView1.SelectedNode?.Tag as JORNode; if (jorServer != null && jorNode != null) { jorServer.SendGenObjectInfo(jorNode); } }
private TreeNode FindTreeNodeChild(TreeNode treeNode, JORNode childJorNode) { foreach (TreeNode childTreeNode in treeNode.Nodes) { if (childTreeNode.Tag == childJorNode) { return(childTreeNode); } } return(null); }
private void BuildPanel(JORNode node) { int x = 0, y = 0; foreach (var jorControl in node.Controls) { Control control = MakeControl(jorControl); LayoutControl(control, ref x, ref y, jorControl.Location); Controls.Add(control); } }
public void Update() { foreach (var node in this.Root.TreeRoot.DepthFirstIter()) { node.Update(this); } if (CurrentNode != null && CurrentNode.Status == JORNodeStatus.Invalid) { CurrentNode = null; } }
public void SetCurrentNode(JORNode node) { if (node == CurrentNode) { return; } CurrentNode = node; if (CurrentNode != null) { SendNodeEvent(CurrentNode, JORNodeEventType.CurrentNodeChanged); } }
public void SendGenObjectInfo(JORNode node) { // Can't request something without a proper pointer. if (node.NodePtr == 0) { return; } Debug.WriteLine("-> GenObjectInfo {0} 0x{1:X8}", node.Name, node.NodePtr); var stream = BeginSendEvent(JOREventType.GenObjectInfo); stream.Write(node.NodePtr); SendEvent(stream); node.Status = JORNodeStatus.GenRequestSent; }
private TreeNode FindTreeNodeForJORNode(JORNode jorNode, TreeNode treeNode) { if (treeNode.Tag == jorNode) { return(treeNode); } foreach (TreeNode childTreeNode in treeNode.Nodes) { var goodNode = FindTreeNodeForJORNode(jorNode, childTreeNode); if (goodNode != null) { return(goodNode); } } return(null); }
public JORNode GetByPtr(uint nodePtr) { if (nodePtr == this.NodePtr) { return(this); } foreach (var child in this.Children) { JORNode childNode = child.GetByPtr(nodePtr); if (childNode != null) { return(childNode); } } return(null); }
public JORNode ReadGenNodeSub(MemoryInputStream stream, bool create = false, JORNode node = null) { string name = stream.ReadSJIS(); uint nodePtr = stream.ReadU32(); // Debug.WriteLine("<- ORef GenNodeSub {0} 0x{1:X8}", name, nodePtr); if (node == null) { if (nodePtr != 0) { node = this.Root.GetByPtr(nodePtr); } if (node == null && create) { node = new JORNode(); } } uint flag1 = stream.ReadU32(); uint flag2 = 0; if ((flag1 & 0x04) != 0) { flag2 = stream.ReadU32(); } if (node != null) { if (name != String.Empty) { node.Name = name; node.flag1 = flag1; node.flag2 = flag2; } node.NodePtr = nodePtr; } return(node); }
private void ProcessUpdateNode(MemoryInputStream stream, JORNode node) { Debug.WriteLine("<- ORef ProcessUpdate CMD {0}", JHI.HexDump(stream.data)); while (stream.HasData()) { JORMessageCommand command = (JORMessageCommand)stream.ReadU32(); Debug.WriteLine("<- ORef ProcessUpdate {0}", command); if (command == JORMessageCommand.UpdateControl) { uint updateMode = stream.ReadU32(); uint id = stream.ReadU32(); var control = node.FindControlByID(id, 0); if (control == null) { // No clue about this control; can't parse. return; } if (control is JORControlCheckBox) { // Checkboxes can have multiple controls with the same ID. uint subID = stream.ReadU32(); control = node.FindControlByID(id, subID); if (control == null) { // Shouldn't happen, but just in case... return; } } control.Update(updateMode, stream); } } }
private void NodeUpdated(JORNode jorNode) { if (ControlPanel.Controls.Count > 0) { JORPanel panel = ControlPanel.Controls[0] as JORPanel; if (jorNode == panel.Node) { SyncPanelControls(jorNode); } } if (this.treeView1.Nodes.Count > 0) { var treeNode = FindTreeNodeForJORNode(jorNode, this.treeView1.Nodes[0]); if (treeNode != null) { SyncTreeNode(treeNode, jorNode); } } else if (jorNode == this.jorServer.Root.TreeRoot) { SyncTree(); } }
private void ProcessUpdateNode(MemoryInputStream stream, JORNode node) { while (stream.HasData()) { JORMessageCommand command = (JORMessageCommand)stream.ReadU32(); // Debug.WriteLine("<- ORef ProcessUpdate {0}", command); if (command == JORMessageCommand.UpdateControl) { uint updateMode = stream.ReadU32(); uint id = stream.ReadU32(); var control = node.FindControlByID(id); if (control == null) { // No clue about this control; can't parse. return; } control.Update(updateMode, stream); } } }
private JORControl ReadControlSub(MemoryInputStream stream, JORNode node) { string controlType = stream.ReadMagic(); JORControl control; if (controlType == "LABL") { control = new JORControlLabel(); } else if (controlType == "BUTN") { control = new JORControlButton(); } else if (controlType == "CHBX") { control = new JORControlCheckBox(); } else if (controlType == "RNGi") { control = new JORControlRangeInt(); } else if (controlType == "RNGf") { control = new JORControlRangeFloat(); } else if (controlType == "CMBX" || controlType == "RBTN") { control = new JORControlSelector(); } else if (controlType == "EDBX") { control = new JORControlEditBox(); } else { control = new JORControlImmutable(); } control.Node = node; control.Type = controlType; control.Kind = (EKind)stream.ReadU32(); control.Name = stream.ReadSJIS(); control.Style = stream.ReadU32(); control.ID = stream.ReadU32(); // Debug.WriteLine("<- Control {0} {1} {2}", control.Type, control.Kind, control.Name); if ((control.Kind & EKind.HasListener) != 0) { control.ListenerPtr = stream.ReadU32(); } if (((control.Kind & EKind.ValueID) != 0) && control.Type != "EDBX") { control.Kind |= (EKind)0x20; } float valueF = 0.0f; uint valueU = 0xFFFFFFFF; uint kindSize = (uint)(control.Kind & EKind.SizeMask); if (kindSize != 0) { if ((control.Kind & EKind.FloatValue) != 0) { valueF = stream.ReadF32(); } else { valueU = stream.ReadU32(); } } if (control is JORControlCheckBox) { var cb = control as JORControlCheckBox; cb.Mask = valueU >> 16; cb.Value = (valueU & 0xFF) != 0; } else if (control is JORControlRangeInt) { var range = control as JORControlRangeInt; range.RangeMin = stream.ReadS32(); range.RangeMax = stream.ReadS32(); range.Value = (int)valueU; } else if (control is JORControlRangeFloat) { var range = control as JORControlRangeFloat; range.RangeMin = stream.ReadF32(); range.RangeMax = stream.ReadF32(); range.Value = valueF; } else if (control is JORControlEditBox) { var editBox = control as JORControlEditBox; editBox.MaxChars = stream.ReadU16(); editBox.Text = stream.ReadSJIS(); } ReadControlLocation(stream, ref control.Location); node.Controls.Add(control); return(control); }
public void Reset() { this.TreeRoot = new JORNode(); this.TreeRoot.Status = JORNodeStatus.Valid; }
public void ProcessTag(JHITag tag) { var stream = new MemoryInputStream(tag.Data); JORMessageType messageType = (JORMessageType)stream.ReadS32(); // Debug.WriteLine("<- ORef {1} {0}", tag.Dump(), messageType); if (messageType == JORMessageType.Reset) { this.Root.Reset(); SendGetRootObjectRef(); } else if (messageType == JORMessageType.InvalidNode) { Assert(stream.ReadU32() == 0x07u); JORNode node = ReadNodeID(stream); // Debug.WriteLine("<- InvalidNode {0}", node); if (node != null) { node.Invalidate(); } Assert(stream.ReadU32() == 0x03u); } else if (messageType == JORMessageType.GetRootObjectRef) { // Reply from GetRootObjectRef request JORNode node = ReadGenNodeSub(stream, false, this.Root.TreeRoot); SendGenObjectInfo(node); } else if (messageType == JORMessageType.GenObjectInfo) { // Reply from GenObjectInfo request ProcessObjectInfo(stream); } else if (messageType == JORMessageType.StartNode) { uint mode = stream.ReadU32(); // startNode = 0, genNode = 3 Assert(mode == 0u || mode == 3u || mode == 11u); if (mode == 0u || mode == 3u) { uint unk1 = stream.ReadU32(); JORNode parentNode = ReadNodeID(stream); JORNode node = ReadGenNodeSub(stream, true); // Debug.WriteLine("<- StartNode {0} Parent = 0x{1:X8}", node?.Name, parentNode); } else if (mode == 11u) { JORNode node = ReadNodeID(stream); } } else if (messageType == JORMessageType.StartUpdateNode) { JORNode node = ReadNodeID(stream); if (node == null) { return; } ProcessUpdateNode(stream, node); } else if (messageType == JORMessageType.OpenMessageBox) { uint retPtr = stream.ReadU32(); uint style = stream.ReadU32(); string msg = stream.ReadSJIS(); string title = stream.ReadSJIS(); MessageBox.Show(msg, title); SendResultU32(retPtr); } else if (messageType == JORMessageType.ShellExecute) { uint retPtr = stream.ReadU32(); string str0 = stream.ReadSJIS(); string str1 = stream.ReadSJIS(); string str2 = stream.ReadSJIS(); string str3 = stream.ReadSJIS(); int unk4 = stream.ReadS32(); // not actually gonna ShellExecute lol Debug.WriteLine("<- ShellExecute {0} {1} {2} {3} {4}", str0, str1, str2, str3, unk4); SendResultU32(retPtr); } else { Debug.WriteLine("<- JOR UNKNOWN!!!"); } }
private void ProcessObjectInfo(MemoryInputStream stream) { JORControlSelector currentSelector = null; Stack <JORNode> nodeStack = new Stack <JORNode>(); JORNode node = null; while (stream.HasData()) { JORMessageCommand command = (JORMessageCommand)stream.ReadU32(); // Debug.WriteLine("<- ORef MessageCommand {0}", command); if (command == JORMessageCommand.StartNode) { nodeStack.Push(node); node = ReadGenNodeSub(stream, true); Debug.WriteLine("<- GenObjectInfo Stack {2} Ptr 0x{1:X8} {0}", node.Name, node.NodePtr, nodeStack.Count); JORNode parentNode = nodeStack.Peek(); if (parentNode != null) { parentNode.AddChild(node); } // Debug.WriteLine("StartNodeClear {0}", node); node.Invalidate(); } else if (command == JORMessageCommand.EndNode) { node.Status = JORNodeStatus.Valid; if (NodeUpdated != null) { NodeUpdated(node); } node = nodeStack.Pop(); } else if (command == JORMessageCommand.GenNode) { JORNode child = ReadGenNodeSub(stream, true); child.Invalidate(); node.AddChild(child); } else if (command == JORMessageCommand.GenControl) { var control = ReadControlSub(stream, node); } else if (command == JORMessageCommand.StartSelector) { var control = ReadControlSub(stream, node); Debug.Assert(control is JORControlSelector); currentSelector = control as JORControlSelector; } else if (command == JORMessageCommand.EndSelector) { currentSelector = null; } else if (command == JORMessageCommand.SelectorItem) { var selection = new JORControlSelectorItem(); selection.Name = stream.ReadSJIS(); selection.Value = stream.ReadU32(); selection.Unk3 = stream.ReadU32(); ReadControlLocation(stream, ref selection.Location); if (currentSelector != null) { currentSelector.Items.Add(selection); } } else { throw new Exception("Unknown message type"); } } Debug.Assert(nodeStack.Count == 0); Debug.Assert(node == null); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { JORNode node = e.Node.Tag as JORNode; SyncPanelControls(node); }