コード例 #1
0
 /// <summary>
 /// 移除模组包
 /// </summary>
 /// <param name="mod">模组包实例</param>
 /// <returns>返回操作是否成功</returns>
 public bool UnLoadGameMod(GameMod mod)
 {
     mod.Destroy();
     gameMods.Remove(mod);
     GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_MOD_UNLOAD, "*", mod.PackageName, mod);
     return(true);
 }
コード例 #2
0
ファイル: GameInit.cs プロジェクト: imengyu/Ballance2
        //加载用户模组
        private IEnumerator GameInitUserMods()
        {
            //加载mod文件夹下所有模组
            string modFolderPath = GamePathManager.GetResRealPath("mod", "");

            if (Directory.Exists(modFolderPath))
            {
                DirectoryInfo direction = new DirectoryInfo(modFolderPath);
                FileInfo[]    files     = direction.GetFiles("*.ballance", SearchOption.TopDirectoryOnly);
                for (int i = 0, c = files.Length; i < c; i++)
                {
                    ModManager.LoadGameMod(GamePathManager.GetResRealPath("mod", files[i].Name), false);

                    GameInitSetUIProgressValue(0.6f + i / (float)c * 0.2f);
                    UIProgressText.text = "Loading " + files[i].Name;
                }
            }

            //根据用户设置启用对应模组
            string[] enableMods = ModManager.GetModEnableStatusList();
            foreach (string packageName in enableMods)
            {
                GameMod m = ModManager.FindGameMod(packageName);
                if (m != null)
                {
                    ModManager.InitializeLoadGameMod(m);

                    yield return(new WaitUntil(m.IsLoadComplete));
                }
            }

            UIProgressText.text = "Loading";
            GameInitSetUIProgressValue(0.8f);
            yield break;
        }
コード例 #3
0
        private void OnModAdded(GameMod mod)
        {
            ModListItemData modListItemData = new ModListItemData();

            UICommonList.CommonListItem newItem = modList.AddItem();
            newItem.id = mod.Uid;
            newItem.itemObject.name = mod.PackageName;
            newItem.data            = modListItemData;

            modListItemData.Mod              = mod;
            modListItemData.Title            = newItem.itemObject.transform.Find("Title").GetComponent <Text>();
            modListItemData.Text             = newItem.itemObject.transform.Find("Text").GetComponent <Text>();
            modListItemData.TextFailed       = newItem.itemObject.transform.Find("TextFailed").GetComponent <Text>();
            modListItemData.TextStatus       = newItem.itemObject.transform.Find("TextStatus").GetComponent <Text>();
            modListItemData.Unload           = newItem.itemObject.transform.Find("Unload").GetComponent <Button>();
            modListItemData.Image            = newItem.itemObject.transform.Find("Image").GetComponent <Image>();
            modListItemData.EnableStatus     = newItem.itemObject.transform.Find("EnableStatus").GetComponent <Toggle>();
            modListItemData.ImageSmall       = newItem.itemObject.transform.Find("ImageSmall").GetComponent <Image>();
            modListItemData.EnableStatusText = newItem.itemObject.transform.Find("EnableStatus/Label").GetComponent <Text>();

            //Events
            modListItemData.Unload.onClick.AddListener(() => OnUnloadModClicked(mod));
            EventTriggerListener.Get(modListItemData.EnableStatus.gameObject).onClick = (b) => OnEnableStatusClicked(mod, newItem);

            UpdateModListItemInfos(newItem, mod);
            UpdateModListCountInfos();
        }
コード例 #4
0
 // Use this for initialization
 void Start()
 {
     DontDestroyOnLoad(this.gameObject);
     currentGameMod            = GameMod.stealthMode;
     isRunning                 = true;
     SceneManager.sceneLoaded += OnSceneLo;
 }
コード例 #5
0
    void StartLevel()
    {
        if (castle != null)
        {
            Destroy(castle);
        }
        GameObject[] gos = GameObject.FindGameObjectsWithTag("Projectile");
        foreach (GameObject tGO in gos)
        {
            Destroy(tGO);
        }

        castle = Instantiate(castles[level]);
        castle.transform.position = castlePos;


        SwitchView("Show Both");
        ProjectileLine.S.Clear();

        Goal.goalMet = false;

        UpdateGUI();

        mode = GameMod.playing;
    }
コード例 #6
0
ファイル: GameInit.cs プロジェクト: imengyu/Ballance2
        private IEnumerator LoadGameInitUI()
        {
            gameInitMod = ModManager.LoadGameMod(GamePathManager.GetResRealPath("core", "core.gameinit.ballance"), false);
            gameInitMod.IsModInitByGameinit = true;

            yield return(StartCoroutine(gameInitMod.LoadInternal()));

            if (gameInitMod.LoadStatus != GameModStatus.InitializeSuccess)
            {
                GameErrorManager.ThrowGameError(GameError.GameInitPartLoadFailed, "加载 GameInit 资源包失败 ");
                StopAllCoroutines();
            }

            gameInitUI = GameManager.UIManager.InitViewToCanvas(gameInitMod.GetPrefabAsset("UIGameInit.prefab"), "GameInitUI").gameObject;

            GameManager.UIManager.MaskBlackSet(false);

            UIProgress      = gameInitUI.transform.Find("UIProgress").GetComponent <RectTransform>();
            UIProgressValue = gameInitUI.transform.Find("UIProgress/UIValue").GetComponent <RectTransform>();
            UIProgressText  = gameInitUI.transform.Find("Text").GetComponent <Text>();
            IntroAnimator   = gameInitUI.GetComponent <Animator>();
            TextError       = gameInitUI.transform.Find("TextError").GetComponent <Text>();

            loadedGameInitUI = true;
        }
コード例 #7
0
ファイル: SoundManager.cs プロジェクト: imengyu/Ballance2
        /// <summary>
        /// 加载模组包中的音乐资源
        /// </summary>
        /// <param name="assets">资源路径(模组包:音乐路径)</param>
        /// <returns></returns>
        public AudioClip LoadAudioResource(string assets)
        {
            string[] names = assets.Split(':');

            GameMod mod = ModManager.FindGameModByAssetStr(names[0]);

            if (mod == null)
            {
                GameLogger.Warning(TAG, "无法加载声音文件 {0} ,因为未找到模组包 {1}", assets, names[0]);
                GameErrorManager.LastError = GameError.NotRegister;
                return(null);
            }
            if (mod.LoadStatus != GameModStatus.InitializeSuccess)
            {
                GameLogger.Warning(TAG, "无法加载声音文件 {0} ,因为模组包 {1} ({2}) 未初始化", assets, names[0], mod.Uid);
                GameErrorManager.LastError = GameError.NotInitialize;
                return(null);
            }

            AudioClip clip = mod.GetAsset <AudioClip>(names[1]);

            if (clip != null)
            {
                clip.name = GamePathManager.GetFileNameWithoutExt(names[1]);
            }
            else
            {
                GameLogger.Warning(TAG, "未找到声音文件 {0} ,在模组包 {1}", assets, names[0]);
                GameErrorManager.LastError = GameError.AssetsNotFound;
            }

            return(clip);
        }
コード例 #8
0
ファイル: JAClientHandler.cs プロジェクト: entdark/JKClient
 public virtual void AdjustGameStateConfigstring(int i, string csStr)
 {
     if (i == GameState.ServerInfo)
     {
         var    info     = new InfoString(csStr);
         string gamename = info["gamename"];
         //TODO: add mod handlers
         if (gamename.Contains("Szlakiem Jedi RPE") ||
             gamename.Contains("Open Jedi Project") ||
             gamename.Contains("OJP Enhanced") ||
             gamename.Contains("OJP Basic") ||
             gamename.Contains("OJRP"))
         {
             this.gameMod          = GameMod.OJP;
             this.MaxConfigstrings = JAClientHandler.MaxConfigstringsOJP;
         }
         else if (gamename.Contains("Movie Battles II"))
         {
             this.gameMod = GameMod.MBII;
         }
         else
         {
             this.gameMod = GameMod.Base;
         }
     }
 }
コード例 #9
0
 /// <summary>
 /// 加载模组包
 /// </summary>
 /// <param name="m">模组包</param>
 /// <returns>返回操作是否成功</returns>
 public bool InitializeLoadGameMod(GameMod m)
 {
     if (m.LoadStatus != GameModStatus.InitializeSuccess)
     {
         m.Load(this);
     }
     return(true);
 }
コード例 #10
0
ファイル: GameInit.cs プロジェクト: imengyu/Ballance2
        //加载GameInit模块
        private IEnumerator GameInitPackages(string GameInitTable)
        {
            StringSpliter sp = new StringSpliter(GameInitTable, '\n');

            if (sp.Count >= 1)
            {
                int      loadedCount = 0;
                string[] args;

                GameLogger.Log(TAG, "Gameinit table : {0}", sp.Count);

                foreach (string ar in sp.Result)
                {
                    if (ar.StartsWith(":"))
                    {
                        continue;
                    }

                    bool           required    = false;
                    string         packageName = "";
                    GameModRunMask mask        = GameModRunMask.GameBase;
                    args = ar.Split(':');

                    if (args.Length >= 3)
                    {
                        required    = args[2] == "Required";
                        packageName = args[0];
                        System.Enum.TryParse(args[1], out mask);
                    }

                    bool modNeedRun = (mask & currentLoadMask) != GameModRunMask.None;

                    //状态
                    loadedCount++;
                    GameInitSetUIProgressValue(loadedCount / (float)sp.Count * 0.6f);
                    UIProgressText.text = "Loading " + packageName;

                    //加载
                    GameMod mod = ModManager.LoadGameModByPackageName(packageName, modNeedRun);
                    if (mod != null)
                    {
                        mod.IsModInitByGameinit = true;

                        yield return(new WaitUntil(mod.IsLoadComplete));
                    }

                    if ((mod == null || (modNeedRun && mod.LoadStatus != GameModStatus.InitializeSuccess)) && required)
                    {
                        GameErrorManager.ThrowGameError(GameError.GameInitPartLoadFailed, "加载模块  " + packageName + " 时发生错误");
                    }
                }
            }

            UIProgressText.text = "Loading";
            GameInitSetUIProgressValue(0.6f);
        }
コード例 #11
0
 private void OnModRemoved(GameMod mod)
 {
     UICommonList.CommonListItem oldItem = modList.GetItemById(mod.Uid);
     if (oldItem != null)
     {
         modList.RemoveItem(oldItem);
     }
     oldItem.data = null;
     UpdateModListCountInfos();
 }
コード例 #12
0
    // Update is called once per frame
    void Update()
    {
        UpdateGUI();

        if ((mode == GameMod.playing) && Goal.goalMet)
        {
            mode = GameMod.levelEnd;
            SwitchView("Show Both");
            Invoke("NextLevel", 2f);
        }
    }
コード例 #13
0
 public void OnModLoadFinished(GameMod m)
 {
     if (m.LoadStatus == GameModStatus.InitializeSuccess)
     {
         GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_MOD_LOAD_SUCCESS, "*", m.PackageName, m);
     }
     else
     {
         GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_MOD_LOAD_FAILED, "*", m.PackageName, m, m.LoadFriendlyErrorExplain);
     }
 }
コード例 #14
0
        private bool OnCommandInitializeMod(string keyword, string fullCmd, string[] args)
        {
            GameMod mod = FindGameModByAssetStr(args[0]);

            if (mod == null)
            {
                GameLogger.Error(TAG, "未找到模组 {0} ", args[0]);
                return(false);
            }
            return(InitializeLoadGameMod(mod));
        }
コード例 #15
0
 private void OnEnableStatusClicked(GameMod mod, UICommonList.CommonListItem newItem)
 {
     modEnableStatusListSaved = false;
     if (((ModListItemData)newItem.data).EnableStatus.isOn)
     {
         modEnableStatusList.Add(mod.PackageName);
     }
     else
     {
         modEnableStatusList.Remove(mod.PackageName);
     }
 }
コード例 #16
0
 private void OnDestroy()
 {
     if (onDestory != null)
     {
         onDestory(self);
     }
     StopLuaEvents();
     if (GameMod != null)
     {
         GameMod.RemoveLuaObject(this);
     }
 }
コード例 #17
0
        private bool OnCommandLoadMod(string keyword, string fullCmd, string[] args)
        {
            GameMod mod = LoadGameMod(args[0], args.Length >= 2 ? args[1] == "true" : false);

            if (mod == null)
            {
                GameLogger.Warning(TAG, "模组 {0} 加载失败", args[0]);
                return(false);
            }
            GameLogger.Log(TAG, "模组已加载 {0} ({1})", mod.PackageName, mod.Uid);
            return(true);
        }
コード例 #18
0
        /// <summary>
        /// 执行模组包代码
        /// </summary>
        /// <param name="modUid">模组包UID</param>
        /// <returns>返回操作是否成功</returns>
        public bool RunGameMod(string packageName)
        {
            GameMod m = FindGameMod(packageName);

            if (m == null)
            {
                GameLogger.Warning(TAG, "无法执行化模组包 {0} ,因为没有加载", packageName);
                GameErrorManager.LastError = GameError.NotRegister;
                return(false);
            }
            return(RunGameMod(m));
        }
コード例 #19
0
        /// <summary>
        /// 卸载模组包
        /// </summary>
        /// <param name="modUid"></param>
        /// <returns></returns>
        public bool UnInitializeLoadGameMod(string modPackageName)
        {
            GameMod m = FindGameMod(modPackageName);

            if (m == null)
            {
                GameLogger.Warning(TAG, "无法卸载模组包 {0} ,因为没有注册", modPackageName);
                GameErrorManager.LastError = GameError.NotRegister;
                return(false);
            }
            return(UnInitializeLoadGameMod(m));
        }
コード例 #20
0
        /// <summary>
        /// 获取模组包是否正在加载
        /// </summary>
        /// <param name="packageName">模组包名</param>
        /// <returns>返回操作是否成功</returns>
        public bool IsGameModLoading(string packageName)
        {
            GameMod mod = FindGameMod(packageName);

            if (mod == null)
            {
                GameLogger.Warning(TAG, "无法卸载模组 (UID: {0}) ,因为没有加载", packageName);
                GameErrorManager.LastError = GameError.NotRegister;
                return(false);
            }
            return(mod.LoadStatus == GameModStatus.Loading);
        }
コード例 #21
0
 /// <summary>
 /// 卸载模组包
 /// </summary>
 /// <param name="modUid"></param>
 /// <returns></returns>
 public bool UnInitializeLoadGameMod(GameMod m)
 {
     if (m.LoadStatus == GameModStatus.InitializeSuccess)
     {
         m.UnLoad();
         return(true);
     }
     else
     {
         GameLogger.Warning(TAG, "无法卸载模组包 {0} ,因为没有加载", m.PackageName);
         GameErrorManager.LastError = GameError.NotInitialize;
         return(false);
     }
 }
コード例 #22
0
        private void DoFlushModList()
        {
            foreach (UICommonList.CommonListItem item in modList.List)
            {
                GameMod mod = ((ModListItemData)item.data).Mod;
                if (mod.IsModInitByGameinit)
                {
                    item.visible = !hideCoreMod;
                }
                UpdateModListItemInfos(item, mod);
            }

            UpdateModListCountInfos();
            modList.Relayout();
        }
コード例 #23
0
        /// <summary>
        /// 执行模组包代码
        /// </summary>
        /// <param name="modUid">模组包UID</param>
        /// <returns>返回操作是否成功</returns>
        public bool RunGameMod(GameMod m)
        {
            if (m == null)
            {
                GameErrorManager.LastError = GameError.ParamNotProvide;
                return(false);
            }
            if (m.LoadStatus == GameModStatus.InitializeSuccess)
            {
                return(m.Run());
            }

            GameLogger.Warning(TAG, "无法执行化模组包 {0},因为没有初始化", m.PackageName);
            GameErrorManager.LastError = GameError.NotInitialize;
            return(false);
        }
コード例 #24
0
        /// <summary>
        /// 加载模组包
        /// </summary>
        /// <param name="packagePath">模组包路径</param>
        /// <param name="initialize">是否立即初始化模组包</param>
        /// <returns>返回模组包UID</returns>
        public GameMod LoadGameMod(string packagePath, bool initialize = true)
        {
            GameMod mod = FindGameModByPath(packagePath);

            if (mod != null)
            {
                GameLogger.Warning(TAG, "Mod \"{0}\" already registered, skip", packagePath);
                return(mod);
            }

            //路径处理
            if (StringUtils.IsUrl(packagePath))
            {
                GameLogger.Error(TAG, "不支持从 URL 加载模组包 \"{0}\" ,请将其先下载至 streamingAssetsPath 后再加载。", packagePath);
                return(null);
            }
            //处理路径至mod文件夹路径
            if (!File.Exists(packagePath) && !GamePathManager.IsAbsolutePath(packagePath))
            {
                packagePath = GamePathManager.GetResRealPath("mod", packagePath);
            }
            if (!File.Exists(packagePath))
            {
                GameLogger.Error(TAG, "Mod file \"{0}\" not exists", packagePath);
                return(null);
            }

            mod = new GameMod(packagePath, this);
            if (!mod.Init())
            {
                return(null);
            }
            if (!gameMods.Contains(mod))
            {
                gameMods.Add(mod);
            }

            GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_MOD_REGISTERED, "*", mod.PackageName, mod);
            GameLogger.Log(TAG, "Register mod \"{0}\"", packagePath);

            if (initialize)
            {
                mod.Load(this);
            }

            return(mod);
        }
コード例 #25
0
        /// <summary>
        /// 移除模组包
        /// </summary>
        /// <param name="modUid">模组包UID</param>
        /// <returns>返回操作是否成功</returns>
        public bool UnLoadGameMod(string packageName)
        {
            GameMod mod = FindGameMod(packageName);

            if (mod == null)
            {
                GameLogger.Warning(TAG, "无法卸载模组 {0},因为没有加载", packageName);
                GameErrorManager.LastError = GameError.NotRegister;
                return(false);
            }

            mod.Destroy();
            gameMods.Remove(mod);
            GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_MOD_UNLOAD, "*", mod.PackageName, mod);

            return(true);
        }
コード例 #26
0
        private unsafe void ClearState()
        {
            this.snap         = new Snapshot();
            this.serverTime   = 0;
            this.newSnapshots = false;
            fixed(GameState *gs = &this.gameState)
            {
                Common.MemSet(gs, 0, sizeof(GameState));
            }

            this.parseEntitiesNum = 0;
            Common.MemSet(this.cmds, 0, sizeof(UserCommand) * UserCommand.CommandBackup);
            this.cmdNumber = 0;
            Common.MemSet(this.outPackets, 0, sizeof(OutPacket) * JKClient.PacketBackup);
            this.serverId = 0;
            Common.MemSet(this.snapshots, 0, sizeof(Snapshot) * JKClient.PacketBackup);
            Common.MemSet(this.entityBaselines, 0, sizeof(EntityState) * Common.MaxGEntities);
            Common.MemSet(this.parseEntities, 0, sizeof(EntityState) * JKClient.MaxParseEntities);
            this.gameMod = GameMod.Undefined;
        }
コード例 #27
0
        private GameMod LoadModInEditor(string pathInEditorMods, string packageName)
        {
#if UNITY_EDITOR
            GameLogger.Warning(TAG, "LoadModInEditor : {0} ({1})", packageName, pathInEditorMods);
            GameMod   mod    = null;
            TextAsset modDef = AssetDatabase.LoadAssetAtPath <TextAsset>(pathInEditorMods + "/ModDef.xml");
            if (modDef == null)
            {
                GameLogger.Warning(TAG, "模组无效 {0} ,未找到 ModDef.xml ", pathInEditorMods);
                GameErrorManager.LastError = GameError.FileNotFound;
                return(null);
            }

            mod = new GameMod(pathInEditorMods, this, packageName);
            mod.IsEditorPack = true;
            mod.ForceLoadEditorPack(modDef);
            return(mod);
#else
            throw new System.Exception("LoadModInEditor can only use in editor mode!");
#endif
        }
コード例 #28
0
ファイル: Q3ClientHandler.cs プロジェクト: entdark/JKClient
 public virtual void AdjustGameStateConfigstring(int i, string csStr)
 {
     if (i == (int)Q3ClientGame.ConfigstringQ3.GameVersion)
     {
         if (csStr.Contains("cpma"))
         {
             this.gameMod = GameMod.CPMA;
         }
         else if (csStr.Contains("defrag"))
         {
             this.gameMod = GameMod.DeFRaG;
         }
     }
     else if (i == 12 && csStr.Contains("RA3"))
     {
         this.gameMod = GameMod.RocketArena3;
     }
     else if (i == 872 && csStr.Length > 0 && csStr[0] != '\0')
     {
         this.gameMod = GameMod.OSP;
     }
 }
コード例 #29
0
 private static string GetGameFilesPathByGameMod(string gameMod)
 {
     try
     {
         GameMods gameMods          = GameMods.LoadFromFile <GameMods>(@"config" + SEP + "gamemods.xml");
         GameMod  ConfiguredGameMod = gameMods.ConfiguredGameMods.SingleOrDefault(name => name.ModName == gameMod);
         if (Directory.Exists(ConfiguredGameMod.PathToGameFiles))
         {
             if (File.Exists(ConfiguredGameMod.PathToGameFiles + SEP + "7daystodie.exe"))
             {
                 return(ConfiguredGameMod.PathToGameFiles);
             }
         }
         Console.WriteLine("Could not extract GameMods GameFiles Path! Set default!");
         return(SDaysToDiePath);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Could not extract GameMods GameFiles Path! Set default! Exception: " + ex.ToString());
         return(SDaysToDiePath);
     }
 }
コード例 #30
0
        private void InitHandler(string luaModulHandlerString)
        {
            if (string.IsNullOrEmpty(luaModulHandlerString))
            {
                throw new System.Exception("luaModulHandlerString is null");
            }
            string[] strs = luaModulHandlerString.Split(':');
            if (strs.Length >= 3)
            {
                targetMod = ModManager.FindGameModByAssetStr(strs[0]);
                if (targetMod == null)
                {
                    return;
                }
                if (strs[1].ToLower() == "main")
                {
                    handlerFuncName = strs[2];
                    handlerFunc     = targetMod.GetLuaFun(handlerFuncName);
                    initSuccess     = true;
                }
                else if (targetMod.FindLuaObject(strs[1], out targetObject))
                {
                    handlerFuncName = strs[2];
                    handlerFunc     = targetObject.GetLuaFun(handlerFuncName);
                    initSuccess     = true;
                }

                if (strs.Length >= 4)
                {
                    handlerArgs = new string[strs.Length - 3];
                    for (int i = 3; i < strs.Length; i++)
                    {
                        handlerArgs[i - 3] = strs[i];
                    }
                }
            }
        }