private static void InitReflection() { try { // Main.DrawPlayerHead _drawPlayerHeadMethod = Main.instance.GetType().GetMethod("DrawPlayerHead", BindingFlags.NonPublic | BindingFlags.Instance); _loadPlayersMethod = typeof(Main).GetMethod("LoadPlayers", BindingFlags.NonPublic | BindingFlags.Static); _startRainMethod = typeof(Main).GetMethod("StartRain", BindingFlags.NonPublic | BindingFlags.Static); _stopRainMethod = typeof(Main).GetMethod("StopRain", BindingFlags.NonPublic | BindingFlags.Static); _startSandstormMethod = typeof(Sandstorm).GetMethod("StartSandstorm", BindingFlags.NonPublic | BindingFlags.Static); _stopSandstormMethod = typeof(Sandstorm).GetMethod("StopSandstorm", BindingFlags.NonPublic | BindingFlags.Static); // _loadNPCMethod = typeof(Main).GetMethod("LoadNPC", BindingFlags.NonPublic | BindingFlags.Instance); // _loadProjectileMethod = typeof(Main).GetMethod("LoadProjectile", BindingFlags.NonPublic | BindingFlags.Instance); // _loadTilesMethod = typeof(Main).GetMethod("LoadTiles", BindingFlags.NonPublic | BindingFlags.Instance); _mouseTextMethod = typeof(Main).GetMethod("MouseText", BindingFlags.NonPublic | BindingFlags.Instance); _invasionWarningMethod = typeof(Main).GetMethod("InvasionWarning", BindingFlags.NonPublic | BindingFlags.Static); _npcDefaultSpawnRate = typeof(NPC).GetField("defaultSpawnRate", BindingFlags.NonPublic | BindingFlags.Static); _npcDefaultMaxSpawns = typeof(NPC).GetField("defaultMaxSpawns", BindingFlags.NonPublic | BindingFlags.Static); _steamid = typeof(ModLoader).GetProperty("SteamID64", BindingFlags.NonPublic | BindingFlags.Static); // _mapIconTextures = Main.instance.GetType().GetField("mapIconTexture", BindingFlags.NonPublic | BindingFlags.Instance); // pub _hueTexture = Main.instance.GetType().GetField("hueTexture", BindingFlags.NonPublic | BindingFlags.Instance); // private // _hoverItem = typeof(Main).GetField("toolTip", BindingFlags.NonPublic | BindingFlags.Static); //Main.toolTip Assembly terraria = Assembly.GetAssembly(typeof(Main)); _itemSortingSortMethod = terraria.GetType("Terraria.UI.ItemSorting").GetMethod("Sort", BindingFlags.Public | BindingFlags.Static); } catch (Exception e) { ModUtils.DebugText(e.Message + " " + e.StackTrace); } }
public override void ModifyInterfaceLayers(List <GameInterfaceLayer> layers) { int inventoryLayerIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text")); if (inventoryLayerIndex != -1) { layers.Insert(inventoryLayerIndex, new LegacyGameInterfaceLayer( "HerosMod: UI", delegate { try { HEROsMod.Update(); HEROsMod.ServiceHotbar.Update(); HEROsMod.DrawBehindUI(Main.spriteBatch); HEROsMod.Draw(Main.spriteBatch); KeybindController.DoPreviousKeyState(); } catch (Exception e) { ModUtils.DebugText("PostDrawInInventory Error: " + e.Message + e.StackTrace); } return(true); }, InterfaceScaleType.UI) ); } }
// Clear EVERYthing, mod is unloaded. public override void Unload() { try { KeybindController.bindings.Clear(); if (ServiceController != null) { if (ServiceController.Services != null) { foreach (var service in ServiceController.Services) { service.Unload(); } } ServiceController.RemoveAllServices(); } HEROsModNetwork.Network.ResetAllPlayers(); HEROsModNetwork.Network.ServerUsingHEROsMod = false; HEROsModNetwork.Network.Regions.Clear(); MasterView.ClearMasterView(); } catch (Exception e) { ModUtils.DebugText("Unload:\n" + e.Message + "\n" + e.StackTrace + "\n"); } }
public override object Call(params object[] args) { string message = args[0] as string; if (message == "AddSimpleButton") { ModUtils.DebugText("Button Adding..."); RegisterButton( args[1] as string, args[2] as Texture2D, args[3] as Action, args[4] as Action <bool>, args[5] as Func <string> ); ModUtils.DebugText("...Button Added"); } else if (message == "AddPermission") { ModUtils.DebugText("Permission Adding..."); // Internal, RegisterPermission( args[1] as string, args[2] as string ); ModUtils.DebugText("...Permission Added"); } else if (message == "HasPermission") { //ModUtils.DebugText("HasPermission?..."); //bool hasPermission = HEROsModNetwork.LoginService.MyGroup.HasPermission((int)args[1], args[1] as string); //ModUtils.DebugText("...HasPermission End"); //return hasPermission; } return(null); }
public override void ModifyInterfaceLayers(List <GameInterfaceLayer> layers) { int inventoryLayerIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Mouse Text")); if (inventoryLayerIndex != -1) { layers.Insert(inventoryLayerIndex, new LegacyGameInterfaceLayer( "HerosMod: UI", delegate { try { HEROsMod.Update(); HEROsMod.ServiceHotbar.Update(); HEROsMod.DrawBehindUI(Main.spriteBatch); HEROsMod.Draw(Main.spriteBatch); KeybindController.DoPreviousKeyState(); } catch (Exception e) { ModUtils.DebugText("HerosMod: UI Error: " + e.Message + e.StackTrace); } return(true); }, InterfaceScaleType.UI) ); // Technically before the above GameInterfaceLayer layers.Insert(inventoryLayerIndex, new LegacyGameInterfaceLayer( "HerosMod: UI (Game Scale)", delegate { try { if (ModUtils.NetworkMode != NetworkMode.Server) { foreach (var service in ServiceController.Services) { service.UpdateGameScale(); } } SelectionTool.Update(); } catch (Exception e) { ModUtils.DebugText("HerosMod: UI (Game Scale) Error: " + e.Message + e.StackTrace); } return(true); }, InterfaceScaleType.Game) ); } }
public void RegisterPermission(string permissionName, string permissionDisplayName) { ModUtils.DebugText($"RegisterPermission: {permissionName} - {permissionDisplayName}"); Group.PermissionList.Add(new PermissionInfo(permissionName, permissionDisplayName)); //foreach (var item in Network.Groups) //{ //} //Network.DefaultGroup.Permissions.Add(permissionName, false); Network.AdminGroup.Permissions.Add(permissionName, true); //modExtensions.AddButton(texture, buttonClickedAction, tooltip); }
// Clear EVERYthing, mod is unloaded. public override void Unload() { UIKit.UIComponents.ItemBrowser.Filters = null; UIKit.UIComponents.ItemBrowser.DefaultSorts = null; UIKit.UIComponents.ItemBrowser.Categories = null; UIKit.UIComponents.ItemBrowser.CategoriesLoaded = false; UIKit.UIButton.buttonBackground = null; UIKit.UIView.closeTexture = null; UIKit.UITextbox.textboxBackground = null; UIKit.UISlider.barTexture = null; UIKit.UIScrollView.ScrollbgTexture = null; UIKit.UIScrollBar.ScrollbarTexture = null; UIKit.UIDropdown.capUp = null; UIKit.UIDropdown.capDown = null; UIKit.UICheckbox.checkboxTexture = null; UIKit.UICheckbox.checkmarkTexture = null; HEROsModServices.Login._loginTexture = null; HEROsModServices.Login._logoutTexture = null; try { KeybindController.bindings.Clear(); if (ServiceController != null) { if (ServiceController.Services != null) { foreach (var service in ServiceController.Services) { service.Unload(); } } ServiceController.RemoveAllServices(); } HEROsModNetwork.Network.ResetAllPlayers(); HEROsModNetwork.Network.ServerUsingHEROsMod = false; HEROsModNetwork.Network.Regions.Clear(); MasterView.ClearMasterView(); } catch (Exception e) { ModUtils.DebugText("Unload:\n" + e.Message + "\n" + e.StackTrace + "\n"); } extensionMenuService = null; miscOptions = null; prefixEditor = null; _hotbar = null; ServiceController = null; TimeWeatherControlHotbar.Unload(); ModUtils.previousInventoryItems = null; translations = null; instance = null; }
public override void PostDrawInterface(SpriteBatch spriteBatch) { try { HEROsMod.Update(); HEROsMod.ServiceHotbar.Update(); HEROsMod.DrawBehindUI(spriteBatch); HEROsMod.Draw(spriteBatch); KeybindController.DoPreviousKeyState(); } catch (Exception e) { ModUtils.DebugText("PostDrawInInventory Error: " + e.Message + e.StackTrace); } }
internal static Dictionary <string, ModTranslation> translations; // reference to private field. public override void Load() { // Since we are using hooks not in older versions, and since ItemID.Count changed, we need to do this. if (ModLoader.version < new Version(0, 10, 1, 3)) { throw new Exception(HEROsMod.HeroText("UpdateTModLoaderToUse")); } try { instance = this; FieldInfo translationsField = typeof(Mod).GetField("translations", BindingFlags.Instance | BindingFlags.NonPublic); translations = (Dictionary <string, ModTranslation>)translationsField.GetValue(this); //LoadTranslations(); // AddGlobalItem("HEROsModGlobalItem", new HEROsModGlobalItem()); // AddPlayer("HEROsModModPlayer", new HEROsModModPlayer()); //if (ModUtils.NetworkMode != NetworkMode.Server) if (!Main.dedServ) { UIKit.UIButton.buttonBackground = HEROsMod.instance.GetTexture("Images/UIKit/buttonEdge"); UIKit.UIView.closeTexture = HEROsMod.instance.GetTexture("Images/closeButton"); UIKit.UITextbox.textboxBackground = HEROsMod.instance.GetTexture("Images/UIKit/textboxEdge"); UIKit.UISlider.barTexture = HEROsMod.instance.GetTexture("Images/UIKit/barEdge"); UIKit.UIScrollView.ScrollbgTexture = GetTexture("Images/UIKit/scrollbgEdge"); UIKit.UIScrollBar.ScrollbarTexture = HEROsMod.instance.GetTexture("Images/UIKit/scrollbarEdge"); UIKit.UIDropdown.capUp = HEROsMod.instance.GetTexture("Images/UIKit/dropdownCapUp"); UIKit.UIDropdown.capDown = HEROsMod.instance.GetTexture("Images/UIKit/dropdownCapDown"); UIKit.UICheckbox.checkboxTexture = HEROsMod.instance.GetTexture("Images/UIKit/checkBox"); UIKit.UICheckbox.checkmarkTexture = HEROsMod.instance.GetTexture("Images/UIKit/checkMark"); } Init(); } catch (Exception e) { ModUtils.DebugText("Load:\n" + e.Message + "\n" + e.StackTrace + "\n"); } }
public static void GameEntered() { ModUtils.DebugText("Game Entered"); if (ModUtils.NetworkMode == NetworkMode.None) { foreach (HEROsModService service in ServiceController.Services) { service.HasPermissionToUse = !service.MultiplayerOnly; } ServiceController.ServiceRemovedCall(); } else { foreach (HEROsModService service in ServiceController.Services) { service.HasPermissionToUse = true; } ServiceController.MyGroupChanged(); } //ServiceController.MyGroupChanged(); }
public override void Load() { // Since we are using hooks not in older versions, and since ItemID.Count changed, we need to do this. if (ModLoader.version < new Version(0, 9, 2)) { throw new Exception("\nThis mod uses functionality only present in the latest tModLoader. Please update tModLoader to use this mod\n\n"); } try { instance = this; // AddGlobalItem("HEROsModGlobalItem", new HEROsModGlobalItem()); AddPlayer("HEROsModModPlayer", new HEROsModModPlayer()); //if (ModUtils.NetworkMode != NetworkMode.Server) Init(); } catch (Exception e) { ModUtils.DebugText("Load:\n" + e.Message + "\n" + e.StackTrace + "\n"); } }
public override object Call(params object[] args) { string message = args[0] as string; if (message == "AddSimpleButton") { ModUtils.DebugText("Button Adding..."); RegisterButton( args[1] as string, args[2] as Texture2D, args[3] as Action, args[4] as Action <bool>, args[5] as Func <string> ); ModUtils.DebugText("...Button Added"); } else if (message == "AddPermission") { ModUtils.DebugText("Permission Adding..."); // Internal, RegisterPermission( args[1] as string, args[2] as string ); ModUtils.DebugText("...Permission Added"); } else if (message == "HasPermission") { if (Main.netMode != Terraria.ID.NetmodeID.Server || args.Length != 3) // for now, only allow this call on Server (2) { return(false); } //int player = Convert.ToInt32(args[1]); // Convert.ToInt32 doesn't throw exception, casting does. Exception is better in this case. //string permission = args[2] as string; return(Network.Players[(int)args[1]].Group.HasPermission(args[2] as string)); } return(null); }
public static void GameLeft() { ModUtils.DebugText("Game left"); Login.LoggedIn = false; ServiceController.MyGroupChanged(); }
public override object Call(params object[] args) { int argsLength = args.Length; Array.Resize(ref args, 6); try { string message = args[0] as string; if (message == "AddSimpleButton") { ModUtils.DebugText("Button Adding..."); RegisterButton( args[1] as string, args[2] as Texture2D, args[3] as Action, args[4] as Action <bool>, args[5] as Func <string> ); ModUtils.DebugText("...Button Added"); } else if (message == "AddPermission") { ModUtils.DebugText("Permission Adding..."); // Internal, RegisterPermission( args[1] as string, args[2] as string, args[3] as Action <bool> ); ModUtils.DebugText("...Permission Added"); } else if (message == "HasPermission") { if (/*Main.netMode != Terraria.ID.NetmodeID.Server ||*/ argsLength != 3) // for now, only allow this call on Server (2) --> why?? { return(false); } //int player = Convert.ToInt32(args[1]); // Convert.ToInt32 doesn't throw exception, casting does. Exception is better in this case. //string permission = args[2] as string; return(Network.Players[(int)args[1]].Group?.HasPermission(args[2] as string) ?? false); // Group might be null, so checking permissions on entering world won't work reliably. } else if (message == "HideHotbar") { if (!ServiceHotbar.Collapsed) { ServiceHotbar.collapseArrow_onLeftClick(null, null); if (!ServiceHotbar.Collapsed) // sub hotbars { ServiceHotbar.collapseArrow_onLeftClick(null, null); } } } else { Logger.Error("Call Error: Unknown Message: " + message); } } catch (Exception e) { Logger.Error("Call Error: " + e.StackTrace + e.Message); } return(null); }