Example #1
0
    void Init()
    {
        Instance               = this;
        WorldLoader.UseHDRP    = true;
        MaterialLoader.UseHDRP = true;

        StdLVLPC = GamePath / "GameData/data/_lvl_pc";
        if (GamePath.IsFile() ||
            !GamePath.Exists() ||
            !CheckExistence("common.lvl") ||
            !CheckExistence("core.lvl") ||
            !CheckExistence("ingame.lvl") ||
            !CheckExistence("inshell.lvl") ||
            !CheckExistence("mission.lvl") ||
            !CheckExistence("shell.lvl"))
        {
            Debug.LogErrorFormat("Invalid game path '{0}!'", GamePath);
            return;
        }

        if (StartupBehaviour == PhxStartupBehaviour.MainMenu)
        {
            EnterMainMenu(true);
        }
        else if (StartupBehaviour == PhxStartupBehaviour.SWBF2Map)
        {
            Debug.Assert(!string.IsNullOrEmpty(StartupSWBF2Map));
            EnterSWBF2Map(StartupSWBF2Map);
        }
        else if (StartupBehaviour == PhxStartupBehaviour.UnityScene)
        {
            Debug.Assert(!string.IsNullOrEmpty(StartupUnityScene));
            EnterUnityScene(StartupUnityScene);
        }
    }
Example #2
0
    void OnGUI()
    {
        PhxRuntimeEnvironment env = PhxGameRuntime.GetEnvironment();

        if (!Application.isPlaying || PhxGameRuntime.Instance == null || env == null)
        {
            EditorGUILayout.LabelField("Game is not running");
            return;
        }

        PhxPath gamePath = PhxGameRuntime.GamePath;

        EditorGUILayout.LabelField("Environment Path", env.Path - gamePath);
        EditorGUILayout.LabelField("Fallback Path", env.FallbackPath - gamePath);
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Environment Stage", env.Stage.ToString());
        EditorGUILayout.Space();

        foreach (var lvl in env.LVLs)
        {
            EditorGUILayout.LabelField(lvl.RelativePath, "Loaded", lvl.bIsFallback ? FallbackLVLStyle : EnvLVLStyle);
        }
        foreach (var lvl in env.LoadingLVLs)
        {
            EditorGUILayout.LabelField(lvl.PathPartial, string.Format("{0:0.} %", env.GetProgress(lvl.Handle) * 100.0f), lvl.bIsFallback ? FallbackLVLStyle : EnvLVLStyle);
        }
    }
Example #3
0
    public void EnterSWBF2Map(string mapScript)
    {
        Debug.Assert(Env == null || Env.IsLoaded);

        ShowLoadscreen();
        RemoveMenu(false);

        PhxPath envPath = StdLVLPC;

        if (RegisteredAddons.TryGetValue(mapScript, out string addonName))
        {
            envPath = AddonPath / addonName / "data/_lvl_pc";
        }

        if (UnitySceneName != null)
        {
            SceneManager.UnloadSceneAsync(UnitySceneName);
            UnitySceneName = null;
        }

        Env?.Delete();
        Env = PhxRuntimeEnvironment.Create(envPath, StdLVLPC);
        Env.ScheduleLVLRel("load/common.lvl");
        Env.OnLoadscreenLoaded += OnLoadscreenTextureLoaded;
        Env.OnLoaded           += OnEnvLoaded;
        Env.OnExecuteMain      += OnEnvExecutionMain;
        Env.Run(mapScript, "ScriptInit", "ScriptPostLoad");
    }
    public SWBF2Handle ScheduleLVLAbs(PhxPath absoluteLVLPath, string[] subLVLs = null, bool bForceLocal = false)
    {
        Debug.Assert(CanSchedule);

        PhxPath leafPath = absoluteLVLPath.GetLeafs(2);

        if (PathToHandle.TryGetValue(leafPath, out SWBF2Handle handle))
        {
            return(handle);
        }

        if (absoluteLVLPath.Exists() && absoluteLVLPath.IsFile())
        {
            handle = EnvCon.AddLevel(absoluteLVLPath, subLVLs);
            LoadingLVLs.Add(new LoadST
            {
                Handle       = handle,
                PathPartial  = leafPath,
                bIsFallback  = false,
                bIsSoundBank = false
            });
            return(handle);
        }

        Debug.LogErrorFormat("Couldn't schedule '{0}'! File not found!", absoluteLVLPath);
        return(new SWBF2Handle(ushort.MaxValue));
    }
    public static PhxRuntimeEnvironment Create(PhxPath envPath, PhxPath fallbackPath = null, bool initMatch = true)
    {
        if (!envPath.Exists())
        {
            Debug.LogErrorFormat("Given environment path '{0}' doesn't exist!", envPath);
            return(null);
        }

        if (fallbackPath == null)
        {
            fallbackPath = envPath;
        }
        Debug.Assert(fallbackPath.Exists());

        PhxAnimationLoader.ClearDB();
        GameLuaEvents.Clear();

        PhxRuntimeEnvironment rt = new PhxRuntimeEnvironment(envPath, fallbackPath);

        rt.ScheduleLVLRel("core.lvl");
        rt.ScheduleLVLRel("shell.lvl");
        rt.ScheduleLVLRel("common.lvl");
        rt.ScheduleLVLRel("mission.lvl");
        rt.ScheduleSoundBankRel("sound/common.bnk");

        rt.RTScene = new PhxRuntimeScene(rt, rt.EnvCon);
        rt.Match   = initMatch ? new PhxRuntimeMatch() : null;
        rt.Timers  = new PhxTimerDB();

        PhxAnimationLoader.Con = rt.EnvCon;

        return(rt);
    }
Example #6
0
    public override bool Equals(object obj)
    {
        PhxPath other = obj as PhxPath;

        if (other == null)
        {
            return(false);
        }
        return(other.GetHashCode() == GetHashCode());
    }
Example #7
0
    bool CheckExistence(string lvlName)
    {
        PhxPath p       = StdLVLPC / lvlName;
        bool    bExists = p.Exists();

        if (!bExists)
        {
            Debug.LogErrorFormat("Could not find '{0}'!", p);
        }
        return(bExists);
    }
Example #8
0
    public static PhxPath Concat(PhxPath lhs, PhxPath rhs)
    {
        PhxPath path = new PhxPath(lhs);

        if (!rhs.P.StartsWith("/"))
        {
            path.P += '/';
        }
        path.P += rhs.P;
        return(path);
    }
    PhxRuntimeEnvironment(PhxPath path, PhxPath fallbackPath)
    {
        Path         = path;
        FallbackPath = fallbackPath;
        Stage        = EnvStage.Init;
        WorldLevel   = null;

        LuaRT  = new PhxLuaRuntime();
        EnvCon = new LibSWBF2.Wrappers.Container();

        Loader.SetGlobalContainer(EnvCon);
    }
Example #10
0
    void ExploreAddons()
    {
        string[] addons = System.IO.Directory.GetDirectories(AddonPath);

        foreach (PhxPath addon in addons)
        {
            PhxPath addme = addon / "addme.script";
            if (addme.Exists() && addme.IsFile())
            {
                Env.ScheduleLVLAbs(addme);
            }
        }
    }
 PhxPath GetLoadscreenPath()
 {
     // First, try grab loadscreen for standard maps
     if (!string.IsNullOrEmpty(InitScriptName))
     {
         PhxPath loadscreenLVL = new PhxPath("load") / (InitScriptName.Substring(0, 4) + ".lvl");
         if ((Path / loadscreenLVL).Exists() || (FallbackPath / loadscreenLVL).Exists())
         {
             return(loadscreenLVL);
         }
     }
     return("load/common.lvl");
 }
Example #12
0
    public static PhxPath Remove(PhxPath lhs, PhxPath rhs)
    {
        PhxPath path = new PhxPath(lhs);

        path.P = path.P.Replace(rhs.P, "");
        if (path.P.StartsWith("/"))
        {
            path.P = path.P.Substring(1, path.P.Length - 1);
        }
        if (path.P.EndsWith("/"))
        {
            path.P = path.P.Substring(0, path.P.Length - 1);
        }
        return(path);
    }
Example #13
0
    // nodeCount: how many nodes to return, starting counting from leaf node
    public PhxPath GetLeafs(int nodeCount)
    {
        Debug.Assert(nodeCount > 0);
        string[] nodes = P.Split('/');
        nodeCount = Mathf.Min(nodeCount, nodes.Length);
        PhxPath result = "";

        for (int i = nodes.Length - nodeCount; i < nodes.Length; ++i)
        {
            result /= nodes[i];
        }
        if (result.P.StartsWith("/"))
        {
            result.P = result.P.Substring(1, result.P.Length - 1);
        }
        return(result);
    }
    // relativeLVLPath: relative to Environment!
    public SWBF2Handle ScheduleSoundBankRel(PhxPath relativeLVLPath)
    {
        Debug.Assert(CanSchedule);

        PhxPath leafPath = relativeLVLPath.GetLeafs(2);

        if (PathToHandle.TryGetValue(leafPath, out SWBF2Handle handle))
        {
            return(handle);
        }

        PhxPath envLVLPath      = Path / relativeLVLPath;
        PhxPath fallbackLVLPath = FallbackPath / relativeLVLPath;

        if (envLVLPath.Exists() && envLVLPath.IsFile())
        {
            handle = EnvCon.AddSoundBank(envLVLPath);
            LoadingLVLs.Add(new LoadST
            {
                Handle       = handle,
                PathPartial  = leafPath,
                bIsFallback  = false,
                bIsSoundBank = true
            });
            return(handle);
        }
        if (fallbackLVLPath.Exists() && fallbackLVLPath.IsFile())
        {
            handle = EnvCon.AddSoundBank(fallbackLVLPath);
            LoadingLVLs.Add(new LoadST
            {
                Handle       = handle,
                PathPartial  = leafPath,
                bIsFallback  = true,
                bIsSoundBank = true
            });
            return(handle);
        }

        Debug.LogErrorFormat("Couldn't schedule '{0}'! File not found!", relativeLVLPath);
        return(new SWBF2Handle(ushort.MaxValue));
    }