示例#1
0
        // Token: 0x0600010A RID: 266 RVA: 0x0000B6B0 File Offset: 0x000098B0
        public void InitMaterials(string slotName, List <ACCMaterial> edited)
        {
            bool flag = false;

            for (int i = 0; i < edited.Count; i++)
            {
                TargetMaterial targetMaterial = this.GetMaterial(slotName, i);
                if (targetMaterial == null)
                {
                    targetMaterial = new TargetMaterial(slotName, i, string.Empty)
                    {
                        onlyModel = true
                    };
                    this.AddSlotMaterial(targetMaterial);
                    TBody.SlotID key = (TBody.SlotID)Enum.Parse(typeof(TBody.SlotID), slotName, false);
                    Item         item;
                    this.itemSlots.TryGetValue(key, out item);
                }
                targetMaterial.Init(edited[i]);
                flag |= targetMaterial.shaderChanged;
                if (targetMaterial.onlyModel)
                {
                    flag |= (targetMaterial.hasTexColorChanged | targetMaterial.hasTexFileChanged);
                }
            }
            foreach (Item item2 in this.addItems)
            {
                if (item2.slot == slotName)
                {
                    item2.needUpdate = flag;
                }
            }
        }
示例#2
0
 // Token: 0x0600016A RID: 362 RVA: 0x0000CEFA File Offset: 0x0000B0FA
 public ReplacedInfo(string src, string replaced, ResourceRef res, TargetMaterial tm)
 {
     this.source   = src;
     this.replaced = replaced;
     this.res      = res;
     this.material = tm;
 }
示例#3
0
        public void AddSlotMaterial(TargetMaterial tm)
        {
            LogUtil.Debug("Add slot material", tm.editname);

            SlotMaterials slotMat;

            if (!slotMaterials.TryGetValue(tm.slotName, out slotMat))
            {
                slotMat = new SlotMaterials();
                slotMaterials[tm.slotName] = slotMat;
            }
            slotMat.SetMaterial(tm);
        }
示例#4
0
        // Token: 0x0600010E RID: 270 RVA: 0x0000B7FC File Offset: 0x000099FC
        public void AddSlotMaterial(TargetMaterial tm)
        {
            LogUtil.Debug(new object[]
            {
                "Add slot material",
                tm.editname
            });
            SlotMaterials slotMaterials;

            if (!this.slotMaterials.TryGetValue(tm.slotName, out slotMaterials))
            {
                slotMaterials = new SlotMaterials();
                this.slotMaterials[tm.slotName] = slotMaterials;
            }
            slotMaterials.SetMaterial(tm);
        }
示例#5
0
        /// <summary>編集されたマテリアル情報を元に、各種マテリアル情報の更新状態を抽出する</summary>
        /// <param name="slotName">対象スロット名</param>
        /// <param name="edited">編集されたマテリアル情報</param>
        public void InitMaterials(string slotName, List <ACCMaterial> edited)
        {
            var needUpdate = false;

            for (var matNo = 0; matNo < edited.Count; matNo++)
            {
                var tm = GetMaterial(slotName, matNo);
                if (tm == null)
                {
                    // menuのマテリアル変更で指定されていないmaterial
                    tm = new TargetMaterial(slotName, matNo, string.Empty)
                    {
                        onlyModel = true
                    };
                    AddSlotMaterial(tm);

                    // modelファイルからマテリアル情報をロード 毎回ロードするのは非効率
                    //   ※高速化したい場合は、不足しているマテリアル情報を一括して取得する
                    var  slot = (TBody.SlotID)Enum.Parse(typeof(TBody.SlotID), slotName, false);
                    Item item;
                    if (itemSlots.TryGetValue(slot, out item))
                    {
                        // TODO modelからmatNoを元に抽出
                        // item.filename
                    }
                }

                tm.Init(edited[matNo]);
                needUpdate |= tm.shaderChanged;
                if (tm.onlyModel)
                {
                    needUpdate |= (tm.hasTexColorChanged | tm.hasTexFileChanged);
                }
            }

            // modelファイルの更新の必要性をチェック
            //   対象slotのモデルでシェーダが変更されたか否か
            //   あるいは、tex色変更かtexファイル変更が行われたか
            foreach (var item in addItems)
            {
                if (item.slot == slotName)
                {
                    item.needUpdate = needUpdate;
                }
            }
        }
示例#6
0
        // Token: 0x06000115 RID: 277 RVA: 0x0000C470 File Offset: 0x0000A670
        public void SetMaterial(TargetMaterial tm)
        {
            int num = tm.matNo - this.materials.Count;

            if (num == 0)
            {
                this.materials.Add(tm);
                return;
            }
            if (num > 0)
            {
                for (int i = 0; i < num; i++)
                {
                    this.materials.Add(null);
                }
                this.materials.Add(tm);
                return;
            }
            this.materials[tm.matNo] = tm;
        }
示例#7
0
        public void SetMaterial(TargetMaterial tm)
        {
            // matNoをリストのインデックスとして挿入
            var lack = tm.matNo - materials.Count;

            if (lack == 0)
            {
                materials.Add(tm);
            }
            else if (lack > 0)
            {
                for (var i = 0; i < lack; i++)
                {
                    materials.Add(null);
                }
                materials.Add(tm);
            }
            else
            {
                materials[tm.matNo] = tm;
            }
        }
        /// <summary>編集されたマテリアル情報を元に、各種マテリアル情報の更新状態を抽出する</summary>
        /// <param name="slotName">対象スロット名</param>
        /// <param name="edited">編集されたマテリアル情報</param>
        public void InitMaterials(string slotName, List<ACCMaterial> edited) {

            bool needUpdate = false;
            for (int matNo=0; matNo< edited.Count; matNo++) {
                TargetMaterial tm = GetMaterial(slotName, matNo);
                if (tm == null) {
                    // menuのマテリアル変更で指定されていないmaterial
                    tm = new TargetMaterial(slotName, matNo, string.Empty);
                    tm.onlyModel = true;
                    AddSlotMaterial(tm);

                    // modelファイルからマテリアル情報をロード 毎回ロードするのは非効率
                    //   ※高速化したい場合は、不足しているマテリアル情報を一括して取得する
                    var slot = (TBody.SlotID)Enum.Parse(typeof(TBody.SlotID), slotName, false);
                    Item item;
                    if (itemSlots.TryGetValue(slot, out item)) {
                        // TODO modelからmatNoを元に抽出
                        // item.filename
                    }
                } 
                tm.Init(edited[matNo]);
                needUpdate |= tm.shaderChanged;
                if (tm.onlyModel) {
                    needUpdate |= (tm.hasTexColorChanged | tm.hasTexFileChanged); 
                }
            }

            // modelファイルの更新の必要性をチェック
            //   対象slotのモデルでシェーダが変更されたか否か
            //   あるいは、tex色変更かtexファイル変更が行われたか
            foreach (var item in addItems) {
                if (item.slot == slotName) {
                    item.needUpdate = needUpdate;
                }
            }
        }
 public void WriteMateFile(string infile, string outfilepath, TargetMaterial trgtMat) {
     bool onBuffer;
     using ( var reader = new BinaryReader(GetStream(infile, out onBuffer), Encoding.UTF8) ) {
         var header = reader.ReadString();
         if (onBuffer || reader.BaseStream.Position > 0) {
             if (header == FileConst.HEAD_MATE) {
                 WriteMateFile(reader, header, outfilepath, trgtMat);
                 return;
             }
             var msg = LogUtil.Error("正しいmateファイルではありません。ヘッダが不正です。", header, ", infile=", infile);
             throw new ACCException(msg.ToString());
         }
     }
     
     // arc内のファイルがロードできない場合の回避策: Sybaris 0410向け対策. 一括読み込み
     using (var reader = new BinaryReader(new MemoryStream(FileUtilEx.Instance.LoadInternal(infile), false), Encoding.UTF8)) {
         string header = reader.ReadString(); // hader
         if (header == FileConst.HEAD_MATE) {
             WriteMateFile(reader, header, outfilepath, trgtMat);
         }
         var msg = LogUtil.Error("正しいmateファイルではありません。ヘッダが不正です。", header, ", infile=", infile);
         throw new ACCException(msg.ToString());
     }
 }
 public void SetMaterial(TargetMaterial tm) {
     // matNoをリストのインデックスとして挿入
     int lack = tm.matNo - materials.Count;
     if (lack == 0) {
         materials.Add(tm);
     } else if (lack > 0) {
         for(int i=0; i<lack; i++) {
             materials.Add(null);
         }
         materials.Add(tm);
     } else {
         materials[tm.matNo] = tm;
     }
 }
示例#11
0
 // Token: 0x0600015D RID: 349 RVA: 0x0000CE04 File Offset: 0x0000B004
 public Func <string, string[], string[]> ReplaceMenuFunc()
 {
     this.replaceFiles = new List <ReplacedInfo>();
     return(delegate(string key, string[] param)
     {
         if (key != null)
         {
             if (!(key == "additem"))
             {
                 if (!(key == "マテリアル変更"))
                 {
                     return param;
                 }
             }
             else
             {
                 if (param.Length < 2)
                 {
                     return param;
                 }
                 string text = param[1];
                 try
                 {
                     TBody.SlotID key2 = (TBody.SlotID)Enum.Parse(typeof(TBody.SlotID), text, false);
                     Item item = this.menu.itemSlots[key2];
                     if (item.needUpdate)
                     {
                         string text2 = param[0];
                         string text3;
                         if (item.filename == text2)
                         {
                             item.worksuffix = null;
                             text3 = item.EditFileName();
                         }
                         else
                         {
                             item.worksuffix = this.suffix;
                             text3 = item.EditFileName();
                             this.replaceFiles.Add(new ReplacedInfo(text2, text3, this, item));
                         }
                         param[0] = text3;
                     }
                     return param;
                 }
                 catch (Exception ex)
                 {
                     LogUtil.Debug(new object[]
                     {
                         "failed to parse SlotID:",
                         text,
                         ex
                     });
                     return param;
                 }
             }
             string slot = param[0];
             int matNo = int.Parse(param[1]);
             string text4 = param[2];
             TargetMaterial material = this.menu.GetMaterial(slot, matNo);
             material.worksuffix = null;
             if (material.filename == text4)
             {
                 param[2] = material.EditFileName();
             }
             else if (material.shaderChanged || material.hasParamChanged || material.hasTexFileChanged || material.hasTexColorChanged)
             {
                 material.worksuffix = this.suffix;
                 string text5 = material.EditFileName();
                 param[2] = text5;
                 ReplacedInfo item2 = new ReplacedInfo(text4, text5, this, material);
                 this.replaceFiles.Add(item2);
             }
         }
         return param;
     });
 }
        // modelファイル内のマテリアル情報を対象とした転送処理
        // .mateファイルのheader, version, name1は存在しない
        public void TransferMaterial(BinaryReader reader, BinaryWriter writer, TargetMaterial trgtMat, bool overwrite) {

            // マテリアル名
            reader.ReadString();
            writer.Write(trgtMat.editname);

            string shaderName1 = reader.ReadString();
            string shaderName2 = reader.ReadString();
            if (trgtMat.shaderChanged) {
                shaderName1 = trgtMat.ShaderNameOrDefault(shaderName1);
                shaderName2 = ShaderType.GetShader2(shaderName1);
            }
            writer.Write(shaderName1);
            writer.Write(shaderName2);

            //var matType = trgtMat.editedMat.type1;
            var shaderType = trgtMat.editedMat.type;
            var writed = new HashSet<PropKey>();
            while(true) {
                string type = reader.ReadString();
                //writer.Write(type);
                if (type == "end") break;

                string propName = reader.ReadString();
                //shaderType.
                var shaderProp = shaderType.GetShaderProp(propName);
                if (shaderProp == null) {
                    // シェーダに対応していないプロパティは読み捨て
                    DiscardMateProp(reader, type);
                    continue;
                }
                
                if (!overwrite) { 
                    // .mateからマテリアル変更で書き換えるため、そのまま転送
                    // ただし、model上に記述されたマテリアルで指定されたtexファイルは存在する必要あり
                    TransferMateProp(reader, writer, type, propName);
                } else {
                    switch (type) {
                    case "tex":
                        // .mateによるマテリアル変更がないケースのみ書き換える
                        // 
                        // texプロパティがある場合にのみ設定
                        TargetTexture trgtTex = null;
                        trgtMat.texDic.TryGetValue(shaderProp.key, out trgtTex);
                        if (trgtTex == null || trgtTex.tex == null || trgtTex.fileChanged || trgtTex.colorChanged) {
                            // 変更がある場合にのみ書き換え (空のものはnull指定)
                            trgtTex.worksuffix = trgtMat.worksuffix;
                            string srcfile = null;
                            TransferMateProp(reader, null, type, null, ref srcfile);
                            if (trgtTex != null) trgtTex.workfilename = srcfile;

                            WriteTex(writer, propName, trgtMat, trgtTex);
                        } else {
                            // 変更がないものはそのまま転送
                            TransferMateProp(reader, writer, type, propName);
                        }
                        break;
                    case "col":
                    case "vec":
                        Write(writer, type, propName);
                        Write(writer, trgtMat.editedMat.material.GetColor(propName));
                        
                        DiscardMateProp(reader, type);
                        break;
                    case "f":
                        Write(writer, type, propName);
                        Write(writer, trgtMat.editedMat.material.GetFloat(propName));
                        
                        DiscardMateProp(reader, type);
                        break;
                    }
                }
                writed.Add(shaderProp.key);
            }

            // シェーダで設定されるプロパティ数が一致しない場合、不足propを追記
            
            if (shaderType.KeyCount() != writed.Count()) {
                foreach (var texProp in shaderType.texProps) {
                    if (writed.Contains(texProp.key)) continue;

                    TargetTexture trgtTex = null;
                    trgtMat.texDic.TryGetValue(texProp.key, out trgtTex);
                    WriteTex(writer, texProp.keyName, trgtMat, trgtTex);
                }

                foreach (var prop in shaderType.colProps) {
                    if (writed.Contains(prop.key)) continue;

                    Write(writer, prop.type.ToString(), prop.keyName);
                    Write(writer, trgtMat.editedMat.material.GetColor(prop.propId));
                }
                
                foreach (var prop in shaderType.fProps) {
                    if (writed.Contains(prop.key)) continue;

                    Write(writer, prop.type.ToString(), prop.keyName);
                    Write(writer, trgtMat.editedMat.material.GetFloat(prop.propId));
                }

            }

            writer.Write("end");
        }
        private void WriteTex(BinaryWriter writer, string propName, TargetMaterial tm, TargetTexture trgtTex) {
            Write(writer, "tex");
            Write(writer, propName);

            var sub = "tex2d";
            if (trgtTex == null || trgtTex.tex == null)  {
                sub = "null";
            }
            Write(writer, sub);
            switch (sub) {
            case "tex2d":
                // カラー変更時にはファイル生成するため、ファイル名も変更が必要
                if (trgtTex.fileChanged || trgtTex.colorChanged) {
                    Write(writer, trgtTex.EditFileNameNoExt()); // 拡張子不要
                    //Write(writer, trgtTex.EditFileName());
                    Write(writer, trgtTex.EditTxtPath());

                    Write(writer, tm.editedMat.material.GetTextureOffset(propName));
                    Write(writer, tm.editedMat.material.GetTextureScale(propName));
                }
                break;
            case "null":
                break;
            case "texRT":            // texRTはない
                writer.Write(string.Empty);
                writer.Write(string.Empty);
                break;
            }
        }
        public void WriteMateFile(BinaryReader reader, string header, string outfilepath, TargetMaterial trgtMat) {

            using ( var writer = new BinaryWriter(File.OpenWrite(outfilepath)) ) {
                writer.Write(header);              // ヘッダ (CM3D2_MATERIAL)
                writer.Write(reader.ReadInt32());  // バージョン
                writer.Write(reader.ReadString()); // マテリアル名1

                TransferMaterial(reader, writer, trgtMat, true);
            }
        }
        public void AddSlotMaterial(TargetMaterial tm) {
            LogUtil.Debug("Add slot material", tm.editname);

            SlotMaterials slotMat;
            if (!slotMaterials.TryGetValue(tm.slotName, out slotMat)) {
                slotMat = new SlotMaterials();
                slotMaterials[tm.slotName] = slotMat;
            }
            slotMat.SetMaterial(tm);
        }
示例#16
0
        // Token: 0x06000110 RID: 272 RVA: 0x0000B9B8 File Offset: 0x00009BB8
        private static void WriteMenuFile(BinaryReader reader, string header, string filepath, ACCMenu menu)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
                {
                    using (BinaryWriter binaryWriter2 = new BinaryWriter(File.OpenWrite(filepath)))
                    {
                        binaryWriter2.Write(header);
                        binaryWriter2.Write(reader.ReadInt32());
                        reader.ReadString();
                        string text = menu.txtpath;
                        if (!text.EndsWith(FileConst.EXT_TXT, StringComparison.OrdinalIgnoreCase))
                        {
                            text += FileConst.EXT_TXT;
                        }
                        binaryWriter2.Write(text);
                        reader.ReadString();
                        reader.ReadString();
                        reader.ReadString();
                        binaryWriter2.Write(menu.name);
                        binaryWriter2.Write(menu.category);
                        string text2 = menu.desc.Replace("\n", FileConst.RET);
                        binaryWriter2.Write(text2);
                        reader.ReadInt32();
                        bool flag = false;
                        for (;;)
                        {
                            int num = (int)reader.ReadByte();
                            if (num == 0)
                            {
                                break;
                            }
                            string   text3 = reader.ReadString();
                            string[] array = new string[num - 1];
                            for (int i = 0; i < num - 1; i++)
                            {
                                array[i] = reader.ReadString();
                            }
                            string key;
                            switch (key = text3)
                            {
                            case "priority":
                                array[0] = menu.priority;
                                flag     = true;
                                break;

                            case "name":
                                array[0] = menu.name;
                                break;

                            case "setumei":
                                array[0] = text2;
                                break;

                            case "icon":
                            case "icons":
                                array[0] = menu.EditIconFileName();
                                break;

                            case "additem":
                            {
                                string text4 = array[0];
                                array[0] = menu.itemFiles[text4].EditFileName();
                                LogUtil.Debug(new object[]
                                    {
                                        "modelfile replaces ",
                                        text4,
                                        "=>",
                                        array[0]
                                    });
                                break;
                            }

                            case "マテリアル変更":
                            {
                                string         slot     = array[0];
                                int            matNo    = int.Parse(array[1]);
                                TargetMaterial material = menu.GetMaterial(slot, matNo);
                                array[2] = material.EditFileName();
                                break;
                            }

                            case "リソース参照":
                                array[1] = menu.resFiles[array[1]].EditFileName();
                                break;

                            case "半脱ぎ":
                                array[0] = menu.resFiles[array[0]].EditFileName();
                                break;
                            }
                            binaryWriter.Write((byte)(array.Length + 1));
                            binaryWriter.Write(text3);
                            foreach (string value in array)
                            {
                                binaryWriter.Write(value);
                            }
                        }
                        binaryWriter.Write(0);
                        if (!flag)
                        {
                            binaryWriter.Write(2);
                            binaryWriter.Write("priority");
                            binaryWriter.Write(menu.priority);
                        }
                        binaryWriter2.Write((int)memoryStream.Length);
                        binaryWriter2.Write(memoryStream.ToArray());
                    }
                }
            }
        }
 public ReplacedInfo(string src, string replaced, ResourceRef res, TargetMaterial tm) {
     this.source = src;
     this.replaced = replaced;
     this.res = res;
     this.material = tm;
 }
示例#18
0
        public Func <string, string[], string[]> ReplaceMenuFunc()
        {
            replaceFiles = new List <ReplacedInfo>();
            // menuファイル中のmodelとmateを更新する
            // それ以外はそのまま出力
            return((string key, string[] param) => {
                switch (key)
                {
                case "additem":
                    if (param.Length >= 2)
                    {
                        string slot0 = param[1];
                        try {
                            var slot = (TBody.SlotID)Enum.Parse(typeof(TBody.SlotID), slot0, false);
                            Item item = menu.itemSlots[slot];

                            // 対応するスロットのアイテムが更新される場合にのみ出力
                            if (item.needUpdate)
                            {
                                var filename0 = param[0];
                                string editfile;
                                // 元のmodelファイルが同一であれば、すでに出力済みと見なす
                                if (item.filename == filename0)
                                {
                                    item.worksuffix = null;
                                    editfile = item.EditFileName();
                                }
                                else
                                {
                                    item.worksuffix = suffix;
                                    editfile = item.EditFileName();
                                    replaceFiles.Add(new ReplacedInfo(filename0, editfile, this, item));
                                }
                                param[0] = editfile;
                            }
                        } catch (Exception e) {
                            LogUtil.Debug("failed to parse SlotID:", slot0, e);
                            // LogUtil.DebugLog("failed to parse additem slot", slot0, e);
                        }
                    }
                    break;

                case "マテリアル変更":
                    string slotName = param[0];
                    int matNo = int.Parse(param[1]);
                    string filename1 = param[2];
                    TargetMaterial tm = menu.GetMaterial(slotName, matNo);
                    // 上位menuと同名ファイルであれば、出力済のファイル名を指定 (上位側が変更されていなければそのまま)
                    tm.worksuffix = null;
                    if (tm.filename == filename1)
                    {
                        param[2] = tm.EditFileName();
                    }
                    else
                    {
                        if (tm.shaderChanged || tm.hasParamChanged || tm.hasTexFileChanged || tm.hasTexColorChanged)
                        {
                            tm.worksuffix = suffix;
                            var editfile = tm.EditFileName();
                            param[2] = editfile;
                            var replaced = new ReplacedInfo(filename1, editfile, this, tm);
                            replaceFiles.Add(replaced);
                        }
                        // マテリアルの内容が変更されていない場合は変更しない
                    }
                    break;
                }
                return param;
            });
        }