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); }