eldenring 0.14.0

Structures, bindings, and utilities for From Software's title Elden Ring
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
use shared::{OwnedPtr, Subclass};

use crate::{
    ArrayWithHeader, DLMap, DLMultiMap, DLVector,
    cs::{BlockId, ItemCategory, ItemId},
    dlkr::DLAllocator,
    fd4::{FD4ParamResCap, FD4ResCap, FD4ResRep, ParamFile},
    param::ParamDef,
};

use bitfield::bitfield;

#[repr(C)]
/// Entry in the weapon upgrade index map.
/// Maps different param row indices to their parent/child/sibling relation for the weapon upgrade levels.
pub struct WeaponUpgradeIndexMapEntry {
    /// Index to the base weapon param id upgrade param row.
    pub parent: i16,
    /// Index to the next sibling param row.
    pub next_sibling: i16,
    /// Index to the first child param row.
    /// -1 if not a parent.
    pub first_child: i16,
}

#[repr(C)]
/// Structure for fast weapon reinforcement param lookups.
/// Uses param row index and allows traversal of the upgrade tree.
///
pub struct CSWepReinforceTree {
    vftable: usize,
    pub allocator: &'static DLAllocator,
    /// Array of map entries, one for each weapon param row.
    /// The index corresponds to the weapon param row index.
    pub index_map: ArrayWithHeader<WeaponUpgradeIndexMapEntry>,
}

impl CSWepReinforceTree {
    /// Get the next upgrade param row index for the given weapon param row index.
    pub fn get_next_upgrade(&self, weapon_param_row_index: usize) -> Option<usize> {
        // Safety: index_map is guaranteed to be valid.
        let upgrade_list = unsafe { self.index_map.as_slice() };
        let next_index = upgrade_list[weapon_param_row_index].first_child;
        if next_index == -1 {
            None
        } else {
            Some(next_index as usize)
        }
    }
    /// Get the base weapon param row index for the given weapon param row index.
    pub fn get_base_weapon(&self, weapon_param_row_index: usize) -> Option<usize> {
        // Safety: index_map is guaranteed to be valid.
        let upgrade_list = unsafe { self.index_map.as_slice() };
        let entry = &upgrade_list[weapon_param_row_index];
        if entry.parent == -1 {
            None
        } else {
            Some(entry.parent as usize)
        }
    }
    /// Get the first child upgrade param row index for the given weapon param row index.
    pub fn get_first_child(&self, weapon_param_row_index: usize) -> Option<usize> {
        // Safety: index_map is guaranteed to be valid.
        let upgrade_list = unsafe { self.index_map.as_slice() };
        let entry = &upgrade_list[weapon_param_row_index];
        let first_child_index = entry.first_child;
        if first_child_index == -1 {
            None
        } else {
            Some(first_child_index as usize)
        }
    }
}

#[repr(C)]
pub struct BuddyStoneTalkChrEntityId {
    /// Chr entity ID of specific buddy stone.
    pub talk_chr_entity_id: u32,
    /// Index into BuddyStoneParam for the stone associated with this chr entity.
    pub buddy_stone_param_index: u32,
}

#[repr(C)]
pub struct BonfireEntityId {
    pub bonfire_entity_id: u32,
    pub bonfire_warp_param_index: u32,
}

bitfield! {
    #[repr(C)]
    #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
    pub struct ChrEquipModelKey(u32);
    impl Debug;

    u8;
    /// Equipment type (high 8 bits)
    pub equip_type, _: 31, 24;
    _, set_equip_type: 31, 24;

    u8;
    /// Gender (next 8 bits)
    pub gender, _: 23, 16;
    _, set_gender: 23, 16;

    u16;
    /// Model id (low 16 bits)
    pub model_id, _: 15, 0;
    _, set_model_id: 15, 0;
}

impl ChrEquipModelKey {
    /// Construct a packed key from separate fields.
    pub fn from_parts(equip_type: u8, gender: u8, model_id: u16) -> Self {
        let mut k = ChrEquipModelKey(0);
        k.set_equip_type(equip_type);
        k.set_gender(gender);
        k.set_model_id(model_id);
        k
    }
}

#[repr(C)]
pub struct ChrEquipModelMapEntry {
    /// Packed key = (equip_type << 24) | (gender << 16) | model_id
    pub key: ChrEquipModelKey,
    /// Row index in [CHR_EQUIP_MODEL_PARAM_ST] (not param ID)
    pub param_row_index: u32,
}

#[repr(C)]
#[derive(Subclass)]
pub struct ParamResCap {
    pub res_cap: FD4ResCap,
    /// Type of ParamResCap, should correspond to where you got it from.
    ///
    /// Eg. [SoloParamRepository] solo param holders will always have
    /// [ParamResCapType::SoloParam]
    /// while CSEventFlagUsageParamManager will have
    /// [ParamResCapType::EventFlagUsageParam]
    pub param_type: ParamResCapType,

    /// The underlying res cap.
    // This is technically owned by [FD4ParamRepository], in the sense that
    // that's the code responsible for creating and destroying it. However, for
    // efficiency reasons, we don't allow access through [FD4ParamRepository]
    // without an `unsafe` block, which makes it safe for us to expose this as
    // an [OwnedPtr] here. See the comment on [FD4ParamRepository] for details.
    pub param_res_cap: OwnedPtr<FD4ParamResCap>,
}

impl ParamResCap {
    /// In debug mode, if this parameter's name and type doesn't `P`.
    ///
    /// In release mode, this is a no-op.
    fn assert_matches_param<P: SoloParam>(&self) {
        debug_assert!(
            self.res_cap.name == P::NAME,
            "Expected param {}, was {}",
            P::NAME,
            self.res_cap.name,
        );

        let struct_name = self.param_res_cap.data.struct_name();
        debug_assert!(
            struct_name == P::StructType::NAME,
            "Expected param struct {}, was {}",
            P::StructType::NAME,
            struct_name,
        );
    }
}

#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ParamResCapType {
    SoloParam = 0,
    EventFlagUsageParam = 1,
    SystemParam = 2,
    GConfigParam = 3,
    PerformanceCheckParam = 4,
}

#[repr(C)]
/// Holder for solo param res caps.
pub struct SoloParamHolder {
    pub res_cap_count: u32,
    /// The list can hold up to 8 param res caps, but the game only seems to use first.
    /// Supposedly this is used for some versioning.
    res_caps: [Option<OwnedPtr<ParamResCap>>; 8],
}

impl SoloParamHolder {
    /// The res cap at `index` in this holder, if it exists.
    pub fn get_res_cap(&self, index: usize) -> Option<&ParamResCap> {
        self.res_caps.get(index)?.as_deref()
    }

    /// The mutable res cap at `index` in this holder, if it exists.
    pub fn get_res_cap_mut(&mut self, index: usize) -> Option<&mut ParamResCap> {
        self.res_caps.get_mut(index)?.as_deref_mut()
    }

    /// An iterator over all res caps in this holder.
    pub fn res_caps(&self) -> impl Iterator<Item = &ParamResCap> {
        self.res_caps.iter().filter_map(|opt| opt.as_deref())
    }

    /// An iterator over all mutable res caps in this holder.
    pub fn res_caps_mut(&mut self) -> impl Iterator<Item = &mut ParamResCap> {
        self.res_caps
            .iter_mut()
            .filter_map(|opt| opt.as_deref_mut())
    }
}

#[repr(C)]
#[shared::singleton("SoloParamRepository")]
#[derive(Subclass)]
pub struct SoloParamRepository {
    pub res_rep: FD4ResRep,
    unk78: u32,
    /// Array of solo param holders, one for each solo param type.
    pub solo_param_holders: [SoloParamHolder; 194],
    /// Structure for fast weapon reinforcement lookups.
    /// Uses param row of WeaponEquipParam as index
    /// and allows traversal of the upgrade tree.
    pub wep_reinforces: CSWepReinforceTree,
    /// Ordered list of buddy stone entity IDs and their associated buddy stone param indices.
    ///
    /// Can be used to search [crate::param::BUDDY_STONE_PARAM_ST] rows based on chr entity ID.
    pub buddy_stone_entity_ids: DLVector<BuddyStoneTalkChrEntityId>,
    /// Ordered list of bonfire entity IDs and their associated bonfire warp param indices.
    ///
    /// Can be used to search [crate::param::BONFIRE_WARP_PARAM_ST] rows based on bonfire entity ID.
    pub bonfire_warps: DLVector<BonfireEntityId>,
    /// MultiMap groupping [WEATHER_ASSET_REPLACE_PARAM_ST] param row index by [BlockId].
    pub weather_asset_replaces: DLMultiMap<BlockId, u32>,
    /// MultiMap groupping [LEGACY_DISTANT_VIEW_PARTS_REPLACE_PARAM] param row index by [BlockId].
    pub legacy_distant_view_parts_replaces: DLMultiMap<BlockId, u32>,
    /// Tree mapping for the [CHR_EQUIP_MODEL_PARAM_ST] param rows.
    /// The usage of this param is unknown.
    pub chr_equip_models: DLMap<ChrEquipModelKey, u32>,
    /// Map of all area IDs to their multiplay event flag limits.
    pub match_area_limits: DLMap<u32, u32>,
}

impl SoloParamRepository {
    /// An iterator over all solo parameters.
    pub fn params(&self) -> impl Iterator<Item = &FD4ParamResCap> {
        self.solo_param_holders
            .iter()
            .flat_map(|h| h.res_caps())
            .map(|rc| rc.param_res_cap.as_ref())
    }

    /// An iterator over all mutable solo parameters.
    pub fn params_mut(&mut self) -> impl Iterator<Item = &mut FD4ParamResCap> {
        self.solo_param_holders
            .iter_mut()
            .flat_map(|h| h.res_caps_mut())
            .map(|rc| rc.param_res_cap.as_mut())
    }

    pub fn get_chr_equip_model_param_by_key(
        &self,
        equip_type: u8,
        gender: u8,
        model_id: u16,
    ) -> Option<&crate::param::CHR_EQUIP_MODEL_PARAM_ST> {
        let key = ChrEquipModelKey::from_parts(equip_type, gender, model_id);
        let entry = self.chr_equip_models.find(&key)?;
        self.get_row_by_index::<ChrEquipModelParam>(*entry as usize)
    }

    pub fn get_by_buddy_stone_param_by_entity_id(
        &self,
        talk_chr_entity_id: u32,
    ) -> Option<&crate::param::BUDDY_STONE_PARAM_ST> {
        let entry_index = self
            .buddy_stone_entity_ids
            .binary_search_by_key(&talk_chr_entity_id, |e| e.talk_chr_entity_id)
            .ok()?;
        let entry = &self.buddy_stone_entity_ids[entry_index];
        self.get_row_by_index::<BuddyStoneParam>(entry.buddy_stone_param_index as usize)
    }

    pub fn get_by_bonfire_warp_param_by_entity_id(
        &self,
        bonfire_entity_id: u32,
    ) -> Option<&crate::param::BONFIRE_WARP_PARAM_ST> {
        let entry_index = self
            .bonfire_warps
            .binary_search_by_key(&bonfire_entity_id, |e| e.bonfire_entity_id)
            .ok()?;
        let entry = &self.bonfire_warps[entry_index];
        self.get_row_by_index::<BonfireWarpParam>(entry.bonfire_warp_param_index as usize)
    }

    pub fn weather_asset_replaces_params_by_block_id(
        &self,
        block_id: &BlockId,
    ) -> impl Iterator<Item = &crate::param::WEATHER_ASSET_REPLACE_PARAM_ST> {
        self.weather_asset_replaces
            .find(block_id)
            .filter_map(|e| self.get_row_by_index::<WeatherAssetReplaceParam>(*e as usize))
    }

    pub fn legacy_distant_view_parts_replaces_by_block_id(
        &self,
        block_id: &BlockId,
    ) -> impl Iterator<Item = &crate::param::LEGACY_DISTANT_VIEW_PARTS_REPLACE_PARAM> {
        self.legacy_distant_view_parts_replaces
            .find(block_id)
            .filter_map(|e| {
                self.get_row_by_index::<LegacyDistantViewPartsReplaceParam>(*e as usize)
            })
    }

    /// Get a solo param (regulation.bin) row by its parameter type and ID.
    pub fn get<P: SoloParam>(&self, param_id: u32) -> Option<&P::StructType> {
        // SAFETY: By construction, [SoloParam] only applies to parameters whose
        // indices are guaranteed by the game to be consistent.
        unsafe {
            self.get_param_file::<P>()
                .get_row_by_id::<P::StructType>(param_id)
        }
    }

    /// Get a mutable solo param (regulation.bin) row by its parameter type and
    /// ID.
    pub fn get_mut<P: SoloParam>(&mut self, param_id: u32) -> Option<&mut P::StructType> {
        // SAFETY: By construction, [SoloParam] only applies to parameters whose
        // indices are guaranteed by the game to be consistent.
        unsafe {
            self.get_param_file_mut::<P>()
                .get_row_by_id_mut::<P::StructType>(param_id)
        }
    }

    /// Get a solo param (regulation.bin) row by its parameter type and row
    /// index.
    ///
    /// **IMPORTANT**: The row index is *not* the same as the parameter ID. Use
    /// this when you already know the index from a mapping like
    /// [SoloParamRepository::wep_reinforces] or
    /// [SoloParamRepository::buddy_stone_entity_ids].
    pub fn get_row_by_index<P: SoloParam>(&self, row_index: usize) -> Option<&P::StructType> {
        // SAFETY: By construction, [SoloParam] only applies to parameters whose
        // indices are guaranteed by the game to be consistent.
        unsafe {
            self.get_param_file::<P>()
                .get_row_by_index::<P::StructType>(row_index)
        }
    }

    /// Get a mutable solo param (regulation.bin) row by its parameter type and
    /// row index.
    ///
    /// **IMPORTANT**: The row index is *not* the same as the parameter ID. Use
    /// this when you already know the index from a mapping like
    /// [SoloParamRepository::wep_reinforces] or
    /// [SoloParamRepository::buddy_stone_entity_ids].
    pub fn get_row_by_index_mut<P: SoloParam>(
        &mut self,
        row_index: usize,
    ) -> Option<&mut P::StructType> {
        // SAFETY: By construction, [SoloParam] only applies to parameters whose
        // indices are guaranteed by the game to be consistent.
        unsafe {
            self.get_param_file_mut::<P>()
                .get_row_by_index_mut::<P::StructType>(row_index)
        }
    }

    /// Returns the index of a solo param (regulation.bin) row by its parameter
    /// type and ID.
    pub fn get_index_by_param_id<P: SoloParam>(&self, param_id: u32) -> Option<usize> {
        self.get_param_file::<P>().find_index(param_id)
    }

    /// Returns an equipment parameter row enum for the given item ID, or `None`
    /// if the row doesn't exit.
    pub fn get_equip_param(&self, id: ItemId) -> Option<EquipParamStruct<'_>> {
        use ItemCategory::*;
        match id.category() {
            Weapon => self
                // Round to the nearest 100 in case the ID is for an upgraded
                // weapon.
                .get::<EquipParamWeapon>((id.param_id() / 100) * 100)
                .map(|p| EquipParam::as_enum(p)),
            Protector => self
                .get::<EquipParamProtector>(id.param_id())
                .map(|p| EquipParam::as_enum(p)),
            Accessory => self
                .get::<EquipParamAccessory>(id.param_id())
                .map(|p| EquipParam::as_enum(p)),
            Gem => self
                .get::<EquipParamGem>(id.param_id())
                .map(|p| EquipParam::as_enum(p)),
            Goods => self
                .get::<EquipParamGoods>(id.param_id())
                .map(|p| EquipParam::as_enum(p)),
        }
    }

    /// Returns a mutable equipment parameter row enum for the given item ID, or `None`
    /// if the row doesn't exit.
    pub fn get_equip_param_mut(&mut self, id: ItemId) -> Option<EquipParamStructMut<'_>> {
        use ItemCategory::*;
        match id.category() {
            Weapon => self
                // Round to the nearest 100 in case the ID is for an upgraded
                // weapon.
                .get_mut::<EquipParamWeapon>((id.param_id() / 100) * 100)
                .map(|p| EquipParam::as_enum_mut(p)),
            Protector => self
                .get_mut::<EquipParamProtector>(id.param_id())
                .map(|p| EquipParam::as_enum_mut(p)),
            Accessory => self
                .get_mut::<EquipParamAccessory>(id.param_id())
                .map(|p| EquipParam::as_enum_mut(p)),
            Gem => self
                .get_mut::<EquipParamGem>(id.param_id())
                .map(|p| EquipParam::as_enum_mut(p)),
            Goods => self
                .get_mut::<EquipParamGoods>(id.param_id())
                .map(|p| EquipParam::as_enum_mut(p)),
        }
    }

    /// Returns an iterator over each row in parameter `P` along with their
    /// parameter IDs, in ID order.
    pub fn rows<'a, P: SoloParam + 'a>(
        &'a self,
    ) -> impl Iterator<Item = (u32, &'a P::StructType)> + 'a {
        unsafe { self.get_param_file::<P>().rows() }
    }

    /// Returns an iterator over each mutable row in parameter `P` along with
    /// their parameter IDs, in ID order.
    pub fn rows_mut<'a, P: SoloParam + 'a>(
        &'a mut self,
    ) -> impl Iterator<Item = (u32, &'a mut P::StructType)> + 'a {
        unsafe { self.get_param_file_mut::<P>().rows_mut() }
    }

    /// Returns the [ParamFile] associated with `P`, if it exists at the
    /// expected index. This should never return `None` for a vanilla game,
    /// because the only [SoloParam]s this library defines are ones that are
    /// found in the game.
    fn get_param_file<P: SoloParam>(&self) -> &ParamFile {
        let holder = self
            .solo_param_holders
            .get(P::INDEX as usize)
            .unwrap_or_else(|| {
                panic!(
                    "Param {} should exist at index {}, but it does not",
                    P::NAME,
                    P::INDEX
                )
            });
        let res_cap = holder
            .get_res_cap(0)
            .expect("Expected param holder to have exactly one res cap");

        res_cap.assert_matches_param::<P>();
        &res_cap.param_res_cap.data
    }

    /// Returns the mutable [ParamFile] associated with `P`, if it exists at the
    /// expected index. This should never return `None` for a vanilla game,
    /// because the only [SoloParam]s this library defines are ones that are
    /// found in the game.
    fn get_param_file_mut<P: SoloParam>(&mut self) -> &mut ParamFile {
        let holder = self
            .solo_param_holders
            .get_mut(P::INDEX as usize)
            .unwrap_or_else(|| {
                panic!(
                    "Param {} should exist at index {}, but it does not",
                    P::NAME,
                    P::INDEX
                )
            });
        let res_cap = holder
            .get_res_cap_mut(0)
            .expect("Expected param holder to have exactly one res cap");

        res_cap.assert_matches_param::<P>();
        &mut res_cap.param_res_cap.data
    }
}

/// A shared trait for parameters that are part of [SoloParamRepository], used
/// to ensure that they can be accessed in a type-safe way.
pub trait SoloParam {
    /// The parameter name. This corresponds to `ParamResCap.res_cap.name` and
    /// `FD4ParamResCap.res_cap.name`, not to [ParamFile::struct_name] and
    /// [ParamDef::NAME].
    const NAME: &'static str;

    /// The index of this parameter in [SoloParamRepository].
    const INDEX: u32;

    /// The type of the data that this parameter contains.
    type StructType: ParamDef;
}

use crate::param::*;

macro_rules! solo_params {
    ( $( ($ParamType:ident, $StructType:ty, $Index:expr) ),* $(,)? ) => {
        $(
            #[doc="The"]
            #[doc=stringify!($ParamType)]
            #[doc="parameter. This can be used with [SoloParamRepository::get] and similar methods"]
            #[doc="to load parameter data."]
            #[allow(non_camel_case_types)]
            pub struct $ParamType;

            impl SoloParam for $ParamType {
                const NAME: &'static str = stringify!($ParamType);
                const INDEX: u32 = $Index;
                type StructType = $StructType;
            }
        )*
    };
}

solo_params!(
    (EquipParamWeapon, EQUIP_PARAM_WEAPON_ST, 0),
    (EquipParamProtector, EQUIP_PARAM_PROTECTOR_ST, 1),
    (EquipParamAccessory, EQUIP_PARAM_ACCESSORY_ST, 2),
    (EquipParamGoods, EQUIP_PARAM_GOODS_ST, 3),
    (ReinforceParamWeapon, REINFORCE_PARAM_WEAPON_ST, 4),
    (ReinforceParamProtector, REINFORCE_PARAM_PROTECTOR_ST, 5),
    (NpcParam, NPC_PARAM_ST, 6),
    (AtkParam_Npc, ATK_PARAM_ST, 7),
    (AtkParam_Pc, ATK_PARAM_ST, 8),
    (NpcThinkParam, NPC_THINK_PARAM_ST, 9),
    (Bullet, BULLET_PARAM_ST, 10),
    (BulletCreateLimitParam, BULLET_CREATE_LIMIT_PARAM_ST, 11),
    (BehaviorParam, BEHAVIOR_PARAM_ST, 12),
    (BehaviorParam_PC, BEHAVIOR_PARAM_ST, 13),
    (Magic, MAGIC_PARAM_ST, 14),
    (SpEffectParam, SP_EFFECT_PARAM_ST, 15),
    (SpEffectVfxParam, SP_EFFECT_VFX_PARAM_ST, 16),
    (SpEffectSetParam, SP_EFFECT_SET_PARAM_ST, 17),
    (TalkParam, TALK_PARAM_ST, 18),
    (MenuColorTableParam, MENU_PARAM_COLOR_TABLE_ST, 19),
    (ItemLotParam_enemy, ITEMLOT_PARAM_ST, 20),
    (ItemLotParam_map, ITEMLOT_PARAM_ST, 21),
    (MoveParam, MOVE_PARAM_ST, 22),
    (CharaInitParam, CHARACTER_INIT_PARAM, 23),
    (EquipMtrlSetParam, EQUIP_MTRL_SET_PARAM_ST, 24),
    (FaceParam, FACE_PARAM_ST, 25),
    (FaceRangeParam, FACE_RANGE_PARAM_ST, 26),
    (ShopLineupParam, SHOP_LINEUP_PARAM, 27),
    (ShopLineupParam_Recipe, SHOP_LINEUP_PARAM, 28),
    (GameAreaParam, GAME_AREA_PARAM_ST, 29),
    (CalcCorrectGraph, CACL_CORRECT_GRAPH_ST, 30),
    (LockCamParam, LOCK_CAM_PARAM_ST, 31),
    (ObjActParam, OBJ_ACT_PARAM_ST, 32),
    (HitMtrlParam, HIT_MTRL_PARAM_ST, 33),
    (KnockBackParam, KNOCKBACK_PARAM_ST, 34),
    (DecalParam, DECAL_PARAM_ST, 35),
    (ActionButtonParam, ACTIONBUTTON_PARAM_ST, 36),
    (AiSoundParam, AI_SOUND_PARAM_ST, 37),
    (PlayRegionParam, PLAY_REGION_PARAM_ST, 38),
    (NetworkAreaParam, NETWORK_AREA_PARAM_ST, 39),
    (NetworkParam, NETWORK_PARAM_ST, 40),
    (NetworkMsgParam, NETWORK_MSG_PARAM_ST, 41),
    (BudgetParam, BUDGET_PARAM_ST, 42),
    (BonfireWarpParam, BONFIRE_WARP_PARAM_ST, 43),
    (BonfireWarpTabParam, BONFIRE_WARP_TAB_PARAM_ST, 44),
    (
        BonfireWarpSubCategoryParam,
        BONFIRE_WARP_SUB_CATEGORY_PARAM_ST,
        45
    ),
    (MenuPropertySpecParam, MENUPROPERTY_SPEC, 46),
    (MenuPropertyLayoutParam, MENUPROPERTY_LAYOUT, 47),
    (MenuValueTableParam, MENU_VALUE_TABLE_SPEC, 48),
    (Ceremony, CEREMONY_PARAM_ST, 49),
    (PhantomParam, PHANTOM_PARAM_ST, 50),
    (CharMakeMenuTopParam, CHARMAKEMENUTOP_PARAM_ST, 51),
    (
        CharMakeMenuListItemParam,
        CHARMAKEMENU_LISTITEM_PARAM_ST,
        52
    ),
    (
        HitEffectSfxConceptParam,
        HIT_EFFECT_SFX_CONCEPT_PARAM_ST,
        53
    ),
    (HitEffectSfxParam, HIT_EFFECT_SFX_PARAM_ST, 54),
    (WepAbsorpPosParam, WEP_ABSORP_POS_PARAM_ST, 55),
    (ToughnessParam, TOUGHNESS_PARAM_ST, 56),
    (SeMaterialConvertParam, SE_MATERIAL_CONVERT_PARAM_ST, 57),
    (ThrowDirectionSfxParam, THROW_DIRECTION_SFX_PARAM_ST, 58),
    (DirectionCameraParam, DIRECTION_CAMERA_PARAM_ST, 59),
    (RoleParam, ROLE_PARAM_ST, 60),
    (WaypointParam, WAYPOINT_PARAM_ST, 61),
    (ThrowParam, THROW_PARAM_ST, 62),
    (GrassTypeParam, GRASS_TYPE_PARAM_ST, 63),
    (GrassTypeParam_Lv1, GRASS_TYPE_PARAM_ST, 64),
    (GrassTypeParam_Lv2, GRASS_TYPE_PARAM_ST, 65),
    (GrassLodRangeParam, GRASS_LOD_RANGE_PARAM_ST, 66),
    (NpcAiActionParam, NPC_AI_ACTION_PARAM_ST, 67),
    (PartsDrawParam, PARTS_DRAW_PARAM_ST, 68),
    (AssetEnvironmentGeometryParam, ASSET_GEOMETORY_PARAM_ST, 69),
    (AssetModelSfxParam, ASSET_MODEL_SFX_PARAM_ST, 70),
    (AssetMaterialSfxParam, ASSET_MATERIAL_SFX_PARAM_ST, 71),
    (
        AttackElementCorrectParam,
        ATTACK_ELEMENT_CORRECT_PARAM_ST,
        72
    ),
    (FootSfxParam, FOOT_SFX_PARAM_ST, 73),
    (MaterialExParam, MATERIAL_EX_PARAM_ST, 74),
    (HPEstusFlaskRecoveryParam, ESTUS_FLASK_RECOVERY_PARAM_ST, 75),
    (MPEstusFlaskRecoveryParam, ESTUS_FLASK_RECOVERY_PARAM_ST, 76),
    (MultiPlayCorrectionParam, MULTI_PLAY_CORRECTION_PARAM_ST, 77),
    (MenuOffscrRendParam, MENU_OFFSCR_REND_PARAM_ST, 78),
    (ClearCountCorrectParam, CLEAR_COUNT_CORRECT_PARAM_ST, 79),
    (
        MapMimicryEstablishmentParam,
        MAP_MIMICRY_ESTABLISHMENT_PARAM_ST,
        80
    ),
    (WetAspectParam, WET_ASPECT_PARAM_ST, 81),
    (SwordArtsParam, SWORD_ARTS_PARAM_ST, 82),
    (
        KnowledgeLoadScreenItemParam,
        KNOWLEDGE_LOADSCREEN_ITEM_PARAM_ST,
        83
    ),
    (
        MultiHPEstusFlaskBonusParam,
        MULTI_ESTUS_FLASK_BONUS_PARAM_ST,
        84
    ),
    (
        MultiMPEstusFlaskBonusParam,
        MULTI_ESTUS_FLASK_BONUS_PARAM_ST,
        85
    ),
    (MultiSoulBonusRateParam, MULTI_SOUL_BONUS_RATE_PARAM_ST, 86),
    (WorldMapPointParam, WORLD_MAP_POINT_PARAM_ST, 87),
    (WorldMapPieceParam, WORLD_MAP_PIECE_PARAM_ST, 88),
    (WorldMapLegacyConvParam, WORLD_MAP_LEGACY_CONV_PARAM_ST, 89),
    (WorldMapPlaceNameParam, WORLD_MAP_PLACE_NAME_PARAM_ST, 90),
    (ChrModelParam, CHR_MODEL_PARAM_ST, 91),
    (LoadBalancerParam, LOAD_BALANCER_PARAM_ST, 92),
    (
        LoadBalancerDrawDistScaleParam,
        LOAD_BALANCER_DRAW_DIST_SCALE_PARAM_ST,
        93
    ),
    (
        LoadBalancerDrawDistScaleParam_ps4,
        LOAD_BALANCER_DRAW_DIST_SCALE_PARAM_ST,
        94
    ),
    (
        LoadBalancerDrawDistScaleParam_ps5,
        LOAD_BALANCER_DRAW_DIST_SCALE_PARAM_ST,
        95
    ),
    (
        LoadBalancerDrawDistScaleParam_xb1,
        LOAD_BALANCER_DRAW_DIST_SCALE_PARAM_ST,
        96
    ),
    (
        LoadBalancerDrawDistScaleParam_xb1x,
        LOAD_BALANCER_DRAW_DIST_SCALE_PARAM_ST,
        97
    ),
    (
        LoadBalancerDrawDistScaleParam_xss,
        LOAD_BALANCER_DRAW_DIST_SCALE_PARAM_ST,
        98
    ),
    (
        LoadBalancerDrawDistScaleParam_xsx,
        LOAD_BALANCER_DRAW_DIST_SCALE_PARAM_ST,
        99
    ),
    (
        LoadBalancerNewDrawDistScaleParam_win64,
        LOAD_BALANCER_NEW_DRAW_DIST_SCALE_PARAM_ST,
        100
    ),
    (
        LoadBalancerNewDrawDistScaleParam_ps4,
        LOAD_BALANCER_NEW_DRAW_DIST_SCALE_PARAM_ST,
        101
    ),
    (
        LoadBalancerNewDrawDistScaleParam_ps5,
        LOAD_BALANCER_NEW_DRAW_DIST_SCALE_PARAM_ST,
        102
    ),
    (
        LoadBalancerNewDrawDistScaleParam_xb1,
        LOAD_BALANCER_NEW_DRAW_DIST_SCALE_PARAM_ST,
        103
    ),
    (
        LoadBalancerNewDrawDistScaleParam_xb1x,
        LOAD_BALANCER_NEW_DRAW_DIST_SCALE_PARAM_ST,
        104
    ),
    (
        LoadBalancerNewDrawDistScaleParam_xss,
        LOAD_BALANCER_NEW_DRAW_DIST_SCALE_PARAM_ST,
        105
    ),
    (
        LoadBalancerNewDrawDistScaleParam_xsx,
        LOAD_BALANCER_NEW_DRAW_DIST_SCALE_PARAM_ST,
        106
    ),
    (
        WwiseValueToStrParam_Switch_AttackType,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        107
    ),
    (
        WwiseValueToStrParam_Switch_DamageAmount,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        108
    ),
    (
        WwiseValueToStrParam_Switch_DeffensiveMaterial,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        109
    ),
    (
        WwiseValueToStrParam_Switch_HitStop,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        110
    ),
    (
        WwiseValueToStrParam_Switch_OffensiveMaterial,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        111
    ),
    (
        WwiseValueToStrParam_Switch_GrassHitType,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        112
    ),
    (
        WwiseValueToStrParam_Switch_PlayerShoes,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        113
    ),
    (
        WwiseValueToStrParam_Switch_PlayerEquipmentTops,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        114
    ),
    (
        WwiseValueToStrParam_Switch_PlayerEquipmentBottoms,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        115
    ),
    (
        WwiseValueToStrParam_Switch_PlayerVoiceType,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        116
    ),
    (
        WwiseValueToStrParam_Switch_AttackStrength,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        117
    ),
    (
        WwiseValueToStrParam_EnvPlaceType,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        118
    ),
    (WeatherParam, WEATHER_PARAM_ST, 119),
    (WeatherLotParam, WEATHER_LOT_PARAM_ST, 120),
    (WeatherAssetCreateParam, WEATHER_ASSET_CREATE_PARAM_ST, 121),
    (
        WeatherAssetReplaceParam,
        WEATHER_ASSET_REPLACE_PARAM_ST,
        122
    ),
    (SpeedtreeParam, SPEEDTREE_MODEL_PARAM_ST, 123),
    (RideParam, RIDE_PARAM_ST, 124),
    (SeActivationRangeParam, SE_ACTIVATION_RANGE_PARAM_ST, 125),
    (RollingObjLotParam, ROLLING_OBJ_LOT_PARAM_ST, 126),
    (
        NpcAiBehaviorProbability,
        NPC_AI_BEHAVIOR_PROBABILITY_PARAM_ST,
        127
    ),
    (BuddyParam, BUDDY_PARAM_ST, 128),
    (GparamRefSettings, GPARAM_REF_SETTINGS_PARAM_ST, 129),
    (RandomAppearParam, RANDOM_APPEAR_PARAM_ST, 130),
    (
        MapGridCreateHeightLimitInfoParam,
        MAP_GRID_CREATE_HEIGHT_LIMIT_INFO_PARAM_ST,
        131
    ),
    (EnvObjLotParam, ENV_OBJ_LOT_PARAM_ST, 132),
    (MapDefaultInfoParam, MAP_DEFAULT_INFO_PARAM_ST, 133),
    (BuddyStoneParam, BUDDY_STONE_PARAM_ST, 134),
    (
        LegacyDistantViewPartsReplaceParam,
        LEGACY_DISTANT_VIEW_PARTS_REPLACE_PARAM,
        135
    ),
    (SoundCommonIngameParam, SOUND_COMMON_INGAME_PARAM_ST, 136),
    (
        SoundAutoEnvSoundGroupParam,
        SOUND_AUTO_ENV_SOUND_GROUP_PARAM_ST,
        137
    ),
    (
        SoundAutoReverbEvaluationDistParam,
        SOUND_AUTO_REVERB_EVALUATION_DIST_PARAM_ST,
        138
    ),
    (
        SoundAutoReverbSelectParam,
        SOUND_AUTO_REVERB_SELECT_PARAM_ST,
        139
    ),
    (EnemyCommonParam, ENEMY_COMMON_PARAM_ST, 140),
    (GameSystemCommonParam, GAME_SYSTEM_COMMON_PARAM_ST, 141),
    (GraphicsCommonParam, GRAPHICS_COMMON_PARAM_ST, 142),
    (MenuCommonParam, MENU_COMMON_PARAM_ST, 143),
    (PlayerCommonParam, PLAYER_COMMON_PARAM_ST, 144),
    (
        CutsceneGparamWeatherParam,
        CUTSCENE_GPARAM_WEATHER_PARAM_ST,
        145
    ),
    (CutsceneGparamTimeParam, CUTSCENE_GPARAM_TIME_PARAM_ST, 146),
    (
        CutsceneTimezoneConvertParam,
        CUTSCENE_TIMEZONE_CONVERT_PARAM_ST,
        147
    ),
    (
        CutsceneWeatherOverrideGparamConvertParam,
        CUTSCENE_WEATHER_OVERRIDE_GPARAM_ID_CONVERT_PARAM_ST,
        148
    ),
    (SoundCutsceneParam, SOUND_CUTSCENE_PARAM_ST, 149),
    (
        ChrActivateConditionParam,
        CHR_ACTIVATE_CONDITION_PARAM_ST,
        150
    ),
    (CutsceneMapIdParam, CUTSCENE_MAP_ID_PARAM_ST, 151),
    (
        CutSceneTextureLoadParam,
        CUTSCENE_TEXTURE_LOAD_PARAM_ST,
        152
    ),
    (GestureParam, GESTURE_PARAM_ST, 153),
    (EquipParamGem, EQUIP_PARAM_GEM_ST, 154),
    (EquipParamCustomWeapon, EQUIP_PARAM_CUSTOM_WEAPON_ST, 155),
    (GraphicsConfig, CS_GRAPHICS_CONFIG_PARAM_ST, 156),
    (SoundChrPhysicsSeParam, SOUND_CHR_PHYSICS_SE_PARAM_ST, 157),
    (FeTextEffectParam, FE_TEXT_EFFECT_PARAM_ST, 158),
    (CoolTimeParam, COOL_TIME_PARAM_ST, 159),
    (WhiteSignCoolTimeParam, WHITE_SIGN_COOL_TIME_PARAM_ST, 160),
    (MapPieceTexParam, MAP_PIECE_TEX_PARAM_ST, 161),
    (MapNameTexParam, MAP_NAME_TEX_PARAM_ST, 162),
    (WeatherLotTexParam, WEATHER_LOT_TEX_PARAM_ST, 163),
    (KeyAssignParam_TypeA, KEY_ASSIGN_PARAM_ST, 164),
    (KeyAssignParam_TypeB, KEY_ASSIGN_PARAM_ST, 165),
    (KeyAssignParam_TypeC, KEY_ASSIGN_PARAM_ST, 166),
    (MapGdRegionInfoParam, MAP_GD_REGION_ID_PARAM_ST, 167),
    (MapGdRegionDrawParam, MAP_GD_REGION_DRAW_PARAM, 168),
    (KeyAssignMenuItemParam, CS_KEY_ASSIGN_MENUITEM_PARAM, 169),
    (
        SoundAssetSoundObjEnableDistParam,
        SOUND_ASSET_SOUND_OBJ_ENABLE_DIST_PARAM_ST,
        170
    ),
    (SignPuddleParam, SIGN_PUDDLE_PARAM_ST, 171),
    (AutoCreateEnvSoundParam, AUTO_CREATE_ENV_SOUND_PARAM_ST, 172),
    (
        WwiseValueToStrParam_BgmBossChrIdConv,
        WWISE_VALUE_TO_STR_CONVERT_PARAM_ST,
        173
    ),
    (ResistCorrectParam, RESIST_CORRECT_PARAM_ST, 174),
    (
        PostureControlParam_WepRight,
        POSTURE_CONTROL_PARAM_WEP_RIGHT_ST,
        175
    ),
    (
        PostureControlParam_WepLeft,
        POSTURE_CONTROL_PARAM_WEP_LEFT_ST,
        176
    ),
    (
        PostureControlParam_Gender,
        POSTURE_CONTROL_PARAM_GENDER_ST,
        177
    ),
    (PostureControlParam_Pro, POSTURE_CONTROL_PARAM_PRO_ST, 178),
    (RuntimeBoneControlParam, RUNTIME_BONE_CONTROL_PARAM_ST, 179),
    (TutorialParam, TUTORIAL_PARAM_ST, 180),
    (BaseChrSelectMenuParam, BASECHR_SELECT_MENU_PARAM_ST, 181),
    (
        MimicryEstablishmentTexParam,
        MIMICRY_ESTABLISHMENT_TEX_PARAM_ST,
        182
    ),
    (SfxBlockResShareParam, SFX_BLOCK_RES_SHARE_PARAM, 183),
    (FinalDamageRateParam, FINAL_DAMAGE_RATE_PARAM_ST, 184),
    (SignPuddleTabParam, SIGN_PUDDLE_TAB_PARAM_ST, 185),
    (
        SignPuddleSubCategoryParam,
        SIGN_PUDDLE_SUB_CATEGORY_PARAM_ST,
        186
    ),
    (
        MapGridCreateHeightDetailLimitInfo,
        MAP_GRID_CREATE_HEIGHT_LIMIT_DETAIL_INFO_PARAM_ST,
        187
    ),
    (MapPieceTexParam_m61, MAP_PIECE_TEX_PARAM_ST_DLC02, 188),
    (MapNameTexParam_m61, MAP_NAME_TEX_PARAM_ST_DLC02, 189),
    (WeatherLotTexParam_m61, WEATHER_LOT_TEX_PARAM_ST_DLC02, 190),
    (
        MimicryEstablishmentTexParam_m61,
        MIMICRY_ESTABLISHMENT_TEX_PARAM_ST_DLC02,
        191
    ),
    (ChrEquipModelParam, CHR_EQUIP_MODEL_PARAM_ST, 192),
    (HitEffectSeParam, HIT_EFFECT_SE_PARAM_ST, 193),
);

#[cfg(test)]
mod tests {
    use crate::cs::ChrEquipModelKey;

    #[test]
    fn chr_equip_model_key_packing() {
        let mut k = ChrEquipModelKey(0);
        k.set_equip_type(3);
        k.set_gender(2);
        k.set_model_id(0xABCD);
        assert_eq!(k.equip_type(), 3);
        assert_eq!(k.gender(), 2);
        assert_eq!(k.model_id(), 0xABCD);
        assert_eq!(k.0, (3u32 << 24) | (2u32 << 16) | 0xABCDu32);
    }
}