少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
    using System;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using UnityEngine;
    using System.Threading;
 
    public partial class DirtyNameConfig :  IConfigPostProcess
    {
 
        private static WordGroup[] DIRTYWORLD = new WordGroup[(int)char.MaxValue];
 
        private static List<string> memoryList = new List<string>();
 
        private static bool dirtyNameInited = false;
 
        static int cursor = 0;
 
        static int wordlenght = 0;
 
        static int nextCursor = 0;
 
        public void OnConfigParseCompleted()
        {
            if (string.IsNullOrEmpty(word))
            {
                Debug.LogErrorFormat("ÆÁ±ÎÃû×Ö id = {0} µÄÄÚÈÝΪ¿Õ ÐèÒªÐÞ¸Ä", id);
                return;
            }
            string key = ToDBC(word);
            memoryList.Add(key);
        }
 
        private static string ToDBC(string input)
        {
            char[] c = input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] == 12288)
                {
                    c[i] = (char)32;
                    continue;
                }
                if (c[i] > 65280 && c[i] < 65375)
                    c[i] = (char)(c[i] - 65248);
            }
            return new string(c).ToLower();
        }
 
        public static bool IsDirtName(string source)
        {
            if (!dirtyNameInited)
            {
                Init();
            }
            if (source != string.Empty)
            {
                cursor = 0;
                nextCursor = 0;
                for (int i = 0; i < source.Length; i++)
                {
                    //²éѯÒÔ¸Ã×ÖΪÊ××Ö·ûµÄ´Ê×é
                    WordGroup group = DIRTYWORLD[(int)ToDBC(source)[i]];
                    if (group != null)
                    {
                        for (int z = 0; z < group.Count(); z++)
                        {
                            string word = group.GetWord(z);
                            if (word.Length == 0 || Check(word, source))
                            {
                                return true;
                            }
                        }
                    }
                    cursor++;
                }
            }
            return false;
        }
 
        private static bool Check(string blackWord, string source)
        {
            wordlenght = 0;
            int wordCnt = 0;
            //¼ì²âÔ´ÏÂһλÓαê
            nextCursor = cursor + 1;
            bool found = false;
            //±éÀú´ÊµÄÿһλ×öÆ¥Åä
            for (int i = 0; i < blackWord.Length; i++)
            {
                //ÌØÊâ×Ö·ûÆ«ÒÆÓαê
                int offset = 0;
                if (nextCursor >= source.Length)
                {
                    break;
                }
                else
                {
                    //¼ì²âÏÂλ×Ö·ûÈç¹û²»ÊǺº×Ö Êý×Ö ×Ö·û Æ«ÒÆÁ¿¼Ó1,,¹ýÂËÌØÊâ×Ö·û
                    for (int y = nextCursor; y < source.Length; y++)
                    {
                        //if (!IsCHS(source[y]) && !IsNum(source[y]) && !IsAlphabet(source[y])) {
                        if (IsSpecial(source[y]))
                        {
                            offset++;
                            //±ÜÈÃÌØÊâ×Ö·û£¬ÏÂλÓαêÈç¹û>=×Ö·û´®³¤¶È Ìø³ö
                            if (nextCursor + offset >= source.Length) break;
                            wordlenght++;
 
                        }
                        else break;
                    }
                    if (nextCursor + offset >= source.Length)
                    {
                        break;
                    }
                    if ((int)blackWord[i] == (int)source[nextCursor + offset])
                    {
                        wordCnt++;
                        found = true;
                    }
                    else
                    {
                        found = false;
                        break;
                    }
                }
                nextCursor = nextCursor + 1 + offset;
                wordlenght++;
            }
            if (blackWord.Length != wordCnt) return false;
            return found;
        }
 
        private static bool IsSpecial(char character)
        {
            if (character == ' ')
            {
                return true;
            }
            return false;
        }
 
        static public void DirtyNameInit()
        {
            if (dirtyNameInited)
            {
                return;
            }
 
            dirtyNameInited = true;
 
            ThreadPool.QueueUserWorkItem((object aaa) =>
            {
                memoryList.Sort((string x, string y) =>
                {
                    return x.CompareTo(y);
                });
                for (int i = memoryList.Count - 1; i > 0; i--)
                {
                    if (memoryList[i].ToString() == memoryList[i - 1].ToString())
                    {
                        memoryList.RemoveAt(i);
                    }
                }
                foreach (string word in memoryList)
                {
                    WordGroup group = DIRTYWORLD[(int)word[0]];
                    if (group == null)
                    {
                        group = new WordGroup();
                        DIRTYWORLD[(int)word[0]] = group;
                    }
                    group.Add(word.Substring(1));
                }
            });
        }
 
        public static bool IsCHS(char character)
        {
            //  ÖÐÎıíÒâ×Ö·ûµÄ·¶Î§ 4E00-9FA5
            int charVal = (int)character;
            return (charVal >= 0x4e00 && charVal <= 0x9fa5);
        }
 
        private static bool IsNum(char character)
        {
            int charVal = (int)character;
            return (charVal >= 48 && charVal <= 57);
        }
 
        private static bool IsAlphabet(char character)
        {
            int charVal = (int)character;
            return ((charVal >= 97 && charVal <= 122) || (charVal >= 65 && charVal <= 90));
        }
 
        private const string FACE_REPLACE = @"#~[0-9a-zA-Z]{1,3}";
        private static Regex FaceRegex = new Regex(FACE_REPLACE, RegexOptions.Singleline);
        public static string FitterSpecial(string source)
        {
            return FaceRegex.Replace(source, "     ");
        }
    }