-
Notifications
You must be signed in to change notification settings - Fork 4
/
UIPlayerBuildCtrl_Patch.cs
66 lines (52 loc) · 2.36 KB
/
UIPlayerBuildCtrl_Patch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using HarmonyLib;
using System.Linq;
namespace PEPatch
{
[HarmonyPatch(typeof(UIPlayerBuildCtrl))]
public class UIPlayerBuildCtrl_Patch
{
[HarmonyPrefix]
[HarmonyPatch("CreatePlayer")]
public static bool CreatePlayer(UIPlayerBuildCtrl __instance)
{
if (Pathea.PeGameMgr.IsMulti)
{
if (__instance.actionOk)
{
__instance.actionOk = false;
__instance.Invoke("ResetActionOK", 2.0f);
var name = Traverse.Create(__instance).Field("mNameInput").Property("text").GetValue<string>();
if (!string.IsNullOrEmpty(name))
{
if (GameClientLobby.Self.myRoles.Any(r => r.deletedFlag ==0 && r.name == name))
{
MessageBox_N.ShowOkBox(PELocalization.GetString(ErrorMessage.NAME_HAS_EXISTED));
return false;
}
var playerModel = Traverse.Create(__instance).Field("mCurrent").GetValue<PlayerModel>();
byte[] appearData = playerModel.mAppearData.Serialize();
byte[] nudeData = playerModel.mNude.Serialize();
var steamId = SteamFriendPrcMgr.Instance.GetMyInfo()._SteamID.m_SteamID;
var roleId = (steamId.GetHashCode() ^ name.GetHashCode()) % 13000000;
var role = new CustomData.RoleInfo()
{
appearData = appearData,
nudeData = nudeData,
name = name,
sex = (byte)(int)Traverse.Create(__instance).Property("Sex").GetValue(),
steamId = steamId,
roleID = roleId
};
GameClientLobby.Self.myRoles.Add(role);
GameClientLobby.Self.myRolesExisted.Add(role);
PatchUtils.SaveMultiplayerData();
MLPlayerInfo.Instance.SetSelectedRole(role.name);
PeSceneCtrl.Instance.GotoMultiRoleScene();
return false;
}
}
}
return true;
}
}
}