コード例 #1
0
        public override void RegisterContent()
        {
            Logger.Debug($"Registering content.");

            var def = RegisterEncounterIcon("@:my_item_icon", "my_item.png");

            RegisterSpriteCollection(
                "@:my_item_coll",
                def
                );
            RegisterSpriteTemplate(
                "@:my_item_sprite",
                "@:my_item_coll",
                "@:my_item_icon"
                );
            RegisterLocalization(
                "@:english_items",
                "english_items.txt",
                "gungeon:english",
                I18N.StringTable.Items
                );

            RegisterItem <MyItem>(
                "@:my_item",
                "@:my_item_icon",
                "@:my_item_sprite",
                "#@:MY_ITEM_NAME",
                "#@:MY_ITEM_SHORT_DESC",
                "#@:MY_ITEM_LONG_DESC"
                );
        }
コード例 #2
0
ファイル: FakePrefab.cs プロジェクト: dadebert/Semi
        /// <summary>
        /// Clones a real prefab or a fake prefab into a new fake prefab.
        /// </summary>
        /// <returns>The new game object.</returns>
        /// <param name="obj">GameObject to clone.</param>
        public static GameObject Clone(GameObject obj)
        {
            var already_fake = IsFakePrefab(obj);
            var was_active   = obj.activeSelf;

            if (was_active)
            {
                obj.SetActive(false);
            }
            var fakeprefab = UnityEngine.Object.Instantiate(obj);

            if (was_active)
            {
                obj.SetActive(true);
            }
            ExistingFakePrefabs.Add(fakeprefab);
            if (already_fake)
            {
                Logger.Debug($"Fake prefab '{obj}' cloned as new fake prefab");
            }
            else
            {
                Logger.Debug($"Prefab/object '{obj}' cloned as new fake prefab");
            }
            return(fakeprefab);
        }
コード例 #3
0
        public void SetupSGUI()
        {
            Logger.Debug("SetupSGUI()");

            GUIRoot = SGUIRoot.Setup();
            SGUIIMBackend.GetFont = (SGUIIMBackend backend) => {
                if (Patches.MainMenuFoyerController.Instance?.VersionLabel == null)
                {
                    return(null);
                }
                return(GungeonFont ?? (GungeonFont = FontConverter.DFFontToUnityFont((dfFont)Patches.MainMenuFoyerController.Instance.VersionLabel.Font, 2)));
            };
        }
コード例 #4
0
                // Raw mode - you provide the path->texture map
                public CollectionGenerator(Dictionary <string, Texture2D> textures, YAML.Collection mapping, GameObject gameobj)
                {
                    TargetGameObject = gameobj;
                    Mapping          = mapping;

                    var tex_list = new List <Texture2D>();

                    // first the general spritesheet, if it exists
                    if (mapping.Spritesheet != null)
                    {
                        _SpritesheetID(mapping.Spritesheet);
                        tex_list.Add(textures[mapping.Spritesheet]);
                        Logger.Debug($"New spritesheet: '{mapping.Spritesheet}', ID: {_LastSpritesheetID - 1}");
                    }

                    // ...then the clip spritesheets
                    foreach (var def in mapping.Definitions)
                    {
                        if (def.Value.Spritesheet != null)
                        {
                            _SpritesheetID(def.Value.Spritesheet);
                            tex_list.Add(textures[def.Value.Spritesheet]);
                            Logger.Debug($"New spritesheet: '{def.Value.Spritesheet}', ID: {_LastSpritesheetID - 1}");
                        }
                    }

                    Textures = tex_list.ToArray();
                }
コード例 #5
0
ファイル: ModVerification.cs プロジェクト: dadebert/Semi
        /// <summary>
        /// Compares two hashes based on the SemiModVerification repository.
        /// </summary>
        /// <returns><c>true</c>, if hashes match, <c>false</c> otherwise.</returns>
        /// <param name="mod_id">ID of the mod.</param>
        /// <param name="hash">The computed hash.</param>
        public static bool ValidateHashOnline(string mod_id, byte[] hash)
        {
            var url = $"{BASE_VERIFICATION_URL}{mod_id}";

            Logger.Debug($"Validating from URL: {url}");
            byte[] online_hash = null;
            using (var client = new WebClient()) {
                ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback;
                client.Encoding = Encoding.UTF8;
                try {
                    online_hash = client.DownloadData(url);
                } catch (WebException e) {
                    Logger.Error($"[{e.GetType().Name}] {e.Message}");
                    Logger.ErrorPretty(e.StackTrace);
                    return(false);
                }
            }

            return(ValidateHash(online_hash, hash));
        }
コード例 #6
0
        internal static Dictionary <string, string> LoadDFLocalizationText(TextReader reader, Dictionary <string, string> dict, bool overwrite = false, string default_namespace = null)
        {
            string text;

            while ((text = reader.ReadLine()) != null)
            {
                if (text.Trim() == "")
                {
                    continue;
                }

                if (!text.StartsWithInvariant("//"))
                {
                    if (text.StartsWithInvariant("#"))
                    {
                        var elements = text.Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries);
                        // we split on " instead of ,
                        // because from my research it appears that " is never used escaped,
                        // and commas appear in the localized text

                        string value = null;

                        if (elements.Length < 2)
                        {
                            Logger.Warn($"DF loc line has <2 elements! Assuming empty value string.");
                            value = "";
                        }
                        else
                        {
                            value = elements[1];
                        }

                        var key = elements[0].Substring(1, elements[0].Length - 2);

                        if (default_namespace != null)
                        {
                            if (key.Count(':') > 1)
                            {
                                Logger.Error($"Failed to add invalid key to table: {key}");
                                continue;
                            }

                            if (!key.Contains(":"))
                            {
                                key = $"{default_namespace}:{key}";
                            }

                            if (key.StartsWithInvariant("gungeon:"))
                            {
                                var pair = key.SplitIntoPair(":");
                                key = $"{pair.EverythingElse}";
                            }
                        }

                        key = $"#{key}";

                        if (elements.Length > 2)
                        {
                            Logger.Warn($"Ignoring unknown elements in DF loc line: #{text}");
                        }

                        if (dict.ContainsKey(key) && !overwrite)
                        {
                            Logger.Error($"Failed to add duplicate key to table: {text}");
                        }
                        else
                        {
                            Logger.Debug($"DF INSERT KEY: {key} VALUE: {value}");
                            dict[key] = value;
                        }
                    }
                }
            }
            return(dict);
        }
コード例 #7
0
 internal static TextAsset LoadTextAsset(string path)
 {
     Logger.Debug($"Loading builtin localization asset 'strings/{path}'");
     return((TextAsset)BraveResources.Load("strings/" + path, typeof(TextAsset), ".txt"));
 }
コード例 #8
0
 public override void RegisterContent()
 {
     Logger.Debug($"Registering content.");
 }
コード例 #9
0
ファイル: Collection.cs プロジェクト: ModUntitled/ModUntitled
            public int PatchCollection(tk2dSpriteCollectionData target)
            {
                // since we modify the target, we have to save these now
                int material_id_offset = target.materials.Length;

                // the reason we calculate the sprite ID offset right now and
                // don't even use it in this method (but instead just return it)
                // is because we modify target.spriteDefinitions later on
                // therefore, any attempt at calculating the offset after running this method
                // will yield totally wrong results
                int sprite_id_offset = target.spriteDefinitions.Length;

                _Logger.Debug($"Material ID offset: {material_id_offset}, sprite ID offset: {sprite_id_offset}");

                // list of merged materials from both target and source
                // note the layout - first target materials, then source materials
                // this means that the length of *just* the target materials
                // will always be the where our target materials start
                // therefore, `material_id_offset`
                var materials_list = new List <Material>(target.materials);

                for (int i = 0; i < CollectionData.materials.Length; i++)
                {
                    _Logger.Debug($"Adding patch material #{i}");
                    materials_list.Add(CollectionData.materials[i]);
                }
                var materials_arr = materials_list.ToArray();

                // try to do the most sensible thing here
                // if target is a bit more unusual and target.materialInsts doesn't have the same refs
                // as target.materials, we do the same thing as above for materialInsts
                // except that we use target.materialInsts
                // in the current version of the animator generation materialInsts has the same refs as materials
                // but just in case that's changed in the future, this also pulls from materialInsts on the
                // patch
                if (!target.materials.SequenceEqual(target.materialInsts))
                {
                    _Logger.Debug($"target.materials sequence-inequal to target.materialInsts");

                    var materialinsts_list = new List <Material>(target.materialInsts);
                    for (int i = 0; i < CollectionData.materialInsts.Length; i++)
                    {
                        materialinsts_list.Add(CollectionData.materialInsts[i]);
                    }
                    target.materialInsts = materialinsts_list.ToArray();
                }
                else
                {
                    // of course, if the refs are the same,
                    // then save on allocations and just assign the same array
                    // to both fields
                    target.materialInsts = materials_arr;
                }

                target.materials = materials_arr;

                var patched_in_order_lookup      = new HashSet <tk2dSpriteDefinition>();
                var definitions_list             = new List <tk2dSpriteDefinition>();
                var patch_definition_name_lookup = new Dictionary <string, tk2dSpriteDefinition>();

                for (int i = 0; i < CollectionData.spriteDefinitions.Length; i++)
                {
                    var def = CollectionData.spriteDefinitions[i];
                    patch_definition_name_lookup[def.name] = def;
                }

                for (int i = 0; i < target.spriteDefinitions.Length; i++)
                {
                    var def = target.spriteDefinitions[i];
                    tk2dSpriteDefinition source_definition = null;
                    if (patch_definition_name_lookup.TryGetValue(def.name, out source_definition))
                    {
                        _Logger.Debug($"Patching definition '{def.name}' at ID {i}");

                        var new_definition = new tk2dSpriteDefinition();
                        CopyDefinition(source_definition, new_definition);

                        // this is why we saved material_id_offset before
                        // we can update the definition's material data by simply adding the offset to the id
                        // and updating the materials
                        new_definition.materialId  += material_id_offset;
                        new_definition.material     = target.materials[new_definition.materialId];
                        new_definition.materialInst = target.materialInsts[new_definition.materialId];

                        definitions_list.Add(new_definition);

                        patched_in_order_lookup.Add(source_definition);
                    }
                    else
                    {
                        definitions_list.Add(def);
                    }
                }

                int total_index = definitions_list.Count - 1;

                for (int i = 0; i < CollectionData.spriteDefinitions.Length; i++)
                {
                    var source_definition = CollectionData.spriteDefinitions[i];
                    if (patched_in_order_lookup.Contains(source_definition))
                    {
                        continue;
                    }

                    total_index++;
                    _Logger.Debug($"Adding definition '{source_definition.name}' at ID {total_index}");
                    var new_definition = new tk2dSpriteDefinition();
                    CopyDefinition(source_definition, new_definition);

                    new_definition.materialId  += material_id_offset;
                    new_definition.material     = target.materials[new_definition.materialId];
                    new_definition.materialInst = target.materialInsts[new_definition.materialId];

                    definitions_list.Add(new_definition);
                }

                target.spriteDefinitions = definitions_list.ToArray();

                // finally, return the sprite id offset
                return(sprite_id_offset);
            }
コード例 #10
0
ファイル: Animation.cs プロジェクト: ModUntitled/ModUntitled
        private tk2dSpriteAnimator _CreateAnimator(GameObject go, tk2dSpriteCollectionData collection, bool replace_component = true)
        {
            var animation = _CreateAnimation(go, collection, replace_component);

            if (replace_component)
            {
                _Logger.Debug("Trying to destroy existing tk2dSpriteAnimator!");
                var component = go.GetComponent <tk2dSpriteAnimator>();
                if (component != null)
                {
                    _Logger.Debug($"Component found");
                    UnityEngine.Object.Destroy(component);
                }
                else
                {
                    _Logger.Debug($"Component not found");
                }
            }
            var animator = go.AddComponent <tk2dSpriteAnimator>();

            animator.enabled = true;
            animator.Library = animation;
            animator.ClipFps = _FPS ?? YAML.Animation.DEFAULT_FPS;

            return(animator);
        }