/// <summary> /// Add data before game data loads /// </summary> /// <param name="proto">要添加的Proto</param> public static void PreAddProto(Proto proto) { int index = ProtoIndex.GetIndex(proto.GetType()); if (!PreToAdd[index].Contains(proto)) { if (proto is StringProto) { int id = FindAvailableStringID(); proto.ID = id; } Bind(proto); PreToAdd[index].Add(proto); TotalDict[index].Add(proto); } }
/// <summary> /// Check if string with id was already registered /// </summary> /// <param name="id">ID</param> private static bool HasStringIdRegisted(int id) { if (LDB.strings.dataIndices.ContainsKey(id)) { return(true); } if (PreToAdd[ProtoIndex.GetIndex(typeof(StringProto))].Any(proto => proto.ID == id)) { return(true); } if (PostToAdd[ProtoIndex.GetIndex(typeof(StringProto))].Any(proto => proto.ID == id)) { return(true); } return(false); }
void Awake() { logger = Logger; ProtoIndex.InitIndex(); LDBTool.Init(); ShowProto = Config.Bind("config", "ShowProto", false, "是否开启数据显示"); ShowProtoHotKey = Config.Bind("config", "ShowProtoHotKey", KeyCode.F5, "呼出界面的快捷键"); ShowItemProtoHotKey = Config.Bind("config", "ShowItemProtoHotKey", KeyCode.I, "显示物品的Proto"); ShowRecipeProtoHotKey = Config.Bind("config", "ShowRecipeProtoHotKey", KeyCode.R, "显示配方的Proto"); Harmony harmony = new Harmony(MODGUID); harmony.PatchAll(Assembly.GetExecutingAssembly()); logger.LogInfo("LDBTool is loaded successfully!"); }
/// <summary> /// Add all Protos in datas to corresponding proto sets /// </summary> /// <param name="datas">List of List of Protos.</param> internal static void AddProtos(List <List <Proto> > datas) { Type[] protoTypes = ProtoIndex.GetAllProtoTypes(); for (int i = 0; i < protoTypes.Length; i++) { Type protoType = protoTypes[i]; PropertyInfo protoProperty = typeof(LDB).GetProperties().First(property => { Type setType = typeof(ProtoSet <>).MakeGenericType(protoType); return(setType.IsAssignableFrom(property.PropertyType)); }); MethodInfo genericMethod = typeof(LDBTool).GetMethod(nameof(AddProtosToSet), AccessTools.all); MethodInfo method = genericMethod.MakeGenericMethod(protoType); object protoSet = protoProperty.GetValue(null); method.Invoke(null, new[] { protoSet, datas[i] }); } }
internal static void Init() { Type configFile = AccessTools.TypeByName("BepInEx.Configuration.ConfigFile"); OrphanedEntriesProp = configFile.GetProperty("OrphanedEntries", AccessTools.all); for (int i = 0; i <= ProtoIndex.GetProtosCount(); i++) { PreToAdd.Add(new List <Proto>()); PostToAdd.Add(new List <Proto>()); TotalDict.Add(new List <Proto>()); IDDict.Add(new Dictionary <string, ConfigEntry <int> >()); GridIndexDict.Add(new Dictionary <string, ConfigEntry <int> >()); } UpdateCustomDataFile(CustomGridIndex); UpdateCustomDataFile(CustomStringENUS); UpdateCustomDataFile(CustomStringZHCN); UpdateCustomDataFile(CustomStringFRFR); }
/// <summary> /// Bind the ID through the configuration file, allowing players to customize the ID in the event of conflict /// </summary> private static void IdBind(Proto proto) { if (proto is StringProto) { return; } int index = ProtoIndex.GetIndex(proto); var entry = CustomID.Bind(ProtoIndex.GetProtoName(proto), proto.Name, proto.ID); proto.ID = entry.Value; if (IDDict[index].ContainsKey(proto.Name)) { LDBToolPlugin.logger.LogError($"[CustomID] ID:{proto.ID} Name:{proto.Name} There is a conflict, please check."); } else { IDDict[index].Add(proto.Name, entry); } }
/// <summary> /// Bind GridIndex through the configuration file, allowing players to customize GridIndex in the event of conflict /// Execute after custom ID /// </summary> private static void GridIndexBind(Proto proto) { ConfigEntry <int> entry = null; if (proto is ItemProto item) { entry = CustomGridIndex.Bind(ProtoIndex.GetProtoName(proto), item.ID.ToString(), 0, $"Default Grid Index = {item.GridIndex}\nItem Name = {item.Name}"); if (entry.Value != 0) { item.GridIndex = entry.Value; } } else if (proto is RecipeProto recipe) { entry = CustomGridIndex.Bind(ProtoIndex.GetProtoName(proto), recipe.ID.ToString(), 0, $"Default Grid Index = {recipe.GridIndex}\nRecipe Name = {recipe.Name}"); if (entry.Value != 0) { recipe.GridIndex = entry.Value; } } if (entry == null) { return; } int index = ProtoIndex.GetIndex(proto); if (GridIndexDict[index].ContainsKey(proto.Name)) { LDBToolPlugin.logger.LogError($"[CustomGridIndex] ID:{proto.ID} Name:{proto.Name} There is a conflict, please check."); } else { GridIndexDict[index].Add(proto.Name, entry); } }