Example #1
0
        private void ParseObject(object o)
        {
            string s;

            Dictionary <string, FieldInfo> fields = new Dictionary <string, FieldInfo>();

            //get all class variables
            foreach (var prop in o.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                fields.Add(prop.Name, prop);
            }
            do
            {
                ParseLine();
                s = getString();
                if (o.GetType() == typeof(LoadSubsystem))
                {
                    LoadSubsystem ls = (LoadSubsystem)o;
                    switch (s)
                    {
                    case "InitFile":
                        ls.AddInitFile(getString());
                        break;

                    case "InitFileDebug":
                        ls.AddInitFileDebug(getString());
                        break;

                    case "InitPath":
                        ls.AddInitPath(getString());
                        break;

                    case "IncludePathCinematics":
                        ls.AddIncludePathCinematics(getString());
                        break;

                    case "ExcludePath":
                        ls.AddExcludePath(getString());
                        break;
                    }
                }
                else if (o.GetType() == typeof(AnimationState))
                {
                    AnimationState state = (AnimationState)o;
                    string         name;
                    switch (s)
                    {
                    case "Animation":
                        Animation anim = new Animation();
                        ParseObject(anim);
                        state.AddAnimation(anim);
                        break;

                    case "BeginScript":
                        string line = getLine();
                        while (!line.Equals("EndScript"))
                        {
                            state.AddScriptLine(line);
                            line = getLine();
                        }
                        break;

                    case "ParticleSysBone":
                        name = getString();
                        state.AddParticleSysBone(name, ParseParticleSysBone());
                        break;
                    }
                }
                else if (o.GetType() == typeof(Armor))
                {
                    Armor ar = (Armor)o;
                    switch (s)
                    {
                    case "Armor":
                        ar.AddType(getString(), getFloat());
                        break;
                    }
                }
                else if (o.GetType() == typeof(AudioEvent))
                {
                    AudioEvent ae = (AudioEvent)o;
                    switch (s)
                    {
                    case "Sounds":
                        string   val    = getStrings();
                        string[] sounds = val.Split(' ');
                        foreach (string sound in sounds)
                        {
                            MusicTrack mt;
                            if (INIManager.TryGetMusicTrack(sound, out mt))
                            {
                                ae.AddMusicTrack(mt);
                            }
                            //else
                            //    PrintError(" no such MusicTrack found: " + sound);
                        }
                        break;
                    }
                }
                else if (o.GetType() == typeof(Draw))
                {
                    Draw   dr = (Draw)o;
                    string name;
                    switch (s)
                    {
                    case "AnimationState":
                        AnimationState astate = new AnimationState();
                        name = getString();
                        ParseObject(astate);
                        dr.AddAnimationState(name, astate);
                        break;

                    case "DefaultModelConditionState":
                        ModelConditionState defMod = new ModelConditionState();
                        ParseObject(defMod);
                        dr.DefaultModelConditionState = defMod;
                        break;

                    case "IdleAnimationState":
                        AnimationState iastate = new AnimationState();
                        ParseObject(iastate);
                        dr.IdleAnimationState = iastate;
                        break;

                    case "ModelConditionState":
                        ModelConditionState mcs = new ModelConditionState();
                        name = getString();
                        ParseObject(mcs);
                        dr.AddModelConditionState(name, mcs);
                        break;
                    }
                }
                else if (o.GetType() == typeof(FXList))
                {
                    FXList fx = (FXList)o;
                    switch (s)
                    {
                    case "BuffNugget":
                        BuffNugget bn = new BuffNugget();
                        ParseObject(bn);
                        fx.buffNugget = bn;
                        break;

                    case "CameraShakerVolume":
                        CameraShakerVolume cs = new CameraShakerVolume();
                        ParseObject(cs);
                        fx.cameraShakerVolume = cs;
                        break;

                    case "DynamicDecal":
                        DynamicDecal dc = new DynamicDecal();
                        ParseObject(dc);
                        fx.AddDynamicDecal(dc);
                        break;

                    case "ParticleSystem":
                        ParticleSystem ps = new ParticleSystem();
                        ParseObject(ps);
                        fx.AddParticleSystem(ps);
                        break;

                    case "Sound":
                        Sound so = new Sound();
                        ParseObject(so);
                        fx.AddSound(so);
                        break;

                    case "TerrainScorch":
                        TerrainScorch ts = new TerrainScorch();
                        ParseObject(ts);
                        fx.AddTerrainScorch(ts);
                        break;

                    case "TintDrawable":
                        TintDrawable td = new TintDrawable();
                        ParseObject(td);
                        fx.tintDrawable = td;
                        break;

                    case "ViewShake":
                        ViewShake vs = new ViewShake();
                        ParseObject(vs);
                        fx.viewShake = vs;
                        break;
                    }
                }
                else if (o.GetType() == typeof(GameData))
                {
                    GameData gd = (GameData)o;
                    switch (s)
                    {
                    case "StandardPublicBone":
                        gd.AddStandardPublicBone(getString());
                        break;

                    case "WeaponBonus":
                        gd.AddWeaponBonus(getString(), getString(), getInt());
                        break;
                    }
                }
                else if (o.GetType() == typeof(ModelConditionState))
                {
                    ModelConditionState mstate = (ModelConditionState)o;
                    string name;
                    switch (s)
                    {
                    case "ParticleSysBone":
                        name = getString();
                        mstate.AddParticleSysBone(name, ParseParticleSysBone());
                        break;
                    }
                }
                else if (o.GetType() == typeof(ModifierList))
                {
                    ModifierList ml = (ModifierList)o;
                    switch (s)
                    {
                    case "Modifier":
                        ml.AddModifier(getString(), getStrings());
                        break;
                    }
                }
                else if (o.GetType() == typeof(Multisound))
                {
                    Multisound ms = (Multisound)o;
                    switch (s)
                    {
                    case "Subsounds":
                        string   val    = getStrings();
                        string[] sounds = val.Split(' ');
                        foreach (string sound in sounds)
                        {
                            MusicTrack mt;
                            if (INIManager.TryGetMusicTrack(sound, out mt))
                            {
                                ms.AddMusicTrack(mt);
                            }
                            //else
                            //   PrintError(" no such MusicTrack found: " + sound);
                        }
                        break;
                    }
                }
                else if (o.GetType() == typeof(INI.Object))
                {
                    INI.Object obj = (INI.Object)o;
                    string     name;
                    switch (s)
                    {
                    case "ArmorSet":
                        ArmorSet set = new ArmorSet();
                        ParseObject(set);
                        obj.AddArmorSet(set);
                        break;

                    case "Behaviour":
                        Behaviour b = new Behaviour();
                        name = getString();
                        ParseObject(b);
                        obj.AddBehaviour(name, b);
                        break;

                    case "Body":
                        Body bo = new Body();
                        name = getString();
                        ParseObject(bo);
                        obj.AddBody(name, bo);
                        break;

                    case "Draw":
                        Draw d = new Draw();
                        name = getString();
                        ParseObject(d);
                        obj.AddDraw(name, d);
                        break;
                    }
                }
                else if (o.GetType() == typeof(Weapon))
                {
                    Weapon w = (Weapon)o;
                    switch (s)
                    {
                    case "AttributeModifierNugget":
                        AttributeModifierNugget amn = new AttributeModifierNugget();
                        ParseObject(amn);
                        w.attributeModifierNugget = amn;
                        break;

                    case "DamageContainedNugget":
                        DamageContainedNugget dcn = new DamageContainedNugget();
                        ParseObject(dcn);
                        w.damageContainedNugget = dcn;
                        break;

                    case "DamageFieldNugget":
                        DamageFieldNugget dfn = new DamageFieldNugget();
                        ParseObject(dfn);
                        w.damageFieldNugget = dfn;
                        break;

                    case "DamageNugget":
                        DamageNugget dn = new DamageNugget();
                        ParseObject(dn);
                        w.damageNugget = dn;
                        break;

                    case "DOTNugget":
                        DOTNugget don = new DOTNugget();
                        ParseObject(don);
                        w.dotNugget = don;
                        break;

                    case "FireLogicNugget":
                        FireLogicNugget fln = new FireLogicNugget();
                        ParseObject(fln);
                        w.fireLogicNugget = fln;
                        break;

                    case "HordeAttackNugget":
                        HordeAttackNugget han = new HordeAttackNugget();
                        ParseObject(han);
                        w.hordeAttackNugget = han;
                        break;

                    case "LuaEventNugget":
                        LuaEventNugget len = new LuaEventNugget();
                        ParseObject(len);
                        w.luaEventNugget = len;
                        break;

                    case "MetaImpactNugget":
                        MetaImpactNugget min = new MetaImpactNugget();
                        ParseObject(min);
                        w.metaImpactNugget = min;
                        break;

                    case "OpenGateNugget":
                        OpenGateNugget ogn = new OpenGateNugget();
                        ParseObject(ogn);
                        w.openGateNugget = ogn;
                        break;

                    case "ParalyzeNugget":
                        ParalyzeNugget pan = new ParalyzeNugget();
                        ParseObject(pan);
                        w.paralyzeNugget = pan;
                        break;

                    case "ProjectileNugget":
                        ProjectileNugget pn = new ProjectileNugget();
                        ParseObject(pn);
                        w.AddProjectileNugget(pn);
                        break;

                    case "SlaveAttackNugget":
                        SlaveAttackNugget san = new SlaveAttackNugget();
                        ParseObject(san);
                        w.slaveAttackNugget = san;
                        break;

                    case "StealMoneyNugget":
                        StealMoneyNugget smn = new StealMoneyNugget();
                        ParseObject(smn);
                        w.stealMoneyNugget = smn;
                        break;

                    case "WeaponOCLNugget":
                        WeaponOCLNugget won = new WeaponOCLNugget();
                        ParseObject(won);
                        w.weaponOCLNugget = won;
                        break;
                    }
                }

                else if (fields.ContainsKey(s))
                {
                    Type type = fields[s].FieldType;
                    if (type == typeof(string))
                    {
                        fields[s].SetValue(o, getString());
                    }
                    else if (type == typeof(int))
                    {
                        fields[s].SetValue(o, getInt());
                    }
                    else if (type == typeof(int[]))
                    {
                        fields[s].SetValue(o, getInts());
                    }
                    else if (type == typeof(float))
                    {
                        fields[s].SetValue(o, getFloat());
                    }
                    else if (type == typeof(float[]))
                    {
                        fields[s].SetValue(o, getFloats());
                    }
                    else if (type == typeof(bool))
                    {
                        fields[s].SetValue(o, getBool());
                    }
                    else if (type == typeof(OpenTK.Vector2))
                    {
                        fields[s].SetValue(o, getVec2());
                    }
                    else if (type == typeof(OpenTK.Vector3))
                    {
                        fields[s].SetValue(o, getVec3());
                    }
                    else
                    {
                        PrintError("invalid type: " + type);
                    }
                }
                else
                {
                    if (!s.Equals("End") && !s.Equals("END"))
                    {
                        PrintError("invalid parameter in " + o.GetType() + " class: " + s);
                    }
                }
            }while (!s.Equals("End") && !s.Equals("END"));
        }