-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working character customizer api call
- Loading branch information
Showing
7 changed files
with
111 additions
and
87 deletions.
There are no files selected for viewing
This file contains 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 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 @@ | ||
internal record Environment(string Url, string Token); |
This file contains 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,86 @@ | ||
using System.Text.Json; | ||
using Google.Protobuf; | ||
using Grpc.Core; | ||
using Grpc.Net.Client; | ||
using Sc.External.Services.CharacterCustomizer.V1; | ||
|
||
var env = JsonSerializer.Deserialize<Environment>(File.ReadAllText("env.json")); | ||
if (env == null || string.IsNullOrWhiteSpace(env.Token) || string.IsNullOrWhiteSpace(env.Url)) | ||
{ | ||
Console.WriteLine("Failed to read env.json"); | ||
return; | ||
} | ||
|
||
var creds = CallCredentials.FromInterceptor((_, metadata) => | ||
{ | ||
metadata.Add("Authorization", $"Bearer {env.Token}"); | ||
return Task.CompletedTask; | ||
}); | ||
|
||
var channel = GrpcChannel.ForAddress(env.Url, new GrpcChannelOptions | ||
{ | ||
Credentials = ChannelCredentials.Create(ChannelCredentials.SecureSsl, creds) | ||
}); | ||
var charClient = new CharacterCustomizerService.CharacterCustomizerServiceClient(channel); | ||
|
||
const string testChar = @"C:\Users\Diogo\Downloads\default_f_diff_eyecolor.grpc"; | ||
|
||
var bytes = GrpcToProtoBytes(File.ReadAllBytes(testChar)); | ||
var character = SaveCharacterCustomizationsRequest.Parser.ParseFrom(bytes); | ||
|
||
ChangeDna(character); | ||
ChangeEyeColor(character); | ||
ChangeBodyColor(character); | ||
|
||
var response = charClient.SaveCharacterCustomizations(character); | ||
|
||
Console.WriteLine(response); | ||
return; | ||
|
||
//TODO: make this not stupid | ||
byte[] GrpcToProtoBytes(byte[] proto) | ||
{ | ||
return proto[5..]; | ||
} | ||
|
||
void ChangeDna(SaveCharacterCustomizationsRequest req) | ||
{ | ||
req.CharacterCustomizations.DnaMatrix = ByteString.CopyFrom(Convert.FromHexString( | ||
"9493d0fc54ebf49e0452d765000000000c00040004000000feff1700feff1700feff1700feff1700feff1700feff1700feff1700feff1700feff1700feff1700feff1700feff1700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); | ||
} | ||
|
||
void ChangeEyeColor(SaveCharacterCustomizationsRequest saveCharacterCustomizationsRequest) | ||
{ | ||
ChangeColorWithId(saveCharacterCustomizationsRequest, 0x442a34ac, 214, 30, 30); | ||
} | ||
|
||
void ChangeBodyColor(SaveCharacterCustomizationsRequest saveCharacterCustomizationsRequest) | ||
{ | ||
//only changes head for now, todo | ||
ChangeColorWithId(saveCharacterCustomizationsRequest, 0xbd530797, 30, 30, 200); | ||
} | ||
|
||
void ChangeColorWithId(SaveCharacterCustomizationsRequest req, uint id, byte r, byte g, byte b) | ||
{ | ||
var materialParams = req.CharacterCustomizations.CustomMaterialParams; | ||
if (materialParams == null) | ||
return; | ||
|
||
var copy = new byte[materialParams.Length]; | ||
materialParams.CopyTo(copy, 0); | ||
var span = copy.AsSpan(); | ||
ReadOnlySpan<byte> colorKey = BitConverter.GetBytes(id); | ||
|
||
var colorIndex = span.IndexOf(colorKey); | ||
if (colorIndex == -1) | ||
return; | ||
|
||
var colorLocation = colorIndex + colorKey.Length; | ||
span[colorLocation + 0] = r; //R | ||
span[colorLocation + 1] = g; //G | ||
span[colorLocation + 2] = b; //B | ||
span[colorLocation + 3] = 0xFF; //A | ||
|
||
req.CharacterCustomizations.CustomMaterialParams = ByteString.CopyFrom(copy); | ||
} |
This file contains 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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\StarBreaker.Grpc\StarBreaker.Grpc.csproj"/> | ||
<Content Include="env.json" CopyToOutputDirectory="PreserveNewest"/> | ||
</ItemGroup> | ||
|
||
|
||
</Project> |
This file was deleted.
Oops, something went wrong.
This file contains 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 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