Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RequireDependency Command #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private void ProcessGetData(byte[] data) {
GameDataType.SettingValue => GetSettingValue((string) objects[1]),
GameDataType.CompleteInfoCommand => AreaCompleteInfo.CreateCommand(),
GameDataType.ModUrl => GetModUrl(),
GameDataType.RequireDependency => GetRequireDependency(),
_ => string.Empty
};

Expand Down Expand Up @@ -194,6 +195,11 @@ string MetaToString(EverestModuleMetadata metadata, int indentation = 0, bool co

string modInfo = "";

if (mapMeta != null) {
modInfo += DependencyToString(mapMeta);
modInfo += "\n";
}

EverestModuleMetadata celesteMeta = metas.First(metadata => metadata.Name == "Celeste");
EverestModuleMetadata everestMeta = metas.First(metadata => metadata.Name == "Everest");
EverestModuleMetadata tasMeta = metas.First(metadata => metadata.Name == "CelesteTAS");
Expand Down Expand Up @@ -251,6 +257,29 @@ string MetaToString(EverestModuleMetadata metadata, int indentation = 0, bool co
return modInfo;
}

private string GetRequireDependency() {
if (Engine.Scene is not Level level) {
return string.Empty;
}

AreaData areaData = AreaData.Get(level);
string moduleName = string.Empty;
EverestModuleMetadata mapMeta = null;
if (Everest.Content.TryGet<AssetTypeMap>("Maps/" + areaData.SID, out ModAsset mapModAsset) && mapModAsset.Source != null) {
moduleName = mapModAsset.Source.Name;
mapMeta = Everest.Modules.Select(module => module.Metadata).FirstOrDefault(meta => meta.Name == moduleName);
if (mapMeta != null) {
return DependencyToString(mapMeta);
}
}

return string.Empty;
}

private string DependencyToString(EverestModuleMetadata metadata) {
return $"{RequireDependencyCommand.CommandName} {metadata.Name} {metadata.VersionString}\n";
}

private string GetSettingValue(string settingName) {
if (typeof(CelesteTasSettings).GetProperty(settingName) is { } property) {
return property.GetValue(TasSettings).ToString();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System;
using System.Linq;
using System.Threading;
using Monocle;
using Celeste;
using Celeste.Mod;
using Celeste.Mod.UI;
using Celeste.Mod.Meta;
using TAS.Utils;
using System.Collections.Generic;

namespace TAS.Input.Commands;

public static class RequireDependencyCommand {

public const string CommandName = "RequireDependency";
// "RequireDependency, StrawberryJam2021",
// "RequireDependency, StrawberryJam2021, 1.0.9"


[TasCommand(CommandName, ExecuteTiming = ExecuteTiming.Runtime, LegalInMainGame = false, CalcChecksum = false)]
private static void RequireDependency(string[] args) {
// if not found, then we goto mod options menu, and let MODOPTIONS_COREMODULE_DOWNLOADDEPS appear, ask Everest to download the dependency as described in the tas file
// it seems this needs Everest.Flags.SupportRuntimeMods = true
if (args.IsEmpty()) return;
EverestModuleMetadata dependency = new();
dependency.Name = args[0];
dependency.VersionString = args.Length > 1 ? args[1] : "0.0.1";

if (Everest.Modules.Where(module => module.Metadata.Name == dependency.Name) is { } matches && matches.Count() > 0) {
if (args.Length == 1) {
return;
}
foreach (EverestModule installed in matches) {
if (Everest.Loader.VersionSatisfiesDependency(dependency.Version, installed.Metadata.Version)) {
return;
}
}
}

EverestModuleMetadata dummy = new();
// Everest will not load it if its name already exists
dummyCount++;
dummy.Name = $"{dummyName}({dummyCount})";
dummy.Dependencies = new List<EverestModuleMetadata> { dependency };
dummy.VersionString = "1.0.0";
Everest.Loader.LoadModDelayed(dummy, null);
Engine.Scene.OnEndOfFrame += GotoOuiModOptions;

AbortTas($"{dependency.Name} {(args.Length > 1 ? args[1] + " " : "")}is not loaded.", true);
}

private static string dummyName = "CelesteTAS - DependencyRequestor";

private static int dummyCount = 0;

public static void GotoOuiModOptions() {
Engine.Scene = OverworldLoaderExt.FastGoto<OuiModOptions>();
}
}


internal class OverworldLoaderExt : OverworldLoader {

public Action<Overworld> overworldFirstAction;
public OverworldLoaderExt(Overworld.StartMode startMode, HiresSnow snow = null) : base(startMode, snow) {
Snow = null;
fadeIn = false;
}

public static OverworldLoaderExt FastGoto<T>() where T : Oui {
return new OverworldLoaderExt(Overworld.StartMode.MainMenu, null).SetOverworldAction(x => x.Goto<T>());
}

public override void Begin() {
Add(new HudRenderer());
/*
Add(Snow);
if (fadeIn) {
ScreenWipe.WipeColor = Color.Black;
new FadeWipe(this, wipeIn: true);
}
*/
base.RendererList.UpdateLists();
Session session = null;
if (SaveData.Instance != null) {
session = SaveData.Instance.CurrentSession_Safe;
}
Entity entity = new Entity {
new Coroutine(Routine(session))
};
Add(entity);
activeThread = Thread.CurrentThread;
activeThread.Priority = ThreadPriority.Lowest;
RunThread.Start(LoadThreadExt, "OVERWORLD_LOADER_EXT", highPriority: true);
}

private void LoadThreadExt() {
base.LoadThread();
overworldFirstAction?.Invoke(overworld);
}

public OverworldLoaderExt SetOverworldAction(Action<Overworld> action) {
overworldFirstAction = action;
return this;
}
}
4 changes: 4 additions & 0 deletions Docs/Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
Assert EndWith 2-OldSite {Session.Area.SID}
```

### RequireDependency
- `RequireDependency, StrawberryJam2021, 1.0.9`
- Check if the dependency is loaded. If not, the game will goto the mod options menu.

### StunPause and EndStunPause
- ```
StunPause, (optional mode, Simulate or Input)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ Here are some examples:
- [.kkapture](https://github.com/DemoJameson/kkapture/wiki): Record high quality smooth tas video on low end PC, Windows only.
- [ldcapture](https://github.com/psyGamer/ldcapture): Record high quality smooth tas video on low end PC, Linux only.
- [GhostMod](https://github.com/DemoJameson/GhostMod): Used to compare old and new tas.
- [GhostModForTas](https://github.com/LozenChen/GhostMod): A successor of GhostMod, also used to compare old and new tas.
14 changes: 12 additions & 2 deletions Studio/Studio.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Studio/Studio.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
Expand Down Expand Up @@ -1709,6 +1709,10 @@ private void insertModInfoStripMenuItem1_Click(object sender, EventArgs e) {
InsertDataFromGame(GameDataType.ModInfo);
}

private void insertRequireDependencyStripMenuItem_Click(object sender, EventArgs e) {
InsertDataFromGame(GameDataType.RequireDependency);
}

private void SwapActionKeys(char key1, char key2) {
if (richText.Selection.IsEmpty) {
return;
Expand Down
3 changes: 2 additions & 1 deletion StudioCommunication/MessageID.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace StudioCommunication;

Expand Down Expand Up @@ -97,6 +97,7 @@ public enum GameDataType : byte {
SettingValue,
CompleteInfoCommand,
ModUrl,
RequireDependency,
}

public enum RecordingFailedReason : byte {
Expand Down
Loading