Skip to content

Commit

Permalink
[BREAKING] FMV now targets x64; Fix cat bug (krkr type)
Browse files Browse the repository at this point in the history
  • Loading branch information
UlyssesWu committed Oct 8, 2024
1 parent 7b8e4cb commit 5bf6fee
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 7 deletions.
1 change: 1 addition & 0 deletions FreeMote.PsBuild/Converters/Krkr2CommonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void Convert(PSB psb)
Travel((PsbDictionary) psb.Objects["object"], iconInfo);
Add(psb);
TranslateTimeline(psb);
psb.FixTimelineContentValueType(); // ur cats are broken SYR
psb.Platform = ToWin ? PsbSpec.win : PsbSpec.common;
}

Expand Down
36 changes: 36 additions & 0 deletions FreeMote.Psb/PsbExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,42 @@ public static bool FixMotionMetadata(this PSB psb)
return false;
}

public static bool FixTimelineContentValueType(this PSB psb)
{
bool hasError = false;
if (psb.Objects.FindByPath("/metadata/timelineControl") is PsbList list)
{
foreach (var timeline in list)
{
if (timeline is PsbDictionary t && t.ContainsKey("variableList") && t["variableList"] is PsbList vl)
{
foreach (var variable in vl)
{
if (variable is PsbDictionary varDic && varDic.ContainsKey("frameList") && varDic["frameList"] is PsbList frameList)
{
foreach (var c in frameList)
{
if (c is PsbDictionary c1 && c1.ContainsKey("content") && c1["content"] is PsbDictionary content && content.ContainsKey("value") && content["value"] is PsbString s)
{
if (int.TryParse(s, out var v))
{
content["value"] = v.ToPsbNumber();
}
else
{
hasError = true;
}
}
}
}
}
}
}
}

return !hasError;
}

/// <summary>
/// Try to measure EMT PSB Canvas Size
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions FreeMote.Tools.EmtConvert/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public enum PsbFixMethod
/// Fix [/metadata/base/motion] missing issue for partial exported motion PSB
/// </summary>
MetadataBase,
/// <summary>
/// Fix [/metadata/timelineControl/variableList/frameList/content/value] type error appeared in Cat Hell series. WTF Sayori
/// </summary>
KrkrTimelineTypeError
}

class Program
Expand Down Expand Up @@ -486,6 +490,21 @@ EmtConvert fix -m MetadataBase sample.psb
}
}
break;
case PsbFixMethod.KrkrTimelineTypeError:
{
Console.Write($"Using {method} to fix {s} ...");
PSB psb = new PSB(s);
if (psb.FixTimelineContentValueType())
{
psb.BuildToFile(Path.ChangeExtension(s, ".fixed.psb"));
Console.WriteLine("Fixed!");
}
else
{
Console.WriteLine("not fixed.");
}
}
break;
default:
Logger.LogError($"Not implemented method: {method}");
break;
Expand Down
12 changes: 10 additions & 2 deletions FreeMote.Tools.Viewer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int Main(string[] args)
var optWidth = app.Option<uint>("-w|--width", "Set Window width", CommandOptionType.SingleValue);
var optHeight = app.Option<uint>("-h|--height", "Set Window height", CommandOptionType.SingleValue);
var optDirectLoad = app.Option("-d|--direct", "Just load with EMT driver, don't try parsing with FreeMote first", CommandOptionType.NoValue);
var optFixMetadata = app.Option("-nf|--no-fix", "Don't try to apply metadata fix (for partial exported PSBs). Can't work together with `-d`", CommandOptionType.NoValue);
var optFixMetadata = app.Option("-nf|--no-fix", "Don't try to apply metadata fix (for partial exported or krkr PSBs). Can't work together with `-d`", CommandOptionType.NoValue);

//args
var argPath = app.Argument("Files", "File paths", multipleValues: true);
Expand Down Expand Up @@ -99,7 +99,15 @@ static int Main(string[] args)
if (!optFixMetadata.HasValue())
{
psb.FixMotionMetadata();
try
{
psb.FixMotionMetadata();
//psb.FixTimelineContentValueType();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
psb.Merge();
Expand Down
6 changes: 2 additions & 4 deletions FreeMote.Tools.Viewer/FreeMote.Tools.Viewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
</PropertyGroup>
<PropertyGroup>
<StartupObject>FreeMote.Tools.Viewer.Program</StartupObject>
<PlatformTarget>x86</PlatformTarget>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FreeMote.NET">
<Version>3.9.0</Version>
</PackageReference>
<PackageReference Include="FreeMote.NET.x64" Version="3.9.7" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils">
<Version>3.0.0</Version>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion FreeMote.Tools.Viewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ private void BeginRenderingScene()
if (_di.IsFrontBufferAvailable)
{
// create a custom D3D scene and get a pointer to its surface
_scene = new IntPtr(_emote.D3DSurface);
_scene = _emote.D3DSurface;

// set the back buffer using the new scene pointer
_di.Lock();
Expand Down

0 comments on commit 5bf6fee

Please sign in to comment.