Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.InteropServices;
- using EUDGen.Communication.Messages;
- using EUDGen.Communication.System;
- namespace EUDGen.Models.Data
- {
- public static class MapExport
- {
- public const string DllName = "MapExport.dll";
- #region Extern method signatures
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int openMap(string path);
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int saveMap();
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int openTrg(string path);
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int saveTrg();
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int newTrigger();
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int setPlayer(int id);
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int addDeaths(int player, int unit, int comparison, int amount);
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int addSetDeaths(int player, int unit, int modifier, int amount);
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int addComment(string comment);
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int addSwitch(int sw, int state);
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int addSetSwitch(int sw, int state);
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern int addPreserve();
- [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
- private static extern void clear();
- #endregion
- private static readonly ExportLogMessage LogMessage = new ExportLogMessage(null, false);
- private static void SendLogMessage(string text, bool terminatingMessage = false)
- {
- LogMessage.Log = text;
- LogMessage.TerminatingMessage = terminatingMessage;
- Messenger.Send(LogMessage);
- }
- public static bool TryOpenMap(string filename)
- {
- return TryFunc(() => openMap(filename));
- }
- public static bool TrySaveMap()
- {
- return TryFunc(saveMap);
- }
- public static bool TryOpenTrg(string filename)
- {
- return TryFunc(() => openTrg(filename));
- }
- public static bool TrySaveTrg()
- {
- return TryFunc(saveTrg);
- }
- public static bool TryNewTrigger()
- {
- return TryFunc(newTrigger);
- }
- public static bool TrySetPlayer(int id)
- {
- return TryFunc(() => setPlayer(id));
- }
- public static bool TryAddCondition(int player, int unit, int comparison, int amount)
- {
- return TryFunc(() => addDeaths(player, unit, comparison, amount));
- }
- public static bool TryAddAction(int player, int unit, int modifier, int amount)
- {
- return TryFunc(() => addSetDeaths(player, unit, modifier, amount));
- }
- public static bool TryAddComment(string comment)
- {
- return TryFunc(() => addComment(comment));
- }
- public static bool TrySwitch(int switchNumber, int switchState)
- {
- return TryFunc(() => addSwitch(switchNumber, switchState));
- }
- public static bool TryAddPreserve(int switchNumber, int switchState)
- {
- return TryFunc(addPreserve);
- }
- public static bool TryAddSwitch(int switchNumber, int switchState)
- {
- return TryFunc(() => addSetSwitch(switchNumber, switchState));
- }
- public static bool TryClear()
- {
- return TryAction(clear);
- }
- private static bool TryAction(Action action)
- {
- return TryFunc(() =>
- {
- action.Invoke();
- return 0;
- });
- }
- private static bool TryFunc(Func<int> func)
- {
- try
- {
- return func.Invoke() == 0;
- }
- catch
- {
- SendLogMessage("ERROR: MapExport exception");
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment