Official Fulqrum Publishing forum

Official Fulqrum Publishing forum (http://forum.fulqrumpublishing.com/index.php)
-   FMB, Mission & Campaign builder Discussions (http://forum.fulqrumpublishing.com/forumdisplay.php?f=203)
-   -   How add user dll (http://forum.fulqrumpublishing.com/showthread.php?t=32284)

podvoxx 05-21-2012 11:10 AM

How add user dll
 
I need to transfer the same parts of the code, which often use in dll-file in the game. For example the code localization(to send messages) and use of global variables in the hostmission and submission scripts. One file will be used in different scripts.

For example code of my dll-file:
Code:

using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using maddox.game;
using maddox.game.world;
using maddox.GP;
using part;

namespace locfiledll
{
    public class localization : AMission
    {
     
        public static int locText(int number1, int number2)
        {
            int result = number1 + number2;
            return result;
        }
    }
}

My mission script:
Code:

//$reference "P11_folder\P11_localization.dll"
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using maddox.game;
using maddox.game.world;
using maddox.GP;
using locfiledll;


public class Mission : localization
{
    public override void OnBattleStarted()
    {
        base.OnBattleStarted();
        MissionNumberListener = -1;

        int xxx = localization.locText(1, 2);
        //SendMessageToAll("Расчет из DLL = " + xxx.ToString(), "Chat");

        //LOAD MAIN MISSION MAP OBJEKTS
        //GamePlay.gpPostMissionLoad("missions\\SMP\\Friday on my mind\\submissions\\Map AAA\\Map AAA.mis");     
    }

In this code I have error on game(Exception). How I can use method localization.locText()?

And can I use this code:
[/CODE]

My mission script:
Code:

//$reference "P11_folder\P11_localization.dll"
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using maddox.game;
using maddox.game.world;
using maddox.GP;
using locfiledll;


public class Mission : AMission
{
    public override void OnBattleStarted()
    {
        base.OnBattleStarted();
        MissionNumberListener = -1;

        int xxx = localization.locText(1, 2);
        //SendMessageToAll("Расчет из DLL = " + xxx.ToString(), "Chat");

        //LOAD MAIN MISSION MAP OBJEKTS
        //GamePlay.gpPostMissionLoad("missions\\SMP\\Friday on my mind\\submissions\\Map AAA\\Map AAA.mis");     
    }

Maybe someone has a ready example of a simple dll?

FG28_Kodiak 05-21-2012 11:41 AM

For example i use this in my dll:
Code:

using System.Collections.Generic;
using System.Globalization;
using maddox.game;
using maddox.game.world;

namespace COD
{
    public static class Message
    {
        static readonly IGamePlay GamePlay = Strategy.THIS.GamePlay;


        public static void ToChatbar(string msg, params object[] args)
        {
            GamePlay.gpLogServer(null, msg, args);
        }


        public static void ToChatbar(Player player, string msg, params object[] args)
        {
            if (player != null)
                GamePlay.gpLogServer(new[] { player }, msg, args);
        }


        public static void ToChatbar(int army, string msg, params object[] args)
        {
            var consignees = new List<Player>();

            if (GamePlay.gpPlayer() != null)
                consignees.Add(GamePlay.gpPlayer());
            if (GamePlay.gpRemotePlayers() != null)
                consignees.AddRange(GamePlay.gpRemotePlayers());

            if (army == -1)
                GamePlay.gpLogServer(null, msg, args);
            else if (consignees.Exists(item => item.Army() == army))
                GamePlay.gpLogServer(consignees.FindAll(item => item.Army() == army).ToArray(), msg, args);
        }


        public static void ToScreen(string msg, params object[] args)
        {
            GamePlay.gpHUDLogCenter(null, msg, args);
        }


        public static void ToScreen(Player player, string msg, params object[] args)
        {
            if (player != null)
                GamePlay.gpHUDLogCenter(new[] { player }, msg, args);
        }


        public static void ToScreen(int army, string msg, params object[] args)
        {
            var consignees = new List<Player>();

            if (GamePlay.gpPlayer() != null)
                consignees.Add(GamePlay.gpPlayer());
            if (GamePlay.gpRemotePlayers() != null)
                consignees.AddRange(GamePlay.gpRemotePlayers());

            if (army == -1)
                GamePlay.gpHUDLogCenter(null, msg, args);
            else if (consignees.Exists(item => item.Army() == army))
                GamePlay.gpHUDLogCenter(consignees.FindAll(item => item.Army() == army).ToArray(), msg, args);
        }
       

        public static void ToScreenCountDown(string message, string endMessage, int seconds)
        {
            string tmpMessage = message + " ";
            int count = 0;

            while (count < seconds)
            {
                Strategy.THIS.Timeout(count++, () =>
                {
                    ToScreen(tmpMessage + seconds--.ToString(CultureInfo.InvariantCulture));
                });
            }
            Strategy.THIS.Timeout(count, () => ToScreen(endMessage));
        }


        public static void ToScreenCountDown(Player player, string message, string endMessage, int seconds)
        {
            string tmpMessage = message + " ";
            int count = 0;

            while (count < seconds)
            {
                Strategy.THIS.Timeout(count++, () =>
                {
                    ToScreen(player, tmpMessage + seconds--.ToString(CultureInfo.InvariantCulture));
                });
            }
            Strategy.THIS.Timeout(count, () => ToScreen(player, endMessage));
        }


        public static void ToScreenCountDown(int army, string message, string endMessage, int seconds)
        {
            string tmpMessage = message + " ";
            int count = 0;

            while (count < seconds)
            {
                Strategy.THIS.Timeout(count++, () =>
                    {
                        ToScreen(army, tmpMessage + seconds--.ToString(CultureInfo.InvariantCulture));
                    });
               
            }
            Strategy.THIS.Timeout(count, () => ToScreen(army, endMessage));
        }

    }
}

In the script file i use

Code:

//$reference parts/core/COD.dll  //reference to my dll (Assembly)
using System;
using maddox.game;
using maddox.game.world;
using COD;  //My namespace

public class Mission : AMission
{

    public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceEnter(player, actor, placeIndex);

      Message.ToChatbar(player, "Welcome {0}", player);
     
       
    }
}


podvoxx 05-21-2012 01:00 PM

Quote:

Originally Posted by FG28_Kodiak (Post 427974)
For example i use this in my dll:


Thank you very much! I will try your version later.

podvoxx 05-21-2012 08:09 PM

Not work :(, I have this error whith your code:

Code:

[22:50:10]        =================================================
[22:50:10]        System.IO.FileNotFoundException: Could not load file or assembly 'SMPlocalization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Не удается найти указанный файл.
[22:50:10]        File name: 'SMPlocalization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
[22:50:10]       
[22:50:10]        Server stack trace:
[22:50:10]          at Mission.OnTickGame()
[22:50:10]          at maddox.game.ABattle.OnTickGame()
[22:50:10]          at maddox.game.world.Strategy.OnTickGame()
[22:50:10]          at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
[22:50:10]          at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
[22:50:10]       
[22:50:10]        Exception rethrown at [0]:
[22:50:10]          at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
[22:50:10]          at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
[22:50:10]          at maddox.game.IBattle.OnTickGame()
[22:50:10]          at maddox.game.GameDef.tickGame()
[22:50:10]          at Rnn9R0HNW1FFeT2aIDs.ltiVH2HK9YyK7SdiCrk.8IDxVdt1dPyeHPkw7Ndf(Object )
[22:50:10]          at Rnn9R0HNW1FFeT2aIDs.ltiVH2HK9YyK7SdiCrk.NaqwoOS5Joc()
[22:50:10]          at JHVeKKyORf15WCVE1pL.eE20r2yPeQB95WctiCJ.ZRMSPQBwmiC(Boolean , Boolean )
[22:50:10]       
[22:50:10]        WRN: Assembly binding logging is turned OFF.
[22:50:10]        To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
[22:50:10]        Note: There is some performance penalty associated with assembly bind failure logging.
[22:50:10]        To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
[22:50:10]       
[22:50:10]        =================================================


FG28_Kodiak 05-21-2012 10:21 PM

Where do you store the file?
For multiplayer it must (should maybe there is another location too) be in "..\Steam\SteamApps\common\il-2 sturmovik cliffs of dover\parts\core" at the moment, until we can create Addins and specify the path of the User Dlls in the xml-file.

Smokeynz 05-22-2012 12:12 AM

I've been wondering about this, or how to modulise methods into individually run code when required.

What sort of restrictions is there at present for dll's?
Actually how do you turn a cs script into a dll?

Kodiak, I see also you run multible occurances of a public static void ToChatBar
I thought this conflicted? How does it know which one to use?

FG28_Kodiak 05-22-2012 05:33 AM

Quote:

Originally Posted by Smokeynz (Post 428147)
What sort of restrictions is there at present for dll's?

Normally none.

Quote:

Actually how do you turn a cs script into a dll?
In Visual select Class Library, after entering code, generate the project. After that (without error) you will find the dll in "..\bin\Debug" (or ..\bin\Release depens on your Project settings) in the project directory.

Quote:

Kodiak, I see also you run multible occurances of a public static void ToChatBar
I thought this conflicted? How does it know which one to use?
I've overloaded the methods, they must differ in type or/and number of arguments. So the Compiler 'knows' which to use.

podvoxx 05-22-2012 07:26 AM

Quote:

Originally Posted by FG28_Kodiak (Post 428112)
Where do you store the file?
For multiplayer it must (should maybe there is another location too) be in "..\Steam\SteamApps\common\il-2 sturmovik cliffs of dover\parts\core" at the moment, until we can create Addins and specify the path of the User Dlls in the xml-file.

My folder in "..\Steam\SteamApps\common\il-2 sturmovik cliffs of dover\MyDLLfolder". In the evening try to change the folder location and add xml-file.

FG28_Kodiak 05-22-2012 09:00 AM

Addins for multiplayer are ignored at the moment or some trick is needed - ok if you get it to work tell me please.

Smokeynz 05-22-2012 10:52 AM

ok, I try to build project(your message above) but get errors, so add references of CLOD, then project won't build and create dll....hmmm

I tried to follow several guides on web, all say process much the same, but dont work because I seem to need references from CLOD, which seem to make the build step fail...sigh.

doing something wrong, not sure what.


All times are GMT. The time now is 03:53 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.