RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Changing a "Private" variable forcibly?

Changing a "Private" variable forcibly?

Hiya, I was wondering if there's any way I can edit a Private variable outside of that class, forcibly or by any other means. The reason I'm actually asking this instead of just changing the scope of the variable because it's within the core. I've looked around, and seemingly couldn't find an exact answer. For the exact code I'm wanting to change without editing the core... See below.

Lines 2679-2682 in Mobile.cs

Code:
        private static TimeSpan m_WalkFoot = TimeSpan.FromSeconds( 0.4 );
        private static TimeSpan m_RunFoot = TimeSpan.FromSeconds( 0.2 );
        private static TimeSpan m_WalkMount = TimeSpan.FromSeconds( 0.2 );
        private static TimeSpan m_RunMount = TimeSpan.FromSeconds( 0.1 );

Thanks for the help in advance!
 

noobie

Wanderer
well, when you have core files, it is really not necassary to use such a thing but here is what you can do:


Code:
Type mobileType = Type.GetType("Server.Mobile");
FieldInfo walkFoot = mobileType.GetField("m_WalkFoot", BindingFlags.NonPublic);
walkFoot.SetValue(null, newVal);
 

Jeff

Lord
noobie;657062 said:
well, when you have core files, it is really not necassary to use such a thing but here is what you can do:


Code:
Type mobileType = Type.GetType("Server.Mobile");
FieldInfo walkFoot = mobileType.GetField("m_WalkFoot", BindingFlags.NonPublic);
walkFoot.SetValue(null, newVal);

wow, doesnt that defeat the purpose of private :/
 

TMSTKSBK

Lord
Ya gotta do what ya gotta do...
(I think really it's just the annoyance factor involved in changing it that keeps private relatively...well..."private".)
 

noobie

Wanderer
there is no such a thing as private :p

sometimes, changing a private value might mess up implementation, but here it is only cpu i guess :)
 

Malaperth

Wanderer
Well, the issue I see with what I believe you are trying to do is that since the members are static, if you change the value, it will change the value for all instances of Mobile in the world, which I think was pretty much what noobie was getting at.

[EDIT]

It also just occurred to me that since in BaseCreature, you can specify Active and Passive speed, there must be a way to change these values already in place since it seems that they corespond to same.
 
Malaperth;657461 said:
It also just occurred to me that since in BaseCreature, you can specify Active and Passive speed, there must be a way to change these values already in place since it seems that they corespond to same.
Uhh, you mean for a Mobile? PlayerMobile has some options for speed in it, though it has a very VERY small effect, if any Since I was taking lag into account, I'd say that's the only reason why one person was faster than another... The test was too run across a field, and the person who I changed their speed from the PlayerMobile ended up getting there just a few steps earlier.

That's why I wanted to edit the mobile. I've had a few speculations about it being a static variable, and thus editing all of the mobiles in the world. Though I was also wondering about the PlayerMobiles little movement speed things, and if they would have any effect. So I was just gonna do a bit of trial & error :rolleyes:

At least once I get it to work the way I want it too... :rolleyes:

It did kind of strike me though that you can change privates like that. Very interesting.
 

Malaperth

Wanderer
In the constructor of a BaseCreature, you specify the Active and Passive speed, which, strangely coincide with the values you mention wanting to change. That means that speed IS already changeable.
 
Malaperth;657616 said:
In the constructor of a BaseCreature, you specify the Active and Passive speed, which, strangely coincide with the values you mention wanting to change. That means that speed IS already changeable.
Not trying to change it for a BaseCreature, i'm trying to change it for a playermobile. I've gone through PlayerMobile.cs, and the values there didn't help it any, as I said before. :\

I wish it was as easy as BaseCreature. :rolleyes:
 

Malaperth

Wanderer
Right, however, BaseCreature inherits from Mobile, so between those two classes, somewhere in there must be a way to change the speed since it is done in BaseCreature, so the capability is already there, you just need to find it.
 
Malaperth;657901 said:
Right, however, BaseCreature inherits from Mobile, so between those two classes, somewhere in there must be a way to change the speed since it is done in BaseCreature, so the capability is already there, you just need to find it.
Ohh true... Hmm... *looks*

Edit: Can't find anything that looks like it'll change that. SpeedInfo was the only really "different" thing in there, and SpeedInfo.cs really has nothing that'll change the mobile speed (I believe it just gets it, and sets a base setting). PlayerMobile.cs already HAD something inside itself for editing speeds... It just didn't alter anything.
 

Malaperth

Wanderer
Well, from just a quick look at BaseCreature, I found this:

Code:
		public BaseCreature(AIType ai,
			FightMode mode,
			int iRangePerception,
			int iRangeFight,[COLOR="Red"]
			double dActiveSpeed, 
			double dPassiveSpeed[/COLOR])

which leads to this:

Code:
			SpeedInfo.GetSpeeds( this, ref [COLOR="Red"]dActiveSpeed[/COLOR], ref [COLOR="Red"]dPassiveSpeed[/COLOR] );
 
Malaperth;658065 said:
Well, from just a quick look at BaseCreature, I found this:

Code:
        public BaseCreature(AIType ai,
            FightMode mode,
            int iRangePerception,
            int iRangeFight,[COLOR=Red]
            double dActiveSpeed, 
            double dPassiveSpeed[/COLOR])
which leads to this:

Code:
            SpeedInfo.GetSpeeds( this, ref [COLOR=Red]dActiveSpeed[/COLOR], ref [COLOR=Red]dPassiveSpeed[/COLOR] );
Yea, but the SpeedInfo doesn't change anything on the BaseCreature...

Code:
using System;
using System.Collections;
using Server;
using Server.Mobiles;
using Server.Factions;

namespace Server
{
    public class SpeedInfo
    {
        // Should we use the new method of speeds?
        private static bool Enabled = true;

        private double m_ActiveSpeed;
        private double m_PassiveSpeed;
        private Type[] m_Types;

        public double ActiveSpeed
        {
            get{ return m_ActiveSpeed; }
            set{ m_ActiveSpeed = value; }
        }

        public double PassiveSpeed
        {
            get{ return m_PassiveSpeed; }
            set{ m_PassiveSpeed = value; }
        }

        public Type[] Types
        {
            get{ return m_Types; }
            set{ m_Types = value; }
        }

        public SpeedInfo( double activeSpeed, double passiveSpeed, Type[] types )
        {
            m_ActiveSpeed = activeSpeed;
            m_PassiveSpeed = passiveSpeed;
            m_Types = types;
        }

        public static bool Contains( object obj )
        {
            if ( !Enabled )
                return false;

            if ( m_Table == null )
                LoadTable();

            SpeedInfo sp = (SpeedInfo)m_Table[obj.GetType()];

            return ( sp != null );
        }

        public static bool GetSpeeds( object obj, ref double activeSpeed, ref double passiveSpeed )
        {
            if ( !Enabled )
                return false;

            if ( m_Table == null )
                LoadTable();

            SpeedInfo sp = (SpeedInfo)m_Table[obj.GetType()];

            if ( sp == null )
                return false;

            activeSpeed = sp.ActiveSpeed;
            passiveSpeed = sp.PassiveSpeed;

            return true;
        }

        private static void LoadTable()
        {
            m_Table = new Hashtable();

            for ( int i = 0; i < m_Speeds.Length; ++i )
            {
                SpeedInfo info = m_Speeds[i];
                Type[] types = info.Types;

                for ( int j = 0; j < types.Length; ++j )
                    m_Table[types[j]] = info;
            }
        }

        private static Hashtable m_Table;

        private static SpeedInfo[] m_Speeds = new SpeedInfo[]
        {
            /* Slow */
            new SpeedInfo( 0.3, 0.6, new Type[]
            {
                typeof( AntLion ),            typeof( ArcticOgreLord ),    typeof( BogThing ),
                typeof( Bogle ),            typeof( BoneKnight ),        typeof( EarthElemental ),
                typeof( Ettin ),            typeof( FrostOoze ),        typeof( FrostTroll ),
                typeof( GazerLarva ),        typeof( Ghoul ),            typeof( Golem ),
                typeof( HeadlessOne ),        typeof( Jwilson ),            typeof( Mummy ),
                typeof( Ogre ),                typeof( OgreLord ),            typeof( PlagueBeast ),
                typeof( Quagmire ),            typeof( Rat ),                typeof( RottingCorpse ),
                typeof( Sewerrat ),            typeof( Skeleton ),            typeof( Slime ),
                typeof( Zombie ),            typeof( Walrus ),            typeof( RestlessSoul ),
                typeof( CrystalElemental ),    typeof( DarknightCreeper ),    typeof( MoundOfMaggots ),
                typeof( Juggernaut )
            } ),
            /* Fast */
            new SpeedInfo( 0.2, 0.4, new Type[]
            {
                typeof( LordOaks ),            typeof( Silvani ),            typeof( AirElemental ),
                typeof( AncientWyrm ),        typeof( Balron ),            typeof( BladeSpirits ),
                typeof( DreadSpider ),        typeof( Efreet ),            typeof( EtherealWarrior ),
                typeof( Lich ),                typeof( Nightmare ),        typeof( OphidianArchmage ),
                typeof( OphidianMage ),        typeof( OphidianWarrior ),    typeof( OphidianMatriarch ),
                typeof( OphidianKnight ),    typeof( PoisonElemental ),    typeof( Revenant ),
                typeof( SandVortex ),        typeof( SavageRider ),        typeof( SavageShaman ),
                typeof( SnowElemental ),    typeof( WhiteWyrm ),        typeof( Wisp ),
                typeof( SummonedAirElemental ),    typeof( GiantBlackWidow ), typeof( DemonKnight )
            } ),
            /* Very Fast */
            new SpeedInfo( 0.175, 0.350, new Type[]
            {
                typeof( Barracoon ),        typeof( Mephitis ),            typeof( Neira ),
                typeof( Rikktor ),            typeof( Semidar ),            typeof( EnergyVortex ),
                typeof( Beetle ),            typeof( Pixie ),            typeof( SilverSerpent ),
                typeof( VorpalBunny ),        typeof( FleshRenderer ),    typeof( KhaldunRevenant ),
                typeof( FactionDragoon ),    typeof( FactionKnight ),    typeof( FactionPaladin ),
                typeof( FactionHenchman ),    typeof( FactionMercenary ),    typeof( FactionNecromancer ),
                typeof( FactionSorceress ),    typeof( FactionWizard ),    typeof( FactionBerserker ),
                typeof( FactionDeathKnight )
            } ),
            /* Medium */
            new SpeedInfo( 0.25, 0.5, new Type[]
            {
                typeof( ToxicElemental ),    typeof( Agapitebeast ),    typeof( Alligator ),
                typeof( AncientLich ),        typeof( Betrayer ),            typeof( Bird ),
                typeof( BlackBear ),        typeof( BlackSolenInfiltratorQueen ), typeof( BlackSolenInfiltratorWarrior ),
                typeof( BlackSolenQueen ),    typeof( BlackSolenWarrior ), typeof( BlackSolenWorker ),
                typeof( BloodElemental ),    typeof( Boar ),                typeof( Bogling ),
                typeof( BoneMagi ),            typeof( Brigand ),            typeof( Bronzebeast ),
                typeof( BrownBear ),        typeof( Bull ),                typeof( BullFrog ),
                typeof( Cat ),                typeof( Centaur ),            typeof( ChaosDaemon ),
                typeof( Chicken ),            typeof( GolemController ),    typeof( Copperbeast ),
                typeof( Copperbeast ),    typeof( Cougar ),            typeof( Cow ),
                typeof( Cyclops ),            typeof( Daemon ),            typeof( DeepSeaSerpent ),
                typeof( DesertOstard ),        typeof( DireWolf ),            typeof( Dog ),
                typeof( Dolphin ),            typeof( Dragon ),            typeof( Drake ),
                typeof( DullCopperbeast ), typeof( Eagle ),            typeof( ElderGazer ),
                typeof( EvilMage ),            typeof( EvilMageLord ),        typeof( Executioner ),
                typeof( Savage ),            typeof( FireElemental ),    typeof( FireGargoyle ),
                typeof( FireSteed ),        typeof( ForestOstard ),        typeof( FrenziedOstard ),
                typeof( FrostSpider ),        typeof( Gargoyle ),            typeof( Gazer ),
                typeof( IceSerpent ),        typeof( GiantRat ),            typeof( GiantSerpent ),
                typeof( GiantSpider ),        typeof( GiantToad ),        typeof( Goat ),
                typeof( Goldenbeast ),    typeof( Gorilla ),            typeof( GreatHart ),
                typeof( GreyWolf ),            typeof( GrizzlyBear ),        typeof( Guardian ),
                typeof( Harpy ),            typeof( Harrower ),            typeof( HellHound ),
                typeof( Hind ),                typeof( HordeMinion ),        typeof( Horse ),
                typeof( Horse ),            typeof( IceElemental ),        typeof( IceFiend ),
                typeof( IceSnake ),            typeof( Imp ),                typeof( JackRabbit ),
                typeof( Kirin ),            typeof( Kraken ),            typeof( PredatorHellCat ),
                typeof( LavaLizard ),        typeof( LavaSerpent ),        typeof( LavaSnake ),
                typeof( Lizardman ),        typeof( Llama ),            typeof( Mongbat ),
                typeof( StrongMongbat ),    typeof( MountainGoat ),        typeof( Orc ),
                typeof( OrcBomber ),        typeof( OrcBrute ),            typeof( OrcCaptain ),
                typeof( OrcishLord ),        typeof( OrcishMage ),        typeof( PackHorse ),
                typeof( PackLlama ),        typeof( Panther ),            typeof( Pig ),
                typeof( PlagueSpawn ),        typeof( PolarBear ),        typeof( Rabbit ),
                typeof( Ratman ),            typeof( RatmanArcher ),        typeof( RatmanMage ),
                typeof( RedSolenInfiltratorQueen ), typeof( RedSolenInfiltratorWarrior ), typeof( RedSolenQueen ),
                typeof( RedSolenWarrior ),    typeof( RedSolenWorker ),    typeof( RidableLlama ),
                typeof( Ridgeback ),        typeof( Scorpion ),            typeof( SeaSerpent ),
                typeof( SerpentineDragon ),    typeof( Shade ),            typeof( ShadowIronbeast ),
                typeof( ShadowWisp ),        typeof( ShadowWyrm ),        typeof( Sheep ),
                typeof( SilverSteed ),        typeof( SkeletalDragon ),    typeof( SkeletalMage ),
                typeof( SkeletalMount ),    typeof( HellCat ),            typeof( Snake ),
                typeof( SnowLeopard ),        typeof( SpectralArmour ),    typeof( Spectre ),
                typeof( StoneGargoyle ),    typeof( StoneHarpy ),        typeof( SwampDragon ),
                typeof( ScaledSwampDragon ), typeof( SwampTentacle ),    typeof( TerathanAvenger ),
                typeof( TerathanDrone ),    typeof( TerathanMatriarch ), typeof( TerathanWarrior ),
                typeof( TimberWolf ),        typeof( Titan ),            typeof( Troll ),
                typeof( Unicorn ),            typeof( Valoritebeast ), typeof( Veritebeast ),
                typeof( CoMWarHorse ),        typeof( MinaxWarHorse ),    typeof( SLWarHorse ),
                typeof( TBWarHorse ),        typeof( WaterElemental ),    typeof( WhippingVine ),
                typeof( WhiteWolf ),        typeof( Wraith ),            typeof( Wyvern ),
                typeof( KhaldunZealot ),    typeof( KhaldunSummoner ),    typeof( SavageRidgeback ),
                typeof( LichLord ),            typeof( SkeletalKnight ),    typeof( SummonedDaemon ),
                typeof( SummonedEarthElemental ),    typeof( SummonedWaterElemental ), typeof( SummonedFireElemental ),
                typeof( MeerWarrior ),        typeof( MeerEternal ),        typeof( MeerMage ),
                typeof( MeerCaptain ),        typeof( JukaLord ),            typeof( JukaMage ),
                typeof( JukaWarrior ),        typeof( AbysmalHorror ),    typeof( BoneDemon ),
                typeof( Devourer ),            typeof( FleshGolem ),        typeof( Gibberling ),
                typeof( GoreFiend ),        typeof( Impaler ),            typeof( PatchworkSkeleton ),
                typeof( Ravager ),            typeof( ShadowKnight ),        typeof( SkitteringHopper ),
                typeof( Treefellow ),        typeof( VampireBat ),        typeof( WailingBanshee ),
                typeof( WandererOfTheVoid ),    typeof( Cursed ),            typeof( GrimmochDrummel ),
                typeof( LysanderGathenwale),    typeof( MorgBergen ),    typeof( ShadowFiend ),
                typeof( SpectralArmour ),    typeof( TavaraSewel ),        typeof( ArcaneDaemon ),
                typeof( Doppleganger ),        typeof( EnslavedGargoyle ), typeof( ExodusMinion ),
                typeof( ExodusOverseer ),    typeof( GargoyleDestroyer ),    typeof( GargoyleEnforcer ),
                typeof( Moloch )
            } )
        };
    }
}

Nothing in there showed me anything about changing their speeds in the slightest. Though I guess it won't hurt to try. Lemme give it a shot, and good thinking on the random tidbit there, i'll just declare a few things, then try this puppy out!
 

Jeff

Lord
Code:
        public double ActiveSpeed
        {
            get{ return m_ActiveSpeed; }
            set{ m_ActiveSpeed = value; }
        }

        public double PassiveSpeed
        {
            get{ return m_PassiveSpeed; }
            set{ m_PassiveSpeed = value; }
        }
These control the speed of the creatures AI.
 

Malaperth

Wanderer
IHaveRegistered;659546 said:
Hmm, I just tried to use the code from BaseCreature.cs and it had no effect on my running/walking speeds.

Shame :\

All I know is that when you change the values passed in to the BaseCreature constructor, it does effect the mobile's speed, so there must be a way to do it even if I/we do not exactly know how.
 

Jeff

Lord
Malaperth;660313 said:
All I know is that when you change the values passed in to the BaseCreature constructor, it does effect the mobile's speed, so there must be a way to do it even if I/we do not exactly know how.

Even when changed in [props it changes the mobiles movement speed.
 

Jeff

Lord
IHaveRegistered;659546 said:
Hmm, I just tried to use the code from BaseCreature.cs and it had no effect on my running/walking speeds.

Shame :\

wait just a min, YOUR movement speeds....thats client based....
 
Top