コード例 #1
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);
        }
コード例 #2
0
ファイル: Item.cs プロジェクト: kulaj/Uchu
        public static Item Instantiate(Lot lot, Inventory inventory, uint count, uint slot, LegoDataDictionary extraInfo = default)
        {
            using var cdClient = new CdClientContext();
            using var ctx      = new UchuContext();

            var cdClientObject = cdClient.ObjectsTable.FirstOrDefault(
                o => o.Id == lot
                );

            var itemRegistryEntry = cdClient.ComponentsRegistryTable.FirstOrDefault(
                r => r.Id == lot && r.Componenttype == 11
                );

            if (cdClientObject == default || itemRegistryEntry == default)
            {
                Logger.Error($"<new item> [{lot}] is not a valid item");
                return(null);
            }

            var instance = Instantiate <Item>
                           (
                inventory.ManagerComponent.Zone, cdClientObject.Name, objectId: ObjectId.Standalone, lot: lot
                           );

            instance.Settings = extraInfo ?? new LegoDataDictionary();

            var itemComponent = cdClient.ItemComponentTable.First(
                i => i.Id == itemRegistryEntry.Componentid
                );

            instance.Inventory = inventory;
            instance.Player    = inventory.ManagerComponent.GameObject as Player;

            var playerCharacter = ctx.Characters.Include(c => c.Items).First(
                c => c.Id == inventory.ManagerComponent.GameObject.Id
                );

            var inventoryItem = new InventoryItem
            {
                Count         = count,
                InventoryType = (int)inventory.InventoryType,
                Id            = instance.Id,
                IsBound       = itemComponent.IsBOP ?? false,
                Slot          = (int)slot,
                Lot           = lot,
                ExtraInfo     = extraInfo?.ToString()
            };

            playerCharacter.Items.Add(inventoryItem);

            ctx.SaveChanges();

            var message = new AddItemToInventoryMessage
            {
                Associate       = inventory.ManagerComponent.GameObject,
                InventoryType   = (int)inventory.InventoryType,
                Delta           = count,
                TotalItems      = count,
                Slot            = (int)slot,
                ItemLot         = lot,
                IsBoundOnEquip  = itemComponent.IsBOE ?? false,
                IsBoundOnPickup = itemComponent.IsBOP ?? false,
                IsBound         = inventoryItem.IsBound,
                Item            = instance,
                ExtraInfo       = extraInfo
            };

            (inventory.ManagerComponent.GameObject as Player)?.Message(message);

            inventory.ManageItem(instance);

            return(instance);
        }