Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Quick Reply
Search this Thread
Lab Assistant
Original Poster
#1 Old 3rd Nov 2010 at 4:11 PM Last edited by jtravers88 : 3rd Nov 2010 at 4:24 PM.
Default 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
Test Subject
#2 Old 3rd Nov 2010 at 5:08 PM
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.
Lab Assistant
Original Poster
#3 Old 3rd Nov 2010 at 5:34 PM
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.
Lab Assistant
Original Poster
#4 Old 3rd Nov 2010 at 5:41 PM
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.
1978 gallons of pancake batter
#5 Old 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.
Yes. Access modifiers are only getting checked during compile-time, not during run-time. If you check twallan's or my code, you'll see accesses of private members as well - in mods that are strictly non-core. After the latest patch, I didn't even bother to change only the access modifiers of members I actually access, but used Find/Replace to simply replace private and family with public everywhere in Sims3GameplaySystems and Sims3GameplayObjects. Would have taken hours otherwise. That only applies to the libraries I reference in VisualStudio, as I don't do core modding.

If gotcha is all you’ve got, then you’ve got nothing. - Paul Krugman
Test Subject
#6 Old 3rd Nov 2010 at 6:42 PM
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:

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
Lab Assistant
Original Poster
#7 Old 3rd Nov 2010 at 7:22 PM
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.
1978 gallons of pancake batter
#8 Old 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.
As I explicitedly stated, I don't include these dlls in my mods.

If gotcha is all you’ve got, then you’ve got nothing. - Paul Krugman
Lab Assistant
Original Poster
#9 Old 17th Sep 2011 at 4:16 AM
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.
1978 gallons of pancake batter
#10 Old 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.
Little wonder if you used Reflector to make the changes.

Quote:
So it's not just enforced at compile time.
Yes, it is.

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.
Refer to the core modding basics tutorial under my profile.

If gotcha is all you’ve got, then you’ve got nothing. - Paul Krugman
Field Researcher
#11 Old 17th Sep 2011 at 8:54 AM
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.
Lab Assistant
Original Poster
#12 Old 24th Sep 2011 at 1:34 AM
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.
Back to top