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
Test Subject
Original Poster
#1 Old 14th Sep 2022 at 4:58 AM
Default Instantiator class not being instantiated/run?
I'm trying to add some custom moodlets, based off of this template: :https://github.com/Cilyan/sims3-moodlet-template

So far I haven't been able to get the custom moodlets I'm trying to add to load.

As a starting point, I've added some test code into the OnWorldLoaded function that, as per my understanding, would just add the phone addict moodlet to everyone in the household, and then added OnWorldLoaded into World.sOnWorldLoadFinishedEventHandler. I'm not seeing the phone addict moodlet getting added either. I am using the nraas unprotected DLLs and changed the code in the template for the world load finished event handler as per https://www.nraas.net/community/chatterbox/topic2652 .

Just wondering if anyone has any input on what I'm doing wrong. I suspect I've got an XML file named incorrectly or otherwise set up wrong in my package file, and that the bootloader class is never getting instantiated in the first place

Tuning XML, named HamBadger.ExpandedWishMoodlets.Bootloader in the package file:

Code:
<?xml version="1.0" encoding="utf-8"?>
<base>
  <Current_Tuning>
    <kInstantiator value="True" />
  </Current_Tuning>
</base>



AssemblyInfo.cs:

Code:
using System.Reflection;
using System.Runtime.CompilerServices;
using Sims3.SimIFace;

// Information about this assembly is defined by the following attributes. 
// Change them to the values specific to your project.

[assembly: AssemblyTitle("HamBadger.ExpandedWishMoodlets")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("GPL")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: Tunable]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.*")]

// The following attributes are used to specify the signing key for the assembly, 
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]


Bootstrap.cs:

Code:
using Sims3.Gameplay.ActorSystems;
using Sims3.Gameplay.Actors;
using Sims3.Gameplay.Utilities;
using Sims3.SimIFace;
using Sims3.UI;
using System;
using Sims3.Gameplay.EventSystem;
using System.Reflection;

namespace HamBadger.ExpandedWishMoodlets
{
    internal class BuffBooter
    {
        public void LoadBuffData()
        {
            this.AddBuffs(null);
            UIManager.NewHotInstallStoreBuffData += new UIManager.NewHotInstallStoreBuffCallback(this.AddBuffs);
        }

        public void AddBuffs(ResourceKey[] resourceKeys)
        {
            try
            {
                ResourceKey key = new ResourceKey(ResourceUtils.HashString64("HamBadger.ExpandedWishMoodlets.Buffs"), 0x0333406C, 0x0);
                XmlDbData xmlDbData = XmlDbData.ReadData(key, false);
                if (xmlDbData != null)
                {
                    BuffManager.ParseBuffData(xmlDbData, true);
                }
            }
            catch
            {
            }
        }
    }

    public static class Bootloader
    {
        [Tunable]
        internal static bool kInstantiator = false;

        static Bootloader()
        {
            LoadSaveManager.ObjectGroupsPreLoad += OnPreLoad;
            World.sOnWorldLoadFinishedEventHandler += OnWorldLoaded;
        }

        private static void OnPreLoad()
        {
            new BuffBooter().LoadBuffData();
        }

        private static void OnWorldLoaded(object sender, System.EventArgs e)
        {
            // This is test code -- I just want to see if it actually adds an already existing moodlet.
            foreach (Sim sim in Sims3.Gameplay.Queries.GetObjects<Sim>())
            {
                if (sim != null && sim.IsInActiveHousehold)
                {
                    sim.BuffManager.AddElement(BuffNames.PhoneJunkie, Origin.None);
                }
            }
        }
    }
}
Attached files:
File Type: zip  ExpandedWishMoodlets.zip (7.5 KB, 4 downloads)
Advertisement
Field Researcher
#2 Old 15th Sep 2022 at 2:56 AM
Hello, so I managed to succesfully get a vanilla moodlet to appear via using the OnWordlLoadFinished event. To be specific I used the pumped moodlet. After that I went to check your code to see if you did anything wrong. And as far as my basic C# knowledge it does not look like you did anything wrong.

I then went to extract your DLL, so I can look at the code in ILspy, and I think I found your problem. I don't believe you built your solution and then imported the DLL into your S3SA tag in s3pe. Which is necessary in order for your package to have your scrip/code inside. Additionally, it looks like the option to import/Export a DLL is not an option for your S3SA tag in your package. I don't know why this might be, but I would suggest just remaking your S3SA by clicking resource, add, and then select type and find the S3SA tag.

After you succesfully remake your S3SA, quickly go back to Visual studios where your code is and on the top there should be a build option. Click it and then click build solution. That will make your DLL which you use to get your code into the package. Then Back in S3pe, right click on your S3SA and select import DLL. Then find your DLL file for your project. It should be in your visual studios project folder. After you import it into the S3SA save it and then test it ingame to see if the moodlet is now able to be added upon loading in.
Field Researcher
#3 Old 15th Sep 2022 at 3:02 AM
Here's a more detailed tutorial of what I am suggesting. Just skip down to check "The Final Code" and "Building The Package".

https://modthesims.info/wiki.php?ti...ripting_Modding
Test Subject
Original Poster
#4 Old 15th Sep 2022 at 12:34 PM Last edited by HamBadger : 15th Sep 2022 at 3:10 PM.
Looks like that did it. I was dragging the DLL into S3PE and not using the add resource option. Thanks!

Something else I noticed was that the template project was referencing the standard system, system.xml, and mscorlib DLLs and not the ones from the Sims 3 package files. No clue if that matters, but it was different from the other tutorial I saw on setting up a Sims 3 Visual Studio project, which did say to use the ones from the package files.
Back to top