Skip to content

Commit

Permalink
Merge pull request #11 from asesidaa/AIBattle
Browse files Browse the repository at this point in the history
Ai battle
  • Loading branch information
asesidaa authored Sep 24, 2022
2 parents 6fc4e4f + 49cabdd commit 799eb85
Show file tree
Hide file tree
Showing 72 changed files with 1,946 additions and 334 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,5 @@ FodyWeavers.xsd
*.msp

# JetBrains Rider
*.sln.iml
*.sln.iml
TaikoLocalServer/wwwroot/data/music_attribute.bin
95 changes: 95 additions & 0 deletions OldSetup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Old setup

1. Download the latest release of [TaikoArcadeLoader](https://github.com/BroGamer4256/TaikoArcadeLoader) and install it. Make sure to setup TAL using the config.toml and set the `server` parameter to your local IP address.
2. Download the latest release of [TaikoReverseProxy](https://github.com/shiibe/TaikoReverseProxy).
3. In the `Data\x64\datatable` folder of the game, find the following files:

```
music_attribute.bin
musicinfo.bin
music_order.bin
wordlist.bin
```
Extract them (you can use [7zip](https://www.7-zip.org)) and rename the extracted file like so:
```
music_attribute -> music_attribute.json
musicinfo -> musicinfo.json
music_order -> music_order.json
wordlist -> wordlist.json
```
Then put these in TaikoLocalServer's `wwwroot/data` folder.
4. Modify hosts, add the following entries (this step can be done automatically with TaikoReverseProxy, check the config for it):
```
server.ip tenporouter.loc
server.ip naominet.jp
server.ip v402-front.mucha-prd.nbgi-amnet.jp
server.ip vsapi.taiko-p.jp
```
where `server.ip` is your computer's ip (or the server's ip)
5. Open command prompt as admin, navigate to game root folder (where init.ps1 is). Run `regsvr32 .\AMCUS\iauthdll.dll`. It should prompt about success
6. Run TaikoReverseProxy and TaikoLocalServer, then run the game. You can access the WebUI by going to `https://naominet.jp:10122/` in your browser.
### Server setup (for TAL<2.00 or other loaders)
1. Download the server from release page, extract anywhere
2. From game's `Data\x64\datatable` folder, find `music_attribute.bin`, `musicinfo.bin`, `music_order.bin` and `wordlist.bin`, decompress them, add `.json` prefix to them.
The result is `music_attribute.json`, `musicinfo.json`, `music_order.json` and `wordlist.json`. Put the json files under` wwwroot/data` folder in server.
3. Modify hosts, add the following entries:
```
server.ip tenporouter.loc
server.ip naominet.jp
server.ip v402-front.mucha-prd.nbgi-amnet.jp
server.ip vsapi.taiko-p.jp
```
where `server.ip` is your computers ip (or the server's ip)
4. Setup [TaikoReverseProxy](https://github.com/shiibe/TaikoReverseProxy) or [Apache](#apache-setup-optional) as reverse proxy.
5. Now run the server, if everything is setup correctly, visit http://localhost:5000, you should be able to see the web ui up and running without errors. (If you encounter errors in web ui for the first time, try visit https://naominet.jp:10122/)
6. Go to game folder, copy the config files (AMConfig.ini and WritableConfig.ini) in the AMCUS folder from server release to AMCUS folder and replace the original ones.
7. Open command prompt as admin, navigate to game root folder (where init.ps1 is). Run `regsvr32 .\AMCUS\iauthdll.dll`. It should prompt about success.
8. Run AMCUS/AMAuthd.exe, then run AMCUS/AMUpdater.exe. If the updater run and exits without issue, you are ready to run the game and connect to server.
9. Run the game, it should now connect to the server.
### Run the server on another computer
If you want to run the server on another computer, the procedure is almost identical.
Before you open browser, in `wwwroot/appsettings.json`, change `BaseUrl` to `https://naominet.jp:10122` then instead of visit localhost, visit the server using domain name to test.
Also note that now the cetificate also need to be imported on client computer, or web ui may not work. If you don't need https, change `BaseUrl` to `http://server.ip:80`, and visit on client. The game does not care about certificate.
### Apache Setup (Optional)
Notice the following assumes a windows install, the server also works on Linux, but the guide only covers windows.
1. Download [Apache](https://www.apachelounge.com/download/), extract anywhere
2. Copy the content in release rar's Apache folder to installed Apache root folder (and replace, which includes httpd.conf and httpd-vhosts.conf, if no prompt to replace files, you are extracting to wrong folder)
3. Open `conf/httpd.conf` (under installed Apache folder), find this line (line 37 by default), modify it to your Apache install (extracted) full path
```htaccess
# For example, if your Apache is extracted to C:\users\username\Apache24, then this should be "c:/users/username/Apache24"
Define SRVROOT "d:/Projects/Apache24"
```

4. Open the certs folder Apache root folder, then click on the localhost.crt file and import it to trusted root store.

If everything is correct, run bin/httpd.exe, a command prompt will open (and stay open, if it shut down, probably something is not setup correctly)
106 changes: 19 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,106 +8,38 @@ This is a server for Taiko no Tatsujin Nijiiro ver 08.18

- A working game, with dongle and card reader emulation. You can use [TaikoArcadeLoader](https://github.com/BroGamer4256/TaikoArcadeLoader) for these if you haven't.

### Tools

- [TaikoArcadeLoader](https://github.com/BroGamer4256/TaikoArcadeLoader): A loader for the game with hardware emulation and other fixes.
- [TaikoReverseProxy](https://github.com/shiibe/TaikoReverseProxy): A no-setup bundled proxy server, use as a user-friendly alternative to Apache.

### Quick Setup

With the newest release (>=2.00) of TaikoArcadeLoader, you no longer need to run AMAuthd or AMUpdater.

1. Download the latest release of [TaikoArcadeLoader](https://github.com/BroGamer4256/TaikoArcadeLoader) and install it. Make sure to setup TAL using the config.toml and set the `server` parameter to your local IP address.
2. Download the latest release of [TaikoReverseProxy](https://github.com/shiibe/TaikoReverseProxy).
3. In the `Data\x64\datatable` folder of the game, find the following files:

```
music_attribute.bin
musicinfo.bin
music_order.bin
wordlist.bin
```
Extract them (you can use [7zip](https://www.7-zip.org)) and rename the extracted file like so:
```
music_attribute -> music_attribute.json
musicinfo -> musicinfo.json
music_order -> music_order.json
wordlist -> wordlist.json
```
Then put these in TaikoLocalServer's `wwwroot/data` folder.
With the newest release (from [this](https://github.com/BroGamer4256/TaikoArcadeLoader/tree/95d633850d89cb7099e98ffe74cd23632fe26e56) commit) of TaikoArcadeLoader, you no longer need to run AMAuthd, AMUpdater or reverse proxy.

4. Modify hosts, add the following entries (this step can be done automatically with TaikoReverseProxy, check the config for it):
1. Extract the server release anywhere

```
server.ip tenporouter.loc
server.ip naominet.jp
server.ip v402-front.mucha-prd.nbgi-amnet.jp
server.ip vsapi.taiko-p.jp
```
where `server.ip` is your computer's ip (or the server's ip)
5. Open command prompt as admin, navigate to game root folder (where init.ps1 is). Run `regsvr32 .\AMCUS\iauthdll.dll`. It should prompt about success
2. From the game files, copy `music_attribute.bin`, `music_order.bin`, `musicinfo.bin` and `wordlist.bin` to `wwwroot/data` folder.

6. Run TaikoReverseProxy and TaikoLocalServer, then run the game. You can access the WebUI by going to `https://naominet.jp:10122/` in your browser.
3. (Optional) Instead of direct copy, extract the specified game files (using 7zip), rename them by adding the file extension `.json` and copy the jsons over.

4. (Optional) In `Certificates` folder, import `root.pfx` to trusted root store, `cert.pfx` to personal store. All the other import options can be kept default.

### Server setup (for TAL<2.00 or other loaders)
5. Visit http://localhost:5000 and (Optional, only if you have done step 4) https://localhost:10122, if the web ui starts without errors, the config is fine.

1. Download the server from release page, extract anywhere
6. Modify comfig.toml from TAL, edit the following line:

2. From game's `Data\x64\datatable` folder, find `music_attribute.bin`, `musicinfo.bin`, `music_order.bin` and `wordlist.bin`, decompress them, add `.json` prefix to them.
The result is `music_attribute.json`, `musicinfo.json`, `music_order.json` and `wordlist.json`. Put the json files under` wwwroot/data` folder in server.
3. Modify hosts, add the following entries:
```
server.ip tenporouter.loc
server.ip naominet.jp
server.ip v402-front.mucha-prd.nbgi-amnet.jp
server.ip vsapi.taiko-p.jp
```toml
server = "https://divamodarchive.com" # Change https://divamodarchive.com to your/server's ip, like 192.168.1.100
```

where `server.ip` is your computers ip (or the server's ip)
7. Now the game should be able to connect.

4. Setup [TaikoReverseProxy](https://github.com/shiibe/TaikoReverseProxy) or [Apache](#apache-setup-optional) as reverse proxy.
### About certificates

5. Now run the server, if everything is setup correctly, visit http://localhost:5000, you should be able to see the web ui up and running without errors. (If you encounter errors in web ui for the first time, try visit https://naominet.jp:10122/)
If you want to change the certificate used by server, just replace `cert.pfx` in `Certificates` folder. The bundled certificate includes the following DNS names:

6. Go to game folder, copy the config files (AMConfig.ini and WritableConfig.ini) in the AMCUS folder from server release to AMCUS folder and replace the original ones.
7. Open command prompt as admin, navigate to game root folder (where init.ps1 is). Run `regsvr32 .\AMCUS\iauthdll.dll`. It should prompt about success.
8. Run AMCUS/AMAuthd.exe, then run AMCUS/AMUpdater.exe. If the updater run and exits without issue, you are ready to run the game and connect to server.
9. Run the game, it should now connect to the server.
### Run the server on another computer
If you want to run the server on another computer, the procedure is almost identical.
Before you open browser, in `wwwroot/appsettings.json`, change `BaseUrl` to `https://naominet.jp:10122` then instead of visit localhost, visit the server using domain name to test.
Also note that now the cetificate also need to be imported on client computer, or web ui may not work. If you don't need https, change `BaseUrl` to `http://server.ip:80`, and visit on client. The game does not care about certificate.
### Apache Setup (Optional)
Notice the following assumes a windows install, the server also works on Linux, but the guide only covers windows.
1. Download [Apache](https://www.apachelounge.com/download/), extract anywhere
2. Copy the content in release rar's Apache folder to installed Apache root folder (and replace, which includes httpd.conf and httpd-vhosts.conf, if no prompt to replace files, you are extracting to wrong folder)
3. Open `conf/httpd.conf` (under installed Apache folder), find this line (line 37 by default), modify it to your Apache install (extracted) full path
```htaccess
# For example, if your Apache is extracted to C:\users\username\Apache24, then this should be "c:/users/username/Apache24"
Define SRVROOT "d:/Projects/Apache24"
```
DNS Name=nbgi-amnet.jp
DNS Name=v402-front.mucha-prd.nbgi-amnet.jp
DNS Name=*.mucha-prd.nbgi-amnet.jp
DNS Name=localhost
DNS Name=vsapi.taiko-p.jp
```

4. Open the certs folder Apache root folder, then click on the localhost.crt file and import it to trusted root store.

If everything is correct, run bin/httpd.exe, a command prompt will open (and stay open, if it shut down, probably something is not setup correctly)
You will need to modify hosts file to use them.
2 changes: 1 addition & 1 deletion SharedProject/Enums/PlayMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ public enum PlayMode
Normal = 0,
DanMode = 1,
// Not sure about this
AiBattle = 2
AiBattle = 6
}
22 changes: 22 additions & 0 deletions SharedProject/Models/AiSectionBestData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using SharedProject.Enums;

namespace SharedProject.Models;

public class AiSectionBestData
{
public int SectionIndex { get; set; }

public CrownType Crown { get; set; }

public bool IsWin { get; set; }

public uint Score { get; set; }

public uint GoodCount { get; set; }

public uint OkCount { get; set; }

public uint MissCount { get; set; }

public uint DrumrollCount { get; set; }
}
9 changes: 9 additions & 0 deletions SharedProject/Models/SongBestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public class SongBestData

public Difficulty Difficulty { get; set; }

public int PlayCount { get; set; }
public int ClearCount { get; set; }
public int FullComboCount { get; set; }
public int PerfectCount { get; set; }

public uint BestScore { get; set; }

public uint BestRate { get; set; }
Expand All @@ -37,4 +42,8 @@ public class SongBestData
public uint HitCount { get; set; }

public uint DrumrollCount { get; set; }

public List<AiSectionBestData> AiSectionBestData { get; set; } = new();

public bool ShowAiData { get; set; }
}
14 changes: 14 additions & 0 deletions SharedProject/Utils/ValueHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace SharedProject.Utils;

public static class ValueHelpers
{
public static T Min<T>(T a, T b) where T : IComparable
{
return Comparer<T>.Default.Compare(a, b) <= 0 ? a : b;
}

public static T Max<T>(T a, T b) where T : IComparable
{
return Comparer<T>.Default.Compare(a, b) >= 0 ? a : b;
}
}
Binary file modified TaikoLocalServer/Certificates/cert.pfx
Binary file not shown.
Binary file added TaikoLocalServer/Certificates/root.pfx
Binary file not shown.
13 changes: 3 additions & 10 deletions TaikoLocalServer/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ public static class Constants
{
public const string DATE_TIME_FORMAT = "yyyyMMddHHmmss";

public const int MUSIC_ID_MAX = 9000;
public const int MUSIC_ID_MAX = 1599;

public const int CROWN_FLAG_ARRAY_SIZE = MUSIC_ID_MAX + 1;

public const int DONDAFUL_CROWN_FLAG_ARRAY_SIZE = MUSIC_ID_MAX + 1;

public const int KIWAMI_SCORE_RANK_ARRAY_SIZE = MUSIC_ID_MAX + 1;

public const int IKI_CORE_RANK_ARRAY_SIZE = MUSIC_ID_MAX + 1;

public const int MIYABI_CORE_RANK_ARRAY_SIZE = MUSIC_ID_MAX + 1;
public const int MUSIC_ID_MAX_EXPANDED = 9000;

public const string DEFAULT_DB_NAME = "taiko.db3";

public const string MUSIC_ATTRIBUTE_FILE_NAME = "music_attribute.json";
public const string MUSIC_ATTRIBUTE_COMPRESSED_FILE_NAME = "music_attribute.bin";

public const string DAN_DATA_FILE_NAME = "dan_data.json";

Expand Down
2 changes: 1 addition & 1 deletion TaikoLocalServer/Common/Utils/FlagCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static byte[] GetBitArrayFromIds(IEnumerable<uint> idArray, int bitArrayS
{
if (id >= bitArraySize)
{
logger.LogWarning("Id out of range!");
logger.LogWarning("Id {Id} out of range!", id);
continue;
}
bitSet.Set((int)id, true);
Expand Down
25 changes: 25 additions & 0 deletions TaikoLocalServer/Context/TaikoDbContextPartial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public partial class TaikoDbContext
{
public virtual DbSet<DanScoreDatum> DanScoreData { get; set; } = null!;
public virtual DbSet<DanStageScoreDatum> DanStageScoreData { get; set; } = null!;
public virtual DbSet<AiScoreDatum> AiScoreData { get; set; } = null!;
public virtual DbSet<AiSectionScoreDatum> AiSectionScoreData { get; set; } = null!;

partial void OnModelCreatingPartial(ModelBuilder modelBuilder)
{
Expand All @@ -30,5 +32,28 @@ partial void OnModelCreatingPartial(ModelBuilder modelBuilder)
.HasForeignKey(d => new {d.Baid, d.DanId})
.OnDelete(DeleteBehavior.Cascade);
});

modelBuilder.Entity<AiScoreDatum>(entity =>
{
entity.HasKey(e => new { e.Baid, e.SongId, e.Difficulty });

entity.HasOne(d => d.Ba)
.WithMany()
.HasPrincipalKey(p => p.Baid)
.HasForeignKey(d => d.Baid)
.OnDelete(DeleteBehavior.Cascade);
});


modelBuilder.Entity<AiSectionScoreDatum>(entity =>
{
entity.HasKey(e => new { e.Baid, e.SongId, e.Difficulty, e.SectionIndex });

entity.HasOne(d => d.Parent)
.WithMany(p => p.AiSectionScoreData)
.HasPrincipalKey(p => new {p.Baid, p.SongId, p.Difficulty })
.HasForeignKey(d => new {d.Baid, d.SongId, d.Difficulty })
.OnDelete(DeleteBehavior.Cascade);
});
}
}
4 changes: 2 additions & 2 deletions TaikoLocalServer/Controllers/AmAuth/PowerOnController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace TaikoLocalServer.Controllers.AmAuth;
[Route("/sys/servlet/PowerOn")]
public class PowerOnController : BaseController<PowerOnController>
{
private readonly UrlSettings settings;
private readonly ServerSettings settings;

public PowerOnController(IOptions<UrlSettings> settings)
public PowerOnController(IOptions<ServerSettings> settings)
{
this.settings = settings.Value;
}
Expand Down
4 changes: 2 additions & 2 deletions TaikoLocalServer/Controllers/AmUpdater/MuchaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace TaikoLocalServer.Controllers.AmUpdater;

public class MuchaController : BaseController<MuchaController>
{
private readonly UrlSettings settings;
private readonly ServerSettings settings;

public MuchaController(IOptions<UrlSettings> settings)
public MuchaController(IOptions<ServerSettings> settings)
{
this.settings = settings.Value;
}
Expand Down
Loading

0 comments on commit 799eb85

Please sign in to comment.