Exemplo n.º 1
0
        public ItemStorage(string itemFile)
        {
            string[] parts = Path.GetFileNameWithoutExtension(itemFile).Split('_');

            guid = parts[parts.Length - 1];
            string itemId       = string.Join("_", parts.Take(parts.Length - 1));
            string templateFile = Path.Combine(BepInExPlugin.templatesPath, itemId + ".json");

            BepInExPlugin.Dbgl($"Loading item storage {itemId} {guid}");

            if (File.Exists(templateFile))
            {
                BepInExPlugin.Dbgl("Loading template data");
                meta = JsonUtility.FromJson <ItemStorageMeta>(File.ReadAllText(templateFile));
            }
            else
            {
                throw new Exception("Template not found");
            }

            inventory = new Inventory(meta.itemName, null, meta.width, meta.height);

            if (File.Exists(itemFile))
            {
                string   input = File.ReadAllText(itemFile);
                ZPackage pkg   = new ZPackage(input);
                inventory.Load(pkg);
                BepInExPlugin.Dbgl($"Loaded existing inventory with {inventory.NrOfItems()} items");
            }
        }
Exemplo n.º 2
0
        private void Awake()
        {
            context       = this;
            modEnabled    = Config.Bind <bool>("General", "Enabled", true, "Enable this mod");
            isDebug       = Config.Bind <bool>("General", "IsDebug", true, "Enable debug logs");
            nexusID       = Config.Bind <int>("General", "NexusID", 1347, "Nexus mod ID for updates");
            nexusID.Value = 1347;

            requireExistingTemplate = Config.Bind <bool>("Variables", "RequireExistingTemplate", true, "Storage template for item must exist to create inventory. (Otherwise a new template will be created)");
            requireEquipped         = Config.Bind <bool>("Variables", "RequireEquipped", true, "Item must be equipped to open inventory");

            if (!modEnabled.Value)
            {
                return;
            }
            assetPath     = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), typeof(BepInExPlugin).Namespace);
            templatesPath = Path.Combine(assetPath, "templates");
            itemsPath     = Path.Combine(assetPath, "items");
            if (!Directory.Exists(assetPath))
            {
                Directory.CreateDirectory(assetPath);
                Directory.CreateDirectory(templatesPath);
                Directory.CreateDirectory(itemsPath);
            }

            harmony = new Harmony(Info.Metadata.GUID);
            harmony.PatchAll();
        }
Exemplo n.º 3
0
 public ItemStorage(ItemDrop.ItemData item, string oldGuid)
 {
     guid = oldGuid;
     meta = new ItemStorageMeta()
     {
         itemId   = item.m_dropPrefab.name,
         itemName = Localization.instance.Localize(item.m_shared.m_name)
     };
     inventory = new Inventory(meta.itemName, null, meta.width, meta.height);
     BepInExPlugin.Dbgl($"Created new item storage {meta.itemId} {oldGuid}");
 }