Exemple #1
0
        private static void VerifyStructWithStringAndFieldConstant(Scs value)
        {
            Expression <Func <Scs> > e =
                Expression.Lambda <Func <Scs> >(
                    Expression.Constant(value, typeof(Scs)),
                    Enumerable.Empty <ParameterExpression>());
            Func <Scs> f = e.Compile();

            Assert.Equal(value, f());
        }
Exemple #2
0
        private static void VerifyWithParameterStructWithStringAndField(Scs value)
        {
            ConstructorInfo constructor = typeof(Scs?).GetConstructor(new Type[] { typeof(Scs) });

            Expression[] exprArgs       = new Expression[] { Expression.Constant(value, typeof(Scs)) };
            Expression <Func <Scs?> > e =
                Expression.Lambda <Func <Scs?> >(
                    Expression.New(constructor, exprArgs),
                    Enumerable.Empty <ParameterExpression>());
            Func <Scs?> f = e.Compile();

            Assert.Equal(new Scs?(value), f());
        }
Exemple #3
0
        private static void OperationTranslateScs(string filename)
        {
            Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read);
            Scs    scs    = Scs.Create(stream);

            stream.Close();

            WebClient client = new WebClient();

            client.BaseAddress = "http://translate.google.com";

            // mapXR.cpk trimming:
            int asbelindex = 0;
            int anmaindex  = scs.Entries.Count;

            for (int i = 0; i < scs.Entries.Count; i++)
            {
                if (scs.Entries[i] == "anma")
                {
                    anmaindex = i;
                }
                else if (scs.Entries[i] == "アスベル")
                {
                    asbelindex = i + 1;
                }
            }

            for (int i = asbelindex; i < anmaindex; i++)
            {
                string entry = scs.Entries[i];
                bool   ascii = true;
                for (int k = 0; k < entry.Length; k++)
                {
                    if ((int)entry[k] > 0xFF)
                    {
                        ascii = false;
                        break;
                    }
                }
                if (ascii)
                {
                    continue;
                }

                try {
                    MatchCollection            varmatches = Regex.Matches(entry, "[\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000A\u000B\u000C\u000D\u000E\u000F\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F]+\\(.+?\\)");
                    List <Pair <int, string> > variables  = new List <Pair <int, string> >();
                    foreach (Match match in varmatches)
                    {
                        variables.Add(new Pair <int, string>(match.Index, match.Value));
                        entry = entry.Replace(match.Value, "");
                    }

                    client.Encoding = Encoding.UTF8;
                    client.Headers["User-Agent"] = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.3) Gecko/20100402 Namoroka/3.6.3 (.NET CLR 3.5.30729)";
                    client.QueryString.Clear();
                    client.QueryString["client"] = "t";
                    client.QueryString["sl"]     = "ja";
                    client.QueryString["tl"]     = "en";
                    client.QueryString["text"]   = entry;
                    string          ret     = client.DownloadString("/translate_a/t");
                    MatchCollection matches = Regex.Matches(ret, "\"trans\":\"(?'text'.*?)\"");
                    ret = "";
                    foreach (Match match in matches)
                    {
                        ret += match.Groups["text"].Value + "\n";
                    }
                    while (true)
                    {
                        int indexof = ret.IndexOf("\\u");
                        if (indexof < 0)
                        {
                            break;
                        }
                        int chr = int.Parse(ret.Substring(indexof + 2, 4), NumberStyles.HexNumber);
                        ret = ret.Substring(0, indexof) + (char)chr + ret.Substring(indexof + 6);
                    }
                    while (true)
                    {
                        int indexof = ret.IndexOf("\\n");
                        if (indexof < 0)
                        {
                            break;
                        }
                        ret = ret.Substring(0, indexof) + '\n' + ret.Substring(indexof + 2);
                    }
                    while (true)
                    {
                        int indexof = ret.IndexOf("\n\n");
                        if (indexof < 0)
                        {
                            break;
                        }
                        ret = ret.Substring(0, indexof) + ret.Substring(indexof + 1);
                    }
                    if (entry[entry.Length - 1] != '\n')
                    {
                        ret = ret.TrimEnd('\n');
                    }
                    if (matches.Count > 0)
                    {
                        foreach (Pair <int, string> var in variables)
                        {
                            int index = var.Key * 2;
                            if (index >= ret.Length)
                            {
                                ret = ret + var.Value;
                            }
                            else
                            {
                                for (; index > 0 && !char.IsWhiteSpace(ret[index]); index--)                                 // Find previous break
                                {
                                    ;
                                }
                                ret = ret.Substring(0, index) + var.Value + ret.Substring(index);
                            }
                        }

                        scs.Entries[i] = ret;
                    }
                    else
                    {
                        throw new Exception("Something bad happened.");
                    }
                } catch (WebException) { }
            }

            Stream ostream = new FileStream(filename + ".new", FileMode.Create, FileAccess.Write);

            scs.Save(ostream);
            ostream.Close();
        }
Exemple #4
0
        private static void VerifyStructWithStringAndValueArrayWithUShortSize(ushort size)
        {
            // generate the expression
            Expression<Func<Scs[]>> e =
                Expression.Lambda<Func<Scs[]>>(
                    Expression.NewArrayBounds(typeof(Scs),
                        Expression.Constant(size, typeof(ushort))),
                    Enumerable.Empty<ParameterExpression>());
            Func<Scs[]> f = e.Compile();

            // get the array
            Scs[] result = null;
            Exception creationEx = null;
            try
            {
                result = f();
            }
            catch (Exception ex)
            {
                creationEx = ex;
            }

            // generate expected array
            Scs[] expected = null;
            Exception expectedEx = null;
            try
            {
                expected = new Scs[(long)size];
            }
            catch (Exception ex)
            {
                expectedEx = ex;
            }

            // if one failed, verify the other did, too
            if (creationEx != null || expectedEx != null)
            {
                Assert.NotNull(creationEx);
                Assert.NotNull(expectedEx);
                Assert.Equal(expectedEx.GetType(), creationEx.GetType());
            }
            else
            {
                // otherwise, verify the contents array
                Assert.Equal(expected.Length, result.Length);
                for (int i = 0; i < result.Length; i++)
                {
                    Assert.Equal(expected[i], result[i]);
                }
            }
        }
Exemple #5
0
 public override void OnStateEnter(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
 {
     base.OnStateEnter(animator, animatorStateInfo, layerIndex);
     Scs.OpenFire();
 }
Exemple #6
0
 public override void OnStateExit(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
 {
     Scs.HoldFire();
 }