Esempio n. 1
0
        public static string GetSpriteFromViewId(int viewIdToFind, ViewIdTypes type, AbstractDb <int> db, ReadableTuple <int> tuple)
        {
            string error;
            Dictionary <int, string> idsToSprite;

            if (GetIdToSpriteTable(db, type, out idsToSprite, out error))
            {
                if (error == PreviewHelper.ViewIdIncrease && tuple != null)
                {
                    var itemKey = tuple.GetKey <int>();

                    if (itemKey >= 2101)
                    {
                        viewIdToFind = itemKey;
                    }
                }

                if (viewIdToFind == 0 && tuple != null)
                {
                    var itemKey = tuple.Key;

                    if (itemKey == 2230 || itemKey == 2231 || itemKey == 5394)
                    {
                        return(PreviewHelper.SpriteNone);
                    }
                }

                if (idsToSprite.ContainsKey(viewIdToFind))
                {
                    return(idsToSprite[viewIdToFind]);
                }
            }
            else
            {
                throw new Exception(error);
            }

            return(null);
        }
Esempio n. 2
0
        public static string GetSpriteFromJob(MultiGrfReader grf, Job job, PreviewHelper helper, string sprite, ViewIdTypes type)
        {
            switch (type)
            {
            case ViewIdTypes.Garment:
                return(GetSpritePathFromJob(grf, job, @"data\sprite\·Îºê\" + sprite + @"\" + helper.GenderString + "\\{0}_" + helper.GenderString, helper.Gender, null, sprite));

            case ViewIdTypes.Shield:
                return(GetSpritePathFromJob(grf, job, @"data\sprite\¹æÆÐ\{0}\{0}_" + helper.GenderString + sprite, helper.Gender, "¹æÆÐ", sprite));

            case ViewIdTypes.Weapon:
                return(GetSpritePathFromJob(grf, job, @"data\sprite\Àΰ£Á·\{0}\{0}_" + helper.GenderString + sprite, helper.Gender, "Àΰ£Á·", sprite));

            case ViewIdTypes.Headgear:
                return(EncodingService.FromAnyToDisplayEncoding(@"data\sprite\¾Ç¼¼»ç¸®\" + helper.GenderString + "\\" + EncodingService.FromAnyToDisplayEncoding(helper.GenderString + "_") + helper.PreviewSprite));

            case ViewIdTypes.Npc:
                if (helper.PreviewSprite != null && helper.PreviewSprite.EndsWith(".gr2", StringComparison.OrdinalIgnoreCase))
                {
                    return(EncodingService.FromAnyToDisplayEncoding(@"data\model\3dmob\" + helper.PreviewSprite));
                }

                return(EncodingService.FromAnyToDisplayEncoding(@"data\sprite\npc\" + helper.PreviewSprite));
            }

            return(null);
        }
Esempio n. 3
0
 public static string GetSpriteFromViewId(int viewIdToFind, ViewIdTypes type, SdeDatabase db, ReadableTuple <int> tuple)
 {
     return(GetSpriteFromViewId(viewIdToFind, type, db.GetDb <int>(ServerDbs.Items), tuple));
 }
Esempio n. 4
0
        public static bool GetIdToSpriteTable(AbstractDb <int> db, ViewIdTypes type, out Dictionary <int, string> outputIdsToSprites, out string error)
        {
            outputIdsToSprites = new Dictionary <int, string>();
            error = null;

            if (db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccId) == null || db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccName) == null)
            {
                error = "The accessory ID table or accessory name table has not been set, the paths are based on those.";
                return(false);
            }

            int    temp_i;
            string temp_s;
            var    accIdPath = ProjectConfiguration.SyncAccId;
            Dictionary <string, int> ids;

            switch (type)
            {
            case ViewIdTypes.Weapon:
                if (_weaponBuffer.IsBuffered())
                {
                    outputIdsToSprites = _weaponBuffer.Ids;
                    error = _weaponBuffer.Error;
                    return(_weaponBuffer.Result);
                }

                var weaponPath = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "weapontable" + Path.GetExtension(accIdPath));
                var weaponData = db.ProjectDatabase.MetaGrf.GetData(weaponPath);

                if (weaponData == null)
                {
                    error = "Couldn't find " + weaponPath;
                    _weaponBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                var weaponTable     = new LuaParser(weaponData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(weaponData), EncodingService.DisplayEncoding);
                var weaponIds       = GetLuaTable(weaponTable, "Weapon_IDs");
                var weaponNameTable = GetLuaTable(weaponTable, "WeaponNameTable");

                ids = SetIds(weaponIds, "Weapon_IDs");

                foreach (var pair in weaponNameTable)
                {
                    temp_s = pair.Key.Trim('[', ']');

                    if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                    {
                        outputIdsToSprites[temp_i] = pair.Value.Trim('\"');
                    }
                }

                _weaponBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);

            case ViewIdTypes.Npc:
                if (_npcBuffer.IsBuffered())
                {
                    outputIdsToSprites = _npcBuffer.Ids;
                    error = _npcBuffer.Error;
                    return(_npcBuffer.Result);
                }

                var npcPathSprites = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "jobname" + Path.GetExtension(accIdPath));
                var npcPathIds     = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "npcIdentity" + Path.GetExtension(accIdPath));
                var npcDataSprites = db.ProjectDatabase.MetaGrf.GetData(npcPathSprites);
                var npcDataIds     = db.ProjectDatabase.MetaGrf.GetData(npcPathIds);

                if (npcDataSprites == null)
                {
                    error = "Couldn't find " + npcPathSprites;
                    _npcBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                if (npcDataIds == null)
                {
                    error = "Couldn't find " + npcPathIds;
                    _npcBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                //var itemDb = db.GetMeta<int>(ServerDbs.Items);
                var jobname = new LuaParser(npcDataSprites, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(npcDataSprites), EncodingService.DisplayEncoding);
                var jobtbl  = new LuaParser(npcDataIds, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(npcDataIds), EncodingService.DisplayEncoding);

                var jobtblT  = GetLuaTable(jobtbl, "jobtbl");
                var jobnameT = GetLuaTable(jobname, "JobNameTable");

                ids = SetIds(jobtblT, "jobtbl");

                foreach (var pair in jobnameT)
                {
                    temp_s = pair.Key.Trim('[', ']');

                    if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                    {
                        outputIdsToSprites[temp_i] = pair.Value.Trim('\"');
                    }
                }

                _npcBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);

            case ViewIdTypes.Headgear:
                if (_headgearBuffer.IsBuffered())
                {
                    outputIdsToSprites = _headgearBuffer.Ids;
                    error = _headgearBuffer.Error;
                    return(_headgearBuffer.Result);
                }

                var redirectionTable = GetRedirectionTable();
                var dataAccId        = db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccId);
                var dataAccName      = db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccName);
                var itemDb           = db.GetMeta <int>(ServerDbs.Items);
                var accId            = new LuaParser(dataAccId, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(dataAccId), EncodingService.DisplayEncoding);
                var accName          = new LuaParser(dataAccName, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(dataAccName), EncodingService.DisplayEncoding);
                var accIdT           = GetLuaTable(accId, "ACCESSORY_IDs");
                var accNameT         = GetLuaTable(accName, "AccNameTable");
                outputIdsToSprites = _getViewIdTable(accIdT, accNameT);

                accIdT.Clear();
                accNameT.Clear();

                var resourceToIds = new Dictionary <string, int>();

                if (ProjectConfiguration.HandleViewIds)
                {
                    try {
                        List <ReadableTuple <int> > headgears = itemDb.FastItems.Where(p => ItemParser.IsArmorType(p) && (p.GetIntNoThrow(ServerItemAttributes.Location) & 7937) != 0).OrderBy(p => p.GetIntNoThrow(ServerItemAttributes.ClassNumber)).ToList();
                        _loadFallbackValues(outputIdsToSprites, headgears, accIdT, accNameT, resourceToIds, redirectionTable);
                    }
                    catch (Exception err) {
                        error = err.ToString();
                        _headgearBuffer.Buffer(outputIdsToSprites, false, error);
                        return(false);
                    }
                }

                _headgearBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);

            case ViewIdTypes.Shield:
                if (_shieldBuffer.IsBuffered())
                {
                    outputIdsToSprites = _shieldBuffer.Ids;
                    error = _shieldBuffer.Error;
                    return(_shieldBuffer.Result);
                }

                var shieldPath = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "ShieldTable" + Path.GetExtension(accIdPath));
                var shieldData = db.ProjectDatabase.MetaGrf.GetData(shieldPath);

                if (shieldData == null)
                {
                    outputIdsToSprites[1] = "_°¡µå";
                    outputIdsToSprites[2] = "_¹öŬ·¯";
                    outputIdsToSprites[3] = "_½¯µå";
                    outputIdsToSprites[4] = "_¹Ì·¯½¯µå";
                    outputIdsToSprites[5] = "";
                    outputIdsToSprites[6] = "";
                }
                else
                {
                    _debugStatus = "OK";

                    var shieldTable = new LuaParser(shieldData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(shieldData), EncodingService.DisplayEncoding);

                    _debugStatus = "LoadTables";

                    var shieldIds       = GetLuaTable(shieldTable, "Shield_IDs");
                    var shieldNameTable = GetLuaTable(shieldTable, "ShieldNameTable");
                    var shieldMapTable  = GetLuaTable(shieldTable, "ShieldMapTable");

                    ids = SetIds(shieldIds, "Shield_IDs");
                    Dictionary <int, string> idsToSprite = new Dictionary <int, string>();

                    foreach (var pair in shieldNameTable)
                    {
                        temp_s = pair.Key.Trim('[', ']');

                        if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                        {
                            temp_s = pair.Value.Trim('\"');
                            idsToSprite[temp_i]        = temp_s;
                            outputIdsToSprites[temp_i] = temp_s;
                        }
                    }

                    foreach (var pair in shieldMapTable)
                    {
                        var key = pair.Key.Trim('[', ']', '\t');
                        int id1;

                        if (ids.TryGetValue(key, out id1))
                        {
                            int id2;
                            temp_s = pair.Value.Trim('\"', '\t');

                            if (ids.TryGetValue(temp_s, out id2) || Int32.TryParse(temp_s, out id2))
                            {
                                if (idsToSprite.TryGetValue(id2, out temp_s))
                                {
                                    outputIdsToSprites[id1] = temp_s;
                                }
                            }
                        }
                    }

                    error = PreviewHelper.ViewIdIncrease;
                }

                _shieldBuffer.Buffer(outputIdsToSprites, true, error);
                return(true);

            case ViewIdTypes.Garment:
                if (_garmentBuffer.IsBuffered())
                {
                    outputIdsToSprites = _garmentBuffer.Ids;
                    error = _garmentBuffer.Error;
                    return(_garmentBuffer.Result);
                }

                var robeSpriteName = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "spriterobename" + Path.GetExtension(accIdPath));
                var robeSpriteId   = GrfPath.Combine(GrfPath.GetDirectoryName(accIdPath), "spriterobeid" + Path.GetExtension(accIdPath));
                var robeNameData   = db.ProjectDatabase.MetaGrf.GetData(robeSpriteName);
                var robeIdData     = db.ProjectDatabase.MetaGrf.GetData(robeSpriteId);

                if (robeNameData == null)
                {
                    error = "Couldn't find " + robeSpriteName;
                    _garmentBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                if (robeIdData == null)
                {
                    error = "Couldn't find " + robeSpriteId;
                    _garmentBuffer.Buffer(outputIdsToSprites, false, error);
                    return(false);
                }

                var robeNameTable = new LuaParser(robeNameData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(robeNameData), EncodingService.DisplayEncoding);
                var robeIdTable   = new LuaParser(robeIdData, true, p => new Lub(p).Decompile(), EncodingService.DetectEncoding(robeIdData), EncodingService.DisplayEncoding);
                var robeNames     = GetLuaTable(robeNameTable, "RobeNameTable");
                var robeIds       = GetLuaTable(robeIdTable, "SPRITE_ROBE_IDs");

                ids = SetIds(robeIds, "SPRITE_ROBE_IDs");

                foreach (var pair in robeNames)
                {
                    temp_s = pair.Key.Trim('[', ']');

                    if (ids.TryGetValue(temp_s, out temp_i) || Int32.TryParse(temp_s, out temp_i))
                    {
                        outputIdsToSprites[temp_i] = pair.Value.Trim('\"');
                    }
                }

                _garmentBuffer.Buffer(outputIdsToSprites, true, null);
                return(true);
            }

            return(false);
        }