// I/O // From byte buffer public void Import(byte[] buffer) { Destroy(); // Generate a ulong GUID m_Guid = CRC64.Compute(buffer); // Read the buffer using (MemoryStream ms = new MemoryStream(buffer)) { m_TexData = new byte[(int)(ms.Length)]; ms.Read(m_TexData, 0, (int)(ms.Length)); } m_Tex = new Texture2D(4, 4); if (!m_Tex.LoadImage(m_TexData)) { Destroy(); Texture2D tex = Resources.Load(s_DefaultTexPath) as Texture2D; m_TexData = tex.EncodeToPNG(); m_Tex = new Texture2D(4, 4); if (!m_Tex.LoadImage(m_TexData)) { Debug.LogError("Can't find default decal texture!"); Destroy(); m_Tex = new Texture2D(16, 16, TextureFormat.ARGB32, false); m_TexData = m_Tex.EncodeToPNG(); } } m_Tex.filterMode = FilterMode.Trilinear; m_Tex.wrapMode = TextureWrapMode.Clamp; }
void EndSendConnect(IAsyncResult ar) { try { _client.EndConnect(ar); //_status = EFileStatus.CHECKING; _fileData.HashCode = CRC64.Compute(_stream); _stream.Position = 0; //_status = EFileStatus.SENDING; NetworkStream netStream = _client.GetStream(); BinaryWriter bw = new BinaryWriter(netStream); byte head = 0xDD; bw.Write(head); bw.Write(_fileData.HashCode); bw.Write(_fileData.FileName); bw.Write(_fileData.FileLength); bw.Write(_account); ReadStream(); } catch (Exception e) { Close(); LogManager.Error(e); } }
public static long ComputeHash(string str) { if (str == null || str == "") { return(0); } str = str.ToLower().Replace('\\', '.').Replace('/', '.'); return((long)crc64.Compute(str)); }
internal static void LoadSteamItems() { _SteamItems.Clear(); string[] fileNames = Directory.GetFiles(VCConfig.s_CreationNetCachePath, "*" + VCConfig.s_CreationNetCacheFileExt); foreach (string name in fileNames) { FileInfo file = new FileInfo(name); Stream stream = file.OpenRead(); ulong hashCode = CRC64.Compute(stream); string[] nameSplit = file.Name.Split('.'); _SteamItems[hashCode] = nameSplit[0]; } }
void OnDownLoadFileCallBack(byte[] fileData, PublishedFileId_t p_id, bool bOK, int index = -1, int dungeonId = -1) { if (isActve == false) { return; } //bool DonLoadSucess = false; if (bOK) { if (mItemsMap.ContainsKey(p_id)) { if (mItemsMap[p_id] != null) { SteamPreFileAndVoteDetail detail = mItemsMap[p_id]; VCIsoHeadData headData; string creation = "Object"; if (VCIsoData.ExtractHeader(fileData, out headData) > 0) { creation = headData.Category.ToString(); creation = creation.Substring(2, creation.Length - 2); } string downLoadFilePath = VCConfig.s_IsoPath + string.Format("/Download/{0}/", creation); string netCacheFilePath = VCConfig.s_CreationNetCachePath; string downLoadFileName = detail.m_rgchTitle; string netCacheFileName = CRC64.Compute(fileData).ToString(); if (SaveToFile(fileData, downLoadFileName, downLoadFilePath, VCConfig.s_IsoFileExt)) { UIWorkShopCtrl.AddDownloadFileName(mItemsMap[p_id].m_rgchTitle + VCConfig.s_IsoFileExt, mIsPrivate); mDownMap[p_id] = 100; } //lz-2016.05.30 保存一份到NetCache路径下,避免NetCache重复下载 SaveToFile(fileData, netCacheFileName, netCacheFilePath, VCConfig.s_CreationNetCacheFileExt); } } } else { mDownMap[p_id] = -1; MessageBox_N.ShowOkBox(PELocalization.GetString(8000493)); } // if (e_DownLoadFile != null) // e_DownLoadFile(filePath,DonLoadSucess); }
public static void SendIsoDataToServer(string name, string desc, byte[] preIso, byte[] isoData, string[] tags, bool sendToServer = true, ulong fileId = 0, bool free = false) { #if PLANET_EXPLORERS //ulong hash_code = CRC64.Compute(isodata); //FileTransManager.RegisterISO(hash_code, isodata); #endif #if SteamVersion SteamWorkShop.SendFile(null, name, desc, preIso, isoData, tags, sendToServer, -1, fileId, free); #else ulong hash_code = CRC64.Compute(isoData); //FileTransManager.RegisterISO(hash_code, isoData); #endif }
void RecveiveCallback(IAsyncResult ar) { try { NetworkStream netStream = _client.GetStream(); int recvLength = netStream.EndRead(ar); _stream.Write(_buffer, 0, recvLength); _pos += recvLength; if (_pos < _fileData.FileLength) { netStream.BeginRead(_buffer, 0, FileConst.BlockSize, new AsyncCallback(RecveiveCallback), null); } else { _stream.Position = 0; ulong hashCode = CRC64.Compute(_stream); bool successed = hashCode == _fileData.HashCode; if (null != _stream) { _stream.Close(); _stream = null; } if (successed) { string fileName = _path + _fileData.FileName; if (File.Exists(fileName)) { File.Delete(fileName); } string fileTmp = _path + _fileData.FileName + ".tmp"; File.Move(fileTmp, fileName); } if (null != CompleteEvent) { CompleteEvent(this, new FileCompleteEventArgs(successed)); } } } catch (Exception e) { Close(); throw e; } }
// Calculate a group of made-material's hash code (64 bit) public static ulong CalcMatGroupHash(VAMaterial[] mats) { string mat_guids = ""; for (int i = 0; i < mats.Length; i++) { if (mats[i] != null) { mat_guids += mats[i].m_Guid.ToString(); } else { mat_guids += "null"; } } return(CRC64.Compute(System.Text.Encoding.UTF8.GetBytes(mat_guids))); }
// Create decal data file public static bool CreateDecalDataFile(VCDecalAsset vcdcl) { try { byte[] buffer = vcdcl.Export(); ulong guid = CRC64.Compute(buffer); string sguid = guid.ToString("X").PadLeft(16, '0'); FileStream fs = new FileStream(VCConfig.s_DecalPath + sguid + VCConfig.s_DecalFileExt, FileMode.Create, FileAccess.ReadWrite); fs.Write(buffer, 0, buffer.Length); fs.Close(); return(true); } catch (Exception) { return(false); } }
// Load Resource public bool LoadRes() { string fn1 = VCConfig.s_CreationPath + HashString + VCConfig.s_CreationFileExt; string fn2 = VCConfig.s_CreationNetCachePath + HashString + VCConfig.s_CreationNetCacheFileExt; string fn = ""; if (File.Exists(fn1)) { fn = fn1; } else if (File.Exists(fn2)) { fn = fn2; } if (fn.Length == 0) { return(false); } try { using (FileStream fs = new FileStream(fn, FileMode.Open)) { m_Resource = new byte [(int)(fs.Length)]; fs.Read(m_Resource, 0, (int)(fs.Length)); fs.Close(); } #if SteamVersion #else if (m_HashCode != CRC64.Compute(m_Resource)) { Debug.LogError("Load Creation Resource Error: \r\nContent doesn't match the hash code"); return(false); } #endif return(ReadRes()); } catch (Exception e) { Debug.LogError("Load Creation Resource Error: \r\n" + e); return(false); } }
public static bool LoadIso(string path) { VArtifactData ISO; long tick = System.DateTime.Now.Ticks; try { ISO = new VArtifactData(); string fullpath = path; string filename = Path.GetFileNameWithoutExtension(fullpath); //TextAsset ta = Resources.Load(fullpath,typeof(TextAsset)) as TextAsset; using (FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read)) { byte[] iso_buffer = new byte[(int)(fs.Length)]; //byte[] iso_buffer = ta.bytes; ulong guid = CRC64.Compute(iso_buffer); fs.Read(iso_buffer, 0, (int)(fs.Length)); fs.Close(); if (ISO.Import(iso_buffer, new VAOption(false))) { isos[guid] = ISO; isoNameId[filename] = guid; Debug.Log("loadIso Time: " + (System.DateTime.Now.Ticks - tick)); return(true); } else { ISO = null; return(false); } } } catch (Exception e) { Debug.LogError("Failed to load file " + path); GameLog.HandleIOException(e, GameLog.EIOFileType.InstallFiles); ISO = null; return(false); } }
public static string DownloadFileCallBack(byte[] fileData, PublishedFileId_t p_id, bool bOK) { string netCacheFilePath = VCConfig.s_CreationNetCachePath; string netCacheFileName = CRC64.Compute(fileData).ToString(); if (bOK) { if (SaveToFile(fileData, netCacheFileName, netCacheFilePath, VCConfig.s_CreationNetCacheFileExt)) { Debug.Log("ISO save to netCache filepath succeed!"); } else { Debug.Log("ISO exist or save failed!"); } return(netCacheFilePath + netCacheFileName + VCConfig.s_CreationNetCacheFileExt); } else { Debug.Log("ISO download failed!"); } return(""); }
// Send some default decals if user's decal count is 0 private static void SendDefaultDecals() { for (int i = 0; i < 6; ++i) { TextAsset ta = Resources.Load("Decals/Default" + i.ToString("00")) as TextAsset; if (ta == null) { continue; } VCDecalAsset vcdcl = new VCDecalAsset(); vcdcl.Import(ta.bytes); try { byte[] buffer = vcdcl.Export(); ulong guid = CRC64.Compute(buffer); string sguid = guid.ToString("X").PadLeft(16, '0'); FileStream fs = new FileStream(VCConfig.s_DecalPath + sguid + VCConfig.s_DecalFileExt, FileMode.Create, FileAccess.ReadWrite); fs.Write(buffer, 0, buffer.Length); fs.Close(); } catch (Exception e) { vcdcl.Destroy(); Debug.LogError("Save decal [" + vcdcl.GUIDString + "] failed ! \r\n" + e.ToString()); continue; } if (s_Decals.ContainsKey(vcdcl.m_Guid)) { s_Decals[vcdcl.m_Guid].Destroy(); s_Decals[vcdcl.m_Guid] = vcdcl; } else { s_Decals.Add(vcdcl.m_Guid, vcdcl); } } }
// Send some default materials if user's material count is 0 private static void SendDefaultMaterials() { foreach (KeyValuePair <int, VCMatterInfo> kvp in VCConfig.s_Matters) { VCMatterInfo matter = kvp.Value; VCMaterial vcmat = new VCMaterial(); vcmat.m_Name = "Default".ToLocalizationString() + " " + matter.Name; vcmat.m_MatterId = matter.ItemIndex; vcmat.m_UseDefault = true; try { byte[] buffer = vcmat.Export(); ulong guid = CRC64.Compute(buffer); string sguid = guid.ToString("X").PadLeft(16, '0'); FileStream fs = new FileStream(VCConfig.s_MaterialPath + sguid + VCConfig.s_MaterialFileExt, FileMode.Create, FileAccess.ReadWrite); fs.Write(buffer, 0, buffer.Length); fs.Close(); vcmat.Import(buffer); } catch (Exception e) { vcmat.Destroy(); Debug.LogError("Save material [" + vcmat.m_Name + "] failed ! \r\n" + e.ToString()); continue; } if (s_Materials.ContainsKey(vcmat.m_Guid)) { s_Materials[vcmat.m_Guid].Destroy(); s_Materials[vcmat.m_Guid] = vcmat; } else { s_Materials.Add(vcmat.m_Guid, vcmat); } } }
// Update is called once per frame void Update() { // Repeat once every 10 seconds if (totalTime * 1000 > msDelay) { string m00Hex; string m01Hex; string m02Hex; string m03Hex; string m10Hex; string m11Hex; string m12Hex; string m13Hex; string m20Hex; string m21Hex; string m22Hex; string m23Hex; Matrix4x4 matrix = Matrix4x4.TRS(OculusTransform.transform.localPosition, OculusTransform.transform.localRotation, OculusTransform.transform.localScale); float m00 = matrix.GetRow(0)[0]; byte[] m00Bytes = BitConverter.GetBytes(m00); float m01 = matrix.GetRow(0)[1]; byte[] m01Bytes = BitConverter.GetBytes(m01); float m02 = matrix.GetRow(0)[2]; byte[] m02Bytes = BitConverter.GetBytes(m02); float m03 = matrix.GetRow(0)[3]; byte[] m03Bytes = BitConverter.GetBytes(m03 * 10); float m10 = matrix.GetRow(1)[0]; byte[] m10Bytes = BitConverter.GetBytes(m10); float m11 = matrix.GetRow(1)[1]; byte[] m11Bytes = BitConverter.GetBytes(m11); float m12 = matrix.GetRow(1)[2]; byte[] m12Bytes = BitConverter.GetBytes(m12); float m13 = matrix.GetRow(1)[3]; byte[] m13Bytes = BitConverter.GetBytes(m13 * 10); float m20 = matrix.GetRow(2)[0]; byte[] m20Bytes = BitConverter.GetBytes(m20); float m21 = matrix.GetRow(2)[1]; byte[] m21Bytes = BitConverter.GetBytes(m21); float m22 = matrix.GetRow(2)[2]; byte[] m22Bytes = BitConverter.GetBytes(m22); float m23 = matrix.GetRow(2)[3]; byte[] m23Bytes = BitConverter.GetBytes(m23 * 10); if (BitConverter.IsLittleEndian) { Array.Reverse(m00Bytes); Array.Reverse(m01Bytes); Array.Reverse(m02Bytes); Array.Reverse(m03Bytes); Array.Reverse(m10Bytes); Array.Reverse(m11Bytes); Array.Reverse(m12Bytes); Array.Reverse(m13Bytes); Array.Reverse(m20Bytes); Array.Reverse(m21Bytes); Array.Reverse(m22Bytes); Array.Reverse(m23Bytes); } m00Hex = BitConverter.ToString(m00Bytes).Replace("-", ""); m01Hex = BitConverter.ToString(m01Bytes).Replace("-", ""); m02Hex = BitConverter.ToString(m02Bytes).Replace("-", ""); m03Hex = BitConverter.ToString(m03Bytes).Replace("-", ""); m10Hex = BitConverter.ToString(m10Bytes).Replace("-", ""); m11Hex = BitConverter.ToString(m11Bytes).Replace("-", ""); m12Hex = BitConverter.ToString(m12Bytes).Replace("-", ""); m13Hex = BitConverter.ToString(m13Bytes).Replace("-", ""); m20Hex = BitConverter.ToString(m20Bytes).Replace("-", ""); m21Hex = BitConverter.ToString(m21Bytes).Replace("-", ""); m22Hex = BitConverter.ToString(m22Bytes).Replace("-", ""); m23Hex = BitConverter.ToString(m23Bytes).Replace("-", ""); body = m00Hex + m10Hex + m20Hex + m01Hex + m11Hex + m21Hex + m02Hex + m12Hex + m22Hex + m03Hex + m13Hex + m23Hex; ulong crcULong = crcGenerator.Compute(StringToByteArray(body), 0, 0); CRC = crcULong.ToString("X16"); string hexmsg = hexHeader + CRC + body; // Encode the data string into a byte array. byte[] msg = StringToByteArray(hexmsg); // Send the data through the socket. int bytesSent = sender.Send(msg); // Reset timer totalTime = 0f; } totalTime = totalTime + Time.deltaTime; }
// ------------ Send Functions ------------ // --- Send Transform --- void SendTransformMessage(Transform objectTransform) { // Header // Header information: // Version 1 // Type Transform // Device Name // Time 0 // Body size 30 bytes // 0001 Type:5452414E53464F524D000000 Name:4F63756C757352696674506F736974696F6E0000 00000000000000000000000000000030 string hexHeader = "0001" + StringToHexString("TRANSFORM", 12) + StringToHexString(objectTransform.name, 20) + "00000000000000000000000000000030"; // Body string m00Hex; string m01Hex; string m02Hex; string m03Hex; string m10Hex; string m11Hex; string m12Hex; string m13Hex; string m20Hex; string m21Hex; string m22Hex; string m23Hex; Matrix4x4 matrix = Matrix4x4.TRS(objectTransform.localPosition, objectTransform.localRotation, objectTransform.localScale); float m00 = matrix.GetRow(0)[0]; byte[] m00Bytes = BitConverter.GetBytes(m00); float m01 = matrix.GetRow(0)[1]; byte[] m01Bytes = BitConverter.GetBytes(m01); float m02 = matrix.GetRow(0)[2]; byte[] m02Bytes = BitConverter.GetBytes(m02); float m03 = matrix.GetRow(0)[3]; byte[] m03Bytes = BitConverter.GetBytes(m03 * scaleMultiplier); float m10 = matrix.GetRow(1)[0]; byte[] m10Bytes = BitConverter.GetBytes(m10); float m11 = matrix.GetRow(1)[1]; byte[] m11Bytes = BitConverter.GetBytes(m11); float m12 = matrix.GetRow(1)[2]; byte[] m12Bytes = BitConverter.GetBytes(m12); float m13 = matrix.GetRow(1)[3]; byte[] m13Bytes = BitConverter.GetBytes(m13 * scaleMultiplier); float m20 = matrix.GetRow(2)[0]; byte[] m20Bytes = BitConverter.GetBytes(m20); float m21 = matrix.GetRow(2)[1]; byte[] m21Bytes = BitConverter.GetBytes(m21); float m22 = matrix.GetRow(2)[2]; byte[] m22Bytes = BitConverter.GetBytes(m22); float m23 = matrix.GetRow(2)[3]; byte[] m23Bytes = BitConverter.GetBytes(m23 * scaleMultiplier); if (BitConverter.IsLittleEndian) { Array.Reverse(m00Bytes); Array.Reverse(m01Bytes); Array.Reverse(m02Bytes); Array.Reverse(m03Bytes); Array.Reverse(m10Bytes); Array.Reverse(m11Bytes); Array.Reverse(m12Bytes); Array.Reverse(m13Bytes); Array.Reverse(m20Bytes); Array.Reverse(m21Bytes); Array.Reverse(m22Bytes); Array.Reverse(m23Bytes); } m00Hex = BitConverter.ToString(m00Bytes).Replace("-", ""); m01Hex = BitConverter.ToString(m01Bytes).Replace("-", ""); m02Hex = BitConverter.ToString(m02Bytes).Replace("-", ""); m03Hex = BitConverter.ToString(m03Bytes).Replace("-", ""); m10Hex = BitConverter.ToString(m10Bytes).Replace("-", ""); m11Hex = BitConverter.ToString(m11Bytes).Replace("-", ""); m12Hex = BitConverter.ToString(m12Bytes).Replace("-", ""); m13Hex = BitConverter.ToString(m13Bytes).Replace("-", ""); m20Hex = BitConverter.ToString(m20Bytes).Replace("-", ""); m21Hex = BitConverter.ToString(m21Bytes).Replace("-", ""); m22Hex = BitConverter.ToString(m22Bytes).Replace("-", ""); m23Hex = BitConverter.ToString(m23Bytes).Replace("-", ""); string body = m00Hex + m10Hex + m20Hex + m01Hex + m11Hex + m21Hex + m02Hex + m12Hex + m22Hex + m03Hex + m13Hex + m23Hex; ulong crcULong = crcGenerator.Compute(StringToByteArray(body), 0, 0); CRC = crcULong.ToString("X16"); string hexmsg = hexHeader + CRC + body; // Encode the data string into a byte array. byte[] msg = StringToByteArray(hexmsg); // Send the data through the socket. Send(socket, msg); }
void BtnUploadOnClick() { if (this.m_ImportIsoing) { return; } this.m_ImportIsoing = true; if (mSelectedIsoIndex == -1 || mSelectedIsoIndex >= mLocalIsoInfo.Count) { SetInfoMsg(UIMsgBoxInfo.mCZ_WorkShopUpNeedSeletedIso.GetString()); this.m_ImportIsoing = false; return; } int i = mSelectedIsoIndex % mLocalGridCtrl.mMaxGridCount; if (i < 0 || i >= mLocalGridCtrl.mMaxGridCount) { this.m_ImportIsoing = false; return; } VCEAssetMgr.IsoFileInfo fileInfo = mLocalIsoInfo[mSelectedIsoIndex]; VCIsoData iso = new VCIsoData(); try { string fullpath = fileInfo.m_Path; using (FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read)) { byte[] iso_buffer = new byte [(int)(fs.Length)]; fs.Read(iso_buffer, 0, (int)(fs.Length)); fs.Close(); iso.Import(iso_buffer, new VCIsoOption(true)); //VCGameMediator.SendIsoDataToServer(); if (iso.m_HeadInfo.Version < 0x02030001) { MessageBox_N.ShowOkBox(PELocalization.GetString(8000487)); this.m_ImportIsoing = false; return; } string isoPath = fullpath.Replace('\\', '/'); isoPath = isoPath.Replace(mDefoutIcoPath, "[ISO]/"); mUpLoadIndex++; //lz-2016.05.17 存储上传中Iso 的 hash ulong hash = CRC64.Compute(iso_buffer); if (null != this.m_UploadingIsoHashList && this.m_UploadingIsoHashList.Contains(hash)) { MessageBox_N.ShowOkBox(PELocalization.GetString(8000488)); this.m_ImportIsoing = false; return; } this.m_UploadingIsoHashList.Add(hash); mUpLoadMap[mUpLoadIndex] = isoPath; mUpLoadStateMap[mUpLoadMap[mUpLoadIndex]] = 0; mLocalGridCtrl.mUIItems[i].ActiveUpDown(true); mLocalGridCtrl.mUIItems[i].UpdteUpDownInfo(PELocalization.GetString(8000908)); //"Uploading" SteamWorkShop.SendFile(UpLoadFileCallBack, iso.m_HeadInfo.Name, iso.m_HeadInfo.SteamDesc, iso.m_HeadInfo.SteamPreview, iso_buffer, SteamWorkShop.AddNewVersionTag(iso.m_HeadInfo.ScenePaths()), false, mUpLoadIndex); } } catch (Exception e) { mLocalGridCtrl.mUIItems[i].ActiveUpDown(false); mLocalGridCtrl.mUIItems[i].UpdteUpDownInfo(""); Debug.Log(" WorkShop Loading ISO Error : " + e.ToString()); MessageBox_N.ShowOkBox(PELocalization.GetString(8000489)); } this.m_ImportIsoing = false; }
internal static void SendFile(SteamUploadEventHandler callBackSteamUploadResult, string name, string desc, byte[] preData, byte[] data, string[] tags, bool sendToServer = true, int id = -1, ulong fileId = 0, bool free = false) { ulong hash = CRC64.Compute(data); bool ret = false; try { if (string.IsNullOrEmpty(name)) { VCEMsgBox.Show(VCEMsgBoxType.EXPORT_EMPTY_NAME); LogManager.Error("File name cannot be null."); return; } if (!SteamUser.BLoggedOn()) { LogManager.Error("log back in steam..."); return; } bool bPublish = !sendToServer; if (SteamRemoteStorage.FileExists(hash.ToString() + "_preview")) { //file exist,don't publish it; } if (!SteamRemoteStorage.IsCloudEnabledForAccount()) { throw new Exception("Account cloud disabled."); } if (!SteamRemoteStorage.IsCloudEnabledForApp()) { throw new Exception("App cloud disabled."); } if (!bPublish) { SteamFileItem item = new SteamFileItem(callBackSteamUploadResult, name, desc, preData, data, hash, tags, bPublish, sendToServer, id, fileId, free); item.StartSend(); } else { SendIsoCache iso = new SendIsoCache(); iso.id = id; iso.hash = hash; iso.name = name; iso.preData = preData; iso.sendToServer = sendToServer; iso.tags = tags; iso.data = data; iso.desc = desc; iso.callBackSteamUploadResult = callBackSteamUploadResult; iso.bPublish = bPublish; if (AddToIsoCache(iso)) { LobbyInterface.LobbyRPC(ELobbyMsgType.UploadISO, hash, SteamMgr.steamId.m_SteamID); } else { return; } } VCEMsgBox.Show(VCEMsgBoxType.EXPORT_NETWORK); ret = true; } catch (Exception e) { VCEMsgBox.Show(VCEMsgBoxType.EXPORT_NETWORK_FAILED); Debug.LogWarning("workshop error :" + e.Message); ToolTipsMgr.ShowText(e.Message); } finally { if (!ret && callBackSteamUploadResult != null) { callBackSteamUploadResult(id, false, hash); } } }
// I/O // From byte buffer public void Import(byte[] buffer) { // Generate a ulong GUID m_Guid = CRC64.Compute(buffer); // Read the buffer using (MemoryStream ms = new MemoryStream(buffer)) { BinaryReader r = new BinaryReader(ms); // Read version int version = r.ReadInt32(); // Version control switch (version) { case 0x1000: { // Read name & game mat item index m_Name = r.ReadString(); m_MatterId = r.ReadInt32(); // Find mat item config VCMatterInfo mc = null; if (VCConfig.s_Matters != null && VCConfig.s_Matters.ContainsKey(m_MatterId)) { mc = VCConfig.s_Matters[m_MatterId]; } else { Debug.LogError("VCConfig.s_Matters was corrupt."); break; } // Fetch item id m_ItemId = mc.ItemId; m_UseDefault = r.ReadBoolean(); // Use default set if (m_UseDefault) { // Load properties m_BumpStrength = mc.DefaultBumpStrength; m_SpecularColor = mc.DefaultSpecularColor; m_SpecularStrength = mc.DefaultSpecularStrength; m_SpecularPower = mc.DefaultSpecularPower; m_EmissiveColor = mc.DefaultEmissiveColor; m_Tile = mc.DefaultTile; // Load texure from resource UnityEngine.Object temp = null; temp = Resources.Load(mc.DefaultDiffuseRes); if (temp != null) { m_DiffuseTex = Texture2D.Instantiate(temp) as Texture2D; } if (m_DiffuseTex == null) { m_DiffuseTex = new Texture2D(4, 4, TextureFormat.ARGB32, false); } m_DiffuseData = m_DiffuseTex.EncodeToPNG(); temp = Resources.Load(mc.DefaultBumpRes); if (temp != null) { m_BumpTex = Texture2D.Instantiate(temp) as Texture2D; } if (m_BumpTex == null) { m_BumpTex = new Texture2D(4, 4, TextureFormat.ARGB32, false); } m_BumpData = m_BumpTex.EncodeToPNG(); } // User customize else { // Load properties m_BumpStrength = r.ReadSingle(); m_SpecularColor.r = r.ReadByte(); m_SpecularColor.g = r.ReadByte(); m_SpecularColor.b = r.ReadByte(); m_SpecularColor.a = r.ReadByte(); m_SpecularStrength = r.ReadSingle(); m_SpecularPower = r.ReadSingle(); m_EmissiveColor.r = r.ReadByte(); m_EmissiveColor.g = r.ReadByte(); m_EmissiveColor.b = r.ReadByte(); m_EmissiveColor.a = r.ReadByte(); // Load texture data and create texture from the data, // then resize to TEX_RESOLUTION and update the byte data m_Tile = r.ReadSingle(); int l = 0; l = r.ReadInt32(); m_DiffuseData = r.ReadBytes(l); m_DiffuseTex = new Texture2D(2, 2, TextureFormat.ARGB32, false); m_DiffuseTex.LoadImage(m_DiffuseData); m_DiffuseData = m_DiffuseTex.EncodeToPNG(); l = r.ReadInt32(); m_BumpData = r.ReadBytes(l); m_BumpTex = new Texture2D(2, 2, TextureFormat.ARGB32, false); m_BumpTex.LoadImage(m_BumpData); m_BumpData = m_BumpTex.EncodeToPNG(); } break; } default: break; } r.Close(); ms.Close(); } }
public static int MakeCreation(string path) { TextAsset aseet = Resources.Load <TextAsset>(path); VCIsoData iso = new VCIsoData(); iso.Import(aseet.bytes, new VCIsoOption(false)); // Multi player if (s_MultiplayerMode) { if (!VCConfig.s_Categories.ContainsKey(iso.m_HeadInfo.Category)) { return(-1); } byte[] isodata = iso.Export(); if (isodata == null || isodata.Length <= 0) { return(-1); } ulong hash = CRC64.Compute(isodata); ulong fileId = SteamWorkShop.GetFileHandle(hash); VCGameMediator.SendIsoDataToServer(iso.m_HeadInfo.Name, iso.m_HeadInfo.SteamDesc, iso.m_HeadInfo.SteamPreview, isodata, SteamWorkShop.AddNewVersionTag(iso.m_HeadInfo.ScenePaths()), true, fileId, true); return(0); } else { CreationData new_creation = new CreationData(); new_creation.m_ObjectID = CreationMgr.QueryNewId(); new_creation.m_RandomSeed = UnityEngine.Random.value; new_creation.m_Resource = iso.Export(); new_creation.ReadRes(); // Attr new_creation.GenCreationAttr(); if (new_creation.m_Attribute.m_Type == ECreation.Null) { Debug.LogWarning("Creation is not a valid type !"); new_creation.Destroy(); return(-1); } // SaveRes if (new_creation.SaveRes()) { new_creation.BuildPrefab(); new_creation.Register(); CreationMgr.AddCreation(new_creation); ItemAsset.ItemObject item; int send_retval = new_creation.SendToPlayer(out item); Debug.Log("Make creation succeed !"); if (send_retval == 0) { return(-1); // Error } else if (send_retval == -1) { return(-4); // Item Package Full } else { if (OnMakeCreation != null) { OnMakeCreation(); } return(0); // Succeed } } else { Debug.LogWarning("Save creation resource file failed !"); new_creation.Destroy(); return(-3); } } }
// Calculate a ulong GUID for this mat public void CalcGUID() { m_Guid = CRC64.Compute(Export()); }
// Hash code calculate public void CalcHash() { m_HashCode = CRC64.Compute(m_Resource); }
protected virtual ulong CalculateHash(string value) => string.IsNullOrEmpty(value) ? 0 : _crc.Compute("#bFfStRiNg::" + value);
public static void CopyCretion(ECreation type) { Pathea.PlayerPackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PlayerPackageCmpt>(); if (null == pkg) { return; } List <int> creationInstanceid = pkg.package.GetCreationInstanceId(type); if (creationInstanceid == null || creationInstanceid.Count == 0) { return; } CreationData cd = CreationMgr.GetCreation(creationInstanceid[0]); if (Pathea.PeGameMgr.IsMulti) { ulong hash = CRC64.Compute(cd.m_Resource); ulong fileId = SteamWorkShop.GetFileHandle(hash); VCGameMediator.SendIsoDataToServer(cd.m_IsoData.m_HeadInfo.Name, cd.m_IsoData.m_HeadInfo.SteamDesc, cd.m_IsoData.m_HeadInfo.SteamPreview, cd.m_Resource, SteamWorkShop.AddNewVersionTag(cd.m_IsoData.m_HeadInfo.ScenePaths()), true, fileId, true); } else { CreationData new_creation = new CreationData(); new_creation.m_ObjectID = CreationMgr.QueryNewId(); new_creation.m_RandomSeed = UnityEngine.Random.value; new_creation.m_Resource = cd.m_Resource; new_creation.ReadRes(); // Attr new_creation.GenCreationAttr(); if (new_creation.m_Attribute.m_Type == ECreation.Null) { Debug.LogWarning("Creation is not a valid type !"); new_creation.Destroy(); return; } // SaveRes if (new_creation.SaveRes()) { new_creation.BuildPrefab(); new_creation.Register(); CreationMgr.AddCreation(new_creation); ItemAsset.ItemObject item; int send_retval = new_creation.SendToPlayer(out item); Debug.Log("Make creation succeed !"); if (send_retval == 0) { return; // Error } else if (send_retval == -1) { return; // Item Package Full } else { return; // Succeed } } else { Debug.LogWarning("Save creation resource file failed !"); new_creation.Destroy(); return; } } }
public static void ExportRandIso(string fullpath, int dungeonId, int index) { if (fullpath == "") { return; } if (!File.Exists(fullpath)) { return; } ulong fileId = DungeonIsos.GetFileId(dungeonId, index); VCIsoData iso = new VCIsoData(); using (FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read)) { byte[] iso_buffer = new byte[(int)(fs.Length)]; fs.Read(iso_buffer, 0, (int)(fs.Length)); fs.Close(); iso.Import(iso_buffer, new VCIsoOption(true)); if (Pathea.PeGameMgr.IsMulti) { ulong hash = CRC64.Compute(iso_buffer); VCGameMediator.SendIsoDataToServer(iso.m_HeadInfo.Name, iso.m_HeadInfo.SteamDesc, iso.m_HeadInfo.SteamPreview, iso_buffer, SteamWorkShop.AddNewVersionTag(iso.m_HeadInfo.ScenePaths()), true, fileId, true); NetworkManager.SyncServer(EPacketType.PT_Common_SendRandIsoHash, dungeonId, index, hash); } else { CreationData new_creation = new CreationData(); new_creation.m_ObjectID = CreationMgr.QueryNewId(); new_creation.m_RandomSeed = UnityEngine.Random.value; new_creation.m_Resource = iso_buffer; new_creation.ReadRes(); ulong hash = CRC64.Compute(iso_buffer); // Attr new_creation.GenCreationAttr(); if (new_creation.m_Attribute.m_Type == ECreation.Null) { Debug.LogWarning("Creation is not a valid type !"); new_creation.Destroy(); return; } // SaveRes if (new_creation.SaveRes()) { new_creation.BuildPrefab(); new_creation.Register(); CreationMgr.AddCreation(new_creation); ItemObject item; new_creation.SendToPlayer(out item, false); Debug.Log("Make creation succeed !"); RandomDungenMgr.Instance.ReceiveIsoObj(dungeonId, hash, item.instanceId); } else { Debug.LogWarning("Save creation resource file failed !"); new_creation.Destroy(); return; } } } }