Exemplo n.º 1
0
        protected override void BroadcastPlayerOptions()
        {
            if (!IsHost)
            {
                return;
            }

            var sb = new ExtendedStringBuilder(PLAYER_OPTIONS_BROADCAST_COMMAND + " ", true);

            sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR;
            foreach (PlayerInfo pInfo in Players.Concat(AIPlayers))
            {
                sb.Append(pInfo.Name);
                sb.Append(pInfo.SideId);
                sb.Append(pInfo.ColorId);
                sb.Append(pInfo.StartingLocation);
                sb.Append(pInfo.TeamId);
                sb.Append(Convert.ToInt32(pInfo.IsAI || pInfo.Ready));
                sb.Append(pInfo.IPAddress);
                if (pInfo.IsAI)
                {
                    sb.Append(pInfo.AILevel);
                }
                else
                {
                    sb.Append("-1");
                }
            }

            BroadcastMessage(sb.ToString());
        }
Exemplo n.º 2
0
        protected override void OnGameOptionChanged()
        {
            base.OnGameOptionChanged();

            if (!IsHost)
            {
                return;
            }

            var sb = new ExtendedStringBuilder(GAME_OPTIONS_COMMAND + " ", true);

            sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR;
            foreach (GameLobbyCheckBox chkBox in CheckBoxes)
            {
                sb.Append(Convert.ToInt32(chkBox.Checked));
            }

            foreach (GameLobbyDropDown dd in DropDowns)
            {
                sb.Append(dd.SelectedIndex);
            }

            sb.Append(RandomSeed);
            sb.Append(Map.SHA1);
            sb.Append(GameMode.Name);
            sb.Append(FrameSendRate);
            sb.Append(Convert.ToInt32(RemoveStartingLocations));

            BroadcastMessage(sb.ToString());
        }
Exemplo n.º 3
0
        protected override void SendChatMessage(string message)
        {
            var sb = new ExtendedStringBuilder(CHAT_COMMAND + " ", true);

            sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR;
            sb.Append(chatColorIndex);
            sb.Append(message);
            SendMessageToHost(sb.ToString());
        }
Exemplo n.º 4
0
        protected override void RequestPlayerOptions(int side, int color, int start, int team)
        {
            var sb = new ExtendedStringBuilder(PLAYER_OPTIONS_REQUEST_COMMAND + " ", true);

            sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR;
            sb.Append(side);
            sb.Append(color);
            sb.Append(start);
            sb.Append(team);
            SendMessageToHost(sb.ToString());
        }
Exemplo n.º 5
0
        public override string ToString()
        {
            var sb = new ExtendedStringBuilder();

            sb.Append("Search engines", SearchEngines);
            sb.Append("Priority engines", PriorityEngines);
            sb.Append("Filtering", Filtering);
            sb.Append("Notification", Notification);
            sb.Append("Notification image", NotificationImage);

            return(sb.ToString());
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            ExtendedStringBuilder builder = new ExtendedStringBuilder();

            GenerateVectorSwizzlesForType(builder, "Real");
            GenerateVectorSwizzlesForType(builder, "Integer");
            GenerateVectorSwizzlesForType(builder, "Boolean");

            GenerateMatrixSwizzlesForType(builder, "Real");

            String result = builder.ToString();

            Clipboard.SetText(result);
        }
Exemplo n.º 7
0
        public override string ToString()
        {
            var sb = new ExtendedStringBuilder(true, ',');

            sb.Append(Name);
            sb.Append(SideId);
            sb.Append(StartingLocation);
            sb.Append(ColorId);
            sb.Append(TeamId);
            sb.Append(AILevel);
            sb.Append(IsAI.ToString());
            sb.Append(Index);
            return(sb.ToString());
        }
Exemplo n.º 8
0
        /// <summary>
        /// Converts a string of dash-separated, or underscore-separated words to a PascalCase string.
        /// </summary>
        /// <param name="s">The string to convert.</param>
        /// <returns>The resulting PascalCase string.</returns>
        public static string ToPascalCase(this string s)
        {
            var words = s.Split(new char[3] {
                '-', '_', ' '
            }, StringSplitOptions.RemoveEmptyEntries);

            var sb = new ExtendedStringBuilder(words.Sum(x => x.Length));

            foreach (string word in words)
            {
                var stringInfo = new StringInfo(word);
                sb += stringInfo.SubstringByTextElements(0, 1).ToUpper();
                sb += stringInfo.SubstringByTextElements(1).ToLower();
            }

            return(sb.ToString());
        }
Exemplo n.º 9
0
        public override string ToString()
        {
            var sb = new ExtendedStringBuilder()
            {
            };

            sb.Append(nameof(Url), Url);

            if (Similarity.HasValue)
            {
                sb.Append($"{nameof(Similarity)}", $"{Similarity.Value / 100:P}");
            }

            if (HasImageDimensions)
            {
                string?val = $"{Width}x{Height} ({MegapixelResolution:F} MP)";


                var resType = DisplayResolution;

                if (resType != DisplayResolutionType.Unknown)
                {
                    val += ($" (~{resType})");
                }

                sb.Append($"Resolution", val);
            }

            sb.Append(nameof(Name), Name);
            sb.Append(nameof(Description), Description);
            sb.Append(nameof(Artist), Artist);
            sb.Append(nameof(Site), Site);
            sb.Append(nameof(Source), Source);
            sb.Append(nameof(Characters), Characters);

            foreach (var(key, value) in OtherMetadata)
            {
                sb.Append(key, value);
            }

            sb.Append($"Detail score", $"{DetailScore}/{DetailFields.Count} ({(IsDetailed ? "Y" : "N")})");

            return(sb.ToString().RemoveLastOccurrence("\n"));
        }
Exemplo n.º 10
0
        private void BroadcastGame()
        {
            var sb = new ExtendedStringBuilder("GAME ", true);

            sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR;
            sb.Append(ProgramConstants.LAN_PROTOCOL_REVISION);
            sb.Append(ProgramConstants.GAME_VERSION);
            sb.Append(localGame);
            sb.Append(lblMapNameValue.Text);
            sb.Append(lblGameModeValue.Text);
            sb.Append(0); // LoadedGameID
            var sbPlayers = new StringBuilder();

            SGPlayers.ForEach(p => sbPlayers.Append(p.Name + ","));
            sbPlayers.Remove(sbPlayers.Length - 1, 1);
            sb.Append(sbPlayers.ToString());
            sb.Append(Convert.ToInt32(started || Players.Count == SGPlayers.Count));
            sb.Append(1); // IsLoadedGame

            GameBroadcast?.Invoke(this, new GameBroadcastEventArgs(sb.ToString()));
        }
Exemplo n.º 11
0
        protected override void BroadcastOptions()
        {
            if (Players.Count > 0)
            {
                Players[0].Ready = true;
            }

            var sb = new ExtendedStringBuilder(OPTIONS_COMMAND + " ", true);

            sb.Separator = ProgramConstants.LAN_DATA_SEPARATOR;

            sb.Append(ddSavedGame.SelectedIndex);

            foreach (PlayerInfo pInfo in Players)
            {
                sb.Append(pInfo.Name);
                sb.Append(Convert.ToInt32(pInfo.Ready));
                sb.Append(pInfo.IPAddress);
            }

            BroadcastMessage(sb.ToString());
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            ExtendedStringBuilder builder = new ExtendedStringBuilder();


            List <String> realVectorTypes = new List <String>();

            for (var i = 2; i <= 4; ++i)
            {
                realVectorTypes.Add(String.Format("Real{0}", i));
            }
            List <String> real23VectorTypes = new List <String>();

            real23VectorTypes.Add(realVectorTypes[0]);
            real23VectorTypes.Add(realVectorTypes[1]);

            List <String> realMatrixTypes = new List <String>();

            for (var y = 2; y <= 4; ++y)
            {
                for (var x = 2; x <= 4; ++x)
                {
                    realMatrixTypes.Add(String.Format("Real{0}x{1}", y, x));
                }
            }
            List <String> realVectorAndScalarTypes = new List <String>();

            realVectorAndScalarTypes.Add("Real");
            realVectorAndScalarTypes.AddRange(realVectorTypes);
            List <String> realVectorAndMatrixTypes = new List <String>();

            realVectorAndMatrixTypes.AddRange(realVectorTypes);
            realVectorAndMatrixTypes.AddRange(realMatrixTypes);
            List <String> allRealTypes = new List <String>();

            allRealTypes.Add("Real");
            allRealTypes.AddRange(realVectorAndMatrixTypes);



            GenerateClass(builder, "MathLengthSq", realVectorTypes, GenerateLengthSq);
            builder.AppendLine();
            GenerateClass(builder, "MathDistanceSq", realVectorTypes, GenerateDistanceSq);
            builder.AppendLine();
            GenerateClass(builder, "MathReflectAcrossVector", realVectorTypes, GenerateReflectAcrossVector);
            builder.AppendLine();
            GenerateClass(builder, "MathProjectOnVector", realVectorTypes, GenerateProjectOnVector);
            builder.AppendLine();
            GenerateClass(builder, "MathProjectOnPlane", realVectorTypes, GenerateProjectOnPlane);
            builder.AppendLine();
            GenerateClass(builder, "MathAngleBetween", realVectorTypes, GenerateAngleBetween);
            builder.AppendLine();
            GenerateClass(builder, "MathRotateTowards", real23VectorTypes, GenerateRotateTowards);
            builder.AppendLine();
            GenerateClass(builder, "MathGetAxis", realVectorTypes, GenerateGetAxis);
            builder.AppendLine();
            GenerateClass(builder, "MathSaturate", realVectorAndScalarTypes, GenerateSaturate);
            builder.AppendLine();

            GenerateClass(builder, "MathCeilPlaces", realVectorAndScalarTypes, GenerateCeilPlaces);
            builder.AppendLine();
            GenerateClass(builder, "MathCeilPlacesBase", realVectorAndScalarTypes, GenerateCeilPlacesBase);
            builder.AppendLine();
            GenerateClass(builder, "MathFloorPlaces", realVectorAndScalarTypes, GenerateFloorPlaces);
            builder.AppendLine();
            GenerateClass(builder, "MathFloorPlacesBase", realVectorAndScalarTypes, GenerateFloorPlacesBase);
            builder.AppendLine();
            GenerateClass(builder, "MathRoundPlaces", realVectorAndScalarTypes, GenerateRoundPlaces);
            builder.AppendLine();
            GenerateClass(builder, "MathRoundPlacesBase", realVectorAndScalarTypes, GenerateRoundPlacesBase);
            builder.AppendLine();
            GenerateClass(builder, "MathTruncatePlaces", realVectorAndScalarTypes, GenerateTruncatePlaces);
            builder.AppendLine();
            GenerateClass(builder, "MathTruncatePlacesBase", realVectorAndScalarTypes, GenerateTruncatePlacesBase);
            builder.AppendLine();

            GenerateClass(builder, "MathFMod", realVectorAndScalarTypes, GenerateFMod);
            builder.AppendLine();
            GenerateClass(builder, "MathLog10", realVectorAndScalarTypes, GenerateLog10);
            builder.AppendLine();
            GenerateClass(builder, "MathMatrixGetByIndex", realMatrixTypes, GenerateGetByIndex);
            builder.AppendLine();
            GenerateClass(builder, "MathMatrixSetByIndex", realMatrixTypes, GenerateSetByIndex);
            builder.AppendLine();
            GenerateSquareMatrixClass(builder, "MathMultiplyPointNoDivide", GenerateMultiplyPointNoDivision);
            builder.AppendLine();
            GenerateSquareMatrixClass(builder, "MathMultiplyNormal", GenerateMultiplyNormal);
            builder.AppendLine();
            GenerateSquareMatrixClass(builder, "MathMultiplyPoint", GenerateMultiplyPoint);

            AddCodeFromFile(builder, "ExtraCode.zilchFrag");

            String result = builder.ToString();

            Clipboard.SetText(result);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Converts a byte-array to an RFC4648 (https://tools.ietf.org/html/rfc4648) Base64 string.
        /// </summary>
        /// <param name="input">The input byte-array.</param>
        /// <param name="options">Any of <see cref="Base64FormattingOptions"/> enumeration values.</param>
        /// <param name="charactersPerLine">If this is a non-zero uinteger, than the number of characters per line will be equivalent to this value.</param>
        /// <returns>The input byte-array encoded into a Base64 string, following the provided options.</returns>
        public static string ToBase64String(this byte[] input, Base64FormattingOptions options = Base64FormattingOptions.RequirePaddingCharacter, uint charactersPerLine = 0)
        {
            string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

            if ((options & Base64FormattingOptions.UrlFilenameSafeAlphabet) == Base64FormattingOptions.UrlFilenameSafeAlphabet)
            {
                alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";
            }
            else if ((options & Base64FormattingOptions.UnixCryptAlphabet) == Base64FormattingOptions.UnixCryptAlphabet)
            {
                alphabet = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=";
            }

            ExtendedStringBuilder workingResult = new ExtendedStringBuilder();

            for (int i = 0; i < input.Length; i += 3)
            {
                int temp = (input[i] & 0xFC) >> 2;

                workingResult += alphabet[temp];

                temp = (input[i] & 0x03) << 4;

                if (i + 1 < input.Length)
                {
                    temp          |= (input[i + 1] & 0xF0) >> 4;
                    workingResult += alphabet[temp];

                    temp = (input[i + 1] & 0x0F) << 2;

                    if (i + 2 < input.Length)
                    {
                        temp          |= (input[i + 2] & 0xC0) >> 6;
                        workingResult += alphabet[temp];
                        workingResult += alphabet[((input[i + 2] & 0x3F))];
                    }
                    else
                    {
                        workingResult += alphabet[temp];

                        if ((options & Base64FormattingOptions.RequirePaddingCharacter) == Base64FormattingOptions.RequirePaddingCharacter)
                        {
                            workingResult += alphabet[64];
                        }
                    }
                }
                else
                {
                    workingResult += alphabet[temp];

                    if ((options & Base64FormattingOptions.RequirePaddingCharacter) == Base64FormattingOptions.RequirePaddingCharacter)
                    {
                        workingResult += alphabet[64];
                        workingResult += alphabet[64];
                    }
                }
            }

            uint lineBreaks = 0;

            if (charactersPerLine > 0)
            {
                lineBreaks = charactersPerLine;
            }
            else if ((options & Base64FormattingOptions.BreakLinesAt64Characters) == Base64FormattingOptions.BreakLinesAt64Characters)
            {
                lineBreaks = 64;
            }
            else if ((options & Base64FormattingOptions.BreakLinesAt76Characters) == Base64FormattingOptions.BreakLinesAt76Characters)
            {
                lineBreaks = 76;
            }

            ExtendedStringBuilder result = new ExtendedStringBuilder();

            string workingString = workingResult;

            if (lineBreaks > 0)
            {
                for (uint line = 0; line < workingResult.Length / lineBreaks; line++)
                {
                    result += workingString.Substring((int)(line * lineBreaks), (int)lineBreaks);

                    string lineBreak = "";

                    if ((options & Base64FormattingOptions.UseCarraigeReturnNewline) == Base64FormattingOptions.UseCarraigeReturnNewline)
                    {
                        lineBreak += "\r";
                    }

                    if ((options & Base64FormattingOptions.UseLineBreakNewLine) == Base64FormattingOptions.UseLineBreakNewLine)
                    {
                        lineBreak += "\n";
                    }

                    if (lineBreak == "")
                    {
                        lineBreak = "\r\n";
                    }

                    result += lineBreak;
                }
            }
            else
            {
                result += workingResult;
            }

            return(result.ToString());
        }
Exemplo n.º 14
0
        /// <summary>
        /// Converts a string of dash-separated, or underscore-separated words to a PascalCase string.
        /// </summary>
        /// <param name="s">The string to convert.</param>
        /// <returns>The resulting PascalCase string.</returns>
        public static string ToPascalCase(this string s)
        {
            var words = s.Split(new char[3] { '-', '_', ' ' }, StringSplitOptions.RemoveEmptyEntries);
            
            var sb = new ExtendedStringBuilder(words.Sum(x => x.Length));

            foreach (string word in words)
            {
                var stringInfo = new StringInfo(word);
                sb += stringInfo.SubstringByTextElements(0, 1).ToUpper();
                sb += stringInfo.SubstringByTextElements(1).ToLower();
            }

            return sb.ToString();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Converts a byte-array to an RFC4648 (https://tools.ietf.org/html/rfc4648) Base64 string.
        /// </summary>
        /// <param name="input">The input byte-array.</param>
        /// <param name="options">Any of <see cref="Base64FormattingOptions"/> enumeration values.</param>
        /// <param name="charactersPerLine">If this is a non-zero uinteger, than the number of characters per line will be equivalent to this value.</param>
        /// <returns>The input byte-array encoded into a Base64 string, following the provided options.</returns>
        public static string ToBase64String(this byte[] input, Base64FormattingOptions options = Base64FormattingOptions.RequirePaddingCharacter, uint charactersPerLine = 0)
        {
            string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

            if ((options & Base64FormattingOptions.UrlFilenameSafeAlphabet) == Base64FormattingOptions.UrlFilenameSafeAlphabet)
            {
                alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";
            }
            else if ((options & Base64FormattingOptions.UnixCryptAlphabet) == Base64FormattingOptions.UnixCryptAlphabet)
            {
                alphabet = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=";
            }

            ExtendedStringBuilder workingResult = new ExtendedStringBuilder();

            for (int i = 0; i < input.Length; i += 3)
            {
                int temp = (input[i] & 0xFC) >> 2;

                workingResult += alphabet[temp];

                temp = (input[i] & 0x03) << 4;

                if (i + 1 < input.Length)
                {
                    temp |= (input[i + 1] & 0xF0) >> 4;
                    workingResult += alphabet[temp];

                    temp = (input[i + 1] & 0x0F) << 2;

                    if (i + 2 < input.Length)
                    {
                        temp |= (input[i + 2] & 0xC0) >> 6;
                        workingResult += alphabet[temp];
                        workingResult += alphabet[((input[i + 2] & 0x3F))];
                    }
                    else
                    {
                        workingResult += alphabet[temp];

                        if ((options & Base64FormattingOptions.RequirePaddingCharacter) == Base64FormattingOptions.RequirePaddingCharacter)
                        {
                            workingResult += alphabet[64];
                        }
                    }
                }
                else
                {
                    workingResult += alphabet[temp];

                    if ((options & Base64FormattingOptions.RequirePaddingCharacter) == Base64FormattingOptions.RequirePaddingCharacter)
                    {
                        workingResult += alphabet[64];
                        workingResult += alphabet[64];
                    }
                }
            }

            uint lineBreaks = 0;

            if (charactersPerLine > 0)
            {
                lineBreaks = charactersPerLine;
            }
            else if ((options & Base64FormattingOptions.BreakLinesAt64Characters) == Base64FormattingOptions.BreakLinesAt64Characters)
            {
                lineBreaks = 64;
            }
            else if ((options & Base64FormattingOptions.BreakLinesAt76Characters) == Base64FormattingOptions.BreakLinesAt76Characters)
            {
                lineBreaks = 76;
            }

            ExtendedStringBuilder result = new ExtendedStringBuilder();

            string workingString = workingResult;

            if (lineBreaks > 0)
            {
                for (uint line = 0; line < workingResult.Length / lineBreaks; line++)
                {
                    result += workingString.Substring((int)(line * lineBreaks), (int)lineBreaks);

                    string lineBreak = "";

                    if ((options & Base64FormattingOptions.UseCarraigeReturnNewline) == Base64FormattingOptions.UseCarraigeReturnNewline)
                    {
                        lineBreak += "\r";
                    }

                    if ((options & Base64FormattingOptions.UseLineBreakNewLine) == Base64FormattingOptions.UseLineBreakNewLine)
                    {
                        lineBreak += "\n";
                    }

                    if (lineBreak == "")
                    {
                        lineBreak = "\r\n";
                    }

                    result += lineBreak;
                }
            }
            else
            {
                result += workingResult;
            }

            return result.ToString();
        }