Пример #1
0
        public ActionResult Registration(Registration regUser)
        {
            AllMethods  allMet = new AllMethods();
            List <User> users  = allMet.GetAllUser();

            if (users.Exists(x => x.UserName.Equals(regUser.UserName)))
            {
                return(RedirectToAction("Login", "Authorization"));
            }
            else
            {
                User user = new User();
                user.UserName = regUser.UserName;
                user.Password = regUser.Password;
                user.Name     = regUser.Name;
                user.LastName = regUser.LastName;
                user.Role     = regUser.Role;
                user.Number   = regUser.Number;
                user.Email    = regUser.Email;
                users.Add(user);
            }

            using (StreamWriter sw = new StreamWriter(Server.MapPath(path)))
            {
                foreach (var item in users)
                {
                    sw.WriteLine(item.UserName + "," + item.Password + "," + item.Name + "," + item.LastName + "," + item.Role + "," + item.Number + "," + item.Email);
                }
            }
            return(RedirectToAction("Login", "Authorization"));
        }
        public virtual JsonRpcResponse Execute()
        {
            JsonRpcResponse response = new JsonRpcResponse();
            // get the method from RpcMethods
            MethodInfo mi = RpcMethods.FirstOrDefault(m => m.Name.Equals(Method, StringComparison.InvariantCultureIgnoreCase));

            // if its not there get it from all methods
            if (mi == null)
            {
                mi = AllMethods.FirstOrDefault(m => m.Name.Equals(Method, StringComparison.InvariantCultureIgnoreCase));
            }
            // if its not there set error in the response
            if (mi == null)
            {
                response = GetErrorResponse(JsonRpcFaultCodes.MethodNotFound);
            }
            else
            {
                ExecutionRequest execRequest = ExecutionRequest.Create(Incubator, mi, GetInputParameters(mi));
                if (execRequest.Execute())
                {
                    response.Result = execRequest.Result;
                }
                else
                {
                    response = GetErrorResponse(JsonRpcFaultCodes.InternalError);
                }
            }

            return(response);
        }
Пример #3
0
        static void Zad2()
        {
            Console.WriteLine("\nЗАДАНИЕ 2\n");
            StringMethods test = new StringMethods
            {
                CurrentString = "Тестовая,   строка,   привет   ААББВВ."
            };

            Console.WriteLine(test.CurrentString);

            AllMethods allMethods = test.DeleteCommas;

            allMethods += test.RemoveSpaces;
            allMethods += test.ToUpperCase;
            allMethods();
            Console.WriteLine(test.CurrentString);
            Action <int, int> add;

            add = test.AddCharacters;
            CharacterPos(10, 5, add);
            Func <char, char, string> Replace = test.ReplaceAtoB;

            Console.WriteLine(Check(' ', '\\', Replace));
            Console.ReadLine();
        }
Пример #4
0
        //Login
        public ActionResult Login(Login user)
        {
            AllMethods  allMet = new AllMethods();
            List <User> users  = allMet.GetAllUser();

            foreach (var item in users)
            {
                //proverava username i password i na osnovu toga formira se cookie
                if (item.UserName.Equals(user.UserName) && item.Password.Equals(user.Password))
                {
                    var identity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, user.UserName),
                        new Claim(ClaimTypes.Surname, user.Password),
                        new Claim(ClaimTypes.Role, item.Role)
                    },
                                                      "21345678908765432");

                    var auth        = Request.GetOwinContext();
                    var authManager = auth.Authentication;
                    authManager.SignIn(identity);
                    return(RedirectToAction("Index", "Furniture"));
                }
            }

            return(View(user));
        }
Пример #5
0
        }                                               //是否是结构体
        public GenerateScorpioClass(Type type)
        {
            m_Type           = type;
            IsStruct         = !type.IsClass;
            FullName         = ScorpioReflectUtil.GetFullName(m_Type);
            ScorpioClassName = "ScorpioClass_" + ScorpioReflectUtil.GetGenerateClassName(type);
            AllFields.AddRange(m_Type.GetFields(ScorpioReflectUtil.BindingFlag));
            AllEvents.AddRange(m_Type.GetEvents(ScorpioReflectUtil.BindingFlag));
            var propertys = m_Type.GetProperties(ScorpioReflectUtil.BindingFlag);

            foreach (var property in propertys)
            {
                //如果是 get 则参数是0个  set 参数是1个  否则就可能是 [] 的重载
                if ((property.CanRead && property.GetGetMethod().GetParameters().Length == 0) ||
                    (property.CanWrite && property.GetSetMethod().GetParameters().Length == 1))
                {
                    AllPropertys.Add(property);
                }
            }
            var methods = (m_Type.IsAbstract && m_Type.IsSealed) ? m_Type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy) : m_Type.GetMethods(ScorpioReflectUtil.BindingFlag);

            foreach (var method in methods)
            {
                //屏蔽掉 模版函数 模板函数只能使用反射
                if (!ScorpioReflectUtil.CheckGenericMethod(method))
                {
                    continue;
                }
                AllMethods.Add(method);
            }
        }
Пример #6
0
        public ActionResult Delete(int id)
        {
            AllMethods     allMet = new AllMethods();
            FurnitureModel fur    = allMet.GetOneFurniture(id);

            return(View(fur));
        }
Пример #7
0
        /// <summary>
        /// Tries to find a disassembled entity, given a disassembled target.
        /// </summary>
        /// <param name="disassemblyTarget">The disassembly target.</param>
        /// <returns></returns>
        public DisassembledEntity FindDisassembledEntity(DisassemblyTarget disassemblyTarget)
        {
            //  If there's no target, we can't find anything.
            if (disassemblyTarget == null)
            {
                return(null);
            }

            switch (disassemblyTarget.TargetType)
            {
            case DisassemblyTargetType.Class:

                //  Find the class with the given name.
                return(AllClasses.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName));

            case DisassemblyTargetType.Enumeration:

                //  Find the enumeration with the given name.
                return(AllEnumerations.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName));

            case DisassemblyTargetType.Method:

                //  Find the entity with the given name.
                return(AllMethods.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName));

            case DisassemblyTargetType.Property:

                //  Find the entity with the given name.
                return(AllProperties.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName));

            case DisassemblyTargetType.Field:

                //  Find the entity with the given name.
                return(AllFields.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName));

            case DisassemblyTargetType.Structure:

                //  Find the structure with the given name.
                return(AllStructures.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName));

            case DisassemblyTargetType.Interface:

                //  Find the structure with the given name.
                return(AllInterfaces.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName));

            case DisassemblyTargetType.Event:

                //  Find the structure with the given name.
                return(AllEvents.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName));

            case DisassemblyTargetType.Delegate:

                //  Find the structure with the given name.
                return(AllDelegates.FirstOrDefault(c => c.FullName == disassemblyTarget.FullName));


            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #8
0
        public ActionResult Delete(int?id)
        {
            AllMethods allMet = new AllMethods();

            allMet.DeleteFurniture(id);

            return(RedirectToAction("Index"));
        }
Пример #9
0
        public ActionResult Create([Bind(Include = "ID, Name, Colour, OriginCountry, ManufacturerName, Price, Quantity, Category, ProductionYear, SalonName")]
                                   FurnitureModel furniture)
        {
            AllMethods allMet = new AllMethods();

            allMet.AddFurniture(furniture);
            return(RedirectToAction("Index"));
        }
Пример #10
0
        public void DivideByZeroTest()
        {
            //Arrange
            AllMethods tes = new AllMethods();

            //Act
            //Assert
            Assert.That(() => tes.Division(x, z), Throws.TypeOf <DivideByZeroException>());
        }
Пример #11
0
 public static MemberInfo GetSomeMember()
 {
     return(GetRandomElement(
                AllMethods.Cast <MemberInfo> ()
                .Concat(s_instanceFields)
                .Concat(s_staticFields)
                .Concat(s_defaultCtors)
                .ToArray()));
 }
Пример #12
0
        public void Substract_7from12()
        {
            //Arrange
            int expected2 = 5;
            //Act
            int actual2 = AllMethods.Substract(12, 7);

            //Assert
            Assert.AreEqual(expected2, actual2);
        }
Пример #13
0
        // GET: Furniture
        public ActionResult Index(string searchBy, string search)
        {
            AllMethods            allMet = new AllMethods();
            List <FurnitureModel> list   = new List <FurnitureModel>();

            list = allMet.GetAllFurniture();

            if (searchBy == "Name")
            {
                return(View(list.Where(x => (x.Name.ToLower()).StartsWith(search.ToLower()) ||
                                       (x.Name.ToLower()).Contains(search.ToLower()) || search == null).ToList()));
            }
            else if (searchBy == "Colour")
            {
                return(View(list.Where(x => (x.Colour.ToLower()).StartsWith(search.ToLower()) ||
                                       (x.Colour.ToLower()).Contains(search.ToLower()) || search == null).ToList()));
            }
            else if (searchBy == "OriginCountry")
            {
                return(View(list.Where(x => (x.OriginCountry.ToLower()).StartsWith(search.ToLower()) ||
                                       (x.OriginCountry.ToLower()).Contains(search.ToLower()) || search == null).ToList()));
            }
            else if (searchBy == "ManufacturerName")
            {
                return(View(list.Where(x => (x.ManufacturerName.ToLower()).StartsWith(search.ToLower()) ||
                                       (x.ManufacturerName.ToLower()).Contains(search.ToLower()) || search == null).ToList()));
            }
            else if (searchBy == "Price")
            {
                return(View(list.Where(x => x.Price.ToString() == search || search == null).ToList()));
            }
            else if (searchBy == "Quantity")
            {
                return(View(list.Where(x => x.Quantity.ToString() == search || search == null).ToList()));
            }
            else if (searchBy == "Category")
            {
                return(View(list.Where(x => (x.Category.ToLower()).StartsWith(search.ToLower()) ||
                                       (x.Category.ToLower()).Contains(search.ToLower()) || search == null).ToList()));
            }
            else if (searchBy == "ProductionYear")
            {
                return(View(list.Where(x => x.ProductionYear.ToString() == search || search == null).ToList()));
            }
            else if (searchBy == "SalonName")
            {
                return(View(list.Where(x => (x.SalonName.ToLower()).StartsWith(search.ToLower()) ||
                                       (x.SalonName.ToLower()).Contains(search.ToLower()) || search == null).ToList()));
            }
            else
            {
                return(View(list));
            }
        }
Пример #14
0
        public void Substract_7from5()
        {
            //Arrange
            int expected1 = -2;
            //int expected1 = -3; // wrong
            //Act
            int actual1 = AllMethods.Substract(5, 7);

            //Assert
            Assert.AreEqual(expected1, actual1);
        }
Пример #15
0
        public void MultiplicationTest()
        {
            //Arrange
            AllMethods tes = new AllMethods();

            //Act
            double actual   = tes.Multiplication(x, y);
            double expected = 300;

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
Пример #16
0
        private void BtnRandoScene_Click(object sender, EventArgs e)
        {
            if (directory != null)
            {
                try
                {
                    if (txtSeed.Text != "")
                    {
                        seed = int.Parse(txtSeed.Text);
                        rnd  = new Random(seed);
                    }
                    else
                    {
                        seed = Environment.TickCount;
                        rnd  = new Random(seed);
                        //rnd = new Random(Guid.NewGuid().GetHashCode());
                    }
                    options = OptionsArrayBuild();
                    //string fileName = lblFileName.Text;
                    byte[] kernelLookup = GZipper.PrepareScene(directory, options, rnd, seed);
                    GZipper.PrepareKernel(directory, kernelLookup, options, rnd, seed);
                    MessageBox.Show("Rando Complete: seed = " + seed);

                    string seedFile = directory + "\\FF7RandomSeeds.txt";
                    if (!File.Exists(seedFile))
                    {
                        using (FileStream fs = File.Create(seedFile))
                        {
                            Byte[] title = new UTF8Encoding(true).GetBytes("Random Seed History");
                            fs.Write(title, 0, title.Length);
                        }
                    }

                    using (StreamWriter w = File.AppendText(seedFile))
                    {
                        AllMethods.Log(seed, w);
                    }

                    using (StreamReader r = File.OpenText(seedFile))
                    {
                        AllMethods.DumpLog(r);
                    }
                }
                catch
                {
                    MessageBox.Show("Error: Randomisation Failed - Check that valid files are in correct locations; if so, report the bug along with selected parameters and files used.");
                }
            }
            else
            {
                MessageBox.Show("Error: Valid directory required");
            }
        }
Пример #17
0
        public void SubtractionTest()
        {
            //Arrange
            AllMethods tes = new AllMethods();

            //Act
            double actual   = tes.Subtraction(x, y);
            double expected = 5;

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
Пример #18
0
 public void Sort_By_LastName()
 {
     //Arrange
     string[] expected = new string[] { "Evelynn", "Dharwin", "Christine", "Boris", "Abraham" };
     //Act
     string[] actual = AllMethods.OrderBy(1);
     //Assert
     //Assert.AreEqual(expected,actual);
     for (int i = 0; i < expected.Length; i++)
     {
         Assert.AreEqual(expected[i], actual[i]);
     }
 }
Пример #19
0
        public void StartTracingMethod(MethodLog methodLog)
        {
            if (_methodStackTrace.Count == 0)
            {
                AllMethods.Add(methodLog);
            }
            else
            {
                _methodStackTrace.Peek().AddNestedMethods(methodLog);
            }

            _methodStackTrace.Push(methodLog);
        }
Пример #20
0
        public void DivisionTest()
        {
            //Arrange
            y = 2;
            AllMethods tes = new AllMethods();

            //Act
            double actual   = tes.Division(x, y);
            double expected = 10;

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
 public static void WritingMethod(int timesToInput)
 {
     using (var sw = new StreamWriter(path, true))
         for (var list = items.ToArray(); timesToInput-- > 0;)
         {
             var inputs = new Dictionary <String, object>();
             for (var i = 0; i < list.Length; ++i)
             {
                 var item   = list[i];
                 var prompt = String.Format(" Enter your {0}: ", item.Key);
                 inputs.Add(
                     item.Key, AllMethods.ReadData(prompt, item.Value));
             }
             var output = String.Format(format, inputs.Values.ToArray());
             sw.WriteLine(output + Environment.NewLine);
             Console.WriteLine(output);
             Console.ReadLine();
         }
 }
Пример #22
0
        public ActionResult SubDepts(int KEY)

        {
            Departments dpt = new Departments();

            dpt.KEY_GLOBAL_DEPT = KEY;

            AllMethods am = new AllMethods();

            am.ListMethodscoda   = dpt.GetcodaDepartments(Database);
            am.ListMethodsfast   = dpt.GetfastDepartments(Database);
            am.ListMethodsgems   = dpt.GetgemsDepartments(Database);
            am.ListMethodsoasis  = dpt.GetoasisDepartments(Database);
            am.ListMethodsbanner = dpt.GetbannerDepartments(Database);
            am.ListMethodsidx    = dpt.GetidxDepartments(Database);
            am.ListMethodsepic   = dpt.GetepicDepartments(Database);
            am.ListMethodssamas  = dpt.GetsamasDepartments(Database);

            return(PartialView("SubDepts", am));
        }
Пример #23
0
            public void buildGui()
            {
                AstEngine.HostPanel.clear();
                "Calculating Mappings fro Methods called".info();
                MethodsCalledMappings    = AstEngine.AstData.calculateMappingsFor_MethodsCalled();
                MethodIsCalledByMappings = AstEngine.AstData.calculateMappingsFor_MethodIsCalledBy(MethodsCalledMappings);

                AllMethods = this.MethodsCalledMappings.Keys.toList();
                AllMethods.add_OnlyNewItems(this.MethodIsCalledByMappings.Keys.toList());
                "MethodsCalledMappings has {0} root methods".info(MethodsCalledMappings.Keys.size());
                "MethodIsCalledByMappings has {0} root methods".info(MethodIsCalledByMappings.Keys.size());
                "AllMethods has {0} root methods".info(AllMethods.size());

                ParentTabControl         = AstEngine.HostPanel.add_TabControl();
                TreeViewModeTab          = ParentTabControl.add_Tab("TreeView Mode");
                GraphModeTab             = ParentTabControl.add_Tab("Graph Mode");
                InteractiveBrowseModeTab = ParentTabControl.add_Tab("Interactive Browse Mode");
                build_TreeViewMode(TreeViewModeTab);
                build_GraphMode(GraphModeTab);
            }
Пример #24
0
        public ActionResult AddToCart(int id)
        {
            AllMethods            allMet = new AllMethods();
            FurnitureModel        fur    = allMet.GetOneFurniture(id);
            List <FurnitureModel> list   = new List <FurnitureModel>();

            list = allMet.GetAllFurniture();
            int sum;

            if (fur.Quantity >= 1)
            {
                sum          = fur.Quantity - (fur.Quantity - 1);
                fur.Quantity = sum;
                shoppingList.Add(fur);
                for (int i = 0; i < list.Count; i++)
                {
                    list[i].Quantity = list[i].Quantity - 1;
                }

                list = allMet.GetAllFurniture();
            }

            return(RedirectToAction("Index"));
        }
Пример #25
0
 public static void Main(string[] args)
 {
     AllMethods.Method2();
 }
Пример #26
0
        static void Main(string[] args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            //Console.WriteLine(AllMethods.Hammin("accde", "abcde"));
            //Console.WriteLine(AllMethods.CountWords("Just an example here move along"));
            //Console.WriteLine(AllMethods.CharCount('a',"edabit"));
            //int[] arr = { 2, 3, 1, 0 };
            //int[] result = AllMethods.MultiplyByLength(arr);
            //foreach (var item in result)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.WriteLine(AllMethods.MonthName(11));
            //double[] array = { 1, 2, 3, 4, 5 };
            //double[] result = AllMethods.FindMinMax(array);
            //foreach (var item in result)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.WriteLine(AllMethods.NumberSyllables("beau-ti-ful"));
            //Console.WriteLine(AllMethods.IsIdentical("ab"));
            //Console.WriteLine(AllMethods.Factorial(5));
            //Console.WriteLine(AllMethods.IsBetween("ostracize", "ostrich", "open"));
            //int[] array = AllMethods.NoOdds(new int[] { 43, 65, 23, 89, 53, 9, 6 });
            //foreach (var item in array)
            //{
            //    Console.WriteLine(item);
            //}
            //object[] objects = AllMethods.RemoveDups(new object[] { 1, 2, 2, 2, 3, 2, 5, 2, 6, 6, 3, 7, 1, 2, 5 });
            //foreach (var item in objects)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.WriteLine(AllMethods.DoubleChar("String"));
            //Console.WriteLine(AllMethods.SubReddit("https://www.reddit.com/r/awww/"));
            //Console.WriteLine(AllMethods.CheckPalindrome("redder"));
            //Console.WriteLine(AllMethods.LettersOnly(",1|2)\")A^1<[_)?^\"]l[a`3+%!d@8-0_0d.*}i@&n?="));
            //int[] array = AllMethods.ArrayOfMultiples(7,5);
            //for (int i = 0; i < array.Length; i++)
            //{
            //    Console.Write(array[i] + " ");
            //}
            //Console.WriteLine(AllMethods.CounterpartCharCode('A'));
            //int[] array = AllMethods.FilterArray(new object[] { 1, 2, "a", "b" });
            //foreach (var item in array)
            //{
            //    Console.Write(item + " ");
            //}
            //Console.WriteLine(AllMethods.Fact(5));
            //Console.WriteLine(AllMethods.IsStrangePair("", ""));
            //Console.WriteLine(AllMethods.MyPi(15)); ;
            //Console.WriteLine(AllMethods.XO("Xo"));
            //Console.WriteLine(AllMethods.Century(1801));
            //Console.WriteLine(AllMethods.IsSmooth("Ben naps so often"));
            //Console.WriteLine(AllMethods.Gcd(8, 12));
            //Console.WriteLine(AllMethods.NoYelling("I just cannot believe it!!!!"));
            //Console.WriteLine(AllMethods.GetMiddle("testing"));
            //Console.WriteLine(AllMethods.ReverseAndNot(1200));
            //Console.WriteLine(AllMethods.MysteryFunc("A3B2V3B2"));
            //Console.WriteLine(AllMethods.ConvertToHex("hello world"));
            //Console.WriteLine(AllMethods.Days(2,2018));
            //Console.WriteLine(AllMethods.DuplicateCount("aa1112"));
            //Console.WriteLine(AllMethods.TextToNum("123-647-EYES"));
            //double[] array = AllMethods.CumulativeSum(new double[] { });
            //foreach (var item in array)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.WriteLine(AllMethods.AlmostPalindrome("ggggi"));
            //Console.WriteLine(AllMethods.Brackets(" (...)...(..(...).... )  "));
            //Console.WriteLine(AllMethods.AlphabetIndex("Wow, does that work?"));
            //Console.WriteLine(AllMethods.Trouble(888, 888));
            //Console.WriteLine(AllMethods.IsValidPhoneNumber("-123) 323-4455"));
            //Console.WriteLine(AllMethods.LongestCommonEnding("pitiful", "beautiful"));
            //Console.WriteLine(AllMethods.ReversedBinaryInteger(776));
            //Console.WriteLine(AllMethods.ConvertTime("12:00 am"));
            //Console.WriteLine(AllMethods.IsParselTongue("You ssseldom sssspeak sso boldly, ssso messmerizingly."));
            //Console.WriteLine(AllMethods.Mangle("Should we start class now, or should we wait for everyone to get here?"));
            //int[] array = AllMethods.RemoveSmallest(new int[] { 1, 2, 3, 4, 5 });
            //foreach (var item in array)
            //{
            //    Console.WriteLine(item);
            //}
            //Console.WriteLine(AllMethods.TextToNumberBinary("one Zero zero one zero zero one one one one one zero oNe one one zero one zerO"));
            //Console.WriteLine(AllMethods.MinTurns("4587","4321"));
            //Console.WriteLine(AllMethods.ToSnakeCase("helloEdabit"));
            //Console.WriteLine(AllMethods.ToCamelCase("hello_edabit"));
            //Console.WriteLine(AllMethods.AverageWordLength("Adsfsd, sdfsdfB C"));
            //Console.WriteLine(AllMethods.WeekdayRobWasBornInDutch(1945, 9, 2));
            //Console.WriteLine(AllMethods.IsValidIP("123.045.067.089"));
            //Console.WriteLine(AllMethods.FirstIndex("74 68 65 20 6e 65 65 64 6c 65 20 69 73 20 74 6f 20 62 65 20 66 6f 75 6e 64", "needle"));
            //Console.WriteLine(AllMethods.ValidatePassword("Fhg93@"));
            //Console.WriteLine(AllMethods.LandscapeType(new int[] { 3, 4, 5, 4, 3 }));
            //Console.WriteLine(AllMethods.Remainder(1,3));
            //Console.WriteLine(AllMethods.ValidName("H. g. Wells"));
            //Console.WriteLine(AllMethods.SameLetterPattern("ACAB", "CDCD"));
            //Console.WriteLine(Allmethods.MysteryFunc(149));
            //Console.WriteLine(Allmethods.WurstIsBetter("Il n’arrête pas de faire l’andouille"));
            //Console.WriteLine(AllMethods.Is_Dividable_By(-12, 2, -6));
            //Console.WriteLine(AllMethods.Is_Dividable_By(-12, 2, -5));
            //Console.WriteLine(AllMethods.Is_Dividable_By(45, 1, 6));
            //Console.WriteLine(AllMethods.Is_Dividable_By(45, 5, 15));
            //Console.WriteLine(AllMethods.Is_Dividable_By(4, 1, 4));
            //Console.WriteLine(AllMethods.Is_Dividable_By(15, -5, 3));
            //int[][] array = new int[][] {
            //    new int[] { 1, 2, 3, 1 },
            //    new int[] { 4, 5, 6, 4 },
            //    new int[] { 7, 8, 9, 7 },
            //    new int[] { 7, 8, 9, 7 }};
            //int[] result = AllMethods.Snail(array);
            //foreach (var item in result)
            //{
            //    Console.Write(item + " ");
            //}
            //Console.WriteLine(AllMethods.IsPerfectPower(4));
            //Console.WriteLine(AllMethods.Buddy(10, 50));
            //List<string> pinVariations = AllMethods.GetPINs("10");
            //foreach (var pin in pinVariations)
            //{
            //    Console.Write(pin + " ");
            //}
            //BigInteger[] result = AllMethods.Mixbonacci(new string[] { "tet" }, 10);
            //foreach (var item in result)
            //{
            //    Console.Write(item + " ");
            //}
            //Console.WriteLine(AllMethods.SongDecoder("WUBWUBABCWUB"));
            //Console.WriteLine(AllMethods.DuplicateEncode("(( @"));
            //Console.WriteLine(AllMethods.RowSumOddNumbers(42));
            //int[] result = AllMethods.ArrayDiff(new int[] { 1, 2, 231312,4324324,124123,4324234 }, new int[] { 2,2,3,3,4324234,432432 });
            //foreach (var item in result)
            //{
            //    Console.WriteLine(item);
            //}
            //string[] result = AllMethods.Dup(new string[] { "ccooddddddewwwaaaaarrrrsssss", "piccaninny", "hubbubbubboo" });
            //foreach  (string word in result)
            //{
            //    Console.WriteLine(word);
            //}
            //Tuple<char?, int> result = AllMethods.LongestRepetition("aabb");
            //Console.WriteLine(result.Item1);
            //Console.WriteLine(result.Item2);
            //Console.WriteLine(AllMethods.DigitalRoot(345234));
            //Console.WriteLine(AllMethods.Rot13("swZkkHx"));
            //Console.WriteLine(AllMethods.SayMeOperations("10 2 5 -3 -15 12"));
            //Console.WriteLine(AllMethods.Score(new int[] { 2, 2, 2, 2, 1 }));
            //Console.WriteLine(AllMethods.Greet("JACK"));
            //Console.WriteLine(AllMethods.FindMissingLetter(new[] { 'a', 'b', 'c', 'd', 'f' }));
            //Console.WriteLine(AllMethods.Encode(10, "If you wish to make an apple pie from scratch, you must first invent the universe."));
            //Console.WriteLine(AllMethods.WhatCentury("2099"));
            //var result = AllMethods.SortArray(new int[] { });
            //foreach (var value in result)
            //{
            //    Console.Write(value);
            //}
            //Console.WriteLine(AllMethods.MaxSequence(new int[] { -2, 1, -3, -4, -1, -2, -1, -5, -4 }));
            Console.WriteLine(AllMethods.Maskify("1"));
        }
Пример #27
0
        public static void PrepareKernel(string directory, byte[] kernelLookup, bool[] options, Random rnd, int seed)
        {
            string kernelDirectory = directory + "\\kernel\\";       // The battle folder where scene.bin resides
            string targetKernel    = kernelDirectory + "KERNEL.bin"; // The kernel.bin for updating the lookup table
            string backupKernel    = targetKernel + "Backup";

            int[][]   jaggedKernelInfo = new int[27][];   // An array of arrays, containing compressed size, uncompressed size, section ID
            ArrayList listedKernelData = new ArrayList(); // Contains all the compressed kernel section data

            byte[] header = new byte[4];                  //Retrieves header information for conversion to int

            int compressedSize;                           // Stores the compressed size of the file
            int uncompressedSize;                         // Stores the uncompressed size of the file
            int sectionID;                                // Stores the section ID of the file
            int offset = 0;                               // Tracks where we are in the kernel.bin

            int headerOffset = 0;                         // Stores the absolute offset value for each section's header (updated on each loop)

            int r = 0;                                    // ro ro
            int o = 0;                                    // fight the powah

            // Step 1: Read the kernel headers
            while (r < 27) // 27 sections in the kernel
            {
                // Opens and reads the headers in the kernel.bin
                FileStream stepOne = new FileStream(targetKernel, FileMode.Open, FileAccess.Read);
                stepOne.Seek(headerOffset, SeekOrigin.Begin);

                stepOne.Read(header, 0, 2); // Header never exceeds 64 bytes
                compressedSize = AllMethods.GetLittleEndianInt(header, 0);

                stepOne.Read(header, 0, 2); // Header never exceeds 64 bytes
                uncompressedSize = AllMethods.GetLittleEndianInt(header, 0);

                stepOne.Read(header, 0, 2); // Header never exceeds 64 bytes
                sectionID = AllMethods.GetLittleEndianInt(header, 0);

                // Stored kernel header information in a jaggy array
                jaggedKernelInfo[o] = new int[] { compressedSize, uncompressedSize, sectionID };
                stepOne.Close();

                headerOffset += compressedSize + 6;
                r++;
                o++;
                stepOne.Close();
            }
            r = 0;
            o = 0;


            // Step 2: Get the compressed data, uncompress it, and then randomise it
            while (r < 27)
            {
                int    bytesRead;
                int    size = jaggedKernelInfo[o][1];
                byte[] uncompressedKernel = new byte[size]; // Used to hold the decompressed kernel section

                using (BinaryReader brg = new BinaryReader(new FileStream(targetKernel, FileMode.Open)))
                {
                    // Calls method to convert little endian values into an integer
                    byte[] compressedKernel = new byte[jaggedKernelInfo[o][0]]; // Used to hold the compressed scene file, where [o][1] is scene size

                    brg.BaseStream.Seek(offset + 6, SeekOrigin.Begin);          // Starts reading the compressed scene file
                    brg.Read(compressedKernel, 0, compressedKernel.Length);

                    using (MemoryStream inputWrapper = new MemoryStream(compressedKernel))
                    {
                        using (MemoryStream decompressedOutput = new MemoryStream())
                        {
                            using (GZipStream zipInput = new GZipStream(inputWrapper, CompressionMode.Decompress, true))
                            {
                                while ((bytesRead = zipInput.Read(uncompressedKernel, 0, size)) != 0)
                                {
                                    decompressedOutput.Write(uncompressedKernel, 0, bytesRead);
                                }
                                zipInput.Close();
                            }
                            decompressedOutput.Close();
                        }
                        inputWrapper.Close();
                    }
                    brg.Close();
                }

                // Sends decompressed scene data to be randomised by section
                switch (r)
                {
                case 0:
                    Kernel.RandomiseSection0(uncompressedKernel, options, rnd, seed);
                    break;

                case 1:
                    Kernel.RandomiseSection1(uncompressedKernel, options, rnd, seed);
                    break;

                case 2:
                    Kernel.RandomiseSection2(uncompressedKernel, options, rnd, seed, kernelLookup);
                    break;

                case 3:
                    Kernel.RandomiseSection3(uncompressedKernel, options, rnd, seed);
                    break;

                case 4:
                    Kernel.RandomiseSection4(uncompressedKernel, options, rnd, seed);
                    break;

                case 5:
                    Kernel.RandomiseSection5(uncompressedKernel, options, rnd, seed);
                    break;

                case 6:
                    Kernel.RandomiseSection6(uncompressedKernel, options, rnd, seed);
                    break;

                case 7:
                    Kernel.RandomiseSection7(uncompressedKernel, options, rnd, seed);
                    break;

                case 8:
                    Kernel.RandomiseSection8(uncompressedKernel, options, rnd, seed);
                    break;
                }

                // Recompress the altered uncompressed data back into GZip
                byte[] recompressedKernel;
                using (var result = new MemoryStream())
                {
                    using (var compressionStream = new GZipStream(result, CompressionMode.Compress))
                    {
                        compressionStream.Write(uncompressedKernel, 0, uncompressedKernel.Length);
                        compressionStream.Close();
                    }
                    recompressedKernel = result.ToArray();
                    result.Close();
                }
                // Offset is updated for the next pass before we write in our new value
                offset += jaggedKernelInfo[o][0] + 6;

                // The size is updated with the newly compressed/padded scene's length
                jaggedKernelInfo[o][0] = recompressedKernel.Length;

                // Byte array is added to the ArrayList
                listedKernelData.Add(recompressedKernel);
                r++;
                o++;
            }
            r = 0;
            o = 0;


            // Step 3: Rebuilding the Kernel.bin
            using (var outputStream = File.Create(targetKernel))
            {
                // Loops until all 27 sections are headered and written
                while (r < 27)
                {
                    // Write the header first
                    byte[] bytes      = new byte[2];
                    byte[] kernelHead = new byte[6];
                    ulong  comSize    = (ulong)jaggedKernelInfo[o][0];
                    ulong  uncomSize  = (ulong)jaggedKernelInfo[o][1];
                    ulong  sectID     = (ulong)jaggedKernelInfo[o][2];

                    bytes         = AllMethods.GetLittleEndianConvert(comSize);
                    kernelHead[0] = bytes[0];
                    kernelHead[1] = bytes[1];

                    bytes         = AllMethods.GetLittleEndianConvert(uncomSize);
                    kernelHead[2] = bytes[0];
                    kernelHead[3] = bytes[1];

                    bytes         = AllMethods.GetLittleEndianConvert(sectID);
                    kernelHead[4] = bytes[0];
                    kernelHead[5] = bytes[1];

                    // Takes the header data, converts it into a stream, and then appends it to the file-in-progress
                    outputStream.Position = outputStream.Length;
                    outputStream.Write(kernelHead, 0, kernelHead.Length);

                    // Takes the byte data from the ArrayList, converts it into a stream, and then appends it to the file-in-progress
                    byte[] kernelData = (byte[])listedKernelData[o];
                    outputStream.Position = outputStream.Length;
                    outputStream.Write(kernelData, 0, kernelData.Length);

                    r++;
                    o++;
                }
                r = 0;
                o = 0;
            }
        }
Пример #28
0
        public static byte[] PrepareScene(string directory, bool[] options, Random rnd, int seed)
        {
            string sceneDirectory = directory + "\\battle\\";     // The battle folder where scene.bin resides
            string targetScene    = sceneDirectory + "scene.bin"; // The target file itself
            string backupScene    = targetScene + "Backup";

            if (!Directory.Exists(backupScene))            // Ensures backup isn't overwritten
            {
                File.Copy(targetScene, backupScene, true); // Creates a backup of the scene.bin
            }

            byte[] header = new byte[64];                         /* Stores the block header
                                                                   * [0-4] = Offset for first GZipped data file (3 enemies per file)
                                                                   * Header total size must be 40h - empty entries == FF FF FF FF
                                                                   */

            int[][]   jaggedSceneInfo = new int[256][];           // An array of arrays, containing offset, size, and absoluteoffset for each scene file
            ArrayList listedSceneData = new ArrayList();          // Contains all the compressed scene data

            int[][][] jaggedModelAttackTypes = new int[3000][][]; // Contains all the uncompressed Attack Anim data

            long initialSize;                                     // The size of the initial scene.bin (can vary, up to 63 blocks but typically 32-33
            int  size;                                            // The size of the compressed file
            int  offset;                                          // Stores the current scene offset
            int  nextOffset;                                      // Stores the next scene offset
            int  absoluteOffset;                                  // Stores the scene's absolute offset in the scene.bin
            int  finalOffset  = 0;                                // Stores the scene's adjusted offset in the scene.bin
            int  headerOffset = 0;                                // Offset of the current block header; goes up in 2000h (8192) increments

            byte[] padder = new byte[1];                          // Scene files, after compression, need to be FF padded to make them multiplicable by 4
            padder[0] = 255;

            //Random rnd = new Random(Guid.NewGuid().GetHashCode());

            byte[] kernelLookup = new byte[64];                 // Stores the new lookup table to be written to the kernel.bin; blank values are FF
            int    i            = 0;

            while (i < 64)
            {
                kernelLookup[i] = 255;
                i++;
            }

            int r = 0;  // C'mon get up and make some noise
            int o = 0;  // while your whiles get looped by
            int c = 0;  // the var street boys
            int k = 0;  // *DJ scratching noises*
            int s = 0;  // *DJ scratching noises intensify*


            /* Step 1: Read the Scene.bin and retrieve its data for use later
             * The goal of this step is to build an array containing information about each scene.
             * We then use this information to derive other important information (for instance, adjusting the header offsets)
             * To get the info we need, the header of each 'block' is read (2000h per block) and this tells us where to find each scene.
             * We need to use GZip compression to get the data out, but we cannot let the Gzipper hit the header or it will break.
             */

            // Entire file is read; offsets and sizes for scenes are extracted and placed in a jagged array (an array of arrays)
            FileStream fs = new FileStream(targetScene, FileMode.Open, FileAccess.Read);

            initialSize = fs.Length;
            fs.Close();
            while (headerOffset < initialSize) // 32 blocks of 2000h/8192 bytes each
            {
                // Opens and reads the default scene.bin
                FileStream stepOne = new FileStream(targetScene, FileMode.Open, FileAccess.Read);
                stepOne.Seek(headerOffset, SeekOrigin.Begin);
                stepOne.Read(header, 0, 64); // Header never exceeds 64 bytes
                stepOne.Close();

                // Max of 16 sections in a header (is usually less however)
                while (r < 16)
                {
                    // If the 2nd byte of the current header is FF then assume there are no more valid scene headers in this block
                    if (header[c + 1] != 0xFF)
                    {
                        // Fetches the current header
                        byte[] currentHeader = new byte[4];
                        currentHeader[0] = header[c];
                        currentHeader[1] = header[c + 1];
                        currentHeader[2] = header[c + 2];
                        currentHeader[3] = header[c + 3];

                        // Fetches the next header - ignored if we're at the end of the block header
                        byte[] nextHeader = new byte[4];
                        if (r < 15)
                        {
                            nextHeader[0] = header[c + 4];
                            nextHeader[1] = header[c + 5];
                            nextHeader[2] = header[c + 6];
                            nextHeader[3] = header[c + 7];
                        }

                        // Converts the current offset and the next offset into integer
                        offset     = AllMethods.GetLittleEndianInt(currentHeader, 0);
                        nextOffset = AllMethods.GetLittleEndianInt(nextHeader, 0);

                        // Checks that next header is not empty or if we are at the last header
                        if (currentHeader[1] == 0xFF || nextHeader[1] == 0xFF || r == 15)
                        {
                            // If next header is FF FF FF FF, then we're at the end of file and should deduct 2000h to get current file size
                            size = 8192 - (offset * 4);
                        }
                        else
                        {
                            // Difference between this offset and next offset provides size; offsets need to be *4 to get actual offset
                            size = (nextOffset - offset) * 4;
                        }
                        // Gets absolute offset in the scene.bin for the current scene
                        absoluteOffset = (offset * 4) + headerOffset;
                        // Store our retrieved/derived information in our jagged array (watch out for the pointy bits)
                        jaggedSceneInfo[o] = new int[] { offset, size, absoluteOffset, finalOffset };
                        o++;
                    }
                    c += 4;
                    r++;
                }
                headerOffset += 8192;
                r             = 0;
                c             = 0;
            }
            o            = 0;
            headerOffset = 0;


            /* Step 2: Randomising the scene data
             * Using absolute offset + compressed size, we locate and decompress the file.
             * We run the scene data through the randomiser.
             * We then recompress the returned data.
             * The size will now have changed; we will update this later while generating our new scene.bin
             */

            // But first, we acquire the camera data of the target scene.bin
            ArrayList listedCameraData = Indexer.GetCameraData(jaggedSceneInfo, targetScene);

            // And the valid Animation Types for each ModelID
            jaggedModelAttackTypes = Indexer.GetAttackData(jaggedSceneInfo, targetScene);

            while (r < 256)
            {
                int    bytesRead;
                byte[] uncompressedScene = new byte[7808]; // Used to hold the decompressed scene file

                using (BinaryReader brg = new BinaryReader(new FileStream(targetScene, FileMode.Open)))
                {
                    // Calls method to convert little endian values into an integer
                    byte[] compressedScene = new byte[jaggedSceneInfo[o][1]];     // Used to hold the compressed scene file, where [o][1] is scene size
                    brg.BaseStream.Seek(jaggedSceneInfo[o][2], SeekOrigin.Begin); // Starts reading the compressed scene file
                    brg.Read(compressedScene, 0, compressedScene.Length);

                    using (MemoryStream inputWrapper = new MemoryStream(compressedScene))
                    {
                        using (MemoryStream decompressedOutput = new MemoryStream())
                        {
                            using (GZipStream zipInput = new GZipStream(inputWrapper, CompressionMode.Decompress, true))
                            {
                                while ((bytesRead = zipInput.Read(uncompressedScene, 0, 7808)) != 0)
                                {
                                    decompressedOutput.Write(uncompressedScene, 0, bytesRead);
                                }
                                zipInput.Close();
                            }
                            decompressedOutput.Close();
                        }
                        inputWrapper.Close();
                    }
                    brg.Close();
                }

                // Sends random camera data to be used
                int    rand    = (byte)rnd.Next(listedCameraData.Count);
                byte[] initCam = Indexer.InitialCamera();
                byte[] randCam = (byte[])listedCameraData[rand];
                int    sceneID = r;

                // Sends decompressed scene data to be randomised
                Scene.RandomiseScene(uncompressedScene, randCam, sceneID, options, rnd, jaggedModelAttackTypes, seed, initCam);

                // Recompress the altered uncompressed data back into GZip
                byte[] recompressedScene;
                using (var result = new MemoryStream())
                {
                    using (var compressionStream = new GZipStream(result, CompressionMode.Compress))
                    {
                        compressionStream.Write(uncompressedScene, 0, uncompressedScene.Length);
                        compressionStream.Close();
                    }
                    recompressedScene = result.ToArray();
                    result.Close();
                }

                // Checks that the file is divisible by 4; FF padding is applied otherwise
                if (recompressedScene.Length % 4 == 3)      // Remainder of 3, add 1 FF
                {
                    recompressedScene = recompressedScene.Concat(padder).ToArray();
                }
                else if (recompressedScene.Length % 4 == 2)  // Remainder of 2, add 2 FFs
                {
                    recompressedScene = recompressedScene.Concat(padder).ToArray();
                    recompressedScene = recompressedScene.Concat(padder).ToArray();
                }
                else if (recompressedScene.Length % 4 == 1)  // Remainder of 1, add 3 FFs
                {
                    recompressedScene = recompressedScene.Concat(padder).ToArray();
                    recompressedScene = recompressedScene.Concat(padder).ToArray();
                    recompressedScene = recompressedScene.Concat(padder).ToArray();
                }

                // The size is updated with the newly compressed/padded scene's length
                jaggedSceneInfo[o][1] = recompressedScene.Length;

                // Byte array is added to the ArrayList
                listedSceneData.Add(recompressedScene);
                r++;
                o++;
            }
            r = 0;
            o = 0;


            /* Step 3: Rebuilding the Scene.bin
             * We dynamically put scenes into a block until it would exceed 8192 bytes; then we create a new block.
             * The header is constantly updated with each new scene added to the block, using previous header to determine size.
             * When all 255 scenes are allocated, we finish up by padding off the last block to get a 40,000h/262,144 byte file.
             * The size will now have changed; we will update this later while generating our new scene.bin
             */

            int sizeLimit = 8193; // Want to start by making a new header so we set size higher than limit to trigger that
            int headerInt;

            byte[] finalHeader = new byte[64];

            using (var outputStream = File.Create(targetScene))
            {
                int blockCount = 0; // Counts blocks for the kernel lookup table index
                // Loops until all 255 scenes are assigned to a block
                while (r < 256)
                {
                    // Checks if the next scene will 'fit' into the current block.
                    // No scene is added yet at this time, that is only done if there's space.
                    sizeLimit += jaggedSceneInfo[o][1];

                    // If this returns true, then our block is 'full' and now needs to be padded to 8192 bytes exactly
                    // 's' represents the number of scenes currently in the block, only 16 scenes can fit into one block
                    if (sizeLimit >= 8192 || s == 16)
                    {
                        if (blockCount != 0)
                        {
                            s += kernelLookup[blockCount - 1];
                        }
                        kernelLookup[blockCount] = (byte)s;
                        blockCount++;

                        // Pads the end of the block until it hits a divisor of 8192.
                        outputStream.Position = outputStream.Length;
                        while (outputStream.Length % 8192 > 0)
                        {
                            outputStream.Write(padder, 0, 1);
                        }

                        // A new blank header of FFs is made for the start of the next new block
                        while (c < 64)
                        {
                            finalHeader[c] = 255;
                            c++;
                        }
                        finalHeader[0] = 16; //First offset is always 16h in a header
                        finalHeader[1] = 0;
                        finalHeader[2] = 0;
                        finalHeader[3] = 0;


                        if (s != 0)
                        {
                            headerOffset += 8192; // Increment headerOffset
                        }

                        // Writes the header to the file at 8192 increments
                        outputStream.Position = outputStream.Length;
                        outputStream.Write(finalHeader, 0, 64);

                        c          = 0;
                        k          = 0;
                        s          = 0;
                        sizeLimit  = jaggedSceneInfo[o][1]; // Resets size to that of the first added scene in this new block
                        sizeLimit += 64;
                    }

                    // When we write a compressed file in, we want to update the header for the next file.
                    // We'll have a +4 incrementing value to write it into the appropriate header address.
                    // This needs to avoid writing to the first header offset.

                    // Takes the byte data from the ArrayList, converts it into a stream, and then appends it to the file-in-progress
                    byte[] sceneData = (byte[])listedSceneData[o];
                    outputStream.Position = outputStream.Length;
                    outputStream.Write(sceneData, 0, sceneData.Length);

                    // Skips offset calculation if it is the first scene in the block as this is always 16h and has been written already
                    if (s != 0)
                    {
                        // Calculates this scene's offset using the previous offset + that offset's file size.
                        headerInt  = AllMethods.GetPreviousLittleEndianInt(finalHeader, k);
                        headerInt *= 4;
                        headerInt += jaggedSceneInfo[o - 1][1];
                        headerInt /= 4;

                        // Now we have new offset calculated, time to convert it into bytes and write to header.
                        byte[] bytes = BitConverter.GetBytes(headerInt);
                        finalHeader[k]     = bytes[0];
                        finalHeader[k + 1] = bytes[1];
                        finalHeader[k + 2] = bytes[2];
                        finalHeader[k + 3] = bytes[3];

                        // Write bytes to offset of k + headerOffset to our file now.
                        outputStream.Position = headerOffset;
                        outputStream.Write(finalHeader, 0, 64);
                    }
                    r++;
                    o++;
                    k += 4;
                    s++;
                }
                r = 0;  // ahhhh
                o = 0;  // We're gonna loop through whiles
                c = 0;  // all night
                k = 0;  // and try-catch every day
                s = 0;  // *gene falls over a rogue assignment*

                // All scenes allocated, the final file must now be padded to 8192 bytes
                outputStream.Position = outputStream.Length;
                while (outputStream.Length % 8192 > 0)
                {
                    outputStream.Write(padder, 0, 1);
                }
                // New scene.bin ready to go. Hopefully.
                outputStream.Close();
            }

            return(kernelLookup);
        }
Пример #29
0
        // Old Method; retrieves camera data from the scene.bin before modification.
        // Contains methods for acquiring scene data for calculations/assignment
        //public static ArrayList GetCameraData(int[][] jaggedSceneInfo, string targetScene)
        //{
        //    int r = 0;
        //    int o = 0;
        //    ArrayList listedCameraData = new ArrayList();

        //    while (r < 256)
        //    {
        //        int bytesRead;
        //        byte[] uncompressedScene = new byte[7808]; // Used to hold the decompressed scene file

        //        using (BinaryReader brg = new BinaryReader(new FileStream(targetScene, FileMode.Open)))
        //        {
        //            // Calls method to convert little endian values into an integer
        //            byte[] compressedScene = new byte[jaggedSceneInfo[o][1]]; // Used to hold the compressed scene file, where [o][1] is scene size
        //            brg.BaseStream.Seek(jaggedSceneInfo[o][2], SeekOrigin.Begin); // Starts reading the compressed scene file
        //            brg.Read(compressedScene, 0, compressedScene.Length);

        //            using (MemoryStream inputWrapper = new MemoryStream(compressedScene))
        //            {
        //                using (MemoryStream decompressedOutput = new MemoryStream())
        //                {
        //                    using (GZipStream zipInput = new GZipStream(inputWrapper, CompressionMode.Decompress, true))
        //                    {
        //                        while ((bytesRead = zipInput.Read(uncompressedScene, 0, 7808)) != 0)
        //                        {
        //                            decompressedOutput.Write(uncompressedScene, 0, bytesRead);
        //                            // If this scene has valid camera data, then pull it out.
        //                            byte[] camera = new byte[48];
        //                            if (uncompressedScene[87] != 255 && uncompressedScene[88] != 255)
        //                            {
        //                                camera = uncompressedScene.Skip(88).Take(48).ToArray();
        //                                listedCameraData.Add(camera);
        //                            }
        //                        }
        //                        zipInput.Close();
        //                    }
        //                    decompressedOutput.Close();
        //                }
        //                inputWrapper.Close();
        //            }
        //            brg.Close();
        //        }
        //        r++;
        //        o++;
        //    }
        //    return listedCameraData;
        //}

        public static int[][][] GetAttackData(int[][] jaggedSceneInfo, string targetScene)
        {
            int r = 0;
            int o = 0;
            int c = 0;
            int k = 0;
            int y = 0;

            int[][]   jaggedAttackType       = new int[1024][];     // Attack ID > Attack Type - Used to derive jaggedModelAttackTypes
            int[][][] jaggedModelAttackTypes = new int[3000][][];   // Model ID > Attack Type > Animation Indices

            while (r < 256)
            {
                int    bytesRead;
                byte[] uncompressedScene = new byte[7808]; // Used to hold the decompressed scene file

                using (BinaryReader brg = new BinaryReader(new FileStream(targetScene, FileMode.Open)))
                {
                    // Calls method to convert little endian values into an integer
                    byte[] compressedScene = new byte[jaggedSceneInfo[o][1]];     // Used to hold the compressed scene file, where [o][1] is scene size
                    brg.BaseStream.Seek(jaggedSceneInfo[o][2], SeekOrigin.Begin); // Starts reading the compressed scene file
                    brg.Read(compressedScene, 0, compressedScene.Length);

                    using (MemoryStream inputWrapper = new MemoryStream(compressedScene))
                    {
                        using (MemoryStream decompressedOutput = new MemoryStream())
                        {
                            using (GZipStream zipInput = new GZipStream(inputWrapper, CompressionMode.Decompress, true))
                            {
                                while ((bytesRead = zipInput.Read(uncompressedScene, 0, 7808)) != 0)
                                {
                                    /* Step 1: Create an array with all AttackIDs and AttackTypes
                                     * To determine attack type, we check the Impact Effect ID (phys) and Attack Effect ID (mag).
                                     * If either are FF then we can assume it is the other type. If both are FF, it is a Misc.
                                     * 0 = Phys, 1 = Mag, 2 = Misc
                                     */

                                    while (c < 32) // Iterate through all 32 entries for attack data in the scene
                                    {
                                        decompressedOutput.Write(uncompressedScene, 0, bytesRead);
                                        byte[] attackID = new byte[2];
                                        int    type;

                                        // Checks AttackID isn't blank and then takes it, converts it into Int for array index
                                        if (uncompressedScene[2113 + k] != 255)
                                        {
                                            attackID = uncompressedScene.Skip(2112 + k).Take(2).ToArray();
                                            int attackIDInt = AllMethods.GetLittleEndianIntTwofer(attackID, 0);

                                            // Checks anim and impact to determine attack type
                                            if (uncompressedScene[1217 + y] != 255)
                                            {
                                                type = 0; // Assigns this AttackID as Physical
                                                jaggedAttackType[attackIDInt] = new int[] { type };
                                            }
                                            else if (uncompressedScene[1229 + y] != 255)
                                            {
                                                type = 1; // Assigns this AttackID as Magic
                                                jaggedAttackType[attackIDInt] = new int[] { type };
                                            }
                                            else
                                            {
                                                type = 2; // Assigns this AttackID as Misc
                                                jaggedAttackType[attackIDInt] = new int[] { type };
                                            }
                                        }
                                        c++;
                                        k += 2;
                                        y += 28;
                                    }
                                    c = 0;
                                    k = 0;
                                    y = 0;


                                    /* Step 2: Create an array that has the ModelIDs and their valid animations sorted into AttackTypes
                                     * To build an array of valid animation indexes for an enemy, we need to get a record of what anim indexes
                                     * have already been set for each of its associated attacks.
                                     * 0 = Phys, 1 = Mag, 2 = Misc
                                     */

                                    int enemyCount = 0;
                                    while (enemyCount < 3) // Iterates through the 3 registerable enemy slots in this scene
                                    {
                                        decompressedOutput.Write(uncompressedScene, 0, bytesRead);
                                        byte[] modelID     = new byte[2];
                                        byte[] attackID    = new byte[2];
                                        byte[] animID      = new byte[1];
                                        int    attackCount = 0;

                                        // Checks if enemy ID is Null/FFFF
                                        if (uncompressedScene[c + 1] != 255)
                                        {
                                            modelID = uncompressedScene.Skip(c).Take(2).ToArray();
                                            int modelIDInt = AllMethods.GetLittleEndianIntTwofer(modelID, 0);
                                            jaggedModelAttackTypes[modelIDInt] = new int[3][]; // 3 entries for 3 attack types
                                            int[] physAnims = new int[16];
                                            int[] magAnims  = new int[16];
                                            int[] miscAnims = new int[16];
                                            int   physCount = 0;
                                            int   magCount  = 0;
                                            int   miscCount = 0;

                                            while (attackCount < 16) // Iterates through the 16 registerable attack slots of this enemy
                                            {
                                                // Checks AttackID isn't blank and then takes it, converts it into Int for array index
                                                if (uncompressedScene[736 + k] != 255 && uncompressedScene[736 + k] != 255)
                                                {
                                                    attackID = uncompressedScene.Skip(736 + k).Take(2).ToArray();
                                                    int attackIDInt = AllMethods.GetLittleEndianIntTwofer(attackID, 0);

                                                    // Checks if an Anim was set for this AttackID (99% of cases one will be)
                                                    if (uncompressedScene[720 + y] != 255)
                                                    {
                                                        animID = uncompressedScene.Skip(720 + y).Take(1).ToArray();

                                                        if (jaggedAttackType[attackIDInt][0] == 0) // Attack Type is physical
                                                        {
                                                            physAnims[physCount] = animID[0];
                                                            physCount++;
                                                        }
                                                        else if (jaggedAttackType[attackIDInt][0] == 1) // Attack type is magical
                                                        {
                                                            magAnims[magCount] = animID[0];
                                                            magCount++;
                                                        }
                                                        else if (jaggedAttackType[attackIDInt][0] == 2) // Attack type is miscellaneous
                                                        {
                                                            miscAnims[miscCount] = animID[0];
                                                            miscCount++;
                                                        }
                                                        else
                                                        {
                                                            MessageBox.Show("Error: An animation was not assigned correctly");
                                                        }
                                                    }
                                                }
                                                k += 2; // Tracks location of AttackID
                                                y++;    // Tracks location of Animation Indice
                                                attackCount++;
                                            }
                                            // Places the phys, mag, misc animations collected so far and places them into the jagged array
                                            jaggedModelAttackTypes[modelIDInt][0] = new int[] { physAnims[0], physAnims[1], physAnims[2], physAnims[3], physAnims[4], physAnims[5], physAnims[6], physAnims[7], physAnims[8], physAnims[9], physAnims[10], physAnims[11], physAnims[12], physAnims[13], physAnims[14], physAnims[15] };
                                            jaggedModelAttackTypes[modelIDInt][1] = new int[] { magAnims[0], magAnims[1], magAnims[2], magAnims[3], magAnims[4], magAnims[5], magAnims[6], magAnims[7], magAnims[8], magAnims[9], magAnims[10], magAnims[11], magAnims[12], magAnims[13], magAnims[14], magAnims[15] };
                                            jaggedModelAttackTypes[modelIDInt][2] = new int[] { miscAnims[0], miscAnims[1], miscAnims[2], miscAnims[3], miscAnims[4], miscAnims[5], miscAnims[6], miscAnims[7], miscAnims[8], miscAnims[9], miscAnims[10], miscAnims[11], miscAnims[12], miscAnims[13], miscAnims[14], miscAnims[15] };
                                        }
                                        else // No enemy, so we move to the data for the next one
                                        {
                                            k += 184; // Tracks location of AttackID
                                            y += 200; // Tracks location of Animation Indice
                                        }

                                        c          += 2; // Next enemy ID offset
                                        attackCount = 0;
                                        enemyCount++;
                                        k += 152;
                                        y += 168;
                                    }
                                    c = 0;
                                    k = 0;
                                    y = 0;
                                }
                                zipInput.Close();
                            }
                            decompressedOutput.Close();
                        }
                        inputWrapper.Close();
                    }
                    brg.Close();
                }
                r++;
                o++;
            }
            return(jaggedModelAttackTypes);
        }
Пример #30
0
 public static MethodInfo GetSomeMethod()
 {
     return(GetRandomElement(AllMethods.Except(s_genericMethods).ToArray()));
 }