Advertisement
dsiver144

DSI Patch System v1.3

Jun 23rd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.80 KB | None | 0 0
  1. #==============================================================================
  2. # DSI Patch System
  3. # -- Last Updated: 2017.06.23
  4. # -- Author: dsiver144
  5. # -- Level: Hard
  6. # -- Requires: n/a
  7. #==============================================================================
  8. $imported = {} if $imported.nil?
  9. $imported["DSI-PatchSystem"] = true
  10. #==============================================================================
  11. # + Updates
  12. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  13. # 2017.06.03 - Finish first version of the script!
  14. # 2017.06.04 - Add Classes tab. Add an option to add new event to existing maps.
  15. # (This doesn't replace old event with same id)
  16. # 2017.06.23 - Fix some important bugs.
  17. # - Cursor remember for "add events to map" tab.
  18. #==============================================================================
  19. # + Instructions
  20. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  21. # To install this script, open up your script editor and copy/paste this script
  22. # to an open slot below �� Materials/�f�� but above �� Main. Remember to save.
  23. #==============================================================================
  24. module DSIVER144
  25. module PATCH_SYSTEM
  26. PATCH_DIR = "DLC"
  27. PATCH_NAME = "UA_*.dlc"
  28. #For ex: Patch file will be created at Patches folder
  29. #which named DLC_1.patch, DLC_2.patch, DLC_3.patch,...
  30. UNIQUE_KEY = "Z01"
  31. LOAD_PATCH_WHEN_TEST = true # set to true to see magic!
  32. #------------------------------------------------------------------------
  33. # * new method: get_patch_files
  34. #------------------------------------------------------------------------
  35. def self.get_patch_files
  36. files = Dir.glob(PATCH_DIR+'/'+PATCH_NAME)
  37. files
  38. end
  39. #------------------------------------------------------------------------
  40. # * new method: get_data
  41. #------------------------------------------------------------------------
  42. def self.get_data(type)
  43. case type
  44. when :item
  45. return $data_items
  46. when :weapon
  47. return $data_weapons
  48. when :armor
  49. return $data_armors
  50. when :actor
  51. return $data_actors
  52. when :class
  53. return $data_classes
  54. when :skill
  55. return $data_skills
  56. when :enemy
  57. return $data_enemies
  58. when :troop
  59. return $data_troops
  60. when :state
  61. return $data_states
  62. when :animation
  63. return $data_animations
  64. when :tileset
  65. return $data_tilesets
  66. when :common_event
  67. return $data_common_events
  68. when :system
  69. return $data_system
  70. when :map_info
  71. return $data_mapinfos
  72. when :map_event
  73. return $data_mapinfos
  74. end
  75. end
  76. #------------------------------------------------------------------------
  77. # * new method: load_patch_data
  78. #------------------------------------------------------------------------
  79. def self.load_patch_data
  80. get_patch_files.each do |file_name|
  81. file = load_data(file_name)
  82. next if file[:unique_id] != UNIQUE_KEY
  83. file[:datas].each_pair do |key, data_array|
  84. next if (key == :map_info) || (key == :map_event)
  85. data_array.each do |data|
  86. next unless data
  87. get_data(key)[data.id] = data
  88. end
  89. end
  90. if file[:datas].has_key?(:map_event)
  91. file[:datas][:map_event].each_with_index do |events, map_id|
  92. next unless events
  93. next if map_id == 0
  94. $data_patch_events ||= {}
  95. $data_patch_events[map_id] ||= []
  96. $data_patch_events[map_id] += events
  97. end
  98. end
  99. if file[:datas].has_key?(:map_info)
  100. $data_mapinfos = file[:datas][:map_info][:info]
  101. $temp_patch_maps = file[:datas][:map_info][:map_datas]
  102. end
  103. end
  104. puts "Load Patch files completed!"
  105. end
  106. #------------------------------------------------------------------------
  107. # * new method: create_patch_file
  108. #------------------------------------------------------------------------
  109. def self.create_patch_file(patch_hash)
  110. old_time = Time.now
  111. patch_data = {}
  112. patch_data[:unique_id] = UNIQUE_KEY
  113. patch_data[:datas] = {}
  114. patch_hash.each_pair do |key, item_array|
  115. next if (key == :map_info) || key == :map_event
  116. patch_data[:datas][key] ||= []
  117. item_array.each do |index|
  118. patch_data[:datas][key] << get_data(key)[index]
  119. end
  120. end
  121. if patch_hash.has_key?(:map_info)
  122. patch_data[:datas][:map_info] = {}
  123. patch_data[:datas][:map_info][:info] = $data_mapinfos
  124. patch_data[:datas][:map_info][:map_datas] = {}
  125. patch_hash[:map_info].each do |map_id|
  126. next if map_id == 0
  127. patch_data[:datas][:map_info][:map_datas][map_id] = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
  128. end
  129. end
  130. if patch_hash.has_key?(:map_event)
  131. patch_hash[:map_event].each_with_index do |event_ids,map_id|
  132. next unless event_ids
  133. next if map_id == 0
  134. map = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
  135. event_ids.each do |id|
  136. next unless map.events[id]
  137. patch_data[:datas][:map_event] ||= []
  138. patch_data[:datas][:map_event][map_id] ||= []
  139. patch_data[:datas][:map_event][map_id][id] = map.events[id]
  140. end
  141. end
  142. end
  143. Dir.mkdir(PATCH_DIR) unless FileTest.directory?(PATCH_DIR)
  144. index = 1
  145. while FileTest.exist?(PATCH_DIR + "/" + PATCH_NAME.gsub("*") {"#{index}"})
  146. index += 1
  147. end
  148. File.open(PATCH_DIR + "/" + PATCH_NAME.gsub("*") {"#{index}"}, "wb") do |file|
  149. Marshal.dump(patch_data, file)
  150. end
  151. new_file = PATCH_DIR + "/" + PATCH_NAME.gsub("*") {"#{index}"}
  152. msgbox_p("New patch file created! Please check [ #{new_file} ]! | Time: #{Time.now - old_time}")
  153. end
  154. end # PATCH_SYSTEM
  155. end # DSIVER144
  156.  
  157. module DataManager
  158. class << self
  159. alias_method(:dsi_load_database_patch_system, :load_database)
  160. alias_method(:dsi_reload_map_if_update, :reload_map_if_updated)
  161. end
  162. #--------------------------------------------------------------------------
  163. # * Load Database
  164. #--------------------------------------------------------------------------
  165. def self.load_database
  166. dsi_load_database_patch_system
  167. end
  168. #--------------------------------------------------------------------------
  169. # alias method: reload_map_if_updated
  170. #--------------------------------------------------------------------------
  171. def self.reload_map_if_updated
  172. dsi_reload_map_if_update
  173. reload_map_if_patched
  174. end
  175. #--------------------------------------------------------------------------
  176. # new method: reload_map_if_patched
  177. #--------------------------------------------------------------------------
  178. def self.reload_map_if_patched
  179. unless $temp_patch_maps[$game_map.map_id].nil?
  180. $game_map.setup($game_map.map_id)
  181. $game_player.center($game_player.x, $game_player.y)
  182. $game_player.make_encounter_count
  183. end
  184. end
  185. end # DataManager
  186.  
  187. class Game_Map
  188. #--------------------------------------------------------------------------
  189. # overwrite method: setup
  190. #--------------------------------------------------------------------------
  191. def setup(map_id)
  192. @map_id = map_id
  193. if $temp_patch_maps.nil? || $temp_patch_maps[@map_id].nil?
  194. @map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))
  195. else
  196. @map = $temp_patch_maps[@map_id]
  197. end
  198. @tileset_id = @map.tileset_id
  199. @display_x = 0
  200. @display_y = 0
  201. referesh_vehicles
  202. setup_events
  203. setup_scroll
  204. setup_parallax
  205. setup_battleback
  206. @need_refresh = false
  207. end
  208. #--------------------------------------------------------------------------
  209. # * new method: find_empty_slot
  210. #--------------------------------------------------------------------------
  211. def find_empty_slot(start=1)
  212. id = start
  213. while @events[id]
  214. id += 1
  215. end
  216. return id
  217. end
  218. #--------------------------------------------------------------------------
  219. # * overwrite method: setup_events
  220. #--------------------------------------------------------------------------
  221. def setup_events
  222. @events = {}
  223. @map.events.each do |i, event|
  224. @events[i] = Game_Event.new(@map_id, event)
  225. end
  226. new_id = @events.size
  227. if $data_patch_events && $data_patch_events[@map_id]
  228. $data_patch_events[@map_id].each_with_index do |event,id|
  229. next unless event
  230. new_id = find_empty_slot(new_id)
  231. event.id = new_id
  232. @events[new_id] = Game_Event.new(@map_id, event)
  233. end
  234. end
  235. @common_events = parallel_common_events.collect do |common_event|
  236. Game_CommonEvent.new(common_event.id)
  237. end
  238. refresh_tile_events
  239. end
  240. end # Game_Map
  241.  
  242. class Scene_Load < Scene_File
  243. alias_method(:dsi_on_load_success, :on_load_success)
  244. #--------------------------------------------------------------------------
  245. # * Confirm Save File
  246. #--------------------------------------------------------------------------
  247. def on_savefile_ok
  248. super
  249. if ($TEST && DSIVER144::PATCH_SYSTEM::LOAD_PATCH_WHEN_TEST) or !$TEST
  250. DSIVER144::PATCH_SYSTEM.load_patch_data
  251. end
  252. if DataManager.load_game(@index)
  253. on_load_success
  254. else
  255. Sound.play_buzzer
  256. end
  257. end
  258. end
  259.  
  260. class Scene_Title
  261. alias_method(:update_patch_trigger, :update)
  262. alias_method(:dsi_command_new_game, :command_new_game)
  263. #--------------------------------------------------------------------------
  264. # * [New Game] Command
  265. #--------------------------------------------------------------------------
  266. def command_new_game
  267. if ($TEST && DSIVER144::PATCH_SYSTEM::LOAD_PATCH_WHEN_TEST) or !$TEST
  268. DSIVER144::PATCH_SYSTEM.load_patch_data
  269. end
  270. dsi_command_new_game
  271. end
  272. #--------------------------------------------------------------------------
  273. # * method: start
  274. #--------------------------------------------------------------------------
  275. def update
  276. update_patch_trigger
  277. if Input.trigger?(:F6) && $TEST
  278. SceneManager.call(Scene_DSIPatch)
  279. end
  280. end
  281. end # Scene_Title
  282.  
  283. class Scene_DSIPatch < Scene_Base
  284. #--------------------------------------------------------------------------
  285. # * method: start
  286. #--------------------------------------------------------------------------
  287. def start
  288. super
  289. @patch_window = Window_Patch_Type.new(0,0)
  290. @patch_window.init_data
  291. @patch_window.x = (Graphics.width - @patch_window.width)*0.5
  292. @patch_window.y = (Graphics.height - @patch_window.height)*0.5 - 24
  293. @patch_window.set_handler(:ok, method(:on_choose_ok))
  294. ww = @patch_window.width; wh = @patch_window.fitting_height(1)
  295. wy = @patch_window.height + @patch_window.y
  296. @patch_help_window = Window_Base.new(@patch_window.x,wy,ww,wh)
  297. @patch_help_window.draw_text(0,0,@patch_help_window.contents_width,24,"F7: Create New Patch! | F5: (Un)Select All!")
  298. end
  299. #--------------------------------------------------------------------------
  300. # * new method: on_choose_ok
  301. #--------------------------------------------------------------------------
  302. def on_choose_ok
  303. if has_category?
  304. if @patch_window.current_category == :map_event
  305. if !@patch_window.second_category
  306. @last_map_index = @patch_window.index
  307. @patch_window.second_category = @patch_window.current_symbol.to_s.to_i
  308. @patch_window.select(0)
  309. @patch_window.refresh
  310. @patch_window.activate
  311. else
  312. #p @patch_window.current_data
  313. @patch_window.activate
  314. map_id = @patch_window.second_category
  315. @patch_window.selected_data[:map_event] ||= []
  316. @patch_window.selected_data[:map_event][map_id] ||= []
  317. if !@patch_window.selected_data[:map_event][map_id].include?(@patch_window.current_item_data[1])
  318. @patch_window.selected_data[:map_event][map_id] << @patch_window.current_item_data[1]
  319. else
  320. @patch_window.selected_data[:map_event][map_id].delete(@patch_window.current_item_data[1])
  321. end
  322. p [map_id, @patch_window.selected_data[:map_event][map_id]]
  323. @patch_window.redraw_current_item
  324. end
  325. else
  326. if @patch_window.has_current_item
  327. @patch_window.unselect_current_item
  328. @patch_window.activate
  329. @patch_window.redraw_current_item
  330. else
  331. @patch_window.add_current_item
  332. @patch_window.activate
  333. @patch_window.redraw_current_item
  334. end
  335. end
  336. else
  337. @patch_window.set_category(@patch_window.current_symbol)
  338. @patch_window.activate
  339. end
  340. end
  341. #--------------------------------------------------------------------------
  342. # * new method: has_category?
  343. #--------------------------------------------------------------------------
  344. def has_category?
  345. return @patch_window.current_category
  346. end
  347. #--------------------------------------------------------------------------
  348. # * method: update
  349. #--------------------------------------------------------------------------
  350. def update
  351. super
  352. if Input.trigger?(:F7)
  353. DSIVER144::PATCH_SYSTEM.create_patch_file(@patch_window.selected_data)
  354. end
  355. if Input.trigger?(:F5)
  356. if !@patch_window.selected_all?
  357. @patch_window.select_all_item
  358. @patch_window.refresh
  359. else
  360. @patch_window.unselect_all_item
  361. @patch_window.refresh
  362. end
  363. end
  364. if has_category?
  365. if Input.trigger?(:B)
  366. if @patch_window.second_category
  367. @patch_window.second_category = nil
  368. if @last_map_index
  369. @patch_window.select(@last_map_index)
  370. @last_map_index = nil
  371. end
  372. @patch_window.refresh
  373. else
  374. @patch_window.clear_category
  375. end
  376. end
  377. end
  378. end # def update
  379. end # Scene_DSIPatch
  380.  
  381. class Window_Patch_Type < Window_Command
  382. attr_accessor :current_category
  383. attr_accessor :second_category
  384. attr_accessor :last_index
  385. attr_accessor :selected_data
  386. #--------------------------------------------------------------------------
  387. # * new method: init_data
  388. #--------------------------------------------------------------------------
  389. def init_data
  390. @selected_data = {}
  391. end
  392. #--------------------------------------------------------------------------
  393. # * Get Number of Lines to Show
  394. #--------------------------------------------------------------------------
  395. def visible_line_number
  396. return 12
  397. end
  398. #----------------------------------------------------------------------------
  399. # * window_width
  400. #----------------------------------------------------------------------------
  401. def window_width
  402. return 400
  403. end
  404. #--------------------------------------------------------------------------
  405. # * new method: clear_category
  406. #--------------------------------------------------------------------------
  407. def clear_category
  408. @current_category = nil
  409. refresh
  410. select(@last_index)
  411. end
  412. #--------------------------------------------------------------------------
  413. # * new method: set_category
  414. #--------------------------------------------------------------------------
  415. def set_category(category)
  416. @last_index = index
  417. @current_category = category
  418. refresh
  419. select(0)
  420. end
  421. #--------------------------------------------------------------------------
  422. # * new method: has_current_item
  423. #--------------------------------------------------------------------------
  424. def has_current_item
  425. type = current_item_data[0]
  426. id = current_item_data[1]
  427. @selected_data[type] && @selected_data[type].include?(id)
  428. end
  429. #--------------------------------------------------------------------------
  430. # * new method: unselect_current_item
  431. #--------------------------------------------------------------------------
  432. def unselect_current_item
  433. type = current_item_data[0]
  434. id = current_item_data[1]
  435. @selected_data[type].delete(id)
  436. end
  437. #--------------------------------------------------------------------------
  438. # * new method: add_current_item
  439. #--------------------------------------------------------------------------
  440. def add_current_item
  441. type = current_item_data[0]
  442. id = current_item_data[1]
  443. add_item(type,id)
  444. end
  445. #--------------------------------------------------------------------------
  446. # * new method: selected_all?
  447. #--------------------------------------------------------------------------
  448. def selected_all?
  449. return if current_item_data.nil?
  450. type = current_item_data[0]
  451. @selected_data[type] ||= []
  452. @selected_data[type].size == item_max+1
  453. end
  454. #--------------------------------------------------------------------------
  455. # * new method: unselect_all_item
  456. #--------------------------------------------------------------------------
  457. def unselect_all_item
  458. type = current_item_data[0]
  459. @selected_data[type] ||= []
  460. @selected_data[type].clear
  461. end
  462. #--------------------------------------------------------------------------
  463. # * new method: select_all_item
  464. #--------------------------------------------------------------------------
  465. def select_all_item
  466. return if current_item_data.nil?
  467. type = current_item_data[0]
  468. (item_max+1).times do |id|
  469. @selected_data[type] ||= []
  470. @selected_data[type] << id
  471. end
  472. @selected_data[type].uniq!
  473. end
  474. #--------------------------------------------------------------------------
  475. # * new method: add_item
  476. #--------------------------------------------------------------------------
  477. def add_item(type,id)
  478. @selected_data[type] ||= []
  479. @selected_data[type] << id
  480. p @selected_data
  481. end
  482. #--------------------------------------------------------------------------
  483. # * new method: item_data
  484. #--------------------------------------------------------------------------
  485. def item_data(index)
  486. [@list[index][:item_type],@list[index][:item_id]]
  487. end
  488. #--------------------------------------------------------------------------
  489. # * new method: current_item_data
  490. #--------------------------------------------------------------------------
  491. def current_item_data
  492. if current_data
  493. [current_data[:item_type],current_data[:item_id]]
  494. end
  495. end
  496. #--------------------------------------------------------------------------
  497. # * overwrite method: draw_item
  498. #--------------------------------------------------------------------------
  499. def draw_item(index)
  500. change_color(normal_color, command_enabled?(index))
  501. if @current_category
  502. data = item_data(index)
  503. if !@second_category
  504. if @selected_data[data[0]] && @selected_data[data[0]].include?(data[1])
  505. contents.fill_rect(item_rect_for_text(index), Color.new(200,121,142,200))
  506. end
  507. else
  508. if @selected_data[:map_event] && @selected_data[:map_event][@second_category] && @selected_data[:map_event][@second_category].include?(data[1])
  509. contents.fill_rect(item_rect_for_text(index), Color.new(200,121,142,200))
  510. end
  511. end
  512. end
  513. draw_text(item_rect_for_text(index), command_name(index), alignment)
  514. end
  515. #----------------------------------------------------------------------------
  516. # * overwrite method: add_command
  517. #----------------------------------------------------------------------------
  518. def add_command(name, symbol, enabled = true, ext = nil, item_id=nil, item_type=nil)
  519. @list.push({:name=>name, :symbol=>symbol, :enabled=>enabled, :ext=>ext, :item_id=>item_id, :item_type=>item_type})
  520. end
  521. #----------------------------------------------------------------------------
  522. # * alias method: make_command_list
  523. #----------------------------------------------------------------------------
  524. def make_command_list
  525. if @second_category
  526. map_data = load_data(sprintf("Data/Map%03d.rvdata2", @second_category))
  527. map_data.events.each_pair do |key,event|
  528. add_command("#{key} - #{event.name}", event.id.to_s.to_sym, true, nil, key, @current_category)
  529. end
  530. return
  531. end
  532. if @current_category
  533. data = DSIVER144::PATCH_SYSTEM.get_data(@current_category)
  534. if ![:map_info, :map_event].include?(@current_category)
  535. data.each do |thing|
  536. next if thing.nil?
  537. add_command("#{thing.id} - #{thing.name}", thing.name.to_sym, true, nil, thing.id, @current_category)
  538. end
  539. else
  540. data.each_pair do |map_id, map_data|
  541. map = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
  542. enabled = @current_category == :map_info ? true : map.events.size > 0
  543. add_command("#{map_id} - #{map_data.name}", map_id.to_s.to_sym, enabled, nil, map_id, @current_category)
  544. end
  545. end
  546. return
  547. end
  548. keys = [:item,:weapon,:armor,:actor,:class,:skill,:enemy,:troop,:state,:animation,:tileset,:common_event,:map_info,:map_event]
  549. keys.each do |key|
  550. name = key.to_s
  551. if key == :map_info; name = "MAPS"; end;
  552. if key == :map_event; name = "ADD NEW EVENT TO MAP"; end;
  553. add_command(name.upcase, key)
  554. end
  555. end
  556. end # Window_Patch_Type
  557. #===============================================================================
  558. # * END OF SCRIPT
  559. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement