private void SetHeaderInfo(ClrAssemblyInput input, PapyrusAssemblyDefinition pex, TypeDefinition type) { pex.Header.HeaderIdentifier = input.TargetPapyrusVersion == PapyrusVersionTargets.Fallout4 ? PapyrusHeader.Fallout4PapyrusHeaderIdentifier : PapyrusHeader.SkyrimPapyrusHeaderIdentifier; pex.Header.SourceHeader.Version = input.TargetPapyrusVersion == PapyrusVersionTargets.Fallout4 ? PapyrusHeader.Fallout4PapyrusVersion : PapyrusHeader.SkyrimPapyrusVersion; pex.Header.SourceHeader.Source = "PapyrusDotNet" + type.Name + ".psc"; pex.Header.SourceHeader.User = Environment.UserName; pex.Header.SourceHeader.Computer = Environment.MachineName; pex.Header.SourceHeader.GameId = (short)input.TargetPapyrusVersion; pex.Header.SourceHeader.CompileTime = UnixTimeConverterUtility.Convert(DateTime.Now); pex.Header.SourceHeader.ModifyTime = UnixTimeConverterUtility.Convert(DateTime.Now); }
/// <summary> /// Converts the assembly. /// </summary> /// <param name="input">The input.</param> /// <returns></returns> protected override PapyrusAssemblyOutput ConvertAssembly(ClrAssemblyInput input) { var clr = input.Assembly; var mainModule = clr.MainModule; papyrusAssemblies.Clear(); propertyMethods = new List <MethodDefinition>(); var papyrusAssemblyToTypeDefinition = new Dictionary <PapyrusAssemblyDefinition, TypeDefinition>(); // Keep track on the enum types so we can verify any parameter, variables, etc, and change the type into integers. ResolveEnumDefinitions(mainModule); foreach (var type in mainModule.Types) { try { // We will skip this one for now // as it will not really provide us with any necessary information at this early stage. if (type.Name == "<Module>") { continue; } // Find all delegate types and methods and create references to them. delegatePairDefinition = delegateFinder.FindDelegateTypes(type); activeClrType = type; var pex = PapyrusAssemblyDefinition.CreateAssembly(input.TargetPapyrusVersion); SetHeaderInfo(input, pex, type); CreateType(pex, type, processorOptions); papyrusAssemblies.Add(pex); papyrusAssemblyToTypeDefinition.Add(pex, type); // After the type has been processed // we will create the methods and then create the debug info as we do not have any info regarding the methods until those have been created ;-) foreach (var t in pex.Types) { var firstState = t.States.FirstOrDefault(); if (firstState == null) { continue; // no state was found?? } CreateMethods(papyrusAssemblies, type, t, pex, processorOptions) .ForEach(firstState.Methods.Add); CreateDebugInfo(pex, t, type); } } catch (ProhibitedCodingBehaviourException exc) { userInterface.DrawError($"Error processing '{type.FullName}': Prohibited use of " + exc.OpCode.GetValueOrDefault().Code + " in " + exc.Method.FullName + " at " + exc.Offset); } catch (Exception exc) { userInterface.DrawError($"Error processing '{type.FullName}': Unhandled Exception - " + exc); } } return(new PapyrusAssemblyOutput(papyrusAssemblies.ToArray())); }
protected abstract PapyrusAssemblyOutput ConvertAssembly(ClrAssemblyInput input);
public int Run() { IAssemblyConverter converter; IAssemblyInput inputData; if (args.Length < 2) { // ui.WriteLine(" Missing Important Arguments."); ui.DrawHelp(); return(128); } ui.Clear(); ui.DrawInterface("Magic is about to happen!"); var clr2Papyrus = !Enumerable.Contains(args, "-clr"); var input = args[0]; if (args.Contains("-i")) { input = args[Array.IndexOf(args, "-i") + 1]; } var output = args[1]; if (args.Contains("-o")) { output = args[Array.IndexOf(args, "-o") + 1]; } var autoClose = args.Contains("x") || args.Contains("X") || args.Contains("-x") || args.Contains("-X"); if (clr2Papyrus) { var targetVersion = Enumerable.Contains(args, "-skyrim") ? PapyrusVersionTargets.Skyrim : PapyrusVersionTargets.Fallout4; var compilerOptions = !Enumerable.Contains(args, "-easy") ? PapyrusCompilerOptions.Strict : PapyrusCompilerOptions.Easy; var readerParameters = new ReaderParameters { ReadSymbols = true }; converter = new Clr2PapyrusConverter(ui, instructorProcessor, compilerOptions); var assemblyDefinition = AssemblyDefinition.ReadAssembly(input, readerParameters); assemblyDefinition.MainModule.ReadSymbols(); inputData = new ClrAssemblyInput(assemblyDefinition, targetVersion); } else { var nsResolver = new NamespaceResolver(); //var camelCaseResolver = new PascalCaseNameResolver(ui, "wordlist-fo4.txt"); // Papyrus2ClrCecilConverter converter = new Papyrus2ClrCecilConverter( ui, nameResolver, nsResolver, new TypeReferenceResolver(nsResolver, new TypeNameResolver(nameResolver))); var pexFiles = Directory.GetFiles(input, "*.pex", SearchOption.AllDirectories); ui.DrawInterface("(1/3) Reading Papyrus Assemblies."); var papyrusAssemblyDefinitions = pexFiles.Select(f => ReadPapyrusAssembly(f, pexFiles.Length)).ToArray(); inputData = new PapyrusAssemblyInput( papyrusAssemblyDefinitions ); } var outputData = converter.Convert(inputData); if (outputData != null) { outputData.Save(output); // Do something... } if (autoClose) { return(0); } while (true) { var openTargetDir = new Hotkeys("Open target directory", ConsoleKey.A, () => { Process.Start(output); }); var exit = new Hotkeys("Exit", ConsoleKey.X, () => { }); ui.DrawHotkeys(openTargetDir, exit); var posx = Console.CursorLeft; var k = Console.ReadKey(); Console.CursorLeft = posx; Console.Write(" "); if (k.Key == exit.Key) { return(0); } if (k.Key == openTargetDir.Key) { openTargetDir.Action(); } } }