コード例 #1
0
        public void MumbleLinkStateChanged()
        {
            MumbleLinkManager manager = new MumbleLinkManager();

            manager.TimeoutRate = 0.1;
            MumbleLinkState?actualState  = null;
            string          actualName   = null;
            string          expectedName = "Super Adventure Wars FTW";

            manager.MumbleLinkStateChanged += (s, e) =>
            {
                actualState = e.State;
                actualName  = e.Name;
            };

            IMumbleLinkConnector connector = Substitute.For <IMumbleLinkConnector>();
            LinkedMem            linkedMem = new LinkedMem()
            {
                uiTick = 1
            };

            unsafe { PointerUtils.CopyArrayToPointer(expectedName.ToCharArray(), linkedMem.name); }
            connector.ReadMemoryMappedFile().Returns(linkedMem);
            manager.UseMumbleLinkConnector(connector);

            manager.Check();
            Assert.IsTrue(manager.IsActive, "Active");
            Assert.AreEqual(expectedName, actualName, "Name");
            actualState = null;
            actualName  = null;
            Thread.Sleep((int)(manager.TimeoutRate * 1000));
            manager.Check();
            Assert.IsFalse(manager.IsActive, "Not active after");
        }
コード例 #2
0
        unsafe public void SetDataFromLinkedMemNotGW2()
        {
            string name = "Not Guild Wars 2";

            LinkedMem linkedMem = new LinkedMem();

            PointerUtils.CopyArrayToPointer(name.ToCharArray(), linkedMem.name);

            Gw2MumbleLinkFile gw2MumbleLinkFile = new Gw2MumbleLinkFile();

            gw2MumbleLinkFile.SetDataFromLinkedMem(linkedMem);

            Assert.IsFalse(gw2MumbleLinkFile.IsValid);
        }
コード例 #3
0
        unsafe public void SetDataFromLinkedGw2Mem()
        {
            // MumbleLinkFileTest contains a test that covers the basic stuff of MumbleLinkFile
            // Only the stuff that is new in Gw2MumbleLinkFile is covered here
            string name          = "Guild Wars 2";
            string characterName = "Rox";
            uint   professionId  = 4;
            uint   mapId         = 218;
            uint   worldId       = 2003;
            uint   teamColorId   = 55;
            bool   isCommander   = true;

            byte[]    serverAddressBytes = new byte[] { 11, 22, 33, 44 };
            IPAddress serverAddress      = new IPAddress(serverAddressBytes);
            uint      mapType            = 2;
            uint      shardId            = 123456789;
            uint      instance           = 10;
            uint      buildId            = 39660;

            GW2Context gw2Context = new GW2Context()
            {
                serverAddress = new SockAddr_In()
                {
                    sin_family = AddressFamily.InterNetwork,
                    sin_addr   = new In_Addr()
                    {
                        s_b1 = serverAddressBytes[0],
                        s_b2 = serverAddressBytes[1],
                        s_b3 = serverAddressBytes[2],
                        s_b4 = serverAddressBytes[3],
                        //s_w1 = (ushort)((serverAddress[0] << 8) | serverAddress[1]),
                        //s_w2 = (ushort)((serverAddress[2] << 8) | serverAddress[3]),
                        //s_addr = (ulong)((serverAddress[0] << 24) | (serverAddress[1] << 16) | (serverAddress[2] << 8) | serverAddress[3])
                    },
                },
                mapId    = mapId,
                mapType  = mapType,
                shardId  = shardId,
                instance = instance,
                buildId  = buildId
            };

            string identityJson = @"{""name"": ""Rox"",""profession"": 4,""map_id"": 218,""world_id"": 2003,""team_color_id"": 55,""commander"": true}";

            byte[] context = PointerUtils.GetBytes(gw2Context);

            LinkedMem linkedMem = new LinkedMem();

            PointerUtils.CopyArrayToPointer(name.ToCharArray(), linkedMem.name);
            PointerUtils.CopyArrayToPointer(identityJson.ToCharArray(), linkedMem.identity);
            PointerUtils.CopyArrayToPointer(context, linkedMem.context);
            linkedMem.context_len = (uint)context.Length;

            Gw2MumbleLinkFile gw2MumbleLinkFile = new Gw2MumbleLinkFile();

            gw2MumbleLinkFile.SetDataFromLinkedMem(linkedMem);

            Assert.IsTrue(gw2MumbleLinkFile.IsValid, "IsValid");
            Assert.AreEqual(characterName, gw2MumbleLinkFile.CharacterName, "CharacterName");
            Assert.AreEqual(professionId, gw2MumbleLinkFile.ProfessionId, "ProfessionId");
            Assert.AreEqual(mapId, gw2MumbleLinkFile.MapId, "MapId");
            Assert.AreEqual(worldId, gw2MumbleLinkFile.WorldId, "WorldId");
            Assert.AreEqual(teamColorId, gw2MumbleLinkFile.TeamColorId, "TeamColorId");
            Assert.AreEqual(isCommander, gw2MumbleLinkFile.IsCommander, "IsCommander");
            Assert.AreEqual(serverAddress, gw2MumbleLinkFile.ServerAddress, "ServerAddress");
            Assert.AreEqual(mapType, gw2MumbleLinkFile.MapType, "MapType");
            Assert.AreEqual(shardId, gw2MumbleLinkFile.ShardId, "ShardId");
            Assert.AreEqual(instance, gw2MumbleLinkFile.Instance, "Instance");
            Assert.AreEqual(buildId, gw2MumbleLinkFile.BuildId, "BuildId");
        }
コード例 #4
0
        unsafe public void SetDataFromLinkedMem()
        {
            uint    uiVersion      = 1;
            uint    uiTick         = 1234;
            Vector3 avatarPosition = new Vector3(34.5f, 65.25f, -12.75f);

            float[] fAvatarPosition = { (float)avatarPosition.X, (float)avatarPosition.Y, (float)avatarPosition.Z };
            Vector3 avatarFront     = new Vector3(89.125f, 14.5f, 90.25f);

            float[] fAvatarFront = { (float)avatarFront.X, (float)avatarFront.Y, (float)avatarFront.Z };
            Vector3 avatarTop    = new Vector3(84.5f, -37.25f, 65f);

            float[] fAvatarTop     = { (float)avatarTop.X, (float)avatarTop.Y, (float)avatarTop.Z };
            string  name           = "Test Wars 42";
            Vector3 cameraPosition = new Vector3(95.25f, 10f, 61f);

            float[] fCameraPosition = { (float)cameraPosition.X, (float)cameraPosition.Y, (float)cameraPosition.Z };
            Vector3 cameraFront     = new Vector3(-74.625f, 98.875f, 0f);

            float[] fCameraFront = { (float)cameraFront.X, (float)cameraFront.Y, (float)cameraFront.Z };
            Vector3 cameraTop    = new Vector3(41.5f, 28.25f, 36.75f);

            float[] fCameraTop = { (float)cameraTop.X, (float)cameraTop.Y, (float)cameraTop.Z };
            string  identity   = "No identity identified";

            byte[] context     = { 123, 65, 255, 0, 123, 26, 73, 186 };
            uint   context_len = (uint)context.Length;
            string description = "Some awesome description is supposed to be here...";

            LinkedMem linkedMem = new LinkedMem();

            linkedMem.uiVersion = uiVersion;
            linkedMem.uiTick    = uiTick;
            PointerUtils.CopyArrayToPointer(fAvatarPosition, linkedMem.fAvatarPosition);
            PointerUtils.CopyArrayToPointer(fAvatarFront, linkedMem.fAvatarFront);
            PointerUtils.CopyArrayToPointer(fAvatarTop, linkedMem.fAvatarTop);
            PointerUtils.CopyArrayToPointer(name.ToCharArray(), linkedMem.name);
            PointerUtils.CopyArrayToPointer(fCameraPosition, linkedMem.fCameraPosition);
            PointerUtils.CopyArrayToPointer(fCameraFront, linkedMem.fCameraFront);
            PointerUtils.CopyArrayToPointer(fCameraTop, linkedMem.fCameraTop);
            PointerUtils.CopyArrayToPointer(identity.ToCharArray(), linkedMem.identity);
            linkedMem.context_len = context_len;
            PointerUtils.CopyArrayToPointer(context, linkedMem.context);
            PointerUtils.CopyArrayToPointer(description.ToCharArray(), linkedMem.description);

            MumbleLinkFile mumbleLinkFile = new MumbleLinkFile();

            mumbleLinkFile.SetDataFromLinkedMem(linkedMem);

            Assert.IsTrue(mumbleLinkFile.IsValid, "IsValid");
            Assert.AreEqual(uiVersion, mumbleLinkFile.UIVersion, "UIVersion");
            Assert.AreEqual(uiTick, mumbleLinkFile.UITick, "UITick");
            Assert.AreEqual(avatarPosition, mumbleLinkFile.AvatarPosition, "AvatarPosition");
            Assert.AreEqual(avatarFront, mumbleLinkFile.AvatarFront, "AvatarFront");
            Assert.AreEqual(avatarTop, mumbleLinkFile.AvatarTop, "AvatarTop");
            Assert.AreEqual(name, mumbleLinkFile.Name, "Name");
            Assert.AreEqual(cameraPosition, mumbleLinkFile.CameraPosition, "CameraPosition");
            Assert.AreEqual(cameraFront, mumbleLinkFile.CameraFront, "CameraFront");
            Assert.AreEqual(cameraTop, mumbleLinkFile.CameraTop, "CameraTop");
            Assert.AreEqual(identity, mumbleLinkFile.Identity, "Identity");
            CollectionAssert.AreEqual(context, mumbleLinkFile.Context, "Context");
            Assert.AreEqual(context_len, mumbleLinkFile.Context.Length, "ContextLength");
            Assert.AreEqual(description, mumbleLinkFile.Description, "Description");
        }