public static string AdjustedForKeys(this string text, List <string> outErrors = null, bool resolveKeys = true) { outErrors?.Clear(); if (text.NullOrEmpty()) { return(text); } int num = 0; while (true) { num++; if (num > 500000) { Log.Error("Too many iterations."); outErrors?.Add("The parsed string caused an infinite loop"); break; } int num2 = text.IndexOf("{Key:"); if (num2 < 0) { break; } int num3 = num2; while (text[num3] != '}') { num3++; if (num3 >= text.Length) { outErrors?.Add("Mismatched braces"); return(text); } } string text2 = text.Substring(num2 + 5, num3 - (num2 + 5)); KeyBindingDef namedSilentFail = DefDatabase <KeyBindingDef> .GetNamedSilentFail(text2); string str = text.Substring(0, num2); if (namedSilentFail != null) { str = ((!resolveKeys) ? (str + "placeholder") : (str + namedSilentFail.MainKeyLabel)); } else { str += "error"; if (outErrors != null) { string text3 = "Could not find key '" + text2 + "'"; string text4 = BackCompatibility.BackCompatibleDefName(typeof(KeyBindingDef), text2); if (text4 != text2) { text3 = text3 + " (hint: it was renamed to '" + text4 + "')"; } outErrors.Add(text3); } } str += text.Substring(num3 + 1); text = str; } return(text); }
public void InjectIntoDefs() { foreach (KeyValuePair <string, string> current in this.injections) { string[] array = current.Key.Split(new char[] { '.' }); string text = array[0]; text = BackCompatibility.BackCompatibleDefName(this.defType, text); if (GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), this.defType, "GetNamedSilentFail", new object[] { text }) == null) { Log.Warning(string.Concat(new object[] { "Def-linked translation error: Found no ", this.defType, " named ", text, " to match ", current.Key })); } else { this.SetDefFieldAtPath(this.defType, current.Key, current.Value); } } GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), this.defType, "ClearCachedData"); }
private static TDef TryFindDef <TDef>(XmlNode node, string defNodeName) where TDef : Def, new() { XmlElement xmlElement = node[defNodeName]; if (xmlElement == null) { return(null); } return(DefDatabase <TDef> .GetNamedSilentFail(BackCompatibility.BackCompatibleDefName(typeof(TDef), xmlElement.InnerText))); }
private void TryAddInjection(FileInfo file, string key, string translation) { string[] array = key.Split('.'); array[0] = BackCompatibility.BackCompatibleDefName(this.defType, array[0]); key = string.Join(".", array); if (!this.HasError(file, key)) { this.injections.Add(key, translation); } }
private string BackCompatibleKey(string key) { string[] array = key.Split('.'); if (array.Any()) { array[0] = BackCompatibility.BackCompatibleDefName(defType, array[0], forDefInjections: true); } key = string.Join(".", array); if (defType == typeof(ConceptDef) && key.Contains(".helpTexts.0")) { key = key.Replace(".helpTexts.0", ".helpText"); } return(key); }
public static T DefFromNode <T>(XmlNode subNode) where T : Def, new() { if (subNode != null && subNode.InnerText != null && !(subNode.InnerText == "null")) { string defName = BackCompatibility.BackCompatibleDefName(typeof(T), subNode.InnerText); T namedSilentFail = DefDatabase <T> .GetNamedSilentFail(defName); if (namedSilentFail == null) { Log.Error("Could not load reference to " + typeof(T) + " named " + subNode.InnerText); } return(namedSilentFail); } return((T)null); }
private string BackCompatibleKey(string key) { string[] array = key.Split(new char[] { '.' }); if (array.Any <string>()) { array[0] = BackCompatibility.BackCompatibleDefName(this.defType, array[0], true); } key = string.Join(".", array); if (this.defType == typeof(ConceptDef) && key.Contains(".helpTexts.0")) { key = key.Replace(".helpTexts.0", ".helpText"); } return(key); }
public void InjectIntoDefs() { foreach (KeyValuePair <string, string> injection in this.injections) { string[] array = injection.Key.Split('.'); string defName = array[0]; defName = BackCompatibility.BackCompatibleDefName(this.defType, defName); object obj = GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), this.defType, "GetNamedSilentFail", defName); if (obj == null) { Log.Warning("Def-linked translation error: Found no " + this.defType + " named " + defName + " to match " + injection.Key); } else { this.SetDefFieldAtPath(this.defType, injection.Key, injection.Value); } } GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), this.defType, "ClearCachedData"); }
public static T DefFromNode <T>(XmlNode subNode) where T : Def, new() { T result; if (subNode == null || subNode.InnerText == null || subNode.InnerText == "null") { result = (T)((object)null); } else { string text = BackCompatibility.BackCompatibleDefName(typeof(T), subNode.InnerText, false); T namedSilentFail = DefDatabase <T> .GetNamedSilentFail(text); if (namedSilentFail == null) { if (text == subNode.InnerText) { Log.Error(string.Concat(new object[] { "Could not load reference to ", typeof(T), " named ", subNode.InnerText }), false); } else { Log.Error(string.Concat(new object[] { "Could not load reference to ", typeof(T), " named ", subNode.InnerText, " after compatibility-conversion to ", text }), false); } } result = namedSilentFail; } return(result); }
public static T DefFromNode <T>(XmlNode subNode) where T : Def, new() { if (subNode == null || subNode.InnerText == null || subNode.InnerText == "null") { return((T)((object)null)); } string defName = BackCompatibility.BackCompatibleDefName(typeof(T), subNode.InnerText); T namedSilentFail = DefDatabase <T> .GetNamedSilentFail(defName); if (namedSilentFail == null) { Log.Error(string.Concat(new object[] { "Could not load reference to ", typeof(T), " named ", subNode.InnerText })); } return(namedSilentFail); }
public static T DefFromNode <T>(XmlNode subNode) where T : Def, new() { if (subNode == null || subNode.InnerText == null || subNode.InnerText == "null") { return((T)null); } string text = BackCompatibility.BackCompatibleDefName(typeof(T), subNode.InnerText); T namedSilentFail = DefDatabase <T> .GetNamedSilentFail(text); if (namedSilentFail == null) { if (text == subNode.InnerText) { Log.Error("Could not load reference to " + typeof(T) + " named " + subNode.InnerText); } else { Log.Error("Could not load reference to " + typeof(T) + " named " + subNode.InnerText + " after compatibility-conversion to " + text); } } return(namedSilentFail); }
public static T DefFromNode <T>(XmlNode subNode) where T : Def, new() { if (subNode == null || subNode.InnerText == null || subNode.InnerText == "null") { return(null); } string text = BackCompatibility.BackCompatibleDefName(typeof(T), subNode.InnerText, forDefInjections: false, subNode); T namedSilentFail = DefDatabase <T> .GetNamedSilentFail(text); if (namedSilentFail == null && !BackCompatibility.WasDefRemoved(subNode.InnerText, typeof(T))) { if (text == subNode.InnerText) { Log.Error(string.Concat("Could not load reference to ", typeof(T), " named ", subNode.InnerText)); } else { Log.Error(string.Concat("Could not load reference to ", typeof(T), " named ", subNode.InnerText, " after compatibility-conversion to ", text)); } BackCompatibility.PostCouldntLoadDef(subNode.InnerText); } return(namedSilentFail); }
private bool SetDefFieldAtPath(Type defType, string path, object value, Type ensureFieldType, bool errorOnDefNotFound, string fileSource, bool isPlaceholder, out string normalizedPath, out string suggestedPath, out string replacedString, out IEnumerable <string> replacedStringsList) { replacedString = null; replacedStringsList = null; normalizedPath = path; suggestedPath = path; string text = path.Split(new char[] { '.' })[0]; text = BackCompatibility.BackCompatibleDefName(defType, text, true); if (GenDefDatabase.GetDefSilentFail(defType, text, false) == null) { if (errorOnDefNotFound) { this.loadErrors.Add(string.Concat(new object[] { "Found no ", defType, " named ", text, " to match ", path, " (", fileSource, ")" })); } return(false); } bool flag = false; int num = 0; bool result; try { List <string> list = path.Split(new char[] { '.' }).ToList <string>(); object obj = GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), defType, "GetNamedSilentFail", new object[] { list[0] }); if (obj == null) { throw new InvalidOperationException("Def named " + list[0] + " not found."); } list.RemoveAt(0); num++; string text2; int num2; DefInjectionPathPartKind defInjectionPathPartKind; FieldInfo field; int num3; int num4; while (true) { text2 = list[0]; num2 = -1; if (int.TryParse(text2, out num2)) { defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex; } else if (this.GetFieldNamed(obj.GetType(), text2) != null) { defInjectionPathPartKind = DefInjectionPathPartKind.Field; } else if (obj.GetType().GetProperty("Count") != null) { if (text2.Contains('-')) { defInjectionPathPartKind = DefInjectionPathPartKind.ListHandleWithIndex; string[] array = text2.Split(new char[] { '-' }); text2 = array[0]; num2 = (int)ParseHelper.FromString(array[1], typeof(int)); } else { defInjectionPathPartKind = DefInjectionPathPartKind.ListHandle; } } else { defInjectionPathPartKind = DefInjectionPathPartKind.Field; } if (list.Count == 1) { break; } if (defInjectionPathPartKind == DefInjectionPathPartKind.Field) { field = obj.GetType().GetField(text2, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { goto Block_41; } if (field.HasAttribute <NoTranslateAttribute>()) { goto Block_42; } if (field.HasAttribute <UnsavedAttribute>()) { goto Block_43; } if (field.HasAttribute <TranslationCanChangeCountAttribute>()) { flag = true; } if (defInjectionPathPartKind == DefInjectionPathPartKind.Field) { obj = field.GetValue(obj); } else { object value2 = field.GetValue(obj); PropertyInfo property = value2.GetType().GetProperty("Item"); if (property == null) { goto Block_46; } num3 = (int)value2.GetType().GetProperty("Count").GetValue(value2, null); if (num2 < 0 || num2 >= num3) { goto IL_ADC; } obj = property.GetValue(value2, new object[] { num2 }); } } else if (defInjectionPathPartKind == DefInjectionPathPartKind.ListIndex || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandle || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandleWithIndex) { object obj2 = obj; PropertyInfo property2 = obj2.GetType().GetProperty("Item"); if (property2 == null) { goto Block_50; } bool flag2; if (defInjectionPathPartKind == DefInjectionPathPartKind.ListHandle || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandleWithIndex) { num2 = TranslationHandleUtility.GetElementIndexByHandle(obj2, text2, num2); defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex; flag2 = true; } else { flag2 = false; } num4 = (int)obj2.GetType().GetProperty("Count").GetValue(obj2, null); if (num2 < 0 || num2 >= num4) { goto IL_BB7; } obj = property2.GetValue(obj2, new object[] { num2 }); if (flag2) { string[] array2 = normalizedPath.Split(new char[] { '.' }); array2[num] = num2.ToString(); normalizedPath = string.Join(".", array2); } else { string bestHandleWithIndexForListElement = TranslationHandleUtility.GetBestHandleWithIndexForListElement(obj2, obj); if (!bestHandleWithIndexForListElement.NullOrEmpty()) { string[] array3 = suggestedPath.Split(new char[] { '.' }); array3[num] = bestHandleWithIndexForListElement; suggestedPath = string.Join(".", array3); } } } else { this.loadErrors.Add(string.Concat(new object[] { "Can't enter node ", text2, " at path ", path, ", element kind is ", defInjectionPathPartKind, ". (", fileSource, ")" })); } list.RemoveAt(0); num++; } bool flag3 = false; foreach (KeyValuePair <string, DefInjectionPackage.DefInjection> current in this.injections) { if (!(current.Key == path)) { if (current.Value.injected && current.Value.normalizedPath == normalizedPath) { string text3 = string.Concat(new string[] { "Duplicate def-injected translation key. Both ", current.Value.path, " and ", path, " refer to the same field (", suggestedPath, ")" }); if (current.Value.path != current.Value.nonBackCompatiblePath) { string text4 = text3; text3 = string.Concat(new string[] { text4, " (", current.Value.nonBackCompatiblePath, " was auto-renamed to ", current.Value.path, ")" }); } text3 = text3 + " (" + current.Value.fileSource + ")"; this.loadErrors.Add(text3); flag3 = true; break; } } } bool flag4 = false; if (!flag3) { if (defInjectionPathPartKind == DefInjectionPathPartKind.Field) { FieldInfo fieldNamed = this.GetFieldNamed(obj.GetType(), text2); if (fieldNamed == null) { throw new InvalidOperationException(string.Concat(new object[] { "Field ", text2, " does not exist in type ", obj.GetType(), "." })); } if (fieldNamed.HasAttribute <NoTranslateAttribute>()) { this.loadErrors.Add(string.Concat(new object[] { "Translated untranslatable field ", fieldNamed.Name, " of type ", fieldNamed.FieldType, " at path ", path, ". Translating this field will break the game. (", fileSource, ")" })); } else if (fieldNamed.HasAttribute <UnsavedAttribute>()) { this.loadErrors.Add(string.Concat(new object[] { "Translated untranslatable field (UnsavedAttribute) ", fieldNamed.Name, " of type ", fieldNamed.FieldType, " at path ", path, ". Translating this field will break the game. (", fileSource, ")" })); } else if (!isPlaceholder && fieldNamed.FieldType != ensureFieldType) { this.loadErrors.Add(string.Concat(new object[] { "Translated non-", ensureFieldType, " field ", fieldNamed.Name, " of type ", fieldNamed.FieldType, " at path ", path, ". Expected ", ensureFieldType, ". (", fileSource, ")" })); } else if (!isPlaceholder && ensureFieldType != typeof(string) && !fieldNamed.HasAttribute <TranslationCanChangeCountAttribute>()) { this.loadErrors.Add(string.Concat(new object[] { "Tried to translate field ", fieldNamed.Name, " of type ", fieldNamed.FieldType, " at path ", path, ", but this field doesn't have [TranslationCanChangeCount] attribute so it doesn't allow this type of translation. (", fileSource, ")" })); } else if (!isPlaceholder) { if (ensureFieldType == typeof(string)) { replacedString = (string)fieldNamed.GetValue(obj); } else { replacedStringsList = (fieldNamed.GetValue(obj) as IEnumerable <string>); } fieldNamed.SetValue(obj, value); flag4 = true; } } else if (defInjectionPathPartKind == DefInjectionPathPartKind.ListIndex || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandle || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandleWithIndex) { object obj3 = obj; if (obj3 == null) { throw new InvalidOperationException("Tried to use index on null list at " + path); } Type type = obj3.GetType(); PropertyInfo property3 = type.GetProperty("Count"); if (property3 == null) { throw new InvalidOperationException("Tried to use index on non-list (missing 'Count' property)."); } if (defInjectionPathPartKind == DefInjectionPathPartKind.ListHandle || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandleWithIndex) { num2 = TranslationHandleUtility.GetElementIndexByHandle(obj3, text2, num2); defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex; } int num5 = (int)property3.GetValue(obj3, null); if (num2 >= num5) { throw new InvalidOperationException(string.Concat(new object[] { "Trying to translate ", defType, ".", path, " at index ", num2, " but the list only has ", num5, " entries (so max index is ", (num5 - 1).ToString(), ")." })); } PropertyInfo property4 = type.GetProperty("Item"); if (property4 == null) { throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property)."); } Type propertyType = property4.PropertyType; if (!isPlaceholder && propertyType != ensureFieldType) { this.loadErrors.Add(string.Concat(new object[] { "Translated non-", ensureFieldType, " list item of type ", propertyType, " at path ", path, ". Expected ", ensureFieldType, ". (", fileSource, ")" })); } else if (!isPlaceholder && ensureFieldType != typeof(string) && !flag) { this.loadErrors.Add(string.Concat(new object[] { "Tried to translate field of type ", propertyType, " at path ", path, ", but this field doesn't have [TranslationCanChangeCount] attribute so it doesn't allow this type of translation. (", fileSource, ")" })); } else if (num2 < 0 || num2 >= (int)type.GetProperty("Count").GetValue(obj3, null)) { this.loadErrors.Add("Index out of bounds (max index is " + ((int)type.GetProperty("Count").GetValue(obj3, null) - 1) + ")"); } else if (!isPlaceholder) { replacedString = (string)property4.GetValue(obj3, new object[] { num2 }); property4.SetValue(obj3, value, new object[] { num2 }); flag4 = true; } } else { this.loadErrors.Add(string.Concat(new object[] { "Translated ", text2, " at path ", path, " but it's not a field, it's ", defInjectionPathPartKind, ". (", fileSource, ")" })); } } if (path != suggestedPath) { IList <string> list2 = value as IList <string>; string text5; if (list2 != null) { text5 = list2.ToStringSafeEnumerable(); } else { text5 = value.ToString(); } this.loadSyntaxSuggestions.Add(string.Concat(new string[] { "Consider using ", suggestedPath, " instead of ", path, " for translation '", text5, "' (", fileSource, ")" })); } result = flag4; return(result); Block_41: throw new InvalidOperationException("Field " + text2 + " does not exist."); Block_42: throw new InvalidOperationException(string.Concat(new object[] { "Translated untranslatable field ", field.Name, " of type ", field.FieldType, " at path ", path, ". Translating this field will break the game." })); Block_43: throw new InvalidOperationException(string.Concat(new object[] { "Translated untranslatable field ([Unsaved] attribute) ", field.Name, " of type ", field.FieldType, " at path ", path, ". Translating this field will break the game." })); Block_46: throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property)."); IL_ADC: throw new InvalidOperationException("Index out of bounds (max index is " + (num3 - 1) + ")"); Block_50: throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property)."); IL_BB7: throw new InvalidOperationException("Index out of bounds (max index is " + (num4 - 1) + ")"); } catch (Exception ex) { string text6 = string.Concat(new object[] { "Couldn't inject ", path, " into ", defType, " (", fileSource, "): ", ex.Message }); if (ex.InnerException != null) { text6 = text6 + " -> " + ex.InnerException.Message; } this.loadErrors.Add(text6); result = false; } return(result); }
private bool SetDefFieldAtPath(Type defType, string path, object value, Type ensureFieldType, bool errorOnDefNotFound, string fileSource, bool isPlaceholder, out string normalizedPath, out string suggestedPath, out string replacedString, out IEnumerable <string> replacedStringsList) { replacedString = null; replacedStringsList = null; string b = path; string text = path; bool flag = TKeySystem.TryGetNormalizedPath(path, out normalizedPath); if (flag) { text = text + " (" + normalizedPath + ")"; suggestedPath = path; path = normalizedPath; } else { normalizedPath = path; suggestedPath = path; } string defName = path.Split('.')[0]; defName = BackCompatibility.BackCompatibleDefName(defType, defName, forDefInjections: true); if (GenDefDatabase.GetDefSilentFail(defType, defName, specialCaseForSoundDefs: false) == null) { if (errorOnDefNotFound) { loadErrors.Add("Found no " + defType + " named " + defName + " to match " + text + " (" + fileSource + ")"); } return(false); } bool flag2 = false; int num = 0; List <object> list = new List <object>(); try { List <string> list2 = path.Split('.').ToList(); object obj = GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), defType, "GetNamedSilentFail", list2[0]); if (obj == null) { throw new InvalidOperationException("Def named " + list2[0] + " not found."); } num++; string text2; int result; DefInjectionPathPartKind defInjectionPathPartKind; while (true) { text2 = list2[num]; list.Add(obj); result = -1; if (int.TryParse(text2, out result)) { defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex; } else if (GetFieldNamed(obj.GetType(), text2) != null) { defInjectionPathPartKind = DefInjectionPathPartKind.Field; } else if (obj.GetType().GetProperty("Count") != null) { if (text2.Contains('-')) { defInjectionPathPartKind = DefInjectionPathPartKind.ListHandleWithIndex; string[] array = text2.Split('-'); text2 = array[0]; result = ParseHelper.FromString <int>(array[1]); } else { defInjectionPathPartKind = DefInjectionPathPartKind.ListHandle; } } else { defInjectionPathPartKind = DefInjectionPathPartKind.Field; } if (num == list2.Count - 1) { break; } switch (defInjectionPathPartKind) { case DefInjectionPathPartKind.Field: { FieldInfo field = obj.GetType().GetField(text2, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { throw new InvalidOperationException("Field or TKey " + text2 + " does not exist."); } if (field.HasAttribute <NoTranslateAttribute>()) { throw new InvalidOperationException("Translated untranslatable field " + field.Name + " of type " + field.FieldType + " at path " + text + ". Translating this field will break the game."); } if (field.HasAttribute <UnsavedAttribute>()) { throw new InvalidOperationException("Translated untranslatable field ([Unsaved] attribute) " + field.Name + " of type " + field.FieldType + " at path " + text + ". Translating this field will break the game."); } if (field.HasAttribute <TranslationCanChangeCountAttribute>()) { flag2 = true; } if (defInjectionPathPartKind == DefInjectionPathPartKind.Field) { obj = field.GetValue(obj); } else { object value2 = field.GetValue(obj); PropertyInfo property2 = value2.GetType().GetProperty("Item"); if (property2 == null) { throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property)."); } int num3 = (int)value2.GetType().GetProperty("Count").GetValue(value2, null); if (result < 0 || result >= num3) { throw new InvalidOperationException("Index out of bounds (max index is " + (num3 - 1) + ")"); } obj = property2.GetValue(value2, new object[1] { result }); } break; } case DefInjectionPathPartKind.ListIndex: case DefInjectionPathPartKind.ListHandle: case DefInjectionPathPartKind.ListHandleWithIndex: { object obj2 = obj; PropertyInfo property = obj2.GetType().GetProperty("Item"); if (property == null) { throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property)."); } bool flag3; if (defInjectionPathPartKind == DefInjectionPathPartKind.ListHandle || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandleWithIndex) { result = TranslationHandleUtility.GetElementIndexByHandle(obj2, text2, result); defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex; flag3 = true; } else { flag3 = false; } int num2 = (int)obj2.GetType().GetProperty("Count").GetValue(obj2, null); if (result < 0 || result >= num2) { throw new InvalidOperationException("Index out of bounds (max index is " + (num2 - 1) + ")"); } obj = property.GetValue(obj2, new object[1] { result }); if (flag3) { string[] array2 = normalizedPath.Split('.'); array2[num] = result.ToString(); normalizedPath = string.Join(".", array2); } else if (!flag) { string bestHandleWithIndexForListElement = TranslationHandleUtility.GetBestHandleWithIndexForListElement(obj2, obj); if (!bestHandleWithIndexForListElement.NullOrEmpty()) { string[] array3 = suggestedPath.Split('.'); array3[num] = bestHandleWithIndexForListElement; suggestedPath = string.Join(".", array3); } } break; } default: loadErrors.Add("Can't enter node " + text2 + " at path " + text + ", element kind is " + defInjectionPathPartKind + ". (" + fileSource + ")"); break; } num++; } bool flag4 = false; foreach (KeyValuePair <string, DefInjection> injection in injections) { if (!(injection.Key == b) && injection.Value.injected && injection.Value.normalizedPath == normalizedPath) { string text3 = "Duplicate def-injected translation key. Both " + injection.Value.path + " and " + text + " refer to the same field (" + suggestedPath + ")"; if (injection.Value.path != injection.Value.nonBackCompatiblePath) { text3 = text3 + " (" + injection.Value.nonBackCompatiblePath + " was auto-renamed to " + injection.Value.path + ")"; } text3 = text3 + " (" + injection.Value.fileSource + ")"; loadErrors.Add(text3); flag4 = true; break; } } bool result2 = false; if (!flag4) { switch (defInjectionPathPartKind) { case DefInjectionPathPartKind.Field: { FieldInfo fieldNamed = GetFieldNamed(obj.GetType(), text2); if (fieldNamed == null) { throw new InvalidOperationException("Field " + text2 + " does not exist in type " + obj.GetType() + "."); } if (fieldNamed.HasAttribute <NoTranslateAttribute>()) { loadErrors.Add("Translated untranslatable field " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + text + ". Translating this field will break the game. (" + fileSource + ")"); } else if (fieldNamed.HasAttribute <UnsavedAttribute>()) { loadErrors.Add("Translated untranslatable field (UnsavedAttribute) " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + text + ". Translating this field will break the game. (" + fileSource + ")"); } else if (!isPlaceholder && fieldNamed.FieldType != ensureFieldType) { loadErrors.Add("Translated non-" + ensureFieldType + " field " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + text + ". Expected " + ensureFieldType + ". (" + fileSource + ")"); } else if (!isPlaceholder && ensureFieldType != typeof(string) && !fieldNamed.HasAttribute <TranslationCanChangeCountAttribute>()) { loadErrors.Add("Tried to translate field " + fieldNamed.Name + " of type " + fieldNamed.FieldType + " at path " + text + ", but this field doesn't have [TranslationCanChangeCount] attribute so it doesn't allow this type of translation. (" + fileSource + ")"); } else if (!isPlaceholder) { if (ensureFieldType == typeof(string)) { replacedString = (string)fieldNamed.GetValue(obj); } else { replacedStringsList = (fieldNamed.GetValue(obj) as IEnumerable <string>); } fieldNamed.SetValue(obj, value); result2 = true; } break; } case DefInjectionPathPartKind.ListIndex: case DefInjectionPathPartKind.ListHandle: case DefInjectionPathPartKind.ListHandleWithIndex: { object obj3 = obj; if (obj3 == null) { throw new InvalidOperationException("Tried to use index on null list at " + text); } Type type = obj3.GetType(); PropertyInfo property3 = type.GetProperty("Count"); if (property3 == null) { throw new InvalidOperationException("Tried to use index on non-list (missing 'Count' property)."); } if (defInjectionPathPartKind == DefInjectionPathPartKind.ListHandle || defInjectionPathPartKind == DefInjectionPathPartKind.ListHandleWithIndex) { result = TranslationHandleUtility.GetElementIndexByHandle(obj3, text2, result); defInjectionPathPartKind = DefInjectionPathPartKind.ListIndex; } int num4 = (int)property3.GetValue(obj3, null); if (result >= num4) { throw new InvalidOperationException("Trying to translate " + defType + "." + text + " at index " + result + " but the list only has " + num4 + " entries (so max index is " + (num4 - 1).ToString() + ")."); } PropertyInfo property4 = type.GetProperty("Item"); if (property4 == null) { throw new InvalidOperationException("Tried to use index on non-list (missing 'Item' property)."); } Type propertyType = property4.PropertyType; if (!isPlaceholder && propertyType != ensureFieldType) { loadErrors.Add("Translated non-" + ensureFieldType + " list item of type " + propertyType + " at path " + text + ". Expected " + ensureFieldType + ". (" + fileSource + ")"); } else if (!isPlaceholder && ensureFieldType != typeof(string) && !flag2) { loadErrors.Add("Tried to translate field of type " + propertyType + " at path " + text + ", but this field doesn't have [TranslationCanChangeCount] attribute so it doesn't allow this type of translation. (" + fileSource + ")"); } else if (result < 0 || result >= (int)type.GetProperty("Count").GetValue(obj3, null)) { loadErrors.Add("Index out of bounds (max index is " + ((int)type.GetProperty("Count").GetValue(obj3, null) - 1) + ")"); } else if (!isPlaceholder) { replacedString = (string)property4.GetValue(obj3, new object[1] { result }); property4.SetValue(obj3, value, new object[1] { result }); result2 = true; } break; } default: loadErrors.Add("Translated " + text2 + " at path " + text + " but it's not a field, it's " + defInjectionPathPartKind + ". (" + fileSource + ")"); break; } } for (int num5 = list.Count - 1; num5 > 0; num5--) { if (list[num5].GetType().IsValueType&& !list[num5].GetType().IsPrimitive) { FieldInfo fieldNamed2 = GetFieldNamed(list[num5 - 1].GetType(), list2[num5]); if (fieldNamed2 != null) { fieldNamed2.SetValue(list[num5 - 1], list[num5]); } } } string tKeyPath; if (flag) { path = suggestedPath; } else if (TKeySystem.TrySuggestTKeyPath(path, out tKeyPath)) { suggestedPath = tKeyPath; } if (path != suggestedPath) { IList <string> list3 = value as IList <string>; string text4 = (list3 == null) ? value.ToString() : list3.ToStringSafeEnumerable(); loadSyntaxSuggestions.Add("Consider using " + suggestedPath + " instead of " + text + " for translation '" + text4 + "' (" + fileSource + ")"); } return(result2); } catch (Exception ex) { string text5 = "Couldn't inject " + text + " into " + defType + " (" + fileSource + "): " + ex.Message; if (ex.InnerException != null) { text5 = text5 + " -> " + ex.InnerException.Message; } loadErrors.Add(text5); return(false); } }