示例#1
0
        private void onMessage(MessageEventArgs e)
        {
            byte[] data = e.RawData;
            if (data.Length == 0)
            {
                return;
            }

            PacketType type = (PacketType)data[0];

            byte[] payload = data.Skip(1).ToArray();

            switch (type)
            {
            case PacketType.Handshake:
                _memory.WriteMemory(0x365FFC, new byte[1] {
                    1
                }, 1);                                                  // let client think that he is host
                _memory.WriteMemory(0x367703, new byte[1] {
                    1
                }, 1);                                                  // let client think that he has player ID 1
                PlayerID = payload[0];
                _gui.AddChatMessage("[SERVER]", "Your player ID is: " + PlayerID);
                break;

            case PacketType.PlayerData:
                onPlayerData(payload);
                break;

            case PacketType.GameMode:
                _memory.WriteMemory(0x365FF7, payload, 1);
                break;

            case PacketType.ChatMessage:
                onChatMessage(payload);
                break;

            case PacketType.RoundtripPing:
                _gui.SetPing((Environment.TickCount - BitConverter.ToInt32(payload, 0)) / 2);
                break;

            case PacketType.WrongVersion:
                int major = (int)payload[0];
                int minor = (int)payload[1];
                MessageBox.Show(null, "Wrong version!\n\nPlease check if there is a new version of Net64", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                break;
            }
        }
示例#2
0
        public static void setMessage(string msg, IEmulatorAccessor mem)
        {
            //int bytesWritten = 0;
            byte[] buffer = Encoding.ASCII.GetBytes(msg.Where(isPrintable).ToArray());

            byte[] newArray = new byte[buffer.Length + 4];
            buffer.CopyTo(newArray, 0);

            for (int i = 0; i < newArray.Length; i += 4)
            {
                byte[] newBuffer = newArray.Skip(i).Take(4).ToArray();
                newBuffer = newBuffer.Reverse().ToArray();
                mem.WriteMemory(0x367684 + i, newBuffer, newBuffer.Length);
            }

            byte[] overWriteBuffer = new byte[] { 0x00, 0x00, 0x00, 0x00 };
            //overWriteBuffer = overWriteBuffer.Reverse().ToArray();
            mem.WriteMemory(0x367680, overWriteBuffer, overWriteBuffer.Length);
        }
示例#3
0
        public ServerConnection(string address, string port, IEmulatorAccessor memory, Form1 gui)
        {
            _ws            = new WebSocket("ws://" + address + ":" + port);
            _gui           = gui;
            _memory        = memory;
            _ws.OnMessage += (sender, e) =>
            {
                onMessage(e);
            };
            _ws.OnOpen += (sender, e) =>
            {
                //Console.WriteLine("Connected");
                _gui.AddChatMessage("[SERVER]", "Connected");

                byte[] payload = new byte[Form1.HANDSHAKE_LENGTH];
                payload[0] = (byte)PacketType.Handshake;
                payload[1] = (byte)Form1.COMPAT_MAJOR_VERSION;
                payload[2] = (byte)Form1.COMPAT_MINOR_VERSION;
                payload[3] = (byte)_gui.GetCharacter();

                string username = _gui.GetUsername();

                if (string.IsNullOrWhiteSpace(username))
                {
                    username = getRandomUsername();
                    _gui.SetUsername(username);
                }

                byte[] usernameBytes = Encoding.ASCII.GetBytes(username);
                int    len           = usernameBytes.Length;
                if (len > 24) // Arbitrary max length
                {
                    len = 24;
                }

                payload[4] = (byte)len;
                Array.Copy(usernameBytes, 0, payload, 5, len);
                _ws.Send(payload);
                SetMessage("connected");
            };
            _ws.OnError += (sender, e) =>
            {
                MessageBox.Show(null, e.Message + "\n\n" + e.Exception, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            };
            _ws.OnClose += (sender, e) =>
            {
                _memory.WriteMemory(0x365FFC, new byte[1], 1);
                _gui.AddChatMessage("[SERVER]", "Disconnected");
                SetMessage("disconnected");
                MessageBox.Show(null, "Server closed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            };
            _ws.Connect();
        }
示例#4
0
 public static void setCharacter(string character, IEmulatorAccessor mem)
 {
     if (character == "Mario")
     {
         //int bytesWritten = 0;
         mem.WriteMemory(0x365FF3, new byte[] { 0x01 }, 1);
     }
     if (character == "Luigi")
     {
         //int bytesWritten = 0;
         mem.WriteMemory(0x365FF3, new byte[] { 0x02 }, 1);
     }
     if (character == "Yoshi")
     {
         //int bytesWritten = 0;
         mem.WriteMemory(0x365FF3, new byte[] { 0x03 }, 1);
     }
     if (character == "Wario")
     {
         //int bytesWritten = 0;
         mem.WriteMemory(0x365FF3, new byte[] { 0x04 }, 1);
     }
     if (character == "Peach")
     {
         //int bytesWritten = 0;
         mem.WriteMemory(0x365FF3, new byte[] { 0x05 }, 1);
     }
     if (character == "Toad")
     {
         //int bytesWritten = 0;
         mem.WriteMemory(0x365FF3, new byte[] { 0x06 }, 1);
     }
     if (character == "Waluigi")
     {
         //int bytesWritten = 0;
         mem.WriteMemory(0x365FF3, new byte[] { 0x07 }, 1);
     }
     if (character == "Rosalina")
     {
         //int bytesWritten = 0;
         mem.WriteMemory(0x365FF3, new byte[] { 0x08 }, 1);
     }
 }
示例#5
0
        private void loadPatches()
        {
            string[] fileEntries = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "/Ressources/");

            foreach (var file in fileEntries)
            {
                string fname = Path.GetFileName(file);
                int    offset;

                if (int.TryParse(fname, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out offset))
                {
                    byte[] buffer = File.ReadAllBytes(file);
                    _memory.WriteMemory(offset, buffer, buffer.Length);
                }
                else if (fname.Contains('.'))
                {
                    // Treat as Regex
                    int    separator    = fname.LastIndexOf(".", StringComparison.Ordinal);
                    string regexPattern = fname.Substring(0, separator);
                    string address      = fname.Substring(separator + 1, fname.Length - separator - 1);
                    string romname      = getRomName();

                    regexPattern = regexPattern.Replace("@", "\\");
                    bool invert = false;

                    if (regexPattern[0] == '!')
                    {
                        regexPattern = regexPattern.Substring(1);
                        invert       = true;
                    }

                    if (romname == null)
                    {
                        continue;
                    }

                    bool isMatch = Regex.IsMatch(romname, regexPattern,
                                                 RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

                    if ((isMatch && !invert) || (!isMatch && invert))
                    {
                        offset = int.Parse(address, NumberStyles.HexNumber, CultureInfo.InvariantCulture);

                        byte[] buffer = File.ReadAllBytes(file);
                        _memory.WriteMemory(offset, buffer, buffer.Length);
                    }
                }
            }
        }
示例#6
0
 public static void setCharacterAll(int character, IEmulatorAccessor mem)
 {
     mem.WriteMemory(0x365FF3, new byte[] { (byte)character }, 1);
 }