// Token: 0x0600072F RID: 1839 RVA: 0x0003A2D0 File Offset: 0x000384D0 private void RPC_ServerList(ZRpc rpc, ZPackage pkg) { this.m_haveServerlist = true; this.m_serverListRevision++; pkg.ReadInt(); int num = pkg.ReadInt(); this.m_servers.Clear(); for (int i = 0; i < num; i++) { ServerData serverData = new ServerData(); serverData.m_name = pkg.ReadString(); serverData.m_host = pkg.ReadString(); serverData.m_port = pkg.ReadInt(); serverData.m_password = pkg.ReadBool(); serverData.m_upnp = pkg.ReadBool(); pkg.ReadLong(); serverData.m_version = pkg.ReadString(); serverData.m_players = pkg.ReadInt(); if (this.m_nameFilter.Length <= 0 || serverData.m_name.Contains(this.m_nameFilter)) { this.m_servers.Add(serverData); } } if (this.m_onServerList != null) { this.m_onServerList(this.m_servers); } }
public void Load(ZPackage pkg) { int propertyCount = pkg.ReadInt(); for (int i = 0; i < propertyCount; i++) { var key = pkg.ReadString(); var dataType = (TyrDataType)Enum.ToObject(typeof(TyrDataType), pkg.ReadInt()); if (dataType == TyrDataType.FLOAT) { var val = pkg.ReadSingle(); m_properties[key] = new TyrProperty(key, val, true); } else if (dataType == TyrDataType.INT) { var val = pkg.ReadInt(); m_properties[key] = new TyrProperty(key, val, true); } else if (dataType == TyrDataType.LONG) { var val = pkg.ReadLong(); m_properties[key] = new TyrProperty(key, val, true); } else if (dataType == TyrDataType.STRING) { var val = pkg.ReadString(); m_properties[key] = new TyrProperty(key, val, true); } } }
/// <summary> /// Create a <see cref="Portal" /> list from a <see cref="ZPackage" /> /// </summary> /// <param name="zpkg"></param> /// <returns></returns> public static PortalList FromZPackage(ZPackage zpkg) { Logger.LogDebug("Deserializing portal list from ZPackage"); var ret = new PortalList(); var numConnectedPortals = zpkg.ReadInt(); while (numConnectedPortals > 0) { var portalPosition = zpkg.ReadVector3(); var portalName = zpkg.ReadString(); Logger.LogDebug($"{portalName}@{portalPosition}"); ret.Add(new Portal(portalPosition, portalName, true)); numConnectedPortals--; } var numUnconnectedPortals = zpkg.ReadInt(); while (numUnconnectedPortals > 0) { var portalPosition = zpkg.ReadVector3(); var portalName = zpkg.ReadString(); Logger.LogDebug($"{portalName}@{portalPosition}"); ret.Add(new Portal(portalPosition, portalName, false)); numUnconnectedPortals--; } return(ret); }
private void ZSteamSocket_Send(ZSteamSocket self, ZPackage pkg) { if (!(_isModEnabled.Value && _isOutputEnabled.Value)) { return; } pkg.SetPos(0); int methodHash = pkg.ReadInt(); if (methodHash == 0) { Logger.LogMessage($"Sending RPC Ping to {self.GetHostName()}"); } else { try { string method = pkg.ReadString(); if (method == "RoutedRPC") { ZPackage wrapped = pkg.ReadPackage(); _ = wrapped.ReadInt(); method = pkg.ReadString(); } Logger.LogMessage($"Sending RPC {method} to {self.GetHostName()}"); } catch (Exception) { } } }
private void ZSteamSocket_Recv(ZSteamSocket self, ZPackage pkg) { if (!(_isModEnabled.Value && _isOutputEnabled.Value)) { return; } if (pkg != null) { int methodHash = pkg.ReadInt(); if (methodHash == 0) { Logger.LogMessage($"Received RPC Ping"); } else { try { string method = pkg.ReadString(); if (method == "RoutedRPC") { ZPackage wrapped = pkg.ReadPackage(); _ = wrapped.ReadInt(); method = pkg.ReadString(); } Logger.LogMessage($"Received RPC {method}"); } catch (Exception) { } } pkg.SetPos(0); } }
/// <summary> /// Sync Pin with clients via the server /// </summary> public static void RPC_VPlusMapPinSync(long sender, ZPackage mapPinPkg) { if (ZNet.m_isServer) //Server { if (sender == ZRoutedRpc.instance.GetServerPeerID()) { return; } if (mapPinPkg == null) { return; } foreach (ZNetPeer peer in ZRoutedRpc.instance.m_peers) { if (peer.m_uid != sender) { ZRoutedRpc.instance.InvokeRoutedRPC(peer.m_uid, "VPlusMapPinSync", new object[] { mapPinPkg }); } } ZLog.Log($"Sent map pin to all clients"); //VPlusAck.SendAck(sender); } else //Client { if (sender != ZRoutedRpc.instance.GetServerPeerID()) { return; //Only bother if it's from the server. } if (mapPinPkg == null) { ZLog.LogWarning("Warning: Got empty map pin package from server."); return; } long pinSender = mapPinPkg.ReadLong(); string senderName = mapPinPkg.ReadString(); if (senderName != Player.m_localPlayer.GetPlayerName() && pinSender != ZRoutedRpc.instance.m_id) { ZLog.Log("Checking sent pin"); Vector3 pinPos = mapPinPkg.ReadVector3(); int pinType = mapPinPkg.ReadInt(); string pinName = mapPinPkg.ReadString(); bool keepQuiet = mapPinPkg.ReadBool(); if (!Minimap.instance.HaveSimilarPin(pinPos, (Minimap.PinType)pinType, pinName, true)) { Minimap.PinData addedPin = Minimap.instance.AddPin(pinPos, (Minimap.PinType)pinType, pinName, true, false); if (!keepQuiet) { MessageHud.instance.ShowMessage(MessageHud.MessageType.Center, $"Received map pin {pinName} from {senderName}!", 0, Minimap.instance.GetSprite((Minimap.PinType)pinType)); } ZLog.Log($"I got pin named {pinName} from {senderName}!"); } } //Send Ack //VPlusAck.SendAck(sender); } }
// Token: 0x06000C0A RID: 3082 RVA: 0x000559B8 File Offset: 0x00053BB8 public static World LoadWorld(string name) { FileStream fileStream = null; try { fileStream = File.OpenRead(World.GetMetaPath(name)); } catch { if (fileStream != null) { fileStream.Dispose(); } ZLog.Log(" failed to load " + name); return(new World(name, true, false)); } World result; try { BinaryReader binaryReader = new BinaryReader(fileStream); int count = binaryReader.ReadInt32(); ZPackage zpackage = new ZPackage(binaryReader.ReadBytes(count)); int num = zpackage.ReadInt(); if (!global::Version.IsWorldVersionCompatible(num)) { ZLog.Log("incompatible world version " + num); result = new World(name, false, true); } else { World world = new World(); world.m_name = zpackage.ReadString(); world.m_seedName = zpackage.ReadString(); world.m_seed = zpackage.ReadInt(); world.m_uid = zpackage.ReadLong(); if (num >= 26) { world.m_worldGenVersion = zpackage.ReadInt(); } result = world; } } catch { ZLog.LogWarning(" error loading world " + name); result = new World(name, true, false); } finally { if (fileStream != null) { fileStream.Dispose(); } } return(result); }
public static WorldPlayer Load(ZPackage pkg) { var worldPlayer = new WorldPlayer(); int num = pkg.ReadInt(); if (!ValheimVersion.IsPlayerVersionCompatible(num)) { return(null); } if (num >= 28) { worldPlayer.PlayerStats_kills = pkg.ReadInt(); worldPlayer.PlayerStats_deaths = pkg.ReadInt(); worldPlayer.PlayerStats_crafts = pkg.ReadInt(); worldPlayer.PlayerStats_builds = pkg.ReadInt(); } worldPlayer.WorldPlayerData.Clear(); int num2 = pkg.ReadInt(); for (int i = 0; i < num2; i++) { long key = pkg.ReadLong(); var worldPlayerData = new WorldPlayerData(); worldPlayerData.m_haveCustomSpawnPoint = pkg.ReadBool(); worldPlayerData.m_spawnPoint = pkg.ReadVector3(); worldPlayerData.m_haveLogoutPoint = pkg.ReadBool(); worldPlayerData.m_logoutPoint = pkg.ReadVector3(); if (num >= 30) { worldPlayerData.m_haveDeathPoint = pkg.ReadBool(); worldPlayerData.m_deathPoint = pkg.ReadVector3(); } worldPlayerData.m_homePoint = pkg.ReadVector3(); if (num >= 29 && pkg.ReadBool()) { worldPlayerData.m_mapData = pkg.ReadByteArray(); } worldPlayer.WorldPlayerData.Add(key, worldPlayerData); } worldPlayer.PlayerName = pkg.ReadString(); worldPlayer.PlayerId = pkg.ReadLong(); worldPlayer.StartSeed = pkg.ReadString(); if (pkg.ReadBool()) { var byteArray = pkg.ReadByteArray(); var playerPkg = new ZPackage(byteArray); worldPlayer.Player = PlayerReaderWriter.Load(playerPkg); } else { worldPlayer.Player = null; } return(worldPlayer); }
private bool LoadPlayerFromDisk() { try { ZPackage zpackage = this.LoadPlayerDataFromDisk(); if (zpackage == null) { ZLog.LogWarning((object)"No player data"); return(false); } int version = zpackage.ReadInt(); if (!Version.IsPlayerVersionCompatible(version)) { ZLog.Log((object)"Player data is not compatible, ignoring"); return(false); } if (version >= 28) { this.m_playerStats.m_kills = zpackage.ReadInt(); this.m_playerStats.m_deaths = zpackage.ReadInt(); this.m_playerStats.m_crafts = zpackage.ReadInt(); this.m_playerStats.m_builds = zpackage.ReadInt(); } this.m_worldData.Clear(); int num = zpackage.ReadInt(); for (int index = 0; index < num; ++index) { long key = zpackage.ReadLong(); PlayerProfile.WorldPlayerData worldPlayerData = new PlayerProfile.WorldPlayerData(); worldPlayerData.m_haveCustomSpawnPoint = zpackage.ReadBool(); worldPlayerData.m_spawnPoint = zpackage.ReadVector3(); worldPlayerData.m_haveLogoutPoint = zpackage.ReadBool(); worldPlayerData.m_logoutPoint = zpackage.ReadVector3(); if (version >= 30) { worldPlayerData.m_haveDeathPoint = zpackage.ReadBool(); worldPlayerData.m_deathPoint = zpackage.ReadVector3(); } worldPlayerData.m_homePoint = zpackage.ReadVector3(); if (version >= 29 && zpackage.ReadBool()) { worldPlayerData.m_mapData = zpackage.ReadByteArray(); } this.m_worldData.Add(key, worldPlayerData); } this.m_playerName = zpackage.ReadString(); this.m_playerID = zpackage.ReadLong(); this.m_startSeed = zpackage.ReadString(); this.m_playerData = !zpackage.ReadBool() ? (byte[])null : zpackage.ReadByteArray(); } catch (Exception ex) { ZLog.LogWarning((object)("Exception while loading player profile:" + this.m_filename + " , " + ex.ToString())); } return(true); }
// Token: 0x060006B0 RID: 1712 RVA: 0x000377B4 File Offset: 0x000359B4 public static Inventory Load(ZPackage pkg) { var inventory = new Inventory(); int num = pkg.ReadInt(); int num2 = pkg.ReadInt(); inventory.m_inventory.Clear(); for (int i = 0; i < num2; i++) { string text = pkg.ReadString(); int stack = pkg.ReadInt(); float durability = pkg.ReadSingle(); Vector2i pos = pkg.ReadVector2i(); bool equiped = pkg.ReadBool(); int quality = 1; if (num >= 101) { quality = pkg.ReadInt(); } int variant = 0; if (num >= 102) { variant = pkg.ReadInt(); } long crafterID = 0L; string crafterName = ""; if (num >= 103) { crafterID = pkg.ReadLong(); crafterName = pkg.ReadString(); } if (text != "") { var item = new InventoryItem() { prefabName = text, m_stack = stack, m_durability = durability, m_gridPos = pos, m_equiped = equiped, m_quality = quality, m_variant = variant, m_crafterID = crafterID, m_crafterName = crafterName }; inventory.m_inventory.Add(item); } } return(inventory); }
public static void RPC_UpdateInventory(ZRpc rpc, ZPackage pkg) { String characterName = pkg.ReadString(); int itemsCount = pkg.ReadInt(); String steamId = rpc.GetSocket().GetEndPointString(); List <Server_ItemData> playerItems = new List <Server_ItemData>(); for (int i = 0; i < itemsCount; i++) { Server_ItemData data = new Server_ItemData { Name = pkg.ReadString(), Stack = pkg.ReadInt(), Quality = pkg.ReadInt(), Variant = pkg.ReadInt() }; playerItems.Add(data); } String dbId = $"{steamId}_{characterName}"; var dbPlayer = Instance.DB.GetPlayerById(dbId); if (dbPlayer == null) { dbPlayer = new DBClasses.DBPlayer() { DBPlayerId = dbId, SteamId = steamId, CharacterName = characterName, Items = new List <DBClasses.DBItem>() }; foreach (var item in playerItems) { dbPlayer.Items.Add(new DBClasses.DBItem() { ItemName = item.Name, PlayerId = dbPlayer.DBPlayerId, StackCount = item.Stack, Quality = item.Quality, Variant = item.Variant }); } Instance.DB.InsertPlayer(dbPlayer); } else { Instance.DB.UpdatePlayer(dbPlayer); } }
public static bool Prefix(ref ZRoutedRpc __instance, ref RoutedRPCData data) { if (ZNet.m_isServer && data?.m_methodHash == GlobalMessages.TalkerSayHashCode) { // Read local say chat messages for users not connected to VChat. // Messages that fit the global chat command name will be redirected as global chat messages. if (GreetingMessage.PeerInfo.TryGetValue(data.m_senderPeerID, out GreetingMessagePeerInfo peerInfo) && !peerInfo.HasReceivedGreeting) { try { var senderPeer = ZNet.instance.GetPeer(data.m_senderPeerID); var package = new ZPackage(data.m_parameters.GetArray()); var ctype = package.ReadInt(); var playerName = package.ReadString(); var text = package.ReadString(); if (ctype == (int)Talker.Type.Normal) { var globalChatCommand = VChatPlugin.CommandHandler.FindCommand(PluginCommandType.SendGlobalMessage); if (VChatPlugin.CommandHandler.IsValidCommandString(text, globalChatCommand, out text)) { VChatPlugin.Log($"Redirecting local message to global chat from peer {data.m_senderPeerID} \"({senderPeer?.m_playerName})\" with message \"{text}\"."); // Redirect this message to the global chat channel. foreach (var peer in ZNet.instance.GetConnectedPeers()) { // Exclude the sender, otherwise it'd probably just be annoying. if (peer.m_uid != data.m_senderPeerID) { GlobalMessages.SendGlobalMessageToPeer(peer.m_uid, (int)GlobalMessageType.RedirectedGlobalMessage, senderPeer?.m_refPos ?? new Vector3(), senderPeer?.m_playerName ?? playerName, text); } } // Intercept message so that other connected users won't receive the same message twice. data.m_methodHash = GlobalMessages.InterceptedSayHashCode; return(false); } } } catch (Exception ex) { VChatPlugin.LogError($"Error reading Talker.Say message for unconnected VChat user ({data.m_senderPeerID}): {ex}"); } } } return(true); }
public static void SetMapData(ZPackage mapData) { ServerPins.Clear(); var version = mapData.ReadInt(); var mapSize = mapData.ReadInt(); var explored = new bool[mapSize * mapSize]; for (var i = 0; i < mapSize * mapSize; i++) { explored[i] = mapData.ReadBool(); } var pinCount = mapData.ReadInt(); for (var i = 0; i < pinCount; i++) { var pin = new PinData { Name = mapData.ReadString(), Pos = mapData.ReadVector3(), Type = (Minimap.PinType)mapData.ReadInt(), Checked = mapData.ReadBool() }; ServerPins.Add(pin); } Explored = explored; }
// Token: 0x0600090D RID: 2317 RVA: 0x0004331C File Offset: 0x0004151C private void HandlePackage(ZPackage package) { int num = package.ReadInt(); if (num == 0) { this.ReceivePing(package); return; } ZRpc.RpcMethodBase rpcMethodBase2; if (ZRpc.m_DEBUG) { package.ReadString(); ZRpc.RpcMethodBase rpcMethodBase; if (this.m_functions.TryGetValue(num, out rpcMethodBase)) { rpcMethodBase.Invoke(this, package); return; } } else if (this.m_functions.TryGetValue(num, out rpcMethodBase2)) { rpcMethodBase2.Invoke(this, package); } }
// Token: 0x06000DBC RID: 3516 RVA: 0x00062418 File Offset: 0x00060618 public void Deserialize(ref ZPackage pkg) { this.m_damage.m_damage = pkg.ReadSingle(); this.m_damage.m_blunt = pkg.ReadSingle(); this.m_damage.m_slash = pkg.ReadSingle(); this.m_damage.m_pierce = pkg.ReadSingle(); this.m_damage.m_chop = pkg.ReadSingle(); this.m_damage.m_pickaxe = pkg.ReadSingle(); this.m_damage.m_fire = pkg.ReadSingle(); this.m_damage.m_frost = pkg.ReadSingle(); this.m_damage.m_lightning = pkg.ReadSingle(); this.m_damage.m_poison = pkg.ReadSingle(); this.m_damage.m_spirit = pkg.ReadSingle(); this.m_toolTier = pkg.ReadInt(); this.m_pushForce = pkg.ReadSingle(); this.m_backstabBonus = pkg.ReadSingle(); this.m_staggerMultiplier = pkg.ReadSingle(); this.m_dodgeable = pkg.ReadBool(); this.m_blockable = pkg.ReadBool(); this.m_point = pkg.ReadVector3(); this.m_dir = pkg.ReadVector3(); this.m_statusEffect = pkg.ReadString(); this.m_attacker = pkg.ReadZDOID(); this.m_skill = (Skills.SkillType)pkg.ReadInt(); }
public static void RPC_ConfigSync(long sender, ZPackage configPkg) { if (ZNet.m_isServer) //Server { Logger.LogInfo($"Sending configuration data to peer #{sender}"); if (Configuration.Current == null) { Configuration.LoadConfiguration(); } var pkg = new ZPackage(); var data = Configuration.Current.GetSyncableSections(); //Add number of clean lines to package pkg.Write(data); ZRoutedRpc.instance.InvokeRoutedRPC(sender, nameof(RPC_ConfigSync), pkg); } else //Client { if (configPkg != null && configPkg.Size() > 0 && sender == ZRoutedRpc.instance.GetServerPeerID() ) // Validate the message is from the server and not another client. { Logger.LogInfo("Received configuration data from server."); var receivedConfig = new Configuration(); Configuration.LoadFromIniString(receivedConfig, configPkg.ReadString()); Configuration.SetSyncableValues(receivedConfig); } } }
public static void RPC_ReceiveMapData(long peerID, ZPackage zpkg) { if (ZNet.instance.IsServer()) { Utils.Log("Server RPC_ReceiveMapData"); ServerTransmitMapData(zpkg); return; } var text = zpkg.ReadString(); Utils.Log($"MapData received! Size: {text.Length}"); var validData = MapData.ParseReceivedMapData(text, out var sentFrom, out var sentTo, out var pluginVersion, out var pins, out var mapData); if (validData) { Utils.Log($"Received map data from {sentFrom} via chat."); MapData.instance.SyncData = text; MapData.instance.MapSender = sentFrom; } else { Utils.Log("MapData was invalid, ignoring."); } }
private static bool Prefix(ref ZNet __instance, ZRpc rpc, ZPackage pkg) { if (__instance.IsServer()) { string self = ""; if (pkg.Size() > 32) { pkg.SetPos(pkg.Size() - 32 - 1); if (pkg.ReadByte() == (byte)32) { pkg.SetPos(pkg.GetPos() - 1); self = pkg.ReadString(); } } ZLog.Log((object)("[AntiMods]: Got client hash: " + self + "\nmine: " + VACPlugin.PluginsHash)); ZLog.LogWarning("Plugins Hash is Equals: " + !self.Equals(VACPlugin.PluginsHash) + " ForceMods: " + VACPlugin.forcesamemods.Value); ZLog.LogWarning("Is in Admin List: " + !ZNet.instance.m_adminList.Contains(rpc.GetSocket().GetHostName()) + "Admin Bypass: "******"[AntiMods]: Kicking Client: " + rpc.GetSocket().GetEndPointString() + " (incompatible mods)")); rpc.Invoke("Error", (object)num); return(false); } ZLog.Log((object)("[AntiMods]: Accepting Client: " + rpc.GetSocket().GetEndPointString())); } return(true); }
// code borrowed from https://github.com/Valheim-Modding/Wiki/wiki/Server-Validated-RPC-System and modified public static void RPC_RequestSetWeather(long sender, ZPackage pkg) { if (pkg != null && pkg.Size() > 0) { // Check that our Package is not null, and if it isn't check that it isn't empty. ZNetPeer peer = ZNet.instance.GetPeer(sender); // Get the Peer from the sender, to later check the SteamID against our Adminlist. if (peer != null) { // Confirm the peer exists string peerSteamID = ((ZSteamSocket)peer.m_socket).GetPeerID().m_SteamID.ToString(); // Get the SteamID from peer. if ( ZNet.instance.m_adminList != null && ZNet.instance.m_adminList.Contains(peerSteamID) ) { // Check that the SteamID is in our Admin List. string msg = pkg.ReadString(); // Read the message from the user. pkg.SetPos(0); // Reset the position of our cursor so the client's can re-read the package. ZRoutedRpc.instance.InvokeRoutedRPC(0L, "EventSetWeather", new object[] { pkg }); // Send our Event to all Clients. 0L specifies that it will be sent to everybody EnvMan.instance.m_debugEnv = msg; } } else { ZPackage newPkg = new ZPackage(); // Create a new ZPackage. newPkg.Write("You aren't an Admin!"); // Tell them what's going on. ZRoutedRpc.instance.InvokeRoutedRPC(sender, "BadRequestMsg", new object[] { newPkg }); // Send the error message. } } }
public static BountyInfo FromPackage(ZPackage pkg) { var result = new BountyInfo(); var version = pkg.ReadInt(); result.Interval = pkg.ReadInt(); result.PlayerID = pkg.ReadLong(); result.Biome = (Heightmap.Biome)pkg.ReadInt(); result.State = (BountyState)pkg.ReadInt(); result.Target = BountyTargetInfo.FromPackage(pkg); result.TargetName = pkg.ReadString(); result.RewardIron = pkg.ReadInt(); result.RewardGold = pkg.ReadInt(); result.Position = SerializableVector3.FromPackage(pkg); result.MinimapCircleOffset = SerializableVector3.FromPackage(pkg); var addsCount = pkg.ReadInt(); result.Adds = new List <BountyTargetInfo>(); for (var index = 0; index < addsCount; index++) { result.Adds.Add(BountyTargetInfo.FromPackage(pkg)); } result.Slain = pkg.ReadBool(); return(result); }
public static void RPC_RequestSetTime(long sender, ZPackage pkg) { if (pkg != null && pkg.Size() > 0) { // Check that our Package is not null, and if it isn't check that it isn't empty. ZNetPeer peer = ZNet.instance.GetPeer(sender); // Get the Peer from the sender, to later check the SteamID against our Adminlist. if (peer != null) { // Confirm the peer exists string peerSteamID = ((ZSteamSocket)peer.m_socket).GetPeerID().m_SteamID.ToString(); // Get the SteamID from peer. if ( ZNet.instance.m_adminList != null && ZNet.instance.m_adminList.Contains(peerSteamID) ) { // Check that the SteamID is in our Admin List. // set server tod String tod_str = pkg.ReadString(); if (tod_str == "sync") { pkg.Clear(); tod_str = EnvMan.instance.m_debugTime.ToString(); pkg.Write(tod_str); } float tod = float.Parse(tod_str); if (tod < 0f) { EnvMan.instance.m_debugTimeOfDay = false; } else { EnvMan.instance.m_debugTimeOfDay = true; EnvMan.instance.m_debugTime = Mathf.Clamp01(tod); } pkg.SetPos(0); string msg = pkg.ReadString(); // Read the message from the user. pkg.SetPos(0); // Reset the position of our cursor so the client's can re-read the package. ZRoutedRpc.instance.InvokeRoutedRPC(0L, "EventSetTime", new object[] { pkg }); // Send our Event to all Clients. 0L specifies that it will be sent to everybody UnityEngine.Debug.Log("changing time of day..."); } } else { ZPackage newPkg = new ZPackage(); // Create a new ZPackage. newPkg.Write("You aren't an Admin!"); // Tell them what's going on. ZRoutedRpc.instance.InvokeRoutedRPC(sender, "BadRequestMsg", new object[] { newPkg }); // Send the error message. } } }
public bool Deserialize(ZPackage zpg) { Debug.LogWarning($"Deserialized config ({_sourceFile})"); var configJson = zpg.ReadString(); _config = EpicLoot.EpicLoot.JsonToObject <T>(configJson); return(_config != null); }
public static void RPC_SetConfigurationValue(long sender, ZPackage inputPkg) { if (ZNet.instance.IsLocalInstance()) // Local game { Logger.LogInfo("RPC_SetConfigurationValue LOCAL"); var input = inputPkg.ReadString(); var inputCopy = (input + " ").Trim(); TryExecuteCommand(ref input, true); } if (ZNet.instance.IsServerInstance()) // Server { var peer = ZNet.instance.GetPeer(sender); if (peer == null) { return; } Logger.LogInfo("RPC_SetConfigurationValue SERVER"); // Check if peer is in admin list var steamId = peer.m_socket.GetHostName(); if (ZNet.instance.m_adminList.Contains(steamId)) { var input = inputPkg.ReadString(); var inputCopy = (input + " ").Trim(); TryExecuteCommand(ref input, true); foreach (var peerEntry in ZNet.instance.m_peers) { Logger.LogDebug($"SENDING {inputCopy}"); // Send same back to all clients to actually also set the value on the client ZRoutedRpc.instance.InvokeRoutedRPC(peerEntry.m_uid, nameof(RPC_SetConfigurationValue), inputPkg); } } } else // Client { Logger.LogInfo("RPC_SetConfigurationValue CLIENT"); var input = inputPkg.ReadString(); var inputCopy = (input + " ").Trim(); TryExecuteCommand(ref input, true); Console.instance.AddString($"Command '{inputCopy}' executed"); } }
public static BountyTargetInfo FromPackage(ZPackage pkg) { var result = new BountyTargetInfo(); result.MonsterID = pkg.ReadString(); result.Count = pkg.ReadInt(); result.Level = pkg.ReadInt(); return(result); }
public static PinData UnpackPin(ZPackage z) { var pin = new PinData { Name = z.ReadString(), Pos = z.ReadVector3(), Type = (Minimap.PinType)z.ReadInt(), Checked = z.ReadBool() }; return(pin); }
public static void Deserialize(ZPackage package) { ZoneT.Clear(); int tnum = package.ReadInt(); for (int i = 0; i < tnum; i++) { ZoneT.Add(new ZoneTypes { Name = package.ReadString(), PVP = package.ReadBool(), PVPEnforce = package.ReadBool(), ShowPosition = package.ReadBool(), PositionEnforce = package.ReadBool(), Admins = package.ReadString(), Configurations = package.ReadString() }); } Zones.Clear(); int num = package.ReadInt(); for (int i = 0; i < num; i++) { Zones.Add(new Zone { ID = package.ReadInt(), Name = package.ReadString(), Type = package.ReadString(), Priority = package.ReadInt(), Shape = package.ReadString(), Position = new Vector2(package.ReadSingle(), package.ReadSingle()), Radius = package.ReadSingle(), }); } }
public static void Deserialize(this PlayerProfile profile, ZPackage data) { Debug.Assert(data.ReadInt() <= Version.m_playerVersion); profile.m_playerStats.m_kills = data.ReadInt(); profile.m_playerStats.m_deaths = data.ReadInt(); profile.m_playerStats.m_crafts = data.ReadInt(); profile.m_playerStats.m_builds = data.ReadInt(); profile.m_worldData.Clear(); int num = data.ReadInt(); for (int i = 0; i < num; i++) { long key = data.ReadLong(); PlayerProfile.WorldPlayerData worldPlayerData = (PlayerProfile.WorldPlayerData)Activator.CreateInstance(typeof(PlayerProfile.WorldPlayerData), true); worldPlayerData.m_haveCustomSpawnPoint = data.ReadBool(); worldPlayerData.m_spawnPoint = data.ReadVector3(); worldPlayerData.m_haveLogoutPoint = data.ReadBool(); worldPlayerData.m_logoutPoint = data.ReadVector3(); worldPlayerData.m_haveDeathPoint = data.ReadBool(); worldPlayerData.m_deathPoint = data.ReadVector3(); worldPlayerData.m_homePoint = data.ReadVector3(); if (data.ReadBool()) { worldPlayerData.m_mapData = data.ReadByteArray(); } profile.m_worldData.Add(key, worldPlayerData); } profile.m_playerName = data.ReadString(); profile.m_playerID = data.ReadLong(); if (profile.m_playerID == 0L) { profile.m_playerID = Utils.GenerateUID(); } profile.m_startSeed = data.ReadString(); if (data.ReadBool()) { profile.m_playerData = data.ReadByteArray(); } }
public static void ReadConfigPkg(ZPackage pkg) { if (!ZNet.IsServer()) { int entries = 0; while (pkg.GetPos() != pkg.Size()) { string configKey = pkg.ReadString(); string stringVal = pkg.ReadString(); entries++; if (Config.Instance._configEntries.ContainsKey(configKey)) { Config.Instance._configEntries[configKey].SetSerializedValue(stringVal); Logger.LogInfo($"Applied Server Authoritative config pair => {configKey}: {stringVal}"); } else { Logger.LogError($"Recieved config key we dont have locally. Possible Version Mismatch. {configKey}: {stringVal}"); } } Logger.LogInfo($"Applied {entries} config pairs"); } }
public static bool CacheItemExists(string id, ZPackage cacheList) { int itemCount = cacheList.ReadInt(); for (int i = 0; i < itemCount; i++) { if (id == cacheList.ReadString()) { return(true); } } return(false); }
// Token: 0x060006B8 RID: 1720 RVA: 0x00037B04 File Offset: 0x00035D04 public void Load(ZPackage pkg) { int num = pkg.ReadInt(); int num2 = pkg.ReadInt(); this.m_inventory.Clear(); for (int i = 0; i < num2; i++) { string text = pkg.ReadString(); int stack = pkg.ReadInt(); float durability = pkg.ReadSingle(); Vector2i pos = pkg.ReadVector2i(); bool equiped = pkg.ReadBool(); int quality = 1; if (num >= 101) { quality = pkg.ReadInt(); } int variant = 0; if (num >= 102) { variant = pkg.ReadInt(); } long crafterID = 0L; string crafterName = ""; if (num >= 103) { crafterID = pkg.ReadLong(); crafterName = pkg.ReadString(); } if (text != "") { this.AddItem(text, stack, durability, pos, equiped, quality, variant, crafterID, crafterName); } } this.Changed(); }