- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Calling private methods etc..
- Site Map >
- Modding and Creation >
- Sims 3 Creation >
- Modding Discussion >
- Calling private methods etc..
Replies: 11 (Who?), Viewed: 4555 times.
#1
3rd Nov 2010 at 4:11 PM
Last edited by jtravers88 : 3rd Nov 2010 at 4:24 PM.
Posts: 159
Thanks: 17 in 1 Posts
Calling private methods etc..
I've been reviewing the code for the awesome.dll. I've noticed a number of calls to 'private' functions within the gameplay.systems dll.When I try accessing a private function in my own dll, I get a 'does not contain a definition for'.
Short of setting those fncs to public, how are these private members accessed? Is it a C# Studio setting I'm missing. I'm using the 3.5 platform.
For instance, MartialArts.GetScoreForMartialArtist. This is a privately declared fnc. I can't compile if I try calling it.
Any help?
Thanks.
Advertisement
#2
3rd Nov 2010 at 5:08 PM
Posts: 32
Thanks: 911 in 9 Posts
first: you shouldn't use 3.5, use 2.0, the libs used in the game don't support 3.5 features so if you do use any new features, they won't work.
as for accessing a private function, I haven't looked myself but I envision a few ways of achieving this:
1) patch the DLL you're referencing so that the function becomes public - I imagine this would work and (probably) wouldn't break when used with the real DLL.
2) use System.Reflection (less abusive) although I'm not entirely sure what level of Reflection is supported by TS3
what I can say is that canonically, you CANNOT access private members, that's the whole point of declaring them private.
as for accessing a private function, I haven't looked myself but I envision a few ways of achieving this:
1) patch the DLL you're referencing so that the function becomes public - I imagine this would work and (probably) wouldn't break when used with the real DLL.
2) use System.Reflection (less abusive) although I'm not entirely sure what level of Reflection is supported by TS3
what I can say is that canonically, you CANNOT access private members, that's the whole point of declaring them private.
#3
3rd Nov 2010 at 5:34 PM
Posts: 159
Thanks: 17 in 1 Posts
I was using 2.0, for the reason you state, but read on the internet that using 3.5 uses a System.Linq library to enable calling private fncs, or allowing extension of methods. But that didn't seem to do anything. I just left it.
When you say, patch the dll I'm referencing, I'm patching it anyway for core changes required for my desired functionality. So the dll is changed. I'm wondering if I set a function to public long enough to compile my dll, then changed it back to private, if my reference to that function would work. I can test it. Or I can leave it public. The game doesn't complain. I just didn't want to make a habit of doing this. But for a constant, Reflector states it can't interpret them. So they stay private.
I could override the entire class and make the constants private I guess.
What is puzzling is that the Awesome mod is referencing alot of private class members, functions and constants, but the core dll included with the Awesome mod does not appear to have those functions set to public.
And if you say I 'canonically' can not access private members, then it wouldn't make sense to change a member to public long enough to compile my dll.
I would need a clarification on using System.Reflection. I have a using statement on System itself in my dll.
When you say, patch the dll I'm referencing, I'm patching it anyway for core changes required for my desired functionality. So the dll is changed. I'm wondering if I set a function to public long enough to compile my dll, then changed it back to private, if my reference to that function would work. I can test it. Or I can leave it public. The game doesn't complain. I just didn't want to make a habit of doing this. But for a constant, Reflector states it can't interpret them. So they stay private.
I could override the entire class and make the constants private I guess.
What is puzzling is that the Awesome mod is referencing alot of private class members, functions and constants, but the core dll included with the Awesome mod does not appear to have those functions set to public.
And if you say I 'canonically' can not access private members, then it wouldn't make sense to change a member to public long enough to compile my dll.
I would need a clarification on using System.Reflection. I have a using statement on System itself in my dll.
#4
3rd Nov 2010 at 5:41 PM
Posts: 159
Thanks: 17 in 1 Posts
Mr. Awesome himself has told me he accesses private members thru msil, not a c# compiler.
I in fact was wondering in the car this morning if I were to make those calls from Reflector, instead of the C# Studio, if I would get away with it.
So I'll try that, although it means I would never get my dll to compile in C# Studio ever again once I do that, without commenting out those lines.
I in fact was wondering in the car this morning if I were to make those calls from Reflector, instead of the C# Studio, if I would get away with it.
So I'll try that, although it means I would never get my dll to compile in C# Studio ever again once I do that, without commenting out those lines.
#5
3rd Nov 2010 at 5:46 PM
Quote: Originally posted by jtravers88
So the dll is changed. I'm wondering if I set a function to public long enough to compile my dll, then changed it back to private, if my reference to that function would work. |
If gotcha is all you’ve got, then you’ve got nothing. - Paul Krugman
#6
3rd Nov 2010 at 6:42 PM
Posts: 32
Thanks: 911 in 9 Posts
I don't have time to try this right now, but please give this a shot and let me know how it goes.
Say you wanted to use MartialArts.GetScoreForMartialArtist yeah? OK... give this code a try:
If you stick that above your code and namespace, it will allow you to call the function... whether it will actually work or not however will be down to testing
Say you wanted to use MartialArts.GetScoreForMartialArtist yeah? OK... give this code a try:
Code:
namespace Sims3.Gameplay.Skills { public partial class MartialArts { public static extern float GetScoreForMartialArtist(Sim actor, MartialArts martialArtsSkill); } }
If you stick that above your code and namespace, it will allow you to call the function... whether it will actually work or not however will be down to testing
#7
3rd Nov 2010 at 7:22 PM
Posts: 159
Thanks: 17 in 1 Posts
Buzzler I'm not sure I'm following you. If you change everything in those two dlls to public, if you include those in your mods then your making a core mod.
Olipro: I'll give that a shot simply because it looks interesting. However, Reflexil 1.1 allows changing constants to public as well as classes. I was using Reflexil 1.0.
So I think I'll go with changing members to public as long as Sims 3 doesn't throw up on it. I really don't relish the idea of using msil now that I'm used to Reflector and C# Studio.
Thanks everybody.
Olipro: I'll give that a shot simply because it looks interesting. However, Reflexil 1.1 allows changing constants to public as well as classes. I was using Reflexil 1.0.
So I think I'll go with changing members to public as long as Sims 3 doesn't throw up on it. I really don't relish the idea of using msil now that I'm used to Reflector and C# Studio.
Thanks everybody.
#8
3rd Nov 2010 at 7:41 PM
Quote: Originally posted by jtravers88
Buzzler I'm not sure I'm following you. If you change everything in those two dlls to public, if you include those in your mods then your making a core mod. |
If gotcha is all you’ve got, then you’ve got nothing. - Paul Krugman
#9
17th Sep 2011 at 4:16 AM
Posts: 159
Thanks: 17 in 1 Posts
Quote: Originally posted by Buzzler
As I explicitedly stated, I don't include these dlls in my mods. |
If I change visibility of classes, variables etc.. in gameplaysystem and gameplayobjects to public just long enough to compile my dll, and then let my dll reference the original gameplaysystem and gameplayobjects, the game crashes. So it's not just enforced at compile time.
Twallan states he makes the changes using ildasm/ilasm but uses the original dlls in the game. I still don't understand how this is accomplished. I'm trying ilasm now instead of reflector. I'll see how it goes.
#10
17th Sep 2011 at 8:42 AM
Quote: Originally posted by jtravers88
If I change visibility of classes, variables etc.. in gameplaysystem and gameplayobjects to public just long enough to compile my dll, and then let my dll reference the original gameplaysystem and gameplayobjects, the game crashes. |
Quote:
So it's not just enforced at compile time. |
Quote:
Twallan states he makes the changes using ildasm/ilasm but uses the original dlls in the game. I still don't understand how this is accomplished. |
If gotcha is all you’ve got, then you’ve got nothing. - Paul Krugman
#11
17th Sep 2011 at 8:54 AM
Posts: 223
Thanks: 9243 in 68 Posts
From my understanding, The Sims 3 uses the Mono framework and not really .Net, and it allows accessing private methods and variables at runtime.
In a normal .net app you would get an error at runtime.
I've used this before by changing the ildasm/ilasm of the game dll just so I could compile it in Visual Studio, but using Reflection should probably work also.
In a normal .net app you would get an error at runtime.
I've used this before by changing the ildasm/ilasm of the game dll just so I could compile it in Visual Studio, but using Reflection should probably work also.
#12
24th Sep 2011 at 1:34 AM
Posts: 159
Thanks: 17 in 1 Posts
Ok. If changes are made using Reflector/Reflexil to the core dlls, and then saved, those dlls can be used, yielding 'a core mod'. Any type of change, visibility or actual logic changes. You can compile your personal dll against those changed dlls and everything works fine ingame, as long as you use your changed core dlls.
But if using the original gamesystems and gameobjects dlls are desired, to avoid a core mod, then ildasm / ilasm must be used to make visibility changes for compiling your personal dll.
At least this is what works for me.
Also, Reflector is not so good at interpreting complicated generic typing. Use ILSpy for this.
But if using the original gamesystems and gameobjects dlls are desired, to avoid a core mod, then ildasm / ilasm must be used to make visibility changes for compiling your personal dll.
At least this is what works for me.
Also, Reflector is not so good at interpreting complicated generic typing. Use ILSpy for this.
Who Posted
|