forked from nikita/muzika-gromche
				
			Compare commits
	
		
			2 Commits
		
	
	
		
			54e88b08a8
			...
			f87da1dfed
		
	
	| Author | SHA1 | Date | 
|---|---|---|
|  | f87da1dfed | |
|  | baaba2be6f | 
|  | @ -17,7 +17,6 @@ | ||||||
|         <PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1" PrivateAssets="all" /> |         <PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1" PrivateAssets="all" /> | ||||||
|         <!-- Publicize internal methods, so we could generate config entries for tracks at runtime instead of generating code at compile time --> |         <!-- Publicize internal methods, so we could generate config entries for tracks at runtime instead of generating code at compile time --> | ||||||
|         <PackageReference Include="Sigurd.BepInEx.CSync" Version="5.0.1" Publicize="true" /> |         <PackageReference Include="Sigurd.BepInEx.CSync" Version="5.0.1" Publicize="true" /> | ||||||
|         <PackageReference Include="AinaVT-LethalConfig" Version="1.4.6" /> |  | ||||||
|     </ItemGroup> |     </ItemGroup> | ||||||
| 
 | 
 | ||||||
|     <ItemGroup> |     <ItemGroup> | ||||||
|  |  | ||||||
|  | @ -7,9 +7,6 @@ using BepInEx; | ||||||
| using BepInEx.Configuration; | using BepInEx.Configuration; | ||||||
| using CSync.Extensions; | using CSync.Extensions; | ||||||
| using CSync.Lib; | using CSync.Lib; | ||||||
| using LethalConfig; |  | ||||||
| using LethalConfig.ConfigItems; |  | ||||||
| using LethalConfig.ConfigItems.Options; |  | ||||||
| using HarmonyLib; | using HarmonyLib; | ||||||
| using UnityEngine; | using UnityEngine; | ||||||
| using UnityEngine.Networking; | using UnityEngine.Networking; | ||||||
|  | @ -18,10 +15,9 @@ namespace MuzikaGromche | ||||||
| { | { | ||||||
|     [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] |     [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] | ||||||
|     [BepInDependency("com.sigurd.csync", "5.0.1")] |     [BepInDependency("com.sigurd.csync", "5.0.1")] | ||||||
|     [BepInDependency("ainavt.lc.lethalconfig", "1.4.6")] |  | ||||||
|     public class Plugin : BaseUnityPlugin |     public class Plugin : BaseUnityPlugin | ||||||
|     { |     { | ||||||
|         internal new static Config Config { get; private set; } = null; |         internal new static Config Config { get; private set; } = null!; | ||||||
| 
 | 
 | ||||||
|         public static Track[] Tracks = [ |         public static Track[] Tracks = [ | ||||||
|             new Track |             new Track | ||||||
|  | @ -221,12 +217,12 @@ namespace MuzikaGromche | ||||||
|         { |         { | ||||||
|             var buffer = new byte[4 * (1 + Weights.Length)]; |             var buffer = new byte[4 * (1 + Weights.Length)]; | ||||||
|             var offset = 0; |             var offset = 0; | ||||||
|             Buffer.BlockCopy(BitConverter.GetBytes(seed), 0, buffer, offset, sizeof(int)); |             System.Buffer.BlockCopy(BitConverter.GetBytes(seed), 0, buffer, offset, sizeof(int)); | ||||||
|             // Make sure that tweaking weights even a little drastically changes the outcome |             // Make sure that tweaking weights even a little drastically changes the outcome | ||||||
|             foreach (var weight in Weights) |             foreach (var weight in Weights) | ||||||
|             { |             { | ||||||
|                 offset += 4; |                 offset += 4; | ||||||
|                 Buffer.BlockCopy(BitConverter.GetBytes(weight), 0, buffer, offset, sizeof(int)); |                 System.Buffer.BlockCopy(BitConverter.GetBytes(weight), 0, buffer, offset, sizeof(int)); | ||||||
|             } |             } | ||||||
|             var sha = SHA256.Create(); |             var sha = SHA256.Create(); | ||||||
|             var hash = sha.ComputeHash(buffer); |             var hash = sha.ComputeHash(buffer); | ||||||
|  | @ -253,7 +249,7 @@ namespace MuzikaGromche | ||||||
|             return index; |             return index; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private int GetWeightedIndex(int rawIndex) |         private int GetRawIndex(int rawIndex) | ||||||
|         { |         { | ||||||
|             if (rawIndex < 0 || rawIndex >= TotalWeights) |             if (rawIndex < 0 || rawIndex >= TotalWeights) | ||||||
|             { |             { | ||||||
|  | @ -278,7 +274,7 @@ namespace MuzikaGromche | ||||||
|         { |         { | ||||||
|             var hash = GetHash(seed); |             var hash = GetHash(seed); | ||||||
|             var index = GetRawIndex(hash); |             var index = GetRawIndex(hash); | ||||||
|             return GetWeightedIndex(index); |             return GetRawIndex(index); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public override string ToString() |         public override string ToString() | ||||||
|  | @ -292,8 +288,15 @@ namespace MuzikaGromche | ||||||
| 
 | 
 | ||||||
|     public class Config : SyncedConfig2<Config> |     public class Config : SyncedConfig2<Config> | ||||||
|     { |     { | ||||||
|  |         // TODO: Comment out for now | ||||||
|  |         // Personal preferrence, explicitly not synced | ||||||
|  |         public ConfigEntry<bool> DisplayLyrics { get; private set; } | ||||||
|  | 
 | ||||||
|         public Config(ConfigFile configFile) : base(PluginInfo.PLUGIN_GUID) |         public Config(ConfigFile configFile) : base(PluginInfo.PLUGIN_GUID) | ||||||
|         { |         { | ||||||
|  |             // TODO: Comment out for now | ||||||
|  |             DisplayLyrics = configFile.Bind("General", "Display Lyrics", false, "Toggle lyrics display"); | ||||||
|  | 
 | ||||||
|             var chanceRange = new AcceptableValueRange<int>(0, 100); |             var chanceRange = new AcceptableValueRange<int>(0, 100); | ||||||
| 
 | 
 | ||||||
|             foreach (var track in Plugin.Tracks) |             foreach (var track in Plugin.Tracks) | ||||||
|  | @ -303,16 +306,8 @@ namespace MuzikaGromche | ||||||
|                     new ConfigDefinition("Tracks", track.Name), |                     new ConfigDefinition("Tracks", track.Name), | ||||||
|                     50, |                     50, | ||||||
|                     new ConfigDescription(description, chanceRange, track)); |                     new ConfigDescription(description, chanceRange, track)); | ||||||
| 
 |  | ||||||
|                 var slider = new IntSliderConfigItem(track.Weight.Entry, new IntSliderOptions |  | ||||||
|                 { |  | ||||||
|                     RequiresRestart = false, |  | ||||||
|                     CanModifyCallback = CanModifyCallback, |  | ||||||
|                 }); |  | ||||||
|                 LethalConfigManager.AddConfigItem(slider); |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             // HACK because CSync doesn't provide an API to register a list of config entries |  | ||||||
|             foreach (var track in Plugin.Tracks) |             foreach (var track in Plugin.Tracks) | ||||||
|             { |             { | ||||||
|                 // This is basically what ConfigFile.PopulateEntryContainer does |                 // This is basically what ConfigFile.PopulateEntryContainer does | ||||||
|  | @ -320,25 +315,23 @@ namespace MuzikaGromche | ||||||
|                 EntryContainer.Add(entryBase.BoxedEntry.ToSyncedEntryIdentifier(), entryBase); |                 EntryContainer.Add(entryBase.BoxedEntry.ToSyncedEntryIdentifier(), entryBase); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             ConfigManager.Register(this); |             // TODO: Remove debug lines | ||||||
|  |             this.InitialSyncCompleted += (sender, e) => | ||||||
|  |             { | ||||||
|  |                 var weights = string.Join(',', Plugin.Tracks.Select(track => track.Weight.Value)); | ||||||
|  |                 Debug.Log($"MuzikaGromche Sync complete! weights={weights}"); | ||||||
|  |             }; | ||||||
|  | 
 | ||||||
|  |             foreach (var track in Plugin.Tracks) | ||||||
|  |             { | ||||||
|  |                 track.Weight.Changed += (sender, e) => | ||||||
|  |                 { | ||||||
|  |                     var track = (Track)e.ChangedEntry.Entry.Description.Tags[0]; | ||||||
|  |                     Debug.Log($"MuzikaGromche Sync changed {track.Name}: {e.OldValue} -> {e.NewValue}"); | ||||||
|  |                 }; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|         public static CanModifyResult CanModifyCallback() |             ConfigManager.Register(this); | ||||||
|         { |  | ||||||
|             var startOfRound = StartOfRound.Instance; |  | ||||||
|             if (!startOfRound) |  | ||||||
|             { |  | ||||||
|                 return CanModifyResult.True(); // Main menu |  | ||||||
|             } |  | ||||||
|             if (!startOfRound.IsHost) |  | ||||||
|             { |  | ||||||
|                 return CanModifyResult.False("Only for host"); |  | ||||||
|             } |  | ||||||
|             if (!startOfRound.inShipPhase) |  | ||||||
|             { |  | ||||||
|                 return CanModifyResult.False("Only while orbiting"); |  | ||||||
|             } |  | ||||||
|             return CanModifyResult.True(); |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,6 +2,5 @@ | ||||||
| <configuration> | <configuration> | ||||||
|   <packageSources> |   <packageSources> | ||||||
|     <add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" /> |     <add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" /> | ||||||
|     <add key="AAron Thunderstore" value="https://nuget.windows10ce.com/nuget/v3/index.json" /> |  | ||||||
|   </packageSources> |   </packageSources> | ||||||
| </configuration> | </configuration> | ||||||
|  |  | ||||||
|  | @ -6,7 +6,6 @@ | ||||||
|     "website_url": "https://git.vilunov.me/nikita/muzika-gromche", |     "website_url": "https://git.vilunov.me/nikita/muzika-gromche", | ||||||
|     "dependencies": [ |     "dependencies": [ | ||||||
|         "BepInEx-BepInExPack-5.4.2100", |         "BepInEx-BepInExPack-5.4.2100", | ||||||
|         "Sigurd-CSync-5.0.1", |         "Sigurd-CSync-5.0.1" | ||||||
|         "ainavt.lc.lethalconfig-1.4.6" |  | ||||||
|     ] |     ] | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue