using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Steamworks;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
public class AedenthornUtils
{
public static bool IgnoreKeyPresses(bool extra = false)
{
int result;
if (!extra)
{
if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog())
{
Chat instance = Chat.instance;
if (instance == null || !instance.HasFocus())
{
result = (Menu.IsVisible() ? 1 : 0);
goto IL_005f;
}
}
result = 1;
goto IL_005f;
}
int result2;
if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog())
{
Chat instance2 = Chat.instance;
if ((instance2 == null || !instance2.HasFocus()) && !StoreGui.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible())
{
TextViewer instance3 = TextViewer.instance;
result2 = ((instance3 != null && instance3.IsVisible()) ? 1 : 0);
goto IL_00d9;
}
}
result2 = 1;
goto IL_00d9;
IL_005f:
return (byte)result != 0;
IL_00d9:
return (byte)result2 != 0;
}
public static bool CheckKeyDown(string value)
{
try
{
return Input.GetKeyDown(value.ToLower());
}
catch
{
return false;
}
}
public static bool CheckKeyHeld(string value, bool req = true)
{
try
{
return Input.GetKey(value.ToLower());
}
catch
{
return !req;
}
}
}
namespace ServerRewards;
[BepInPlugin("aedenthorn.ServerRewards", "Server Rewards", "0.8.0")]
public class BepInExPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(ZNet), "Awake")]
public static class ZNet_Awake_Patch
{
public static void Postfix(ZNet __instance)
{
if (modEnabled.Value)
{
Dbgl($"ZNet Awake! Server? {__instance.IsServer()}");
if (__instance.IsServer())
{
((MonoBehaviour)context).InvokeRepeating("UpdatePlayersRepeated", 1f, (float)updateInterval.Value);
}
}
}
}
[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
public static class ZNet_OnNewConnection_Patch
{
public static void Postfix(ZNet __instance, ZNetPeer peer)
{
if (modEnabled.Value)
{
Dbgl("New connection");
peer.m_rpc.Register<string>("SendServerRewardsJSON", (Action<ZRpc, string>)RPC_SendJSON);
if (__instance.IsServer())
{
peer.m_rpc.Register<string>("ServerRewardsConsoleCommand", (Action<ZRpc, string>)RPC_ConsoleCommand);
context.UpdatePlayers(forced: true);
}
}
}
}
[HarmonyPatch(typeof(PlayerController), "TakeInput")]
private static class TakeInput_Patch
{
private static bool Prefix(ref bool __result)
{
if (!modEnabled.Value || !storeOpen)
{
return true;
}
__result = false;
return false;
}
}
[HarmonyPatch(typeof(Player), "InCutscene")]
private static class InCutscene_Patch
{
private static bool Prefix(ref bool __result)
{
if (!modEnabled.Value || !storeOpen)
{
return true;
}
__result = true;
return false;
}
}
[HarmonyPatch(typeof(TombStone), "GetHoverText")]
private static class TombStone_GetHoverText_Patch
{
private static bool Prefix(ZNetView ___m_nview, ref string __result)
{
if (!modEnabled.Value)
{
return true;
}
object obj;
if (___m_nview == null)
{
obj = null;
}
else
{
ZDO zDO = ___m_nview.GetZDO();
obj = ((zDO != null) ? zDO.GetString("ServerReward", (string)null) : null);
}
string text = (string)obj;
if (text != null)
{
__result = text;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Terminal), "InputText")]
private static class InputText_Patch
{
private static bool Prefix(Terminal __instance)
{
if (!modEnabled.Value)
{
return true;
}
string text = ((TMP_InputField)__instance.m_input).text;
if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset"))
{
((BaseUnityPlugin)context).Config.Reload();
((BaseUnityPlugin)context).Config.Save();
ApplyConfig();
Traverse.Create((object)__instance).Method("AddString", new object[1] { text }).GetValue();
Traverse.Create((object)__instance).Method("AddString", new object[1] { ((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded" }).GetValue();
return false;
}
if (text.ToLower().StartsWith(typeof(BepInExPlugin).Namespace.ToLower() + " "))
{
ZRpc serverRPC = ZNet.instance.GetServerRPC();
if (serverRPC != null)
{
serverRPC.Invoke("ServerRewardsConsoleCommand", new object[1] { text });
}
Traverse.Create((object)__instance).Method("AddString", new object[1] { text }).GetValue();
return false;
}
return true;
}
}
public static ConfigEntry<bool> modEnabled;
public static ConfigEntry<bool> isDebug;
public static ConfigEntry<bool> testing;
public static ConfigEntry<int> nexusID;
public static ConfigEntry<int> updateInterval;
public static ConfigEntry<string> openUIKey;
public static ConfigEntry<int> updateIntervalReward;
public static ConfigEntry<int> staticLoginReward;
public static ConfigEntry<string> consecutiveLoginReward;
public static ConfigEntry<bool> consecutiveLoginRewardOnce;
public static ConfigEntry<int> playerStartCurrency;
public static ConfigEntry<bool> useTombstone;
public static ConfigEntry<bool> coinBeforeAmount;
public static ConfigEntry<float> windowWidth;
public static ConfigEntry<float> windowHeight;
public static ConfigEntry<Vector2> windowPosition;
public static ConfigEntry<int> titleFontSize;
public static ConfigEntry<int> currencyFontSize;
public static ConfigEntry<int> labelFontSize;
public static ConfigEntry<int> tooltipFontSize;
public static ConfigEntry<int> packagesPerRow;
public static ConfigEntry<string> storeTitleString;
public static ConfigEntry<string> currencyString;
public static ConfigEntry<string> packageString;
public static ConfigEntry<string> myCurrencyString;
public static ConfigEntry<string> packageInfoString;
public static ConfigEntry<string> rewardString;
public static ConfigEntry<Color> windowBackgroundColor;
public static ConfigEntry<Color> tooltipBackgroundColor;
public static ConfigEntry<Color> tooltipTextColor;
private static BepInExPlugin context;
private static int myCurrency;
private static bool storeOpen;
private static float coinFactor = 0.75f;
private static Vector2 scrollPosition;
private static GUIStyle titleStyle;
private static GUIStyle currencyStyle;
private static GUIStyle labelStyle;
private static GUIStyle tooltipStyle;
private static Texture2D tooltipBackground;
private static GUIStyle coinStyle;
private static GUIStyle tooltipWindowStyle;
private static Rect windowRect;
private static string windowTitleText;
private static List<PackageInfo> storePackages = new List<PackageInfo>();
private static Dictionary<string, Texture2D> textureDict = new Dictionary<string, Texture2D>();
private string thisTooltip;
public static void Dbgl(string str = "", bool pref = true)
{
if (isDebug.Value)
{
Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
}
}
private void Awake()
{
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0323: Unknown result type (might be due to invalid IL or missing references)
//IL_0347: Unknown result type (might be due to invalid IL or missing references)
//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
//IL_04bc: Expected O, but got Unknown
context = this;
modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
isDebug = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "IsDebug", true, "Enable debug logs");
testing = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Testing", false, "Enable mod testing mode (populates store locally)");
nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 1131, "Nexus mod ID for updates");
openUIKey = ((BaseUnityPlugin)this).Config.Bind<string>("Config", "OpenUIKey", "f10", "Key to open currency UI");
updateInterval = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "UpdateInterval", 60, "Update interval in seconds (server only)");
useTombstone = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UseTombstone", false, "Place items in a tombstone instead of dropping on ground.");
updateIntervalReward = ((BaseUnityPlugin)this).Config.Bind<int>("Currency", "UpdateIntervalReward", 1, "Currency awarded every update interval");
staticLoginReward = ((BaseUnityPlugin)this).Config.Bind<int>("Currency", "StaticLoginReward", 100, "Currency awarded for logging in");
consecutiveLoginReward = ((BaseUnityPlugin)this).Config.Bind<string>("Currency", "ConsecutiveLoginReward", "100,200,300,400,500,600,700", "Login rewards for logging in a consecutive number of days");
consecutiveLoginRewardOnce = ((BaseUnityPlugin)this).Config.Bind<bool>("Currency", "ConsecutiveLoginRewardOnce", true, "Consecutive login reward only applies once, otherwise repeats from start");
playerStartCurrency = ((BaseUnityPlugin)this).Config.Bind<int>("Currency", "PlayerStartCurrency", 0, "Players start with this amount of currency.");
windowWidth = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "WindowWidth", (float)(Screen.width / 3), "Width of the store window");
windowHeight = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "WindowHeight", (float)(Screen.height / 3), "Height of the store window");
windowPosition = ((BaseUnityPlugin)this).Config.Bind<Vector2>("UI", "WindowPosition", new Vector2((float)(Screen.width / 3), (float)(Screen.height / 3)), "Position of the store window");
packagesPerRow = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "PackagesPerRow", 4, "Packages per row");
titleFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "TitleFontSize", 24, "Size of the store window title");
currencyFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "CurrencyFontSize", 20, "Size of the currency info");
labelFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "LabelFontSize", 20, "Size of the package labels");
tooltipFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "TooltipFontSize", 16, "Size of the tooltip text");
coinBeforeAmount = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "CoinBeforeAmount", true, "Display the currency icon before the amount? Otherwise after");
windowBackgroundColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Colors", "WindowBackgroundColor", new Color(0f, 0f, 0f, 0.5f), "Store window background color");
tooltipBackgroundColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Colors", "TooltipBackgroundColor", Color.black, "Tooltip background color");
tooltipTextColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Colors", "TooltipTextColor", Color.white, "Tooltip background color");
storeTitleString = ((BaseUnityPlugin)this).Config.Bind<string>("Text", "StoreTitle", "<b><color=#FFFFFFFF>Server Store</color></b>", "Store window title");
currencyString = ((BaseUnityPlugin)this).Config.Bind<string>("Text", "CurrencyString", "<b><color=#FFFF00FF>{0}</color></b>", "Currency string");
myCurrencyString = ((BaseUnityPlugin)this).Config.Bind<string>("Text", "MyCurrencyString", "<b><color=#FFFFFFFF>My Balance:</color></b>", "My currency string");
packageString = ((BaseUnityPlugin)this).Config.Bind<string>("Text", "PackageString", "<b><color=#FFFFFFFF>{0}</color></b>", "Package string");
packageInfoString = ((BaseUnityPlugin)this).Config.Bind<string>("Text", "PackageInfoString", "{0} chest purchased by {1}", "Reward string to show on the tombstone. {0} is replaced by the package name, {1} is replaced by the player name.");
rewardString = ((BaseUnityPlugin)this).Config.Bind<string>("Text", "RewardString", "You received a {0}!", "Reward string to show when dropping items in world.");
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ServerRewards");
if (!Directory.Exists(text))
{
Dbgl("Creating mod folder");
Directory.CreateDirectory(text);
}
string path = Path.Combine(text, "Assets");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string[] files = Directory.GetFiles(path, "*.png");
foreach (string path2 in files)
{
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, false);
byte[] array = File.ReadAllBytes(path2);
ImageConversion.LoadImage(val, array);
textureDict.Add(Path.GetFileNameWithoutExtension(path2), val);
}
string path3 = Path.Combine(text, "PlayerInfo");
if (!Directory.Exists(path3))
{
Directory.CreateDirectory(path3);
}
string text2 = Path.Combine(text, "StoreInfo");
if (!Directory.Exists(text2))
{
Directory.CreateDirectory(text2);
PackageInfo packageInfo = new PackageInfo
{
name = "Shields",
id = "Shields",
type = "Common",
price = 50,
items = new List<string> { "ShieldWood,1,70,choice", "ShieldBronzeBuckler,1,30,choice" }
};
File.WriteAllText(Path.Combine(text2, packageInfo.id + ".json"), JsonUtility.ToJson((object)packageInfo));
}
if (testing.Value)
{
storePackages = GetAllPackages();
myCurrency = 805;
}
windowTitleText = storeTitleString.Value;
ApplyConfig();
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
}
private static void ApplyConfig()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Expected O, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Expected O, but got Unknown
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Expected O, but got Unknown
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Expected O, but got Unknown
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
windowRect = new Rect(windowPosition.Value.x, windowPosition.Value.y, windowWidth.Value, windowHeight.Value);
titleStyle = new GUIStyle
{
richText = true,
fontSize = titleFontSize.Value,
wordWrap = true,
alignment = (TextAnchor)4
};
currencyStyle = new GUIStyle
{
richText = true,
fontSize = currencyFontSize.Value,
wordWrap = true,
alignment = (TextAnchor)3
};
labelStyle = new GUIStyle
{
richText = true,
fontSize = labelFontSize.Value,
wordWrap = true,
alignment = (TextAnchor)4
};
coinStyle = new GUIStyle
{
alignment = (TextAnchor)4
};
tooltipStyle = new GUIStyle
{
richText = true,
fontSize = tooltipFontSize.Value,
wordWrap = true,
alignment = (TextAnchor)3
};
tooltipBackground = new Texture2D(1, 1, (TextureFormat)5, false);
tooltipBackground.SetPixel(0, 0, tooltipBackgroundColor.Value);
tooltipBackground.Apply();
}
private void Update()
{
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
if (!modEnabled.Value)
{
return;
}
if (testing.Value)
{
if (AedenthornUtils.CheckKeyDown(openUIKey.Value))
{
storeOpen = !storeOpen;
}
}
else
{
if (!Object.op_Implicit((Object)(object)ZNet.instance) || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || AedenthornUtils.IgnoreKeyPresses(extra: true) || !AedenthornUtils.CheckKeyDown(openUIKey.Value))
{
return;
}
Dbgl("Pressed hotkey");
if (storeOpen)
{
Traverse.Create((object)GameCamera.instance).Field("m_mouseCapture").SetValue((object)true);
Cursor.lockState = (CursorLockMode)1;
Cursor.visible = false;
Dbgl("Closing store");
storeOpen = false;
return;
}
ZRpc serverRPC = ZNet.instance.GetServerRPC();
if (serverRPC != null)
{
Dbgl("Requesting store data");
JsonCommand obj = new JsonCommand
{
command = "RequestStoreInfo"
};
CSteamID steamID = SteamUser.GetSteamID();
obj.id = ((object)(CSteamID)(ref steamID)).ToString();
JsonCommand jsonCommand = obj;
string text = JsonUtility.ToJson((object)jsonCommand);
Dbgl(text);
serverRPC.Invoke("SendServerRewardsJSON", new object[1] { text });
}
}
}
private void OnGUI()
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Expected O, but got Unknown
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Expected O, but got Unknown
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_0270: Unknown result type (might be due to invalid IL or missing references)
//IL_0280: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Expected O, but got Unknown
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
//IL_030c: Unknown result type (might be due to invalid IL or missing references)
if (!modEnabled.Value)
{
return;
}
if (thisTooltip != null && thisTooltip.Length > 0)
{
if (!storeOpen)
{
thisTooltip = null;
}
else
{
tooltipWindowStyle = new GUIStyle(GUI.skin.window);
tooltipWindowStyle.normal.background = tooltipBackground;
GUI.Window(424244, new Rect(Input.mousePosition.x + 30f, (float)Screen.height - Input.mousePosition.y + 30f, 400f, 80f), new WindowFunction(TooltipBuilder), thisTooltip.Split(new char[1] { '^' })[0], tooltipWindowStyle);
}
}
if (testing.Value)
{
if (storeOpen)
{
if (Object.op_Implicit((Object)(object)GameCamera.instance))
{
Traverse.Create((object)GameCamera.instance).Field("m_mouseCapture").SetValue((object)false);
Cursor.lockState = (CursorLockMode)0;
Cursor.visible = ZInput.IsMouseActive();
}
GUI.backgroundColor = windowBackgroundColor.Value;
windowRect = GUI.Window(424243, windowRect, new WindowFunction(WindowBuilder), "");
if (!Input.GetKey((KeyCode)323) && (((Rect)(ref windowRect)).x != windowPosition.Value.x || ((Rect)(ref windowRect)).y != windowPosition.Value.y))
{
windowPosition.Value = new Vector2(((Rect)(ref windowRect)).x, ((Rect)(ref windowRect)).y);
}
}
return;
}
ZNet instance = ZNet.instance;
if (instance != null && !instance.IsServer() && Object.op_Implicit((Object)(object)Player.m_localPlayer))
{
if (storeOpen)
{
Traverse.Create((object)GameCamera.instance).Field("m_mouseCapture").SetValue((object)false);
Cursor.lockState = (CursorLockMode)0;
Cursor.visible = ZInput.IsMouseActive();
GUI.backgroundColor = windowBackgroundColor.Value;
windowRect = GUI.Window(424243, windowRect, new WindowFunction(WindowBuilder), "");
}
if (!Input.GetKey((KeyCode)323) && (((Rect)(ref windowRect)).x != windowPosition.Value.x || ((Rect)(ref windowRect)).y != windowPosition.Value.y))
{
windowPosition.Value = new Vector2(((Rect)(ref windowRect)).x, ((Rect)(ref windowRect)).y);
}
}
}
private void TooltipBuilder(int id)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
if (thisTooltip != null && thisTooltip.Length != 0)
{
tooltipStyle.normal.textColor = tooltipTextColor.Value;
GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(windowWidth.Value) });
GUILayout.Label(thisTooltip.Split(new char[1] { '^' })[1], tooltipStyle, Array.Empty<GUILayoutOption>());
GUILayout.EndVertical();
}
}
private void WindowBuilder(int id)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0339: Unknown result type (might be due to invalid IL or missing references)
//IL_035b: Expected O, but got Unknown
GUI.DragWindow(new Rect(0f, 0f, windowWidth.Value, 20f));
GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(windowWidth.Value) });
GUILayout.Label(windowTitleText, titleStyle, Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Label(myCurrencyString.Value, currencyStyle, Array.Empty<GUILayoutOption>());
if (coinBeforeAmount.Value)
{
GUILayout.Space(5f);
GUILayout.Button((Texture)(object)(textureDict.ContainsKey("currency") ? textureDict["currency"] : null), coinStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width((float)currencyFontSize.Value * coinFactor),
GUILayout.Height((float)currencyFontSize.Value)
});
}
GUILayout.Space(5f);
GUILayout.Label(string.Format(currencyString.Value, myCurrency), currencyStyle, Array.Empty<GUILayoutOption>());
if (!coinBeforeAmount.Value)
{
GUILayout.Space(5f);
GUILayout.Button((Texture)(object)(textureDict.ContainsKey("currency") ? textureDict["currency"] : null), coinStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width((float)currencyFontSize.Value * coinFactor),
GUILayout.Height((float)currencyFontSize.Value)
});
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
float num = windowWidth.Value - 70f;
float num2 = num / (float)packagesPerRow.Value;
scrollPosition = GUILayout.BeginScrollView(scrollPosition, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(windowWidth.Value - 20f) });
GUILayout.Space(10f);
GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num) });
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
storePackages.Sort((PackageInfo a, PackageInfo b) => a.price.CompareTo(b.price));
for (int i = 0; i < storePackages.Count; i++)
{
if (i > 0 && i % packagesPerRow.Value == 0)
{
GUILayout.EndHorizontal();
GUILayout.Space(10f);
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
}
PackageInfo packageInfo = storePackages[i];
string text = (textureDict.ContainsKey(packageInfo.type) ? packageInfo.type : "Common");
if (!textureDict.ContainsKey(text))
{
Dbgl("Missing texture for " + text + " type");
continue;
}
GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num2) });
if (GUILayout.Button(new GUIContent((Texture)(object)textureDict[text], packageInfo.name + "^" + packageInfo.description), (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(num2),
GUILayout.Height(num2)
}) && myCurrency >= packageInfo.price)
{
if (testing.Value)
{
myCurrency -= packageInfo.price;
storeOpen = false;
PlayEffects();
}
else
{
ZRpc serverRPC = ZNet.instance.GetServerRPC();
if (serverRPC != null)
{
Dbgl("Requesting store data");
JsonCommand jsonCommand = new JsonCommand
{
command = "BuyPackage",
packageid = packageInfo.id
};
string text2 = JsonUtility.ToJson((object)jsonCommand);
Dbgl(text2);
serverRPC.Invoke("SendServerRewardsJSON", new object[1] { text2 });
}
}
}
GUILayout.Label(string.Format(packageString.Value, packageInfo.name), labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num2) });
GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(num2) });
GUILayout.FlexibleSpace();
if (coinBeforeAmount.Value)
{
GUILayout.Button((Texture)(object)textureDict["currency"], coinStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width((float)labelFontSize.Value * coinFactor),
GUILayout.Height((float)labelFontSize.Value)
});
GUILayout.Space(5f);
}
GUILayout.Label(string.Format(currencyString.Value, packageInfo.price), labelStyle, Array.Empty<GUILayoutOption>());
if (!coinBeforeAmount.Value)
{
GUILayout.Space(5f);
GUILayout.Button((Texture)(object)textureDict["currency"], coinStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width((float)labelFontSize.Value * coinFactor),
GUILayout.Height((float)labelFontSize.Value)
});
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
if (GUI.tooltip != null && GUI.tooltip.Length > 0)
{
thisTooltip = GUI.tooltip;
}
else
{
thisTooltip = null;
}
GUILayout.EndHorizontal();
GUILayout.Space(10f);
GUILayout.EndVertical();
GUILayout.EndScrollView();
GUILayout.EndVertical();
}
private static void RPC_ConsoleCommand(ZRpc rpc, string command)
{
//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
//IL_04da: Unknown result type (might be due to invalid IL or missing references)
//IL_04df: Unknown result type (might be due to invalid IL or missing references)
//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
if (!modEnabled.Value || !ZNet.instance.IsServer())
{
return;
}
ZNetPeer value = Traverse.Create((object)ZNet.instance).Method("GetPeer", new object[1] { rpc }).GetValue<ZNetPeer>();
string peerID = GetPeerID(value);
Dbgl("RPC_ConsoleCommand received command " + command + " from " + peerID);
if (!Traverse.Create((object)ZNet.instance).Field("m_adminList").GetValue<SyncedList>()
.Contains(rpc.GetSocket().GetHostName()))
{
Dbgl("User is not admin!");
return;
}
string[] array = command.Split(new char[1] { ' ' }).Skip(1).ToArray();
string text = "";
if (array[0] == "help")
{
text = "Usage:\r\nserverrewards list users\r\nserverrewards list packages\r\nserverrewards give <steamID> <currency>\r\nserverrewards give all <currency>\r\nserverrewards set <steamID> <currency>\r\nserverrewards set all <currency>\r\nserverrewards givepackage <steamID> <packageID>\r\nserverrewards givepackage all <packageID>\r\nserverrewards spawn <spawnName>";
}
else if (array[0] == "list" && array.Length == 2)
{
if (array[1] == "users")
{
List<string> list = new List<string>();
List<string> allPlayerIDs = GetAllPlayerIDs();
List<ZNetPeer> connectedPeers = ZNet.instance.GetConnectedPeers();
foreach (string user in allPlayerIDs)
{
string text2 = "(offline)";
ZNetPeer val = connectedPeers.Find((ZNetPeer p) => GetPeerID(p) == user);
if (val != null)
{
text2 = val.m_playerName + " (online)";
}
list.Add(user + " " + text2);
}
text = string.Join("\r\n", list);
}
else if (array[1] == "packages")
{
List<string> list2 = new List<string>();
List<PackageInfo> allPackages = GetAllPackages();
foreach (PackageInfo item in allPackages)
{
list2.Add(item.id + " " + item.price);
}
text = string.Join("\r\n", list2);
}
else
{
text = "Syntax error.";
}
}
else if (array[0] == "give" && array.Length == 3)
{
try
{
string steamID = GetSteamID(array[1]);
text = ((steamID == null) ? "User not found." : ((!AdjustCurrency(steamID, int.Parse(array[2]))) ? "Error adjusting player balance." : "Balance adjusted."));
}
catch
{
text = "Syntax error.";
}
}
else if (array[0] == "set" && array.Length == 3)
{
try
{
string steamID2 = GetSteamID(array[1]);
text = ((steamID2 == null) ? "User not found." : ((!SetCurrency(steamID2, int.Parse(array[2]))) ? "Error setting player balance." : "Balance set."));
}
catch
{
text = "Syntax error.";
}
}
else if (array[0] == "givepackage" && array.Length == 3)
{
if (array[1] == "all")
{
IEnumerable<string> allPlayerIDs2 = GetAllPlayerIDs();
int num = 0;
foreach (string item2 in allPlayerIDs2)
{
string text3 = GivePackage(array[1], array[2]);
if (text3 == null)
{
num++;
}
}
text = $"Package sent to {num} users!";
}
else
{
string steamID3 = GetSteamID(array[1]);
if (steamID3 == null)
{
text = "User not found.";
}
else
{
text = GivePackage(steamID3, array[2]);
if (text == null)
{
text = "Package sent!";
}
}
}
}
else if (array[0] == "spawn" && array.Length == 2)
{
GameObject prefab = ZNetScene.instance.GetPrefab(array[1]);
if (!Object.op_Implicit((Object)(object)prefab))
{
text = "Item " + array[1] + " not found!";
}
else
{
GameObject val2 = Object.Instantiate<GameObject>(prefab, ((Component)Player.m_localPlayer).transform.position + ((Component)Player.m_localPlayer).transform.forward * 2f + Vector3.up, Quaternion.identity);
((Character)Player.m_localPlayer).Message((MessageType)1, string.Format(packageInfoString.Value, Localization.instance.Localize(val2.GetComponent<ItemDrop>().m_itemData.m_shared.m_name)), 0, (Sprite)null);
}
}
else
{
text = "Syntax error.";
}
JsonCommand jsonCommand = new JsonCommand
{
command = "SendConsoleString",
data = text
};
rpc.Invoke("SendServerRewardsJSON", new object[1] { JsonUtility.ToJson((object)jsonCommand) });
Dbgl(text);
}
private static void RPC_SendJSON(ZRpc rpc, string json)
{
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Expected O, but got Unknown
//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
//IL_03af: Unknown result type (might be due to invalid IL or missing references)
//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
//IL_06a3: Unknown result type (might be due to invalid IL or missing references)
//IL_06b2: Unknown result type (might be due to invalid IL or missing references)
//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
//IL_06c6: Unknown result type (might be due to invalid IL or missing references)
//IL_06cb: Unknown result type (might be due to invalid IL or missing references)
//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
//IL_074a: Unknown result type (might be due to invalid IL or missing references)
//IL_0754: Unknown result type (might be due to invalid IL or missing references)
//IL_0759: Unknown result type (might be due to invalid IL or missing references)
//IL_0767: Unknown result type (might be due to invalid IL or missing references)
//IL_0776: Unknown result type (might be due to invalid IL or missing references)
//IL_0780: Unknown result type (might be due to invalid IL or missing references)
//IL_0785: Unknown result type (might be due to invalid IL or missing references)
//IL_078a: Unknown result type (might be due to invalid IL or missing references)
//IL_078f: Unknown result type (might be due to invalid IL or missing references)
//IL_0794: Unknown result type (might be due to invalid IL or missing references)
//IL_0796: Unknown result type (might be due to invalid IL or missing references)
//IL_079b: Unknown result type (might be due to invalid IL or missing references)
if (!modEnabled.Value)
{
return;
}
JsonCommand command = JsonUtility.FromJson<JsonCommand>(json);
Dbgl("RPC_SendJSON received command " + command.command + " " + json + " from id " + command.id);
ZNetPeer val = (ZNetPeer)AccessTools.Method(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(ZNet.instance, new object[1] { rpc });
if (val == null)
{
Dbgl("Peer is null, aborting");
return;
}
string peerID = GetPeerID(val);
if (ZNet.instance.IsServer())
{
if (peerID == null)
{
Dbgl("steamID is null, aborting");
return;
}
context.UpdatePlayers(forced: true);
if (command.command == "BuyPackage")
{
List<PackageInfo> allPackages = GetAllPackages();
PackageInfo packageInfo;
try
{
packageInfo = allPackages.First((PackageInfo p) => p.id == command.packageid);
}
catch
{
Dbgl("Package " + command.packageid + " not found");
return;
}
PlayerInfo player = GetPlayerInfo(peerID);
if (!CanBuyPackage(ref player, packageInfo, checkCurrency: true, checkLimit: true, out var result))
{
WritePlayerData(player);
return;
}
Dbgl(result);
player.currency -= packageInfo.price;
WritePlayerData(player);
JsonCommand jsonCommand = new JsonCommand
{
command = "PurchaseResult",
currency = player.currency,
packageid = packageInfo.id,
packagename = packageInfo.name,
packagedescription = packageInfo.description,
items = GetPackageItems(packageInfo, player)
};
rpc.Invoke("SendServerRewardsJSON", new object[1] { JsonUtility.ToJson((object)jsonCommand) });
}
else if (command.command == "RequestStoreInfo")
{
int userCurrency = GetUserCurrency(peerID);
if (userCurrency == -1)
{
Dbgl("Error getting store info");
return;
}
PlayerInfo playerInfo = GetPlayerInfo(peerID);
JsonCommand jsonCommand2 = new JsonCommand
{
command = "SendStoreInfo",
storeTitle = storeTitleString.Value,
storeInventory = GetStoreInventoryString(playerInfo),
currencyString = currencyString.Value,
currency = userCurrency
};
rpc.Invoke("SendServerRewardsJSON", new object[1] { JsonUtility.ToJson((object)jsonCommand2) });
}
}
else if (command.command == "PurchaseResult")
{
Traverse.Create((object)GameCamera.instance).Field("m_mouseCapture").SetValue((object)true);
Cursor.lockState = (CursorLockMode)1;
Cursor.visible = false;
storeOpen = false;
string[] array = command.items.Split(new char[1] { ';' });
GameObject val2 = null;
PlayerProfile playerProfile = Game.instance.GetPlayerProfile();
Traverse val3 = null;
if (useTombstone.Value)
{
val2 = Object.Instantiate<GameObject>(Player.m_localPlayer.m_tombstone, ((Character)Player.m_localPlayer).GetCenterPoint() + ((Component)Player.m_localPlayer).transform.forward, ((Component)Player.m_localPlayer).transform.rotation);
val2.GetComponent<Container>().m_name = command.packagename;
val3 = Traverse.Create((object)val2.GetComponent<Container>().GetInventory());
val3.Field("m_name").SetValue((object)command.packagename);
val3.Field("m_width").SetValue((object)8);
int num = array.Count() / 8 + 2;
if (array.Count() % 8 != 0)
{
num++;
}
val3.Field("m_height").SetValue((object)num);
TombStone component = val2.GetComponent<TombStone>();
component.Setup(command.packagename, playerProfile.GetPlayerID());
}
myCurrency = command.currency;
List<string> list = new List<string>();
string[] array2 = array;
foreach (string text in array2)
{
Dbgl("Receving " + text);
string[] array3 = text.Split(new char[1] { ',' });
string text2 = array3[0];
GameObject prefab = ZNetScene.instance.GetPrefab(text2);
if (!Object.op_Implicit((Object)(object)prefab))
{
Dbgl("Item " + text2 + " not found!");
continue;
}
int num2 = int.Parse(array3[1]);
if (useTombstone.Value)
{
ItemData itemData = prefab.GetComponent<ItemDrop>().m_itemData;
double value = num2 / itemData.m_shared.m_maxStackSize / 8;
val3.Field("m_height").SetValue((object)((int)val3.Field("m_height").GetValue() + (int)Math.Round(value, 0)));
while (num2 >= itemData.m_shared.m_maxStackSize)
{
int num3 = Mathf.Min(itemData.m_shared.m_maxStackSize, num2);
val2.GetComponent<Container>().GetInventory().AddItem(text2, num3, itemData.m_quality, itemData.m_variant, Player.m_localPlayer.GetPlayerID(), Player.m_localPlayer.GetPlayerName(), false);
num2 -= num3;
}
if (num2 > 0)
{
val2.GetComponent<Container>().GetInventory().AddItem(text2, num2, itemData.m_quality, itemData.m_variant, Player.m_localPlayer.GetPlayerID(), Player.m_localPlayer.GetPlayerName(), false);
}
list.Add(Localization.instance.Localize(itemData.m_shared.m_name) + " " + array3[0]);
}
else if (num2 == 1)
{
GameObject val4 = Object.Instantiate<GameObject>(prefab, ((Component)Player.m_localPlayer).transform.position + ((Component)Player.m_localPlayer).transform.forward * 2f + Vector3.up, Quaternion.identity);
ItemData itemData2 = val4.GetComponent<ItemDrop>().m_itemData;
itemData2.m_durability = itemData2.m_shared.m_maxDurability;
((Character)Player.m_localPlayer).Message((MessageType)1, string.Format(rewardString.Value, Localization.instance.Localize(val4.GetComponent<ItemDrop>().m_itemData.m_shared.m_name)), 0, (Sprite)null);
}
else
{
for (int j = 0; j < num2; j++)
{
Vector3 val5 = Random.insideUnitSphere * 0.5f;
GameObject val6 = Object.Instantiate<GameObject>(prefab, ((Component)Player.m_localPlayer).transform.position + ((Component)Player.m_localPlayer).transform.forward * 2f + Vector3.up + val5, Quaternion.identity);
ItemData itemData3 = val6.GetComponent<ItemDrop>().m_itemData;
itemData3.m_durability = itemData3.m_shared.m_maxDurability;
((Character)Player.m_localPlayer).Message((MessageType)1, Localization.instance.Localize(val6.GetComponent<ItemDrop>().m_itemData.m_shared.m_name), 0, (Sprite)null);
}
}
}
if (useTombstone.Value)
{
val3.Method("Changed", Array.Empty<object>()).GetValue();
val2.GetComponent<ZNetView>().GetZDO().Set("ServerReward", string.Format(packageInfoString.Value, command.packagename, playerProfile.GetName()) + "\r\n" + string.Join("\r\n", list));
}
}
else if (command.command == "SendStoreInfo")
{
if (command.currency == -1)
{
Dbgl("Error getting store info");
return;
}
myCurrency = command.currency;
windowTitleText = command.storeTitle;
currencyString.Value = command.currencyString;
storePackages = GetStorePackagesFromString(command.storeInventory);
Dbgl($"Got store inventory {storePackages.Count}, user currency: {myCurrency}");
storeOpen = true;
}
else if (command.command == "SendConsoleString")
{
Traverse.Create((object)Console.instance).Method("AddString", new object[1] { command.data }).GetValue();
Dbgl(command.data);
}
}
public void UpdatePlayersRepeated()
{
UpdatePlayers(forced: false);
}
public void UpdatePlayers(bool forced)
{
if (!modEnabled.Value || !ZNet.instance.IsServer())
{
return;
}
Dbgl("Updating players");
List<ZNetPeer> connectedPeers = ZNet.instance.GetConnectedPeers();
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ServerRewards");
if (!Directory.Exists(text))
{
Dbgl("Creating mod folder");
Directory.CreateDirectory(text);
}
string path = Path.Combine(text, "PlayerInfo");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
List<string> allPlayerIDs = GetAllPlayerIDs();
Dbgl($"Got {allPlayerIDs.Count} player files, {connectedPeers.Count} online players");
if (connectedPeers.Count > 0)
{
foreach (ZNetPeer item in connectedPeers)
{
string peerID = GetPeerID(item);
if (peerID != null && !allPlayerIDs.Contains(peerID))
{
Dbgl("Adding peer " + peerID);
AddNewPlayerInfo(peerID);
}
}
}
if (allPlayerIDs.Count <= 0)
{
return;
}
foreach (string id in allPlayerIDs)
{
Dbgl("Processing id " + id);
PlayerInfo playerInfo = GetPlayerInfo(id);
if (!connectedPeers.Exists((ZNetPeer p) => GetPeerID(p) == id))
{
if (playerInfo.online)
{
Dbgl("\tPlayer went offline, removing");
playerInfo.online = false;
WritePlayerData(playerInfo);
}
else
{
Dbgl("\tPlayer not online, skipping");
}
continue;
}
if (!playerInfo.online)
{
Dbgl("\tPlayer coming online, processing daily rewards");
if (consecutiveLoginReward.Value.Length > 0 && (playerInfo.lastLogin == 0L || DateTime.Today - new DateTime(playerInfo.lastLogin).Date == TimeSpan.FromDays(1.0)))
{
Dbgl("\tPlayer logged in yesterday");
string[] array = consecutiveLoginReward.Value.Split(new char[1] { ',' });
int num = -1;
playerInfo.consecutiveDays++;
if (consecutiveLoginRewardOnce.Value)
{
if (playerInfo.maxConsecutiveDays < playerInfo.consecutiveDays && playerInfo.consecutiveDays < array.Length && playerInfo.maxConsecutiveDays < playerInfo.consecutiveDays)
{
num = playerInfo.consecutiveDays;
}
}
else
{
num = playerInfo.consecutiveDays % array.Length;
}
if (num > -1)
{
Dbgl("\tgiving consecutive login reward " + array[num]);
playerInfo.currency += int.Parse(array[num]);
}
if (playerInfo.maxConsecutiveDays < playerInfo.consecutiveDays)
{
playerInfo.maxConsecutiveDays = playerInfo.consecutiveDays;
}
}
if (staticLoginReward.Value > 0 && DateTime.Today - new DateTime(playerInfo.lastLogin).Date >= TimeSpan.FromDays(1.0))
{
Dbgl("\tPlayer has not logged in today, giving static login reward");
playerInfo.currency += staticLoginReward.Value;
}
playerInfo.lastLogin = DateTime.Now.Ticks;
playerInfo.online = true;
}
else if (!forced)
{
playerInfo.currency += updateIntervalReward.Value;
}
Dbgl($"\tPlayer currency {playerInfo.currency}, writing json");
WritePlayerData(playerInfo);
}
}
private static string GetPackageItems(PackageInfo package, PlayerInfo player)
{
int num = 0;
bool flag = false;
List<string> list = new List<string>();
foreach (string item in package.items)
{
Dbgl("Checking " + item);
int num2 = Random.Range(1, 100);
string[] array = item.Split(new char[1] { ',' });
ItemInfo itemInfo = new ItemInfo
{
name = array[0],
amount = array[1],
chance = array[2],
type = array[3]
};
if (itemInfo.type.ToLower() == "choice")
{
if (flag)
{
continue;
}
num += int.Parse(itemInfo.chance);
Dbgl($"Checking choice {num} > {num2}");
if (num2 > num)
{
continue;
}
flag = true;
Dbgl("Won choice");
}
else
{
int num3 = Random.Range(1, 100);
Dbgl($"Checking chance {itemInfo.chance} > {num3}");
if (num3 > int.Parse(itemInfo.chance))
{
continue;
}
Dbgl("Won chance");
}
int num4 = 0;
if (itemInfo.amount.Contains("-"))
{
string[] array2 = itemInfo.amount.Split(new char[1] { '-' });
num4 = Random.Range(int.Parse(array2[0]), int.Parse(array2[1]));
}
else
{
num4 = int.Parse(itemInfo.amount);
}
if (num4 > 0)
{
list.Add(itemInfo.name + "," + num4);
}
Dbgl($"Added {num4} {itemInfo.name}");
}
return string.Join(";", list);
}
private static List<PackageInfo> GetStorePackagesFromString(List<string> storeInventory)
{
List<PackageInfo> list = new List<PackageInfo>();
foreach (string item in storeInventory)
{
string[] array = item.Split(new char[1] { ',' });
list.Add(new PackageInfo
{
id = array[0],
name = array[1],
description = array[2],
type = array[3],
price = int.Parse(array[4])
});
}
return list;
}
private static List<PackageInfo> GetAllPackages()
{
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ServerRewards", "StoreInfo");
if (!Directory.Exists(path))
{
Dbgl("Missing store info");
return null;
}
List<PackageInfo> list = new List<PackageInfo>();
string[] files = Directory.GetFiles(path, "*.json");
foreach (string path2 in files)
{
string text = File.ReadAllText(path2);
PackageInfo item = JsonUtility.FromJson<PackageInfo>(text);
list.Add(item);
}
return list;
}
private static PackageInfo GetPackage(string packageID)
{
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ServerRewards", "StoreInfo");
if (!Directory.Exists(path))
{
Dbgl("Missing store info");
return null;
}
string[] files = Directory.GetFiles(path, "*.json");
foreach (string path2 in files)
{
string text = File.ReadAllText(path2);
PackageInfo packageInfo = JsonUtility.FromJson<PackageInfo>(text);
if (packageInfo.id == packageID)
{
return packageInfo;
}
}
return null;
}
private static List<string> GetStoreInventoryString(PlayerInfo player)
{
List<string> list = new List<string>();
foreach (PackageInfo allPackage in GetAllPackages())
{
if (CanBuyPackage(ref player, allPackage, checkCurrency: false, checkLimit: true, out var _))
{
list.Add(allPackage.StoreString());
}
}
return list;
}
private static int GetUserCurrency(string steamID)
{
PlayerInfo playerInfo = GetPlayerInfo(steamID);
if (playerInfo == null)
{
Dbgl("Player info is null");
}
return playerInfo?.currency ?? (-1);
}
private static void AddNewPlayerInfo(string steamID)
{
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ServerRewards");
if (!Directory.Exists(text))
{
Dbgl("Creating mod folder");
Directory.CreateDirectory(text);
}
string text2 = Path.Combine(text, "PlayerInfo");
if (!Directory.Exists(text2))
{
Directory.CreateDirectory(text2);
}
PlayerInfo playerInfo = new PlayerInfo
{
id = steamID,
currency = playerStartCurrency.Value
};
string contents = JsonUtility.ToJson((object)playerInfo);
string path = Path.Combine(text2, steamID + ".json");
File.WriteAllText(path, contents);
}
private static PlayerInfo GetPlayerInfo(string steamID)
{
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ServerRewards", "PlayerInfo", steamID + ".json");
if (!File.Exists(path))
{
Dbgl("Player file not found");
return null;
}
string text = File.ReadAllText(path);
return JsonUtility.FromJson<PlayerInfo>(text);
}
private static string GetSteamID(string idOrName)
{
if (Regex.IsMatch(idOrName, "[^0-9]"))
{
ZNetPeer peer = ((IEnumerable<ZNetPeer>)ZNet.instance.GetConnectedPeers()).FirstOrDefault((Func<ZNetPeer, bool>)((ZNetPeer p) => p.m_playerName == idOrName));
idOrName = GetPeerID(peer);
}
return idOrName;
}
private static List<string> GetAllPlayerIDs()
{
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ServerRewards");
if (!Directory.Exists(text))
{
Dbgl("Creating mod folder");
Directory.CreateDirectory(text);
}
string path = Path.Combine(text, "PlayerInfo");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
List<string> list = new List<string>();
string[] files = Directory.GetFiles(path, "*.json");
foreach (string path2 in files)
{
list.Add(Path.GetFileNameWithoutExtension(path2));
}
return list;
}
private static void WritePlayerData(PlayerInfo playerInfo)
{
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ServerRewards", "PlayerInfo", playerInfo.id + ".json");
string contents = JsonUtility.ToJson((object)playerInfo);
File.WriteAllText(path, contents);
}
private static bool CanBuyPackage(ref PlayerInfo player, PackageInfo package, bool checkCurrency, bool checkLimit, out string result)
{
result = null;
if (checkCurrency && player.currency < package.price)
{
result = $"Player doesn't have enough currency {player.currency}, price {package.price}";
return false;
}
for (int i = 0; i < player.packages.Count; i++)
{
string[] array = player.packages[i].Split(new char[1] { ',' });
if (array[0] == package.id)
{
if (checkLimit && package.limit > 0 && int.Parse(array[1]) >= package.limit)
{
result = "Player has bought more than the limit for this package.";
return false;
}
player.packages[i] = package.id + "," + (int.Parse(array[1]) + 1);
result = "Player can buy this package.";
}
}
if (result == null)
{
player.packages.Add(package.id + ",1");
result = "Player can buy this package.";
}
return true;
}
private static bool AdjustCurrency(string steamID, int amount)
{
List<ZNetPeer> connectedPeers = ZNet.instance.GetConnectedPeers();
foreach (ZNetPeer item in connectedPeers)
{
string peerID = GetPeerID(item);
if (steamID == "all" || peerID == steamID)
{
PlayerInfo playerInfo = GetPlayerInfo(peerID);
if (playerInfo == null)
{
playerInfo = new PlayerInfo
{
id = peerID
};
}
playerInfo.currency += amount;
WritePlayerData(playerInfo);
if (steamID != "all")
{
return true;
}
}
}
return steamID == "all";
}
private static bool SetCurrency(string steamID, int amount)
{
List<ZNetPeer> connectedPeers = ZNet.instance.GetConnectedPeers();
foreach (ZNetPeer item in connectedPeers)
{
string peerID = GetPeerID(item);
if (steamID == "all" || peerID == steamID)
{
PlayerInfo playerInfo = GetPlayerInfo(peerID);
if (playerInfo == null)
{
playerInfo = new PlayerInfo
{
id = peerID
};
}
playerInfo.currency = amount;
WritePlayerData(playerInfo);
if (steamID != "all")
{
return true;
}
}
}
return steamID == "all";
}
private static string GivePackage(string steamID, string packageID)
{
PlayerInfo playerInfo = GetPlayerInfo(steamID);
if (playerInfo == null)
{
return "User not found!";
}
PackageInfo package = GetPackage(packageID);
if (package == null)
{
return "Package not found!";
}
ZNetPeer val = ZNet.instance.GetConnectedPeers().Find((ZNetPeer p) => GetPeerID(p) == steamID);
if (val == null)
{
return "User not online!";
}
JsonCommand jsonCommand = new JsonCommand
{
command = "PurchaseResult",
currency = playerInfo.currency,
items = GetPackageItems(package, playerInfo)
};
val.m_rpc.Invoke("SendServerRewardsJSON", new object[1] { JsonUtility.ToJson((object)jsonCommand) });
return null;
}
private static void PlayEffects()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
EffectList val = new EffectList();
List<EffectData> list = new List<EffectData>();
for (int i = 0; i < ((Character)Player.m_localPlayer).m_deathEffects.m_effectPrefabs.Length; i++)
{
list.Add(((Character)Player.m_localPlayer).m_deathEffects.m_effectPrefabs[i]);
}
val.m_effectPrefabs = list.ToArray();
val.Create(((Component)Player.m_localPlayer).transform.position, ((Component)Player.m_localPlayer).transform.rotation, ((Component)Player.m_localPlayer).transform, 1f, -1);
}
public static string GetPeerID(ZNetPeer peer)
{
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
ISocket val = peer.m_socket;
if (((object)peer.m_socket).GetType().Name.EndsWith("BufferingSocket"))
{
Dbgl("ServerSync peer");
try
{
val = (ISocket)AccessTools.Field(((object)peer.m_socket).GetType(), "Original").GetValue(peer.m_socket);
}
catch (Exception arg)
{
Dbgl($"Failed to get socket from ServerSync: \n\n {arg}");
}
}
if (val is ZSteamSocket)
{
CSteamID peerID = ((ZSteamSocket)((val is ZSteamSocket) ? val : null)).GetPeerID();
return ((object)(CSteamID)(ref peerID)).ToString();
}
if (val is ZPlayFabSocket)
{
return AccessTools.FieldRefAccess<ZPlayFabSocket, string>((ZPlayFabSocket)(object)((val is ZPlayFabSocket) ? val : null), "m_remotePlayerId");
}
Dbgl($"Wrong peer type: {((object)val).GetType()}");
return null;
}
}
public class ItemInfo
{
public string name;
public string amount;
public string chance;
public string type;
}
public class JsonCommand
{
public string command;
public string id;
public string storeData;
public string storeTitle;
public string currencyString;
public int currency;
public List<string> storeInventory;
public string packageid;
public string packagename;
public string packagedescription;
public string items;
public string data;
}
public class PackageInfo
{
public string id;
public string name;
public string description;
public int price;
public int limit;
public string type;
public List<string> items;
public string StoreString()
{
return string.Join(",", id, name, description, type, price.ToString() ?? "");
}
}
public class PlayerInfo
{
public bool online = false;
public int currency = 0;
public long lastLogin = 0L;
public int consecutiveDays = 0;
public int maxConsecutiveDays = 0;
public List<string> packages = new List<string>();
public string id;
}