/// <inheritdoc /> public override void Run(MappingDatabase mappingDatabase) { if (Args == null) { PrintErrorUsage(); return; } var mappingSource = InteractiveMapper.GetSelectedMappingSource(); if (mappingSource == null) { return; } var mappings = mappingSource.Search(Args); foreach (var mapping in mappings) { if (mapping.ParentOfficialName != null) { var parentMapping = mappingSource.GetClassByObf(mapping.ParentOfficialName); Lumberjack.Log($"{mapping.GetMappingString()} (child of {parentMapping.GetMappingString()})"); } else { Lumberjack.Log($"{mapping.GetMappingString()}"); } } }
public static void Run() { // Load local mapping database Lumberjack.Log("Loading mapping database..."); _mappingDatabase = new MappingDatabase(Path.Combine(Program.BaseDirConfig, "mappings.db")); var assy = Assembly.GetExecutingAssembly().GetName(); Lumberjack.Info("Fabric Lightweight Obfuscation Remapping Assistant (FLORA)"); Lumberjack.Info($"Version {assy.Version} - parzivail"); Lumberjack.Info($"Source, issues and discussion: {"https://github.com/Parzivail-Modding-Team/FLORA".Pastel(Color.RoyalBlue)}"); Lumberjack.Info("Interactive Mode - \"help\" for commands, \"exit\" to quit."); // Enter read-eval-print loop InteractiveCommand command; do { command = GetCommand(); if (command == null) { Lumberjack.Error("Unknown command"); } else { command.Run(_mappingDatabase); } } while (!(command is ExitCommand)); }
/// <inheritdoc /> public override void Run(MappingDatabase mappingDatabase) { if (Args == null) { PrintErrorUsage(); return; } if (Args.EndsWith(".tiny")) { if (!File.Exists(Args)) { Lumberjack.Error($"Mapping file \"{Args}\" could not be found!"); return; } mappingDatabase.UseLocalFile(Args); Lumberjack.Log($"Using mappings from \"{Args}\""); } else { LoadRemoteMappings(mappingDatabase, Args); } }
protected void Log(string msg) { msg = msg.Trim(); if (msg.Length > 0) { Lumberjack.Log(msg, ConsoleColor.DarkYellow, OutputLevel.Debug, "GLSL"); } }
/// <inheritdoc /> public override void PrintAdvancedHelp() { Lumberjack.Log(GetCommandDescription().Usage); Lumberjack.Log(""); Lumberjack.Log("The mapjar command is used to convert the intermediary mappings in all of the Java"); Lumberjack.Log("files in a given jar/zip archive to their named counterparts. The input file must be"); Lumberjack.Log("a \"source\" jar or a decompiled zip (as produced by jd-gui, for example), where the"); Lumberjack.Log("contents are Java files and not class files. All of the contents of the jar will be"); Lumberjack.Log("copied to the output directory, even if they were not modified by the mapping"); Lumberjack.Log("procedure. If no output directory is specified, a directory based on the input filename"); Lumberjack.Log("is used."); }
/// <summary> /// Check if the mapping for the regex match is valid /// </summary> /// <param name="mapping">The class, field or method mapping from the database</param> /// <param name="match">The regex match for the keyword</param> /// <param name="failedMappings">The list to insert failed mappings into</param> /// <returns></returns> private static string CheckMatch(Mapping mapping, Capture match, List <string> failedMappings = null) { if (mapping != null) { Lumberjack.Log($"{match.Value}\t-> {mapping.GetMappingString()}"); return(mapping.MappedShortName); } Lumberjack.Warn($"{match.Value}\t-> ??? (No mapping)"); failedMappings?.Add(match.Value); return(match.Value); }
private static void LoadRemoteMappings(MappingDatabase mappingDatabase, string version) { Lumberjack.Log("Fetching mapping versions from remote..."); var yarnVersions = YarnUtil.GetYarnVersions(); if (yarnVersions == null) { // If we couldn't get them, try to use the ones we've already cached Lumberjack.Warn("Working in offline mode. Only local Yarn mappings will be available."); yarnVersions = mappingDatabase.GetYarnVersions(); } if (yarnVersions.All(mapping => mapping.Version != version)) { // If a specific mapping version was specified that doesn't exist in the version listing, fail Lumberjack.Error($"Could not find mapping version {version}!"); return; } var mappingVersion = yarnVersions.First(mapping => mapping.Version == version); if (!mappingDatabase.HasMappingSet(mappingVersion)) { // If we don't have those mappings cached, download them and cache them Lumberjack.Log("Fetching mappings from remote..."); var mappings = YarnUtil.GetYarnMappings(mappingVersion); if (mappings != null) { Lumberjack.Log("Updating database..."); mappingDatabase.CreateMappingSet(mappingVersion, mappings); } else { Lumberjack.Error($"Failed to load requested mappings {mappingVersion.Version}"); Environment.Exit((int)ExitConditions.MappingVersionNotFound); } } else { Lumberjack.Log("Local database contains required mappings."); } InteractiveMapper.SetYarnVersion(mappingVersion); Lumberjack.Log($"Using mappings from yarn {version}"); }
/// <inheritdoc /> public override void PrintAdvancedHelp() { Lumberjack.Log(GetCommandDescription().Usage); Lumberjack.Log(""); Lumberjack.Log("The mapsrc command is used to set which mappings are being used by the interactive"); Lumberjack.Log("environment. As a parameter, you can specify a Tiny v1 mapping file or a Yarn version"); Lumberjack.Log("string. If the latter is specified, the mappings will be saved to a local mapping"); Lumberjack.Log("database (mappings.db) for faster reuse of those mappings. If you do not have an"); Lumberjack.Log("internet connection, you are limited to using mappings in a provided Tiny v1 file or"); Lumberjack.Log("ones already cached in the database."); Lumberjack.Log(""); Lumberjack.Log("Examples:"); Lumberjack.Log(""); Lumberjack.Info("mapsrc 1.15.2+build.7"); Lumberjack.Info("mapsrc my_mappings.tiny"); }
/// <inheritdoc /> public override void PrintAdvancedHelp() { Lumberjack.Log(GetCommandDescription().Usage); Lumberjack.Log(""); Lumberjack.Log("The children command is useful to determine what methods, fields, and classes are"); Lumberjack.Log("defined explicitly as children of the given class. The class can be given in either"); Lumberjack.Log("the mapped form, the intermediate form, or the official/obfuscated form. For example:"); Lumberjack.Log(""); Lumberjack.Info("children MatrixStack"); Lumberjack.Info("children class_4587"); Lumberjack.Info("children cyl"); Lumberjack.Log(""); Lumberjack.Log("are all equivelant. The children listed will only be children that are explicitly"); Lumberjack.Log("defined in the target class. As such, fields, methods, and subclasses that are"); Lumberjack.Log("inherited from a superclass will not be shown unless they are overridden."); }
/// <inheritdoc /> public override void PrintAdvancedHelp() { Lumberjack.Log(GetCommandDescription().Usage); Lumberjack.Log(""); Lumberjack.Log("The search command is used to find the mappings associated with the given named,"); Lumberjack.Log("intermediary, or official/obfuscated mapping. Searching by official/obfuscated names"); Lumberjack.Log("is only available for classes, as all classes' fields and methods first obfuscated"); Lumberjack.Log("name is the same, and there's a good chance any given query will return thousands of"); Lumberjack.Log("results."); Lumberjack.Log(""); Lumberjack.Log("Examples:"); Lumberjack.Log(""); Lumberjack.Info("search CowEntity"); Lumberjack.Info("search class_1430"); Lumberjack.Info("search ath"); }
/// <inheritdoc /> public override void PrintAdvancedHelp() { Lumberjack.Log(GetCommandDescription().Usage); Lumberjack.Log(""); Lumberjack.Log("The yarnver command is used to determine the yarn versions that are applicable to"); Lumberjack.Log("the given game version. If no game version is provided, then all known yarn versions"); Lumberjack.Log("are shown, grouped by their applicable game version. Next to the Yarn version string,"); Lumberjack.Log("the maven ID is provided, and stable versions are denoted."); Lumberjack.Log(""); Lumberjack.Log("Examples:"); Lumberjack.Log(""); Lumberjack.Info("yarnver"); Lumberjack.Log("\tWill search all mappings"); Lumberjack.Info("yarnver 1.15"); Lumberjack.Log("\tWill search all mappings for 1.15.x"); Lumberjack.Info("yarnver 1.15.1"); Lumberjack.Log("\tWill search all mappings for 1.15.1"); }
/// <inheritdoc /> public override void Run(MappingDatabase mappingDatabase) { if (Args == null) { PrintErrorUsage(); return; } var mappingSource = InteractiveMapper.GetSelectedMappingSource(); if (mappingSource == null) { return; } var mapped = Mapper.MapString(mappingSource, Args); Lumberjack.Log("Mapped string:"); Lumberjack.Log($"\t{mapped}".Pastel(Color.White)); }
/// <inheritdoc /> public override void Run(MappingDatabase mappingDatabase) { if (Args == null) { PrintErrorUsage(); return; } var mappingSource = InteractiveMapper.GetSelectedMappingSource(); if (mappingSource == null) { return; } var mappings = mappingSource.GetChildren(Args); foreach (var mapping in mappings) { Lumberjack.Log(mapping.GetMappingString()); } }
/// <inheritdoc /> public override void Run(MappingDatabase mappingDatabase) { var versions = YarnUtil.GetYarnVersions(); if (Args != null) { versions = versions.Where(version => YarnUtil.DoVersionsMatch(version, Args)).ToArray(); } var groups = versions.GroupBy(version => version.GameVersion); foreach (var group in groups) { Lumberjack.Log(group.Key); Lumberjack.PushIndent(); foreach (var yarnVersion in group.OrderByDescending(version => version.Build)) { Lumberjack.Log(yarnVersion.ToColorfulString()); } Lumberjack.PopIndent(); } }
public bool LoadScript(string code) { var codeDomProvider = CodeDomProvider.CreateProvider("CSharp"); var compilerParameters = new CompilerParameters(); compilerParameters.ReferencedAssemblies.Add("system.dll"); compilerParameters.ReferencedAssemblies.Add("TerrainGenCore.dll"); compilerParameters.GenerateExecutable = false; compilerParameters.GenerateInMemory = true; var compilerResults = codeDomProvider.CompileAssemblyFromSource(compilerParameters, code); if (compilerResults.Errors.HasErrors) { var errorMessage = "Compilation failed.\r\n"; foreach (var error in compilerResults.Output) { errorMessage += error + "\r\n"; } Lumberjack.Error(errorMessage); return(false); } var compiledAssembly = compilerResults.CompiledAssembly; try { var types = compiledAssembly.DefinedTypes; foreach (var type in types) { if (type.FullName is null || !type.IsDefined(typeof(TerrainProviderAttribute))) { continue; } _generatorInstance = compiledAssembly.CreateInstance(type.FullName); Lumberjack.Log($"Creating instance of {type.FullName}"); break; } if (_generatorInstance is null) { Lumberjack.Log("No classes found in assembly with the TerrainProvider attribute"); return(false); } var typeInfo = _generatorInstance.GetType(); var methods = typeInfo.GetMethods(); foreach (var requiredMethod in RequiredMethods) { if (methods.All(method => method.Name != requiredMethod.Name)) { Lumberjack.Error($"Required method {requiredMethod.Name} not found in instantiated class"); return(false); } var foundMethod = typeInfo.GetMethod(requiredMethod.Name, requiredMethod.ParameterTypes); if (foundMethod is null) { Lumberjack.Error($"Required method {requiredMethod.Name} does not have required signature {string.Join(", ", requiredMethod.ParameterTypes.Select(type => type.Name))}"); return(false); } if (foundMethod.ReturnType != requiredMethod.ReturnType) { Lumberjack.Error($"Required method {requiredMethod.Name} does not have required return type {requiredMethod.ReturnType.Name}"); return(false); } } _methodGetValue = typeInfo.GetMethod("GetTerrain"); _methodGetWaterLevel = typeInfo.GetMethod("GetWaterLevel"); } catch (Exception e) { Lumberjack.Error(e.Message); return(false); } return(true); }
/// <summary> /// Iterates over the files in an archive and maps the intermediary names in the java files /// </summary> /// <param name="mappingSource">The mapping provider</param> /// <param name="srcArchive">The archive to iterate through</param> /// <param name="destDir">The destination for the mapped files</param> public static void MapArchive(IMappingSource mappingSource, string srcArchive, string destDir) { // Keep the failed mappings to create a report at the end var failedMappings = new List <string>(); destDir = Path.Combine(Program.BaseDirOutput, destDir); using (var srcZip = ZipFile.OpenRead(srcArchive)) { foreach (var srcEntry in srcZip.Entries) { // Directories are entries too, skip them if (srcEntry.FullName.EndsWith("/")) { continue; } var destFile = $"{destDir}/{srcEntry.FullName}"; var fileDir = Path.GetDirectoryName(destFile); Debug.Assert(fileDir != null); // Make sure the output directory structure exists Directory.CreateDirectory(fileDir); if (Path.GetExtension(srcEntry.Name) == ".java") { // Read and map java files Lumberjack.Log(srcEntry.FullName); string file; using (var reader = new StreamReader(srcEntry.Open())) file = reader.ReadToEnd(); Lumberjack.PushIndent(); var mappedContents = MapString(mappingSource, file, failedMappings); File.WriteAllBytes(destFile, Encoding.UTF8.GetBytes((string)mappedContents)); Lumberjack.PopIndent(); } else { // Copy all files directly that aren't java files using (var reader = srcEntry.Open()) using (var writer = File.Open(destFile, FileMode.Create)) reader.CopyTo(writer); } } } // Report all of the failed mappings if (failedMappings.Count > 0) { Lumberjack.Warn("Failed mappings:"); Lumberjack.PushIndent(); Lumberjack.PushCategory("Failed"); foreach (var failedMapping in failedMappings) { Lumberjack.Warn(failedMapping); } Lumberjack.PopCategory(); Lumberjack.PopIndent(); } else { Lumberjack.Log("No failed mappings"); } }
public static void PrintHelp(InteractiveCommandDescAttribute commandDescription) { Lumberjack.Info(commandDescription.Usage); Lumberjack.Log($"\t{commandDescription.QuickHelp}"); }