add live select pannel
This commit is contained in:
@@ -0,0 +1,463 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &1679236400360698642
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1679236400360698643}
|
||||||
|
- component: {fileID: 1679236400360698641}
|
||||||
|
- component: {fileID: 1679236400360698640}
|
||||||
|
- component: {fileID: 7159069016347322542}
|
||||||
|
- component: {fileID: 5423960384028092001}
|
||||||
|
- component: {fileID: 4882398606576421441}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: CharaSelect
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &1679236400360698643
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400360698642}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children:
|
||||||
|
- {fileID: 8943345654956533132}
|
||||||
|
- {fileID: 1679236400528196893}
|
||||||
|
- {fileID: 1679236400529307937}
|
||||||
|
- {fileID: 2014716433788527325}
|
||||||
|
m_Father: {fileID: 0}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
|
m_AnchorMax: {x: 0, y: 0}
|
||||||
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
|
m_SizeDelta: {x: 180, y: 250}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!222 &1679236400360698641
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400360698642}
|
||||||
|
m_CullTransparentMesh: 1
|
||||||
|
--- !u!114 &1679236400360698640
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400360698642}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 0.2}
|
||||||
|
m_RaycastTarget: 1
|
||||||
|
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_Maskable: 1
|
||||||
|
m_OnCullStateChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
|
m_Type: 1
|
||||||
|
m_PreserveAspect: 0
|
||||||
|
m_FillCenter: 1
|
||||||
|
m_FillMethod: 4
|
||||||
|
m_FillAmount: 1
|
||||||
|
m_FillClockwise: 1
|
||||||
|
m_FillOrigin: 0
|
||||||
|
m_UseSpriteMesh: 0
|
||||||
|
m_PixelsPerUnitMultiplier: 1
|
||||||
|
--- !u!114 &7159069016347322542
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400360698642}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Navigation:
|
||||||
|
m_Mode: 3
|
||||||
|
m_WrapAround: 0
|
||||||
|
m_SelectOnUp: {fileID: 0}
|
||||||
|
m_SelectOnDown: {fileID: 0}
|
||||||
|
m_SelectOnLeft: {fileID: 0}
|
||||||
|
m_SelectOnRight: {fileID: 0}
|
||||||
|
m_Transition: 1
|
||||||
|
m_Colors:
|
||||||
|
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||||
|
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
|
||||||
|
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||||
|
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
|
||||||
|
m_ColorMultiplier: 1
|
||||||
|
m_FadeDuration: 0.1
|
||||||
|
m_SpriteState:
|
||||||
|
m_HighlightedSprite: {fileID: 0}
|
||||||
|
m_PressedSprite: {fileID: 0}
|
||||||
|
m_SelectedSprite: {fileID: 0}
|
||||||
|
m_DisabledSprite: {fileID: 0}
|
||||||
|
m_AnimationTriggers:
|
||||||
|
m_NormalTrigger: Normal
|
||||||
|
m_HighlightedTrigger: Highlighted
|
||||||
|
m_PressedTrigger: Pressed
|
||||||
|
m_SelectedTrigger: Selected
|
||||||
|
m_DisabledTrigger: Disabled
|
||||||
|
m_Interactable: 1
|
||||||
|
m_TargetGraphic: {fileID: 1679236400360698640}
|
||||||
|
m_OnClick:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
--- !u!114 &5423960384028092001
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400360698642}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: c73dbc71d1114ee4d9faf37a28216671, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
CharaId: 0
|
||||||
|
CostumeId:
|
||||||
|
CharaImage: {fileID: 1679236400528196890}
|
||||||
|
BackGroundImage: {fileID: 4359019069968187769}
|
||||||
|
CostumeImage: {fileID: 1679236400529307950}
|
||||||
|
IndexText: {fileID: 2233745518321098558}
|
||||||
|
--- !u!114 &4882398606576421441
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400360698642}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 31a19414c41e5ae4aae2af33fee712f6, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_ShowMaskGraphic: 1
|
||||||
|
--- !u!1 &1679236400528196892
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1679236400528196893}
|
||||||
|
- component: {fileID: 1679236400528196891}
|
||||||
|
- component: {fileID: 1679236400528196890}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: Chara
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &1679236400528196893
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400528196892}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1679236400360698643}
|
||||||
|
m_RootOrder: 1
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0.5, y: 1}
|
||||||
|
m_AnchorMax: {x: 0.5, y: 1}
|
||||||
|
m_AnchoredPosition: {x: 0, y: -55}
|
||||||
|
m_SizeDelta: {x: 120, y: 120}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!222 &1679236400528196891
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400528196892}
|
||||||
|
m_CullTransparentMesh: 1
|
||||||
|
--- !u!114 &1679236400528196890
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400528196892}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_RaycastTarget: 0
|
||||||
|
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_Maskable: 1
|
||||||
|
m_OnCullStateChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
m_Sprite: {fileID: 21300000, guid: fcb07487bdd0f054f81d8865b4800c13, type: 3}
|
||||||
|
m_Type: 0
|
||||||
|
m_PreserveAspect: 0
|
||||||
|
m_FillCenter: 1
|
||||||
|
m_FillMethod: 4
|
||||||
|
m_FillAmount: 1
|
||||||
|
m_FillClockwise: 1
|
||||||
|
m_FillOrigin: 0
|
||||||
|
m_UseSpriteMesh: 0
|
||||||
|
m_PixelsPerUnitMultiplier: 1
|
||||||
|
--- !u!1 &1679236400529307936
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 1679236400529307937}
|
||||||
|
- component: {fileID: 1679236400529307951}
|
||||||
|
- component: {fileID: 1679236400529307950}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: Dress
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &1679236400529307937
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400529307936}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1679236400360698643}
|
||||||
|
m_RootOrder: 2
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0.5, y: 1}
|
||||||
|
m_AnchorMax: {x: 0.5, y: 1}
|
||||||
|
m_AnchoredPosition: {x: 0, y: -180}
|
||||||
|
m_SizeDelta: {x: 120, y: 120}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!222 &1679236400529307951
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400529307936}
|
||||||
|
m_CullTransparentMesh: 1
|
||||||
|
--- !u!114 &1679236400529307950
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1679236400529307936}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_RaycastTarget: 0
|
||||||
|
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_Maskable: 1
|
||||||
|
m_OnCullStateChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
m_Sprite: {fileID: 21300000, guid: 74c10446f10883c4683a526eb8380a5b, type: 3}
|
||||||
|
m_Type: 0
|
||||||
|
m_PreserveAspect: 0
|
||||||
|
m_FillCenter: 1
|
||||||
|
m_FillMethod: 4
|
||||||
|
m_FillAmount: 1
|
||||||
|
m_FillClockwise: 1
|
||||||
|
m_FillOrigin: 0
|
||||||
|
m_UseSpriteMesh: 0
|
||||||
|
m_PixelsPerUnitMultiplier: 1
|
||||||
|
--- !u!1 &4346032192954077524
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 8943345654956533132}
|
||||||
|
- component: {fileID: 9146919278922802724}
|
||||||
|
- component: {fileID: 4359019069968187769}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: BG
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &8943345654956533132
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 4346032192954077524}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1679236400360698643}
|
||||||
|
m_RootOrder: 0
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0.5, y: 1}
|
||||||
|
m_AnchorMax: {x: 0.5, y: 1}
|
||||||
|
m_AnchoredPosition: {x: 0, y: -115}
|
||||||
|
m_SizeDelta: {x: 345, y: 345}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!222 &9146919278922802724
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 4346032192954077524}
|
||||||
|
m_CullTransparentMesh: 1
|
||||||
|
--- !u!114 &4359019069968187769
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 4346032192954077524}
|
||||||
|
m_Enabled: 0
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 0.5019608}
|
||||||
|
m_RaycastTarget: 0
|
||||||
|
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_Maskable: 1
|
||||||
|
m_OnCullStateChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
m_Sprite: {fileID: 21300000, guid: fcb07487bdd0f054f81d8865b4800c13, type: 3}
|
||||||
|
m_Type: 0
|
||||||
|
m_PreserveAspect: 0
|
||||||
|
m_FillCenter: 1
|
||||||
|
m_FillMethod: 4
|
||||||
|
m_FillAmount: 1
|
||||||
|
m_FillClockwise: 1
|
||||||
|
m_FillOrigin: 0
|
||||||
|
m_UseSpriteMesh: 0
|
||||||
|
m_PixelsPerUnitMultiplier: 1
|
||||||
|
--- !u!1 &7987743244650596613
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 2014716433788527325}
|
||||||
|
- component: {fileID: 3508166106652295565}
|
||||||
|
- component: {fileID: 2233745518321098558}
|
||||||
|
m_Layer: 5
|
||||||
|
m_Name: Index
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &2014716433788527325
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7987743244650596613}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 1679236400360698643}
|
||||||
|
m_RootOrder: 3
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
|
m_AnchorMax: {x: 1, y: 1}
|
||||||
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
|
m_SizeDelta: {x: -10, y: -10}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!222 &3508166106652295565
|
||||||
|
CanvasRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7987743244650596613}
|
||||||
|
m_CullTransparentMesh: 1
|
||||||
|
--- !u!114 &2233745518321098558
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7987743244650596613}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_Color: {r: 0, g: 0, b: 0, a: 1}
|
||||||
|
m_RaycastTarget: 0
|
||||||
|
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
m_Maskable: 1
|
||||||
|
m_OnCullStateChanged:
|
||||||
|
m_PersistentCalls:
|
||||||
|
m_Calls: []
|
||||||
|
m_FontData:
|
||||||
|
m_Font: {fileID: 12800000, guid: 036631af73b15ac41a9d10f75f5bbafe, type: 3}
|
||||||
|
m_FontSize: 25
|
||||||
|
m_FontStyle: 0
|
||||||
|
m_BestFit: 0
|
||||||
|
m_MinSize: 10
|
||||||
|
m_MaxSize: 56
|
||||||
|
m_Alignment: 0
|
||||||
|
m_AlignByGeometry: 0
|
||||||
|
m_RichText: 1
|
||||||
|
m_HorizontalOverflow: 0
|
||||||
|
m_VerticalOverflow: 0
|
||||||
|
m_LineSpacing: 1
|
||||||
|
m_Text: 1
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: db8e57d6cda624648bbe2c78faf0644f
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
@@ -0,0 +1,108 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fcb07487bdd0f054f81d8865b4800c13
|
||||||
|
TextureImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 11
|
||||||
|
mipmaps:
|
||||||
|
mipMapMode: 0
|
||||||
|
enableMipMap: 0
|
||||||
|
sRGBTexture: 1
|
||||||
|
linearTexture: 0
|
||||||
|
fadeOut: 0
|
||||||
|
borderMipMap: 0
|
||||||
|
mipMapsPreserveCoverage: 0
|
||||||
|
alphaTestReferenceValue: 0.5
|
||||||
|
mipMapFadeDistanceStart: 1
|
||||||
|
mipMapFadeDistanceEnd: 3
|
||||||
|
bumpmap:
|
||||||
|
convertToNormalMap: 0
|
||||||
|
externalNormalMap: 0
|
||||||
|
heightScale: 0.25
|
||||||
|
normalMapFilter: 0
|
||||||
|
isReadable: 0
|
||||||
|
streamingMipmaps: 0
|
||||||
|
streamingMipmapsPriority: 0
|
||||||
|
vTOnly: 0
|
||||||
|
grayScaleToAlpha: 0
|
||||||
|
generateCubemap: 6
|
||||||
|
cubemapConvolution: 0
|
||||||
|
seamlessCubemap: 0
|
||||||
|
textureFormat: 1
|
||||||
|
maxTextureSize: 2048
|
||||||
|
textureSettings:
|
||||||
|
serializedVersion: 2
|
||||||
|
filterMode: 1
|
||||||
|
aniso: 1
|
||||||
|
mipBias: 0
|
||||||
|
wrapU: 1
|
||||||
|
wrapV: 1
|
||||||
|
wrapW: 0
|
||||||
|
nPOTScale: 0
|
||||||
|
lightmap: 0
|
||||||
|
compressionQuality: 50
|
||||||
|
spriteMode: 1
|
||||||
|
spriteExtrude: 1
|
||||||
|
spriteMeshType: 1
|
||||||
|
alignment: 0
|
||||||
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
|
spritePixelsToUnits: 100
|
||||||
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
spriteGenerateFallbackPhysicsShape: 1
|
||||||
|
alphaUsage: 1
|
||||||
|
alphaIsTransparency: 1
|
||||||
|
spriteTessellationDetail: -1
|
||||||
|
textureType: 8
|
||||||
|
textureShape: 1
|
||||||
|
singleChannelComponent: 0
|
||||||
|
flipbookRows: 1
|
||||||
|
flipbookColumns: 1
|
||||||
|
maxTextureSizeSet: 0
|
||||||
|
compressionQualitySet: 0
|
||||||
|
textureFormatSet: 0
|
||||||
|
ignorePngGamma: 0
|
||||||
|
applyGammaDecoding: 0
|
||||||
|
platformSettings:
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: DefaultTexturePlatform
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: Standalone
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
spriteSheet:
|
||||||
|
serializedVersion: 2
|
||||||
|
sprites: []
|
||||||
|
outline: []
|
||||||
|
physicsShape: []
|
||||||
|
bones: []
|
||||||
|
spriteID: 5e97eb03825dee720800000000000000
|
||||||
|
internalID: 0
|
||||||
|
vertices: []
|
||||||
|
indices:
|
||||||
|
edges: []
|
||||||
|
weights: []
|
||||||
|
secondaryTextures: []
|
||||||
|
spritePackingTag:
|
||||||
|
pSDRemoveMatte: 0
|
||||||
|
pSDShowRemoveMatteOption: 0
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
@@ -0,0 +1,108 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 74c10446f10883c4683a526eb8380a5b
|
||||||
|
TextureImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 11
|
||||||
|
mipmaps:
|
||||||
|
mipMapMode: 0
|
||||||
|
enableMipMap: 0
|
||||||
|
sRGBTexture: 1
|
||||||
|
linearTexture: 0
|
||||||
|
fadeOut: 0
|
||||||
|
borderMipMap: 0
|
||||||
|
mipMapsPreserveCoverage: 0
|
||||||
|
alphaTestReferenceValue: 0.5
|
||||||
|
mipMapFadeDistanceStart: 1
|
||||||
|
mipMapFadeDistanceEnd: 3
|
||||||
|
bumpmap:
|
||||||
|
convertToNormalMap: 0
|
||||||
|
externalNormalMap: 0
|
||||||
|
heightScale: 0.25
|
||||||
|
normalMapFilter: 0
|
||||||
|
isReadable: 0
|
||||||
|
streamingMipmaps: 0
|
||||||
|
streamingMipmapsPriority: 0
|
||||||
|
vTOnly: 0
|
||||||
|
grayScaleToAlpha: 0
|
||||||
|
generateCubemap: 6
|
||||||
|
cubemapConvolution: 0
|
||||||
|
seamlessCubemap: 0
|
||||||
|
textureFormat: 1
|
||||||
|
maxTextureSize: 2048
|
||||||
|
textureSettings:
|
||||||
|
serializedVersion: 2
|
||||||
|
filterMode: 1
|
||||||
|
aniso: 1
|
||||||
|
mipBias: 0
|
||||||
|
wrapU: 1
|
||||||
|
wrapV: 1
|
||||||
|
wrapW: 0
|
||||||
|
nPOTScale: 0
|
||||||
|
lightmap: 0
|
||||||
|
compressionQuality: 50
|
||||||
|
spriteMode: 1
|
||||||
|
spriteExtrude: 1
|
||||||
|
spriteMeshType: 1
|
||||||
|
alignment: 0
|
||||||
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
|
spritePixelsToUnits: 100
|
||||||
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
spriteGenerateFallbackPhysicsShape: 1
|
||||||
|
alphaUsage: 1
|
||||||
|
alphaIsTransparency: 1
|
||||||
|
spriteTessellationDetail: -1
|
||||||
|
textureType: 8
|
||||||
|
textureShape: 1
|
||||||
|
singleChannelComponent: 0
|
||||||
|
flipbookRows: 1
|
||||||
|
flipbookColumns: 1
|
||||||
|
maxTextureSizeSet: 0
|
||||||
|
compressionQualitySet: 0
|
||||||
|
textureFormatSet: 0
|
||||||
|
ignorePngGamma: 0
|
||||||
|
applyGammaDecoding: 0
|
||||||
|
platformSettings:
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: DefaultTexturePlatform
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: Standalone
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
spriteSheet:
|
||||||
|
serializedVersion: 2
|
||||||
|
sprites: []
|
||||||
|
outline: []
|
||||||
|
physicsShape: []
|
||||||
|
bones: []
|
||||||
|
spriteID: 5e97eb03825dee720800000000000000
|
||||||
|
internalID: 0
|
||||||
|
vertices: []
|
||||||
|
indices:
|
||||||
|
edges: []
|
||||||
|
weights: []
|
||||||
|
secondaryTextures: []
|
||||||
|
spritePackingTag:
|
||||||
|
pSDRemoveMatte: 0
|
||||||
|
pSDShowRemoveMatteOption: 0
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+1266
-17
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class LiveCharacterSelect : MonoBehaviour
|
||||||
|
{
|
||||||
|
public int CharaId;
|
||||||
|
public string CostumeId;
|
||||||
|
public Image CharaImage;
|
||||||
|
public Image BackGroundImage;
|
||||||
|
public Image CostumeImage;
|
||||||
|
public Text IndexText;
|
||||||
|
|
||||||
|
public void SelectChara(UmaViewerUI ui)
|
||||||
|
{
|
||||||
|
if (!ui) return;
|
||||||
|
ui.CurrentSeletChara = this;
|
||||||
|
if (!ui.SelectCharacterPannel.activeInHierarchy)
|
||||||
|
ui.ToggleUIPanel(ui.SelectCharacterPannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetValue(int charaId, string costumeId,Sprite charaSprite, Sprite costumeSprite)
|
||||||
|
{
|
||||||
|
CharaId = charaId;
|
||||||
|
CostumeId = costumeId;
|
||||||
|
CharaImage.sprite = charaSprite;
|
||||||
|
BackGroundImage.enabled = true;
|
||||||
|
BackGroundImage.sprite = charaSprite;
|
||||||
|
CostumeImage.sprite = costumeSprite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 71e62a5239b1859499398c28ccee9b96
|
guid: c73dbc71d1114ee4d9faf37a28216671
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -79,6 +79,8 @@ public class LiveEntry
|
|||||||
{
|
{
|
||||||
public int MusicId;
|
public int MusicId;
|
||||||
public string SongName;
|
public string SongName;
|
||||||
|
public int MemberCount;
|
||||||
|
public int DefaultDress;
|
||||||
public string BackGroundId;
|
public string BackGroundId;
|
||||||
public Sprite Icon;
|
public Sprite Icon;
|
||||||
public List<string[]> LiveSettings = new List<string[]>();
|
public List<string[]> LiveSettings = new List<string[]>();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UmaMusumeAudio;
|
using UmaMusumeAudio;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
public class UmaViewerBuilder : MonoBehaviour
|
public class UmaViewerBuilder : MonoBehaviour
|
||||||
{
|
{
|
||||||
@@ -459,17 +460,16 @@ public class UmaViewerBuilder : MonoBehaviour
|
|||||||
RecursiveLoadAsset(entry);
|
RecursiveLoadAsset(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadLive(LiveEntry live)
|
public void LoadLive(LiveEntry live,List<LiveCharacterSelect> characters)
|
||||||
{
|
{
|
||||||
var asset = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.EndsWith("cutt_son" + live.MusicId));
|
characters.ForEach(a => {
|
||||||
var BGasset = UmaViewerMain.Instance.AbList.FirstOrDefault(a => a.Name.EndsWith($"pfb_env_live{live.BackGroundId}_controller000"));
|
if (a.CharaId == 0 || a.CostumeId == "") {
|
||||||
if (asset == null || BGasset == null) return;
|
a.CharaId = Main.Characters[Random.Range(0, Main.Characters.Count)].Id;
|
||||||
|
a.CostumeId = "00";
|
||||||
|
}
|
||||||
|
});//fill empty
|
||||||
|
|
||||||
|
|
||||||
UnloadLive();
|
|
||||||
UnloadAllBundle();
|
|
||||||
CurrentLiveContainer = new GameObject(Path.GetFileName(asset.Name)).AddComponent<UmaContainer>();
|
|
||||||
RecursiveLoadAsset(asset);
|
|
||||||
RecursiveLoadAsset(BGasset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Use CriWare Library
|
//Use CriWare Library
|
||||||
|
|||||||
@@ -116,6 +116,9 @@ public class UmaViewerMain : MonoBehaviour
|
|||||||
{
|
{
|
||||||
var musicId = Convert.ToInt32(item["music_id"]);
|
var musicId = Convert.ToInt32(item["music_id"]);
|
||||||
var songName = item["songname"].ToString();
|
var songName = item["songname"].ToString();
|
||||||
|
var membercount = Convert.ToInt32(item["live_member_number"]);
|
||||||
|
var defaultdress = Convert.ToInt32(item["default_main_dress"]);
|
||||||
|
|
||||||
if (!Lives.Where(c => c.MusicId == musicId).Any())
|
if (!Lives.Where(c => c.MusicId == musicId).Any())
|
||||||
{
|
{
|
||||||
if (bundle.Contains(musicId.ToString()))
|
if (bundle.Contains(musicId.ToString()))
|
||||||
@@ -126,8 +129,10 @@ public class UmaViewerMain : MonoBehaviour
|
|||||||
{
|
{
|
||||||
MusicId = musicId,
|
MusicId = musicId,
|
||||||
SongName = songName,
|
SongName = songName,
|
||||||
|
MemberCount = membercount,
|
||||||
|
DefaultDress = defaultdress,
|
||||||
Icon = UmaViewerBuilder.Instance.LoadLiveIcon(musicId)
|
Icon = UmaViewerBuilder.Instance.LoadLiveIcon(musicId)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,18 @@ public class UmaViewerUI : MonoBehaviour
|
|||||||
public GameObject BG_HSVPickerObj;
|
public GameObject BG_HSVPickerObj;
|
||||||
public Image BG_Image;
|
public Image BG_Image;
|
||||||
|
|
||||||
|
[Header("live settings")]
|
||||||
|
public Sprite CharaIconDefault;
|
||||||
|
public Sprite CostumeIconDefault;
|
||||||
|
public LiveCharacterSelect CurrentSeletChara;
|
||||||
|
public GameObject LiveSelectPrefab;
|
||||||
|
public GameObject LiveSelectPannel;
|
||||||
|
public GameObject SelectCharacterPannel;
|
||||||
|
public ScrollRect LiveSelectList;
|
||||||
|
public Image LiveSelectImage;
|
||||||
|
public Text LiveSelectInfoText;
|
||||||
|
private LiveEntry currentLive;
|
||||||
|
|
||||||
[Header("settings")]
|
[Header("settings")]
|
||||||
public TMP_InputField SSWidth;
|
public TMP_InputField SSWidth;
|
||||||
public TMP_InputField SSHeight;
|
public TMP_InputField SSHeight;
|
||||||
@@ -92,6 +104,7 @@ public class UmaViewerUI : MonoBehaviour
|
|||||||
public GameObject UmaContainerLivePrefab;
|
public GameObject UmaContainerLivePrefab;
|
||||||
public GameObject UmaContainerSliderPrefab;
|
public GameObject UmaContainerSliderPrefab;
|
||||||
public GameObject UmaContainerAssetsPrefab;
|
public GameObject UmaContainerAssetsPrefab;
|
||||||
|
|
||||||
private int LoadedAssetCount = 0;
|
private int LoadedAssetCount = 0;
|
||||||
[SerializeField] private RectTransform LoadedAssetsPanel;
|
[SerializeField] private RectTransform LoadedAssetsPanel;
|
||||||
|
|
||||||
@@ -207,12 +220,12 @@ public class UmaViewerUI : MonoBehaviour
|
|||||||
container3.Name = container3.name = chara.Id + " " + chara.Name;
|
container3.Name = container3.name = chara.Id + " " + chara.Name;
|
||||||
container3.Button.onClick.AddListener(() => {
|
container3.Button.onClick.AddListener(() => {
|
||||||
HighlightChildImage(CharactersList.content, container3);
|
HighlightChildImage(CharactersList.content, container3);
|
||||||
ListCostumes(charaInstance.Id, false);
|
ListCostumes(charaInstance, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (chara.Icon)
|
if (chara.Icon)
|
||||||
{
|
{
|
||||||
container3.Image.sprite = chara.Icon;
|
container3.Image.sprite = (chara.Icon == null ? CharaIconDefault : chara.Icon);
|
||||||
container3.Image.enabled = true;
|
container3.Image.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +238,7 @@ public class UmaViewerUI : MonoBehaviour
|
|||||||
|
|
||||||
if (chara.Icon)
|
if (chara.Icon)
|
||||||
{
|
{
|
||||||
container4.Image.sprite = chara.Icon;
|
container4.Image.sprite = (chara.Icon == null ? CharaIconDefault : chara.Icon);
|
||||||
container4.Image.enabled = true;
|
container4.Image.enabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -247,7 +260,7 @@ public class UmaViewerUI : MonoBehaviour
|
|||||||
container2.Name = container2.name = chara.Id + " " + chara.Name;
|
container2.Name = container2.name = chara.Id + " " + chara.Name;
|
||||||
container2.Button.onClick.AddListener(() => {
|
container2.Button.onClick.AddListener(() => {
|
||||||
HighlightChildImage(MiniCharactersList.content, container2);
|
HighlightChildImage(MiniCharactersList.content, container2);
|
||||||
ListCostumes(charaInstance.Id, true);
|
ListCostumes(charaInstance, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (chara.Icon)
|
if (chara.Icon)
|
||||||
@@ -442,7 +455,7 @@ public class UmaViewerUI : MonoBehaviour
|
|||||||
container.Image.enabled = container.Image.sprite;
|
container.Image.enabled = container.Image.sprite;
|
||||||
container.Button.onClick.AddListener(() => {
|
container.Button.onClick.AddListener(() => {
|
||||||
HighlightChildImage(LiveList.content, container);
|
HighlightChildImage(LiveList.content, container);
|
||||||
Builder.LoadLive(live);
|
ShowLiveSelectPannel(live);
|
||||||
});
|
});
|
||||||
|
|
||||||
var CharaContainer = Instantiate(UmaContainerLivePrefab, LiveSoundList.content).GetComponent<UmaUIContainer>();
|
var CharaContainer = Instantiate(UmaContainerLivePrefab, LiveSoundList.content).GetComponent<UmaUIContainer>();
|
||||||
@@ -509,30 +522,72 @@ public class UmaViewerUI : MonoBehaviour
|
|||||||
ScenePageCtrl.Initialize(pageentrys, SceneList);
|
ScenePageCtrl.Initialize(pageentrys, SceneList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListCostumes(int umaId, bool mini)
|
public void PlayLive()
|
||||||
|
{
|
||||||
|
if (currentLive == null) return;
|
||||||
|
var selectlist = LiveSelectList.content.GetComponentsInChildren<LiveCharacterSelect>();
|
||||||
|
if(selectlist != null)
|
||||||
|
{
|
||||||
|
Builder.LoadLive(currentLive, new List<LiveCharacterSelect>(selectlist));
|
||||||
|
LiveSelectPannel.SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowLiveSelectPannel(LiveEntry entry)
|
||||||
|
{
|
||||||
|
LiveSelectPannel.SetActive(true);
|
||||||
|
for (int i = LiveSelectList.content.childCount - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
Destroy(LiveSelectList.content.GetChild(i).gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLive = entry;
|
||||||
|
LiveSelectImage.sprite = entry.Icon;
|
||||||
|
LiveSelectInfoText.text = $"{entry.SongName}\nMembers Count: {entry.MemberCount}";
|
||||||
|
for (int i = 0; i < entry.MemberCount; i++)
|
||||||
|
{
|
||||||
|
var chara = Instantiate(LiveSelectPrefab, LiveSelectList.content).GetComponent<LiveCharacterSelect>();
|
||||||
|
chara.IndexText.text = (i + 1).ToString();
|
||||||
|
chara.GetComponent<Button>().onClick.AddListener(() => {
|
||||||
|
chara.SelectChara(this);
|
||||||
|
foreach (var t in LiveSelectList.content.GetComponentsInChildren<LiveCharacterSelect>())
|
||||||
|
{
|
||||||
|
t.GetComponentInChildren<Text>().color = (t == chara ? Color.white : Color.black);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ListCostumes(CharaEntry chara, bool mini)
|
||||||
{
|
{
|
||||||
ScrollRect costumeList = mini ? MiniCostumeList : CostumeList;
|
ScrollRect costumeList = mini ? MiniCostumeList : CostumeList;
|
||||||
for (int i = costumeList.content.childCount - 1; i >= 0; i--)
|
for (int i = costumeList.content.childCount - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
Destroy(costumeList.content.GetChild(i).gameObject);
|
Destroy(costumeList.content.GetChild(i).gameObject);
|
||||||
}
|
}
|
||||||
string nameVar = mini ? $"pfb_mbdy{umaId}" : $"pfb_bdy{umaId}";
|
string nameVar = mini ? $"pfb_mbdy{chara.Id}" : $"pfb_bdy{chara.Id}";
|
||||||
foreach (var entry in Main.AbList.Where(a => !a.Name.Contains("clothes") && a.Name.Contains(nameVar)))
|
foreach (var entry in Main.AbList.Where(a => !a.Name.Contains("clothes") && a.Name.Contains(nameVar)))
|
||||||
{
|
{
|
||||||
var container = Instantiate(UmaContainerCostumePrefab, costumeList.content).GetComponent<UmaUIContainer>();
|
var container = Instantiate(UmaContainerCostumePrefab, costumeList.content).GetComponent<UmaUIContainer>();
|
||||||
string[] split = entry.Name.Split('_');
|
string[] split = entry.Name.Split('_');
|
||||||
string costumeId = split[split.Length - 1];
|
string costumeId = split[split.Length - 1];
|
||||||
container.Name = container.name = GetCostumeName(costumeId);
|
container.Name = container.name = GetCostumeName(costumeId);
|
||||||
container.Button.onClick.AddListener(() => {
|
var icon = Main.Costumes.FirstOrDefault(a => (a.CharaId == chara.Id && a.BodyTypeSub == int.Parse(costumeId)));
|
||||||
HighlightChildImage(costumeList.content, container);
|
container.Image.sprite = (icon == null ? CostumeIconDefault : icon.Icon);
|
||||||
StartCoroutine(Builder.LoadUma(umaId, costumeId, mini));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
var icon = Main.Costumes.FirstOrDefault(a => (a.CharaId == umaId&&a.BodyTypeSub == int.Parse(costumeId)));
|
|
||||||
if (icon == null) icon = Main.Costumes[0];
|
|
||||||
container.Image.sprite = icon.Icon;
|
|
||||||
container.Image.enabled = true;
|
container.Image.enabled = true;
|
||||||
|
container.Button.onClick.AddListener(() => {
|
||||||
|
if (LiveSelectPannel.activeInHierarchy && CurrentSeletChara)
|
||||||
|
{
|
||||||
|
CurrentSeletChara.SetValue(chara.Id, costumeId, chara.Icon, container.Image.sprite);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HighlightChildImage(costumeList.content, container);
|
||||||
|
StartCoroutine(Builder.LoadUma(chara.Id, costumeId, mini));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//Common costumes
|
//Common costumes
|
||||||
List<string> costumes = new List<string>();
|
List<string> costumes = new List<string>();
|
||||||
@@ -547,18 +602,24 @@ public class UmaViewerUI : MonoBehaviour
|
|||||||
string costumeId = id;
|
string costumeId = id;
|
||||||
var container = Instantiate(UmaContainerCostumePrefab, costumeList.content).GetComponent<UmaUIContainer>();
|
var container = Instantiate(UmaContainerCostumePrefab, costumeList.content).GetComponent<UmaUIContainer>();
|
||||||
container.Name = container.name = GetCostumeName(id);
|
container.Name = container.name = GetCostumeName(id);
|
||||||
container.Button.onClick.AddListener(() => {
|
|
||||||
HighlightChildImage(costumeList.content, container);
|
|
||||||
StartCoroutine(Builder.LoadUma(umaId, costumeId, mini));
|
|
||||||
});
|
|
||||||
|
|
||||||
var data = costumeId.Split('_');
|
var data = costumeId.Split('_');
|
||||||
var bodytype = int.Parse(data[0]);
|
var bodytype = int.Parse(data[0]);
|
||||||
var bodysub = int.Parse(data[1]);
|
var bodysub = int.Parse(data[1]);
|
||||||
var icon = Main.Costumes.FirstOrDefault(a => a.BodyType == bodytype&& a.BodyTypeSub == bodysub);
|
|
||||||
if (icon == null) icon = Main.Costumes[0];
|
var icon = Main.Costumes.FirstOrDefault(a => a.BodyType == bodytype && a.BodyTypeSub == bodysub);
|
||||||
container.Image.sprite = icon.Icon;
|
container.Image.sprite = (icon == null ? CostumeIconDefault : icon.Icon);
|
||||||
container.Image.enabled = true;
|
container.Image.enabled = true;
|
||||||
|
container.Button.onClick.AddListener(() => {
|
||||||
|
if (LiveSelectPannel.activeInHierarchy && CurrentSeletChara)
|
||||||
|
{
|
||||||
|
CurrentSeletChara.SetValue(chara.Id, costumeId, chara.Icon, container.Image.sprite);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HighlightChildImage(costumeList.content, container);
|
||||||
|
StartCoroutine(Builder.LoadUma(chara.Id, costumeId, mini));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public static class A2U
|
|
||||||
{
|
|
||||||
public enum Blend
|
|
||||||
{
|
|
||||||
Normal = 0,
|
|
||||||
Add = 1,
|
|
||||||
Multiply = 2,
|
|
||||||
Screen = 3,
|
|
||||||
Overlay = 4
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Order
|
|
||||||
{
|
|
||||||
PreImageEffect = 0,
|
|
||||||
InImageEffect = 1,
|
|
||||||
PostImageEffect = 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 94a19af2ebcc39448a7265778a585f83
|
guid: 593ab9e85604a4648b0a0e8878793796
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6f1a2a3c0634d0947a0b1fd6a5ff4506
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1531897059
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using DereTore.Exchange.Audio.HCA;
|
||||||
|
using DereTore.Exchange.Archive.ACB;
|
||||||
|
|
||||||
|
public class DecodeACB
|
||||||
|
{
|
||||||
|
public static class CgssCipher
|
||||||
|
{
|
||||||
|
/* ミリシタ
|
||||||
|
public static readonly uint Key1 = 0xBC731A85;
|
||||||
|
public static readonly uint Key2 = 0x0002B875;
|
||||||
|
*/
|
||||||
|
|
||||||
|
//デレステ
|
||||||
|
public static readonly uint Key1 = 0xf27e3b22;
|
||||||
|
public static readonly uint Key2 = 0x00003657;
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void AsyncDecode(byte[] inData, string outstr);
|
||||||
|
|
||||||
|
public static void Decode(string inputfilename, string outputfilename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(inputfilename)) { return; }
|
||||||
|
if (File.Exists(outputfilename)) { return; }
|
||||||
|
|
||||||
|
byte[] inData = File.ReadAllBytes(inputfilename);
|
||||||
|
|
||||||
|
Decode(inData, outputfilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Decode(byte[] inputData, string outputfilename)
|
||||||
|
{
|
||||||
|
if (inputData != null)
|
||||||
|
{
|
||||||
|
AsyncDecode asyncDecode = DecodeProc;
|
||||||
|
asyncDecode.BeginInvoke(inputData, outputfilename, null, null); //非同期で実行
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DecodeProc(byte[] inputData, string outputfilename)
|
||||||
|
{
|
||||||
|
//復号Keyをセット
|
||||||
|
var decodeParams = DecodeParams.CreateDefault();
|
||||||
|
decodeParams.Key1 = CgssCipher.Key1;
|
||||||
|
decodeParams.Key2 = CgssCipher.Key2;
|
||||||
|
|
||||||
|
//HCAの出力設定
|
||||||
|
var audioParams = AudioParams.CreateDefault();
|
||||||
|
audioParams.InfiniteLoop = false;
|
||||||
|
audioParams.SimulatedLoopCount = 0; //ループ回数
|
||||||
|
audioParams.OutputWaveHeader = true;
|
||||||
|
|
||||||
|
//Streamの生成
|
||||||
|
MemoryStream memoryStream = new MemoryStream(inputData);
|
||||||
|
|
||||||
|
//acbファイルを展開
|
||||||
|
using (AcbFile acb = AcbFile.FromStream(memoryStream,0,inputData.Length,"default",true))
|
||||||
|
{
|
||||||
|
var fileNames = acb.GetFileNames();
|
||||||
|
var s = fileNames[0];
|
||||||
|
byte[] outdata = null;
|
||||||
|
|
||||||
|
//hcaファイルを展開
|
||||||
|
using (var source = acb.OpenDataStream(s))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var hcaStream = new HcaAudioStream(source, decodeParams, audioParams))
|
||||||
|
{
|
||||||
|
//出力
|
||||||
|
outdata = new byte[hcaStream.Length];
|
||||||
|
hcaStream.Read(outdata, 0, (int)hcaStream.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("HCA Decodeでエラーが発生しました。");
|
||||||
|
Console.WriteLine("File : " + s);
|
||||||
|
Console.WriteLine(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (outdata != null)
|
||||||
|
{
|
||||||
|
string tmpfile = outputfilename + ".tmp";
|
||||||
|
File.WriteAllBytes(tmpfile, outdata);
|
||||||
|
File.Move(tmpfile, outputfilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: da7bf8ee0c95a8343a31634e5937040d
|
||||||
|
timeCreated: 1532218344
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 92850131af35f784f8f3e438824fb74a
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public sealed class AcbCueRecord {
|
||||||
|
|
||||||
|
internal AcbCueRecord() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint CueId { get; set; }
|
||||||
|
public byte ReferenceType { get; set; }
|
||||||
|
public ushort ReferenceIndex { get; set; }
|
||||||
|
|
||||||
|
public bool IsWaveformIdentified { get; set; }
|
||||||
|
public ushort WaveformIndex { get; set; }
|
||||||
|
public ushort WaveformId { get; set; }
|
||||||
|
public byte EncodeType { get; set; }
|
||||||
|
public bool IsStreaming { get; set; }
|
||||||
|
|
||||||
|
public string CueName { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 30a227313ddb56a4abfa993a99360d4c
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public class AcbException : ApplicationException {
|
||||||
|
|
||||||
|
public AcbException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AcbException(string message)
|
||||||
|
: base(message) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AcbException(string message, Exception innerException)
|
||||||
|
: base(message, innerException) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3d65846458ed4f6498c1841f755eae16
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public class AcbFieldMissingException : AcbException {
|
||||||
|
|
||||||
|
public AcbFieldMissingException(string fieldName)
|
||||||
|
: base("Missing" + fieldName + "field.") {
|
||||||
|
}
|
||||||
|
|
||||||
|
public AcbFieldMissingException(string fieldName, Exception innerException)
|
||||||
|
: base("Missing" + fieldName + "field.", innerException) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7e6aff4b2afdd3e4ca3ca7314d15b1db
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,289 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using DereTore.Common;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public partial class AcbFile {
|
||||||
|
|
||||||
|
internal override void Initialize() {
|
||||||
|
base.Initialize();
|
||||||
|
InitializeAcbTables();
|
||||||
|
InitializeCueNameToWaveformTable();
|
||||||
|
InitializeAwbArchives();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing) {
|
||||||
|
|
||||||
|
if(_internalAwb != null) { _internalAwb.Dispose(); }
|
||||||
|
if(_externalAwb != null) { _externalAwb.Dispose(); }
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AcbFile(Stream stream, long offset, long size, string acbFileName, bool disposeStream)
|
||||||
|
: this(stream, offset, size, acbFileName, false, disposeStream) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private AcbFile(Stream stream, long offset, long size, string acbFileName, bool includeCueIdInFileName, bool disposeStream)
|
||||||
|
: base(stream, offset, size, acbFileName, disposeStream) {
|
||||||
|
_includeCueIdInFileName = includeCueIdInFileName;
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeAcbTables() {
|
||||||
|
var stream = Stream;
|
||||||
|
long refItemOffset = 0, refItemSize = 0, refCorrection = 0;
|
||||||
|
|
||||||
|
var tables = new Dictionary<string, UtfTable>();
|
||||||
|
_tables = tables;
|
||||||
|
|
||||||
|
var cueTable = GetTable("CueTable");
|
||||||
|
var waveformTable = GetTable("WaveformTable");
|
||||||
|
var synthTable = GetTable("SynthTable");
|
||||||
|
var cues = new AcbCueRecord[cueTable.Rows.Length];
|
||||||
|
_cues = cues;
|
||||||
|
|
||||||
|
for (var i = 0; i < cues.Length; ++i) {
|
||||||
|
var cue = new AcbCueRecord();
|
||||||
|
cue.IsWaveformIdentified = false;
|
||||||
|
cue.CueId = cueTable.GetFieldValueAsNumber<uint>(i, "CueId").Value;
|
||||||
|
cue.ReferenceType = cueTable.GetFieldValueAsNumber<byte>(i, "ReferenceType").Value;
|
||||||
|
cue.ReferenceIndex = cueTable.GetFieldValueAsNumber<ushort>(i, "ReferenceIndex").Value;
|
||||||
|
cues[i] = cue;
|
||||||
|
|
||||||
|
switch (cue.ReferenceType) {
|
||||||
|
case 2:
|
||||||
|
refItemOffset = synthTable.GetFieldOffset(cue.ReferenceIndex, "ReferenceItems").Value;
|
||||||
|
refItemSize = synthTable.GetFieldSize(cue.ReferenceIndex, "ReferenceItems").Value;
|
||||||
|
refCorrection = refItemSize + 2;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
case 8:
|
||||||
|
if (i == 0) {
|
||||||
|
var refItemOffsetNullable = synthTable.GetFieldOffset(0, "ReferenceItems");
|
||||||
|
if (refItemOffsetNullable == null) {
|
||||||
|
throw new AcbFieldMissingException("ReferenceItems");
|
||||||
|
}
|
||||||
|
refItemOffset = refItemOffsetNullable.Value;
|
||||||
|
var refItemSizeNullable = synthTable.GetFieldSize(0, "ReferenceItems");
|
||||||
|
if (refItemSizeNullable == null) {
|
||||||
|
throw new AcbFieldMissingException("ReferenceItems");
|
||||||
|
}
|
||||||
|
refItemSize = refItemSizeNullable.Value;
|
||||||
|
refCorrection = refItemSize - 2;
|
||||||
|
} else {
|
||||||
|
refCorrection += 4;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new FormatException(string.Format("Unexpected ReferenceType '{0}' for CueIndex: '{1}.'", cues[i].ReferenceType, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (refItemSize != 0) {
|
||||||
|
cue.WaveformIndex = stream.PeekUInt16BE(refItemOffset + refCorrection);
|
||||||
|
var isStreamingNullable = waveformTable.GetFieldValueAsNumber<byte>(cue.WaveformIndex, "Streaming");
|
||||||
|
if (isStreamingNullable != null) {
|
||||||
|
cue.IsStreaming = isStreamingNullable.Value != 0;
|
||||||
|
|
||||||
|
var waveformIdNullable = waveformTable.GetFieldValueAsNumber<ushort>(cue.WaveformIndex, "Id");
|
||||||
|
if (waveformIdNullable != null) {
|
||||||
|
cue.WaveformId = waveformIdNullable.Value;
|
||||||
|
} else if (cue.IsStreaming) {
|
||||||
|
waveformIdNullable = waveformTable.GetFieldValueAsNumber<ushort>(cue.WaveformIndex, "StreamAwbId");
|
||||||
|
if (waveformIdNullable == null) {
|
||||||
|
throw new AcbFieldMissingException("StreamAwbId");
|
||||||
|
}
|
||||||
|
cue.WaveformId = waveformIdNullable.Value;
|
||||||
|
} else {
|
||||||
|
// MemoryAwbId is for ADX2LE encoder.
|
||||||
|
waveformIdNullable = waveformTable.GetFieldValueAsNumber<ushort>(cue.WaveformIndex, "MemoryAwbId");
|
||||||
|
if (waveformIdNullable == null) {
|
||||||
|
throw new AcbFieldMissingException("MemoryAwbId");
|
||||||
|
}
|
||||||
|
cue.WaveformId = waveformIdNullable.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var encTypeNullable = waveformTable.GetFieldValueAsNumber<byte>(cue.WaveformIndex, "EncodeType");
|
||||||
|
if (encTypeNullable == null) {
|
||||||
|
throw new AcbFieldMissingException("EncodeType");
|
||||||
|
}
|
||||||
|
cue.EncodeType = encTypeNullable.Value;
|
||||||
|
|
||||||
|
cue.IsWaveformIdentified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeCueNameToWaveformTable() {
|
||||||
|
var cueNameTable = GetTable("CueNameTable");
|
||||||
|
var cues = Cues;
|
||||||
|
var includeCueIdInFileName = _includeCueIdInFileName;
|
||||||
|
var cueNameToWaveform = new Dictionary<string, ushort>();
|
||||||
|
//_cueNameToWaveform = cueNameToWaveform;
|
||||||
|
|
||||||
|
for (var i = 0; i < cueNameTable.Rows.Length; ++i) {
|
||||||
|
var cueIndexNullable = cueNameTable.GetFieldValueAsNumber<ushort>(i, "CueIndex");
|
||||||
|
if (cueIndexNullable == null) {
|
||||||
|
throw new AcbFieldMissingException("CueIndex");
|
||||||
|
}
|
||||||
|
var cueIndex = cueIndexNullable.Value;
|
||||||
|
var cue = cues[cueIndex];
|
||||||
|
if (cue.IsWaveformIdentified) {
|
||||||
|
var cueName = cueNameTable.GetFieldValueAsString(i, "CueName");
|
||||||
|
if (cueName == null) {
|
||||||
|
throw new AcbFieldMissingException("CueName");
|
||||||
|
}
|
||||||
|
cueName += GetExtensionForEncodeType(cue.EncodeType);
|
||||||
|
if (includeCueIdInFileName) {
|
||||||
|
cueName = cue.CueId.ToString("D5") + "_" + cueName;
|
||||||
|
}
|
||||||
|
cue.CueName = cueName;
|
||||||
|
cueNameToWaveform.Add(cueName, cue.WaveformId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeAwbArchives() {
|
||||||
|
var internalAwbSize = GetFieldSize(0, "AwbFile");
|
||||||
|
if (internalAwbSize.HasValue && internalAwbSize.Value > 0) {
|
||||||
|
_internalAwb = GetInternalAwbArchive();
|
||||||
|
}
|
||||||
|
var externalAwbSize = GetFieldSize(0, "StreamAwbAfs2Header");
|
||||||
|
if (externalAwbSize.HasValue && externalAwbSize.Value > 0) {
|
||||||
|
_externalAwb = GetExternalAwbArchive();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stream GetDataStreamFromCueInfo(AcbCueRecord cue, string fileNameForErrorInfo) {
|
||||||
|
if (!cue.IsWaveformIdentified) {
|
||||||
|
throw new InvalidOperationException(string.Format("File '{0}' is not identified.", fileNameForErrorInfo));
|
||||||
|
}
|
||||||
|
if (cue.IsStreaming) {
|
||||||
|
var externalAwb = ExternalAwb;
|
||||||
|
if (externalAwb == null) {
|
||||||
|
throw new InvalidOperationException(string.Format("External AWB does not exist for streaming file '{0}'.", fileNameForErrorInfo));
|
||||||
|
}
|
||||||
|
if (!externalAwb.Files.ContainsKey(cue.WaveformId)) {
|
||||||
|
throw new InvalidOperationException(string.Format("Waveform ID {0} is not found in AWB file {1}.", cue.WaveformId, externalAwb.FileName));
|
||||||
|
}
|
||||||
|
var targetExternalFile = externalAwb.Files[cue.WaveformId];
|
||||||
|
using (var fs = File.Open(externalAwb.FileName, FileMode.Open, FileAccess.Read)) {
|
||||||
|
return AcbHelper.ExtractToNewStream(fs, targetExternalFile.FileOffsetAligned, (int)targetExternalFile.FileLength);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var internalAwb = InternalAwb;
|
||||||
|
if (internalAwb == null) {
|
||||||
|
throw new InvalidOperationException(string.Format("Internal AWB is not found for memory file '{0}' in '{1}'.", fileNameForErrorInfo, AcbFileName));
|
||||||
|
}
|
||||||
|
if (!internalAwb.Files.ContainsKey(cue.WaveformId)) {
|
||||||
|
throw new InvalidOperationException(string.Format("Waveform ID {0} is not found in internal AWB in {1}.", cue.WaveformId, AcbFileName));
|
||||||
|
}
|
||||||
|
var targetInternalFile = internalAwb.Files[cue.WaveformId];
|
||||||
|
return AcbHelper.ExtractToNewStream(Stream, targetInternalFile.FileOffsetAligned, (int)targetInternalFile.FileLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Afs2Archive GetInternalAwbArchive() {
|
||||||
|
var internalAwbOffset = GetFieldOffset(0, "AwbFile");
|
||||||
|
if (internalAwbOffset == null) {
|
||||||
|
throw new AcbFieldMissingException("AwbFile");
|
||||||
|
}
|
||||||
|
var internalAwb = new Afs2Archive(Stream, internalAwbOffset.Value, AcbFileName, false);
|
||||||
|
internalAwb.Initialize();
|
||||||
|
return internalAwb;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Afs2Archive GetExternalAwbArchive() {
|
||||||
|
var acbFileName = AcbFileName;
|
||||||
|
var awbDirPath = Path.GetDirectoryName(acbFileName);
|
||||||
|
var awbBaseFileName = Path.GetFileNameWithoutExtension(acbFileName);
|
||||||
|
string[] awbFiles = null;
|
||||||
|
string awbMask1 = null, awbMask2 = null, awbMask3 = null;
|
||||||
|
|
||||||
|
if (awbFiles == null || awbFiles.Length < 1) {
|
||||||
|
awbMask1 = string.Format(AwbFileNameFormats.Format1, awbBaseFileName);
|
||||||
|
awbFiles = Directory.GetFiles(awbDirPath, awbMask1, SearchOption.TopDirectoryOnly);
|
||||||
|
}
|
||||||
|
if (awbFiles == null || awbFiles.Length < 1) {
|
||||||
|
awbMask2 = string.Format(AwbFileNameFormats.Format2, awbBaseFileName);
|
||||||
|
awbFiles = Directory.GetFiles(awbDirPath, awbMask2, SearchOption.TopDirectoryOnly);
|
||||||
|
}
|
||||||
|
if (awbFiles == null || awbFiles.Length < 1) {
|
||||||
|
awbMask3 = string.Format(AwbFileNameFormats.Format3, awbBaseFileName);
|
||||||
|
awbFiles = Directory.GetFiles(awbDirPath, awbMask3, SearchOption.TopDirectoryOnly);
|
||||||
|
}
|
||||||
|
if (awbFiles.Length < 1) {
|
||||||
|
throw new FileNotFoundException(string.Format("Cannot find AWB file. Please verify corresponding AWB file is named '{0}', '{1}', or '{2}'.", awbMask1, awbMask2, awbMask3));
|
||||||
|
}
|
||||||
|
if (awbFiles.Length > 1) {
|
||||||
|
throw new FileNotFoundException(string.Format("More than one matching AWB file for this ACB. Please verify only one AWB file is named '{0}', '{1}', or '{2}'.", awbMask1, awbMask2, awbMask3));
|
||||||
|
}
|
||||||
|
|
||||||
|
var externalAwbHash = GetFieldValueAsData(0, "StreamAwbHash");
|
||||||
|
var fs = File.Open(awbFiles[0], FileMode.Open, FileAccess.Read);
|
||||||
|
var awbHash = AcbHelper.GetMd5Checksum(fs);
|
||||||
|
Afs2Archive archive;
|
||||||
|
if (AcbHelper.AreDataIdentical(awbHash, externalAwbHash)) {
|
||||||
|
archive = new Afs2Archive(fs, 0, fs.Name, true);
|
||||||
|
archive.Initialize();
|
||||||
|
} else {
|
||||||
|
fs.Dispose();
|
||||||
|
throw new FormatException(string.Format("Checksum of AWB file '{0}' ({1}) does not match MD5 checksum inside ACB file '{2}' ({3}).", fs.Name, BitConverter.ToString(awbHash), acbFileName, BitConverter.ToString(externalAwbHash)));
|
||||||
|
}
|
||||||
|
return archive;
|
||||||
|
}
|
||||||
|
|
||||||
|
private UtfTable ResolveTable(string tableName) {
|
||||||
|
var tableOffset = GetFieldOffset(0, tableName);
|
||||||
|
if (!tableOffset.HasValue) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var tableSize = GetFieldSize(0, tableName);
|
||||||
|
if (!tableSize.HasValue) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var table = new UtfTable(Stream, tableOffset.Value, tableSize.Value, AcbFileName, false);
|
||||||
|
table.Initialize();
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetExtensionForEncodeType(byte encodeType) {
|
||||||
|
string ext;
|
||||||
|
switch ((WaveformEncodeType)encodeType) {
|
||||||
|
case WaveformEncodeType.Adx:
|
||||||
|
ext = ".adx";
|
||||||
|
break;
|
||||||
|
case WaveformEncodeType.Hca:
|
||||||
|
ext = ".hca";
|
||||||
|
break;
|
||||||
|
case WaveformEncodeType.Atrac3:
|
||||||
|
ext = ".at3";
|
||||||
|
break;
|
||||||
|
case WaveformEncodeType.Vag:
|
||||||
|
ext = ".vag";
|
||||||
|
break;
|
||||||
|
case WaveformEncodeType.BcWav:
|
||||||
|
ext = ".bcwav";
|
||||||
|
break;
|
||||||
|
case WaveformEncodeType.NintendoDsp:
|
||||||
|
ext = ".dsp";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ext = string.Format(".et-{0}.bin", encodeType.ToString("D2"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly bool _includeCueIdInFileName;
|
||||||
|
|
||||||
|
private Dictionary<string, UtfTable> _tables;
|
||||||
|
//private Dictionary<string, ushort> _cueNameToWaveform;
|
||||||
|
private AcbCueRecord[] _cues;
|
||||||
|
private Afs2Archive _internalAwb;
|
||||||
|
private Afs2Archive _externalAwb;
|
||||||
|
private string[] _fileNames;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bf2e5893cf0c0744ab2b0d6fb80aae47
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public sealed partial class AcbFile : UtfTable {
|
||||||
|
|
||||||
|
public static AcbFile FromStream(FileStream stream) {
|
||||||
|
return FromStream(stream, 0, stream.Length, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AcbFile FromStream(FileStream stream, bool disposeStream) {
|
||||||
|
return FromStream(stream, 0, stream.Length, disposeStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AcbFile FromStream(FileStream stream, long offset, long size) {
|
||||||
|
return new AcbFile(stream, offset, size, stream.Name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AcbFile FromStream(FileStream stream, long offset, long size, bool disposeStream) {
|
||||||
|
return new AcbFile(stream, offset, size, stream.Name, disposeStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AcbFile FromStream(FileStream stream, long offset, long size, bool includeCueIdInFileName, bool disposeStream) {
|
||||||
|
return new AcbFile(stream, offset, size, stream.Name, includeCueIdInFileName, disposeStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AcbFile FromStream(Stream stream, string acbFileName, bool disposeStream) {
|
||||||
|
return FromStream(stream, 0, stream.Length, acbFileName, disposeStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AcbFile FromStream(Stream stream, long offset, long size, string acbFileName, bool disposeStream) {
|
||||||
|
return new AcbFile(stream, offset, size, acbFileName, disposeStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AcbFile FromStream(Stream stream, long offset, long size, string acbFileName, bool includeCueIdInFileName, bool disposeStream) {
|
||||||
|
return new AcbFile(stream, offset, size, acbFileName, includeCueIdInFileName, disposeStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AcbFile FromFile(string fileName) {
|
||||||
|
var fs = File.Open(fileName, FileMode.Open, FileAccess.Read);
|
||||||
|
return FromStream(fs, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dictionary<string, UtfTable> Tables
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _tables;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AcbCueRecord[] Cues
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _cues;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Afs2Archive InternalAwb
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _internalAwb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Afs2Archive ExternalAwb
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _externalAwb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public UtfTable GetTable(string tableName) {
|
||||||
|
if (_tables == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var tables = _tables;
|
||||||
|
UtfTable table;
|
||||||
|
if (tables.ContainsKey(tableName)) {
|
||||||
|
table = tables[tableName];
|
||||||
|
} else {
|
||||||
|
table = ResolveTable(tableName);
|
||||||
|
if (table != null) {
|
||||||
|
tables.Add(tableName, table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] GetFileNames() {
|
||||||
|
if (_cues != null)
|
||||||
|
{
|
||||||
|
_fileNames = Cues.Select(cue => cue.CueName).ToArray();
|
||||||
|
}
|
||||||
|
return _fileNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool FileExists(string fileName) {
|
||||||
|
return _fileNames != null && _fileNames.Contains(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream OpenDataStream(string fileName) {
|
||||||
|
AcbCueRecord cue;
|
||||||
|
try {
|
||||||
|
cue = Cues.Single(c => c.CueName == fileName);
|
||||||
|
} catch (InvalidOperationException ex) {
|
||||||
|
throw new InvalidOperationException(string.Format("File '{0}' is not found or it has multiple entries.", fileName), ex);
|
||||||
|
}
|
||||||
|
return GetDataStreamFromCueInfo(cue, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream OpenDataStream(uint cueId) {
|
||||||
|
AcbCueRecord cue;
|
||||||
|
var tempFileName = string.Format("cue #{0}", cueId);
|
||||||
|
try {
|
||||||
|
cue = Cues.Single(c => c.CueId == cueId);
|
||||||
|
} catch (InvalidOperationException ex) {
|
||||||
|
throw new InvalidOperationException(string.Format("File '{0}' is not found or it has multiple entries.", tempFileName), ex);
|
||||||
|
}
|
||||||
|
return GetDataStreamFromCueInfo(cue, tempFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetSymbolicFileNameFromCueId(uint cueId) {
|
||||||
|
return string.Format("dat_{0:000000}.bin", cueId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ea2e9f6906272ac4e8c27ad50b313b98
|
||||||
|
timeCreated: 1531897076
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.IO;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
internal static class AcbHelper {
|
||||||
|
|
||||||
|
public static string NameOf<T>(Expression<Func<T>> e)
|
||||||
|
{
|
||||||
|
return ((MemberExpression)e.Body).Member.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool AreDataIdentical(byte[] array1, long offset1, byte[] array2, long offset2, long length) {
|
||||||
|
if (length <= 0) {
|
||||||
|
throw new ArgumentOutOfRangeException(NameOf(() => length));
|
||||||
|
}
|
||||||
|
if (offset1 < 0) {
|
||||||
|
throw new ArgumentOutOfRangeException(NameOf(() => offset1));
|
||||||
|
}
|
||||||
|
if (offset2 < 0) {
|
||||||
|
throw new ArgumentOutOfRangeException(NameOf(() => offset2));
|
||||||
|
}
|
||||||
|
long end1 = offset1 + length, end2 = offset2 + length;
|
||||||
|
if (end1 > array1.LongLength) {
|
||||||
|
throw new IndexOutOfRangeException("Length of array 1 is not enough.");
|
||||||
|
}
|
||||||
|
if (end2 > array2.LongLength) {
|
||||||
|
throw new IndexOutOfRangeException("Length of array 2 is not enough.");
|
||||||
|
}
|
||||||
|
for (; offset1 < end1; ++offset1, ++offset2) {
|
||||||
|
if (array1[offset1] != array2[offset2]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool AreDataIdentical(byte[] array1, int offset1, byte[] array2, int offset2, int length) {
|
||||||
|
return AreDataIdentical(array1, offset1, array2, offset2, (long)length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool AreDataIdentical(byte[] array1, byte[] array2, long length) {
|
||||||
|
return AreDataIdentical(array1, 0, array2, 0, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool AreDataIdentical(byte[] array1, byte[] array2, int length) {
|
||||||
|
return AreDataIdentical(array1, 0, array2, 0, (long)length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool AreDataIdentical(byte[] array1, byte[] array2) {
|
||||||
|
return AreDataIdentical(array1, 0, array2, 0, array1.LongLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int RoundUpToAlignment(int valueToRound, int byteAlignment) {
|
||||||
|
var roundedValue = (valueToRound + byteAlignment - 1) / byteAlignment * byteAlignment;
|
||||||
|
return roundedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static uint RoundUpToAlignment(uint valueToRound, uint byteAlignment) {
|
||||||
|
var roundedValue = (valueToRound + byteAlignment - 1) / byteAlignment * byteAlignment;
|
||||||
|
return roundedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long RoundUpToAlignment(long valueToRound, long byteAlignment) {
|
||||||
|
var roundedValue = (valueToRound + byteAlignment - 1) / byteAlignment * byteAlignment;
|
||||||
|
return roundedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ulong RoundUpToAlignment(ulong valueToRound, ulong byteAlignment) {
|
||||||
|
var roundedValue = (valueToRound + byteAlignment - 1) / byteAlignment * byteAlignment;
|
||||||
|
return roundedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] GetMd5Checksum(Stream stream) {
|
||||||
|
return Md5.ComputeHash(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] GetMd5Checksum(byte[] data) {
|
||||||
|
return Md5.ComputeHash(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream ExtractToNewStream(Stream stream, long offset, int length) {
|
||||||
|
var originalPosition = stream.Position;
|
||||||
|
stream.Seek(offset, SeekOrigin.Begin);
|
||||||
|
var buffer = new byte[length];
|
||||||
|
var memory = new byte[length];
|
||||||
|
long currentIndex = 0;
|
||||||
|
var bytesLeft = length;
|
||||||
|
do {
|
||||||
|
var read = stream.Read(buffer, 0, bytesLeft);
|
||||||
|
Array.Copy(buffer, 0, memory, currentIndex, read);
|
||||||
|
currentIndex += read;
|
||||||
|
bytesLeft -= read;
|
||||||
|
} while (bytesLeft > 0);
|
||||||
|
stream.Position = originalPosition;
|
||||||
|
var memoryStream = new MemoryStream(memory, false) {
|
||||||
|
Capacity = length
|
||||||
|
};
|
||||||
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
return memoryStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly MD5 Md5 = new MD5CryptoServiceProvider();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2154610d9ad88364a9deafa2a52bcf8f
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public sealed class AcbInfo {
|
||||||
|
|
||||||
|
internal AcbInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string VersionString { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6ffc9d74917f4d1408797d11b62fb3d8
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using DereTore.Common;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public sealed class Afs2Archive : DisposableBase {
|
||||||
|
|
||||||
|
public Afs2Archive(Stream stream, long offset, string fileName, bool disposeStream) {
|
||||||
|
_fileName = fileName;
|
||||||
|
_stream = stream;
|
||||||
|
_streamOffset = offset;
|
||||||
|
_disposeStream = disposeStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize() {
|
||||||
|
var stream = _stream;
|
||||||
|
var offset = _streamOffset;
|
||||||
|
var acbFileName = _fileName;
|
||||||
|
if (!IsAfs2Archive(stream, offset)) {
|
||||||
|
throw new FormatException("File '" + acbFileName + "' does not contain a valid AFS2 archive at offset {offset}.");
|
||||||
|
}
|
||||||
|
var fileCount = (int)stream.PeekUInt32LE(offset + 8);
|
||||||
|
if (fileCount > ushort.MaxValue) {
|
||||||
|
throw new IndexOutOfRangeException("File count " + fileCount + " exceeds maximum possible value (65535).");
|
||||||
|
}
|
||||||
|
var files = new Dictionary<int, Afs2FileRecord>(fileCount);
|
||||||
|
_files = files;
|
||||||
|
var byteAlignment = stream.PeekUInt32LE(offset + 12);
|
||||||
|
_byteAlignment = byteAlignment;
|
||||||
|
var version = stream.PeekUInt32LE(offset + 4);
|
||||||
|
_version = version;
|
||||||
|
var offsetFieldSize = (int)(version >> 8) & 0xff; // versionBytes[1], always 4?
|
||||||
|
uint offsetMask = 0;
|
||||||
|
for (var j = 0; j < offsetFieldSize; j++) {
|
||||||
|
offsetMask |= (uint)(0xff << (j * 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
const int invalidCueId = -1;
|
||||||
|
var previousCueId = invalidCueId;
|
||||||
|
var fileOffsetFieldBase = 0x10 + fileCount * 2;
|
||||||
|
for (ushort i = 0; i < fileCount; ++i) {
|
||||||
|
var currentFileOffsetBase = fileOffsetFieldBase + offsetFieldSize * i;
|
||||||
|
var record = new Afs2FileRecord {
|
||||||
|
CueId = stream.PeekUInt16LE(offset + (0x10 + 2 * i)),
|
||||||
|
// TODO: Dynamically judge if the field is U32/U16 or else (see offsetFieldSize).
|
||||||
|
FileOffsetRaw = stream.PeekUInt32LE(offset + currentFileOffsetBase)
|
||||||
|
};
|
||||||
|
record.FileOffsetRaw &= offsetMask;
|
||||||
|
record.FileOffsetRaw += offset;
|
||||||
|
record.FileOffsetAligned = AcbHelper.RoundUpToAlignment(record.FileOffsetRaw, ByteAlignment);
|
||||||
|
if (i == fileCount - 1) {
|
||||||
|
record.FileLength = stream.PeekUInt32LE(offset + currentFileOffsetBase + offsetFieldSize) + offset - record.FileOffsetAligned;
|
||||||
|
}
|
||||||
|
if (previousCueId != invalidCueId) {
|
||||||
|
files[previousCueId].FileLength = record.FileOffsetRaw - files[previousCueId].FileOffsetAligned;
|
||||||
|
}
|
||||||
|
files.Add(record.CueId, record);
|
||||||
|
previousCueId = record.CueId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsAfs2Archive(Stream stream, long offset) {
|
||||||
|
var fileSignature = stream.PeekBytes(offset, 4);
|
||||||
|
return AcbHelper.AreDataIdentical(fileSignature, Afs2Signature);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string FileName { get { return _fileName; } }
|
||||||
|
|
||||||
|
public uint ByteAlignment { get { return _byteAlignment; } }
|
||||||
|
|
||||||
|
public Dictionary<int, Afs2FileRecord> Files { get { return _files; } }
|
||||||
|
|
||||||
|
public uint Version { get { return _version; } }
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing) {
|
||||||
|
if (_disposeStream) {
|
||||||
|
try {
|
||||||
|
_stream.Dispose();
|
||||||
|
} catch (ObjectDisposedException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly byte[] Afs2Signature = { 0x41, 0x46, 0x53, 0x32 }; // 'AFS2'
|
||||||
|
|
||||||
|
private uint _byteAlignment;
|
||||||
|
private Dictionary<int, Afs2FileRecord> _files;
|
||||||
|
private uint _version;
|
||||||
|
private readonly string _fileName;
|
||||||
|
private readonly Stream _stream;
|
||||||
|
private readonly long _streamOffset;
|
||||||
|
private readonly bool _disposeStream;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 877d9df8d8359454ab89db6127e24130
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public sealed class Afs2FileRecord {
|
||||||
|
|
||||||
|
internal Afs2FileRecord() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ushort CueId { get; set; }
|
||||||
|
public long FileOffsetRaw { get; set; }
|
||||||
|
public long FileOffsetAligned { get; set; }
|
||||||
|
public long FileLength { get; set; }
|
||||||
|
public string FileName { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 12f45a00cf528a7499fc4607a12bf688
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
internal static class AwbFileNameFormats {
|
||||||
|
|
||||||
|
public static readonly string Format1 = "{0}_streamfiles.awb";
|
||||||
|
public static readonly string Format2 = "{0}.awb";
|
||||||
|
public static readonly string Format3 = "{0}_STR.awb";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 03ed2a16422c1bd4390cfe34b919f529
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public enum AwbLocation {
|
||||||
|
|
||||||
|
Unknown = 0,
|
||||||
|
Internal = 1,
|
||||||
|
External = 2
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5046b4a5c6de9ec4786f465dbcd47bf9
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public enum ColumnStorage : byte {
|
||||||
|
|
||||||
|
Zero = 0x10,
|
||||||
|
Constant = 0x30,
|
||||||
|
PerRow = 0x50,
|
||||||
|
Constant2 = 0x70,
|
||||||
|
Mask = 0xf0
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 163cfd528c2fa56478013994443e0fbd
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public enum ColumnType : byte {
|
||||||
|
|
||||||
|
Byte = 0x00,
|
||||||
|
SByte = 0x01,
|
||||||
|
UInt16 = 0x02,
|
||||||
|
Int16 = 0x03,
|
||||||
|
UInt32 = 0x04,
|
||||||
|
Int32 = 0x05,
|
||||||
|
UInt64 = 0x06,
|
||||||
|
Int64 = 0x07, // not sure
|
||||||
|
Single = 0x08,
|
||||||
|
Double = 0x09, // not sure
|
||||||
|
String = 0x0a,
|
||||||
|
Data = 0x0b,
|
||||||
|
Mask = 0x0f
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1b90a05d134840b4586cc811f03749bc
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
[StructLayout(LayoutKind.Explicit)]
|
||||||
|
public struct NumericUnion {
|
||||||
|
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public byte U8;
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public sbyte S8;
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public short S16;
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public ushort U16;
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public int S32;
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public uint U32;
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public long S64;
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public ulong U64;
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public float R32;
|
||||||
|
[FieldOffset(0)]
|
||||||
|
public double R64;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f176cf14cdf2e9441bee89b39b26f0e7
|
||||||
|
timeCreated: 1531897076
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 009868f8c43db7746b02378159830aa2
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
public partial class AcbSerializer {
|
||||||
|
|
||||||
|
private byte[] GetTableBytes<T>(T[] tableRows) where T : UtfRowBase {
|
||||||
|
var tableImage = PrepareTable(tableRows);
|
||||||
|
byte[] buffer;
|
||||||
|
using (var memory = new MemoryStream()) {
|
||||||
|
tableImage.WriteTo(memory);
|
||||||
|
//memory.Capacity = (int)AcbHelper.RoundUpToAlignment((int)memory.Length, Alignment);
|
||||||
|
buffer = new byte[memory.Length];
|
||||||
|
//memory.GetBuffer().CopyTo(buffer, 0);
|
||||||
|
Array.Copy(memory.GetBuffer(), buffer, buffer.Length);
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private UtfTableImage PrepareTable<T>(T[] tableRows) where T : UtfRowBase {
|
||||||
|
var tableName = GetTableName(tableRows);
|
||||||
|
var tableImage = new UtfTableImage(tableName, Alignment);
|
||||||
|
foreach (var tableRow in tableRows) {
|
||||||
|
var targetMembers = SerializationHelper.GetSearchTargetFieldsAndProperties(tableRow);
|
||||||
|
var tableImageRow = new List<UtfFieldImage>();
|
||||||
|
tableImage.Rows.Add(tableImageRow);
|
||||||
|
// TODO: Save misc data first, then the tables.
|
||||||
|
foreach (var member in targetMembers) {
|
||||||
|
var fieldInfo = member.FieldInfo;
|
||||||
|
var fieldType = fieldInfo.FieldType;
|
||||||
|
var fieldAttribute = member.FieldAttribute;
|
||||||
|
CheckFieldType(fieldType);
|
||||||
|
var fieldValue = member.FieldInfo.GetValue(tableRow);
|
||||||
|
var fieldImage = new UtfFieldImage {
|
||||||
|
Order = fieldAttribute.Order,
|
||||||
|
Name = string.IsNullOrEmpty(fieldAttribute.FieldName) ? fieldInfo.Name : fieldAttribute.FieldName,
|
||||||
|
Storage = fieldAttribute.Storage,
|
||||||
|
};
|
||||||
|
// Empty tables are treated as empty data.
|
||||||
|
if (IsTypeRowList(fieldType) && fieldValue != null && ((UtfRowBase[])fieldValue).Length > 0) {
|
||||||
|
var tableBytes = GetTableBytes((UtfRowBase[])fieldValue);
|
||||||
|
fieldImage.SetValue(tableBytes);
|
||||||
|
fieldImage.IsTable = true;
|
||||||
|
} else if (fieldType == typeof(byte[]) && member.ArchiveAttribute != null) {
|
||||||
|
var files = new List<byte[]> {
|
||||||
|
(byte[])fieldValue
|
||||||
|
};
|
||||||
|
var archiveBytes = SerializationHelper.GetAfs2ArchiveBytes(files.AsReadOnly(), Alignment);
|
||||||
|
fieldImage.SetValue(archiveBytes);
|
||||||
|
fieldImage.IsTable = true;
|
||||||
|
} else {
|
||||||
|
if (fieldValue == null) {
|
||||||
|
fieldImage.SetNullValue(MapFromRawType(fieldType));
|
||||||
|
} else {
|
||||||
|
fieldImage.SetValue(fieldValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tableImageRow.Add(fieldImage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tableImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CheckFieldType(Type type) {
|
||||||
|
if (!SupportedTypes.Contains(type) && !IsTypeRowList(type)) {
|
||||||
|
throw new InvalidCastException("Unsupported type: '" + type.FullName + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsTypeRowList(Type type) {
|
||||||
|
return type.IsArray && type.HasElementType && type.GetElementType().IsSubclassOf(typeof(UtfRowBase));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ColumnType MapFromRawType(Type rawType) {
|
||||||
|
if (IsTypeRowList(rawType)) {
|
||||||
|
return ColumnType.Data;
|
||||||
|
}
|
||||||
|
var index = SupportedTypes.IndexOf(rawType);
|
||||||
|
return (ColumnType)index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetTableName<T>(T[] tableRows) where T : UtfRowBase {
|
||||||
|
if (tableRows == null) {
|
||||||
|
throw new ArgumentNullException(NameOf(() => tableRows));
|
||||||
|
}
|
||||||
|
if (tableRows.Length < 1) {
|
||||||
|
throw new ArgumentException("There should be at least one row in a table.", NameOf(() => tableRows));
|
||||||
|
}
|
||||||
|
// Assuming all the rows are of the same type.
|
||||||
|
var tableType = tableRows[0].GetType();
|
||||||
|
var tableAttributes = tableType.GetCustomAttributes(typeof(UtfTableAttribute), false);
|
||||||
|
if (tableAttributes.Length == 1) {
|
||||||
|
return ((UtfTableAttribute)tableAttributes[0]).Name;
|
||||||
|
} else {
|
||||||
|
var s = tableType.Name;
|
||||||
|
if (s.EndsWith("Table")) {
|
||||||
|
s = s.Substring(0, s.Length - 5);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly Type[] SupportedTypes = {
|
||||||
|
typeof(byte), typeof(sbyte), typeof(ushort), typeof(short), typeof(uint), typeof(int), typeof(ulong), typeof(long),
|
||||||
|
typeof(float),typeof(double),
|
||||||
|
typeof(string),
|
||||||
|
typeof(byte[])
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6e9ed21e969c0974f852b6d63577ad04
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using DereTore.Common;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
public sealed partial class AcbSerializer {
|
||||||
|
|
||||||
|
public static string NameOf<T>(Expression<Func<T>> e)
|
||||||
|
{
|
||||||
|
return ((MemberExpression)e.Body).Member.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AcbSerializer() {
|
||||||
|
Alignment = 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Serialize<T>(T[] tableRows, Stream serializationStream) where T : UtfRowBase {
|
||||||
|
if (tableRows == null) {
|
||||||
|
throw new ArgumentNullException(NameOf(() => tableRows));
|
||||||
|
}
|
||||||
|
var tableData = GetTableBytes(tableRows).RoundUpTo(Alignment);
|
||||||
|
serializationStream.WriteBytes(tableData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint Alignment {
|
||||||
|
get {
|
||||||
|
return _alignment;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if (value <= 0 || value % 16 != 0) {
|
||||||
|
throw new ArgumentException("Alignment should be a positive integer, also a multiple of 16.", NameOf(() => value));
|
||||||
|
}
|
||||||
|
_alignment = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private uint _alignment;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 64569347a4afa7347b1e1fa83baa4ff7
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
|
||||||
|
internal static class AcbSerializerPrivateUtilities {
|
||||||
|
|
||||||
|
public static int IndexOf(this Type[] types, Type value) {
|
||||||
|
for (var i = 0; i < types.Length; ++i) {
|
||||||
|
if (types[i] == value) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6b4e4cf86c5a23f458e4432890460f7d
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
[AttributeUsage(AttributeTargets.Field)]
|
||||||
|
public sealed class Afs2ArchiveAttribute : Attribute {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d647b12edd11bc543add498843dd38f7
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
internal static class ArrayExtensions {
|
||||||
|
|
||||||
|
public static byte[] RoundUpTo(this byte[] data, int alignment) {
|
||||||
|
var newLength = AcbHelper.RoundUpToAlignment(data.Length, alignment);
|
||||||
|
var buffer = new byte[newLength];
|
||||||
|
data.CopyTo(buffer, 0);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] RoundUpTo(this byte[] data, uint alignment) {
|
||||||
|
var newLength = AcbHelper.RoundUpToAlignment(data.Length, alignment);
|
||||||
|
var buffer = new byte[newLength];
|
||||||
|
data.CopyTo(buffer, 0);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 044a5c10b6b06874aa4823562e88ca12
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
internal sealed class MemberAbstract {
|
||||||
|
|
||||||
|
internal MemberAbstract(FieldInfo fieldInfo, UtfFieldAttribute fieldAttribute, Afs2ArchiveAttribute archiveAttribute) {
|
||||||
|
_FieldInfo = fieldInfo;
|
||||||
|
_FieldAttribute = fieldAttribute;
|
||||||
|
_ArchiveAttribute = archiveAttribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldInfo FieldInfo { get { return _FieldInfo; } }
|
||||||
|
private FieldInfo _FieldInfo;
|
||||||
|
|
||||||
|
public UtfFieldAttribute FieldAttribute { get { return _FieldAttribute; } }
|
||||||
|
private UtfFieldAttribute _FieldAttribute;
|
||||||
|
|
||||||
|
public Afs2ArchiveAttribute ArchiveAttribute { get { return _ArchiveAttribute; } }
|
||||||
|
private Afs2ArchiveAttribute _ArchiveAttribute;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b0e0c0fd76bfca34c988deb86eca234e
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using DereTore.Common;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
internal static class SerializationHelper {
|
||||||
|
|
||||||
|
public static uint RoundUpAsTable(uint value, uint alignment) {
|
||||||
|
// This action seems weird. But it does exist (see Cue table in CGSS song_1001[oneshin]), I don't know why.
|
||||||
|
value = AcbHelper.RoundUpToAlignment(value, 4);
|
||||||
|
if (value % alignment == 0) {
|
||||||
|
value += alignment;
|
||||||
|
}
|
||||||
|
return AcbHelper.RoundUpToAlignment(value, alignment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MemberAbstract[] GetSearchTargetFieldsAndProperties(UtfRowBase tableObject) {
|
||||||
|
var type = tableObject.GetType();
|
||||||
|
var objFields = type.GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic);
|
||||||
|
var validDescriptors = new List<MemberAbstract>();
|
||||||
|
foreach (var field in objFields) {
|
||||||
|
var caField = field.GetCustomAttributes(typeof(UtfFieldAttribute), false);
|
||||||
|
// It is a field that needs serialization.
|
||||||
|
if (caField.Length == 1) {
|
||||||
|
var caArchive = field.GetCustomAttributes(typeof(Afs2ArchiveAttribute), false);
|
||||||
|
var ca1 = caField[0] as UtfFieldAttribute;
|
||||||
|
var ca2 = caArchive.Length == 1 ? caArchive[0] as Afs2ArchiveAttribute : null;
|
||||||
|
validDescriptors.Add(new MemberAbstract(field, ca1, ca2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
validDescriptors.Sort((d1, d2) => d1.FieldAttribute.Order - d2.FieldAttribute.Order);
|
||||||
|
return validDescriptors.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] GetAfs2ArchiveBytes(ReadOnlyCollection<byte[]> files, uint alignment) {
|
||||||
|
if (files.Count == 0) {
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
byte[] buffer;
|
||||||
|
using (var memory = new MemoryStream()) {
|
||||||
|
WriteAfs2ArchiveToStream(files, memory, alignment);
|
||||||
|
buffer = new byte[memory.Length];
|
||||||
|
Array.Copy(memory.GetBuffer(), buffer, buffer.Length);
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteAfs2ArchiveToStream(ReadOnlyCollection<byte[]> files, Stream stream, uint alignment) {
|
||||||
|
var fileCount = (uint)files.Count;
|
||||||
|
if (files.Count >= ushort.MaxValue) {
|
||||||
|
throw new IndexOutOfRangeException("File count " + fileCount +" exceeds maximum possible value (65535).");
|
||||||
|
}
|
||||||
|
if (files.Count != 1) {
|
||||||
|
throw new NotSupportedException("Currently DereTore does not support more than one file.");
|
||||||
|
}
|
||||||
|
stream.WriteBytes(Afs2Archive.Afs2Signature);
|
||||||
|
const uint version = 0x00020401;
|
||||||
|
stream.WriteUInt32LE(version);
|
||||||
|
stream.WriteUInt32LE(fileCount);
|
||||||
|
stream.WriteUInt32LE(alignment);
|
||||||
|
const uint offsetFieldSize = (version >> 8) & 0xff; // version[1], always 4? See Afs2Archive.Initialize().
|
||||||
|
|
||||||
|
// Prepare the fields.
|
||||||
|
var afs2HeaderSegmentSize = 0x10 + // General data
|
||||||
|
2 * fileCount + // Cue IDs
|
||||||
|
offsetFieldSize * fileCount + // File offsets
|
||||||
|
sizeof(uint); // Size of last file (U32)
|
||||||
|
// Assuming the music file always has ID 0 in Waveform table and Cue table.
|
||||||
|
var records = new List<Afs2FileRecord>();
|
||||||
|
var currentFileRawOffset = afs2HeaderSegmentSize;
|
||||||
|
for (ushort i = 0; i < fileCount; ++i) {
|
||||||
|
var record = new Afs2FileRecord {
|
||||||
|
// TODO: Use the Cue table.
|
||||||
|
CueId = i,
|
||||||
|
FileOffsetRaw = currentFileRawOffset,
|
||||||
|
FileOffsetAligned = AcbHelper.RoundUpToAlignment(currentFileRawOffset, alignment)
|
||||||
|
};
|
||||||
|
records.Add(record);
|
||||||
|
currentFileRawOffset = (uint)(record.FileOffsetAligned + files[i].Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastFileEndOffset = currentFileRawOffset;
|
||||||
|
for (var i = 0; i < files.Count; ++i) {
|
||||||
|
stream.WriteUInt16LE(records[i].CueId);
|
||||||
|
}
|
||||||
|
for (var i = 0; i < files.Count; ++i) {
|
||||||
|
stream.WriteUInt32LE((uint)records[i].FileOffsetRaw);
|
||||||
|
}
|
||||||
|
// TODO: Dynamically judge it. See Afs2Archive.Initialize().
|
||||||
|
stream.WriteUInt32LE(lastFileEndOffset);
|
||||||
|
for (var i = 0; i < files.Count; ++i) {
|
||||||
|
stream.SeekAndWriteBytes(files[i], records[i].FileOffsetAligned);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 360766700a675444ab45e71a5a500dee
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
[AttributeUsage(AttributeTargets.Field)]
|
||||||
|
public sealed class UtfFieldAttribute : Attribute {
|
||||||
|
|
||||||
|
public UtfFieldAttribute(int order, ColumnStorage storage = ColumnStorage.PerRow, string fieldName = null) {
|
||||||
|
_Order = order;
|
||||||
|
_Storage = storage;
|
||||||
|
_FieldName = fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Order { get { return _Order; } }
|
||||||
|
private int _Order;
|
||||||
|
|
||||||
|
public string FieldName { get { return _FieldName; } }
|
||||||
|
private string _FieldName;
|
||||||
|
|
||||||
|
public ColumnStorage Storage { get { return _Storage; } }
|
||||||
|
private ColumnStorage _Storage;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1dd355c8369d4654ca82038a9524c907
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+154
@@ -0,0 +1,154 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using DereTore.Common;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
internal sealed class UtfFieldImage : IComparable<UtfFieldImage> {
|
||||||
|
|
||||||
|
public static string NameOf<T>(Expression<Func<T>> e)
|
||||||
|
{
|
||||||
|
return ((MemberExpression)e.Body).Member.Name;
|
||||||
|
}
|
||||||
|
internal UtfFieldImage() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColumnStorage Storage { get; set; }
|
||||||
|
public ColumnType Type { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public NumericUnion NumericValue { get; set; }
|
||||||
|
public byte[] DataValue { get; set; }
|
||||||
|
public string StringValue { get; set; }
|
||||||
|
public int Order { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Table is a subtype of 'data' type. It requires strict byte alignment.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsTable { get; set; }
|
||||||
|
|
||||||
|
public byte[] StringValueBytesCache { get; set; }
|
||||||
|
public byte[] NameBytesCache { get; set; }
|
||||||
|
public uint NameOffset { get; set; }
|
||||||
|
public uint StringOffset { get; set; }
|
||||||
|
public uint DataOffset { get; set; }
|
||||||
|
|
||||||
|
public void SetValue(object value) {
|
||||||
|
ColumnType type;
|
||||||
|
var union = new NumericUnion();
|
||||||
|
if (value is byte) {
|
||||||
|
type = ColumnType.Byte;
|
||||||
|
union.U8 = (byte)value;
|
||||||
|
} else if (value is sbyte) {
|
||||||
|
type = ColumnType.SByte;
|
||||||
|
union.S8 = (sbyte)value;
|
||||||
|
} else if (value is ushort) {
|
||||||
|
type = ColumnType.UInt16;
|
||||||
|
union.U16 = (ushort)value;
|
||||||
|
} else if (value is short) {
|
||||||
|
type = ColumnType.Int16;
|
||||||
|
union.S16 = (short)value;
|
||||||
|
} else if (value is uint) {
|
||||||
|
type = ColumnType.UInt32;
|
||||||
|
union.U32 = (uint)value;
|
||||||
|
} else if (value is int) {
|
||||||
|
type = ColumnType.Int32;
|
||||||
|
union.S32 = (int)value;
|
||||||
|
} else if (value is ulong) {
|
||||||
|
type = ColumnType.UInt64;
|
||||||
|
union.U64 = (ulong)value;
|
||||||
|
} else if (value is long) {
|
||||||
|
type = ColumnType.Int64;
|
||||||
|
union.S64 = (long)value;
|
||||||
|
} else if (value is float) {
|
||||||
|
type = ColumnType.Single;
|
||||||
|
union.R32 = (float)value;
|
||||||
|
} else if (value is double) {
|
||||||
|
type = ColumnType.Double;
|
||||||
|
union.R64 = (double)value;
|
||||||
|
} else if (value is string) {
|
||||||
|
type = ColumnType.String;
|
||||||
|
StringValue = (string)value;
|
||||||
|
} else if (value is byte[]) {
|
||||||
|
type = ColumnType.Data;
|
||||||
|
DataValue = (byte[])value;
|
||||||
|
} else {
|
||||||
|
throw new ArgumentException("Unsupported argument type.", NameOf(() => value));
|
||||||
|
}
|
||||||
|
Type = type;
|
||||||
|
switch (type) {
|
||||||
|
case ColumnType.String:
|
||||||
|
case ColumnType.Data:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
NumericValue = union;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetNullValue(ColumnType type) {
|
||||||
|
switch (type) {
|
||||||
|
case ColumnType.String:
|
||||||
|
StringValue = null;
|
||||||
|
Type = ColumnType.String;
|
||||||
|
break;
|
||||||
|
case ColumnType.Data:
|
||||||
|
DataValue = null;
|
||||||
|
Type = ColumnType.Data;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("Cannot set null value with type " +type+".", NameOf(() => type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteValueTo(Stream stream) {
|
||||||
|
switch (Type) {
|
||||||
|
case ColumnType.Byte:
|
||||||
|
stream.WriteByte(NumericValue.U8);
|
||||||
|
break;
|
||||||
|
case ColumnType.SByte:
|
||||||
|
stream.WriteSByte(NumericValue.S8);
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt16:
|
||||||
|
stream.WriteUInt16BE(NumericValue.U16);
|
||||||
|
break;
|
||||||
|
case ColumnType.Int16:
|
||||||
|
stream.WriteInt16BE(NumericValue.S16);
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt32:
|
||||||
|
stream.WriteUInt32BE(NumericValue.U32);
|
||||||
|
break;
|
||||||
|
case ColumnType.Int32:
|
||||||
|
stream.WriteInt32BE(NumericValue.S32);
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt64:
|
||||||
|
stream.WriteUInt64BE(NumericValue.U64);
|
||||||
|
break;
|
||||||
|
case ColumnType.Int64:
|
||||||
|
stream.WriteInt64BE(NumericValue.S64);
|
||||||
|
break;
|
||||||
|
case ColumnType.Single:
|
||||||
|
stream.WriteSingleBE(NumericValue.R32);
|
||||||
|
break;
|
||||||
|
case ColumnType.Double:
|
||||||
|
stream.WriteDoubleBE(NumericValue.R64);
|
||||||
|
break;
|
||||||
|
case ColumnType.String:
|
||||||
|
stream.WriteUInt32BE(StringOffset);
|
||||||
|
break;
|
||||||
|
case ColumnType.Data:
|
||||||
|
stream.WriteUInt32BE(DataOffset);
|
||||||
|
stream.WriteUInt32BE((uint)DataValue.Length);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(NameOf(() => Type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(UtfFieldImage other) {
|
||||||
|
return this.Order - other.Order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return "UtfFieldImage {{" +Name + "}}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: da3190e7ecc8b194684acb25bf9078ab
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
public abstract class UtfRowBase {
|
||||||
|
|
||||||
|
protected UtfRowBase() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ec10a330a896aa94b9b79fa2b0ff3223
|
||||||
|
timeCreated: 1531897076
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public sealed class UtfTableAttribute : Attribute {
|
||||||
|
|
||||||
|
public UtfTableAttribute(string name) {
|
||||||
|
_Name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name { get { return _Name; } }
|
||||||
|
private string _Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 627f41c382ad0124cb6bbcf8dd58efb1
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+114
@@ -0,0 +1,114 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using DereTore.Common;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
internal sealed partial class UtfTableImage {
|
||||||
|
|
||||||
|
public void WriteTo(Stream bufferStream) {
|
||||||
|
Rows.ForEach(row => {
|
||||||
|
row.Sort((t1, t2) => {
|
||||||
|
if (!ReferenceEquals(t1, t2) && t1.Order == t2.Order) {
|
||||||
|
throw new InvalidOperationException("Each field must have different order.");
|
||||||
|
}
|
||||||
|
return t1.Order - t2.Order;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ProcessStringTable();
|
||||||
|
ProcessDataFields();
|
||||||
|
UtfFieldImage[] orderedDataFieldImages;
|
||||||
|
var header = GetHeader(out orderedDataFieldImages);
|
||||||
|
WriteHeaderTo(header, bufferStream);
|
||||||
|
SetStringFieldRelocations(header);
|
||||||
|
SetExtraDataFieldRelocations(header, orderedDataFieldImages);
|
||||||
|
WriteFieldDescriptorsTo(header, bufferStream);
|
||||||
|
WritePerRowDataTo(header, bufferStream);
|
||||||
|
WriteStringTableTo(header, bufferStream);
|
||||||
|
WriteExtraDataTo(header, bufferStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteHeaderTo(UtfHeader header, Stream bufferStream) {
|
||||||
|
bufferStream.SeekAndWriteBytes(UtfTable.UtfSignature, 0);
|
||||||
|
bufferStream.SeekAndWriteUInt32BE(header.TableSize - 8, 4);
|
||||||
|
bufferStream.SeekAndWriteUInt16BE(1, 8);
|
||||||
|
bufferStream.SeekAndWriteUInt16BE((ushort)(header.PerRowDataOffset - 8), 10);
|
||||||
|
bufferStream.SeekAndWriteUInt32BE(header.StringTableOffset - 8, 12);
|
||||||
|
bufferStream.SeekAndWriteUInt32BE(header.ExtraDataOffset - 8, 16);
|
||||||
|
bufferStream.SeekAndWriteUInt32BE(header.TableNameOffset, 20);
|
||||||
|
bufferStream.SeekAndWriteUInt16BE(header.FieldCount, 24);
|
||||||
|
bufferStream.SeekAndWriteUInt16BE(header.RowSize, 26);
|
||||||
|
bufferStream.SeekAndWriteUInt32BE(header.RowCount, 28);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteFieldDescriptorsTo(UtfHeader header, Stream bufferStream) {
|
||||||
|
bufferStream.Seek(SchemaOffset, SeekOrigin.Begin);
|
||||||
|
var row = Rows[0];
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
bufferStream.WriteByte((byte)((byte)fieldImage.Storage | (byte)fieldImage.Type));
|
||||||
|
bufferStream.WriteUInt32BE(fieldImage.NameOffset);
|
||||||
|
if (fieldImage.Storage == ColumnStorage.Constant || fieldImage.Storage == ColumnStorage.Constant2) {
|
||||||
|
fieldImage.WriteValueTo(bufferStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WritePerRowDataTo(UtfHeader header, Stream bufferStream) {
|
||||||
|
bufferStream.Seek(header.PerRowDataOffset, SeekOrigin.Begin);
|
||||||
|
foreach (var row in Rows) {
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
if (fieldImage.Storage == ColumnStorage.PerRow) {
|
||||||
|
fieldImage.WriteValueTo(bufferStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteStringTableTo(UtfHeader header, Stream bufferStream) {
|
||||||
|
bufferStream.Seek(header.StringTableOffset, SeekOrigin.Begin);
|
||||||
|
bufferStream.WriteBytes(TableNameBytesCache);
|
||||||
|
var row0 = Rows[0];
|
||||||
|
foreach (var fieldImage in row0) {
|
||||||
|
bufferStream.WriteBytes(fieldImage.NameBytesCache);
|
||||||
|
}
|
||||||
|
foreach (var fieldImage in row0) {
|
||||||
|
if ((fieldImage.Storage == ColumnStorage.Constant || fieldImage.Storage == ColumnStorage.Constant2) && fieldImage.Type == ColumnType.String) {
|
||||||
|
bufferStream.WriteBytes(fieldImage.StringValueBytesCache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var row in Rows) {
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
if (fieldImage.Type == ColumnType.String && fieldImage.Storage == ColumnStorage.PerRow) {
|
||||||
|
bufferStream.WriteBytes(fieldImage.StringValueBytesCache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteExtraDataTo(UtfHeader header, Stream bufferStream) {
|
||||||
|
var baseOffset = header.ExtraDataOffset;
|
||||||
|
for (var i = 0; i < Rows.Count; ++i) {
|
||||||
|
var row = Rows[i];
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
if (fieldImage.Type == ColumnType.Data) {
|
||||||
|
var shouldWrite = false;
|
||||||
|
switch (fieldImage.Storage) {
|
||||||
|
case ColumnStorage.Constant:
|
||||||
|
case ColumnStorage.Constant2:
|
||||||
|
shouldWrite = i == 0;
|
||||||
|
break;
|
||||||
|
case ColumnStorage.PerRow:
|
||||||
|
shouldWrite = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (shouldWrite && fieldImage.DataValue.Length > 0) {
|
||||||
|
bufferStream.SeekAndWriteBytes(fieldImage.DataValue, baseOffset + fieldImage.DataOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 01fab10829496e647b2deb517d77c1f6
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+192
@@ -0,0 +1,192 @@
|
|||||||
|
using System;
|
||||||
|
using System.Text;
|
||||||
|
using DereTore.Common;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
internal sealed partial class UtfTableImage {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Some fields are not filled.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public UtfHeader GetHeader(out UtfFieldImage[] orderedDataFieldImages) {
|
||||||
|
// Basic information
|
||||||
|
if (Rows.Count < 1) {
|
||||||
|
throw new InvalidOperationException("Rows should not be empty.");
|
||||||
|
}
|
||||||
|
var fieldCount = Rows[0].Count;
|
||||||
|
for (var i = 1; i < Rows.Count; ++i) {
|
||||||
|
if (Rows[i].Count != fieldCount) {
|
||||||
|
throw new InvalidOperationException("Number of fields in each row do not match.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var header = new UtfHeader {
|
||||||
|
TableName = TableName,
|
||||||
|
RowCount = (uint)Rows.Count,
|
||||||
|
FieldCount = (ushort)fieldCount,
|
||||||
|
Unknown1 = 1,
|
||||||
|
RowSize = GetSingleRowDataSize(),
|
||||||
|
PerRowDataOffset = GetRowDescriptorSize() + SchemaOffset // "per row" data offset, actually
|
||||||
|
};
|
||||||
|
var perRowDataSize = header.RowCount * header.RowSize;
|
||||||
|
header.StringTableOffset = header.PerRowDataOffset + perRowDataSize;
|
||||||
|
header.TableNameOffset = 0;
|
||||||
|
|
||||||
|
var stringTableSize = GetStringTableSize();
|
||||||
|
header.ExtraDataOffset = header.StringTableOffset + stringTableSize;
|
||||||
|
var extraDataSize = GetExtraDataSize(header, out orderedDataFieldImages);
|
||||||
|
|
||||||
|
header.TableSize = header.ExtraDataOffset + extraDataSize;
|
||||||
|
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessStringTable() {
|
||||||
|
TableNameBytesCache = Encoding.ASCII.GetBytes(TableName).Append(0);
|
||||||
|
// Prepare static strings first.
|
||||||
|
var row = Rows[0];
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
fieldImage.NameBytesCache = Encoding.ASCII.GetBytes(fieldImage.Name).Append(0);
|
||||||
|
switch (fieldImage.Storage) {
|
||||||
|
case ColumnStorage.Constant:
|
||||||
|
case ColumnStorage.Constant2:
|
||||||
|
if (fieldImage.Type == ColumnType.String) {
|
||||||
|
if (string.IsNullOrEmpty(fieldImage.StringValue)) {
|
||||||
|
fieldImage.StringValueBytesCache = EmptyAsciiStringBytes;
|
||||||
|
} else {
|
||||||
|
fieldImage.StringValueBytesCache = Encoding.ASCII.GetBytes(fieldImage.StringValue).Append(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var row0 = row;
|
||||||
|
for (var i = 1; i < Rows.Count; ++i) {
|
||||||
|
for (var j = 0; j < Rows[i].Count; ++j) {
|
||||||
|
var fieldImage = Rows[i][j];
|
||||||
|
fieldImage.Name = row0[j].Name;
|
||||||
|
fieldImage.NameBytesCache = row0[j].NameBytesCache;
|
||||||
|
switch (fieldImage.Storage) {
|
||||||
|
case ColumnStorage.Constant:
|
||||||
|
case ColumnStorage.Constant2:
|
||||||
|
if (fieldImage.Type == ColumnType.String) {
|
||||||
|
fieldImage.StringValue = row0[j].StringValue;
|
||||||
|
fieldImage.StringValueBytesCache = row0[j].StringValueBytesCache;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Per-row strings.
|
||||||
|
foreach (var r in Rows) {
|
||||||
|
foreach (var fieldImage in r) {
|
||||||
|
if (fieldImage.Storage == ColumnStorage.PerRow && fieldImage.Type == ColumnType.String) {
|
||||||
|
if (string.IsNullOrEmpty(fieldImage.StringValue)) {
|
||||||
|
fieldImage.StringValueBytesCache = EmptyAsciiStringBytes;
|
||||||
|
} else {
|
||||||
|
fieldImage.StringValueBytesCache = Encoding.ASCII.GetBytes(fieldImage.StringValue).Append(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessDataFields() {
|
||||||
|
foreach (var row in Rows) {
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
if (fieldImage.Type == ColumnType.Data && fieldImage.DataValue == null) {
|
||||||
|
fieldImage.DataValue = EmptyByteArray;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetStringFieldRelocations(UtfHeader header) {
|
||||||
|
// String table
|
||||||
|
var currentStringTableOffset = (uint)TableNameBytesCache.Length;
|
||||||
|
var row0 = Rows[0];
|
||||||
|
var row = row0;
|
||||||
|
// Field names and static strings
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
fieldImage.NameOffset = currentStringTableOffset;
|
||||||
|
currentStringTableOffset += (uint)fieldImage.NameBytesCache.Length;
|
||||||
|
}
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
switch (fieldImage.Storage) {
|
||||||
|
case ColumnStorage.Constant:
|
||||||
|
case ColumnStorage.Constant2:
|
||||||
|
if (fieldImage.Type == ColumnType.String) {
|
||||||
|
fieldImage.StringOffset = currentStringTableOffset;
|
||||||
|
currentStringTableOffset += (uint)fieldImage.StringValueBytesCache.Length;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var i = 1; i < Rows.Count; ++i) {
|
||||||
|
for (var j = 0; j < Rows[i].Count; ++j) {
|
||||||
|
var fieldImage = Rows[i][j];
|
||||||
|
fieldImage.NameOffset = row0[j].NameOffset;
|
||||||
|
switch (fieldImage.Storage) {
|
||||||
|
case ColumnStorage.Constant:
|
||||||
|
case ColumnStorage.Constant2:
|
||||||
|
if (fieldImage.Type == ColumnType.String) {
|
||||||
|
fieldImage.StringOffset = row0[j].StringOffset;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Per-row strings
|
||||||
|
foreach (var r in Rows) {
|
||||||
|
foreach (var fieldImage in r) {
|
||||||
|
if (fieldImage.Storage == ColumnStorage.PerRow && fieldImage.Type == ColumnType.String) {
|
||||||
|
fieldImage.StringOffset = currentStringTableOffset;
|
||||||
|
currentStringTableOffset += (uint)fieldImage.StringValueBytesCache.Length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetExtraDataFieldRelocations(UtfHeader header, UtfFieldImage[] orderedFieldImages) {
|
||||||
|
// This value is already calibrated in GetExtraDataSize(). It will move to a mod16 position if the first item is a table.
|
||||||
|
var baseOffset = header.ExtraDataOffset;
|
||||||
|
var currentOffset = baseOffset;
|
||||||
|
|
||||||
|
foreach (var fieldImage in orderedFieldImages) {
|
||||||
|
if (fieldImage.DataValue.Length > 0) {
|
||||||
|
// For priority, see AddToNewOrderedDataFieldList().
|
||||||
|
if (fieldImage.IsTable) {
|
||||||
|
currentOffset = SerializationHelper.RoundUpAsTable(currentOffset, Alignment);
|
||||||
|
}
|
||||||
|
fieldImage.DataOffset = currentOffset - baseOffset;
|
||||||
|
currentOffset += (uint)fieldImage.DataValue.Length;
|
||||||
|
} else {
|
||||||
|
fieldImage.DataOffset = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var row0 = Rows[0];
|
||||||
|
for (var i = 1; i < Rows.Count; ++i) {
|
||||||
|
for (var j = 0; j < Rows[i].Count; ++j) {
|
||||||
|
var fieldImage = Rows[i][j];
|
||||||
|
if (fieldImage.Type == ColumnType.Data && (fieldImage.Storage == ColumnStorage.Constant || fieldImage.Storage == ColumnStorage.Constant2)) {
|
||||||
|
fieldImage.DataOffset = row0[j].DataOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly byte[] EmptyByteArray = new byte[0];
|
||||||
|
private static readonly byte[] EmptyAsciiStringBytes = new byte[1];
|
||||||
|
private static readonly ushort SchemaOffset = 0x20;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 178a8f31c12b2ac4ab1314cbc26dfe18
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+210
@@ -0,0 +1,210 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
internal sealed partial class UtfTableImage {
|
||||||
|
|
||||||
|
public static string NameOf<T>(Expression<Func<T>> e)
|
||||||
|
{
|
||||||
|
return ((MemberExpression)e.Body).Member.Name;
|
||||||
|
}
|
||||||
|
private uint GetRowDescriptorSize() {
|
||||||
|
uint totalSize = 0;
|
||||||
|
foreach (var row in Rows) {
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
// Storage descriptor (1 byte) + field name offset (4 bytes)
|
||||||
|
totalSize += 5;
|
||||||
|
var storage = fieldImage.Storage;
|
||||||
|
switch (storage) {
|
||||||
|
case ColumnStorage.Constant:
|
||||||
|
case ColumnStorage.Constant2:
|
||||||
|
var type = fieldImage.Type;
|
||||||
|
switch (type) {
|
||||||
|
case ColumnType.Byte:
|
||||||
|
case ColumnType.SByte:
|
||||||
|
totalSize += 1;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt16:
|
||||||
|
case ColumnType.Int16:
|
||||||
|
totalSize += 2;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt32:
|
||||||
|
case ColumnType.Int32:
|
||||||
|
totalSize += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt64:
|
||||||
|
case ColumnType.Int64:
|
||||||
|
totalSize += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.Single:
|
||||||
|
totalSize += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.Double:
|
||||||
|
totalSize += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.String:
|
||||||
|
totalSize += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.Data:
|
||||||
|
totalSize += 4 + 4;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(NameOf(() => type));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ColumnStorage.PerRow:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(NameOf(() => storage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return totalSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Total size of "per row" data is [single row data size] x [row count].
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private ushort GetSingleRowDataSize() {
|
||||||
|
ushort totalSize = 0;
|
||||||
|
var row = Rows[0];
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
var storage = fieldImage.Storage;
|
||||||
|
switch (storage) {
|
||||||
|
case ColumnStorage.PerRow:
|
||||||
|
var type = fieldImage.Type;
|
||||||
|
switch (type) {
|
||||||
|
case ColumnType.Byte:
|
||||||
|
case ColumnType.SByte:
|
||||||
|
totalSize += 1;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt16:
|
||||||
|
case ColumnType.Int16:
|
||||||
|
totalSize += 2;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt32:
|
||||||
|
case ColumnType.Int32:
|
||||||
|
totalSize += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt64:
|
||||||
|
case ColumnType.Int64:
|
||||||
|
totalSize += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.Single:
|
||||||
|
totalSize += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.Double:
|
||||||
|
totalSize += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.String:
|
||||||
|
totalSize += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.Data:
|
||||||
|
totalSize += 4 + 4;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(NameOf(() => type));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ColumnStorage.Constant:
|
||||||
|
case ColumnStorage.Constant2:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(NameOf(() => storage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return totalSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private uint GetStringTableSize() {
|
||||||
|
uint totalSize = 0;
|
||||||
|
totalSize += (uint)TableNameBytesCache.Length;
|
||||||
|
totalSize += Rows[0].Aggregate<UtfFieldImage, uint>(0, (current, fieldImage) => current + (uint)fieldImage.NameBytesCache.Length);
|
||||||
|
for (var i = 0; i < Rows.Count; ++i) {
|
||||||
|
var row = Rows[i];
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
switch (fieldImage.Type) {
|
||||||
|
case ColumnType.String:
|
||||||
|
switch (fieldImage.Storage) {
|
||||||
|
case ColumnStorage.Constant:
|
||||||
|
case ColumnStorage.Constant2:
|
||||||
|
if (i == 0) {
|
||||||
|
totalSize += (uint)fieldImage.StringValueBytesCache.Length;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ColumnStorage.PerRow:
|
||||||
|
totalSize += (uint)fieldImage.StringValueBytesCache.Length;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return totalSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private uint GetExtraDataSize(UtfHeader header, out UtfFieldImage[] orderedDataFieldImages) {
|
||||||
|
var baseOffset = header.ExtraDataOffset;
|
||||||
|
uint totalSize = 0;
|
||||||
|
|
||||||
|
var fieldImagesInNewOrder = new List<UtfFieldImage>();
|
||||||
|
var row0 = Rows[0];
|
||||||
|
var firstTableDataFieldIndex = -1;
|
||||||
|
foreach (var fieldImage in row0) {
|
||||||
|
if (fieldImage.Type == ColumnType.Data && (fieldImage.Storage == ColumnStorage.Constant || fieldImage.Storage == ColumnStorage.Constant2)) {
|
||||||
|
AddToNewOrdererdDataFieldList(fieldImagesInNewOrder, fieldImage, ref firstTableDataFieldIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var row in Rows) {
|
||||||
|
foreach (var fieldImage in row) {
|
||||||
|
if (fieldImage.Type == ColumnType.Data && fieldImage.Storage == ColumnStorage.PerRow) {
|
||||||
|
AddToNewOrdererdDataFieldList(fieldImagesInNewOrder, fieldImage, ref firstTableDataFieldIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the first field is a table, rebase the whole data field.
|
||||||
|
if (firstTableDataFieldIndex == 0) {
|
||||||
|
baseOffset = SerializationHelper.RoundUpAsTable(baseOffset, Alignment);
|
||||||
|
header.ExtraDataOffset = baseOffset;
|
||||||
|
}
|
||||||
|
orderedDataFieldImages = fieldImagesInNewOrder.ToArray();
|
||||||
|
|
||||||
|
foreach (var fieldImage in orderedDataFieldImages) {
|
||||||
|
var rawOffset = baseOffset;
|
||||||
|
if (fieldImage.IsTable && fieldImage.DataValue.Length > 0) {
|
||||||
|
baseOffset = SerializationHelper.RoundUpAsTable(baseOffset, Alignment);
|
||||||
|
}
|
||||||
|
baseOffset += (uint)fieldImage.DataValue.Length;
|
||||||
|
totalSize += (baseOffset - rawOffset);
|
||||||
|
}
|
||||||
|
return totalSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddToNewOrdererdDataFieldList(List<UtfFieldImage> fieldImagesInNewOrder, UtfFieldImage fieldImage, ref int firstTableDataFieldIndex) {
|
||||||
|
// Tables are always the last fields to store.
|
||||||
|
// Priority: [static misc data] > [dynamic static data] > [static table] > [dynamic table]
|
||||||
|
if (fieldImage.IsTable) {
|
||||||
|
fieldImagesInNewOrder.Add(fieldImage);
|
||||||
|
if (firstTableDataFieldIndex < 0) {
|
||||||
|
firstTableDataFieldIndex = fieldImagesInNewOrder.Count - 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (firstTableDataFieldIndex < 0) {
|
||||||
|
fieldImagesInNewOrder.Add(fieldImage);
|
||||||
|
} else {
|
||||||
|
fieldImagesInNewOrder.Insert(firstTableDataFieldIndex, fieldImage);
|
||||||
|
++firstTableDataFieldIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f2b7901b42420df4eb7d93ae5f34b1f1
|
||||||
|
timeCreated: 1531897076
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB.Serialization {
|
||||||
|
internal sealed partial class UtfTableImage {
|
||||||
|
|
||||||
|
internal UtfTableImage(string name, uint alignment) {
|
||||||
|
_Rows = new List<List<UtfFieldImage>>();
|
||||||
|
_TableName = name;
|
||||||
|
_Alignment = alignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string TableName { get { return _TableName; } }
|
||||||
|
private string _TableName;
|
||||||
|
|
||||||
|
public List<List<UtfFieldImage>> Rows { get { return _Rows; } }
|
||||||
|
private List<List<UtfFieldImage>> _Rows;
|
||||||
|
|
||||||
|
public uint Alignment { get { return _Alignment; } }
|
||||||
|
private uint _Alignment;
|
||||||
|
|
||||||
|
private byte[] TableNameBytesCache { get; set; }
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return "UtfTableImage {{" +TableName+"}}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f0b7e5aeadac03340b141cfbbf2bda5a
|
||||||
|
timeCreated: 1531897076
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public sealed class UtfField {
|
||||||
|
|
||||||
|
public static string NameOf<T>(Expression<Func<T>> e)
|
||||||
|
{
|
||||||
|
return ((MemberExpression)e.Body).Member.Name;
|
||||||
|
}
|
||||||
|
internal UtfField() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte Type { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public ColumnType ConstrainedType { get; set; }
|
||||||
|
public NumericUnion NumericValue { get; set; }
|
||||||
|
public byte[] DataValue { get; set; }
|
||||||
|
public string StringValue { get; set; }
|
||||||
|
public long Offset { get; set; }
|
||||||
|
public long Size { get; set; }
|
||||||
|
|
||||||
|
public void SetValue(object value) {
|
||||||
|
ColumnType type;
|
||||||
|
var union = new NumericUnion();
|
||||||
|
if (value is byte) {
|
||||||
|
type = ColumnType.Byte;
|
||||||
|
union.U8 = (byte)value;
|
||||||
|
} else if (value is sbyte) {
|
||||||
|
type = ColumnType.SByte;
|
||||||
|
union.S8 = (sbyte)value;
|
||||||
|
} else if (value is ushort) {
|
||||||
|
type = ColumnType.UInt16;
|
||||||
|
union.U16 = (ushort)value;
|
||||||
|
} else if (value is short) {
|
||||||
|
type = ColumnType.Int16;
|
||||||
|
union.S16 = (short)value;
|
||||||
|
} else if (value is uint) {
|
||||||
|
type = ColumnType.UInt32;
|
||||||
|
union.U32 = (uint)value;
|
||||||
|
} else if (value is int) {
|
||||||
|
type = ColumnType.Int32;
|
||||||
|
union.S32 = (int)value;
|
||||||
|
} else if (value is ulong) {
|
||||||
|
type = ColumnType.UInt64;
|
||||||
|
union.U64 = (ulong)value;
|
||||||
|
} else if (value is long) {
|
||||||
|
type = ColumnType.Int64;
|
||||||
|
union.S64 = (long)value;
|
||||||
|
} else if (value is string) {
|
||||||
|
type = ColumnType.String;
|
||||||
|
StringValue = (string)value;
|
||||||
|
} else if (value is byte[]) {
|
||||||
|
type = ColumnType.Data;
|
||||||
|
DataValue = (byte[])value;
|
||||||
|
} else {
|
||||||
|
throw new ArgumentException("Unsupported argument type.", NameOf(() => value));
|
||||||
|
}
|
||||||
|
ConstrainedType = type;
|
||||||
|
Type = (byte)type;
|
||||||
|
switch (type) {
|
||||||
|
case ColumnType.String:
|
||||||
|
case ColumnType.Data:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
NumericValue = union;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public object GetValue() {
|
||||||
|
var constrainedType = ConstrainedType;
|
||||||
|
object ret;
|
||||||
|
switch (constrainedType) {
|
||||||
|
case ColumnType.Byte:
|
||||||
|
ret = NumericValue.U8;
|
||||||
|
break;
|
||||||
|
case ColumnType.SByte:
|
||||||
|
ret = NumericValue.S8;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt16:
|
||||||
|
ret = NumericValue.U16;
|
||||||
|
break;
|
||||||
|
case ColumnType.Int16:
|
||||||
|
ret = NumericValue.S16;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt32:
|
||||||
|
ret = NumericValue.U32;
|
||||||
|
break;
|
||||||
|
case ColumnType.Int32:
|
||||||
|
ret = NumericValue.S32;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt64:
|
||||||
|
ret = NumericValue.U64;
|
||||||
|
break;
|
||||||
|
case ColumnType.Int64:
|
||||||
|
ret = NumericValue.S64;
|
||||||
|
break;
|
||||||
|
case ColumnType.Single:
|
||||||
|
ret = NumericValue.R32;
|
||||||
|
break;
|
||||||
|
case ColumnType.Double:
|
||||||
|
ret = NumericValue.R64;
|
||||||
|
break;
|
||||||
|
case ColumnType.String:
|
||||||
|
ret = StringValue;
|
||||||
|
break;
|
||||||
|
case ColumnType.Data:
|
||||||
|
ret = DataValue;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(NameOf(() => constrainedType));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 655b2e2c4ebb5764bbaa16f5d3f88c64
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public sealed class UtfHeader {
|
||||||
|
|
||||||
|
internal UtfHeader() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint TableSize { get; set; }
|
||||||
|
public ushort Unknown1 { get; set; }
|
||||||
|
public uint PerRowDataOffset { get; set; }
|
||||||
|
public uint StringTableOffset { get; set; }
|
||||||
|
public uint ExtraDataOffset { get; set; }
|
||||||
|
public uint TableNameOffset { get; set; }
|
||||||
|
public string TableName { get; set; }
|
||||||
|
public ushort FieldCount { get; set; }
|
||||||
|
public ushort RowSize { get; set; }
|
||||||
|
public uint RowCount { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e3a4f64ddf2dc474898f08c952f44164
|
||||||
|
timeCreated: 1531897076
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using DereTore.Common;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
internal sealed class UtfReader {
|
||||||
|
|
||||||
|
public UtfReader() {
|
||||||
|
_isEncrypted = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UtfReader(byte seed, byte increment) {
|
||||||
|
_seed = seed;
|
||||||
|
_increment = increment;
|
||||||
|
_isEncrypted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsEncrypted { get { return _isEncrypted; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stream"></param>
|
||||||
|
/// <param name="baseOffset">Offset of the UTF table, starting from the beginning of ACB file.</param>
|
||||||
|
/// <param name="size">Requested data size.</param>
|
||||||
|
/// <param name="utfOffset">Offset of the bytes to read, starting from the beginning of the UTF table.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public byte[] PeekBytes(Stream stream, long baseOffset, int size, long utfOffset) {
|
||||||
|
var data = stream.PeekBytes(baseOffset + utfOffset, size);
|
||||||
|
if (!IsEncrypted) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
if (utfOffset < _currentUtfOffset) {
|
||||||
|
_currentUtfOffset = 0;
|
||||||
|
}
|
||||||
|
if (_currentUtfOffset == 0) {
|
||||||
|
_currentXor = _seed;
|
||||||
|
}
|
||||||
|
for (var j = _currentUtfOffset; j < utfOffset; j++) {
|
||||||
|
if (j > 0) {
|
||||||
|
_currentXor *= _increment;
|
||||||
|
}
|
||||||
|
_currentUtfOffset++;
|
||||||
|
}
|
||||||
|
for (long i = 0; i < size; i++) {
|
||||||
|
if ((_currentUtfOffset != 0) || (i > 0)) {
|
||||||
|
_currentXor *= _increment;
|
||||||
|
}
|
||||||
|
|
||||||
|
data[i] ^= _currentXor;
|
||||||
|
_currentUtfOffset++;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte PeekByte(Stream stream, long baseOffset, long utfOffset) {
|
||||||
|
var data = stream.PeekByte(baseOffset + utfOffset);
|
||||||
|
if (!IsEncrypted) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
if (utfOffset < _currentUtfOffset) {
|
||||||
|
_currentUtfOffset = 0;
|
||||||
|
}
|
||||||
|
if (_currentUtfOffset == 0) {
|
||||||
|
_currentXor = _seed;
|
||||||
|
}
|
||||||
|
for (var j = _currentUtfOffset; j < utfOffset; j++) {
|
||||||
|
if (j > 0) {
|
||||||
|
_currentXor *= _increment;
|
||||||
|
}
|
||||||
|
_currentUtfOffset++;
|
||||||
|
}
|
||||||
|
if (_currentUtfOffset != 0) {
|
||||||
|
_currentXor *= _increment;
|
||||||
|
}
|
||||||
|
data ^= _currentXor;
|
||||||
|
_currentUtfOffset++;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sbyte PeekSByte(Stream stream, long baseOffset, long utfOffset) {
|
||||||
|
unchecked {
|
||||||
|
return (sbyte)PeekByte(stream, baseOffset, utfOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ushort PeekUInt16(Stream stream, long baseOffset, long utfOffset) {
|
||||||
|
var temp = PeekBytes(stream, baseOffset, 2, utfOffset);
|
||||||
|
if (BitConverter.IsLittleEndian) {
|
||||||
|
Array.Reverse(temp);
|
||||||
|
}
|
||||||
|
return BitConverter.ToUInt16(temp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public short PeekInt16(Stream stream, long baseOffset, long utfOffset) {
|
||||||
|
var temp = PeekBytes(stream, baseOffset, 2, utfOffset);
|
||||||
|
if (BitConverter.IsLittleEndian) {
|
||||||
|
Array.Reverse(temp);
|
||||||
|
}
|
||||||
|
return BitConverter.ToInt16(temp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint PeekUInt32(Stream stream, long baseOffset, long utfOffset) {
|
||||||
|
var temp = PeekBytes(stream, baseOffset, 4, utfOffset);
|
||||||
|
if (BitConverter.IsLittleEndian) {
|
||||||
|
Array.Reverse(temp);
|
||||||
|
}
|
||||||
|
return BitConverter.ToUInt32(temp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int PeekInt32(Stream stream, long baseOffset, long utfOffset) {
|
||||||
|
var temp = PeekBytes(stream, baseOffset, 4, utfOffset);
|
||||||
|
if (BitConverter.IsLittleEndian) {
|
||||||
|
Array.Reverse(temp);
|
||||||
|
}
|
||||||
|
return BitConverter.ToInt32(temp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ulong PeekUInt64(Stream stream, long baseOffset, long utfOffset) {
|
||||||
|
var temp = PeekBytes(stream, baseOffset, 8, utfOffset);
|
||||||
|
if (BitConverter.IsLittleEndian) {
|
||||||
|
Array.Reverse(temp);
|
||||||
|
}
|
||||||
|
return BitConverter.ToUInt64(temp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float PeekSingle(Stream stream, long baseOffset, long utfOffset) {
|
||||||
|
var temp = PeekBytes(stream, baseOffset, 4, utfOffset);
|
||||||
|
if (BitConverter.IsLittleEndian) {
|
||||||
|
Array.Reverse(temp);
|
||||||
|
}
|
||||||
|
return BitConverter.ToSingle(temp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ReadZeroEndedStringAsAscii(Stream stream, long baseOffset, long utfOffset) {
|
||||||
|
if (!IsEncrypted) {
|
||||||
|
return stream.PeekZeroEndedStringAsAscii(baseOffset + utfOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.Position = baseOffset + utfOffset;
|
||||||
|
if (utfOffset < _currentUtfStringOffset) {
|
||||||
|
_currentUtfStringOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_currentUtfStringOffset == 0) {
|
||||||
|
_currentStringXor = _seed;
|
||||||
|
}
|
||||||
|
for (var j = _currentUtfStringOffset; j < utfOffset; j++) {
|
||||||
|
if (j > 0) {
|
||||||
|
_currentStringXor *= _increment;
|
||||||
|
}
|
||||||
|
_currentUtfStringOffset++;
|
||||||
|
}
|
||||||
|
|
||||||
|
var asciiVal = new StringBuilder();
|
||||||
|
var remained = stream.Length - stream.Position - (baseOffset + utfOffset);
|
||||||
|
for (var i = 0; i < remained; i++) {
|
||||||
|
_currentStringXor *= _increment;
|
||||||
|
_currentUtfStringOffset++;
|
||||||
|
var encryptedByte = (byte)stream.ReadByte();
|
||||||
|
var decryptedByte = (byte)(encryptedByte ^ _currentStringXor);
|
||||||
|
if (decryptedByte == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
asciiVal.Append((char)decryptedByte);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return asciiVal.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly bool _isEncrypted;
|
||||||
|
private readonly byte _increment;
|
||||||
|
private readonly byte _seed;
|
||||||
|
|
||||||
|
private byte _currentXor;
|
||||||
|
private long _currentUtfOffset;
|
||||||
|
private byte _currentStringXor;
|
||||||
|
private long _currentUtfStringOffset;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 991ae559b3d1cd44fa41249bbd3fd446
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,372 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using DereTore.Common;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public partial class UtfTable {
|
||||||
|
|
||||||
|
internal UtfTable(Stream stream, long offset, long size, string acbFileName, bool disposeStream) {
|
||||||
|
_acbFileName = acbFileName;
|
||||||
|
_stream = stream;
|
||||||
|
_offset = offset;
|
||||||
|
_size = size;
|
||||||
|
_disposeStream = disposeStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal virtual void Initialize() {
|
||||||
|
var stream = _stream;
|
||||||
|
var offset = _offset;
|
||||||
|
|
||||||
|
var magic = stream.PeekBytes(offset, 4);
|
||||||
|
magic = CheckEncryption(magic);
|
||||||
|
if (!AcbHelper.AreDataIdentical(magic, UtfSignature)) {
|
||||||
|
throw new FormatException(string.Format("'@UTF' signature (or its encrypted equivalent) is not found in '{0}' at offset 0x{1:x8}.",_acbFileName,offset));
|
||||||
|
}
|
||||||
|
using (var tableDataStream = GetTableDataStream()) {
|
||||||
|
var header = GetUtfHeader(tableDataStream);
|
||||||
|
_utfHeader = header;
|
||||||
|
_rows = new Dictionary<string, UtfField>[header.RowCount];
|
||||||
|
if (header.TableSize > 0) {
|
||||||
|
InitializeUtfSchema(stream, tableDataStream, 0x20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing) {
|
||||||
|
if (_disposeStream) {
|
||||||
|
try {
|
||||||
|
_stream.Dispose();
|
||||||
|
} catch (ObjectDisposedException) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool GetKeysForEncryptedUtfTable(byte[] encryptedUtfSignature, out byte seed, out byte increment) {
|
||||||
|
for (var s = 0; s <= byte.MaxValue; s++) {
|
||||||
|
if ((encryptedUtfSignature[0] ^ s) != UtfSignature[0]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (var i = 0; i <= byte.MaxValue; i++) {
|
||||||
|
var m = (byte)(s * i);
|
||||||
|
if ((encryptedUtfSignature[1] ^ m) != UtfSignature[1]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var t = (byte)i;
|
||||||
|
for (var j = 2; j < UtfSignature.Length; j++) {
|
||||||
|
m *= t;
|
||||||
|
if ((encryptedUtfSignature[j] ^ m) != UtfSignature[j]) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (j < UtfSignature.Length - 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
seed = (byte)s;
|
||||||
|
increment = (byte)i;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seed = 0;
|
||||||
|
increment = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] CheckEncryption(byte[] magicBytes) {
|
||||||
|
if (AcbHelper.AreDataIdentical(magicBytes, UtfSignature)) {
|
||||||
|
_isEncrypted = false;
|
||||||
|
_utfReader = new UtfReader();
|
||||||
|
return magicBytes;
|
||||||
|
} else {
|
||||||
|
_isEncrypted = true;
|
||||||
|
byte seed, increment;
|
||||||
|
var keysFound = GetKeysForEncryptedUtfTable(magicBytes, out seed, out increment);
|
||||||
|
if (!keysFound) {
|
||||||
|
throw new FormatException(string.Format("Unable to decrypt UTF table at offset 0x{0:x8}",_offset));
|
||||||
|
} else {
|
||||||
|
_utfReader = new UtfReader(seed, increment);
|
||||||
|
}
|
||||||
|
return UtfSignature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stream GetTableDataStream() {
|
||||||
|
var stream = _stream;
|
||||||
|
var offset = _offset;
|
||||||
|
var tableSize = (int)_utfReader.PeekUInt32(stream, offset, 4) + 8;
|
||||||
|
if (!IsEncrypted) {
|
||||||
|
return AcbHelper.ExtractToNewStream(stream, offset, tableSize);
|
||||||
|
}
|
||||||
|
// Another reading process. Unlike the one with direct reading, this may encounter UTF table decryption.
|
||||||
|
var originalPosition = stream.Position;
|
||||||
|
var totalBytesRead = 0;
|
||||||
|
var memory = new byte[tableSize];
|
||||||
|
var currentIndex = 0;
|
||||||
|
var currentOffset = offset;
|
||||||
|
do {
|
||||||
|
var shouldRead = tableSize - totalBytesRead;
|
||||||
|
var buffer = _utfReader.PeekBytes(stream, currentOffset, shouldRead, totalBytesRead);
|
||||||
|
Array.Copy(buffer, 0, memory, currentIndex, buffer.Length);
|
||||||
|
currentOffset += buffer.Length;
|
||||||
|
currentIndex += buffer.Length;
|
||||||
|
totalBytesRead += buffer.Length;
|
||||||
|
} while (totalBytesRead < tableSize);
|
||||||
|
stream.Position = originalPosition;
|
||||||
|
var memoryStream = new MemoryStream(memory, false) {
|
||||||
|
Capacity = tableSize
|
||||||
|
};
|
||||||
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
return memoryStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static UtfHeader GetUtfHeader(Stream stream) {
|
||||||
|
return GetUtfHeader(stream, stream.Position);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static UtfHeader GetUtfHeader(Stream stream, long offset) {
|
||||||
|
if (offset != stream.Position) {
|
||||||
|
stream.Seek(offset, SeekOrigin.Begin);
|
||||||
|
}
|
||||||
|
var header = new UtfHeader {
|
||||||
|
TableSize = stream.PeekUInt32BE(offset + 4),
|
||||||
|
Unknown1 = stream.PeekUInt16BE(offset + 8),
|
||||||
|
PerRowDataOffset = (uint)stream.PeekUInt16BE(offset + 10) + 8,
|
||||||
|
StringTableOffset = stream.PeekUInt32BE(offset + 12) + 8,
|
||||||
|
ExtraDataOffset = stream.PeekUInt32BE(offset + 16) + 8,
|
||||||
|
TableNameOffset = stream.PeekUInt32BE(offset + 20),
|
||||||
|
FieldCount = stream.PeekUInt16BE(offset + 24),
|
||||||
|
RowSize = stream.PeekUInt16BE(offset + 26),
|
||||||
|
RowCount = stream.PeekUInt32BE(offset + 28)
|
||||||
|
};
|
||||||
|
header.TableName = stream.PeekZeroEndedStringAsAscii(header.StringTableOffset + header.TableNameOffset);
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeUtfSchema(Stream sourceStream, Stream tableDataStream, long schemaOffset) {
|
||||||
|
var header = _utfHeader;
|
||||||
|
var rows = _rows;
|
||||||
|
var baseOffset = _offset;
|
||||||
|
for (uint i = 0; i < header.RowCount; i++) {
|
||||||
|
var currentOffset = schemaOffset;
|
||||||
|
var row = new Dictionary<string, UtfField>();
|
||||||
|
rows[i] = row;
|
||||||
|
long currentRowOffset = 0;
|
||||||
|
long currentRowBase = header.PerRowDataOffset + header.RowSize * i;
|
||||||
|
|
||||||
|
for (var j = 0; j < header.FieldCount; j++) {
|
||||||
|
var field = new UtfField {
|
||||||
|
Type = tableDataStream.PeekByte(currentOffset)
|
||||||
|
};
|
||||||
|
|
||||||
|
long nameOffset = tableDataStream.PeekInt32BE(currentOffset + 1);
|
||||||
|
field.Name = tableDataStream.PeekZeroEndedStringAsAscii(header.StringTableOffset + nameOffset);
|
||||||
|
|
||||||
|
var union = new NumericUnion();
|
||||||
|
var constrainedStorage = (ColumnStorage)(field.Type & (byte)ColumnStorage.Mask);
|
||||||
|
var constrainedType = (ColumnType)(field.Type & (byte)ColumnType.Mask);
|
||||||
|
switch (constrainedStorage) {
|
||||||
|
case ColumnStorage.Constant:
|
||||||
|
case ColumnStorage.Constant2:
|
||||||
|
var constantOffset = currentOffset + 5;
|
||||||
|
long dataOffset;
|
||||||
|
switch (constrainedType) {
|
||||||
|
case ColumnType.String:
|
||||||
|
dataOffset = tableDataStream.PeekInt32BE(constantOffset);
|
||||||
|
field.StringValue = tableDataStream.PeekZeroEndedStringAsAscii(header.StringTableOffset + dataOffset);
|
||||||
|
currentOffset += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.Int64:
|
||||||
|
union.S64 = tableDataStream.PeekInt64BE(constantOffset);
|
||||||
|
currentOffset += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt64:
|
||||||
|
union.U64 = tableDataStream.PeekUInt64BE(constantOffset);
|
||||||
|
currentOffset += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.Data:
|
||||||
|
dataOffset = tableDataStream.PeekUInt32BE(constantOffset);
|
||||||
|
long dataSize = tableDataStream.PeekUInt32BE(constantOffset + 4);
|
||||||
|
field.Offset = baseOffset + header.ExtraDataOffset + dataOffset;
|
||||||
|
field.Size = dataSize;
|
||||||
|
// don't think this is encrypted, need to check
|
||||||
|
field.DataValue = sourceStream.PeekBytes(field.Offset, (int)dataSize);
|
||||||
|
currentOffset += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.Double:
|
||||||
|
union.R64 = tableDataStream.PeekDoubleBE(constantOffset);
|
||||||
|
currentOffset += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.Single:
|
||||||
|
union.R32 = tableDataStream.PeekSingleBE(constantOffset);
|
||||||
|
currentOffset += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.Int32:
|
||||||
|
union.S32 = tableDataStream.PeekInt32BE(constantOffset);
|
||||||
|
currentOffset += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt32:
|
||||||
|
union.U32 = tableDataStream.PeekUInt32BE(constantOffset);
|
||||||
|
currentOffset += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.Int16:
|
||||||
|
union.S16 = tableDataStream.PeekInt16BE(constantOffset);
|
||||||
|
currentOffset += 2;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt16:
|
||||||
|
union.U16 = tableDataStream.PeekUInt16BE(constantOffset);
|
||||||
|
currentOffset += 2;
|
||||||
|
break;
|
||||||
|
case ColumnType.SByte:
|
||||||
|
union.S8 = tableDataStream.PeekSByte(constantOffset);
|
||||||
|
currentOffset += 1;
|
||||||
|
break;
|
||||||
|
case ColumnType.Byte:
|
||||||
|
union.U8 = tableDataStream.PeekByte(constantOffset);
|
||||||
|
currentOffset += 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new FormatException(string.Format("Unknown column type at offset: 0x{0:x8}",currentOffset));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ColumnStorage.PerRow:
|
||||||
|
// read the constant depending on the type
|
||||||
|
long rowDataOffset;
|
||||||
|
switch (constrainedType) {
|
||||||
|
case ColumnType.String:
|
||||||
|
rowDataOffset = tableDataStream.PeekUInt32BE(currentRowBase + currentRowOffset);
|
||||||
|
field.StringValue = tableDataStream.PeekZeroEndedStringAsAscii(header.StringTableOffset + rowDataOffset);
|
||||||
|
currentRowOffset += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.Int64:
|
||||||
|
union.S64 = tableDataStream.PeekInt64BE(currentRowBase + currentRowOffset);
|
||||||
|
currentRowOffset += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt64:
|
||||||
|
union.U64 = tableDataStream.PeekUInt64BE(currentRowBase + currentRowOffset);
|
||||||
|
currentRowOffset += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.Data:
|
||||||
|
rowDataOffset = tableDataStream.PeekUInt32BE(currentRowBase + currentRowOffset);
|
||||||
|
long rowDataSize = tableDataStream.PeekUInt32BE(currentRowBase + currentRowOffset + 4);
|
||||||
|
field.Offset = baseOffset + header.ExtraDataOffset + rowDataOffset;
|
||||||
|
field.Size = rowDataSize;
|
||||||
|
// don't think this is encrypted
|
||||||
|
field.DataValue = sourceStream.PeekBytes(field.Offset, (int)rowDataSize);
|
||||||
|
currentRowOffset += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.Double:
|
||||||
|
union.R64 = tableDataStream.PeekDoubleBE(currentRowBase + currentRowOffset);
|
||||||
|
currentRowOffset += 8;
|
||||||
|
break;
|
||||||
|
case ColumnType.Single:
|
||||||
|
union.R32 = tableDataStream.PeekSingleBE(currentRowBase + currentRowOffset);
|
||||||
|
currentRowOffset += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.Int32:
|
||||||
|
union.S32 = tableDataStream.PeekInt32BE(currentRowBase + currentRowOffset);
|
||||||
|
currentRowOffset += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt32:
|
||||||
|
union.U32 = tableDataStream.PeekUInt32BE(currentRowBase + currentRowOffset);
|
||||||
|
currentRowOffset += 4;
|
||||||
|
break;
|
||||||
|
case ColumnType.Int16:
|
||||||
|
union.S16 = tableDataStream.PeekInt16BE(currentRowBase + currentRowOffset);
|
||||||
|
currentRowOffset += 2;
|
||||||
|
break;
|
||||||
|
case ColumnType.UInt16:
|
||||||
|
union.U16 = tableDataStream.PeekUInt16BE(currentRowBase + currentRowOffset);
|
||||||
|
currentRowOffset += 2;
|
||||||
|
break;
|
||||||
|
case ColumnType.SByte:
|
||||||
|
union.S8 = tableDataStream.PeekSByte(currentRowBase + currentRowOffset);
|
||||||
|
currentRowOffset += 1;
|
||||||
|
break;
|
||||||
|
case ColumnType.Byte:
|
||||||
|
union.U8 = tableDataStream.PeekByte(currentRowBase + currentRowOffset);
|
||||||
|
currentRowOffset += 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new FormatException(string.Format("Unknown column type at offset: 0x{0:x8}",currentOffset));
|
||||||
|
}
|
||||||
|
field.ConstrainedType = (ColumnType)field.Type;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new FormatException(string.Format("Unknown column storage at offset: 0x{0:x8}",currentOffset));
|
||||||
|
}
|
||||||
|
// Union polyfill
|
||||||
|
field.ConstrainedType = constrainedType;
|
||||||
|
switch (constrainedType) {
|
||||||
|
case ColumnType.String:
|
||||||
|
case ColumnType.Data:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
field.NumericValue = union;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
row.Add(field.Name, field);
|
||||||
|
currentOffset += 5; // sizeof(CriField.Type + CriField.NameOffset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private object GetFieldValue(int rowIndex, string fieldName) {
|
||||||
|
var rows = Rows;
|
||||||
|
if (rowIndex >= rows.Length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var row = rows[rowIndex];
|
||||||
|
return row.ContainsKey(fieldName) ? row[fieldName].GetValue() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal T? GetFieldValueAsNumber<T>(int rowIndex, string fieldName) where T : struct {
|
||||||
|
return (T?)GetFieldValue(rowIndex, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal string GetFieldValueAsString(int rowIndex, string fieldName) {
|
||||||
|
return (string)GetFieldValue(rowIndex, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal byte[] GetFieldValueAsData(int rowIndex, string fieldName) {
|
||||||
|
return (byte[])GetFieldValue(rowIndex, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal long? GetFieldOffset(int rowIndex, string fieldName) {
|
||||||
|
var rows = Rows;
|
||||||
|
if (rowIndex >= rows.Length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var row = rows[rowIndex];
|
||||||
|
if (row.ContainsKey(fieldName)) {
|
||||||
|
return row[fieldName].Offset;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal long? GetFieldSize(int rowIndex, string fieldName) {
|
||||||
|
var rows = Rows;
|
||||||
|
if (rowIndex >= rows.Length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var row = rows[rowIndex];
|
||||||
|
if (row.ContainsKey(fieldName)) {
|
||||||
|
return row[fieldName].Size;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static readonly byte[] UtfSignature = { 0x40, 0x55, 0x54, 0x46 }; // '@UTF'
|
||||||
|
|
||||||
|
private readonly string _acbFileName;
|
||||||
|
private readonly Stream _stream;
|
||||||
|
private readonly long _offset;
|
||||||
|
private readonly long _size;
|
||||||
|
private readonly bool _disposeStream;
|
||||||
|
|
||||||
|
private UtfReader _utfReader;
|
||||||
|
private bool _isEncrypted;
|
||||||
|
private UtfHeader _utfHeader;
|
||||||
|
private Dictionary<string, UtfField>[] _rows;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 026cd89ef1e6dc0459e9710f4de76eb0
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using DereTore.Common;
|
||||||
|
|
||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
public partial class UtfTable : DisposableBase {
|
||||||
|
|
||||||
|
public Stream Stream { get { return _stream; } }
|
||||||
|
|
||||||
|
public string AcbFileName { get { return _acbFileName; } }
|
||||||
|
|
||||||
|
public long Offset { get { return _offset; } }
|
||||||
|
|
||||||
|
public long Size { get { return _size; } }
|
||||||
|
|
||||||
|
public bool IsEncrypted { get { return _isEncrypted; } }
|
||||||
|
|
||||||
|
public UtfHeader Header { get { return _utfHeader; } }
|
||||||
|
|
||||||
|
public Dictionary<string, UtfField>[] Rows { get { return _rows; } }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f0b5145b64163484e9eb044c13ba2501
|
||||||
|
timeCreated: 1531897076
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace DereTore.Exchange.Archive.ACB {
|
||||||
|
internal enum WaveformEncodeType : byte {
|
||||||
|
|
||||||
|
Adx = 0,
|
||||||
|
Hca = 2,
|
||||||
|
Vag = 7,
|
||||||
|
Atrac3 = 8,
|
||||||
|
BcWav = 9,
|
||||||
|
NintendoDsp = 13
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 288b3ea33829f824798f005a030f974b
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b3a6d513df0fa794faa2de4b34366ad8
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace DereTore.Common {
|
||||||
|
public static class ArrayExtensions {
|
||||||
|
|
||||||
|
public static void ZeroMem(this int[] array) {
|
||||||
|
if (array == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < array.Length; ++i) {
|
||||||
|
array[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ZeroMem(this uint[] array) {
|
||||||
|
if (array == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < array.Length; ++i) {
|
||||||
|
array[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ZeroMem(this byte[] array) {
|
||||||
|
if (array == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < array.Length; ++i) {
|
||||||
|
array[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ZeroMem(this float[] array) {
|
||||||
|
if (array == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < array.Length; ++i) {
|
||||||
|
array[i] = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int Write(this byte[] array, uint value, int index) {
|
||||||
|
if (!BitConverter.IsLittleEndian) {
|
||||||
|
value = DereToreHelper.SwapEndian(value);
|
||||||
|
}
|
||||||
|
var bytes = BitConverter.GetBytes(value);
|
||||||
|
for (var i = 0; i < 4; ++i) {
|
||||||
|
array[index + i] = bytes[i];
|
||||||
|
}
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int Write<T>(this byte[] array, T value, int index) where T : struct {
|
||||||
|
var size = Marshal.SizeOf(typeof(T));
|
||||||
|
var bytes = new byte[size];
|
||||||
|
var ptr = Marshal.AllocHGlobal(size);
|
||||||
|
Marshal.StructureToPtr(value, ptr, true);
|
||||||
|
Marshal.Copy(ptr, bytes, 0, size);
|
||||||
|
Marshal.FreeHGlobal(ptr);
|
||||||
|
Array.Copy(bytes, 0, array, index, size);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int Write(this byte[] array, byte[] value, int index) {
|
||||||
|
var length = value.Length;
|
||||||
|
Array.Copy(value, 0, array, index, length);
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] Append(this byte[] data, byte[] toAppend) {
|
||||||
|
var buffer = new byte[data.Length + toAppend.Length];
|
||||||
|
data.CopyTo(buffer, 0);
|
||||||
|
toAppend.CopyTo(buffer, data.Length);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] Append(this byte[] data, byte toAppend) {
|
||||||
|
var buffer = new byte[data.Length + 1];
|
||||||
|
data.CopyTo(buffer, 0);
|
||||||
|
buffer[buffer.Length - 1] = toAppend;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int IndexOf<T>(this T[] array, T item) {
|
||||||
|
for (var i = 0; i < array.Length; ++i) {
|
||||||
|
if (EqualityComparer<T>.Default.Equals(array[i], item)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1cfdaab710a2ee046b5af4a155189dde
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DereTore.Common {
|
||||||
|
public static class DereToreHelper {
|
||||||
|
|
||||||
|
public static ushort SwapEndian(ushort v) {
|
||||||
|
var r = (ushort)(v & 0xff);
|
||||||
|
r <<= 8;
|
||||||
|
v >>= 8;
|
||||||
|
r |= (ushort)(v & 0xff);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static short SwapEndian(short v) {
|
||||||
|
unchecked {
|
||||||
|
var s = (ushort)v;
|
||||||
|
return (short)SwapEndian(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static uint SwapEndian(uint v) {
|
||||||
|
var r = v & 0xff;
|
||||||
|
r <<= 8;
|
||||||
|
v >>= 8;
|
||||||
|
r |= v & 0xff;
|
||||||
|
r <<= 8;
|
||||||
|
v >>= 8;
|
||||||
|
r |= v & 0xff;
|
||||||
|
r <<= 8;
|
||||||
|
v >>= 8;
|
||||||
|
r |= v & 0xff;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int SwapEndian(int v) {
|
||||||
|
unchecked {
|
||||||
|
var s = (uint)v;
|
||||||
|
return (int)SwapEndian(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ulong SwapEndian(ulong v) {
|
||||||
|
var r = v & 0xff;
|
||||||
|
r <<= 8;
|
||||||
|
v >>= 8;
|
||||||
|
r |= v & 0xff;
|
||||||
|
r <<= 8;
|
||||||
|
v >>= 8;
|
||||||
|
r |= v & 0xff;
|
||||||
|
r <<= 8;
|
||||||
|
v >>= 8;
|
||||||
|
r |= v & 0xff;
|
||||||
|
r <<= 8;
|
||||||
|
v >>= 8;
|
||||||
|
r |= v & 0xff;
|
||||||
|
r <<= 8;
|
||||||
|
v >>= 8;
|
||||||
|
r |= v & 0xff;
|
||||||
|
r <<= 8;
|
||||||
|
v >>= 8;
|
||||||
|
r |= v & 0xff;
|
||||||
|
r <<= 8;
|
||||||
|
v >>= 8;
|
||||||
|
r |= v & 0xff;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long SwapEndian(long v) {
|
||||||
|
unchecked {
|
||||||
|
var s = (ulong)v;
|
||||||
|
return (long)SwapEndian(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float SwapEndian(float v) {
|
||||||
|
var bytes = BitConverter.GetBytes(v);
|
||||||
|
var b = bytes[0];
|
||||||
|
bytes[0] = bytes[1];
|
||||||
|
bytes[1] = b;
|
||||||
|
b = bytes[2];
|
||||||
|
bytes[2] = bytes[3];
|
||||||
|
bytes[3] = b;
|
||||||
|
return BitConverter.ToSingle(bytes, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double SwapEndian(double v) {
|
||||||
|
var bytes = BitConverter.GetBytes(v);
|
||||||
|
Array.Reverse(bytes);
|
||||||
|
return BitConverter.ToDouble(bytes, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Swap<T>(ref T t1, ref T t2) {
|
||||||
|
var t = t1;
|
||||||
|
t1 = t2;
|
||||||
|
t2 = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 47686260da6f9ee49b544500cbbe9f39
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DereTore.Common {
|
||||||
|
public abstract class DisposableBase : IDisposable {
|
||||||
|
|
||||||
|
protected DisposableBase() {
|
||||||
|
_isDisposed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
if (_isDisposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Dispose(true);
|
||||||
|
_isDisposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsDisposed { get { return _isDisposed; } }
|
||||||
|
|
||||||
|
protected abstract void Dispose(bool disposing);
|
||||||
|
|
||||||
|
private bool _isDisposed;
|
||||||
|
|
||||||
|
~DisposableBase() {
|
||||||
|
if (_isDisposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Dispose(false);
|
||||||
|
_isDisposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dab724b4f02f71747b62e2fbf8502fd9
|
||||||
|
timeCreated: 1531897075
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace DereTore.Common {
|
||||||
|
public enum Endian {
|
||||||
|
|
||||||
|
BigEndian,
|
||||||
|
LittleEndian
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 17d9c97d6a3f7aa4ca6dc74325e6245f
|
||||||
|
timeCreated: 1531897074
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace DereTore.Common {
|
||||||
|
public class EndianBinaryReader : BinaryReader {
|
||||||
|
|
||||||
|
public static string NameOf<T>(Expression<Func<T>> e)
|
||||||
|
{
|
||||||
|
return ((MemberExpression)e.Body).Member.Name;
|
||||||
|
}
|
||||||
|
public EndianBinaryReader(Stream stream, Endian endian)
|
||||||
|
: base(stream) {
|
||||||
|
Endian = endian;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Endian Endian { get; set; }
|
||||||
|
|
||||||
|
public void Seek(long position, SeekOrigin origin) {
|
||||||
|
switch (origin) {
|
||||||
|
case SeekOrigin.Begin:
|
||||||
|
Position = position;
|
||||||
|
break;
|
||||||
|
case SeekOrigin.Current:
|
||||||
|
Position += position;
|
||||||
|
break;
|
||||||
|
case SeekOrigin.End:
|
||||||
|
Position = BaseStream.Length - position;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(NameOf(() => origin), origin, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long Position {
|
||||||
|
get { return BaseStream.Position; }
|
||||||
|
set { BaseStream.Position = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override short ReadInt16() {
|
||||||
|
if (Endian != SystemEndian.Type) {
|
||||||
|
var value = base.ReadInt16();
|
||||||
|
value = DereToreHelper.SwapEndian(value);
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return base.ReadInt16();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int ReadInt32() {
|
||||||
|
if (Endian != SystemEndian.Type) {
|
||||||
|
var value = base.ReadInt32();
|
||||||
|
value = DereToreHelper.SwapEndian(value);
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return base.ReadInt32();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override long ReadInt64() {
|
||||||
|
if (Endian != SystemEndian.Type) {
|
||||||
|
var value = base.ReadInt64();
|
||||||
|
value = DereToreHelper.SwapEndian(value);
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return base.ReadInt64();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ushort ReadUInt16() {
|
||||||
|
if (Endian != SystemEndian.Type) {
|
||||||
|
var value = base.ReadUInt16();
|
||||||
|
value = DereToreHelper.SwapEndian(value);
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return base.ReadUInt16();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override uint ReadUInt32() {
|
||||||
|
if (Endian != SystemEndian.Type) {
|
||||||
|
var value = base.ReadUInt32();
|
||||||
|
value = DereToreHelper.SwapEndian(value);
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return base.ReadUInt32();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ulong ReadUInt64() {
|
||||||
|
if (Endian != SystemEndian.Type) {
|
||||||
|
var value = base.ReadUInt64();
|
||||||
|
value = DereToreHelper.SwapEndian(value);
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return base.ReadUInt64();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override float ReadSingle() {
|
||||||
|
if (Endian != SystemEndian.Type) {
|
||||||
|
var value = base.ReadSingle();
|
||||||
|
value = DereToreHelper.SwapEndian(value);
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return base.ReadSingle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override double ReadDouble() {
|
||||||
|
if (Endian != SystemEndian.Type) {
|
||||||
|
var value = base.ReadDouble();
|
||||||
|
value = DereToreHelper.SwapEndian(value);
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return base.ReadDouble();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user