private static int PerformMath(BurikoMathType type, BurikoVariable a, BurikoVariable b) { int num = a.IntValue(); int num2 = b.IntValue(); switch (type) { case BurikoMathType.Equals: return((num == num2) ? 1 : 0); case BurikoMathType.Add: return(num + num2); case BurikoMathType.Divide: return(num / num2); case BurikoMathType.Multiply: return(num * num2); case BurikoMathType.Subtract: return(num - num2); case BurikoMathType.GreaterThan: return((num > num2) ? 1 : 0); case BurikoMathType.GreaterThanOrEquals: return((num >= num2) ? 1 : 0); case BurikoMathType.LessThan: return((num < num2) ? 1 : 0); case BurikoMathType.LessThanOrEquals: return((num <= num2) ? 1 : 0); case BurikoMathType.Modulus: return(num % num2); case BurikoMathType.NotEquals: return((num != num2) ? 1 : 0); case BurikoMathType.And: return((num != 0 && num2 != 0) ? 1 : 0); case BurikoMathType.Or: return((num != 0 || num2 != 0) ? 1 : 0); default: throw new Exception("Cannot find a handler for math type " + type); } }
public BurikoVariable(BinaryReader stream) { Type = (BurikoValueType)stream.ReadInt16(); switch (Type) { case BurikoValueType.Null: valueInt = -1; break; case BurikoValueType.Bool: valueInt = stream.ReadByte(); break; case BurikoValueType.Int: valueInt = stream.ReadInt32(); break; case BurikoValueType.String: valueString = stream.ReadString(); break; case BurikoValueType.Variable: stream.BaseStream.Seek(-2L, SeekOrigin.Current); valueReference = ReadReference(stream); break; case BurikoValueType.Math: { BurikoMathType type = (BurikoMathType)stream.ReadInt16(); BurikoVariable a = new BurikoVariable(stream); BurikoVariable b = new BurikoVariable(stream); Type = BurikoValueType.Int; valueInt = PerformMath(type, a, b); break; } case BurikoValueType.Operation: valueVariable = BurikoScriptSystem.Instance.GetCurrentScript().ExecuteOperation((BurikoOperations)stream.ReadInt16()); break; default: throw new NotImplementedException("BurikoVariable: Unhandled BurikoValueType " + Type); } }
public static BurikoReference ReadReference(BinaryReader dataReader) { short num = dataReader.ReadInt16(); if (num != 5) { throw new Exception("Cannot perform assignment to an object that is not a declared variable."); } string property = dataReader.ReadString(); int member = new BurikoVariable(dataReader).IntValue(); bool flag = dataReader.ReadBoolean(); BurikoReference burikoReference = new BurikoReference(property, member); if (flag) { burikoReference.Reference = ReadReference(dataReader); } return(burikoReference); }
public BurikoVariable(BurikoReference reference, BurikoVariable variable) { Type = BurikoValueType.Variable; valueReference = reference; valueVariable = variable; }