Esempio n. 1
0
        public static AdhocFile ReadFromFile(string path)
        {
            var bytes = File.ReadAllBytes(path);
            var sr    = new SpanReader(bytes, encoding: Encoding.UTF8);

            string magic = sr.ReadStringRaw(4);

            if (!magic.Equals(MAGIC))
            {
                throw new Exception("Invalid MAGIC, doesn't match ADCH.");
            }

            byte version = (byte)int.Parse(sr.ReadStringRaw(3));

            sr.ReadByte();
            var adc = new AdhocFile(version);

            if (adc.Version >= 9)
            {
                adc.ParseStringTable(ref sr);
            }

            adc.ParentCode = new AdhocCode();
            adc.ParentCode.Deserialize(adc, ref sr);

            return(adc);
        }
Esempio n. 2
0
 public static string ReadADCString(AdhocFile parent, ref SpanReader sr)
 {
     if (parent.Version <= 8)
     {
         return(sr.ReadString2());
     }
     else
     {
         uint strTableIndex = (uint)sr.DecodeBitsAndAdvance();
         return(parent.StringTable[strTableIndex]);
     }
 }
Esempio n. 3
0
        public static List <string> ReadADCStringTable(AdhocFile parent, ref SpanReader sr)
        {
            uint          strCount = sr.ReadUInt32();
            List <string> list     = new List <string>((int)strCount);

            for (int i = 0; i < strCount; i++)
            {
                string str = ReadADCString(parent, ref sr);
                list.Add(str);
            }

            return(list);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            if (args.Length == 1)
            {
                if (args[0].ToLower().EndsWith(".adc"))
                {
                    AdhocFile adc        = null;
                    bool      withOffset = true;
                    try
                    {
                        adc = AdhocFile.ReadFromFile(args[0]);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Errored while reading: {e.Message}");
                    }

                    adc.Disassemble(Path.ChangeExtension(args[0], ".ad.diss"), withOffset);

                    if (adc.Version == 12)
                    {
                        adc.PrintStrings(Path.ChangeExtension(args[0], ".strings"));
                    }

                    return;
                }
                else if (args[0].ToLower().EndsWith(".gpb"))
                {
                    var gpb = GpbBase.ReadFile(args[0]);
                    if (gpb is null)
                    {
                        Console.WriteLine("Could not parse GPB Header.");
                        return;
                    }

                    string fileName = Path.GetFileNameWithoutExtension(args[0]);
                    string dir      = Path.GetDirectoryName(args[0]);

                    gpb.Unpack(Path.GetFileNameWithoutExtension(args[0]), null);
                    return;
                }
            }

            Parser.Default.ParseArguments <PackVerbs, UnpackVerbs, MProjectToBinVerbs, MProjectToTextVerbs>(args)
            .WithParsed <PackVerbs>(Pack)
            .WithParsed <UnpackVerbs>(Unpack)
            .WithParsed <MProjectToBinVerbs>(MProjectToBin)
            .WithParsed <MProjectToTextVerbs>(MProjectToText);
        }