Author Topic: [WIP] C# (Edit)  (Read 725 times)

0 Members and 1 Guest are viewing this topic.

JAZZ 0R KILLER

  • Member
  • ***
  • Posts: 114
  • YT - Solo Crew
  • Awards Top contributors to the forum downloads.
    • View Profile
    • YouTube
    • Awards
  • Xbox: JAZZ 0R KILLER
[WIP] C# (Edit)
« on: April 02, 2018, 08:30:46 PM »
Big shout out to Justyn! He has helped me with almost all of this project that I am working on.

I am working on a project that adds a sound effect to the game when a button is pressed. I got all the way up to the point to where you add the references, and you're supposed to add all the .dll files from the Total Miner directory. For some reason it doesn't let me add all of the .dlls, I get an error. Can someone help me out? What am I doing wrong?

Spoiler for Hidden Content:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace Sound_Effects_Mod
{
    public class Class1
    {
        SoundEffect[] SoundEffects;
        ITMGame gameVar;
        public void Draw(ITMPlayer player, ITMPlayer virtualPlayer)
        {

        }

        public void Initialize(ITMPluginManager agr, string path)
        {

        }

        public void InitializeGame(ITMGame game)
        {
            this.gameVar = game;
            this.SoundEffects = new SoundEffect[1];
            this.SoundEffects[0] = this.gameVar.AudioManager.LoadSoundEffectFromStream(@"C:\Users\First.Last\Desktop\Sound_Effects\Sound_Effect.wav");

        }

        public void PlayerJoined(ITMPlayer player)
        {

        }

        public void PlayerLeft(ITMPlayer player)
        {

        }

        public void Update(ITMPlayer player)
        {
            if (InputManager.IsKeyReleasedNew(player.PlayerIndex, Keys.N))
            {
                int index = this.gameVar.Random.Next(1, 1);
                this.SoundEffects[index].Play();
            }
        }

        public void Update()
        {

        }
    }
}
« Last Edit: April 06, 2018, 10:25:03 AM by JAZZ 0R KILLER »
Look at you being all cool!

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6650
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: C# (Need help)
« Reply #1 on: April 03, 2018, 08:39:57 AM »
What error? Do you mean the yellow icon next to the reference?

It's probably better to just copy the dll's from total miner directly to your bin folder and reference the dll's from there, or create a sub folder in your project, named Libs or something, and copy the dll's into there and reference them from there.

JAZZ 0R KILLER

  • Member
  • ***
  • Posts: 114
  • YT - Solo Crew
  • Awards Top contributors to the forum downloads.
    • View Profile
    • YouTube
    • Awards
  • Xbox: JAZZ 0R KILLER
Re: C# (Need help)
« Reply #2 on: April 03, 2018, 01:28:25 PM »
Im getting errors like this: Severity   Code   Description   Project   File   Line   Suppression State
Error   CS0234   The type or namespace name 'Touch' does not exist in the namespace 'Microsoft.Xna.Framework.Input' (are you missing an assembly reference?)   Noise effect Mod   C:\Users\My.Name\Documents\My Games\TotalMinerBeta\Mods\Noise effect Mod\Noise effect Mod\Noise effect Mod\Class1.cs   10   Active
Look at you being all cool!

JAZZ 0R KILLER

  • Member
  • ***
  • Posts: 114
  • YT - Solo Crew
  • Awards Top contributors to the forum downloads.
    • View Profile
    • YouTube
    • Awards
  • Xbox: JAZZ 0R KILLER
Re: C# (Need help)
« Reply #3 on: April 03, 2018, 01:31:13 PM »
I've tried adding all the .dlls from Total Miner directory to the references, almost all work, but CSteamworks, DSETUP, dsetup32, and steam_api wont load into the references. Also, where can I get the Total Miner plugins? That might contribute greatly to my problem
Look at you being all cool!

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6650
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: C# (Need help)
« Reply #4 on: April 03, 2018, 06:20:04 PM »
You don't need to add steamworks, dsetup etc, you only need to add whichever StudioForge, Microsoft.Xna and System assemblies your code will actually reference. See some of the examples here: https://github.com/cmartin99/TotalMinerMods

JAZZ 0R KILLER

  • Member
  • ***
  • Posts: 114
  • YT - Solo Crew
  • Awards Top contributors to the forum downloads.
    • View Profile
    • YouTube
    • Awards
  • Xbox: JAZZ 0R KILLER
Re: C# (Need help)
« Reply #5 on: April 03, 2018, 06:29:06 PM »
How do I see the references on these projects?
Look at you being all cool!

JAZZ 0R KILLER

  • Member
  • ***
  • Posts: 114
  • YT - Solo Crew
  • Awards Top contributors to the forum downloads.
    • View Profile
    • YouTube
    • Awards
  • Xbox: JAZZ 0R KILLER
Re: C# (Need help)
« Reply #6 on: April 03, 2018, 07:13:32 PM »
It says it can't find ITMPlayer, ITMGame, "The name InputManager does not exist" and 14 other errors
Look at you being all cool!

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6650
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: C# (Need help)
« Reply #7 on: April 03, 2018, 07:26:18 PM »
How do I see the references on these projects?
Download the solution and look at the projects in Visual Studio.

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6650
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: C# (Need help)
« Reply #8 on: April 03, 2018, 07:26:56 PM »
It says it can't find ITMPlayer, ITMGame, "The name InputManager does not exist" and 14 other errors
You need 'using' statements at top of source file. See the projects I posted above.

JAZZ 0R KILLER

  • Member
  • ***
  • Posts: 114
  • YT - Solo Crew
  • Awards Top contributors to the forum downloads.
    • View Profile
    • YouTube
    • Awards
  • Xbox: JAZZ 0R KILLER
Re: C# (Need help)
« Reply #9 on: April 03, 2018, 07:48:19 PM »
Okay, I've looked at some things. My mod folder for the mod I am trying to create only has Class1.cs of the cs files. And I also don't have the .dll file
Look at you being all cool!

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6650
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: C# (Need help)
« Reply #10 on: April 03, 2018, 07:54:47 PM »
I'm going to create a Getting Started video for C# soon, probably later today. You might be best waiting for that.

JAZZ 0R KILLER

  • Member
  • ***
  • Posts: 114
  • YT - Solo Crew
  • Awards Top contributors to the forum downloads.
    • View Profile
    • YouTube
    • Awards
  • Xbox: JAZZ 0R KILLER
Re: C# (Need help)
« Reply #11 on: April 03, 2018, 07:55:23 PM »
Will do, I'll be looking for it
Look at you being all cool!

Rorthic

  • Jr. Member
  • **
  • Posts: 15
    • View Profile
    • Awards
Re: C# (Need help)
« Reply #12 on: April 03, 2018, 08:56:21 PM »
I typed this up a while ago as a reminder to myself on how to do a mod. I briefly read through it and I believe it is still correct.

Spoiler for Hidden Content:
1) Install XNA Game Studio in Visual Studio 2017 follow this tutorial: http://totalminerforums.net/index.php?topic=19324.0
2) Open Visual studio and create a new project for XNA Game Studio Windows Game Library(4.0) with your mod name for the name  ex: TM_ExampleMod.
3) In the Solution Explorer right click on References select add reference
4) Click Browse and navigate to your Total Miner steam Directory                             
  (C:\Program Files (x86)\Steam\steamapps\common\Total Miner)
5) Select all the .dll files and click add, or add 1 at a time, currently there are 7 in total: StudioForge.Engine.Core.dll, StudioForge.Engine.GUI.dll, StudioForge.Engine.Services.dll, StudioForge.Engine.Integration.dll, StudioForge.Engine.Game.dll, StudioForge.BlockWorld.dll, StudioForge.TotalMiner.API.dll
6) After adding them select the ones you need with check marks and click ok
7) Rename the default class1.cs file to the mod name TM_ExampleMod1.cs by right clicking on it and choosing rename.
8 ) Open the cs file for editing
9) At the top add
using StudioForge.TotalMiner.API;
using StudioForge.TotalMiner;
10) change the class name to match your mod name and make it extend ITMPlugin public class Class1 to
public class TM_ExampleMod1 : ITMPlugin
11)  Add the required interfaces to the class:                                                           
public void WorldSaved(int version){}
       public void PlayerJoined(ITMPlayer player){}
       public void PlayerLeft(ITMPlayer player){}
       public void Initialize(ITMPluginManager manager, string path){}
       public void InitializeGame(ITMGame game){}
       public bool HandleInput(ITMPlayer player){return false;}
       public void Update(ITMPlayer player){}
       public void Update(){}
       public void Draw(ITMPlayer player, ITMPlayer virtualPlayer){}
12)  In solution explorer right click on your mod name not the solution name and choose add new item
13)  find Code File C# highlight it and click add
14) Rename it to TMPluginProvider.cs  note: this is the required name
15)  open the file for editing with required code and implement required interfaces:             
using StudioForge.TotalMiner.API;

       namespace TM_ExampleMod
   {
       class TMPluginProvider : ITMPluginProvider
       {
            public ITMPlugin GetPlugin()
      {
         return new TM_ExampleMod1();
      }
           public ITMPluginBlocks GetPluginBlocks(){return null;}
           public ITMPluginArcade GetPluginArcade(){return null;}
          public ITMPluginGUI GetPluginGUI(){return null;}
       }
   }
note: namespace TM_ExampleMod is mod namespace name, return new TM_ExampleMod1() is constructor for mod name
16) Code your mod, build your solution, copy your modname.dll to the mod folder for TM in a folder of the mod name
   C:\Users\YourName\Documents\My Games\TotalMiner\Mods\ TM_ExampleMod1
17) Run Total Miner and test your mod.

Optional Settings

1) Right click on mod project file and choose properties
2) under XNA Game Studio select Use HiDef to access the complete API
3) go to Build Events and for Post-Build event command line: add     
   xcopy /Y /E /I "$(TargetPath)" "$(ProjectDir)\Install\"   
   xcopy /Y /E /I "$(ProjectDir)\Content" "$(ProjectDir)\Install"     
   xcopy /Y /E /I "$(ProjectDir)\Install" "$(HOMEDRIVE)$    (HOMEPATH)\Documents\MyGames\TotalMiner\Mods\$(ProjectName)"
   note: this copies the mod files to the mod directory automatically. make sure the path is correct.

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6650
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: C# (Need help)
« Reply #13 on: April 03, 2018, 11:29:18 PM »
Heres the first video

I'll post a 2nd video for Arcade Block Games later.

Craig

  • Developer
  • Extreme Member
  • ******
  • Posts: 6650
  • Dig Deep
  • Awards Developer 5 years on site 4 years on site 3 years on site 2 years on site Was in the top 10 of the forum stats page as of 4/12/15 Members who have unlocked the robotic avatar 1 year on site Day 1 w/25+ posts (4/12/13)
    • View Profile
    • Twitter
    • Awards
  • Steam: tota1miner
Re: C# (Need help)
« Reply #14 on: April 04, 2018, 03:15:58 AM »
Arcade block