-
Notifications
You must be signed in to change notification settings - Fork 8
CelesteNet Support #2
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
Draft
s5bug
wants to merge
4
commits into
bigkahuna443:dev
Choose a base branch
from
s5bug:celestenet
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| using Celeste.Mod.CelesteNet; | ||
| using Celeste.Mod.CelesteNet.Client; | ||
| using Celeste.Mod.CelesteNet.Client.Entities; | ||
| using Celeste.Mod.CelesteNet.DataTypes; | ||
| using MonoMod.RuntimeDetour; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Reflection; | ||
|
|
||
| namespace SkinModHelper.Module | ||
| { | ||
|
|
||
| public class SkinModHelperCelesteNet | ||
| { | ||
| public static void HandleDataReady(CelesteNetConnection con, DataReady data) | ||
| { | ||
| con.Send(new SkinModHelperChange {SkinID = SkinModHelperModule.Settings.SelectedSkinMod}); | ||
| } | ||
|
|
||
| private static DataHandler handleDataReady; | ||
|
|
||
| public static void HandleSkinModHelperChange(CelesteNetConnection con, SkinModHelperChange data) | ||
| { | ||
| SkinModHelperModule.GhostIDRefreshSet.Add(data.ChangePlayer.ID); | ||
| } | ||
|
|
||
| private static DataHandler handleSkinModHelperChange; | ||
|
|
||
| public static void Load() | ||
| { | ||
| CelesteNetClientContext.OnInit += clientContext => | ||
| { | ||
| CelesteNetClient client = clientContext.Client; | ||
| handleDataReady = client.Data.RegisterHandler<DataReady>(HandleDataReady); | ||
| handleSkinModHelperChange = client.Data.RegisterHandler<SkinModHelperChange>(HandleSkinModHelperChange); | ||
| }; | ||
| } | ||
|
|
||
| public static void Unload() | ||
| { | ||
| CelesteNetClient client = CelesteNetClientModule.Instance.Client; | ||
| if (client != null) | ||
| { | ||
| if (handleDataReady != null) | ||
| { | ||
| client.Data.UnregisterHandler(typeof(DataReady), handleDataReady); | ||
| handleDataReady = null; | ||
| } | ||
|
|
||
| if (handleSkinModHelperChange != null) | ||
| { | ||
| client.Data.UnregisterHandler(typeof(SkinModHelperChange), handleSkinModHelperChange); | ||
| handleSkinModHelperChange = null; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public class SkinModHelperChange : DataType<SkinModHelperChange> | ||
| { | ||
| static SkinModHelperChange() | ||
| { | ||
| DataID = "skinmodhelperChange"; | ||
| } | ||
|
|
||
| public DataPlayerInfo ChangePlayer; | ||
| public string SkinID; | ||
|
|
||
| public override MetaType[] GenerateMeta(DataContext ctx) | ||
| { | ||
| return new MetaType[] | ||
| { | ||
| new MetaPlayerPrivateState(ChangePlayer), | ||
| new MetaBoundRef(DataType<DataPlayerInfo>.DataID, ChangePlayer?.ID ?? uint.MaxValue, true) | ||
| }; | ||
| } | ||
|
|
||
| public override void FixupMeta(DataContext ctx) | ||
| { | ||
| ChangePlayer = Get<MetaPlayerPrivateState>(ctx).Player; | ||
| Get<MetaBoundRef>(ctx).ID = ChangePlayer?.ID ?? uint.MaxValue; | ||
| } | ||
|
|
||
| protected override void Read(CelesteNetBinaryReader reader) | ||
| { | ||
| SkinID = reader.ReadNetString(); | ||
| } | ||
|
|
||
| protected override void Write(CelesteNetBinaryWriter writer) | ||
| { | ||
| writer.WriteNetString(SkinID); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely think CN should be an optional dependency, so this will need some logic to only run the CN logic if the dependency is loaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I gotta add some more checkboxes to the first post