private static void WriteConditions(Utf8JsonWriter writer, obj_f namesField, obj_f argsField, Dictionary <obj_f, object> properties) { var modNames = (IReadOnlyList <int>)properties[namesField]; var modData = (IReadOnlyList <int>)properties.GetValueOrDefault(argsField, new int[0]); writer.WriteStartArray(); var argIdx = 0; foreach (var modNameHash in modNames) { var condition = GameSystems.D20.Conditions.GetByHash(modNameHash); if (condition.numArgs == 0) { writer.WriteStringValue(condition.condName); continue; } writer.WriteStartArray(); writer.WriteStringValue(condition.condName); for (var i = 0; i < condition.numArgs; i++) { writer.WriteNumberValue(modData[argIdx++]); } writer.WriteEndArray(); } writer.WriteEndArray(); }
public static int getObjVar(GameObject obj, obj_f var, int idx, int mask, int bits) { var bitMask = mask << (idx * bits); var val = obj.GetInt32(var) & bitMask; val = val >> (idx * bits); return(val & mask); }
public static void setObjVar(GameObject obj, obj_f var, int idx, int val, int mask, int bits) { // print "obj=", object, " var=", var, " idx=", idx, " val=", val var bitMask = mask << (idx * bits); val = val << (idx * bits); var oldVal = obj.GetInt32(var) & ~bitMask; obj.SetInt32(var, oldVal | val); }
public static void SetInt(this GameObject obj, obj_f field, int value) { if (field == obj_f.critter_subdual_damage) { GameSystems.MapObject.ChangeSubdualDamage(obj, value); } else { obj.SetInt32(field, value); } }
public static void WriteField(this Utf8JsonWriter writer, obj_f field, object value) { // Drop broken-ass radius and render-height if (field == obj_f.radius && ((float)value <= 0 || (float)value > 9999)) { Console.WriteLine($"Dropping invalid radius: {value}"); return; } if (field == obj_f.render_height_3d && ((float)value <= 0 || (float)value > 9999)) { Console.WriteLine($"Dropping invalid render-height: {value}"); return; } ref readonly var fieldDef = ref ObjectFields.GetFieldDef(field);
public static void setObjVarDWord(GameObject obj, obj_f var, int val) { obj.SetInt32(var, val); }
public static void setObjVarNibble(GameObject obj, obj_f var, int idx, int val) { setObjVar(obj, var, idx, val, 15, 4); }
private static void WriteField(Utf8JsonWriter writer, Dictionary <obj_f, object> properties, obj_f field) { // Special handling that spans different fields switch (field) { case obj_f.permanent_mods: writer.WritePropertyName("permanent_mod_args"); WriteConditions(writer, obj_f.permanent_mods, obj_f.permanent_mod_data, properties); break; case obj_f.permanent_mod_data: // Handled by permanent_mods break; case obj_f.item_pad_wielder_condition_array: writer.WritePropertyName("item_wielder_conditions"); WriteConditions(writer, obj_f.item_pad_wielder_condition_array, obj_f.item_pad_wielder_argument_array, properties); break; case obj_f.item_pad_wielder_argument_array: // Handled by item_pad_wielder_condition_array break; case obj_f.npc_standpoints: WriteNpcStandpoints(writer, properties); break; case obj_f.armor_flags: WriteArmorFlags(writer, (ArmorFlag)(int)properties[field]); break; default: writer.WriteField(field, properties[field]); break; } }
public static void setObjVarByte(GameObject obj, obj_f var, int idx, int val) { setObjVar(obj, var, idx, val, 255, 8); }
public static int getObjVarNibble(GameObject obj, obj_f var, int idx) { return(getObjVar(obj, var, idx, 15, 4)); }
public static void setObjVarWord(GameObject obj, obj_f var, int idx, int val) { setObjVar(obj, var, idx, val, 65535, 16); }
public static int getObjVarByte(GameObject obj, obj_f var, int idx) { return(getObjVar(obj, var, idx, 255, 8)); }
public static int getObjVarWord(GameObject obj, obj_f var, int idx) { return(getObjVar(obj, var, idx, 65535, 16)); }
public static int GetInt(this GameObject obj, obj_f field) { return(obj.GetInt32(field)); }
// Util functions for getting & setting words, bytes and nibbles in object integers. // object = reference to the object containing the integer variable. // var = the variable to be used. e.g. obj_f_weapon_pad_i_2 // idx = the index of the word (0-1), byte (0-3) or nibble (0-7) to use. // val = the value to be set. public static int getObjVarDWord(GameObject obj, obj_f var) { return(obj.GetInt32(var)); }
public object?GetFieldValue(obj_f field) { switch (field) { case obj_f.render_color: return(renderColor); case obj_f.render_colors: return(renderColors); case obj_f.render_palette: return(renderPalette); case obj_f.render_scale: return(renderScale); case obj_f.render_alpha: return(renderAlpha); case obj_f.render_x: return(renderX); case obj_f.render_y: return(renderY); case obj_f.render_width: return(renderWidth); case obj_f.render_height: return(renderHeight); case obj_f.palette: return(palette); case obj_f.color: return(color); case obj_f.colors: return(colors); case obj_f.render_flags: return(renderFlags); case obj_f.temp_id: return(tempId); case obj_f.light_handle: return(lightHandle); case obj_f.overlay_light_handles: return(overlayLightHandles); case obj_f.find_node: return(findNode); case obj_f.animation_handle: return(animationHandle); case obj_f.grapple_state: return(grappleState); default: throw new ArgumentOutOfRangeException(nameof(field), field, null); } }
public void SetFieldValue(obj_f field, object newValue) { switch (field) { case obj_f.render_color: renderColor = (int)newValue; break; case obj_f.render_colors: renderColors = (int)newValue; break; case obj_f.render_palette: renderPalette = (int)newValue; break; case obj_f.render_scale: renderScale = (int)newValue; break; case obj_f.render_alpha: if (!ReferenceEquals(renderAlpha, newValue)) { renderAlpha?.Dispose(); } renderAlpha = (SparseArray <int>)newValue; break; case obj_f.render_x: renderX = (int)newValue; break; case obj_f.render_y: renderY = (int)newValue; break; case obj_f.render_width: renderWidth = (int)newValue; break; case obj_f.render_height: renderHeight = (int)newValue; break; case obj_f.palette: palette = (int)newValue; break; case obj_f.color: color = (int)newValue; break; case obj_f.colors: colors = (int)newValue; break; case obj_f.render_flags: renderFlags = (int)newValue; break; case obj_f.temp_id: tempId = (int)newValue; break; case obj_f.light_handle: lightHandle = (int)newValue; break; case obj_f.overlay_light_handles: if (!ReferenceEquals(overlayLightHandles, newValue)) { overlayLightHandles?.Dispose(); } overlayLightHandles = (SparseArray <int>)newValue; break; case obj_f.find_node: findNode = (int)newValue; break; case obj_f.animation_handle: animationHandle = (int)newValue; break; case obj_f.grapple_state: grappleState = (int)newValue; break; default: throw new ArgumentOutOfRangeException(nameof(field), field, null); } }