Esempio n. 1
0
        private static void InnerPatch(TmodFileWrapper.ITmodFile modFile, IEnumerable <Type> processors, string dll = null)
        {
            if (string.IsNullOrWhiteSpace(dll))
            {
                dll = modFile.HasFile("All.dll") ? "All.dll" : "Windows.dll";
            }

            Logger.Info(Strings.Patching, dll);

            var module = AssemblyDef.Load(modFile.GetFile(dll)).Modules.Single();

            foreach (var processor in processors)
            {
                try
                {
                    var proc = Activator.CreateInstance(processor, modFile, module, _language);
                    var tran = LoadFiles(SourcePath, processor);

                    processor.GetMethod(nameof(Processor <Content> .PatchContents))?.Invoke(proc, new[] { tran });
                }
                catch (Exception ex)
                {
                    Logger.Warn(Strings.ProcExceptionOccur, processor.FullName);
                    Logger.Error(ex);
                }
            }

            using (var ms = new MemoryStream())
            {
                module.Assembly.Write(ms);

                modFile.Files[dll] = ms.ToArray();
            }
        }
        public void Run()
        {
            try
            {
                var wrapper = new TmodFileWrapper(typeof(Terraria.BitsByte).Assembly);
                Mod = wrapper.LoadFile(ModPath);
            }
            catch (Exception ex)
            {
                throw new Exception("Cannot initialize mod file instance", ex);
            }

            var processors = GetProcessors();

            switch (Mode)
            {
            case RunningMode.Dump:
                Dump(processors);
                break;

            case RunningMode.Patch:
                Patch(processors);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public HardCodedTranslationProvider(TmodFileWrapper.ITmodFile modFile, ModuleDef module, GameCultures lang)
        {
            _modFile = modFile;
            _module  = module ?? throw new ArgumentNullException(nameof(module));
            _lang    = lang;

            _logger = LogManager.GetLogger(GetType().Name);

            LoadTypeDefinitions();
            CreateInitializationMethod();
        }
Esempio n. 4
0
            public string Load(TmodFileWrapper.ITmodFile modFile)
            {
                var prop = LoadRaw(modFile);

                var json = JsonConvert.SerializeObject(prop, new JsonSerializerSettings
                {
                    ContractResolver = new StringFieldContractResolver(),
                    Formatting       = Formatting.Indented
                });

                return(json);
            }
        protected ProcessEngine(string modPath, string sourcePath, GameCultures language)
        {
            ModPath    = modPath;
            SourcePath = sourcePath;
            Language   = language;

            var wrapper = new TmodFileWrapper(typeof(BitsByte).Assembly);

            Mod = wrapper.LoadFile(ModPath);

            Processors = new List <Type>();
            SetupProcessors((IList <Type>)Processors);
        }
        protected Processor(TmodFileWrapper.ITmodFile modFile, ModuleDef modModule, GameCultures culture)
        {
            ModFile   = modFile ?? throw new ArgumentNullException(nameof(modFile));
            ModModule = modModule ?? throw new ArgumentNullException(nameof(modModule));

            Logger = LogManager.GetLogger("Proc." + GetType().Name);

            InstructionSelectors = new Dictionary <string, MethodInfo>();

            Provider = new HardCodedTranslationProvider(modFile, modModule, culture);

            InitializeInstructionSelectors();
        }
Esempio n. 7
0
        private static void Patch(TmodFileWrapper.ITmodFile modFile, IEnumerable <Type> processors)
        {
            const string mono = "Mono.dll";

            var procs = processors as Type[] ?? processors.ToArray();

            if (modFile.HasFile(mono))
            {
                InnerPatch(modFile, procs, mono);
            }

            InnerPatch(modFile, procs);

            // save mod file
            var file = string.Format(DefaultConfigurations.OutputFileNameFormat, modFile.Name);

            Logger.Warn(Strings.Saving, file);

            modFile.Write(file);
        }
Esempio n. 8
0
        private static void Dump(TmodFileWrapper.ITmodFile modFile, IEnumerable <Type> processors)
        {
            var module = AssemblyDef.Load(modFile.GetMainAssembly()).Modules.Single();

            foreach (var processor in processors)
            {
                try
                {
                    var proc = Activator.CreateInstance(processor, modFile, module, _language);

                    var contents =
                        (IReadOnlyList <Content>)processor.GetMethod(nameof(Processor <Content> .DumpContents))?.Invoke(proc, new object[0]);

                    if (contents == null)
                    {
                        Logger.Warn(Strings.ProcNotUsed, processor.Name);
                        continue;
                    }

                    Logger.Debug("Using " + processor.Name);

                    foreach (var val in contents.GroupBy(x => x.Namespace, x => x))
                    {
                        File.WriteAllText(
                            DefaultConfigurations.GetPath(modFile, processor, val.Key + ".json"),
                            JsonConvert.SerializeObject(val.ToList(), Formatting.Indented)
                            );

                        Logger.Info(Strings.DumpNamespace, val.Key);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Warn(Strings.ProcExceptionOccur, processor.FullName);
                    Logger.Error(ex);
                }
            }
        }
Esempio n. 9
0
            public void Write(TmodFileWrapper.ITmodFile modFile, string json)
            {
                // Creates a new blank information object from json data
                var obj = JsonConvert.DeserializeObject(json, _readBuildFile.DeclaringType, new JsonSerializerSettings
                {
                    ContractResolver = new StringFieldContractResolver()
                });

                // Loads the property object within current mod
                var info = LoadRaw(modFile);

                // Replaces target fields
                foreach (var field in obj.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Where(FieldSelector))
                {
                    var replace = field.GetValue(obj);
                    field.SetValue(info, replace);
                }

                // Serializes the property object and store it inside mod file
                var data = (byte[])_toBytes.Invoke(info, new object[0]);

                modFile.Files["Info"] = data;
            }
 public TileProcessor(TmodFileWrapper.ITmodFile modFile, ModuleDef modModule, GameCultures culture) : base(modFile, modModule, culture)
 {
 }
Esempio n. 11
0
 public static string GetPath(TmodFileWrapper.ITmodFile mod, Type processorType, string file)
 {
     return(Path.Combine(mod.Name, FolderMapper[processorType], file));
 }
Esempio n. 12
0
 private object LoadRaw(TmodFileWrapper.ITmodFile modFile)
 {
     return(_readBuildFile.Invoke(null, new[] { modFile.Instance }));
 }