예제 #1
0
        private void ReplaceMaterials(GameObject go, string path)
        {
            var meshRenderers = go.GetComponentsInChildren <MeshRenderer>();

            foreach (var meshRenderer in meshRenderers)
            {
                var materials = meshRenderer.materials;
                if (materials == null)
                {
                    continue;
                }
                for (var index = 0; index < materials.Length; index++)
                {
                    var material     = materials[index];
                    var materialName = material.name.Replace(" (Instance)", "");

                    Sideloader.LogDebug($"Material: {string.Join(":", new[] {path, materialName})}");
                    var materialMod = AssetTree.Find(path, materialName).FirstOrDefault();
                    if (materialMod != null)
                    {
                        materials[index] = materialMod.Mod.LoadMaterial(materialMod.FullPath);
                    }
                }

                meshRenderer.materials = materials;
            }
        }
예제 #2
0
 private void PatchLoadedResource(ResourceLoadedContext ctx)
 {
     Sideloader.LogDebug(
         $"Loaded resource to load resource {ctx.Parameters.Path}, {ctx.Parameters.Type}");
     foreach (var obj in ctx.Assets)
     {
         var path = ctx.GetUniqueFileSystemAssetPath(obj);
         if (!(obj is ItemSpawnerID itemSpawnerId))
         {
             continue;
         }
         ReplaceItemSpawnerIcon(itemSpawnerId, path);
     }
 }
예제 #3
0
        private void ReplaceMeshes(GameObject go, string path)
        {
            // TODO: Eventually, might need to handle SkinnedMeshRenderers, but for now it seems H3 doesn't use those for guns
            var meshFilters = go.GetComponentsInChildren <MeshFilter>();

            foreach (var meshFilter in meshFilters)
            {
                var filterName = meshFilter.name;
                var meshName   = meshFilter.mesh.name.Replace(" Instance", "");
                Sideloader.LogDebug($"Mesh: {string.Join(":", new[] {path, filterName, meshName})}");
                var replacement = AssetTree.Find(path, filterName, meshName).FirstOrDefault();
                if (replacement != null)
                {
                    meshFilter.mesh = replacement.Mod.LoadMesh(replacement.FullPath);
                }
            }
        }
예제 #4
0
        private void ReplaceItemSpawnerIcon(ItemSpawnerID itemSpawnerId, string path)
        {
            if (!itemSpawnerId.Sprite)
            {
                return;
            }
            Sideloader.LogDebug(
                $"ItemSpawnerID Icon: {string.Join(":", new[] {path, itemSpawnerId.Sprite.name, itemSpawnerId.Sprite.texture.name})}");
            var mod = AssetTree.Find(path, itemSpawnerId.Sprite.name, itemSpawnerId.Sprite.texture.name)
                      .FirstOrDefault();

            if (mod == null)
            {
                return;
            }
            var tex    = mod.Mod.LoadTexture(mod.FullPath);
            var sprite = Sprite.Create(tex, itemSpawnerId.Sprite.rect, itemSpawnerId.Sprite.pivot,
                                       itemSpawnerId.Sprite.pixelsPerUnit, 0, SpriteMeshType.Tight, itemSpawnerId.Sprite.border);

            itemSpawnerId.Sprite = sprite;
        }
예제 #5
0
        private void ReplaceTextures(GameObject go, string path)
        {
            var meshRenderers = go.GetComponentsInChildren <MeshRenderer>();

            foreach (var meshRenderer in meshRenderers)
            {
                var materials = meshRenderer.materials;
                if (materials == null)
                {
                    continue;
                }
                foreach (var material in materials)
                {
                    var materialName = material.name.Replace("(Instance)", "").Trim();

                    var textureName = material.mainTexture ? material.mainTexture.name : "NULL";
                    Sideloader.LogDebug($"Texture: {string.Join(":", new[] {path, materialName, textureName})}");
                    var nodes = AssetTree.Find(path, materialName, textureName);
                    if (nodes.Length == 0)
                    {
                        continue;
                    }
                    // TODO: Remove duplicates to prevent duplicate loading
                    foreach (var modNode in nodes)
                    {
                        var tex = modNode.Mod.LoadTexture(modNode.FullPath);
                        if (modNode.Path == null)
                        {
                            material.mainTexture = tex;
                        }
                        else
                        {
                            material.SetTexture(modNode.Path, tex);
                        }
                    }
                }

                meshRenderer.materials = materials;
            }
        }