Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
修复回收时(特殊情况)使用正则匹配无效的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
LazuliKao committed Sep 11, 2020
1 parent b649ea5 commit 3a89205
Show file tree
Hide file tree
Showing 16 changed files with 638 additions and 48 deletions.
Binary file modified .vs/PFSHOP/v16/.suo
Binary file not shown.
439 changes: 439 additions & 0 deletions PFSHOP/BDS/Component.cs

Large diffs are not rendered by default.

79 changes: 70 additions & 9 deletions PFSHOP/BDS/Events.cs
Expand Up @@ -7,6 +7,7 @@
* 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
*/
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text;

Expand Down Expand Up @@ -185,6 +186,23 @@ public struct Vec3 {
public float x, y, z;
}

[StructLayoutAttribute(LayoutKind.Sequential)]
public struct Std_Vector
{
public IntPtr data;
public IntPtr last;
public IntPtr end;
// 从std::vector中读取所有元素(限定为指针)
public ArrayList toList() {
ArrayList al = new ArrayList();
var l = ((ulong)last - (ulong)data) / (ulong)IntPtr.Size;
for (ulong i = 0; i < l; i++) {
al.Add(Marshal.ReadIntPtr(data, (int)(i * (ulong)IntPtr.Size)));
}
return al;
}
}

[StructLayoutAttribute(LayoutKind.Sequential)]
public struct Std_String {
public IntPtr data;
Expand Down Expand Up @@ -404,6 +422,7 @@ public class PlayerEvent : BaseEvent {
protected Vec3 mXYZ;
protected int mdimensionid;
protected bool misstand;
protected IntPtr mplayer;
/// <summary>
/// 玩家名字
/// </summary>
Expand All @@ -424,6 +443,10 @@ public class PlayerEvent : BaseEvent {
/// 玩家是否立足于方块/悬空
/// </summary>
public bool isstand {get{return misstand;}}
/// <summary>
/// 玩家指针
/// </summary>
public IntPtr playerPtr { get { return mplayer; } }
protected void loadData(IntPtr s) {
// 此处为转换过程
mplayername = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 0));
Expand Down Expand Up @@ -464,6 +487,7 @@ public static new FormSelectEvent getFrom(Events e)
fse.muuid = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 40));
fse.mselected = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 48));
fse.mformid = Marshal.ReadInt32(s, 56);
fse.mplayer = Marshal.ReadIntPtr(s, 64);
return fse;
}
}
Expand Down Expand Up @@ -515,7 +539,8 @@ public static new UseItemEvent getFrom(Events e)
ue.mitemid = Marshal.ReadInt16(s, 60);
ue.mitemaux = Marshal.ReadInt16(s, 62);
ue.mblockname = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 64));
ue.mblockid = Marshal.ReadInt16(s, 80);
ue.mblockid = Marshal.ReadInt16(s, 72);
ue.mplayer = Marshal.ReadIntPtr(s, 80);
return ue;
}
}
Expand All @@ -542,6 +567,7 @@ public class BlockEvent : PlayerEvent {
mblockname = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 40));
mposition = (BPos3)Marshal.PtrToStructure(s + 48, typeof(BPos3));
mblockid = Marshal.ReadInt16(s, 60);
mplayer = Marshal.ReadIntPtr(s, 64);
}
}

Expand Down Expand Up @@ -695,6 +721,7 @@ public static new SetSlotEvent getFrom(Events e)
le.mitemaux = Marshal.ReadInt16(s, 76);
le.mblockid = Marshal.ReadInt16(s, 78);
le.mitemid = Marshal.ReadInt16(s, 80);
le.mplayer = Marshal.ReadIntPtr(s, 88);
return le;
}

Expand All @@ -711,6 +738,7 @@ public static new ChangeDimensionEvent getFrom(Events e)
if (le == null)
return null;
le.loadData(e.data);
le.mplayer = Marshal.ReadIntPtr(e.data, 40);
return le;
}
}
Expand All @@ -726,6 +754,7 @@ public class HurtEvent : BaseEvent {
protected int mdimensionid;
protected int mdmcase;
protected bool misstand;
protected IntPtr mmob;
/// <summary>
/// 生物名称
/// </summary>
Expand Down Expand Up @@ -766,6 +795,10 @@ public class HurtEvent : BaseEvent {
/// 玩家是否立足于方块/悬空(附加信息)
/// </summary>
public bool isstand {get{return misstand;}}
/// <summary>
/// 生物指针
/// </summary>
public IntPtr mobPtr { get { return mmob; } }
protected void loadData(IntPtr s) {
// 此处为转换过程
mmobname = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 0));
Expand All @@ -792,6 +825,7 @@ public static new MobDieEvent getFrom(Events e)
if (le == null)
return null;
le.loadData(e.data);
le.mmob = Marshal.ReadIntPtr(e.data, 72);
return le;
}
}
Expand Down Expand Up @@ -826,6 +860,7 @@ public static new MobHurtEvent getFrom(Events e)
le.mdmtype = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 72));
le.mhealth = StrTool.itof(Marshal.ReadInt32(s, 80));
le.mdmcount = Marshal.ReadInt32(s, 84);
le.mmob = Marshal.ReadIntPtr(s, 88);
return le;
}
}
Expand All @@ -841,6 +876,7 @@ public static new RespawnEvent getFrom(Events e)
if (le == null)
return null;
le.loadData(e.data);
le.mplayer = Marshal.ReadIntPtr(e.data, 40);
return le;
}
}
Expand Down Expand Up @@ -902,6 +938,7 @@ public static new InputTextEvent getFrom(Events e)
IntPtr s = e.data;
le.loadData(s);
le.mmsg = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 40));
le.mplayer = Marshal.ReadIntPtr(s, 48);
return le;
}
}
Expand Down Expand Up @@ -942,6 +979,7 @@ public static new CommandBlockUpdateEvent getFrom(Events e)
le.mactortype = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 48));
le.mposition = (BPos3)Marshal.PtrToStructure(s+56, typeof(BPos3));
le.misblock = Marshal.ReadByte(s, 68) == 1;
le.mplayer = Marshal.ReadIntPtr(s, 72);
return le;
}
}
Expand All @@ -964,6 +1002,7 @@ public static new InputCommandEvent getFrom(Events e)
IntPtr s = e.data;
le.loadData(s);
le.mcmd = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 40));
le.mplayer = Marshal.ReadIntPtr(s, 48);
return le;
}
}
Expand Down Expand Up @@ -1034,6 +1073,7 @@ public class NpcCmdEvent : BaseEvent {
protected int mactionid;
protected int mentityid;
protected int mdimensionid;
protected IntPtr mnpc;
/// <summary>
/// NPC名字
/// </summary>
Expand Down Expand Up @@ -1066,6 +1106,10 @@ public class NpcCmdEvent : BaseEvent {
/// NPC所处维度ID
/// </summary>
public int dimensionid {get{return mdimensionid;}}
/// <summary>
/// NPC指针
/// </summary>
public IntPtr npcPtr { get { return mnpc; } }
public static new NpcCmdEvent getFrom(Events e)
{
var le = createHead(e, EventType.onNpcCmd, typeof(NpcCmdEvent)) as NpcCmdEvent;
Expand All @@ -1080,6 +1124,7 @@ public static new NpcCmdEvent getFrom(Events e)
le.mactionid = Marshal.ReadInt32(s, 44);
le.mentityid = Marshal.ReadInt32(s, 48);
le.mdimensionid = Marshal.ReadInt32(s, 52);
le.mnpc = Marshal.ReadIntPtr(s, 56);
return le;
}
}
Expand All @@ -1093,6 +1138,7 @@ public class LoadNameEvent : BaseEvent {
protected string muuid;
protected string mxuid;
protected string mability;
protected IntPtr mplayer;
/// <summary>
/// 玩家名字
/// </summary>
Expand All @@ -1109,16 +1155,26 @@ public class LoadNameEvent : BaseEvent {
/// 玩家能力值列表(可选,商业版可用)
/// </summary>
public string ability {get{return mability;}}
/// <summary>
/// 玩家指针
/// </summary>
public IntPtr playerPtr { get { return mplayer; } }
protected void loadData(IntPtr s)
{
// 此处为转换过程
mplayername = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 0));
muuid = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 8));
mxuid = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 16));
mability = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 24));
mplayer = Marshal.ReadIntPtr(s, 32);
}
public static new LoadNameEvent getFrom(Events e)
{
var le = createHead(e, EventType.onLoadName, typeof(LoadNameEvent)) as LoadNameEvent;
if (le == null)
return null;
IntPtr s = e.data; // 此处为转换过程
le.mplayername = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 0));
le.muuid = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 8));
le.mxuid = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 16));
le.mability = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 24));
le.loadData(s);
return le;
}
}
Expand All @@ -1134,10 +1190,7 @@ public static new PlayerLeftEvent getFrom(Events e)
if (le == null)
return null;
IntPtr s = e.data; // 此处为转换过程
le.mplayername = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 0));
le.muuid = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 8));
le.mxuid = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 16));
le.mability = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 24));
le.loadData(s);
return le;
}
}
Expand All @@ -1149,6 +1202,7 @@ public static new MoveEvent getFrom(Events e)
if (ate == null)
return null;
ate.loadData(e.data);
ate.mplayer = Marshal.ReadIntPtr(e.data, 40);
return ate;
}
}
Expand All @@ -1161,6 +1215,7 @@ public class AttackEvent : PlayerEvent {
protected string mactorname;
protected string mactortype;
protected Vec3 mactorpos;
protected IntPtr mattacked;
/// <summary>
/// 被攻击实体名称
/// </summary>
Expand All @@ -1173,6 +1228,10 @@ public class AttackEvent : PlayerEvent {
/// 被攻击实体所处位置
/// </summary>
public Vec3 actorpos {get{return mactorpos;}}
/// <summary>
/// 被击者实体指针
/// </summary>
public IntPtr attackedentityPtr { get { return mattacked; } }
public static new AttackEvent getFrom(Events e)
{
var ate = createHead(e, EventType.onAttack, typeof(AttackEvent)) as AttackEvent;
Expand All @@ -1183,6 +1242,8 @@ public static new AttackEvent getFrom(Events e)
ate.mactorname = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 40));
ate.mactortype = StrTool.readUTF8str((IntPtr)Marshal.ReadInt64(s, 48));
ate.mactorpos = (Vec3)Marshal.PtrToStructure(s + 56, typeof(Vec3));
ate.mplayer = Marshal.ReadIntPtr(s, 72);
ate.mattacked = Marshal.ReadIntPtr(s, 80);
return ate;
}
}
Expand Down
43 changes: 37 additions & 6 deletions PFSHOP/BDS/MCCSAPI.cs
Expand Up @@ -133,7 +133,7 @@ public enum CommandCheatFlag : byte {
private delegate bool RENAMEBYUUIDFUNC(string uuid, string newName);
private RENAMEBYUUIDFUNC creNameByUuid, csetPlayerAbilities, csetPlayerTempAttributes,
csetPlayerMaxAttributes, csetPlayerItems, caddPlayerItemEx, csetPlayerEffects,
ctalkAs, cruncmdAs, csetPlayerPermissionAndGametype;
ctalkAs, cruncmdAs, cdisconnectClient, csetPlayerPermissionAndGametype;
private delegate Std_String GETPLAYERABILITIESFUNC(string uuid);
private GETPLAYERABILITIESFUNC cgetPlayerAbilities, cgetPlayerAttributes, cgetPlayerMaxAttributes,
cgetPlayerItems, cgetPlayerSelectedItem, cgetPlayerEffects, cselectPlayer, cgetPlayerPermissionAndGametype;
Expand All @@ -158,10 +158,10 @@ public enum CommandCheatFlag : byte {
private delegate int GETSCOREBOARDVALUEFUNC(string uuid, string objname);
private GETSCOREBOARDVALUEFUNC cgetscoreboardValue;
private delegate IntPtr GETEXTRAAPI(string apiname);
GETEXTRAAPI cgetExtraAPI;
private GETEXTRAAPI cgetExtraAPI;

// 转换附加函数指针
private T ConvertExtraFunc<T>(string apiname) where T : Delegate
private T ConvertExtraFunc<T>(string apiname) where T : Delegate
{
if (cgetExtraAPI != null) {
IntPtr f = cgetExtraAPI(apiname);
Expand All @@ -174,7 +174,26 @@ public enum CommandCheatFlag : byte {
Console.WriteLine("Get ExtraApi {0} failed.", apiname);
return null;
}


private delegate IntPtr MCCOMPONENTAPI(string apiname);
private MCCOMPONENTAPI cmcComponentAPI;
// 获取组件相关API
public T ConvertComponentFunc<T>(string apiname) where T : Delegate
{
if (cmcComponentAPI != null)
{
IntPtr f = cmcComponentAPI(apiname);
if (f != IntPtr.Zero)
{
return (T)Marshal.GetDelegateForFunctionPointer(f, typeof(T));
//若.net framework版本高于4.5.1可用以下替换以上
//return Marshal.GetDelegateForFunctionPointer<T>(f);
}
}
Console.WriteLine("Get ComponentApi {0} failed.", apiname);
return null;
}

// 初始化所有api函数
void initApis()
{
Expand All @@ -190,9 +209,11 @@ void initApis()
clogout = Invoke<LOGOUTFUNC>("logout");
cgetOnLinePlayers = Invoke<GETONLINEPLAYERSFUNC>("getOnLinePlayers");
cgetExtraAPI = Invoke<GETEXTRAAPI>("getExtraAPI");
cmcComponentAPI = Invoke<MCCOMPONENTAPI>("mcComponentAPI");
creNameByUuid = Invoke<RENAMEBYUUIDFUNC>("reNameByUuid");
ctalkAs = Invoke<RENAMEBYUUIDFUNC>("talkAs");
cruncmdAs = Invoke<RENAMEBYUUIDFUNC>("runcmdAs");
cdisconnectClient = Invoke<RENAMEBYUUIDFUNC>("disconnectClient");
csendSimpleForm = Invoke<SENDSIMPLEFORMFUNC>("sendSimpleForm");
csendModalForm = Invoke<SENDMODALFORMFUNC>("sendModalForm");
csendCustomForm = Invoke<SENDCUSTOMFORMFUNC>("sendCustomForm");
Expand Down Expand Up @@ -686,7 +707,17 @@ private void removecb(string k, EventCab cb)
public bool runcmdAs(string uuid, string cmd) {
return (cruncmdAs != null) && cruncmdAs(uuid, cmd);
}


/// <summary>
/// 断开一个玩家的连接
/// </summary>
/// <param name="uuid">在线玩家的uuid字符串</param>
/// <param name="tips">断开提示(设空值则为默认值)</param>
/// <returns></returns>
public bool disconnectClient(string uuid, string tips) {
return (cdisconnectClient != null) && cdisconnectClient(uuid, tips);
}

/// <summary>
/// 向指定的玩家发送一个简单表单
/// </summary>
Expand Down
13 changes: 11 additions & 2 deletions PFSHOP/Language.cs
Expand Up @@ -16,8 +16,16 @@ public class Language
public string ClosedFormWithoutAction = "§7表单已关闭,未收到操作";
public string sellMainTitle = "点击选择你想要购买的物品";
public string sellMainContent = "";
public string sellPreviousList = "<==返回上级菜单";
public string sellSubList = "§l{0}\n§o子菜单==>";
public string sellListItem = "#{0}§l{1}\n{2}像素币/个";

public string recycleMainTitle = "点击选择你想要回收的物品";
public string recycleMainContent = "";
public string recyclePreviousList = "<==返回上级菜单";
public string recycleSubList = "§l{0}\n§o子菜单==>";
public string recycleListItem = "#{0}§l{1}\n{2}像素币/个";

public string InputSellDetailTitle = "输入购买数量";
public string InputRecycleDetailTitle = "输入回收数量";
public string InputSellDetailContentWhenUseSlider = "\n您已选择 {0}\n\n拖动滑块选择购买数量\n单价:{1}\n §l§5X§r\n数量";
Expand All @@ -41,10 +49,10 @@ public class Language
public string confirmRecycleCancel = "我再想想";
public string confirmRecycleCanceled = "回收已取消";

public string buySuccessfullyTitle = "\n\n\n§b购买成功";
public string buySuccessfullyTitle = "\n\n\n§b购买成功";
public string buySuccessfullySubtitle = "已花费 {0} 像素币\n购买 {1} 个 {2}";
public string buyFailedTitle = "\n\n\n§c购买失败!";
public string buyFailedSubtitle= "购买 {1} 个 {2} 需要 {0} 像素币";
public string buyFailedSubtitle = "购买 {1} 个 {2} 需要 {0} 像素币";

public string recycleGetItemApiFailed = "API获取失败";
public string recycleGetItemApiFailedDetail = "api.getPlayerItems()函数尚不支持,请使用CSR商业版运行本插件";
Expand All @@ -55,6 +63,7 @@ public class Language
public string recycleFailedSubtitle = "你背包里只有 {3} 个 {2}";



#region preferenceMain
public string preferenceMainTitle = "个人偏好设置";
public string preferenceMainSellText = "●出售商店\n 数量输入方式";
Expand Down

0 comments on commit 3a89205

Please sign in to comment.