public static void Inject(string addon_target, D2Library library) { var lines = File.ReadAllLines("LibraryInjections.txt"); var list_lines = lines.ToList(); list_lines.Add(""); lines = list_lines.ToArray<string>(); var start_line = -1; for (int i = 0; i < lines.Length; i++) { if (lines[i].StartsWith(library.FullyQualifiedName + ":")) { start_line = i; break; } } if (start_line >= 0) { var end_line = -1; for (int i = start_line; i < lines.Length; i++) { var trimmed_line = lines[i].Trim().Replace("\n", "").Replace("\t", "").Replace("\r", ""); if (trimmed_line.Length == 0) { end_line = i; break; } } File.AppendAllText(addon_target, "-- INJECTED CODE FROM \"" + library.FullyQualifiedName + "\"\n"); File.AppendAllLines(addon_target, lines.SubArray<string>(start_line + 1, end_line - start_line - 1)); File.AppendAllText(addon_target, "-- ENDINJECTION"); } }
public static void ReloadLibraries() { string keypath = @"Software\Valve\Steam"; RegistryKey key = Registry.CurrentUser.OpenSubKey(keypath); string registeredFilePath = key.GetValue("SteamPath").ToString(); D2PackageManagerMainForm.AddonContentFolder = registeredFilePath + "\\steamapps\\common\\dota 2 beta\\content\\dota_addons"; D2PackageManagerMainForm.AddonGameFolder = registeredFilePath + "\\steamapps\\common\\dota 2 beta\\game\\dota_addons"; var libraries = File.ReadAllLines("LibraryLocationsIndex.txt"); for (int i = 0; i < libraries.Length; i++) { var library_text = libraries[i]; var library = new D2Library(); D2Libraries.Add(library); library.Author = library_text.Split(',')[0].Split('/')[0]; library.Name = library_text.Split(',')[0].Split('/')[1]; library.Branch = library_text.Split(',')[1].Split(':')[0]; var library_info = library_text.Split('[', ']')[1]; var library_info_split = library_info.Split(','); for (int j = 0; j < library_info_split.Length; j++) { var library_info_key = library_info_split[j].Split(':')[0]; var library_info_value = library_info_split[j].Split(':')[1]; if (library_info_key.StartsWith("remap_")) { var remap_variable_name = library_info_key.Replace("remap_", ""); var remap_variable = (RemapKey)System.Enum.Parse(typeof(RemapKey), remap_variable_name); library.Remaps.Add(remap_variable, library_info_value); } if (library_info_key == "modtype" && library_info_value == "library") { library.ModType = ModType.Library; } if (library_info_key == "modtype" && library_info_value == "lua_scripts") { library.ModType = ModType.LuaScripts; } } } }