/// <summary> /// Instantiates an item using saved information from the player (e.g. the count, slot and LDD) /// </summary> /// <param name="itemInstance">An item as fetched from the Uchu database to base this item on</param> /// <param name="owner">The owner (generally player) of this item</param> /// <param name="inventory">The inventory to add the item to</param> /// <returns>The instantiated item</returns> public static async Task <Item> Instantiate(InventoryItem itemInstance, GameObject owner, Inventory inventory) { return(await Instantiate(owner, itemInstance.Lot, inventory, (uint)itemInstance.Count, (uint)itemInstance.Slot, LegoDataDictionary.FromString(itemInstance.ExtraInfo), (ObjectId)itemInstance.Id, isEquipped : itemInstance.IsEquipped, isBound : itemInstance.IsBound, rootItem : inventory.ManagerComponent.Items.FirstOrDefault(i => i.Id == itemInstance.ParentId))); }
public override void Deserialize(BitReader reader) { Confirmed = reader.ReadBit(); DeleteItem = reader.ReadBit(); OutSuccess = reader.ReadBit(); if (reader.ReadBit()) { InventoryType = (InventoryType)reader.Read <int>(); } if (reader.ReadBit()) { ItemType = (ItemType)reader.Read <int>(); } var len = reader.Read <uint>(); if (len > 0) { var info = reader.ReadString((int)len, true); ExtraInfo = LegoDataDictionary.FromString(info); } ForceDeletion = reader.ReadBit(); if (reader.ReadBit()) { Source = reader.ReadGameObject(Associate.Zone); } if (reader.ReadBit()) { Item = reader.ReadGameObject <Item>(Associate.Zone); } if (reader.ReadBit()) { Requesting = reader.ReadGameObject(Associate.Zone); } if (reader.ReadBit()) { TotalItems = reader.Read <uint>(); } if (reader.ReadBit()) { SubKey = reader.Read <long>(); } if (reader.ReadBit()) { TradeId = reader.Read <long>(); } }
public override void Serialize(BitWriter writer) { writer.WriteBit(true); writer.Write((uint)Items.Count); foreach (var(_, item) in Items) { writer.Write(item.InventoryItemId); writer.Write(item.LOT); writer.WriteBit(false); var stack = item.Count > 1; writer.WriteBit(stack); if (stack) { writer.Write((uint)item.Count); } var hasSlot = item.Slot != -1; writer.WriteBit(hasSlot); if (hasSlot) { writer.Write((ushort)item.Slot); } var hasInventoryType = item.InventoryType != -1; writer.WriteBit(hasInventoryType); if (hasInventoryType) { writer.Write((uint)item.InventoryType); } var hasExtraData = !string.IsNullOrWhiteSpace(item.ExtraInfo); writer.WriteBit(hasExtraData); if (hasExtraData) { writer.WriteLdfCompressed(LegoDataDictionary.FromString(item.ExtraInfo)); } writer.WriteBit(true); } writer.WriteBit(true); writer.Write <uint>(0); }
/// <summary> /// Launches the client. /// </summary> /// <param name="host">Host to launch.</param> /// <returns>Process that was started.</returns> public Process Launch(ServerEntry host) { // Set up the runtime if it isn't installed. if (!this.Runtime.IsInstalled) { if (this.Runtime.CanInstall) { // Install the runtime. this.Runtime.Install(); } else { // Stop the launch if a valid runtime isn't set up. return(null); } } // Modify the boot file. var bootConfigLocation = Path.Combine(this.systemInfo.ClientLocation, "boot.cfg"); LegoDataDictionary bootConfig = null; try { bootConfig = LegoDataDictionary.FromString(File.ReadAllText(bootConfigLocation).Trim().Replace("\n", ""), ','); } catch (FormatException) { bootConfig = LegoDataDictionary.FromString(File.ReadAllText(Path.Combine(this.systemInfo.ClientLocation, "boot_backup.cfg")).Trim().Replace("\n", ""), ','); } bootConfig["SERVERNAME"] = host.ServerName; bootConfig["AUTHSERVERIP"] = host.ServerAddress; File.WriteAllText(bootConfigLocation, bootConfig.ToString(",")); // Apply any pre-launch patches. foreach (var patch in Patcher.Patches) { if (patch is IPreLaunchPatch preLaunchPatch) { if (!patch.Installed) { continue; } preLaunchPatch.OnClientRequestLaunch(); } } // Launch the client. var clientProcess = this.Runtime.RunApplication(Path.Combine(this.systemInfo.ClientLocation, "legouniverse.exe"), this.systemInfo.ClientLocation); clientProcess.Start(); // Return the output. return(clientProcess); }
public override void Deserialize(BitReader reader) { Type = reader.Read <int>(); Value = reader.Read <int>(); Activator = reader.ReadGameObject(Associate.Zone); var ldl = reader.ReadString((int)reader.Read <uint>(), true); Settings = LegoDataDictionary.FromString(ldl); }
private async Task UpdateCountAsync(uint count) { if (count >= Count) { AddCount(count); } else { RemoveCount(count); } if (count > 0) { return; } await using var ctx = new UchuContext(); var item = await ctx.InventoryItems.FirstOrDefaultAsync( i => i.Id == Id ); if (item == default) { return; } if (await IsEquippedAsync()) { await UnEquipAsync(); } ctx.InventoryItems.Remove(item); await ctx.SaveChangesAsync(); // Disassemble item. if (LegoDataDictionary.FromString(item.ExtraInfo).TryGetValue("assemblyPartLOTs", out var list)) { foreach (var part in (LegoDataList)list) { await Inventory.ManagerComponent.AddItemAsync((int)part, 1); } } Destroy(this); }
public void Deserialize(BitReader reader) { ObjectId = reader.Read <ulong>(); Lot = reader.Read <int>(); if (LvlVersion >= 0x26) { AssetType = reader.Read <uint>(); } if (LvlVersion >= 0x20) { UnknownInt = reader.Read <uint>(); } Position = reader.Read <Vector3>(); Rotation = reader.ReadNiQuaternion(); Scale = reader.Read <float>(); var legoInfo = reader.ReadNiString(true); if (legoInfo.Length > 0) { try { LegoInfo = LegoDataDictionary.FromString(legoInfo); } catch (Exception e) { Console.WriteLine(legoInfo); Console.WriteLine(e); throw; } } if (LvlVersion >= 0x7) { UnknownInt1 = reader.Read <uint>(); } }
public async Task SetCountSilentAsync(uint count) { await using var ctx = new UchuContext(); if (count > ItemComponent.StackSize && ItemComponent.StackSize > 0) { Logger.Error( $"Trying to set {Lot} count to {Count}, this is beyond the item's stack-size; Setting it to stack-size" ); count = (uint)ItemComponent.StackSize; } var item = await ctx.InventoryItems.FirstAsync(i => i.Id == Id); item.Count = count; Logger.Debug($"Setting {this}'s stack size to {item.Count}"); if (count <= 0) { if (await IsEquippedAsync()) { await UnEquipAsync(); } ctx.InventoryItems.Remove(item); Destroy(this); // Disassemble item. if (LegoDataDictionary.FromString(item.ExtraInfo).TryGetValue("assemblyPartLOTs", out var list)) { foreach (var part in (LegoDataList)list) { await Inventory.ManagerComponent.AddItemAsync((int)part, 1); } } } await ctx.SaveChangesAsync(); }
public static Item Instantiate(long itemId, Inventory inventory) { using var cdClient = new CdClientContext(); using var ctx = new UchuContext(); var item = ctx.InventoryItems.FirstOrDefault( i => i.Id == itemId && i.Character.Id == inventory.ManagerComponent.GameObject.Id ); if (item == default) { Logger.Error($"{itemId} is not an item on {inventory.ManagerComponent.GameObject}"); return(null); } var cdClientObject = cdClient.ObjectsTable.FirstOrDefault( o => o.Id == item.Lot ); var itemRegistryEntry = ((Lot)item.Lot).GetComponentId(ComponentId.ItemComponent); if (cdClientObject == default || itemRegistryEntry == default) { Logger.Error($"{itemId} [{item.Lot}] is not a valid item"); return(null); } var instance = Instantiate <Item> ( inventory.ManagerComponent.Zone, cdClientObject.Name, objectId: itemId, lot: item.Lot ); if (!string.IsNullOrWhiteSpace(item.ExtraInfo)) { instance.Settings = LegoDataDictionary.FromString(item.ExtraInfo); } instance.Inventory = inventory; instance.Player = inventory.ManagerComponent.GameObject as Player; return(instance); }
public override void Serialize(BitWriter writer) { writer.WriteBit(true); var items = Items.Values.ToArray(); writer.Write((uint)items.Length); foreach (var item in items) { writer.Write(item.Id); writer.Write(item.Lot); writer.WriteBit(false); writer.WriteBit(false); writer.WriteBit(false); writer.WriteBit(false); var info = item.Id.FindItem(); if (info == default) { writer.WriteBit(false); } else { if (writer.Flag(!string.IsNullOrWhiteSpace(info.ExtraInfo))) { writer.WriteLdfCompressed(LegoDataDictionary.FromString(info.ExtraInfo)); } } writer.WriteBit(true); } writer.WriteBit(false); }
/// <summary> /// Performs and operations between setting the /// boot.cfg and launching the client. This will /// yield launching the client. /// </summary> public void OnClientRequestLaunch() { // Determine the host to check. var bootConfig = LegoDataDictionary.FromString(File.ReadAllText(Path.Combine(this.systemInfo.ClientLocation, "boot.cfg").Replace("\n", "")).Trim(), ','); var host = (string)bootConfig["AUTHSERVERIP"]; Console.WriteLine("Check for TCP/UDP for: " + host); // Assume TCP/UDP if any port is specified. // Even if 1001, the stock client will not connect correctly. if (host.Contains(":")) { var portString = host.Remove(0, host.IndexOf(":", StringComparison.Ordinal) + 1).Trim(); if (int.TryParse(portString, out var port)) { Console.WriteLine("Custom port " + port + " specified. Assuming TCP/UDP."); this.Enable(); return; } } // Try to connect and disconnect from port 21836 (default TCP/UDP port). // Port 1001 is more likely to be used by other applications like games. try { // Enable TCP/UDP after a successful connect and close. var client = new TcpClient(host, 21836); client.Close(); Console.WriteLine("Connection to default TCP/UDP port 21836 successful. Assuming TCP/UDP."); this.Enable(); } catch (Exception) { // Disable TCP/UDP (assume RakNet). Console.WriteLine("Connection to default TCP/UDP port 21836 failed. Assuming not TCP/UDP."); this.Disable(); } }