Exemple #1
0
        private void ReadMEXP(int size, ref BinaryReader reader)
        {
            string[] names = ReadStringTable(ref reader, false, false);

            for (int i = 0; i < MapVariables.Count; i++)
            {
                Console.WriteLine($"{i} = {names[i]}; ${MapVariables.Count}");
                if (MapVariables.ContainsKey(i))
                {
                    MapVariable v = MapVariables[i];
                    // v.Name = names[i];
                    MapVariables[i] = v;
                }
            }

            for (int i = MapVariables.Count; i < MapArrays.Count; i++)
            {
                Console.WriteLine($"{i} = {names[i]}; ${MapVariables.Count}");
                if (MapArrays.ContainsKey(i))
                {
                    MapArray v = MapArrays[i];
                    // v.Name = names[i];
                    MapArrays[i] = v;
                }
            }
        }
Exemple #2
0
        private void ReadMSTR(int size, ref BinaryReader reader)
        {
            int num = size / 4;

            for (int i = 0; i < num; i++)
            {
                int         index = reader.ReadInt32();
                MapVariable v     = MapVariables[index];
                v.IsString          = true;
                MapVariables[index] = v;
            }
        }
Exemple #3
0
        private void ReadMINI(int size, ref BinaryReader reader)
        {
            int numVars   = (size / 4) - 1;
            int baseIndex = reader.ReadInt32();

            for (int i = 0; i < numVars; i++)
            {
                int index = baseIndex + i;
                int value = reader.ReadInt32();

                MapVariable v = new MapVariable();
                v.Name     = $"_m_{index:d4}_";
                v.Value    = value;
                v.IsString = false;

                MapVariables[index] = v;
            }
        }
Exemple #4
0
        public void Disassemble(Stream outputStream)
        {
            OutputStream = outputStream;

            AssemblyName assemblyName = Assembly.GetExecutingAssembly().GetName();

            WriteLine("// Disassembled by " + assemblyName.Name + " version " + assemblyName.Version);
            WriteLine("//");
            WriteLine("// String Table:");
            for (int i = 0; i < StringTable.Count; i++)
            {
                WriteLine($"//  {i,4} " + StringTable[i]);
            }

            WriteLine();

            if (Format == AcsFormat.Acs95)
            {
                WriteLine("#include \"common.acs\"");
            }
            else
            {
                WriteLine("#include \"zcommon.acs\"");
            }

            WriteLine();
            foreach (var library in Libraries)
            {
                WriteLine($"#import \"{library}\"");
            }
            WriteLine();

            WriteLine("// ================================================== MAP ARRAYS");
            WriteLine();

            if (ImportedMapArrays.Count > 0)
            {
                WriteLine($"/* Imported map arrays ({ImportedMapArrays.Count}:");
                foreach (KeyValuePair <int, ImportedArray> pair in ImportedMapArrays)
                {
                    int           index = pair.Key;
                    ImportedArray array = pair.Value;

                    WriteLine($"/* imported - index {index:x4} */ int {array.Name}[{array.Size}];");
                }
                WriteLine("//*/");
            }

            foreach (var pair in MapArrays)
            {
                int      index    = pair.Key;
                MapArray mapArray = pair.Value;
                int[]    array    = mapArray.Values;

                string name = (!String.IsNullOrEmpty(mapArray.Name) ? mapArray.Name : $"_a_{index:x4}_");
                string type = (mapArray.IsString ? "str" : "int");

                Write($"{type} {name}[{array.Length}] = " + "{");
                for (int i = 0; i < array.Length; i++)
                {
                    if (mapArray.IsString)
                    {
                        string s;
                        int    sI = array[i];

                        if (sI < StringTable.Count)
                        {
                            s = StringTable[array[i]];
                        }
                        else
                        {
                            s = "(DeACC: Invalid string index " + sI + ")";
                        }
                        Write($"\"{s}\"");
                    }
                    else
                    {
                        Write(array[i].ToString());
                    }

                    if (i < array.Length - 1)
                    {
                        Write(", ");
                    }
                }
                WriteLine("};");
            }

            WriteLine();
            WriteLine("// ================================================== MAP VARIABLES");
            WriteLine();

            if (ImportedMapVariables.Count > 0)
            {
                WriteLine($"/* Imported map variables ({ImportedMapVariables.Count}:");
                foreach (KeyValuePair <int, string> pair in ImportedMapVariables)
                {
                    int    index = pair.Key;
                    string name  = pair.Value;

                    WriteLine($"int {name}; // imported - index {index:x4}");
                }
                WriteLine("//*/");
            }

            foreach (var pair in MapVariables)
            {
                int         index = pair.Key;
                MapVariable var   = pair.Value;

                string type = (var.IsString ? "str" : "int");

                WriteLine($"{type} {var.Name} = {var.Value};");
            }

            WriteLine();
            WriteLine("// ================================================== FUNCTIONS");
            WriteLine();

            foreach (KeyValuePair <string, AcsFunction> pair in FunctionMap)
            {
                string      name     = pair.Key;
                AcsFunction function = pair.Value;

                string returnType = (function.Returns ? "int" : "void");
                string args;

                if (function.NumberOfArguments > 0)
                {
                    args = "";
                    for (int i = 0; i < function.NumberOfArguments; i++)
                    {
                        args += $"int _p_{ParameterCounter:x4}_";
                        ParameterCounter++;

                        if (i < function.NumberOfArguments - 1)
                        {
                            args += ", ";
                        }
                    }
                }
                else
                {
                    args = "void";
                }

                WriteLine($"// Pointer: {function.Pointer}; Size = {function.CodeSize}");
                WriteLine($"function {returnType} {name} ({args})");
                WriteLine("{");
                WriteCode(function.Code);
                WriteLine("}");
                WriteLine();
            }

            WriteLine();
            WriteLine("// ================================================== SCRIPTS");
            WriteLine();

            foreach (KeyValuePair <int, AcsScript> pair in Scripts)
            {
                int       number = pair.Key;
                AcsScript script = pair.Value;

                string args  = "(void)";
                string type  = "";
                string flags = "";

                if (script.NumberOfArguments > 0)
                {
                    args = "(";
                    for (int i = 0; i < script.NumberOfArguments; i++)
                    {
                        args += $"int _p_{ParameterCounter:x4}_";
                        ParameterCounter++;

                        if (i < script.NumberOfArguments - 1)
                        {
                            args += ", ";
                        }
                    }
                    args += ")";
                }
                else if (script.NumberOfArguments == 0 && script.Type != ScriptType.Closed)
                {
                    args = "";
                }

                if (script.Type != ScriptType.Closed)
                {
                    type = script.Type.ToString().ToUpper();
                }

                if ((script.Flags & (int)ScriptFlags.Net) != 0)
                {
                    flags += "NET ";
                }

                if ((script.Flags & (int)ScriptFlags.Clientside) != 0)
                {
                    flags += "CLIENTSIDE ";
                }

                string argsSpace = (String.IsNullOrEmpty(args) ? "" : " ");
                string typeSpace = (script.Type != ScriptType.Closed ? " " : "");

                string name = (String.IsNullOrEmpty(script.Name) ? number.ToString() : $"\"{script.Name}\"");

                WriteLine($"// Pointer: {script.Pointer}; Size = {script.CodeSize}");
                WriteLine($"Script {name}{argsSpace}{args}{typeSpace}{type} {flags}");

                WriteLine("{");
                WriteCode(script.Code);
                WriteLine("}");
                WriteLine();
            }
        }