public static void Clear()
        {
            TextureReplacements.Clear();
            TextureResolutions.Clear();
            FilesExist.Clear();
            MusicManager.ReloadMusic();
            SoundEffectManager.ReloadSounds();
            ModelManager.Clear();
            TextureManager.TextureList.Clear();
            // TODO
            //Water.ClearAnimationResources();
            //Whirlpool.LoadedWaterTemp = false;
            //Waterfall.ClearAnimationResources();

            Logger.Debug("---Cleared ContentPackManager---");
        }
示例#2
0
        public static Texture ReplaceTexture(Texture original)
        {
            if (original == null)
            {
                //Debug.Log("original is null");
                return(original);
            }

            if (!(TextureReplacements.ContainsKey(original.name)))
            {
                return(original);
            }

            Debug.Log($"Replacing {original.name} with {TextureReplacements[original.name].Name}");

            return(GetTexture(TextureReplacements[original.name].Name));
        }
        public static void Load(string contentPackFile)
        {
            if (Directory.Exists(Path.Combine(GameController.GamePath, "ContentPacks")))
            {
                if (!File.Exists(contentPackFile))
                {
                    return;
                }
                foreach (var line in File.ReadAllLines(contentPackFile))
                {
                    switch (line.CountSplits("|"))
                    {
                    case 2:
                        //ResolutionChange
                        var textureName = line.GetSplit(0, "|");
                        var resolution  = Convert.ToInt32(line.GetSplit(1, "|"));

                        if (!TextureResolutions.ContainsKey(textureName))
                        {
                            TextureResolutions.Add(textureName, resolution);
                        }
                        break;

                    case 4:
                        //TextureReplacement
                        var oldTextureName = line.GetSplit(0, "|");
                        var newTextureName = line.GetSplit(2, "|");
                        var oRs            = line.GetSplit(1, "|");
                        //oRS = oldRectangleSource
                        var nRs = line.GetSplit(3, "|");
                        //nRS = newRectangleSource

                        var oldTextureSource = new TextureSource(oldTextureName, new Rectangle(Convert.ToInt32(oRs.GetSplit(0)), Convert.ToInt32(oRs.GetSplit(1)), Convert.ToInt32(oRs.GetSplit(2)), Convert.ToInt32(oRs.GetSplit(3))));
                        var newTextureSource = new TextureSource(newTextureName, new Rectangle(Convert.ToInt32(nRs.GetSplit(0)), Convert.ToInt32(nRs.GetSplit(1)), Convert.ToInt32(nRs.GetSplit(2)), Convert.ToInt32(nRs.GetSplit(3))));

                        if (!TextureReplacements.ContainsKey(oldTextureSource))
                        {
                            TextureReplacements.Add(oldTextureSource, newTextureSource);
                        }

                        break;
                    }
                }
            }
        }
示例#4
0
        /// <inheritdoc/>
        public void LoadBinaryData(byte[] inData)
        {
            using (var ms = new MemoryStream(inData))
                using (var br = new BinaryReader(ms))
                {
                    br.ReadUInt32(); // Signature
                    Version = br.ReadUInt32();
                    Name    = br.ReadMD20String(br.ReadUInt32(), br.ReadUInt32());
                    Flags   = br.ReadUInt32(); // TODO: Implement Flags


                    // Global Sequences
                    UInt32 count     = br.ReadUInt32();
                    UInt32 offset    = br.ReadUInt32();
                    long   headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        UInt32 value = br.ReadUInt32();
                        GlobalSequences.Add(value);
                    }
                    br.BaseStream.Position = headerpos;

                    // Sequences
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Sequence seq = new M2Sequence();

                        seq.AnimationID         = br.ReadUInt16();
                        seq.SubAnimationID      = br.ReadUInt16();
                        seq.Length              = br.ReadUInt32();
                        seq.MovingSpeed         = br.ReadSingle();
                        seq.Flags               = br.ReadUInt32();
                        seq.Probability         = br.ReadInt16();
                        seq.Padding             = br.ReadUInt16();
                        seq.MinimumRepetitions  = br.ReadUInt32();
                        seq.MaximumRepetitions  = br.ReadUInt32();
                        seq.BlendTime           = br.ReadUInt32();
                        seq.BoundsMinimumExtend = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        seq.BoundsMaximumExtend = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        seq.BoundRadius         = br.ReadSingle();
                        seq.NextAnimation       = br.ReadInt16();
                        seq.aliasNext           = br.ReadUInt16();

                        Sequences.Add(seq);
                    }
                    br.BaseStream.Position = headerpos;

                    //SequencesLookups
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        SequencesLookups.Add(br.ReadInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Bones
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Bone bone = new M2Bone();

                        bone.KeyBoneID  = br.ReadInt32();
                        bone.Flags      = br.ReadUInt32();
                        bone.ParentBone = br.ReadInt16();
                        bone.SubmeshID  = br.ReadUInt16();

                        bone.CompressData[0] = br.ReadUInt16();
                        bone.CompressData[1] = br.ReadUInt16();

                        //translation

                        M2Track translation = new M2Track();
                        translation.readM2Track(br);
                        bone.translation = translation;

                        // rotation
                        M2Track rotation = new M2Track();
                        rotation.readM2Track(br);
                        bone.rotation = rotation;

                        // Scale
                        M2Track scale = new M2Track();
                        scale.readM2Track(br);
                        bone.scale = scale;

                        bone.pivot = new C3Vector(br.ReadUInt32(), br.ReadUInt32(), br.ReadUInt32());

                        Bones.Add(bone);
                    }
                    br.BaseStream.Position = headerpos;

                    // key_bone_lookup
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        KeyBoneLookup.Add(br.ReadInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Vetices
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Vertex temp = new M2Vertex();

                        temp.Pos = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        for (int a = 0; a < 4; a++)
                        {
                            temp.BoneWeights.Add(br.ReadByte());
                        }
                        for (int a = 0; a < 4; a++)
                        {
                            temp.BoneIndices.Add(br.ReadByte());
                        }
                        temp.Normal = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        temp.TexCords.Add(new C2Vector(br.ReadSingle(), br.ReadSingle()));
                        temp.TexCords.Add(new C2Vector(br.ReadSingle(), br.ReadSingle()));
                    }
                    br.BaseStream.Position = headerpos;

                    // Number of Skin profiles
                    NumberSkinProfiles = br.ReadUInt32();

                    // Colors
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Color temp = new M2Color();

                        // Color
                        M2Track color = new M2Track();
                        color.readM2Track(br);
                        temp.Color = color;

                        // Alpha
                        M2Track alpha = new M2Track();
                        alpha.readM2Track(br);
                        temp.Alpha = alpha;

                        Color.Add(temp);
                    }
                    br.BaseStream.Position = headerpos;

                    // Textures
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Texture temp = new M2Texture();

                        temp.Type  = br.ReadUInt32();
                        temp.Flags = br.ReadUInt32();

                        UInt32 tCount     = br.ReadUInt32();
                        UInt32 tOffset    = br.ReadUInt32();
                        long   tHeaderpos = br.BaseStream.Position;
                        br.BaseStream.Position = tOffset;

                        temp.Filename = "";
                        for (int a = 0; a < tCount; a++)
                        {
                            temp.Filename += br.ReadChar();
                        }
                        br.BaseStream.Position = tHeaderpos;

                        Texture.Add(temp);
                    }
                    br.BaseStream.Position = headerpos;

                    // Texture Weights
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Track temp = new M2Track();
                        temp.readM2Track(br);
                        TextureWeights.Add(temp);
                    }
                    br.BaseStream.Position = headerpos;

                    // UV Animations
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2TextureTransform temp = new M2TextureTransform();

                        M2Track translation = new M2Track();
                        translation.readM2Track(br);
                        temp.Translation = translation;

                        M2Track rotation = new M2Track();
                        rotation.readM2Track(br);
                        temp.Rotation = rotation;

                        M2Track scaling = new M2Track();
                        scaling.readM2Track(br);
                        temp.Scaling = scaling;

                        UvAnimations.Add(temp);
                    }
                    br.BaseStream.Position = headerpos;

                    // Texture Replacements
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        TextureReplacements.Add(br.ReadInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Materials
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Material temp = new M2Material();

                        temp.Flags     = br.ReadUInt16();
                        temp.BlendMode = br.ReadUInt16();

                        Materials.Add(temp);
                    }
                    br.BaseStream.Position = headerpos;

                    // Bone Lookups
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        BoneLookups.Add(br.ReadUInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Texture Units
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        TextureUnits.Add(br.ReadUInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Texture Weights Lookups
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        TextureWeightsLookups.Add(br.ReadUInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Animation Lookups
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        UvAnimationLookups.Add(br.ReadInt16());
                    }
                    br.BaseStream.Position = headerpos;
                }
        }