Merge pull request '移除RenderTexutre,调整Resources和StreamAssets目录结构,加上"NES"父目录,以区分不同模拟器,加入ROMDB机制,修改ROM Mapper信息' (#25) from Alienjack/AxibugEmuOnline:master into master

Reviewed-on: sin365/AxibugEmuOnline#25
This commit is contained in:
sin365 2024-08-05 23:27:30 +08:00
commit c7f32874ae
28 changed files with 87150 additions and 59 deletions

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 6b52033f7628c4346a6dd0b2806e75ee
guid: 319a1a12506a5334ebd963b4fd991c2a
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ccf426abdad56c74682de4e38b3048e3
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 29131082dba8d234481296f0cf29a1fe, type: 3}
m_Name: ROMDB
m_EditorClassIdentifier:

View File

@ -1,8 +1,8 @@
fileFormatVersion: 2
guid: 6645567e4c11d9447b1aee2406f681c5
guid: 42cbfafb123e63b45841ae95eb432053
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 31d7b6b33f06e3d468b409ab9e71bf1f
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,40 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!84 &8400000
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: RenderTexture
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
m_IsAlphaChannelOptional: 0
serializedVersion: 5
m_Width: 256
m_Height: 240
m_AntiAliasing: 1
m_MipCount: -1
m_DepthStencilFormat: 92
m_ColorFormat: 8
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_EnableRandomWrite: 0
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 0
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
m_ShadowSamplingMode: 2

View File

@ -1,8 +1,8 @@
using AxibugEmuOnline.Client.ClientCore;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Linq;
using System.Xml.Linq;
using UnityEngine;
using VirtualNes.Core;
@ -15,9 +15,9 @@ namespace AxibugEmuOnline.Client
get
{
#if UNITY_EDITOR
return "Assets/StreamingAssets/Roms";
return "Assets/StreamingAssets/NES/Roms";
#else
return $"{Application.streamingAssetsPath}/Roms";
return $"{Application.streamingAssetsPath}/NES/Roms";
#endif
}
}
@ -44,7 +44,7 @@ namespace AxibugEmuOnline.Client
public Stream OpenFile_DISKSYS()
{
return File.Open($"{Application.streamingAssetsPath}/Disksys.rom", FileMode.Open, FileAccess.Read);
return new MemoryStream(Resources.Load<TextAsset>("NES/Disksys.rom").bytes);
}
public void SaveSRAMToFile(byte[] sramContent, string romName)
@ -92,5 +92,11 @@ namespace AxibugEmuOnline.Client
}
}
public bool TryGetMapperNo(ROM rom, out int mapperNo)
{
var db = Resources.Load<RomDB>("NES/ROMDB");
return db.GetMapperNo(rom.GetPROM_CRC(), out mapperNo);
}
}
}

View File

@ -1,4 +1,6 @@
using AxibugEmuOnline.Client.ClientCore;
using System;
using System.Xml.Linq;
using UnityEngine;
using VirtualNes.Core;
using VirtualNes.Core.Debug;
@ -56,5 +58,29 @@ namespace AxibugEmuOnline.Client
AudioProvider.ProcessSound(m_nesIns);
}
}
#if UNITY_EDITOR
[ContextMenu("IMPORT")]
public void TTTA()
{
var db = Resources.Load<RomDB>("NES/ROMDB");
db.Clear();
var dbFile = Resources.Load<TextAsset>("NES/nes20db");
var xml = XDocument.Parse(dbFile.text);
var games = xml.Element("nes20db").Elements("game");
foreach (var game in games)
{
var crcStr = game.Element("rom").Attribute("crc32").Value;
var crc = uint.Parse($"{crcStr}", System.Globalization.NumberStyles.HexNumber);
var mapper = int.Parse($"{game.Element("pcb").Attribute("mapper").Value}");
db.AddInfo(new RomDB.RomInfo { CRC = crc, Mapper = mapper });
}
UnityEditor.AssetDatabase.SaveAssets();
}
#endif
}
}

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace AxibugEmuOnline.Client.ClientCore
{
public class RomDB : ScriptableObject
{
[SerializeField]
private List<RomInfo> romInfos = new List<RomInfo>();
private Dictionary<uint, RomInfo> crc_Info_mapper;
public void AddInfo(RomInfo romInfo)
{
romInfos.Add(romInfo);
}
public void Clear()
{
romInfos.Clear();
}
public bool GetMapperNo(uint crc, out int mapperNo)
{
if (crc_Info_mapper == null)
{
crc_Info_mapper = new Dictionary<uint, RomInfo>();
foreach (var info in romInfos)
{
crc_Info_mapper[info.CRC] = info;
}
}
if (crc_Info_mapper.TryGetValue(crc, out var romInfo))
{
mapperNo = romInfo.Mapper;
return true;
}
else
{
mapperNo = -1;
return false;
}
}
[Serializable]
public class RomInfo
{
public uint CRC;
public int Mapper;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 29131082dba8d234481296f0cf29a1fe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,5 +1,6 @@
fileFormatVersion: 2
guid: 588a6a32c9d46b943b4909b1757f4572
guid: fc7102c34a9fa4148b4aa74d54e82b1f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:

View File

@ -415,12 +415,6 @@ namespace VirtualNes.Core
{
header.control2 |= (byte)EnumRomControlByte2.ROM_VSUNISYSTEM;
}
//吞食天地2 豪华中文版
if (crc == 0x19B9E732)
{
mapper = 199;
}
}
}
}

View File

@ -247,8 +247,8 @@ namespace VirtualNes.Core
Debuger.Log($"Mapper : #{rom.GetMapperNo():D3}");
Debuger.Log($"PROM-CRC : #{rom.GetPROM_CRC():X2}");
Debuger.Log($"VROM-CRC : #{rom.GetVROM_CRC():X2}");
Debuger.Log($"PRG SIZE : {16 * rom.GetPROM_SIZE():4:0000}K");
Debuger.Log($"CHR SIZE : {8 * rom.GetVROM_SIZE():4:0000}K");
Debuger.Log($"PRG SIZE : {16 * rom.GetPROM_SIZE():0000}K");
Debuger.Log($"CHR SIZE : {8 * rom.GetVROM_SIZE():0000}K");
Debuger.Log($"V MIRROR :{rom.IsVMIRROR()}");
Debuger.Log($"4 SCREEN :{rom.Is4SCREEN()}");

View File

@ -244,6 +244,11 @@ namespace VirtualNes.Core
FileNameCheck(fname);
if (Supporter.TryGetMapperNo(this, out int mapperNo))
{
mapper = mapperNo;
}
RomPatch.DoPatch(ref crc, ref lpPRG, ref lpCHR, ref mapper, ref header);
fdsmakerID = fdsgameID = 0;
@ -362,7 +367,7 @@ namespace VirtualNes.Core
return (header.control2 & (byte)EnumRomControlByte2.ROM_VSUNISYSTEM) != 0;
}
internal uint GetPROM_CRC()
public uint GetPROM_CRC()
{
return crc;
}

View File

@ -49,6 +49,11 @@ namespace VirtualNes.Core
return s_support.OpenFile(directPath, fileName);
}
public static bool TryGetMapperNo(ROM rom, out int mapperNo)
{
return s_support.TryGetMapperNo(rom, out mapperNo);
}
public static EmulatorConfig Config => s_support.Config;
}
@ -64,5 +69,6 @@ namespace VirtualNes.Core
void PrepareDirectory(string directPath);
void SaveFile(byte[] fileData, string directPath, string fileName);
Stream OpenFile(string directPath, string fileName);
bool TryGetMapperNo(ROM rom, out int mapperNo);
}
}