Example #1
0
        public void TestBAC()
        {
            /*
             * Not correct length: BAC_B59
             * Bytes does not match up: BAC_CMN Position: 21C Original was: 0 Created was: 1C
             * Not correct length: BAC_EFE
             */

            List <string> exceptions = new List <string>();

            foreach (var file in Directory.GetFiles(@"Originals\BAC"))
            {
                var originalBytes = File.ReadAllBytes(file);
                var bac           = BAC.FromUassetFile(file);
                BAC.ToUassetFile(bac, @"Originals\BAC\testfile.uasset");
                var  createdBytes    = File.ReadAllBytes(@"Originals\BAC\testfile.uasset");
                bool isCorrectLength = true;

                if (originalBytes.Length != createdBytes.Length)
                {
                    exceptions.Add("Not correct length: " + Path.GetFileNameWithoutExtension(file));
                    isCorrectLength = false;
                }

                if (isCorrectLength)
                {
                    for (int i = 0; i < originalBytes.Length; i++)
                    {
                        if (originalBytes[i] != createdBytes[i])
                        {
                            exceptions.Add("Bytes does not match up: " + Path.GetFileNameWithoutExtension(file) +
                                           " Position: " + i.ToString("X") + " Original was: " +
                                           originalBytes[i].ToString("X") + " Created was: " +
                                           createdBytes[i].ToString("X"));
                        }
                    }
                }
            }

            File.Delete(@"Originals\BAC\testfile.uasset");

            foreach (var exception in exceptions)
            {
                Debug.WriteLine(exception);
            }

            if (exceptions.Count > 0)
            {
                var output = "";
                foreach (var exception in exceptions)
                {
                    output += exception + "\n";
                }

                Assert.Fail("Test failed, found exceptions:\n" + output);
            }
        }
Example #2
0
        public void OldModifiedBACJson_ShouldReadOldNames()
        {
            var filePath = "Test Files/BAC_RYU.json";

            try
            {
                var isBacSuccessful = BAC.JsonToBac(filePath, "fileOutput (unused in test)");

                Assert.IsTrue(isBacSuccessful);
            }
            catch (System.Exception e)
            {
                Debug.WriteLine("Caught exception:\n" + e.Message);
            }
        }
Example #3
0
        private void UpdateFileInMemory(string fileName)
        {
            if (!MemoryFileList.Exists(m => m.JsonFilePath == fileName))
            {
                return;
            }

            var tempFileName = "temp_" + Path.GetFileName(fileName);
            var success      = BAC.JsonToBac(fileName, tempFileName);

            if (!success)
            {
                success = BCM.JsonToBcm(fileName,
                                        tempFileName);
            }

            if (!success)
            {
                lbOutput.Items.Add("Couldn't parse JSON");
                return;
            }

            var memFile = MemoryFileList.First(m => m.JsonFilePath == fileName);

            var fileBytes = File.ReadAllBytes(tempFileName).ToList();

            fileBytes.RemoveRange(0, BitConverter.ToInt32(fileBytes.ToArray(), 0x18) + 36);

            if (memFile.NewAddress == 0)
            {
                Console.WriteLine("Allocating memory space...");
                var newAddress = Memory.AllocAndWriteFileToMemory(fileBytes.ToArray());
                Console.WriteLine("Got some space at: " + newAddress.ToString("X"));
                memFile.NewAddress = newAddress;
                Console.WriteLine("Wrote file to: " + newAddress.ToString("X"));

                foreach (var pointer in memFile.Pointers)
                {
                    Memory.Write(pointer, BitConverter.GetBytes(memFile.NewAddress));
                    Console.WriteLine("Updated pointer at: " + pointer.ToString("X"));
                }
            }

            Memory.Write(memFile.NewAddress, fileBytes.ToArray());
            Console.WriteLine("Wrote file to: " + memFile.NewAddress.ToString("X"));
            WriteToOutput("Wrote: " + Path.GetFileName(fileName) + " to " + memFile.UassetFileName + " - " +
                          memFile.NewAddress.ToString("X"));
        }
Example #4
0
        public async Task <IActionResult> Result(CalculateFormViewModel model)
        {
            var age           = model.Age;
            var weight        = model.Weight;
            var drinkingHours = model.HoursDrinking;
            var totalDrinks   = model.TotalDrinks;
            var beerAbv       = await this.beers.GetAbvBIdAsync(model.BeerId);

            var bacResult = BAC.Calculate(age, weight, drinkingHours, totalDrinks, beerAbv);

            var bacConclusion = BAC.Conclusion(bacResult / 10.0);

            bacConclusion.Bac      = bacResult;
            bacConclusion.ImageUrl = "https://fthmb.tqn.com/mm0XORjQpYtckiap7AQsuklUkJM=/768x0/filters:no_upscale()/homer_2008_v2F_hires2-56a00fd43df78cafda9fde98.jpg";

            return(View(nameof(Result), bacConclusion));
        }
Example #5
0
        public void TestBCMeff()
        {
            foreach (var file in Directory.GetFiles(@"Originals\BACeff"))
            {
                var originalBytes = File.ReadAllBytes(file);
                var bac           = BAC.FromUassetFile(file);
                BAC.ToUassetFile(bac, @"Originals\BACeff\testfile.uasset");
                var createdBytes = File.ReadAllBytes(@"Originals\BACeff\testfile.uasset");

                Assert.AreEqual(originalBytes.Length, createdBytes.Length);

                for (int i = 0; i < originalBytes.Length; i++)
                {
                    Assert.AreEqual(originalBytes[i], createdBytes[i]);
                }
            }

            File.Delete(@"Originals\BACeff\testfile.uasset");
        }
Example #6
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("\n");
                Console.WriteLine("BAC/BCM/BCH to JSON: MoveTool.exe InFile.uasset OutFile.json");
                Console.WriteLine("JSON to BAC/BCM/BCH: MoveTool.exe InFile.json OutFile.uasset");
                Console.WriteLine("\n");
                Console.WriteLine("You can also drag and drop files onto this tool and it will\nautomatically create the JSON or BAC/BCM/BCH file with the same\nname in the same directory as the original file.");
                Console.WriteLine("\n");
                Console.WriteLine(("Back up your files, this tool will overwrite any file with the\nsame name as the output file!").ToUpper());
            }

            if (args.Length == 1)
            {
                Console.WriteLine(Path.GetDirectoryName(args[0]) + @"\" + Path.GetFileNameWithoutExtension(args[0]));

                if (File.Exists(args[0]))
                {
                    if (args[0].ToLower().EndsWith("uasset"))
                    {
                        var type = FileTypeDecider.Decide(args[0]);

                        if (type == FileType.BAC)
                        {
                            Console.WriteLine("BAC file detected. Trying to do BAC to JSON.");
                            try
                            {
                                BAC.BacToJson(args[0],
                                              Path.GetDirectoryName(args[0]) + @"\" + Path.GetFileNameWithoutExtension(args[0]) +
                                              ".json");
                                Console.WriteLine("Done writing file: " + Path.GetDirectoryName(args[0]) + @"\" +
                                                  Path.GetFileNameWithoutExtension(args[0]) + ".json");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Something went wrong: " + ex.Message + " - " + ex.Data);
                                Console.Read();
                            }
                        }
                        else if (type == FileType.BCM)
                        {
                            try
                            {
                                Console.WriteLine("BCM file detected. Trying to do BCM to JSON.");
                                BCM.BcmToJson(args[0],
                                              Path.GetDirectoryName(args[0]) + @"\" + Path.GetFileNameWithoutExtension(args[0]) +
                                              ".json");
                                Console.WriteLine("Done writing file: " + Path.GetDirectoryName(args[0]) + @"\" + Path.GetFileNameWithoutExtension(args[0]) + ".json");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Something went wrong: " + ex.Message + " - " + ex.Data);
                                Console.Read();
                            }
                        }
                        else if (type == FileType.BCH)
                        {
                            try
                            {
                                Console.WriteLine("BCH file detected. Trying to do BCH to JSON.");
                                BCH.BchToJson(args[0],
                                              Path.GetDirectoryName(args[0]) + @"\" + Path.GetFileNameWithoutExtension(args[0]) +
                                              ".json");
                                Console.WriteLine("Done writing file: " + Path.GetDirectoryName(args[0]) + @"\" + Path.GetFileNameWithoutExtension(args[0]) + ".json");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Something went wrong: " + ex.Message + " - " + ex.Data);
                                Console.Read();
                            }
                        }
                        else if (type == FileType.Unknown)
                        {
                            Console.WriteLine("Unsupported format.");
                            Console.Read();
                        }
                    }

                    if (args[0].ToLower().EndsWith("json"))
                    {
                        Console.WriteLine("File is json.");

                        var success = BAC.JsonToBac(args[0],
                                                    Path.GetDirectoryName(args[0]) + @"\" + Path.GetFileNameWithoutExtension(args[0]) + ".uasset");

                        if (!success)
                        {
                            success = BCM.JsonToBcm(args[0],
                                                    Path.GetDirectoryName(args[0]) + @"\" + Path.GetFileNameWithoutExtension(args[0]) + ".uasset");
                        }

                        if (!success)
                        {
                            success = BCH.JsonToBch(args[0],
                                                    Path.GetDirectoryName(args[0]) + @"\" + Path.GetFileNameWithoutExtension(args[0]) + ".uasset");
                        }

                        if (!success)
                        {
                            Console.WriteLine("Something went wrong while parsing json.");
                            Console.Read();
                        }
                        else
                        {
                            Console.WriteLine("Done writing file: " + Path.GetDirectoryName(args[0]) + @"\" + Path.GetFileNameWithoutExtension(args[0]) + ".uasset");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("File does not exist: " + args[0]);
                    Console.Read();
                }
            }

            if (args.Length == 2)
            {
                string inFile  = args[0];
                string outFile = args[1];

                if (inFile.ToLower().EndsWith("uasset"))
                {
                    if (!outFile.ToLower().EndsWith("json"))
                    {
                        outFile += ".json";
                    }

                    var type = FileTypeDecider.Decide(inFile);

                    if (type == FileType.BAC)
                    {
                        Console.WriteLine("BAC file detected. Trying to do BAC to JSON.");
                        BAC.BacToJson(inFile, outFile);
                        Console.WriteLine("Done writing file: " + outFile);
                    }
                    else if (type == FileType.BCM)
                    {
                        Console.WriteLine("BCM file detected. Trying to do BCM to JSON.");
                        BCM.BcmToJson(inFile, outFile);
                        Console.WriteLine("Done writing file: " + outFile);
                    }
                    else if (type == FileType.BCH)
                    {
                        Console.WriteLine("BCH file detected. Trying to do BCH to JSON.");
                        BCH.BchToJson(inFile, outFile);
                        Console.WriteLine("Done writing file: " + outFile);
                    }
                    else if (type == FileType.Unknown)
                    {
                        Console.WriteLine("Unsupported format.");
                        Console.Read();
                    }
                }

                if (inFile.ToLower().EndsWith("json"))
                {
                    if (!outFile.ToLower().EndsWith("uasset"))
                    {
                        outFile += ".uasset";
                    }

                    Console.WriteLine("File is json.");

                    var success = BAC.JsonToBac(inFile, outFile);

                    if (!success)
                    {
                        success = BCM.JsonToBcm(inFile, outFile);
                    }

                    if (!success)
                    {
                        success = BCH.JsonToBch(inFile, outFile);
                    }

                    if (!success)
                    {
                        Console.WriteLine("Something went wrong while parsing json.");
                        Console.Read();
                    }
                    else
                    {
                        Console.WriteLine("Done writing file: " + outFile);
                    }
                }
            }

            if (args.Length > 2)
            {
                Console.WriteLine("MoveTool can not understand more than 2 arguments. If you have spaces\n" + @"in the paths, try adding "" around them.");
            }
        }
Example #7
0
        private static void Start(string[] args)
        {
            switch (args.Length)
            {
            case 0:
            {
                Console.WriteLine("\nBAC/BCM/BCH to JSON: MoveTool.exe InFile.uasset OutFile.json" +
                                  "\nJSON to BAC/BCM/BCH: MoveTool.exe InFile.json OutFile.uasset" +
                                  "\n\nYou can also drag and drop files onto this tool and it will" +
                                  "\nautomatically create the JSON or BAC/BCM/BCH file with the " +
                                  "\nsame name in the same directory as the original file." +
                                  ("\n\nBack up your files, this tool will overwrite any file with the" +
                                   "\nsame name as the output file!").ToUpper());

                break;
            }

            case 1:
            {
                var path      = args[0];
                var directory = Path.GetDirectoryName(path) + Separator;
                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);

                Console.WriteLine(directory + fileNameWithoutExtension);

                // Check if file exists
                if (!File.Exists(path))
                {
                    Console.WriteLine("File does not exist: " + path);
                    break;
                }

                #region Handle .UASSET files

                if (path.ToLower().EndsWith("uasset"))
                {
                    var type = FileTypeDecider.Decide(path);

                    switch (type)
                    {
                    case FileType.BAC:
                        Console.WriteLine("BAC file detected. Trying to do BAC to JSON.");
                        try
                        {
                            BAC.BacToJson(path, directory + fileNameWithoutExtension + ".json");

                            Console.WriteLine("Done writing file: " +
                                              directory + fileNameWithoutExtension + ".json");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Something went wrong: " + ex.Message + " - " + ex.Data);
                        }

                        break;

                    case FileType.BCM:
                        try
                        {
                            Console.WriteLine("BCM file detected. Trying to do BCM to JSON.");

                            BCM.BcmToJson(path,
                                          directory + fileNameWithoutExtension + ".json");

                            Console.WriteLine("Done writing file: " +
                                              directory + fileNameWithoutExtension + ".json");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Something went wrong: " + ex.Message + " - " + ex.Data);
                        }

                        break;

                    case FileType.BCH:
                        try
                        {
                            Console.WriteLine("BCH file detected. Trying to do BCH to JSON.");
                            BCH.BchToJson(path,
                                          directory + fileNameWithoutExtension + ".json");
                            Console.WriteLine("Done writing file: " +
                                              directory + fileNameWithoutExtension + ".json");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Something went wrong: " + ex.Message + " - " + ex.Data);
                        }

                        break;

                    case FileType.Unknown:
                    default:
                        Console.WriteLine("Unsupported format.");
                        break;
                    }
                }

                #endregion

                #region Handle .JSON files

                if (args[0].ToLower().EndsWith("json"))
                {
                    Console.WriteLine("File is json.");

                    var success = BAC.JsonToBac(
                        args[0],
                        Path.GetDirectoryName(args[0]) + Separator +
                        Path.GetFileNameWithoutExtension(args[0]) + ".uasset");

                    if (!success)
                    {
                        success = BCM.JsonToBcm(args[0],
                                                Path.GetDirectoryName(args[0]) + Separator +
                                                Path.GetFileNameWithoutExtension(args[0]) + ".uasset");
                    }

                    if (!success)
                    {
                        success = BCH.JsonToBch(args[0],
                                                Path.GetDirectoryName(args[0]) + Separator +
                                                Path.GetFileNameWithoutExtension(args[0]) + ".uasset");
                    }

                    if (!success)
                    {
                        Console.WriteLine("Something went wrong while parsing json.");
                    }
                    else
                    {
                        Console.WriteLine("Done writing file: " + Path.GetDirectoryName(args[0]) +
                                          Separator + Path.GetFileNameWithoutExtension(args[0]) +
                                          ".uasset");
                    }
                }

                #endregion

                break;
            }

            case 2:
            {
                var inFile  = args[0];
                var outFile = args[1];

                if (inFile.ToLower().EndsWith("uasset"))
                {
                    if (!outFile.ToLower().EndsWith("json"))
                    {
                        outFile += ".json";
                    }

                    var type = FileTypeDecider.Decide(inFile);

                    switch (type)
                    {
                    case FileType.BAC:
                        Console.WriteLine("BAC file detected. Trying to do BAC to JSON.");
                        BAC.BacToJson(inFile, outFile);
                        Console.WriteLine("Done writing file: " + outFile);
                        break;

                    case FileType.BCM:
                        Console.WriteLine("BCM file detected. Trying to do BCM to JSON.");
                        BCM.BcmToJson(inFile, outFile);
                        Console.WriteLine("Done writing file: " + outFile);
                        break;

                    case FileType.BCH:
                        Console.WriteLine("BCH file detected. Trying to do BCH to JSON.");
                        BCH.BchToJson(inFile, outFile);
                        Console.WriteLine("Done writing file: " + outFile);
                        break;

                    case FileType.Unknown:
                    default:
                        Console.WriteLine("Unsupported format.");
                        break;
                    }
                }
                else if (inFile.ToLower().EndsWith("json"))
                {
                    if (!outFile.ToLower().EndsWith("uasset"))
                    {
                        outFile += ".uasset";
                    }

                    Console.WriteLine("File is json.");

                    var success = BAC.JsonToBac(inFile, outFile);

                    if (!success)
                    {
                        success = BCM.JsonToBcm(inFile, outFile);
                    }

                    if (!success)
                    {
                        success = BCH.JsonToBch(inFile, outFile);
                    }

                    if (!success)
                    {
                        Console.WriteLine("Something went wrong while parsing json.");
                    }
                    else
                    {
                        Console.WriteLine("Done writing file: " + outFile);
                    }
                }

                break;
            }

            default:
            {
                Console.WriteLine("MoveTool can not understand more than 2 arguments. \n" +
                                  @"If the paths contain spaces, try wrapping the paths in double quotes ("").");
                break;
            }
            }

            Pause();
        }