public ScriptFile(Stream scriptStream, OpcodeSet opcodeSet)
        {
            file    = scriptStream;
            CodeSet = opcodeSet;

            CodeTable    = new List <byte>();
            Functions    = new List <Function>(); FunctionLoc = new Dictionary <int, Function>();
            AggFunctions = new List <Function>(); AggregateLoc = new Dictionary <int, Function>();

            Header         = ScriptHeader.Generate(scriptStream);
            StringTable    = new StringTable(scriptStream, Header.StringTableOffsets, Header.StringBlocks, Header.StringsSize);
            X64NativeTable = new X64NativeTable(scriptStream, Header.NativesOffset + Header.RSC7Offset, Header.NativesCount, Header.CodeLength);
            for (int i = 0; i < Header.CodeBlocks; i++)
            {
                int    tablesize = ((i + 1) * 0x4000 >= Header.CodeLength) ? Header.CodeLength % 0x4000 : 0x4000;
                byte[] working   = new byte[tablesize];
                scriptStream.Position = Header.CodeTableOffsets[i];
                scriptStream.Read(working, 0, tablesize);
                CodeTable.AddRange(working);
            }
        }
        private static void InitializeINIFields(Options o)
        {
            IsBit32 = SwapEndian = RDROpcodes = RDRNativeCipher = false;
            switch (o.Opcode.ToLower())
            {
            case "v":
                Program.Codeset = new OpcodeSet();
                break;

            case "vconsole":
                IsBit32         = SwapEndian = true;
                Program.Codeset = new OpcodeSet();
                break;

            case "rdr":
                RDROpcodes      = RDRNativeCipher = true;
                Program.Codeset = new RDROpcodeSet();
                break;

            case "rdr1311":
                RDROpcodes      = RDRNativeCipher = true;
                Program.Codeset = new RDR1311OpcodeSet();
                break;

            case "rdrconsole":
                RDROpcodes      = true;
                Program.Codeset = new RDRConsoleOpcodeSet();
                break;

            default:
                throw new System.ArgumentException("Invalid Opcode Set: " + o.Opcode);
            }

            Program.hashbank           = new Hashes();
            Program.gxtbank            = new GXTEntries();
            Program.UseMultiThreading  = o.UseMultiThreading;
            Program.CompressedInput    = o.CompressedInput;
            Program.CompressedOutput   = o.CompressOutput;
            Program.AggregateFunctions = o.Aggregate;
            if (o.AggregateMinLines > 0)
            {
                Program.AggregateMinLines = o.AggregateMinLines;
            }
            if (o.AggregateMinHits > 0)
            {
                Program.AggregateMinHits = o.AggregateMinHits;
            }

            if (!o.Default)
            {
                Program.UppercaseNatives  = o.UppercaseNatives;
                Program.ShowNamespace     = o.ShowNamespace;
                Program.DeclareVariables  = o.DeclareVariables;
                Program.ShiftVariables    = o.ShiftVariables;
                Program.ReverseHashes     = o.ReverseHashes;
                Program.ShowArraySize     = o.ShowArraySize;
                Program.ShowEntryComments = o.ShowEntryComments;
                Program.HexIndex          = o.HexIndex;
                Program.ShowFuncPosition  = o.ShowFuncPosition;
                switch (o.IntStyle.ToLower())
                {
                case "uint": Program.IntStyle = IntType._uint; break;

                case "hex": Program.IntStyle = IntType._hex; break;

                case "int":
                default:
                    Program.IntStyle = IntType._int; break;
                }
            }
        }
        public ScriptFile(Stream scriptStream, OpcodeSet opcodeSet)
        {
            file    = scriptStream;
            CodeSet = opcodeSet;

            CodeTable    = new List <byte>();
            Functions    = new List <Function>();
            AggFunctions = new List <Function>();
            FunctionLoc  = new Dictionary <int, FunctionName>();

            Header         = ScriptHeader.Generate(scriptStream);
            StringTable    = new StringTable(scriptStream, Header.StringTableOffsets, Header.StringBlocks, Header.StringsSize);
            X64NativeTable = new X64NativeTable(scriptStream, Header.NativesOffset + Header.RSC7Offset, Header.NativesCount, Header.CodeLength);
            name           = Header.ScriptName;

            for (int i = 0; i < Header.CodeBlocks; i++)
            {
                int    tablesize = ((i + 1) * 0x4000 >= Header.CodeLength) ? Header.CodeLength % 0x4000 : 0x4000;
                byte[] working   = new byte[tablesize];
                scriptStream.Position = Header.CodeTableOffsets[i];
                scriptStream.Read(working, 0, tablesize);
                CodeTable.AddRange(working);
            }

            GetStaticInfo();
            GetFunctions();
            foreach (Function func in Functions)
            {
                func.PreDecode();
            }
            Statics.checkvars();

            bool dirty = true;

            while (dirty)
            {
                dirty = false;
                foreach (Function func in Functions)
                {
                    if (func.Dirty)
                    {
                        dirty      = true;
                        func.Dirty = false;
                        func.decodeinsructionsforvarinfo();
                    }
                }
            }

            if (Program.AggregateFunctions)
            {
                foreach (Function func in AggFunctions)
                {
                    func.PreDecode();
                }
            }
            foreach (Function func in Functions)
            {
                func.Decode();
            }
            if (Program.AggregateFunctions)
            {
                foreach (Function func in AggFunctions)
                {
                    func.Decode();
                }
            }
        }