private void _GenerateSPSPrims(BinaryReader reader, Int32 spsOffset) { this.spsPrims.Clear(); FieldSPS.FieldSPSPrim item = default(FieldSPS.FieldSPSPrim); reader.BaseStream.Seek((Int64)spsOffset, SeekOrigin.Begin); for (Int32 i = 0; i < this.works.primCount; i++) { item.code = this.works.code; item.tpage = this.works.tpage; item.clut = this.works.clut; Int32 num = (Int32)reader.ReadSByte(); Int32 num2 = (Int32)reader.ReadSByte(); num <<= 2; Int32 num3 = num - this.works.h; Int32 num4 = num + this.works.h; num2 <<= 2; Int32 num5 = num2 - this.works.w; num2 += this.works.w; num3 &= 65535; num4 &= 65535; num5 <<= 16; num2 <<= 16; Int32toSByteConverter int32toSByteConverter = num3 | num5; item.v0 = new Vector3((Single)((Int32)int32toSByteConverter.SByte2 << 8 | (Int32)((Byte)int32toSByteConverter.SByte1)), (Single)((Int32)int32toSByteConverter.SByte4 << 8 | (Int32)((Byte)int32toSByteConverter.SByte3)), 0f); int32toSByteConverter = (num4 | num5); item.v1 = new Vector3((Single)((Int32)int32toSByteConverter.SByte2 << 8 | (Int32)((Byte)int32toSByteConverter.SByte1)), (Single)((Int32)int32toSByteConverter.SByte4 << 8 | (Int32)((Byte)int32toSByteConverter.SByte3)), 0f); int32toSByteConverter = (num3 | num2); item.v2 = new Vector3((Single)((Int32)int32toSByteConverter.SByte2 << 8 | (Int32)((Byte)int32toSByteConverter.SByte1)), (Single)((Int32)int32toSByteConverter.SByte4 << 8 | (Int32)((Byte)int32toSByteConverter.SByte3)), 0f); int32toSByteConverter = (num4 | num2); item.v3 = new Vector3((Single)((Int32)int32toSByteConverter.SByte2 << 8 | (Int32)((Byte)int32toSByteConverter.SByte1)), (Single)((Int32)int32toSByteConverter.SByte4 << 8 | (Int32)((Byte)int32toSByteConverter.SByte3)), 0f); num3 = (Int32)reader.ReadByte(); Int64 position = reader.BaseStream.Position; num5 = (num3 & 15); num5 <<= 1; num5 += this.works.pt; reader.BaseStream.Seek((Int64)num5, SeekOrigin.Begin); num4 = (Int32)reader.ReadUInt16(); Int32 num6 = (Int32)((UInt32)this.works.h >> 1); num5 = (num4 & 255); num4 = (Int32)((UInt32)num4 >> 8); num2 = num5 + num6; num6 = (Int32)((UInt32)this.works.w >> 1); num = num4 + num6; num4 <<= 8; num <<= 8; num6 = (num5 | num4); item.uv0 = new Vector2((Single)(num6 & 255), (Single)(num6 >> 8 & 255)); num6 = (num2 | num4); item.uv1 = new Vector2((Single)(num6 & 255), (Single)(num6 >> 8 & 255)); num6 = (num5 | num); item.uv2 = new Vector2((Single)(num6 & 255), (Single)(num6 >> 8 & 255)); num6 = (num2 | num); item.uv3 = new Vector2((Single)(num6 & 255), (Single)(num6 >> 8 & 255)); num = (Int32)((UInt32)num3 >> 4); num <<= 2; num += this.works.rgb; reader.BaseStream.Seek((Int64)num, SeekOrigin.Begin); num3 = (Int32)reader.ReadUInt16(); num5 = (Int32)reader.ReadSByte(); num5 <<= 16; num3 |= num5; if (this.works.fade >= 0) { UInt32 num7 = (UInt32)this.works.fade; num5 = (num3 & 255); UInt32 num8 = (UInt32)num5; num4 = (Int32)((UInt32)num3 >> 8); num4 &= 255; UInt32 num9 = (UInt32)num4; num5 = (Int32)((UInt32)num3 >> 16); num5 &= 255; UInt32 num10 = (UInt32)num5; num8 = num8 * num7 >> 12; num9 = num9 * num7 >> 12; num10 = num10 * num7 >> 12; num8 = (UInt32)Mathf.Clamp(num8, -32768f, 32767f); num9 = (UInt32)Mathf.Clamp(num9, -32768f, 32767f); num10 = (UInt32)Mathf.Clamp(num10, -32768f, 32767f); if ((FF9StateSystem.Common.FF9.fldMapNo == 2901 && (this.refNo == 644 || this.refNo == 736)) || (FF9StateSystem.Common.FF9.fldMapNo == 2913 && (this.refNo == 646 || this.refNo == 737)) || (FF9StateSystem.Common.FF9.fldMapNo == 2925 && (this.refNo == 990 || this.refNo == 988))) { item.color = new Color(num8 / 255f, num9 / 255f, num10 / 255f, 1f); } else { item.color = new Color(num8 / 127f, num9 / 127f, num10 / 127f, 1f); } } else { num5 = (num3 & 255); UInt32 num8 = (UInt32)num5; num4 = (Int32)((UInt32)num3 >> 8); num4 &= 255; UInt32 num9 = (UInt32)num4; num5 = (Int32)((UInt32)num3 >> 16); num5 &= 255; UInt32 num10 = (UInt32)num5; item.color = new Color(num8 / 127f, num9 / 127f, num10 / 127f, 1f); } item.otz = 0; this.spsPrims.Add(item); reader.BaseStream.Seek(position, SeekOrigin.Begin); } }
private void _GenerateSPSMesh() { if (this.spsPrims.Count == 0) { return; } Boolean flag = false; BGCAM_DEF currentBgCamera = this.fieldMap.GetCurrentBgCamera(); if (currentBgCamera == null) { return; } Single num = (Single)this.scale / 4096f; Matrix4x4 localRTS = Matrix4x4.identity; Boolean flag2 = false; if (FF9StateSystem.Common.FF9.fldMapNo == 2929) { flag = true; } if (flag) { if (FF9StateSystem.Common.FF9.fldMapNo == 2929) { localRTS = Matrix4x4.TRS(this.pos * 0.9925f, Quaternion.Euler(-this.rot.x / 2f, -this.rot.y / 2f, this.rot.z / 2f), new Vector3(num, -num, 1f)); } else { localRTS = Matrix4x4.TRS(this.pos, Quaternion.Euler(this.rot.x, this.rot.y, this.rot.z), new Vector3(num, -num, 1f)); } } else { Vector3 vector = PSX.CalculateGTE_RTPT_POS(this.pos, Matrix4x4.identity, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset(), true); num *= currentBgCamera.GetViewDistance() / vector.z; if (vector.z < 0f) { flag2 = true; } vector.z /= 4f; vector.z += (Single)currentBgCamera.depthOffset; base.transform.localPosition = new Vector3(vector.x, vector.y, vector.z + (Single)this.zOffset); base.transform.localScale = new Vector3(num, -num, 1f); base.transform.localRotation = Quaternion.Euler(this.rot.x, this.rot.y, -this.rot.z); } this._vertices.Clear(); this._colors.Clear(); this._uv.Clear(); this._indices.Clear(); for (Int32 i = 0; i < this.spsPrims.Count; i++) { if (flag2) { break; } FieldSPS.FieldSPSPrim fieldSPSPrim = this.spsPrims[i]; Int32 count = this._vertices.Count; if (flag) { Vector3 a = PSX.CalculateGTE_RTPT(fieldSPSPrim.v0, localRTS, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset()); Vector3 a2 = PSX.CalculateGTE_RTPT(fieldSPSPrim.v1, localRTS, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset()); Vector3 a3 = PSX.CalculateGTE_RTPT(fieldSPSPrim.v2, localRTS, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset()); Vector3 a4 = PSX.CalculateGTE_RTPT(fieldSPSPrim.v3, localRTS, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset()); Single num2 = PSX.CalculateGTE_RTPTZ(Vector3.zero, localRTS, currentBgCamera.GetMatrixRT(), currentBgCamera.GetViewDistance(), this.fieldMap.GetProjectionOffset()); num2 /= 4f; num2 += (Single)currentBgCamera.depthOffset; Vector3 b = new Vector3(0f, 0f, num2 - (Single)i / 100f); this._vertices.Add(a + b); this._vertices.Add(a2 + b); this._vertices.Add(a3 + b); this._vertices.Add(a4 + b); } else { Vector3 b2 = new Vector3(0f, 0f, (Single)(this.spsPrims.Count - i) / 100f); this._vertices.Add(fieldSPSPrim.v0 + b2); this._vertices.Add(fieldSPSPrim.v1 + b2); this._vertices.Add(fieldSPSPrim.v2 + b2); this._vertices.Add(fieldSPSPrim.v3 + b2); } this._colors.Add(fieldSPSPrim.color); this._colors.Add(fieldSPSPrim.color); this._colors.Add(fieldSPSPrim.color); this._colors.Add(fieldSPSPrim.color); this._uv.Add((fieldSPSPrim.uv0 + new Vector2(0.5f, 0.5f)) * 0.00390625f); this._uv.Add((fieldSPSPrim.uv1 + new Vector2(-0.5f, 0.5f)) * 0.00390625f); this._uv.Add((fieldSPSPrim.uv2 + new Vector2(0.5f, -0.5f)) * 0.00390625f); this._uv.Add((fieldSPSPrim.uv3 + new Vector2(-0.5f, -0.5f)) * 0.00390625f); this._indices.Add(count); this._indices.Add(count + 1); this._indices.Add(count + 2); this._indices.Add(count + 1); this._indices.Add(count + 3); this._indices.Add(count + 2); } Mesh mesh = this.meshFilter.mesh; mesh.Clear(); mesh.vertices = this._vertices.ToArray(); mesh.colors = this._colors.ToArray(); mesh.uv = this._uv.ToArray(); mesh.triangles = this._indices.ToArray(); this.meshFilter.mesh = mesh; FieldSPS.FieldSPSPrim fieldSPSPrim2 = this.spsPrims[0]; PSXTexture texture = PSXTextureMgr.GetTexture(fieldSPSPrim2.FlagTP, fieldSPSPrim2.FlagTY, fieldSPSPrim2.FlagTX, fieldSPSPrim2.FlagClutY, fieldSPSPrim2.FlagClutX); texture.SetFilter(FilterMode.Bilinear); Int32 num3 = (Int32)((this.arate >= 4) ? 4 : this.arate); this.materials[num3].mainTexture = texture.texture; this.meshRenderer.material = this.materials[num3]; if (this.spsActor != (UnityEngine.Object)null) { this.spsActor.spsPos = this.pos; } }