Skip to content

Commit

Permalink
handle packet xor and blowfish
Browse files Browse the repository at this point in the history
  • Loading branch information
shnok committed Jun 27, 2024
1 parent e56d222 commit d94c6ac
Show file tree
Hide file tree
Showing 21 changed files with 969 additions and 170 deletions.
211 changes: 103 additions & 108 deletions l2-unity/Assets/Scenes/Menu.unity
Original file line number Diff line number Diff line change
Expand Up @@ -233,41 +233,6 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2bc6245aea0342f4f8c76719bfe12012, type: 3}
--- !u!21 &580384090
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Height Fog Global
m_Shader: {fileID: 4800000, guid: 3a7ef1b66bafb7a448a880ef76d2e6e6, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs: []
m_Ints: []
m_Floats:
- _AdvancedCat: 1
- _Banner: 1
- _DirectionalCat: 1
- _FogCat: 1
- _HeightFogGlobal: 1
- _IsHeightFogShader: 1
- _NoiseCat: 1
- _SkyboxCat: 1
m_Colors: []
m_BuildTextureStacks: []
--- !u!1 &803395386
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -382,6 +347,75 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 83fdd740fc38f874e98662e404ccb3d1, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!21 &888419019
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Override
m_Shader: {fileID: 4800000, guid: a3a3bc8785681554d9558e2ea68f100e, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs: []
m_Ints: []
m_Floats:
- _AdvancedCat: 1
- _Banner: 1
- _DirectionalCat: 1
- _DirectionalFalloff: 2
- _DirectionalIntensity: 1
- _FarDistanceHeight: 0
- _FarDistanceOffset: 0
- _FogAxisMode: 1
- _FogCameraMode: 0
- _FogCat: 1
- _FogColorDuo: 1
- _FogDistanceEnd: 100
- _FogDistanceFalloff: 2
- _FogDistanceStart: 0
- _FogHeightEnd: 100
- _FogHeightFalloff: 2
- _FogHeightStart: 0
- _FogIntensity: 1
- _FogLayersMode: 0
- _IsHeightFogPreset: 1
- _IsHeightFogShader: 1
- _JitterIntensity: 1
- _NoiseCat: 1
- _NoiseDistanceEnd: 50
- _NoiseIntensity: 1
- _NoiseMax: 1
- _NoiseMin: 0
- _NoiseModeBlend: 1
- _NoiseScale: 30
- _SkyboxCat: 1
- _SkyboxFogBottom: 0
- _SkyboxFogFalloff: 1
- _SkyboxFogFill: 1
- _SkyboxFogHeight: 1
- _SkyboxFogIntensity: 1
- _SkyboxFogOffset: 0
m_Colors:
- _DirectionalColor: {r: 1, g: 0.7793103, b: 0.5, a: 1}
- _DirectionalDir: {r: 0, g: 0, b: 0, a: 0}
- _FogAxisOption: {r: 0, g: 0, b: 0, a: 0}
- _FogColorEnd: {r: 0.8862745, g: 1.443137, b: 2, a: 1}
- _FogColorStart: {r: 0.4411765, g: 0.722515, b: 1, a: 1}
- _NoiseSpeed: {r: 0.5, g: 0, b: 0.5, a: 0}
m_BuildTextureStacks: []
--- !u!1001 &1001879169
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -612,7 +646,7 @@ PrefabInstance:
- target: {fileID: 14083907825353274, guid: 8742fc349ac4f354d9cfb98ebb79a0e3, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 1652434060}
objectReference: {fileID: 1875641955}
- target: {fileID: 2134954596300280144, guid: 8742fc349ac4f354d9cfb98ebb79a0e3, type: 3}
propertyPath: m_Name
value: Height Fog Global
Expand Down Expand Up @@ -863,12 +897,42 @@ PrefabInstance:
propertyPath: m_Name
value: Networking
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 2437028863278307910, guid: babd2d27777f4774581e9efa23af7856, type: 3}
- {fileID: 1960525163452634930, guid: babd2d27777f4774581e9efa23af7856, type: 3}
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 3645245019413108373, guid: babd2d27777f4774581e9efa23af7856, type: 3}
insertIndex: -1
addedObject: {fileID: 1733393677}
m_SourcePrefab: {fileID: 100100000, guid: babd2d27777f4774581e9efa23af7856, type: 3}
--- !u!21 &1652434060
--- !u!1 &1733393672 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 3645245019413108373, guid: babd2d27777f4774581e9efa23af7856, type: 3}
m_PrefabInstance: {fileID: 1447152442}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1733393677
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1733393672}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 40a8cf2805911f4418a5e04ed1e25378, type: 3}
m_Name:
m_EditorClassIdentifier:
_serverIp: 127.0.0.1
_serverPort: 2106
_username:
_connectionTimeoutMs: 10000
_logReceivedPackets: 1
_logSentPackets: 1
_serverIp: 127.0.0.1
_serverPort: 9014
--- !u!21 &1875641955
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -903,75 +967,6 @@ Material:
- _SkyboxCat: 1
m_Colors: []
m_BuildTextureStacks: []
--- !u!21 &1910091392
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Override
m_Shader: {fileID: 4800000, guid: a3a3bc8785681554d9558e2ea68f100e, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs: []
m_Ints: []
m_Floats:
- _AdvancedCat: 1
- _Banner: 1
- _DirectionalCat: 1
- _DirectionalFalloff: 2
- _DirectionalIntensity: 1
- _FarDistanceHeight: 0
- _FarDistanceOffset: 0
- _FogAxisMode: 1
- _FogCameraMode: 0
- _FogCat: 1
- _FogColorDuo: 1
- _FogDistanceEnd: 100
- _FogDistanceFalloff: 2
- _FogDistanceStart: 0
- _FogHeightEnd: 100
- _FogHeightFalloff: 2
- _FogHeightStart: 0
- _FogIntensity: 1
- _FogLayersMode: 0
- _IsHeightFogPreset: 1
- _IsHeightFogShader: 1
- _JitterIntensity: 1
- _NoiseCat: 1
- _NoiseDistanceEnd: 50
- _NoiseIntensity: 1
- _NoiseMax: 1
- _NoiseMin: 0
- _NoiseModeBlend: 1
- _NoiseScale: 30
- _SkyboxCat: 1
- _SkyboxFogBottom: 0
- _SkyboxFogFalloff: 1
- _SkyboxFogFill: 1
- _SkyboxFogHeight: 1
- _SkyboxFogIntensity: 1
- _SkyboxFogOffset: 0
m_Colors:
- _DirectionalColor: {r: 1, g: 0.7793103, b: 0.5, a: 1}
- _DirectionalDir: {r: 0, g: 0, b: 0, a: 0}
- _FogAxisOption: {r: 0, g: 0, b: 0, a: 0}
- _FogColorEnd: {r: 0.8862745, g: 1.443137, b: 2, a: 1}
- _FogColorStart: {r: 0.4411765, g: 0.722515, b: 1, a: 1}
- _NoiseSpeed: {r: 0.5, g: 0, b: 0.5, a: 0}
m_BuildTextureStacks: []
--- !u!114 &1769945945372889719
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,30 @@
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using L2_login;

public class AsynchronousClient {
public static byte[] STATIC_BLOWFISH_KEY = {
(byte) 0x6b,
(byte) 0x60,
(byte) 0xcb,
(byte) 0x5b,
(byte) 0x82,
(byte) 0xce,
(byte) 0x90,
(byte) 0xb1,
(byte) 0xcc,
(byte) 0x2b,
(byte) 0x6c,
(byte) 0x55,
(byte) 0x6c,
(byte) 0x6c,
(byte) 0x6c,
(byte) 0x6c
};

private BlowfishEngine _blowfish;
private Socket _socket;
private string _ipAddress;
private string _username;
Expand All @@ -15,17 +35,29 @@ public class AsynchronousClient {
private ClientPacketHandler _clientPacketHandler;
private ServerPacketHandler _serverPacketHandler;
private DefaultClient _client;
private bool _initPacket = true;

private byte[] _blowfishKey;
public byte[] BlowfishKey { get { return _blowfishKey; } set { _blowfishKey = value; } }

public int Ping { get; set; }

public AsynchronousClient(string ip, int port, DefaultClient client, ClientPacketHandler clientPacketHandler, ServerPacketHandler serverPacketHandler) {
SetBlowFishKey(STATIC_BLOWFISH_KEY);
_ipAddress = ip;
_port = port;
_clientPacketHandler = clientPacketHandler;
_serverPacketHandler = serverPacketHandler;
_clientPacketHandler.SetClient(this);
_serverPacketHandler.SetClient(this, _clientPacketHandler);
_client = client;

}

public void SetBlowFishKey(byte[] blowfishKey) {
_blowfishKey = blowfishKey;
_blowfish = new BlowfishEngine();
_blowfish.init(false, AsynchronousClient.STATIC_BLOWFISH_KEY);
}

public bool Connect() {
Expand Down Expand Up @@ -79,33 +111,44 @@ public void SendPacket(ClientPacket packet) {
}

public void StartReceiving() {
Debug.Log("Start receiving");

using (NetworkStream stream = new NetworkStream(_socket)) {
for(;;) {
int lengthHi;
int lengthLo;
int length;

for (;;) {
if(!_connected) {
Debug.LogWarning("Disconnected.");
break;
}
int packetType = stream.ReadByte();
if (packetType == -1 || !_connected) {

lengthLo = stream.ReadByte();
lengthHi = stream.ReadByte();
length = (lengthHi * 256) + lengthLo;

if (lengthHi == -1 || !_connected) {
Debug.Log("Server terminated the connection.");
Disconnect();
break;
}

int packetLength = stream.ReadByte();
byte[] packet = new byte[packetLength];
packet[0] = (byte)packetType;
packet[1] = (byte)packetLength;

int received = 0;
int readCount = 0;

while ((readCount != -1) && (received < packet.Length - 2)) {
readCount = stream.Read(packet, 2, packet.Length - 2);
received += readCount;
Debug.Log("lengthLo: " + lengthLo);
Debug.Log("lengthHi: " + lengthHi);
Debug.Log("Packet length: " + length);

byte[] data = new byte[length];

int receivedBytes = 0;
int newBytes = 0;
while ((newBytes != -1) && (receivedBytes < (length))) {
newBytes = stream.Read(data, 0, length);
receivedBytes = receivedBytes + newBytes;
}

Task.Run(() => _serverPacketHandler.HandlePacketAsync(packet));

Task.Run(() => _serverPacketHandler.HandlePacketAsync(data, _blowfish, _initPacket));
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions l2-unity/Assets/Scripts/Networking/ClientLibrary/Crypto.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d94c6ac

Please sign in to comment.