Skip to content

Commit

Permalink
Merge pull request #63 from BigBang1112/dev
Browse files Browse the repository at this point in the history
GBX.NET 1.1.1
  • Loading branch information
BigBang1112 authored Dec 30, 2022
2 parents 531be51 + b9c380c commit c22ea2d
Show file tree
Hide file tree
Showing 37 changed files with 870 additions and 399 deletions.
50 changes: 1 addition & 49 deletions .github/workflows/deploy-gbxexplorer-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,51 +66,9 @@ jobs:
name: app
path: publish/wwwroot
retention-days: 1

build-docs:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Clone wiki
run: |
git clone https://github.com/BigBang1112/gbx-net.wiki.git wiki
cp -r wiki/* Docs/wiki
- name: Create global.json
uses: 1arp/create-a-file-action@0.2
with:
path: Docs
file: global.json
content: |
{
"_gitContribute": {
"repo": "https://github.com/BigBang1112/gbx-net",
"branch": "${{ github.ref_name }}"
}
}
- name: Generate docs
uses: nikeee/docfx-action@v1.0.0
with:
args: Docs/docfx.json --globalMetadataFiles global.json

- name: Copy docs to root
run: cp -r Docs/_site docs

- name: Upload docs artifact
uses: actions/upload-artifact@v3.1.0
with:
name: docs
path: docs
retention-days: 1

deploy:
needs: [build-gbxexplorer, build-docs]
needs: build-gbxexplorer

environment:
name: github-pages
Expand All @@ -123,12 +81,6 @@ jobs:
uses: actions/download-artifact@v3.0.0
with:
name: app

- name: Download docs artifact
uses: actions/download-artifact@v3.0.0
with:
name: docs
path: docs

- name: Setup Pages
uses: actions/configure-pages@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Here are some of the useful classes/types to start with:
- Current C# language version is **11**.

To build the solution:
- Installing Visual Studio 2022 with default .NET tools, **.NET WebAssembly Build Tools**, and **.NET Framework 4.6.2 Targeting Pack** is the easiest option.
- Installing Visual Studio 2022 with default .NET tools, **.NET WebAssembly Build Tools**, **.NET Core 3.1 Runtime**, and **.NET Framework 4.6.2 Targeting Pack** is the easiest option.
- JetBrains Rider also works as it should. Visual Studio Code may work with a bit more setup.
- Make sure you have all the needed targetting packs installed (currently **.NET 7.0**, .NET 6.0, .NET Standard 2.1, .NET Standard 2.0, and .NET Framework 4.6.2).

Expand Down
2 changes: 1 addition & 1 deletion Samples/BlocksAndTheirClipsTM2020/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Ground = CreateVariant(blockInfo.VariantBaseGround)
};

dict.Add(blockInfo.Author.Id, block);
dict.Add(blockInfo.Ident.Id, block);
}
catch (NotAGbxException)
{
Expand Down
2 changes: 1 addition & 1 deletion Src/GBX.NET.PAK/GBX.NET.PAK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<Version>1.1.1</Version>
<Version>1.1.2</Version>
<PackageReleaseNotes></PackageReleaseNotes>

<TargetFrameworks>net7.0;net6.0;netstandard2.1;netstandard2.0;net462</TargetFrameworks>
Expand Down
44 changes: 29 additions & 15 deletions Src/GBX.NET.PAK/NadeoPakFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,40 @@ public Stream Open()

public string GetFullFileName()
{
if (Folder == null) return Name;

var currentParent = Folder;
var folders = new List<string>
{
Name
};
return Path.Combine(GetDirectoryName(), Name);
}

while (currentParent != null)
{
folders.Insert(0, currentParent.Name);
currentParent = currentParent.Parent;
}
/// <summary>
/// Gets the directory name (relative to the PAK file), also including directories in <see cref="Name"/>.
/// </summary>
/// <returns>A full directory name.</returns>
public string GetFullDirectoryName()
{
return Path.GetDirectoryName(GetFullFileName()) ?? "";
}

return Path.Combine(folders.ToArray());
/// <summary>
/// Gets the directory name (relative to the PAK file), not part of the <see cref="Name"/> itself.
/// </summary>
/// <returns></returns>
public string GetDirectoryName()
{
#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER
return string.Join(Path.DirectorySeparatorChar, GetParentDirectories().Reverse());
#else
return Path.Combine(GetParentDirectories().Reverse().ToArray());
#endif
}

public string? GetFullDirectoryName()
private IEnumerable<string> GetParentDirectories()
{
return Path.GetDirectoryName(GetFullFileName());
var currentParent = Folder;

while (currentParent is not null)
{
yield return currentParent.Name;
currentParent = currentParent.Parent;
}
}

public string GetFileName()
Expand Down
83 changes: 83 additions & 0 deletions Src/GBX.NET/BitReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
namespace GBX.NET;

public class BitReader
{
private readonly byte[] data;

public int Position { get; private set; }
public int Length { get; }

public BitReader(byte[] data)
{
this.data = data;

Length = data.Length * 8;
}

private bool ReadBit(ReadOnlySpan<byte> data)
{
var result = (data[Position / 8] & (1 << (Position % 8))) != 0;
Position++;
return result;
}

public bool ReadBit()
{
return ReadBit(data);
}

public ulong ReadNumber(int bits)
{
ulong result = 0;

ReadOnlySpan<byte> dataSpan = data;

for (var i = 0; i < bits; i++)
{
result |= (ulong)(ReadBit(dataSpan) ? 1 : 0) << i;
}

return result;
}

public byte Read2Bit()
{
return (byte)ReadNumber(bits: 2);
}

public byte ReadByte()
{
return (byte)ReadNumber(bits: 8);
}

public sbyte ReadSByte()
{
return (sbyte)ReadNumber(bits: 8);
}

public short ReadInt16()
{
return (short)ReadNumber(bits: 16);
}

public ushort ReadUInt16()
{
return (ushort)ReadNumber(bits: 16);
}

public int ReadInt32()
{
return (int)ReadNumber(bits: 32);
}

// ReadToEnd through bits

public byte[] ReadToEnd()
{
var remaining = Length - Position;
var result = new byte[(remaining + 7) / 8];
for (var i = 0; i < remaining; i++)
result[i / 8] |= (byte)((ReadBit() ? 1 : 0) << (i % 8));
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace GBX.NET.Builders.Engines.Game;

public partial class CGameCtnMediaBlockTriangles3DBuilder
{
public class TMUF : GameBuilder<CGameCtnMediaBlockTriangles3DBuilder, CGameCtnMediaBlockTriangles3D>
{
public IList<CGameCtnMediaBlockTriangles.Key>? Keys { get; set; }

public TMUF(CGameCtnMediaBlockTriangles3DBuilder baseBuilder, CGameCtnMediaBlockTriangles3D node) : base(baseBuilder, node) { }

public TMUF WithKeys(Func<CGameCtnMediaBlockTriangles3D, IList<CGameCtnMediaBlockTriangles.Key>> keys)
{
Keys = keys(Node);
return this;
}

public override CGameCtnMediaBlockTriangles3D Build()
{
Node.Keys = Keys ?? new List<CGameCtnMediaBlockTriangles.Key>();
return Node;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace GBX.NET.Builders.Engines.Game;

public partial class CGameCtnMediaBlockTriangles3DBuilder : Builder
{
public Vec4[] Vertices { get; }
public Int3[]? Triangles { get; set; }

/// <param name="vertices">Array of vertex colors.</param>
public CGameCtnMediaBlockTriangles3DBuilder(Vec4[] vertices)
{
Vertices = vertices;
}

public CGameCtnMediaBlockTriangles3DBuilder WithTriangles(Int3[] triangles)
{
Triangles = triangles;
return this;
}

public TMUF ForTMUF() => new(this, NewNode());

internal CGameCtnMediaBlockTriangles3D NewNode()
{
var node = new CGameCtnMediaBlockTriangles3D
{
Vertices = Vertices,
Triangles = Triangles ?? Array.Empty<Int3>()
};

node.CreateChunk<CGameCtnMediaBlockTriangles.Chunk03029001>();

return node;
}
}
24 changes: 17 additions & 7 deletions Src/GBX.NET/Engines/Control/CControlEffectSimi.Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,28 @@ public override void ReadWrite(GameBoxReaderWriter rw, int version)
{
base.ReadWrite(rw, version);

// GmSimi2::Archive
rw.Vec2(ref position);
rw.Single(ref rotation);
rw.Vec2(ref scale);
rw.Single(ref opacity);
rw.Single(ref depth);
//

if (version != 2)
if (version >= 1)
{
rw.Single(ref U01);
rw.Single(ref isContinuousEffect);
rw.Single(ref U02);
rw.Single(ref U03);
rw.Single(ref opacity);

if (version >= 2)
{
rw.Single(ref depth);

if (version >= 3)
{
rw.Single(ref U01);
rw.Single(ref isContinuousEffect);
rw.Single(ref U02);
rw.Single(ref U03);
}
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions Src/GBX.NET/Engines/Control/CControlEffectSimi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ public static CControlEffectSimiBuilder Create()

#region Chunks

#region 0x001 chunk

/// <summary>
/// CControlEffectSimi 0x001 chunk
/// </summary>
[Chunk(0x07010001)]
public class Chunk07010001 : Chunk<CControlEffectSimi>
{
public override void ReadWrite(CControlEffectSimi n, GameBoxReaderWriter rw)
{
rw.List<Key>(ref n.keys!, (rw, x) => x.ReadWrite(rw, version: 1));
rw.Boolean(ref n.centered);
}
}

#endregion

#region 0x002 chunk

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Src/GBX.NET/Engines/Game/CGameCtnChallenge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4470,14 +4470,14 @@ public override void Write(CGameCtnChallenge n, GameBoxWriter w)
{
var gbxItem = item.GetGbx() ?? throw new ThisShouldNotHappenException();

if (item.Author is null)
if (item.Ident is null)
{
continue;
}

if (gbxItem.FileName is null)
{
embedded.Add(item.Author);
embedded.Add(item.Ident);
continue;
}

Expand All @@ -4494,7 +4494,7 @@ public override void Write(CGameCtnChallenge n, GameBoxWriter w)
}
}

embedded.Add(item.Author with { Id = id });
embedded.Add(item.Ident with { Id = id });
}

writer.WriteList(embedded, (x, w) => w.Write(x));
Expand Down
Loading

0 comments on commit c22ea2d

Please sign in to comment.