Beispiel #1
0
    // Use this for initialization


    // Update is called once per frame
    public static void Write(PGF current, TextMeshProUGUI description)
    {
        if (description == null)
        {
            return;
        }

        if (current != null && description != null)
        {
            /*
             * description.text = "";
             * description.text += "GUN " + current.MetaData.name + "\n";
             * description.text += "Base Damage: " + current.ImpactDamageData.baseDamage + "\n";
             * description.text += "Damage DropOff: " + current.ImpactDamageData.damageDropOff + "\n";
             * description.text += "ROF baseRate: " + current.RateOfFireData.baseRate + "\n";
             * description.text += "ROF Arr: " + current.RateOfFireData.burstData.ToString() + "\n";
             * //description.text += "Distance before spread: " + current.ProjectileTrajectoryData.timeBeforeSpread + "\n";
             * description.text += "Speed: " + current.ProjectileTrajectoryData.initialSpeed + "\n";
             * description.text += "Spread Angle: " + current.ProjectileTrajectoryData.maxSpreadAngle + "\n";
             */

            string gunText = JsonUtility.ToJson(current.Data);

            description.text = gunText;
        }
        else
        {
            description.text = "NO GUN";
        }
    }
Beispiel #2
0
        private bool isIncorrectFont(PGF fontFile)
        {
            // Fonts created by ttf2pgf (e.g. default pspsharp fonts)
            // do not contain complete Glyph information.
            string fontName = fontFile.FontName;

            return(fontName.StartsWith("Liberation", StringComparison.Ordinal) || fontName.StartsWith("Sazanami", StringComparison.Ordinal) || fontName.StartsWith("UnDotum", StringComparison.Ordinal));
        }
Beispiel #3
0
    void GenerateNewPGF()
    {
        if (currentPGF != null)
        {
            Destroy(GameObject.FindGameObjectWithTag("Generated"));
        }

        foreach (GameObject x in GameObject.FindGameObjectsWithTag("Projectile"))
        {
            Destroy(x);
        }
        ;

        Current = PGFFactory.Instance.CreatePGF();

        UIText.Write(currentPGF, description);
    }
Beispiel #4
0
    public LinScoredFloat GetPGFValue(PGF pgf)
    {
        switch (field)
        {
        case PGFDataField.ImpactDamage:
            return(pgf.Data.projectile.ImpactDamage.baseDamage);

        case PGFDataField.ImpactDamageDropoff:
            return(pgf.Data.projectile.ImpactDamage.damageDropOff);

        case PGFDataField.AreaDamage:
            return(pgf.Data.projectile.AreaDamage.maxDamage);

        case PGFDataField.BlastRadius:
            return(pgf.Data.projectile.AreaDamage.maxBlastRange);

        case PGFDataField.ImpactsToDetonation:
            return(pgf.Data.projectile.AreaDamage.numImpactsToDetonate);

        case PGFDataField.SpreadAngle:
            return(pgf.Data.projectile.Trajectory.maxInitialSpreadAngle);

        case PGFDataField.InitialSpeed:
            return(pgf.Data.projectile.Trajectory.initialSpeed);

        case PGFDataField.Dropoff:
            return(pgf.Data.projectile.Trajectory.dropOffRatio);

        case PGFDataField.RateOfFire:
            return(pgf.Data.rateOfFire.baseRate);

        case PGFDataField.AmmoCapacity:
            return(pgf.Data.rateOfFire.reloadingData.n);

        case PGFDataField.ReloadTime:
            return(pgf.Data.rateOfFire.reloadingData.r);

        default:
            return(null);
        }
    }
Beispiel #5
0
    /// <summary>
    /// Creates a new PGF
    /// </summary>
    /// <returns></returns>
    public PGF CreatePGF()
    {
        //Create the PGF
        var newPGF = Instantiate(pgfPrefab);

        if (newPGF != null)
        {
            newPGF.transform.position = pgfStartTransform.position;
            newPGF.transform.forward  = pgfStartTransform.forward;
            newPGF.transform.rotation = pgfStartTransform.rotation;
        }

        PGF pgf = newPGF.GetComponent <PGF>();

        pgf.ammo = ammo;
        pgf.transform.SetParent(Camera.main.transform);

        pgf.Data = new PGFData()
        {
            meta = CreateMetaData()
        };
        return(pgf);
    }
Beispiel #6
0
        // Create and retrieve a glyph from the font data.
        private Glyph getGlyph(int[] fontdata, long charPtr, int glyphType, PGF fontFile)
        {
            Glyph glyph = new Glyph();

            if (glyphType == FONT_PGF_GLYPH_TYPE_SHADOW)
            {
                if (charPtr + 96 > fontdataBits)
                {
                    return(null);
                }
                // First 14 bits are offset to shadow glyph
                charPtr += getBits(14, fontdata, charPtr) * 8;
            }
            if (charPtr + 96 > fontdataBits)
            {
                return(null);
            }

            glyph.glyphPtr = charPtr / 8;

            charPtr += 14;

            glyph.w  = getBits(7, fontdata, charPtr);
            charPtr += 7;

            glyph.h  = getBits(7, fontdata, charPtr);
            charPtr += 7;

            glyph.left = getBits(7, fontdata, charPtr);
            charPtr   += 7;
            if (glyph.left >= 64)
            {
                glyph.left -= 128;
            }

            glyph.top = getBits(7, fontdata, charPtr);
            charPtr  += 7;
            if (glyph.top >= 64)
            {
                glyph.top -= 128;
            }

            glyph.flags = getBits(6, fontdata, charPtr);
            charPtr    += 6;

            if (glyphType == FONT_PGF_GLYPH_TYPE_CHAR)
            {
                // Unknown values
                int unknown1 = getBits(2, fontdata, charPtr);
                charPtr += 2;
                int unknown2 = getBits(2, fontdata, charPtr);
                charPtr += 2;
                int unknown3 = getBits(3, fontdata, charPtr);
                charPtr += 3;
                if (log.TraceEnabled)
                {
                    log.trace(string.Format("unknown1={0:D}, unknown2={1:D}, unknown3={2:D}", unknown1, unknown2, unknown3));
                }

                glyph.shadowID = getBits(9, fontdata, charPtr);
                charPtr       += 9;

                if (glyph.hasFlag(FONT_PGF_METRIC_DIMENSION_INDEX))
                {
                    int dimensionIndex = getBits(8, fontdata, charPtr);
                    charPtr += 8;
                    if (dimensionIndex < fontFile.DimensionTableLength)
                    {
                        int[][] dimensionTable = fontFile.DimensionTable;
                        glyph.dimensionWidth  = dimensionTable[0][dimensionIndex];
                        glyph.dimensionHeight = dimensionTable[1][dimensionIndex];
                    }

                    if (dimensionIndex == 0 && isIncorrectFont(fontFile))
                    {
                        // Fonts created by ttf2pgf do not contain complete Glyph information.
                        // Provide default values.
                        glyph.dimensionWidth  = glyph.w << 6;
                        glyph.dimensionHeight = glyph.h << 6;
                    }
                }
                else
                {
                    glyph.dimensionWidth = getBits(32, fontdata, charPtr);
                    charPtr += 32;
                    glyph.dimensionHeight = getBits(32, fontdata, charPtr);
                    charPtr += 32;
                }

                if (glyph.hasFlag(FONT_PGF_METRIC_BEARING_X_INDEX))
                {
                    int xAdjustIndex = getBits(8, fontdata, charPtr);
                    charPtr += 8;
                    if (xAdjustIndex < fontFile.XAdjustTableLength)
                    {
                        int[][] xAdjustTable = fontFile.XAdjustTable;
                        glyph.xAdjustH = xAdjustTable[0][xAdjustIndex];
                        glyph.xAdjustV = xAdjustTable[1][xAdjustIndex];
                    }

                    if (xAdjustIndex == 0 && isIncorrectFont(fontFile))
                    {
                        // Fonts created by ttf2pgf do not contain complete Glyph information.
                        // Provide default values.
                        glyph.xAdjustH = glyph.left << 6;
                        glyph.xAdjustV = glyph.left << 6;
                    }
                }
                else
                {
                    glyph.xAdjustH = getBits(32, fontdata, charPtr);
                    charPtr       += 32;
                    glyph.xAdjustV = getBits(32, fontdata, charPtr);
                    charPtr       += 32;
                }

                if (glyph.hasFlag(FONT_PGF_METRIC_BEARING_Y_INDEX))
                {
                    int yAdjustIndex = getBits(8, fontdata, charPtr);
                    charPtr += 8;
                    if (yAdjustIndex < fontFile.YAdjustTableLength)
                    {
                        int[][] yAdjustTable = fontFile.YAdjustTable;
                        glyph.yAdjustH = yAdjustTable[0][yAdjustIndex];
                        glyph.yAdjustV = yAdjustTable[1][yAdjustIndex];
                    }

                    if (yAdjustIndex == 0 && isIncorrectFont(fontFile))
                    {
                        // Fonts created by ttf2pgf do not contain complete Glyph information.
                        // Provide default values.
                        glyph.yAdjustH = glyph.top << 6;
                        glyph.yAdjustV = glyph.top << 6;
                    }
                }
                else
                {
                    glyph.yAdjustH = getBits(32, fontdata, charPtr);
                    charPtr       += 32;
                    glyph.yAdjustV = getBits(32, fontdata, charPtr);
                    charPtr       += 32;
                }

                if (glyph.hasFlag(FONT_PGF_METRIC_ADVANCE_INDEX))
                {
                    int advanceIndex = getBits(8, fontdata, charPtr);
                    charPtr += 8;
                    if (advanceIndex < fontFile.AdvanceTableLength)
                    {
                        int[][] advanceTable = fontFile.AdvanceTable;
                        glyph.advanceH = advanceTable[0][advanceIndex];
                        glyph.advanceV = advanceTable[1][advanceIndex];
                    }
                }
                else
                {
                    glyph.advanceH = getBits(32, fontdata, charPtr);
                    charPtr       += 32;
                    glyph.advanceV = getBits(32, fontdata, charPtr);
                    charPtr       += 32;
                }
            }
            else
            {
                glyph.shadowID = 65535;
                glyph.advanceH = 0;
            }

            glyph.ptr = charPtr / 8;

            return(glyph);
        }
Beispiel #7
0
        public SceFontInfo(PGF fontFile)
        {
            // PGF.
            fileName = fontFile.FileNamez;
            fileType = fontFile.PGFMagic;

            // Characters/Shadow characters' variables.
            charmap      = new int[fontFile.CharMapLength * 2];
            advancex     = fontFile.MaxAdvance[0] / 16;
            advancey     = fontFile.MaxAdvance[1] / 16;
            shadowScaleX = fontFile.ShadowScale[0];
            shadowScaleY = fontFile.ShadowScale[1];
            glyphs       = new Glyph[fontFile.CharPointerLength];
            shadowGlyphs = new Glyph[fontFile.ShadowMapLength];
            firstGlyph   = fontFile.FirstGlyphInCharMap;

            // Charmap compression tables
            int[][] charmapCompressionTable1 = fontFile.CharMapCompressionTable1;
            int[][] charmapCompressionTable2 = fontFile.CharMapCompressionTable2;
            if (charmapCompressionTable1 == null || charmapCompressionTable2 == null)
            {
                charmap_compr_len = 1;
                charmap_compr     = new int[2];
                charmap_compr[0]  = firstGlyph;
                charmap_compr[1]  = fontFile.LastGlyphInCharMap - firstGlyph + 1;

                shadow_compr_len = 1;
                shadow_compr     = new int[2];
                shadow_compr[0]  = charmap_compr[0];
                shadow_compr[1]  = charmap_compr[1];
            }
            else
            {
                charmap_compr_len = charmapCompressionTable1[0].Length;
                charmap_compr     = new int[charmap_compr_len * 2];
                for (int j = 0, i = 0; j < charmapCompressionTable1[0].Length; j++)
                {
                    charmap_compr[i++] = charmapCompressionTable1[0][j];
                    charmap_compr[i++] = charmapCompressionTable1[1][j];
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("CharMap Compression Table #{0:D}: 0x{1:X}, Length={2:D}", j, charmapCompressionTable1[0][j], charmapCompressionTable1[1][j]));
                    }
                }

                shadow_compr_len = charmapCompressionTable2[0].Length;
                shadow_compr     = new int[shadow_compr_len * 2];
                for (int j = 0, i = 0; j < charmapCompressionTable2[0].Length; j++)
                {
                    shadow_compr[i++] = charmapCompressionTable2[0][j];
                    shadow_compr[i++] = charmapCompressionTable2[1][j];
                }
            }

            // Get char map.
            int[] rawCharMap = fontFile.CharMap;
            for (int i = 0; i < fontFile.CharMapLength; i++)
            {
                charmap[i] = getBits(fontFile.CharMapBpe, rawCharMap, i * fontFile.CharMapBpe);
                if (charmap[i] >= glyphs.Length)
                {
                    charmap[i] = 65535;
                }
            }

            // Get raw fontdata.
            fontdata     = fontFile.Fontdata;
            fontdataBits = fontdata.Length * 8L;

            int[] charPointers = getTable(fontFile.CharPointerTable, fontFile.CharPointerBpe, glyphs.Length);
            int[] shadowMap    = getTable(fontFile.ShadowCharMap, fontFile.ShadowMapBpe, shadowGlyphs.Length);

            // Generate glyphs for all chars.
            for (int i = 0; i < glyphs.Length; i++)
            {
                glyphs[i] = getGlyph(fontdata, (charPointers[i] * 4 * 8), FONT_PGF_GLYPH_TYPE_CHAR, fontFile);
            }

            // Generate shadow glyphs for all chars.
            if (shadowGlyphs.Length > 0)
            {
                for (int i = 0; i < glyphs.Length; i++)
                {
                    int shadowId = glyphs[i].shadowID;
                    if (shadowId >= 0 && shadowId < shadowMap.Length && shadowId < shadowGlyphs.Length)
                    {
                        int charId = getCharID(shadowMap[shadowId]);
                        if (charId >= 0 && charId < glyphs.Length)
                        {
                            if (shadowGlyphs[shadowId] == null)
                            {
                                shadowGlyphs[shadowId] = getGlyph(fontdata, (charPointers[charId] * 4 * 8), FONT_PGF_GLYPH_TYPE_SHADOW, fontFile);
                            }
                        }
                    }
                }
            }

            // Dump all glyphs for debugging purpose
            if (dumpGlyphs && log.TraceEnabled)
            {
                for (int i = 0; i < glyphs.Length; i++)
                {
                    int endPtr = (int)(i + 1 < glyphs.Length ? glyphs[i + 1].glyphPtr : glyphs[i].ptr);
                    log.trace(string.Format("charCode=0x{0:X4}: 0x{1:X}-0x{2:X}-0x{3:X}", getCharCode(i, charmap_compr), glyphs[i].glyphPtr, glyphs[i].ptr, endPtr));
                    for (int j = (int)glyphs[i].ptr; j < endPtr; j++)
                    {
                        log.trace(string.Format("  0x{0:X}: 0x{1:X2}", j, fontdata[j]));
                    }
                }
                for (int i = 0; i < shadowGlyphs.Length; i++)
                {
                    if (shadowGlyphs[i] != null)
                    {
                        log.trace(string.Format("shadowGlyphs#{0:D}: 0x{1:X}-0x{2:X}", i, shadowGlyphs[i].glyphPtr, shadowGlyphs[i].ptr));
                    }
                }
            }
        }