Skip to content

Commit

Permalink
上传ChestRestore
Browse files Browse the repository at this point in the history
  • Loading branch information
cjx committed Aug 14, 2024
1 parent e70ce0a commit 1f0bab6
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChestRestore/ChestRestore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\template.targets" />

</Project>
121 changes: 121 additions & 0 deletions ChestRestore/MainPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Newtonsoft.Json;
using Terraria;
using TerrariaApi.Server;
using TShockAPI;

namespace ChestRestore
{
[ApiVersion(2, 1)]
public class MainPlugin : TerrariaPlugin
{
public MainPlugin(Main game) : base(game)
{
}
public override string Name
{
get
{
return "ChestRestore";
}
}
public override Version Version
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version;
}
}
public override string Author
{
get
{
return "Cjx修改";
}
}
public override string Description
{
get
{
return "箱子自动补充资源";
}
}
public override void Initialize()
{
ServerApi.Hooks.NetGetData.Register(this, new HookHandler<GetDataEventArgs>(this.OnGetData));
GetDataHandlers.ChestOpen += new EventHandler<GetDataHandlers.ChestOpenEventArgs>(this.OnChestOpen);
}
private void OnChestOpen(object sender, GetDataHandlers.ChestOpenEventArgs args)
{
int num = Chest.FindChest(args.X, args.Y);
Chest chest = Main.chest[num];
if (chest != null)
{
bool flag = false;
for (int i = 0; i < chest.item.Length; i++)
{
if (chest.item[i].stack != 0)
{
flag = true;
}
}
if (flag)
{
List<NetItem> list = new List<NetItem>();
for (int j = 0; j < chest.item.Length; j++)
{
Item item = chest.item[j];
list.Add(new NetItem(item.netID, item.stack, item.prefix));
}
args.Player.SetData<string>("chestrestore", JsonConvert.SerializeObject(list));
args.Player.SetData<int>("chestx", args.X);
args.Player.SetData<int>("chesty", args.Y);
}
}
}
private void OnGetData(GetDataEventArgs args)
{
if (args.MsgID == PacketTypes.ChestOpen)
{
using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(args.Msg.readBuffer, args.Index, args.Length)))
{
TSPlayer tsplayer = TShock.Players[args.Msg.whoAmI];
int num = (int)binaryReader.ReadInt16();
int num2 = Chest.FindChest(tsplayer.GetData<int>("chestx"), tsplayer.GetData<int>("chesty"));
Chest chest = null;
if (num2 != -1)
{
chest = Main.chest[num2];
}
if (num == -1 && chest != null)
{
List<NetItem> list = JsonConvert.DeserializeObject<List<NetItem>>(tsplayer.GetData<string>("chestrestore"));
for (int i = 0; i < chest.item.Length; i++)
{
Item item = chest.item[i];
item.netDefaults(list[i].NetId);
item.stack = list[i].Stack;
item.prefix = list[i].PrefixId;
TSPlayer.All.SendData(PacketTypes.ChestItem, "", num2, (float)i, 0f, 0f, 0);
}
tsplayer.SetData<string>("chestrestore", "");
tsplayer.SetData<int>("chestx", 0);
tsplayer.SetData<int>("chesty", 0);
}
}
}
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
ServerApi.Hooks.NetGetData.Deregister(this, new HookHandler<GetDataEventArgs>(this.OnGetData));
GetDataHandlers.ChestOpen -= new EventHandler<GetDataHandlers.ChestOpenEventArgs>(this.OnChestOpen);
}
base.Dispose(disposing);
}
}
}
23 changes: 23 additions & 0 deletions ChestRestore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ChestRestore

- 作者: 未知(Cjx修改)
- 资源无限插件

## 更新日志

```
暂无
```

## 指令


## 配置


## 反馈
- 优先发issued -> 共同维护的插件库:https://github.com/Controllerdestiny/TShockPlugin
- 次优先:TShock官方群:816771079
- 大概率看不到但是也可以:国内社区trhub.cn ,bbstr.net , tr.monika.love
12 changes: 11 additions & 1 deletion Plugin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceGen", "Yaaiomni\Sourc
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmartRegions", "SmartRegions\SmartRegions.csproj", "{CBB56AB5-84D6-460A-8D0C-DA85A03BA811}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxyProtocolSocket", "ProxyProtocolSocket\ProxyProtocolSocket.csproj", "{CBCF3F14-A506-435D-BC55-A06FFEB095B2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProxyProtocolSocket", "ProxyProtocolSocket\ProxyProtocolSocket.csproj", "{CBCF3F14-A506-435D-BC55-A06FFEB095B2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnseenInventory", "UnseenInventory\UnseenInventory.csproj", "{5ECADACA-6DD4-47CC-BC23-A1F2A81186DE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChestRestore", "ChestRestore\ChestRestore.csproj", "{0C2924D3-41E7-417A-990D-46AEFF754662}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1116,6 +1118,14 @@ Global
{5ECADACA-6DD4-47CC-BC23-A1F2A81186DE}.Release|Any CPU.Build.0 = Release|Any CPU
{5ECADACA-6DD4-47CC-BC23-A1F2A81186DE}.Release|x64.ActiveCfg = Release|Any CPU
{5ECADACA-6DD4-47CC-BC23-A1F2A81186DE}.Release|x64.Build.0 = Release|Any CPU
{0C2924D3-41E7-417A-990D-46AEFF754662}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C2924D3-41E7-417A-990D-46AEFF754662}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C2924D3-41E7-417A-990D-46AEFF754662}.Debug|x64.ActiveCfg = Debug|Any CPU
{0C2924D3-41E7-417A-990D-46AEFF754662}.Debug|x64.Build.0 = Debug|Any CPU
{0C2924D3-41E7-417A-990D-46AEFF754662}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C2924D3-41E7-417A-990D-46AEFF754662}.Release|Any CPU.Build.0 = Release|Any CPU
{0C2924D3-41E7-417A-990D-46AEFF754662}.Release|x64.ActiveCfg = Release|Any CPU
{0C2924D3-41E7-417A-990D-46AEFF754662}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 1f0bab6

Please sign in to comment.