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);
        }
Beispiel #2
0
        public virtual object GetCachedResult(string id)
        {
            if (!id.StartsWith("%") || !id.EndsWith("%"))
            {
                switch (id)
                {
                case "UIVersion": return(this.MumbleLinkFile.UIVersion);

                case "UITick": return(this.MumbleLinkFile.UITick);

                case "Name": return(this.MumbleLinkFile.Name);

                case "AvatarPosition": return(this.MumbleLinkFile.AvatarPosition.ToDictionary());

                case "AvatarFront": return(this.MumbleLinkFile.AvatarFront.ToDictionary());

                case "AvatarTop": return(this.MumbleLinkFile.AvatarTop.ToDictionary());

                case "CameraPosition": return(this.MumbleLinkFile.CameraPosition.ToDictionary());

                case "CameraFront": return(this.MumbleLinkFile.CameraFront.ToDictionary());

                case "CameraTop": return(this.MumbleLinkFile.CameraTop.ToDictionary());

                case "Description": return(this.MumbleLinkFile.Description);
                }

                if (this.MumbleLinkFile is Gw2MumbleLinkFile)
                {
                    Gw2MumbleLinkFile gw2MumbleLinkFile = (Gw2MumbleLinkFile)this.MumbleLinkFile;
                    switch (id)
                    {
                    case "CharacterName": return(gw2MumbleLinkFile.CharacterName);

                    case "ProfessionId": return(gw2MumbleLinkFile.ProfessionId);

                    case "MapId": return(gw2MumbleLinkFile.MapId);

                    case "WorldId": return(gw2MumbleLinkFile.WorldId);

                    case "TeamColorId": return(gw2MumbleLinkFile.TeamColorId);

                    case "IsCommander": return(gw2MumbleLinkFile.IsCommander);

                    case "ServerAddress": return(gw2MumbleLinkFile.ServerAddress.GetAddressBytes());

                    case "MapType": return(gw2MumbleLinkFile.MapType);

                    case "ShardId": return(gw2MumbleLinkFile.ShardId);

                    case "Instance": return(gw2MumbleLinkFile.Instance);

                    case "BuildId": return(gw2MumbleLinkFile.BuildId);
                    }
                }

                if (this.scriptVariables.ContainsKey(id))
                {
                    IScriptVariable script = this.scriptVariables[id];
                    if (!script.HasCachedVariable)
                    {
                        script.UpdateCachedVariable();
                    }
                    return(script.CachedVariable);
                }
            }
            else
            {
                id = id.Substring(1, id.Length - 2);
                if (this.scriptFormatters.ContainsKey(id))
                {
                    IScriptFormatter script = this.scriptFormatters[id];
                    if (!script.HasCachedVariable)
                    {
                        script.UpdateCachedVariable();
                    }
                    return(script.CachedVariable);
                }
            }

            return(null);
        }
        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");
        }
Beispiel #4
0
        public void GetCachedMumbleLinkResult()
        {
            uint    uiVersion      = 1;
            uint    uiTick         = 1234;
            string  name           = "Guild Wars 2";
            Vector3 avatarPosition = new Vector3(34.5f, 65.25f, -12.75f);
            Vector3 avatarFront    = new Vector3(89.125f, 14.5f, 90.25f);
            Vector3 avatarTop      = new Vector3(84.5f, -37.25f, 65f);
            Vector3 cameraPosition = new Vector3(95.25f, 10f, 61f);
            Vector3 cameraFront    = new Vector3(-74.625f, 98.875f, 0f);
            Vector3 cameraTop      = new Vector3(41.5f, 28.25f, 36.75f);
            string  description    = "Some awesome description is supposed to be here...";

            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;

            Gw2MumbleLinkFile gw2MumbleLinkFile = new Gw2MumbleLinkFile()
            {
                UIVersion      = uiVersion,
                UITick         = uiTick,
                Name           = name,
                AvatarPosition = avatarPosition,
                AvatarFront    = avatarFront,
                AvatarTop      = avatarTop,
                CameraPosition = cameraPosition,
                CameraFront    = cameraFront,
                CameraTop      = cameraTop,
                Description    = description,
                CharacterName  = characterName,
                ProfessionId   = professionId,
                MapId          = mapId,
                WorldId        = worldId,
                TeamColorId    = teamColorId,
                IsCommander    = isCommander,
                ServerAddress  = serverAddress,
                MapType        = mapType,
                ShardId        = shardId,
                Instance       = instance,
                BuildId        = buildId
            };

            this.scriptsManager.UseMumbleLinkFile(gw2MumbleLinkFile);

            Assert.AreEqual(uiVersion, this.scriptsManager.GetCachedResult("UIVersion"), "UIVersion");
            Assert.AreEqual(uiTick, this.scriptsManager.GetCachedResult("UITick"), "UITick");
            Assert.AreEqual(name, this.scriptsManager.GetCachedResult("Name"), "Name");
            Assert.AreEqual(avatarPosition.ToDictionary(), this.scriptsManager.GetCachedResult("AvatarPosition"), "Name");
            Assert.AreEqual(avatarFront.ToDictionary(), this.scriptsManager.GetCachedResult("AvatarFront"), "AvatarFront");
            Assert.AreEqual(avatarTop.ToDictionary(), this.scriptsManager.GetCachedResult("AvatarTop"), "AvatarTop");
            Assert.AreEqual(cameraPosition.ToDictionary(), this.scriptsManager.GetCachedResult("CameraPosition"), "CameraPosition");
            Assert.AreEqual(cameraFront.ToDictionary(), this.scriptsManager.GetCachedResult("CameraFront"), "CameraFront");
            Assert.AreEqual(cameraTop.ToDictionary(), this.scriptsManager.GetCachedResult("CameraTop"), "CameraTop");
            Assert.AreEqual(description, this.scriptsManager.GetCachedResult("Description"), "Description");

            Assert.AreEqual(characterName, this.scriptsManager.GetCachedResult("CharacterName"), "CharacterName");
            Assert.AreEqual(professionId, this.scriptsManager.GetCachedResult("ProfessionId"), "ProfessionId");
            Assert.AreEqual(mapId, this.scriptsManager.GetCachedResult("MapId"), "MapId");
            Assert.AreEqual(worldId, this.scriptsManager.GetCachedResult("WorldId"), "WorldId");
            Assert.AreEqual(teamColorId, this.scriptsManager.GetCachedResult("TeamColorId"), "TeamColorId");
            Assert.AreEqual(isCommander, this.scriptsManager.GetCachedResult("IsCommander"), "IsCommander");
            Assert.AreEqual(serverAddressBytes, this.scriptsManager.GetCachedResult("ServerAddress"), "ServerAddress");
            Assert.AreEqual(mapType, this.scriptsManager.GetCachedResult("MapType"), "MapType");
            Assert.AreEqual(shardId, this.scriptsManager.GetCachedResult("ShardId"), "ShardId");
            Assert.AreEqual(instance, this.scriptsManager.GetCachedResult("Instance"), "Instance");
            Assert.AreEqual(buildId, this.scriptsManager.GetCachedResult("BuildId"), "BuildId");
        }