Exemplo n.º 1
0
 static void Main(string[] args)
 {
     if (args.Length == 0)
     {
         Console.Write("Filename: ");
         args = new string[] { Console.ReadLine().Trim('"') };
     }
     foreach (string filename in args)
     {
         byte[] fc;
         if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
         {
             fc = Prs.Decompress(filename);
         }
         else
         {
             fc = File.ReadAllBytes(filename);
         }
         string         path = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filename)), Path.GetFileNameWithoutExtension(filename));
         JsonSerializer js   = new JsonSerializer();
         EventIniData   ini;
         using (TextReader tr = File.OpenText(Path.Combine(path, Path.ChangeExtension(Path.GetFileName(filename), ".json"))))
             using (JsonTextReader jtr = new JsonTextReader(tr))
                 ini = js.Deserialize <EventIniData>(jtr);
         uint key;
         if (fc[0] == 0x81)
         {
             ByteConverter.BigEndian = true;
             key = 0x8125FE60;
         }
         else
         {
             ByteConverter.BigEndian = false;
             key = 0xC600000;
         }
         bool        battle               = ini.Game == Game.SA2B;
         List <byte> modelbytes           = new List <byte>(fc);
         Dictionary <string, uint> labels = new Dictionary <string, uint>();
         foreach (string file in ini.Files.Where(a => a.Key.EndsWith(".sa2mdl", StringComparison.OrdinalIgnoreCase) && HelperFunctions.FileHash(Path.Combine(path, a.Key)) != a.Value).Select(a => a.Key))
         {
             modelbytes.AddRange(new ModelFile(Path.Combine(path, file)).Model.GetBytes((uint)(key + modelbytes.Count), false, labels, out uint _));
         }
         if (battle)
         {
             List <byte> motionbytes             = new List <byte>(new byte[(ini.Motions.Count + 1) * 8]);
             Dictionary <string, int> partcounts = new Dictionary <string, int>(ini.Motions.Count);
             foreach (string file in ini.Files.Where(a => a.Key.EndsWith(".saanim", StringComparison.OrdinalIgnoreCase)).Select(a => a.Key))
             {
                 NJS_MOTION motion = NJS_MOTION.Load(Path.Combine(path, file));
                 motionbytes.AddRange(motion.GetBytes((uint)(key + motionbytes.Count), labels, out uint _));
                 partcounts.Add(motion.Name, motion.ModelParts);
             }
             byte[] mfc = motionbytes.ToArray();
             for (int i = 0; i < ini.Motions.Count; i++)
             {
                 if (ini.Motions[i] == null)
                 {
                     new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }
                 }
Exemplo n.º 2
0
        private void LoadFile(string filename)
        {
            this.filename = filename;
            byte[] fc;
            if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
            {
                fc = Prs.Decompress(filename);
            }
            else
            {
                fc = File.ReadAllBytes(filename);
            }
            ByteConverter.BigEndian = false;
            uint le = ByteConverter.ToUInt32(fc, 0);

            ByteConverter.BigEndian = true;
            uint be = ByteConverter.ToUInt32(fc, 0);

            if (be > le)
            {
                bigEndian = false;
            }
            else if (be < le)
            {
                bigEndian = true;
            }
            ByteConverter.BigEndian = bigEndian;
            bigEndianGCSteamToolStripMenuItem.Checked = bigEndian;
            useSJIS = char.ToLowerInvariant(Path.GetFileNameWithoutExtension(filename).Last()) == 'j';
            shiftJISToolStripMenuItem.Checked    = useSJIS;
            windows1252ToolStripMenuItem.Checked = !useSJIS;
            Encoding encoding = useSJIS ? jpenc : euenc;

            messages.Clear();
            int  address   = 0;
            int  off       = ByteConverter.ToInt32(fc, 0);
            int  end       = off;
            bool hasEscape = false;

            while (off != -1 && address < end)
            {
                string str = fc.GetCString(off, encoding);
                messages.Add(Message.FromString(str));
                if (CheckForEscapeCharacter(str))
                {
                    hasEscape = true;
                }
                address += 4;
                off      = ByteConverter.ToInt32(fc, address);
                end      = Math.Min(off, end);
            }
            textOnlyToolStripMenuItem.Checked = !hasEscape;
            UpdateMessageSelect();
            messagePanel.Enabled = false;
            AddRecentFile(filename);
            Text = "SA2 Message File Editor - " + Path.GetFileName(filename);
            findNextToolStripMenuItem.Enabled = false;
        }
Exemplo n.º 3
0
        public Event(string filename)
        {
            byte[] fc;
            if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
            {
                fc = Prs.Decompress(filename);
            }
            else
            {
                fc = File.ReadAllBytes(filename);
            }
            bool battle = false;
            uint key;

            if (fc[0] == 0x81)
            {
                ByteConverter.BigEndian = true;
                key    = 0x8125FE60;
                battle = true;
            }
            else
            {
                ByteConverter.BigEndian = false;
                key = 0xC600000;
            }
            List <NJS_MOTION> motions = null;

            if (battle)
            {
                motions = ReadMotionFile(Path.ChangeExtension(filename, null) + "motion.bin");
            }
            Dictionary <string, NJS_OBJECT> models = new Dictionary <string, NJS_OBJECT>();
            int ptr = fc.GetPointer(0x20, key);

            if (ptr != 0)
            {
                int cnt = battle ? 18 : 16;
                Upgrades = new EventUpgrade[cnt];
                for (int i = 0; i < cnt; i++)
                {
                    Upgrades[i] = new EventUpgrade(fc, ptr, key, models);
                    ptr        += EventUpgrade.Size;
                }
            }
            int gcnt = ByteConverter.ToInt32(fc, 8);

            ptr = fc.GetPointer(0, key);
            if (ptr != 0)
            {
                Scenes = new List <EventScene>();
                for (int gn = 0; gn <= gcnt; gn++)
                {
                    Scenes.Add(new EventScene(fc, ptr, key, battle, models, motions));
                    ptr += EventScene.Size;
                }
            }
        }
Exemplo n.º 4
0
 private void Execute()
 {
     if (this.compressRadioButton.Checked)
     {
         Prs.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
     }
     else if (this.decompressRadioButton.Checked)
     {
         Prs.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
     }
 }
Exemplo n.º 5
0
        private void LoadFile(string filename)
        {
            this.filename = filename;
            byte[] fc;
            if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
            {
                fc = Prs.Decompress(filename);
            }
            else
            {
                fc = File.ReadAllBytes(filename);
            }
            ByteConverter.BigEndian = false;
            uint le = ByteConverter.ToUInt32(fc, 0);

            ByteConverter.BigEndian = true;
            uint be        = ByteConverter.ToUInt32(fc, 0);
            uint imageBase = 0;

            if (be > le)
            {
                bigEndian = false;
                imageBase = 0xCBD0000u;
            }
            else if (be < le)
            {
                bigEndian = true;
                imageBase = 0x817AFE60u;
            }

            ByteConverter.BigEndian = bigEndian;
            bigEndianGCSteamToolStripMenuItem.Checked = bigEndian;
            useSJIS = Path.GetFileNameWithoutExtension(filename).Last() == '0';
            shiftJISToolStripMenuItem.Checked    = useSJIS;
            windows1252ToolStripMenuItem.Checked = !useSJIS;
            Encoding encoding = useSJIS ? jpenc : euenc;

            scenes.Clear();
            int address = 0;
            int id      = ByteConverter.ToInt32(fc, 0);

            while (id != -1)
            {
                scenes.Add(new Scene(fc, address, imageBase, encoding));
                address += Scene.Size;
                id       = ByteConverter.ToInt32(fc, address);
            }
            UpdateSceneSelect();
            scenePanel.Enabled = false;
            AddRecentFile(filename);
            Text = "SA2 Cutscene Text Editor - " + Path.GetFileName(filename);
            findNextToolStripMenuItem.Enabled = false;
        }
Exemplo n.º 6
0
        private static Stream OpenMaybePRSFile(string filepath)
        {
            Stream stream = File.OpenRead(filepath);

            try
            {
                var decompressedStream = new MemoryStream();
                Prs.Decompress(stream, decompressedStream);
                stream.Dispose();
                stream = decompressedStream;
            }
            catch (Exception)
            {
                // Not compressed
            }

            stream.Position = 0;
            return(stream);
        }
Exemplo n.º 7
0
        private void btn_DecompressDragDrop_DragDrop(object sender, DragEventArgs e)
        {
            // Get files dropped onto button and process them.
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            ParallelOptions options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            };

            Parallel.ForEach(files, file =>
            {
                byte[] compressedFile   = File.ReadAllBytes(file);
                byte[] decompressedFile = Prs.Decompress(ref compressedFile);

                string fileName = Path.GetFileName(file);
                File.WriteAllBytes($"{TempDirectoryName}\\{fileName}", decompressedFile);
            });

            // Open directory
            Process.Start(TempDirectoryName);
        }
Exemplo n.º 8
0
 public void Compress(byte[] file)
 {
     byte[] compressed   = Prs.Compress(file, 0x1FFF);
     byte[] decompressed = Prs.Decompress(compressed);
     Assert.Equal(file, decompressed);
 }
Exemplo n.º 9
0
        public static void Build(string filename)
        {
            nodenames.Clear();
            modelfiles.Clear();
            motionfiles.Clear();

            byte[] fc;
            if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
            {
                fc = Prs.Decompress(filename);
            }
            else
            {
                fc = File.ReadAllBytes(filename);
            }
            string         path = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filename)), Path.GetFileNameWithoutExtension(filename));
            JsonSerializer js   = new JsonSerializer();
            EventIniData   ini;

            using (TextReader tr = File.OpenText(Path.Combine(path, Path.ChangeExtension(Path.GetFileName(filename), ".json"))))
                using (JsonTextReader jtr = new JsonTextReader(tr))
                    ini = js.Deserialize <EventIniData>(jtr);
            uint key;
            bool battle     = ini.Game == Game.SA2B;
            bool battlebeta = ini.Game == Game.SA2B;
            bool dcbeta     = ini.Game == Game.SA2;

            if (fc[0] == 0x81)
            {
                if (fc[0x2B] <= 1 && fc[0x2A] == 0)
                {
                    ByteConverter.BigEndian = true;
                    key    = 0x8125FE60;
                    battle = true;
                }
                else
                {
                    ByteConverter.BigEndian = true;
                    key        = 0x812FFE60;
                    battlebeta = true;
                }
            }
            else
            {
                if ((fc[37] == 0x25) || (fc[38] == 0x22) || ((fc[36] == 0) && ((fc[1] == 0xFE) || (fc[1] == 0xF2) || ((fc[1] == 0x27) && fc[2] == 0x9F))))
                {
                    ByteConverter.BigEndian = false;
                    key    = 0xC600000;
                    dcbeta = true;
                }
                else
                {
                    ByteConverter.BigEndian = false;
                    key = 0xC600000;
                }
            }
            List <byte> modelbytes           = new List <byte>(fc);
            Dictionary <string, uint> labels = new Dictionary <string, uint>();

            foreach (string file in ini.Files.Where(a => a.Key.EndsWith(".sa2mdl", StringComparison.OrdinalIgnoreCase) && HelperFunctions.FileHash(Path.Combine(path, a.Key)) != a.Value).Select(a => a.Key))
            {
                modelbytes.AddRange(new ModelFile(Path.Combine(path, file)).Model.GetBytes((uint)(key + modelbytes.Count), false, labels, new List <uint>(), out uint _));
            }
            if (battle)
            {
                foreach (string file in ini.Files.Where(a => a.Key.EndsWith(".sa2bmdl", StringComparison.OrdinalIgnoreCase) && HelperFunctions.FileHash(Path.Combine(path, a.Key)) != a.Value).Select(a => a.Key))
                {
                    modelbytes.AddRange(new ModelFile(Path.Combine(path, file)).Model.GetBytes((uint)(key + modelbytes.Count), false, labels, new List <uint>(), out uint _));
                }
                List <byte> motionbytes             = new List <byte>(new byte[(ini.Motions.Count + 1) * 8]);
                Dictionary <string, int> partcounts = new Dictionary <string, int>(ini.Motions.Count);
                foreach (string file in ini.Files.Where(a => a.Key.EndsWith(".saanim", StringComparison.OrdinalIgnoreCase)).Select(a => a.Key))
                {
                    NJS_MOTION motion = NJS_MOTION.Load(Path.Combine(path, file));
                    motionbytes.AddRange(motion.GetBytes((uint)motionbytes.Count, labels, out uint _));
                    partcounts.Add(motion.Name, motion.ModelParts);
                }
                byte[] mfc = motionbytes.ToArray();
                for (int i = 0; i < ini.Motions.Count; i++)
                {
                    if (ini.Motions[i] == null)
                    {
                        new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }
                    }
Exemplo n.º 10
0
        public static void Split(string filename)
        {
            nodenames.Clear();
            modelfiles.Clear();
            motionfiles.Clear();

            Console.WriteLine("Splitting file {0}...", filename);
            byte[] fc;
            if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
            {
                fc = Prs.Decompress(filename);
            }
            else
            {
                fc = File.ReadAllBytes(filename);
            }
            MiniEventIniData ini = new MiniEventIniData()
            {
                Name = Path.GetFileNameWithoutExtension(filename)
            };
            string            path = Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filename)), Path.GetFileNameWithoutExtension(filename))).FullName;
            uint              key;
            List <NJS_MOTION> motions = null;

            if (fc[4] == 0x81)
            {
                Console.WriteLine("File is in GC/PC format.");
                ByteConverter.BigEndian = true;
                key      = 0x816DFE60;
                ini.Game = Game.SA2B;
            }
            else
            {
                Console.WriteLine("File is in DC format.");
                ByteConverter.BigEndian = false;
                key      = 0xCB00000;
                ini.Game = Game.SA2;
            }
            int ptr = fc.GetPointer(8, key);

            if (ptr != 0)
            {
                Console.WriteLine("Sonic is in this Mini-Event");
                Directory.CreateDirectory(Path.Combine(path, "Sonic"));
                MiniEventChars data = new MiniEventChars();
                data.BodyAnims = GetMotion(fc, ptr, key, $"Sonic\\Body.saanim", motions, 62);
                int ptr2 = fc.GetPointer(ptr + 4, key);
                if (ptr2 != 0)
                {
                    data.HeadPart = GetModel(fc, ptr + 4, key, $"Sonic\\Head.sa2mdl");
                }
                if (data.HeadPart != null)
                {
                    data.HeadAnims = GetMotion(fc, ptr + 8, key, $"Sonic\\Head.saanim", motions, modelfiles[data.HeadPart].Model.CountAnimated());
                    if (data.HeadAnims != null)
                    {
                        modelfiles[data.HeadPart].Motions.Add($"Head.saanim");
                    }
                    data.HeadShapeMotions = GetMotion(fc, ptr + 0xC, key, $"Sonic\\HeadShape.saanim", motions, modelfiles[data.HeadPart].Model.CountMorph());
                    if (data.HeadShapeMotions != null)
                    {
                        modelfiles[data.HeadPart].Motions.Add($"HeadShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x10, key);
                if (ptr2 != 0)
                {
                    data.MouthPart = GetModel(fc, ptr + 0x10, key, $"Sonic\\Mouth.sa2mdl");
                }
                if (data.MouthPart != null)
                {
                    data.MouthAnims = GetMotion(fc, ptr + 0x14, key, $"Sonic\\Mouth.saanim", motions, modelfiles[data.MouthPart].Model.CountAnimated());
                    if (data.MouthAnims != null)
                    {
                        modelfiles[data.MouthPart].Motions.Add($"Mouth.saanim");
                    }
                    data.MouthShapeMotions = GetMotion(fc, ptr + 0x18, key, $"Sonic\\MouthShape.saanim", motions, modelfiles[data.MouthPart].Model.CountMorph());
                    if (data.MouthShapeMotions != null)
                    {
                        modelfiles[data.MouthPart].Motions.Add($"MouthShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x1C, key);
                if (ptr2 != 0)
                {
                    data.LHandPart = GetModel(fc, ptr + 0x1C, key, $"Sonic\\LeftHand.sa2mdl");
                }
                if (data.LHandPart != null)
                {
                    data.LHandAnims = GetMotion(fc, ptr + 0x20, key, $"Sonic\\LeftHand.saanim", motions, modelfiles[data.LHandPart].Model.CountAnimated());
                    if (data.LHandAnims != null)
                    {
                        modelfiles[data.LHandPart].Motions.Add($"LeftHand.saanim");
                    }
                    data.LHandShapeMotions = GetMotion(fc, ptr + 0x24, key, $"Sonic\\LeftHandShape.saanim", motions, modelfiles[data.LHandPart].Model.CountMorph());
                    if (data.LHandShapeMotions != null)
                    {
                        modelfiles[data.LHandPart].Motions.Add($"LeftHandShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x28, key);
                if (ptr2 != 0)
                {
                    data.RHandPart = GetModel(fc, ptr + 0x28, key, $"Sonic\\RightHand.sa2mdl");
                }
                if (data.RHandPart != null)
                {
                    data.RHandAnims = GetMotion(fc, ptr + 0x2C, key, $"Sonic\\RightHand.saanim", motions, modelfiles[data.RHandPart].Model.CountAnimated());
                    if (data.RHandAnims != null)
                    {
                        modelfiles[data.RHandPart].Motions.Add($"RightHand.saanim");
                    }
                    data.RHandShapeMotions = GetMotion(fc, ptr + 0x30, key, $"Sonic\\RightHandShape.saanim", motions, modelfiles[data.RHandPart].Model.CountMorph());
                    if (data.RHandShapeMotions != null)
                    {
                        modelfiles[data.RHandPart].Motions.Add($"RightHandShape.saanim");
                    }
                }
                ini.Sonic.Add(data);
            }
            ptr = fc.GetPointer(0xC, key);
            if (ptr != 0)
            {
                Console.WriteLine("Shadow is in this Mini-Event");
                Directory.CreateDirectory(Path.Combine(path, "Shadow"));
                MiniEventChars data = new MiniEventChars();
                data.BodyAnims = GetMotion(fc, ptr, key, $"Shadow\\Body.saanim", motions, 62);
                int ptr2 = fc.GetPointer(ptr + 4, key);
                if (ptr2 != 0)
                {
                    data.HeadPart = GetModel(fc, ptr + 4, key, $"Shadow\\Head.sa2mdl");
                }
                if (data.HeadPart != null)
                {
                    data.HeadAnims = GetMotion(fc, ptr + 8, key, $"Shadow\\Head.saanim", motions, modelfiles[data.HeadPart].Model.CountAnimated());
                    if (data.HeadAnims != null)
                    {
                        modelfiles[data.HeadPart].Motions.Add($"Head.saanim");
                    }
                    data.HeadShapeMotions = GetMotion(fc, ptr + 0xC, key, $"Shadow\\HeadShape.saanim", motions, modelfiles[data.HeadPart].Model.CountMorph());
                    if (data.HeadShapeMotions != null)
                    {
                        modelfiles[data.HeadPart].Motions.Add($"HeadShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x10, key);
                if (ptr2 != 0)
                {
                    data.MouthPart = GetModel(fc, ptr + 0x10, key, $"Shadow\\Mouth.sa2mdl");
                }
                if (data.MouthPart != null)
                {
                    data.MouthAnims = GetMotion(fc, ptr + 0x14, key, $"Shadow\\Mouth.saanim", motions, modelfiles[data.MouthPart].Model.CountAnimated());
                    if (data.MouthAnims != null)
                    {
                        modelfiles[data.MouthPart].Motions.Add($"Mouth.saanim");
                    }
                    data.MouthShapeMotions = GetMotion(fc, ptr + 0x18, key, $"Shadow\\MouthShape.saanim", motions, modelfiles[data.MouthPart].Model.CountMorph());
                    if (data.MouthShapeMotions != null)
                    {
                        modelfiles[data.MouthPart].Motions.Add($"MouthShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x1C, key);
                if (ptr2 != 0)
                {
                    data.LHandPart = GetModel(fc, ptr + 0x1C, key, $"Shadow\\LeftHand.sa2mdl");
                }
                if (data.LHandPart != null)
                {
                    data.LHandAnims = GetMotion(fc, ptr + 0x20, key, $"Shadow\\LeftHand.saanim", motions, modelfiles[data.LHandPart].Model.CountAnimated());
                    if (data.LHandAnims != null)
                    {
                        modelfiles[data.LHandPart].Motions.Add($"LeftHand.saanim");
                    }
                    data.LHandShapeMotions = GetMotion(fc, ptr + 0x24, key, $"Shadow\\LeftHandShape.saanim", motions, modelfiles[data.LHandPart].Model.CountMorph());
                    if (data.LHandShapeMotions != null)
                    {
                        modelfiles[data.LHandPart].Motions.Add($"LeftHandShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x28, key);
                if (ptr2 != 0)
                {
                    data.RHandPart = GetModel(fc, ptr + 0x28, key, $"Shadow\\RightHand.sa2mdl");
                }
                if (data.RHandPart != null)
                {
                    data.RHandAnims = GetMotion(fc, ptr + 0x2C, key, $"Shadow\\RightHand.saanim", motions, modelfiles[data.RHandPart].Model.CountAnimated());
                    if (data.RHandAnims != null)
                    {
                        modelfiles[data.RHandPart].Motions.Add($"RightHand.saanim");
                    }
                    data.RHandShapeMotions = GetMotion(fc, ptr + 0x30, key, $"Shadow\\RightHandShape.saanim", motions, modelfiles[data.RHandPart].Model.CountMorph());
                    if (data.RHandShapeMotions != null)
                    {
                        modelfiles[data.RHandPart].Motions.Add($"RightHandShape.saanim");
                    }
                }
                ini.Shadow.Add(data);
            }
            ptr = fc.GetPointer(0x18, key);
            if (ptr != 0)
            {
                Console.WriteLine("Knuckles is in this Mini-Event");
                Directory.CreateDirectory(Path.Combine(path, "Knuckles"));
                MiniEventChars data = new MiniEventChars();
                data.BodyAnims = GetMotion(fc, ptr, key, $"Knuckles\\Body.saanim", motions, 62);
                int ptr2 = fc.GetPointer(ptr + 4, key);
                if (ptr2 != 0)
                {
                    data.HeadPart = GetModel(fc, ptr + 4, key, $"Knuckles\\Head.sa2mdl");
                }
                if (data.HeadPart != null)
                {
                    data.HeadAnims = GetMotion(fc, ptr + 8, key, $"Knuckles\\Head.saanim", motions, modelfiles[data.HeadPart].Model.CountAnimated());
                    if (data.HeadAnims != null)
                    {
                        modelfiles[data.HeadPart].Motions.Add($"Head.saanim");
                    }
                    data.HeadShapeMotions = GetMotion(fc, ptr + 0xC, key, $"Knuckles\\HeadShape.saanim", motions, modelfiles[data.HeadPart].Model.CountMorph());
                    if (data.HeadShapeMotions != null)
                    {
                        modelfiles[data.HeadPart].Motions.Add($"HeadShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x10, key);
                if (ptr2 != 0)
                {
                    data.MouthPart = GetModel(fc, ptr + 0x10, key, $"Knuckles\\Mouth.sa2mdl");
                }
                if (data.MouthPart != null)
                {
                    data.MouthAnims = GetMotion(fc, ptr + 0x14, key, $"Knuckles\\Mouth.saanim", motions, modelfiles[data.MouthPart].Model.CountAnimated());
                    if (data.MouthAnims != null)
                    {
                        modelfiles[data.MouthPart].Motions.Add($"Mouth.saanim");
                    }
                    data.MouthShapeMotions = GetMotion(fc, ptr + 0x18, key, $"Knuckles\\MouthShape.saanim", motions, modelfiles[data.MouthPart].Model.CountMorph());
                    if (data.MouthShapeMotions != null)
                    {
                        modelfiles[data.MouthPart].Motions.Add($"MouthShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x1C, key);
                if (ptr2 != 0)
                {
                    data.LHandPart = GetModel(fc, ptr + 0x1C, key, $"Knuckles\\LeftHand.sa2mdl");
                }
                if (data.LHandPart != null)
                {
                    data.LHandAnims = GetMotion(fc, ptr + 0x20, key, $"Knuckles\\LeftHand.saanim", motions, modelfiles[data.LHandPart].Model.CountAnimated());
                    if (data.LHandAnims != null)
                    {
                        modelfiles[data.LHandPart].Motions.Add($"LeftHand.saanim");
                    }
                    data.LHandShapeMotions = GetMotion(fc, ptr + 0x24, key, $"Knuckles\\LeftHandShape.saanim", motions, modelfiles[data.LHandPart].Model.CountMorph());
                    if (data.LHandShapeMotions != null)
                    {
                        modelfiles[data.LHandPart].Motions.Add($"LeftHandShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x28, key);
                if (ptr2 != 0)
                {
                    data.RHandPart = GetModel(fc, ptr + 0x28, key, $"Knuckles\\RightHand.sa2mdl");
                }
                if (data.RHandPart != null)
                {
                    data.RHandAnims = GetMotion(fc, ptr + 0x2C, key, $"Knuckles\\RightHand.saanim", motions, modelfiles[data.RHandPart].Model.CountAnimated());
                    if (data.RHandAnims != null)
                    {
                        modelfiles[data.RHandPart].Motions.Add($"RightHand.saanim");
                    }
                    data.RHandShapeMotions = GetMotion(fc, ptr + 0x30, key, $"Knuckles\\RightHandShape.saanim", motions, modelfiles[data.RHandPart].Model.CountMorph());
                    if (data.RHandShapeMotions != null)
                    {
                        modelfiles[data.RHandPart].Motions.Add($"RightHandShape.saanim");
                    }
                }
                ini.Knuckles.Add(data);
            }
            ptr = fc.GetPointer(0x1C, key);
            if (ptr != 0)
            {
                Console.WriteLine("Rouge is in this Mini-Event");
                Directory.CreateDirectory(Path.Combine(path, "Rouge"));
                MiniEventChars data = new MiniEventChars();
                data.BodyAnims = GetMotion(fc, ptr, key, $"Rouge\\Body.saanim", motions, 62);
                int ptr2 = fc.GetPointer(ptr + 4, key);
                if (ptr2 != 0)
                {
                    data.HeadPart = GetModel(fc, ptr + 4, key, $"Rouge\\Head.sa2mdl");
                }
                if (data.HeadPart != null)
                {
                    data.HeadAnims = GetMotion(fc, ptr + 8, key, $"Rouge\\Head.saanim", motions, modelfiles[data.HeadPart].Model.CountAnimated());
                    if (data.HeadAnims != null)
                    {
                        modelfiles[data.HeadPart].Motions.Add($"Head.saanim");
                    }
                    data.HeadShapeMotions = GetMotion(fc, ptr + 0xC, key, $"Rouge\\HeadShape.saanim", motions, modelfiles[data.HeadPart].Model.CountMorph());
                    if (data.HeadShapeMotions != null)
                    {
                        modelfiles[data.HeadPart].Motions.Add($"HeadShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x10, key);
                if (ptr2 != 0)
                {
                    data.MouthPart = GetModel(fc, ptr + 0x10, key, $"Rouge\\Mouth.sa2mdl");
                }
                if (data.MouthPart != null)
                {
                    data.MouthAnims = GetMotion(fc, ptr + 0x14, key, $"Rouge\\Mouth.saanim", motions, modelfiles[data.MouthPart].Model.CountAnimated());
                    if (data.MouthAnims != null)
                    {
                        modelfiles[data.MouthPart].Motions.Add($"Mouth.saanim");
                    }
                    data.MouthShapeMotions = GetMotion(fc, ptr + 0x18, key, $"Rouge\\MouthShape.saanim", motions, modelfiles[data.MouthPart].Model.CountMorph());
                    if (data.MouthShapeMotions != null)
                    {
                        modelfiles[data.MouthPart].Motions.Add($"MouthShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x1C, key);
                if (ptr2 != 0)
                {
                    data.LHandPart = GetModel(fc, ptr + 0x1C, key, $"Rouge\\LeftHand.sa2mdl");
                }
                if (data.LHandPart != null)
                {
                    data.LHandAnims = GetMotion(fc, ptr + 0x20, key, $"Rouge\\LeftHand.saanim", motions, modelfiles[data.LHandPart].Model.CountAnimated());
                    if (data.LHandAnims != null)
                    {
                        modelfiles[data.LHandPart].Motions.Add($"LeftHand.saanim");
                    }
                    data.LHandShapeMotions = GetMotion(fc, ptr + 0x24, key, $"Rouge\\LeftHandShape.saanim", motions, modelfiles[data.LHandPart].Model.CountMorph());
                    if (data.LHandShapeMotions != null)
                    {
                        modelfiles[data.LHandPart].Motions.Add($"LeftHandShape.saanim");
                    }
                }
                ptr2 = fc.GetPointer(ptr + 0x28, key);
                if (ptr2 != 0)
                {
                    data.RHandPart = GetModel(fc, ptr + 0x28, key, $"Rouge\\RightHand.sa2mdl");
                }
                if (data.RHandPart != null)
                {
                    data.RHandAnims = GetMotion(fc, ptr + 0x2C, key, $"Rouge\\RightHand.saanim", motions, modelfiles[data.RHandPart].Model.CountAnimated());
                    if (data.RHandAnims != null)
                    {
                        modelfiles[data.RHandPart].Motions.Add($"RightHand.saanim");
                    }
                    data.RHandShapeMotions = GetMotion(fc, ptr + 0x30, key, $"Rouge\\RightHandShape.saanim", motions, modelfiles[data.RHandPart].Model.CountMorph());
                    if (data.RHandShapeMotions != null)
                    {
                        modelfiles[data.RHandPart].Motions.Add($"RightHandShape.saanim");
                    }
                }
                ini.Rouge.Add(data);
            }
            ptr = fc.GetPointer(0x24, key);
            if (ptr != 0)
            {
                Console.WriteLine("Mech Eggman is in this Mini-Event");
                Directory.CreateDirectory(Path.Combine(path, "Mech Eggman"));
                ini.MechEggmanBodyAnims = GetMotion(fc, ptr, key, $"Mech Eggman\\Body.saanim", motions, 33);
            }
            ptr = fc.GetPointer(4, key);
            if (ptr != 0)
            {
                ini.Camera    = GetMotion(fc, ptr + 0x10, key, $"Camera.saanim", motions, 1);
                ini.CamFrames = ByteConverter.ToInt32(fc, ptr + 4);
            }
            else
            {
                Console.WriteLine("Mini-Event does not contain a camera.");
            }
            foreach (var item in motionfiles.Values)
            {
                string fn = item.Filename;
                string fp = Path.Combine(path, fn);
                item.Motion.Save(fp);
                ini.Files.Add(fn, HelperFunctions.FileHash(fp));
            }
            foreach (var item in modelfiles.Values)
            {
                string fp = Path.Combine(path, item.Filename);
                ModelFile.CreateFile(fp, item.Model, item.Motions.ToArray(), null, null, null, item.Format);
                ini.Files.Add(item.Filename, HelperFunctions.FileHash(fp));
            }
            JsonSerializer js = new JsonSerializer
            {
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore
            };

            using (var tw = File.CreateText(Path.Combine(path, Path.ChangeExtension(Path.GetFileName(filename), ".json"))))
                js.Serialize(tw, ini);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Decompresses the data to a fixed array of bytes.
 /// </summary>
 public byte[] DecompressData()
 {
     return(Prs.Decompress(GetCompressedDataPtr(), FileSize));
 }
Exemplo n.º 12
0
        public static void Split(string filename)
        {
            nodenames.Clear();
            modelfiles.Clear();
            motionfiles.Clear();

            Console.WriteLine("Splitting file {0}...", filename);
            byte[] fc;
            if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
            {
                fc = Prs.Decompress(filename);
            }
            else
            {
                fc = File.ReadAllBytes(filename);
            }
            EventIniData ini = new EventIniData()
            {
                Name = Path.GetFileNameWithoutExtension(filename)
            };
            string            path = Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filename)), Path.GetFileNameWithoutExtension(filename))).FullName;
            uint              key;
            List <NJS_MOTION> motions = null;
            bool              battle;
            bool              dcbeta;

            if (fc[0] == 0x81)
            {
                if (fc[0x2B] <= 0x01 && fc[0x2A] == 0)
                {
                    Console.WriteLine("File is in GC/PC format.");
                    ByteConverter.BigEndian = true;
                    key         = 0x8125FE60;
                    ini.Game    = Game.SA2B;
                    battle      = true;
                    dcbeta      = false;
                    motions     = ReadMotionFile(Path.ChangeExtension(filename, null) + "motion.bin");
                    ini.Motions = motions.Select(a => a?.Name).ToList();
                    foreach (var mtn in motions.Where(a => a != null))
                    {
                        motionfiles[mtn.Name] = new MotionInfo(null, mtn);
                    }
                }
                else
                {
                    Console.WriteLine("File is in GC/PC Beta format.");
                    ByteConverter.BigEndian = true;
                    key      = 0x812FFE60;
                    ini.Game = Game.SA2B;
                    battle   = false;
                    dcbeta   = false;
                }
            }
            else
            {
                if ((fc[37] == 0x25) || (fc[38] == 0x22) || ((fc[36] == 0) && ((fc[1] == 0xFE) || (fc[1] == 0xF2) || ((fc[1] == 0x27) && fc[2] == 0x9F))))
                {
                    Console.WriteLine("File is in DC Beta format.");
                    ByteConverter.BigEndian = false;
                    key      = 0xC600000;
                    ini.Game = Game.SA2;
                    battle   = false;
                    dcbeta   = true;
                }
                else
                {
                    Console.WriteLine("File is in DC format.");
                    ByteConverter.BigEndian = false;
                    key      = 0xC600000;
                    ini.Game = Game.SA2;
                    battle   = false;
                    dcbeta   = false;
                }
            }
            int ptr = fc.GetPointer(0x20, key);

            if (ptr != 0)
            {
                if (!dcbeta)
                {
                    for (int i = 0; i < (battle ? 18 : 16); i++)
                    {
                        string upnam = upgradenames[i];
                        string chnam = upnam;
                        switch (i)
                        {
                        case 0:
                            chnam = "Sonic";
                            break;

                        case 4:
                            chnam = "Shadow";
                            break;

                        case 6:
                            chnam = "Knuckles";
                            break;

                        case 12:
                            chnam = "Rouge";
                            break;

                        case 16:
                            chnam = "Mech Tails";
                            break;

                        case 17:
                            chnam = "Mech Eggman";
                            break;
                        }
                        UpgradeInfo info = new UpgradeInfo();
                        info.RootNode = GetModel(fc, ptr, key, $"{chnam} Root.sa2mdl");
                        if (info.RootNode != null)
                        {
                            int ptr2 = fc.GetPointer(ptr + 4, key);
                            if (ptr2 != 0)
                            {
                                info.AttachNode1 = $"object_{ptr2:X8}";
                            }
                            int ptr3 = fc.GetPointer(ptr + 8, key);
                            if (ptr3 != 0)
                            {
                                info.Model1 = GetModel(fc, ptr + 8, key, $"{upnam} Model 1.sa2mdl");
                            }
                            ptr2 = fc.GetPointer(ptr + 0xC, key);
                            if (ptr2 != 0)
                            {
                                info.AttachNode2 = $"object_{ptr2:X8}";
                            }
                            ptr3 = fc.GetPointer(ptr + 0x10, key);
                            if (ptr3 != 0)
                            {
                                info.Model2 = GetModel(fc, ptr + 0x10, key, $"{upnam} Model 2.sa2mdl");
                            }
                        }
                        ini.Upgrades.Add(info);
                        ptr += 0x14;
                    }
                }
                else
                {
                    for (int i = 0; i < 14; i++)
                    {
                        string upnam = upgradebetanames[i];
                        string chnam = upnam;
                        switch (i)
                        {
                        case 0:
                            chnam = "Sonic";
                            break;

                        case 4:
                            chnam = "Shadow";
                            break;

                        case 6:
                            chnam = "Knuckles";
                            break;

                        case 10:
                            chnam = "Rouge";
                            break;
                        }
                        UpgradeInfo info = new UpgradeInfo();
                        info.RootNode = GetModel(fc, ptr, key, $"{chnam} Root.sa2mdl");
                        if (info.RootNode != null)
                        {
                            int ptr2 = fc.GetPointer(ptr + 4, key);
                            if (ptr2 != 0)
                            {
                                info.AttachNode1 = $"object_{ptr2:X8}";
                            }
                            int ptr3 = fc.GetPointer(ptr + 8, key);
                            if (ptr3 != 0)
                            {
                                info.Model1 = GetModel(fc, ptr + 8, key, $"{upnam} Model 1.sa2mdl");
                            }
                            ptr2 = fc.GetPointer(ptr + 0xC, key);
                            if (ptr2 != 0)
                            {
                                info.AttachNode2 = $"object_{ptr2:X8}";
                            }
                            ptr3 = fc.GetPointer(ptr + 0x10, key);
                            if (ptr3 != 0)
                            {
                                info.Model2 = GetModel(fc, ptr + 0x10, key, $"{upnam} Model 2.sa2mdl");
                            }
                        }
                        ini.Upgrades.Add(info);
                        ptr += 0x14;
                    }
                }
            }
            else
            {
                Console.WriteLine("Event contains no character upgrades.");
            }
            ptr = fc.GetPointer(0x18, key);
            if (ptr != 0)
            {
                for (int i = 0; i < 93; i++)
                {
                    string name = $"object_{ptr:X8}";
                    if (name != null)
                    {
                        ini.MechParts.Add(i, name);
                    }
                    ptr += 4;
                }
            }
            else
            {
                Console.WriteLine("Event contains no mech parts.");
            }
            int gcnt = ByteConverter.ToInt32(fc, 8);

            ptr = fc.GetPointer(0, key);
            if (ptr != 0)
            {
                Console.WriteLine("Event contains {0} scene(s).", gcnt + 1);
                for (int gn = 0; gn <= gcnt; gn++)
                {
                    Directory.CreateDirectory(Path.Combine(path, $"Scene {gn + 1}"));
                    SceneInfo scn  = new SceneInfo();
                    int       ptr2 = fc.GetPointer(ptr, key);
                    int       ecnt = ByteConverter.ToInt32(fc, ptr + 4);
                    if (ptr2 != 0)
                    {
                        Console.WriteLine("Scene {0} contains {1} entit{2}.", gn + 1, ecnt, ecnt == 1 ? "y" : "ies");
                        for (int en = 0; en < ecnt; en++)
                        {
                            EntityInfo ent = new EntityInfo();
                            ent.Model = GetModel(fc, ptr2, key, $"Scene {gn + 1}\\Entity {en + 1} Model.sa2mdl");
                            if (ent.Model != null)
                            {
                                ent.Motion = GetMotion(fc, ptr2 + 4, key, $"Scene {gn + 1}\\Entity {en + 1} Motion.saanim", motions, modelfiles[ent.Model].Model.CountAnimated());
                                if (ent.Motion != null)
                                {
                                    modelfiles[ent.Model].Motions.Add(motionfiles[ent.Motion].Filename);
                                }
                                ent.ShapeMotion = GetMotion(fc, ptr2 + 8, key, $"Scene {gn + 1}\\Entity {en + 1} Shape Motion.saanim", motions, modelfiles[ent.Model].Model.CountMorph());
                                if (ent.ShapeMotion != null)
                                {
                                    modelfiles[ent.Model].Motions.Add(motionfiles[ent.ShapeMotion].Filename);
                                }
                            }
                            if (battle)
                            {
                                ent.GCModel     = GetGCModel(fc, ptr2 + 12, key, $"Scene {gn + 1}\\Entity {en + 1} GC Model.sa2bmdl");
                                ent.ShadowModel = GetModel(fc, ptr2 + 16, key, $"Scene {gn + 1}\\Entity {en + 1} Shadow Model.sa2mdl");
                                ent.Position    = new Vertex(fc, ptr2 + 24);
                                ent.Flags       = ByteConverter.ToUInt32(fc, ptr2 + 36);
                                ent.Layer       = ByteConverter.ToUInt32(fc, ptr2 + 40);
                            }
                            else
                            {
                                ent.Position = new Vertex(fc, ptr2 + 16);
                                ent.Flags    = ByteConverter.ToUInt32(fc, ptr2 + 28);
                            }
                            scn.Entities.Add(ent);
                            ptr2 += battle ? 0x2C : 0x20;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Scene {0} contains no entities.", gn + 1);
                    }
                    ptr2 = fc.GetPointer(ptr + 8, key);
                    if (ptr2 != 0)
                    {
                        int cnt = ByteConverter.ToInt32(fc, ptr + 12);
                        for (int i = 0; i < cnt; i++)
                        {
                            scn.CameraMotions.Add(GetMotion(fc, ptr2, key, $"Scene {gn + 1}\\Camera Motion {i + 1}.saanim", motions, 1));
                            ptr2 += sizeof(int);
                        }
                    }
                    ptr2 = fc.GetPointer(ptr + 0x18, key);
                    if (ptr2 != 0)
                    {
                        BigInfo big = new BigInfo();
                        big.Model = GetModel(fc, ptr2, key, $"Scene {gn + 1}\\Big Model.sa2mdl");
                        if (big.Model != null)
                        {
                            int anicnt = modelfiles[big.Model].Model.CountAnimated();
                            int ptr3   = fc.GetPointer(ptr2 + 4, key);
                            if (ptr3 != 0)
                            {
                                int cnt = ByteConverter.ToInt32(fc, ptr2 + 8);
                                for (int i = 0; i < cnt; i++)
                                {
                                    big.Motions.Add(new string[] { GetMotion(fc, ptr3, key, $"Scene {gn + 1}\\Big Motion {i + 1}a.saanim", motions, anicnt), GetMotion(fc, ptr3 + 4, key, $"Scene {gn + 1}\\Big Motion {i + 1}b.saanim", motions, anicnt) });
                                    ptr3 += 8;
                                }
                            }
                        }
                        big.Unknown = ByteConverter.ToInt32(fc, ptr2 + 12);
                        scn.Big     = big;
                    }
                    scn.FrameCount = ByteConverter.ToInt32(fc, ptr + 28);
                    ini.Scenes.Add(scn);
                    ptr += 0x20;
                }
            }
            else
            {
                Console.WriteLine("Event contains no scenes.");
            }
            ptr = fc.GetPointer(0x1C, key);
            if (ptr != 0)
            {
                ini.TailsTails = GetModel(fc, ptr, key, $"Tails' tails.sa2mdl");
            }
            else
            {
                Console.WriteLine("Event does not contain Tails' tails.");
            }
            ptr = fc.GetPointer(4, key);
            if (ptr == 0)
            {
                Console.WriteLine("Event does not contain an internal texture list.");
            }
            ptr = fc.GetPointer(0xC, key);
            if (ptr == 0)
            {
                Console.WriteLine("Event does not contain texture sizes.");
            }
            ptr = fc.GetPointer(0x24, key);
            if (ptr == 0)
            {
                Console.WriteLine("Event does not contain texture animation data.");
            }
            if (battle && fc[0x2B] == 0)
            {
                Console.WriteLine("Event does not use GC shadow maps.");
            }
            if (battle && fc[0x2B] == 1)
            {
                Console.WriteLine("Event uses GC shadow maps.");
            }
            foreach (var item in motionfiles.Values)
            {
                string fn = item.Filename ?? $"Unknown Motion {motions.IndexOf(item.Motion)}.saanim";
                string fp = Path.Combine(path, fn);
                item.Motion.Save(fp);
                ini.Files.Add(fn, HelperFunctions.FileHash(fp));
            }
            foreach (var item in modelfiles.Values)
            {
                string fp = Path.Combine(path, item.Filename);
                ModelFile.CreateFile(fp, item.Model, item.Motions.ToArray(), null, null, null, item.Format);
                ini.Files.Add(item.Filename, HelperFunctions.FileHash(fp));
            }
            JsonSerializer js = new JsonSerializer
            {
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore
            };

            using (var tw = File.CreateText(Path.Combine(path, Path.ChangeExtension(Path.GetFileName(filename), ".json"))))
                js.Serialize(tw, ini);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Decompresses the file (if necessary), retrieving the data corresponding to this file.
 /// </summary>
 public byte[] GetUncompressedData()
 {
     return(IsDataCompressed ? Prs.Decompress(Data) : Data);
 }
Exemplo n.º 14
0
        public static void Build(string filename)
        {
            nodenames.Clear();
            modelfiles.Clear();
            motionfiles.Clear();

            byte[] fc;
            if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
            {
                fc = Prs.Decompress(filename);
            }
            else
            {
                fc = File.ReadAllBytes(filename);
            }
            string           path = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filename)), Path.GetFileNameWithoutExtension(filename));
            JsonSerializer   js   = new JsonSerializer();
            MiniEventIniData ini;

            using (TextReader tr = File.OpenText(Path.Combine(path, Path.ChangeExtension(Path.GetFileName(filename), ".json"))))
                using (JsonTextReader jtr = new JsonTextReader(tr))
                    ini = js.Deserialize <MiniEventIniData>(jtr);
            uint key;

            if (fc[4] == 0x81)
            {
                ByteConverter.BigEndian = true;
                key = 0x816DFE60;
            }
            else
            {
                ByteConverter.BigEndian = false;
                key = 0xCB00000;
            }
            List <byte> modelbytes           = new List <byte>(fc);
            Dictionary <string, uint> labels = new Dictionary <string, uint>();

            foreach (string file in ini.Files.Where(a => a.Key.EndsWith(".sa2mdl", StringComparison.OrdinalIgnoreCase) && HelperFunctions.FileHash(Path.Combine(path, a.Key)) != a.Value).Select(a => a.Key))
            {
                modelbytes.AddRange(new ModelFile(Path.Combine(path, file)).Model.GetBytes((uint)(key + modelbytes.Count), false, labels, new List <uint>(), out uint _));
            }
            foreach (string file in ini.Files.Where(a => a.Key.EndsWith(".saanim", StringComparison.OrdinalIgnoreCase) && HelperFunctions.FileHash(Path.Combine(path, a.Key)) != a.Value).Select(a => a.Key))
            {
                modelbytes.AddRange(NJS_MOTION.Load(Path.Combine(path, file)).GetBytes((uint)(key + modelbytes.Count), labels, out uint _));
            }
            fc = modelbytes.ToArray();
            int ptr = fc.GetPointer(8, key);

            if (ptr != 0)
            {
                MiniEventChars info = ini.Sonic[0];
                if (labels.ContainsKeySafer(info.BodyAnims))
                {
                    ByteConverter.GetBytes(labels[info.BodyAnims]).CopyTo(fc, ptr);
                }
                if (info.HeadPart != null)
                {
                    if (labels.ContainsKeySafer(info.HeadPart))
                    {
                        ByteConverter.GetBytes(labels[info.HeadPart]).CopyTo(fc, ptr + 4);
                    }
                    if (labels.ContainsKeySafer(info.HeadAnims))
                    {
                        ByteConverter.GetBytes(labels[info.HeadAnims]).CopyTo(fc, ptr + 8);
                    }
                    if (labels.ContainsKeySafer(info.HeadShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.HeadShapeMotions]).CopyTo(fc, ptr + 0xC);
                    }
                    if (labels.ContainsKeySafer(info.MouthPart))
                    {
                        ByteConverter.GetBytes(labels[info.MouthPart]).CopyTo(fc, ptr + 0x10);
                    }
                    if (labels.ContainsKeySafer(info.MouthAnims))
                    {
                        ByteConverter.GetBytes(labels[info.MouthAnims]).CopyTo(fc, ptr + 0x14);
                    }
                    if (labels.ContainsKeySafer(info.MouthShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.MouthShapeMotions]).CopyTo(fc, ptr + 0x18);
                    }
                    if (labels.ContainsKeySafer(info.LHandPart))
                    {
                        ByteConverter.GetBytes(labels[info.LHandPart]).CopyTo(fc, ptr + 0x1C);
                    }
                    if (labels.ContainsKeySafer(info.LHandAnims))
                    {
                        ByteConverter.GetBytes(labels[info.LHandAnims]).CopyTo(fc, ptr + 0x20);
                    }
                    if (labels.ContainsKeySafer(info.LHandShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.LHandShapeMotions]).CopyTo(fc, ptr + 0x24);
                    }
                    if (labels.ContainsKeySafer(info.RHandPart))
                    {
                        ByteConverter.GetBytes(labels[info.RHandPart]).CopyTo(fc, ptr + 0x28);
                    }
                    if (labels.ContainsKeySafer(info.RHandAnims))
                    {
                        ByteConverter.GetBytes(labels[info.RHandAnims]).CopyTo(fc, ptr + 0x2C);
                    }
                    if (labels.ContainsKeySafer(info.RHandShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.RHandShapeMotions]).CopyTo(fc, ptr + 0x30);
                    }
                }
            }
            ptr = fc.GetPointer(0xC, key);
            if (ptr != 0)
            {
                MiniEventChars info = ini.Shadow[0];
                if (labels.ContainsKeySafer(info.BodyAnims))
                {
                    ByteConverter.GetBytes(labels[info.BodyAnims]).CopyTo(fc, ptr);
                }
                if (info.HeadPart != null)
                {
                    if (labels.ContainsKeySafer(info.HeadPart))
                    {
                        ByteConverter.GetBytes(labels[info.HeadPart]).CopyTo(fc, ptr + 4);
                    }
                    if (labels.ContainsKeySafer(info.HeadAnims))
                    {
                        ByteConverter.GetBytes(labels[info.HeadAnims]).CopyTo(fc, ptr + 8);
                    }
                    if (labels.ContainsKeySafer(info.HeadShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.HeadShapeMotions]).CopyTo(fc, ptr + 0xC);
                    }
                    if (labels.ContainsKeySafer(info.MouthPart))
                    {
                        ByteConverter.GetBytes(labels[info.MouthPart]).CopyTo(fc, ptr + 0x10);
                    }
                    if (labels.ContainsKeySafer(info.MouthAnims))
                    {
                        ByteConverter.GetBytes(labels[info.MouthAnims]).CopyTo(fc, ptr + 0x14);
                    }
                    if (labels.ContainsKeySafer(info.MouthShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.MouthShapeMotions]).CopyTo(fc, ptr + 0x18);
                    }
                    if (labels.ContainsKeySafer(info.LHandPart))
                    {
                        ByteConverter.GetBytes(labels[info.LHandPart]).CopyTo(fc, ptr + 0x1C);
                    }
                    if (labels.ContainsKeySafer(info.LHandAnims))
                    {
                        ByteConverter.GetBytes(labels[info.LHandAnims]).CopyTo(fc, ptr + 0x20);
                    }
                    if (labels.ContainsKeySafer(info.LHandShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.LHandShapeMotions]).CopyTo(fc, ptr + 0x24);
                    }
                    if (labels.ContainsKeySafer(info.RHandPart))
                    {
                        ByteConverter.GetBytes(labels[info.RHandPart]).CopyTo(fc, ptr + 0x28);
                    }
                    if (labels.ContainsKeySafer(info.RHandAnims))
                    {
                        ByteConverter.GetBytes(labels[info.RHandAnims]).CopyTo(fc, ptr + 0x2C);
                    }
                    if (labels.ContainsKeySafer(info.RHandShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.RHandShapeMotions]).CopyTo(fc, ptr + 0x30);
                    }
                }
            }
            ptr = fc.GetPointer(0x18, key);
            if (ptr != 0)
            {
                MiniEventChars info = ini.Knuckles[0];
                if (labels.ContainsKeySafer(info.BodyAnims))
                {
                    ByteConverter.GetBytes(labels[info.BodyAnims]).CopyTo(fc, ptr);
                }
                if (info.HeadPart != null)
                {
                    if (labels.ContainsKeySafer(info.HeadPart))
                    {
                        ByteConverter.GetBytes(labels[info.HeadPart]).CopyTo(fc, ptr + 4);
                    }
                    if (labels.ContainsKeySafer(info.HeadAnims))
                    {
                        ByteConverter.GetBytes(labels[info.HeadAnims]).CopyTo(fc, ptr + 8);
                    }
                    if (labels.ContainsKeySafer(info.HeadShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.HeadShapeMotions]).CopyTo(fc, ptr + 0xC);
                    }
                    if (labels.ContainsKeySafer(info.MouthPart))
                    {
                        ByteConverter.GetBytes(labels[info.MouthPart]).CopyTo(fc, ptr + 0x10);
                    }
                    if (labels.ContainsKeySafer(info.MouthAnims))
                    {
                        ByteConverter.GetBytes(labels[info.MouthAnims]).CopyTo(fc, ptr + 0x14);
                    }
                    if (labels.ContainsKeySafer(info.MouthShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.MouthShapeMotions]).CopyTo(fc, ptr + 0x18);
                    }
                    if (labels.ContainsKeySafer(info.LHandPart))
                    {
                        ByteConverter.GetBytes(labels[info.LHandPart]).CopyTo(fc, ptr + 0x1C);
                    }
                    if (labels.ContainsKeySafer(info.LHandAnims))
                    {
                        ByteConverter.GetBytes(labels[info.LHandAnims]).CopyTo(fc, ptr + 0x20);
                    }
                    if (labels.ContainsKeySafer(info.LHandShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.LHandShapeMotions]).CopyTo(fc, ptr + 0x24);
                    }
                    if (labels.ContainsKeySafer(info.RHandPart))
                    {
                        ByteConverter.GetBytes(labels[info.RHandPart]).CopyTo(fc, ptr + 0x28);
                    }
                    if (labels.ContainsKeySafer(info.RHandAnims))
                    {
                        ByteConverter.GetBytes(labels[info.RHandAnims]).CopyTo(fc, ptr + 0x2C);
                    }
                    if (labels.ContainsKeySafer(info.RHandShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.RHandShapeMotions]).CopyTo(fc, ptr + 0x30);
                    }
                }
            }
            ptr = fc.GetPointer(0x1C, key);
            if (ptr != 0)
            {
                MiniEventChars info = ini.Rouge[0];
                if (labels.ContainsKeySafer(info.BodyAnims))
                {
                    ByteConverter.GetBytes(labels[info.BodyAnims]).CopyTo(fc, ptr);
                }
                if (info.HeadPart != null)
                {
                    if (labels.ContainsKeySafer(info.HeadPart))
                    {
                        ByteConverter.GetBytes(labels[info.HeadPart]).CopyTo(fc, ptr + 4);
                    }
                    if (labels.ContainsKeySafer(info.HeadAnims))
                    {
                        ByteConverter.GetBytes(labels[info.HeadAnims]).CopyTo(fc, ptr + 8);
                    }
                    if (labels.ContainsKeySafer(info.HeadShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.HeadShapeMotions]).CopyTo(fc, ptr + 0xC);
                    }
                    if (labels.ContainsKeySafer(info.MouthPart))
                    {
                        ByteConverter.GetBytes(labels[info.MouthPart]).CopyTo(fc, ptr + 0x10);
                    }
                    if (labels.ContainsKeySafer(info.MouthAnims))
                    {
                        ByteConverter.GetBytes(labels[info.MouthAnims]).CopyTo(fc, ptr + 0x14);
                    }
                    if (labels.ContainsKeySafer(info.MouthShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.MouthShapeMotions]).CopyTo(fc, ptr + 0x18);
                    }
                    if (labels.ContainsKeySafer(info.LHandPart))
                    {
                        ByteConverter.GetBytes(labels[info.LHandPart]).CopyTo(fc, ptr + 0x1C);
                    }
                    if (labels.ContainsKeySafer(info.LHandAnims))
                    {
                        ByteConverter.GetBytes(labels[info.LHandAnims]).CopyTo(fc, ptr + 0x20);
                    }
                    if (labels.ContainsKeySafer(info.LHandShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.LHandShapeMotions]).CopyTo(fc, ptr + 0x24);
                    }
                    if (labels.ContainsKeySafer(info.RHandPart))
                    {
                        ByteConverter.GetBytes(labels[info.RHandPart]).CopyTo(fc, ptr + 0x28);
                    }
                    if (labels.ContainsKeySafer(info.RHandAnims))
                    {
                        ByteConverter.GetBytes(labels[info.RHandAnims]).CopyTo(fc, ptr + 0x2C);
                    }
                    if (labels.ContainsKeySafer(info.RHandShapeMotions))
                    {
                        ByteConverter.GetBytes(labels[info.RHandShapeMotions]).CopyTo(fc, ptr + 0x30);
                    }
                }
            }
            ptr = fc.GetPointer(0x24, key);
            if (ptr != 0 && labels.ContainsKeySafer(ini.MechEggmanBodyAnims))
            {
                ByteConverter.GetBytes(labels[ini.MechEggmanBodyAnims]).CopyTo(fc, ptr);
            }
            ptr = fc.GetPointer(4, key);
            if (ptr != 0 && labels.ContainsKeySafer(ini.Camera))
            {
                ByteConverter.GetBytes(labels[ini.Camera]).CopyTo(fc, 4);
                //ByteConverter.GetBytes(ini.CamFrames).CopyTo(fc, ptr + 4);
                ByteConverter.GetBytes(labels[ini.Camera]).CopyTo(fc, ptr + 0x10);
            }
            if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
            {
                Prs.Compress(fc, filename);
            }
            else
            {
                File.WriteAllBytes(filename, fc);
            }
        }
Exemplo n.º 15
0
        private static List <MaterialBuildInfo> BuildProceduralMaterials(string baseDirectory, List <Assimp.Material> aiMaterials, string texturePakPath)
        {
            var textureArchive       = new GvmArchive();
            var textureArchiveStream = new MemoryStream();
            var textureArchiveWriter = ( GvmArchiveWriter )textureArchive.Create(textureArchiveStream);
            var textureIdLookup      = new Dictionary <string, int>(StringComparer.InvariantCultureIgnoreCase);

            if (texturePakPath != null && File.Exists(texturePakPath))
            {
                var extension  = Path.GetExtension(texturePakPath);
                var fileStream = ( Stream )File.OpenRead(texturePakPath);
                if (extension.Equals(".prs", StringComparison.InvariantCultureIgnoreCase))
                {
                    try
                    {
                        var decompressedFileStream = new MemoryStream();
                        Prs.Decompress(fileStream, decompressedFileStream);
                        fileStream.Dispose();
                        fileStream = decompressedFileStream;
                    }
                    catch (Exception)
                    {
                        // Not compressed
                    }

                    fileStream.Position = 0;
                }

                var existingTextureArchive       = new GvmArchive();
                var existingTextureArchiveReader = ( GvmArchiveReader )existingTextureArchive.Open(fileStream);
                for (var i = 0; i < existingTextureArchiveReader.Entries.Count; i++)
                {
                    var entry = existingTextureArchiveReader.Entries[i];

                    // Make copy of entry stream
                    var entryStreamCopy = new MemoryStream();
                    entry.Open().CopyTo(entryStreamCopy);
                    entryStreamCopy.Position = 0;

                    var texture = new VrSharp.GvrTexture.GvrTexture(entryStreamCopy);
                    Console.WriteLine(texture.GlobalIndex);
                    entryStreamCopy.Position = 0;

                    // Clean entry name from the added extension
                    var entryName = Path.ChangeExtension(entry.Name, null);

                    textureArchiveWriter.CreateEntry(entryStreamCopy, entryName);
                    textureIdLookup[entryName] = i;
                }
            }

            var materials = new List <MaterialBuildInfo>();

            foreach (var aiMaterial in aiMaterials)
            {
                var textureName = Path.GetFileNameWithoutExtension(aiMaterial.TextureDiffuse.FilePath).ToLowerInvariant();
                if (!textureIdLookup.TryGetValue(textureName, out var textureId))
                {
                    textureId = textureIdLookup[textureName] = textureIdLookup.Count;
                    var texturePath = Path.GetFullPath(Path.Combine(baseDirectory, aiMaterial.TextureDiffuse.FilePath));
                    if (File.Exists(texturePath))
                    {
                        // Convert texture
                        var texture = new GvrTexture {
                            GlobalIndex = ( uint )(1 + textureId)
                        };

                        var textureStream = new MemoryStream();
                        var textureBitmap = new Bitmap(texturePath);
                        texture.Write(textureBitmap, textureStream);
                        textureStream.Position = 0;

                        // Add it
                        textureArchiveWriter.CreateEntry(textureStream, textureName);
                    }
                }

                var material = new MaterialBuildInfo
                {
                    Ambient          = AssimpHelper.FromAssimp(aiMaterial.ColorAmbient),
                    Diffuse          = AssimpHelper.FromAssimp(aiMaterial.ColorDiffuse),
                    Specular         = AssimpHelper.FromAssimp(aiMaterial.ColorSpecular),
                    ClampU           = aiMaterial.TextureDiffuse.WrapModeU == Assimp.TextureWrapMode.Clamp,
                    ClampV           = aiMaterial.TextureDiffuse.WrapModeV == Assimp.TextureWrapMode.Clamp,
                    FlipU            = aiMaterial.TextureDiffuse.WrapModeU == Assimp.TextureWrapMode.Mirror,
                    FlipV            = aiMaterial.TextureDiffuse.WrapModeV == Assimp.TextureWrapMode.Mirror,
                    DestinationAlpha = DstAlphaOp.InverseDst,
                    Exponent         = 0,
                    FilterMode       = FilterMode.Trilinear,
                    MipMapDAdjust    = MipMapDAdjust.D050,
                    SourceAlpha      = SrcAlphaOp.Src,
                    SuperSample      = false,
                    TextureId        = (short)textureId,
                };

                materials.Add(material);
            }

            // Write texture archive to file
            textureArchiveWriter.Flush();
            textureArchiveStream.Position = 0;

            if (texturePakPath != null)
            {
                // Compress it.
                var textureArchivePrsStream = new MemoryStream();
                Prs.Compress(textureArchiveStream, textureArchivePrsStream);

                // Save compressed file.
                textureArchivePrsStream.Position = 0;
                using (var outFile = File.Create(texturePakPath))
                    textureArchivePrsStream.CopyTo(outFile);
            }

            return(materials);
        }
Exemplo n.º 16
0
 static void Main(string[] args)
 {
     if (args.Length == 0)
     {
         Console.Write("Filename: ");
         args = new string[] { Console.ReadLine().Trim('"') };
     }
     foreach (string filename in args)
     {
         Console.WriteLine("Splitting file {0}...", filename);
         byte[] fc;
         if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
         {
             fc = Prs.Decompress(filename);
         }
         else
         {
             fc = File.ReadAllBytes(filename);
         }
         EventIniData ini = new EventIniData()
         {
             Name = Path.GetFileNameWithoutExtension(filename)
         };
         string path = Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filename)), Path.GetFileNameWithoutExtension(filename))).FullName;
         uint   key;
         if (fc[0] == 0x81)
         {
             Console.WriteLine("File is in GC/PC format.");
             ByteConverter.BigEndian = true;
             key      = 0x8125FE60;
             ini.Game = Game.SA2B;
         }
         else
         {
             Console.WriteLine("File is in DC format.");
             ByteConverter.BigEndian = false;
             key      = 0xC600000;
             ini.Game = Game.SA2;
         }
         List <string> nodenames = new List <string>();
         Dictionary <string, KeyValuePair <string, NJS_OBJECT> > modelfiles = new Dictionary <string, KeyValuePair <string, NJS_OBJECT> >();
         int ptr = fc.GetPointer(0x20, key);
         if (ptr != 0)
         {
             for (int i = 0; i < (ini.Game == Game.SA2B ? 18 : 16); i++)
             {
                 UpgradeInfo info = new UpgradeInfo();
                 info.RootNode = GetModel(fc, ptr, key, Path.Combine(path, $"Upgrade {i + 1} Root.sa2mdl"), nodenames, modelfiles);
                 if (info.RootNode != null)
                 {
                     int ptr2 = fc.GetPointer(ptr + 4, key);
                     if (ptr2 != 0)
                     {
                         info.AttachNode1 = $"object_{ptr2:X8}";
                     }
                     info.Model1 = GetModel(fc, ptr + 8, key, Path.Combine(path, $"Upgrade {i + 1} Model 1.sa2mdl"), nodenames, modelfiles);
                     ptr2        = fc.GetPointer(ptr + 0xC, key);
                     if (ptr2 != 0)
                     {
                         info.AttachNode2 = $"object_{ptr2:X8}";
                     }
                     info.Model2 = GetModel(fc, ptr + 0x10, key, Path.Combine(path, $"Upgrade {i + 1} Model 2.sa2mdl"), nodenames, modelfiles);
                 }
                 ini.Upgrades.Add(info);
                 ptr += 0x14;
             }
         }
         else
         {
             Console.WriteLine("Event contains no character upgrades.");
         }
         int gcnt = ByteConverter.ToInt32(fc, 8);
         ptr = fc.GetPointer(0, key);
         if (ptr != 0)
         {
             Console.WriteLine("Event contains {0} group(s).", gcnt + 1);
             for (int gn = 0; gn <= gcnt; gn++)
             {
                 GroupInfo info = new GroupInfo();
                 int       ptr2 = fc.GetPointer(ptr, key);
                 int       ecnt = ByteConverter.ToInt32(fc, ptr + 4);
                 if (ptr2 != 0)
                 {
                     Console.WriteLine("Group {0} contains {1} entit{2}.", gn + 1, ecnt, ecnt == 1 ? "y" : "ies");
                     for (int en = 0; en < ecnt; en++)
                     {
                         string name = GetModel(fc, ptr2, key, Path.Combine(path, $"Group {gn + 1} Entity {en + 1} Model.sa2mdl"), nodenames, modelfiles);
                         if (name != null)
                         {
                             info.Entities.Add(name);
                         }
                         ptr2 += ini.Game == Game.SA2B ? 0x2C : 0x20;
                     }
                 }
                 else
                 {
                     Console.WriteLine("Group {0} contains no entities.", gn + 1);
                 }
                 ptr2 = fc.GetPointer(ptr + 0x18, key);
                 if (ptr2 != 0)
                 {
                     info.Big = GetModel(fc, ptr2, key, Path.Combine(path, $"Group {gn + 1} Big Model.sa2mdl"), nodenames, modelfiles);
                 }
                 ini.Groups.Add(info);
                 ptr += 0x20;
             }
         }
         else
         {
             Console.WriteLine("Event contains no groups.");
         }
         ptr = fc.GetPointer(0x18, key);
         if (ptr != 0)
         {
             for (int i = 0; i < 93; i++)
             {
                 string name = GetModel(fc, ptr, key, Path.Combine(path, $"Mech Part {i + 1}.sa2mdl"), nodenames, modelfiles);
                 if (name != null)
                 {
                     ini.MechParts.Add(i, name);
                 }
                 ptr += 4;
             }
         }
         else
         {
             Console.WriteLine("Event contains no mech parts.");
         }
         ptr = fc.GetPointer(0x1C, key);
         if (ptr != 0)
         {
             ini.TailsTails = GetModel(fc, ptr, key, Path.Combine(path, $"Tails tails.sa2mdl"), nodenames, modelfiles);
         }
         else
         {
             Console.WriteLine("Event does not contain Tails' tails.");
         }
         foreach (var item in modelfiles)
         {
             ModelFile.CreateFile(item.Value.Key, item.Value.Value, null, null, null, null, null, ModelFormat.Chunk);
             ini.Files.Add(Path.GetFileName(item.Value.Key), HelperFunctions.FileHash(item.Value.Key));
         }
         IniSerializer.Serialize(ini, Path.Combine(path, Path.ChangeExtension(Path.GetFileName(filename), ".ini")));
     }
 }
Exemplo n.º 17
0
 public byte[] Decompress() => Prs.Decompress(FileDataCompressed);
Exemplo n.º 18
0
 static void Main(string[] args)
 {
     if (args.Length == 0)
     {
         Console.Write("Filename: ");
         args = new string[] { Console.ReadLine().Trim('"') };
     }
     foreach (string filename in args)
     {
         byte[] fc;
         if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
         {
             fc = Prs.Decompress(filename);
         }
         else
         {
             fc = File.ReadAllBytes(filename);
         }
         string       path = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filename)), Path.GetFileNameWithoutExtension(filename));
         EventIniData ini  = IniSerializer.Deserialize <EventIniData>(Path.Combine(path, Path.ChangeExtension(Path.GetFileName(filename), ".ini")));
         uint         key;
         if (fc[0] == 0x81)
         {
             ByteConverter.BigEndian = true;
             key = 0x8125FE60;
         }
         else
         {
             ByteConverter.BigEndian = false;
             key = 0xC600000;
         }
         List <byte> modelbytes           = new List <byte>(fc);
         Dictionary <string, uint> labels = new Dictionary <string, uint>();
         foreach (string file in ini.Files.Where(a => HelperFunctions.FileHash(Path.Combine(path, a.Key)) != a.Value).Select(a => a.Key))
         {
             modelbytes.AddRange(new ModelFile(Path.Combine(path, file)).Model.GetBytes((uint)(key + modelbytes.Count), false, labels, out uint address));
         }
         fc = modelbytes.ToArray();
         int ptr = fc.GetPointer(0x20, key);
         if (ptr != 0)
         {
             for (int i = 0; i < (ini.Game == Game.SA2B ? 18 : 16); i++)
             {
                 UpgradeInfo info = ini.Upgrades[i];
                 if (info.RootNode != null)
                 {
                     if (labels.ContainsKey(info.RootNode))
                     {
                         ByteConverter.GetBytes(labels[info.RootNode]).CopyTo(fc, ptr);
                     }
                     if (labels.ContainsKey(info.AttachNode1))
                     {
                         ByteConverter.GetBytes(labels[info.AttachNode1]).CopyTo(fc, ptr + 4);
                     }
                     if (labels.ContainsKey(info.Model1))
                     {
                         ByteConverter.GetBytes(labels[info.Model1]).CopyTo(fc, ptr + 8);
                     }
                     if (info.AttachNode2 != null && labels.ContainsKey(info.AttachNode2))
                     {
                         ByteConverter.GetBytes(labels[info.AttachNode2]).CopyTo(fc, ptr + 12);
                     }
                     if (info.Model2 != null && labels.ContainsKey(info.Model2))
                     {
                         ByteConverter.GetBytes(labels[info.Model2]).CopyTo(fc, ptr + 16);
                     }
                 }
                 ptr += 0x14;
             }
         }
         int gcnt = ByteConverter.ToInt32(fc, 8);
         ptr = fc.GetPointer(0, key);
         if (ptr != 0)
         {
             for (int gn = 0; gn <= gcnt; gn++)
             {
                 GroupInfo info = ini.Groups[gn];
                 int       ptr2 = fc.GetPointer(ptr, key);
                 int       ecnt = Math.Min(ByteConverter.ToInt32(fc, ptr + 4), info.Entities?.Count ?? 0);
                 if (ptr2 != 0)
                 {
                     for (int en = 0; en < ecnt; en++)
                     {
                         if (labels.ContainsKey(info.Entities[en]))
                         {
                             ByteConverter.GetBytes(labels[info.Entities[en]]).CopyTo(fc, ptr2);
                         }
                         ptr2 += ini.Game == Game.SA2B ? 0x2C : 0x20;
                     }
                 }
                 ptr2 = fc.GetPointer(ptr + 0x18, key);
                 if (ptr2 != 0 && info.Big != null && labels.ContainsKey(info.Big))
                 {
                     ByteConverter.GetBytes(labels[info.Big]).CopyTo(fc, ptr2);
                 }
                 ptr += 0x20;
             }
         }
         ptr = fc.GetPointer(0x18, key);
         if (ptr != 0)
         {
             for (int i = 0; i < 18; i++)
             {
                 if (ini.MechParts.ContainsKey(i) && labels.ContainsKey(ini.MechParts[i]))
                 {
                     ByteConverter.GetBytes(labels[ini.MechParts[i]]).CopyTo(fc, ptr);
                 }
                 ptr += 4;
             }
         }
         ptr = fc.GetPointer(0x1C, key);
         if (ptr != 0 && ini.TailsTails != null && labels.ContainsKey(ini.TailsTails))
         {
             ByteConverter.GetBytes(labels[ini.TailsTails]).CopyTo(fc, ptr);
         }
         if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
         {
             Prs.Compress(fc, filename);
         }
         else
         {
             File.WriteAllBytes(filename, fc);
         }
     }
 }
Exemplo n.º 19
0
        /*
         *  Set of constructors.
         *  Self explanatory.
         */

        /// <summary>
        /// Returns a copy of the current file that has been PRS Decompressed, ready for writing to disk or manipulation.
        /// </summary>
        public byte[] DecompressThis()
        {
            return(Prs.Decompress(ref this.CompressedData));
        }
Exemplo n.º 20
0
 /// <summary>
 /// 解压缩文件
 /// </summary>
 /// <param name="compFile"></param>
 /// <returns></returns>
 public override byte[] Decompress(string file)
 {
     return(Prs.Decompress(file));
 }
Exemplo n.º 21
0
 /// <summary>
 /// Writes an uncompressed copy of this individual file to disk.
 /// </summary>
 /// <returns></returns>
 public void WriteToFile(string path)
 {
     File.WriteAllBytes(path, Prs.Decompress(ref this.CompressedData));
 }