static public void edit(Ucfb_editor model, uint factor) { var info = model.find_child("INFO"); // SWBF and SWBFII have different sized INFO chunks // however the (what I assume is) poly count is always // the last field in these chunks. info.seek(-4, SeekOrigin.End, false); var current_count = info.read_uint32(); info.seek(-4, SeekOrigin.Current, false); info.write_uint32(current_count / factor); }
static public void edit(Ucfb_editor game_model, uint factor) { game_model.read_child(); // NAME chunk game_model.read_child(); // INFO chunk while (!game_model.at_end) { var child = game_model.read_child(); child.seek(-4, SeekOrigin.End, false); var current_count = child.read_uint32(); child.seek(-4, SeekOrigin.Current, false); child.write_uint32(current_count / factor); } }
static void process_file(string file_path, uint factor) { var mapped_file = MemoryMappedFile.CreateFromFile(file_path, FileMode.Open); var editor = new Ucfb_editor(mapped_file); var model = editor.find_child("modl"); if (model != null) { Modl_editor.edit(model, factor); } var game_model = editor.find_child("gmod"); if (game_model != null) { Gmod_editor.edit(game_model, factor); } Console.WriteLine("Edited {0}", file_path); }