private void Sala_OnNpcPracticeChange(Thing sender, object[] obs) { if (World.Instance.GetFlag(111111002) != 1) { foreach (var npc in ThingMgr.Instance.NpcList) { if (npc.Camp == XiaWorld.Fight.g_emFightCamp.Player) { if (npc.PropertyMgr.CheckExperienceVaild("SALA_Idlest") == false && npc.PropertyMgr.CheckFeature("ProtagonistOfSala") == true) { if (npc.Rank == g_emNpcRank.Disciple) { GlobalSet.SetNpcCanDoWorkAndDisciple(npc); #if DEBUG KLog.Dbg("initWorkerBehaviour"); #endif #if DEBUG foreach (var behaviour in GlobalSet.GetNpcBehaviours(npc)) { KLog.Dbg(behaviour.GetType().ToString()); } #endif World.Instance.SetFlag(111111002, 1); } } } } } if (World.Instance.GetFlag(111111002) == 1) { EventMgr.Instance.RemoveEvent(g_emEvent.NpcPracticeChange, Sala_OnNpcPracticeChange); } }
private void Sala_OnThingUpdateGridKey(Thing sender, object[] obs) { if (World.Instance.GetFlag(111111001) != 1) { foreach (var npc in ThingMgr.Instance.NpcList) { #if DEBUG KLog.Dbg("Check ProtagonistOfSala"); #endif if (npc.Camp == XiaWorld.Fight.g_emFightCamp.Player) { if (npc.PropertyMgr.CheckExperienceVaild("SALA_Idlest") == false && npc.PropertyMgr.CheckFeature("ProtagonistOfSala") == false) { npc.PropertyMgr.AddFeature("ProtagonistOfSala"); } else { npc.DoDeath(); } } } Wnd_Message.Show("不对,还有一个人在天雷中活了下来,如此气运恐怕将成为修仙界新的传奇。", 1, null, true, "全新的传奇"); Wnd_Message.Show("当空一声霹雳,好不容易逃出来的太一幸存者,就这样全部倒下了。游戏就这样结束了。", 1, null, true, "逃亡的终结"); World.Instance.SetFlag(111111001, 1); } if (World.Instance.GetFlag(111111001) == 1) { EventMgr.Instance.RemoveEvent(g_emEvent.ThingUpdateGridKey, Sala_OnThingUpdateGridKey); } }
// will be called each time the game is saving. public static void Save() { if (!string.IsNullOrEmpty(GameWatch.Instance.LoadFile)) { var fullPath = Path.Combine(Directory.GetCurrentDirectory(), $"saves/{GameWatch.Instance.LoadFile}.mll"); using (var fs = new FileStream(fullPath, FileMode.Create)) { try { Config.Configuration.Save(); foreach (var asm in assemblies) { Utilities.Util.Call(asm, "OnSave"); } var serializer = new BinaryFormatter(); serializer.Serialize(fs, saves); } catch (Exception e) { KLog.Dbg("Failed to deserialize. Reason: " + e.Message); KLog.Dbg(e.StackTrace); } } } }
public static void Call(Assembly asm, string method) { if (asm != null) { try { var name = asm.GetName().Name; KLog.Dbg($"[ModLoaderLite] calling the {method} method for {name}..."); asm.GetType($"{name}.{name}")?.GetMethod(method)?.Invoke(null, null); } catch (ArgumentException ae) { KLog.Dbg(ae.Message); } catch (TargetInvocationException tie) { KLog.Dbg($"invocation of {method} in {asm.FullName} failed!"); var ie = tie.InnerException; KLog.Dbg(ie.Message); KLog.Dbg(ie.StackTrace); } catch (Exception e) { KLog.Dbg(e.Message); KLog.Dbg(e.StackTrace); } } }
public static void OnLoad() { KLog.Dbg("[AmzCuiTiAll] OnLoad x"); Configuration.AddCheckBox(nameof(AmzCuiTiAll), "CuiTiAllEnabled", "淬体显示全部词条", CuiTiAllEnabled); Configuration.AddCheckBox(nameof(AmzCuiTiAll), "SouHunEnabled", "无限制搜魂大法", CuiTiAllEnabled); Configuration.Subscribe(new EventCallback0(AmzCuiTiAll.HandleConfig)); }
public static List <string> GetModFiles(string localpath, string modpath, string pattern) { var files = new List <string>(); if (string.IsNullOrEmpty(modpath)) { var paths = ModsMgr.Instance.GetPath(localpath).Where(pd => pd.mod != null).Select(pd => pd.path); // we ignore vanilla files. foreach (var path in paths) { try { files.AddRange(Directory.GetFiles(path, pattern, SearchOption.AllDirectories)); } catch (Exception ex) { KLog.Dbg($"Unable to get files in path {path}, ignoring the mod!"); KLog.Dbg($"the error is: {ex.Message}"); } } } else { try { var path = Path.Combine(modpath, localpath); files.AddRange(Directory.GetFiles(path, pattern, SearchOption.AllDirectories)); } catch (Exception ex) { KLog.Dbg($"Unable to get files in {localpath} of {modpath}, check your directory name parameters!"); KLog.Dbg($"the error is: {ex.Message}"); } } return(files); }
static List <T> LoadXmlFile <T>(string localpath, string modpath, string pattern) { var ret = new List <T>(); var id = Path.Combine(localpath, typeof(T).ToString()); if (serializers.TryGetValue(id, out var serializer)) { foreach (var file in Utilities.Util.GetModFiles(localpath, modpath, pattern)) { try { using (var fs = new FileStream(file, FileMode.Open)) { var defs = (T)serializer.Deserialize(fs); ret.Add(defs); } } catch (Exception ex) { KLog.Dbg(ex.Message); KLog.Dbg(ex.StackTrace); } } } return(ret); }
static void AddMenu() { // add a menu in the mainmenu. KLog.Dbg("[ModLoaderLite] adding config menu option..."); var mainMenu = Traverse.Create(Wnd_GameMain.Instance).Field <PopupMenu>("MainMenu").Value; mainMenu?.AddItem("MLL设置", () => Config.Configuration.Show()); }
// will be called each time a game is loaded. public static void Load() { KLog.Dbg("[ModLoaderLite] game loading..."); AddMenu(); DoLoad(); foreach (var asm in assemblies) { Utilities.Util.Call(asm, "OnLoad"); } Config.Configuration.Load(); }
public int Main() { KLog.Dbg("Start Sala"); GlobalSet.SetSchoolMaxNpcAsOne(); SalaEvents salaEvents = new SalaEvents(); salaEvents.InitEventRegister(); return(0); }
static void replaceMenu(PopupMenu ___MainMenu) { KLog.Dbg("[AmzHardCoreSaver] add buttons v1"); var i = 0; var t1 = -1; var t2 = -1; foreach (var gObject in ___MainMenu._list.GetChildren()) { if (gObject.asButton.title == TFMgr.Get("存档并返回")) { t1 = i; } else if (gObject.asButton.title == TFMgr.Get("存档并退出")) { t2 = i; } i++; } if (t1 >= 0) { var name = ___MainMenu.GetItemName(t1); KLog.Dbg("[AmzHardCoreSaver] remove {0} {1}", t1, name); if (___MainMenu.RemoveItem(name)) { ___MainMenu.AddItem(TFMgr.Get("存档"), (EventCallback0)(() => Wnd_Save.Instance.ShowSaveWnd(0))); } } else { // ___MainMenu.AddItem(TFMgr.Get("存档"), // (EventCallback0) (() => Wnd_Save.Instance.ShowSaveWnd(0))); } if (t2 >= 0) { if (___MainMenu.RemoveItem(___MainMenu.GetItemName(t2))) { ___MainMenu.AddItem(TFMgr.Get("读档"), (EventCallback0)(() => Wnd_Save.Instance.ShowSaveWnd(1))); } } else { // ___MainMenu.AddItem(TFMgr.Get("读档"), // (EventCallback0) (() => Wnd_Save.Instance.ShowSaveWnd(1))); } }
// the handle resolve event doesn't fire if an assembly of the same name is present... // so we have to manually load our own dependencies to prevent conflict. public static void LoadDep() { if (!depLoaded) { KLog.Dbg("[ModLoaderLite] Loading dependencies..."); KLog.Dbg($"[ModLoaderLite] {typeof(MLLMain).AssemblyQualifiedName}"); var currentDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var harmonyLib = Path.Combine(currentDir, "0Harmony.dll"); var simdLib = Path.Combine(currentDir, "Mono.Simd.dll"); //var protobuf = Path.Combine(currentDir, "protobuf-net.dll"); Assembly.LoadFrom(harmonyLib); KLog.Dbg("[ModLoaderLite] Harmony loaded."); Assembly.LoadFrom(simdLib); KLog.Dbg("[ModLoaderLite] Mono.Simd loaded."); //Assembly.LoadFrom(protobuf); //KLog.Dbg("[ModLoaderLite] Protobuf loaded."); depLoaded = true; } }
public static Assembly LoadAssembly(Assembly asm) { if (asm != null) { try { KLog.Dbg($"Loading: {asm.FullName}"); var loaded = Assembly.LoadFrom(asm.Location); return(loaded); } catch (Exception ex) { KLog.Dbg($"loading assembly {asm.GetName()} failed!"); KLog.Dbg(ex.Message); KLog.Dbg(ex.StackTrace); } } return(null); }
public static List <T> LoadJson <T>(string localpath, string modpath = null, string pattern = "*.json") { var ret = new List <T>(); foreach (var file in Utilities.Util.GetModFiles(localpath, modpath, pattern)) { try { var str = File.ReadAllText(file); var items = JsonConvert.DeserializeObject <List <T> >(str, settings); ret.AddRange(items); } catch (Exception ex) { KLog.Dbg(ex.Message); KLog.Dbg(ex.StackTrace); } } return(ret); }
public static AssetBundle LoadAssetBundleFromMod(ModsMgr.ModData data, string fileName) { if (!assetBundles.TryGetValue(fileName, out var loadedAB)) { try { var bundleFile = Path.Combine(Path.Combine(data.Path, "Resources/AssetBundles"), fileName); loadedAB = AssetBundle.LoadFromFile(bundleFile); if (loadedAB != null) { KLog.Dbg($"[ModLoaderLite BundleManager] AB {fileName} loaded!"); assetBundles.Add(fileName, loadedAB); } } catch (Exception e) { KLog.Dbg(e.Message); KLog.Dbg(e.StackTrace); } } return(loadedAB); }
public static Assembly PreLoadAssembly(string file) { var fileName = Path.GetFileName(file); // we exclude errogenous libraries that may be a problem. if (!(fileName.ToLower() == "0harmony") && !(fileName.ToLower().Contains("modloaderlite"))) { try { KLog.Dbg($"Pre-Loading: {fileName}"); var assembly = Assembly.ReflectionOnlyLoadFrom(file); return(assembly); } catch (Exception ex) { KLog.Dbg($"Pre-Loading assembly {fileName} failed!"); KLog.Dbg(ex.Message); KLog.Dbg(ex.StackTrace); } } return(null); }
public static bool ApplyHarmony(Assembly asm, string name) { if (asm != null) { var harmony_name = string.IsNullOrEmpty(name) ? asm.FullName : name; try { KLog.Dbg($"Applying harmony patch: {harmony_name}"); var harmonyInstance = new Harmony(harmony_name); harmonyInstance?.PatchAll(asm); KLog.Dbg($"Applying patch {harmony_name} succeeded!"); return(true); } catch (Exception ex) { KLog.Dbg($"Patching harmony mod {harmony_name} failed!"); KLog.Dbg(ex.Message); KLog.Dbg(ex.StackTrace); } } return(false); }
// single time method that loads the assemblies and applies harmony patches. // also calls the oninit events that ought to be run only once each game. public static void Init() { if (!inited) { KLog.Dbg("[ModLoaderLite] patching the game with modloaderlite patches..."); var harmony = new Harmony("jnjly.ModLoaderLite"); harmony.PatchAll(); KLog.Dbg("[ModLoaderLite] loading assemblies..."); var lua_assemblies = Traverse.Create(LuaMgr.Instance.Env).Field("translator").Field("assemblies").GetValue <List <Assembly> >(); var activated = ModsMgr.Instance.AllMods.Where(p => p.Value.IsActive == true && p.Value.Name != "ModLoaderLite"); // excluding ourself. foreach (var p in activated) { try { var files = Directory.GetFiles(p.Value.Path, $"{p.Value.Name}.dll", SearchOption.AllDirectories); var harmony_name = $"{p.Value.Author}.{p.Value.Name}"; foreach (var file in files) { var rasm = Utilities.Util.PreLoadAssembly(file); var asm = Utilities.Util.LoadAssembly(rasm); if (asm != null) { assemblies.Add(asm); lua_assemblies.Add(asm); } Utilities.Util.Call(asm, "OnInit"); Utilities.Util.ApplyHarmony(asm, harmony_name); } AssetBundles.BundleManager.LoadAssetBundleFromMod(p.Value, p.Value.Name.ToLower()); } catch (Exception ex) { KLog.Dbg($"the mod {p.Value.DisplayName} cannot be loaded!"); KLog.Dbg($"the error is: {ex.Message}"); } } inited = true; } }
static void DoLoad() { var fileName = GameWatch.Instance.LoadFile; var fullName = Path.Combine(Directory.GetCurrentDirectory(), $"saves/{fileName}.mll"); if (File.Exists(fullName)) { using (var fs = new FileStream(fullName, FileMode.Open)) { try { var serializer = new BinaryFormatter(); saves = (Dictionary <string, object>)serializer.Deserialize(fs); } catch (Exception e) { KLog.Dbg("Failed to serialize. Reason: " + e.Message); KLog.Dbg(e.StackTrace); } } } }
static void Prefix(Wnd_GameMain __instance, ref PopupMenu ___MainMenu) { KLog.Dbg("[AmzHardCoreSaver] Prefix"); if (___MainMenu != null && World.Instance != null) { if (oldLength == 0) { oldLength = ___MainMenu._list.numItems; } if (___MainMenu._list.numItems <= oldLength) { if (World.Instance.GameMode == g_emGameMode.HardCore) { KLog.Dbg("[AmzHardCoreSaver] AddMenu"); // 替换为存档 ___MainMenu.AddItem(TFMgr.Get("存档"), (EventCallback0)(() => Wnd_Save.Instance.ShowSaveWnd(0))); // 替换为读档 ___MainMenu.AddItem(TFMgr.Get("读档"), (EventCallback0)(() => Wnd_Save.Instance.ShowSaveWnd(1))); } } } }
static void GetRandomQuenchingLabelListPost(PracticeMgr __instance, Npc npc, string part, string item, ref List <BPLabelCacheDef.LabelDataTemp> __result) { if (!AmzCuiTiAll.CuiTiAllEnabled || __result.Count == 0) { return; } NpcBodyData.NpcBodyPart partB = npc.PropertyMgr.BodyData.GetPart(part); BodyPartDef def = partB.def; // 基础池子 string cachename = "BaseCache"; if (!string.IsNullOrEmpty(def.BPQLabelBaseCache)) { cachename = def.BPQLabelBaseCache; } __result.Clear(); var list = __result; // 排重 var labelMap = new Dictionary <string, Boolean>(); labelMap.Add("QuenchingLabel_Lv0_Base", true); //排除 var sMapBpLabelCacheDefs = AccessTools.StaticFieldRefAccess <Dictionary <string, BPLabelCacheDef> >( typeof(PracticeMgr), "s_mapBPLabelCacheDefs"); foreach (var sMapBpLabelCacheDef in sMapBpLabelCacheDefs) { // 判断池子 if (!(sMapBpLabelCacheDef.Key.StartsWith("Cache") || sMapBpLabelCacheDef.Key == cachename)) { continue; } KLog.Dbg("[AmzCuiTiAll] 当前池子{0}", sMapBpLabelCacheDef.Key); var bpLabelCacheDef = sMapBpLabelCacheDef.Value; var labelDataItemsRef = AccessTools.FieldRefAccess <List <string> >(typeof(BPLabelCacheDef.LabelData), "Items"); bpLabelCacheDef.Labels.ForEach(labelData => { if (!labelMap.ContainsKey(labelData.Label)) { labelMap.Add(labelData.Label, true); // 获取fit物品 var fitItem = item; if (!string.IsNullOrEmpty(labelData.ItemStr)) { var items = labelDataItemsRef.Invoke(labelData); if (items == null) { labelData.IsFit(def.Kind.ToString(), item, def.Name); //单纯的初始化 } fitItem = labelDataItemsRef.Invoke(labelData)[0]; } if (labelData.IsFit(def.Kind.ToString(), fitItem, def.Name)) { // 计算lv int num = labelData.Lv; if (!string.IsNullOrEmpty(item)) { ThingDef tdef = ThingMgr.Instance.GetDef(g_emThingType.Item, item); if (tdef.Rate > 0) { int a = Mathf.Max(0, tdef.Rate); num = Mathf.Max(1, num * World.RandomRange(a, 2 * a, GMathUtl.RandomType.emNone)); } } list.Add(new BPLabelCacheDef.LabelDataTemp() { Label = labelData.Label, Lv = num }); } } }); } }