package org.runite.client;

import org.rs09.client.Node;
import org.rs09.client.rendering.Toolkit;

import java.util.Objects;
import java.util.Random;

public abstract class Font extends Node {

    private static final RSString[] aClass94Array3753 = new RSString[100];
    private static final RSString aClass94_3745 = Unsorted.emptyString(100);

    private static int anInt3746 = -1;
    private static int anInt3747 = -1;
    private static int anInt3748 = 0;
    private static int anInt3749 = 0;
    private static int anInt3750 = 256;
    private static int anInt3751 = 256;
    private static int anInt3752 = -1;
    private static int anInt3754 = -1;
    private static int anInt3755 = 0;
    private static int anInt3756 = 0;

    int[] anIntArray3709;
    int[] anIntArray3721;
    int anInt3727 = 0;
    private int anInt3710;
    private int[] anIntArray3719;
    private int anInt3722;
    private int[] anIntArray3723;
    private int[] anIntArray3730;
    private byte[] aByteArray3733;
    private int[] anIntArray3736;
    private AbstractIndexedSprite[] aClass109Array3740;


    Font(byte[] var1, int[] var2, int[] var3, int[] var4, int[] var5) {
        this.anIntArray3719 = var2;
        this.anIntArray3730 = var3;
        this.anIntArray3709 = var4;
        this.anIntArray3721 = var5;
        this.method700(var1);
        int var6 = Integer.MAX_VALUE;
        int var7 = Integer.MIN_VALUE;

        for (int var8 = 0; var8 < 256; ++var8) {
            if (this.anIntArray3730[var8] < var6 && this.anIntArray3721[var8] != 0) {
                var6 = this.anIntArray3730[var8];
            }

            if (this.anIntArray3730[var8] + this.anIntArray3721[var8] > var7) {
                var7 = this.anIntArray3730[var8] + this.anIntArray3721[var8];
            }
        }

        this.anInt3722 = this.anInt3727 - var6;
        this.anInt3710 = var7 - this.anInt3727;
    }

    Font(byte[] var1) {
        this.method700(var1);
    }

    static RSString method686(RSString var0) {
        int var1 = var0.length();
        int var2 = 0;

        int var4;
        for (int var3 = 0; var3 < var1; ++var3) {
            var4 = var0.charAt(var3, (byte) 50);
            if (var4 == 60 || var4 == 62) {
                var2 += 3;
            }
        }

        RSString var6 = Unsorted.emptyString(var1 + var2);

        for (var4 = 0; var4 < var1; ++var4) {
            int var5 = var0.charAt(var4, (byte) -101);
            if (var5 == 60) {
                Objects.requireNonNull(var6).append(RSString.parse("<lt>"));
            } else if (var5 == 62) {
                Objects.requireNonNull(var6).append(RSString.parse("<gt>"));
            } else {
                Objects.requireNonNull(var6).appendCharacter(var5);
            }
        }

        return var6;
    }

    private static int method694(byte[][] var0, byte[][] var1, int[] var2, int[] var3, int[] var4, int var5, int var6) {
        int var7 = var2[var5];
        int var8 = var7 + var4[var5];
        int var9 = var2[var6];
        int var10 = var9 + var4[var6];
        int var11 = var7;
        if (var9 > var7) {
            var11 = var9;
        }

        int var12 = var8;
        if (var10 < var8) {
            var12 = var10;
        }

        int var13 = var3[var5];
        if (var3[var6] < var13) {
            var13 = var3[var6];
        }

        byte[] var14 = var1[var5];
        byte[] var15 = var0[var6];
        int var16 = var11 - var7;
        int var17 = var11 - var9;

        for (int var18 = var11; var18 < var12; ++var18) {
            int var19 = var14[var16++] + var15[var17++];
            if (var19 < var13) {
                var13 = var19;
            }
        }

        return -var13;
    }

    public final void method676(RSString var1, int var2, int var3, int var4, int var5, int var6, int var7, int var8, int var9, int var10) {
        this.method693(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10);
    }

    private void method677(RSString var1, int var2, int var3) {
        var3 -= this.anInt3727;
        int var4 = -1;
        int var5 = 0;
        int var6 = var1.length();

        for (int var7 = 0; var7 < var6; ++var7) {
            int var8 = var1.charAt(var7, (byte) 72);
            if (var8 == 60) {
                var4 = var7;
            } else {
                int var10;
                if (var8 == 62 && var4 != -1) {
                    RSString var9 = var1.substring(var4 + 1, var7, 0);
                    var4 = -1;
                    if (var9.equalsString(RSString.parse("lt"))) {
                        var8 = 60;
                    } else if (var9.equalsString(RSString.parse("gt"))) {
                        var8 = 62;
                    } else if (var9.equalsString(RSString.parse("nbsp"))) {
                        var8 = 160;
                    } else if (var9.equalsString(RSString.parse("shy"))) {
                        var8 = 173;
                    } else if (var9.equalsString(RSString.parse("times"))) {
                        var8 = 215;
                    } else if (var9.equalsString(RSString.parse("euro"))) {
                        var8 = 128;
                    } else if (var9.equalsString(RSString.parse("copy"))) {
                        var8 = 169;
                    } else {
                        if (!var9.equalsString(RSString.parse("reg"))) {
                            if (var9.startsWith(RSString.parse("img="))) {
                                try {//TODO: Chat image?...
                                    var10 = var9.substring(4).parseInt();
                                    AbstractIndexedSprite var15 = this.aClass109Array3740[var10];
                                    int var12 = this.anIntArray3723 != null ? this.anIntArray3723[var10] : var15.anInt1467;
                                    if (anInt3750 == 256) {
                                        var15.method1667(var2, var3 + this.anInt3727 - var12);
                                    } else {
                                        var15.method1666(var2, var3 + this.anInt3727 - var12, anInt3750);
                                    }

                                    var2 += var15.anInt1469;
                                    var5 = 0;
                                } catch (Exception var13) {
                                    if (!var13.toString().contains("java.lang.ArrayIndexOutOfBoundsException")) {
                                        // TODO Added by Tech to figure out the weird issue
                                        System.out.println(var13.toString() + ", full string: '" + var9.toString() + "'");
                                        var13.printStackTrace();
                                    }
                                }
                            } else {
                                this.method685(var9);
                            }
                            continue;
                        }

                        var8 = 174;
                    }
                }

                if (var4 == -1) {
                    if (this.aByteArray3733 != null && var5 != 0) {
                        var2 += this.aByteArray3733[(var5 << 8) + var8];
                    }

                    int var14 = this.anIntArray3709[var8];
                    var10 = this.anIntArray3721[var8];
                    if (var8 != 32) {
                        if (anInt3750 == 256) {
                            if (anInt3754 != -1) {
                                this.method678(var8, var2 + this.anIntArray3719[var8] + 1, var3 + this.anIntArray3730[var8] + 1, var14, var10, anInt3754);
                            }

                            this.method678(var8, var2 + this.anIntArray3719[var8], var3 + this.anIntArray3730[var8], var14, var10, anInt3755);
                        } else {
                            if (anInt3754 != -1) {
                                this.method679(var8, var2 + this.anIntArray3719[var8] + 1, var3 + this.anIntArray3730[var8] + 1, var14, var10, anInt3754, anInt3750);
                            }

                            this.method679(var8, var2 + this.anIntArray3719[var8], var3 + this.anIntArray3730[var8], var14, var10, anInt3755, anInt3750);
                        }
                    } else if (anInt3756 > 0) {
                        anInt3748 += anInt3756;
                        var2 += anInt3748 >> 8;
                        anInt3748 &= 255;
                    }

                    int var11 = this.anIntArray3736[var8];
                    if (anInt3746 != -1) {
                        Toolkit.getActiveToolkit().drawHorizontalLine(var2, var3 + (int) ((double) this.anInt3727 * 0.7D), var11, anInt3746);
                    }

                    if (anInt3747 != -1) {
                        Toolkit.getActiveToolkit().drawHorizontalLine(var2, var3 + this.anInt3727 + 1, var11, anInt3747);
                    }

                    var2 += var11;
                    var5 = var8;
                }
            }
        }

    }

    abstract void method678(int var1, int var2, int var3, int var4, int var5, int var6);

    abstract void method679(int var1, int var2, int var3, int var4, int var5, int var6, int var7);

    public final int method680(RSString var1, int var2) {
        int var3 = this.method691(var1, new int[]{var2}, aClass94Array3753);
        int var4 = 0;

        for (int var5 = 0; var5 < var3; ++var5) {
            int var6 = this.method682(aClass94Array3753[var5]);
            if (var6 > var4) {
                var4 = var6;
            }
        }

        return var4;
    }

    public final void method681(RSString var1, int var2, int var3, int var4, int var5) {
        if (var1 != null) {
            this.method698(var4, var5);
            this.method677(var1, var2, var3);
        }
    }

    public final int method682(RSString var1) {
        if (var1 == null) {
            return 0;
        } else {
            int var2 = -1;
            int var3 = 0;
            int var4 = 0;
            int var5 = var1.length();

            for (int var6 = 0; var6 < var5; ++var6) {
                int var7 = var1.charAt(var6, (byte) -45);
                if (var7 == 60) {
                    var2 = var6;
                } else {
                    if (var7 == 62 && var2 != -1) {
                        RSString var8 = var1.substring(var2 + 1, var6, 0);
                        var2 = -1;
                        if (var8.equalsString(RSString.parse("lt"))) {
                            var7 = 60;
                        } else if (var8.equalsString(RSString.parse("gt"))) {
                            var7 = 62;
                        } else if (var8.equalsString(RSString.parse("nbsp"))) {
                            var7 = 160;
                        } else if (var8.equalsString(RSString.parse("shy"))) {
                            var7 = 173;
                        } else if (var8.equalsString(RSString.parse("times"))) {
                            var7 = 215;
                        } else if (var8.equalsString(RSString.parse("euro"))) {
                            var7 = 128;
                        } else if (var8.equalsString(RSString.parse("copy"))) {
                            var7 = 169;
                        } else {
                            if (!var8.equalsString(RSString.parse("reg"))) {
                                if (var8.startsWith(RSString.parse("img="))) {
                                    try {//No clue
                                        int var9 = var8.substring(4).parseInt();
                                        var4 += this.aClass109Array3740[var9].anInt1469;
                                        var3 = 0;
                                    } catch (Exception var10) {
                                    }
                                }
                                continue;
                            }

                            var7 = 174;
                        }
                    }

                    if (var2 == -1) {
                        var4 += this.anIntArray3736[var7];
                        if (this.aByteArray3733 != null && var3 != 0) {
                            var4 += this.aByteArray3733[(var3 << 8) + var7];
                        }

                        var3 = var7;
                    }
                }
            }

            return var4;
        }
    }

    final int method683(RSString var1, int var2, int var3, Random var6, int var7) {
        if (var1 == null) {
            return 0;
        } else {
            var6.setSeed(var7);
            this.method701(16777215, 0, 192 + (var6.nextInt() & 31));
            int var8 = var1.length();
            int[] var9 = new int[var8];
            int var10 = 0;

            for (int var11 = 0; var11 < var8; ++var11) {
                var9[var11] = var10;
                if ((var6.nextInt() & 3) == 0) {
                    ++var10;
                }
            }

            this.method703(var1, var2, var3, var9, null);
            return var10;
        }
    }

    public final int method684(RSString var1, int var2) {
        return this.method691(var1, new int[]{var2}, aClass94Array3753);
    }

    private void method685(RSString var1) {
        try {
            if (var1.startsWith(RSString.parse("col="))) {
                anInt3755 = var1.substring(4).parseInt(16);
            } else if (var1.equalsString(RSString.parse(")4col"))) {
                anInt3755 = anInt3749;
            } else if (var1.startsWith(RSString.parse("trans="))) {
                anInt3750 = var1.substring(6).parseInt();
            } else if (var1.equalsString(RSString.parse(")4trans"))) {
                anInt3750 = anInt3751;
            } else if (var1.startsWith(RSString.parse("str="))) {
                anInt3746 = var1.substring(4).parseInt(16);
            } else if (var1.equalsString(RSString.parse("str"))) {
                anInt3746 = 8388608;
            } else if (var1.equalsString(RSString.parse(")4str"))) {
                anInt3746 = -1;
            } else if (var1.startsWith(RSString.parse("u="))) {
                anInt3747 = var1.substring(2).parseInt(16);
            } else if (var1.equalsString(RSString.parse("u"))) {
                anInt3747 = 0;
            } else if (var1.equalsString(RSString.parse(")4u"))) {
                anInt3747 = -1;
            } else if (var1.startsWith(RSString.parse("shad="))) {
                anInt3754 = var1.substring(5).parseInt(16);
            } else if (var1.equalsString(RSString.parse("shad"))) {
                anInt3754 = 0;
            } else if (var1.equalsString(RSString.parse(")4shad"))) {
                anInt3754 = anInt3752;
            } else if (var1.equalsString(RSString.parse("br"))) {
                this.method701(anInt3749, anInt3752, anInt3751);
            }
        } catch (Exception var3) {
        }

    }

    private int method687(int var1) {
        return this.anIntArray3736[var1 & 0xFF];
    }

    final void drawStringRightAnchor(RSString var1, int var2, int var3, int var4, int var5) {
        if (var1 != null) {
            this.method698(var4, var5);
            this.method677(var1, var2 - this.method682(var1), var3);
        }
    }

    private void method690(RSString var1, int var2) {
        int var3 = 0;
        boolean var4 = false;
        int var5 = var1.length();

        for (int var6 = 0; var6 < var5; ++var6) {
            int var7 = var1.charAt(var6, (byte) 75);
            if (var7 == 60) {
                var4 = true;
            } else if (var7 == 62) {
                var4 = false;
            } else if (!var4 && var7 == 32) {
                ++var3;
            }
        }

        if (var3 > 0) {
            anInt3756 = (var2 - this.method682(var1) << 8) / var3;
        }

    }

    final int method691(RSString var1, int[] var2, RSString[] var3) {
        if (var1 == null) {
            return 0;
        } else {
            aClass94_3745.method1553(0);
            int var4 = 0;
            int var5 = 0;
            int var6 = -1;
            int var7 = 0;
            byte var8 = 0;
            int var9 = -1;
            int var10 = 0;
            int var11 = 0;
            int var12 = var1.length();

            for (int var13 = 0; var13 < var12; ++var13) {
                int var14 = var1.charAt(var13, (byte) -30);
                if (var14 == 60) {
                    var9 = var13;
                } else {
                    if (var14 == 62 && var9 != -1) {
                        RSString var15 = var1.substring(var9 + 1, var13, 0);
                        var9 = -1;
                        aClass94_3745.appendCharacter(60);
                        aClass94_3745.append(var15);
                        aClass94_3745.appendCharacter(62);
                        if (var15.equalsString(RSString.parse("br"))) {
                            if (var3[var11] == null) {
                                var3[var11] = aClass94_3745.method1563(101).substring(var5, aClass94_3745.length(), 0);
                            } else {
                                var3[var11].method1553(0);
                                var3[var11].method1542(aClass94_3745, var5, aClass94_3745.length());
                            }

                            ++var11;
                            var5 = aClass94_3745.length();
                            var4 = 0;
                            var6 = -1;
                            var10 = 0;
                        } else if (var15.equalsString(RSString.parse("lt"))) {
                            var4 += this.method687(60);
                            if (this.aByteArray3733 != null && var10 != 0) {
                                var4 += this.aByteArray3733[(var10 << 8) + 60];
                            }

                            var10 = 60;
                        } else if (var15.equalsString(RSString.parse("gt"))) {
                            var4 += this.method687(62);
                            if (this.aByteArray3733 != null && var10 != 0) {
                                var4 += this.aByteArray3733[(var10 << 8) + 62];
                            }

                            var10 = 62;
                        } else if (var15.equalsString(RSString.parse("nbsp"))) {
                            var4 += this.method687(160);
                            if (this.aByteArray3733 != null && var10 != 0) {
                                var4 += this.aByteArray3733[(var10 << 8) + 160];
                            }

                            var10 = 160;
                        } else if (var15.equalsString(RSString.parse("shy"))) {
                            var4 += this.method687(173);
                            if (this.aByteArray3733 != null && var10 != 0) {
                                var4 += this.aByteArray3733[(var10 << 8) + 173];
                            }

                            var10 = 173;
                        } else if (var15.equalsString(RSString.parse("times"))) {
                            var4 += this.method687(215);
                            if (this.aByteArray3733 != null && var10 != 0) {
                                var4 += this.aByteArray3733[(var10 << 8) + 215];
                            }

                            var10 = 215;
                        } else if (var15.equalsString(RSString.parse("euro"))) {
                            var4 += this.method687(128);
                            if (this.aByteArray3733 != null && var10 != 0) {
                                var4 += this.aByteArray3733[(var10 << 8) + 128];
                            }

                            var10 = 128;
                        } else if (var15.equalsString(RSString.parse("copy"))) {
                            var4 += this.method687(169);
                            if (this.aByteArray3733 != null && var10 != 0) {
                                var4 += this.aByteArray3733[(var10 << 8) + 169];
                            }

                            var10 = 169;
                        } else if (var15.equalsString(RSString.parse("reg"))) {
                            var4 += this.method687(174);
                            if (this.aByteArray3733 != null && var10 != 0) {
                                var4 += this.aByteArray3733[(var10 << 8) + 174];
                            }

                            var10 = 174;
                        } else if (var15.startsWith(RSString.parse("img="))) {
                            try {
                                int var16 = var15.substring(4).parseInt();
                                var4 += this.aClass109Array3740[var16].anInt1469;
                                var10 = 0;
                            } catch (Exception var17) {
                            }
                        }

                        var14 = 0;
                    }

                    if (var9 == -1) {
                        if (var14 != 0) {
                            aClass94_3745.appendCharacter(var14);
                            var4 += this.anIntArray3736[var14];
                            if (this.aByteArray3733 != null && var10 != 0) {
                                var4 += this.aByteArray3733[(var10 << 8) + var14];
                            }

                            var10 = var14;
                        }

                        if (var14 == 32) {
                            var6 = aClass94_3745.length();
                            var7 = var4;
                            var8 = 1;
                        }

                        if (var2 != null && var4 > var2[var11 < var2.length ? var11 : var2.length - 1] && var6 >= 0) {
                            if (var3[var11] == null) {
                                var3[var11] = aClass94_3745.method1563(88).substring(var5, var6 - var8, 0);
                            } else {
                                var3[var11].method1553(0);
                                var3[var11] = var3[var11].method1542(aClass94_3745, var5, var6 - var8);
                            }

                            ++var11;
                            var5 = var6;
                            var6 = -1;
                            var4 -= var7;
                            var10 = 0;
                        }

                        if (var14 == 45) {
                            var6 = aClass94_3745.length();
                            var7 = var4;
                            var8 = 0;
                        }
                    }
                }
            }

            if (aClass94_3745.length() > var5) {
                if (var3[var11] == null) {
                    var3[var11] = aClass94_3745.method1563(94).substring(var5, aClass94_3745.length(), 0);
                } else {
                    var3[var11].method1553(0);
                    var3[var11] = var3[var11].method1542(aClass94_3745, var5, aClass94_3745.length());
                }

                ++var11;
            }

            return var11;
        }
    }

    final void method692(RSString var1, int var2, int var3, int var4, int var6, int var7) {
        if (var1 != null) {
            this.method698(var4, 0);
            double var8 = 7.0D - (double) var7 / 8.0D;
            if (var8 < 0.0D) {
                var8 = 0.0D;
            }

            int var10 = var1.length();
            int[] var11 = new int[var10];

            for (int var12 = 0; var12 < var10; ++var12) {
                var11[var12] = (int) (Math.sin((double) var12 / 1.5D + (double) var6 / 1.0D) * var8);
            }

            this.method703(var1, var2 - this.method682(var1) / 2, var3, null, var11);
        }
    }

    public final int method693(RSString var1, int var2, int var3, int var4, int var5, int var6, int var7, int var9, int var10, int var11) {
        if (var1 == null) {
            return 0;
        } else {
            this.method701(var6, var7, 256);
            if (var11 == 0) {
                var11 = this.anInt3727;
            }

            int[] var12 = new int[]{var4};
            if (var5 < this.anInt3722 + this.anInt3710 + var11 && var5 < var11 + var11) {
                var12 = null;
            }

            int var13 = this.method691(var1, var12, aClass94Array3753);
            if (var10 == 3 && var13 == 1) {
                var10 = 1;
            }

            int var14;
            int var15;
            if (var10 == 0) {
                var14 = var3 + this.anInt3722;
            } else if (var10 == 1) {
                var14 = var3 + this.anInt3722 + (var5 - this.anInt3722 - this.anInt3710 - (var13 - 1) * var11) / 2;
            } else if (var10 == 2) {
                var14 = var3 + var5 - this.anInt3710 - (var13 - 1) * var11;
            } else {
                var15 = (var5 - this.anInt3722 - this.anInt3710 - (var13 - 1) * var11) / (var13 + 1);
                if (var15 < 0) {
                    var15 = 0;
                }

                var14 = var3 + this.anInt3722 + var15;
                var11 += var15;
            }

            for (var15 = 0; var15 < var13; ++var15) {
                if (var9 == 0) {
                    this.method677(aClass94Array3753[var15], var2, var14);
                } else if (var9 == 1) {
                    this.method677(aClass94Array3753[var15], var2 + (var4 - this.method682(aClass94Array3753[var15])) / 2, var14);
                } else if (var9 == 2) {
                    this.method677(aClass94Array3753[var15], var2 + var4 - this.method682(aClass94Array3753[var15]), var14);
                } else if (var15 == var13 - 1) {
                    this.method677(aClass94Array3753[var15], var2, var14);
                } else {
                    this.method690(aClass94Array3753[var15], var4);
                    this.method677(aClass94Array3753[var15], var2, var14);
                    anInt3756 = 0;
                }

                var14 += var11;
            }

            return var13;
        }
    }

    final void method695(RSString var1, int var2, int var3, int var4, int var6) {
        if (var1 != null) {
            this.method698(var4, 0);
            int var7 = var1.length();
            int[] var8 = new int[var7];
            int[] var9 = new int[var7];

            for (int var10 = 0; var10 < var7; ++var10) {
                var8[var10] = (int) (Math.sin((double) var10 / 5.0D + (double) var6 / 5.0D) * 5.0D);
                var9[var10] = (int) (Math.sin((double) var10 / 3.0D + (double) var6 / 5.0D) * 5.0D);
            }

            this.method703(var1, var2 - this.method682(var1) / 2, var3, var8, var9);
        }
    }

    final void method696(RSString var1, int var2, int var3, int var4, int var6) {
        if (var1 != null) {
            this.method698(var4, 0);
            int var7 = var1.length();
            int[] var8 = new int[var7];

            for (int var9 = 0; var9 < var7; ++var9) {
                var8[var9] = (int) (Math.sin((double) var9 / 2.0D + (double) var6 / 5.0D) * 5.0D);
            }

            this.method703(var1, var2 - this.method682(var1) / 2, var3, null, var8);
        }
    }

    final void method697(AbstractIndexedSprite[] var1, int[] var2) {
        if (var2 == null || var2.length == var1.length) {
            this.aClass109Array3740 = var1;
            this.anIntArray3723 = var2;
        } else {
            throw new IllegalArgumentException();
        }
    }

    private void method698(int var1, int var2) {
        anInt3746 = -1;
        anInt3747 = -1;
        anInt3752 = var2;
        anInt3754 = var2;
        anInt3749 = var1;
        anInt3755 = var1;
        anInt3751 = 256;
        anInt3750 = 256;
        anInt3756 = 0;
        anInt3748 = 0;
    }

    public final void method699(RSString var1, int var2, int var3, int var4, int var5) {
        if (var1 != null) {
            this.method698(var4, var5);
            this.method677(var1, var2 - this.method682(var1) / 2, var3);
        }
    }

    private void method700(byte[] var1) {
        this.anIntArray3736 = new int[256];
        int var2;
        if (var1.length == 257) {
            for (var2 = 0; var2 < this.anIntArray3736.length; ++var2) {
                this.anIntArray3736[var2] = var1[var2] & 0xFF;
            }

            this.anInt3727 = var1[256] & 0xFF;
        } else {
            var2 = 0;

            for (int var3 = 0; var3 < 256; ++var3) {
                this.anIntArray3736[var3] = var1[var2++] & 0xFF;
            }

            int[] var10 = new int[256];
            int[] var4 = new int[256];

            int var5;
            for (var5 = 0; var5 < 256; ++var5) {
                var10[var5] = var1[var2++] & 0xFF;
            }

            for (var5 = 0; var5 < 256; ++var5) {
                var4[var5] = var1[var2++] & 0xFF;
            }

            byte[][] var12 = new byte[256][];

            int var8;
            for (int var6 = 0; var6 < 256; ++var6) {
                var12[var6] = new byte[var10[var6]];
                byte var7 = 0;

                for (var8 = 0; var8 < var12[var6].length; ++var8) {
                    var7 += var1[var2++];
                    var12[var6][var8] = var7;
                }
            }

            byte[][] var11 = new byte[256][];

            int var13;
            for (var13 = 0; var13 < 256; ++var13) {
                var11[var13] = new byte[var10[var13]];
                byte var14 = 0;

                for (int var9 = 0; var9 < var11[var13].length; ++var9) {
                    var14 += var1[var2++];
                    var11[var13][var9] = var14;
                }
            }

            this.aByteArray3733 = new byte[65536];

            for (var13 = 0; var13 < 256; ++var13) {
                if (var13 != 32 && var13 != 160) {
                    for (var8 = 0; var8 < 256; ++var8) {
                        if (var8 != 32 && var8 != 160) {
                            this.aByteArray3733[(var13 << 8) + var8] = (byte) method694(var12, var11, var4, this.anIntArray3736, var10, var13, var8);
                        }
                    }
                }
            }

            this.anInt3727 = var4[32] + var10[32];
        }

    }

    private void method701(int var1, int var2, int var3) {
        anInt3746 = -1;
        anInt3747 = -1;
        anInt3752 = var2;
        anInt3754 = var2;
        anInt3749 = var1;
        anInt3755 = var1;
        anInt3751 = var3;
        anInt3750 = var3;
        anInt3756 = 0;
        anInt3748 = 0;
    }

    final void method702(RSString var1, int var2, int var3, int var4, int var5, int var6, int var7, int var8, int var9, Random var10, int var11, int[] var12) {
        if (var1 == null) return;

        var10.setSeed(var11);
        this.method701(var6, var7, 192 + (var10.nextInt() & 31));
        int var13 = var1.length();
        int[] var14 = new int[var13];
        int var15 = 0;

        int var16;
        for (var16 = 0; var16 < var13; ++var16) {
            var14[var16] = var15;
            if ((var10.nextInt() & 3) == 0) {
                ++var15;
            }
        }

        var16 = var2;
        int var17 = var3 + this.anInt3722;
        int var18 = -1;
        if (var9 == 1) {
            var17 += (var5 - this.anInt3722 - this.anInt3710) / 2;
        } else if (var9 == 2) {
            var17 = var3 + var5 - this.anInt3710;
        }

        if (var8 == 1) {
            var18 = this.method682(var1) + var15;
            var16 = var2 + (var4 - var18) / 2;
        } else if (var8 == 2) {
            var18 = this.method682(var1) + var15;
            var16 = var2 + (var4 - var18);
        }

        this.method703(var1, var16, var17, var14, null);
        if (var12 != null) {
            if (var18 == -1) {
                var18 = this.method682(var1) + var15;
            }

            var12[0] = var16;
            var12[1] = var17 - this.anInt3722;
            var12[2] = var18;
            var12[3] = this.anInt3722 + this.anInt3710;
        }
    }

    private void method703(RSString var1, int var2, int var3, int[] var4, int[] var5) {
        var3 -= this.anInt3727;
        int var6 = -1;
        int var7 = 0;
        int var8 = 0;
        int var9 = var1.length();

        for (int var10 = 0; var10 < var9; ++var10) {
            int var11 = var1.charAt(var10, (byte) 95);
            if (var11 == 60) {
                var6 = var10;
            } else {
                int var13;
                int var14;
                int var15;
                if (var11 == 62 && var6 != -1) {
                    RSString var12 = var1.substring(var6 + 1, var10, 0);
                    var6 = -1;
                    if (var12.equalsString(RSString.parse("lt"))) {
                        var11 = 60;
                    } else if (var12.equalsString(RSString.parse("gt"))) {
                        var11 = 62;
                    } else if (var12.equalsString(RSString.parse("nbsp"))) {
                        var11 = 160;
                    } else if (var12.equalsString(RSString.parse("shy"))) {
                        var11 = 173;
                    } else if (var12.equalsString(RSString.parse("times"))) {
                        var11 = 215;
                    } else if (var12.equalsString(RSString.parse("euro"))) {
                        var11 = 128;
                    } else if (var12.equalsString(RSString.parse("copy"))) {
                        var11 = 169;
                    } else {
                        if (!var12.equalsString(RSString.parse("reg"))) {
                            if (var12.startsWith(RSString.parse("img="))) {
                                try {
                                    if (var4 == null) {
                                        var13 = 0;
                                    } else {
                                        var13 = var4[var8];
                                    }

                                    if (var5 == null) {
                                        var14 = 0;
                                    } else {
                                        var14 = var5[var8];
                                    }

                                    ++var8;
                                    var15 = var12.substring(4).parseInt();
                                    AbstractIndexedSprite var20 = this.aClass109Array3740[var15];
                                    int var17 = this.anIntArray3723 != null ? this.anIntArray3723[var15] : var20.anInt1467;
                                    if (anInt3750 == 256) {
                                        var20.method1667(var2 + var13, var3 + this.anInt3727 - var17 + var14);
                                    } else {
                                        var20.method1666(var2 + var13, var3 + this.anInt3727 - var17 + var14, anInt3750);
                                    }

                                    var2 += var20.anInt1469;
                                    var7 = 0;
                                } catch (Exception var18) {
                                }
                            } else {
                                this.method685(var12);
                            }
                            continue;
                        }

                        var11 = 174;
                    }
                }

                if (var6 == -1) {
                    if (this.aByteArray3733 != null && var7 != 0) {
                        var2 += this.aByteArray3733[(var7 << 8) + var11];
                    }

                    int var19 = this.anIntArray3709[var11];
                    var13 = this.anIntArray3721[var11];
                    if (var4 == null) {
                        var14 = 0;
                    } else {
                        var14 = var4[var8];
                    }

                    if (var5 == null) {
                        var15 = 0;
                    } else {
                        var15 = var5[var8];
                    }

                    ++var8;
                    if (var11 != 32) {
                        if (anInt3750 == 256) {
                            if (anInt3754 != -1) {
                                this.method678(var11, var2 + this.anIntArray3719[var11] + 1 + var14, var3 + this.anIntArray3730[var11] + 1 + var15, var19, var13, anInt3754);
                            }

                            this.method678(var11, var2 + this.anIntArray3719[var11] + var14, var3 + this.anIntArray3730[var11] + var15, var19, var13, anInt3755);
                        } else {
                            if (anInt3754 != -1) {
                                this.method679(var11, var2 + this.anIntArray3719[var11] + 1 + var14, var3 + this.anIntArray3730[var11] + 1 + var15, var19, var13, anInt3754, anInt3750);
                            }

                            this.method679(var11, var2 + this.anIntArray3719[var11] + var14, var3 + this.anIntArray3730[var11] + var15, var19, var13, anInt3755, anInt3750);
                        }
                    } else if (anInt3756 > 0) {
                        anInt3748 += anInt3756;
                        var2 += anInt3748 >> 8;
                        anInt3748 &= 255;
                    }

                    int var16 = this.anIntArray3736[var11];
                    if (anInt3746 != -1) {
                        Toolkit.getActiveToolkit().drawHorizontalLine(var2, var3 + (int) ((double) this.anInt3727 * 0.7D), var16, anInt3746);
                    }

                    if (anInt3747 != -1) {
                        Toolkit.getActiveToolkit().drawHorizontalLine(var2, var3 + this.anInt3727, var16, anInt3747);
                    }

                    var2 += var16;
                    var7 = var11;
                }
            }
        }

    }

}
