Framework mod for making new casino games in "Game With Your Friends".
Note: The Fishing Game mod: https://github.com/Syd4r/FishingGame is a good reference for how to build a game using this framework.
To build a compatible mod you will need to set up your file structure as such:
As you can see there are 3 main things you need for a game to work properly:
In the next sections, I will go through how to set up each of these correcly.
To build a compatible unity asset bundle you must first set up a good Unity scene. I highly recommend using AssetRipper on the Gamble With Your Friends_data folder in steamapps\common\Gamble With Your Friends. Then, in AssetRipper, export the ripped files to a Unity project. In Unity Hub make sure to download Unity version 6000.3.6f1 and open the Unity project with this version. This will give you all of the materials, meshes, and prefabs that the game has. The major issue is that all of the scripts get disconnected, so you should delete all C# scripts in the folder. Then find a prefab that already exists in the game like Crash CasinoGame. You can edit this prefab and use it as a base to build what you want. Make sure to remove all dangling components that use scripts, as these will throw errors. Also, make sure to add the TextMeshPro package so that you can add TextMeshPro components to any text. To get the game's font, look for Assets/Font/Dangrek-Regular.ttf and use it to build Dangrek-Regular SDF.asset which you should place in Assets/Resources/fonts & materials/ then just select Dangrek-Regular in TextMeshPro.
If you look at a prefab for a preexisting casino game it will look something like this:
If you set up your Unity scene to have these things and set up asset bundling, after you bundle just rename the bundle to your game name and drag it into your game folder.
Download Visual Studio and setup a new project using "Class Library (.Net Framework)".
Make a new C# script. In this file you will only need to add a new public class extending gamebase. For example:
public class ExampleGameName : GameBase {}
I highly recommend using dnSpy to look at the classes for the base casino games or looking at https://github.com/Syd4r/FishingGame to understand how to do things.
Here are a few helpful things you should know:
void Start() {} This will run when the object gets instantiated.
public override bool Weaved() { return true; } We are semi-manually weaving the code so we dont need weaver to do anything with this file.
protected override void StartGame() Your play button will run this function when it gets clicked.
void Update() {} This will run every frame
You must have this block of code below somewhere in your C# script, replace your name and your mod name with the correct values.
namespace YourModNameeMod
{
[BepInPlugin("com.YourName.YourModName", "YourModName", "1.0.0")]
[BepInDependency("com.moregames.base", BepInDependency.DependencyFlags.HardDependency)]
public class YourModNamePlugin : BaseUnityPlugin
{
private void Awake()
{
Logger.LogInfo("YourModName Assembly loaded by BepInEx! Waiting for Base Loader...");
}
}
}
NETWORK STUFF IMPORTANT!!!
If you want a visual thing to occur in your game it must get synced across the network, thus it is not enough if your function just updates the visuals for the client, here is how to correctly set up networking:
public void BroadcastTestMethod(string text) {
if (!NetworkServer.active) return;
string methodSignature = "System.Void TestMod.TestGameName::UserRpcTestMethod(System.String)";
int rpcHash = methodSignature.GetStableHashCode();
NetworkWriterPooled writer = NetworkWriterPool.Get();
writer.WriteString(text);
this.SendRPCInternal(methodSignature, rpcHash, writer, 0, true);
NetworkWriterPool.Return(writer);
}
public void UserRpcTestMethod(string networkText) {
if (!NetworkClient.active) return;
--DO THE VISUAL THING--
}
If your function is one that runs when you push a button it must be set up like this:
[Server]
public void TestButtonClicked(PlayerInteract interact = null) {
if (!NetworkServer.active) return;
-- DO SOMETHING --
}
When you want to payout just use the this.Payout function:
this.Payout((double)multiplier, ChangeType.GameResult, null, -1L);
This C# script will be doing all of the logic of your game, if you have any issues just message me on discord: syd4r
The game manifest is by far the easiest part of this whole setup. Here is an example game manifest:
{
"name": "TestGameName", //This should match your folder name and all of your file names
"baseMinBet": 20, //Min bet on keypad for first floor
"baseMaxBet": 360, //Max bet on keypad for first floor (this will be off by 10-20 for some reason)
"directions": [ //definse how multiple machines will spawn in a cluster
"North",
"South",
],
"floorWeights": { //Weight of being picked on each floor, these are the values to get the machine to spawn in the same as the others
"1": 0.167,
"2": 0.111,
"3": 0.091,
"4": 0.063
},
"buttons": [ //Define which function to call when clicking the button with this name in Unity
{
"objectName": "PlayButton", //Play button must call TryStartGame
"functionName": "TryStartGame"
},
{
"objectName": "TestButton", //Other buttons can call whatever
"functionName": "TestFunction"
},
],
"fields": [ //If you want to be able to access things from your asset bundle in your C# script, add them here
{
"fieldName": "testField", //field name in C# script
"source": "child", //it will almost always be child
"targetName": "Test_Object" //unity object name
},
{
"fieldName": "testPrefabs",
"source": "child",
"targetNames": [ //you can also make an array of unity objects
"test_1", "test_2", "test_3", "test_4",
"test_5", "test_6", "test_7", "test_8",
"test_9", "test_10", "test_11", "test_12"
]
}
]
}
Make sure to set up the gamemanifest.json like this and include it in the game folder.
If you follow these steps, hopefully you should be able to make your own custom game. If you run into any issues feel free to reach out. I would highly recommend checking out how I made my custom game at https://github.com/Syd4r/FishingGame