Skip to content

Commit 813de73

Browse files
committed
Squashed commit of the following:
commit ae66f37 Author: kenjiuno <[email protected]> Date: Fri Dec 11 12:27:14 2020 +0900 Update doc. commit 5513b40 Author: kenjiuno <[email protected]> Date: Fri Dec 11 12:00:34 2020 +0900 Refactoring MapTexFooter to TexFooter. commit f4a071c Author: kenjiuno <[email protected]> Date: Fri Dec 11 11:45:11 2020 +0900 Adding r/w consistency tests. commit b678b58 Author: kenjiuno <[email protected]> Date: Fri Dec 11 01:06:24 2020 +0900 Fix errors. commit 995f473 Author: kenjiuno <[email protected]> Date: Fri Dec 11 00:35:58 2020 +0900 Add consistency tests for local. commit dc3fdc7 Author: kenjiuno <[email protected]> Date: Thu Dec 10 22:35:48 2020 +0900 Fix some bugs. commit 3c7504a Author: kenjiuno <[email protected]> Date: Thu Dec 10 22:18:24 2020 +0900 2 integers after _KN5 of Model commit 79095c7 Author: kenjiuno <[email protected]> Date: Thu Dec 10 02:41:00 2020 +0900 Implement import to OpenKh.Command.MapTexFooter. commit dd8ea49 Author: kenjiuno <[email protected]> Date: Thu Dec 10 00:17:47 2020 +0900 Add export to OpenKh.Command.MapTexFooter. commit 950e58a Author: kenjiuno <[email protected]> Date: Mon Dec 7 20:13:04 2020 +0900 Decode FooterData of model texture
1 parent 6c8b3d2 commit 813de73

32 files changed

+1581
-19
lines changed

OpenKh.Command.MapGen/Models/MapGenConfig.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ public class BarEntryConfig
7575

7676
public bool reuseImd { get; set; }
7777

78+
public List<UvscItem> uvscList { get; set; } = new List<UvscItem>();
79+
80+
public class UvscItem
81+
{
82+
/// <summary>
83+
/// 0 to 15
84+
/// </summary>
85+
public int index { get; set; }
86+
public float u { get; set; }
87+
public float v { get; set; }
88+
}
89+
7890
public MaterialDef FindMaterial(string name)
7991
{
8092
return materials

OpenKh.Command.MapGen/Models/MaterialDef.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public class MaterialDef
6666

6767
public short? transparentFlag { get; set; }
6868

69+
public int? uvscIndex { get; set; }
70+
6971
public static MaterialDef CreateFallbackFor(string name) =>
7072
new MaterialDef
7173
{

OpenKh.Command.MapGen/Utils/MapBuilder.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using NLog;
1+
using NLog;
22
using OpenKh.Command.MapGen.Models;
33
using OpenKh.Kh2;
4+
using OpenKh.Kh2.TextureFooter;
45
using System;
56
using System.Collections.Generic;
67
using System.IO;
@@ -50,6 +51,23 @@ public MapBuilder(string modelFile, MapGenConfig config, Func<MaterialDef, Imgd>
5051
.Select(matDef => new ImageSet { image = imageLoader(matDef), matDef = matDef, })
5152
.ToArray();
5253

54+
var footerData = new MemoryStream();
55+
{
56+
var footer = new TextureFooterData();
57+
foreach (var uvscItem in config.uvscList)
58+
{
59+
footer.UvscList.Add(
60+
new UvScroll
61+
{
62+
TextureIndex = uvscItem.index,
63+
UScrollSpeed = uvscItem.u,
64+
VScrollSpeed = uvscItem.v,
65+
}
66+
);
67+
}
68+
footer.Write(footerData);
69+
}
70+
5371
var build = new ModelTexture.Build
5472
{
5573
images = imageSets
@@ -81,6 +99,8 @@ public MapBuilder(string modelFile, MapGenConfig config, Func<MaterialDef, Imgd>
8199
}
82100
)
83101
.ToArray(),
102+
103+
footerData = footerData.ToArray(),
84104
};
85105

86106
modelTex = new ModelTexture(build);
@@ -266,6 +286,8 @@ private void ConvertModelIntoMapModel(string modelFile, MapGenConfig config)
266286
0,
267287
},
268288
IsTransparentFlag = smallMesh.matDef.transparentFlag ?? 0,
289+
EnableUvsc = smallMesh.matDef.uvscIndex.HasValue,
290+
UvscIndex = smallMesh.matDef.uvscIndex ?? 0,
269291
}
270292
);
271293
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
4+
using System.Text;
5+
6+
namespace OpenKh.Command.TexFooter.Interfaces
7+
{
8+
public interface ISpriteImageSource
9+
{
10+
/// <summary>
11+
/// Only 4 or 8
12+
/// </summary>
13+
int BitsPerPixel { get; }
14+
15+
/// <summary>
16+
/// Width is 32, 64, or such.
17+
/// </summary>
18+
Size Size { get; }
19+
20+
/// <summary>
21+
/// For 4bpp: pass swapped data. 0x12 0x34 is [2, 1, 4, 3]
22+
/// For 8bpp: pass platform native data. 0x12 0x34 is [0x12, 0x34]
23+
/// </summary>
24+
byte[] Data { get; }
25+
}
26+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using OpenKh.Kh2.TextureFooter;
2+
using System;
3+
using System.Linq;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
using YamlDotNet.Core;
7+
using YamlDotNet.Serialization;
8+
using OpenKh.Imaging;
9+
using OpenKh.Command.TexFooter.Interfaces;
10+
11+
namespace OpenKh.Command.TexFooter.Models
12+
{
13+
public class TextureAnimationIMEx
14+
{
15+
public ushort Unk1 { get; set; }
16+
public ushort TextureIndex { get; set; }
17+
public ushort FrameStride { get; set; }
18+
public ushort BaseSlotIndex { get; set; }
19+
20+
public string SpriteImageFile { get; set; }
21+
public ushort NumSpritesInImageData { get; set; }
22+
public ushort UOffsetInBaseImage { get; set; }
23+
public ushort VOffsetInBaseImage { get; set; }
24+
25+
public int DefaultAnimationIndex { get; set; }
26+
27+
public short[] SlotTable { get; set; }
28+
public TextureFrameGroup[] FrameGroupList { get; set; }
29+
30+
internal TextureAnimation _source;
31+
32+
public TextureAnimationIMEx()
33+
{
34+
35+
}
36+
37+
public TextureAnimationIMEx(TextureAnimation src)
38+
{
39+
_source = src;
40+
41+
Unk1 = src.Unk1;
42+
TextureIndex = src.TextureIndex;
43+
FrameStride = src.FrameStride;
44+
BaseSlotIndex = src.BaseSlotIndex;
45+
NumSpritesInImageData = src.NumSpritesInImageData;
46+
UOffsetInBaseImage = src.UOffsetInBaseImage;
47+
VOffsetInBaseImage = src.VOffsetInBaseImage;
48+
DefaultAnimationIndex = src.DefaultAnimationIndex;
49+
SlotTable = src.SlotTable;
50+
FrameGroupList = src.FrameGroupList;
51+
}
52+
53+
public TextureAnimation ConvertBack(Func<string, ISpriteImageSource> imageLoader)
54+
{
55+
var spriteImage = imageLoader(SpriteImageFile);
56+
var bitsPerPixel = spriteImage.BitsPerPixel;
57+
58+
var back = new TextureAnimation
59+
{
60+
Unk1 = Unk1,
61+
TextureIndex = TextureIndex,
62+
FrameStride = FrameStride,
63+
BitsPerPixel = Convert.ToUInt16(bitsPerPixel),
64+
BaseSlotIndex = BaseSlotIndex,
65+
MaximumSlotIndex = Convert.ToUInt16(BaseSlotIndex + SlotTable.Length - 1),
66+
67+
NumAnimations = Convert.ToUInt16(FrameGroupList.Length),
68+
NumSpritesInImageData = NumSpritesInImageData,
69+
UOffsetInBaseImage = UOffsetInBaseImage,
70+
VOffsetInBaseImage = VOffsetInBaseImage,
71+
SpriteWidth = Convert.ToUInt16(spriteImage.Size.Width),
72+
SpriteHeight = Convert.ToUInt16(spriteImage.Size.Height / NumSpritesInImageData),
73+
74+
OffsetSlotTable = 0,
75+
76+
OffsetAnimationTable = 0,
77+
78+
OffsetSpriteImage = 0,
79+
DefaultAnimationIndex = DefaultAnimationIndex,
80+
81+
SlotTable = SlotTable,
82+
FrameGroupList = FrameGroupList,
83+
SpriteImage = spriteImage.Data,
84+
};
85+
86+
return back;
87+
}
88+
}
89+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using OpenKh.Command.TexFooter.Interfaces;
2+
using OpenKh.Imaging;
3+
using OpenKh.Kh2.TextureFooter;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
9+
namespace OpenKh.Command.TexFooter.Models
10+
{
11+
public class TextureFooterDataIMEx
12+
{
13+
public List<UvScroll> UvscList { get; set; }
14+
public List<TextureAnimationIMEx> TextureAnimationList { get; set; }
15+
public byte[] UnkFooter { get; set; }
16+
public bool ShouldEmitDMYAtFirst { get; set; }
17+
public bool ShouldEmitKN5 { get; set; }
18+
19+
public TextureFooterDataIMEx()
20+
{
21+
22+
}
23+
24+
public TextureFooterDataIMEx(TextureFooterData footerData)
25+
{
26+
UvscList = footerData.UvscList.ToList();
27+
TextureAnimationList = footerData.TextureAnimationList.Select(it => new TextureAnimationIMEx(it)).ToList();
28+
UnkFooter = footerData.UnkFooter;
29+
ShouldEmitDMYAtFirst = footerData.ShouldEmitDMYAtFirst;
30+
ShouldEmitKN5 = footerData.ShouldEmitKN5;
31+
}
32+
33+
public TextureFooterData ConvertBack(Func<string, ISpriteImageSource> imageLoader)
34+
{
35+
var back = new TextureFooterData();
36+
back.UvscList.AddRange(UvscList);
37+
back.TextureAnimationList.AddRange(
38+
TextureAnimationList
39+
.Select(texa => texa.ConvertBack(imageLoader))
40+
);
41+
back.UnkFooter = UnkFooter;
42+
back.ShouldEmitDMYAtFirst = ShouldEmitDMYAtFirst;
43+
back.ShouldEmitKN5 = ShouldEmitKN5;
44+
return back;
45+
}
46+
}
47+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.0.0" />
10+
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
11+
<PackageReference Include="YamlDotNet" Version="9.1.0" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\nQuant\nQuant.Core\nQuant.Core.csproj" />
16+
<ProjectReference Include="..\OpenKh.Kh2\OpenKh.Kh2.csproj" />
17+
<ProjectReference Include="..\OpenKh.Tools.Common\OpenKh.Tools.Common.csproj" />
18+
</ItemGroup>
19+
20+
</Project>

OpenKh.Command.TexFooter/Program.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using McMaster.Extensions.CommandLineUtils;
2+
using System;
3+
using System.IO;
4+
using System.Reflection;
5+
using OpenKh.Command.TexFooter.Subcommands;
6+
7+
namespace OpenKh.Command.TexFooter
8+
{
9+
[Command("OpenKh.Command.TexFooter")]
10+
[VersionOptionFromMember("--version", MemberName = nameof(GetVersion))]
11+
[Subcommand(typeof(ExportCommand), typeof(ImportCommand))]
12+
class Program
13+
{
14+
static int Main(string[] args)
15+
{
16+
try
17+
{
18+
return CommandLineApplication.Execute<Program>(args);
19+
}
20+
catch (FileNotFoundException e)
21+
{
22+
Console.WriteLine($"The file {e.FileName} cannot be found. The program will now exit.");
23+
return 1;
24+
}
25+
catch (Exception e)
26+
{
27+
Console.WriteLine($"FATAL ERROR: {e.Message}\n{e.StackTrace}");
28+
return 1;
29+
}
30+
}
31+
32+
protected int OnExecute(CommandLineApplication app)
33+
{
34+
app.ShowHelp();
35+
return 1;
36+
}
37+
38+
private static string GetVersion()
39+
=> typeof(Program).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
40+
}
41+
}

0 commit comments

Comments
 (0)