Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# reflection need help.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Thu Sep 16, 2010 10:39 am    Post subject: C# reflection need help. Reply with quote

Hello.

I'm trying to figure out how to design a dll to trigger this code. My book didn't cover it so I don't know what to do.

Code:
   foreach (string f in Directory.GetFiles(System.Environment.CurrentDirectory, "addon-*.dll"))
            {
                Assembly asm = Assembly.LoadFile(f);

                object[] descs = asm.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                AssemblyDescriptionAttribute desc = (AssemblyDescriptionAttribute)descs[0];
                Console.WriteLine(desc.Description);

                foreach (Type t in asm.GetTypes())
                {
                    if (t.Name.EndsWith("Greeting"))
                    {
                        MethodInfo greet = t.GetMethod("Greet");
                        greet.Invoke(null, null);
                        break;
                    }
                }
            }


Hmm.. So I need a class named greeting with a method called Greet? and the dll can be named addon-andsomerandomname.dll

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Sep 16, 2010 1:25 pm    Post subject: Reply with quote

You may need to use Assembly.LoadFrom instead of LoadFile.

Use the LoadFile method to load and examine assemblies that have the same identity, but are located in different paths. LoadFile does not load files into the LoadFrom context, and does not resolve dependencies using the load path, as the LoadFrom method does. LoadFile is useful in this limited scenario because LoadFrom cannot be used to load assemblies that have the same identities but different paths; it will load only the first such assembly.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Thu Sep 16, 2010 4:23 pm    Post subject: sorry. i not clear Reply with quote

Thx but my code worked too.

Let me make my question clearer Smile

My questions was (ye i forgot to write them):

1. When useing reflection can the plugins do whatever it wants?
2.Can i load plugins in their own domain?
3. Can i apply Cas to plugins?

Thx

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Csimbi
I post too much
Reputation: 98

Joined: 14 Jul 2007
Posts: 3399

PostPosted: Thu Sep 16, 2010 5:44 pm    Post subject: Re: sorry. i not clear Reply with quote

NINTENDO wrote:
My questions was (ye i forgot to write them)

A classic, LOL
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Sep 16, 2010 9:24 pm    Post subject: Re: sorry. i not clear Reply with quote

NINTENDO wrote:
Thx but my code worked too.

Let me make my question clearer Smile

My questions was (ye i forgot to write them):

1. When useing reflection can the plugins do whatever it wants?
2.Can i load plugins in their own domain?
3. Can i apply Cas to plugins?

Thx


1. Depends on the functions definitions. You can't reflect and call private members since you technically don't have access to them.

2. Yes. Take a look at this scripting engine, they load all scripts (C#/VB.NET) into their own app domain to run them:
http://www.west-wind.com/presentations/dynamicCode/DynamicCode.htm

3. Not sure what you mean by 'Cas'.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Sep 17, 2010 12:30 am    Post subject: Reply with quote

You should define an abstract base class that these plugins inherit from, and then check for the existence of this base class. It's quite a bit more stable when you do it this way (and has the advantage of providing a limited 'API' of sorts).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites