[SPOILER ]Can I see your cursed stardew images please

SomeoneEls

Sodbuster
And if this still technically isnt quite stardew valley it is still part of the game so...
This code. I hate it.

C#:
private void randomWarpEvent(object obj)
{
    while(Game1.player.IsBusyDoingSomething())
    {

    }
    try
    {
        int loc = new Random().Next(0, 32);

        //finds a valid location
        while (loc == 15 || (loc >= 17 && loc <= 21) || (loc >= 25 && loc <= 30))
        {
            loc = new Random().Next(0, 32);
        }

        GameLocation locat = Game1.locations.ElementAt(loc);
        Vector2 vect;
        GameLocation playerLocat = Game1.player.currentLocation;
        Vector2 playerVect = Game1.player.Tile;
 
        try
        {
            
            //Looks at the diagonal left half of the map for an empty tile.
            for (int y = 1; true; y++)
            {
                for (int x = 1; x<y; x++)
                {
                    Vector2 buf = new Vector2(x, y);
                    if (!locat.IsTileBlockedBy(buf))
                    {
                        vect = buf;

                        
                        int r = new Random().Next(0, 64);
                        if (r==3)
                        {
                            // I ****ing hate using goto here as goto sucks but its better than trying to create a complex break system that works with vector2 buf, as buf cannot be null.
                            goto randomWarpEvent_outOfLoop;
                        }
                        
                    }
                }
            }

        }
        catch (Exception e)
        {
            //keep doing it until it works, since using goto causes issues. This is pretty cursed though. I'm sorry for my crimes.
            
            if (GC.GetTotalMemory(false)> 1073741824)
            {
                //This doesnt really need to be here, but just in case you are SUPER unlucky and this loop goes on for far too long, no crash will happen.
                // In reality, if this executes there is something very wrong. (ie, there is more than a GB of memory that is being used?!?!)
                Console.WriteLine("Chaosaddon: Random warp failed due to lack of memory (OVER 1 GB OF MEMORY USED)");
                return;
            }
            randomWarpEvent(obj);
            return;
        }

    randomWarpEvent_outOfLoop:
        Game1.warpFarmer(locat.Name, (int)vect.X, (int)vect.Y, false);
        Thread.Sleep(15000);

        //if the integer cast made the current tile blocked
        if (playerLocat.IsTileBlockedBy(new Vector2((int)playerVect.X, (int)playerVect.Y)))
        {

            Game1.warpHome();
        }
        else
        {
            Game1.warpFarmer(playerLocat.Name, (int)playerVect.X, (int)playerVect.Y, false);
        }




    }
    catch(Exception e)
    {

    }
}
 

zack123

Farmhand
And if this still technically isnt quite stardew valley it is still part of the game so...
This code. I hate it.

C#:
private void randomWarpEvent(object obj)
{
    while(Game1.player.IsBusyDoingSomething())
    {

    }
    try
    {
        int loc = new Random().Next(0, 32);

        //finds a valid location
        while (loc == 15 || (loc >= 17 && loc <= 21) || (loc >= 25 && loc <= 30))
        {
            loc = new Random().Next(0, 32);
        }

        GameLocation locat = Game1.locations.ElementAt(loc);
        Vector2 vect;
        GameLocation playerLocat = Game1.player.currentLocation;
        Vector2 playerVect = Game1.player.Tile;

        try
        {
           
            //Looks at the diagonal left half of the map for an empty tile.
            for (int y = 1; true; y++)
            {
                for (int x = 1; x<y; x++)
                {
                    Vector2 buf = new Vector2(x, y);
                    if (!locat.IsTileBlockedBy(buf))
                    {
                        vect = buf;

                       
                        int r = new Random().Next(0, 64);
                        if (r==3)
                        {
                            // I ****ing hate using goto here as goto sucks but its better than trying to create a complex break system that works with vector2 buf, as buf cannot be null.
                            goto randomWarpEvent_outOfLoop;
                        }
                       
                    }
                }
            }

        }
        catch (Exception e)
        {
            //keep doing it until it works, since using goto causes issues. This is pretty cursed though. I'm sorry for my crimes.
           
            if (GC.GetTotalMemory(false)> 1073741824)
            {
                //This doesnt really need to be here, but just in case you are SUPER unlucky and this loop goes on for far too long, no crash will happen.
                // In reality, if this executes there is something very wrong. (ie, there is more than a GB of memory that is being used?!?!)
                Console.WriteLine("Chaosaddon: Random warp failed due to lack of memory (OVER 1 GB OF MEMORY USED)");
                return;
            }
            randomWarpEvent(obj);
            return;
        }

    randomWarpEvent_outOfLoop:
        Game1.warpFarmer(locat.Name, (int)vect.X, (int)vect.Y, false);
        Thread.Sleep(15000);

        //if the integer cast made the current tile blocked
        if (playerLocat.IsTileBlockedBy(new Vector2((int)playerVect.X, (int)playerVect.Y)))
        {

            Game1.warpHome();
        }
        else
        {
            Game1.warpFarmer(playerLocat.Name, (int)playerVect.X, (int)playerVect.Y, false);
        }




    }
    catch(Exception e)
    {

    }
}
What does this code do??????
Curious
 

DOBITEUS

Sodbuster
And if this still technically isnt quite stardew valley it is still part of the game so...
This code. I hate it.

C#:
private void randomWarpEvent(object obj)
{
    while(Game1.player.IsBusyDoingSomething())
    {

    }
    try
    {
        int loc = new Random().Next(0, 32);

        //finds a valid location
        while (loc == 15 || (loc >= 17 && loc <= 21) || (loc >= 25 && loc <= 30))
        {
            loc = new Random().Next(0, 32);
        }

        GameLocation locat = Game1.locations.ElementAt(loc);
        Vector2 vect;
        GameLocation playerLocat = Game1.player.currentLocation;
        Vector2 playerVect = Game1.player.Tile;

        try
        {
           
            //Looks at the diagonal left half of the map for an empty tile.
            for (int y = 1; true; y++)
            {
                for (int x = 1; x<y; x++)
                {
                    Vector2 buf = new Vector2(x, y);
                    if (!locat.IsTileBlockedBy(buf))
                    {
                        vect = buf;

                       
                        int r = new Random().Next(0, 64);
                        if (r==3)
                        {
                            // I ****ing hate using goto here as goto sucks but its better than trying to create a complex break system that works with vector2 buf, as buf cannot be null.
                            goto randomWarpEvent_outOfLoop;
                        }
                       
                    }
                }
            }

        }
        catch (Exception e)
        {
            //keep doing it until it works, since using goto causes issues. This is pretty cursed though. I'm sorry for my crimes.
           
            if (GC.GetTotalMemory(false)> 1073741824)
            {
                //This doesnt really need to be here, but just in case you are SUPER unlucky and this loop goes on for far too long, no crash will happen.
                // In reality, if this executes there is something very wrong. (ie, there is more than a GB of memory that is being used?!?!)
                Console.WriteLine("Chaosaddon: Random warp failed due to lack of memory (OVER 1 GB OF MEMORY USED)");
                return;
            }
            randomWarpEvent(obj);
            return;
        }

    randomWarpEvent_outOfLoop:
        Game1.warpFarmer(locat.Name, (int)vect.X, (int)vect.Y, false);
        Thread.Sleep(15000);

        //if the integer cast made the current tile blocked
        if (playerLocat.IsTileBlockedBy(new Vector2((int)playerVect.X, (int)playerVect.Y)))
        {

            Game1.warpHome();
        }
        else
        {
            Game1.warpFarmer(playerLocat.Name, (int)playerVect.X, (int)playerVect.Y, false);
        }




    }
    catch(Exception e)
    {

    }
}
What's the purpose of having that first while empty? 🤔 In my poor logic, I get that does nothing until the player "it's free" and then enters the try-catch statement, but it couldn't be replaced with a negative conditional or something? Can an AI find an alternative to not use the goto? 😅
 
And if this still technically isnt quite stardew valley it is still part of the game so...
This code. I hate it.

C#:
private void randomWarpEvent(object obj)
{
    while(Game1.player.IsBusyDoingSomething())
    {

    }
    try
    {
        int loc = new Random().Next(0, 32);

        //finds a valid location
        while (loc == 15 || (loc >= 17 && loc <= 21) || (loc >= 25 && loc <= 30))
        {
            loc = new Random().Next(0, 32);
        }

        GameLocation locat = Game1.locations.ElementAt(loc);
        Vector2 vect;
        GameLocation playerLocat = Game1.player.currentLocation;
        Vector2 playerVect = Game1.player.Tile;

        try
        {
           
            //Looks at the diagonal left half of the map for an empty tile.
            for (int y = 1; true; y++)
            {
                for (int x = 1; x<y; x++)
                {
                    Vector2 buf = new Vector2(x, y);
                    if (!locat.IsTileBlockedBy(buf))
                    {
                        vect = buf;

                       
                        int r = new Random().Next(0, 64);
                        if (r==3)
                        {
                            // I ****ing hate using goto here as goto sucks but its better than trying to create a complex break system that works with vector2 buf, as buf cannot be null.
                            goto randomWarpEvent_outOfLoop;
                        }
                       
                    }
                }
            }

        }
        catch (Exception e)
        {
            //keep doing it until it works, since using goto causes issues. This is pretty cursed though. I'm sorry for my crimes.
           
            if (GC.GetTotalMemory(false)> 1073741824)
            {
                //This doesnt really need to be here, but just in case you are SUPER unlucky and this loop goes on for far too long, no crash will happen.
                // In reality, if this executes there is something very wrong. (ie, there is more than a GB of memory that is being used?!?!)
                Console.WriteLine("Chaosaddon: Random warp failed due to lack of memory (OVER 1 GB OF MEMORY USED)");
                return;
            }
            randomWarpEvent(obj);
            return;
        }

    randomWarpEvent_outOfLoop:
        Game1.warpFarmer(locat.Name, (int)vect.X, (int)vect.Y, false);
        Thread.Sleep(15000);

        //if the integer cast made the current tile blocked
        if (playerLocat.IsTileBlockedBy(new Vector2((int)playerVect.X, (int)playerVect.Y)))
        {

            Game1.warpHome();
        }
        else
        {
            Game1.warpFarmer(playerLocat.Name, (int)playerVect.X, (int)playerVect.Y, false);
        }




    }
    catch(Exception e)
    {

    }
}
what does this do??? I don’t speak C# 😭
 

SomeoneEls

Sodbuster
And if this still technically isnt quite stardew valley it is still part of the game so...
This code. I hate it.

C#:
private void randomWarpEvent(object obj)
{
    while(Game1.player.IsBusyDoingSomething())
    {

    }
    try
    {
        int loc = new Random().Next(0, 32);

        //finds a valid location
        while (loc == 15 || (loc >= 17 && loc <= 21) || (loc >= 25 && loc <= 30))
        {
            loc = new Random().Next(0, 32);
        }

        GameLocation locat = Game1.locations.ElementAt(loc);
        Vector2 vect;
        GameLocation playerLocat = Game1.player.currentLocation;
        Vector2 playerVect = Game1.player.Tile;

        try
        {
         
            //Looks at the diagonal left half of the map for an empty tile.
            for (int y = 1; true; y++)
            {
                for (int x = 1; x<y; x++)
                {
                    Vector2 buf = new Vector2(x, y);
                    if (!locat.IsTileBlockedBy(buf))
                    {
                        vect = buf;

                     
                        int r = new Random().Next(0, 64);
                        if (r==3)
                        {
                            // I ****ing hate using goto here as goto sucks but its better than trying to create a complex break system that works with vector2 buf, as buf cannot be null.
                            goto randomWarpEvent_outOfLoop;
                        }
                     
                    }
                }
            }

        }
        catch (Exception e)
        {
            //keep doing it until it works, since using goto causes issues. This is pretty cursed though. I'm sorry for my crimes.
         
            if (GC.GetTotalMemory(false)> 1073741824)
            {
                //This doesnt really need to be here, but just in case you are SUPER unlucky and this loop goes on for far too long, no crash will happen.
                // In reality, if this executes there is something very wrong. (ie, there is more than a GB of memory that is being used?!?!)
                Console.WriteLine("Chaosaddon: Random warp failed due to lack of memory (OVER 1 GB OF MEMORY USED)");
                return;
            }
            randomWarpEvent(obj);
            return;
        }

    randomWarpEvent_outOfLoop:
        Game1.warpFarmer(locat.Name, (int)vect.X, (int)vect.Y, false);
        Thread.Sleep(15000);

        //if the integer cast made the current tile blocked
        if (playerLocat.IsTileBlockedBy(new Vector2((int)playerVect.X, (int)playerVect.Y)))
        {

            Game1.warpHome();
        }
        else
        {
            Game1.warpFarmer(playerLocat.Name, (int)playerVect.X, (int)playerVect.Y, false);
        }




    }
    catch(Exception e)
    {

    }
}
So, basically, this code warps you somewhere random as part of an event, then warps you back.

1. Waits untill the player is doing nothing (like not in a dialouge box or smthn)
2. Picks a random location.
3. Looks at the left diagonal half of the map for an empty tile, then does a random check if that tile will be used. If not, keep going. (this makes it so you warp at a random place at the map)
4. Catch statement. If the game tried to acess an invalid tile (a tile outside of the map), this runs the whole cycle over again.
5. Warp the farmer. Wait like 3 mins or smthn
6. Go back to the tile the farmer was at before. If its blocked, (integer casting bollocks) just warp home.

This works completely fine unless you have 1 GB of memory being used in the garbage collector. If this is true, it exits early and gives an exception message.
This is because of all the recursive calls. It basically loads the GC with a.. sizable amount of data if you are unlucky. It's very rare that you would have a stack overflow issue with this but just to make sure you arent like.. running 16 mods all with memory leakage issues (which is crazy) this stops. Honestly this last part is just me overengineering this.
 
Last edited:

SomeoneEls

Sodbuster
What's the purpose of having that first while empty? 🤔 In my poor logic, I get that does nothing until the player "it's free" and then enters the try-catch statement, but it couldn't be replaced with a negative conditional or something? Can an AI find an alternative to not use the goto? 😅
1.
This whole thing has multithreading so the game is basically running while this is running. Using an if statement that returns would make it so that you would have to call the function constantly, and then have a break statment when the thing is over.
2.
uhhh maybe but well...
The problem is that you CAN do this without a goto statement, but in order to do so you would have to add like, an if statment to every single scope with a flag. That would look way worse than it is currently. Here is a simpliler example.

C#:
void doRomance(int seed)
{
    int x = 2;
    bool can = false;
    bool noCanidates = true;


    foreach (var data in Game1.characterData)
    {
        Netcode.NetBool t = new Netcode.NetBool(true);
        Netcode.NetBool f = new Netcode.NetBool(false);
        NPC n = Game1.getCharacterFromName(data.Key);
        if (n == null)
        {
            continue; //if that charcter doesnt exist
        }
        foreach (var data2 in data.Value.FriendsAndFamily) //Remove any married ppl from the pool
        {
         
            if (data2.Value == "[LocalizedText Strings\\Characters:Relative_Husband]" || data2.Value == "[LocalizedText Strings\\Characters:Relative_Wife]")
            {
                can = false;
                Assembly.GetAssembly(typeof(NPC))
                     .GetType("StardewValley.NPC")
                    .GetField("datable")
                     .SetValue(n, f);
                goto NPCoverride; //either its a goto or ANOTHER flag. It just reads better for me using goto, and the label is pretty clear on what it does.
            }
        }
     
        if ((seed % x > x / 2) && (data.Value.Age == NpcAge.Adult)) //Adults only!                                                                            //Seed mod x must be greater than the middle of all the possible values.                                                      //(not quite this in retrospect but it works)
        {
            //Seed mod x must be greater than all the possible values.
            //(not quite this in retrospect but it works)
            can = true;
            noCanidates = false;
            Assembly.GetAssembly(typeof(NPC))
            .GetType("StardewValley.NPC")
           .GetField("datable")
            .SetValue(n, t);

        }
        else
        {

            can = false;
            Assembly.GetAssembly(typeof(NPC))
                 .GetType("StardewValley.NPC")
                .GetField("datable")
                 .SetValue(n, f);
        }

    NPCoverride:
     
        data.Value.CanBeRomanced = can;

        canRomance.TryAdd(data.Key, can);
        x++;
     
    }


    if(noCanidates)
    {
        doRomance(++seed);
    }


}
This, without the goto, can be written as

C#:
void doRomance(int seed)
{
    int x = 2;
    bool can = false;
    bool noCanidates = true;
    bool newflag = true;

    foreach (var data in Game1.characterData)
    {
        Netcode.NetBool t = new Netcode.NetBool(true);
        Netcode.NetBool f = new Netcode.NetBool(false);
        NPC n = Game1.getCharacterFromName(data.Key);
        if (n == null)
        {
            continue; //if that charcter doesnt exist
        }
        foreach (var data2 in data.Value.FriendsAndFamily) //Remove any married ppl from the pool
        {
         
            if (data2.Value == "[LocalizedText Strings\\Characters:Relative_Husband]" || data2.Value == "[LocalizedText Strings\\Characters:Relative_Wife]")
            {
                can = false;
                Assembly.GetAssembly(typeof(NPC))
                     .GetType("StardewValley.NPC")
                    .GetField("datable")
                     .SetValue(n, f);
                //goto NPCoverride; //either its a goto or ANOTHER flag. It just reads better for me using goto, and the label is pretty clear on what it does.
                newflag = false;
            }
        }
     
    new flag here -->    if ((seed % x > x / 2) && (data.Value.Age == NpcAge.Adult) && newflag) //Adults only!                                                                            //Seed mod x must be greater than the middle of all the possible values.                                                      //(not quite this in retrospect but it works)
        {
            //Seed mod x must be greater than all the possible values.
            //(not quite this in retrospect but it works)
            can = true;
            noCanidates = false;
            Assembly.GetAssembly(typeof(NPC))
            .GetType("StardewValley.NPC")
           .GetField("datable")
            .SetValue(n, t);

        }
    new flag here too -->    else if (newflag)
        {

            can = false;
            Assembly.GetAssembly(typeof(NPC))
                 .GetType("StardewValley.NPC")
                .GetField("datable")
                 .SetValue(n, f);
        }

    //NPCoverride:
     
        data.Value.CanBeRomanced = can;

        canRomance.TryAdd(data.Key, can);
        x++;
     
    }


    if(noCanidates)
    {
        doRomance(++seed);
    }


}
Its a bit less readable now, but imagine doing that for every single scope. Nightmares.
(Note that you would also do a lot of juggling with trying to get vect out)
 
Last edited:
Top