Skip to content

Commit a388c41

Browse files
committed
v0.3, update to tModLoader v0.11.5, HideHotbar, default group fix.
1 parent 455b5b8 commit a388c41

File tree

15 files changed

+245
-198
lines changed

15 files changed

+245
-198
lines changed

HEROsMod.cs

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal class HEROsMod : Mod
2222
{
2323
public static HEROsMod instance;
2424
internal static Dictionary<string, ModTranslation> translations; // reference to private field.
25+
internal Dictionary<string, Action<bool>> crossModGroupUpdated = new Dictionary<string, Action<bool>>();
2526

2627
public override void Load()
2728
{
@@ -287,6 +288,7 @@ public static void Init()
287288
UIView.exclusiveControl = null;
288289
//HEROsModVideo.Services.DropRateInfo.DropTableBuilder.ImportDropTable();
289290
InventoryManager.SetKeyBindings();
291+
//AchievementManger.Load();
290292
//ZoomToolsService.SetKeyBindings();
291293
//KeybindController.LoadBindings();
292294
//UIKit.UIComponents.ItemTooltip.SetKeyBindings();
@@ -313,36 +315,60 @@ public static void Init()
313315

314316
public override object Call(params object[] args)
315317
{
316-
string message = args[0] as string;
317-
if (message == "AddSimpleButton")
318-
{
319-
ModUtils.DebugText("Button Adding...");
320-
RegisterButton(
321-
args[1] as string,
322-
args[2] as Texture2D,
323-
args[3] as Action,
324-
args[4] as Action<bool>,
325-
args[5] as Func<string>
326-
);
327-
ModUtils.DebugText("...Button Added");
328-
}
329-
else if (message == "AddPermission")
318+
int argsLength = args.Length;
319+
Array.Resize(ref args, 6);
320+
321+
try
330322
{
331-
ModUtils.DebugText("Permission Adding...");
332-
// Internal,
333-
RegisterPermission(
334-
args[1] as string,
335-
args[2] as string
336-
);
337-
ModUtils.DebugText("...Permission Added");
323+
string message = args[0] as string;
324+
if (message == "AddSimpleButton")
325+
{
326+
ModUtils.DebugText("Button Adding...");
327+
RegisterButton(
328+
args[1] as string,
329+
args[2] as Texture2D,
330+
args[3] as Action,
331+
args[4] as Action<bool>,
332+
args[5] as Func<string>
333+
);
334+
ModUtils.DebugText("...Button Added");
335+
}
336+
else if (message == "AddPermission")
337+
{
338+
ModUtils.DebugText("Permission Adding...");
339+
// Internal,
340+
RegisterPermission(
341+
args[1] as string,
342+
args[2] as string,
343+
args[3] as Action<bool>
344+
);
345+
ModUtils.DebugText("...Permission Added");
346+
}
347+
else if (message == "HasPermission")
348+
{
349+
if (/*Main.netMode != Terraria.ID.NetmodeID.Server ||*/ argsLength != 3) // for now, only allow this call on Server (2) --> why??
350+
return false;
351+
//int player = Convert.ToInt32(args[1]); // Convert.ToInt32 doesn't throw exception, casting does. Exception is better in this case.
352+
//string permission = args[2] as string;
353+
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.
354+
}
355+
else if (message == "HideHotbar")
356+
{
357+
if (!ServiceHotbar.Collapsed)
358+
{
359+
ServiceHotbar.collapseArrow_onLeftClick(null, null);
360+
if(!ServiceHotbar.Collapsed) // sub hotbars
361+
ServiceHotbar.collapseArrow_onLeftClick(null, null);
362+
}
363+
}
364+
else
365+
{
366+
Logger.Error("Call Error: Unknown Message: " + message);
367+
}
338368
}
339-
else if (message == "HasPermission")
369+
catch (Exception e)
340370
{
341-
if (Main.netMode != Terraria.ID.NetmodeID.Server || args.Length != 3) // for now, only allow this call on Server (2)
342-
return false;
343-
//int player = Convert.ToInt32(args[1]); // Convert.ToInt32 doesn't throw exception, casting does. Exception is better in this case.
344-
//string permission = args[2] as string;
345-
return Network.Players[(int)args[1]].Group.HasPermission(args[2] as string);
371+
Logger.Error("Call Error: " + e.StackTrace + e.Message);
346372
}
347373
return null;
348374
}
@@ -358,7 +384,7 @@ public void RegisterButton(string permissionName, Texture2D texture, Action butt
358384
}
359385
}
360386

361-
public void RegisterPermission(string permissionName, string permissionDisplayName)
387+
public void RegisterPermission(string permissionName, string permissionDisplayName, Action<bool> groupUpdated)
362388
{
363389
ModUtils.DebugText($"RegisterPermission: {permissionName} - {permissionDisplayName}");
364390
Group.PermissionList.Add(new PermissionInfo(permissionName, permissionDisplayName));
@@ -368,6 +394,11 @@ public void RegisterPermission(string permissionName, string permissionDisplayNa
368394
//Network.DefaultGroup.Permissions.Add(permissionName, false);
369395
Network.AdminGroup.Permissions.Add(permissionName, true);
370396

397+
if (groupUpdated != null)
398+
{
399+
crossModGroupUpdated[permissionName] = groupUpdated;
400+
}
401+
371402
//modExtensions.AddButton(texture, buttonClickedAction, tooltip);
372403
}
373404

HEROsMod.csproj

Lines changed: 8 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,13 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<Import Project="..\..\references\tModLoader.targets" />
44
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{FC1BED12-874C-4134-ABD2-5425FA425503}</ProjectGuid>
8-
<OutputType>Library</OutputType>
9-
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>HEROsMod</RootNamespace>
115
<AssemblyName>HEROsMod</AssemblyName>
12-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13-
<FileAlignment>512</FileAlignment>
14-
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
6+
<TargetFramework>net45</TargetFramework>
7+
<PlatformTarget>x86</PlatformTarget>
8+
<LangVersion>latest</LangVersion>
159
</PropertyGroup>
16-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17-
<PlatformTarget>AnyCPU</PlatformTarget>
18-
<DebugSymbols>true</DebugSymbols>
19-
<DebugType>full</DebugType>
20-
<Optimize>false</Optimize>
21-
<OutputPath>bin\Debug\</OutputPath>
22-
<DefineConstants>DEBUG;TRACE</DefineConstants>
23-
<ErrorReport>prompt</ErrorReport>
24-
<WarningLevel>4</WarningLevel>
25-
</PropertyGroup>
26-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27-
<PlatformTarget>AnyCPU</PlatformTarget>
28-
<DebugType>pdbonly</DebugType>
29-
<Optimize>true</Optimize>
30-
<OutputPath>bin\Release\</OutputPath>
31-
<DefineConstants>TRACE</DefineConstants>
32-
<ErrorReport>prompt</ErrorReport>
33-
<WarningLevel>4</WarningLevel>
34-
</PropertyGroup>
35-
<PropertyGroup>
36-
<StartupObject />
37-
</PropertyGroup>
38-
<ItemGroup>
39-
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
40-
<SpecificVersion>False</SpecificVersion>
41-
<HintPath>..\..\..\..\..\..\..\..\Windows\Microsoft.NET\assembly\GAC_32\Microsoft.Xna.Framework\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.dll</HintPath>
42-
</Reference>
43-
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553" />
44-
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
45-
<Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86">
46-
<SpecificVersion>False</SpecificVersion>
47-
<HintPath>..\..\..\..\..\..\..\..\Windows\Microsoft.NET\assembly\GAC_32\Microsoft.Xna.Framework.Xact\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Xact.dll</HintPath>
48-
</Reference>
49-
<Reference Include="Newtonsoft.Json">
50-
<HintPath>..\..\..\Modding\tModLoader\references\Newtonsoft.Json.dll</HintPath>
51-
</Reference>
52-
<Reference Include="ReLogic">
53-
<HintPath>..\..\..\Modding\tModLoader\references\ReLogic.dll</HintPath>
54-
</Reference>
55-
<Reference Include="System" />
56-
<Reference Include="System.Runtime.Serialization" />
57-
<Reference Include="System.XML" />
58-
<Reference Include="System.Xml.Linq" />
59-
<Reference Include="Terraria, Version=1.3.5.1, Culture=neutral, processorArchitecture=x86">
60-
<SpecificVersion>False</SpecificVersion>
61-
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Terraria\Terraria.exe</HintPath>
62-
</Reference>
63-
</ItemGroup>
64-
<ItemGroup>
65-
<Compile Include="Commands\AdminInstructionsCommand.cs" />
66-
<Compile Include="Commands\BecomeAdmin.cs" />
67-
<Compile Include="HEROsModModPlayer.cs" />
68-
<Compile Include="HEROsModModWorld.cs" />
69-
<Compile Include="HEROsModNetwork\DatabaseController.cs" />
70-
<Compile Include="HEROsModNetwork\HEROsModPlayer.cs" />
71-
<Compile Include="HEROsModNetwork\GeneralMessages.cs" />
72-
<Compile Include="HEROsModNetwork\Group.cs" />
73-
<Compile Include="HEROsModNetwork\LoginService.cs" />
74-
<Compile Include="HEROsModNetwork\Network.cs" />
75-
<Compile Include="HEROsModNetwork\Region.cs" />
76-
<Compile Include="HEROsModNetwork\TileChangeController.cs" />
77-
<Compile Include="HEROsModServices\BuffService.cs" />
78-
<Compile Include="HEROsModServices\CheckTileModificationTool.cs" />
79-
<Compile Include="HEROsModServices\EnemyToggler.cs" />
80-
<Compile Include="HEROsModServices\ExtensionMenuService.cs" />
81-
<Compile Include="HEROsModServices\FlyCam.cs" />
82-
<Compile Include="HEROsModServices\GenericExtensionService.cs" />
83-
<Compile Include="HEROsModServices\HEROsModService.cs" />
84-
<Compile Include="HEROsModServices\GodModeService.cs" />
85-
<Compile Include="HEROsModServices\GroupInspector.cs" />
86-
<Compile Include="HEROsModServices\InfiniteReach.cs" />
87-
<Compile Include="HEROsModServices\InvasionService.cs" />
88-
<Compile Include="HEROsModServices\InventoryManager.cs" />
89-
<Compile Include="HEROsModServices\ItemBanner.cs" />
90-
<Compile Include="HEROsModServices\ItemBrowser.cs" />
91-
<Compile Include="HEROsModServices\ItemClearer.cs" />
92-
<Compile Include="HEROsModServices\KeybindController.cs" />
93-
<Compile Include="HEROsModServices\LightHack.cs" />
94-
<Compile Include="HEROsModServices\Login.cs" />
95-
<Compile Include="HEROsModServices\MapRevealer.cs" />
96-
<Compile Include="HEROsModServices\MobSpawner.cs" />
97-
<Compile Include="HEROsModServices\MiscOptions.cs" />
98-
<Compile Include="HEROsModServices\PlayerList.cs" />
99-
<Compile Include="HEROsModServices\PrefixEditor.cs" />
100-
<Compile Include="HEROsModServices\PrefixScraper.cs" />
101-
<Compile Include="HEROsModServices\PSAService.cs" />
102-
<Compile Include="HEROsModServices\RegionService.cs" />
103-
<Compile Include="HEROsModServices\SelectionTool.cs" />
104-
<Compile Include="HEROsModServices\ServiceController.cs" />
105-
<Compile Include="HEROsModServices\ServiceHotbar.cs" />
106-
<Compile Include="HEROsModServices\SpawnPointSetter.cs" />
107-
<Compile Include="HEROsModServices\StatsService.cs" />
108-
<Compile Include="HEROsModServices\Teleporter.cs" />
109-
<Compile Include="HEROsModServices\TestHotbarSevice.cs" />
110-
<Compile Include="HEROsModServices\ToggleGravestones.cs" />
111-
<Compile Include="HEROsModServices\Waypoints.cs" />
112-
<Compile Include="HEROsModServices\TimeWeatherChanger.cs" />
113-
<Compile Include="HEROsModVideo\Services\MobHUD\MobInfo.cs" />
114-
<Compile Include="HEROsModVideo\Services\MobHUD\MobInfoView.cs" />
115-
<Compile Include="HEROsMod.cs" />
116-
<Compile Include="ModUtils.cs" />
117-
<Compile Include="UIKit\ColorSliders.cs" />
118-
<Compile Include="UIKit\MasterView.cs" />
119-
<Compile Include="UIKit\UIButton.cs" />
120-
<Compile Include="UIKit\UICheckbox.cs" />
121-
<Compile Include="UIKit\UIColorPicker.cs" />
122-
<Compile Include="UIKit\UIColorSlider.cs" />
123-
<Compile Include="UIKit\UIComponents\DropTableView.cs" />
124-
<Compile Include="UIKit\UIComponents\HostPlayWindow.cs" />
125-
<Compile Include="UIKit\UIComponents\ItemBrowser.cs" />
126-
<Compile Include="UIKit\UIComponents\ItemCollectionView.cs" />
127-
<Compile Include="UIKit\UIComponents\ItemTooltip.cs" />
128-
<Compile Include="UIKit\UIComponents\ItemView.cs" />
129-
<Compile Include="UIKit\UIComponents\MoneyView.cs" />
130-
<Compile Include="UIKit\UIComponents\SliderWithTextbox.cs" />
131-
<Compile Include="UIKit\UIComponents\Slot.cs" />
132-
<Compile Include="UIKit\UIComponents\UIHotbar.cs" />
133-
<Compile Include="UIKit\UIDropdown.cs" />
134-
<Compile Include="UIKit\UIImage.cs" />
135-
<Compile Include="UIKit\UILabel.cs" />
136-
<Compile Include="UIKit\UIListView.cs" />
137-
<Compile Include="UIKit\UIMessageBox.cs" />
138-
<Compile Include="UIKit\UIPlayerHead.cs" />
139-
<Compile Include="UIKit\UIRect.cs" />
140-
<Compile Include="UIKit\UIScreen.cs" />
141-
<Compile Include="UIKit\UIScrollBar.cs" />
142-
<Compile Include="UIKit\UIScrollView.cs" />
143-
<Compile Include="UIKit\UISlider.cs" />
144-
<Compile Include="UIKit\UITextbox.cs" />
145-
<Compile Include="UIKit\UIView.cs" />
146-
<Compile Include="UIKit\UIWindow.cs" />
147-
<Compile Include="UIKit\UIWrappingLabel.cs" />
148-
</ItemGroup>
149-
<ItemGroup>
150-
<Content Include="build.txt" />
151-
<Content Include="description.txt" />
152-
</ItemGroup>
153-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
154-
<PropertyGroup>
155-
<PostBuildEvent>"C:\Program Files (x86)\Steam\steamapps\common\terraria\tModLoaderServer.exe" -build "$(ProjectDir)\" -eac "$(TargetPath)"</PostBuildEvent>
156-
</PropertyGroup>
157-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
158-
Other similar extension points exist, see Microsoft.Common.targets.
159-
<Target Name="BeforeBuild">
160-
</Target>
161-
<Target Name="AfterBuild">
10+
<Target Name="BuildMod" AfterTargets="Build">
11+
<Exec Command="&quot;$(tMLBuildServerPath)&quot; -build $(ProjectDir) -eac $(TargetPath) -define $(DefineConstants) -unsafe $(AllowUnsafeBlocks)" />
16212
</Target>
163-
-->
16413
</Project>

HEROsModNetwork/Group.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public Group(string name)
7373
Permissions.Add(p.Key, false);
7474
}
7575
Permissions["ModifyTerrain"] = true;
76+
77+
if (name == "Default")
78+
{
79+
Network.DefaultGroup = this;
80+
}
7681
}
7782

7883
public bool HasPermission(string permissionName)

HEROsModNetwork/LoginService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,9 @@ private static void ProcessSetGroupPermissionsRequest(ref BinaryReader reader, i
451451

452452
for (int i = 0; i < Network.Players.Length; i++)
453453
{
454+
//if (Network.Players[i].Group?.ID == group.ID)
454455
if (Network.Players[i].Group == group)
455-
{
456+
{
456457
SendPlayerPermissions(i);
457458
}
458459
}

HEROsModServerConfig.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
using HEROsMod.HEROsModNetwork;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.ComponentModel;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Terraria.ModLoader.Config;
10+
11+
namespace HEROsMod
12+
{
13+
class HEROsModServerConfig : ModConfig
14+
{
15+
public override ConfigScope Mode => ConfigScope.ServerSide;
16+
17+
[Label("Disable Achievements")]
18+
[Tooltip("While this is true, vanilla steam achievements will not be obtained.\nUse this if you don't wish to get achievements illegitimately.")]
19+
[DefaultValue(false)]
20+
public bool DisableAchievements { get; set; }
21+
22+
public override bool AcceptClientChanges(ModConfig pendingConfig, int whoAmI, ref string message)
23+
{
24+
if (Network.Players[whoAmI].Group.IsAdmin)
25+
return true;
26+
27+
message = $"You must be Admin in Heros Mod to change the server permissions.";
28+
return false;
29+
}
30+
}
31+
}
32+
*/

0 commit comments

Comments
 (0)