Exemplo n.º 1
0
        internal static void CopyKeys()
        {
            LoadedLanguage active = LanguageDatabase.activeLanguage;

            if (active == null)
            {
                return;
            }

            var builder = new StringBuilder();

            foreach (KeyValuePair <string, LoadedLanguage.KeyedReplacement> pair in active.keyedReplacements)
            {
                string key = pair.Key;
                LoadedLanguage.KeyedReplacement value = pair.Value;

                if (!TranslationProxy.TryAdd(key, value.value))
                {
                    builder.AppendLine($"- {key}");
                }
            }

            if (builder.Length <= 0)
            {
                return;
            }

            builder.Insert(0, "Could not copy the following translations:");
            builder.AppendLine();
            builder.AppendLine("You may experience translation errors!");
            TkUtils.Logger.Warn(builder.ToString());
        }
Exemplo n.º 2
0
        static PharmacistPatch()
        {
            try
            {
                ((Action)(() =>
                {
                    Log.Message("Patching Pharmacist medcare list");

                    //get ordered medicine list
                    List <MedicalCareCategory> careList = ModMedicinePatch.GetOrderedCareList();

                    //setup replacement Pharmacist medical care list
                    MedicalCareCategory[] medCareReplacement = careList.ToArray();

                    //add language labels
                    foreach (MedicalCareCategory care in careList)
                    {
                        if (!LanguageDatabase.activeLanguage.HaveTextForKey($"MedicalCareCategory_{(int)care}"))
                        {
                            LoadedLanguage.KeyedReplacement kr = new LoadedLanguage.KeyedReplacement();
                            kr.key = $"MedicalCareCategory_{(int)care}";
                            kr.value = MedicalCareUtility.GetLabel(care);
                            LanguageDatabase.activeLanguage.keyedReplacements.Add(kr.key, kr);
                        }
                    }

                    //set Pharmacist's medcares array
                    Traverse.Create <Pharmacist.MainTabWindow_Pharmacist>().Field("medcares").SetValue(medCareReplacement);

                    //add modded meds to Pharmacists texture library
                    Texture2D[] tex = new Texture2D[ModMedicinePatch.indexedMedList.Count];
                    for (int i = 0; i < ModMedicinePatch.indexedMedList.Count; i++)
                    {
                        tex[i] = ModMedicinePatch.indexedMedList[i].tex;
                    }

                    Traverse.Create(typeof(Pharmacist.Resources)).Field("medcareGraphics").SetValue(tex);

                    Log.Message("Done Patching Pharmacist medcare list");

                    Log.Message("Patching Pharmacist comparison function..");
                    var harmony = new Harmony("Antaios.Rimworld.PharmMedicinePatch");

                    harmony.Patch(
                        typeof(Pharmacist.PharmacistUtility).GetMethod("TendAdvice", new Type[] { typeof(Pawn), typeof(Pharmacist.InjurySeverity) }),
                        null,
                        new HarmonyMethod(typeof(PharmacistPatch).GetMethod("TendAdvicePostfix"))
                        );

                    Log.Message("Done patching Pharmacist comparison function..");
                }))();
            }
            catch (TypeLoadException)
            {
                Log.Message("Pharmacist not detected");
            }
        }